ENH: Initial integration of IHCantrabria wave functionality

- Wave models significantly restructured and refactored into a hierarchy of run-time selecatable models
- Gravity no longer hard-coded
- Ability to use any direction as the gravity direction
- Boundary conditions simplified and take reference to the wave model
  - removes a lot of code duplication and new code is ~30% faster
- Removed unused functions

Requires further testing
- Restart behaviour needs to be addressed
This commit is contained in:
Andrew Heather
2016-11-16 14:05:46 +00:00
parent 95e9467e84
commit b3b0704202
36 changed files with 5805 additions and 0 deletions

View File

@ -0,0 +1,251 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "BoussinesqWaveModel.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
defineTypeNameAndDebug(Boussinesq, 0);
addToRunTimeSelectionTable
(
waveModel,
Boussinesq,
patch
);
}
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::scalar Foam::waveModels::Boussinesq::eta
(
const scalar H,
const scalar h,
const scalar x,
const scalar y,
const scalar theta,
const scalar t,
const scalar X0
) const
{
scalar C = sqrt(mag(g_)*(H + h));
scalar ts = 3.5*h/sqrt(H/h);
scalar aux = sqrt(3.0*H/(4.0*h))/h;
scalar Xa = -C*t + ts - X0 + x*cos(theta) + y*sin(theta);
return H*1.0/sqr(cosh(aux*Xa));
}
Foam::vector Foam::waveModels::Boussinesq::Deta
(
const scalar H,
const scalar h,
const scalar x,
const scalar y,
const scalar theta,
const scalar t,
const scalar X0
) const
{
vector deta(vector::zero);
scalar C = sqrt(mag(g_)*(H + h));
scalar ts = 3*h/sqrt(H/h);
scalar a = sqrt(3*H/(4*h))/h;
scalar Xa = -C*t + ts - X0 + x*cos(theta) + y*sin(theta);
scalar expTerm = exp(2*a*Xa);
scalar b = 8*a*h*expTerm;
deta[0] =
b*(1 - expTerm)
/pow3(1 + expTerm);
deta[1] =
2*a*b*(exp(4*a*Xa) - 4*expTerm + 1)
/pow4(1 + expTerm);
deta[2] =
-4*sqr(a)*b*(exp(6*a*Xa) - 11*exp(4*a*Xa) + 11*expTerm - 1)
/pow5(1 + expTerm);
return deta;
}
Foam::vector Foam::waveModels::Boussinesq::U
(
const scalar H,
const scalar h,
const scalar x,
const scalar y,
const scalar theta,
const scalar t,
const scalar X0,
const scalar z
) const
{
scalar C = sqrt(mag(g_)*(H + h));
scalar eta = this->eta(H, h, x, y, theta, t, X0);
vector Deta = this->Deta(H, h, x, y, theta, t, X0);
scalar u =
C*eta/h
*(
1.0
- eta/(4.0*h)
+ sqr(h)/(3.0*eta)*(1.0 - 3.0/2.0*sqr(z/h))*Deta[1]
);
scalar w =
-C*z/h
*(
(1.0 - eta/(2.0*h))*Deta[0]
+ sqr(h)/3.0*(1.0 - 1.0/2.0*sqr(z/h))*Deta[2]
);
scalar v = u*sin(waveAngle_);
u *= cos(waveAngle_);
return vector(u, v, w);
}
void Foam::waveModels::Boussinesq::setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const
{
forAll(level, paddlei)
{
const scalar eta =
this->eta
(
waveHeight_,
waterDepthRef_,
xPaddle_[paddlei],
yPaddle_[paddlei],
waveAngle_,
t,
x0_
);
level[paddlei] = waterDepthRef_ + tCoeff*eta;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::waveModels::Boussinesq::Boussinesq
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields
)
:
solitaryWaveModel(dict, mesh, patch, false)
{
if (readFields)
{
read();
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::waveModels::Boussinesq::~Boussinesq()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::waveModels::Boussinesq::read()
{
if (solitaryWaveModel::read())
{
return true;
}
return false;
}
void Foam::waveModels::Boussinesq::setVelocity
(
const scalar t,
const scalar tCoeff,
const scalarField& level
)
{
forAll(U_, facei)
{
// Fraction of geometry represented by paddle - to be set
scalar fraction = 1;
// Height - to be set
scalar z = 0;
setPaddlePropeties(level, facei, fraction, z);
if (fraction > 0)
{
const label paddlei = faceToPaddle_[facei];
const vector Uf = U
(
waveHeight_,
waterDepthRef_,
xPaddle_[paddlei],
yPaddle_[paddlei],
waveAngle_,
t,
x0_,
z
);
U_[facei] = fraction*Uf*tCoeff;
}
}
}
void Foam::waveModels::Boussinesq::info(Ostream& os) const
{
solitaryWaveModel::info(os);
}
// ************************************************************************* //

View File

@ -0,0 +1,145 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::waveModels::Boussinesq
Description
\*---------------------------------------------------------------------------*/
#ifndef waveModels_Boussinesq_H
#define waveModels_Boussinesq_H
#include "solitaryWaveModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
/*---------------------------------------------------------------------------*\
Class Boussinesq Declaration
\*---------------------------------------------------------------------------*/
class Boussinesq
:
public solitaryWaveModel
{
protected:
// Protected Member Functions
//- Wave height
virtual scalar eta
(
const scalar H,
const scalar h,
const scalar x,
const scalar y,
const scalar theta,
const scalar t,
const scalar X0
) const;
//- wave
virtual vector Deta
(
const scalar H,
const scalar h,
const scalar x,
const scalar y,
const scalar theta,
const scalar t,
const scalar X0
) const;
//- Wave velocity
virtual vector U
(
const scalar H,
const scalar h,
const scalar x,
const scalar y,
const scalar theta,
const scalar t,
const scalar X0,
const scalar z
) const;
//- Set the water level
virtual void setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const;
//- Calculate the wave model velocity
virtual void setVelocity
(
const scalar t,
const scalar tCoeff,
const scalarField& level
);
public:
//- Runtime type information
TypeName("Boussinesq");
//- Constructor
Boussinesq
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields = true
);
//- Destructor
virtual ~Boussinesq();
// Public Member Functions
//- Read from dictionary
virtual bool read();
//- Info
virtual void info(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace waveModels
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,238 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "StokesIWaveModel.H"
#include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
using namespace Foam::constant;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
defineTypeNameAndDebug(StokesI, 0);
addToRunTimeSelectionTable
(
waveModel,
StokesI,
patch
);
}
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::scalar Foam::waveModels::StokesI::waveLength
(
const scalar h,
const scalar T
) const
{
scalar L0 = mag(g_)*T*T/(2.0*mathematical::pi);
scalar L = L0;
for (int i=1; i<=100; i++)
{
L = L0*tanh(2.0*mathematical::pi*h/L);
}
return L;
}
Foam::scalar Foam::waveModels::StokesI::eta
(
const scalar H,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase
) const
{
scalar phaseTot = Kx*x + Ky*y - omega*t + phase;
return H*0.5*cos(phaseTot);
}
Foam::vector Foam::waveModels::StokesI::U
(
const scalar H,
const scalar h,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase,
const scalar z
) const
{
scalar k = sqrt(Kx*Kx + Ky*Ky);
scalar phaseTot = Kx*x + Ky*y - omega*t + phase;
scalar u = H*0.5*omega*cos(phaseTot)*cosh(k*z)/sinh(k*h);
scalar w = H*0.5*omega*sin(phaseTot)*sinh(k*z)/sinh(k*h);
scalar v = u*sin(waveAngle_);
u *= cos(waveAngle_);
return vector(u, v, w);
}
void Foam::waveModels::StokesI::setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const
{
const scalar waveOmega = mathematical::twoPi/wavePeriod_;
const scalar waveK = mathematical::twoPi/waveLength_;
const scalar waveKx = waveK*cos(waveAngle_);
const scalar waveKy = waveK*sin(waveAngle_);
forAll(level, paddlei)
{
const scalar eta =
this->eta
(
waveHeight_,
waveKx,
xPaddle_[paddlei],
waveKy,
yPaddle_[paddlei],
waveOmega,
t,
wavePhase_
);
level[paddlei] = waterDepthRef_ + tCoeff*eta;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::waveModels::StokesI::StokesI
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields
)
:
regularWaveModel(dict, mesh, patch, false)
{
if (readFields)
{
read();
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::waveModels::StokesI::~StokesI()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::waveModels::StokesI::read()
{
if (regularWaveModel::read())
{
waveLength_ = waveLength(waterDepthRef_, wavePeriod_);
return true;
}
return false;
}
void Foam::waveModels::StokesI::setVelocity
(
const scalar t,
const scalar tCoeff,
const scalarField& level
)
{
const scalar waveOmega = mathematical::twoPi/wavePeriod_;
const scalar waveK = mathematical::twoPi/waveLength_;
const scalar waveKx = waveK*cos(waveAngle_);
const scalar waveKy = waveK*sin(waveAngle_);
forAll(U_, facei)
{
// Fraction of geometry represented by paddle - to be set
scalar fraction = 1;
// Height - to be set
scalar z = 0;
setPaddlePropeties(level, facei, fraction, z);
if (fraction > 0)
{
const label paddlei = faceToPaddle_[facei];
const vector Uf = U
(
waveHeight_,
waterDepthRef_,
waveKx,
xPaddle_[paddlei],
waveKy,
yPaddle_[paddlei],
waveOmega,
t,
wavePhase_,
z
);
U_[facei] = fraction*Uf*tCoeff;
}
}
}
void Foam::waveModels::StokesI::info(Ostream& os) const
{
regularWaveModel::info(os);
os << " Wave type: " << waveType() << nl;
}
// ************************************************************************* //

View File

@ -0,0 +1,138 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::waveModels::StokesI
Description
\*---------------------------------------------------------------------------*/
#ifndef waveModels_StokesI_H
#define waveModels_StokesI_H
#include "regularWaveModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
/*---------------------------------------------------------------------------*\
Class StokesI Declaration
\*---------------------------------------------------------------------------*/
class StokesI
:
public regularWaveModel
{
protected:
// Protected Member Functions
//- Return the wavelength
virtual scalar waveLength(const scalar h, const scalar T) const;
virtual scalar eta
(
const scalar H,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase
) const;
virtual vector U
(
const scalar H,
const scalar h,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase,
const scalar z
) const;
//- Set the water level
virtual void setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const;
//- Calculate the wave model velocity
virtual void setVelocity
(
const scalar t,
const scalar tCoeff,
const scalarField& level
);
public:
//- Runtime type information
TypeName("StokesI");
//- Constructor
StokesI
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields = true
);
//- Destructor
virtual ~StokesI();
// Public Member Functions
//- Read from dictionary
virtual bool read();
//- Info
virtual void info(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace waveModels
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,181 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "StokesIIWaveModel.H"
#include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
using namespace Foam::constant;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
defineTypeNameAndDebug(StokesII, 0);
addToRunTimeSelectionTable
(
waveModel,
StokesII,
patch
);
}
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::scalar Foam::waveModels::StokesII::eta
(
const scalar H,
const scalar h,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase
) const
{
const scalar k = sqrt(Kx*Kx + Ky*Ky);
const scalar sigma = tanh(k*h);
const scalar phaseTot = Kx*x + Ky*y - omega*t + phase;
return
H*0.5*cos(phaseTot)
+ k*H*H/4.0*(3.0 - sigma*sigma)/(4.0*pow3(sigma))*cos(2.0*phaseTot);
}
Foam::vector Foam::waveModels::StokesII::U
(
const scalar H,
const scalar h,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase,
const scalar z
) const
{
const scalar k = sqrt(Kx*Kx + Ky*Ky);
const scalar phaseTot = Kx*x + Ky*y - omega*t + phase;
scalar u =
H*0.5*omega*cos(phaseTot)*cosh(k*z)/sinh(k*h)
+ 3.0/4.0*H*H/4.0*omega*k*cosh(2.0*k*z)/pow4(sinh(k*h))*cos(2.0*phaseTot);
scalar w =
H*0.5*omega*sin(phaseTot)*sinh(k*z)/sinh(k*h)
+ 3.0/4.0*H*H/4.0*omega*k*sinh(2.0*k*z)/pow4(sinh(k*h))*sin(2.0*phaseTot);
scalar v = u*sin(waveAngle_);
u *= cos(waveAngle_);
return vector(u, v, w);
}
void Foam::waveModels::StokesII::setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const
{
const scalar waveOmega = mathematical::twoPi/wavePeriod_;
const scalar waveK = mathematical::twoPi/waveLength_;
const scalar waveKx = waveK*cos(waveAngle_);
const scalar waveKy = waveK*sin(waveAngle_);
forAll(level, paddlei)
{
const scalar eta =
this->eta
(
waveHeight_,
waterDepthRef_,
waveKx,
xPaddle_[paddlei],
waveKy,
yPaddle_[paddlei],
waveOmega,
t,
wavePhase_
);
level[paddlei] = waterDepthRef_ + tCoeff*eta;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::waveModels::StokesII::StokesII
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields
)
:
StokesI(dict, mesh, patch, false)
{
if (readFields)
{
read();
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::waveModels::StokesII::~StokesII()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::waveModels::StokesII::read()
{
if (StokesI::read())
{
return true;
}
return false;
}
void Foam::waveModels::StokesII::info(Ostream& os) const
{
StokesI::info(os);
}
// ************************************************************************* //

View File

@ -0,0 +1,128 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::waveModels::StokesII
Description
\*---------------------------------------------------------------------------*/
#ifndef waveModels_StokesII_H
#define waveModels_StokesII_H
#include "StokesIWaveModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
/*---------------------------------------------------------------------------*\
Class StokesII Declaration
\*---------------------------------------------------------------------------*/
class StokesII
:
public StokesI
{
protected:
// Protected Member Functions
virtual scalar eta
(
const scalar H,
const scalar h,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase
) const;
virtual vector U
(
const scalar H,
const scalar h,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase,
const scalar z
) const;
//- Set the water level
virtual void setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const;
public:
//- Runtime type information
TypeName("StokesII");
//- Constructor
StokesII
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields = true
);
//- Destructor
virtual ~StokesII();
// Public Member Functions
//- Read from dictionary
virtual bool read();
//- Info
virtual void info(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace waveModels
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,895 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "StokesVWaveModel.H"
#include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
using namespace Foam::constant;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
defineTypeNameAndDebug(StokesV, 0);
addToRunTimeSelectionTable
(
waveModel,
StokesV,
patch
);
}
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::scalar Foam::waveModels::StokesV::A11
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
return 1.0/s;
}
Foam::scalar Foam::waveModels::StokesV::A13
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return -sqr(c)*(5*sqr(c) + 1)/(8*pow5(s));
}
Foam::scalar Foam::waveModels::StokesV::A15
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
-(
1184*pow(c, 10)
- 1440*pow(c, 8)
- 1992*pow6(c)
+ 2641*pow4(c)
- 249*sqr(c) + 18
)
/(1536*pow(s, 11));
}
Foam::scalar Foam::waveModels::StokesV::A22
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
return 3/(8*pow4(s));
}
Foam::scalar Foam::waveModels::StokesV::A24
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
(192*pow(c, 8) - 424*pow(c, 6) - 312*pow4(c) + 480*sqr(c) - 17)
/(768*pow(s, 10));
}
Foam::scalar Foam::waveModels::StokesV::A33
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return (13 - 4*sqr(c))/(64*pow(s, 7));
}
Foam::scalar Foam::waveModels::StokesV::A35
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
(
512*pow(c, 12)
+ 4224*pow(c, 10)
- 6800*pow(c, 8)
- 12808*pow(c, 6)
+ 16704.0*pow4(c)
- 3154*sqr(c)
+ 107
)
/(4096*pow(s, 13)*(6*sqr(c) - 1));
}
Foam::scalar Foam::waveModels::StokesV::A44
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
(80*pow(c, 6) - 816*pow4(c) + 1338*sqr(c) - 197)
/(1536*pow(s, 10)*(6*sqr(c) - 1));
}
Foam::scalar Foam::waveModels::StokesV::A55
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
-(
2880*pow(c, 10)
- 72480*pow(c, 8)
+ 324000*pow(c, 6)
- 432000*pow4(c)
+ 163470*sqr(c)
- 16245
)
/(61440*pow(s, 11)*(6*sqr(c) - 1)*(8*pow4(c) - 11*sqr(c) + 3));
}
Foam::scalar Foam::waveModels::StokesV::B22
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return (2*sqr(c) + 1)*c/(4*pow3(s));
}
Foam::scalar Foam::waveModels::StokesV::B24
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
(272*pow(c, 8) - 504*pow(c, 6) - 192*pow4(c) + 322*sqr(c) + 21)*c
/(384*pow(s, 9));
}
Foam::scalar Foam::waveModels::StokesV::B33
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return (8*pow6(c) + 1)*3/(64*pow6(s));
}
Foam::scalar Foam::waveModels::StokesV::B33k
(
const scalar h,
const scalar k
) const // d B33 / d k
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
const scalar sk = h*s;
const scalar ck = h*c;
return 9.*pow5(c)*ck/(4*pow6(s)) - (9*(8*pow6(c) + 1))/(32*pow(s, 7))*sk;
}
Foam::scalar Foam::waveModels::StokesV::B35
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
(
88128*pow(c, 14)
- 208224*pow(c, 12)
+ 70848*pow(c, 10)
+ 54000*pow(c, 8)
- 21816*pow6(c)
+ 6264*pow4(c)
- 54*sqr(c)
- 81
)
/(12288*pow(s, 12)*(6*sqr(c) - 1));
}
Foam::scalar Foam::waveModels::StokesV::B35k
(
const scalar h,
const scalar k
) const // d B35 / d k
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
const scalar sk = h*s;
const scalar ck = h*c;
return
(
14*88128*pow(c, 13)*ck
- 12*208224*pow(c, 11)*ck
+ 10*70848*pow(c, 9)*ck
+ 8*54000.0*pow(c, 7)*ck
- 6*21816*pow5(c)*ck
+ 4*6264*pow3(c)*ck
- 2*54*c*ck
)
/(12288*pow(s, 12)*(6*sqr(c) - 1))
- (
88128*pow(c, 14)
- 208224*pow(c, 12)
+ 70848*pow(c, 10)
+ 54000*pow(c, 8)
- 21816*pow6(c)
+ 6264*pow4(c)
- 54*sqr(c)
- 81
)*12
/(12288*pow(s, 13)*(6*sqr(c) - 1))*sk
- (
88128*pow(c,14)
- 208224*pow(c, 12)
+ 70848*pow(c, 10)
+ 54000*pow(c, 8)
- 21816*pow6(c)
+ 6264*pow4(c)
- 54*sqr(c)
- 81
)*12*c*ck
/(12288*pow(s, 12)*sqr(6*sqr(c) - 1));
}
Foam::scalar Foam::waveModels::StokesV::B44
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
(
768*pow(c, 10)
- 448*pow(c, 8)
- 48*pow6(c)
+ 48*pow4(c)
+ 106*sqr(c)
- 21
)*c
/(384*pow(s, 9)*(6*sqr(c) - 1));
}
Foam::scalar Foam::waveModels::StokesV::B55
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
(
192000*pow(c, 16)
- 262720*pow(c, 14)
+ 83680*pow(c, 12)
+ 20160*pow(c, 10)
- 7280*pow(c, 8)
+ 7160*pow(c, 6)
- 1800*pow(c, 4)
- 1050*sqr(c)
+ 225
)
/(12288*pow(s, 10)*(6*sqr(c) - 1)*(8*pow4(c) - 11*sqr(c) + 3));
}
Foam::scalar Foam::waveModels::StokesV::B55k
(
const scalar h,
const scalar k
) const // d B55 / d k
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
const scalar sk = h*s;
const scalar ck = h*c;
return
(
16*192000*pow(c, 15)*ck
- 14*262720*pow(c, 13)*ck
+ 12*83680*pow(c, 11)*ck
+ 10*20160*pow(c, 9)*ck
- 8*7280*pow(c, 7)*ck
+ 6*7160*pow(c, 5)*ck
- 4*1800*pow(c, 3)*ck
- 2*1050*pow(c,1)*ck
)
/(12288*pow(s, 10)*(6*sqr(c) - 1)*(8*pow(c, 4) - 11*sqr(c) + 3))
- (
192000*pow(c, 16)
- 262720*pow(c, 14)
+ 83680*pow(c, 12)
+ 20160*pow(c, 10)
- 7280*pow(c, 8)
+ 7160*pow(c, 6)
- 1800*pow(c, 4)
- 1050*pow(c, 2)
+ 225
)*10.0
/(12288*pow(s, 11)*(6*sqr(c) - 1)*(8*pow4(c) - 11*sqr(c) + 3))*sk
- (
192000*pow(c, 16)
- 262720*pow(c, 14)
+ 83680*pow(c, 12)
+ 20160*pow(c,10)
- 7280*pow(c, 8)
+ 7160*pow(c, 6)
- 1800*pow(c,4)
- 1050*pow(c, 2)
+ 225
)*12*c*ck
/(12288*pow(s, 10)*sqr(6*sqr(c) - 1)*(8*pow4(c) - 11*sqr(c) + 3))
- (
192000*pow(c, 16)
- 262720*pow(c, 14)
+ 83680*pow(c, 12)
+ 20160*pow(c, 10)
- 7280*pow(c, 8)
+ 7160*pow(c, 6)
- 1800*pow(c, 4)
- 1050*pow(c, 2)
+ 225
)*(32*pow3(c) - 22*c)*ck
/(12288*pow(s, 10)*(6*sqr(c) - 1)*sqr(8*pow4(c) - 11*sqr(c) + 3));
}
Foam::scalar Foam::waveModels::StokesV::C1
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return (8*pow4(c) - 8*sqr(c) + 9)/(8*pow4(s));
}
Foam::scalar Foam::waveModels::StokesV::C1k
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
const scalar sk = h*s;
const scalar ck = h*c;
return
(4*8*pow3(c)*ck - 2*8*c*ck)/(8*pow4(s))
- (8*pow4(c) - 8*sqr(c) + 9)*4*sk/(8*pow5(s));
}
Foam::scalar Foam::waveModels::StokesV::C2
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
(
3840*pow(c, 12)
- 4096*pow(c, 10)
+ 2592*pow(c, 8)
- 1008*pow(c, 6)
+ 5944*pow(c, 4)
- 1830*pow(c, 2)
+ 147
) // - 2592
/(512*pow(s, 10)*(6*sqr(c) - 1));
}
Foam::scalar Foam::waveModels::StokesV::C2k
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
const scalar sk = h*s;
const scalar ck = h*c;
return
(
12*3840*pow(c, 11)*ck
- 10*4096*pow(c,9)*ck
+ 8*2592*pow(c, 7)*ck
- 6*1008*pow(c, 5)*ck
+ 4*5944*pow(c, 3)*ck
- 2*1830*c*ck
)
/(512*pow(s, 10)*(6*sqr(c) - 1))
- (
3840*pow(c, 12)
- 4096*pow(c, 10)
+ 2592*pow(c, 8)
- 1008*pow(c, 6)
+ 5944*pow(c, 4)
- 1830*pow(c, 2)
+ 147
)*10*sk
/(512*pow(s, 11)*(6*sqr(c) - 1))
- (
3840*pow(c, 12)
- 4096*pow(c, 10)
+ 2592*pow(c, 8)
- 1008*pow(c, 6)
+ 5944*pow(c, 4)
- 1830*pow(c, 2)
+ 147
)*12*c*ck
/(512*pow(s, 10)*sqr(6*sqr(c) - 1));
}
Foam::scalar Foam::waveModels::StokesV::C3
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return -1/(4*s*c);
}
Foam::scalar Foam::waveModels::StokesV::C4
(
const scalar h,
const scalar k
) const
{
const scalar s = sinh(k*h);
const scalar c = cosh(k*h);
return
(12*pow(c, 8) + 36*pow(c, 6) - 162*pow(c, 4) + 141*sqr(c) -27)
/(192*c*pow(s, 9));
}
void Foam::waveModels::StokesV::initialise
(
const scalar H,
const scalar d,
const scalar T,
scalar& kOut,
scalar& LambdaOut,
scalar& f1Out,
scalar& f2Out
) const
{
scalar f1 = 1;
scalar f2 = 1;
const scalar pi = mathematical::pi;
scalar k = 2.0*pi/(sqrt(mag(g_)*d)*T);
scalar lambda = H/2.0*k;
label n = 0;
const scalar tolerance = 1e-12;
const label iterMax = 10000;
while ((mag(f1) > tolerance || mag(f2) > tolerance) && (n < iterMax))
{
const scalar b33 = B33(d, k);
const scalar b35 = B35(d, k);
const scalar b55 = B55(d, k);
const scalar c1 = C1(d, k);
const scalar c2 = C2(d, k);
const scalar b33k = B33k(d, k);
const scalar b35k = B35k(d, k);
const scalar b55k = B55k(d, k);
const scalar c1k = C1k(d, k);
const scalar c2k = C2k(d, k);
const scalar l2 = sqr(lambda);
const scalar l3 = l2*lambda;
const scalar l4 = l3*lambda;
const scalar l5 = l4*lambda;
const scalar Bmat11 =
2*pi/(sqr(k)*d)*(lambda + l3*b33 + l5*(b35 + b55))
- 2*pi/(k*d)*(l3*b33k + l5*(b35k + b55k));
const scalar Bmat12 =
- 2*pi/(k*d)*(1 + 3*l2*b33 + 5*l4*(b35 + b55));
const scalar Bmat21 =
- d/(2*pi)*tanh(k*d)*(1 + l2*c1 + l4*c2)
- k*d/(2*pi)*(1 - sqr(tanh(k*d)))*d*(1 + l2*c1 + l4*c2)
- k*d/(2*pi)*tanh(k*d)*(l2*c1k + l4*c2k);
const scalar Bmat22 = - k*d/(2.0*pi)*tanh(k*d)*(2*lambda*c1 + 4*l3*c2);
f1 = pi*H/d - 2*pi/(k*d)*(lambda + l3*b33 + l5*(b35 + b55));
f2 = (2*pi*d)/(mag(g_)*sqr(T)) - k*d/(2*pi)*tanh(k*d)*(1 + l2*c1 + l4*c2);
const scalar lambdaPr =
(f1*Bmat21 - f2*Bmat11)/(Bmat11*Bmat22 - Bmat12*Bmat21);
const scalar kPr =
(f2*Bmat12 - f1*Bmat22)/(Bmat11*Bmat22 - Bmat12*Bmat21);
lambda += lambdaPr;
k += kPr;
n++;
}
kOut = k;
LambdaOut = lambda;
f1Out = mag(f1);
f2Out = mag(f2);
}
Foam::scalar Foam::waveModels::StokesV::eta
(
const scalar h,
const scalar kx,
const scalar ky,
const scalar lambda,
const scalar T,
const scalar x,
const scalar y,
const scalar t,
const scalar phase
) const
{
const scalar k = sqrt(kx*kx + ky*ky);
const scalar b22 = B22(h, k);
const scalar b24 = B24(h, k);
const scalar b33 = B33(h, k);
const scalar b35 = B35(h, k);
const scalar b44 = B44(h, k);
const scalar b55 = B55(h, k);
const scalar l2 = sqr(lambda);
const scalar l3 = l2*lambda;
const scalar l4 = l3*lambda;
const scalar l5 = l4*lambda;
const scalar amp1 = lambda/k;
const scalar amp2 = (b22*l2 + b24*l4)/k;
const scalar amp3 = (b33*l3 + b35*l5)/k;
const scalar amp4 = b44*l4/k;
const scalar amp5 = b55*l5/k;
const scalar theta = kx*x + ky*y - 2.0*mathematical::pi/T*t + phase;
return
amp1*cos(theta)
+ amp2*cos(2*theta)
+ amp3*cos(3*theta)
+ amp4*cos(4*theta)
+ amp5*cos(5*theta);
}
Foam::vector Foam::waveModels::StokesV::U
(
const scalar d,
const scalar kx,
const scalar ky,
const scalar lambda,
const scalar T,
const scalar x,
const scalar y,
const scalar t,
const scalar phase,
const scalar z
) const
{
const scalar k = sqrt(kx*kx + ky*ky);
const scalar a11 = A11(d, k);
const scalar a13 = A13(d, k);
const scalar a15 = A15(d, k);
const scalar a22 = A22(d, k);
const scalar a24 = A24(d, k);
const scalar a33 = A33(d, k);
const scalar a35 = A35(d, k);
const scalar a44 = A44(d, k);
const scalar a55 = A55(d, k);
const scalar pi = mathematical::pi;
const scalar l2 = sqr(lambda);
const scalar l3 = l2*lambda;
const scalar l4 = l3*lambda;
const scalar l5 = l4*lambda;
const scalar a1u = 2*pi/T/k*(lambda*a11 + l3*a13 + l5*a15);
const scalar a2u = 2*2*pi/T/k*(l2*a22 + l4*a24);
const scalar a3u = 3*2*pi/T/k*(l3*a33 + l5*a35);
const scalar a4u = 4*2*pi/T/k*(l4*a44);
const scalar a5u = 5*2*pi/T/k*(l5*a55);
const scalar theta = kx*x + ky*y - 2*pi/T*t + phase;
scalar u =
a1u*cosh(k*z)*cos(theta)
+ a2u*cosh(2.0*k*z)*cos(2.0*(theta))
+ a3u*cosh(3.0*k*z)*cos(3.0*(theta))
+ a4u*cosh(4.0*k*z)*cos(4.0*(theta))
+ a5u*cosh(5.0*k*z)*cos(5.0*(theta));
scalar w =
a1u*sinh(k*z)*sin(theta)
+ a2u*sinh(2.0*k*z)*sin(2.0*(theta))
+ a3u*sinh(3.0*k*z)*sin(3.0*(theta))
+ a4u*sinh(4.0*k*z)*sin(4.0*(theta))
+ a5u*sinh(5.0*k*z)*sin(5.0*(theta));
scalar v = u*sin(waveAngle_);
u *= cos(waveAngle_);
return vector(u, v, w);
}
void Foam::waveModels::StokesV::setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const
{
const scalar waveK = mathematical::twoPi/waveLength_;
const scalar waveKx = waveK*cos(waveAngle_);
const scalar waveKy = waveK*sin(waveAngle_);
forAll(level, paddlei)
{
const scalar eta =
this->eta
(
waterDepthRef_,
waveKx,
waveKy,
lambda_,
wavePeriod_,
xPaddle_[paddlei],
yPaddle_[paddlei],
t,
wavePhase_
);
level[paddlei] = waterDepthRef_ + tCoeff*eta;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::waveModels::StokesV::StokesV
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields
)
:
regularWaveModel(dict, mesh, patch, false),
lambda_(0)
{
if (readFields)
{
read();
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::waveModels::StokesV::~StokesV()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::waveModels::StokesV::read()
{
if (regularWaveModel::read())
{
scalar f1;
scalar f2;
scalar waveK;
initialise
(
waveHeight_,
waterDepthRef_,
wavePeriod_,
waveK,
lambda_,
f1,
f2
);
if (f1 > 0.001 || f2 > 0.001)
{
FatalErrorInFunction
<< "No convergence for Stokes V wave theory" << nl
<< " f1: " << f1 << nl
<< " f2: " << f2 << nl
<< exit(FatalError);
}
waveLength_ = 2.0*mathematical::pi/waveK;
return true;
}
return false;
}
void Foam::waveModels::StokesV::setVelocity
(
const scalar t,
const scalar tCoeff,
const scalarField& level
)
{
const scalar waveK = mathematical::twoPi/waveLength_;
const scalar waveKx = waveK*cos(waveAngle_);
const scalar waveKy = waveK*sin(waveAngle_);
forAll(U_, facei)
{
// Fraction of geometry represented by paddle - to be set
scalar fraction = 1;
// Height - to be set
scalar z = 0;
setPaddlePropeties(level, facei, fraction, z);
if (fraction > 0)
{
const label paddlei = faceToPaddle_[facei];
const vector Uf = U
(
waterDepthRef_,
waveKx,
waveKy,
lambda_,
wavePeriod_,
xPaddle_[paddlei],
yPaddle_[paddlei],
t,
wavePhase_,
z
);
U_[facei] = fraction*Uf*tCoeff;
}
}
}
void Foam::waveModels::StokesV::info(Ostream& os) const
{
regularWaveModel::info(os);
os << " Lambda : " << lambda_ << nl
<< " Wave type : " << waveType() << nl;
}
// ************************************************************************* //

View File

@ -0,0 +1,227 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::waveModels::StokesV
Description
\*---------------------------------------------------------------------------*/
#ifndef waveModels_StokesV_H
#define waveModels_StokesV_H
#include "regularWaveModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
/*---------------------------------------------------------------------------*\
Class StokesV Declaration
\*---------------------------------------------------------------------------*/
class StokesV
:
public regularWaveModel
{
protected:
// Proteced Data
//-
scalar lambda_;
// Protected Member Functions
//-
virtual scalar A11(const scalar h, const scalar k) const;
//-
virtual scalar A13(const scalar h, const scalar k) const;
//-
virtual scalar A15(const scalar h, const scalar k) const;
//-
virtual scalar A22(const scalar h, const scalar k) const;
//-
virtual scalar A24(const scalar h, const scalar k) const;
//-
virtual scalar A33(const scalar h, const scalar k) const;
//-
virtual scalar A35(const scalar h, const scalar k) const;
//-
virtual scalar A44(const scalar h, const scalar k) const;
//-
virtual scalar A55(const scalar h, const scalar k) const;
//-
virtual scalar B22(const scalar h, const scalar k) const;
//-
virtual scalar B24(const scalar h, const scalar k) const;
//-
virtual scalar B33(const scalar h, const scalar k) const;
//-
virtual scalar B33k(const scalar h, const scalar k) const;
//-
virtual scalar B35(const scalar h, const scalar k) const;
//-
virtual scalar B35k(const scalar h, const scalar k) const;
//-
virtual scalar B44(const scalar h, const scalar k) const;
//-
virtual scalar B55(const scalar h, const scalar k) const;
//-
virtual scalar B55k(const scalar h, const scalar k) const;
//-
virtual scalar C1(const scalar h, const scalar k) const;
//-
virtual scalar C1k(const scalar h, const scalar k) const;
//-
virtual scalar C2(const scalar h, const scalar k) const;
//-
virtual scalar C2k(const scalar h, const scalar k) const;
//-
virtual scalar C3(const scalar h, const scalar k) const;
//-
virtual scalar C4(const scalar h, const scalar k) const;
//-
virtual void initialise
(
const scalar H,
const scalar d,
const scalar T,
scalar& kOut,
scalar& LambdaOut,
scalar& f1Out,
scalar& f2Out
) const;
//-
virtual scalar eta
(
const scalar h,
const scalar kx,
const scalar ky,
const scalar lambda,
const scalar T,
const scalar x,
const scalar y,
const scalar t,
const scalar phase
) const;
//-
virtual vector U
(
const scalar d,
const scalar kx,
const scalar ky,
const scalar lambda,
const scalar T,
const scalar x,
const scalar y,
const scalar t,
const scalar phase,
const scalar z
) const;
//- Set the water level
virtual void setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const;
//- Calculate the wave model velocity
virtual void setVelocity
(
const scalar t,
const scalar tCoeff,
const scalarField& level
);
public:
//- Runtime type information
TypeName("StokesV");
//- Constructor
StokesV
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields = true
);
//- Destructor
virtual ~StokesV();
// Public Member Functions
//- Read from dictionary
virtual bool read();
//- Info
virtual void info(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace waveModels
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,152 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
Namespace
Foam::Elliptic
Description
\*---------------------------------------------------------------------------*/
#include "mathematicalConstants.H"
using namespace Foam::constant;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace Elliptic
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void ellipticIntegralsKE(const scalar m, scalar& K, scalar& E)
{
if (m == 0)
{
K = 0.5*mathematical::pi;
E = 0.5*mathematical::pi;
return;
}
scalar a = 1;
scalar g = Foam::sqrt(1 - m);
scalar ga = g*a;
scalar aux = 1;
scalar sum = 2 - m;
while (true)
{
scalar aOld = a;
scalar gOld = g;
ga = gOld*aOld;
a = 0.5*(gOld + aOld);
aux += aux;
sum -= aux*(a*a - ga);
if (mag(aOld - gOld) < SMALL)
{
break;
}
g = sqrt(ga);
}
K = 0.5*mathematical::pi/a;
E = 0.25*mathematical::pi/a*sum;
}
Foam::scalar JacobiAmp(const scalar u, const scalar mIn)
{
static const label ITER = 25;
FixedList<scalar, ITER + 1> a, g, c;
scalar aux, amp;
label n;
const scalar m = mag(mIn);
if (m == 0)
{
return u;
}
if (m == 1)
{
return 2*atan(exp(u)) - mathematical::pi/2;
}
a[0] = 1.0;
g[0] = Foam::sqrt(1.0 - m);
c[0] = Foam::sqrt(m);
aux = 1.0;
for (n = 0; n < ITER; n++)
{
if (mag(a[n] - g[n]) < SMALL)
{
break;
}
aux += aux;
a[n+1] = 0.5*(a[n] + g[n]);
g[n+1] = Foam::sqrt(a[n]*g[n]);
c[n+1] = 0.5*(a[n] - g[n]);
}
amp = aux*a[n]*u;
for (; n > 0; n--)
{
amp = 0.5*(amp + asin(c[n]*sin(amp)/a[n]));
}
return scalar(amp);
}
void JacobiSnCnDn
(
const scalar u,
const scalar m,
scalar& Sn,
scalar& Cn,
scalar& Dn
)
{
const scalar amp = Elliptic::JacobiAmp(u, m);
Sn = sin(amp);
Cn = cos(amp);
Dn = sqrt(1.0 - m*sin(amp)*sin(amp));
return;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Elliptic
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,367 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "cnoidalWaveModel.H"
#include "mathematicalConstants.H"
#include "addToRunTimeSelectionTable.H"
#include "Elliptic.H"
using namespace Foam::constant;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
defineTypeNameAndDebug(cnoidal, 0);
addToRunTimeSelectionTable
(
waveModel,
cnoidal,
patch
);
}
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
void Foam::waveModels::cnoidal::initialise
(
const scalar H,
const scalar d,
const scalar T,
scalar& mOut,
scalar& LOut
) const
{
const scalar mTolerance = 0.0001;
scalar mElliptic = 0.5;
scalar LElliptic = 0;
scalar phaseSpeed = 0;
scalar mError = 0.0;
scalar mMinError = GREAT;
while (mElliptic < 1.0)
{
scalar KElliptic, EElliptic;
Elliptic::ellipticIntegralsKE(mElliptic, KElliptic, EElliptic);
LElliptic = KElliptic*sqrt(16.0*pow3(d)*mElliptic/(3.0*H));
phaseSpeed =
sqrt(mag(g_)*d)
*(1.0 - H/d/2.0 + H/d/mElliptic*(1.0 - 3.0/2.0*EElliptic/KElliptic));
mError = mag(T - LElliptic/phaseSpeed);
if (mError <= mMinError)
{
mOut = mElliptic;
LOut = LElliptic;
mMinError = mError;
}
mElliptic += mTolerance;
}
}
Foam::scalar Foam::waveModels::cnoidal::eta
(
const scalar H,
const scalar m,
const scalar kx,
const scalar ky,
const scalar T,
const scalar x,
const scalar y,
const scalar t
) const
{
scalar K, E;
Elliptic::ellipticIntegralsKE(m, K, E);
const scalar uCnoidal =
K/mathematical::pi*(kx*x + ky*y - 2.0*mathematical::pi*t/T);
scalar sn, cn, dn;
Elliptic::JacobiSnCnDn(uCnoidal, m, sn, cn, dn);
return H*((1.0 - E/K)/m - 1.0 + sqr(cn));
}
Foam::scalar Foam::waveModels::cnoidal::eta1D
(
const scalar H,
const scalar m,
const scalar t,
const scalar T
) const
{
scalar K, E;
Elliptic::ellipticIntegralsKE(m, K, E);
const scalar uCnoidal = -2.0*K*(t/T);
scalar sn, cn, dn;
Elliptic::JacobiSnCnDn(uCnoidal, m, sn, cn, dn);
return H*((1.0 - E/K)/m - 1.0 + sqr(cn));
}
Foam::scalar Foam::waveModels::cnoidal::etaMeanSq
(
const scalar H,
const scalar m,
const scalar T
) const
{
scalar eta = 0;
scalar etaSumSq = 0;
for (int i=0; i<1000; i++)
{
eta = eta1D(H, m, i*T/(1000.0), T);
etaSumSq += eta*eta;
}
etaSumSq /= 1000.0;
return etaSumSq;
}
Foam::vector Foam::waveModels::cnoidal::dEtaDx
(
const scalar H,
const scalar m,
const scalar uCnoidal,
const scalar L,
const scalar K,
const scalar E
) const
{
const scalar dudx = 2.0*K/L;
const scalar dudxx = 2.0*K/L*dudx;
const scalar dudxxx = 2.0*K/L*dudxx;
scalar sn, cn, dn;
Elliptic::JacobiSnCnDn(uCnoidal, m, sn, cn, dn);
scalar d1 = -2.0*H*cn*dn*sn*dudx;
scalar d2 = 2.0*H*(dn*dn*sn*sn - cn*cn*dn*dn + m*cn*cn*sn*sn)*dudxx;
scalar d3 =
8.0*H
*(
cn*sn*dn*dn*dn*(-4.0 - 2.0*m)
+ 4.0*m*cn*sn*sn*sn*dn
- 2.0*m*cn*cn*cn*sn*dn
)
*dudxxx;
return vector(d1, d2, d3);
}
Foam::vector Foam::waveModels::cnoidal::U
(
const scalar H,
const scalar h,
const scalar m,
const scalar kx,
const scalar ky,
const scalar T,
const scalar x,
const scalar y,
const scalar t,
const scalar z
) const
{
scalar K, E;
Elliptic::ellipticIntegralsKE(m, K, E);
const scalar uCnoidal =
K/mathematical::pi*(kx*x + ky*y - 2.0*mathematical::pi*t/T);
const scalar k = sqrt(kx*kx + ky*ky);
const scalar L = 2.0*mathematical::pi/k;
const scalar c = L/T;
const scalar etaCN = eta(H, m, kx, ky, T, x, y, t);
const vector etaX = this->dEtaDx(H, m, uCnoidal, L, K, E);
const scalar etaMS = etaMeanSq(H, m, T);
scalar u =
c*etaCN/h
- c*(etaCN*etaCN/h/h + etaMS*etaMS/h/h)
+ 1.0/2.0*c*h*(1.0/3.0 - z*z/h/h)*etaX[1];
scalar w =
-c*z*(etaX[0]/h*(1.0 - 2.0*etaCN/h) + 1.0/6.0*h*(1.0 - z*z/h/h)*etaX[2]);
scalar v = u*sin(waveAngle_);
u *= cos(waveAngle_);
return vector(u, v, w);
}
void Foam::waveModels::cnoidal::setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const
{
const scalar waveK = mathematical::twoPi/waveLength_;
const scalar waveKx = waveK*cos(waveAngle_);
const scalar waveKy = waveK*sin(waveAngle_);
forAll(level, paddlei)
{
const scalar eta =
this->eta
(
waveHeight_,
m_,
waveKx,
waveKy,
wavePeriod_,
xPaddle_[paddlei],
yPaddle_[paddlei],
t
);
level[paddlei] = waterDepthRef_ + tCoeff*eta;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::waveModels::cnoidal::cnoidal
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields
)
:
regularWaveModel(dict, mesh, patch, false),
m_(0)
{
if (readFields)
{
read();
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::waveModels::cnoidal::~cnoidal()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::waveModels::cnoidal::read()
{
if (regularWaveModel::read())
{
// Initialise m parameter and wavelength
initialise
(
waveHeight_,
waterDepthRef_,
wavePeriod_,
m_,
waveLength_
);
return true;
}
return false;
}
void Foam::waveModels::cnoidal::setVelocity
(
const scalar t,
const scalar tCoeff,
const scalarField& level
)
{
const scalar waveK = mathematical::twoPi/waveLength_;
const scalar waveKx = waveK*cos(waveAngle_);
const scalar waveKy = waveK*sin(waveAngle_);
forAll(U_, facei)
{
// Fraction of geometry represented by paddle - to be set
scalar fraction = 1;
// Height - to be set
scalar z = 0;
setPaddlePropeties(level, facei, fraction, z);
if (fraction > 0)
{
const label paddlei = faceToPaddle_[facei];
const vector Uf = U
(
waveHeight_,
waterDepthRef_,
m_,
waveKx,
waveKy,
wavePeriod_,
xPaddle_[paddlei],
yPaddle_[paddlei],
t,
z
);
U_[facei] = fraction*Uf*tCoeff;
}
}
}
void Foam::waveModels::cnoidal::info(Ostream& os) const
{
regularWaveModel::info(os);
os << " Cnoidal m parameter : " << m_ << nl;
}
// ************************************************************************* //

View File

@ -0,0 +1,174 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015 IH-Cantabria
-------------------------------------------------------------------------------
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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::waveModels::cnoidal
Description
\*---------------------------------------------------------------------------*/
#ifndef waveModels_cnoidal_H
#define waveModels_cnoidal_H
#include "regularWaveModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace waveModels
{
/*---------------------------------------------------------------------------*\
Class cnoidal Declaration
\*---------------------------------------------------------------------------*/
class cnoidal
:
public regularWaveModel
{
protected:
// Protected data
//- `m' coefficient
scalar m_;
// Protected Member Functions
void initialise
(
const scalar H,
const scalar d,
const scalar T,
scalar& mOut,
scalar& LOut
) const;
virtual scalar eta
(
const scalar H,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase
) const;
scalar eta1D
(
const scalar H,
const scalar m,
const scalar t,
const scalar T
) const;
scalar etaMeanSq
(
const scalar H,
const scalar m,
const scalar T
) const;
vector dEtaDx
(
const scalar H,
const scalar m,
const scalar uCnoidal,
const scalar L,
const scalar K,
const scalar E
) const;
virtual vector U
(
const scalar H,
const scalar h,
const scalar Kx,
const scalar x,
const scalar Ky,
const scalar y,
const scalar omega,
const scalar t,
const scalar phase,
const scalar z
) const;
//- Set the water level
virtual void setLevel
(
const scalar t,
const scalar tCoeff,
scalarField& level
) const;
//- Calculate the wave model velocity
virtual void setVelocity
(
const scalar t,
const scalar tCoeff,
const scalarField& level
);
public:
//- Runtime type information
TypeName("cnoidal");
//- Constructor
cnoidal
(
const dictionary& dict,
const fvMesh& mesh,
const polyPatch& patch,
const bool readFields = true
);
//- Destructor
virtual ~cnoidal();
// Public Member Functions
//- Read from dictionary
virtual bool read();
//- Info
virtual void info(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace waveModels
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //