Commit da813d02 authored by Andrew Heather's avatar Andrew Heather

ENH: Refactored waveMaker BC to support piston and flap motions

parent 6f806ad6
......@@ -20,6 +20,7 @@ waveAbsorptionModels/derived/shallowWaterAbsorption/shallowWaterAbsorption.C
derivedFvPatchFields/waveVelocity/waveVelocityFvPatchVectorField.C
derivedFvPatchFields/waveAlpha/waveAlphaFvPatchScalarField.C
derivedPointPatchFields/waveMaker/waveMakerPointPatchVectorField.C
fvOptions/multiphaseMangrovesSource/multiphaseMangrovesSource.C
fvOptions/multiphaseMangrovesTurbulenceModel/multiphaseMangrovesTurbulenceModel.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 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 "waveMakerPistonPointPatchVectorField.H"
#include "mathematicalConstants.H"
#include "pointPatchFields.H"
#include "addToRunTimeSelectionTable.H"
#include "Time.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::waveMakerPistonPointPatchVectorField::
waveMakerPistonPointPatchVectorField
(
const pointPatch& p,
const DimensionedField<vector, pointMesh>& iF
)
:
fixedValuePointPatchField<vector>(p, iF),
initialDepth_(0.0),
wavePeriod_(0.0),
waveHeigth_(0.0),
waveLength_(0.0),
wavePhase_(0.0),
waveNumber_(0.0),
rampTime_(0.0),
g_(Zero),
secondOrder_(false)
{}
Foam::waveMakerPistonPointPatchVectorField::
waveMakerPistonPointPatchVectorField
(
const pointPatch& p,
const DimensionedField<vector, pointMesh>& iF,
const dictionary& dict
)
:
fixedValuePointPatchField<vector>(p, iF, dict),
initialDepth_(readScalar(dict.lookup("initialDepth"))),
wavePeriod_(readScalar(dict.lookup("wavePeriod"))),
waveHeigth_(readScalar(dict.lookup("waveHeigth"))),
waveLength_(readScalar(dict.lookup("waveLength"))),
wavePhase_(readScalar(dict.lookup("wavePhase"))),
waveNumber_(readScalar(dict.lookup("waveNumber"))),
rampTime_(readScalar(dict.lookup("rampTime"))),
g_(dict.lookup("g")),
secondOrder_(dict.lookupOrDefault<bool>("secondOrder",false))
{
if (!dict.found("value"))
{
updateCoeffs();
}
}
Foam::waveMakerPistonPointPatchVectorField::
waveMakerPistonPointPatchVectorField
(
const waveMakerPistonPointPatchVectorField& ptf,
const pointPatch& p,
const DimensionedField<vector, pointMesh>& iF,
const pointPatchFieldMapper& mapper
)
:
fixedValuePointPatchField<vector>(ptf, p, iF, mapper),
initialDepth_(ptf.initialDepth_),
wavePeriod_(ptf.wavePeriod_),
waveHeigth_(ptf.waveHeigth_),
waveLength_(ptf.waveLength_),
wavePhase_(ptf.wavePhase_),
waveNumber_(ptf.waveNumber_),
rampTime_(ptf.rampTime_),
g_(ptf.g_),
secondOrder_(ptf.secondOrder_)
{}
Foam::waveMakerPistonPointPatchVectorField::
waveMakerPistonPointPatchVectorField
(
const waveMakerPistonPointPatchVectorField& ptf,
const DimensionedField<vector, pointMesh>& iF
)
:
fixedValuePointPatchField<vector>(ptf, iF),
initialDepth_(ptf.initialDepth_),
wavePeriod_(ptf.wavePeriod_),
waveHeigth_(ptf.waveHeigth_),
waveLength_(ptf.waveLength_),
wavePhase_(ptf.wavePhase_),
waveNumber_(ptf.waveNumber_),
rampTime_(ptf.rampTime_),
g_(ptf.g_),
secondOrder_(ptf.secondOrder_)
{}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::scalar Foam::waveMakerPistonPointPatchVectorField::waveLength
(
const scalar h,
const scalar T
)
{
const scalar L0 = mag(g_)*T*T/(constant::mathematical::twoPi);
scalar L = L0;
for(int i=1; i<=100; i++)
{
L = L0*tanh(constant::mathematical::twoPi*h/L);
}
return L;
}
Foam::scalar Foam::waveMakerPistonPointPatchVectorField::timeCoeff
(
const scalar t
) const
{
return max(0, min(t/rampTime_, 1));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::waveMakerPistonPointPatchVectorField::updateCoeffs()
{
if (this->updated())
{
return;
}
const polyMesh& mesh = this->internalField().mesh()();
const Time& t = mesh.time();
// Time ramp weight
const scalar tCoeff = timeCoeff(t.value());
vectorField localPoints_ = this->patch().localPoints();
vectorField auxPoints = 0.0*localPoints_;
waveLength_ = waveLength (initialDepth_, wavePeriod_);
const scalar waveK = constant::mathematical::twoPi/waveLength_;
vector waveBoardMotion_(0,0,0);
const scalar sigma_ = (2.0*constant::mathematical::pi) / wavePeriod_;
//first order
if ( secondOrder_ == false)
{
scalar waveBoardStroke_ = (sinh(2.0*waveK*initialDepth_)
+ 2.0*waveK*initialDepth_)
/ (2.0*(cosh(2.0*waveK*initialDepth_)
- 1.0)) * waveHeigth_;
waveBoardMotion_.component(0)= tCoeff*(waveBoardStroke_/2.0)
* sin(sigma_*t.value());
Field<vector>::operator=
(
waveBoardMotion_
);
}
//second order
else if ( secondOrder_ == true)
{
scalar m1_ = (2.0*(cosh(2.0*waveK*initialDepth_)-1.0))
/ (sinh(2.0*waveK*initialDepth_)
+ 2.0*waveK*initialDepth_);
waveBoardMotion_.component(0) = tCoeff * (waveHeigth_/(2.0*m1_)
* sin(sigma_*t.value()) + pow(waveHeigth_,2)
/ (32.0*initialDepth_)*(3.0*cosh(waveK*initialDepth_)
/ pow(sinh(waveK*initialDepth_),3)-2.0/m1_)
* sin(2.0*sigma_*t.value()));
Field<vector>::operator=
(
waveBoardMotion_
);
}
fixedValuePointPatchField<vector>::updateCoeffs();
}
void Foam::waveMakerPistonPointPatchVectorField::write(Ostream& os) const
{
pointPatchField<vector>::write(os);
os.writeEntry("initialDepth", initialDepth_);
os.writeEntry("wavePeriod", wavePeriod_);
os.writeEntry("waveHeigth", waveHeigth_);
os.writeEntry("waveLength", waveLength_);
os.writeEntry("wavePhase", wavePhase_);
os.writeEntry("waveNumber", waveNumber_);
os.writeEntry("rampTime", rampTime_);
os.writeEntry("g", g_);
os.writeEntry("secondOrder", secondOrder_);
writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePointPatchTypeField
(
pointPatchVectorField,
waveMakerPistonPointPatchVectorField
);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 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::waveMakerPistonPointPatchVectorField
Description
Foam::waveMakerPistonPointPatchVectorField
SourceFiles
waveMakerPistonPointPatchVectorField.C
\*---------------------------------------------------------------------------*/
#ifndef waveMakerPistonPointPatchVectorField_H
#define waveMakerPistonPointPatchVectorField_H
#include "fixedValuePointPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class waveMakerPistonPointPatchVectorField Declaration
\*---------------------------------------------------------------------------*/
class waveMakerPistonPointPatchVectorField
:
public fixedValuePointPatchField<vector>
{
// Private data
//inital water depth
scalar initialDepth_;
//wave period
scalar wavePeriod_;
//wave heigth
scalar waveHeigth_;
//wavelength
scalar waveLength_;
//wave phase
scalar wavePhase_;
//wave number
scalar waveNumber_;
//ramp time
scalar rampTime_;
// gravity vector
vector g_;
//on/off second order generation
scalar secondOrder_;
// Protected Member Functions
// Dispersion equation
virtual scalar waveLength(const scalar h, const scalar T);
//- Return the time scaling coefficient
virtual scalar timeCoeff(const scalar t) const;
public:
//- Runtime type information
TypeName("waveMakerPiston");
// Constructors
//- Construct from patch and internal field
waveMakerPistonPointPatchVectorField
(
const pointPatch&,
const DimensionedField<vector, pointMesh>&
);
//- Construct from patch, internal field and dictionary
waveMakerPistonPointPatchVectorField
(
const pointPatch&,
const DimensionedField<vector, pointMesh>&,
const dictionary&
);
//- Construct by mapping given patchField<vector> onto a new patch
waveMakerPistonPointPatchVectorField
(
const waveMakerPistonPointPatchVectorField&,
const pointPatch&,
const DimensionedField<vector, pointMesh>&,
const pointPatchFieldMapper&
);
//- Construct and return a clone
virtual autoPtr<pointPatchField<vector>> clone() const
{
return autoPtr<pointPatchField<vector>>
(
new waveMakerPistonPointPatchVectorField
(
*this
)
);
}
//- Construct as copy setting internal field reference
waveMakerPistonPointPatchVectorField
(
const waveMakerPistonPointPatchVectorField&,
const DimensionedField<vector, pointMesh>&
);
//- Construct and return a clone setting internal field reference
virtual autoPtr<pointPatchField<vector>> clone
(
const DimensionedField<vector, pointMesh>& iF
) const
{
return autoPtr<pointPatchField<vector>>
(
new waveMakerPistonPointPatchVectorField
(
*this,
iF
)
);
}
// Member functions
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018 IH-Cantabria
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -22,20 +22,63 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::waveMakerFlapPointPatchVectorField
Foam::waveMakerPointPatchVectorField
Description
Foam::waveMakerFlapPointPatchVectorField
Point motion boundary condition to generate waves based on either piston
or flap motions.
Based on the reference
\verbatim
Hughes, S.A. (1993).
Physical Models And Laboratory Techniques In Coastal Engineering.
Advanced Series On Ocean Engineering, volume 7
\endverbatim
Usage
Example patch specification
\verbatim
leftwall
{
type waveMaker;
motionType flap;
n (1 0 0);
initialDepth 0.25;
wavePeriod 2.0;
waveHeight 0.06;
wavePhase 0;
rampTime 2.0;
}
\endverbatim
where
\table
Property | Description | Required | Default value
motionType | See motion types below | yes |
x0 | Reference point on patch | yes |
n | Direction of motion | yes |
initialDepth | Initial depth | yes |
wavePeriod | wave period | yes |
waveHeight | Wave height | yes |
wavePhase | wave phase | yes |
rampTime | Time to reach maximum motion | yes |
secondOrder | Second order calculation | no | no
\endtable
Available motion types include:
- piston
- flap
SourceFiles
waveMakerFlapPointPatchVectorField.C
waveMakerPointPatchVectorField.C
\*---------------------------------------------------------------------------*/
#ifndef waveMakerFlapPointPatchVectorField_H
#define waveMakerFlapPointPatchVectorField_H
#ifndef waveMakerPointPatchVectorField_H
#define waveMakerPointPatchVectorField_H
#include "fixedValuePointPatchField.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -43,67 +86,89 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class waveMakerFlapPointPatchVectorField Declaration
Class waveMakerPointPatchVectorField Declaration
\*---------------------------------------------------------------------------*/
class waveMakerFlapPointPatchVectorField
class waveMakerPointPatchVectorField
:
public fixedValuePointPatchField<vector>
{
public:
enum motionTypes
{
piston,
flap
};
//- Names for motion types
static const Enum<motionTypes> motionTypeNames;
// Private data
//inital water depth
//- Motion type
motionTypes motionType_;
//- Patch normal direction
// Note: cannot use patch normal of the initial patch unless it is
// in its neutral position (flap mode)
vector n_;
//- Vertical direction
vector gHat_;
//- Inital water depth
scalar initialDepth_;
//wave period
//- Wave period
scalar wavePeriod_;
//wave heigth
scalar waveHeigth_;
//- Wave height
scalar waveHeight_;
//wavelength
scalar waveLength_;
//wave phase
//- Wave phase
scalar wavePhase_;
//wave number
scalar waveNumber_;
//- Wave length
scalar waveLength_;
//ramp time
//- Ramp time
scalar rampTime_;
// gravity vector
vector g_;
//on/off second order generation
//- On/off second order calculation switch
scalar secondOrder_;
// Protected Member Functions
// Dispersion equation
virtual scalar waveLength(const scalar h, const scalar T);
//- Return the gravitational acceleration
const vector& g();
//- Dispersion equation
virtual scalar waveLength(const scalar h, const scalar T);
//- Return the time scaling coefficient
virtual scalar timeCoeff(const scalar t) const;
virtual scalar timeCoeff(const scalar t) const;
public:
//- Runtime type information
TypeName("waveMakerFlap");
TypeName("waveMaker");
// Constructors
//- Construct from patch and internal field
waveMakerFlapPointPatchVectorField
waveMakerPointPatchVectorField
(
const pointPatch&,
const DimensionedField<vector, pointMesh>&
);
//- Construct from patch, internal field and dictionary
waveMakerFlapPointPatchVectorField
waveMakerPointPatchVectorField
(
const pointPatch&,
const DimensionedField<vector, pointMesh>&,
......@@ -111,9 +176,9 @@ public:
);
//- Construct by mapping given patchField<vector> onto a new patch
waveMakerFlapPointPatchVectorField
waveMakerPointPatchVectorField
(
const waveMakerFlapPointPatchVectorField&,
const waveMakerPointPatchVectorField&,
const pointPatch&,
const DimensionedField<vector, pointMesh>&,
const pointPatchFieldMapper&
......@@ -124,7 +189,7 @@ public:
{
return autoPtr<pointPatchField<vector>>
(
new waveMakerFlapPointPatchVectorField
new waveMakerPointPatchVectorField
(
*this
)
......@@ -132,9 +197,9 @@ public:
}
//- Construct as copy setting internal field reference
waveMakerFlapPointPatchVectorField
waveMakerPointPatchVectorField
(
const waveMakerFlapPointPatchVectorField&,
const waveMakerPointPatchVectorField&,
const DimensionedField<vector, pointMesh>&
);
......@@ -146,7 +211,7 @@ public:
{
return autoPtr<pointPatchField<vector>>
(
new waveMakerFlapPointPatchVectorField
new waveMakerPointPatchVectorField
(
*this,
iF
......
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.1.1 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0";
object p_rgh;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [1 -1 -2 0 0 0 0];
internalField uniform 0;