Saturday, 20 April 2013

Falling drop simulation with OpenFOAM in 2D

In this post I describe a simple simulation of a falling drop with OpenFOAM. The case data can be downloaded here: drop2d.tgz. All you have to do to run the simulation is to untar it with  

tar xvzf drop2d.tgz

and type


in the drop2d folder. Your results should look like this:

Please note that the results are not validated in any way and are just of qualitative nature. 2D drops are also not very typical in nature;)

The Setup

Now a few words about the setup. The case is modification of the damBreak tutorial case which uses the solver interFoam. This solver is based on the VOF (volume of fluid) method and is usually used for multiphase problems like the one presented here.
The mesh consists of a single block generated with blockMesh. There are separate patches for the top, the sides & bottom and front & back. I observed that the results look realistic or not completely artificial even for very low mesh resolutions. 

The essential setting for a free surface problem like the one described here is the initial condition. In the VOF solver the alpha1 variable describes the local proportion of the fluids in the simulation. In our case 0 stand for pure air and 1 for pure water. Using setFields the scenario shown below can be generated easily.
Initial conditions: left: alpha, right: velocity.
The initialisation of alpha consists of just two blocks, the water pool and the drop. Here the corresponding setFieldsDict (it's located in the system folder):

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.1.0                                 |
|   \\  /    A nd           | Web:                      |
|    \\/     M anipulation  |                                                 |
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      setFieldsDict;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    volScalarFieldValue alpha1 0

    boxToCell // drop
        box (0.046 0.14 -1) (0.054 0.148 1);
            volScalarFieldValue alpha1 1
            volVectorFieldValue U (0 -1 0)

    boxToCell // water
        box (-1 -1 -1) (1 0.025 1);
            volScalarFieldValue alpha1 1

// ************************************************************************* //

I also prescribed an initial velocity of Uy = -1 to the drop. This simulates a bigger fall height without extending the computational domain. Setting positive values will cause the drop to fly up first and then fall into the water. SetFields allows only boxes for initialisation so the drop looks edged in the beginning. It gets a more physical form during the fall.
One thing that often causes confusion are the .org files in the 0 folder. After running setFields the chosen variable files are extended with volume data for each cell. They might become very large and are only valid for the given mesh. In case you want to change the grid or archive the case, you have to get rid of the volume data. As there is no undo for setFields, it's a good idea to keep the originals (.org) and just make a copy. In the presented case the copying is done by Allrun.


The case is set up to write out the solution for several time steps. Just type


in the case folder to view the results. To visulalise only the water and blank out the air the clip filter (everything in paraview is called filter;) is a good choice. It can be found in the menu Filters > Alphabetical > Clip or as a shortcut, see screen shot below. Just select scalar as clipping function, choose alpha1 and set the threshold to 0.5. You should see something like this:

Paraview pipeline for the drop simulation

Clicking on play should start the animation. To make a movie, go to File and choose Save Animation. The time steps will be then saved as single images. Under this link you'll find a quick method to merge the images to a movie:

Happy simulating!


  1. Great post man. This will be a very very helpful post for me. Thank you sooo much for the work you put. I am eager to know if you also give tech support about this case?
    Once again thanks DIY.

  2. DIY,
    Can you please tell me how did you calculate position of drop in the domain? Please reply quick. Awaiting a reply. Thank you.

  3. The initial position of the drop is set arbitrarily. I don't understand the question completely.

  4. DIY,
    Thanks. I could resolve the problem. Actually I was not knowing how you picked the co-ordinates of the box representing the drop but now I understood it :).

  5. This comment has been removed by the author.

  6. Hi,

    Do you know how I can plot/calculate falling drop velocity?



    1. Please take a look at this:

  7. This comment has been removed by the author.

  8. Hi DIY,
    Thank you for the post.Can I simulate this case in openFOAM version-3.0.1.Awaiting a reply.Thank you

  9. I didn't try it up to now.

  10. Hello, I was trying to run this tutorial. I first run ./Allrun then interFoam, but here there was fatal error: FOAM FATAL IO ERROR:
    Unknown patchField type buoyantPressure for patch type wall

    Can you help to know how i can handle that error?

    Thank you!