CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (http://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Defining constants for funkySetFields and groovyBC (http://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)


All times are GMT -4. The time now is 22:58.