CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   funkySetBoundaryFields and matematical function (http://www.cfd-online.com/Forums/openfoam/114344-funkysetboundaryfields-matematical-function.html)

alessio.nz March 9, 2013 13:38

funkySetBoundaryFields and matematical function
 
1 Attachment(s)
Hello, I am using the funkySetBoundaryFields from the swak4foam and I found it very useful for setting up the BC using a mathematical function.

I tried to use the formula for a parabolic inlet for velocity in the funkySetBoundaryDict file and it works:

--------

velocities
{
field U;
expressions
(
{
target value;
patchName inlet;
variables
(
"Umax=1.0;"
"xCoord=pos().x;"
"xCoordMax=max(xCoord);"

);
expression "(1-pow(xCoord/xCoordMax,2)) * Umax * vector(0,1,0)";
}
);
}

----------

After solving this I want to include the same BC using also a time dependent value in order to see how this boundary condition (and in particular the U inlet of the simulation) changes as a function of time.

The function erf (t) introduced here, gives me a behavior going from 0 to 1 with the time evolution and it will be multiplied by the previous equation.

Unfortunately the expression that I introduced does not work. I would expect for the first times a velocity equal to 0 but, after certain time (in this case on the order of 0.1 seconds ) a change from 0 values of this ERF function till a 1 value (which means that the total velocity inlet goes from 0 to the parabolic profile as mentioned before). Instead of this expectation, the inlet remain 0 always and there is no flow evolution. I have also plotted this ERF function with matlab and it gives this behaviour (see attachment).

The expression is:((1+(erf((time()-0.1)/0.025)))/2)

I am wondering how the tool uses the time() variable and if really uses the erf(t) correctly.

Is anyone able to help me in this?

The script is written below. Many thanks. alex

velocities
{
field U;
expressions
(
{
target value;
patchName inlet;
variables
(
"Umax=1.0;"
"xCoord=pos().x;"
"xCoordMax=max(xCoord);"
"ERF=((1+(erf((time()-0.1)/0.025)))/2);"
);
expression "(1-pow(xCoord/xCoordMax,2)) * Umax * vector(0,1,0)* ERF";
}
);
}

gschaider March 9, 2013 15:46

Quote:

Originally Posted by alessio.nz (Post 412761)
Hello, I am using the funkySetBoundaryFields from the swak4foam and I found it very useful for setting up the BC using a mathematical function.

I tried to use the formula for a parabolic inlet for velocity in the funkySetBoundaryDict file and it works:

--------

velocities
{
field U;
expressions
(
{
target value;
patchName inlet;
variables
(
"Umax=1.0;"
"xCoord=pos().x;"
"xCoordMax=max(xCoord);"

);
expression "(1-pow(xCoord/xCoordMax,2)) * Umax * vector(0,1,0)";
}
);
}

----------

After solving this I want to include the same BC using also a time dependent value in order to see how this boundary condition (and in particular the U inlet of the simulation) changes as a function of time.

The function erf (t) introduced here, gives me a behavior going from 0 to 1 with the time evolution and it will be multiplied by the previous equation.

Unfortunately the expression that I introduced does not work. I would expect for the first times a velocity equal to 0 but, after certain time (in this case on the order of 0.1 seconds ) a change from 0 values of this ERF function till a 1 value (which means that the total velocity inlet goes from 0 to the parabolic profile as mentioned before). Instead of this expectation, the inlet remain 0 always and there is no flow evolution. I have also plotted this ERF function with matlab and it gives this behaviour (see attachment).

The expression is:((1+(erf((time()-0.1)/0.025)))/2)

I am wondering how the tool uses the time() variable and if really uses the erf(t) correctly.

Is anyone able to help me in this?

The script is written below. Many thanks. alex

velocities
{
field U;
expressions
(
{
target value;
patchName inlet;
variables
(
"Umax=1.0;"
"xCoord=pos().x;"
"xCoordMax=max(xCoord);"
"ERF=((1+(erf((time()-0.1)/0.025)))/2);"
);
expression "(1-pow(xCoord/xCoordMax,2)) * Umax * vector(0,1,0)* ERF";
}
);
}

OK. First: you checked the value of the BC how? Looked at the file or displayed it in paraview? Because what people sometimes do is only get the internalField into Paraview which of course is completely untouched by the BC (instead tick that away and tick at the inlet patch)

Second: the final purpose of this is to have a inlet boundary condition that "switches" on in a smooth wayduring a simulation, right? FSBF is only good for static BCs. What I usually do is set up the boundary as a groovyBC and then to check that I coded it correctly run the replayTranisientBC (comes with swak4Foam) on the case. This loads a set of fields (user definable) into memory and then "only" does the timestepping, update of the boundary conditions on these fields and writing of the fields at the usual times. As there is no solving of equations involved this only needs a fraction of the time the regular solver needs (seconds instead of hours) nad in the end you see whether the BC behaves the way you wanted it to (this of course assumes that the BC does not depend on the rest of the solution).

I haven't used the erf myself, just implemented the call to it so I don't think the error is there. Where I CAN imagine a bug (although I don't think so) is the way "time()" is treated in FSBF. Could you try the following: replace in your expression "time()" with 0.1 (or a later time) and see if you get the expected behaviour

alessio.nz March 11, 2013 12:13

Thank you Mr Gschaider for your answer!

I tried with the first step, instead of using the time "time()", putting a value of -0.05 to the erf, which gives me the value : ((1+(erf((-0.05)/0.025)))/2 = 0.0023 and, in the post processing on paraview after running the simulation, the value of U is actually in that order of magnitude (Umagnitude = 0.0023383 m/s). So the erf function works, but it seems that the time() is not the proper one. Could I kindly ask you, if you know, how would you set the groovyBC or the replayTransientBC in the OF? Are there tutorials about this feature so I can try to set myself?

Best regards,

Alex

gschaider March 11, 2013 17:47

Quote:

Originally Posted by alessio.nz (Post 413159)
Thank you Mr Gschaider for your answer!

I tried with the first step, instead of using the time "time()", putting a value of -0.05 to the erf, which gives me the value : ((1+(erf((-0.05)/0.025)))/2 = 0.0023 and, in the post processing on paraview after running the simulation, the value of U is actually in that order of magnitude (Umagnitude = 0.0023383 m/s). So the erf function works, but it seems that the time() is not the proper one. Could I kindly ask you, if you know, how would you set the groovyBC or the replayTransientBC in the OF? Are there tutorials about this feature so I can try to set myself?

Well. If you know how to use funkySetBoundaryField and how to modify boundary conditions then you're halfway there: http://openfoamwiki.net/index.php/Contrib_groovyBC should provide you with the missing pieces (most of the info there is still relevant). Also have a looked at the presentations linked from the swak-page and the Examples/groovyBC in the swak-distro

alessio.nz March 12, 2013 03:28

Thanks again:

I found on the contribution (see this link http://www.cfd-online.com/Forums/ope...-groovybc.html) the following script which, for my case, becomes:

inlet
{

type groovyBC;
variables
"Umax=1.0;c=vector(0,0,0);n=vector(1,0,0);p=po s()-c;r=mag(p)+1.0e-10;R=max(r);ERF=((1+((erf((time()-0.1)/0.025)))/2);uprof=(1-pow(r/R,2))*Umax*ERF*normal();";
valueExpression "(-uprof)";
timelines();
value uniform (0 1 0);
}

Unfortunately :confused: during the simulation it gives me the following error which I don't really understand:

diagonal: Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
PIMPLE: iteration 1
swak4Foam: Allocating new repository for sampledGlobalVariables


--> FOAM FATAL ERROR:
The expected return type scalar is different from the stored result type "vector"



From function tmp<Field<Type> > ExpressionResult::getResult()
in file lnInclude/ExpressionResultI.H at line 124.

FOAM exiting

gschaider March 12, 2013 11:23

Quote:

Originally Posted by alessio.nz (Post 413319)
Thanks again:

I found on the contribution (see this link http://www.cfd-online.com/Forums/ope...-groovybc.html) the following script which, for my case, becomes:

inlet
{

type groovyBC;
variables
"Umax=1.0;c=vector(0,0,0);n=vector(1,0,0);p=po s()-c;r=mag(p)+1.0e-10;R=max(r);ERF=((1+((erf((time()-0.1)/0.025)))/2);uprof=(1-pow(r/R,2))*Umax*ERF*normal();";
valueExpression "(-uprof)";
timelines();
value uniform (0 1 0);
}

Unfortunately :confused: during the simulation it gives me the following error which I don't really understand:

diagonal: Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
PIMPLE: iteration 1
swak4Foam: Allocating new repository for sampledGlobalVariables


--> FOAM FATAL ERROR:
The expected return type scalar is different from the stored result type "vector"



From function tmp<Field<Type> > ExpressionResult::getResult()
in file lnInclude/ExpressionResultI.H at line 124.

FOAM exiting

My guess: the variable "p". swak4Foam seems to be a bit inconsistent here. It finds pressure-p which is scalar and uses that info to go on. Then it asks for values and gets a vector. Which confuses it. Try renaming the variable p to something more unique ("myP" for instance)

alessio.nz March 13, 2013 06:50

Your guess was right! Now it runs, I hope it will recognize the time() properly :) !!

thank you for your support! alex

gschaider March 13, 2013 09:32

Quote:

Originally Posted by alessio.nz (Post 413637)
Your guess was right! Now it runs, I hope it will recognize the time() properly :) !!

groovyBC? Yeah. That should know about "time()"

Behzad Taghilou September 6, 2016 05:04

Quote:

Originally Posted by gschaider (Post 412789)
OK. First: you checked the value of the BC how? Looked at the file or displayed it in paraview? Because what people sometimes do is only get the internalField into Paraview which of course is completely untouched by the BC (instead tick that away and tick at the inlet patch)

Second: the final purpose of this is to have a inlet boundary condition that "switches" on in a smooth wayduring a simulation, right? FSBF is only good for static BCs. What I usually do is set up the boundary as a groovyBC and then to check that I coded it correctly run the replayTranisientBC (comes with swak4Foam) on the case. This loads a set of fields (user definable) into memory and then "only" does the timestepping, update of the boundary conditions on these fields and writing of the fields at the usual times. As there is no solving of equations involved this only needs a fraction of the time the regular solver needs (seconds instead of hours) nad in the end you see whether the BC behaves the way you wanted it to (this of course assumes that the BC does not depend on the rest of the solution).

I haven't used the erf myself, just implemented the call to it so I don't think the error is there. Where I CAN imagine a bug (although I don't think so) is the way "time()" is treated in FSBF. Could you try the following: replace in your expression "time()" with 0.1 (or a later time) and see if you get the expected behaviour

Hello Mr. Gschaider
I used a boundary condition in which various parameters would be defined. for example:

outlet
{
type totalPressure;
p0 uniform 0;
U U;
phi phi;
rho none;
psi none;
gamma 1;
value uniform 0;
}

but I want to put a time dependent boundary for "p0" parameter.
when I wrote groovyBC instead of totalPressure type, I could not get access the "p0" parameter.
How can I wrote time dependent function for "p0"?

thank you in advance.

Behzad Taghilou

gschaider September 6, 2016 06:37

Quote:

Originally Posted by Behzad Taghilou (Post 616741)
Hello Mr. Gschaider
I used a boundary condition in which various parameters would be defined. for example:

outlet
{
type totalPressure;
p0 uniform 0;
U U;
phi phi;
rho none;
psi none;
gamma 1;
value uniform 0;
}

but I want to put a time dependent boundary for "p0" parameter.
when I wrote groovyBC instead of totalPressure type, I could not get access the "p0" parameter.
How can I wrote time dependent function for "p0"?

thank you in advance.

Behzad Taghilou

There comes a library groovyStandardBCs in swak4foam which has a boundary condition groovyTotalPressure. Should do what you want

Behzad Taghilou September 6, 2016 14:27

Quote:

Originally Posted by gschaider (Post 616761)
There comes a library groovyStandardBCs in swak4foam which has a boundary condition groovyTotalPressure. Should do what you want

thank you Mr. Gschaider for replying.
I wrote the groovyTotalPressure instead of totalPressure and it was OK.
another BC is this:

wall
{
type tractionDisplacement;
traction uniform ( 0 0 0 );
pressure uniform 0;
value uniform (0 0 0);
}

And I need a time dependent function for pressure.
what should have been done for this boundary condition?

Behzad Taghilou September 6, 2016 17:03

groovyStandardBC library
 
I have figured out how to add a new groovyBC to the standard BCs library. I found this groovyTractionDisplacementBC and I thought to use it as a guideline.
Any help or advice is appreciated.

Thank you and best regards,

Behzad


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