CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Any hints for user-defined BCs without using groovyBC/Swak4Foam? (https://www.cfd-online.com/Forums/openfoam/114998-any-hints-user-defined-bcs-without-using-groovybc-swak4foam.html)

 keepfit March 21, 2013 09:22

Any hints for user-defined BCs without using groovyBC/Swak4Foam?

Hi Foamers,

as I am not very clear about the idea/principle behind Swak4Foam/groovyBC, so I was wondering, is there some easy way to define some customized boundary conditions?

For instance: assuming inlet z coordinates is from z = 0 m to z = 4 m, I want to define an "alpha 1" source from z =0 to z =2 m at the inlet with a velocity 2 m/s at x-axis, while the pressure of outlet is fixed to 0.

Or more complex, I want the source velocity varying from: Vx = | 2*sin(t* 2*Pi/T) | (absolute value) , where T is the period.

So how to implement these BCs without using predefine Swak4Foam?

Any recommendations or hints will be highly appreciated.

 gschaider March 21, 2013 10:02

Quote:
 Originally Posted by keepfit (Post 415504) Hi Foamers, as I am not very clear about the idea/principle behind Swak4Foam/groovyBC, so I was wondering, is there some easy way to define some customized boundary conditions? For instance: assuming inlet z coordinates is from z = 0 m to z = 4 m, I want to define an "alpha 1" source from z =0 to z =2 m at the inlet with a velocity 2 m/s at x-axis, while the pressure of outlet is fixed to 0. Or more complex, I want the source velocity varying from: Vx = | 2*sin(t* 2*Pi/T) | (absolute value) , where T is the period. So how to implement these BCs without using predefine Swak4Foam? Any recommendations or hints will be highly appreciated.
There is the coded-BC (since OF 2.0) that allows you to include little C++-programs that calculate your BC. If you're fluent in C++ and know the OF-API well then you might be as fast writing your BC with it as you might be with groovyBC.

The expressions you mention would be "pos().z<2 ? 1 : 0" for alpha1 (if I understand your description correctly) and "2*sin(time()*2*pi/42)" (with a period 42) in groovyBC which I think (but I'm biased) is pretty straightforward. It's a bit more typing (but not exactly rocket-science) in coded/C++

 JR22 March 21, 2013 10:13

There is a tutorial by Hakan Nilsson from Chalmers University on how to implement your own boundary condition. You can find it here:
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD/implementBoundaryCondition.pdf

The tutorial seems to be current as of version 2.0.x.

 keepfit March 21, 2013 14:54

Quote:
 Originally Posted by JR22 (Post 415517) There is a tutorial by Hakan Nilsson from Chalmers University on how to implement your own boundary condition. You can find it here: http://www.tfd.chalmers.se/~hani/kurser/OS_CFD/implementBoundaryCondition.pdf The tutorial seems to be current as of version 2.0.x.
Quote:
 Originally Posted by gschaider (Post 415514) There is the coded-BC (since OF 2.0) that allows you to include little C++-programs that calculate your BC. If you're fluent in C++ and know the OF-API well then you might be as fast writing your BC with it as you might be with groovyBC. The expressions you mention would be "pos().z<2 ? 1 : 0" for alpha1 (if I understand your description correctly) and "2*sin(time()*2*pi/42)" (with a period 42) in groovyBC which I think (but I'm biased) is pretty straightforward. It's a bit more typing (but not exactly rocket-science) in coded/C++
thanks, it's great help.

What I want is to code a small fraction of C++ and make it usable for calculating the specified BCs. The difficult part is the OF-API that operates on the mesh properties like cell faces, coordinates and so on.

In this way I might be able to make a wave-generation BCs with varying the "alpha1" position according to the wave period T and other parameters.

 brocco October 29, 2013 10:10

1 Attachment(s)
Hi bernard!
Yesterday I started to have a look on swak and in particular the capabilities of groovybc,but in truth i've not understood a lot !(my brain after thesis is cooked!). I was interested to know how to produce the input speed with only conditions of geometric type as you suggested to keepfit for alpha1 but obviously for me is a velocity vector.
The idea is to produce sub-areas without having to change each time the mesh. For example on a square produce strips with input speed not anything. How could I do?
for example
1<x<3, 0<y<1, & 4<x<6, 2<y<3 ecc....

suggestions?

 gschaider October 29, 2013 12:41

Quote:
 Originally Posted by brocco (Post 459659) Hi bernard! Yesterday I started to have a look on swak and in particular the capabilities of groovybc,but in truth i've not understood a lot !(my brain after thesis is cooked!). I was interested to know how to produce the input speed with only conditions of geometric type as you suggested to keepfit for alpha1 but obviously for me is a velocity vector. The idea is to produce sub-areas without having to change each time the mesh. For example on a square produce strips with input speed not anything. How could I do? for example 1
That'd be with the ?: operator. For the two rectangles in you example (I guess your & was meant to be a | ) it should be something like

"((1<pos().x && pos().x<3 && 0<pos().y && pos().y<1) || (4<pos().x && pos().x<6 && 2<pos().y && pos().y<3)) ? 1 : 0"

would give the value 1 on these two rectangles and 0 elsewhere

 brocco October 30, 2013 06:56

thanks a lot!works perfectly...

caldaiasemplificata_ingresso_ariaprimaria
{
type groovyBCFixedValue;
valueExpression "((1<pos().x && pos().x<2 && -22<pos().y && pos().y<-21) || (3<pos().x && pos().x<4 && -28<pos().y && pos().y<-26)) ? vector(0,0,0.6) : vector(0,0,0)";

}

thanks again ;)

 All times are GMT -4. The time now is 17:01.