Top Banner
CFD with OpenSource software A course at Chalmers University of Technology Taught by H˚ akan Nilsson Project work: Make a fish swim Developed for foam extend 4.0 and Openfoam 1706 version Requires: pimpleDyMFoam, snap- pyHexMesh, cfMesh Author: Sahil Bhagat Peer reviewed by: akan 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. December 11, 2017
41

Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

Aug 09, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

CFD with OpenSource software

A course at Chalmers University of TechnologyTaught by Hakan Nilsson

Project work:

Make a fish swim

Developed for foam extend 4.0 andOpenfoam 1706 versionRequires: pimpleDyMFoam, snap-pyHexMesh, cfMesh

Author:Sahil Bhagat

Peer reviewed by:

Hakan 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 gone

through 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.

December 11, 2017

hani
Typewritten Text
Cite as: Bhagat, S.: Make a fish swim. In Proceedings of CFD with OpenSource Software, 2017, Edited by Nilsson. H., http://dx.doi.org/10.17196/OS_CFD#YEAR_2017
hani
Cross-Out
hani
Typewritten Text
The final report was not peer-reviewed, neither reviewed in detail by the assistants nor the examiner. The reason for this is that it had issues at the time of the peer-review process, and when they had been addressed the peer-review process was finished. The report should be read taken that into account.
hani
Cross-Out
Page 2: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

Learning outcomes

The reader will learn:

• about snappyHexMesh and cfMesh dictionary for meshing

• How to implement library for moving/dynamic mesh.

• Point patch motion

1

Page 3: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

Contents

1 Geometry 31.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Geometry Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 Case Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.3.1 Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3.2 Using snappyHexMesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.3.3 Using cfMesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2 Mesh Motion 132.1 myWaveDisplacement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.1.1 Original library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.1.2 Implementing patch deformation into user library . . . . . . . . . . . . . . . . 16

2.2 myAngularVelocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162.2.1 Original library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

2.3 Implementing patch deformation into user library . . . . . . . . . . . . . . . . . . . . 192.4 dynamicMeshDict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

3 Deformation of fish 243.1 Using myWaveDisplacement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3.1.1 Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.1.2 Mesh motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3.2 Using myAngularVelocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283.2.1 Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283.2.2 Mesh Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

4 Discussion 33

5 Appendix 345.1 snappyHexMeshDict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345.2 cfMesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

2

Page 4: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

Chapter 1

Geometry

1.1 Background

Water is the natural habitat of a fish. Some fishes can change their body shape to generate specialswimming abilities. Crucian carp (Carassius carassius) is an example of phenotypic plasticity inbody shapes which makes it special for understanding the relation between its body form andfunction. These fishes have an induced morphological defence against Pike (Esox Lucius) predation.The anti-predator adpation is achieved by transforming to deep bodied in the presence of Pikeand shallow bodied in the absence of Pike. Deep bodied Crucian carp can attain higher speed,acceleration and turning radius. One of the reason of enhanced performance could be an increasedmuscle mass during anti-predator adaption.In this project, a geometry of Crucian carp is converted to STL form. Geometry is then meshedusing available openfoam utilites and then finally a pointwise mesh motion is implemented using alibrary.

1.2 Geometry Preparation

A fish model, Hera, which is a type of Crucian carp is used to create geometry for test case. Netfabbis used to generate a clean STL (StereoLithoGraphy) file of the fish model.

Figure 1.1: Fish Geometry(.STL).

3

Page 5: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

1.3. CASE SETUP CHAPTER 1. GEOMETRY

1.3 Case Setup

A general setup for the case has to be created in the user directory. Three required folders are0, constant and system. 0 folder has initial values for the fields. constant folder containstransportProperties, mesh related files and dictionaries like polyMesh and dynamicMeshDict.system has controlDict, fvSchemes, fvSolution where discretisation schemes, flow solvers etcare specified. Files related to mesh generation are also specified in system folder.A test case is created by typing:

mkdir $WM_PROJECT_USER_DIR/run/Fish

All three above mentioned folders are added to the folder Fish. Properties of water are addedin transportProperties. Case file for this project can be extracted from here or through coursehomepage.

1.3.1 Mesh

Fish geometry is meshed using two automatic mesh generator, snappyHexMesh utility and cfMeshutility in openfoam. blockMeshDict is used to create a background mesh of hexahedral cells so asto bound the fish in a box and simulate for mesh motion and flow around the fish. blockMeshDictis present in constant/polyMesh. A block/box of (1.25m, 0.55m, 0.6m) is created. Command forblockMesh are as follows:

cd $WM_PROJECT_USER_DIR/Fish

blockMesh

blockMeshDict is shown below:

convertToMeters 1;

vertices

(

(-0.25 -0.2 -0.2)

(1 -0.2 -0.2)

(1 0.35 -0.2)

(-0.25 0.35 -0.2)

(-0.25 -0.2 0.4)

(1 -0.2 0.4)

(1 0.35 0.4)

(-0.25 0.35 0.4)

);

blocks

(

hex (0 1 2 3 4 5 6 7) (40 15 15) simpleGrading (1 1 1)

);

edges

(

);

boundary

(

frontAndBack

{

type patch;

4

Page 6: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

1.3. CASE SETUP CHAPTER 1. GEOMETRY

faces

(

(3 7 6 2)

(1 5 4 0)

);

}

inlet

{

type patch;

faces

(

(0 4 7 3)

);

}

outlet

{

type patch;

faces

(

(2 6 5 1)

);

}

lowerWall

{

type wall;

faces

(

(0 3 2 1)

);

}

upperWall

{

type patch;

faces

(

(4 5 6 7)

);

}

);

1.3.2 Using snappyHexMesh

The snappyHexMesh utility automatically generates a 3-D mesh of hexahedral and split-hexahedralfrom STL or OBJ format. To run the utility of snappyHexMesh, STL needs to be copied toconstant/triSurface folder. Background mesh is generated using blockMeshDict as describedabove. Dictionary snappyHexMeshDict is copied to system folder. Complete snappyHexMeshDict

for this project is shown in Appendix5. Mesh can be generated by typing snappyHexMesh.

cd $WM_PROJECT_USER_DIR/run/Fish

snappyHexMesh -overwrite

where -overwrite command overwrites existing mesh files.

Stages of meshing can be controlled by switching boolean to true and false. Three main stagesare castellatedMesh, snap and addLayers.

5

Page 7: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

1.3. CASE SETUP CHAPTER 1. GEOMETRY

// Which of the steps to run

castellatedMesh true;

snap true;

addLayers true;

Surface file (.STL) to be meshed is copied to constant/triSurface folder. Under geometry, patchor region around which refinement needed is specified. The patch/region can also be renamed whilemeshing. In this project, the region is named as fish. A region or a bounding box can be specifiedunder geometry which is required for refinement. In this tutorial, a sphere and cylinder is specifiedso as to refine the mesh close to fish body. This is done to capture better resolution of motionparameters close to fish patch.

geometry

{

fish.stl

{

type triSurfaceMesh;

name fish;

regions

{

fish

{

name fish;

}

}

}

refinement1

{

type searchableSphere;

centre (0.05 0.08 0.087);

radius 0.09;

}

refinement2

{

type searchableCylinder;

point1 (0.05 0.08 0.87);

point2 (0.5 0.08 0.87);

radius 0.12;

}

};

Under castellatedMeshControls, entries are made which is needed for cell splitting. Two en-teries under region in refinementSurfaces indicates minimum and maximum level of refinement.Minimum level of refinement is applicable to all cells along the surface whereas maximum level isapplicable when intersecting cells form an angle larger than refinementSurfaces. Refinement in aspecific region is defined under refinementRegions. Mode inside indicates that the volume to berefined is inside the region of refinement. Other available options are outside and distance. Firstentry in levels correspond to distance of refinement from the surface and second entry correspondsto level of refinement. For inside and outside mode, default entry for distance (i.e. first entry forlevels) is 0.

6

Page 8: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

1.3. CASE SETUP CHAPTER 1. GEOMETRY

// Settings for the castellatedMesh generation.

castellatedMeshControls

{

// Refinement parameters

// ~~~~~~~~~~~~~~~~~~~~~

maxLocalCells 100000;

maxGlobalCells 2000000;

minRefinementCells 100;

nCellsBetweenLevels 1;

// Explicit feature edge refinement

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

features

();

// Surface based refinement

// ~~~~~~~~~~~~~~~~~~~~~~~~

refinementSurfaces

{

fish

{

// Surface-wise min and max refinement level

level (4 4);

}

}

// Resolve sharp angles

resolveFeatureAngle 30;

refinementRegions

{

refinement1

{

mode inside;

levels ((0.0 3));

}

refinement2

{

mode inside;

levels ((0.0 4));

}

}

7

Page 9: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

1.3. CASE SETUP CHAPTER 1. GEOMETRY

// Mesh selection

// ~~~~~~~~~~~~~~

locationInMesh (-0.2 0.075 0.1);

allowFreeStandingZoneFaces false;

}

The castellated mesh has to be leveled with the STL surfaces. Entries for this snapping process isdefined under snapControls. Iterations for smoothing, snapping relaxation etc. are mentioned hereas shown.

// Settings for the snapping.

snapControls

{

nSmoothPatch 3;

tolerance 4.0;

nSolveIter 30;

nRelaxIter 5;

}

Additional layers can be added under addLayersControls. This helps to add layers at the boundarysurfaces of the patch which may have irregular cells after snapping. Patch for snapping is calledunder layers and several other features like nSurfacelayers, expansionRatio etc are available todefine the layer as required.

// Settings for the layer addition.

addLayersControls

{

relativeSizes true;

// Per final patch (so not geometry!) the layer information

layers

{

}

// Expansion factor for layer mesh

expansionRatio 1.0;

finalLayerThickness 0.3;

minThickness 0.1;

nGrow 0;

// Advanced settings

featureAngle 30;//60;

nRelaxIter 3;

8

Page 10: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

1.3. CASE SETUP CHAPTER 1. GEOMETRY

nSmoothSurfaceNormals 1;

nSmoothNormals 3;

nSmoothThickness 10;

maxFaceThicknessRatio 0.5;

maxThicknessToMedialRatio 0.3;

minMedianAxisAngle 130;

nBufferCellsNoExtrude 0;

nLayerIter 50;

nRelaxedIter 20;

}

Quality of the mesh can be controlled by giving entries to various features under meshQualityControls.Cell skewness, non-orthogonality, twist and many more parameters can be specified to control meshquality.

meshQualityControls

{

maxNonOrtho 65;

maxBoundarySkewness 20;

maxInternalSkewness 4;

maxConcave 80;

minVol 1e-20;

minTetQuality 1e-30;

minArea -1;

minTwist 0.02;

minDeterminant 0.001;

minFaceWeight 0.02;

minVolRatio 0.01;

minTriangleTwist -1;

// Advanced

nSmoothScale 4;

errorReduction 0.75;

}

9

Page 11: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

1.3. CASE SETUP CHAPTER 1. GEOMETRY

Generated mesh can be seen in Figure 1.2 and 1.3. Patch for fish is shown in Figure 1.2. A slicedsection of mesh is shown in Figure 1.3.

(a) Fish patch (b) Fish inside box patch

Figure 1.2: Mesh using snappyHexMesh.

(a) Section along z-axis (b) Section along x-axis

Figure 1.3: Sectional view of mesh.

1.3.3 Using cfMesh

cfMesh is another utility used for meshing in this project. cfMesh utility is available in foam-extend-4.0. So, case file is copied to user directory in foam-extend and meshed. Foam-extend 4.0 is initializedin new terminal. Meshing utility can be run by typing cartesianMesh.

fe40

cd $WM_PROJECT_USER_DIR/run

cp -r /home/sahil/OpenFOAM/sahil-plus/run/Fish .

cd Fish

cartesianMesh

To run cfMesh utility, a dictionary meshDict must be defined in system folder. Unlike snappyHexMesh,surface file should be saved directly in the case folder instead of constant/triSurface. Boundingbox is defined in the same STL of fish. So, blockMeshDict is not required. Maximum and minimumcell size can be defined under maxCellSize and minCellSize respectively. Patches can be renamedunder renameBoundary sub-dictionary. As compared to snappyHexMeshDict, number of featuresto control the mesh are limited. To limit mesh size, fins are removed to generate a coarse mesh.meshDict is shown below:

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | cfMesh: A library for mesh generation |

| \\ / O peration | |

| \\ / A nd | Author: Franjo Juretic |

| \\/ M anipulation | E-mail: [email protected] |

10

Page 12: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

1.3. CASE SETUP CHAPTER 1. GEOMETRY

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "system";

object meshDict;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

surfaceFile "fish.stl";

maxCellSize 0.05;

minCellSize 0.0060;

renameBoundary

{

defaultName walls;

defaultType wall;

newPatchNames

{

"inlet"

{

newName inlet;

Type patch;

}

"outlet"

{

newName outlet;

Type patch;

}

"fish"

{

newName fish;

Type wall;

}

}

}

// ************************************************************************* //

Mesh generated with help of cfMesh can be seen in Figure 1.4 and 1.5. Fish patch and fish in boxis shown in Figure 1.4. A sliced section of mesh is shown in Figure 1.5.

11

Page 13: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

1.3. CASE SETUP CHAPTER 1. GEOMETRY

(a) Fish Patch. (b) Fish inside box patch.

Figure 1.4: Mesh using cfMesh.

(a) Section along z-axis (b) Section along x-axis

Figure 1.5: Sectional view of mesh.

12

Page 14: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

Chapter 2

Mesh Motion

In this project, mesh motion is achieved by point-wise deformation of mesh patches. Two differentlibraries are implemented to illustrate motion of the fish.

2.1 myWaveDisplacement

A fish may exhibit different motions to swim and maneuver. In this project, motion of fish is basedon the swimming motion described in a journal paper[5]. In the paper[5], authors have observed themotion of giant danio (Danio malabaricus). Giant danio is found to exhibit a transverse motion inthe form of equation:

y(x, t) = a(x) sin (kx− ωt) (2.1)

where a(x) is the amplitude given in following quadratic form:

a(x) = c1x+ c2x2 (2.2)

where c1 and c2 are adjustable coefficients. Above mentioned equations are implemented in a libraryand then mesh motions are visualized on the fish in this project.A library is selected which can rotate patch in a wavy motion. Openfoam environment is set usingcommand:OF1706+Original library can be found in:$FOAM_SRC/fvMotionSolver/pointPatchFields/derived/waveDisplacement

Original library is copied to user directory along with Make folder:cd $WM_PROJECT_USER_DIR

mkdir src

cd src

cp -r $FOAM_SRC/fvMotionSolver/pointPatchFields/derived/ \

waveDisplacement .

cp -r $FOAM_SRC/fvMotionSolver/Make .

cd $FOAM_RUN/waveDisplacement

wclean

To avoid confusion with original library, it is recommended to rename files. The folders are renamedto myWaveDisplacement.cd ..

mv waveDisplacement myWaveDisplacement

cd myWaveDisplacement

13

Page 15: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.1. MYWAVEDISPLACEMENT CHAPTER 2. MESH MOTION

Renaming waveDisplacementPointPatchVectorField.C and .H files tomyWaveDisplacementPointPatchVectorField.C and .H. Also, it is necessary to change all thenames in .H and .C files from waveDisplacement to myWaveDisplacement.

mv waveDisplacementPointPatchVectorField.H myWaveDisplacement\

PointPatchVectorField.H

mv waveDisplacementPointPatchVectorField.C myWaveDisplacement\

PointPatchVectorField.C

sed -i 's/waveDisplacement/myWaveDisplacement/g' myWaveDisplacement\

PointPatchVectorField.C

sed -i 's/waveDisplacement/myWaveDisplacement/g' myWaveDisplacement\

PointPatchVectorField.H

It is required to edit the files and options files inside the Make folder. Make/files looks like:

myWaveDisplacementPointPatchVectorField.C1

2

LIB = $(FOAM_USER_LIBBIN)/myWaveDisplacement3

USER is added in line 3 to compile a separate library in user directory and to keep the clean originalopenfoam libraries.Now the library can be complied from myWaveDisplacement folder by typing:wmake libso

This library has to be recognised in case file. This can be done by adding a line,libs("myWaveDisplacement.so")

at the end of system/controlDict.

2.1.1 Original library

A brief explanation of original library is discussed in this section. It is necessary to declare andinitialize variables. Declaration is done in waveDisplacementPointPatchVectorField.H. Origi-nal waveDisplacementPointPatchVectorField.H file declares variables like amplitude, omega andwave number as shown:

class myWaveDisplacementPointPatchVectorField

:

public fixedValuePointPatchField<vector>

{

// Private data

vector amplitude_;

scalar omega_;

vector waveNumber_;

waveDisplacementPointPatchVectorField.C has four constructors to initialize the values for vari-ables defined in .H file. One of the constructor looks up for the value in 0/pointDisplacement file.The constructor that initializes value from look up table is shown below:

Foam::myWaveDisplacementPointPatchVectorField::

myWaveDisplacementPointPatchVectorField

(

14

Page 16: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.1. MYWAVEDISPLACEMENT CHAPTER 2. MESH MOTION

const pointPatch& p,

const DimensionedField<vector, pointMesh>& iF,

const dictionary& dict

)

:

fixedValuePointPatchField<vector>(p, iF, dict),

amplitude_(dict.lookup("amplitude")),

omega_(readScalar(dict.lookup("omega"))),

waveNumber_(dict.lookupOrDefault<vector>("waveNumber", Zero)),

defTime_(readScalar(dict.lookup("defTime")))

{

if (!dict.found("value"))

{

updateCoeffs();

}

}

Equation of motion is defined under updateCoeffs which is a member function in .C file. Operator’=’ is redefined to include displacement of points in a deformed patch. Finally, write function printsout data of control variables. updateCoeffs and write functions are shown below:

void Foam::waveDisplacementPointPatchVectorField::updateCoeffs()

{

if (this->updated())

{

return;

}

const polyMesh& mesh = this->internalField().mesh()();

const Time& t = mesh.time();

const scalarField points( waveNumber_ & patch().localPoints());

Field<vector>::operator=

(

amplitude_*cos(omega_*t.value() - points)

);

fixedValuePointPatchField<vector>::updateCoeffs();

}

void Foam::waveDisplacementPointPatchVectorField::write(Ostream& os) const

{

pointPatchField<vector>::write(os);

os.writeKeyword("amplitude")

<< amplitude_ << token::END_STATEMENT << nl;

os.writeKeyword("omega")

<< omega_ << token::END_STATEMENT << nl;

os.writeKeyword("waveNumber")

<< waveNumber_ << token::END_STATEMENT << nl;

writeEntry("value", os);

}

15

Page 17: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.2. MYANGULARVELOCITY CHAPTER 2. MESH MOTION

2.1.2 Implementing patch deformation into user library

In this section, mesh motion is implemented into the user library i.e. myWaveDisplacement. Re-quired variables are declared and initialized in the original files. Patch deformation is implementedusing equation 2.1 and 2.2. Equation 2.1 is implemented in line 120. Equation 2.2 is implementedusing a scalar amplitude_ and a factor of xCoord+2*xCoord*xCoord.

void Foam::myWaveDisplacementPointPatchVectorField::updateCoeffs()105

{106

if (this->updated())107

{108

return;109

}110

111

const polyMesh& mesh = this->internalField().mesh()();112

const Time& t = mesh.time();113

114

const scalarField points( waveNumber_ & patch().localPoints());115

scalarField xCoord = patch().localPoints().component(vector::X);116

117

Field<vector>::operator=118

(119

amplitude_*(xCoord+2*xCoord*xCoord)*sin(omega_*t.value() - points)120

);121

122

fixedValuePointPatchField<vector>::updateCoeffs();123

}124

125

2.2 myAngularVelocity

Another library myAngularVelocity is implemented to deform mesh according to a polynomialfunction. The polynomial function is not the sinusoidal equation but rather equation 2.2 which isthe amplitude of travelling wave during motion. The implementation of library for patch deformationis based on the work by Eysteinn Helgason [2].Here, a library is selected which can rotate patch around a desired axis by defining velocity at eachnode. Compiling library in user directory is same as done in previous section. Openfoam environ-ment is set using command:OF1706+

Original library can be found in:$FOAM_SRC/fvMotionSolver/pointPatchFields/derived/angularOscillatingVelocity

Copying to user directory along with Make folder:cd $WM_PROJECT_USER_DIR

mkdir src

cd src

cp -r $FOAM_SRC/fvMotionSolver/pointPatchFields/derived/ \

angularOscillatingVelocity .

cp -r $FOAM_SRC/fvMotionSolver/Make .

cd $FOAM_RUN/angularOscillatingVelocity

wclean

16

Page 18: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.2. MYANGULARVELOCITY CHAPTER 2. MESH MOTION

Folders are renamed to myAngularOscillatingVelocity.cd ..

mv angularOscillatingVelocity myAngularOscillatingVelocity

cd myAngularOscillatingVelocity

Renaming angularOscillatingVelocityPointPatchVectorField to myAngularOscillating/

VelocityPointPatchVectorField.

mv angularOscillatingVelocityPointPatchVectorField.H myAngularOscillatingVelocity\

PointPatchVectorField.H

mv angularOscillatingVelocityPointPatchVectorField.C myAngularOscillatingVelocity\

PointPatchVectorField.C

sed -i 's/angularOscillating/myAngularOscillating/g' myAngularOscillatingVelocity\

PointPatchVectorField.C

sed -i 's/angularOscillating/myAngularOscillating/g' myAngularOscillatingVelocity\

PointPatchVectorField.H

Editing Make/files for user library:

myAngularOscillatingVelocityPointPatchVectorField.C126

127

LIB = $(FOAM_USER_LIBBIN)/myAngularOscillatingVelocity128

Now the library can be complied from myAngularOscillatingVelocity folder by typing:wmake libso

This library has to be recognised in case file. This can be done by adding a line,libs("myAngularOscillatingVelocity.so")

at the end of system/controlDict.

2.2.1 Original library

A brief explanation of original library is discussed in this section. It is necessary to declare and ini-tialize variables. Declaration is done in angularOscillatingVelocityPointPatchVectorField.H.Original angularOscillatingVelocityPointPatchVectorField.H file declares variables like axis,origin etc as shown:

class angularOscillatingVelocityPointPatchVectorField49

:50

public fixedValuePointPatchField<vector>51

{52

// Private data53

54

vector axis_;55

vector origin_;56

scalar angle0_;57

scalar amplitude_;58

scalar omega_;59

60

pointField p0_;61

angularOscillatingVelocityPointPatchVectorField.C has four constructors to initialize thevalues for variables defined in .H file. One constructor looks up for the value in 0/pointMotionU file.

17

Page 19: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.2. MYANGULARVELOCITY CHAPTER 2. MESH MOTION

angularOscillatingVelocityPointPatchVectorField::56

angularOscillatingVelocityPointPatchVectorField57

(58

const pointPatch& p,59

const DimensionedField<vector, pointMesh>& iF,60

const dictionary& dict61

)62

:63

fixedValuePointPatchField<vector>(p, iF, dict),64

axis_(dict.lookup("axis")),65

origin_(dict.lookup("origin")),66

angle0_(readScalar(dict.lookup("angle0"))),67

amplitude_(readScalar(dict.lookup("amplitude"))),68

omega_(readScalar(dict.lookup("omega")))69

{70

if (!dict.found("value"))71

{72

updateCoeffs();73

}74

75

if (dict.found("p0"))76

{77

p0_ = vectorField("p0", dict , p.size());78

}79

else80

{81

p0_ = p.localPoints();82

}83

}84

Calculation for deformation is defined under updateCoeffs which is a member function in .C file.Operator ’=’ is redefined to include velocity at nodes in a deformed patch. write function printsout data of control variables. updateCoeffs and write functions are shown below:

void angularOscillatingVelocityPointPatchVectorField::updateCoeffs()151

{152

if (this->updated())153

{154

return;155

}156

157

const polyMesh& mesh = this->internalField().mesh()();158

const Time& t = mesh.time();159

const pointPatch& p = this->patch();160

161

scalar angle = angle0_ + amplitude_*\sin(omega_*t.value());162

vector axisHat = axis_/mag(axis_);163

vectorField p0Rel(p0_ - origin_);164

165

vectorField::operator=166

(167

(168

p0_169

+ p0Rel*(\cos(angle) - 1)170

18

Page 20: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.3. IMPLEMENTING PATCH DEFORMATION INTO USER LIBRARYCHAPTER 2. MESH MOTION

+ (axisHat ^ p0Rel*\sin(angle))171

+ (axisHat & p0Rel)*(1 - \cos(angle))*axisHat172

- p.localPoints()173

)/t.deltaTValue()174

);175

176

fixedValuePointPatchField<vector>::updateCoeffs();177

}178

179

180

void angularOscillatingVelocityPointPatchVectorField::write181

(182

Ostream& os183

) const184

{185

pointPatchField<vector>::write(os);186

os.writeKeyword("axis")187

<< axis_ << token::END_STATEMENT << nl;188

os.writeKeyword("origin")189

<< origin_ << token::END_STATEMENT << nl;190

os.writeKeyword("angle0")191

<< angle0_ << token::END_STATEMENT << nl;192

os.writeKeyword("amplitude")193

<< amplitude_ << token::END_STATEMENT << nl;194

os.writeKeyword("omega")195

<< omega_ << token::END_STATEMENT << nl;196

p0_.writeEntry("p0", os);197

writeEntry("value", os);198

}199

2.3 Implementing patch deformation into user library

In this section, pointwise mesh motion is implemented in user library i.e. myAngularOscillatingVelocity.Patch deformation is implemented using a polynomial function. Based on equation 2.2, polynomialfunction has the following form:

z = X2× x2 +X1× x (2.3)

Input variables are declared in myAngularOscillatingVelocityPointPatchVectorField.H file.New coordinate system is set up to describe a surface in any direction by only x and y. xAxis

in line 63 denotes transformation from fixed coordinate system. origin denotes the origin of newcoordinate system. defTime denotes the time for deformation. periodic is used to trigger theperiodic motion.

class myAngularOscillatingVelocityPointPatchVectorField49

:50

public fixedValuePointPatchField<vector>51

{52

// Private data53

54

55

vector origin_;56

pointField p0_;57

scalar X2_;58

scalar X1_;59

19

Page 21: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.3. IMPLEMENTING PATCH DEFORMATION INTO USER LIBRARYCHAPTER 2. MESH MOTION

vector xAxis_;60

vector yAxis_;61

scalar periodic_;62

scalar defTime_;63

Input variables are initialized by constructors in myAngularOscillatingVelocity

PointPatchVectorField.C file as shown:

myAngularOscillatingVelocityPointPatchVectorField::39

myAngularOscillatingVelocityPointPatchVectorField40

(41

const pointPatch& p,42

const DimensionedField<vector, pointMesh>& iF43

)44

:45

fixedValuePointPatchField<vector>(p, iF),46

47

origin_(Zero),48

p0_(p.localPoints()),49

X2_(0.0),50

X1_(0.0),51

xAxis_(vector::zero),52

yAxis_(vector::zero),53

periodic_(0.0),54

defTime_(0.0)55

{}56

Deformation is defined using polynomial functions. Points on the patch are selected. Then thesepoints are rotated from fixed coordinate system i.e. (x, y, z), to coordinate system of polynomiali.e. (X,Y, Z). Rotation is carried out with help of Euler angles. N is a line of nodes which is theintersection of xy and XY planes of two coordinate systems. α is the angle between line of nodesand x-axis. β is the angle between z-axis and Z-axis. And γ is the angle between X-axis and lineof nodes N . Matrix for rotation is given as:

p = pR

=[x y z

] cosα − sinα 0sinα cosα 0

0 0 1

1 0 00 cosβ − sinβ0 sinβ cosβ

cos γ − sin γ 0sin γ cos γ 0

0 0 1

On multiplication, it gives :

R =

cosα cos γ − sinα cosβ sin γ − cosα sin γ − sinα cosβ cos γ sinβ sinαsinα cos γ − cosα cosβ sin γ − sinα sin γ − cosα cosβ cos γ − sinβ cosα

sinβ sin γ sinβ cos γ cosβ

(2.4)

Patch motion is implemented in updateCoeffs function. Rotation matrix R is created in line 197.For loop in line 202 implements the polynomial equation in the z-plane of the patch. Patch is rotatedback to original coordinate system in line 208. scalar multipl controls the deformation direction.Periodic motion is defined in line 228. Operator ’=’ is redefined in line 212 to include velocity.updateCoeffs function is shown below:

void myAngularOscillatingVelocityPointPatchVectorField::updateCoeffs()163

{164

if (this->updated())165

{166

20

Page 22: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.3. IMPLEMENTING PATCH DEFORMATION INTO USER LIBRARYCHAPTER 2. MESH MOTION

return;167

}168

169

const polyMesh& mesh = this->internalField().mesh()();170

const Time& t = mesh.time();171

const pointPatch& p = this->patch();172

173

vectorField p0Rel = p0_ - origin_;174

vector zAxis = xAxis_ ^ yAxis_;175

//Original axis used for reference176

vector xAxisOrg = vector(1, 0, 0);177

vector yAxisOrg = vector(0, 1, 0);178

vector zAxisOrg = vector(0, 0, 1);179

180

//Euler Angles181

vector Nline = (xAxisOrg ^ yAxisOrg) ^ (xAxis_ ^ yAxis_);182

scalar alpha = acos(xAxisOrg & Nline);183

scalar beta = acos(zAxisOrg & zAxis);184

scalar gamma = acos(Nline & xAxis_);185

scalar Rrot1(cos(alpha)*cos(gamma)-sin(alpha)*cos(beta)*sin(gamma));186

scalar Rrot2(-cos(alpha)*sin(gamma)-sin(alpha)*cos(beta)*cos(gamma));187

scalar Rrot3(sin(beta)*sin(alpha));188

scalar Rrot4(sin(alpha)*cos(gamma)+cos(alpha)*cos(beta)*sin(gamma));189

scalar Rrot5(-sin(alpha)*sin(gamma)+cos(alpha)*cos(beta)*cos(gamma));190

scalar Rrot6(-sin(beta)*cos(alpha));191

scalar Rrot7(sin(beta)*sin(gamma));192

scalar Rrot8(sin(beta)*cos(gamma));193

scalar Rrot9(cos(beta));194

195

//Rotation Matrix196

tensor Rrot(Rrot1, Rrot2, Rrot3, Rrot4, Rrot5, Rrot6, Rrot7, Rrot8, Rrot9);197

tensor RrotInv = inv(Rrot);198

vector p0rot;199

vectorField sd=p0Rel;200

201

forAll(p0_,iter)202

{203

p0rot = p0Rel[iter] & Rrot; // p relative to new origin rotated204

// Plane from x values calculated and inserted into z values205

p0rot = vector(0, 0, X2_*p0rot[0]*p0rot[0]+X1_*p0rot[0]);206

207

sd[iter] = p0rot & RrotInv; // Plane rotated back to original position208

};209

210

scalar multipl = 1;211

if ( periodic_ == 1 ) // For periodic b.c.212

{213

if (((int)floor(t.value()/defTime_)%2 != 0) && (t.value()> defTime_)) multipl = -2;214

else if (((int)floor(t.value()/defTime_)%2 == 0) && (t.value()> defTime_)) multipl =2;215

216

}217

else if ((periodic_ == 0) && (t.value()> defTime_)) multipl = 0; // No motion218

vectorField::operator=219

(220

21

Page 23: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.4. DYNAMICMESHDICT CHAPTER 2. MESH MOTION

sd *multipl / defTime_221

);222

223

fixedValuePointPatchField<vector>::updateCoeffs();224

}225

226

2.4 dynamicMeshDict

dynamicMesh utility can be used to deform mesh without doing any flow calculations.In Openfoam, there are two approaches for mesh motion i.e. dynamicFvMesh and topoChangerFvMesh.topoChangerFvMesh includes changes in mesh topology whereas dynamicFvMesh doesn’t allow topo-logical changes. In this project, dynamicFvMesh is used so as to maintain mesh topology.Different classes of dynamicFvMesh are:

• dynamicInkJetFvMesh

• dynamicMotionSolverFvMesh

• dynamicMotionSolverListFvMesh

• dynamicMotionSolverTopoFvMesh

• dynamicMultiMotionSolverFvMesh

• dynamicRefineFvMesh

• staticFvMesh

staticFvMesh is used when there is no mesh motions. dynamicMotionSolverFvMesh solves meshmotion of points using diffusivity models and the boundary conditions. This is the simplest solverfor mesh motion. Other classes are improved version of dynamicMotionSolverFvMesh.Quality of mesh and spacing during motion is controlled by different diffusivity models [3]. Diffusivitymodel defines a way to distribute boundary motion through out the mesh. Dynamic library for meshmotion and control is libfvMotionSolvers.so.Different diffusivity models available are:

• displacementLaplacian

• displacementSBRStress

• displacementComponentLaplacian

• multiSolidBodyMotionSolver

• velocityDisplacement

• velocityLaplacian

• velocityComponentLaplacian

Important difference between solvers is the equations that are solved. For example, displacementLaplaciansolves using laplacian of diffusivity and cell displacement. velocityLaplacian solves using laplacianof diffusivity and velocity of cell motion.Diffusivity models are required to define the movements of points while cell motion equations aresolved. Among different diffusion laws, two main methods are used in openfoam [3]:

• Quality based: where diffusion field is a function of cell quantity measure:

1. uniform: where cell motion is uniformly distributed among all cells.

22

Page 24: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

2.4. DYNAMICMESHDICT CHAPTER 2. MESH MOTION

2. directional: where cell compression and extension is done along the direction of motion.Mean cell non-orthogonality and mean cell skewness is defined.

3. motionDirectional: where cell diffusivity is done by giving preference to the motion of thebody.

4. inverseDistance: where cell diffusivity is based on inverse of the distance from the bound-ary. One or more boundaries can be defined.

5. inverseVolume: where cell diffusivity is based on inverse of volume field.

• Distance based : where diffusion field (γ) is a function of cell center distance (l) to the nearestpatch or boundary.

1. quadratic: where diffusion field is a function of inverse of square of the distance. (γ = 1/l2)

2. exponential: where diffusion field is an exponential function of the distance. (γ = e−l)

dynamicMeshDict is required in constant folder for mesh motion. An example of dynamicMeshDictis shown below:

/*--------------------------------*- C++ -*----------------------------------*\1

| ========= | |2

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |3

| \\ / O peration | Version: 4.0 |4

| \\ / A nd | Web: http://www.OpenFOAM.org |5

| \\/ M anipulation | |6

\*---------------------------------------------------------------------------*/7

FoamFile8

{9

version 2.0;10

format ascii;11

class dictionary;12

object dynamicMeshDict;13

}14

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //15

16

dynamicFvMesh dynamicMotionSolverFvMesh;17

18

motionSolverLibs ("libfvMotionSolvers.so");19

20

solver velocityLaplacian;21

22

diffusivity uniform;23

24

// ************************************************************************* //25

23

Page 25: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

Chapter 3

Deformation of fish

Deformation of fish will be shown in this section. Two meshing techniques are used in this project.However, mesh generated using cfMesh utility is used as it produces stable results when simulated.A coarse mesh is used in this case so as to limit the time of simulation. A coarse mesh may not beable to generate correct solution but it is used to show patch deformation. Two libraries are createdto deform the fish and the results are shown in following subsections. Mesh used for test case of fishcan be seen in Figure 3.1. Figure3.1a also illustrates different patches used in the case setup.

(a) Case setup (b) A sliced section

Figure 3.1: Meshing of fish using cfMesh.

3.1 Using myWaveDisplacement

Case files can be accessed from the link in section 1.3. Boundary conditions and results of meshmotion using myWaveDisplacement is discussed in this section.

3.1.1 Boundary Conditions

Initial conditions for the fields is set in 0 folder. U, p and pointDisplacement are three fields in0 folder. Conditions set for fish patch in pointDisplacement is shown below. Since the motion offish is restricted to y-plane, only y-coordinate is entered in amplitude.

fish

{

type myWaveDisplacement;

amplitude (0 0.01 0);

omega 40;

waveNumber (20 0 0);

value uniform (0 0 0);

}

24

Page 26: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

3.1. USING MYWAVEDISPLACEMENT CHAPTER 3. DEFORMATION OF FISH

Enteries for dynamicMeshDict is shown below. displacementLaplacian is used to solve for meshmotion. Diffusivity is solved using quadratic inverseDistance method.

dynamicFvMesh dynamicMotionSolverFvMesh;

motionSolverLibs ("libfvMotionSolvers.so");

motionSolver displacementLaplacian;

diffusivity quadratic inverseDistance 1 (fish);

Inlet velocity Ux = 1 m/s is used as boundary condition on inlet patch (left). Slip condition isused on all the walls. movingWallVelocity is used as boundary condition for U on fish patch dueto moving mesh. myWaveDisplacement is used at pointDisplacement which is the implementedlibrary. This library has to recognised during simulation. So, one extra line has to be added at theend of system/controlDict.

libs ("myWaveDisplacement.so");

Boundary conditions set on different patches are shown in Table 3.1.

Patch U p pointDisplacementinlet fixedValue (1,0,0) zeroGradient fixedValue (0,0,0)

outlet inletOutlet fixedValue (0,0,0) fixedValue (0,0,0)fish movingWallVelocity (0,0,0) zeroGradient myWaveDisplacement

walls slip zeroGradient slip

Table 3.1: Boundary Conditions.

3.1.2 Mesh motion

pimpleDyMFoam is used to generate flow solution. Solver pimpleDyMFoam (’DyM’ indicates dynamicmesh) is a transient solver for incompressible, laminar flow of newtonian fluid on a moving mesh.Following commands to be used to simulate the case:

cd Fish_myWave

pimpleDyMFoam

Time step used is 5e-4 s. Mesh motion and fields can be visualized by typing:paraFoam

Results for mesh motion of fish patch can be seen in Figure 3.4.

25

Page 27: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

3.1. USING MYWAVEDISPLACEMENT CHAPTER 3. DEFORMATION OF FISH

(a) 0.005s

(b) 0.05s

(c) 0.1s

(d) 0.15s

(e) 0.2s

(f) 0.25s

(g) 0.3s

(h) 0.35s

Figure 3.2: Mesh motion at intervals of 0.05s. Time step used is 5e-4s

Figure 3.6 and 3.7 shows velocity and pressure distribution respectively at selected times.

26

Page 28: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

3.1. USING MYWAVEDISPLACEMENT CHAPTER 3. DEFORMATION OF FISH

(a) 0.005s

(b) 0.05s

(c) 0.1s

(d) 0.15s

(e) 0.2s

(f) 0.25s

(g) 0.3s

(h) 0.35s

Figure 3.3: Distribution of velocity at interval of 0.05s

27

Page 29: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

3.2. USING MYANGULARVELOCITY CHAPTER 3. DEFORMATION OF FISH

(a) 0.005s

(b) 0.05s

(c) 0.1s

(d) 0.15s

(e) 0.2s

(f) 0.25s

(g) 0.3s

(h) 0.35s

Figure 3.4: Distribution of pressure at intervals of 0.05s

3.2 Using myAngularVelocity

In this section, the case is simulated using myAngularVelocity library. Again case files can beaccessed from the link in section 1.3.

3.2.1 Boundary Conditions

Initial conditions for p is same as used in section 3.1.1. pointMotionU is required to simulate thecase using myAngularVelocity library. Library is recognised by adding following line at the end ofsystem/controlDict file:libs ("myAngularOscillatingVelocity.so"); Boundary conditions for U, p and pointMotionU

are shown below in Table 3.2.

28

Page 30: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

3.2. USING MYANGULARVELOCITY CHAPTER 3. DEFORMATION OF FISH

Patch U p pointMotionUinlet fixedValue (1,0,0) zeroGradient fixedValue (0,0,0)

outlet zeroGradient fixedValue (0,0,0) fixedValue (0,0,0)fish slip zeroGradient myAngularOscillatingVelocity

walls slip zeroGradient fixedValue (0,0,0)

Table 3.2: Boundary Conditions.

Enteries for dynamicMeshDict is shown below. Here, mesh motion is solved using velocityLaplacianmethod.

dynamicFvMesh dynamicMotionSolverFvMesh;

motionSolverLibs ("libfvMotionSolvers.so");

motionSolver velocityLaplacian;

diffusivity quadratic inverseDistance 1 (fish);

pointMotionU (cell motion velocity) file is required for velocityLaplacian solver. velocityLaplaciansolver solves the laplacian of diffusivity and cell motion velocity [1]. Detailed boundary conditionfish patch as set in 0/pointMotionU is shown below:

fish38

{39

type myAngularOscillatingVelocity;40

origin (0.1 0.08 0.1);41

value uniform (0 0 0);42

X2 -0.4;43

X1 -0.05;44

xAxis (1 0 0);45

yAxis (0 0 -1);46

periodic 1;47

defTime 5e-4;48

}49

pointMotionU boundary condition for fish patch shows that the origin is set as (0.1, 0.08, 0.1). Themotion follows the function f(x, y) = −0.4x2 + 0.05x. Time for deformation is set as 5e− 4s.

3.2.2 Mesh Motion

Mesh motion can be simulated by running the command moveDynamicMesh. Following commandsto be used to simulate the case:

cd Fish_myAngular

pimpleDyMFoam

Time step used is 1e-5 s. Mesh motion and fields can be visualized by typing:paraFoam Figure 3.5 shows mesh motion at selected times.

29

Page 31: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

3.2. USING MYANGULARVELOCITY CHAPTER 3. DEFORMATION OF FISH

(a) 2.5e-3s

(b) 5e-3s

(c) 7.5e-3s

(d) 0.001s

(e) 0.00125s

(f) 0.0015s

Figure 3.5: Mesh motion at different times. Time step used is 1e-5s

Again, pimpleDyMFoam is used to generate flow solution. Figure 3.6 and 3.7 shows velocity andpressure distribution respectively at selected times.

30

Page 32: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

3.2. USING MYANGULARVELOCITY CHAPTER 3. DEFORMATION OF FISH

(a) 2.5e-3s

(b) 5e-3s

(c) 7.5e-3s

(d) 0.001s

(e) 0.00125s

(f) 0.0015s

Figure 3.6: Distribution of velocity at intervals of 2.5e-3 s.

31

Page 33: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

3.2. USING MYANGULARVELOCITY CHAPTER 3. DEFORMATION OF FISH

(a) 2.5e-3s

(b) 5e-3s

(c) 7.5e-3s

(d) 0.001s

(e) 0.00125s

(f) 0.0015s

Figure 3.7: Distribution of pressure at intervals of 2.5e-3 s.

32

Page 34: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

Chapter 4

Discussion

Mesh motion is simulated using dynamicMesh. A good way to start is by selecting a library/solverfor mesh motion which is close to the requirement for project. Thereafter, the library can beimplemented in user directory . Care should be taken in selecting appropriate diffusivity modelfor mesh motions. Among different diffusivity methods, inverse Distance method with quadraticmanipulations is found to generate valid mesh results in this project. During simulations, a smalltime step is used to maintain a courant number close to 1. Field solution is carried for a simplelaminar case. Flow results may differ with a better mesh resolution and complete fish geometry. Inthis project, mesh motion is simulated for only body of the fish. Complete fish geometry includingfins may alter flow solution.Mesh plays an important role in selecting diffusivity models and time step for simulation. Thoughautomatic mesh generator is a user friendly utility, it may be difficult to get a good mesh forcomplicated geometry. Between two meshing utilities used in this project, cfMesh has a limitednumber of parameters to control meshing. To limit simulation time, coarse mesh generated usingcfMesh is used.Mesh motion on the patch is simulated using two different libraries where one generated a sinusoidalwavy motion and other a quadratic motion. The main idea of this project is to begin from scratch,clean the fish geometry and mesh it and finally solve for mesh motion. Pressure and velocitydistribution are shown to illustrate a flow solution in a moving mesh.

33

Page 35: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

Chapter 5

Appendix

5.1 snappyHexMeshDict

// Which of the steps to run

castellatedMesh true;

snap true;

addLayers true;

geometry

{

fish.stl

{

type triSurfaceMesh;

name fish;

regions

{

fish

{

name fish;

}

}

}

refinement1

{

type searchableSphere;

centre (0.05 0.08 0.087);

radius 0.09;

}

refinement2

{

type searchableCylinder;

point1 (0.05 0.08 0.87);

point2 (0.5 0.08 0.87);

radius 0.12;

}

};

34

Page 36: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

5.1. SNAPPYHEXMESHDICT CHAPTER 5. APPENDIX

// Settings for the castellatedMesh generation.

castellatedMeshControls

{

// Refinement parameters

// ~~~~~~~~~~~~~~~~~~~~~

maxLocalCells 100000;

maxGlobalCells 2000000;

minRefinementCells 100;

nCellsBetweenLevels 1;

// Explicit feature edge refinement

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

features

();

// Surface based refinement

// ~~~~~~~~~~~~~~~~~~~~~~~~

refinementSurfaces

{

fish

{

// Surface-wise min and max refinement level

level (4 4);

}

}

// Resolve sharp angles

resolveFeatureAngle 30;

refinementRegions

{

refinement1

{

mode inside;

levels ((0.0 3));

}

refinement2

{

mode inside;

levels ((0.0 4));

}

}

35

Page 37: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

5.1. SNAPPYHEXMESHDICT CHAPTER 5. APPENDIX

// Mesh selection

// ~~~~~~~~~~~~~~

locationInMesh (-0.2 0.075 0.1);

allowFreeStandingZoneFaces false;

}

// Settings for the snapping.

snapControls

{

nSmoothPatch 3;

tolerance 4.0;

nSolveIter 30;

nRelaxIter 5;

}

// Settings for the layer addition.

addLayersControls

{

relativeSizes true;

// Per final patch (so not geometry!) the layer information

layers

{

}

// Expansion factor for layer mesh

expansionRatio 1.0;

finalLayerThickness 0.3;

minThickness 0.1;

nGrow 0;

// Advanced settings

featureAngle 30;//60;

nRelaxIter 3;

nSmoothSurfaceNormals 1;

nSmoothNormals 3;

nSmoothThickness 10;

maxFaceThicknessRatio 0.5;

36

Page 38: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

5.1. SNAPPYHEXMESHDICT CHAPTER 5. APPENDIX

maxThicknessToMedialRatio 0.3;

minMedianAxisAngle 130;

nBufferCellsNoExtrude 0;

nLayerIter 50;

nRelaxedIter 20;

}

meshQualityControls

{

maxNonOrtho 65;

maxBoundarySkewness 20;

maxInternalSkewness 4;

maxConcave 80;

minVol 1e-20;

minTetQuality 1e-30;

minArea -1;

minTwist 0.02;

minDeterminant 0.001;

minFaceWeight 0.02;

minVolRatio 0.01;

minTriangleTwist -1;

// Advanced

nSmoothScale 4;

errorReduction 0.75;

}

// Advanced

debug 0;

mergeTolerance 1e-6;

37

Page 39: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

5.2. CFMESH CHAPTER 5. APPENDIX

5.2 cfMesh

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | cfMesh: A library for mesh generation |

| \\ / O peration | |

| \\ / A nd | Author: Franjo Juretic |

| \\/ M anipulation | E-mail: [email protected] |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "system";

object meshDict;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

surfaceFile "merge.stl";

maxCellSize 0.05;

minCellSize 0.0050;

localRefinement

{

"fish.*"

{

cellSize 0.002;

additionalRefinementLevels 2;

RefinementThickness 0.005;

}

}

boundaryLayers

{

// nLayers 3;

// thicknessRatio 1.2;

// maxFirstLayerThickness 0.5;

patchBoundaryLayers

{

"fish.*"

{

nLayers 2;

thicknessRatio 1.1;

38

Page 40: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

5.2. CFMESH CHAPTER 5. APPENDIX

maxFirstLayerThickness 0.1;

allowDiscontinuity 0;

}

}

}

renameBoundary

{

defaultName walls;

defaultType wall;

newPatchNames

{

"inlet"

{

newName inlet;

Type patch;

}

"outlet"

{

newName outlet;

Type patch;

}

"fish"

{

newName fish;

Type wall;

}

}

}

// ************************************************************************* //

39

Page 41: Project work: Make a sh swim - Thermohani/kurser/OS_CFD_2017/Sahil... · Sahil Bhagat Peer reviewed by: H akan Nilsson Disclaimer: This is a student project work, done as part of

Bibliography

[1] Andreu Oliver Gonzalez. “Mesh motion alternatives in openfoam”. In: OpenSource CFD, ChalmersUniversity (2009).

[2] Eysteinn Helgason. “Point-wise deformation of mesh patches”. In: OpenSource CFD, ChalmersUniversity (2009).

[3] Hrvoje Jasak and Zeljko Tukovic. “Automatic mesh motion for the unstructured finite volumemethod”. In: Transactions of FAMENA 30.2 (2006), pp. 1–20.

[4] CFD Open. “OpenFOAM user guide”. In: OpenFOAM Foundation 2.1 (2011).

[5] MJ Wolfgang et al. “Near-body flow dynamics in swimming fish”. In: Journal of ExperimentalBiology 202.17 (1999), pp. 2303–2327.

40