CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   "if" function in boundary condition (https://www.cfd-online.com/Forums/openfoam-programming-development/151231-if-function-boundary-condition.html)

Supersale April 7, 2015 04:13

"if" function in boundary condition
 
Hello all,

i want to simulate a pressure-boundary condition consisting of two parts depending on time. basically, the first part (from t=0 till t=t1)is changing the pressure from 0 to the maximum and the second part (t1<) is making this pressure harmonically change.
In MATLAB/octave it looks like this:

Code:


for i=1:length(t)
    if  t(i)<=t1
        p_cos(i)=pMax/2*(1+C_if*cos(2*pi*f1*t(i)));   
    else
        p_cos(i)=(p0*(1+(C1*cos(2*pi*f*t(i)-pi/2)+C1*cos(4*pi*f*t(i)+pi/2))));
    end   
end

but how can i do this in OpenFOAM?
All help apriciated!!

blacksquirrel April 7, 2015 05:23

Hi Supersale,

OpenFOAM can handle time-dependent boundaries, described here:
http://www.openfoam.org/version2.1.0...conditions.php

But regarding your function I would suggest using groovyBC from swak4Foam:
https://openfoamwiki.net/index.php/Contrib/groovyBC
http://www.cfd-online.com/Forums/ope...end-inlet.html

Regards
Squirrel

Supersale April 7, 2015 21:27

Hi!

thanks for the reply, it seems to work using groovyBC. I used this code:

Code:


inlet
  {
    type            groovyBC;
    variables "p0=437500;f=64000.0;pi=3.14159265358979323846264338327950288;t1=5.5e-06;f1=1/(2*t1);pMax=530000;C1=(pMax-p0)/(p0*(cos(2*pi*f*t1-pi/2)+cos(4*pi*f*t1+pi/2)));p0_if=pMax/2;Cif=-(pMax/p0_if-1)/(cos(2*pi*f1*t1+pi));";
    valueExpression "(time()<t1) ? pMax/2*(1+Cif*cos(2*pi*f1*time())) : p0*(1+C1*cos(2*pi*f*time()-pi/2)+C1*cos(4*pi*f*time()+pi/2))";
    value          uniform 0;
  }



All times are GMT -4. The time now is 11:04.