CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Specifying nonuniform initial condition (http://www.cfd-online.com/Forums/openfoam-solving/58077-specifying-nonuniform-initial-condition.html)

msyaml March 25, 2005 12:05

Hi, I have a 2D domain consis
 
Hi,
I have a 2D domain consisting of four blocks. I want to specify the initial condition for a field variable as T=1 in block 0 and as T=0 in the other three blocks. Is there a way to specify the initial condition block-by-block? i.e., in file T in folder 0 use the keyword non-uniform and specify a list of blocks and the corresponding T values. I am a novice user and was not able find an example for this in the user's or programmer's guide or in tutorial cases (e.g., damBreak example is similar but seems to use an initialization program). Thanks.
Syam

mattijs March 25, 2005 12:34

The concept of blocks only exi
 
The concept of blocks only exists in blockMesh. (assuming that you are using blockMesh) After mesh generation (with whichever mesh generator you use) OpenFOAM has no concept of blocks. The whole mesh is one unstructured set of cells of arbitrary shape.

Since there is no information kept on what cells originate from what block you'll have to select them yourself. The damBreak application comes closest to your needs I think.

Mattijs

sampaio March 25, 2005 13:04

What if you build another case
 
What if you build another case, with only one block, coinciding with the one you want T=1. Than, if you use mapFields from there to your actual case....
Would that work for you?
I know, it is a little dirty solution...
Luiz

msyaml March 25, 2005 16:16

Luiz, Thanks for that clever
 
Luiz,
Thanks for that clever solution! Although an additional case was needed, your solution reduced the complexity of the original case (fewer blocks) and eliminated the need for an initialization program.
Syam

maka November 15, 2005 15:06

I'm trying to set a turbulent
 
I'm trying to set a turbulent nonuniform initial condition for a channel flow case. The field is available in a file with the format (column-wise):

x y z u v w p

1) I found that SetField utility that is used in the dam break case (1.2) is designed to do similar job but it uses dictionary as its input. Can any body explain how to use or modify the utility to use a data file as input.

2) I also thought of using mapField utility after trying to make a new case and cast my data into the OpenFOAM format but I faced the following problem:

the file constant/polyMesh/"points" describes vertices while what is available at my case is the node values that correspond to the values of 0/U and 0/p. I would be grateful if some body can give some help about how to solve this problem.


3) one final question about constant/polyMesh/cells: does the file format of openFOAM enforces any rules regarding the order of cells in the file or it is fully unstructured and I can order the cells as I like as long as it is consistent with 0/U, and 0/p format.

Thanks.
best regards,
Maka

maka November 15, 2005 15:40

I noticed a talk about cellSet
 
I noticed a talk about cellSet in:
http://www.cfd-online.com/OpenFOAM_D...tml?1131637441
http://www.cfd-online.com/OpenFOAM_D...es/1/1240.html

Can any one explain or give example of how to use cellSet to solve this problem or even what is cellSet? sorry I'm a beginner. Thanks.

Regards,
Maka

mattijs November 16, 2005 05:28

Look at e.g. interFoam/system/
 
Look at e.g. interFoam/system/setFieldsDict.

It uses the 'boxToCell' source. Instead you can use say the 'cellToCell' source which allows you to use a cellSet. (b.t.w. these sources are exactly the same one cellSet uses)

Mistype it and run setFields to see all the possible sources.

vvqf November 16, 2005 11:36

in boxToCell, we have ´╗┐def
 
in boxToCell, we have
´╗┐defaultFieldValues
(
volScalarFieldValue alpha 1
);

regions
(
boxToCell
{
box (0.4 0 0) (1 1 0.1);

fieldValues
(
volScalarFieldValue alpha 0.1
);
}

What about cellToCell, how to write this?
I looked into the source codes cellToCell.H/C, but didn't find answer.

mattijs November 17, 2005 06:05

to e.g. read cellSet c0 replac
 
to e.g. read cellSet c0 replace the

boxToCell
{
box (..)(..)

fieldValues ...
}

with:


cellToCell
{
set "c0";

fieldValues ...
}


(or maybe lose the quotes around c0)
Also look at the sample cellSetDict in the cellSet utility.

nico January 4, 2006 07:39

Hi Mattijis How to read in
 
Hi Mattijis

How to read in a file containig a list of cells, for example /constant/polyMesh/sets/fluid.1 ?


The file looks like:

/*---------------------------------------------------------------------------*
FoamFile
{
version 2.0;
format ascii;

root "OpenFOAM/nico-1.2/run/tutorials/simpleFoam";
case "test01";
instance ""constant"";
local "polyMesh/sets";

class cellSet;
object fluid.4;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


240
(
50
51
52
53
.
.
279
280
)

/*************************************************/

Thanks and a happy new year

gschaider January 13, 2006 05:04

As an example for reading a ce
 
As an example for reading a cellSet and manipulating data in these cells you can use this:

http://openfoamwiki.net/index.php/Contrib_setfiel dbycellset

melanie March 20, 2006 12:29

Hello, I would like to spec
 
Hello,

I would like to specify non uniform initial conditions for my case, with respect to the coordinates of the nodes.
Exemple: the velocity field is defined such as
r = x^2 + y^2
U[x] = y * a/ r^2
U[y] = -x * b/ r^2

How would you write it ? Firstly, I don't know how to access to the nodes coordinates which is blocking me...

Thanks.

mattijs March 21, 2006 05:09

Look at the setGammaDambreak a
 
Look at the setGammaDambreak app from OpenFOAM1.1. Or look on this site for setGammaField. It should contain how to access coordinates.

melanie March 21, 2006 05:54

Mattijs, I looked at the DamB
 
Mattijs,
I looked at the DamBreak case, but the velocity field is set thanks to a bounding box, so this is a different case.
Here I report what I have already written, with the error message at compilation:

#include "fvCFD.H"
#include "physicalConstants.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{

# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"
# include "createFields.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

scalar pi = physicalConstant::pi;
scalar r_0 = 0.0036;
scalar r_c = r_0*2.0/9.0;
scalar gamma = 4.0 * pi * r_c * 340.0 / 2.0;


forAll(mesh.C(), celli)
{
scalar x = mesh.C()[celli].x;
scalar y = mesh.C()[celli].y;

scalar r_1 = ::pow((x+r_0)*(x+r_0) + y*y ,0.5);
scalar r_2 = ::pow((x-r_0)*(x-r_0) + y*y ,0.5);

scalar V_theta1 = - gamma * r_1/(2.*pi*(r_c*r_c + r_1*r_1));
scalar V_theta2 = - gamma * r_2/(2.*pi*(r_c*r_c + r_2*r_2));

scalar Ux = -y * (V_theta1/r_1 + V_theta2/r_2);
scalar Uy = (x-r_0) * V_theta1/r_1 + (x+r_0) * V_theta2/r_2;
scalar Uz = 0.0;

U[celli] = (Ux Uy Uz);

}

U.write();

Info << "\n end\n";

return(0);
}

--------------------------------------------------
--------------------------------------------------

tzntgq@cfdlem04:~/OpenFOAM/OpenFOAM-1.2.1/applications/utilities/preProcessing/corotVortex> wmake
Making dependency list for source file corotVortex.C

SOURCE_DIR=.
SOURCE=corotVortex.C ; g++ -m64 -DlinuxAMD64 -Wall -W -Wno-unused-parameter -Wold-style-cast -march=opteron -O3 -ffast-math -DNoRepository -ftemplate-depth-30 -Wno-deprecated -I/home/tzntgq/OpenFOAM/OpenFOAM-1.2.1/src/cfdTools/compressible -I/home/tzntgq/OpenFOAM/OpenFOAM-1.2.1/src/cfdTools/general/lnInclude -I/home/tzntgq/OpenFOAM/OpenFOAM-1.2.1/src/OpenFOAM/lnInclude -IlnInclude -I. -fPIC -c $SOURCE -o Make/linuxAMD64Gcc4Opt/corotVortex.o
corotVortex.C: In function 'int main(int, char**)':
corotVortex.C:57: error: cannot resolve overloaded function 'x' based on conversion to type 'Foam::scalar'
corotVortex.C:58: error: cannot resolve overloaded function 'y' based on conversion to type 'Foam::scalar'
corotVortex.C:70: error: expected `)' before 'Uy'
corotVortex.C:70: error: no match for 'operator=' in 'U.Foam::GeometricField<foam::vector,>::<anonymous >.Foam::Field<foam::vector>::< anonymous>.Foam::List<foam::vector<foam::scalar> >::<anonymous>.Foam::UList<t>::operator[] [with T = Foam::vector](celli) = Ux'
/home/tzntgq/OpenFOAM/OpenFOAM-1.2.1/src/OpenFOAM/lnInclude/Vector.H:62: note: candidates are: Foam::Vector<foam::scalar>& Foam::Vector<foam::scalar>::operator=(const Foam::Vector<foam::scalar>&)
corotVortex.C:67: warning: unused variable 'Uy'
corotVortex.C:68: warning: unused variable 'Uz'
make: *** [Make/linuxAMD64Gcc4Opt/corotVortex.o] Error 1

At compilation, x and y are not recognized and the vector field U is not understood...
Could anyone give me a hint please ?

pierre March 21, 2006 08:35

maybe try forAll(mesh.cells(
 
maybe try
forAll(mesh.cells(), cellsI)
scalar x = mesh.C()[cellI].component(0)
rather than forAll(mesh.C(), celli)...

Pierre

melanie March 21, 2006 09:26

Thank you Pierre, it worked fo
 
Thank you Pierre, it worked for x and y with actually
forAll(mesh.cells(),cellI)
scalar x = mesh.C()[cellI].component(0).

Now I still have a problem with the velocity; I have defined Ux, Uy and Uz, and the line
U[cellI] = (Ux, Uy, Uz);
gives me the error message

corotVortex.C:71: warning: left-hand operand of comma has no effect
corotVortex.C:71: warning: right-hand operand of comma has no effect
corotVortex.C:71: error: no match for 'operator=' in 'U.Foam::GeometricField<foam::vector,>::<anonymous >.Foam::Field<foam::vector>::< anonymous>.Foam::List<foam::vector<foam::scalar> >::<anonymous>.Foam::UList<t>::operator[] [with T = Foam::vector](cellI) = (((void)Ux, (void)Uy), Uz)'
/home/tzntgq/OpenFOAM/OpenFOAM-1.2.1/src/OpenFOAM/lnInclude/Vector.H:62: note: candidates are: Foam::Vector<foam::scalar>& Foam::Vector<foam::scalar>::operator=(const Foam::Vector<foam::scalar>&)

pierre March 21, 2006 09:55

try U = vector(Ux, Uy, Uz);
 
try
U[cellI] = vector(Ux, Uy, Uz);

Pierre

melanie March 21, 2006 10:54

thank you Pierre, now everythi
 
thank you Pierre, now everything is working well !
mÚlanie

gschaider March 26, 2006 17:21

Inspired by this thread (and b
 
Inspired by this thread (and because I wanted such a thing for myself for some time) I decided to visit two friends of the time of my diploma thesis (the compiler generators bison and flex) and write a utility that can set fields using complex expressions (from the command line or with a dictionary). A first version is available at

http://openfoamwiki.net/index.php/Contrib_funkySe tFields

For instance the velocity field Melanie specified on the 20th:

r = x^2 + y^2
U[x] = y * a/ r^2
U[y] = -x * b/ r^2

could be set with the utility with the call (assuming a and b to be 1 and 2):

funkySetFields . theCase -field U -expression 'vector(pos().y*1/pow(mag(pos()),4),-pos().x*2/pow(mag(pos()),4),0)' -time 0

Another example would be setting the initial condition for the damBreak-tutorial:

funkySetFields . damBreak -time 0 -field gamma -expression " pos().x <= 0.1461 && pos().y <= 0.292 ? 1 : 0"

or (if you don't want to overwrite the whole gamma field):

funkySetFields . damBreak -time 0 -field gamma -expression 1 -condition "pos().x <= 0.1461 && pos().y <= 0.292"

anja March 28, 2006 05:54

Hi, can someone please expl
 
Hi,

can someone please explain me, what the following line defines

forAll(mesh.cells(),cellI)
scalar x = mesh.C()[cellI].component(0)

Thanks
Anja


All times are GMT -4. The time now is 06:14.