projectwork: adaptivemeshrefinementwithamoving...

25
CFD with OpenSource software A course at Chalmers University of Technology Taught by Håkan Nilsson Project work: Adaptive Mesh Refinement with a Moving Mesh using sprayDyMFoam Developed for OpenFOAM-3.0.x Author: Andreas Nygren Peer reviewed by: Magnus Urquhart Håkan Nilsson Disclaimer: This is a student project work, done as part of a course where OpenFOAM and some other OpenSource software are introduced to the students. Any reader should be aware that it might not be free of errors. Still, it might be useful for someone who would like learn some details similar to the ones presented in the report and in the accompanying files. The material has gone through a review process. The role of the reviewer is to go through the tutorial and make sure that it works, that it is possible to follow, and to some extent correct the writing. The reviewer has no responsibility for the contents. January 25, 2016

Upload: others

Post on 26-Oct-2019

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CFD with OpenSource software

A course at Chalmers University of TechnologyTaught by Håkan Nilsson

Project work:

Adaptive Mesh Refinement with a MovingMesh using sprayDyMFoam

Developed for OpenFOAM-3.0.x

Author:Andreas Nygren

Peer reviewed by:Magnus Urquhart

Håkan Nilsson

Disclaimer: This is a student project work, done as part of a course where OpenFOAM and someother OpenSource software are introduced to the students. Any reader should be aware that it

might not be free of errors. Still, it might be useful for someone who would like learn some detailssimilar to the ones presented in the report and in the accompanying files. The material has gonethrough a review process. The role of the reviewer is to go through the tutorial and make sure thatit works, that it is possible to follow, and to some extent correct the writing. The reviewer has no

responsibility for the contents.

January 25, 2016

Page 2: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

Contents

1 Introduction 41.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2 Code Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Dynamic Mesh Refinement With A Moving Mesh 62.1 Dynamic Mesh Libraries in OpenFOAM . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 How to create a dynamicMotionSolverRefineFvMesh class . . . . . . . . . . . . . . . 7

3 Refinement Based on The Gradient of a Field 11

4 Case Set-up 144.1 Pre-Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.2 Solver Set Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.3 Post-Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

1

Page 3: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

Learning Outcomes

In this tutorial we will learn the following:

• How to combine the dynamicRefineFvMesh class with the dynamicMotionSolverFvMesh class

• How to modify sprayDyMFoam to calculate and output the gradient of the velocity field to beused as basis for the adaptive mesh refinement.

• How to setup a case with mesh motion and adaptive mesh refinement.

2

Page 4: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

Study Questions

1. What is the difference between mesh motion and mesh motion with topological changes?

2. Where are the dynamicFvMesh source files located?

3. What is the purpose of the movingConeTopoFvMesh-class?

4. What does the DyM in sprayDyMFoam mean?

5. From which file are the field variables initialized by a solver in OpenFOAM?

3

Page 5: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

Chapter 1

Introduction

1.1 IntroductionWhen performing CFD simulations it is of paramount importance to have a mesh that is fineenough to properly capture the underlying physics. One way of solving this would be to makemesh refinements in regions of interest. However sometimes the regions of interest are not knownbefore hand. One possible solution to this problem is adaptive mesh refinement based on a fieldor possibly the gradient of a field. In OpenFOAM adaptive mesh refinement is implemented in thedynamicRefineFvMesh class. In its current state it only supports adaptive mesh refinement with astatic mesh. However it can be modified to also run with a moving mesh.

1.2 Code EnvironmentsIn this report, code will be displayed in different environments depending on what type of codeit is. C++ code will be displayed in a green environment. For C++ code, the user should find thecorresponding lines in the file and insert the code under the comment //Add This.... The C++Environment will typically display a couple of lines of code before the part where it should be addedto help find the correct position in the code. The line numbers in the C++ environment should matchthe ones in the file. For an example, see C++ Code 1.1.

Bash code that is supposed to be executed in the Linux shell has a purple environment. Herethe whole block of code should be copied and inserted into the terminal. Note that it is importantto copy and paste the whole block of code, as some commands span multiple lines in the text.For an example, see Bash Code 1.1.

OpenFoam-Dictionaries will be displayed in a red environment. Here the user should create a newor replace the current dictionary with the contents of the displayed OpenFoam environment. For anexample see OpenFoam Environment 1.1

4

Page 6: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 1. INTRODUCTION

C++ Code 1.1: C++ Example

1 // C++ Code will be displayed in this environment2 // Example:3 void Foam::helloFoam::hello()4 {5 //Add this line:6 Info << "Hello OpenFoam!" << endl;7 }

Bash Code 1.1: Bash Example

# Bash commands will be displayed in this environment.# Commands that are displayed in this environment should be copy-pasted# into a Bash terminal# Example:OF30xmkdir -p $FOAM_RUNcp -r $FOAM_TUTORIALS $FOAM_RUNcd $FOAM_RUN/incompressible/icoFoam/cavityblockMeshicoFoam

OpenFoam Dictionary 1.1: openFoam Dict Example

/*--------------------------------*- C++ -*----------------------------------*\| ========= | || \\ / F ield | OpenFOAM: The Open Source CFD Toolbox || \\ / O peration | Version: 3.0.x || \\ / A nd | Web: www.OpenFOAM.org || \\/ M anipulation | |\*---------------------------------------------------------------------------*/FoamFile{

version 2.0;format ascii;class volScalarField;object someObject;

}// ************************************************************************* //

dimensions [0 0 0 0 0 0 0];

someDict{

someSubDict someValue}// ************************************************************************* //

5

Page 7: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

Chapter 2

Dynamic Mesh Refinement With AMoving Mesh

2.1 Dynamic Mesh Libraries in OpenFOAMIn OpenFOAM there are two libraries that handles moving meshes. They are called dynamicFvMeshand topoChangerFvMesh. dynamicFvMesh handles mesh motion without topological changes, andtopoChangerFvMesh handles mesh motion together with topological changes. Topological changesmeans that the connection between the cells changes, whereas normal mesh motion are just pointschanging position. The directory structure of both libraries are shown in figure 2.1. The topoChangerFvMesh

$FOAM_SRC/dynamicFvMesh/| ---- dynamicFvMesh| ---- dynamicInkJetFvMesh| ---- dynamicMotionSolverFvMesh| ---- dynamicRefineFvMesh| ---- i n c lude| ---- l n Inc lude| ---- Make| ---- solidBodyMotionFvMesh+---- staticFvMesh

$FOAM_SRC/topoChangerFvMesh/| ---- l inearValveFvMesh| ---- l inearValveLayersFvMesh| ---- l n Inc lude| ---- Make| ---- mixerFvMesh| ---- movingConeTopoFvMesh| ---- rawTopoChangerFvMesh+---- topoChangerFvMesh

Figure 2.1: Directory Structure of the dynamicFvMesh and topoChangerFvMesh libraries

library consists of the movingConeTopoChangerFvMesh andrawTopoChangerFvMesh classes. It should also be noted that the linearValveFvMesh andlinearValveLayersFvMesh classes have been commented out of the Make file, thus it can be as-sumed that they are no longer supported in recent versions of OpenFOAM. For mesh motion withtopological changes it is currently up to the user to write his own class do the mesh motion. ThemovingConeTopoChangerFvMesh class provides an example that uses layerAdditionRemoval to dy-namically add or remove hexahedral mesh layers on the movingCone case. For users that want tocreate their own class for mesh motion with topological changes the rawTopoChangerFvMesh classprovides a starting point.

The dynamicFvMesh library consists of several classes designed for different type of mesh mo-tion without topological changes. The most basic one is the dynamicMotionSolverFvMesh classwhich just solves the equations for mesh motion and move cells according to a diffusivity model.The dynamicInkJetFvMesh class is is specifically ”designed for the pumping system of an ink-jet injector”[2] and does not solve for mesh motion. The solidBodyMotionFvMesh moves themesh according to a prescribed motion function. For a list of available motion functions type

6

Page 8: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 2. DYNAMIC MESH REFINEMENT WITH A MOVING MESH

ls $FOAM_SRC/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFunctions/ in the linuxterminal. The dynamicRefineFvMesh class provides adaptive mesh refinement during run-time. Itmarks a cell for refinement if the cell value of a user specified field is within a certain range. If the acell is marked for refinement it calls the mesh cutter hexRef8 and split the cell into eight new cells.This is also known as oct-tree refinement.

In this tutorial we will focus on the dynamicMotionSolverFvMesh and dynamicRefineFvMeshclasses. For further information on the dynamic mesh libraries consult the OpenFOAM Program-mer’s guide[1].

2.2 How to create a dynamicMotionSolverRefineFvMesh classTo achieve adaptive mesh refinement together with mesh motion, the two classesdynamicMotionSolverFvMesh and dynamicRefineFvMesh can be combined into one class with rel-ative ease. Start by copying dynamicMotionSolverFvMesh to your own directory and renameit:

Bash Code 2.1: Copy and Rename dynamicRefineFvMesh

OF30xmkdir -p $WM_PROJECT_USER_DIR/src/motionRefinementFvMesh/cd $WM_PROJECT_USER_DIR/src/motionRefinementFvMesh/cp -r $FOAM_SRC/dynamicFvMesh/dynamicRefineFvMesh .mv dynamicRefineFvMesh dynamicMotionSolverRefineFvMeshcd dynamicMotionSolverRefineFvMeshmv dynamicRefineFvMesh.C dynamicMotionSolverRefineFvMesh.Cmv dynamicRefineFvMesh.H dynamicMotionSolverRefineFvMesh.H

Now change all occurrences of dynamicRefineFvMesh to dynamicMotionSolverRefineFvMesh insidethe .C and -H files using the sed command:

Bash Code 2.2: Change all occurences to

sed -i s/dynamicRefineFvMesh/dynamicMotionSolverRefineFvMesh/g dynamicMotionSolverRefineFvMesh.Csed -i s/dynamicRefineFvMesh/dynamicMotionSolverRefineFvMesh/g dynamicMotionSolverRefineFvMesh.H

Now we need to create the Make folder, which contains information on how the code should becompiled and which libraries it should be linked to. Start by creating the following files and fold-ers:

Bash Code 2.3: Create Make folder and files

cd ..mkdir Maketouch Make/filestouch Make/options

Firstly, we edit the empty Make/files file::

7

Page 9: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 2. DYNAMIC MESH REFINEMENT WITH A MOVING MESH

Bash Code 2.4: Create the files file

echo -e "dynamicMotionSolverRefineFvMesh/dynamicMotionSolverRefineFvMesh.CLIB = \$(FOAM_USER_LIBBIN)/libmotionRefinementFvMesh" > Make/files

The first line of code is the path to the source file(s) of the library. The second line of code is thelocation where the compiled library will be put. Secondly, we should edit the empty Make/options:

Bash Code 2.5: Create the options file

echo -e "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" > Make/options

The Make/options file tells the compiler that the motionRefinementFvMesh library should be linkedto the dynamicFvMesh library.

Before we edit the actual source files to combine the classes, we should try and compile thelibrary. This is a good way to check that we have copied and renamed all files and folders properly.Compile the library by typing the following in the terminal:

wclean libwmake

If the compilation is successful, then that is an indication of that everything up to this point hasbeen done properly. If not, please go back and review the previous sections of this chapter.

Now we are ready to start combining the classes. We are going to start with the .H file. Go intothe dynamicMotionSolverRefineFvMesh folder. Start by editing dynamicMotionSolverRefineFvMesh.H.Firstly we need to add a class declaration for the motionSolver at the top of the file.

C++ Code 2.1: dynamicMotionSolverRefineFvMesh.H

78 namespace Foam79 {80 class motionSolver; // Add Class Declaration for the Motion Solver Class

Secondly, we need to add a declaration for the pointer to the motionSolver:

8

Page 10: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 2. DYNAMIC MESH REFINEMENT WITH A MOVING MESH

C++ Code 2.2: dynamicMotionSolverRefineFvMesh.H

85 class dynamicMotionSolverRefineFvMesh86 :87 public dynamicFvMesh88 {89 autoPtr<motionSolver> motionPtr_; //Add declaration for pointer to Motion Solver

Save and exit dynamicMotionSolverRefineFvMesh.H. Now we edit the dynamicMotionSolverRefineFvMesh.Cfile. The first thing we should do is to add some includes for the motion solver:

C++ Code 2.3: dynamicMotionSolverRefineFvMesh.C

26 #include "dynamicMotionSolverRefineFvMesh.H"27 #include "addToRunTimeSelectionTable.H"28 #include "surfaceInterpolate.H"29 #include "volFields.H"30 #include "polyTopoChange.H"31 #include "surfaceFields.H"32 #include "syncTools.H"33 #include "pointFields.H"34 #include "sigFpe.H"35 #include "cellSet.H"36 #include "motionSolver.H" //Added to the Header37 #include "mapPolyMesh.H" //Added to the Header

Next thing we need to do is to construct a motionSolver object. We do this by defining a pointer toa motionSolver object in the constructor of our dynamicMotionSolverRefineFvMesh class:

C++ Code 2.4: dynamicMotionSolverRefineFvMesh.C

1008 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //1009

1010 Foam::dynamicMotionSolverRefineFvMesh::dynamicMotionSolverRefineFvMesh(const IOobject& io)1011 :1012 dynamicFvMesh(io),1013 motionPtr_(motionSolver::New(*this)), //Add a pointer to the motionSolver

The last thing we need to add in the .C file is a call for the movePoints function in the motionSolverclass. This should be added at the top of the update function in dynamicMotionSolverRefineFvMeshclass. The update function is then called by the solver during run-time to execute the mesh refine-ment refinement.

C++ Code 2.5: dynamicMotionSolverRefineFvMesh.C

1197 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //1198

1199 bool Foam::dynamicMotionSolverRefineFvMesh::update()1200 {1201 dynamicFvMesh::movePoints(motionPtr_->newPoints());// Add a function call to the motionSolver

9

Page 11: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 2. DYNAMIC MESH REFINEMENT WITH A MOVING MESH

Save and exit dynamicMotionSolverRefineFvMesh.C. Now it is time to compile the combined classinto a new library:

Bash Code 2.6: Clean and Compile

cd ..wclean libwmake

10

Page 12: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

Chapter 3

Refinement Based on The Gradient ofa Field

It is well known that it is beneficial to have a fine mesh in regions where gradients are high. Thus itwould be good to base the mesh refinement on the gradient of a field rather than a field it self. Todo this we need to calculate the gradient of the field at every time step, and for the mesh refinementengine to be able to access the field, it needs to be in the object registry. The easies way of doingthis is to modify our solver, in this case sprayDyMFoam. sprayDyMFoam is a version of sprayFoamthat supports mesh motion. Start by copying sprayDyMFoam to your own directory:

Bash Code 3.1: Copy and rename sprayDyMFoam

mkdir -p $WM_PROJECT_DIR/applications/solvers/mySprayDyMFoamcd $WM_PROJECT_DIR/applications/solvers/mySprayDyMFoamcp $FOAM_SOLVERS/lagrangian/sprayFoam/createFields.H .cp $FOAM_SOLVERS/lagrangian/sprayFoam/sprayDyMFoam/sprayDyMFoam.C .mv sprayDyMFoam.C mySprayDyMFoam.C

Bash Code 3.2: Create Make/options file

mkdir Maketouch Make/optionsecho -e "EXE_INC = \\-I\$(FOAM_SOLVERS)/lagrangian/sprayFoam \\-I\$(FOAM_SOLVERS)/lagrangian/reactingParcelFoam \\-I\$(FOAM_SOLVERS)/compressible/rhoPimpleFoam/rhoPimpleDyMFoam \\" > Make/optionstail -n +5 $FOAM_SOLVERS/lagrangian/sprayFoam/sprayDyMFoam/Make/options >> Make/options

Bash Code 3.3: Create Make/files file

touch Make/filesecho -e "mySprayDyMFoam.CEXE = \$(FOAM_USER_APPBIN)/mySprayDyMFoam" > Make/files

11

Page 13: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 3. REFINEMENT BASED ON THE GRADIENT OF A FIELD

Before we start to modify the solver, clean and compile the newly copied files so that we can seethat everything is named correctly:

Bash Code 3.4: Clean and Compile

wcleanwmake

Now we are ready to modify the solver. The first thing we should do is to initialize the gradientfield. Start by editing createField.H file. Firstly, the gradient field has to be initialized. This isdone by editing the createField.H file: Initialize the gradient field by adding the following linesafter the initialization of U:

C++ Code 3.1: createFields.H

44 volVectorField U45 (46 IOobject47 (48 "U",49 runTime.timeName(),50 mesh,51 IOobject::MUST_READ,52 IOobject::AUTO_WRITE53 ),54 mesh55 );56 // Add the following to initialize the velocity gradient field:57 volScalarField UGrad58 (59 IOobject60 (61 "UGrad",62 runTime.timeName(),63 mesh,64 IOobject::READ_IF_PRESENT,65 IOobject::AUTO_WRITE66 ),67 mag(fvc::grad(U))68 );

The gradient of the velocity magnitude is calculated by mag(fvc::grad(U)). Since it is calculatedwhen it is initialized, it does not have to be supplied as a initial value with the case. Save and closecreateFields.H. Now it is time to modify the actual solver. Start by editing mySprayDyMFoam.C.

12

Page 14: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 3. REFINEMENT BASED ON THE GRADIENT OF A FIELD

Add the expression for the velocity gradient after the initialization of the rhoU volVectorFieldinside of the run() function.

C++ Code 3.2: mySprayDyMFoam.C

89 // Store momentum to set rhoUf for introduced faces.90 volVectorField rhoU("rhoU", rho*U);91

92 // Add the calculation of the velocity gradient before the mesh changes93 UGrad = mag(fvc::grad(U));

Save and close mySprayDyMFoam.C, and then clean and compile:

Bash Code 3.5: Clean and compile

wcleanwmake

13

Page 15: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

Chapter 4

Case Set-up

To test the mesh refinement with a moving mesh we are going to use a modified version of theAachen bomb case. The Aachen bomb is a spray chamber where fuel is injected at the top. Thedomain is shown in figure 4.1. We are going to modify it so that it will shrink gradually during thesimulation while it is refining the mesh based on the gradient of the velocity field.

Figure 4.1: The Aachen Bomb Case

14

Page 16: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 4. CASE SET-UP

4.1 Pre-ProcessingStart by copying the aachenBomb case to your run folder:

Bash Code 4.1: Copy and rename the aachenBomb case

runcp -r $FOAM_TUTORIALS/lagrangian/sprayFoam/aachenBomb .mv aachenBomb shrinkingAachenBombcd shrinkingAachenBomb

Then we need to modify the blockMeshDict (Note that the blockMeshDict is located in system/ inOpenFOAM-3.0.x). Two new patches has to be created from the top and bottom of the domain. Onepatch called movingwall, on which we will later prescribe the mesh motion. And a another one calledfixedWall. We will also reduce the mesh size to speed up the simulation and to better illustrate therefinement around the spray cone. Remove the contents from the current system/blockMeshDict,and replace it with OpenFoamDictionary 4.1.

15

Page 17: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 4. CASE SET-UP

OpenFoam Dictionary 4.1: system/blockMeshDict

FoamFile{version 2.0;format ascii;class dictionary;object blockMeshDict;}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //convertToMeters 0.001;vertices((-10 0 -10)(-10 0 10)(10 0 10)(10 0 -10)(-10 100 -10)(-10 100 10)(10 100 10)(10 100 -10));blocks(hex (0 1 2 3 4 5 6 7) (11 11 20) simpleGrading (1 1 1));edges();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)));mergePatchPairs();

Now the bottom patch is called moving wall, and we can specify it as such in the set-up later Tocreate the mesh run blockMesh:

16

Page 18: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 4. CASE SET-UP

Bash Code 4.2: Create mesh

blockMesh

The boundary conditions for this case are the same as the original aachenBomb case, except for thevelocity. However, all initial files need to be edited to correspond to the newly created patches. Thiscan be easily done by using the sed command:

Bash Code 4.3: Edit the initial files to correspond to new patch names

sed -r -i s/walls/’"(movingWall|fixedWall|walls)"’/g 0/*sed -i ’s/movingWall//’ 0/Used -i ’28,$’d 0/Uecho -e "movingWall{type movingWallVelocity;value uniform ( 0 0 0 );}}" >> 0/U

[Create 0/pointMotionUy] In addition to the initial files that is included in the aachenBomb case, anew file pointMotionUy has to be created:

Bash Code 4.4

touch 0/pointMotionUy

pointMotionUy is used to prescribe the motion of the moving wall. Edit pointMotionUy and copythe content of OpenFoam Dictionary 4.2 into the file.

17

Page 19: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 4. CASE SET-UP

OpenFoam Dictionary 4.2: 0/pointMotionUy

FoamFile{version 2.0;format ascii;class pointScalarField;object pointMotionUy;}// ************************************************************************* //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;}}// ************************************************************************* //

4.2 Solver Set UpSince we are running a case with a moving mesh, we need a constant/dynamicMeshDict to specifyoptions for the mesh motion and for the refinement. Create and edit a file, constant/dynamicMeshDict.Copy and insert the contents of OpenFoam Dictionary 4.2 into constant/dynamicMeshDict. Nowthe mesh will be refined if the velocity gradient is between 10 000 and 70 000 s−1. If it falls be-low 10 000 s−1, the mesh will be unrefined. The fluxes for U and rhoUf will also be interpolatedagain.

18

Page 20: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 4. CASE SET-UP

OpenFoam Dictionary 4.3: constant/dynamicMeshDict

FoamFile{version 2.0;format ascii;class dictionary;location "constant";object dynamicMeshDict;}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //dynamicFvMesh dynamicMotionSolverRefineFvMesh;motionSolverLibs ( "libfvMotionSolvers.so" );solver velocityComponentLaplacian;

velocityComponentLaplacianCoeffs{component y;diffusivity inverseDistance (movingWall);}

dynamicMotionSolverRefineFvMeshCoeffs{// How often to refinerefineInterval 1;// Field to be refinement onfield UGrad;// Refine field inbetween lower..upperlowerRefineLevel 10000;upperRefineLevel 70000;// If value < unrefineLevel unrefineunrefineLevel 9999;// Have slower than 2:1 refinementnBufferLayers 1;// Refine cells only up to maxRefinement levelsmaxRefinement 2;// Stop refinement if maxCells reachedmaxCells 200000;correctFluxes((phi U)(phi_0 U_0)(rhorUf phi)(faceDiffusivity none)(meshPhi none)(weights none));dumpLevel true;}

The mesh motion also require some additional entries to fvSolution and fvSchemes. Firstly add adiscretization scheme for meshPhi.

19

Page 21: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 4. CASE SET-UP

Bash Code 4.5: Add a scheme for meshPhi

sed -i ’/div(phi,Yi_h) Gauss upwind;/a div(meshPhi,p) Gauss linear;’ system/fvSolution

We also need to define linear solvers for the cell motion, so add the following to the fvSolutionfile:

Bash Code 4.6

sed -i ’/pFinal/i \cellMotionUy\{\solver PCG;\preconditioner DIC;\tolerance 1e-08;\relTol 0;\}\\"(pcorr|pcorrFinal)"\{\$p;\relTol 0;\}’ system/fvSolution

Bash Code 4.7: Add our motionRefine library to the controlDict

sed -i ’/runTimeModifiable yes;/a libs ("libmotionRefinementFvMesh.so");’ system/controlDict

If the user want a faster simulation and just watch the mesh refinement around the spray cone, wecan also turn of combustion:

Bash Code 4.8: Deactivate combustion

sed -i s/PaSR/noCombustion/g constant/combustionPropertiessed -i s/yes/no/g constant/combustionPropertiessed -i s/psiChemistryCombustion/psiThermoCombustion/g constant/combustionProperties

Now the simulation can be executed by running:

Bash Code 4.9: Run Simulation

mySprayDyMFoam

4.3 Post-ProcessingStart post-processing:

20

Page 22: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 4. CASE SET-UP

Bash Code 4.10: Start Paraview

paraFoam

Create a clip filter by clicking on the clip icon in the toolbar. Press the Z-Axis button and then pressapply. Note that we are now looking at a cross section of the domain. Initalize the temperature fieldby ticking the T box under the properties tab. Click on the clip filter in the pipeline browser. Colourthe cross section with T by selecting it from the drop down menu in the toolbar. Then changerepresentation from "surface" to "surface with edges" to visualize the mesh Make sure to turn onVTKPolyhedron to properly visualize the mesh. Click the play button to visualize how the domainshrinks and how the mesh is refined near the injection where velocity gradients are high. Figure 4.2shows how the mesh initially look like. Figure 4.3 show how the mesh looks like after injection whenthe mesh is refined near the injection site.

21

Page 23: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 4. CASE SET-UP

Figure 4.2: Inital Temperature Field and Mesh22

Page 24: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

CHAPTER 4. CASE SET-UP

Figure 4.3: Temperature Field and Mesh after 0.006 seconds23

Page 25: Projectwork: AdaptiveMeshRefinementwithaMoving ...hani/kurser/OS_CFD_2015/AndreasNygren/Tutorial... · Chapter1 Introduction 1.1 Introduction When performing CFD simulations it is

Bibliography

[1] C. J Greenshields. OpenFOAM Programmer’s Guide.

[2] OpenFoam Foundation Ltd. OpenFOAM Source Code, 2015.

24