Unsteady boundary conditions in openFOAM 29

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:

  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 🙂

29 thoughts on “Unsteady boundary conditions in openFOAM

  • Alexander Smirnovsky

    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)

    • Alberto Post author

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

  • Rodrigo

    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 Post author


      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.


  • Zubair

    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 Post author

      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).

  • samar

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


    • Alberto Post author

      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.


  • Greg

    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.

    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

  • Rasoul

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

  • Rasoul

    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

  • danfy

    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:

    type timeVaryingUniformFixedValue;
    fileName “zetaBcJinjiling”;
    outOfBounds clamp;

    • Alberto Post author

      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.

  • Bjarke

    Hi Alberto.
    Thank you for your post. I am trying to set up a simulation where I have a combined wave and current situation. To save time I have made to wave+current boundary layer i 1D and saved on period. This I have used together with timeVaryingUniformFixedValue. However even though i have chosen outOfBounds repeat; my simulation continues with my last value instead of repeating the cycle

    • Alberto Post author

      Hi Bjarke,
      the implementation of this boundary condition significantly changed since I wrote the article, so I would need to know what version of OpenFOAM you are using.

    • Alberto Post author

      Hi Bjarke,
      I don’t remember exactly what version of OpenFOAM corresponds to the 1.6-ext realease, because the numbering of the two was messed up multiple times. However, if it was based on the official 2.1.x release (or following), the structure of the time-dependent boundary condition changed significantly. You can see it here http://www.openfoam.org/version2.1.0/boundary-conditions.php

      I hope this helps.

Comments are closed.