CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [swak4Foam] Using groovyBC and storedVariables to set periodic mooving walls (https://www.cfd-online.com/Forums/openfoam-community-contributions/180975-using-groovybc-storedvariables-set-periodic-mooving-walls.html)

Tanmay95 December 4, 2016 20:30

Using groovyBC and storedVariables to set periodic mooving walls
 
Hello,

I am simulating a 2D cavity flow using icoFoam and I want my top and bottom walls to move periodically.
Utop=U and Ubottom=0 for nT< t <(n+0.5)T
Utop=0 and Ubottom=U for (n+0.5)T< t <(n+1)T

Basically T is period and n is period number. During each period for half the period top wall moves with constant velocity and then for remaining half period bottom wall moves.

What I used is


topMovingWall
{
type groovyBC;

storedVariables
(
{
name n;
initialValue "0";
}
);
variables
(
"tperiod=20;"
"n = (time() % tperiod == 0) ? n+1 : n;"
);
valueExpression "vector((time()>n*tperiod && time()<(n+0.5)*tperiod)?0.01:0,0,0)";
}

bottomMovingWall
{
type groovyBC;

storedVariables
(
{
name n;
initialValue "0";
}
);
variables
(
"tperiod=20;"
"n = (time() % tperiod == 0) ? n+1 : n;"
);
valueExpression "vector((time()>(n+0.5)*tperiod && time()<(n+1)*tperiod)?0.01:0,0,0)";
}


For n=0 it works and I get wall motions but my n is not incrementing when a period of T (denoted by tperiod) gets over.

Tanmay95 March 17, 2017 00:46

In case anyone is interested, following worked
 
dimensions [0 1 -1 0 0 0 0];

internalField uniform (0 0 0);

boundaryField
{
topMovingWall
{
type groovyBC;
valueExpression "vector((time()>n*tperiod && time()<(n+0.5)*tperiod)?0.01:0,0,0)";
value uniform (0 0 0);
storedVariables
(
{
name n;
initialValue "0";
}
);
variables
(
"tperiod=20;"
"n=(time()>n*tperiod && time()<(n+1)*tperiod)?n:n+1;"
);

}

bottomMovingWall
{
type groovyBC;
valueExpression "vector((time()>(n+0.5)*tperiod && time()<(n+1)*tperiod)?-0.01:0,0,0)";
value uniform (0 0 0);
storedVariables
(
{
name n;
initialValue "0";
}
);
variables
(
"tperiod=20;"
"n=(time()>n*tperiod && time()<(n+1)*tperiod)?n:n+1;"
);

}

fixWall
{
type fixedValue;
value uniform (0 0 0);
}

frontAndBack
{
type empty;
}
}


All times are GMT -4. The time now is 23:38.