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/)
-   -   funkySetBoundaryFields - Manipulation of existing field (https://www.cfd-online.com/Forums/openfoam-pre-processing/96280-funkysetboundaryfields-manipulation-existing-field.html)

jhertel January 18, 2012 04:47

funkySetBoundaryFields - Manipulation of existing field
 
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!

gschaider January 23, 2012 11:29

Quote:

Originally Posted by jhertel (Post 339877)
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")

jhertel February 12, 2012 07:39

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?

gschaider February 13, 2012 05:58

Quote:

Originally Posted by jhertel (Post 344001)
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)?

jhertel February 14, 2012 13:00

Quote:

Originally Posted by gschaider (Post 344114)
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

gschaider February 14, 2012 18:25

Quote:

Originally Posted by jhertel (Post 344409)
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

MOHAMMAD67 February 26, 2012 13:44

Problem using funky . . .
 
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::open(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

gschaider February 26, 2012 17:24

Quote:

Originally Posted by MOHAMMAD67 (Post 346356)
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

jhertel February 28, 2012 09:19

After the fix the expressions work totally fine now. Thanks a lot!!!

xisto September 24, 2012 10:58

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

gschaider September 24, 2012 13:19

Quote:

Originally Posted by xisto (Post 383348)
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)

xisto September 24, 2012 14:42

Sorry Bernard, yes the second one is for funkysetboudary.

Thank you very much for your help.

Carlos

FedericaF July 25, 2013 07:47

Hello,
 
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 !!!


gschaider July 25, 2013 08:33

Quote:

Originally Posted by FedericaF (Post 441919)
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

samice2008 March 18, 2015 07:58

setup funkySetBoundaryDict
 
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 March 19, 2015 08:42

define Neumann boundary in funkySetBoundaryFiled
 
Hi,

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

Thanks

mcfdma May 18, 2020 06:32

parabolic profile at inlet
 
Quote:

Originally Posted by gschaider (Post 346372)
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


All times are GMT -4. The time now is 07:54.