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: H˚ 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
Embed
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
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
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
Learning outcomes
The reader will learn:
• about snappyHexMesh and cfMesh dictionary for meshing
• How to implement library for moving/dynamic mesh.
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
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:
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
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
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
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
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
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 |
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
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
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
To avoid confusion with original library, it is recommended to rename files. The folders are renamedto myWaveDisplacement.cd ..
mv waveDisplacement myWaveDisplacement
cd myWaveDisplacement
13
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.
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:
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:
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.
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
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.
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:
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
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
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:
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
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
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
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)
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
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
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
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
3.2. USING MYANGULARVELOCITY CHAPTER 3. DEFORMATION OF FISH
Patch U p pointMotionUinlet fixedValue (1,0,0) zeroGradient fixedValue (0,0,0)
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
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
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
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
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
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
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
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
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
5.2. CFMESH CHAPTER 5. APPENDIX
5.2 cfMesh
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | cfMesh: A library for mesh generation |
[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.