CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Equations in Cylinder Coordinates (http://www.cfd-online.com/Forums/openfoam-programming-development/71624-equations-cylinder-coordinates.html)

fishlurch January 9, 2010 13:47

Equations in Cylinder Coordinates
 
Hi,


I just started learning OpenFOAM and somewhere on the first manual pages it is mentioned, that OpenFOAM uses the carthesian coordinate system by default. I want to simulate the flow through a cylinder and so want to set up my equations in cylindrical coordinates... can I "teach" OpenFOAM to use another system than the cathesian one?


Thanks a lot
Greez
Steffen

P.S. is there a good source for learning how to develop a simulation case by hand? = not take an example and change the settings but develop a case by myself...

Thanks

fishlurch January 9, 2010 16:41

additional question
 
Hi again,


it seems to me that icoFOAM bases on the Navier-Stokes Equation, which I need. But...

... is the continuity equation also included there?
... how can I set up additional boundary and starting conditions? Do I need to write them into any part of the C Code and recompile the Files or is it possible to set them up into the "normal" config files?
... again - how can I make OpenFOAM use cylindrical Coordinates? So I have to change and recompile the code for that or can I set that up in any of the config files?
... If I have to change so many things on an existing project, will it be better/ easier to built a project by myself?

Thanks a lot - I am a little "overextended" because of the huge power and possibilities of the program.


Greez
Steffen

sega January 9, 2010 19:06

Quote:

Originally Posted by fishlurch (Post 241977)
can I "teach" OpenFOAM to use another system than the cathesian one?

I don't think so. Prove me wrong, developers ...

sega January 9, 2010 19:13

Quote:

Originally Posted by fishlurch (Post 241987)
... is the continuity equation also included there?

Yes. icoFoam uses the PISO-algorithm which includes the numerical treatment of the continuity equation.

Quote:

Originally Posted by fishlurch (Post 241987)
... how can I set up additional boundary and starting conditions?

What are "additional" boundary and starting conditions for you?

Quote:

Originally Posted by fishlurch (Post 241987)
... again - how can I make OpenFOAM use cylindrical Coordinates?

I'm not sure this is possible. If you want to simulate within an axisymmetric coordinate system you can use the wedge-boundary condition!
Have a look at Fig. 5.4 in the User Guide.

Quote:

Originally Posted by fishlurch (Post 241987)

... If I have to change so many things on an existing project, will it be better/ easier to built a project by myself?

Are you talking about a single simulation or the whole OpenFOAM when you say "project"?

fishlurch January 10, 2010 09:05

Boundaries:
For solving a DiffEq one needs boundary and starting conditions, like e.g. U(t=0)=0 or p(x=0)=0; How and where are such conditions set up in a simulation (=project) (as e.g. icoFOAM)? And If I want to change such conditions in an existing project, where can I do so? Do I have to touch the C code or can it be realized via changing parameters in the already compiled files (as one can find in the tutorials folder).

Sorry if my questions are not posed very precisely, but it is because I just started with OpenFOAM.


Thanks a lot
Greez
Steffen

sega January 10, 2010 15:33

Quote:

Originally Posted by fishlurch (Post 242020)
Boundaries:
For solving a DiffEq one needs boundary and starting conditions, like e.g. U(t=0)=0 or p(x=0)=0; How and where are such conditions set up in a simulation (=project) (as e.g. icoFOAM)? And If I want to change such conditions in an existing project, where can I do so? Do I have to touch the C code or can it be realized via changing parameters in the already compiled files (as one can find in the tutorials folder).

Sorry if my questions are not posed very precisely, but it is because I just started with OpenFOAM.


Thanks a lot
Greez
Steffen

Did you have a look at the tutorial cases, like mentioned in the User Guide?
Initial and boundary conditions for each fields are stored within the case directory's subdirectory '0' (corresponsing to time = 0).

Like: 0/U (Velocity) or 0/p (Pressure)

You don't have to touch the OpenFOAM code, but simply run the icoFoam on a case. But if you haven't figured that out yet I supposed you haven't had a look into the User Guide. I suggest you do that in the next step.

olesen January 11, 2010 04:42

Quote:

Originally Posted by fishlurch (Post 241977)
I just started learning OpenFOAM and somewhere on the first manual pages it is mentioned, that OpenFOAM uses the carthesian coordinate system by default. I want to simulate the flow through a cylinder and so want to set up my equations in cylindrical coordinates

Just because your geometry is cylindrical why do you need to solve the governing equations in a cylindrical coordinate system?

fishlurch January 11, 2010 05:52

As a first approxomation for my diploma thesis I want to simulate the flow through a pipe (=cylinder), which has specific properties. When using a cylindrical coordinate system, the equations look much easier than in carthesian coordinates. For sure I could use the carthesian one, but then the equations become quite ugly...

@ Mark: Do you think it makes sense to make OpenFOAM use another coordinate system? (I found this: http://openfoamwiki.net/index.php/Si...ry_/_Tutorials). If I used the carthesian system, my boundary conditions become quite complicated (e.g. describe a condition on the wall of the cylinder...)

@ Sebastian: I read the user guide's chapters about boundaries, but it is still unclear how to handle them. Now I know that somehow the "boundary" file and the "p" and "U" files correspond, but I still dont understand in which way... e.g. If I simply wanted to say: "U_x(x=0,y,z,t)=0" or "p(t=0,x,y,z)=p_start", how could I set this up?


Perhaps one can explain my problem with a little example:

"boundary file":
movingWall
{
type wall;
nFaces 20;
startFace 760;
}

"/0/p file":
movingWall
{
type zeroGradient;
}

Does that mean that the moving wall (specified in polyMeshDict) has a zeroGradient (in what?) for all the time? And what does nFaces and startFaces mean?


Sorry for this huge postings - but I am really interested in OpenFOAM and this unclearity in my brain drives me crazy :confused:

Thank you!

olesen January 11, 2010 06:39

Quote:

Originally Posted by fishlurch (Post 242116)
As a first approxomation for my diploma thesis I want to simulate the flow through a pipe (=cylinder), which has specific properties. When using a cylindrical coordinate system, the equations look much easier than in carthesian coordinates. For sure I could use the carthesian one, but then the equations become quite ugly...

@ Mark: Do you think it makes sense to make OpenFOAM use another coordinate system?

Cylindrical coordinates may make it easier to formulate your boundary conditions, but I would not agree that governing equations (Navier-Stokes) look much easier - cf. http://en.wikipedia.org/wiki/Navier%E2%80%93Stokes_equations#Cylindrical_coordi nates
... not even considering how something like the Reynolds' stresses would look like in cylindrical coordinates!
Also consider that the code would internally need different definitions for the gradient, divergence, laplacian etc. operators, as well as cell positions, volume calculations etc. And of course, your cylindrical domain would always need to be exactly coincide with the global coordinates .... I hope you can see why Cartesian coordinates are used for general purpose CFD codes (commercial or open source).

If you wish to solve your problem with OpenFOAM, STAR-CD, Fluent, CFX, etc. just get used to the idea that you need to solve in Cartesian coordinates. Of course you are still free to transform your final results back into cylindrical if that's what you need.

fishlurch January 11, 2010 06:49

Oh all right - I see the problem... thanks for advice :-)

At the moment I am trying to simulate a simple Hagen-Poisseuilles Flow in a cylindrical tube - just for Practice...

If I wanted to extend this first test to a non-rigid (= extesible tube), how do I have to build up my mesh? Does it have to be variable in size? Or is there any "common" technique for that?


Thx and Greez
Steffen

sega January 11, 2010 07:48

Quote:

Originally Posted by fishlurch (Post 242116)
As a first approxomation for my diploma thesis I want to simulate the flow through a pipe (=cylinder), which has specific properties. When using a cylindrical coordinate system, the equations look much easier than in carthesian coordinates. For sure I could use the carthesian one, but then the equations become quite ugly...

@ Mark: Do you think it makes sense to make OpenFOAM use another coordinate system? (I found this: http://openfoamwiki.net/index.php/Si...ry_/_Tutorials). If I used the carthesian system, my boundary conditions become quite complicated (e.g. describe a condition on the wall of the cylinder...)

@ Sebastian: I read the user guide's chapters about boundaries, but it is still unclear how to handle them. Now I know that somehow the "boundary" file and the "p" and "U" files correspond, but I still dont understand in which way... e.g. If I simply wanted to say: "U_x(x=0,y,z,t)=0" or "p(t=0,x,y,z)=p_start", how could I set this up?


Perhaps one can explain my problem with a little example:

"boundary file":
movingWall
{
type wall;
nFaces 20;
startFace 760;
}

"/0/p file":
movingWall
{
type zeroGradient;
}

Does that mean that the moving wall (specified in polyMeshDict) has a zeroGradient (in what?) for all the time? And what does nFaces and startFaces mean?


Sorry for this huge postings - but I am really interested in OpenFOAM and this unclearity in my brain drives me crazy :confused:

Thank you!

You are investigating in the right direction!
First of all you mesh with the blockMesh tool.
This is where you specify the boundary conditions, like wall in you example.
blockMesh writes the boundary file which should not be touched by you at this moment.

All you have to do is to manipulate the 0/U file!
Code:

movingWall     
    {
type wall;
    }

Looks a little bit like a repetition of the blockMeshDict file...
Well, at least for such a simple boundary condition this may be true.

Wall corresponds to U=0 at this boundary.
If you have specified wall as boundary condition in the blockMesh file zeroGradient (velocity gradient normal to the boundary) would not be possible as it is allready set to U=0 from blockMesh and written to the boundary file.
Still with me?
Make sure you understand that you specify the boundaries within the blockMeshDict and in the field file as well and they have to correspond.

Example (besides the many in the tutorial cases):

To set up a Neuman boundary condition, select patch in the blockMeshDict file and select zeroGradient in the field file.

To select a moving Wall, select patch in the blockMeshDict file
and select type fixedValue; value uniform(0 1 0) corresponding to the velocity direction you wall is moving.

amedlin March 26, 2010 01:27

Advantage of cylindrical coordinates
 
The main advantage of cylindrical coordinates as I see it is that you can more easily exploit rotational symmetry in your problem to make it more computationally tractable.

For example, if your 3D geometry is axisymmetric, you could write your equations in cylindrical coordinates and reduce it to a 2D problem. A 2D simulation domain is likely to run orders of magnitude faster than the same thing modelled in 3D.

I'm not sure if OpenFOAM supports it, but even with your mesh in cartesian coordinates you could effectively solve it in a 2D domain if the solver implements angular cyclic boundary conditions. In this case your mesh dimension in the theta direction could be 1 cell, effectively turning it into a 2D problem.

sega March 26, 2010 04:11

Quote:

Originally Posted by amedlin (Post 251763)
I'm not sure if OpenFOAM supports it, but even with your mesh in cartesian coordinates you could effectively solve it in a 2D domain if the solver implements angular cyclic boundary conditions. In this case your mesh dimension in the theta direction could be 1 cell, effectively turning it into a 2D problem.

No, OpenFOAM does not support cylindrical coordinates.
It's all 3D cartesian!

akidess June 8, 2010 10:09

Quote:

Originally Posted by sega (Post 251772)
No, OpenFOAM does not support cylindrical coordinates.
It's all 3D cartesian!

For sake of completeness:
It's all 3D cartesian, but it is possible to specify a wedge boundary condition (angular cyclic) as amedlin described to effectively reduce your computation to 2D.

skynet4ever January 4, 2012 11:51

Hi,

sorry i resurrect this old Thread but I have exactly the same question as the original poster, plus the answers of akidess & amedlin go in the direction I want:

My problem has cylinder symmetry which reduces my 3D Problem to 2D. My Problem is now to design a solver with the governing equations which of cause differ a little from their Cartesian form. My equations read:

momentum equation:
r\Omega^2 - \frac{GM r}{\left(r^2+z^2\right)^{3/2}}-\frac{1}{\rho}\frac{\partial P}{\partial r}= 0 (radial direction)
\frac{GM z}{\left(r^2+z^2\right)^{3/2}}-\frac{1}{\rho}\frac{\partial P}{\partial r}= 0 (vertical direction)

together with the mass conservation:
\frac{\partial \rho}{\partial t}+\frac{1}{r}\frac{\partial}{\partial r}\left( r \rho \mathbf{v}_r \right) + \frac{\partial}{\partial z} \left(\rho \mathbf{v}_z \right)= 0

whereas:
r,z are coordinate variable names
G,M are constants
P is the pressure field
rho is the density field

Now how do I formulate this in the OF language? In particular how do I use the coordinate position in the formulation of the equations? Can I write something like:
Code:

volScalarField temp1(r*rho & v_r);
volScalarField temp2(rho & v_z);

solve (      fvm::ddt(rho)    + 1/r * fvm::grad(temp1) + fvm::grad(temp2)      ==    - fvc::grad(p) );

I know this is probably (very very) wrong, but I hope you know what I mean.

I would really like to use OpenFOAM for this because I like C++ and the OO programming style. I also think OpenFOAM knowledge can be a key ability for later jobs. If you like to know where the equations come from: It is going to be the simulation of a solar nebula in its disk phase.

Thank you for helping!

p.s.: The singularity at r=0 is no problem because I stop the simulation before the Sun starts ;-)

skynet4ever January 12, 2012 08:08

1 Attachment(s)
Hi Foamers,

can't somebody give me a hint? I have done a sketch of my problem which I appended as an attachment.

I have already constructed a grid using wedge boundary conditions. Which can be found in this Thread http://www.cfd-online.com/Forums/ope...wo-blocks.html

as I read in multiple Threads I can't use equations in cylindrical symetry, right? (please answer) So I have to transform my equations. But as my grid is only 2D I see no point in giving an expression for the symmetric Coordinate. If that is so can I simply replace r->x and z->z? Or dose the wedge boundary internally need the full equation? The continuity equation is straightforward but I have trouble with the momentum equation...
I also could really need some help for the construction of the corresponding field from the equation above. I found some useful code in the tutorial "Flow around a cylinder" from the programmers guide:
Code:

          Info<< "\nEvaluating analytical solution" << endl;

            const volVectorField& centres = UA.mesh().C();
            volScalarField magCentres(mag(centres));
            volScalarField theta(acos((centres & vector(1,0,0))/magCentres));

            volVectorField cs2theta
            (
                cos(2*theta)*vector(1,0,0)
              + sin(2*theta)*vector(0,1,0)
            );

            UA = uInfX*(dimensionedVector(vector(1,0,0))
              - pow((radius/magCentres),2)*cs2theta);

can I use this to construct an appropriate Vectorfield which can be used by differential operators? Or can I solve the problem in the CS and transform it afterwards? Please help. I think the rotational symmetry problems are of general interest (when looking at the read-numbers)

From the http://openfoamwiki.net/index.php/Si...ry_/_Tutorials I learn that it is at least possible to introduce a Cylindrical Coordinate Systems...

Thanks in advance.
Philipp


All times are GMT -4. The time now is 16:17.