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 Tree1Likes
  • 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
anaiman is offline   Reply With Quote

Old   November 29, 2011, 19:01
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,915
Rep Power: 40
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,915
Rep Power: 40
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: 3
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, 16 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,915
Rep Power: 40
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

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 06:18.