OpenFoam® motorBike case with adaptive volume & surface mesh refinement based on curl(U) or grad(p)
This repository provides adaptive mesh refinement for both the volume mesh and the surface mesh. Any field can be used for refinement. In this tutorial, two options have been included:
-
grad(p): the pressure gradient
-
curl(U): the curl of the velocity field
Both are multipled by the cell length to "discourage" the algorithm to keep refining the smallest cells. The method has 3 major parts:
-
Initial mesh
SnappyHexMesh is run in two separate steps:
- castellated mesh: only runs the refinement phase using "baffles" for the surface of the geometry (to avoid the mesh inside the geometry being cut and to keep all cells hexagonal).
This mesh is stored in
primal_refinement
for use in the mesh refinement phase. - snapping phase: this part will cut the mesh (by also having castellated enabled) and snap it to the surface (by setting the surface patch type to
wall
). This mesh is used inprimal_run
for the first CFD loop.
- castellated mesh: only runs the refinement phase using "baffles" for the surface of the geometry (to avoid the mesh inside the geometry being cut and to keep all cells hexagonal).
This mesh is stored in
-
Refinement field
Once the first CFD loop has finished, it maps the fields onto the stored castellated mesh (in
primal_refinement
) and calculates the refinement field (refVal
), for which the lower limit value should be set manually indynamicMeshDict
. -
Mesh refinement
The refinement is then applied to the castellated mesh of the first loop. Once refinement is done, the castellated mesh is copied to
primal_run
where the snapping phase is executed again to snap the refined mesh to the surface. This mesh is then used for the second CFD run.
This method allows for mesh refinement of both the volume and the surface mesh.
In contrast to other OpenFOAM® based methods that refine on the surface, the mesh is re-snapped after refinement, which improves the correspondence to the real geometry.
Adaptive mesh refinement can greatly reduce the computational cost, as the mesh is applied in a more efficient way.
Any given field can be created to steer the mesh refinement. The gradient of pressure (useful for airfoils for example) and curl of the velocity field (useful for wake refinement for example) have been included.
We definitely welcome any contribution to further improve this method (for example, would it be easier to just use refineMesh instead of pimpleFoam?).
- Make sure you have installed latest OpenFoam® v2012
- Clone this repository on your machine
git clone https://github.com/airshaper/adaptive-mesh-refinement.git
- Adopt
primal_run/system/decomposeParDict
depending on number of cores you have. ChangenumberOfSubdomains 6
to number of cores or threads you have available. Also modifyn
undercoeffs
to reflectnumberOfSubdomains
change. For example if you have 12 cores yourn
should be(3 2 2)
if you have 16 cores for example thenn
should be(4 2 2)
and so on. - Go to
cd ./primal_run
then run./Allrun
Refined mesh slice with curl(U) (notice how curl(U) refines the wake as well)
Refined mesh slice with grad(p) (notice how grad(p) mostly refines the surface)
Zoomed Refined mesh slice with curl(U)
Zoomed Refined mesh slice with grad(p)
Refined surface mesh based on curl(U)
Refined surface mesh based on grad(p)