project work: generating a wake eld using volume forceshani/kurser/os_cfd_2012/anonymous... ·...

67
CFD with OpenSource software A course at Chalmers University of Technology Taught by H˚ akan Nilsson Project work: Generating a wake field using volume forces Developed for OpenFOAM-2.1.x 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. December 8, 2012

Upload: others

Post on 21-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

CFD with OpenSource software

A course at Chalmers University of TechnologyTaught by Hakan Nilsson

Project work:

Generating a wake field using volumeforces

Developed for OpenFOAM-2.1.x

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.

December 8, 2012

Page 2: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Contents

1 Introduction 21.1 The wake field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 interPhaseChangeFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Generating the wake field 32.1 volume forces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 Volume force connection to velocity change . . . . . . . . . . . . . . . . . . . . . . . 32.3 Wake fraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 Implementation in OpenFOAM 53.1 Copying and renaming files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.2 wake.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.3 wake.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.4 interPhaseChangeWakeFoam.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.5 Ueqn.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.6 createFields.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.7 Make/files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.8 Other files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.9 Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.10 Implementation in another solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4 Using the solver 194.1 constant directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.2 0 directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.3 system directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.4 Solving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5 Performance 225.1 Disk thickness effect on axial wake . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.2 Viscous momentum diffussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6 Conclusion and future work 32

A wake.h 34

B wake.cpp 37

C fvSolution 64

Page 3: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Chapter 1

Introduction

Cavitation erosion, noise and vibrations are problems for marine propellers mainly occuring dueto the non-uniform velocity field which the propeller is operating in according Dyne and Bark [1].This non-uniform velocity field is a result from the flow distortion caused by the hull in front of thepropeller and is called the wake field.

For numerical analysis of cavitating propellers the CPU effort could be reduced if the wake fieldis generated without having to include the whole ship. This report describes how to generate awake field using volume forces with the solver interPhaseChangeFoam in OpenFOAM-2.1.x with thelatest version pulled at the time of computation (18/10/2012). The axial component of the wakefield has been generated before as can be seen in Shin, Andersen and Mikkelsen[2]. This projectaims to generate the axial wake field component as well as the lateral ditto. Volume force appliedin a disk has been implemented before in OpenFoam 1.5-dev as can be seen in Svenning [3]. Themethodology chosen to be used for implementation of volume force throughout this project is basedon the one described by Svenning [3].

1.1 The wake field

The wake field results in non-uniform propeller loading which should be avoided especially in thecircumferential direction according to Larsson and Raven [4]. When experimentally measuring thewake field it is usually the wake field without a propeller called nominal wake that is measured.Although the nominal wake field is different from the wake field with operating propeller, calledeffective wake field, the difference is limited and the wake quality can be assessed reasonably wellbased on the nominal wake according to Larsson and Raven [4].

1.2 interPhaseChangeFoam

The solver to be modified is supposed to be transient and take phase change such as cavitationinto account as it should be possible to use the solver for a rotating cavitating propeller. in-terPhaseChangeFoam in OpenFOAM-2.1x is chosen to be used as it is a transient solver for twoincompressible fluids. The solver takes phase change into account by capturing the interface witha Volume of fluid method. The solver includes Merkle, Knuz and SchnerrSauer cavitation models.It uses the PISO algorithm to solve the Navier Stokes equations by first solving the momentumequations (momentum prediction) with pressure from the previous time step followed by solving thepressure equation for the new velocity field followed by velocity correction according to Jasak [5].

2

Page 4: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Chapter 2

Generating the wake field

The wake field is to be generated by adding volume forces in a disk in the computational domain.

2.1 volume forces

Volume forces is forces that acts through the volume of the fluid. Volume force f is added to theNavier stokes equations for incompressible flow, see White [6], in this project to achieve a wantedvelocity field. The Navier stokes with body forces can be seen in eq 2.1.

ρ(∂v

∂t+ v · ∇v) = −∇p + µ∇2v + f (2.1)

2.2 Volume force connection to velocity change

The relationship between the desired velocity change and the applied volume force is assumed toaccord to eq 2.2 where l is the thickness of the volume force disk, v1 the initial velocity and v2 thefinal velocity. The viscous diffussion is assumed to be small if the volume force disk is thin. Thedensity of the fluid is assumed to be constant ie. no phase change is assumed in the volume forcedisk.

f = ρv2|v2| − v21

2l(2.2)

2.3 Wake fraction

The volume force disk to be added is assumed to be symmetric about the axial- upward plane wherethe axial direction is the direction of the disk centerline. To be able to specify only one half ofthe target wake field the third direction making a three dimensional coordinate system is chosen tobe the outward direction. This direction is perpendicular to the axial and upward direction and isalways positive away from the centerline. This means that the outward direction will be oppositevectors depending on which side of the axial- upward plane that is considered.

The wake field is described in terms of wake fraction, defined as w = 1 − VV∞

according toLarsson and Raven [4], where V∞ is the freestream velocity. This leads to the following equationsfor the volume force magnitudes |f | in axial, upward and outward direction as functions of the wakefractions which is to be achieved and hereby referred to as the target wake field.

|faxial| = ρV∞(1− waxial)|V∞(1− waxial)| − V 2

∞2l

(2.3)

|fupward| = ρV∞(1− wupward)|V∞(1− wupward)|

2l(2.4)

3

Page 5: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

2.3. WAKE FRACTION CHAPTER 2. GENERATING THE WAKE FIELD

|foutward| = ρV∞(1− woutward)|V∞(1− woutward)|

2l(2.5)

The wake fractions to be specified by the user are those at the following radial locations rinner,rinner + 1

4 (router − rinner), rinner + 12 (router − rinner), rinner + 3

4 (router − rinner) and router whererinner and router is the inner and outer radius of the target wake field. At the inner radius the wakefield is assumed to be rotational symmetric about the centerline so that only one value needs to begiven for each direction. At all other radii the wake fractions to be given are at 0, 30, 60, 90, 120,150 and 180 degrees to the upward direction.

The wake fraction for a point P located at angle φP between φA and φB and at radius rP betweenrC and rD is calculated by interpolation along radial and circumferential direction according to eq 2.6.

wakeP =

(wakeAC

φB − ΦP

φB − φA+ wakeAD

φP − φA

φB − φA

)rD − rP

rD − rC+

(wakeBC

φB − ΦP

φB − φA+ wakeCD

φP − φA

φB − φA

)rP − rC

rD − rC(2.6)

4

Page 6: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Chapter 3

Implementation in OpenFOAM

The wake field is generated in OpenFOAM by creating a vector field volumeforceField which isnon-zero only in a disk specified by the user. For every cell in this region the target wake fractionsin all three dimensions are calculated using eq 2.6 with wake fractions specified by the user. Themagnitudes of the volume force vector components are calculated from the target wake fractionsaccording to eq 2.3, eq 2.5 and eq 2.4. The volume force vector field is added to the momentumequation in the momentum predictor step in the PISO loop.

3.1 Copying and renaming files

Start by copying the interPhaseChangeFoam solver to a suitable directory. Also copy the file cor-rectPhi.H from the interFoam solver which will be motivated later.

OF21x

foam

cp -r --parent applications/solvers/multiphase/interPhaseChangeFoam

$WM_PROJECT_USER_DIR/

cp applications/solvers/multiphase/interFoam/correctPhi.H $WM_PROJECT_USER_DIR

cd $WM_PROJECT_USER_DIR/

mv correctPhi.H applications/solver/multiphase/interPhaseChangeFoam/

Rename the directory to interPhaseChangeWakeFoam

cd $WM_PROJECT_USER_DIR

cd applications/solvers/multiphase/

mv interPhaseChangeFoam interPhaseChangeWakeFoam

3.2 wake.h

A class with necessary member functions to generate the volume force vector field is declared in theheader file wake.h. For the complete wake.h see appendices.

To avoid multiple inclusions

...

#ifndef wake_H_

#define wake_H_

The fundamental tools for finite volume method is included and the namespace for OpenFOAMnamed Foam is used

5

Page 7: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.2. WAKE.H CHAPTER 3. IMPLEMENTATION IN OPENFOAM

#include "fvCFD.H"

namespace Foam {

The member function Calcvolumeforce is used to calculate the volume force vector field. This is apublic member function as it needs to be reached from outside of the class.

class wake {

public:

TypeName("wake");

wake();

~wake();

void CalcVolumeForce(const fvMesh &iMesh, vectorField &ioVolumeForceField);

The wake.h file also contains declaration of member data variables to contain input data regardingthe volume force disk geometry, flow properties and the target wake field as specified by the user.

private:

vector mStartCenterLine;

vector mEndCenterLine;

vector mvecUp;

scalar mOuterRadius, mInnerRadius;

scalar mFreeStreamVelocity;

scalar mRho;

scalar mAxialR000Phi000,mAxialR025Phi000,...

static const double mPI = 3.141592654;

ReadParameters is a private member function used to read the volume force parameters specifiedby the user in fvSolution.

void ReadParameters(const fvMesh &iMesh);

CheckCellCenter is a private member function used to check if a cell center is located in thevolume force disk and CalcForceMagnitudes is also a private memberfunction, used to calculate thevolume force magnitude in all three directions (axially, upwards and outwards)for a cell.

bool CheckIfCellCenterIsInDisk(const vector &iPointStartCenterLine,

const vector &iPointEndCenterLine, const vector &iCellCenter, vector &oaxialDirection,

vector &oUpDirection, vector &oOutDirection, scalar &oAngle, const vector &ivecUp,

scalar &oRad, scalar &iInnerRadius, scalar &iOuterRadius, scalar &oDiskThickness);

void CalcForceMagnitudes(const scalar &iAngle, const scalar &iRad,scalar &oaxialForce,

scalar &oupForce, scalar &ooutForce, const scalar &iFreeStreamVelocity,

scalar &oDiskThickness, const scalar &iRho, const scalar &iAxialR000Phi000,

6

Page 8: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.3. WAKE.CPP CHAPTER 3. IMPLEMENTATION IN OPENFOAM

const scalar &iAxialR025Phi000,...

};

};

}

#endif /* wake_H_ */

3.3 wake.cpp

The classes declared in wake.h are defined in wake.cpp. The header is followed by including theclass declaration file wake.h. The namespace is set to foam and the class wake declared in wake.his chosen to be used. The debug mode is set by default to 0 which. To change this the globalcontrolDict needs to be edited by including the class wake and the desired debug number. For thecomplete wake.cpp see appendices.

...

#include "wake.h"

namespace Foam {

defineTypeNameAndDebug(wake, 0);

The default constructor is used to construct preliminary values of the member data declared inwake.h.

wake::wake() {

// constructs values of data members

mStartCenterLine.x() = 0.0;

mStartCenterLine.y() = 0.0;

mStartCenterLine.z() = 0.0;

mEndCenterLine.x() = 0.0;

mEndCenterLine.y() = 0.0;

mEndCenterLine.z() = 0.0;

mvecUp.x() = 0.0;

mvecUp.y() = 0.0;

mvecUp.z() = 0.0;

mOuterRadius = 0.0;

mInnerRadius = 0.0;

mFreeStreamVelocity = 1;

mAxialR000Phi000 = 0;

mAxialR025Phi000 = 0;

mAxialR025Phi030 = 0;

...

}

7

Page 9: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.3. WAKE.CPP CHAPTER 3. IMPLEMENTATION IN OPENFOAM

wake::~wake() {

}

The member function ReadParameters is defined to read the fvSolution file located in the systemdirectory. Under the sub-dictionary volumeForceDisk the user specified parameters are read and thecorresponding member data is set to these values.

void wake::ReadParameters(const fvMesh &iMesh) {

if(debug >= 1) {

Info << "Reading volume force disk properties\n";

}

///////////////////////////////////////////////////////////////////////

//Read volume forceDisk parameters from fvSolution

//////////////////////////////////////////////////////////////////////

Istream& is1 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("innerRadius");

is1.format(IOstream::ASCII);

is1 >> mInnerRadius;

Istream& is2 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("outerRadius");

is2.format(IOstream::ASCII);

is2 >> mOuterRadius;

Istream& is3 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("startCenterLine");

is3.format(IOstream::ASCII);

is3 >> mStartCenterLine;

Istream& is4 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("endCenterLine");

is4.format(IOstream::ASCII);

is4 >> mEndCenterLine;

Istream& is5 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("upDirection");

is5.format(IOstream::ASCII);

is5 >> mvecUp;

Istream& is6 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("freeStreamVelocity");

is6.format(IOstream::ASCII);

is6 >> mFreeStreamVelocity;

Istream& is7 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("density");

is7.format(IOstream::ASCII);

is7 >> mRho;

Istream& is8 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR000Phi000");

8

Page 10: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.3. WAKE.CPP CHAPTER 3. IMPLEMENTATION IN OPENFOAM

is8.format(IOstream::ASCII);

is8 >> mAxialR000Phi000;

Istream& is9 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR025Phi000");

is9.format(IOstream::ASCII);

is9 >> mAxialR025Phi000;

Istream& is10 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR025Phi030");

is10.format(IOstream::ASCII);

is10 >> mAxialR025Phi030;

...

}

}

The CheckIfCellCenterIsInDisk member function is defined to check if the cell center of a cellis located in the volume force disk or not, generating boolean output. Also normalized vectorspointing in axial, upward and outward direction (perpendicular to the axial and upward direction)are calculated.

The centerline, the disk thickness and the axial direction are determined and it is checked if thecell center is located inside the volume force disk with regards to axial location.

bool wake::CheckIfCellCenterIsInDisk(const vector &iStartCenterLine,

const vector &iEndCenterLine,const vector &iCellCenter, vector &oaxialDirection,

vector &oUpDirection, vector &oOutDirection, scalar &oAngle, const vector &ivecUp,

scalar &oRad, scalar &iInnerRadius, scalar &iOuterRadius, scalar &oDiskThickness) {

if(debug >= 1) {

Info << "Checks if the current cell center is located inside the non-zero volume

force disk\n";

}

///////////////////////////////////////////////////////////////////////////////////

// Checks if current cell center is located inside the non-zero volume force disk

///////////////////////////////////////////////////////////////////////////////////

// Calculates the centerline vector between startCenterLine and endCenterLine

vector vecCenterLine(iEndCenterLine - iStartCenterLine);

oDiskThickness = mag(vecCenterLine);

// Checks if the centerline length is positive and non-zero

if(!(oDiskThickness > 0)) {

Info << "The volume force disk has no length \n";

}

// Defines the axial direction as the centerline divided by its length

vecCenterLine /= mag(vecCenterLine);

oaxialDirection = vecCenterLine;

9

Page 11: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.3. WAKE.CPP CHAPTER 3. IMPLEMENTATION IN OPENFOAM

// Calculates the axial distance from the startpoint to the cell center

vector vecStartToCellCenter(iCellCenter - iStartCenterLine);

scalar CellCenterProjCenterLine(vecStartToCellCenter & vecCenterLine);

//Checks if the cellcenter is located inside the disk in axial direction,

if not false is returned

if(!(CellCenterProjCenterLine >= 0.0 && CellCenterProjCenterLine

<= oDiskThickness)) {

return false;

}

The radial distance from the cell center to the centerline is calculated and the up-direction andangle against the updirection are determined.

// Calculates perpendicular vector from centerline to cell center

vector vecCenterLineToCellCenter(vecStartToCellCenter

- (vecCenterLine*CellCenterProjCenterLine));

// Calculates the radial distance

scalar RadialDist = mag(vecCenterLineToCellCenter);

// Normalized by the radius of the volume force disk (external

radius - internal radius)

oRad = mag(RadialDist-iInnerRadius)/mag(iOuterRadius-iInnerRadius);

// Calculates the upward direction vector as the normalized

up direction specified by the user

vector vecUp(ivecUp);

vecUp /= mag(vecUp);

oUpDirection = vecUp;

// Calculates the angle between the upward vector and the perpendicular

vector (radial direction) from centerline to cell center

oAngle = acos(vecUp&vecCenterLineToCellCenter/(mag(vecUp)

*mag(vecCenterLineToCellCenter))) *180/mPI;

The out-direction is calculated as the normalized vector product of the up direction vector andthe axial direction vector.

// Calculates a vector perpendicular to both the axial-

and radial direction always pointing outwards

10

Page 12: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.3. WAKE.CPP CHAPTER 3. IMPLEMENTATION IN OPENFOAM

oOutDirection = vecUp^vecCenterLine;

oOutDirection /= mag(oOutDirection);

The out direction is ensured to be pointing outwards.

// Checks if the projection of the radial vector onto the

outdirection vector is positive or zero, otherwise the outward vector

is multiplied by -1 to make sure it is pointing outwards

scalar foo = vecCenterLineToCellCenter&oOutDirection;

if( 0 > foo) {

oOutDirection *= -1;

}

It is checked if the cell center is located inside the volume force disk with regards to the radialposition.

// Checks if the volume force disk radius is positive and non-zero and

the exterior radius is larger than the interior

if(!((mOuterRadius > mInnerRadius) & (mOuterRadius > 0))){

Info << "The exterior radius is zero or smaller than the interior radius \n";

}

// Check if the point is inside the volume force disk in the radial direction,

if so a true is returned

return(RadialDist <= mOuterRadius && RadialDist >= mInnerRadius);

}

The member function CalcForceMagnitudes calculates the volume force magnitudes for a cell.If-statements are used to determine the four nearby specified wake fractions.

void wake::CalcForceMagnitudes(const scalar &iAngle, const scalar &iRad,

scalar &oaxialForce, scalar &oupForce, scalar &ooutForce,

const scalar &iFreeStreamVelocity, scalar &oDiskThickness, const scalar &iRho,

const scalar &iAxialR000Phi000,

const scalar &iAxialR025Phi000, const scalar &iAxialR025Phi030, ...) {

if(debug >= 1) {

Info << "Calculates the volume force vector magnitudes\n";

}

/////////////////////////////////////////////////////////////////////////////////////

// Calculates the target wakefraction based on radial and angular position.

// The magnitudes of the three components of the volume force vectors are calculated

// from the target wakefraction.

11

Page 13: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.3. WAKE.CPP CHAPTER 3. IMPLEMENTATION IN OPENFOAM

/////////////////////////////////////////////////////////////////////////////////////

scalar axialWake = 0;

scalar axialWake11 = 0;

scalar axialWake12 = 0;

scalar axialWake21 = 0;

scalar axialWake22 = 0;

scalar upWake = 0;

scalar upWake11 = 0;

scalar upWake12 = 0;

scalar upWake21 = 0;

scalar upWake22 = 0;

scalar outWake = 0;

scalar outWake11 = 0;

scalar outWake12 = 0;

scalar outWake21 = 0;

scalar outWake22 = 0;

scalar Phi1 = 0;

scalar Phi2 = 1;

scalar Rad1 = 0;

scalar Rad2 = 0;

// Setting the nearby values (for interpolation)

based on cell position (radial fraction and angle)

if(0.25 >= iRad){

Rad1 = 0;

Rad2 = 0.25;

if(30 >= iAngle){

axialWake11 = iAxialR000Phi000;

axialWake12 = iAxialR000Phi000;

axialWake21 = iAxialR025Phi000;

axialWake22 = iAxialR025Phi030;

upWake11 = iUpR000Phi000;

upWake12 = iUpR000Phi000;

upWake21 = iUpR025Phi000;

upWake22 = iUpR025Phi030;

outWake11 = iOutR000Phi000;

outWake12 = iOutR000Phi000;

outWake21 = iOutR025Phi000;

outWake22 = iOutR025Phi030;

Phi1 = 0;

Phi2 = 30;

}

else if(60 >= iAngle){

axialWake11 = iAxialR000Phi000;

12

Page 14: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.3. WAKE.CPP CHAPTER 3. IMPLEMENTATION IN OPENFOAM

axialWake12 = iAxialR000Phi000;

axialWake21 = iAxialR025Phi030;

axialWake22 = iAxialR025Phi060;

upWake11 = iUpR000Phi000;

upWake12 = iUpR000Phi000;

upWake21 = iUpR025Phi030;

upWake22 = iUpR025Phi060;

outWake11 = iOutR000Phi000;

outWake12 = iOutR000Phi000;

outWake21 = iOutR025Phi030;

outWake22 = iOutR025Phi060;

Phi1 = 30;

Phi2 = 60;

}

...

}

The four nearby wake fractions for each direction are used to calculate the wake fractions in thecell center according to eq 2.6.

// Interpolation of wake fractions

axialWake = (axialWake11*(Phi2-iAngle)*(1/(Phi2-Phi1))

+axialWake12*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(Rad2 - iRad)

*(1/0.25) + (axialWake21*(Phi2-iAngle)*(1/(Phi2-Phi1))+axialWake22

*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(iRad - Rad1)*(1/0.25);

upWake = (upWake11*(Phi2-iAngle)*(1/(Phi2-Phi1))+upWake12

*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(Rad2 - iRad)*(1/0.25)

+ (upWake21*(Phi2-iAngle)*(1/(Phi2-Phi1))+upWake22*(iAngle-Phi1)

*(1/(Phi2-Phi1)))*(iRad - Rad1)*(1/0.25);

outWake = (outWake11*(Phi2-iAngle)*(1/(Phi2-Phi1))

+outWake12*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(Rad2 - iRad)

*(1/0.25) + (outWake21*(Phi2-iAngle)*(1/(Phi2-Phi1))

+outWake22*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(iRad - Rad1)*(1/0.25);

The volume force magnitudes are calculated from the wake fractions according to eq 2.3, eq 2.5and eq 2.4. These lines should be modified if another model for the velocity change to volume forceconnection should be applied.

// Calculates force magnitudes based on the wake fractions

oaxialForce = iRho * 0.5 * ( (1-axialWake) * iFreeStreamVelocity

* mag(1-axialWake) * iFreeStreamVelocity - iFreeStreamVelocity

* iFreeStreamVelocity)/oDiskThickness;

oupForce = iRho * 0.5 * (1 - upWake)*iFreeStreamVelocity

*mag(1 - upWake)*iFreeStreamVelocity/oDiskThickness;

13

Page 15: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.3. WAKE.CPP CHAPTER 3. IMPLEMENTATION IN OPENFOAM

ooutForce = iRho * 0.5 * (1 - outWake)*iFreeStreamVelocity

*mag(1 - outWake)*iFreeStreamVelocity/oDiskThickness;

}

The CalcVolumeForce member function is defined to initiate other memberfunctions to finallycalculate the volume force vector field. First the memberfunction ReadParameters is initialized

void wake::CalcVolumeForce(const fvMesh &iMesh, vectorField &ioVolumeForceField) {

if(debug >= 1) {

Info << "Computes the volume force vectorfield\n";

}

// Reading the parameters specified in fvSolution

ReadParameters(iMesh);

Variables for outputs from member functions are declared

// Declaring the output variables

scalar Angle;

vector axialDirection;

vector UpDirection;

vector OutDirection;

vector TotalForce(0,0,0);

scalar Rad;

scalar axialForce;

scalar upForce;

scalar outForce;

scalar diskThickness;

All cells are looped over and it is checked if the cell center is located in the volume force diskusing the member function CheckIfCellCenterIsInDisk

// Loop over all cells

for(label i = 0; i < iMesh.C().size(); i++) {

// Checks if the cell center is in the volume force disk

if(CheckIfCellCenterIsInDisk(mStartCenterLine,mEndCenterLine,iMesh.C()[i],

axialDirection, UpDirection, OutDirection, Angle, mvecUp, Rad, mInnerRadius,

mOuterRadius, diskThickness)) {

If the cell center is located in the volume force disk the volume force magnitudes are calculatedby the member function CalcForceMagnitudes with radial distance to cell center and angle to theupward direction calculated previously by the memberfunction CheckIfCellCenterIsInDisk

// Initializes the force magnitude calculation for cells with cell center inside

the disk CalcForceMagnitudes(Angle, Rad, axialForce, upForce, outForce,

mFreeStreamVelocity, diskThickness, mRho, mAxialR000Phi000,mAxialR025Phi000,

mAxialR025Phi030,...);

14

Page 16: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.4. INTERPHASECHANGEWAKEFOAM.CCHAPTER 3. IMPLEMENTATION IN OPENFOAM

The volume force vector for every cell is calculated by multiplying the volume force magnitudesby the axial, outward and upward direction vectors.

// Calculates the volume force vector to be added in the current cell

vector vecVolumeForce = axialDirection*axialForce + UpDirection*upForce

+ OutDirection*outForce;

The volume force vector is inserted into the place in the volume force vector field which corre-sponds to the current cell.

// Adds the volume force vector to the volume force vectorfield

ioVolumeForceField[i] += vecVolumeForce;

The total force added in the volume force disk is calculated and written by summing volumeforce multiplied by the cell volume for all cells.

// Calculates the total added force by summing the volume force multiplied

by the cell volume for all cells

TotalForce += vecVolumeForce*iMesh.V()[i];

}

}

// Writes the total added force

Info << "Total added force: " << TotalForce << "\n";

}

3.4 interPhaseChangeWakeFoam.C

The interPhaseChangeWakeFoam.C is created by renaming interPhaseChangeFoam.C to interPhaseChange-WakeFoam.C followed by modification

mv interPhaseChangeFoam.C interPhaseChangeWakeFoam.C

The class declaration file wake.h is included by adding the line #include ”wake.h” at line 53in interPhaseChangeWakeFoam.C. The file ”correctPhi.h” is included by a relative path by inter-PhaseChangeFoam which will not work if the interFoam solver is not located in the same folder asour. This is the reason for copying correctPhi.h before and this file need to be included. Changethe line ”#include ”../interFoam/correctPhi.H”” to #include ”correctPhi.H” .

An object volumeforceDisk of class wake is created by adding the line ”wake volumeForceDisk;”at line 68.

15

Page 17: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.5. UEQN.H CHAPTER 3. IMPLEMENTATION IN OPENFOAM

3.5 Ueqn.H

The volume force vector field should as explained earlier be included when solving the momentumequations in the momentum predictor step. First the volume force vector field must be made emptyin case of existing values. This is performed by looping over the whole size and putting every vectorto zero.

fvVectorMatrix UEqn

(

fvm::ddt(rho, U)

+ fvm::div(rhoPhi, U)

- fvm::Sp(fvc::ddt(rho) + fvc::div(rhoPhi), U)

+ turbulence->divDevRhoReff(rho, U)

);

UEqn.relax();

// Setting volume force vectorfield components to zero

for(label k = 0; k < VolumeForceField.size(); k++) {

VolumeForceField[k] = vector::zero;

}

The memberfunction CalcVolumeForce is initialized to set values to the volume force vector field.

// Calculates the volume force vectorfield

(setting values to the volume force vectorfield)

volumeForceDisk.CalcVolumeForce(mesh, VolumeForceField);

The volume force vector field is added to the momentum equation to be solved in the momentumpredictor step. Notice that the momentum predictor step must be performed to include the volumeforces.

// The volume force field is added to the momentum predictor

if (pimple.momentumPredictor())

{

solve

(

UEqn

==

fvc::reconstruct

(

(

fvc::interpolate(interface.sigmaK())*fvc::snGrad(alpha1)

- ghf*fvc::snGrad(rho)

- fvc::snGrad(p_rgh)

) * mesh.magSf()

)

+ VolumeForceField

);

}

16

Page 18: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.6. CREATEFIELDS.H CHAPTER 3. IMPLEMENTATION IN OPENFOAM

3.6 createFields.H

Fields such as the velocity vector field or the pressure scalar field are read and written according tothe createFields.H file. A vector field called volumeforceField is created. This is a vector field andis therefore a volVectorField just like the velocity vector field. It should be read as well as writtento the time directories. Add the following at line 42 in createFields.H.

Info << "Creating volume force vector field.\n";

volVectorField VolumeForceField

(

IOobject

(

"VolumeForce",

runTime.timeName(),

mesh,

IOobject::MUST_READ,

IOobject::AUTO_WRITE

),

mesh

);

3.7 Make/files

Both the interPhaseChangeWakeFoam.C and wake.cpp are source files which should be compiled.Change the first row in files from interPhaseChangeFoam.C to interPhaseChangeWakeFoam.C andinsert wake.cpp on the second row. As this solver is user developed it should be stored in the$FOAM USER APPBIN directory and names the same as the application following standardconvention (interPhaseChangeWakeFoam), according to the OpenFOAM user guide [7].

interPhaseChangeWakeFoam.C

wake.cpp

phaseChangeTwoPhaseMixtures/phaseChangeTwoPhaseMixture/phaseChangeTwoPhaseMixture.C

phaseChangeTwoPhaseMixtures/phaseChangeTwoPhaseMixture/newPhaseChangeTwoPhaseMixture.C

phaseChangeTwoPhaseMixtures/Kunz/Kunz.C

phaseChangeTwoPhaseMixtures/Merkle/Merkle.C

phaseChangeTwoPhaseMixtures/SchnerrSauer/SchnerrSauer.C

EXE = $(FOAM_USER_APPBIN)/interPhaseChangeWakeFoam

3.8 Other files

Make/options, alphaEqn.H, alphaEqnSubCycle.H, correctPhi.H, pEqn.H and all files in the phaseChangeT-woPhaseMixture are kept unchanged.

3.9 Compilation

The solver can now be compiled with no errors appearing

wmake

17

Page 19: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

3.10. IMPLEMENTATION IN ANOTHER SOLVERCHAPTER 3. IMPLEMENTATION IN OPENFOAM

3.10 Implementation in another solver

The same procedure can be performed in another solver to include a volume force disk. Cautionhowever should be held especially considering including the volume force field when solving themomentum equation. Some solvers, such as simpleFoam, solves the momentum equation with allterms divided by the density ρ which should also hold for the volume force field.

18

Page 20: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Chapter 4

Using the solver

The solver will be used to generate a wake field in a flow through a rectangular box. No propellerwill be included and no phase change will occur. Only the accuracy of the generated wake field isassessed with this tutorial. Start by copying the interPhaseChangeFoam tutorial cavitatingBullet tothe user run directory and rename the case to LaminarWake

foam

cp -r --parent tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet

$WM_PROJECT_USER_DIR/

cd $WM_PROJECT_USER_DIR

cp -r tutorials/multiphase/interPhaseChangeFoam/cavitatingBullet run/

cd run/

mv cavitatingBullet LaminarWake

cd LaminarWake

4.1 constant directory

The mesh to be generated by the blockMesh utility should be changed, open the blockMeshDict

gedit constant/polyMesh/blockMeshDict

Change convertToMeters to 1 and the vertices such as follows

vertices

(

(-5 -5 -5)

(5 -5 -5)

(5 5 -5)

(-5 5 -5)

(-5 -5 10)

(5 -5 10)

(5 5 10)

(-5 5 10)

);

The blocks should be changed to a 16x16x24 mesh.

blocks

19

Page 21: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

4.2. 0 DIRECTORY CHAPTER 4. USING THE SOLVER

(

hex (0 1 2 3 4 5 6 7) (16 16 24) simpleGrading (1 1 1)

);

The files turbulenceProperties specifying the choice of turbulence model, g specifying the gravi-tational constant and transportProperties specifying fluid properties should be left unchanged.

4.2 0 directory

The bullet will not be included so the bullet should be deleted from the boundaryField in the U,alpha1 and p rgh files. The volume force field needs a file to read from the 0. Copy the U file andrename the copy to volume force

cd ../0

cp U VolumeForce

The volume force field have different dimensions compared to the velocity field. Change thedimensions of the volume force field to kg

m2s2 which is written as dimensions [1 -2 -2 0 0];

in OpenFOAM.The velocity should be specified to 7 m/s. The inlet is set to have the same velocity as the

internalField therefore it is only necessary to change the internalField to (0 0 7);.

4.3 system directory

In the controlDict file change the endTime to 5 and the writeInterval to 1.In fvSolution the momentum predictor should be set to yes. The volume force disk to be added

should start at (0 0 0) and end at (0 0 0.12) having up-direction in (0 1 0) and innerRadius 0.2and outerRadius 2. The freeStreamVelocity is 7 and density 1000. The wake field parameters areresulting from a visual estimation of the Hamburg test case wake field as can be seen in Larssonsand Raven [4]. These wake field parameters are not to be considered of good precision. ChangefvSchemes snGradSchemes default to corrected.Specify U final to the same as U byUFinal{$U;}See appendix for fvSolution.

The snappyHexMesh utility is used to refine the mesh in a cylinder of radius 5 from (0 0 -1) to(0 0 4) without including the bullet geometry. The cylinder is refined of level 2 with 2 cells betweenlevels. See the refinement zone in figure 4.1.

4.4 Solving

The case is solved by first generating the background mesh with blockMesh

blockMesh

The mesh refinement is performed by snappyHexMesh and can be seen in figure 4.1.

snappyHexMesh -overwrite

The case is decomposed and run on 4 CPU cores in parallel by

decomposePar

mpirun -np 4 interPhaseWakeFoam -parallel >&log &

20

Page 22: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

4.4. SOLVING CHAPTER 4. USING THE SOLVER

(a) X normal slice through origo (b) Z normal slice through origo

Figure 4.1: The refined mesh

When the solving is done the case is reconstructed by

reconstructPar -latestTime

The components of the volume force field and the velocity field are calculated using foamCalc

foamCalc components U

foamCalc components VolumeForce

And the solution can be visualized in ParaView

paraFoam

The solving can also be performed by initializing the Allrun script which performs all stepsfor solving. When the ParaView application is opened the state file wakeComparison.pvsm can beopened by File → Load state to visualize the acheived wake field and the target wake field specifiedin fvSolution.

./Allrun

21

Page 23: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Chapter 5

Performance

The result at time 5 [s], where no significant change in time was found, is visualized using Paraview3.12.0. The achieved wake field is calculated using the calculator filter in paraview, calculating:1− U/U∞. The target wake field is calculated according to eq 2.3, eq 2.5 and eq 2.4 to achieve thetarget wake field from the applied volume force. The target wake field can be seen in figures 5.1,5.2and 5.3

Figure 5.1: Target axial wake field

22

Page 24: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

CHAPTER 5. PERFORMANCE

Figure 5.2: Target up-directed wake field

Figure 5.3: Target out-directed wake field

23

Page 25: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

CHAPTER 5. PERFORMANCE

The achieved axial wake field from the case described in chapter 4, 3 meters downstream of theend of the volume force disk, where the pressure gradient, arrising from the volume forces, is low,can be seen in figure 5.4 The achieved wake is, as can be seen, too low in comparison with the targetaxial wake seen in figure 5.1 although the pattern from the axial volume forces can be recognised.This means that the velocity difference due to the volume forces are too small in axial direction.

Figure 5.4: Achieved axial wake field 3 meters downstream of the disk

24

Page 26: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

CHAPTER 5. PERFORMANCE

Comparing the achieved up-direction wake field in figure 5.5 with the target wake field in fig-ure 5.2 it can be seen that some resemblence of the volume force pattern can be recognised but themagnitudes of the velocity changes are too small.

Figure 5.5: Achieved up-directed wake field 3 meters downstream of the disk

25

Page 27: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

5.1. DISK THICKNESS EFFECT ON AXIAL WAKE CHAPTER 5. PERFORMANCE

Also for the achieved out-directed wake field as can be seen in figure 5.6 the magnitude of thevolume force induced velcity changes are too small. The out directed velocity is positive away fromthe disk center possibly due to the pressure created by the volume forces in front of the disk. Thevelocity is altough lower in the upper half-circle which could be a result of the out-directed volumeforce.

Figure 5.6: Achieved out-directed wake field 3 meters downstream of the disk

5.1 Disk thickness effect on axial wake

To investigate the disk thickness effect on performance two cases were computed with different diskthickness. In the first case, described in chapter 4, the volume force is 0.12 m thick which correspondsto approximately 1 cell length. The results can be seen in figures 5.4, 5.5 and 5.6. In the secondcase the volume force disk have a thickness of 0.63 m which approximately corresponds to 5 celllengths. The resulting axial wake field, located 3 meters downstream of the disk end can be seen infigure 5.7.

26

Page 28: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

5.2. VISCOUS MOMENTUM DIFFUSSION CHAPTER 5. PERFORMANCE

Figure 5.7: Achieved axial wake field 3 meters downstream of the disk (diskthickness: 0.63 m)

The specified extension of the volume force disk need to coincide with the total length of thecells which cell centers are found within the specified disk. This is accounted for by placing startand end of the disk centerline at estimated cell bounds. As can be seen by comparing figure 5.7and figure 5.4 no significant difference was achieved with a thicker disk (0.63 m) compared to thethinner disk (0.12m).

5.2 Viscous momentum diffussion

To investigate the influence of the viscous momentum diffussion another case was run. With dynamicviscosity ν = 0 the case was run with results as can be seen in figure 5.8, figure 5.9 and figure 5.10.As can be seen no significant difference was acheived when setting the dynamic viscosity to zero.

27

Page 29: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

5.2. VISCOUS MOMENTUM DIFFUSSION CHAPTER 5. PERFORMANCE

Figure 5.8: Achieved axial wake field 3 meters downstream of the disk (ν = 0)

Figure 5.9: Achieved up-directed wake field 3 meters downstream of the disk (ν = 0)

28

Page 30: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

5.2. VISCOUS MOMENTUM DIFFUSSION CHAPTER 5. PERFORMANCE

Figure 5.10: Achieved out-directed wake field 3 meters downstream of the disk (ν = 0)

29

Page 31: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Chapter 6

Conclusion and future work

This report have described a way of including volume forces in the OpenFoam 2.1.x solver inter-PhaseChangeFoam. The volume forces were supposed to generate a user perscribed velocity fieldgiven as wake fractions, but the volume force disk produces too small velocity changes.

As the precision of the disk extension coinciding with the cell boundaries can not be held to begood no conclusions can be drawn from the small differences between the axial wake from a 0.12m thick disk in figure 5.4 and with a 0.63 m thick disk seen in figure 5.7 other than that the diskthickness is not the reason for the too small velocity changes.

The role of viscous diffusion for the lack of performance can be considered small or negligable asno difference in acheived wake field could be seen when the dynamic viscosity ν was changed from9e−7 to 0.

This gives reason to question the initial guess for volume force - velocity change connection seenin eq 2.2.

Also the necessary number of variables specifying the target wake field need to be investigatedby regarding sufficient flow detail for propeller cavitation computations and also the potential forachieving flow details using volume forces.

30

Page 32: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Bibliography

[1] Dyne, G. Bark, G. (2005) Ship propulsion. Gothenburg: Chalmers University of Technologyshipping and marine technology: Division of hydromechanics ( Compendium for part of the MSccourse ”Ship resistance and propulsion”)

[2] Shin, K, W. Andersen, Mikkelsen, Robert. (2011) Cavitation Simulation on Conventional andHighly-Skewed Propellers in the Behind-Hull Condition. Hamburg, Germany.( Second Interna-tional Symposium on Marine Propulsors smp’11)

[3] Svenning, E. (2010) Implementation of an actuator disk in OpenFOAM. Gothenburg, Sweden.

[4] Larsson, L. Raven, H C. (2010) Ship Resistance And Flow. Jersey, New Jersey: The Society ofNaval Architects and Marine Engineers ( The Principles of Naval Architecture Series)

[5] Jasak, H. (1996) Error Analysis and Estimation for the Finite Volume Method with Applicationsto Fluid Flows. PhD thesis, Imperial College of Science, London, UK.

[6] White, F M. (1998) Fluid Mechanics. Fourth edition. University of Rhode Island: McGraw-HillHigher Education ( McGraw-Hill Series in Mechanical Engineering)

[7] Compiling applications and libraries (2012) OpenFOAM user guide. http://www.openfoam.

org/docs/user/compiling-applications.php (2012-10-18).

31

Page 33: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Appendix A

wake.h

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

========= |

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

\\ / O peration |

\\ / A nd | Copyright held by original author

\\/ M anipulation |

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software; you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by the

Free Software Foundation; either version 2 of the License, or (at your

option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM; if not, write to the Free Software Foundation,

Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Application

wake

Description

Add volume force to generate a wake field

Written by Simon Tornros, October 2012

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

#ifndef wake_H_

#define wake_H_

#include "fvCFD.H"

32

Page 34: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX A. WAKE.H

namespace Foam {

class wake {

public:

TypeName("wake");

wake();

~wake();

void CalcVolumeForce(const fvMesh &iMesh, vectorField &ioVolumeForceField);

private:

vector mStartCenterLine;

vector mEndCenterLine;

vector mvecUp;

scalar mOuterRadius, mInnerRadius;

scalar mFreeStreamVelocity;

scalar mRho;

scalar mAxialR000Phi000,mAxialR025Phi000, mAxialR025Phi030, mAxialR025Phi060,

mAxialR025Phi090, mAxialR025Phi120, mAxialR025Phi150, mAxialR025Phi180,

mAxialR050Phi000, mAxialR050Phi030, mAxialR050Phi060, mAxialR050Phi090,

mAxialR050Phi120, mAxialR050Phi150, mAxialR050Phi180, mAxialR075Phi000,

mAxialR075Phi030, mAxialR075Phi060, mAxialR075Phi090, mAxialR075Phi120,

mAxialR075Phi150, mAxialR075Phi180, mAxialR100Phi000, mAxialR100Phi030,

mAxialR100Phi060, mAxialR100Phi090, mAxialR100Phi120, mAxialR100Phi150,

mAxialR100Phi180, mUpR000Phi000, mUpR025Phi000, mUpR025Phi030, mUpR025Phi060,

mUpR025Phi090, mUpR025Phi120, mUpR025Phi150, mUpR025Phi180, mUpR050Phi000,

mUpR050Phi030, mUpR050Phi060, mUpR050Phi090, mUpR050Phi120, mUpR050Phi150,

mUpR050Phi180, mUpR075Phi000, mUpR075Phi030, mUpR075Phi060, mUpR075Phi090,

mUpR075Phi120, mUpR075Phi150, mUpR075Phi180, mUpR100Phi000, mUpR100Phi030,

mUpR100Phi060, mUpR100Phi090, mUpR100Phi120, mUpR100Phi150, mUpR100Phi180,

mOutR000Phi000, mOutR025Phi000, mOutR025Phi030, mOutR025Phi060, mOutR025Phi090,

mOutR025Phi120, mOutR025Phi150, mOutR025Phi180, mOutR050Phi000, mOutR050Phi030,

mOutR050Phi060, mOutR050Phi090, mOutR050Phi120, mOutR050Phi150, mOutR050Phi180,

mOutR075Phi000, mOutR075Phi030, mOutR075Phi060, mOutR075Phi090, mOutR075Phi120,

mOutR075Phi150, mOutR075Phi180, mOutR100Phi000, mOutR100Phi030, mOutR100Phi060,

mOutR100Phi090, mOutR100Phi120, mOutR100Phi150, mOutR100Phi180;

static const double mPI = 3.141592654;

void ReadParameters(const fvMesh &iMesh);

bool CheckIfCellCenterIsInDisk(const vector &iPointStartCenterLine,

const vector &iPointEndCenterLine, const vector &iCellCenter,

vector &oaxialDirection, vector &oUpDirection, vector &oOutDirection,

scalar &oAngle, const vector &ivecUp, scalar &oRad, scalar &iInnerRadius,

scalar &iOuterRadius, scalar &oDiskThickness);

void CalcForceMagnitudes(const scalar &iAngle, const scalar &iRad,

scalar &oaxialForce,scalar &oupForce, scalar &ooutForce,

33

Page 35: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX A. WAKE.H

const scalar &iFreeStreamVelocity, scalar &oDiskThickness, const scalar &iRho,

const scalar &iAxialR000Phi000, const scalar &iAxialR025Phi000,

const scalar &iAxialR025Phi030, const scalar &iAxialR025Phi060,

const scalar &iAxialR025Phi090, const scalar &iAxialR025Phi120,

const scalar &iAxialR025Phi150, const scalar &iAxialR025Phi180,

const scalar &iAxialR050Phi000, const scalar &iAxialR050Phi030,

const scalar &iAxialR050Phi060, const scalar &iAxialR050Phi090,

const scalar &iAxialR050Phi120, const scalar &iAxialR050Phi150,

const scalar &iAxialR050Phi180, const scalar &iAxialR075Phi000,

const scalar &iAxialR075Phi030, const scalar &iAxialR075Phi060,

const scalar &iAxialR075Phi090, const scalar &iAxialR075Phi120,

const scalar &iAxialR075Phi150, const scalar &iAxialR075Phi180,

const scalar &iAxialR100Phi000, const scalar &iAxialR100Phi030,

const scalar &iAxialR100Phi060, const scalar &iAxialR100Phi090,

const scalar &iAxialR100Phi120, const scalar &iAxialR100Phi150,

const scalar &iAxialR100Phi180, const scalar &iUpR000Phi000,

const scalar &iUpR025Phi000, const scalar &iUpR025Phi030,

const scalar &iUpR025Phi060, const scalar &iUpR025Phi090,

const scalar &iUpR025Phi120, const scalar &iUpR025Phi150,

const scalar &iUpR025Phi180, const scalar &iUpR050Phi000,

const scalar &iUpR050Phi030, const scalar &iUpR050Phi060,

const scalar &iUpR050Phi090, const scalar &iUpR050Phi120,

const scalar &iUpR050Phi150, const scalar &iUpR050Phi180,

const scalar &iUpR075Phi000, const scalar &iUpR075Phi030,

const scalar &iUpR075Phi060, const scalar &iUpR075Phi090,

const scalar &iUpR075Phi120, const scalar &iUpR075Phi150,

const scalar &iUpR075Phi180, const scalar &iUpR100Phi000,

const scalar &iUpR100Phi030, const scalar &iUpR100Phi060,

const scalar &iUpR100Phi090, const scalar &iUpR100Phi120,

const scalar &iUpR100Phi150, const scalar &iUpR100Phi180,

const scalar &iOutR000Phi000, const scalar &iOutR025Phi000,

const scalar &iOutR025Phi030, const scalar &iOutR025Phi060,

const scalar &iOutR025Phi090, const scalar &iOutR025Phi120,

const scalar &iOutR025Phi150, const scalar &iOutR025Phi180,

const scalar &iOutR050Phi000, const scalar &iOutR050Phi030,

const scalar &iOutR050Phi060, const scalar &iOutR050Phi090,

const scalar &iOutR050Phi120, const scalar &iOutR050Phi150,

const scalar &iOutR050Phi180, const scalar &iOutR075Phi000,

const scalar &iOutR075Phi030, const scalar &iOutR075Phi060,

const scalar &iOutR075Phi090, const scalar &iOutR075Phi120,

const scalar &iOutR075Phi150, const scalar &iOutR075Phi180,

const scalar &iOutR100Phi000, const scalar &iOutR100Phi030,

const scalar &iOutR100Phi060, const scalar &iOutR100Phi090,

const scalar &iOutR100Phi120, const scalar &iOutR100Phi150,

const scalar &iOutR100Phi180);

};

}

#endif /* wake_H_ */

34

Page 36: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Appendix B

wake.cpp

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

========= |

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

\\ / O peration |

\\ / A nd | Copyright held by original author

\\/ M anipulation |

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software; you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by the

Free Software Foundation; either version 2 of the License, or (at your

option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM; if not, write to the Free Software Foundation,

Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Application

wake

Description

Adds volume force to generate a wake field with the solver

interPhaseChangeWakeFoam

Written by Simon Tornros, October 2012

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

#include "wake.h"

namespace Foam {

defineTypeNameAndDebug(wake, 0);

35

Page 37: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

wake::wake() {

// constructs values of data members

mStartCenterLine.x() = 0.0;

mStartCenterLine.y() = 0.0;

mStartCenterLine.z() = 0.0;

mEndCenterLine.x() = 0.0;

mEndCenterLine.y() = 0.0;

mEndCenterLine.z() = 0.0;

mvecUp.x() = 0.0;

mvecUp.y() = 0.0;

mvecUp.z() = 0.0;

mOuterRadius = 0.0;

mInnerRadius = 0.0;

mFreeStreamVelocity = 1;

mAxialR000Phi000 = 0;

mAxialR025Phi000 = 0;

mAxialR025Phi030 = 0;

mAxialR025Phi060 = 0;

mAxialR025Phi090 = 0;

mAxialR025Phi120 = 0;

mAxialR025Phi150 = 0;

mAxialR025Phi180 = 0;

mAxialR050Phi000 = 0;

mAxialR050Phi030 = 0;

mAxialR050Phi060 = 0;

mAxialR050Phi090 = 0;

mAxialR050Phi120 = 0;

mAxialR050Phi150 = 0;

mAxialR050Phi180 = 0;

mAxialR075Phi000 = 0;

mAxialR075Phi030 = 0;

mAxialR075Phi060 = 0;

mAxialR075Phi090 = 0;

mAxialR075Phi120 = 0;

mAxialR075Phi150 = 0;

mAxialR075Phi180 = 0;

mAxialR100Phi000 = 0;

mAxialR100Phi030 = 0;

mAxialR100Phi060 = 0;

mAxialR100Phi090 = 0;

mAxialR100Phi120 = 0;

mAxialR100Phi150 = 0;

36

Page 38: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

mAxialR100Phi180 = 0;

mUpR000Phi000 = 0.0;

mUpR025Phi000 = 0;

mUpR025Phi030 = 0;

mUpR025Phi060 = 0;

mUpR025Phi090 = 0;

mUpR025Phi120 = 0;

mUpR025Phi150 = 0;

mUpR025Phi180 = 0;

mUpR050Phi000 = 0;

mUpR050Phi030 = 0;

mUpR050Phi060 = 0;

mUpR050Phi090 = 0;

mUpR050Phi120 = 0;

mUpR050Phi150 = 0;

mUpR050Phi180 = 0;

mUpR075Phi000 = 0;

mUpR075Phi030 = 0;

mUpR075Phi060 = 0;

mUpR075Phi090 = 0;

mUpR075Phi120 = 0;

mUpR075Phi150 = 0;

mUpR075Phi180 = 0;

mUpR100Phi000 = 0;

mUpR100Phi030 = 0;

mUpR100Phi060 = 0;

mUpR100Phi090 = 0;

mUpR100Phi120 = 0;

mUpR100Phi150 = 0;

mUpR100Phi180 = 0;

mOutR000Phi000 = 0;

mOutR025Phi000 = 0;

mOutR025Phi030 = 0;

mOutR025Phi060 = 0;

mOutR025Phi090 = 0;

mOutR025Phi120 = 0;

mOutR025Phi150 = 0;

mOutR025Phi180 = 0;

mOutR050Phi000 = 0;

mOutR050Phi030 = 0;

mOutR050Phi060 = 0;

mOutR050Phi090 = 0;

mOutR050Phi120 = 0;

mOutR050Phi150 = 0;

mOutR050Phi180 = 0;

37

Page 39: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

mOutR075Phi000 = 0;

mOutR075Phi030 = 0;

mOutR075Phi060 = 0;

mOutR075Phi090 = 0;

mOutR075Phi120 = 0;

mOutR075Phi150 = 0;

mOutR075Phi180 = 0;

mOutR100Phi000 = 0;

mOutR100Phi030 = 0;

mOutR100Phi060 = 0;

mOutR100Phi090 = 0;

mOutR100Phi120 = 0;

mOutR100Phi150 = 0;

mOutR100Phi180 = 0;

}

wake::~wake() {

}

void wake::ReadParameters(const fvMesh &iMesh) {

if(debug >= 1) {

Info << "Reading volume force disk properties\n";

}

////////////////////////////////////////////////////////////////////////

//Read volumeForceDisk parameters from fvSolution

////////////////////////////////////////////////////////////////////////

Istream& is1 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("innerRadius");

is1.format(IOstream::ASCII);

is1 >> mInnerRadius;

Istream& is2 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("outerRadius");

is2.format(IOstream::ASCII);

is2 >> mOuterRadius;

Istream& is3 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("startCenterLine");

is3.format(IOstream::ASCII);

is3 >> mStartCenterLine;

Istream& is4 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("endCenterLine");

is4.format(IOstream::ASCII);

is4 >> mEndCenterLine;

Istream& is5 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("upDirection");

38

Page 40: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

is5.format(IOstream::ASCII);

is5 >> mvecUp;

Istream& is6 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("freeStreamVelocity");

is6.format(IOstream::ASCII);

is6 >> mFreeStreamVelocity;

Istream& is7 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("density");

is7.format(IOstream::ASCII);

is7 >> mRho;

Istream& is8 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR000Phi000");

is8.format(IOstream::ASCII);

is8 >> mAxialR000Phi000;

Istream& is9 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR025Phi000");

is9.format(IOstream::ASCII);

is9 >> mAxialR025Phi000;

Istream& is10 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR025Phi030");

is10.format(IOstream::ASCII);

is10 >> mAxialR025Phi030;

Istream& is11 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR025Phi060");

is11.format(IOstream::ASCII);

is11 >> mAxialR025Phi060;

Istream& is12 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR025Phi090");

is12.format(IOstream::ASCII);

is12 >> mAxialR025Phi090;

Istream& is13 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR025Phi120");

is13.format(IOstream::ASCII);

is13 >> mAxialR025Phi120;

Istream& is14 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR025Phi150");

is14.format(IOstream::ASCII);

is14 >> mAxialR025Phi150;

Istream& is15 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR025Phi180");

is15.format(IOstream::ASCII);

is15 >> mAxialR025Phi180;

Istream& is16 = iMesh.solutionDict().subDict("volumeForceDisk").

39

Page 41: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

lookup("wakeAxialR050Phi000");

is16.format(IOstream::ASCII);

is16 >> mAxialR050Phi000;

Istream& is17 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR050Phi030");

is17.format(IOstream::ASCII);

is17 >> mAxialR050Phi030;

Istream& is18 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR050Phi060");

is18.format(IOstream::ASCII);

is18 >> mAxialR050Phi060;

Istream& is19 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR050Phi090");

is19.format(IOstream::ASCII);

is19 >> mAxialR050Phi090;

Istream& is20 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR050Phi120");

is20.format(IOstream::ASCII);

is20 >> mAxialR050Phi120;

Istream& is21 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR050Phi150");

is21.format(IOstream::ASCII);

is21 >> mAxialR050Phi150;

Istream& is22 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR050Phi180");

is22.format(IOstream::ASCII);

is22 >> mAxialR050Phi180;

Istream& is23 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR075Phi000");

is23.format(IOstream::ASCII);

is23 >> mAxialR075Phi000;

Istream& is24 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR075Phi030");

is24.format(IOstream::ASCII);

is24 >> mAxialR075Phi030;

Istream& is25 = iMesh.solutionDict().subDict("volumeForceDisk").lookup("wakeAxialR075Phi060");

is25.format(IOstream::ASCII);

is25 >> mAxialR075Phi060;

Istream& is26 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR075Phi090");

is26.format(IOstream::ASCII);

is26 >> mAxialR075Phi090;

Istream& is27 = iMesh.solutionDict().subDict("volumeForceDisk").

40

Page 42: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

lookup("wakeAxialR075Phi120");

is27.format(IOstream::ASCII);

is27 >> mAxialR075Phi120;

Istream& is28 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR075Phi150");

is28.format(IOstream::ASCII);

is28 >> mAxialR075Phi150;

Istream& is29 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR075Phi180");

is29.format(IOstream::ASCII);

is29 >> mAxialR075Phi180;

Istream& is30 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR100Phi000");

is30.format(IOstream::ASCII);

is30 >> mAxialR100Phi000;

Istream& is31 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR100Phi030");

is31.format(IOstream::ASCII);

is31 >> mAxialR100Phi030;

Istream& is32 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR100Phi060");

is32.format(IOstream::ASCII);

is32 >> mAxialR100Phi060;

Istream& is33 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR100Phi090");

is33.format(IOstream::ASCII);

is33 >> mAxialR100Phi090;

Istream& is34 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR100Phi120");

is34.format(IOstream::ASCII);

is34 >> mAxialR100Phi120;

Istream& is35 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR100Phi150");

is35.format(IOstream::ASCII);

is35 >> mAxialR100Phi150;

Istream& is36 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeAxialR100Phi180");

is36.format(IOstream::ASCII);

is36 >> mAxialR100Phi180;

Istream& is37 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR000Phi000");

is37.format(IOstream::ASCII);

is37 >> mUpR000Phi000;

41

Page 43: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

Istream& is38 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR025Phi000");

is38.format(IOstream::ASCII);

is38 >> mUpR025Phi000;

Istream& is39 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR025Phi030");

is39.format(IOstream::ASCII);

is39 >> mUpR025Phi030;

Istream& is40 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR025Phi060");

is40.format(IOstream::ASCII);

is40 >> mUpR025Phi060;

Istream& is41 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR025Phi090");

is41.format(IOstream::ASCII);

is41 >> mUpR025Phi090;

Istream& is42 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR025Phi120");

is42.format(IOstream::ASCII);

is42 >> mUpR025Phi120;

Istream& is43 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR025Phi150");

is43.format(IOstream::ASCII);

is43 >> mUpR025Phi150;

Istream& is44 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR025Phi180");

is44.format(IOstream::ASCII);

is44 >> mUpR025Phi180;

Istream& is45 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR050Phi000");

is45.format(IOstream::ASCII);

is45 >> mUpR050Phi000;

Istream& is46 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR050Phi030");

is46.format(IOstream::ASCII);

is46 >> mUpR050Phi030;

Istream& is47 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR050Phi060");

is47.format(IOstream::ASCII);

is47 >> mUpR050Phi060;

Istream& is48 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR050Phi090");

is48.format(IOstream::ASCII);

is48 >> mUpR050Phi090;

42

Page 44: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

Istream& is49 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR050Phi120");

is49.format(IOstream::ASCII);

is49 >> mUpR050Phi120;

Istream& is50 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR050Phi150");

is50.format(IOstream::ASCII);

is50 >> mUpR050Phi150;

Istream& is51 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR050Phi180");

is51.format(IOstream::ASCII);

is51 >> mUpR050Phi180;

Istream& is52 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR075Phi000");

is52.format(IOstream::ASCII);

is52 >> mUpR075Phi000;

Istream& is53 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR075Phi030");

is53.format(IOstream::ASCII);

is53 >> mUpR075Phi030;

Istream& is54 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR075Phi060");

is54.format(IOstream::ASCII);

is54 >> mUpR075Phi060;

Istream& is55 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR075Phi090");

is55.format(IOstream::ASCII);

is55 >> mUpR075Phi090;

Istream& is56 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR075Phi120");

is56.format(IOstream::ASCII);

is56 >> mUpR075Phi120;

Istream& is57 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR075Phi150");

is57.format(IOstream::ASCII);

is57 >> mUpR075Phi150;

Istream& is58 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR075Phi180");

is58.format(IOstream::ASCII);

is58 >> mUpR075Phi180;

Istream& is59 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR100Phi000");

is59.format(IOstream::ASCII);

43

Page 45: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

is59 >> mUpR100Phi000;

Istream& is60 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR100Phi030");

is60.format(IOstream::ASCII);

is60 >> mUpR100Phi030;

Istream& is61 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR100Phi060");

is61.format(IOstream::ASCII);

is61 >> mUpR100Phi060;

Istream& is62 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR100Phi090");

is62.format(IOstream::ASCII);

is62 >> mUpR100Phi090;

Istream& is63 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR100Phi120");

is63.format(IOstream::ASCII);

is63 >> mUpR100Phi120;

Istream& is64 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR100Phi150");

is64.format(IOstream::ASCII);

is64 >> mUpR100Phi150;

Istream& is65 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeUpR100Phi180");

is65.format(IOstream::ASCII);

is65 >> mUpR100Phi180;

Istream& is66 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR000Phi000");

is66.format(IOstream::ASCII);

is66 >> mOutR000Phi000;

Istream& is67 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR025Phi000");

is67.format(IOstream::ASCII);

is67 >> mOutR025Phi000;

Istream& is68 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR025Phi030");

is68.format(IOstream::ASCII);

is68 >> mOutR025Phi030;

Istream& is69 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR025Phi060");

is69.format(IOstream::ASCII);

is69 >> mOutR025Phi060;

Istream& is70 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR025Phi090");

44

Page 46: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

is70.format(IOstream::ASCII);

is70 >> mOutR025Phi090;

Istream& is71 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR025Phi120");

is71.format(IOstream::ASCII);

is71 >> mOutR025Phi120;

Istream& is72 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR025Phi150");

is72.format(IOstream::ASCII);

is72 >> mOutR025Phi150;

Istream& is73 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR025Phi180");

is73.format(IOstream::ASCII);

is73 >> mOutR025Phi180;

Istream& is74 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR050Phi000");

is74.format(IOstream::ASCII);

is74 >> mOutR050Phi000;

Istream& is75 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR050Phi030");

is75.format(IOstream::ASCII);

is75 >> mOutR050Phi030;

Istream& is76 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR050Phi060");

is76.format(IOstream::ASCII);

is76 >> mOutR050Phi060;

Istream& is77 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR050Phi090");

is77.format(IOstream::ASCII);

is77 >> mOutR050Phi090;

Istream& is78 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR050Phi120");

is78.format(IOstream::ASCII);

is78 >> mOutR050Phi120;

Istream& is79 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR050Phi150");

is79.format(IOstream::ASCII);

is79 >> mOutR050Phi150;

Istream& is80 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR050Phi180");

is80.format(IOstream::ASCII);

is80 >> mOutR050Phi180;

Istream& is81 = iMesh.solutionDict().subDict("volumeForceDisk").

45

Page 47: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

lookup("wakeOutR075Phi000");

is81.format(IOstream::ASCII);

is81 >> mOutR075Phi000;

Istream& is82 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR075Phi030");

is82.format(IOstream::ASCII);

is82 >> mOutR075Phi030;

Istream& is83 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR075Phi060");

is83.format(IOstream::ASCII);

is83 >> mOutR075Phi060;

Istream& is84 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR075Phi090");

is84.format(IOstream::ASCII);

is84 >> mOutR075Phi090;

Istream& is85 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR075Phi120");

is85.format(IOstream::ASCII);

is85 >> mOutR075Phi120;

Istream& is86 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR075Phi150");

is86.format(IOstream::ASCII);

is86 >> mOutR075Phi150;

Istream& is87 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR075Phi180");

is87.format(IOstream::ASCII);

is87 >> mOutR075Phi180;

Istream& is88 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR100Phi000");

is88.format(IOstream::ASCII);

is88 >> mOutR100Phi000;

Istream& is89 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR100Phi030");

is89.format(IOstream::ASCII);

is89 >> mOutR100Phi030;

Istream& is90 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR100Phi060");

is90.format(IOstream::ASCII);

is90 >> mOutR100Phi060;

Istream& is91 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR100Phi090");

is91.format(IOstream::ASCII);

is91 >> mOutR100Phi090;

46

Page 48: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

Istream& is92 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR100Phi120");

is92.format(IOstream::ASCII);

is92 >> mOutR100Phi120;

Istream& is93 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR100Phi150");

is93.format(IOstream::ASCII);

is93 >> mOutR100Phi150;

Istream& is94 = iMesh.solutionDict().subDict("volumeForceDisk").

lookup("wakeOutR100Phi180");

is94.format(IOstream::ASCII);

is94 >> mOutR100Phi180;

}

}

bool wake::CheckIfCellCenterIsInDisk(const vector &iStartCenterLine,

const vector &iEndCenterLine, const vector &iCellCenter, vector &oaxialDirection,

vector &oUpDirection, vector &oOutDirection, scalar &oAngle, const vector &ivecUp,

scalar &oRad, scalar &iInnerRadius, scalar &iOuterRadius, scalar &oDiskThickness) {

if(debug >= 1) {

Info << "Checks if the current cell center is located inside the non-zero volumeforce

disk\n";

}

//////////////////////////////////////////////////////////////////////////////////////

// Checks if current cell center is located inside the non-zero volumeforce disk

//////////////////////////////////////////////////////////////////////////////////////

// Calculates the centerline vector between startCenterLine and endCenterLine

vector vecCenterLine(iEndCenterLine - iStartCenterLine);

oDiskThickness = mag(vecCenterLine);

// Checks if the centerline length is positive and non-zero

if(!(oDiskThickness > 0)) {

Info << "The volumeforce disk has no length \n";

}

// Defines the axial direction as the centerline divided by its length

vecCenterLine /= mag(vecCenterLine);

oaxialDirection = vecCenterLine;

// Calculates the axial distance from the startpoint to the cell center

vector vecStartToCellCenter(iCellCenter - iStartCenterLine);

scalar CellCenterProjCenterLine(vecStartToCellCenter & vecCenterLine);

47

Page 49: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

//Checks if the cellcenter is located inside the disk in axial direction,

if not false is returned

if(!(CellCenterProjCenterLine >= 0.0 && CellCenterProjCenterLine <= oDiskThickness))

{

return false;

}

// Calculates perpendicular vector from centerline to cell center

vector vecCenterLineToCellCenter(vecStartToCellCenter -

(vecCenterLine*CellCenterProjCenterLine));

// Calculates the radial distance

scalar RadialDist = mag(vecCenterLineToCellCenter);

// Normalized by the radius of the volumeforce disk

(external radius - internal radius)

oRad = mag(RadialDist-iInnerRadius)/mag(iOuterRadius-iInnerRadius);

// Calculates the upward direction vector as the normalized

up direction specified by the user

vector vecUp(ivecUp);

vecUp /= mag(vecUp);

oUpDirection = vecUp;

// Calculates the angle between the upward vector and the perpendicular vector

(radial direction) from centerline to cell center

oAngle = acos(vecUp&vecCenterLineToCellCenter/(mag(vecUp)

*mag(vecCenterLineToCellCenter))) *180/mPI;

// Calculates a vector perpendicular to both the axial-

and radial direction always pointing outwards

oOutDirection = vecUp^vecCenterLine;

oOutDirection /= mag(oOutDirection);

// Checks if the projection of the radial vector onto the outdirection vector

is positive or zero, otherwise the outward vector is multiplied

by -1 to make sure it is pointing outwards

scalar foo = vecCenterLineToCellCenter&oOutDirection;

if( 0 > foo) {

oOutDirection *= -1;

}

48

Page 50: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

// Checks if the volumeforce disk radius is positive and non-zero and

the exterior radius is larger than the interior

if(!((mOuterRadius > mInnerRadius) & (mOuterRadius > 0))){

Info << "The exterior radius is zero or smaller than the interior radius \n";

}

// Check if the point is inside the volume force disk in the radial direction,

if so a true is returned

return(RadialDist <= mOuterRadius && RadialDist >= mInnerRadius);

}

void wake::CalcForceMagnitudes(const scalar &iAngle, const scalar &iRad,

scalar &oaxialForce, scalar &oupForce, scalar &ooutForce, const scalar &iFreeStreamVelocity,

scalar &oDiskThickness, const scalar &iRho, const scalar &iAxialR000Phi000,

const scalar &iAxialR025Phi000, const scalar &iAxialR025Phi030,

const scalar &iAxialR025Phi060,const scalar &iAxialR025Phi090,

const scalar &iAxialR025Phi120, const scalar &iAxialR025Phi150,

const scalar &iAxialR025Phi180, const scalar &iAxialR050Phi000,

const scalar &iAxialR050Phi030,const scalar &iAxialR050Phi060,

const scalar &iAxialR050Phi090, const scalar &iAxialR050Phi120,

const scalar &iAxialR050Phi150, const scalar &iAxialR050Phi180,

const scalar &iAxialR075Phi000,const scalar &iAxialR075Phi030,

const scalar &iAxialR075Phi060, const scalar &iAxialR075Phi090,

const scalar &iAxialR075Phi120, const scalar &iAxialR075Phi150,

const scalar &iAxialR075Phi180,const scalar &iAxialR100Phi000,

const scalar &iAxialR100Phi030, const scalar &iAxialR100Phi060,

const scalar &iAxialR100Phi090, const scalar &iAxialR100Phi120,

const scalar &iAxialR100Phi150,const scalar &iAxialR100Phi180,

const scalar &iUpR000Phi000, const scalar &iUpR025Phi000,

const scalar &iUpR025Phi030, const scalar &iUpR025Phi060,

const scalar &iUpR025Phi090,const scalar &iUpR025Phi120,

const scalar &iUpR025Phi150, const scalar &iUpR025Phi180,

const scalar &iUpR050Phi000, const scalar &iUpR050Phi030,

const scalar &iUpR050Phi060,const scalar &iUpR050Phi090, const scalar &iUpR050Phi120,

const scalar &iUpR050Phi150,

const scalar &iUpR050Phi180, const scalar &iUpR075Phi000, const scalar &iUpR075Phi030,

const scalar &iUpR075Phi060, const scalar &iUpR075Phi090, const scalar &iUpR075Phi120,

const scalar &iUpR075Phi150, const scalar &iUpR075Phi180, const scalar &iUpR100Phi000,

const scalar &iUpR100Phi030, const scalar &iUpR100Phi060, const scalar &iUpR100Phi090,

const scalar &iUpR100Phi120, const scalar &iUpR100Phi150, const scalar &iUpR100Phi180,

const scalar &iOutR000Phi000, const scalar &iOutR025Phi000, const scalar &iOutR025Phi030,

const scalar &iOutR025Phi060, const scalar &iOutR025Phi090, const scalar &iOutR025Phi120,

const scalar &iOutR025Phi150, const scalar &iOutR025Phi180, const scalar &iOutR050Phi000,

const scalar &iOutR050Phi030, const scalar &iOutR050Phi060, const scalar &iOutR050Phi090,

const scalar &iOutR050Phi120, const scalar &iOutR050Phi150, const scalar &iOutR050Phi180,

const scalar &iOutR075Phi000, const scalar &iOutR075Phi030, const scalar &iOutR075Phi060,

const scalar &iOutR075Phi090, const scalar &iOutR075Phi120, const scalar &iOutR075Phi150,

const scalar &iOutR075Phi180, const scalar &iOutR100Phi000, const scalar &iOutR100Phi030,

const scalar &iOutR100Phi060, const scalar &iOutR100Phi090, const scalar &iOutR100Phi120,

49

Page 51: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

const scalar &iOutR100Phi150, const scalar &iOutR100Phi180) {

if(debug >= 1) {

Info << "Calculates the volumeforce vector magnitudes\n";

}

/////////////////////////////////////////////////////////////////////////////////

// Calculates the target wakefraction based on radial and angular position.

// The magnitudes of the three components of the volumeforce vectors are

//calculated from the target wakefraction.

/////////////////////////////////////////////////////////////////////////////////

scalar axialWake = 0;

scalar axialWake11 = 0;

scalar axialWake12 = 0;

scalar axialWake21 = 0;

scalar axialWake22 = 0;

scalar upWake = 0;

scalar upWake11 = 0;

scalar upWake12 = 0;

scalar upWake21 = 0;

scalar upWake22 = 0;

scalar outWake = 0;

scalar outWake11 = 0;

scalar outWake12 = 0;

scalar outWake21 = 0;

scalar outWake22 = 0;

scalar Phi1 = 0;

scalar Phi2 = 1;

scalar Rad1 = 0;

scalar Rad2 = 0;

// Setting the nearby values (for interpolation)

// based on cell position (radial fraction and angle)

if(0.25 >= iRad){

Rad1 = 0;

Rad2 = 0.25;

if(30 >= iAngle){

axialWake11 = iAxialR000Phi000;

axialWake12 = iAxialR000Phi000;

axialWake21 = iAxialR025Phi000;

axialWake22 = iAxialR025Phi030;

upWake11 = iUpR000Phi000;

upWake12 = iUpR000Phi000;

upWake21 = iUpR025Phi000;

upWake22 = iUpR025Phi030;

50

Page 52: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

outWake11 = iOutR000Phi000;

outWake12 = iOutR000Phi000;

outWake21 = iOutR025Phi000;

outWake22 = iOutR025Phi030;

Phi1 = 0;

Phi2 = 30;

}

else if(60 >= iAngle){

axialWake11 = iAxialR000Phi000;

axialWake12 = iAxialR000Phi000;

axialWake21 = iAxialR025Phi030;

axialWake22 = iAxialR025Phi060;

upWake11 = iUpR000Phi000;

upWake12 = iUpR000Phi000;

upWake21 = iUpR025Phi030;

upWake22 = iUpR025Phi060;

outWake11 = iOutR000Phi000;

outWake12 = iOutR000Phi000;

outWake21 = iOutR025Phi030;

outWake22 = iOutR025Phi060;

Phi1 = 30;

Phi2 = 60;

}

else if(90 >= iAngle){

axialWake11 = iAxialR000Phi000;

axialWake12 = iAxialR000Phi000;

axialWake21 = iAxialR025Phi060;

axialWake22 = iAxialR025Phi090;

upWake11 = iUpR000Phi000;

upWake12 = iUpR000Phi000;

upWake21 = iUpR025Phi060;

upWake22 = iUpR025Phi090;

outWake11 = iOutR000Phi000;

outWake12 = iOutR000Phi000;

outWake21 = iOutR025Phi060;

outWake22 = iOutR025Phi090;

Phi1 = 60;

Phi2 = 90;

}

else if(120 >= iAngle){

axialWake11 = iAxialR000Phi000;

axialWake12 = iAxialR000Phi000;

axialWake21 = iAxialR025Phi090;

axialWake22 = iAxialR025Phi120;

upWake11 = iUpR000Phi000;

upWake12 = iUpR000Phi000;

upWake21 = iUpR025Phi090;

upWake22 = iUpR025Phi120;

51

Page 53: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

outWake11 = iOutR000Phi000;

outWake12 = iOutR000Phi000;

outWake21 = iOutR025Phi090;

outWake22 = iOutR025Phi120;

Phi1 = 90;

Phi2 = 120;

}

else if(150 >= iAngle){

axialWake11 = iAxialR000Phi000;

axialWake12 = iAxialR000Phi000;

axialWake21 = iAxialR025Phi120;

axialWake22 = iAxialR025Phi150;

upWake11 = iUpR000Phi000;

upWake12 = iUpR000Phi000;

upWake21 = iUpR025Phi120;

upWake22 = iUpR025Phi150;

outWake11 = iOutR000Phi000;

outWake12 = iOutR000Phi000;

outWake21 = iOutR025Phi120;

outWake22 = iOutR025Phi150;

Phi1 = 120;

Phi2 = 150;

}

else if(180 >= iAngle){

axialWake11 = iAxialR000Phi000;

axialWake12 = iAxialR000Phi000;

axialWake21 = iAxialR025Phi150;

axialWake22 = iAxialR025Phi180;

upWake11 = iUpR000Phi000;

upWake12 = iUpR000Phi000;

upWake21 = iUpR025Phi150;

upWake22 = iUpR025Phi180;

outWake11 = iOutR000Phi000;

outWake12 = iOutR000Phi000;

outWake21 = iOutR025Phi150;

outWake22 = iOutR025Phi180;

Phi1 = 150;

Phi2 = 180;

}

}

else if(0.5 >= iRad){

Rad1 = 0.25;

Rad2 = 0.5;

if(30 >= iAngle){

52

Page 54: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

axialWake11 = iAxialR025Phi000;

axialWake12 = iAxialR025Phi030;

axialWake21 = iAxialR050Phi000;

axialWake22 = iAxialR050Phi030;

upWake11 = iUpR025Phi000;

upWake12 = iUpR025Phi030;

upWake21 = iUpR050Phi000;

upWake22 = iUpR050Phi030;

outWake11 = iOutR025Phi000;

outWake12 = iOutR025Phi030;

outWake21 = iOutR050Phi000;

outWake22 = iOutR050Phi030;

Phi1 = 0;

Phi2 = 30;

}

else if(60 >= iAngle){

axialWake11 = iAxialR025Phi030;

axialWake12 = iAxialR025Phi060;

axialWake21 = iAxialR050Phi030;

axialWake22 = iAxialR050Phi060;

upWake11 = iUpR025Phi030;

upWake12 = iUpR025Phi060;

upWake21 = iUpR050Phi030;

upWake22 = iUpR050Phi060;

outWake11 = iOutR025Phi030;

outWake12 = iOutR025Phi060;

outWake21 = iOutR050Phi030;

outWake22 = iOutR050Phi060;

Phi1 = 30;

Phi2 = 60;

}

else if(90 >= iAngle){

axialWake11 = iAxialR025Phi060;

axialWake12 = iAxialR025Phi090;

axialWake21 = iAxialR050Phi060;

axialWake22 = iAxialR050Phi090;

upWake11 = iUpR025Phi060;

upWake12 = iUpR025Phi090;

upWake21 = iUpR050Phi060;

upWake22 = iUpR050Phi090;

outWake11 = iOutR025Phi060;

outWake12 = iOutR025Phi090;

outWake21 = iOutR050Phi060;

outWake22 = iOutR050Phi090;

Phi1 = 60;

Phi2 = 90;

53

Page 55: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

}

else if(120 >= iAngle){

axialWake11 = iAxialR025Phi090;

axialWake12 = iAxialR025Phi120;

axialWake21 = iAxialR050Phi090;

axialWake22 = iAxialR050Phi120;

upWake11 = iUpR025Phi090;

upWake12 = iUpR025Phi120;

upWake21 = iUpR050Phi090;

upWake22 = iUpR050Phi120;

outWake11 = iOutR025Phi090;

outWake12 = iOutR025Phi120;

outWake21 = iOutR050Phi090;

outWake22 = iOutR050Phi120;

Phi1 = 90;

Phi2 = 120;

}

else if(150 >= iAngle){

axialWake11 = iAxialR025Phi120;

axialWake12 = iAxialR025Phi150;

axialWake21 = iAxialR050Phi120;

axialWake22 = iAxialR050Phi150;

upWake11 = iUpR025Phi120;

upWake12 = iUpR025Phi150;

upWake21 = iUpR050Phi120;

upWake22 = iUpR050Phi150;

outWake11 = iOutR025Phi120;

outWake12 = iOutR025Phi150;

outWake21 = iOutR050Phi120;

outWake22 = iOutR050Phi150;

Phi1 = 120;

Phi2 = 150;

}

else if(180 >= iAngle){

axialWake11 = iAxialR025Phi150;

axialWake12 = iAxialR025Phi180;

axialWake21 = iAxialR050Phi150;

axialWake22 = iAxialR050Phi180;

upWake11 = iUpR025Phi150;

upWake12 = iUpR025Phi180;

upWake21 = iUpR050Phi150;

upWake22 = iUpR050Phi180;

outWake11 = iOutR025Phi150;

outWake12 = iOutR025Phi180;

outWake21 = iOutR050Phi150;

outWake22 = iOutR050Phi180;

54

Page 56: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

Phi1 = 150;

Phi2 = 180;

}

}

else if(0.75 >= iRad){

Rad1 = 0.5;

Rad2 = 0.75;

if(30 >= iAngle){

axialWake11 = iAxialR050Phi000;

axialWake12 = iAxialR050Phi030;

axialWake21 = iAxialR075Phi000;

axialWake22 = iAxialR075Phi030;

upWake11 = iUpR050Phi000;

upWake12 = iUpR050Phi030;

upWake21 = iUpR075Phi000;

upWake22 = iUpR075Phi030;

outWake11 = iOutR050Phi000;

outWake12 = iOutR050Phi030;

outWake21 = iOutR075Phi000;

outWake22 = iOutR075Phi030;

Phi1 = 0;

Phi2 = 30;

}

else if(60 >= iAngle){

axialWake11 = iAxialR050Phi030;

axialWake12 = iAxialR050Phi060;

axialWake21 = iAxialR075Phi030;

axialWake22 = iAxialR075Phi060;

upWake11 = iUpR050Phi030;

upWake12 = iUpR050Phi060;

upWake21 = iUpR075Phi030;

upWake22 = iUpR075Phi060;

outWake11 = iOutR050Phi030;

outWake12 = iOutR050Phi060;

outWake21 = iOutR075Phi030;

outWake22 = iOutR075Phi060;

Phi1 = 30;

Phi2 = 60;

}

else if(90 >= iAngle){

axialWake11 = iAxialR050Phi060;

axialWake12 = iAxialR050Phi090;

axialWake21 = iAxialR075Phi060;

axialWake22 = iAxialR075Phi090;

upWake11 = iUpR050Phi060;

55

Page 57: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

upWake12 = iUpR050Phi090;

upWake21 = iUpR075Phi060;

upWake22 = iUpR075Phi090;

outWake11 = iOutR050Phi060;

outWake12 = iOutR050Phi090;

outWake21 = iOutR075Phi060;

outWake22 = iOutR075Phi090;

Phi1 = 60;

Phi2 = 90;

}

else if(120 >= iAngle){

axialWake11 = iAxialR050Phi090;

axialWake12 = iAxialR050Phi120;

axialWake21 = iAxialR075Phi090;

axialWake22 = iAxialR075Phi120;

upWake11 = iUpR050Phi090;

upWake12 = iUpR050Phi120;

upWake21 = iUpR075Phi090;

upWake22 = iUpR075Phi120;

outWake11 = iOutR050Phi090;

outWake12 = iOutR050Phi120;

outWake21 = iOutR075Phi090;

outWake22 = iOutR075Phi120;

Phi1 = 90;

Phi2 = 120;

}

else if(150 >= iAngle){

axialWake11 = iAxialR050Phi120;

axialWake12 = iAxialR050Phi150;

axialWake21 = iAxialR075Phi120;

axialWake22 = iAxialR075Phi150;

upWake11 = iUpR050Phi120;

upWake12 = iUpR050Phi150;

upWake21 = iUpR075Phi120;

upWake22 = iUpR075Phi150;

outWake11 = iOutR050Phi120;

outWake12 = iOutR050Phi150;

outWake21 = iOutR075Phi120;

outWake22 = iOutR075Phi150;

Phi1 = 120;

Phi2 = 150;

}

else if(180 >= iAngle){

axialWake11 = iAxialR050Phi150;

axialWake12 = iAxialR050Phi180;

axialWake21 = iAxialR075Phi150;

56

Page 58: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

axialWake22 = iAxialR075Phi180;

upWake11 = iUpR050Phi150;

upWake12 = iUpR050Phi180;

upWake21 = iUpR075Phi150;

upWake22 = iUpR075Phi180;

outWake11 = iOutR050Phi150;

outWake12 = iOutR050Phi180;

outWake21 = iOutR075Phi150;

outWake22 = iOutR075Phi180;

Phi1 = 150;

Phi2 = 180;

}

}

else if(1 >= iRad){

Rad1 = 0.75;

Rad2 = 1;

if(30 >= iAngle){

axialWake11 = iAxialR075Phi000;

axialWake12 = iAxialR075Phi030;

axialWake21 = iAxialR100Phi000;

axialWake22 = iAxialR100Phi030;

upWake11 = iUpR075Phi000;

upWake12 = iUpR075Phi030;

upWake21 = iUpR100Phi000;

upWake22 = iUpR100Phi030;

outWake11 = iOutR075Phi000;

outWake12 = iOutR075Phi030;

outWake21 = iOutR100Phi000;

outWake22 = iOutR100Phi030;

Phi1 = 0;

Phi2 = 30;

}

else if(60 >= iAngle){

axialWake11 = iAxialR075Phi030;

axialWake12 = iAxialR075Phi060;

axialWake21 = iAxialR100Phi030;

axialWake22 = iAxialR100Phi060;

upWake11 = iUpR075Phi030;

upWake12 = iUpR075Phi060;

upWake21 = iUpR100Phi030;

upWake22 = iUpR100Phi060;

outWake11 = iOutR075Phi030;

outWake12 = iOutR075Phi060;

outWake21 = iOutR100Phi030;

outWake22 = iOutR100Phi060;

57

Page 59: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

Phi1 = 30;

Phi2 = 60;

}

else if(90 >= iAngle){

axialWake11 = iAxialR075Phi060;

axialWake12 = iAxialR075Phi090;

axialWake21 = iAxialR100Phi060;

axialWake22 = iAxialR100Phi090;

upWake11 = iUpR075Phi060;

upWake12 = iUpR075Phi090;

upWake21 = iUpR100Phi060;

upWake22 = iUpR100Phi090;

outWake11 = iOutR075Phi060;

outWake12 = iOutR075Phi090;

outWake21 = iOutR100Phi060;

outWake22 = iOutR100Phi090;

Phi1 = 60;

Phi2 = 90;

}

else if(120 >= iAngle){

axialWake11 = iAxialR075Phi090;

axialWake12 = iAxialR075Phi120;

axialWake21 = iAxialR100Phi090;

axialWake22 = iAxialR100Phi120;

upWake11 = iUpR075Phi090;

upWake12 = iUpR075Phi120;

upWake21 = iUpR100Phi090;

upWake22 = iUpR100Phi120;

outWake11 = iOutR075Phi090;

outWake12 = iOutR075Phi120;

outWake21 = iOutR100Phi090;

outWake22 = iOutR100Phi120;

Phi1 = 90;

Phi2 = 120;

}

else if(150 >= iAngle){

axialWake11 = iAxialR075Phi120;

axialWake12 = iAxialR075Phi150;

axialWake21 = iAxialR100Phi120;

axialWake22 = iAxialR100Phi150;

upWake11 = iUpR075Phi120;

upWake12 = iUpR075Phi150;

upWake21 = iUpR100Phi120;

upWake22 = iUpR100Phi150;

outWake11 = iOutR075Phi120;

58

Page 60: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

outWake12 = iOutR075Phi150;

outWake21 = iOutR100Phi120;

outWake22 = iOutR100Phi150;

Phi1 = 120;

Phi2 = 150;

}

else if(180 >= iAngle){

axialWake11 = iAxialR075Phi150;

axialWake12 = iAxialR075Phi180;

axialWake21 = iAxialR100Phi150;

axialWake22 = iAxialR100Phi180;

upWake11 = iUpR075Phi150;

upWake12 = iUpR075Phi180;

upWake21 = iUpR100Phi150;

upWake22 = iUpR100Phi180;

outWake11 = iOutR075Phi150;

outWake12 = iOutR075Phi180;

outWake21 = iOutR100Phi150;

outWake22 = iOutR100Phi180;

Phi1 = 150;

Phi2 = 180;

}

}

// Interpolation of wake fractions

axialWake = (axialWake11*(Phi2-iAngle)*(1/(Phi2-Phi1))

+axialWake12*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(Rad2 - iRad)*(1/0.25)

+ (axialWake21*(Phi2-iAngle)*(1/(Phi2-Phi1))+axialWake22*(iAngle-Phi1)

*(1/(Phi2-Phi1)))*(iRad - Rad1)*(1/0.25);

upWake = (upWake11*(Phi2-iAngle)*(1/(Phi2-Phi1))

+upWake12*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(Rad2 - iRad)*(1/0.25)

+ (upWake21*(Phi2-iAngle)*(1/(Phi2-Phi1))

+upWake22*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(iRad - Rad1)*(1/0.25);

outWake = (outWake11*(Phi2-iAngle)*(1/(Phi2-Phi1))

+outWake12*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(Rad2 - iRad)*(1/0.25)

+ (outWake21*(Phi2-iAngle)*(1/(Phi2-Phi1))

+outWake22*(iAngle-Phi1)*(1/(Phi2-Phi1)))*(iRad - Rad1)*(1/0.25);

// Calculates force magnitudes based on the wake fractions

oaxialForce = iRho * 0.5 * ( (1-axialWake) * iFreeStreamVelocity

* mag(1-axialWake) * iFreeStreamVelocity

- iFreeStreamVelocity * iFreeStreamVelocity)/oDiskThickness;

oupForce = iRho * 0.5 * (1 - upWake)*iFreeStreamVelocity

*mag(1 - upWake)*iFreeStreamVelocity/oDiskThickness;

ooutForce = iRho * 0.5 * (1 - outWake)*iFreeStreamVelocity

*mag(1 - outWake)*iFreeStreamVelocity/oDiskThickness;

59

Page 61: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

}

void wake::CalcVolumeForce(const fvMesh &iMesh, vectorField &ioVolumeForceField) {

if(debug >= 1) {

Info << "Computes the volumeforce vector field\n";

}

// Reading the parameters specified in fvSolution

ReadParameters(iMesh);

// Declaring the output variables

scalar Angle;

vector axialDirection;

vector UpDirection;

vector OutDirection;

vector TotalForce(0,0,0);

scalar Rad;

scalar axialForce;

scalar upForce;

scalar outForce;

scalar diskThickness;

// Loop over all cells

for(label i = 0; i < iMesh.C().size(); i++) {

// Checks if the cell center is in the volumeforce disk

if(CheckIfCellCenterIsInDisk(mStartCenterLine,mEndCenterLine,iMesh.C()[i],

axialDirection, UpDirection, OutDirection, Angle, mvecUp, Rad, mInnerRadius,

mOuterRadius, diskThickness)) {

// Initializes the force magnitude calculation for cells with cell center inside the disk

CalcForceMagnitudes(Angle, Rad, axialForce, upForce, outForce,

mFreeStreamVelocity, diskThickness, mRho, mAxialR000Phi000,mAxialR025Phi000,

mAxialR025Phi030, mAxialR025Phi060, mAxialR025Phi090, mAxialR025Phi120,

mAxialR025Phi150, mAxialR025Phi180, mAxialR050Phi000, mAxialR050Phi030,

mAxialR050Phi060, mAxialR050Phi090, mAxialR050Phi120, mAxialR050Phi150,

mAxialR050Phi180, mAxialR075Phi000, mAxialR075Phi030, mAxialR075Phi060,

mAxialR075Phi090, mAxialR075Phi120, mAxialR075Phi150, mAxialR075Phi180,

mAxialR100Phi000, mAxialR100Phi030, mAxialR100Phi060, mAxialR100Phi090,

mAxialR100Phi120, mAxialR100Phi150, mAxialR100Phi180, mUpR000Phi000,

mUpR025Phi000, mUpR025Phi030, mUpR025Phi060, mUpR025Phi090,

mUpR025Phi120, mUpR025Phi150, mUpR025Phi180, mUpR050Phi000,

mUpR050Phi030, mUpR050Phi060, mUpR050Phi090, mUpR050Phi120,

mUpR050Phi150, mUpR050Phi180, mUpR075Phi000, mUpR075Phi030,

mUpR075Phi060, mUpR075Phi090, mUpR075Phi120, mUpR075Phi150,

mUpR075Phi180, mUpR100Phi000, mUpR100Phi030, mUpR100Phi060,

mUpR100Phi090, mUpR100Phi120, mUpR100Phi150, mUpR100Phi180,

mOutR000Phi000, mOutR025Phi000, mOutR025Phi030, mOutR025Phi060,

mOutR025Phi090, mOutR025Phi120, mOutR025Phi150, mOutR025Phi180,

mOutR050Phi000, mOutR050Phi030, mOutR050Phi060, mOutR050Phi090,

mOutR050Phi120, mOutR050Phi150, mOutR050Phi180, mOutR075Phi000,

mOutR075Phi030, mOutR075Phi060, mOutR075Phi090, mOutR075Phi120,

mOutR075Phi150, mOutR075Phi180, mOutR100Phi000, mOutR100Phi030,

60

Page 62: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX B. WAKE.CPP

mOutR100Phi060, mOutR100Phi090, mOutR100Phi120, mOutR100Phi150,

mOutR100Phi180);

// Calculates the volumeforce vector to be added in the current cell

vector vecVolumeForce = axialDirection*axialForce +

UpDirection*upForce + OutDirection*outForce;

// Adds the volumeforce vector to the volumeforce vector field

ioVolumeForceField[i] += vecVolumeForce;

// Calculates the total added force by summing the volumeforce multiplied

//by the cell volume for all cells

TotalForce += vecVolumeForce*iMesh.V()[i];

}

}

// Writes the total added force

Info << "Total added force: " << TotalForce << "\n";

}

61

Page 63: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

Appendix C

fvSolution

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

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

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

| \\ / O peration | Version: 2.1.x |

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

| \\/ M anipulation | |

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

FoamFile

{

version 2.0;

format ascii;

class dictionary;

object fvSolution;

}

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

solvers

{

alpha1

{

maxUnboundedness 1e-5;

CoCoeff 2;

maxIter 5;

nLimiterIter 2;

solver PBiCG;

preconditioner DILU;

tolerance 1e-12;

relTol 0.1;

};

U

{

solver PBiCG;

preconditioner DILU;

tolerance 1e-06;

relTol 0;

};

62

Page 64: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX C. FVSOLUTION

UFinal

{

$U;

}

p_rgh

{

solver GAMG;

tolerance 1e-8;

relTol 0.1;

smoother DICGaussSeidel;

nPreSweeps 0;

nPostSweeps 2;

cacheAgglomeration true;

nCellsInCoarsestLevel 10;

agglomerator faceAreaPair;

mergeLevels 1;

maxIter 50;

};

pcorr

{

$p_rgh;

relTol 0;

};

p_rghFinal

{

solver PCG;

preconditioner

{

preconditioner GAMG;

tolerance 1e-6;

relTol 0;

nVcycles 2;

smoother DICGaussSeidel;

nPreSweeps 0;

nPostSweeps 2;

nFinestSweeps 2;

cacheAgglomeration false;

nCellsInCoarsestLevel 10;

agglomerator faceAreaPair;

mergeLevels 1;

};

tolerance 1e-7;

relTol 0;

63

Page 65: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX C. FVSOLUTION

maxIter 50;

};

}

PIMPLE

{

momentumPredictor yes;

nOuterCorrectors 1;

nCorrectors 1;

nNonOrthogonalCorrectors 1;

cAlpha 0;

nAlphaCorr 1;

nAlphaSubCycles 1;

}

relaxationFactors

{

fields

{

}

equations

{

"U.*" 1;

}

}

volumeForceDisk

{

startCenterLine (0 0 0);

endCenterLine (0 0 0.12);

upDirection (0 1 0);

innerRadius 0.5;

outerRadius 2;

freeStreamVelocity 7;

density 1000;

wakeAxialR000Phi000 0.5;

wakeAxialR025Phi000 0.6;

wakeAxialR025Phi030 0.45;

wakeAxialR025Phi060 0.6;

wakeAxialR025Phi090 0.6;

wakeAxialR025Phi120 0.6;

wakeAxialR025Phi150 0.75;

wakeAxialR025Phi180 0.7;

wakeAxialR050Phi000 0.65;

wakeAxialR050Phi030 0.65;

wakeAxialR050Phi060 0.7;

wakeAxialR050Phi090 0.6;

64

Page 66: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX C. FVSOLUTION

wakeAxialR050Phi120 0.6;

wakeAxialR050Phi150 0.6;

wakeAxialR050Phi180 0.5;

wakeAxialR075Phi000 0.7;

wakeAxialR075Phi030 0.5;

wakeAxialR075Phi060 0.5;

wakeAxialR075Phi090 0.35;

wakeAxialR075Phi120 0.35;

wakeAxialR075Phi150 0.35;

wakeAxialR075Phi180 0.3;

wakeAxialR100Phi000 0.65;

wakeAxialR100Phi030 0.35;

wakeAxialR100Phi060 0.35;

wakeAxialR100Phi090 0.1;

wakeAxialR100Phi120 0.05;

wakeAxialR100Phi150 0.05;

wakeAxialR100Phi180 0.05;

wakeUpR000Phi000 1.2;

wakeUpR025Phi000 1.2;

wakeUpR025Phi030 1.1;

wakeUpR025Phi060 1.02;

wakeUpR025Phi090 1;

wakeUpR025Phi120 1.02;

wakeUpR025Phi150 1.05;

wakeUpR025Phi180 1;

wakeUpR050Phi000 1.2;

wakeUpR050Phi030 1.05;

wakeUpR050Phi060 0.97;

wakeUpR050Phi090 0.95;

wakeUpR050Phi120 0.95;

wakeUpR050Phi150 0.97;

wakeUpR050Phi180 0.9;

wakeUpR075Phi000 1.1;

wakeUpR075Phi030 1.05;

wakeUpR075Phi060 0.92;

wakeUpR075Phi090 0.88;

wakeUpR075Phi120 0.9;

wakeUpR075Phi150 0.93;

wakeUpR075Phi180 0.95;

wakeUpR100Phi000 1.03;

wakeUpR100Phi030 0.97;

wakeUpR100Phi060 0.88;

wakeUpR100Phi090 0.9;

wakeUpR100Phi120 0.92;

wakeUpR100Phi150 0.94;

65

Page 67: Project work: Generating a wake eld using volume forceshani/kurser/OS_CFD_2012/Anonymous... · 2012. 12. 12. · CFD with OpenSource software A course at Chalmers University of Technology

APPENDIX C. FVSOLUTION

wakeUpR100Phi180 0.95;

wakeOutR000Phi000 1;

wakeOutR025Phi000 1;

wakeOutR025Phi030 1;

wakeOutR025Phi060 1;

wakeOutR025Phi090 1.01;

wakeOutR025Phi120 0.99;

wakeOutR025Phi150 1;

wakeOutR025Phi180 1;

wakeOutR050Phi000 1;

wakeOutR050Phi030 1.05;

wakeOutR050Phi060 1.02;

wakeOutR050Phi090 1.01;

wakeOutR050Phi120 0.98;

wakeOutR050Phi150 0.99;

wakeOutR050Phi180 1;

wakeOutR075Phi000 1;

wakeOutR075Phi030 1.08;

wakeOutR075Phi060 1.05;

wakeOutR075Phi090 1.01;

wakeOutR075Phi120 1.02;

wakeOutR075Phi150 1.005;

wakeOutR075Phi180 1;

wakeOutR100Phi000 1;

wakeOutR100Phi030 1.12;

wakeOutR100Phi060 1.08;

wakeOutR100Phi090 1.02;

wakeOutR100Phi120 1;

wakeOutR100Phi150 0.99;

wakeOutR100Phi180 1;

}

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

66