## 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

*. 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 …*

**/constant**The **nBufferLayers** parameter specifies the number of “buffer” cells between two refinement levels. This parameter has an identical effect to * nCellsBetweenLevels* used by

*. Thus, nBufferLayers 1; indicates that there will be one cell between two mesh levels. The*

**snappyHexMesh***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*

**maxRefinement***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*

**maxCells***keyword. In this case, the flux will be “updated” by interpolating the velocity field to the face.*

**correctFluxes**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

*). A set directory is created in each decomposition directory of the calculation case:*

**decomposePar**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.

## Numerical methodology

The methodology proposed for this case is as follows:

- Use
to create the necessary background mesh for**blockMesh**.**snappyHexMesh** - Meshing with
by “snapping” the surfaces (.stl format, created under**snappyHexMesh**) of the inclined plate and the pipe.**Salome** - Define boundary conditions, turbulence model, fluid properties, scheme, linear solvers
- Decompose the case on n processors (here 4) with
**decomposePar.**

- Use the
solver on 4 cores.**interDyMFoam** - 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:

Patch | U | k | omega | p | nut | alpha |
---|---|---|---|---|---|---|

Inlet | fixedValue (5 m/s) | fixedValue | fixedValue | zeroGradient | calculated | fixedValue |

Outlet/Top/Bottom/Front/Side | pressureInletOutletVelocity uniform (0.0 0 0); | inletOutlet | inletOutlet | totalPressure; p0 uniform 0; | calculated | inletOutlet |

Plate | noSlip | kqRWallFunction | omegaWallFunction | fixedFluxPressure; | nutkWallFunction | zeroGradient |

Symmetry | symmetry | symmetry | symmetry | symmetry | symmetry | symmetry |

Note that for numerical stability arguments it is advisable to combine * pressureInletOutletVelocity* for velocity with

*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.*

**totalPressure**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):

## Results

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.

But I believe it has problems with reconstruction, decomposition and restarting the case. Ready to discuss that.

You say that there might be a problem if you get bad protected cells. Though in the final case you have been able to remove the protected cells from the simulation.

How did you manage to not produce protected cells?

Dear Magnus,

Protected cells are created if you use renumberMesh. In the tutorial case you will see that renumberMesh is not called.

Best regards,

CFD-training admin

In my case with pimpleFoam they are also becoming protected without doing anything between snappyHexMesh and pimpleFoam. Some of these cells are completely flat cells that have been morphed to snap to the surface, and some are square cells in the middle of the domain.

In my case is it wind flow over an inclined plate, quite similar to your setup.

This is very strange. Please write us at contact@cfd-training.com we will take a look.

Best regards,

CFD-training admin