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

./Allrun 

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:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      setFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

defaultFieldValues
(
    volScalarFieldValue alpha1 0
);

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

    boxToCell // water
    {
        box (-1 -1 -1) (1 0.025 1);
        fieldValues
        (
            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.

Visualisation  

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

paraFoam 

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:
http://doc-diy.net/photo/image_processing_linux/#makingtimelapse


Happy simulating!


Friday, 19 April 2013

Hello world!

Some of you may know my web site www.doc-diy.net related to do-it-yourself projects in electronics, photography and other technical topics. In contrast to the more static site, this blog is going to be the more dynamic counterpart and the place for smaller projects, good and not so good ideas, images, code snippets, etc...
You are welcome to read, comment, criticize, link, follow, add or interact in whatever way this medium allows to.

Stay tuned!

Luk