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

funkySetBoundaryFields - Manipulation of existing field

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 18, 2012, 05:47
Default funkySetBoundaryFields - Manipulation of existing field
  #1
New Member
 
Julian Hertel
Join Date: Dec 2011
Posts: 4
Rep Power: 15
jhertel is on a distinguished road
Hi everybody,

I would like to set a complex boundary condition at my Inlet (simple rectangular patch) with the funkySetBoundaryField utility. Instead of implementing an analytical expression depending on the spacial parameters pos().x and pos().y, I would like to manipulate an existing field.

Actually, the implemented velocity field at the Inlet should represent a complex flow field of a fan. I therefore interpolated experimental data over the whole inlet. There are, however, additional effects on the flow field caused by the fan blades I cant display by a simple interpolation. Thats why I wanted to run the funkySetBoundaryField utility over the interpolated velocity field at the inlet. According to the contrib description of the funkySetField utility on the wiki page it should be possible to manipulate existing fields:

"All the fields in the current time-step can be used. If the field is also the target field the old value is used. Then the field is written using the new value."

So, does anybody know how to call by an "OldField value" within an expression? Such as pos().x is the syntax for the x position of the cell center.

Thanks!
jhertel is offline   Reply With Quote

Old   January 23, 2012, 12:29
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by jhertel View Post
Hi everybody,

I would like to set a complex boundary condition at my Inlet (simple rectangular patch) with the funkySetBoundaryField utility. Instead of implementing an analytical expression depending on the spacial parameters pos().x and pos().y, I would like to manipulate an existing field.

Actually, the implemented velocity field at the Inlet should represent a complex flow field of a fan. I therefore interpolated experimental data over the whole inlet. There are, however, additional effects on the flow field caused by the fan blades I cant display by a simple interpolation. Thats why I wanted to run the funkySetBoundaryField utility over the interpolated velocity field at the inlet. According to the contrib description of the funkySetField utility on the wiki page it should be possible to manipulate existing fields:

"All the fields in the current time-step can be used. If the field is also the target field the old value is used. Then the field is written using the new value."

So, does anybody know how to call by an "OldField value" within an expression? Such as pos().x is the syntax for the x position of the cell center.

Thanks!
Just specify the field name: "2*p" if applied to p gives you a field that is two times what it was before. Should work with funkySetBoundaryField also. But beware: there is no way to undo this (for the next evaluation the "new value" becomes the "old value")
gschaider is offline   Reply With Quote

Old   February 12, 2012, 08:39
Default
  #3
New Member
 
Julian Hertel
Join Date: Dec 2011
Posts: 4
Rep Power: 15
jhertel is on a distinguished road
Thank you very much for your reply gschaider. Using the variable p in an expression works fine but unfortunately it doesn´t work with the variable U. The error message is that I use a non scalar value when I use e.g. the following expressions: "mag(U)" or "2*U". Isn´t the mag() function supposed to work for vector values as well as scalar values? And anyway there shouldn´t be any problem with the expression "2*U", which is just a scalar multiplication. Any ideas?
jhertel is offline   Reply With Quote

Old   February 13, 2012, 06:58
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by jhertel View Post
Thank you very much for your reply gschaider. Using the variable p in an expression works fine but unfortunately it doesn´t work with the variable U. The error message is that I use a non scalar value when I use e.g. the following expressions: "mag(U)" or "2*U". Isn´t the mag() function supposed to work for vector values as well as scalar values? And anyway there shouldn´t be any problem with the expression "2*U", which is just a scalar multiplication. Any ideas?
What kind of field are you trying to manipulate? A scalar field or a vector field?

"mag(U)" should evaluate to a scalar. "2*U" to a vector. Could you please post the funkySetBoundaryFieldDict (or whatever is the exact name)?
gschaider is offline   Reply With Quote

Old   February 14, 2012, 14:00
Default
  #5
New Member
 
Julian Hertel
Join Date: Dec 2011
Posts: 4
Rep Power: 15
jhertel is on a distinguished road
Quote:
Originally Posted by gschaider View Post
What kind of field are you trying to manipulate? A scalar field or a vector field?

"mag(U)" should evaluate to a scalar. "2*U" to a vector. Could you please post the funkySetBoundaryFieldDict (or whatever is the exact name)?
I´d like to manipulate the vectorfield U. Below the content of the funkySetBoundaryDict:

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

velocities
{
field U;
expressions
(

//NOT working
{
target value;
patchName INLET;
expression "2*U";
}

//Working
// {
// target value;
// patchName INLET;
// expression "pos().x>0.11 && pos().x<0.1583 ? vector(0.0,0.0,1.0) : vector(0.0,0.0,0.0)";
// }

);
}

ERROR MESSAGE:

--> FOAM FATAL ERROR:
No field of type scalar with the name "U" found
jhertel is offline   Reply With Quote

Old   February 14, 2012, 19:25
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by jhertel View Post
I´d like to manipulate the vectorfield U. Below the content of the funkySetBoundaryDict:

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

velocities
{
field U;
expressions
(

//NOT working
{
target value;
patchName INLET;
expression "2*U";
}

//Working
// {
// target value;
// patchName INLET;
// expression "pos().x>0.11 && pos().x<0.1583 ? vector(0.0,0.0,1.0) : vector(0.0,0.0,0.0)";
// }

);
}

ERROR MESSAGE:

--> FOAM FATAL ERROR:
No field of type scalar with the name "U" found
I can reproduce the problem but I'm not quite sure what is causing it. Could you open a Bug on the openfoam-extend-Mantis (this makes sure that I don't forget about it) and I'll look into it as soon as possible
gschaider is offline   Reply With Quote

Old   February 26, 2012, 14:44
Default Problem using funky . . .
  #7
Member
 
Mohammad Fereshtehpour
Join Date: Jul 2011
Location: Iran
Posts: 61
Rep Power: 15
MOHAMMAD67 is on a distinguished road
Send a message via Skype™ to MOHAMMAD67
Dear Bernard
Hi
I edit the funkysetboundaryfield to implement a simple velocity profile whatever I write it faces a parser error. could you please tell me what to do?
Here is its dictionary:

PHP Code:
velocities {
    
field U;
    
expressions
    
(
        {
            
target value;
            
patchName inlet;
            
variables "maxY=0.1;"//"Vmax=vector(1.5,0,0);";
            
expression "(pos().y<=maxY) ? vector(1,0,0)*(1.5/0.1*mag(pos().y)) : vector(0.004,0,0);";
        }
);

It faces the following error:


Quote:
Create time

--> FOAM Warning :
From function dlLibraryTable:pen(const fileName&, const bool)
in file db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C at line 96
could not load "libswakFunctionObjects.so"
Create mesh for time = 0

Time = 0


Part: velocities working on field U
Setting value on inlet the expression "(pos().y<=maxY) ? vector(1,0,0)*(1.5/0.1*mag(pos().y)) : vector(0.004,0,0);"


--> FOAM FATAL ERROR:
Parser Error at "1.75" :"invalid character"
"(pos().y<=maxY) ? vector(1,0,0)*(1.5/0.1*mag(pos().y)) : vector(0.004,0,0);"
" ^"

From function parsingValue
in file lnInclude/CommonValueExpressionDriverI.H at line 724.

FOAM exiting
MOHAMMAD67 is offline   Reply With Quote

Old   February 26, 2012, 18:24
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by MOHAMMAD67 View Post
Dear Bernard
Hi
I edit the funkysetboundaryfield to implement a simple velocity profile whatever I write it faces a parser error. could you please tell me what to do?
Here is its dictionary:

PHP Code:
velocities {
    
field U;
    
expressions
    
(
        {
            
target value;
            
patchName inlet;
            
variables "maxY=0.1;"//"Vmax=vector(1.5,0,0);";
            
expression "(pos().y<=maxY) ? vector(1,0,0)*(1.5/0.1*mag(pos().y)) : vector(0.004,0,0);";
        }
);

It faces the following error:
The semicolon in the end of expression is the problem. Semicolon is only needed for the variables. In all other expressions it gives an error
gschaider is offline   Reply With Quote

Old   February 28, 2012, 10:19
Default
  #9
New Member
 
Julian Hertel
Join Date: Dec 2011
Posts: 4
Rep Power: 15
jhertel is on a distinguished road
After the fix the expressions work totally fine now. Thanks a lot!!!
jhertel is offline   Reply With Quote

Old   September 24, 2012, 11:58
Default
  #10
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 17
xisto is on a distinguished road
Send a message via MSN to xisto
Hello Bernard

I'm using funkysetfields to initialize a field with 4 different conditional statements, imagine a cylinder with four quadrants:

Code:
magnetic_1o_quadrant
    {
        field B;
        expression "vector(-1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*sin(atan(pos().y/pos().x)),1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*cos(atan(pos().y/pos().x)),0)";
              condition "pos().z <= 0.12 && pos().x > 0 && pos().y >=0";
 
    }

    magnetic_2o_quadrant
    {
        field B;
        expression "vector(-1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*sin(atan(pos().y/pos().x)+pi),1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*cos(atan(pos().y/pos().x)+pi),0)";
              condition "pos().z <= 0.12 && pos().x <= 0 && pos().y >0";
 
    }

    magnetic_3o_quadrant
    {
        field B;
        expression "vector(-1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*sin(atan(pos().y/pos().x)-pi),1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*cos(atan(pos().y/pos().x)-pi),0)";
              condition "pos().z <= 0.12 && pos().x < 0 && pos().y <0";
 
    }

    magnetic_4o_quadrant
    {
        field B;
        expression "vector(-1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*sin(atan(pos().y/pos().x)+2*pi),1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*cos(atan(pos().y/pos().x)+2*pi),0)";
              condition "pos().z <= 0.12 && pos().x > 0 && pos().y < 0";
 
    }
I want to do the same for my inlet but I can only define a condition for a single quadrant.

Code:
        {
            target value;
            patchName  inlet;
expression "(pos().z <= 0.12 && pos().x > 0 && pos().y >=0) ? vector(-1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*sin(atan(pos().y/pos().x)),1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*cos(atan(pos().y/pos().x)),0): vector (0,0,0)";//1st quadrant

        }
It is not possible to use your application to slip the inlet in four different zones?

Thanks,

Carlos
xisto is offline   Reply With Quote

Old   September 24, 2012, 14:19
Default
  #11
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by xisto View Post
Hello Bernard

I'm using funkysetfields to initialize a field with 4 different conditional statements, imagine a cylinder with four quadrants:

Code:
<snipped>
I want to do the same for my inlet but I can only define a condition for a single quadrant.

Code:
        {
            target value;
            patchName  inlet;
expression "(pos().z <= 0.12 && pos().x > 0 && pos().y >=0) ? vector(-1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*sin(atan(pos().y/pos().x)),1.069/sqrt(pos().x*pos().x+pos().y*pos().y)*cos(atan(pos().y/pos().x)),0): vector (0,0,0)";//1st quadrant

        }
It is not possible to use your application to slip the inlet in four different zones?
I think we're missing a bit of context here: the second example is for funkySetBoundaryFields, right?

Your problem is that there is no conditions-entry. I didn't add this as it would add some subtle problems if the entry is not currently present. There are two solutions I could think of. One would be a monster expression for all four quadrants. This is a sketch:

"pos().x>0 ? (pos().y>0 ? v1 :v2) : (pos().y>0 ? v3 : v4)"

(maybe variables can ease the pain here)

The other possibility would be a sequence of expressions where you use the value of the field (but this would only work for the value-entry):

"pos().x>0 && pos().y>0 ? v1 : vector(0,0,0)"
"pos().x>0 && pos().y<=0 ? v2 : U"
"pos().x<0 && pos().y>0 ? v3 : U"
"pos().x<0 && pos().y<=0 ? v4 : U"

But I'm not sure whether the field would have to be written to disc for this to work (or whether the cache-command-line-option is needed)
__________________
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   September 24, 2012, 15:42
Default
  #12
Member
 
Carlos Xisto
Join Date: Nov 2009
Location: Covilhã, Portugal
Posts: 53
Rep Power: 17
xisto is on a distinguished road
Send a message via MSN to xisto
Sorry Bernard, yes the second one is for funkysetboudary.

Thank you very much for your help.

Carlos
xisto is offline   Reply With Quote

Old   July 25, 2013, 08:47
Default Hello,
  #13
New Member
 
Federica Farisco
Join Date: Jul 2013
Posts: 2
Rep Power: 0
FedericaF is on a distinguished road
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.7.1 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

velocityswirl {
 field U;
   expressions
   (
       {    
            target value;
            patchName inlet;
                       
            variables       "rpm=1000.0;Un=10;c=sum(pos()*mag(Sf()))/sum(mag(Sf()));n=sum(normal())/mag(sum(normal()));n=sum(normal())/mag(sum(normal()));p=pos()-c;r=mag(pos()-vector(0,0,1))+1.0e-10;R=max(r);xt=vector(0,n.z,-n.y);xT=xt/mag(xt);yt=vector(n.y*n.y+n.z*n.z,-n.x*n.y,-n.x*n.z);yT=yt/mag(yt);";
                   
                          expression "-Un*normal() + (rpm*pi/30)*(((pos()-c) & yT)*xT-((pos()-c) & xT)*yT)";
       }
);
}  


//!!! in "variables" do not leave any space between the definitions of two variables and in "espression" try to replace the name of few variables with their definitions !!!

//!!! c=sum(pos()*mag(Sf()))/sum(mag(Sf())) works just for full patches; for other cases you have to set it manually !!!

Last edited by FedericaF; July 25, 2013 at 09:03. Reason: I used funkySetBoundary to generate a swirl flow in the inlet patch of a cylinder sector and it works.
FedericaF is offline   Reply With Quote

Old   July 25, 2013, 09:33
Default
  #14
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by FedericaF View Post
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.7.1 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

velocityswirl {
 field U;
   expressions
   (
       {    
            target value;
            patchName inlet;
                       
            variables       "rpm=1000.0;Un=10;c=sum(pos()*mag(Sf()))/sum(mag(Sf()));n=sum(normal())/mag(sum(normal()));n=sum(normal())/mag(sum(normal()));p=pos()-c;r=mag(pos()-vector(0,0,1))+1.0e-10;R=max(r);xt=vector(0,n.z,-n.y);xT=xt/mag(xt);yt=vector(n.y*n.y+n.z*n.z,-n.x*n.y,-n.x*n.z);yT=yt/mag(yt);";
                   
                          expression "-Un*normal() + (rpm*pi/30)*(((pos()-c) & yT)*xT-((pos()-c) & xT)*yT)";
       }
);
}  


//!!! in "variables" do not leave any space between the definitions of two variables and in "espression" try to replace the name of few variables with their definitions !!!

//!!! c=sum(pos()*mag(Sf()))/sum(mag(Sf())) works just for full patches; for other cases you have to set it manually !!!
I'm not quite clear on the purpose of this posting. If you wanted to demonstrate that it works and how it works then it would be nice if you could add it as an example at http://openfoamwiki.net/index.php/Co...Usage_examples
__________________
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   March 18, 2015, 08:58
Default setup funkySetBoundaryDict
  #15
New Member
 
sammasum
Join Date: May 2014
Posts: 5
Rep Power: 12
samice2008 is on a distinguished road
Hi,

I have modified the funkySetBoundaryDict for my problem and it is in the 'system' folder. but my program is not reading it.

I have groovyBC installed and that works fine. I wonder if I have to add something like 'libsgroovyBC.so' in the controlDict file for the funkySetBoundary.

Please suggest.

Many thanks
samice2008 is offline   Reply With Quote

Old   March 19, 2015, 09:42
Default define Neumann boundary in funkySetBoundaryFiled
  #16
New Member
 
sammasum
Join Date: May 2014
Posts: 5
Rep Power: 12
samice2008 is on a distinguished road
Hi,

How should I set up Neumann boundary condition using funkySetBounaryField? It seems like taking only Dirichlet boundary.

Thanks
samice2008 is offline   Reply With Quote

Old   May 18, 2020, 07:32
Default parabolic profile at inlet
  #17
Member
 
X
Join Date: Jan 2019
Posts: 63
Rep Power: 7
mcfdma is on a distinguished road
Quote:
Originally Posted by gschaider View Post
The semicolon in the end of expression is the problem. Semicolon is only needed for the variables. In all other expressions it gives an error
Hi Gschaider,

I am trying to use funkySetBoundaryFieldDict to create a parabolic inlet profile but I am getting a plug flow even after introducing FSBF.

Code:
velocities {
    field U;
    expressions
    (
        {
            target value;
            patchName inlet;
            variables "maxY=0.1e-3;";
            expression "(pos().y<=maxY) ? (vector(10,0,0)-((vector(10,0,0)*pos().y*pos().y)/maxY*maxY)) : vector(0,0,0)"; // umax(1-(r/R)^2
        }
);
}
Can you indicate what is it I am doing incorrectly? Thanks
mcfdma is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Phase Field modeling in OpenFOAM adona058 OpenFOAM Running, Solving & CFD 35 November 16, 2021 01:16
problems after decomposing for running alessio.nz OpenFOAM 7 March 5, 2021 05:49
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 07:20
Internal field manipulation on run-time Martin123 OpenFOAM Running, Solving & CFD 2 June 3, 2009 19:11
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51


All times are GMT -4. The time now is 13:08.