29
How to make a dynamicMotionRefineFvMesh class Questions CFD with OpenSource Software How to make a dynamicMotionRefineFvMesh class Bjarke Eltard-Larsen Mechanical Engineering, Technical University of Denmark 2015-12-01 Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 1 / 29

CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

  • Upload
    others

  • View
    12

  • Download
    1

Embed Size (px)

Citation preview

Page 1: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

CFD with OpenSource SoftwareHow to make a dynamicMotionRefineFvMesh class

Bjarke Eltard-Larsen

Mechanical Engineering,Technical University of Denmark

2015-12-01

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 1 / 29

Page 2: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Learning outcomes

Learning outcomes

Upon completion of this tutorial the follower should be able to do thefollowing.

Explain how a dynamicMotionRefineFvMesh class can be usefull inthe study of tsunamis and their interaction with the seabed.

Understand functionality of the dynamicRefineFvMesh class.

Understand the functionality of the motionSolverFvMesh class.

Adapt the damBreak case to work with dynamic mesh refinement.

Implement the dynamicMotionRefineFvMesh class by following theinstructions of this tutorial

(Set up the damBreak case to work with both dynamic meshrefinement and moving mesh.)

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 2 / 29

Page 3: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Introduction

Motivation

Tsunami seabed interaction

The incoming tsunami changesthe morphology of the beach− > moving mesh is needed

The scales of the tsunami are solarge that refinement along thesurface could savecomputational time − >dynamic mesh refinement isneeded

Source: http://www.theatlantic.com/photo/

2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 3 / 29

Page 4: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Introduction

The dynamicFvMesh class

staticFvMesh: No mesh motion.

dynamicInkJetFvMesh: The mesh motion is described by an equationinside the class.

motionSolverFvMesh: The motion of the mesh is solved for byspecifying a boundary condition and a diffusivity model.

dynamicRefineFvMesh: Points are added or removed to refine orunrefine the mesh.

solidBodyMotionFvMesh: Solid body motion of the mesh is specifiedby a motion function.

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 4 / 29

Page 5: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Introduction

dynamicMotionSolverFvMesh

Requires a boundary condition anddiffusivity model.

The solver can be velocityLaplacian orpositionLaplacian (specified indynamicMeshDict)Diffusivity model can be quality based ordistance based (specified indynamciMeshDict).Particulars of the boundary conditionsfor the mesh motion is given in the0-directoryInputs for the solution of the movingmesh needs to be given insystem/fvSolution

The mesh of the movingCone tutorial

at (top) t =0 s and (bottom) t = 0.0008 s

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 5 / 29

Page 6: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Introduction

dynamicRefineFvMesh

The mesh is refined/unrefined byadding or removing points

Inputs are given in thedynamicMeshDict

refineIntervalfieldlowerRefineLevelupperRefineLevelunrefineLevelnBufferLayersmaxRefinementmaxCellscorrectFluxes The mesh of the damBreakWithObstacle tutorial

at (top) t =0 s and (bottom) t = 0.02 s

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 6 / 29

Page 7: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Copying and renaming the dynamicRefineFvMesh

Copying the dynamicRefineFvMesh class

Make a copy of the dynamicRefineFvMesh and put it in the userdirectory

src

cp -r --parents dynamicFvMesh/dynamicRefineFvMesh \

$WM_PROJECT_USER_DIR/src

cd $WM_PROJECT_USER_DIR/src/dynamicFvMesh

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 7 / 29

Page 8: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Copying and renaming the dynamicRefineFvMesh

Renaming the dynamicRefineFvMesh class

Rename the copied class as well as all the files in the class

mv dynamicRefineFvMesh dynamicMotionRefineFvMesh

cd dynamicMotionRefineFvMesh

mv dynamicRefineFvMesh.C dynamicMotionRefineFvMesh.C

mv dynamicRefineFvMesh.H dynamicMotionRefineFvMesh.H

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 8 / 29

Page 9: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Copying and renaming the dynamicRefineFvMesh

Renaming the dynamicRefineFvMesh class

Inside dynamicMotionRefineFvMesh.C anddynamicMotionRefineFvMesh.H, change all occurances ofdynamicRefineFvMesh to dynamicMotionRefineFvMesh

sed -i s/dynamicRefineFvMesh/dynamicMotionRefineFvMesh/g \

dynamicMotionRefineFvMesh.C

sed -i s/dynamicRefineFvMesh/dynamicMotionRefineFvMesh/g \

dynamicMotionRefineFvMesh.H

cd ..

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 9 / 29

Page 10: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Copying and renaming the dynamicRefineFvMesh

Create make/files and make/options

Create Make/files:

mkdir Make

echo "dynamicMotionRefineFvMesh/dynamicMotionRefineFvMesh.C

LIB=\$(FOAM_USER_LIBBIN)/libdynamicMotionRefineFvMesh" >Make/files

Create Make/options:

echo "EXE_INC = \\

-I\$(LIB_SRC)/triSurface/lnInclude \\

-I\$(LIB_SRC)/meshTools/lnInclude \\

-I\$(LIB_SRC)/dynamicMesh/lnInclude \\

-I\$(LIB_SRC)/finiteVolume/lnInclude \\

-I\$(LIB_SRC)/dynamicFvMesh/lnInclude

LIB_LIBS = \\

-ltriSurface \\

-lmeshTools \\

-ldynamicMesh \\

-lfiniteVolume " >Make/optionsBjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 10 / 29

Page 11: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Copying and renaming the dynamicRefineFvMesh

Clean and compile

Clean and compile:

wclean

wmake libso

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 11 / 29

Page 12: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Test compilation

damBreak with mesh refinement

Copy the damBreak tutorial into the user’s run directory

cd $WM_PROJECT_DIR/tutorials/multiphase

cp -r interFoam/laminar/damBreak $FOAM_RUN

Copy dynamicMeshDict, fvSolution and fvSchemes from thedamBreakWithObstacle tutorial and place them in your copy of thedamBreak tutorial

cd interDyMFoam/ras/damBreakWithObstacle

cp -r constant/dynamicMeshDict $FOAM_RUN/damBreak/constant

cp -r system/fvS* $FOAM_RUN/damBreak/system

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 12 / 29

Page 13: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Test compilation

Run the tutorial with mesh refinement

Check if the tutorial can run with mesh refinement

cd $FOAM_RUN/damBreak/0

cp -r alpha.water.org alpha.water

cd ..

blockMesh

setFields

sed -i s/"\(endTime[ \t]*\) 1;"/"\1 0.05;"/g system/controlDict

interDyMFoam

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 13 / 29

Page 14: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Test compilation

Running the tutorial with the renamed class

Change all instances of dynamicRefineFvMesh todynamicMotionRefineFvMesh in dynamicMeshDict and specify thetutorial to utilize dynamicMotionRefineFvMesh library

sed -i s/dynamicRefineFvMesh/dynamicMotionRefineFvMesh/g \

constant/dynamicMeshDict

sed -i ’/dynamicFvMesh/i dynamicFvMeshLibs ("libdynamicMotionRefineFvMesh.so");’ \

constant/dynamicMeshDict

Clean up the case and run

rm -rf 0.05

interDyMFoam

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 14 / 29

Page 15: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Implementing the changes

Changes to the .H file

Declare the dynamicMotionRefineFvMesh to be of class motionSolverby inserting the line ”class motionSolver” before the line containing”class dynamicMotionRefineFvMesh”

cd $WM_PROJECT_USER_DIR/src/dynamicFvMesh/dynamicMotionRefineFvMesh

sed -i ’/class dynamicMotionRefineFvMesh/i class motionSolver;’ \

dynamicMotionRefineFvMesh.H

Initialize a pointer needed for moving the mesh by inserting the line”autoPtr<motionSolver> motionPtr ;” after the line containing”PackedBoolList protectedCell ;”.

sed -i ’/PackedBoolList protectedCell_;/a \

autoPtr<motionSolver> motionPtr_;’ \

dynamicMotionRefineFvMesh.H

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 15 / 29

Page 16: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Implementing the changes

Changes to the .C file

Include ”motionSolver.H”

sed -i ’/#include "surfaceInterpolate.H"/i #include "motionSolver.H"’ \

dynamicMotionRefineFvMesh.C

Include the pointer for the moving cells in the constructor call

sed -i ’/protectedCell_(nCells(), 0)/a motionPtr_(motionSolver::New(*this))’ \

dynamicMotionRefineFvMesh.C

sed -i ’/protectedCell_(nCells(), 0)/s/$/,/’ dynamicMotionRefineFvMesh.C

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 16 / 29

Page 17: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Implementing the changes

Insert the code for moving the mesh in the member functions beforethe function for the refinement of the mesh

sed -i ’/bool Foam::dynamicMotionRefineFvMesh::update/{N;s/$/ \

fvMesh::movePoints(motionPtr_->newPoints());/}’ \

dynamicMotionRefineFvMesh.C

sed -i ’/bool Foam::dynamicMotionRefineFvMesh::update/{N;N;s/$/ \

if (foundObject<volVectorField>("U"))/}’ dynamicMotionRefineFvMesh.C

sed -i ’/bool Foam::dynamicMotionRefineFvMesh::update/ {N;N;N;s/$/ \

{/}’ dynamicMotionRefineFvMesh.C

sed -i ’/bool Foam::dynamicMotionRefineFvMesh::update/{N;N;N;N;s/$/ \

volVectorField\& U =/}’ dynamicMotionRefineFvMesh.C

sed -i ’/bool Foam::dynamicMotionRefineFvMesh::update/ {N;N;N;N;N;s/$/ \

const_cast<volVectorField\&>(lookupObject<volVectorField>("U"));/}’ \

dynamicMotionRefineFvMesh.C

sed -i ’/bool Foam::dynamicMotionRefineFvMesh::update/{N;N;N;N;N;N;s/$/ \

U.correctBoundaryConditions();/}’ dynamicMotionRefineFvMesh.C

sed -i ’/bool Foam::dynamicMotionRefineFvMesh::update/{N;N;N;N;N;N;N;s/$/ \

}/}’ dynamicMotionRefineFvMesh.C

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 17 / 29

Page 18: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Implementing the changes

Changes to the .C file

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 18 / 29

Page 19: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Clean and compile

Compile the code

Go back, clean and compile

cd ..

wclean

wmake libso

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 19 / 29

Page 20: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Test compilation

Simple tsunami

Go to the unpacked tutorial ”simpleTsunami”

The ”simpleTsunami” tutorial is build from the damBreak case.

Small changes to mesh (new moving wall)Changed alpha.water fieldInclusion of cellMotionU and pointMotionUchanged dynamicMehsDictfvSolution includes input for cellMotionU

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 20 / 29

Page 21: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Test compilation

Simple tsunami

Run the case by

blockMesh

setFields

interDyMFoam

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 21 / 29

Page 22: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Test compilation

Simple tsunami

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 22 / 29

Page 23: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Further application

Running in parallel

The new class works also in parallel although care must be takenwhen reconstructing

To make the previous simpleTsunami case run in parallel first copythe case to a new case

cd $FOAM_RUN/

mkdir simpleTsunami_parallel

cd $FOAM_RUN/simpleTsunami

cp -r 0 constant system $FOAM_RUN/simpleTsunami_parallel

cd $FOAM_RUN/simpleTsunami_parallel

rm -rf system/decomposeParDict

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 23 / 29

Page 24: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Further application

Create the decomposeParDict file

echo -e "FoamFile \

\n{ \

\nversion 2.0; \

\nformat ascii; \

\nclass dictionary; \

\nlocation "system";

\nobject decomposeParDict; \

\n} \

\n // * * * * * * * * * * * * * * * * * // \

\nnumberOfSubdomains 4; \

\nmethod simple; \

\nsimpleCoeffs \

\n{ \

\nn ( 4 1 1 ); \

\n delta 0.001; \

\n} \

\ndistributed no; \

\nroots ( ); \

" >system/decomposeParDictBjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 24 / 29

Page 25: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Further application

Running in parallel

Run the case by:

blockMesh

setFields

decomposePar

mpirun -np 4 interDyMFoam -parallel >& log&

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 25 / 29

Page 26: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Further application

Reconstruction

Reconstruct the case by

sed -i s/"\(writeFormat[ \t]*\) ascii;"/"\1 binary;"/g \

system/controlDict

reconstructParMesh

reconstructPar

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 26 / 29

Page 27: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Further application

Wave flume

A simple wave flume can be created by periodically moving a side wallof a domain

The wall can be moved utilizing the e.g. the codedFixedValueboundary condition or groovyBC which is part of swak4Foam

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 27 / 29

Page 28: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Further application

Experiences

The class has been experienced to have some problems when themoving boundary and the area of mesh refinement coincides.

Simulation time can be reduced if the refinement interval is reduced.

Specifying other boundary conditions than the standarduniform(x,x,x) is difficult.

I have had success with groovyBC and codedFixedValueI have had problems with timeVaryingMappedFixedValue andoscillatingFixedValue

The previous is believed to have nothing to do with theimplementation of the new class, but with the motionSolverFvMesh

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 28 / 29

Page 29: CFD with OpenSource Software How to make a …hani/kurser/OS_CFD_2015/... · 2016. 1. 14. · 2014/12/ten-years-since-the-2004-indian-ocean-tsunami/100878 Bjarke Eltard-Larsen CFD

How to make a dynamicMotionRefineFvMesh class Questions

Study questions

In tsunami research where can this new class be applied?

In which files are the inputs for all classes of type dynamicFvMeshgiven?

Where are the boundary conditions given if the mesh is moved withthe velocityLaplacian solver?

What is performed first. The mesh movement or the meshrefinement?

Which class does the dynamicMotionRefineMesh inherit from thatmakes it possible to move the mesh?

Bjarke Eltard-Larsen CFD with OpenSource Software 2015-12-01 29 / 29