Alberto Passalacqua

Unsteady boundary conditions in openFOAM

Posted on | August 15, 2008 | 29 Comments

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 Responses to “Unsteady boundary conditions in openFOAM”

  1. Andrea
    February 11th, 2009 @ 5:04 pm

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


  2. Alexander Smirnovsky
    April 23rd, 2009 @ 12:00 pm

    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
    April 23rd, 2009 @ 12:15 pm

    P.S. Of course, I mean periodicity in time ;-)

  4. Rodrigo
    June 18th, 2009 @ 4:19 pm


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

  5. Alberto
    June 18th, 2009 @ 5:42 pm

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

  6. Rodrigo
    June 19th, 2009 @ 3:55 pm

    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;

  7. Alberto
    June 19th, 2009 @ 4:23 pm


    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.


  8. timeVaryingUniformFixedValue -- CFD Online Discussion Forums
    March 11th, 2010 @ 7:47 pm

    […] Check that out: […]

  9. Varying U BC not working for settlingFoam -- CFD Online Discussion Forums
    April 20th, 2010 @ 9:36 pm

    […] it in order to get a variable inlet velocity in the dahl case, following alberto's instructions (, and I get the next error message: Starting time loop Time = 0.1 Courant Number mean: 0.0163852 […]

  10. Zubair
    June 28th, 2010 @ 12:36 pm

    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 ??

  11. Alberto
    June 30th, 2010 @ 6:34 am

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

  12. samar
    August 24th, 2010 @ 12:39 am

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


  13. Alberto
    August 24th, 2010 @ 7:25 pm

    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.


  14. InterFoam+Droplets -- CFD Online Discussion Forums
    September 22nd, 2010 @ 9:27 pm

    […] 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: […]

  15. How to change boundary condition with time? -- CFD Online Discussion Forums
    April 13th, 2011 @ 1:32 pm

    […] Also, you can try to use the type timeVaryingUniformFixedValue;. Take a look here: […]

  16. Small time step in interFoam -- CFD Online Discussion Forums
    May 19th, 2011 @ 3:36 pm

    […] so the easiest way is described by alberto on his home page: or you could use the groovyBC: I personaly […]

  17. Greg
    July 19th, 2011 @ 4:04 am

    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

  18. Alberto
    July 20th, 2011 @ 4:53 pm

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

  19. Rasoul
    July 30th, 2011 @ 5:40 am

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

  20. Alberto
    July 30th, 2011 @ 5:52 am

    The easy way is to use groovyBC, which is part of swak4Foam.

  21. Rasoul
    August 8th, 2011 @ 7:59 am

    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

  22. Amin
    December 10th, 2011 @ 10:40 pm

    Thank you very much, it really helped me.

  23. interFoam open channel -- CFD Online Discussion Forums
    March 30th, 2012 @ 9:26 am

    […] yes you can. If you want more info about how use unsteady BC, have a look here (thanks to Alberto Passalacqua). best […]

  24. danfy
    April 16th, 2013 @ 4:29 pm

    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;

  25. Alberto
    April 17th, 2013 @ 3:33 am

    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.

  26. Bjarke
    June 25th, 2014 @ 2:36 pm

    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

  27. Alberto
    June 29th, 2014 @ 5:23 pm

    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.

  28. Bjarke
    June 30th, 2014 @ 1:21 pm

    Hi Alberto
    Thank you for answering. I am using the 1.6-ext version

  29. Alberto
    June 30th, 2014 @ 1:30 pm

    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

    I hope this helps.

  • openSUSE counter

  • Spread Firefox

    Spread Firefox Affiliate Button
  • Thunderbird

    Spread Firefox Affiliate Button
  • License