CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Pre-Processing

Defining constants for funkySetFields and groovyBC

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By anaiman
  • 1 Post By gschaider
  • 1 Post By gschaider

Reply
 
LinkBack Thread Tools Display Modes
Old   November 29, 2011, 16:03
Default Defining constants for funkySetFields and groovyBC
  #1
New Member
 
Alex Naiman
Join Date: Nov 2011
Location: Menlo Park, CA
Posts: 2
Rep Power: 0
anaiman is on a distinguished road
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
vsammartano likes this.
anaiman is offline   Reply With Quote

Old   November 29, 2011, 19:01
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,989
Rep Power: 42
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by anaiman View Post
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)
Bernhard likes this.
gschaider is offline   Reply With Quote

Old   November 30, 2011, 13:29
Default
  #3
New Member
 
Alex Naiman
Join Date: Nov 2011
Location: Menlo Park, CA
Posts: 2
Rep Power: 0
anaiman is on a distinguished road
Quote:
Originally Posted by gschaider View Post
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!
anaiman is offline   Reply With Quote

Old   November 30, 2011, 14:32
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,989
Rep Power: 42
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by anaiman View Post
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 View Post
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
gschaider is offline   Reply With Quote

Old   October 3, 2013, 12:46
Default
  #5
New Member
 
sasan
Join Date: Sep 2013
Posts: 28
Rep Power: 5
Sasy is on a distinguished road
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
Attached Images
File Type: jpg a.JPG (10.6 KB, 37 views)
Sasy is offline   Reply With Quote

Old   October 3, 2013, 13:01
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,989
Rep Power: 42
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Sasy View Post
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)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   December 1, 2016, 06:34
Angry funckySetFieldsDict and #include "file_with_variables"
  #7
New Member
 
vsammartano's Avatar
 
Vincenzo
Join Date: Oct 2012
Location: Palermo (IT)
Posts: 15
Rep Power: 6
vsammartano is on a distinguished road
Send a message via Skype™ to vsammartano
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
vsammartano is offline   Reply With Quote

Old   December 4, 2016, 06:37
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,989
Rep Power: 42
gschaider will become famous soon enoughgschaider will become famous soon enough
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 View Post
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 likes this.
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   December 5, 2016, 15:14
Default
  #9
New Member
 
vsammartano's Avatar
 
Vincenzo
Join Date: Oct 2012
Location: Palermo (IT)
Posts: 15
Rep Power: 6
vsammartano is on a distinguished road
Send a message via Skype™ to vsammartano
Quote:
Originally Posted by gschaider View Post
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:perator>>(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
vsammartano is offline   Reply With Quote

Old   December 8, 2016, 17:53
Default
  #10
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,989
Rep Power: 42
gschaider will become famous soon enoughgschaider will become famous soon enough
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 View Post
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:perator>>(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
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   December 9, 2016, 05:18
Default #include <file> doe not work
  #11
New Member
 
vsammartano's Avatar
 
Vincenzo
Join Date: Oct 2012
Location: Palermo (IT)
Posts: 15
Rep Power: 6
vsammartano is on a distinguished road
Send a message via Skype™ to vsammartano
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 is offline   Reply With Quote

Old   December 13, 2016, 18:34
Default
  #12
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,989
Rep Power: 42
gschaider will become famous soon enoughgschaider will become famous soon enough
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 View Post
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);"

);
}

);
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   February 9, 2017, 12:45
Default funkySetFieldDict and variables call
  #13
New Member
 
vsammartano's Avatar
 
Vincenzo
Join Date: Oct 2012
Location: Palermo (IT)
Posts: 15
Rep Power: 6
vsammartano is on a distinguished road
Send a message via Skype™ to vsammartano
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 View Post
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
vsammartano is offline   Reply With Quote

Reply

Tags
funkysetfields, groovybc

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
groovyBC and funkySetFields married and got a kid named swak4Foam gschaider OpenFOAM 164 January 13, 2015 03:52
GroovyBC problem in the defining inlet velocity iampolaris OpenFOAM Running, Solving & CFD 7 October 18, 2014 09:25
GroovyBC for 2D wave flume! Hisham OpenFOAM Running, Solving & CFD 13 January 20, 2012 06:04
groovyBC and Eqn.setReference() benk OpenFOAM 3 June 2, 2011 08:49
Wall heat transfer using groovyBC (XiFoam solver) usergk OpenFOAM 7 February 4, 2011 14:36


All times are GMT -4. The time now is 15:44.