CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Defining constants for funkySetFields and groovyBC (https://www.cfd-online.com/Forums/openfoam-pre-processing/94910-defining-constants-funkysetfields-groovybc.html)

anaiman November 29, 2011 16:03

Defining constants for funkySetFields and groovyBC
 
I'd like to set some constant values in a single file that will be used to define my velocity boundary conditions and initial conditions. I've attempted to do this by writing them as variables in a file (say, "case/0/include/constants"):

Code:


variables (
"Uref=1.0;"
);

and then including them in the initial field dictionary (say, "case/0/U"):

Code:


boundaryField
{
    inlet
    {
        type            groovyBC;
        value          $internalField;
        #include "include/constants"
        valueExpression "vector(Uref, 0, 0)";
    }
}

The goal is to eventually take advantage of the groovyBC to set a more complicated inlet velocity profile. This works fine.

But I would also like to use the same constants to set the initial velocity field. I tried including the file (in "case/system/funkySetFieldsDict"):

Code:


expressions
(
 init_U
 {
  field U;
  expression "vector(Uref, 0, 0)";
  keepPatches 1;
  #include "../0/include/constants"
 }
);

but this resulted in a FOAM fatal IO error: attempt to read beyond EOF while reading the funkySetFieldsDict. If I replace the #include directive with what's in the 0/include/constants file, it works the way I want it to, so I think I at least have the right idea . . .

I'm not entirely clear on how parsing of the dictionary files happens - am I using the #include directive wrong? Or is this a funkySetFields bug?

Thanks for any suggestions,
Alex

gschaider November 29, 2011 19:01

Quote:

Originally Posted by anaiman (Post 334020)
I'd like to set some constant values in a single file that will be used to define my velocity boundary conditions and initial conditions. I've attempted to do this by writing them as variables in a file (say, "case/0/include/constants"):

Code:


variables (
"Uref=1.0;"
);

and then including them in the initial field dictionary (say, "case/0/U"):

Code:


boundaryField
{
    inlet
    {
        type            groovyBC;
        value          $internalField;
        #include "include/constants"
        valueExpression "vector(Uref, 0, 0)";
    }
}

The goal is to eventually take advantage of the groovyBC to set a more complicated inlet velocity profile. This works fine.

But I would also like to use the same constants to set the initial velocity field. I tried including the file (in "case/system/funkySetFieldsDict"):

Code:


expressions
(
 init_U
 {
  field U;
  expression "vector(Uref, 0, 0)";
  keepPatches 1;
  #include "../0/include/constants"
 }
);

but this resulted in a FOAM fatal IO error: attempt to read beyond EOF while reading the funkySetFieldsDict. If I replace the #include directive with what's in the 0/include/constants file, it works the way I want it to, so I think I at least have the right idea . . .

I'm not entirely clear on how parsing of the dictionary files happens - am I using the #include directive wrong? Or is this a funkySetFields bug?

Thanks for any suggestions,
Alex

I'm not an expert on #include in OF, but I think include only works at the the top level of a file. What you might wan to try is to write in your file

Code:


defaultVariables (
"Uref=1.0;"
);

include it at the start of your file and then use the value in your dictionaries

Code:


variables $defaultVariables;

Another thing that might interest you (although it is a bit of an overkill for this application) is the globalVariables-thing in the last release of swak4Foam (you've got to use the -allowFunctionObjects-option for funkySetFields as global variables are defined by functionObjects)

anaiman November 30, 2011 13:29

Quote:

Originally Posted by gschaider (Post 334044)
I'm not an expert on #include in OF, but I think include only works at the the top level of a file. What you might wan to try is to write in your file

Code:


defaultVariables (
"Uref=1.0;"
);

include it at the start of your file and then use the value in your dictionaries

Code:


variables $defaultVariables;


That appears to be the right way to go about this, thanks for your help. This seems like something that nearly everyone running OF would want to do at some point, but the user guide on Directives and Macro Substitutions is not very edifying . . . the final sentence of that section being
Quote:

The extent to which such functionality can be used is almost endless.
Indeed. Thanks again!

gschaider November 30, 2011 14:32

Quote:

Originally Posted by anaiman (Post 334164)
That appears to be the right way to go about this, thanks for your help. This seems like something that nearly everyone running OF would want to do at some point,

I can imagine why it is not allowed (basically because this substitution business is not a completely separate stage like the preprocessor is for a C++ compiler). I think the alternatives could lead to even more confusing errors

Quote:

Originally Posted by anaiman (Post 334164)
but the user guide on Directives and Macro Substitutions is not very edifying . . . the final sentence of that section being
Quote:

The extent to which such functionality can be used is almost endless.

Brilliant. I always had a bad concience about the swak-docu, but no more: I'll reuse the sentence

Sasy October 3, 2013 12:46

1 Attachment(s)
Hi all
I want simulate two phase flow and I have Non-uniform initial conditions,I know,should use funkySetFields for this, and I read http://openfoamwiki.net/index.php/Co...funkySetFields
but I have problem and cant write true ,I attach my equation (that show interface two phase)
any body know how Write this equation with funkySetFields

gschaider October 3, 2013 13:01

Quote:

Originally Posted by Sasy (Post 454913)
Hi all
I want simulate two phase flow and I have Non-uniform initial conditions,I know,should use funkySetFields for this, and I read http://openfoamwiki.net/index.php/Co...funkySetFields
but I have problem and cant write true ,I attach my equation (that show interface two phase)
any body know how Write this equation with funkySetFields

Reposting the same question in multiple threads is a sure-fire way to be ignored ... at least by me.

Before I go on: what docu HAVE you already read? (I think that the funkySetFields and the swak-page on the Wiki should have all the information necessary for your equation. Maybe also read the reference guide which is linked from the swak-page)

vsammartano December 1, 2016 06:34

funckySetFieldsDict and #include "file_with_variables"
 
Hi all,
dear gschaider and anaiman, I have read your posts about the importing constants for funkySetFields. did you solved the problem?
I am having a similar problem.
I would like to import some variables in the funckySetFieldsDict, using the #include function in this way:

/////////////////////////////////////////////////
#include "initialConditions"
defaultFieldValues
(
volScalarFieldValue alpha.water 0
);

expressions
(
init_alpha.water
{
field alpha.water;
expression "(((max(min((($a*cos(($omega*time())-($k*pos().x)))-pos().z),$tr/2),-$tr/2))+$tr/2)/$tr)";
condition "pos().x<=0.1";
keepPatches true; //keep the boundary conditions that were set before
}
);

obviously the variables called inside the expression are all included in the file InitialConditions.
This code does not work at all!
FOAM says me:

....

--> FOAM FATAL ERROR:
Entry "a" not found in ".init_alpha.water"
From function CommonValueExpressionDriver::getEntryString
in file CommonValueExpressionDriver.C at line 699.
FOAM exiting


I am stuck with it.

Please could you help me to solve this issue?
Thank you so much

PS: I have also tried to put #include "initialConditions" inside expression, but this does not give me a good results:

....
--> FOAM FATAL IO ERROR:
keyword field is undefined in dictionary ".init_alpha.water"

file: .init_alpha.water from line 3 to line 32.

From function const Foam::entry& Foam::dictionary::lookupEntry(const Foam::word&, bool, bool) const
in file db/dictionary/dictionary.C at line 441.

FOAM exiting

gschaider December 4, 2016 06:37

At first: please use the CODE-tag (that is the # in the icons of the editor). It makes it much clearer what is your text and what is OF-input/output

Quote:

Originally Posted by vsammartano (Post 627724)
Hi all,
dear gschaider and anaiman, I have read your posts about the importing constants for funkySetFields. did you solved the problem?
I am having a similar problem.
I would like to import some variables in the funckySetFieldsDict, using the #include function in this way:

/////////////////////////////////////////////////
#include "initialConditions"
defaultFieldValues
(
volScalarFieldValue alpha.water 0
);

expressions
(
init_alpha.water
{
field alpha.water;
expression "(((max(min((($a*cos(($omega*time())-($k*pos().x)))-pos().z),$tr/2),-$tr/2))+$tr/2)/$tr)";
condition "pos().x<=0.1";
keepPatches true; //keep the boundary conditions that were set before
}
);

obviously the variables called inside the expression are all included in the file InitialConditions.
This code does not work at all!
FOAM says me:

....

--> FOAM FATAL ERROR:
Entry "a" not found in ".init_alpha.water"
From function CommonValueExpressionDriver::getEntryString
in file CommonValueExpressionDriver.C at line 699.
FOAM exiting


I am stuck with it.

Please could you help me to solve this issue?
Thank you so much

PS: I have also tried to put #include "initialConditions" inside expression, but this does not give me a good results:

....
Code:

--> FOAM FATAL IO ERROR:
keyword field is undefined in dictionary ".init_alpha.water"

file: .init_alpha.water from line 3 to line 32.

    From function const Foam::entry& Foam::dictionary::lookupEntry(const Foam::word&, bool, bool) const
    in file db/dictionary/dictionary.C at line 441.
FOAM exiting


You haven't posted your initialConditions-file. But the last error suggests that you forgot the last ; (semicolon) in it. If your file looks like this
Code:

foo 42;
bar 666

and you include it immediately before the field-entry then OpenFOAM assumes that there is an entry
Code:

bar 666 field alpha.water;
but no entry field.

Still there might be a problem with the macro-expansion as the semantics of that changed a bit between OF-versions so it would be important to know what that is

vsammartano December 5, 2016 15:14

Quote:

Originally Posted by gschaider (Post 628191)
At first: please use the CODE-tag (that is the # in the icons of the editor). It makes it much clearer what is your text and what is OF-input/output



You haven't posted your initialConditions-file. But the last error suggests that you forgot the last ; (semicolon) in it. If your file looks like this
Code:

foo 42;
bar 666

and you include it immediately before the field-entry then OpenFOAM assumes that there is an entry
Code:

bar 666 field alpha.water;
but no entry field.

Still there might be a problem with the macro-expansion as the semantics of that changed a bit between OF-versions so it would be important to know what that is


Dear gschaider,
first of all thank you for your kind reply.
I have modified the funkySetfieldDict as follow:


/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v4.x |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object funkySetFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

defaultFieldValues
(
volScalarFieldValue alpha.water 0
);
expressions
(
init_alpha.water
{
defaultVariables
(
#include "initialConditions"
);
variables
(
"#defaultVariables;"
"eta = a*cos((omega*time())-(k*pos().x))"
"M1 = min(eta-pos().z,tr/2);"
"M2 = max(M1,-tr/2);"
);

field alpha.water;

expression "(M2+0.5*tr)/tr";
condition "pos().x<=0.5";
keepPatches true; //keep the boundary conditions that were set before
}
);


and here it is the initialConditions file:

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v4.x |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object initialConditions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
h 0.5;
T 6;
H 0.1;
a 0.05;
omega 1.0472;
L 13.1611;
c 2.19351;
k 0.477406;
xmin 0;
ymin 0;
zmin -0.5;
xmax 39;
ymax 0.1;
zmax 0.4;
z0 0;
x1 6;
x2 32;
pz1 0.28;
pz2 0.195;
pz3 0.195;
pz4 0.33;
ztot 0.9;
Ncz 100;
dz 0.009;
tr 0.009;
/*


The dictionary works better, but there is still an error that I do not understand at all:

/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 4.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 4.x-a6a964b26579
Exec : funkySetFields -time 0
Date : Dec 05 2016
Time : 20:06:30
Host : "viciolinux"
PID : 6602
Case : /home/vicio/OpenFOAM/vicio-4.x/run/wave1
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
swakVersion: 0.4.1 (Release date: Next release) - HG Branch:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Using #calcEntry at line 28 in file "/home/vicio/OpenFOAM/vicio-4.x/run/wave1/system/controlDict"
Using #codeStream with "/home/vicio/OpenFOAM/vicio-4.x/run/wave1/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_129f61639bcd524f3f670ac2b58913ef0a86 7c06.so"
Create mesh for time = 0


Time = 0
Using funkySetFieldsDict



Part: init_alpha.water
Modifying field alpha.water of type volScalarField

Putting "(M2+tr/2)/tr" into field alpha.water at t = "0" if condition "pos().x<=0.5" is true
Keeping patches unaltered



--> FOAM FATAL IO ERROR:
wrong token type - expected string, found on line 1 the word 'FoamFile'

file: .init_alpha.water.defaultVariables at line 1.

From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::string&)
in file primitives/strings/string/stringIO.C at line 56.

FOAM exiting


Any ideas about this issue?
Thank you again!
Regards,
Vincenzo

gschaider December 8, 2016 17:53

Please start using the CODE-tag if I ask you for it. It makes it much easier to distinguish your text and the input/output. Formatting is also nicer. It takes you only 2 seconds to click on the # but it saves me 20 seconds of head scratching ("where does this file end? Is that REALLY part of the file? Indentation would make this easier to read"). If you think that your two seconds are more valuable than my 20 seconds then I'll assume that you can answer the question yourself and ignore further postings from you

Quote:

Originally Posted by vsammartano (Post 628416)
Dear gschaider,
first of all thank you for your kind reply.
I have modified the funkySetfieldDict as follow:


/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v4.x |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object funkySetFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

defaultFieldValues
(
volScalarFieldValue alpha.water 0
);
expressions
(
init_alpha.water
{
defaultVariables
(
#include "initialConditions"
);
variables
(
"#defaultVariables;"
"eta = a*cos((omega*time())-(k*pos().x))"
"M1 = min(eta-pos().z,tr/2);"
"M2 = max(M1,-tr/2);"
);

field alpha.water;

expression "(M2+0.5*tr)/tr";
condition "pos().x<=0.5";
keepPatches true; //keep the boundary conditions that were set before
}
);


and here it is the initialConditions file:

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v4.x |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object initialConditions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
h 0.5;
T 6;
H 0.1;
a 0.05;
omega 1.0472;
L 13.1611;
c 2.19351;
k 0.477406;
xmin 0;
ymin 0;
zmin -0.5;
xmax 39;
ymax 0.1;
zmax 0.4;
z0 0;
x1 6;
x2 32;
pz1 0.28;
pz2 0.195;
pz3 0.195;
pz4 0.33;
ztot 0.9;
Ncz 100;
dz 0.009;
tr 0.009;
/*


The dictionary works better, but there is still an error that I do not understand at all:

/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 4.x |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 4.x-a6a964b26579
Exec : funkySetFields -time 0
Date : Dec 05 2016
Time : 20:06:30
Host : "viciolinux"
PID : 6602
Case : /home/vicio/OpenFOAM/vicio-4.x/run/wave1
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
swakVersion: 0.4.1 (Release date: Next release) - HG Branch:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Using #calcEntry at line 28 in file "/home/vicio/OpenFOAM/vicio-4.x/run/wave1/system/controlDict"
Using #codeStream with "/home/vicio/OpenFOAM/vicio-4.x/run/wave1/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_129f61639bcd524f3f670ac2b58913ef0a86 7c06.so"
Create mesh for time = 0


Time = 0
Using funkySetFieldsDict



Part: init_alpha.water
Modifying field alpha.water of type volScalarField

Putting "(M2+tr/2)/tr" into field alpha.water at t = "0" if condition "pos().x<=0.5" is true
Keeping patches unaltered



--> FOAM FATAL IO ERROR:
wrong token type - expected string, found on line 1 the word 'FoamFile'

file: .init_alpha.water.defaultVariables at line 1.

From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::string&)
in file primitives/strings/string/stringIO.C at line 56.

FOAM exiting


Any ideas about this issue?
Thank you again!
Regards,
Vincenzo

In a file loaded by #include the FoamFile-header is not needed and might even make OpenFOAM fail. Reason is that #include just takes the text from the include-file and inserts it into the "master"-file. Only then is the master-file parsed

vsammartano December 9, 2016 05:18

#include <file> doe not work
 
Hi, thank you for your reply.
I think this is not the reason why the #include does not work. Actually I have used this file (initialConditions) as it is in other "applications" and OpenFOAM gives me NO errors! ...for example I used this file in groovyBC and it works, in blockMeshDict it works, in setFieldsDict works ...
However, as you are suggesting me I have used the initialConditions file without the header and OpenFOAM still replies me with the same fu**** error. So, I think that the #include <file> does not work at all in the funkySetFieldDict, I mean this is bug.
For a short time I thought there were an error in the expressions, so I removed the #include <file> and wrote the variables into the funkySetFieldDict file....and it works pretty good!
However the #include file could have been a smart way in order to reduce some repeated variables, as you can see in the following funkySetFieldDict file.
Again, thank you.


code:

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 4 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object funkySetFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "initialConditions"
defaultFieldValues
(
volScalarFieldValue alpha.water 0;
volVectorFieldValue U 0;
);


expressions
(
AlphaWater_Inlet
{
field alpha.water;
expression "aw_inlet";
keepPatches false; //keep the boundary conditions that were set before
patchName "inlet";
variables
(
"a=0.05;"
"omega=1.0472;"
"tshift=-pi/2;"
"eta_inlet=a*cos(omega*(tshift));"
"thres=0.009;" //threshold value depends on the mesh ... improvement here
"DZmin=min((eta_inlet-pos().z),0.5*thres);"
"DZmax=max(DZmin,-0.5*thres);"
"aw_inlet=(DZmax+0.5*thres)/thres;" //alpha water value

);
}


AlphaWater
{
field alpha.water;
expression "aw";
keepPatches true; //keep the boundary conditions that were set before
variables
(
"a=0.05;"
"omega=1.0472;"
"k=0.477406;"
"tshift=-pi/2;"
"eta=a*cos(omega*(time()+tshift)-k*pos().x);"
"thres=0.009;"
"DZmin=min((eta-pos().z),0.5*thres);"
"DZmax=max(DZmin,-0.5*thres);"
"aw=(DZmax+0.5*thres)/thres;" //alpha water value

);
}

VelocityField_Inlet
{
field U;
expression "Uw_inlet";
keepPatches false; //keep the boundary conditions that were set before
patchName "inlet";
variables
(
"a=0.05;"
"h=0.5;"
"omega=1.0472;"
"k=0.477406;"
"tshift=-pi/2;"
"gg=vector(0,0,-9.81);"
"eta_inlet=a*cos(omega*(time()+tshift));"
"thres=0.009;" //threshold value depends on the mesh dimentions
"DZmin=min((eta_inlet-pos().z),0.5*thres);"
"DZmax=max(DZmin,-0.5*thres);"
"aw_inlet=(DZmax+0.5*thres)/thres;" //alpha water value
"Uwx_in=aw_inlet*(a*(mag(gg)/omega)*k*(cosh((h+pos().z)*k)/cosh(h*k))*(cos(-(omega*(time()+tshift)))));"
"Uwy_in=0;"
"Uwz_in=aw_inlet*(a*(mag(gg)/omega)*k*(sinh((h+pos().z)*k)/cosh(h*k))*(sin(-(omega*(time()+tshift)))));"
"Uw_inlet=vector(Uwx_in, Uwy_in, Uwz_in);"

);
}

VelocityField
{
field U;
expression "Uw";
keepPatches true; //keep the boundary conditions that were set before
variables
(
"a=0.05;"
"h=0.5;"//0.5
"omega=1.0472;"
"k=0.477406;"
"tshift=-pi/2;"
"gg=vector(0,0,-9.81);"
"eta=a*cos(omega*(time()+tshift)-k*pos().x);"
"thres=0.009;" //threshold value depends on the mesh dimentions
"DZmin=min((eta-pos().z),0.5*thres);"
"DZmax=max(DZmin,-0.5*thres);"
"aw=(DZmax+0.5*thres)/thres;" //alpha water value
"Uwx=aw*(a*(mag(gg)/omega)*k*(cosh((h+pos().z)*k)/cosh(h*k))*(cos(k*pos().x-(omega*(time()+tshift)))));"
"Uwy=0;"
"Uwz=aw*(a*(mag(gg)/omega)*k*(sinh((h+pos().z)*k)/cosh(h*k))*(sin(k*pos().x-(omega*(time()+tshift)))));"
"Uw=vector(Uwx, Uwy, Uwz);"

);
}

);

gschaider December 13, 2016 18:34

This is what source code looks like with the code-environment:
Code:

dict {
      val 1;
      sub {
          a 1;
          b 2;
      }
}

And this way without:

dict {
val 1;
sub {
a 1;
b 2;
}
}

The first form makes it easy for me to see what is going on. The second form I have to count brackets to see what the problem might be. It also makes it hard for me to see where the file ends and the text starts.

That said: I didn't have a closer look at your post because it is unreadable

Quote:

Originally Posted by vsammartano (Post 628896)
Hi, thank you for your reply.
I think this is not the reason why the #include does not work. Actually I have used this file (initialConditions) as it is in other "applications" and OpenFOAM gives me NO errors! ...for example I used this file in groovyBC and it works, in blockMeshDict it works, in setFieldsDict works ...
However, as you are suggesting me I have used the initialConditions file without the header and OpenFOAM still replies me with the same fu**** error. So, I think that the #include <file> does not work at all in the funkySetFieldDict, I mean this is bug.
For a short time I thought there were an error in the expressions, so I removed the #include <file> and wrote the variables into the funkySetFieldDict file....and it works pretty good!
However the #include file could have been a smart way in order to reduce some repeated variables, as you can see in the following funkySetFieldDict file.
Again, thank you.


code:

/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 4 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object funkySetFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "initialConditions"
defaultFieldValues
(
volScalarFieldValue alpha.water 0;
volVectorFieldValue U 0;
);


expressions
(
AlphaWater_Inlet
{
field alpha.water;
expression "aw_inlet";
keepPatches false; //keep the boundary conditions that were set before
patchName "inlet";
variables
(
"a=0.05;"
"omega=1.0472;"
"tshift=-pi/2;"
"eta_inlet=a*cos(omega*(tshift));"
"thres=0.009;" //threshold value depends on the mesh ... improvement here
"DZmin=min((eta_inlet-pos().z),0.5*thres);"
"DZmax=max(DZmin,-0.5*thres);"
"aw_inlet=(DZmax+0.5*thres)/thres;" //alpha water value

);
}


AlphaWater
{
field alpha.water;
expression "aw";
keepPatches true; //keep the boundary conditions that were set before
variables
(
"a=0.05;"
"omega=1.0472;"
"k=0.477406;"
"tshift=-pi/2;"
"eta=a*cos(omega*(time()+tshift)-k*pos().x);"
"thres=0.009;"
"DZmin=min((eta-pos().z),0.5*thres);"
"DZmax=max(DZmin,-0.5*thres);"
"aw=(DZmax+0.5*thres)/thres;" //alpha water value

);
}

VelocityField_Inlet
{
field U;
expression "Uw_inlet";
keepPatches false; //keep the boundary conditions that were set before
patchName "inlet";
variables
(
"a=0.05;"
"h=0.5;"
"omega=1.0472;"
"k=0.477406;"
"tshift=-pi/2;"
"gg=vector(0,0,-9.81);"
"eta_inlet=a*cos(omega*(time()+tshift));"
"thres=0.009;" //threshold value depends on the mesh dimentions
"DZmin=min((eta_inlet-pos().z),0.5*thres);"
"DZmax=max(DZmin,-0.5*thres);"
"aw_inlet=(DZmax+0.5*thres)/thres;" //alpha water value
"Uwx_in=aw_inlet*(a*(mag(gg)/omega)*k*(cosh((h+pos().z)*k)/cosh(h*k))*(cos(-(omega*(time()+tshift)))));"
"Uwy_in=0;"
"Uwz_in=aw_inlet*(a*(mag(gg)/omega)*k*(sinh((h+pos().z)*k)/cosh(h*k))*(sin(-(omega*(time()+tshift)))));"
"Uw_inlet=vector(Uwx_in, Uwy_in, Uwz_in);"

);
}

VelocityField
{
field U;
expression "Uw";
keepPatches true; //keep the boundary conditions that were set before
variables
(
"a=0.05;"
"h=0.5;"//0.5
"omega=1.0472;"
"k=0.477406;"
"tshift=-pi/2;"
"gg=vector(0,0,-9.81);"
"eta=a*cos(omega*(time()+tshift)-k*pos().x);"
"thres=0.009;" //threshold value depends on the mesh dimentions
"DZmin=min((eta-pos().z),0.5*thres);"
"DZmax=max(DZmin,-0.5*thres);"
"aw=(DZmax+0.5*thres)/thres;" //alpha water value
"Uwx=aw*(a*(mag(gg)/omega)*k*(cosh((h+pos().z)*k)/cosh(h*k))*(cos(k*pos().x-(omega*(time()+tshift)))));"
"Uwy=0;"
"Uwz=aw*(a*(mag(gg)/omega)*k*(sinh((h+pos().z)*k)/cosh(h*k))*(sin(k*pos().x-(omega*(time()+tshift)))));"
"Uw=vector(Uwx, Uwy, Uwz);"

);
}

);


vsammartano February 9, 2017 12:45

funkySetFieldDict and variables call
 
Dear Bernhard,
I am so sorry for the piece of code I sent you ... that was so messed-up! :(
The code is working, but i would like to use a list of variables included in the "initialConditions" instead of repeat the same variables in the fields included inside the expressions brackets.
I have attached the code below.
Thank you again.
Vincenzo

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  4.x                                  |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object funkySetFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "initialConditions"
defaultFieldValues
        (
                volScalarFieldValue alpha.water 0;
                volVectorFieldValue U (0,0,0);
                volScalarFieldValue p_rgh 0;
        );

expressions
(
       

        AlphaWater
        {
                field alpha.water;
                expression "aw";
                keepPatches true; //keep the boundary conditions that were set before
        variables
                (
                "a=0.05;"
                "omega=1.0472;"
                "k=0.477406;"
                "eta=a*cos(omega*time()-k*pos().x);"
                "thres=0.003;" //threshold value depends on the mesh ... improvement here
                "DZmin=min((eta-pos().z),0.5*thres);"       
                "DZmax=max(DZmin,-0.5*thres);"
                "aw=(DZmax+0.5*thres)/thres;" //alpha water value
                );
        }
       
        VelocityField
        {
                field U;
                expression "Uw";
                keepPatches true; //keep the boundary conditions that were set before
                //patchName "inlet";
        variables
                (
                "a=0.05;"
                "h=0.5;"
                "omega=1.0472;"
                "k=0.477406;"
                "gg=vector(0,0,-9.81);"
                "eta=a*cos(omega*time()-k*pos().x);"
                "thres=0.003;" //threshold value depends on the mesh dimentions
                "DZmin=min((eta-pos().z),0.5*thres);"
                "DZmax=max(DZmin,-0.5*thres);"
                "aw=(DZmax+0.5*thres)/thres;" //alpha water value
                "Uwx=aw*(a*(mag(gg)/omega)*k*(cosh((h+pos().z)*k)/cosh(h*k))*cos(k*pos().x-omega*time()));"
                "Uwy=0;"
                "Uwz=aw*(a*(mag(gg)/omega)*k*(sinh((h+pos().z)*k)/cosh(h*k))*sin(k*pos().x-omega*time()));"
                "Uw=vector(Uwx, Uwy, Uwz);"
                );
        }


        PressureField
        {
                field p_rgh;
                expression "pw_rgh";
                keepPatches true; //keep the boundary conditions that were set before
                //patchName "inlet";
        variables
                (
                "a=0.05;"
                "h=0.5;"
                "omega=1.0472;"
                "k=0.477406;"
                "gg=vector(0,0,-9.81);"
                "ro=1000;"
                "eta=a*cos(omega*time()-k*pos().x);"
                "thres=0.003;" //threshold value depends on the mesh dimentions
                "DZmin=min((eta-pos().z),0.5*thres);"
                "DZmax=max(DZmin,-0.5*thres);"
                "aw=(DZmax+0.5*thres)/thres;" //alpha water value
                "pw=ro*mag(gg)*((eta*cosh((h+pos().z)*k)/cosh(h*k))-pos().z);" //pressure
                "pw_rgh=aw*(pw-ro*mag(gg)*(-h));"  //pressure p_rgh = p-ro*g*z
                );
        }

);


Quote:

Originally Posted by gschaider (Post 629543)
This is what source code looks like with the code-environment:
Code:

dict {
      val 1;
      sub {
          a 1;
          b 2;
      }
}

And this way without:

dict {
val 1;
sub {
a 1;
b 2;
}
}

The first form makes it easy for me to see what is going on. The second form I have to count brackets to see what the problem might be. It also makes it hard for me to see where the file ends and the text starts.

That said: I didn't have a closer look at your post because it is unreadable



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