Skip to content

Usage & I/O

Overview

This page describes how to include the FluidDynamics module in a simulation, configure it via the input file, and interpret the output.


Minimal usage example

The following shows a minimal incompressible single-phase flow simulation:

cpp
#include "FluidDynamics/FlowSolverLBM.h"
#include "BoundaryConditions.h"
#include "PhaseField.h"
#include "Settings.h"
#include "Velocities.h"

using namespace openphase;

int main(int argc, char* argv[])
{
    std::string InputFile = DefaultInputFileName;

    Settings           OPSettings(InputFile);
    BoundaryConditions BC(OPSettings, InputFile);
    PhaseField         Phase(OPSettings);
    Velocities         Vel(OPSettings);
    FlowSolverLBM      FL(OPSettings, InputFile);
    RunTimeControl     RTC(OPSettings, InputFile);

    // Initialize microstructure ...
    // Initializations::Single(Phase, 0, BC);

    FL.FinalizeInitialization(Phase, Vel, BC);

    while (!RTC.Finished())
    {
        FL.Solve(Phase, Vel, BC);

        if (RTC.WriteVTK())
            FL.WriteVTK(OPSettings, Phase, RTC.Step());

        RTC.Increment();
    }
    return 0;
}

Input file parameters

Parameters are read from the project input file (.opi) under the [FlowSolverLBM] section.

Required parameters

KeyTypeDescription
N_Fluid_CompintNumber of fluid components
nudouble (per component)Kinematic viscosity [m²/s]
dRhodoubleLattice-to-physical density scaling [kg/m³]
dtdoubleLattice-to-physical time scaling [s]

Optional: flow features

KeyDefaultDescription
Do_GravityfalseEnable gravitational force
GA{0,0,0}Gravitational acceleration [m/s²]
Do_BounceBackfalseSolid–fluid no-slip boundary
Do_BounceBackElasticfalseMoving solid bounce-back
Do_DragfalseInterface drag force
h_star0Drag force parameter
Do_FixPopulationsfalseFix negative populations

Optional: two-phase flow

KeyDefaultDescription
Do_TwoPhasefalseEnable two-phase flow
Do_BenzifalseUse Benzi pseudo-potential
Do_KupershtokhfalseUse Kupershtokh two-phase model
LiquidDensityEquilibrium liquid density [kg/m³]
VaporDensityEquilibrium vapor density [kg/m³]
SurfaceTensionSurface tension [kg/s²]
rho_0Benzi reference density
GbBenzi interaction strength matrix
WettingWetting parameter matrix (phase × fluid component)

Use BenziGas::EquilibriumValues() or VanDerWaalsGas::EquilibriumValues() to determine the correct values for LiquidDensity, VaporDensity, and SurfaceTension.

Optional: thermal compressibility

KeyDefaultDescription
Do_ThermalCompfalseEnable thermally compressible extension
Pth01e5Initial thermodynamic pressure [Pa]
Poutlet1e-6Outlet hydrodynamic pressure [Pa]
GradRho_VanLeerfalseUse Van Leer density gradient
GradRho_CentralfalseUse central differences for density gradient

Output fields

VTK output

cpp
FL.WriteVTK(OPSettings, Phase, tStep);

Writes to VTK/FlowSolverLBM_<tStep>.vts:

FieldDescription
FluidDensityPhysical mass density [kg/m³]
FluidVelocityPhysical velocity vector [m/s]
PressureLattice pressure
ObstacleSolid/fluid mask (0 = fluid, 1 = solid)

Lattice population output

cpp
FL.lbWriteVTK(OPSettings, Phase, tStep);

Writes raw populations for debugging — not intended for production output.

Binary restart files

cpp
FL.Write(OPSettings, tStep);    // write
FL.Read(OPSettings, BC, tStep); // read

Populations and obstacle states are stored in binary format for checkpointing.


Diagnostic quantities

Useful methods for monitoring simulation health:

cpp
// Mass monitoring
vector<double> mass = FL.CalculateFluidMass();
double liqVol = FL.CalculateLiquidVolume(0);     // component 0 liquid
double vapVol = FL.CalculateVaporVolume(0);

// Node counts
size_t nFluid    = FL.CountFluidNodes();
size_t nObstacle = FL.CountObstacleNodes();

// Local field access
double p    = FL.Pressure(i, j, k);
dVector3 u  = FL.FluidVelocity(i, j, k);
double rho  = FL.FluidDensity(i, j, k);

Boundary conditions

The BoundaryConditions object controls domain boundaries. Typical configurations for LBM:

BC typeLBM effect
PeriodicPopulations wrap around domain boundaries
No-slip wallBounce-back applied at boundary nodes
Inlet velocitySetUniformVelocity(BC, U0) — sets populations to equilibrium at u0
Outlet pressurePoutlet sets the outlet hydrodynamic pressure

Inlet flow with a prescribed velocity:

cpp
dVector3 U0 = {0.01, 0.0, 0.0}; // [m/s]
FL.SetUniformVelocity(BC, U0);

Validation test cases

TestLocationValidates
Capillary bridgetests/LBCapillaryBridgeSurface tension, contact angle
Gravity-driven flowtests/LBGravityBody force, Poiseuille profile
Density equilibriumtests/LBDensityMulti-component phase separation

Run a test with:

bash
cd openphase/tests/LBCapillaryBridge
make
./LBCapillaryBridge
./compare.sh  # compare to reference results

Performance tips

  • Use grid dimensions that are multiples of your CPU's SIMD width (multiples of 8 or 16).
  • Minimize WriteVTK frequency; VTK I/O is the dominant overhead at high output rates.
  • For MPI runs, set domain decomposition along the longest spatial dimension.
  • Do_FixPopulations adds overhead; enable only when needed (high density ratio or unstable cases).
  • Restart files (Read/Write) are compact — checkpoint every few thousand steps for long runs.

Released under the GNU GPLv3 License.