Commit a7425273 authored by Andrew Heather's avatar Andrew Heather
Browse files

INT: refactored wave model code

parent 13d49f60
......@@ -2,6 +2,7 @@ waveModel/waveModel.C
waveModel/waveModelNew.C
waveGenerationModels/base/waveGenerationModel/waveGenerationModel.C
waveGenerationModels/base/irregularWaveModel/irregularWaveModel.C
waveGenerationModels/base/regularWaveModel/regularWaveModel.C
waveGenerationModels/base/solitaryWaveModel/solitaryWaveModel.C
waveGenerationModels/derived/Boussinesq/BoussinesqWaveModel.C
......@@ -12,6 +13,7 @@ waveGenerationModels/derived/streamFunction/streamFunctionWaveModel.C
waveGenerationModels/derived/StokesII/StokesIIWaveModel.C
waveGenerationModels/derived/StokesI/StokesIWaveModel.C
waveGenerationModels/derived/StokesV/StokesVWaveModel.C
waveGenerationModels/derived/irregularMultiDirectional/irregularMultiDirectionalWaveModel.C
waveAbsorptionModels/base/waveAbsorptionModel/waveAbsorptionModel.C
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
License
......@@ -49,6 +49,7 @@ Foam::scalar Foam::waveModels::irregularWaveModel::timeCoeff
return max(0, min(t/rampTime_, 1));
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::waveModels::irregularWaveModel::irregularWaveModel
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
License
......@@ -41,7 +41,7 @@ namespace waveModels
{
/*---------------------------------------------------------------------------*\
Class irregularWaveModel Declaration
Class irregularWaveModel Declaration
\*---------------------------------------------------------------------------*/
class irregularWaveModel
......@@ -69,6 +69,7 @@ protected:
//- Return the time scaling coefficient
virtual scalar timeCoeff(const scalar t) const;
public:
//- Runtime type information
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
License
......@@ -41,15 +41,6 @@ namespace waveModels
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::scalar Foam::waveModels::regularWaveModel::timeCoeff
(
const scalar t
) const
{
return max(0, min(t/rampTime_, 1));
}
Foam::word Foam::waveModels::regularWaveModel::waveType() const
{
scalar waveK = 2.0*mathematical::pi/waveLength_;
......@@ -78,8 +69,9 @@ Foam::waveModels::regularWaveModel::regularWaveModel
const bool readFields
)
:
waveGenerationModel(dict, mesh, patch, false),
rampTime_(VSMALL),
irregularWaveModel(dict, mesh, patch, false),
waveHeight_(0),
waveAngle_(0),
wavePeriod_(0),
waveLength_(0),
wavePhase_(1.5*mathematical::pi)
......@@ -104,9 +96,10 @@ bool Foam::waveModels::regularWaveModel::readDict
const dictionary& overrideDict
)
{
if (waveGenerationModel::readDict(overrideDict))
if (irregularWaveModel::readDict(overrideDict))
{
lookup("rampTime") >> rampTime_;
waveHeight_ = readWaveHeight();
waveAngle_ = readWaveAngle();
lookup("wavePeriod") >> wavePeriod_;
if (wavePeriod_ < 0)
......@@ -130,9 +123,10 @@ bool Foam::waveModels::regularWaveModel::readDict
void Foam::waveModels::regularWaveModel::info(Ostream& os) const
{
waveGenerationModel::info(os);
irregularWaveModel::info(os);
os << " Ramp time : " << rampTime_ << nl
os << " Wave height : " << waveHeight_ << nl
<< " Wave angle : " << 180/mathematical::pi*waveAngle_ << nl
<< " Wave period : " << wavePeriod_ << nl
<< " Wave length : " << waveLength_ << nl
<< " Wave phase : " << wavePhase_ << nl;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
License
......@@ -31,7 +31,7 @@ Description
#ifndef waveModels_reguarWaveModel_H
#define waveModels_reguarWaveModel_H
#include "waveGenerationModel.H"
#include "irregularWaveModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -46,7 +46,7 @@ namespace waveModels
class regularWaveModel
:
public waveGenerationModel
public irregularWaveModel
{
// Private Member Functions
......@@ -61,8 +61,11 @@ protected:
// Protected data
//- Ramp time
scalar rampTime_;
//- Wave height / [m]
scalar waveHeight_;
//- Wave angle / [rad] (read in degrees)
scalar waveAngle_;
//- Wave period
scalar wavePeriod_;
......@@ -76,9 +79,6 @@ protected:
// Protected Member Functions
//- Return the time scaling coefficient
virtual scalar timeCoeff(const scalar t) const;
//- Return word description of wave type
virtual word waveType() const;
......
......@@ -27,6 +27,11 @@ License
#include "polyPatch.H"
#include "SubField.H"
#include "mathematicalConstants.H"
using namespace Foam::constant;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
......@@ -61,6 +66,8 @@ Foam::waveModels::solitaryWaveModel::solitaryWaveModel
)
:
waveGenerationModel(dict, mesh, patch, false),
waveHeight_(0),
waveAngle_(0),
x_
(
patch.faceCentres().component(0)*cos(waveAngle_)
......@@ -90,6 +97,9 @@ bool Foam::waveModels::solitaryWaveModel::readDict
{
if (waveGenerationModel::readDict(overrideDict))
{
waveHeight_ = readWaveHeight();
waveAngle_ = readWaveAngle();
return true;
}
......@@ -101,7 +111,9 @@ void Foam::waveModels::solitaryWaveModel::info(Ostream& os) const
{
waveGenerationModel::info(os);
os << " x0: " << x0_ << nl;
os << " Wave height : " << waveHeight_ << nl
<< " Wave angle : " << 180/mathematical::pi*waveAngle_ << nl
<< " x0: " << x0_ << nl;
}
......
......@@ -53,6 +53,12 @@ protected:
// Protected data
//- Wave height / [m]
scalar waveHeight_;
//- Wave angle / [rad] (read in degrees)
scalar waveAngle_;
//-
const scalarField& x_;
......
......@@ -39,6 +39,30 @@ namespace waveModels
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::scalar Foam::waveModels::waveGenerationModel::readWaveHeight() const
{
scalar h(readScalar(lookup("waveHeight")));
if (h < 0)
{
FatalIOErrorInFunction(*this)
<< "Wave height must be greater than zero. Supplied"
<< " value waveHeight = " << h
<< exit(FatalIOError);
}
return h;
}
Foam::scalar Foam::waveModels::waveGenerationModel::readWaveAngle() const
{
scalar angle(readScalar(lookup("waveAngle")));
return angle* mathematical::pi/180;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::waveModels::waveGenerationModel::waveGenerationModel
......@@ -49,9 +73,7 @@ Foam::waveModels::waveGenerationModel::waveGenerationModel
const bool readFields
)
:
waveModel(dict, mesh, patch, false),
waveHeight_(0),
waveAngle_(0)
waveModel(dict, mesh, patch, false)
{
if (readFields)
{
......@@ -77,18 +99,6 @@ bool Foam::waveModels::waveGenerationModel::readDict
{
lookup("activeAbsorption") >> activeAbsorption_;
lookup("waveHeight") >> waveHeight_;
if (waveHeight_ < 0)
{
FatalIOErrorInFunction(*this)
<< "Wave height must be greater than zero. Supplied"
<< " value waveHeight = " << waveHeight_
<< exit(FatalIOError);
}
lookup("waveAngle") >> waveAngle_;
waveAngle_ *= mathematical::pi/180;
return true;
}
......@@ -99,9 +109,6 @@ bool Foam::waveModels::waveGenerationModel::readDict
void Foam::waveModels::waveGenerationModel::info(Ostream& os) const
{
waveModel::info(os);
os << " Wave height : " << waveHeight_ << nl
<< " Wave angle : " << 180/mathematical::pi*waveAngle_ << nl;
}
......
......@@ -50,13 +50,13 @@ class waveGenerationModel
{
protected:
// Protected data
// Protected Member Functions
//- Wave height / [m]
scalar waveHeight_;
//- Helper function to read the wave height from the coeff dictionary
scalar readWaveHeight() const;
//- Wave angle / [rad] (read in degrees)
scalar waveAngle_;
//- Helper function to read the wave angle from the coeff dictionary
scalar readWaveAngle() const;
public:
......
......@@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/
#include "irregularWavesMultiDirecWaveModel.H"
#include "irregularMultiDirectionalWaveModel.H"
#include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
......@@ -35,11 +35,11 @@ namespace Foam
{
namespace waveModels
{
defineTypeNameAndDebug(irregularWavesMultiDirec, 0);
defineTypeNameAndDebug(irregularMultiDirectional, 0);
addToRunTimeSelectionTable
(
waveModel,
irregularWavesMultiDirec,
irregularMultiDirectional,
patch
);
}
......@@ -48,8 +48,7 @@ namespace waveModels
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
// First order wave height
Foam::scalar Foam::waveModels::irregularWavesMultiDirec::eta
Foam::scalar Foam::waveModels::irregularMultiDirectional::eta
(
const scalar H,
const scalar Kx,
......@@ -68,8 +67,7 @@ Foam::scalar Foam::waveModels::irregularWavesMultiDirec::eta
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
//Calculate waveLength
Foam::scalar Foam::waveModels::irregularWavesMultiDirec::waveLength
Foam::scalar Foam::waveModels::irregularMultiDirectional::waveLength
(
const scalar h,
const scalar T
......@@ -78,7 +76,7 @@ Foam::scalar Foam::waveModels::irregularWavesMultiDirec::waveLength
scalar L0 = mag(g_)*T*T/(2.0*mathematical::pi);
scalar L = L0;
for (int iii=1; iii<=100; iii++)
for (label i=1; i<=100; ++i)
{
L = L0*tanh(2.0*mathematical::pi*h/L);
}
......@@ -87,7 +85,7 @@ Foam::scalar Foam::waveModels::irregularWavesMultiDirec::waveLength
}
Foam::vector Foam::waveModels::irregularWavesMultiDirec::U
Foam::vector Foam::waveModels::irregularMultiDirectional::Uf
(
const scalar h,
const scalar x,
......@@ -100,98 +98,80 @@ Foam::vector Foam::waveModels::irregularWavesMultiDirec::U
scalar v = 0.0;
scalar w = 0.0;
scalar phaseTot = 0.0;
scalar waveKs_ = 0.0;
scalar waveOmegas_ = 0.0;
int ii;
int jj;
scalar COLUMNAS = 0;
scalar FILAS = irregWaveHeights_.size();
for (ii=0; ii<FILAS; ++ii)
{
COLUMNAS= irregWaveHeights_[ii].size();
for (jj=0; jj<COLUMNAS; ++jj)
{
waveKs_ = mathematical::twoPi/irregWaveLengths_[ii][jj];
waveOmegas_ = mathematical::twoPi/irregWavePeriods_[ii][jj];
phaseTot = waveKs_*x*cos(irregWaveDirs_[ii][jj]) + waveKs_*y*sin(irregWaveDirs_[ii][jj]) - waveOmegas_*t + irregWavePhases_[ii][jj];
const vector Uf = uMultiDirec
(
irregWaveHeights_[ii][jj],
waveOmegas_,
phaseTot,
waveKs_,
z,
h,
irregWaveDirs_[ii][jj]
);
u = u + Uf[0];
v = v + Uf[1];
w = w + Uf[2];
}
forAll(irregWaveHeights_, ii)
{
forAll(irregWaveHeights_[ii], jj)
{
scalar waveKs = mathematical::twoPi/irregWaveLengths_[ii][jj];
scalar waveOmegas = mathematical::twoPi/irregWavePeriods_[ii][jj];
scalar phaseTot =
waveKs*x*cos(irregWaveDirs_[ii][jj])
+ waveKs*y*sin(irregWaveDirs_[ii][jj])
- waveOmegas*t
+ irregWavePhases_[ii][jj];
const vector Uf = uMultiDirec
(
irregWaveHeights_[ii][jj],
waveOmegas,
phaseTot,
waveKs,
z,
h,
irregWaveDirs_[ii][jj]
);
u += Uf[0];
v += Uf[1];
w += Uf[2];
}
}
return vector(u, v, w);
}
void Foam::waveModels::irregularWavesMultiDirec::setLevel
void Foam::waveModels::irregularMultiDirectional::setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const
{
scalar eta = 0.0;
scalar COLUMNAS = 0;
scalar FILAS = 0;
scalar waveKs_ = 0.0;
scalar waveOmegas_ = 0.0;
int ii;
int jj;
forAll(level, paddlei)
{
eta = 0.0;
FILAS= irregWaveHeights_.size();
scalar eta = 0;
for (ii=0; ii<FILAS; ++ii)
{
COLUMNAS= irregWaveHeights_[ii].size();
for (jj=0; jj<COLUMNAS; ++jj)
{
waveKs_ = mathematical::twoPi/irregWaveLengths_[ii][jj];
waveOmegas_ = mathematical::twoPi/irregWavePeriods_[ii][jj];
forAll(irregWaveHeights_, ii)
{
forAll(irregWaveHeights_[ii], jj)
{
scalar waveKs = mathematical::twoPi/irregWaveLengths_[ii][jj];
scalar waveOmegas =
mathematical::twoPi/irregWavePeriods_[ii][jj];
eta +=
this->eta
(
(
irregWaveHeights_[ii][jj],
waveKs_*cos(irregWaveDirs_[ii][jj]),
xPaddle_[paddlei],
waveKs_*sin(irregWaveDirs_[ii][jj]),
yPaddle_[paddlei],
waveOmegas_,
waveKs*cos(irregWaveDirs_[ii][jj]),
xPaddle_[paddlei],
waveKs*sin(irregWaveDirs_[ii][jj]),
yPaddle_[paddlei],
waveOmegas,
t,
irregWavePhases_[ii][jj]
);
}
}
);
}
}
level[paddlei] = waterDepthRef_ + tCoeff*eta;
level[paddlei] = waterDepthRef_ + tCoeff*eta;
}
}
Foam::vector Foam::waveModels::irregularWavesMultiDirec::uMultiDirec
Foam::vector Foam::waveModels::irregularMultiDirectional::uMultiDirec
(
const scalar irregH,
const scalar irregWaveOmega,
......@@ -202,31 +182,23 @@ Foam::vector Foam::waveModels::irregularWavesMultiDirec::uMultiDirec
const scalar irregDir
) const
{
const scalar ksh = irregWaveKs*hh;
const scalar ksz = irregWaveKs*zz;
scalar u =
irregH*0.5*irregWaveOmega*
cos(pha)*
(cosh(irregWaveKs*zz)/
sinh(irregWaveKs*hh))*
cos(irregDir);
scalar v =
irregH*0.5*irregWaveOmega*
cos(pha)*
(cosh(irregWaveKs*zz)/
sinh(irregWaveKs*hh))*
sin(irregDir);
irregH*0.5*irregWaveOmega*cos(pha)*(cosh(ksz)/sinh(ksh))*cos(irregDir);
scalar v =
irregH*0.5*irregWaveOmega*cos(pha)*(cosh(ksz)/sinh(ksh))*sin(irregDir);
scalar w =
irregH*0.5*irregWaveOmega*
sin(pha)*
(sinh(irregWaveKs*zz)/
sinh(irregWaveKs*hh));
irregH*0.5*irregWaveOmega*sin(pha)*(sinh(ksz)/sinh(ksh));
return vector(u, v, w);
}
void Foam::waveModels::irregularWavesMultiDirec::setVelocity
void Foam::waveModels::irregularMultiDirectional::setVelocity
(
const scalar t,
const scalar tCoeff,
......@@ -247,8 +219,8 @@ void Foam::waveModels::irregularWavesMultiDirec::setVelocity
{
const label paddlei = faceToPaddle_[facei];
const vector Uf = U
(
const vector Uf = this->Uf
(
waterDepthRef_,
xPaddle_[paddlei],
yPaddle_[paddlei],
......@@ -257,15 +229,14 @@ void Foam::waveModels::irregularWavesMultiDirec::setVelocity
);
U_[facei] = fraction*Uf*tCoeff;
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::waveModels::irregularWavesMultiDirec::irregularWavesMultiDirec
Foam::waveModels::irregularMultiDirectional::irregularMultiDirectional
(