Adaptive Mesh Refinement With a Moving Mesh using sprayDyMFoam - - PowerPoint PPT Presentation
Adaptive Mesh Refinement With a Moving Mesh using sprayDyMFoam - - PowerPoint PPT Presentation
Adaptive Mesh Refinement With a Moving Mesh using sprayDyMFoam Andreas Nygren Chalmers University of Technology Division of Combustion 8-9th of December OpenFoam Course Andreas Nygren OpenFoam Course - December 8-9 2015 Introduction
Introduction Motivation
- To properly resolve the physics, fine meshes are needed in
regions of interest.
- It is computationally expensive to make the whole mesh very
fine.
- For automotive applications moving meshes are used to model
piston movement.
Andreas Nygren OpenFoam Course - December 8-9 2015
Introduction Learning Outcomes
Today you will learn how to:
- How to combine the dynamicRefineFvMesh class with
thedynamicMotionSolverFvMesh class
- Modify sprayDyMFoam to calculate and output the gradient
- f the velocity field to be used as basis for the adaptive mesh
refinement.
- How to set-up a case with mesh motion and on-line adaptive
mesh refinement.
Andreas Nygren OpenFoam Course - December 8-9 2015
Introduction Dynamic Mesh Libraries in OpenFOAM
dynamicFvMesh
- dynamicMotionSolverFvMesh
- dynamicRefineFvMesh
- solidBodyMotionFvMesh
- dynamicInkJetFvMesh
topoChangerFvMesh
- linearValveFvMesh
- linearValveLayersFvMesh
- mixerFvMesh
- movingConeTopoFvMesh
- rawTopoChangerFvMesh
Andreas Nygren OpenFoam Course - December 8-9 2015
Introduction Dynamic Mesh Libraries in OpenFOAM
dynamicFvMesh
- dynamicMotionSolverFvMesh
- dynamicRefineFvMesh
- solidBodyMotionFvMesh
- dynamicInkJetFvMesh
topoChangerFvMesh
- linearValveFvMesh
- linearValveLayersFvMesh
- mixerFvMesh
- movingConeTopoFvMesh
- rawTopoChangerFvMesh
Focus on simple mesh motion with mesh refinement!
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement with Motion First off!
- Combine dynamicRefineFvMesh and
dynamicMotionSolverFvMesh
- Create a library for both mesh motion and refinement
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement with Motion Copy and rename
Start by copying dynamicRefineFvMesh to your own folder OF30x mkdir -p $FOAM_RUN/../src/motionRefinementFvMesh/ cd $FOAM_RUN/../src/motionRefinementFvMesh/ cp -r $FOAM_SRC/dynamicFvMesh/dynamicRefineFvMesh . mv dynamicRefineFvMesh dynamicMotionSolverRefineFvMesh cd dynamicMotionSolverRefineFvMesh mv dynamicRefineFvMesh.C dynamicMotionSolverRefineFvMesh.C mv dynamicRefineFvMesh.H dynamicMotionSolverRefineFvMesh.H
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement with Motion Renaming Inside Files
- Function calls and includes etc need to be renamed to the
new class name
- Use the sed command!
sed command
sed -i s/dynamicRefineFvMesh/dynamicMotionSolverRefineFvMesh/g dynamicMotionSolverRefineFvMesh.C sed -i s/dynamicRefineFvMesh/dynamicMotionSolverRefineFvMesh/g dynamicMotionSolverRefineFvMesh.H
- A Convenient and safe way to change the name
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement with Motion Edit dynamicMotionSolverRefineFvMesh.H
Class Declaration for motionSolver
namespace Foam { // Add Class Declaration for the Motion Solver Class class motionSolver;
Declare a pointer to the motionSolver
class dynamicMotionSolverRefineFvMesh : public dynamicFvMesh { //Add declaration for pointer to Motion Solver autoPtr<motionSolver> motionPtr_; protected:
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement with Motion Edit dynamicMotionSolverRefineFvMesh.C
Includes for the Motion Solver
#include "dynamicMotionSolverRefineFvMesh.H" #include "addToRunTimeSelectionTable.H" #include "surfaceInterpolate.H" #include "volFields.H" #include "polyTopoChange.H" #include "surfaceFields.H" #include "syncTools.H" #include "pointFields.H" #include "sigFpe.H" #include "cellSet.H" // Add the Following Includes to the Header: #include "motionSolver.H" #include "mapPolyMesh.H" #include "pointField.H" Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement with Motion Edit dynamicMotionSolverRefineFvMesh.C
Pointer to the motionSolver object in the Constructor
dynamicFvMesh(io), //define a pointer to the motionSolver Object in the Constructor: motionPtr_(motionSolver::New(*this)), meshCutter_(*this), dumpLevel_(false), nRefinementIterations_(0), protectedCell_(nCells(), 0)
function call to move points
bool Foam::dynamicMotionSolverRefineFvMesh::update() { // Add a function call to the motionSolver // to move points before refinement. dynamicFvMesh::movePoints(motionPtr_->newPoints());
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement with Motion Create a Make folder
Copy the Make folder from dynamicFvMesh
cd .. cp -r $FOAM_SRC/dynamicFvMesh/Make .
Edit Make/files
dynamicMotionSolverRefineFvMesh/dynamicMotionSolverRefineFvMesh.C LIB = $(FOAM_USER_LIBBIN)/libmotionRefinementFvMesh
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement with Motion
Make/options link with dynamicFvMesh
EXE_INC = \
- I$(LIB_SRC)/triSurface/lnInclude \
- I$(LIB_SRC)/meshTools/lnInclude \
- I$(LIB_SRC)/dynamicMesh/lnInclude \
- I$(LIB_SRC)/dynamicFvMesh/lnInclude \
- I$(LIB_SRC)/finiteVolume/lnInclude
LIB_LIBS = \
- ltriSurface \
- lmeshTools \
- ldynamicMesh \
- ldynamicFvMesh \
- lfiniteVolume
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement with Motion Clean and Compile!
Make
wclean wmake
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement Based on a Gradient
- It is known that the mesh should be refined where the
gradient of a field is high.
- We can base our mesh refinement on the gradient of a field
rather than the field itself.
- We just need to calculate the gradient of the field every time
step
- An easy way of doing this is to just modify the solver
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement Based on a Gradient Copying The Files
Copy and rename sprayDyMFoam
mkdir -p $FOAM_RUN/../applications/solvers/mySprayDyMFoam cd $FOAM_RUN/../applications/solvers/mySprayDyMFoam cp $FOAM_SOLVERS/lagrangian/sprayFoam/createClouds.H . cp $FOAM_SOLVERS/lagrangian/sprayFoam/createFields.H . cp $FOAM_SOLVERS/lagrangian/sprayFoam/rhoEqn.H . cp $FOAM_SOLVERS/lagrangian/sprayFoam/UEqn.H . cp $FOAM_SOLVERS/lagrangian/sprayFoam/sprayDyMFoam/pEqn.H . cp $FOAM_SOLVERS/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C . cp -r $FOAM_SOLVERS/lagrangian/sprayFoam/sprayDyMFoam/Make . mv sprayDyMFoam.C mySprayDyMFoam.C
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement Based on a Gradient Initialize The Gradient Field
Add to createFields.H
// Initialize After U! volScalarField UGrad ( IOobject ( "UGrad", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE ), mag(fvc::grad(U)) );
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement Based on a Gradient Modify the Solver
Add gradient calculation
// Store momentum to set rhoUf for introduced faces. volVectorField rhoU("rhoU", rho*U); // Add the calculation of the velocity // gradient before the mesh changes UGrad = mag(fvc::grad(U)); // Do any mesh changes mesh.update();
Andreas Nygren OpenFoam Course - December 8-9 2015
Mesh Refinement Based on a Gradient Create Make/files, Make/options and compile
Make/files - Change Name
mySprayDyMFoam.C EXE = $(FOAM_USER_APPBIN)/mySprayDyMFoam
Make/options - Change the Path to Two Folders
- I$(FOAM_SOLVERS)/lagrangian/reactingParcelFoam \
- I$(FOAM_SOLVERS)/compressible/rhoPimpleFoam/rhoPimpleDyMFoam \
Clean and Compile!
wclean wmake
Andreas Nygren OpenFoam Course - December 8-9 2015
Case Set-Up Aachen-Bomb case
- Static Spray combustion
chamber
- sprayFoam tutorial case
- We can modify it to run
with dynamicMotionSolver- RefineFvMesh
Andreas Nygren OpenFoam Course - December 8-9 2015
Case Set-Up
- Download the aachenBombMotionRefine case.
- It has been modified so that the spray chamber will shrink
during run-time.
- It serve to illustrate the simultaneous mesh motion and
refinement.
- This is not a ”real spray simulation”. The mesh is to coarse.
- We will now go through the modifications and then run the
case.
Andreas Nygren OpenFoam Course - December 8-9 2015
Case Set-Up Add patches for movingWall
patches ( wall walls ( (2 6 5 1) (0 4 7 3) (0 1 5 4) (7 6 2 3) ) wall fixedWall ( (4 5 6 7) ) wall movingWall ( (0 1 2 3) ) );
Andreas Nygren OpenFoam Course - December 8-9 2015
Case Set-Up Modify inital files to correspond to new patches
boundaryField { walls { type zeroGradient; } fixedWall { type zeroGradient; } movingWall { type zeroGradient; } }
Andreas Nygren OpenFoam Course - December 8-9 2015
Case Set-Up Moving Wall velocity for U
movingWall { type movingWallVelocity; value uniform (0 0 0); }
Andreas Nygren OpenFoam Course - December 8-9 2015
Case Set-Up pointMotion
dimensions [ 0 1 -1 0 0 0 0 ]; internalField uniform 0; boundaryField { movingWall { type uniformFixedValue; uniformValue 1; value uniform 1; } walls { type slip; } fixedWall { type uniformFixedValue; uniformValue 0; value uniform 0; } }
- Special Inital File
- Prescribe velocity for mesh
points at movingWall
Andreas Nygren OpenFoam Course - December 8-9 2015
Case Set-Up dynamicMeshDict - Motion Coeffs
dynamicFvMesh dynamicMotionSolverRefineFvMesh; motionSolverLibs ( "libfvMotionSolvers.so" ); solver velocityComponentLaplacian; velocityComponentLaplacianCoeffs { component y; diffusivity inverseDistance (movingWall); }
Andreas Nygren OpenFoam Course - December 8-9 2015
Case Set-Up dynamicMeshDict - Refinement Coeffs
dynamicMotionSolverRefineFvMeshCoeffs //dynamicRefineFvMeshCoeffs { // How often to refine refineInterval 1; // Field to be refinement on field UGrad; // Refine field inbetween lower..upper lowerRefineLevel 10000; upperRefineLevel 70000; // If value < unrefineLevel unrefine unrefineLevel 1; // Have slower than 2:1 refinement nBufferLayers 1; // Refine cells only up to maxRefinement levels maxRefinement 2; // Stop refinement if maxCells reached maxCells 160000; // Flux field and corresponding velocity field. Fluxes on changed // faces get recalculated by interpolating the velocity. Use none // on surfaceScalarFields that do not need to be reinterpolated. correctFluxes ( (phi_0 U_0) (phi U)