Heat transfer in Elmer / OpenFOAM

Numerical methods and mathematical models of Elmer
homerun4711
Posts: 40
Joined: 07 Jun 2011, 11:24
Antispam: Yes

Heat transfer in Elmer / OpenFOAM

Post by homerun4711 »

Hello!

My company needs to do some heat transfer calculations on a cooling tower using a 2D
cut through the tower. So I am searching for a FEM-software that can calculate this.

At first I had a look at OpenFOAM, this looks quite interesting and highly configurable,
but I am not sure if it would be the best solution. Searching for alternatives I came
across Elmer and had a look into its models and BCs and it looks fine so far.

I hope you can help to figure out if Elmer fits our needs.

Attached you find a picture showing our model and the BCs we want to apply.

The outer wall should get three BCs:

- Convection to the ambient temperature T_ambient: J_conv = alpha * (T_surface - T_ambient)
The convection could for a first approach be set to a fixed value (e.g. 20 W/m^2)

- Radiation to the sky: J_rad = sigma_boltz * emissitivity * (T_surface^4 - T_sky^4)

- a transient heat flux simulating sun shine, this is written in a text file that must be used

The inner wall should only use a (maybe fixed) convection for now.

Having to apply three BCs and to read one of them from a file is quite difficult in OpenFOAM.
I would have to rewrite a solver and add a mixed BC since it is only possible to add one
condition per border in OpenFOAM.

Can you tell me if Elmer will fit our needs?

Kind regards,
Walter
Attachments
mesh_tower.jpg
mesh_tower.jpg (48.21 KiB) Viewed 7932 times
raback
Site Admin
Posts: 4832
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Heat transfer in Elmer / OpenFOAM

Post by raback »

Hi Walter

The BCs that you need should be rather straight-forward: 1) and 2 are trivial. 3) is also easy if you can express the flux as a one dimensional table e.g. flux with time, [t f]. Then you can just a reference to table in the command file. If you need dependency also on the angular coordinate it might be easiest to use a user defined function where the dependecy is fitted to some polynomical expression, for example.

-Peter
homerun4711
Posts: 40
Joined: 07 Jun 2011, 11:24
Antispam: Yes

Re: Heat transfer in Elmer / OpenFOAM

Post by homerun4711 »

Hi!

Thanks for your quick response. These are really good news! Is it really that easy
to add multiple BDs in Elmer? I can hardly believe it :)
I would really like to start calculating and quit searching for the right tool :)

Sure, the flux can be expressed as a one dimensional table,
it is calculated using Octave, so I can put the values
to any desired format.

So far my plan is not to use an angle parameter to write the
depencency of the solar radiation on tower, but to discretize the outer
wall into small parts, maybe 1° or 5°. Each of this elements will
be a separate boundary with different BCs
(Octave written text file with dot product of surface normal * solar angle).

Since this surfaces should be created, named and assigned automatically
I would use Octave to write text files in Elmer's desired format.

Does this sound like a good idea? The hint with the angular dependency is
good, too and I will take a look at this.

Kind regards,
Walter
raback
Site Admin
Posts: 4832
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Heat transfer in Elmer / OpenFOAM

Post by raback »

Hi Walter

In practice what you plan sounds ok. The only concern I would have is that if you have discretization by fixed angles you will not have optimal accuracy with the mesh parameter. You will also have dependency on the additional discretization parameter. Perhaps you could eventually make a Fortran (or C) library of the solar forcing to a user defined subroutine and calculate it on-the-fly given the angle and time. But for testing purposes this would certainly not be needed.

-Peter
homerun4711
Posts: 40
Joined: 07 Jun 2011, 11:24
Antispam: Yes

Re: Heat transfer in Elmer / OpenFOAM

Post by homerun4711 »

Hi!

Thanks for your response.
Yes, writing a subroutine could be done if we further develop the model. But for the first calculations it should be ok.

Is it difficult to call a subroutine or a C-function from the *.sif file? Or at best - is it possible to call MatLab/Octave-functions direcly?

I don't unterstand what you mean saying
if you have discretization by fixed angles you will not have optimal accuracy with the mesh parameter.
I have yet another question:
The mesh should be created automatically, depending on the angle of the pieces, diameter and wall thickness. I want to create it using a Octave/MatLab function that writes a textfile (*.geo for gmsh)...same procedure as with setting the BCs.
Would you recommend to use a tool (e.g. gmsh) for this or should I stick to ElmerGrid? Or do you have a better idea?

Kind regards,
Walter
raback
Site Admin
Posts: 4832
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Heat transfer in Elmer / OpenFOAM

Post by raback »

Hi Walter

The default user defined subroutine interface includes some Elmer structures that might be difficult to address in C. Hence I would think that it would be easier to wrap the C code in piece of Fortran passing only some primitive data types.

Perhaps I understood wrong. What I meant that if you divide the 2*pi to segments and there apply constant BCs per segment, you'll introduce additional discretization.

You could indeed automate the meshing with
octave -> gmsh -> ElmerGrid -> ElmerSolver

If you want to compare different designs then often different mesh morphing methods may be attractive since their results are numerically differentiable. Of course that approach has its limitations also.

-Peter
homerun4711
Posts: 40
Joined: 07 Jun 2011, 11:24
Antispam: Yes

Re: Heat transfer in Elmer / OpenFOAM

Post by homerun4711 »

Hi!
The default user defined subroutine interface includes some Elmer structures that might be difficult to address in C. Hence I would think that it would be easier to wrap the C code in piece of Fortran passing only some primitive data types.
Do you have a very small piece of code showing how this is done in principle? Can this be added to the *.sif file or is it hard-coded?

About the discretization, you understood that right. But I do not get the point to what you mean with "not have optimal accuracy with the mesh parameter".
Juha
Site Admin
Posts: 357
Joined: 21 Aug 2009, 15:11

Re: Heat transfer in Elmer / OpenFOAM

Post by Juha »

Hi,

i think there is some documentation on this on the manuals. But anyway, you can define
a parameter (material, bc, or otherwise) from the sif file as a fortran procedure as follows:

Code: Select all

param = Variable v1,v2,v3
   Real Procedure "file" "proc"
the corresponding fortran code would have

Code: Select all

FUNCTION proc(model,n,x) RESULT(param)
  USE DefUtils
  TYPE(Model_t) :: Model
  INTEGER :: n
  REAL(KIND=dp) :: param, x(*) ! x(1)==v1, x(2)==v2,etc...


! here  you give param some value


END FUNCTION proc
then do

Code: Select all

elmerf90 file.f90 -o file
Juha
Juha
Site Admin
Posts: 357
Joined: 21 Aug 2009, 15:11

Re: Heat transfer in Elmer / OpenFOAM

Post by Juha »

Hi,

an example of calling c-function from the fortran could be

Code: Select all

FUNCTION...

  INTERFACE
     SUBROUTINE p(x,y,z,param) BIND(c)
       USE iso_c_binding
       REAL(C_DOUBLE), VALUE :: x,y,z
       REAL(C_DOUBLE) :: param
     END SUBROUTINE p
  END INTERFACE

  ..
  CALL p(x,y,z,param)

END FUNCTION ...
for the c-function

Code: Select all

void p(double x,double y,double  z,double *param)
{
  *param = x*y*z;
}
and linked together with

Code: Select all

elmerf90 file.f90 file1.c -o file
BR,Juha
homerun4711
Posts: 40
Joined: 07 Jun 2011, 11:24
Antispam: Yes

Re: Heat transfer in Elmer / OpenFOAM

Post by homerun4711 »

Thanks for your answer. This was exactly what I was looking for.

Ok, I am on my way to create the mesh. So far I found out that it is a bit tricky to write an Octave script that writes that *.geo file for gmsh.
I have to use some for-loop to discretize the outer and inner circle of the tower.

e.g.
for k = 0:359
xCoord = outerDiameter * sin( conv_deg_to_rad(k));
yCoord = outerDiameter * cos( conv_deg_to_rad(k));
fprintf(fid, 'Point(%d) = {%f, %f, 0, %f};\n', point_counter, xCoord, yCoord, meshSize);
point_counter += 1;
end
It gets even more tricky to connect the lines afterwards, because since I want to completly automatize
the mesh-creation I have to walk along the inner and outer circle and the line numbers have to be uniqe.

e.g.
for k = 0:358
fprintf(fid, 'Line(%d) = {%d, %d};\n', k , k , k+1);
end
So, I thought one of you might know an easier solution, whether it is another meshing tool or another way to accomplish the automated creation.
I found a pdf here in the forum (viewtopic.php?f=9&t=704, download/file.php?id=417)
explaining how to create and numbering BCs while converting the mesh from gmsh to Elmer's format. And since this is not completly easy going I hope you can
show me the best way how to complete my task.
I would really like to use a clear unique naming for BCs in the mesh-data and BCs in Elmer's sif-file, e.g. BC_outer_001 or something like this. Is this
supported in Elmer (if yes, which suitable meshing tool does?) or do BCs have to be assigned using only numbers in the sif-file?

Kind regards,
Walter
Post Reply