46
Cite as: Katsidoniotaki, E.: Focused Wave generation based on Linear NewWave Theory, using OpenFOAM and waves2Foam toolbox. In Proceedings of CFD with OpenSource Software, 2019, Edited by Nilsson. H., http://dx.doi.org/10.17196/OS_CFD#YEAR_2019 CFD with OpenSource software A course at Chalmers University of Technology Taught by H˚ akan Nilsson Focused Wave generation based on Linear NewWave Theory, using OpenFOAM and and waves2Foam toolbox Developed for OpenFOAMv1906 Requires: waves2Foam toolbox and waveFoam solver Author: Eirini Katsidoniotaki Uppsala University, Sweden [email protected] Peer reviewed by: Mohammad Khanouki Petra Tisovska Licensed under CC-BY-NC-SA, https://creativecommons.org/licenses/ Disclaimer: This is a student project work, done as part of a course where OpenFOAM and some other OpenSource software are introduced to the students. Any reader should be aware that it might not be free of errors. Still, it might be useful for someone who would like learn some details similar to the ones presented in the report and in the accompanying files. The material has gone through a review process. The role of the reviewer is to go through the tutorial and make sure that it works, that it is possible to follow, and to some extent correct the writing. The reviewer has no responsibility for the contents. December 22, 2019

Focused Wave generation based on Linear NewWave Theory

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Focused Wave generation based on Linear NewWave Theory

Cite as: Katsidoniotaki, E.: Focused Wave generation based on Linear NewWave Theory, using

OpenFOAM and waves2Foam toolbox. In Proceedings of CFD with OpenSource Software, 2019, Edited by

Nilsson. H., http://dx.doi.org/10.17196/OS_CFD#YEAR_2019

CFD with OpenSource software

A course at Chalmers University of TechnologyTaught by Hakan Nilsson

Focused Wave generation based on LinearNewWave Theory, using OpenFOAM and

and waves2Foam toolbox

Developed for OpenFOAMv1906Requires: waves2Foam toolboxand waveFoam solver

Author:Eirini KatsidoniotakiUppsala University, [email protected]

Peer reviewed by:Mohammad Khanouki

Petra Tisovska

Licensed under CC-BY-NC-SA, https://creativecommons.org/licenses/

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

might not be free of errors. Still, it might be useful for someone who would like learn some detailssimilar to the ones presented in the report and in the accompanying files. The material has gone

through a review process. The role of the reviewer is to go through the tutorial and make sure thatit works, that it is possible to follow, and to some extent correct the writing. The reviewer has no

responsibility for the contents.

December 22, 2019

Page 2: Focused Wave generation based on Linear NewWave Theory

Learning outcomes

The main requirements of a tutorial is that it should teach the four points: How to use it, Thetheory of it, How it is implemented, and How to modify it. Therefore the list of learning outcomesis organized with those headers.

The reader will learn:

How to use it:

• Classification of waves2Foam toolbox libraries and classes

• Categorization of the available Wave Theories in waves2Foam toolbox

• How to create a new Wave Theory besides the existing ones in the waves2Foam toolbox

• How to set up basic the Ocean Wave parameters and wave spectra characteristics at thewaveParameters.input dictionary

The theory of it:

• Why extreme wave simulation?

• Linear NewWave Theory

• Wave spectrum theories

How it is implemented:

• waves2Foam and waves2FoamProcessing libraries description

• Description of waveTheory class and sub-classes

• Description of setWaveProperties class and sub-classes

• Description of waveSpectra class and sub-classes

How to modify it:

• Steps for creating a new Wave Theory in waves2Foam toolbox

• Source code modification

• Settings in the waveProperties.input dictionary

• Example of Numerical Wave Tank with wave propagation based on NewWave Theory

1

Page 3: Focused Wave generation based on Linear NewWave Theory

Prerequisites

The reader is expected to know the following in order to get maximum benefit out of this report:

• Knowledge about Ocean waves theories

• Previous experience with the toolbox waves2Foam and ocean wave generation citation [Jacob-sen, N. G., Fuhrman, D. R. and Fredsøe, J. (2012), ’A wave generation toolbox for theopen-source CFD library: OpenFOAM’,International Journal for Numerical Methods in Fluids 70,1073-1088]

• Fundamentals of Linear New Wave Theory; citation [Tromans, P. S., Anaturk, A. R. andHagemeijer, P. (1991), A new model for the kinematics oflarge ocean waves - application asa design wave,in ’Proceedings of the 1st InternationalOffshore and Polar Engineering Confer-ence’, Edinburgh, UK, pp. 64-71]

• It is recommended to gain a brief insight about the purpose of focused wave generation based onLinear Wave Theory from PhD theses: Survivability of Wave Energy Converter and MooringCoupled System using CFD, 2015, Edward Jack Ransley

2

Page 4: Focused Wave generation based on Linear NewWave Theory

Contents

1 Introduction 51.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2 Theoretical Background 62.1 Waves2Foam toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Extreme wave simulation in OpenFOAM . . . . . . . . . . . . . . . . . . . . . . . . . 72.3 NewWave Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.4 Wave Spectrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.4.1 JONSWAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.4.2 Pierson-Moskowitz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3 Waves2Foam Toolbox’s Libraries and Classes Organization 103.1 Role of waves2Foam Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3.1.1 waveTheory class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.1.2 waveTheory class and sub-classes . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.2 Role of waves2FoamProcessing Library . . . . . . . . . . . . . . . . . . . . . . . . . . 183.2.1 setWaveProperties class part of waves2FoamProcessing library . . . . . . . . 193.2.2 setWaveProperties class and sub-classes . . . . . . . . . . . . . . . . . . . . . 193.2.3 Main class setWaveProperties.C and sub-classes . . . . . . . . . . . . . . . . . 203.2.4 Wave Spectrum Theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4 Modification 254.1 focusedWave type in waves2Foam library . . . . . . . . . . . . . . . . . . . . . . . . 25

4.1.1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.1.2 Rename files and folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.1.3 Change class name in source files . . . . . . . . . . . . . . . . . . . . . . . . . 254.1.4 Create Make folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264.1.5 Modify Make/files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

4.2 focusedWaveProperties in waves2FoamProcessing library . . . . . . . . . . . . . . . . 264.2.1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.2.2 Rename files and folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.2.3 Change class name in source files . . . . . . . . . . . . . . . . . . . . . . . . . 274.2.4 Create Make folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.2.5 Modify Make/files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

4.3 Compile the waves2Foam and waves2FoamProcessing libraries . . . . . . . . . . . . . 284.4 Tutorial focusedWave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.5 Create wave spectra class for focusedWave type . . . . . . . . . . . . . . . . . . . . . 30

4.5.1 Rename files and folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.5.2 Change class name in source files . . . . . . . . . . . . . . . . . . . . . . . . . 304.5.3 Source code modification in PiersonMoskowitz class . . . . . . . . . . . . . . 314.5.4 Source code modification in JONSWAP class . . . . . . . . . . . . . . . . . . 324.5.5 Modify Make/files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

4.6 Compile the waves2Foam and waves2FoamProcessing libraries . . . . . . . . . . . . . 34

3

Page 5: Focused Wave generation based on Linear NewWave Theory

CONTENTS CONTENTS

5 Test Case 355.1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365.2 Set-up the 0.org folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365.3 Set-up the Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365.4 Set-up the system folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

5.4.1 Modify the fvSchemes file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375.4.2 Modify the fvSolution file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375.4.3 Modify the controlDict file . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

5.5 Set-up the constant folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405.5.1 Modify the waveProperties.input file . . . . . . . . . . . . . . . . . . . . . . . 405.5.2 Modify the transportProperties file . . . . . . . . . . . . . . . . . . . . . . . . 41

5.6 Set-up the Allrun file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.7 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

4

Page 6: Focused Wave generation based on Linear NewWave Theory

Chapter 1

Introduction

1.1 Introduction

The interest for extreme wave conditions in the offshore marine sector is growing. Numerical andexperimental approaches are used to model the response of a device under the experience of extremewaves. In practice, in one commonly used extreme wave approach, an extreme wave is generated bythe superposition of different frequency wave components focusing at a specific point in space andtime; thus, the term focused wave. In offshore engineering, the design wave approach ”NewWave”is devised for modelling extreme wave interactions with offshore structures. Therefore, the focusedwave group based on NewWave theory is often used for that purpose.

The toolbox waves2Foam is introduced in this tutorial. waves2Foam, coupled with OpenFOAM,is widespread applied for ocean waves generation. The toolbox includes important waves theories,techniques for wave generation and absorption, solvers for ocean wave interaction and propagationin a computational domain.

The purpose of this tutorial is to discuss how linear NewWave Theory can be added besides theexisting wave theories in the waves2Foam toolbox. In general, a focused wave can be generatedusing either irregular or combinedWaves wave type. But in particular, focused wave relying onNewWave Theory can be done only by combinedWaves type. In this case, an extrernal procedure isdemanded for building the wave components imported in the waveProperties.input file.

The purpose of this tutorial is to allow the waves2Foam user to choose directly a new wave typenamed focusedWave based on the linear New Wave Theory. It is the simplest approach since actu-ally represents the superposition of Stokes First type ocean wave components focusing in a definedlocation and time. A design spectrum similar to Pierson Moskowitz and JONSWAP spectra is usedto describe the wave conditions for a particular sea location.

In the waves2Foam toolbox, the required classes needed for the generation of focusedWave can befound. However, some modifications should be implemented in terms of wave components amplitudecalculation according to NewWave Theory.

5

Page 7: Focused Wave generation based on Linear NewWave Theory

Chapter 2

Theoretical Background

One of the main purposes of this tutorial is the ocean wave simulation in extreme conditions. Areliable toolbox named waves2Foam has been developed for ocean wave’s generation and is coupledwith OpenFOAM.

This section provides a brief description of waves2Foam toolbox and discusses the necessity forextreme wave CFD simulations. Moreover, a new wave type has been added in the waves2Foamtoolbox with the name focusedWave. The theoretical background of the wave type is based on NewWave Theory, which is also explained herein.

2.1 Waves2Foam toolbox

The library waves2Foam is a toolbox used to generate and absorb free surface water waves. Currentlythe method applies the relaxation zone technique and a large range of wave theories are supported.The toolbox is also able to model the interaction between free-surface waves and a permeable mediumsuch as breakwaters, scour protection etc. Instructions on how to download and install the toolboxcan be found at http://openfoamwiki.net/ index.php/Contrib/waves2Foam.

For making waves2Foam toolbox compatible with OpenFoam v1906, only minor changes are needed.Since the complex number class in OpenFOAM/src/OpenFOAM has changed and thus two small changesare needed:

1. In the file

/waves2Foam/src/waves2FoamProcessing/Make/files

the following line should be commented out:

/* $(ppw)/$(spec)/$(specHelp)/complexExp.C */

2. In the file

/postProcessing/postProcessingWaves/spectralAnalysis/fftBasedMethods \

/reflectionAnalysis2DFFT/reflectionAnalysis2DFFT.C",

the expression complex::zero should be changed to complex(Zero), in 4 instances.

The available wave theories in waves2Foam toolbox are algebraic, bichromatic, first-order irregular,potential current, solitary wave theory, combined waves and external wave theories.

In order to give the information for the First-order irregular wave theory, there are three classes ofinformation needed:

6

Page 8: Focused Wave generation based on Linear NewWave Theory

2.2. EXTREME WAVE SIMULATION IN OPENFOAMCHAPTER 2. THEORETICAL BACKGROUND

1. Spectral Shape

2. Spectral discretization

3. Phases

The following spectral shape are currently implemented:

1. JONSWAP

2. Pierson-Moskowitz

There are currently two discretization methods available for the frequency axis

1. equidistantFrequencyAxis

2. cosineStretchedFrequencyAxis

There are two types of phasing methods available

1. randomPhase

2. focusingPhase

More information about the waves2Foam toolbox are available in the manualhttps://www.researchgate.net/publication/319160515_waves2Foam_Manual

In waves2Foam toolbox, there is the option for focused wave generation using the available classesbut not for linear NewWave Theory focused wave generation. The wave components amplitudecalculation, as the NewWave theory dictates, is not supported by any of the available classes.

One way to generate focused wave based on NewWave Theory is to use the combinedWaves type.However, a pre-processing stage is needed for setting-up the wave components in the waveProperties.inputfile. The user should first define manually each one of the wave components and then introduce themin the waveProperties.input file. For doing that, Matlab or Python scripts are required in mostof the cases. For example, the combinedWaves type combines all the wave components provided inthe wavesProperties.input file. For a focused wave generation, it can consist of hundrend of wavecomponents. In that case, additional scripts are used in order to insert the characteristic of eachone of the wave components to waveProperties file.

2.2 Extreme wave simulation in OpenFOAM

Numerical simulation based on Computational Fluid Dynamic (CFD) has attracted a lot of attentionrecently due to advances in numerical methods and the availability of high performance computers.CFD is a useful tool to predict impact forces potentially with high accuracy for floating bodies. Toevaluate floating bodies’ impact loads, an extreme wave generator needs to be deployed.

The extreme wave occurs as a highly transient event within a multi frequency sea state. Regularwaves, such as Stokes 5th order, do not represent these extreme waves accurately and random wavegeneration is an extremely time consuming process, as the events of interest only occur rarely.

A fully non-linear theoretical model of an extreme wave does not exist. Therefore, the final conceptof extreme wave representation is the motion of a single event with a specific shape and crest heightover a single associated period. This equivalent extreme wave approach can be applied to examinepeak surface elevations and loads due to extreme events in a reproducible, deterministic way. Inoffshore engineering a design-wave known as NewWave is referred to extensively and has become theindustry standard for modelling extreme wave interactions with offshore structures.

7

Page 9: Focused Wave generation based on Linear NewWave Theory

2.3. NEWWAVE THEORY CHAPTER 2. THEORETICAL BACKGROUND

New Wave Theory [Tromans et al. (1991)] provides a realistic deterministic description of the largestwaves in a random sea and is an alternative to regular wave theories. It is able to efficiently generatetargeted waves at a prescribed time and location by combining smaller, sinusoidal components ofdifferent frequencies. The linear NewWave considers a linear, random, Gaussian sea and discretizesthe sea state into a finite number of sinusoidal components.

In this tutorial, a new wave type based on linear NewWave model has been employed to generateinput conditions for focused wave CFD simulations using the open source software OpenFOAM andthe waves2Foam library. The wave type developed in this tutorial is limited to uni-directional seasand produces a linear, crest-focused wave group.

Higher-corrections to the NewWave definition have been proposed, but for the purpose of this tutoriala new wave type based on a linear NewWave approximation will be use to describe the incidentextreme wave.

2.3 NewWave Theory

The NewWave theory describes the surface elevation and the wave velocity components of a fo-cused group of localized waves derived from a measured theoretical spectrum, such as JOSWAP orPierson-Moskowitz. The waves are superposed and brought into phase at one point in the tank ata specified time. This generates an extreme wave event, which represents the wave environment ofthe underlying spectrum.

For the linear NewWave, the amplitude of each wave component ai of frequency fi is defined as:

ai = AoS(fi)∆f∑Nn=1 S(fi)∆f

(2.1)

where S(fi) is the surface spectral density, the frequency step ∆f (which depends on the number ofwave components N and the bandwidth), given by

∆f =fu − flN − 1

, (2.2)

with fu and fl being, respectively the upper and the lower limit of a given frequency bandwidth.Ao is the target theoretical linear crest amplitude of the focused wave given by

Ao =√

2m0ln(N), (2.3)

where m0 is the 0th moment of the spectrum and the value of linear crest amplitude Ao is importantsince it ensures a NewWave model of the largest wave in N waves. It is general assumed that a threehour sea state has approximately 1000 waves, so N = 1000.

The extreme wave represented by linear NewWave theory is simply the scaled auto-correlation func-tion corresponding to a specified spectrum.

The linear surface displacement η and horizontal and vertical velocities u and w are given by:

η(x, t) =

N∑n=1

aicos[ki(x− x0) − ωi(t− t0)] (2.4)

u(x, t) =

N∑n=1

aigkiωi

coshki(z + h)

cosh(kih)cos[ki(x− x0) − ωi(t− t0)] (2.5)

8

Page 10: Focused Wave generation based on Linear NewWave Theory

2.4. WAVE SPECTRUM CHAPTER 2. THEORETICAL BACKGROUND

w(x, t) =

N∑n=1

aigkiωi

sinhki(z + h)

cosh(kih)sin[ki(x− x0) − ωi(t− t0)] (2.6)

Where z is the vertical coordinate measured upwards from the Mean Water Level (MWL),x0,t0 arethe predefined focal location and focal time, respectively, g is the gravitational acceleration, h is thewater depth, ki = ω2

i /gtanh(kih) is the wave number and ωi = 2πfi is the frequency.

Various spectra may be used to represent the sea states. The JONSWAP and Pierson-Moskowitzfrequency spectrum, S(fi), are frequently employed.

2.4 Wave Spectrum

2.4.1 JONSWAP

According to JONSWAP spectrum the surface spectral density for a given frequency, S(fi), isdescribed as:

S(f) = aH2s f

4pf

−5exp[−5

4(fpf

)4]γβ (2.7)

a =0.0624

0.23 + 0.0336γ − 0.1851−9+γ

(2.8)

β = exp[−(f − fp)

2

2σ2f2p ] (2.9)

where Hs is the significant wave height, fp = 1Tp

is the peak frequency, Tp is the peak period of the

JONSWAP spectrum and γ is the peak lifting factor.

a is a coefficient that is related to the peak lifting factor γ. σ is the peak shape parameter the valueof which is defined as:

σ =

{0.09 f ≥ fp

0.07 f > fp(2.10)

2.4.2 Pierson-Moskowitz

According to Pierson-Moskowitz spectrum the surface spectral density for a given frequency, S(fi),is described as:

S(f) =5

16H2s f

4pf

−5exp[−5

4(fpf

)4] (2.11)

Where Hs is the significant wave height, fp = 1Tp

is the peak frequency, Tp is the peak period of the

JONSWAP spectrum.

9

Page 11: Focused Wave generation based on Linear NewWave Theory

Chapter 3

Waves2Foam Toolbox’s Librariesand Classes Organization

The toolbox waves2Foam was originally developed at the Technical University of Denmark by NielsGjøl Jacobsen under the supervision of Prof. Jorgen Fredsøe. The waves2Foam toolbox is a plug-into the OpenFOAM package and is used for the generation and absorption of free surface wavesas well as modelling the interaction between free-surface waves and bodies using the free surfacecapabilities of OpenFOAM. All the available utilities provided by the toolbox waves2Foam comefrom the libraries listed below:

1. waves2Foam

2. waves2FoamMooring

3. waves2FoamPorosity

4. waves2FoamProcessing

5. waves2FoamSampling

In this project, NewWave Theory for focused wave generation will be added in the existing oneswaves2Foam toolbox supports. The name of the new wave type is focusedWave. Two of the abovementioned libraries are essentials; libwaves2Foam and libwaves2FoamProcessing for the purposeof this tutorial.

The OpenFOAM and waves2Foam toolbox user would provide all the information for the wavegeneration though the file waveProperties.input, like wave theory, sea state characteristics, waterdepth, wave spectrum, wave generation and absorption method. More details about that topic willbe provided later on.

This chapter discusses a classification of the main classes consisting the libraries waves2Foam andwaves2FoamProcessing. Then, the classes and sub-classes essential for the scope of this tutorial, arepresented. Finally, a brief explanation of the source code is discussed allowing the user to understandbetter the modifications in Chapter 4.

3.1 Role of waves2Foam Library

The library waves2Foam includes the major classes listed below:

1. convexPolyhedral

2. fvPatchFields

10

Page 12: Focused Wave generation based on Linear NewWave Theory

3.1. ROLE OF WAVES2FOAM LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

3. relaxationZone

4. setWaveField

5. waveTheory

3.1.1 waveTheory class

The class waveTheory is used for the purpose of this tutorial. The wave theories available inwaves2Foam are implemented in the library. These wave theories include Algebraic and External

wave theories.

All the wave theories available in waves2Foam are located at:

$WM_PROJECT_DIR/applications/utilities/waves2Foam/src/waves2Foam/waveTheories

The Algebraic wave theories are given in the algebraic form and they are listed below:

1. Regular Wave Theories

• Stokes First order

• Standing Stokes First order

• Stokes Second order

• Modulated second order Stokes

• Stokes Fifth order

• First order cnoidal

• Stream function wave

2. Bichromatic Wave Theories

• First order bichromatic wave

• Second order bichromatic wave

• First order irregular waves

3. Potential Current

4. Solitary First order

5. Combined Waves

The External wave theories are listed below:

1. Empty external method

2. Fast summation of irregular waves

3. OceanWave3D

3.1.2 waveTheory class and sub-classes

The base class waveTheory is located at:

$WM_PROJECT_DIR/applications/utilities/waves2Foam/src/waves2Foam /waveTheories/waveTheory

There are two files in the folder waveTheory: waveTheory.H is the class declaration and waveTheory.C

is the class definition.

11

Page 13: Focused Wave generation based on Linear NewWave Theory

3.1. ROLE OF WAVES2FOAM LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

At the declaration file, waveTheory.H, an autopointer of waveTheory class is created. The choiceof wave theory is referred in the dictionary file which is passed as an argument as seen below. Baseclass shows different virtual class for defining the wave elevation function η, pressure gradient p andvelocity U .

// Selectors

//- Return a reference to the selected turbulence model

static autoPtr<waveTheory> New

(

const word& subDictName,

const fvMesh& mesh_

);

virtual void printCoeffs() = 0;

// Destructor

virtual ~waveTheory();

// Member Functions

virtual Switch conflictTSoftInitialise() const = 0;

virtual bool isInitialiser() const

{

return true;

};

const vector windVelocity( const scalar& time ) const

{

return factor( time )*wind_;

};

// Access - single value

virtual scalar eta

(

const point&,

const scalar&

) const = 0;

virtual vector U

(

const point&,

const scalar&

) const = 0;

virtual scalar pExcess

(

const point&,

const scalar&

) const

{

12

Page 14: Focused Wave generation based on Linear NewWave Theory

3.1. ROLE OF WAVES2FOAM LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

return 0.0;

};

virtual bool implementPressure() const

{

return false;

};

// Access - field

virtual scalarField eta

(

const pointField&,

const scalar&

) const;

virtual vectorField U

(

const pointField&,

const scalar&

) const;

At the definition part, waveTheory.C, the role of the class is outlined. The class waveTheory.C

has access to several dictionaries to read the values of some parameters and provide this value tothe class member data. For example, access to the waveProperties file for reading the value ofseaLevel and provide this value to seaLevel_, or access to the dictionary g and feed the memberdata of the class g_.

IOdictionary

(

mesh_.thisDb().lookupObject<IOobject>("waveProperties")

),

seaLevel_(readScalar(lookup("seaLevel"))),

g_(meshObjects::gravity::New(mesh_.thisDb().time()).value()),

direction_( g_/mag(g_) ),

coeffDict_(subDict(subDictName + "Coeffs")),

PI_( M_PI ),

wind_( lookupOrDefault<vector>( "wind", vector::zero ) )

{

{

IOdictionary transProp

(

IOobject

(

"transportProperties",

"constant",

mesh_,

IOobject::MUST_READ,

IOobject::NO_WRITE

)

13

Page 15: Focused Wave generation based on Linear NewWave Theory

3.1. ROLE OF WAVES2FOAM LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

);

dictionary sD(transProp.subDict(Foam::waves2Foam::waterPhase()));

rhoWater_ = (dimensionedScalar(sD.lookup("rho"))).value();

}

// Set the reference level

referenceLevel_ = vector::zero;

bool correctReference =

this->lookupOrDefault<bool>("seaLevelAsReference", false);

if (correctReference)

{

referenceLevel_ = seaLevel_*Foam::cmptMultiply(direction_, direction_);

}

In the waveTheory.C, the member functions are defined as well. The purpose of the memberfunctions here is to give the value of reference pressure value depending on the sea level and checkthe direction of wave propagation, surface elevation and velocity of the wave. In the definiton of themember functions for checking the Wave direction (checkWaveDirection), surface elevation (eta)and velocity (U), sub-classes member functions are called. According to the chosen wave type, thereferred sub-class dictionary is called to couple with the base class.

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

scalar waveTheory::referencePressure() const

{

return referencePressure(seaLevel_);

}

scalar waveTheory::referencePressure(const scalar localSeaLevel) const

{

return rhoWater_*Foam::mag(g_)

*(localSeaLevel + (referenceLevel_ & direction_));

}

void waveTheory::checkWaveDirection(const vector& k) const

{

if (Foam::mag(k & direction_) > SMALL)

{

FatalErrorIn("void waveTheory::checkWaveDirection(const vector& k)")

<< "The wave number " << k << " is not perpendicular to the \n"

<< "direction of the gravitational vector " << g_ << "\n"

<< endl << endl << exit(FatalError);

}

}

void waveTheory::checkWaveDirection(const vectorField& k) const

{

forAll (k, ki)

{

checkWaveDirection(k[ki]);

}

}

14

Page 16: Focused Wave generation based on Linear NewWave Theory

3.1. ROLE OF WAVES2FOAM LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

scalarField waveTheory::eta

(

const pointField& x,

const scalar& time

) const

{

scalarField temp(x.size(),0.0);

forAll (x,ii)

{

temp[ii] = eta(x[ii],time);

}

return temp;

}

vectorField waveTheory::U

(

const pointField& x,

const scalar& time

) const

{

vectorField temp(x.size(),vector::zero);

forAll (x,ii)

{

temp[ii] = U(x[ii],time);

}

return temp;

}

Each of the specific wave theories are the sub-class of the main class waveTheory and they arelocated at:

$WM_PROJECT_DIR/applications/utilities/waves2Foam/src/waves2Foam/waveTheories

For the scope of this tutorial, the First Order Irregular Wave Theory is going to be used as basesource code for the focusedWave generation. Therefore, a brief explanation of the irregular classdeclaration and definition is also provided. The irregular class is loacated at:

$WM_PROJECT_DIR/applications/utilities/waves2Foam/src/waves2Foam/waveTheories \

/irregular/irregular

where two files are located; irregular.H for the class declaration and irregular.C for the classdefinition.

The irregular wave is the sum of a finite number of wave components. The wave components are FirstOrder Stokes waves so linear wave theory is applied. The irregular sub-class gives to waveTheory

class the wave elevation function eta, pressure gradient p and velocity U . For doing this, irregularclass reads all the essential variables from waveProperties file.

// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

irregular::irregular

15

Page 17: Focused Wave generation based on Linear NewWave Theory

3.1. ROLE OF WAVES2FOAM LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

(

const word& subDictName,

const fvMesh& mesh_

)

:

waveTheory(subDictName, mesh_),

N_(readScalar(coeffDict_.lookup("N"))),

h_(readScalar(coeffDict_.lookup("depth"))),

amp_("amplitude", coeffDict_, N_),

omega_("frequency", coeffDict_, N_),

phi_("phaselag", coeffDict_, N_),

k_("waveNumber", coeffDict_, N_),

K_(N_),

compDir_(N_),

period_(N_, 0),

velAmp_(N_, 0),

Tsoft_( readScalar(coeffDict_.lookup("Tsoft"))),

Tend_(coeffDict_.lookupOrDefault<scalar>("Tend", GREAT))

{

if (Tend_ < GREAT)

{

Tdecay_ = readScalar(coeffDict_.lookup("Tdecay"));

}

omega_ *= (2.0*PI_);

// Compute the length of k_

K_ = Foam::mag(k_);

compDir_ = k_ / K_;

// Compute the period

forAll (period_, index)

{

period_[index] = 2.0*PI_/omega_[index];

}

// Compute the velocity amplitude

forAll (velAmp_, index)

{

velAmp_[index] = PI_*2.0*amp_[index]/period_[index]

/Foam::sinh(K_[index]*h_);

}

checkWaveDirection(k_);

}

void irregular::printCoeffs()

{

Info << "Loading wave theory: " << typeName << endl;

}

16

Page 18: Focused Wave generation based on Linear NewWave Theory

3.1. ROLE OF WAVES2FOAM LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

scalar irregular::factor(const scalar& time) const

{

scalar factor(1.0);

if (0.0 < Tsoft_ && time < Tsoft_)

{

factor = Foam::sin(2*PI_/(4.0*Tsoft_)*Foam::min(Tsoft_, time));

}

if (Tend_ <= time)

{

scalar diffT(Foam::min(time - Tend_, Tdecay_));

factor = Foam::cos(2*PI_/(4.0*Tdecay_)*diffT);

}

return factor;

}

scalar irregular::eta

(

const point& x,

const scalar& time

) const

{

scalar eta(0);

forAll (amp_, index)

{

scalar arg = omega_[index]*time - (k_[index] & x) + phi_[index];

eta += amp_[index]*Foam::cos(arg);

}

eta *= factor(time);

eta += seaLevel_;

return eta;

}

scalar irregular::pExcess

(

const point& x,

const scalar& time

) const

{

scalar Z(returnZ(x));

scalar res = 0;

forAll (amp_, index)

{

scalar arg0 = omega_[index]*time - (k_[index] & x) + phi_[index];

scalar arg1 = K_[index]*(Z + h_);

17

Page 19: Focused Wave generation based on Linear NewWave Theory

3.2. ROLE OF WAVES2FOAMPROCESSING LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

res += rhoWater_*mag(g_)*amp_[index]*Foam::cosh(arg1)

/Foam::cosh(K_[index]*h_)*Foam::cos(arg0);

}

res *= factor(time);

res += referencePressure();

return res;

}

vector irregular::U

(

const point& x,

const scalar& time

) const

{

scalar Z(returnZ(x));

vector U(vector::zero);

forAll (amp_, index)

{

scalar arg0 = omega_[index]*time - (k_[index] & x) + phi_[index];

scalar arg1 = K_[index]*(Z + h_);

scalar Uhorz = velAmp_[index]*Foam::cosh(arg1)*Foam::cos(arg0);

scalar Uvert = - velAmp_[index]*Foam::sinh(arg1)*Foam::sin(arg0);

// Note "-" because of "g" working in the opposite direction

U += Uhorz*compDir_[index] - Uvert*direction_;

}

U *= factor(time);

return U;

To summarize, the base class waveTheory provides important functions for checking the wave char-acteristics and calculating the wave dynamics in space and time. waveTheory class works togetherwith sub-classes. Each sub-class expresses a wave theory and calculates the surface elevation andwave dynamics. Sub-classes work together with the file waveProperties, located at the constant

folder of the case directory. The file waveProperties is created by the waveProperties.input filein conjuction with the setWaveProperties class of the library waves2FoamProcessing.

3.2 Role of waves2FoamProcessing Library

The library waves2FoamProcessing contains all the pre-processing and post-processing utili-ties. It is located at:

$WM_PROJECT_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing

For the scope of this tutorial, we are intersted in pre-processing utilities of the library, which arelisted below:

18

Page 20: Focused Wave generation based on Linear NewWave Theory

3.2. ROLE OF WAVES2FOAMPROCESSING LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

1. probes

2. setWaveProperties

3.2.1 setWaveProperties class part of waves2FoamProcessing library

In particular, we focus on the setWaveProperties utility. But what is the purpose of setWave-Properties class?Practically, as it has already been mentioned, the information of wave theories are given by the user,through the file waveProperties.input. The class setWaveProperties uses the file waveProperties.inputin order to create a new file waveProperties. The new file contains more information depended onthe selected wave theory.

3.2.2 setWaveProperties class and sub-classes

The base class setWaveProperties is located at:

$WM_PROJECT_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing \

/preProcessing/setWavePropeties

Where there are two files: setWaveProperties.H is the class declaration and setWaveProperties.C isthe class definition. In the same location, there are folders having the name of wave theories. Inthese folder the sub-classes of the main class setWaveProperties are located.

1. Regular Wave Theories

• Stokes First order Properties

• Standing Stokes First order Properties

• Stokes Second order Properties

• Modulated second order Stokes Properties

• Stokes Fifth order Properties

• First order cnoidal Properties

• Stream function wave Properties

2. Irregular Wave Theories

• First order bichromatic wave Properties

• Second order bichromatic wave Properties

• First order irregular waves Properties

• Wave Spectra

3. Potential Current Properties

4. Solitary First order Properties

5. Combined Waves Properties

6. External Source Properties

7. OceanWave3D Properties

19

Page 21: Focused Wave generation based on Linear NewWave Theory

3.2. ROLE OF WAVES2FOAMPROCESSING LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

3.2.3 Main class setWaveProperties.C and sub-classes

In this section, the code is described allowing the user to gain a brief understanding about thestructure of the setWaveProperties class and the sub-classes.The main purpose of the class setWaveProperties is to identify the selected waveTheory in thewaveProperties.input file and call the corresponding sub-class in order to create the file waveProperties.A piece of code from the declaration file setWaveProperties.H is presented below. An autopointerof setWaveProperties class is created. The choice of the wave theory is reffered in the dictionaryfile which is passed as an argument as seen below.

static autoPtr<setWaveProperties> New

(

const Time&,

dictionary&,

bool

);

In the definition file setWaveProperties.C, the autopointer definition is taken place. The waveTypedefinded in the file waveProperties.input is read and the derived sub-class is called.

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

autoPtr<setWaveProperties> setWaveProperties::New

(

const Time& rT,

dictionary& dict,

bool write

)

{

word waveTheoryTypeName;

dict.lookup("waveType") >> waveTheoryTypeName;

setWavePropertiesConstructorTable::iterator cstrIter =

setWavePropertiesConstructorTablePtr_->find

(

waveTheoryTypeName+"Properties"

);

if (cstrIter == setWavePropertiesConstructorTablePtr_->end())

{

FatalErrorIn

(

"setWaveProperties::New(const fvMesh&, const Time&, ...)"

)

<< "Unknown wave property type " << waveTheoryTypeName << "Properties"

<< endl << endl

<< "Valid wave property types are :" << endl

<< setWavePropertiesConstructorTablePtr_->toc()

<< exit(FatalError);

}

return autoPtr<setWaveProperties>(cstrIter()(rT, dict, write));

}

In this tutorial, the irregular wave theory is going to be used as the base source code for focusedWavegeneration. Thus, a brief description of irregularProperties sub-class is provided here. The irregularProperties

20

Page 22: Focused Wave generation based on Linear NewWave Theory

3.2. ROLE OF WAVES2FOAMPROCESSING LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

declaration and definition files are locared at:

$WM_PROJECT_USER_DIR/src/applications/utilities/waves2Foam/src \

/waves2FoamPrcessing/preProcessing/setWaveProperties/irregular/irregularProperties

The irregularProperties is sub-class of setWaveProperties. It means that the sub-class inheritattributes from already existing classes and extend with new attributes, creating pointers connectedwith the class spectra, frequencyAxis for the calculation of amplitude, frequency, phaselag

and waveNumber.

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

void irregularProperties::set( Ostream& os )

{

// Write the beginning of the sub-dictionary

writeBeginning( os );

// Write the already given parameters

writeGiven( os, "waveType" );

writeGiven( os, "spectrum");

writeGiven( os, "N" );

writeGiven( os, "Tsoft");

if (dict_.found("writeSpectrum" ))

{

writeGiven( os, "writeSpectrum");

}

if (dict_.found("Tend"))

{

writeGiven(os, "Tend");

writeGiven(os, "Tdecay");

}

// Make a pointer to the spectral theory

scalarField amp(0);

scalarField frequency(0);

scalarField phaselag(0);

vectorField waveNumber(0);

autoPtr<waveSpectra> spectra

(

waveSpectra::New(rT_, dict_, amp, frequency, phaselag, waveNumber)

);

// Write properties specific to chosen spectral theory

wordList specificInput( spectra->list() );

forAll (specificInput, speci)

{

writeGiven( os, specificInput[speci] );

}

21

Page 23: Focused Wave generation based on Linear NewWave Theory

3.2. ROLE OF WAVES2FOAMPROCESSING LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

// Computing the spectral quantities

spectra->set( os );

if (write_)

{

writeDerived( os, "amplitude", amp);

writeDerived( os, "frequency", frequency);

writeDerived( os, "phaselag", phaselag);

writeDerived( os, "waveNumber", waveNumber);

}

// Write the frequency axis information

if (dict_.found("frequencyAxis"))

{

word fa("frequencyAxis");

os << nl << indent << fa << nl << indent << token::BEGIN_BLOCK

<< incrIndent << nl;

dictionary sd(dict_.subDict(fa));

wordList toc( sd.toc() );

forAll (toc, item)

{

ITstream it(sd.lookup(toc[item]));

addITstream(os, toc[item], it);

}

os << decrIndent << indent << token::END_BLOCK << endl;

}

// Write the relaxation zone

writeRelaxationZone( os );

// Write the closing bracket

writeEnding( os );

}

3.2.4 Wave Spectrum Theories

In the waves2Foam toolbox, Pierson-Moskowitz and JONSWAP are part of the waves2FoamProcessinglibrary. These classes are located at:

$WM_PROJECT_USER_DIR/src/applications/utilities/waves2Foam/src \

/waves2FoamPrcessing/preProcessing/setWaveProperties/irregular/waveSpectra/spectra.

The definition class for Pierson-Moskowitz spectrum is explained. JONSWAP spectrum has quitesimilar explanation. The definition class is located at:

$WM_PROJECT_USER_DIR/src/applications/utilities/waves2Foam/src/waves2FoamPrcessing \

/preProcessing/setWaveProperties/irregular/waveSpectra/spectra/PiersonMoskowitz.

22

Page 24: Focused Wave generation based on Linear NewWave Theory

3.2. ROLE OF WAVES2FOAMPROCESSING LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

In the Pierson-Moskowitz source code, the private member function spectralvalue is called for thecalculation of surface spectral density for a given frequency. The private member function is visibleonly within the subclass.

// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //

scalarField PiersonMoskowitz::spectralValue

(

const scalar& Hs,

const scalar& Tp,

const scalarField& freq

) const

{

scalar fp = 1.0/Tp;

// Compute spectrum

scalarField S = 5.0/16.0*Foam::pow(Hs,2.0)*Foam::pow(fp,4.0)

*Foam::pow(freq,-5.0)*Foam::exp(- 5.0/4.0*Foam::pow(fp/freq, 4.0));

return S;

}

Read the input variables from the file waveProperties.input.

// Get the input parameters

scalar Hs(readScalar(dict_.lookup("Hs")));

scalar Tp(readScalar(dict_.lookup("Tp")));

scalar depth(readScalar(dict_.lookup("depth")));

vector direction(vector(dict_.lookup("direction")));

label N = readLabel(dict_.lookup("N"));

Calling the class frequencyAxis for the discretization phase.

equidistantFrequencyAxis equiFA(rT_, dict_);

scalarField tempFreqAxis = equiFA.freqAxis(10000);

scalarField tempSpectrum

= this->spectralValue(Hs, Tp, tempFreqAxis);

nodeFrequency = fA->freqAxis(tempFreqAxis, tempSpectrum, N);

Prepare the variables giving a size depending on the number of wave components N and computethe return values:

// Prepare variables

freq_.setSize(N);

amp_.setSize(N);

phi_.setSize(N);

k_.setSize(N);

// Compute spectrum

scalarField S = this->spectralValue(Hs, Tp, nodeFrequency);

23

Page 25: Focused Wave generation based on Linear NewWave Theory

3.2. ROLE OF WAVES2FOAMPROCESSING LIBRARYCHAPTER 3. WAVES2FOAM TOOLBOX’S LIBRARIES AND CLASSES ORGANIZATION

// Prepare stokesFirst to compute wave numbers

Foam::stokesFirstProperties stp( rT_, dict_ );

// Compute return variables

for (int i = 1; i < N + 1; i++)

{

// The frequency is the mid-point between two nodes

freq_[i - 1] = 0.5*(nodeFrequency[i - 1] + nodeFrequency[i]);

// Amplitude is the square root of the trapezoidal integral

amp_[i - 1] =

Foam::sqrt

(

(S[i-1] + S[i])

*(nodeFrequency[i] - nodeFrequency[i - 1])

);

// Wave number based on linear wave theory

k_[i - 1] = direction*stp.linearWaveNumber(depth, freq_[i-1]);

// The phase is computed based on the phase-function

phi_[i - 1] = phases_->phase(freq_[i - 1], k_[i - 1]);

}

Using a pointer, the private member function for the surface spectral density is called.

// Compute spectrum

scalarField S = this->spectralValue(Hs, Tp, nodeFrequency);

24

Page 26: Focused Wave generation based on Linear NewWave Theory

Chapter 4

Modification

4.1 focusedWave type in waves2Foam library

As it has already been discussed, waveTheory class is part of the shared object library libwaves2Foam.so.This essentially means that a new class can be added in the existing wave theories and the changedfunctionallity will be included in all applications, that link to the library libwaves2Foam. A newclass is required for the addition of the NewWave Theory Focused Wave in the existing wave theories.In the original code of the waves2Foam toolbox, the new wave type will be included. In the librarylibwaves2Foam, the new class named focusedWave is placed.

4.1.1 Getting started

First ensure that OpenFOAM installation has been sourced. Since there is not the need to start fromscratch new class focusedWave creation, the class irregular is copied and the required modificationsare applied on the existing code.The folder irregular is located at:

$WM_PROJECT_USER_DIR/src/applications \

/utilities/waves2Foam/src/waves2Foam/waveTheories/irregular/irregular

Execute the commands below, which will create a copy of the folder irregular and rename thefolder to focusedWave. A new wave theory is included besides the existing wave theories supportedby the waves2Foam toolbox.

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2Foam/waveTheories

mkdir --parents focusedWave/focusedWave

cp -r irregular/irregular/irregular.* focusedWave/focusedWave/

4.1.2 Rename files and folders

Once the existing source code has been copied, for avoiding ambiguity that will lead to errors andmay require reinstallation of waves2Foam toolbox, the files are renamed.

cd focusedWave/focusedWave

mv irregular.C focusedWave.C

mv irregular.H focusedWave.H

4.1.3 Change class name in source files

sed -i s/irregular/focusedWave/g focusedWave.H

sed -i s/irregular/focusedWave/g focusedWave.C

25

Page 27: Focused Wave generation based on Linear NewWave Theory

4.2. FOCUSEDWAVEPROPERTIES IN WAVES2FOAMPROCESSING LIBRARYCHAPTER 4. MODIFICATION

4.1.4 Create Make folder

The new class focusedWave needs to be included in the file files, located in the folder Make. Aftercompilation, the focusedWave type will be included in the library waves2Foam. The folder Make islocated at:

$WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2Foam

The original Make folder is copied and renamed as Make_backup. Then, a new Make folder is createdand all the changes are taking place on it.

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2Foam

mv Make Make_backup

cp -r Make_backup Make

4.1.5 Modify Make/files

In the file files inside the folder Make, the files that should be compiled are listed first and at thevery last line the location and the name of the compiled shared object library is defined. Here, anew piece of code is added in the section:

/* WAVE THEORIES */

After the part of code:

/* Irregular wave theories */

irregular=irregular

$(waveTheories)/$(irregular)/irregular/irregular.C

$(waveTheories)/$(irregular)/bichromaticFirst/bichromaticFirst.C

$(waveTheories)/$(irregular)/bichromaticSecond/bichromaticSecond.C

We add:

/* Focused wave theories */

focusedWave=focusedWave

$(waveTheories)/$(focusedWave)/focusedWave/focusedWave.C

Save and close the file!We are currently in the directory$WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2Foam

Now, we execute the commandwclean

4.2 focusedWaveProperties in waves2FoamProcessing library

The setWaveProperties class is part of the shared object library file libwaves2FoamProcessing.so.This essentially means that a new class can be added in the library and the changed functionallitywill be included in all applications, that link to the library. Since the new class focusedWave has beenadded in the library waves2Foam, a new class should be added in the library waves2FoamProcessing.The new class is named focusedWaveProperties and is a sub-class of the setWaveProperties class.In the following sub-sectios, it is shown it can be done.

26

Page 28: Focused Wave generation based on Linear NewWave Theory

4.2. FOCUSEDWAVEPROPERTIES IN WAVES2FOAMPROCESSING LIBRARYCHAPTER 4. MODIFICATION

4.2.1 Getting started

The setWaveProperties class and its sub-classes are located at the folder:

$WM_PROJECT_USER_DIR/src/applications/ \

\verb+/utilities/waves2Foam/src/waves2FoamProcessing/preProcessing/setWaveProperties

We do not need start from stratch. We simply copy the existing class irregularProperties, renameinto focusedWaveProperties and make all the required modifications.The folder irregularProperties is located at:

$WM_PROJECT_USER_DIR/src/applications \

/utilities/waves2Foam/src/waves2FoamProcessing/preProcessing/setWaveProperties/irregular \

Executing the commands below, a copy of the folder irregularProperties is created which will bethe new class focusedWaveProperties.

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing \

/preProcessing/setWaveProperties

mkdir --parents focusedWave/focusedWaveProperties

cp -r irregular/irregularProperties/irregularProperties.* focusedWave/focusedWaveProperties/

4.2.2 Rename files and folders

Once the existing source code has been copied, for avoiding ambiguity that will lead to errors andmay require reinstallation of waves2Foam toolbox, the files are renamed.

cd focusedWave/focusedWaveProperties

mv irregularProperties.C focusedWaveProperties.C

mv irregularProperties.H focusedWaveProperties.H

4.2.3 Change class name in source files

sed -i s/irregular/focusedWave/g focusedWaveProperties.C

sed -i s/irregular/focusedWave/g focusedWaveProperties.H

4.2.4 Create Make folder

The new class focusedWaveproperties needs to be included in the file files, which is locatedin the folder Make and after recompiling, the new wave theory will be included in the librarywaves2FoamProcessing. The folder Make is located at:

$WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing

Copy the original Make folder and rename it Make_backup and then we create a new Make folder andwork on it.

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing

mv Make Make_backup

cp -r Make_backup Make

4.2.5 Modify Make/files

In the file files inside the folder Make, the source files that should be compiled in the library arelisted first and then at the very last line the location and the name of the compiled shared objectlibrary is defined. Here new piece of code has been added in the section:

/* SET WAVE PROPERTIES */

27

Page 29: Focused Wave generation based on Linear NewWave Theory

4.3. COMPILE THE WAVES2FOAM AND WAVES2FOAMPROCESSING LIBRARIESCHAPTER 4. MODIFICATION

After the part of code:

/* Irregular wave theories */

irregular=irregular

$(waveProp)/$(irregular)/bichromaticFirstProperties/bichromaticFirstProperties.C

$(waveProp)/$(irregular)/bichromaticSecondProperties/bichromaticSecondProperties.C

....

....

....

$(waveProp)/$(irregular)/irregularProperties/irregularProperties.C

Add:

/* Focused wave theories */

focusedWave=focusedWave

$(waveProp)/$(focusedWave)/focusedWaveProperties/focusedWaveProperties.C

Save and close the file!We are currently in the directory$WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing

Now, execute the commandwclean

4.3 Compile the waves2Foam and waves2FoamProcessing li-braries

Until now, the existing classes irregular and irregularProperties have been copied, generat-ing the new classes focusedWave and focusedWaveProperties in the libraries waves2Foam andwaves2FoamProcessing, respectively. The only modifications in the source code are related to thenames replace.In that stage, compile the libraries to check if everything has been done correctly.

Go back to the directory:cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src

Compile the libraries by executing:./Allwmake

Now, a new wave type named focusedWave and a new setWaveProperties sub-class named focusedWaveProperties

class exist.Actually, at this stage focusedWave type behaves exactly as the irregular wave type, since nomodified in the source code have been completed yet. In the following sections, the source code istaking place.

4.4 Tutorial focusedWave

At this stage, for the veryfication that everything have been done correctly so far, the focusedWave

type is applied. If the tutorial runs properly, it means that focusedWave has been implementedcorrectly inside the waves2Foam toolbox.Start by copying the existing tutorial waveFlume and rename it into focusedWaveVerify, thenchange the settings in the file waveProperties.input and run.Go to:

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/tutorials/waveFoam

28

Page 30: Focused Wave generation based on Linear NewWave Theory

4.4. TUTORIAL FOCUSEDWAVE CHAPTER 4. MODIFICATION

cp -r waveFlume focusedWaveVerify

cd focusedWaveVerify/constant

Modify the waveProperties.input file, substituting the section intelCoeffs with the followingpiece of code:

inletCoeffs

{

// Wave type to be used at boundary "inlet" and in relaxation zone "inlet"

waveType focusedWave;

N 50;

// Ramp time of 2 s

Tsoft 10;

//Define the phases

phaseMethod focusingPhase;

focusTime 10.0;

focusPoint (8 0 0);

//Define the spectrum

spectrum PiersonMoskowitz;

Hs 1;

Tp 10;

depth 0.4;

direction (1 0 0);

//Define the frequency

frequencyAxis

{

discretisation equidistantFrequencyAxis;

lowerFrequencyCutoff 0.01;

upperFrequencyCutoff 0.4;

writeSpectrum false;

}

// Specifications on the relaxation zone shape and relaxation scheme

relaxationZone

{

relaxationScheme Spatial;

relaxationShape Rectangular;

beachType Empty;

relaxType INLET;

startX (0 0.0 -1);

endX (5 0.0 1);

orientation (1.0 0.0 0.0);

}

};

Save and close the file. Now, go one level up and execute:

cd ..

./Allrun

29

Page 31: Focused Wave generation based on Linear NewWave Theory

4.5. CREATE WAVE SPECTRA CLASS FOR FOCUSEDWAVE TYPECHAPTER 4. MODIFICATION

The tutorial should run using the focusedWave type. Check inside the folder constant th filewaveProperties. Actually, since no code modification has been added in the new classes, thesolution of the tutorial does not follow the NewWave Theory. The purpose of running this tutorialis just to check that all the above described steps have been applied correctly. The user can proceednow in the next step for further code modification.

4.5 Create wave spectra class for focusedWave type

There are two wave spectum theories applied by waves2Foam toolbox; Pierson-Moskowitz andJONSWAP. For the needs of NewWave Theory, some modification will take place inside the spectraclasses. For that reason, it is preferable to create new spectra class named waveSpectra_FW andnew spectrum sub-classes named PiersonMoskowitz_FWJONSWAP_FW. The new classes will work ex-clusively together with the new wave type focusedWave.

Go to:

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing \

/preProcessing/setWaveProperties/irregular

cp --parents waveSpectra/spectra/PiersonMoskowitz/* ../focusedWave/

cp --parents waveSpectra/spectra/JONSWAP/* ../focusedWave/

cp -r waveSpectra/waveSpectra.C ../focusedWave/waveSpectra_FW/

cp -r waveSpectra/waveSpectra.H ../focusedWave/waveSpectra_FW/

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing \

/preProcessing/setWaveProperties/focusedWave

4.5.1 Rename files and folders

For avoiding confusion due to same names, the spectra related classes are renamed.We are currently in the directory:

$WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing \

/preProcessing/setWaveProperties/focusedWave

Rename the files and folders;

mv waveSpectra waveSpectra_FW

cd waveSpectra_FW

mv spectra spectra_FW

mv waveSpectra.C waveSpectra_FW.C

mv waveSpectra.H waveSpectra_FW.H

cd spectra_FW

mv PiersonMoskowitz PiersonMoskowitz_FW

mv JONSWAP JONSWAP_FW

mv PiersonMoskowitz_FW/PiersonMoskowitz.C PiersonMoskowitz_FW/PiersonMoskowitz_FW.C

mv PiersonMoskowitz_FW/PiersonMoskowitz.H PiersonMoskowitz_FW/PiersonMoskowitz_FW.H

mv JONSWAP_FW/JONSWAP.C JONSWAP_FW/JONSWAP_FW.C

mv JONSWAP_FW/JONSWAP.H JONSWAP_FW/JONSWAP_FW.H

4.5.2 Change class name in source files

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing \

/preProcessing/setWaveProperties/focusedWave/waveSpectra_FW

sed -i s/waveSpectra/waveSpectra_FW/g waveSpectra_FW.H

sed -i s/waveSpectra/waveSpectra_FW/g waveSpectra_FW.C

30

Page 32: Focused Wave generation based on Linear NewWave Theory

4.5. CREATE WAVE SPECTRA CLASS FOR FOCUSEDWAVE TYPECHAPTER 4. MODIFICATION

sed -i s/PiersonMoskowitz/PiersonMoskowitz_FW/g spectra_FW/PiersonMoskowitz_FW/PiersonMoskowitz_FW.H

sed -i s/PiersonMoskowitz/PiersonMoskowitz_FW/g spectra_FW/PiersonMoskowitz_FW/PiersonMoskowitz_FW.C

sed -i s/waveSpectra/waveSpectra_FW/g spectra_FW/PiersonMoskowitz_FW/PiersonMoskowitz_FW.H

sed -i s/waveSpectra/waveSpectra_FW/g spectra_FW/PiersonMoskowitz_FW/PiersonMoskowitz_FW.C

sed -i s/JONSWAP/JONSWAP_FW/g spectra_FW/JONSWAP_FW/JONSWAP_FW.H

sed -i s/JONSWAP/JONSWAP_FW/g spectra_FW/JONSWAP_FW/JONSWAP_FW.C

sed -i s/waveSpectra/waveSpectra_FW/g spectra_FW/JONSWAP_FW/JONSWAP_FW.H

sed -i s/waveSpectra/waveSpectra_FW/g spectra_FW/JONSWAP_FW/JONSWAP_FW.C

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing/preProcessing/setWaveProperties/focusedWave/focusedWaveProperties

sed -i s/waveSpectra/waveSpectra_FW/g focusedWaveProperties.H

sed -i s/waveSpectra/waveSpectra_FW/g focusedWaveProperties.C

4.5.3 Source code modification in PiersonMoskowitz class

Go to PiersonMoskowitz_FW folder:

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src \

/waves2FoamProcessing/preProcessing/setWaveProperties/focusedWave \

/waveSpectra_FW/spectra_FW/PiersonMoskowitz_FW

Open the class definition file PiersonMoskowitz_FW.C and modify the mmember functionwordList PiersonMoskowitz_FW::list() by changing the dimension of res() table, since we needto add the input Ao. The member function should look like the following piece of code:

wordList PiersonMoskowitz_FW::list()

{

wordList res(5);

res[0] = "Hs";

res[1] = "Tp";

res[2] = "depth";

res[3] = "direction";

res[4] = "Ao";

return res;

}

The member function void PiersonMoskowitz_FW::set( Ostream& os ) is also modified. Thesection // Get the input parameters should look like:

// Get the input parameters

scalar Hs(readScalar(dict_.lookup("Hs")));

scalar Tp(readScalar(dict_.lookup("Tp")));

scalar depth(readScalar(dict_.lookup("depth")));

vector direction(vector(dict_.lookup("direction")));

scalar Ao(readScalar(dict_.lookup("Ao")));

label N = readLabel(dict_.lookup("N"));

31

Page 33: Focused Wave generation based on Linear NewWave Theory

4.5. CREATE WAVE SPECTRA CLASS FOR FOCUSEDWAVE TYPECHAPTER 4. MODIFICATION

The sections // Prepare variables, // Calculate the spectrum, // Prepare stokesFirst re-main the same. Then, substitute the rest of the code with the following part:

// Compute the total energy spectrum times the frequency increment

scalar Stot = 0;

for (int i = 1; i < N + 1; i++)

{

Stot = Stot + 0.5* (S[i-1] + S[i]) * (nodeFrequency[i] - nodeFrequency[i - 1]);

}

// Compute return variables

for (int i = 1; i < N + 1; i++)

{

// The frequency is the mid-point between two nodes

freq_[i - 1] = 0.5*(nodeFrequency[i - 1] + nodeFrequency[i]);

// Amplitude for NewWave Theory

amp_[i - 1] = Ao * 0.5* (S[i-1] + S[i]) * (nodeFrequency[i] - nodeFrequency[i - 1]) /Stot;

// Wave number based on linear wave theory

k_[i - 1] = direction*stp.linearWaveNumber(depth, freq_[i-1]);

// The phase is computed based on the phase-function

phi_[i - 1] = phases_->phase(freq_[i - 1], k_[i - 1]);

}

writeSpectrum(os, nodeFrequency, S);

}

4.5.4 Source code modification in JONSWAP class

Go to JONSWAP_FW folder:

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src \

/waves2FoamProcessing/preProcessing/setWaveProperties/focusedWave \

/waveSpectra_FW/spectra_FW/JONSWAP_FW

Open the class definition file JONSWAP_FW.C and modify the member function wordList JONSWAP_FW::list()

by changing the dimension of res() table, since we need to add the input Ao. The member functionshould look like;

wordList PiersonMoskowitz_FW::list()

{

wordList res(6);

res[0] = "Hs";

res[1] = "Tp";

res[2] = "gamma";

res[3] = "depth";

res[4] = "direction";

res[5] = "Ao";

return res;

}

32

Page 34: Focused Wave generation based on Linear NewWave Theory

4.5. CREATE WAVE SPECTRA CLASS FOR FOCUSEDWAVE TYPECHAPTER 4. MODIFICATION

The member function void JONSWAP_FW::set(Ostream& os) is also modified. The section// Get the input parameters, should look like:

// Get the input parameters

scalar Hs(readScalar(dict_.lookup("Hs")));

scalar Tp(readScalar(dict_.lookup("Tp")));

scalar gamma(readScalar(dict_.lookup("gamma")));

scalar depth(readScalar(dict_.lookup("depth")));

vector direction(vector(dict_.lookup("direction")));

scalar Ao(readScalar(dict_.lookup("Ao")));

label N = readLabel(dict_.lookup("N"));

The sections // Prepare variables, // Calculate the spectrum, // Prepare stokesFirst re-main the same. Then, substitute the rest of the code with the following part:

// Compute the total energy spectrum times the frequency increment

scalar Stot = 0;

for (int i = 1; i < N + 1; i++)

{

Stot = Stot + 0.5* (S[i-1] + S[i]) * (nodeFrequency[i] - nodeFrequency[i - 1]);

}

// Compute return variables

for (int i = 1; i < N + 1; i++)

{

// The frequency is the mid-point between two nodes

freq_[i - 1] = 0.5*(nodeFrequency[i - 1] + nodeFrequency[i]);

// Amplitude for NewWave Theory

amp_[i - 1] = Ao * 0.5* (S[i-1] + S[i]) * (nodeFrequency[i] - nodeFrequency[i - 1]) /Stot;

// Wave number based on linear wave theory

k_[i - 1] = direction*stp.linearWaveNumber(depth, freq_[i-1]);

// The phase is computed based on the phase-function

phi_[i - 1] = phases_->phase(freq_[i - 1], k_[i - 1]);

}

writeSpectrum(os, nodeFrequency, S);

}

4.5.5 Modify Make/files

Go to Make folder, for adding the new classes in the file files.

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing/Make

In the file files, we had added a piece of code. Check again the section 4.2.5. We had added:

33

Page 35: Focused Wave generation based on Linear NewWave Theory

4.6. COMPILE THE WAVES2FOAM AND WAVES2FOAMPROCESSING LIBRARIESCHAPTER 4. MODIFICATION

/* Focused wave theories */

focusedWave=focusedWave

$(waveProp)/$(focusedWave)/focusedWaveProperties/focusedWaveProperties.C

Now add a new piece of code, so the final code in the file files will looks like:

/* Focused wave theories */

focusedWave=focusedWave

dwsFW=waveSpectra_FW

$(waveProp)/$(focusedWave)/$(dwsFW)/waveSpectra_FW.C

spectraFW=spectra_FW

$(waveProp)/$(focusedWave)/$(dwsFW)/$(spectraFW)/JONSWAP_FW/JONSWAP_FW.C

$(waveProp)/$(focusedWave)/$(dwsFW)/$(spectraFW)/PiersonMoskowitz_FW/PiersonMoskowitz_FW.C

$(waveProp)/$(focusedWave)/focusedWaveProperties/focusedWaveProperties.C

Save and close the file!Go to the directory:cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src/waves2FoamProcessing

Execute the command:wclean

4.6 Compile the waves2Foam and waves2FoamProcessing li-braries

In that stage, it is time for the compilation. All the new classes related to wave spectrum and themodicications in the source code are implemented.

Go back to the directory:cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/src

Compile the libraries by executing:./Allwmake

34

Page 36: Focused Wave generation based on Linear NewWave Theory

Chapter 5

Test Case

For checking that all the procedure described in Chapter 4 has been applied correctly but also forbetter understanding of the focusedWave type, this chapter lies in step by step tutorial presentation.

For the focused wave profile resprodution, a predifined focus location xo, focus time to, the numberof wave components and the uniformly spaced frequency range need to be defined.

The 2D Numerical Wave Tank (NWT) simulates the COAST Laboratory Ocean Basin at the Uni-versity of Plymouth, with 3m depth. Eight wave gauge positions are used in total and the focusedwave position is expected at wave gauge 5. The NWT is empty, without the presence of any float-ing body since the goal of the present tutorial is the comprehension of focused wave generation inOpenFOAM.

The amplitudes of the frequency components are derived by applying the NewWave theory to aPierson-Moskowitz spectrum with the parameters in the Table 5.1. All waves are crested focusedwaves i.e. have zero phase angle at the focus location. For simplicity, the focused wave consistsof 65 wave components, uniformly spaced between 0.101563Hz and 2Hz. The theoretical focus lo-cation, xo , is at a distance 4.35m and the focus time, to, 20sec. The whole simulation lasts for 30sec.

Ao fp Hs kA

(m) (Hz) (m) (m)

0.25 0.4 0.274 0.160972

Table 5.1: New Wave characteristics

The wave propagation as calculated at wave gauge 5, is compared with the theoretical focusedwave. The key file for the wave definition is the waveProperties.input. For creating the desiredwave profile we should provide information about the number of wave components N , the definitionof the focus location x0 and time t0. The phase of the waves focusing is zero. Moreover the wavespectrum, sea state characteristics like the significant wave height,Hs, peak period, Tp and the valueof linear crest amplitude Ao . Last but not least the frequency range is also declared. It is importanthere that if we are interested in the frequency range between fmin = 0.101563Hz and fmax = 2Hz,the the lowerFrequencyCutoff and upperFrequencyCutoff are calculated as:

∆f =fmax − fmin

N − 1(5.1)

35

Page 37: Focused Wave generation based on Linear NewWave Theory

5.1. GETTING STARTED CHAPTER 5. TEST CASE

lowerFrequencyCutoff = fmin − δf

2(5.2)

upperFrequencyCutoff = fmax +δf

2(5.3)

5.1 Getting started

Go to:

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam/tutorials/waveFoam

cp -r waveFlume newWave_focusedWave

cd newWave_focusedWave

5.2 Set-up the 0.org folder

Create the bounary conditions in the folder 0.org:

cd 0.org

mv alpha1.org alpha.water

mv p_rgh.1706.org p_rgh

touch U.org U

5.3 Set-up the Mesh

Go to the polyMesh folder:

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam \

/tutorials/waveFoam/newWave_focusedWave/constant/polyMesh

Open the file blockMeshDict and replace the vertices and blocks part:

vertices

(

( 0 -3.0 -0.05 )

( 25 -3.0 -0.05 )

( 0 1.5 -0.05 )

( 25 1.5 -0.05 )

( 0 -3.0 0.05 )

( 25 -3.0 0.05 )

( 0 1.5 0.05 )

( 25 1.5 0.05 )

);

blocks

(

hex (0 1 3 2 4 5 7 6) ( 1000 180 1 ) simpleGrading (1 1 1)

);

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

36

Page 38: Focused Wave generation based on Linear NewWave Theory

5.4. SET-UP THE SYSTEM FOLDER CHAPTER 5. TEST CASE

Save and close!

5.4 Set-up the system folder

Go to the system folder:

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam \

/tutorials/waveFoam/newWave_focusedWave/system

Modify the fvSchemes, fvSolution:

cp fvFiles/fvSchemes.1706 fvSchemes

cp fvFiles/fvSolution.1706 fvSolution

5.4.1 Modify the fvSchemes file

Open the file fvSchemes and add the following line in the divSchemes:

divSchemes

{

...

div((muEff*dev(T(grad(U))))) Gauss linear;

...

}

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

Save and close!

5.4.2 Modify the fvSolution file

Open the file fvSolution and write the following:

PISO

{

cAlpha 1;

}

PIMPLE

{

pdRefCell 0;

pdRefValue 0;

momentumPredictor yes;

nOuterCorrectors 1;

nCorrectors 3;

nNonOrthogonalCorrectors 1;

nAlphaCorr 1;

nAlphaSubCycles 1;

}

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

Save and Close!

37

Page 39: Focused Wave generation based on Linear NewWave Theory

5.4. SET-UP THE SYSTEM FOLDER CHAPTER 5. TEST CASE

5.4.3 Modify the controlDict file

Open the existing file controlDict and change:

endTime 30;

....

....

functions

{

surfaceElevationAnyName

{

type surfaceElevation;

functionObjectLibs ( "libwaves2FoamSampling.so" );

writeControl timeStep;

writeInterval 1;

setFormat raw;

interpolationScheme cellPointFace;

fields (alpha.water);

sets

(

WG1

{

type face;

axis y;

start (0 -3 0);

end (0 1.5 0);

nPoints 1000;

}

WG2

{

type face;

axis y;

start (1.5 -3 0);

end (1.5 1.5 0);

nPoints 1000;

}

WG3

{

type face;

axis y;

start (2.25 -3 0);

end (2.25 1.5 0);

nPoints 1000;

}

WG4

{

type face;

38

Page 40: Focused Wave generation based on Linear NewWave Theory

5.4. SET-UP THE SYSTEM FOLDER CHAPTER 5. TEST CASE

axis y;

start (2.75 -3 0);

end (2.75 1.5 0);

nPoints 1000;

}

WG5

{

type face;

axis y;

start (4.25 -3 0);

end (4.25 1.5 0);

nPoints 1000;

}

WG6

{

type face;

axis y;

start (5.75 -3 0);

end (5.75 1.5 0);

nPoints 1000;

}

WG7

{

type face;

axis y;

start (6.25 -3 0);

end (6.25 1.5 0);

nPoints 1000;

}

WG8

{

type face;

axis y;

start (7.0 -3 0);

end (7.0 1.5 0);

nPoints 1000;

}

);

}

//#includeIfPresent "../waveGaugesNProbes/surfaceElevationAnyName_controlDict";

}

39

Page 41: Focused Wave generation based on Linear NewWave Theory

5.5. SET-UP THE CONSTANT FOLDER CHAPTER 5. TEST CASE

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

Save and close!

5.5 Set-up the constant folder

5.5.1 Modify the waveProperties.input file

Go back to constant folder and modify the waveProperties.input file like the following piece ofcode:

initializationName inlet;

inletCoeffs

{

waveType focusedWave;

N 65;

// Ramp time of 2 s

Tsoft 10 ;

//Define the phases

phaseMethod focusingPhase;

focusTime 20.0;

focusPoint (4.25 0 0);

//Define the spectrum

spectrum PiersonMoskowitz_FW;

Hs 0.274;

Tp 2.5;

depth 3.0;

direction (1 0 0);

Ao 0.25;

frequencyAxis

{

discretisation equidistantFrequencyAxis;

lowerFrequencyCutoff 0.0869595;

upperFrequencyCutoff 2;

writeSpectrum false;

}

relaxationZone

{

relaxationScheme Spatial;

relaxationShape Rectangular;

beachType Empty;

relaxType INLET;

startX (0 0.0 -1);

40

Page 42: Focused Wave generation based on Linear NewWave Theory

5.5. SET-UP THE CONSTANT FOLDER CHAPTER 5. TEST CASE

endX (1.3 0.0 1);

orientation (1.0 0.0 0.0);

}

};

outletCoeffs

{

waveType potentialCurrent;

U (0 0 0);

Tsoft 2;

relaxationZone

{

relaxationScheme Spatial;

relaxationShape Rectangular;

beachType Empty;

relaxType OUTLET;

startX (17.17 0.0 -1);

endX (25 0.0 1);

orientation (1.0 0.0 0.0);

}

};

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

Save and close!

5.5.2 Modify the transportProperties file

Create a new file named transportProperties:

touch transportProperties

Add the following code:

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

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

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

| \\ / O peration | Version: 2.1.0 |

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

| \\/ M anipulation | |

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

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "constant";

object transportProperties;

}

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

phases (water air);

41

Page 43: Focused Wave generation based on Linear NewWave Theory

5.6. SET-UP THE ALLRUN FILE CHAPTER 5. TEST CASE

water

{

transportModel Newtonian;

nu nu [ 0 2 -1 0 0 0 0 ] 1e-06;

rho rho [ 1 -3 0 0 0 0 0 ] 1000;

CrossPowerLawCoeffs

{

nu0 nu0 [ 0 2 -1 0 0 0 0 ] 1e-06;

nuInf nuInf [ 0 2 -1 0 0 0 0 ] 1e-06;

m m [ 0 0 1 0 0 0 0 ] 1;

n n [ 0 0 0 0 0 0 0 ] 0;

}

BirdCarreauCoeffs

{

nu0 nu0 [ 0 2 -1 0 0 0 0 ] 0.0142515;

nuInf nuInf [ 0 2 -1 0 0 0 0 ] 1e-06;

k k [ 0 0 1 0 0 0 0 ] 99.6;

n n [ 0 0 0 0 0 0 0 ] 0.1003;

}

}

air

{

transportModel Newtonian;

nu nu [ 0 2 -1 0 0 0 0 ] 1.48e-05;

rho rho [ 1 -3 0 0 0 0 0 ] 1;

CrossPowerLawCoeffs

{

nu0 nu0 [ 0 2 -1 0 0 0 0 ] 1e-06;

nuInf nuInf [ 0 2 -1 0 0 0 0 ] 1e-06;

m m [ 0 0 1 0 0 0 0 ] 1;

n n [ 0 0 0 0 0 0 0 ] 0;

}

BirdCarreauCoeffs

{

nu0 nu0 [ 0 2 -1 0 0 0 0 ] 0.0142515;

nuInf nuInf [ 0 2 -1 0 0 0 0 ] 1e-06;

k k [ 0 0 1 0 0 0 0 ] 99.6;

n n [ 0 0 0 0 0 0 0 ] 0.1003;

}

}

sigma sigma [ 1 0 -2 0 0 0 0 ] 0.00;

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

5.6 Set-up the Allrun file

Now go back to the case directory

42

Page 44: Focused Wave generation based on Linear NewWave Theory

5.7. RESULTS CHAPTER 5. TEST CASE

cd $WM_PROJECT_USER_DIR/applications/utilities/waves2Foam \

/tutorials/waveFoam/newWave_focusedWave

Modify the Allrun file as the following:

#!/bin/bash

./Cleanall

cp -r 0.org 0

# Source tutorial run functions

. $WM_PROJECT_DIR/bin/tools/RunFunctions

# Set application name

application="waveFoam"

# Create the computational mesh

runApplication blockMesh

# Compute the wave parameters

runApplication setWaveParameters

# Write the relaxation zone layout

runApplication relaxationZoneLayout

# Set the wave field

runApplication setWaveField

# Run the application

runApplication $application

Save and Close!

Now you can run the tutorial executing:

./Allrun

5.7 Results

The focused wave at the theoretical focus location xo =4.35m as calculated by CFD simulation incomparison with the theoretical focused wave is given in the Figure 5.1.

Figure 5.2 comes from ParaView and depicts the surface elevation in the focus location and focustime.

43

Page 45: Focused Wave generation based on Linear NewWave Theory

5.7. RESULTS CHAPTER 5. TEST CASE

Figure 5.1: Theoretical vs Numerical surface elevation in the focus location

Figure 5.2: Focused Wave in Paraview

44

Page 46: Focused Wave generation based on Linear NewWave Theory

Study questions

1. Which are the main waves2Foam toolbox libraries have been discussed in the project?

2. Why the above libraries are important for the scope of this tutorial?

3. Which classes have been used in the present tutorial?

4. How the linear NewWave Theory has been implemented in this project?

5. How JONSWAP and PiersonMoskowitz classes have been modified?

6. How the same procedure can be done with less source code repetion?

45