What if your mesh could be adapted automatically to improve the accuracy of your solution? That’s exactly what Adaptive Mesh Refinement (AMR) is all about. OpenFOAM has built-in tools to automatically refine the mesh locally using whatever criteria you specify. But, what criteria should we use?
Probably the most sound method involves simply looking for zones with large enough gradients on the flow solution variables. After all, the whole point of discretizing space is to solve the effect of those spatial derivatives!
In this video, I show an example of how to set-up this kind of AMR criteria, using the flow around a cylinder (with Reynolds number of 220) as an example. Mesh is refined wherever the magnitude of the gradient of the velocity field exceeds a certain threshold.
The implementation is pretty straightforward: first, a coded function object is included in the “controlDict” file, which computes the refinement indicator field, in this case mag(grad(U)). Then the desired thresholds are configured in the “dynamicMeshDict” file.
Notice that the gradient of a single variable (the velocity) is used as refinement criteria in this simple case. For more complex cases, like those involving advected scalars (temperature, pollutants, etc), the gradient of two or more variables could be included in the same algorithm. For example, in a case with variables U and T, the refinement indicator field could be defined as:
indicatorField = max(mag(grad(U)) / U_threshold, mag(grad(T)) / T_threshold)
And refinement would be performed wherever indicatorField is greater than one.
In case you want to take a closer look at how everything is put together, I have uploaded the case to GitHub: