How to use dynamicRefineFvMesh library using OpenFOAM®
The setting of the automatic mesh refinement is relatively simple. Just fill in the dynamicMeshDict dictionary (or dataset) located in the directory /constant. The dictionary requires several entries including a scalar field for the automatic refinement criterion (volume fraction, concentration of a passive scalar ..), a refinement frequency, a maximum number of cells, levels of refinement etc …
The nBufferLayers parameter specifies the number of “buffer” cells between two refinement levels. This parameter has an identical effect to nCellsBetweenLevels used by snappyHexMesh. Thus, nBufferLayers 1; indicates that there will be one cell between two mesh levels. The maxRefinement parameter determines the maximum number of times a cell can be cut. Here, with maxRefinement 2; a hexahedral type cell can be cut at most twice, thus giving rise to 2 ^ 3 * 2 ^ 3 (64 cells). The maxCells parameter limits the maximum number of cells in the model. It is also possible to choose to correct some flux after cutting a cell by listing them using the correctFluxes keyword. In this case, the flux will be “updated” by interpolating the velocity field to the face.
Automatic refinement can struggle on cells called protected cells. A message similar to the following appears in the terminal when the solving the numerical model:
The protected cells appear when you start the calculation and you have used renumberMesh (after decomposePar). A set directory is created in each decomposition directory of the calculation case:
The two figures below illustrate the problems encountered in the case where protected cells are present:
Abnormal functioning due to protected cells (gauche) – Normal functioning (droite)
Example case : Water jet on an inclined plate
The simulation of a jet (water) on an inclined plate (at 45 ° for example) is a relevant case to illustrate the dynamic libraryRefineFvMesh possibilities. As mentioned before, the automatic refinement is only possible in 3D (it is possible to use it in 2D but stability problems can occur because the cells will still be cut out of the plane).
The mesh is relatively coarse at the beginning (~ 140k cells) in order to limit the calculation time.
Of course, it’s a pure demonstrative case. The physical validity of the calculation is not sought here.
The methodology proposed for this case is as follows:
- Use blockMesh to create the necessary background mesh for snappyHexMesh.
- Meshing with snappyHexMesh by “snapping” the surfaces (.stl format, created under Salome) of the inclined plate and the pipe.
- Define boundary conditions, turbulence model, fluid properties, scheme, linear solvers
- Decompose the case on n processors (here 4) with decomposePar.
- Use the interDyMFoam solver on 4 cores.
- Post-process the results with Paraview®.
The following figures show the surfaces (.stl) of the inclined plate and the pipe boundary as well as the mesh. Three boundary layer elements were added with snappyHexMesh.
Input stl surface for snappyHexMesh (left) – Cartesian mesh generated by snappyHexMesh (right)
The turbulence model used is the k-omega SST model.
The boundary conditions are summarized in the following table:
|fixedValue (5 m/s)
uniform (0.0 0 0);
p0 uniform 0;
Note that for numerical stability arguments it is advisable to combine pressureInletOutletVelocity for velocity with totalPressure for dynamic pressure. The reader may refer to the boundary condition calculator for estimating k and omega (https://cfd-training.com/en/turbulent-boundary-conditions-calculator/) at the inlet patch of the computational domain.
The speed pressure coupling is handled with the PIMPLE loop using only one external corrector. Under these conditions, the PIMPLE loop is equivalent to the PISO loop.
For the pressure resolution three internal correctors are used.
For this case example, 2 buffer cells and 3 levels (max) of refinement are defined in the dynamicMeshDict dictionary (the other settings are identical to the dictionary presented at the beginning of the article):
The GIF below shows the evolution of the jet with the automatic refinement of the free surface. Automatic refinement is achieved by referring to 0 mesh level. Thus, as refinement is possible, level 0 cells of the initial mesh can be refined three times. Level 1 cells, twice, etc. Initially, level 3 cells are present in the vicinity of the plate. These cells will not be refined. It should be noted that the number of cells increases during the calculation until about 870k.