Adaptive mesh refinement with load balancing in OpenFOAM-14: how to set up the refiner and the distributor

TL;DR
- In OpenFOAM-14 (openfoam.org), adaptive mesh refinement (AMR) is a
refinerblock inconstant/dynamicMeshDict. Redistributing the refined mesh across MPI ranks while the run is going is a second block,distributor, in the same file. - Without redistribution, AMR can be slower than no AMR. On 16 ranks, AMR to 5 cm used 2.4ร fewer cells than a uniform 5 cm mesh, yet took 1,714 s against 1,603 s. Its busiest rank held on average 2.3ร the mean cell count.
- With the distributor, the same AMR run took 1,143 s: 1.5ร faster than AMR without redistribution and 1.4ร faster than the uniform mesh.
- At 2.5 cm on 32 ranks, the distributor made the first 60 s of the run 2.4ร faster (3,403 s against 8,236 s). After the first second, the busiest rank dropped from up to 7.3ร the average to at most 1.1ร.
- Re-partitioning more often does not pay. Checking every 5 steps with a 5 % threshold halved the imbalance but re-partitioned twice as often (406 vs 189 times), and finished 9 % slower than the defaults (every 10 steps, 10 %). Each re-partition is computed from scratch, and our samples suggest most of the mesh is re-sent each time.

Steckler room on 32 MPI ranks, slice y = 0, first 60 s. Top: refinement level (10, 5, 2.5 cm). Middle: which rank owns each cell. Colours are matched frame to frame, so a colour follows a region. Bottom: cells per rank and the imbalance and wall-clock histories.
Why this matters
AMR puts cells where the flow needs them: here, the fire plume and the hot smoke layer. Those regions move and grow during the run. The initial decomposition (decomposePar) splits the 10 cm base mesh evenly among the MPI ranks, but it knows nothing about where refinement will happen.
When the plume refines, the ranks that own it receive up to 8 cells for each cell (64 for two levels), while the others keep their coarse cells. Every time step, all ranks wait for the busiest one. OpenFOAM solves this with dynamic load balancing: during the run it measures the cell distribution and, when it drifts too far, re-partitions the mesh and sends cells and fields to their new owners.
The setup is short, but it needs a few entries that the error messages don’t explain well. This post goes through all of them: every parameter, what it changes, and what it cost in our runs on cloudHPC.
This is a numerical-methods post. The fire is a simple volumetric heat source used to drive the refinement; it is not validated against the Steckler measurements here. For the fire physics, see our Steckler room fire post: FDS vs OpenFOAM.
The test case

- Geometry: the Steckler compartment (Test 14 geometry from the FDS validation suite): a 2.80 ร 2.80 ร 2.13 m room (the height used in the FDS validation input) with a 0.74 ร 1.83 m door, plus a 1.1 m deep outside region with open boundaries. The domain is 4 ร 4 ร 3 m.
- Base mesh:
blockMeshwith 10 cm hexahedra, graded so that grid lines fall exactly on the door edges and the ceiling.subsetMeshthen removes the cells outside the room/door/outside region. The result is 28,872 cells. - Fire: a 40.9 kW volumetric heat source (the convective part of 62.9 kW) in a 0.22 ร 0.22 m box over the burner, from the floor up to 0.92 m.
- Solver: OpenFOAM-14 (build 14-a4867fc914c1),
foamRun -solver fluid, LES (kEqn), perfect gas, no radiation, 13 mm fibre-board walls as an equivalent heat-transfer coefficient. - AMR criterion: refine where T > Tambient + 30 K, up to 5 cm (level 1) or 2.5 cm (level 2).
- Machines: cloudHPC hypercore, spot instances, 16 or 32 MPI ranks.
How AMR and redistribution fit together

Both features live in constant/dynamicMeshDict and run at the start of each time step, in this order:
- Refiner (
topoChanger). EveryrefineIntervalsteps, it marks the cells whose field value lies betweenlowerRefineLevelandupperRefineLevel, addsnBufferLayersaround them, and splits each marked hexahedron into 8 (hexRef8). Previously refined cells that are no longer marked are merged back. A 2:1 rule keeps neighbouring cells within one level of each other. - Distributor. Every
redistributionIntervalsteps, it computes the imbalance as the largest value over all ranks of |1 โ nrank/nideal|, where nideal is the total cell count divided by the number of ranks. An under-loaded rank counts as much as an overloaded one. - Re-partition, only if the imbalance exceeds
maxImbalance. OpenFOAM calls the decomposition method named bydistributorinsystem/decomposeParDictand builds a new decomposition from scratch.fvMeshDistributethen sends cells, faces and all fields to their new owners. - Solve. The solver corrects the face fluxes on the changed mesh (a
pcorrpressure-correction equation), then runs the normal PIMPLE step.
The configuration, line by line
constant/dynamicMeshDict
topoChanger
{
type refiner;
libs ("libfvMeshTopoChangers.so");
refineInterval 5; // refine/unrefine every 5 time steps
field T; // any volScalarField in the registry
lowerRefineLevel 331.15; // refine where 331.15 K < T < 5000 K
upperRefineLevel 5000; // (ambient 301.15 K + 30 K)
nBufferLayers 1; // extra layer of refined cells around the band
maxRefinement 2; // 10 cm -> 5 cm -> 2.5 cm
maxCells 20000000; // global cap on the total cell count
dumpLevel true; // write cellLevel at write times
}
distributor
{
type distributor; // balance by cell count
libs ("libfvMeshDistributors.so");
redistributionInterval 10; // check the balance every 10 steps (default 10)
maxImbalance 0.1; // re-partition above 10 % (default 0.1)
}
system/decomposeParDict
numberOfSubdomains 32;
method scotch; // initial decomposition (decomposePar)
// distributor ptscotch; // optional: method used for re-partitioning
// during the run; defaults to 'method'
Without a distributor entry, OpenFOAM uses method for the re-partitions too. In our runs the log shows Selecting distributor scotch, and scotch re-partitioned correctly in parallel in OpenFOAM-14. In the OpenFOAM-14 tutorials, the cases with type distributor (incompressibleVoF/floatingObject and rotatingCube) set distributor hierarchical;. The cases with type loadBalancer (cyclone, aachenBomb, counterFlowFlame2D_GRI) set distributor zoltan; with libs ("libzoltanDecomp.so");. We did not test zoltan, ptscotch or hierarchical here.
Three entries the distributor needs (without them the run stops)
// system/blockMeshDict, boundary: an empty patch of type internal
internalFaces { type internal; faces (); }
// every field in 0/: constraint types, including the internal patch
boundaryField
{
#includeEtc "caseDicts/setConstraintTypes"
...
}
// system/fvSolution: a solver for the flux correction after a mesh change
"pcorr.*"
{
solver GAMG;
smoother GaussSeidel;
tolerance 1e-5;
relTol 0;
}
Heat sources and other zones: generate them, don’t store them
// constant/fvModels
fire
{
type heatSource;
cellZone
{
type box;
box (1.29 -0.11 0) (1.51 0.11 0.92);
regenerate yes; // re-select the cells from the current mesh every step
}
Q 40885; // total power [W], spread over the zone volume
}
What each parameter does
| Parameter | Default | Used here | What it controls | Effect seen in our runs |
|---|---|---|---|---|
refineInterval | required | 5 | How often the refiner runs (in time steps). | A step with refinement took 0.41 s against 0.11 s for a plain step (30โ60 s, about 0.5 M cells, 32 ranks). Smaller values track the plume more closely but cost more. |
field | required | T | The volScalarField used to mark cells. | Temperature follows the plume and the smoke layer directly. |
lowerRefineLevel / upperRefineLevel | required | 331.15 / 5000 K | Cells with a value inside the band are refined; cells outside it (beyond the buffer) are unrefined. | The lower bound sets how much of the domain gets refined. At 28 s, + 15 K had 573k cells against 399k with + 30 K, and it was still growing towards the full room because the warm lower layer was refined too. With + 30 K the mesh grew slowly to 640k at 150 s. |
nBufferLayers | required | 1 | Extra cell layers added around the marked band. They protect cells from unrefinement and smooth the level transitions. | More layers mean more cells but less refine/unrefine churn at the band edge. |
maxRefinement | required | 1 or 2 | Maximum level; each level splits a cell into 8. | Level 1: about 95k cells. Level 2: up to 641k cells, 35 % of a uniform 2.5 cm mesh (1.85 M). |
maxCells | required | 20 M | Global cap; once reached, no more cells are refined. | Never reached. A low value is a cheap safety net against a criterion that refines everything. |
dumpLevel | required | true | Writes the refinement level (cellLevel) at write times. | Useful for checking the mesh in ParaView. |
correctFluxes | optional | not set | How to treat surface fluxes on new faces. | Not needed with the fluid solver, which re-solves the fluxes with pcorr after every mesh change. |
distributor.type | โ | distributor | distributor balances cell counts. loadBalancer balances measured CPU time per cell. | loadBalancer needs a model that reports a CPU load per cell (chemistry or Lagrangian particles). A heat-source fire has none, so we used distributor. |
redistributionInterval | 10 | 10 (5) | How often the balance is checked (in time steps), independent of refineInterval. | Every 10 steps: 189 re-partitions in the first 60 s. Every 5 steps (together with 5 %): 406. |
maxImbalance | 0.1 | 0.1 (0.05) | Re-partition when max |1 โ n/nideal| exceeds this value. | 0.1: mean imbalance 5 %, at most 11.5 %. 0.05 (with interval 5): mean 2.4 %, at most 5 %, but 9 % more wall time. |
decomposeParDict: distributor | method | not set (scotch) | The decomposition method used for the re-partitions during the run. | scotch worked in parallel. Every re-partition starts from scratch. |
Results
| Run | Mesh | Ranks | Simulated | Cells (end) | Re-partitions | Mean imbalance | Solver wall time | Billed cost |
|---|---|---|---|---|---|---|---|---|
| U5 | uniform 5 cm | 16 | 150 s | 230,976 | โ | 1 % | 1,603 s | โฌ0.98 |
| A1N | AMR 10 โ 5 cm, no redistribution | 16 | 150 s | 95,435 | 0 | 128 % | 1,714 s | โฌ1.03 |
| A1D | AMR 10 โ 5 cm, distributor (10 steps, 10 %) | 16 | 150 s | 95,162 | 81 | 5 % | 1,143 s | โฌ0.85 |
| A2N | AMR 10 โ 2.5 cm, no redistribution | 32 | 60 s | 569,678 | 0 | 390 % | 8,236 s | โฌ8.46 |
| A2Dp | AMR 10 โ 2.5 cm, distributor (5 steps, 5 %) | 32 | 60 s | 592,120 | 406 | 2.4 % | 3,698 s | โฌ4.11 |
| A2D | AMR 10 โ 2.5 cm, distributor (10 steps, 10 %) | 32 | 150 s | 639,664 | 224 (189 in 60 s) | 5 % | 9,467 s (3,403 s at 60 s) | โฌ9.65 |
Imbalance here is (busiest rank โ average) / average, sampled every time step after the first 2 s. Solver wall time is the ClockTime of the OpenFOAM log. Billed cost includes boot, upload and end-of-run detection on cloudHPC spot hypercore instances.

Without redistribution the imbalance is huge from the first seconds. decomposePar splits the 10 cm mesh evenly. As soon as the plume reaches the ceiling, the few ranks that own the plume and the upper room start refining, and the others don’t. At 2.5 cm the busiest rank held up to 7.3ร the average cell count. Later in the run, as the smoke layer spreads across more ranks, it eased back to about 3.3ร. The distributor holds the imbalance close to its threshold: the blue line saw-tooths up to about 10 % (briefly 11.5 %) and drops back after each re-partition.

At 5 cm (16 ranks), AMR without redistribution lost to the uniform mesh. It had 2.4ร fewer cells but was 7 % slower over 150 s (1,714 s vs 1,603 s). The wall time of each time step is set by the slowest rank, so the extra cells on the overloaded ranks cancel the savings. With the distributor, AMR took 1,143 s, 29 % less than uniform.
At 2.5 cm (32 ranks), the distributor made the run 2.4ร faster over the first 60 s. With it, the full 150 s took 9,467 s of solver time (โฌ9.65).

What a re-partition costs. With the defaults, during 30โ60 s, a plain time step took 0.11 s, a step with refinement 0.41 s, and a step with refinement and re-partition 2.48 s. Re-partitioning added 12 % to the solver time while the plume was growing (0โ10 s), 10 % at 10โ30 s and 5 % at 30โ60 s (extra CPU time of the re-partition steps on the master rank, from medians). With every 5 steps and 5 %, those numbers roughly doubled (21 %, 20 %, 9 %), which is why the more aggressive setting finished 9 % slower despite a better balance.
Why it moves so many cells. The distributor computes each new decomposition from scratch and does not try to keep a region on the rank that owned it before. Comparing the rank map on the y = 0 slice of the default run one second apart (1โ3 re-partitions in between), between 69 % and 100 % of the slice area changed rank number, which suggests that most of the mesh is re-sent. The shape of the partitions changed much less: only 13โ41 % of the area once rank numbers are matched by overlap. That is why the GIF matches colours between frames. It shows how the partitions evolve, and the counter shows how often the mesh was actually re-sent.
What broke on the way (and how we fixed it)
We built the case from scratch. Each of these stopped or spoiled a run on cloudHPC; the fix is one line or one file.
| Symptom (log) | Cause | Fix |
|---|---|---|
Cannot find patchField entry for procBoundary23to0 | decomposePar -copyZero copies 0/ without the processor patches. | Run plain decomposePar. |
Cannot find a internal patch โฆ An internal patch must be provided for the exposed internal faces | fvMeshDistribute needs a patch of type internal to hold faces temporarily while cells move. | Add internalFaces { type internal; faces (); } to the mesh. |
Cannot find patchField entry for internalFaces | The fields have no entry for the new patch. | #includeEtc "caseDicts/setConstraintTypes" in every boundaryField. |
keyword pcorr is undefined in dictionary โฆ/fvSolution | After the first mesh change the solver corrects the fluxes with pcorr. | Add a "pcorr.*" solver. |
| No error, but the heat source left its box: after a few seconds the lower part of the burner zone was cold and warm gas rose from the floor beside it | A cellZone created with createZones and stored in the mesh did not stay attached to the burner through hundreds of refinements and re-partitions. | Define the zone inline with type box; regenerate yes;, so it is re-selected from the current mesh every step. |
Two more lessons, not specific to AMR:
- Open boundaries. With a static-pressure outlet (
prghPressure) on the open sides of the outside region, spurious inflow jets grew at the corners (about 60 m/s from 6 s on, without AMR as well).prghTotalHydrostaticPressurewith a hydrostatic initialisation (ph_rgh.orig,hydrostaticInitialisation yes) fixed it: peak velocity stayed below 9.5 m/s. loadBalancerbalances measured CPU time per cell rather than cell count. It only works when a model reports a CPU load per cell, namely chemistry or Lagrangian clouds (see theaachenBombtutorial). For a single-phase flow with a heat source,distributoris the right choice.
Recommendations
- Always pair AMR with the distributor when running on more than a few ranks. The
distributorblock is four lines; without it, AMR can end up slower than no AMR. - Start from the defaults (
redistributionInterval 10,maxImbalance 0.1). Tighter settings re-partition more often, and each re-partition re-sends a large part of the mesh. If the log shows manyRedistributing mesh with imbalancelines per second, try looser values (for example 20 steps, 0.15; not tested here). - Choose the refinement band carefully. It decides the cell count far more than
maxRefinementdoes. Check it on a short run before the series. - Add the three mandatory entries up front (internal patch,
setConstraintTypes,pcorr) and generate zones withregenerate yes. - Log cells per rank. A five-line coded function object (in the case files below) prints the min, max and total cell count every step. That is how the imbalance curves in this post were made.
How to run it on cloudHPC
- Upload the case folder (
0/,constant/,system/and theAllrun) to a storage folder. - Launch
openFoam-of14on hypercore (16 or 32 vCPU, spot). cloudHPC runs theAllrun:blockMesh,subsetMesh,checkMesh,decomposePar,foamRun -parallel. It setsnumberOfSubdomainsindecomposeParDictto the number of cores. - Results are reconstructed at the end. The y = 0 slices (VTK, with
processorID) are inpostProcessing/sliceY0/.
The case generator and all six configurations are in the downloadable case files. All runs in this post used spot instances; none was interrupted.
FAQ
How do I enable dynamic load balancing with AMR in OpenFOAM.org?
Add a distributor block (type distributor, libs ("libfvMeshDistributors.so")) to constant/dynamicMeshDict next to the refiner. Add an empty internal patch to the mesh, #includeEtc "caseDicts/setConstraintTypes" to every field, and a pcorr solver to fvSolution.
What is the difference between distributor and loadBalancer in OpenFOAM?
distributor re-partitions to equalise cell counts. loadBalancer uses the measured CPU time per cell as weights, which requires a model that reports CPU loads (chemistry, Lagrangian particles). Without such a model, use distributor.
What do redistributionInterval and maxImbalance do?
Every redistributionInterval time steps (default 10), OpenFOAM computes max |1 โ nrank/nideal|. If it exceeds maxImbalance (default 0.1), the mesh is re-partitioned from scratch and redistributed.
Does re-partitioning more often make the run faster? Not in our test. Every 5 steps with a 5 % threshold halved the mean imbalance (2.4 % vs 5 %) but doubled the number of re-partitions and finished 9 % slower than the defaults.
Why does OpenFOAM AMR without redistribution run slower than expected? The initial decomposition doesn’t know where refinement will happen. The ranks that own the refined region end up with several times the average cell count (up to 7.3ร here), and the wall time of every time step waits for them.
References
- OpenFOAM Foundation, OpenFOAM-14 source code:
src/fvMeshTopoChangers/refiner,src/fvMeshDistributors/distributor,src/fvMeshDistributors/loadBalancer. github.com/OpenFOAM/OpenFOAM-14 - OpenFOAM-14 tutorials:
type distributorinincompressibleVoF/floatingObjectandincompressibleVoF/rotatingCube;type loadBalancerinincompressibleDenseParticleFluid/cyclone,multicomponentFluid/aachenBombandmulticomponentFluid/counterFlowFlame2D_GRI; AMR withrefinerinincompressibleVoF/damBreak3D. - K. D. Steckler, J. G. Quintiere and W. J. Rinkinen, Flow Induced by Fire in a Compartment, NBSIR 82-2520, National Bureau of Standards, 1982.
- NIST Fire Modeling repositories: FDS validation input
Validation/Steckler_Compartment(github.com/firemodels/fds) and experimental dataSteckler_Compartment(github.com/firemodels/exp). - F. Pellegrini and J. Roman, “SCOTCH: A software package for static mapping by dual recursive bipartitioning of process and architecture graphs”, HPCN Europe 1996, LNCS 1067, pp. 493โ498, Springer, 1996.
- cloudHPC documentation: OpenFOAM on cloudHPC and scalability guidelines, docs.cloudhpc.cloud.
- cloudHPC blog: Steckler room fire: FDS vs OpenFOAM.
CloudHPC is a HPC provider to run engineering simulations on the cloud. CloudHPC provides from 1 to 224 vCPUs for each process in several configuration of HPC infrastructure - both multi-thread and multi-core. Current software ranges includes several CAE, CFD, FEA, FEM software among which OpenFOAM, FDS, Blender and several others.
New users benefit of a FREE trial of 300 vCPU/Hours to be used on the platform in order to test the platform, all each features and verify if it is suitable for their needs