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

funkySetBoundaryFields and matematical function

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   March 9, 2013, 13:38
Default funkySetBoundaryFields and matematical function
  #1
Member
 
alessio.nz's Avatar
 
Alex
Join Date: Apr 2010
Posts: 48
Rep Power: 7
alessio.nz is on a distinguished road
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";
}
);
}
Attached Images
File Type: jpg figure.jpg (11.5 KB, 10 views)
alessio.nz is offline   Reply With Quote

Old   March 9, 2013, 15:46
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 alessio.nz View Post
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
__________________
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 11, 2013, 12:13
Default
  #3
Member
 
alessio.nz's Avatar
 
Alex
Join Date: Apr 2010
Posts: 48
Rep Power: 7
alessio.nz is on a distinguished road
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
alessio.nz is offline   Reply With Quote

Old   March 11, 2013, 17:47
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 alessio.nz View Post
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
__________________
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 12, 2013, 03:28
Default
  #5
Member
 
alessio.nz's Avatar
 
Alex
Join Date: Apr 2010
Posts: 48
Rep Power: 7
alessio.nz is on a distinguished road
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 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
alessio.nz is offline   Reply With Quote

Old   March 12, 2013, 11:23
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 alessio.nz View Post
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 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)
__________________
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 13, 2013, 06:50
Default
  #7
Member
 
alessio.nz's Avatar
 
Alex
Join Date: Apr 2010
Posts: 48
Rep Power: 7
alessio.nz is on a distinguished road
Your guess was right! Now it runs, I hope it will recognize the time() properly !!

thank you for your support! alex
alessio.nz is offline   Reply With Quote

Old   March 13, 2013, 09:32
Default
  #8
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 alessio.nz View Post
Your guess was right! Now it runs, I hope it will recognize the time() properly !!
groovyBC? Yeah. That should know about "time()"
__________________
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

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



All times are GMT -4. The time now is 00:42.