Creating a New Solver in OpenFOAM: Implementing AMR Mesh Refinement for Combustion Simulations
Combustion simulations are computationally demanding, especially when high resolution is required in critical regions like flame fronts or areas with steep gradients. Refining the entire mesh is often inefficient and costly. That’s where Adaptive Mesh Refinement (AMR) comes in a technique that dynamically refines only the regions that need it, saving computational resources while maintaining accuracy.
In this article, I’ll walk you through how I implemented AMR functionality into OpenFOAM’s reactingFoam solver, creating a new solver called amrReactingFoam.
The Problem: Why AMR?
Combustion simulations often require high resolution in localized areas, such as flame fronts or regions with high velocity gradients. However, refining the entire mesh is computationally expensive. AMR solves this by dynamically refining only the critical regions and coarsening the rest, ensuring optimal resource utilization.
The Solution: Creating amrReactingFoam
The goal was to integrate AMR functionality from interFoam into reactingFoam. Here’s how it was done:
1. Adding AMR Features
The dynamic mesh refinement algorithms and mesh update functions from interFoam were integrated into reactingFoam. Key changes in the source code included:
#include "dynamicFvMesh.H" // Added for AMR
#include "createDynamicFvMesh.H" // Replaced createMesh.H
#include "createDyMControls.H" // Added for dynamic mesh control
#include "readDyMControls.H"
//Mesh update
if (pimple.firstPimpleIter() || moveMeshOuterCorrectors)
{
mesh.update();
if (mesh.changing() && checkMeshCourantNo)
{
#include "meshCourantNo.H"
}
}
//End of mesh update
2. Including Necessary Libraries
The Make/files and Make/options files were updated to include the required libraries for dynamic mesh handling:
# Make/files
EXE = $(FOAM_APPBIN)/amrReactingFoam
# Make/options
EXE_INC = -I$(LIB_SRC)/dynamicFvMesh/lnInclude
EXE_LIBS = -ldynamicFvMesh -ltopoChangerFvMesh
3. Introducing a New Scalar Field
A new scalar field for the velocity gradient was added to serve as a refinement criterion:
// Calculation of velocity gradient in amrReactingFoam.C
gradChange = mag(fvc::div(U));
// Added in createFields.H
volScalarField gradChange
(
IOobject
(
"gradChange", //What to be written to the disk
runTime.timeName(),
mesh,
IOobject::NO_READ, // option to not read from disk
IOobject::AUTO_WRITE // Automatically write at intervals
),
mesh,
dimensionedScalar("gradChange", dimensionSet( 0, 0, -1, 0, 0, 0, 0), 0.0)
);
Compiling the New Solver
The new solver was compiled using OpenFOAM’s build system:
领英推荐
Testing the Solver: Case Setup and Results
The solver was tested using the SandiaD_LTS tutorial. Key steps included:
1. Modifying the Dynamic Mesh File
The dynamicMeshDict file was updated to enable AMR:
dynamicFvMesh dynamicRefineFvMesh;
dynamicRefineFvMeshCoeffs
{
refineInterval 1;
field gradChange;
lowerRefineLevel 1000;
upperRefineLevel 1e9;
unrefineLevel 10;
nBufferLayers 1;
maxRefinement 1;
maxCells 200000;
}
2. Results
The results, visualized in ParaView, demonstrated effective mesh refinement in regions with high velocity gradients. A side-by-side comparison of the mesh with and without AMR highlighted the solver’s capabilities.
Why This Matters
The implementation of AMR in reactingFoam is a game-changer for combustion simulations. By enabling localized mesh refinement, amrReactingFoam reduces computational costs while maintaining high accuracy in critical regions. This is particularly valuable for large-scale simulations, where efficiency is crucial.
Future Work
While amrReactingFoam is already a powerful tool, there’s always room for improvement. Future enhancements could include:
Conclusion
Creating amrReactingFoam was a challenging but rewarding project. By integrating AMR functionality into reactingFoam, we’ve developed a solver that combines computational efficiency with high accuracy, making it a valuable tool for combustion simulations. I’m excited to see how this work can be further improved and applied to real-world problems.
If you’re working on similar projects or have questions about implementing AMR in OpenFOAM, feel free to reach out. Let’s keep pushing the boundaries of computational fluid dynamics!
Acoustics | Aeroacoustics | Measurements | Wind turbine | PhD candidate | CFD | Casual academic | Learning advisor
2 个月Thanks for sharing
TEI - TUSA? Engine Industries, Inc. ?irketinde Advanced Lead Combustion Aerodynamics Engineer
2 个月Great work! A problem with current reactingFlow solver is to access reaction rates of chemical mechanisms. Reaction rate gradients of certain heat-release reactions could be an ideal way to detect flame front and drive amr. does your future plan include such investigations?
Thermofluids / Numerical modelling & CFD | Advanced Researcher - Eurecat
2 个月What do you think are good candidates to set the refinement criterion for combustion simulations? I am thinking about the gradient of the temperature... or something related to the local temperature + pressure + fuel fraction, which automatically refines if the cell is about to enter to combustion.... what do you think?
Scientific Computing | Computational Fluid Dynamics
2 个月AMR tutorial in OpenFOAM: https://github.com/OpenFOAM/OpenFOAM-dev/tree/master/tutorials/incompressibleVoF/damBreak3D Runtime load balancing (which can be combined with AMR): https://github.com/OpenFOAM/OpenFOAM-dev/tree/master/tutorials/multicomponentFluid/aachenBomb You can use the velocity gradient magnitude field by using grad() function object on U, and mag() function object on grad(U), and specifying mag(grad(U)) field in dynamicMeshDict.