I recently had to help a friend setting up a case in OpenFOAM, where a ramp boundary condition for the velocity was required. Apparently OpenFOAM doesn’t offer this boudary condition, or at least it might seem so at a first impression.

Actually, OpenFOAM offers a very general way to specify unsteady boundary conditions called timeVaryingFixedValue, which can read a data set from a text file, interpolate them with respect to time and use them to generate the unsteady boundary condition.

I will show how to use this boundary condition with a simple example of a ramp for a velocity boundary condition. We want the velocity to ramp from the value U1 = (0, 1, 0) to the value U2 = (0, 3, 0) in the time interval between t1 = 0 and t2 = 5s. The velocity stays constant and equal to U2 for t > t2.

The ramp is simply defined by the extrema: the interpolation routine will automatically provide the correct values for the times contained inside the interval specified above. So, we need to create a text file with the following format:

```(
(t_0 value_0)
...
(t_n value_n)
)```

In our specific case, we create a file called ramp containing the following lines:

```(
(0.0 (0 1 0))
(5.0 (0 3 0))
)```

This file must be saved in the main directory of the simulation case, containing the 0, constant and system directories.

The boundary condition can be then specified in the velocity dictionary in the 0 directory as follows:

```rampInlet
{
type         timeVaryingUniformFixedValue;
fileName     "ramp";
outOfBounds  clamp;
}```

It is worth to pay attention to the option

` outOfBounds  clamp;`

which specifies that for all the values of t outside the interval provided by the data, the values of the dependent variable are clamped to the last available value. In our case this means that the condition U = U2 for t > t2 will be imposed.

The clamp option is also useful if we want to specify a ramp that begins for t > 0 or to change the final value of the dependent variable when the ramp is completed. Let’s consider the previous example again. Now we want the ramp to start at t = 2s and the velocity to go to zero at the end of the ramp. This can be simply accomplished by adding two lines to the dictionary, as follows:

```(
(1.99999 (0 0 0))
(2.0 (0 1 0))
(5.0 (0 3 0))
(5.00001 (0 0 0))
)```

The timeVaryingFixedValue boundary condition is of course suitable for all kinds of fields. For a scalar, the dictionary will contain couples of data (t, value), while for tensors each line will have a 9 components tuple.

Note: This procedure was tested on OpenFOAM 1.5.

Enjoy

Tagged with:

### 25 Responses to Unsteady boundary conditions in openFOAM

1. Andrea says:

Thanks a lot! This kind of tutorial really speed up my work, and of course help spreading openFoam.

Ciao!

2. Alexander Smirnovsky says:

Thank you for such useful article!
In addition I want to say about periodic boundary condition.
Simply, if you want to get a periodic profile at boundary, you should set “outOfBounds repeat” and enjoy!
(It exactly works on OpenFOAM 3.3-cvs)

3. Alexander Smirnovsky says:

P.S. Of course, I mean periodicity in time

4. Rodrigo says:

Thanks!

I wonder if this can be done to a total pressure BC.

• Alberto says:

I this so, if you modify the totalPressure BC to read the values of the total pressure, as done in the unsteady boundary.

5. Rodrigo says:

But how would you change it here, for example?
For me, it seems to work only when you specify field (uniform fixed) value.

type totalPressure;
p0 uniform 95200.0;
U U;
phi phi;
rho rho;
psi none;
gamma 1.4;
value uniform 95200.0;

• Alberto says:

Hi,

the existing unsteady boundary conditions works only for fixed values. What I meant is that you need to create a new BC which mixes the two. In other words, you need to code your unsteady total pressure boundary condition using the two existing one as starting point.

Best,
Alberto

6. [...] Check that out: http://albertopassalacqua.com/?p=69 [...]

7. [...] it in order to get a variable inlet velocity in the dahl case, following alberto's instructions (http://albertopassalacqua.com/?p=69), and I get the next error message: Starting time loop Time = 0.1 Courant Number mean: 0.0163852 [...]

8. Zubair says:

Thanks for this work
I am looking the possibility to give velocity Input as a vectors of values. is it possible ?
for example I have a circular input and I want more velocity in the bottom then the upper part of circular region .. how can I do that ??

• Alberto says:

Hello, if I understand your question correctly, you want to specify a non-uniform boundary condition. To do that there are many ways. You can either use one of the utilities provided by Bernhard on the OpenFoam Wiki (search for funkySetField and groovyBC), or write a small piece of code that initializes the patch corresponding to your boundary condition. If you have a simple initialization, life for example two values of the velocity, one for the top and the other for the bottom, you can simply initialize those values in the whole domain, and use the \$internalField macro (see OpenFOAM user’s guide for details and examples).

9. samar says:

I want to print out the boundary conditions. How can I do that ? What should I change in the solvers or utilities?

thanks

• Alberto says:

What do you mean with printing out the BC’s? They are stored in the file corresponding to the field in each time directory, and you can export data on the plane of each BC using paraview or sample.

Best,
Alberto

10. [...] I don't think it is the best solution to your problem, but might be the only one. Generate input, i.e. using your own code, and plug it inside input library: http://albertopassalacqua.com/?p=69 [...]

11. [...] Also, you can try to use the type timeVaryingUniformFixedValue;. Take a look here: http://albertopassalacqua.com/?p=69 [...]

12. [...] so the easiest way is described by alberto on his home page: http://albertopassalacqua.com/?p=69 or you could use the groovyBC: http://openfoamwiki.net/index.php/Contrib_groovyBC I personaly [...]

13. Greg says:

Great stuff Alberto! Except I’m having a bit of trouble running it. I get the following error message
when I run the solver (Piso or Pimple)… any idea what went wrong with my new inlet condition? The set-up was exactly as above.

–> FOAM FATAL IO ERROR:
keyword inlet is undefined in dictionary “/Users/greggivogue/Documents/openfoam-work/run/tutorials/incompressible/simpleFoam/VISN008Gregnu1point5Ramp/0/U::boundaryField”

file: /Users/greggivogue/Documents/openfoam-work/run/tutorials/incompressible/simpleFoam/VISN008Gregnu1point5Ramp/0/U::boundaryField from line 27 to line 45.

From function dictionary::subDict(const word& keyword) const
in file db/dictionary/dictionary.C at line 456.

FOAM exiting

• Alberto says:

You have a boundary condition called “inlet” in your mesh, which is not defined in your 0/U file.

14. Rasoul says:

Hi, i hope that you are well
how can one define a function for velocity at the inlet BC’s?

15. Rasoul says:

Hi alberto, tanx for your reply
another my question is how to define a function to move one boudary, for example:
i work on Vertical Axis Wind Turbine and i simulate it with fixed blade that rotated around shaft, now i wanna move each blades a round its axis under difinition function, would you tell me how do it?

(i used GGI for simulating it)

tnx alot
______
Rasoul

16. Amin says:

Thank you very much, it really helped me.

17. [...] yes you can. If you want more info about how use unsteady BC, have a look here http://albertopassalacqua.com/?p=69 (thanks to Alberto Passalacqua). best [...]

18. danfy says:

hello! I have a question.I do as you writed in the blog, but why is there the information “Cannot find ‘value’ entry on patch**(Actual type timeVaryingUniformFixedValue) Please add the ‘value’ entry to the write function of the user-defined boundary-condition ”

and below is my boudaryfield:

JINJILINGBRIDGE
{
type timeVaryingUniformFixedValue;
fileName “zetaBcJinjiling”;
outOfBounds clamp;
}

• Alberto says:

Hi Danfy,

as the name suggests, the timeVaryingUniformFixedValue is derived from the fixedValue BC, which requires a “value” entry. You have then to specify it, even though the specified value won’t be used.