OpenFOAM utility for setting initial alpha.water field in interFoam simulations with free surface flow.
floodField is a preprocessing tool designed to initialize the alpha.water field for interFoam simulations involving free surface flows, particularly useful when simulating scenarios with floating objects (e.g., a boat with an empty hull).
The standard setFields utility does not adequately handle cases where the water surface intersects with complex geometries. floodField solves this by using a flood-fill algorithm that:
- Reads the mesh and initializes all
alpha.watervalues to 0 - Locates cells containing user-defined seed points (known to be underwater and outside solid regions)
- Performs a breadth-first search from seed points, filling connected cells with water (
alpha.water = 1) as long as they remain below the water surface
This approach naturally handles complex geometries like boat hulls, ensuring water is only placed in valid regions below the free surface.
The water surface is defined by:
- Gravity vector: Read from
constant/g(determines the direction of "down") - Water level: A scalar value representing the projection along the
-gdirection
For standard gravity (0 0 -9.81), a water level of 5 corresponds to z = 5 m.
floodField/
├── floodField.C # Main application source
├── floodFieldDict # Example configuration file
└── Make/
├── files # Build configuration
└── options # Compiler/linker flags
tutorials/floodField/
├── Allrun # Script to run the tutorial
├── Allclean # Script to clean the tutorial
├── system/
│ ├── blockMeshDict # Background mesh definition
│ ├── snappyHexMeshDict # Mesh refinement settings
│ ├── fvSchemes # Discretization schemes
│ ├── fvSolution # Solver settings
│ └── controlDict # Time control
├── constant/
│ ├── g # Gravity vector
│ ├── transportProperties
│ └── triSurface/
│ └── boat.stl # Boat hull geometry
└── floodedDomain.png # Visualization of result
To compile the utility, run:
git clone https://github.com/furstj/floodField.git
cd floodField
wmakeThe compiled executable will be placed in $FOAM_USER_APPBIN/floodField.
Copy floodFieldDict to system/floodFieldDict in your case directory:
// Water level as scalar projection along -g direction
// With gravity (0 0 -9.81), waterLevel 5 means z = 5 m
waterLevel 5;
// Seed points guaranteed to be underwater and outside solid regions
seedPoints
(
(9 9 2) // x y z coordinates
);-
Prepare your mesh using e.g.
blockMeshand optionallysnappyHexMesh:blockMesh snappyHexMesh -overwrite
-
Run
floodField:floodField
-
The utility will create/update the
alpha.waterfield in the time directory.
The flood-fill algorithm works as follows:
- Initialize all
alpha.watervalues to 0 - For each seed point, find the containing cell and add it to a queue
- While the queue is not empty:
- Pop a cell from the queue
- Check all neighboring cells
- If a neighbor has
alpha.water = 0and its center is below the water surface (projection along-g< waterLevel), setalpha.water = 1and add to queue
See tutorials/floodField/ for a complete example case featuring:
- A 10×10×10 m domain
- Water level at z = 5 m
- A boat hull without top face
This utility is provided as-is for use with OpenFOAM.
