mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
waves: Added waves library and setWaves utility
This addition allows for theoretical wave models to be utilised for
initialisation and as boundary conditions. Multiple models can be used
simultaneously, each with differing phases and orientations. If multiple
models are used the shapes and velocities are superimposed.
The wave models are specified in the velocity boundary condition. The
phase fraction boundary condition and the set utility both look up the
velocity condition in order to access the wave model. A velocity
boundary may be specified as follows:
inlet
{
type waveVelocity;
origin (0 0 0);
direction (1 0 0);
speed 2;
waves
(
Airy
{
length 300;
amplitude 2.5;
depth 150;
phase 0;
angle 0;
}
);
scale table ((1200 1) (1800 0));
crossScale constant 1;
}
The alpha boundary only requires the type, unless the name of the
velocity field is non-standard, in which case a "U" entry will also be
needed. The setWaves utility does not require a dictionary file; non-
standard field names can be specified as command-line arguments.
Wave models currently available are Airy (1st order) and Stokes2 (second
order). If a depth is specified, and it is not too large, then shallow
terms will be included, otherwise the models assume that the liquid is
deep.
This work was supported by Jan Kaufmann and Jan Oberhagemann at DNV GL.
This commit is contained in:
3
applications/utilities/preProcessing/setWaves/Make/files
Normal file
3
applications/utilities/preProcessing/setWaves/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
setWaves.C
|
||||
|
||||
EXE = $(FOAM_APPBIN)/setWaves
|
||||
@ -0,0 +1,9 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude \
|
||||
-I$(LIB_SRC)/waves/lnInclude
|
||||
|
||||
EXE_LIBS = \
|
||||
-lfiniteVolume \
|
||||
-lmeshTools \
|
||||
-lwaves
|
||||
252
applications/utilities/preProcessing/setWaves/setWaves.C
Normal file
252
applications/utilities/preProcessing/setWaves/setWaves.C
Normal file
@ -0,0 +1,252 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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/>.
|
||||
|
||||
Application
|
||||
setWaves
|
||||
|
||||
Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fvCFD.H"
|
||||
#include "levelSet.H"
|
||||
#include "timeSelector.H"
|
||||
#include "waveAlphaFvPatchScalarField.H"
|
||||
#include "waveVelocityFvPatchVectorField.H"
|
||||
#include "waveSuperposition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
void addWaves
|
||||
(
|
||||
const waveSuperposition& waves,
|
||||
const bool liquid,
|
||||
volScalarField& alpha,
|
||||
volVectorField& U
|
||||
)
|
||||
{
|
||||
const scalar t = alpha.time().value();;
|
||||
const fvMesh& mesh = alpha.mesh();
|
||||
const pointMesh& pMesh = pointMesh::New(mesh);
|
||||
|
||||
// Height fields
|
||||
const scalarField heightC(waves.height(t, mesh.cellCentres()));
|
||||
const scalarField heightP(waves.height(t, mesh.points()));
|
||||
|
||||
// Velocity fields
|
||||
const DimensionedField<vector, volMesh>
|
||||
UGasC
|
||||
(
|
||||
IOobject("UGasC", mesh.time().timeName(), mesh),
|
||||
mesh,
|
||||
dimVelocity,
|
||||
waves.UGas(t, mesh.cellCentres())
|
||||
);
|
||||
const DimensionedField<vector, pointMesh>
|
||||
UGasP
|
||||
(
|
||||
IOobject("UGasP", mesh.time().timeName(), mesh),
|
||||
pMesh,
|
||||
dimVelocity,
|
||||
waves.UGas(t, mesh.points())
|
||||
);
|
||||
const DimensionedField<vector, volMesh>
|
||||
ULiquidC
|
||||
(
|
||||
IOobject("ULiquidC", mesh.time().timeName(), mesh),
|
||||
mesh,
|
||||
dimVelocity,
|
||||
waves.ULiquid(t, mesh.cellCentres())
|
||||
);
|
||||
const DimensionedField<vector, pointMesh>
|
||||
ULiquidP
|
||||
(
|
||||
IOobject("ULiquidP", mesh.time().timeName(), mesh),
|
||||
pMesh,
|
||||
dimVelocity,
|
||||
waves.ULiquid(t, mesh.points())
|
||||
);
|
||||
|
||||
// Convert from the level set to volume-averaged fields and sum up
|
||||
alpha.ref() += levelSetFraction(mesh, heightC, heightP, !liquid);
|
||||
U.ref() +=
|
||||
levelSetAverage
|
||||
(
|
||||
mesh,
|
||||
heightC,
|
||||
heightP,
|
||||
UGasC,
|
||||
UGasP,
|
||||
ULiquidC,
|
||||
ULiquidP
|
||||
);
|
||||
|
||||
// Now set the boundary fields
|
||||
forAll(alpha.boundaryField(), patchi)
|
||||
{
|
||||
fvPatchScalarField& alphap = alpha.boundaryFieldRef()[patchi];
|
||||
fvPatchVectorField& Up = U.boundaryFieldRef()[patchi];
|
||||
|
||||
const fvPatch& patch = alphap.patch();
|
||||
|
||||
// Height fields
|
||||
const scalarField heightF(waves.height(t, patch.Cf()));
|
||||
const scalarField heightP(waves.height(t, patch.patch().localPoints()));
|
||||
|
||||
// Velocity fields
|
||||
const vectorField UGasC(waves.UGas(t, mesh.cellCentres()));
|
||||
const vectorField UGasP(waves.UGas(t, mesh.points()));
|
||||
const vectorField ULiquidC(waves.ULiquid(t, mesh.cellCentres()));
|
||||
const vectorField ULiquidP(waves.ULiquid(t, mesh.points()));
|
||||
|
||||
alphap == alphap + levelSetFraction(patch, heightF, heightP, !liquid);
|
||||
Up == Up
|
||||
+ levelSetAverage
|
||||
(
|
||||
patch,
|
||||
heightC,
|
||||
heightP,
|
||||
UGasC,
|
||||
UGasP,
|
||||
ULiquidC,
|
||||
ULiquidP
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
timeSelector::addOptions(false, false);
|
||||
|
||||
Foam::argList::addOption
|
||||
(
|
||||
"U",
|
||||
"name",
|
||||
"name of the velocity field, default is \"U\""
|
||||
);
|
||||
|
||||
Foam::argList::addOption
|
||||
(
|
||||
"alpha",
|
||||
"name",
|
||||
"name of the volume fraction field, default is \"alpha\""
|
||||
);
|
||||
|
||||
#include "setRootCase.H"
|
||||
#include "createTime.H"
|
||||
|
||||
instantList timeDirs = timeSelector::selectIfPresent(runTime, args);
|
||||
|
||||
#include "createMesh.H"
|
||||
#include "readGravitationalAcceleration.H"
|
||||
|
||||
forAll(timeDirs, timeI)
|
||||
{
|
||||
runTime.setTime(timeDirs[timeI], timeI);
|
||||
|
||||
Info<< "Time = " << runTime.timeName() << nl << endl;
|
||||
|
||||
mesh.readUpdate();
|
||||
|
||||
// Read the phase fraction and velocity fields
|
||||
volScalarField alpha
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
args.optionFound("alpha") ? args["alpha"] : "alpha",
|
||||
runTime.timeName(),
|
||||
mesh,
|
||||
IOobject::MUST_READ
|
||||
),
|
||||
mesh
|
||||
);
|
||||
volVectorField U
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
args.optionFound("U") ? args["U"] : "U",
|
||||
runTime.timeName(),
|
||||
mesh,
|
||||
IOobject::MUST_READ
|
||||
),
|
||||
mesh
|
||||
);
|
||||
|
||||
// Zero the fields
|
||||
alpha = dimensionedScalar("0", alpha.dimensions(), 0);
|
||||
U = dimensionedVector("0", U.dimensions(), vector::zero);
|
||||
forAll(alpha.boundaryField(), patchi)
|
||||
{
|
||||
alpha.boundaryFieldRef()[patchi] == 0;
|
||||
U.boundaryFieldRef()[patchi] == vector::zero;
|
||||
}
|
||||
|
||||
// Loop the patches, looking for wave conditions
|
||||
forAll(alpha.boundaryField(), patchi)
|
||||
{
|
||||
const fvPatchScalarField& alphap = alpha.boundaryField()[patchi];
|
||||
const fvPatchVectorField& Up = U.boundaryField()[patchi];
|
||||
|
||||
const bool isWave = isA<waveAlphaFvPatchScalarField>(alphap);
|
||||
|
||||
if (isA<waveVelocityFvPatchVectorField>(Up) != isWave)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "The alpha condition on patch " << Up.patch().name()
|
||||
<< " is " << alphap.type() << " and the velocity condition"
|
||||
<< " is " << Up.type() << ". Wave boundary conditions must"
|
||||
<< " be set in pairs. If the alpha condition is "
|
||||
<< waveAlphaFvPatchScalarField::typeName
|
||||
<< " then the velocity condition must be "
|
||||
<< waveVelocityFvPatchVectorField::typeName
|
||||
<< " and vice-versa." << exit(FatalError);
|
||||
}
|
||||
|
||||
if (isWave)
|
||||
{
|
||||
Info<< "Adding waves from patch " << Up.patch().name() << endl;
|
||||
addWaves
|
||||
(
|
||||
refCast<const waveVelocityFvPatchVectorField>(Up).waves(),
|
||||
refCast<const waveAlphaFvPatchScalarField>(alphap).liquid(),
|
||||
alpha,
|
||||
U
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
Info<< "Writing " << alpha.name() << nl;
|
||||
alpha.write();
|
||||
Info<< "Writing " << U.name() << nl << endl;
|
||||
U.write();
|
||||
}
|
||||
|
||||
Info<< "End\n" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -78,6 +78,7 @@ functionObjects/Allwmake $targetType $*
|
||||
wmake $targetType sixDoFRigidBodyMotion
|
||||
wmake $targetType rigidBodyDynamics
|
||||
wmake $targetType rigidBodyMeshMotion
|
||||
wmake $targetType waves
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@ -39,23 +39,29 @@ Foam::levelSetFraction
|
||||
const bool above
|
||||
)
|
||||
{
|
||||
DimensionedField<scalar, volMesh> sum
|
||||
tmp<DimensionedField<scalar, volMesh>> tResult
|
||||
(
|
||||
IOobject
|
||||
new DimensionedField<scalar, volMesh>
|
||||
(
|
||||
"levelSetIntegral",
|
||||
mesh.time().timeName(),
|
||||
mesh
|
||||
),
|
||||
mesh,
|
||||
dimensionedScalar("0", dimVolume, 0)
|
||||
IOobject
|
||||
(
|
||||
"levelSetFraction",
|
||||
mesh.time().timeName(),
|
||||
mesh
|
||||
),
|
||||
mesh,
|
||||
dimensionedScalar("0", dimless, 0)
|
||||
)
|
||||
);
|
||||
DimensionedField<scalar, volMesh>& result = tResult.ref();
|
||||
|
||||
forAll(sum, cI)
|
||||
forAll(result, cI)
|
||||
{
|
||||
const List<tetIndices> cellTetIs =
|
||||
polyMeshTetDecomposition::cellTetIndices(mesh, cI);
|
||||
|
||||
scalar v = 0, r = 0;
|
||||
|
||||
forAll(cellTetIs, cellTetI)
|
||||
{
|
||||
const tetIndices& tetIs = cellTetIs[cellTetI];
|
||||
@ -82,18 +88,22 @@ Foam::levelSetFraction
|
||||
levelP[pIB]
|
||||
};
|
||||
|
||||
v += cut::volumeOp()(tet);
|
||||
|
||||
if (above)
|
||||
{
|
||||
sum[cI] += tetCut(tet, level, cut::volumeOp(), cut::noOp());
|
||||
r += tetCut(tet, level, cut::volumeOp(), cut::noOp());
|
||||
}
|
||||
else
|
||||
{
|
||||
sum[cI] += tetCut(tet, level, cut::noOp(), cut::volumeOp());
|
||||
r += tetCut(tet, level, cut::noOp(), cut::volumeOp());
|
||||
}
|
||||
}
|
||||
|
||||
result[cI] = r/v;
|
||||
}
|
||||
|
||||
return sum/mesh.V();
|
||||
return tResult;
|
||||
}
|
||||
|
||||
|
||||
@ -105,12 +115,15 @@ Foam::tmp<Foam::scalarField> Foam::levelSetFraction
|
||||
const bool above
|
||||
)
|
||||
{
|
||||
vectorField sum(patch.size(), vector::zero);
|
||||
tmp<scalarField> tResult(new scalarField(patch.size(), 0));
|
||||
scalarField& result = tResult.ref();
|
||||
|
||||
forAll(sum, fI)
|
||||
forAll(result, fI)
|
||||
{
|
||||
const face& f = patch.patch().localFaces()[fI];
|
||||
|
||||
vector a = vector::zero, r = vector::zero;
|
||||
|
||||
for(label eI = 0; eI < f.size(); ++ eI)
|
||||
{
|
||||
const edge e = f.faceEdge(eI);
|
||||
@ -130,18 +143,22 @@ Foam::tmp<Foam::scalarField> Foam::levelSetFraction
|
||||
levelP[e[1]]
|
||||
};
|
||||
|
||||
a += cut::areaOp()(tri);
|
||||
|
||||
if (above)
|
||||
{
|
||||
sum[fI] += triCut(tri, level, cut::areaOp(), cut::noOp());
|
||||
r += triCut(tri, level, cut::areaOp(), cut::noOp());
|
||||
}
|
||||
else
|
||||
{
|
||||
sum[fI] += triCut(tri, level, cut::noOp(), cut::areaOp());
|
||||
r += triCut(tri, level, cut::noOp(), cut::areaOp());
|
||||
}
|
||||
}
|
||||
|
||||
result[fI] = a/magSqr(a) & r;
|
||||
}
|
||||
|
||||
return sum & patch.Sf()/sqr(patch.magSf());
|
||||
return tResult;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -42,28 +42,30 @@ Foam::tmp<Foam::DimensionedField<Type, Foam::volMesh>> Foam::levelSetAverage
|
||||
const DimensionedField<Type, pointMesh>& negativeP
|
||||
)
|
||||
{
|
||||
DimensionedField<Type, volMesh> sum
|
||||
tmp<DimensionedField<Type, volMesh>> tResult
|
||||
(
|
||||
IOobject
|
||||
new DimensionedField<Type, volMesh>
|
||||
(
|
||||
"levelSetIntegral",
|
||||
mesh.time().timeName(),
|
||||
mesh
|
||||
),
|
||||
mesh,
|
||||
dimensioned<Type>
|
||||
(
|
||||
"0",
|
||||
positiveC.dimensions()*dimVolume,
|
||||
pTraits<Type>::zero
|
||||
IOobject
|
||||
(
|
||||
positiveC.name() + ":levelSetAverage",
|
||||
mesh.time().timeName(),
|
||||
mesh
|
||||
),
|
||||
mesh,
|
||||
dimensioned<Type>("0", positiveC.dimensions(), Zero)
|
||||
)
|
||||
);
|
||||
DimensionedField<Type, volMesh>& result = tResult.ref();
|
||||
|
||||
forAll(sum, cI)
|
||||
forAll(result, cI)
|
||||
{
|
||||
const List<tetIndices> cellTetIs =
|
||||
polyMeshTetDecomposition::cellTetIndices(mesh, cI);
|
||||
|
||||
scalar v = 0;
|
||||
Type r = Zero;
|
||||
|
||||
forAll(cellTetIs, cellTetI)
|
||||
{
|
||||
const tetIndices& tetIs = cellTetIs[cellTetI];
|
||||
@ -106,11 +108,15 @@ Foam::tmp<Foam::DimensionedField<Type, Foam::volMesh>> Foam::levelSetAverage
|
||||
negativeP[pIB]
|
||||
});
|
||||
|
||||
sum[cI] += tetCut(tet, level, positive, negative);
|
||||
v += cut::volumeOp()(tet);
|
||||
|
||||
r += tetCut(tet, level, positive, negative);
|
||||
}
|
||||
|
||||
result[cI] = r/v;
|
||||
}
|
||||
|
||||
return sum/mesh.V();
|
||||
return tResult;
|
||||
}
|
||||
|
||||
|
||||
@ -128,12 +134,16 @@ Foam::tmp<Foam::Field<Type>> Foam::levelSetAverage
|
||||
{
|
||||
typedef typename outerProduct<Type, vector>::type sumType;
|
||||
|
||||
Field<sumType> sum(patch.size(), pTraits<sumType>::zero);
|
||||
tmp<Field<Type>> tResult(new Field<Type>(patch.size(), Zero));
|
||||
Field<Type>& result = tResult.ref();
|
||||
|
||||
forAll(sum, fI)
|
||||
forAll(result, fI)
|
||||
{
|
||||
const face& f = patch.patch().localFaces()[fI];
|
||||
|
||||
vector a = vector::zero;
|
||||
sumType r = Zero;
|
||||
|
||||
for(label eI = 0; eI < f.size(); ++ eI)
|
||||
{
|
||||
const edge e = f.faceEdge(eI);
|
||||
@ -167,11 +177,15 @@ Foam::tmp<Foam::Field<Type>> Foam::levelSetAverage
|
||||
negativeP[e[1]]
|
||||
});
|
||||
|
||||
sum[fI] += triCut(tri, level, positive, negative);
|
||||
a += cut::areaOp()(tri);
|
||||
|
||||
r += triCut(tri, level, positive, negative);
|
||||
}
|
||||
|
||||
result[fI] = a/magSqr(a) & r;
|
||||
}
|
||||
|
||||
return patch.Sf()/sqr(patch.magSf()) & sum;
|
||||
return tResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
11
src/waves/Make/files
Normal file
11
src/waves/Make/files
Normal file
@ -0,0 +1,11 @@
|
||||
waveModels/waveModel/waveModel.C
|
||||
waveModels/waveModel/newWaveModel.C
|
||||
waveModels/Airy/Airy.C
|
||||
waveModels/Stokes2/Stokes2.C
|
||||
|
||||
waveSuperposition/waveSuperposition.C
|
||||
|
||||
derivedFvPatchFields/waveAlpha/waveAlphaFvPatchScalarField.C
|
||||
derivedFvPatchFields/waveVelocity/waveVelocityFvPatchVectorField.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/libwaves
|
||||
7
src/waves/Make/options
Normal file
7
src/waves/Make/options
Normal file
@ -0,0 +1,7 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude
|
||||
|
||||
LIB_LIBS = \
|
||||
-lfiniteVolume \
|
||||
-lmeshTools
|
||||
@ -0,0 +1,187 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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 "waveAlphaFvPatchScalarField.H"
|
||||
#include "waveVelocityFvPatchVectorField.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "levelSet.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "volFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::waveAlphaFvPatchScalarField::alpha() const
|
||||
{
|
||||
const scalar t = db().time().timeOutputValue();
|
||||
|
||||
const waveVelocityFvPatchVectorField& Up =
|
||||
refCast<const waveVelocityFvPatchVectorField>
|
||||
(
|
||||
patch().lookupPatchField<volVectorField, scalar>(UName_)
|
||||
);
|
||||
const waveSuperposition& waves = Up.waves();
|
||||
|
||||
return
|
||||
levelSetFraction
|
||||
(
|
||||
patch(),
|
||||
waves.height(t, patch().Cf()),
|
||||
waves.height(t, patch().patch().localPoints()),
|
||||
!liquid_
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveAlphaFvPatchScalarField::waveAlphaFvPatchScalarField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<scalar, volMesh>& iF
|
||||
)
|
||||
:
|
||||
mixedFvPatchScalarField(p, iF),
|
||||
UName_("U"),
|
||||
liquid_(true),
|
||||
inletOutlet_(true)
|
||||
{
|
||||
refValue() = Zero;
|
||||
refGrad() = Zero;
|
||||
valueFraction() = 0;
|
||||
}
|
||||
|
||||
|
||||
Foam::waveAlphaFvPatchScalarField::waveAlphaFvPatchScalarField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<scalar, volMesh>& iF,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
mixedFvPatchScalarField(p, iF),
|
||||
UName_(dict.lookupOrDefault<word>("U", "U")),
|
||||
liquid_(dict.lookupOrDefault<bool>("liquid", true)),
|
||||
inletOutlet_(dict.lookupOrDefault<bool>("inletOutlet", true))
|
||||
{
|
||||
if (dict.found("value"))
|
||||
{
|
||||
fvPatchScalarField::operator=(scalarField("value", dict, p.size()));
|
||||
}
|
||||
else
|
||||
{
|
||||
fvPatchScalarField::operator=(patchInternalField());
|
||||
}
|
||||
|
||||
refValue() = *this;
|
||||
refGrad() = Zero;
|
||||
valueFraction() = 0;
|
||||
}
|
||||
|
||||
|
||||
Foam::waveAlphaFvPatchScalarField::waveAlphaFvPatchScalarField
|
||||
(
|
||||
const waveAlphaFvPatchScalarField& ptf,
|
||||
const fvPatch& p,
|
||||
const DimensionedField<scalar, volMesh>& iF,
|
||||
const fvPatchFieldMapper& mapper
|
||||
)
|
||||
:
|
||||
mixedFvPatchScalarField(ptf, p, iF, mapper),
|
||||
UName_(ptf.UName_),
|
||||
liquid_(ptf.liquid_),
|
||||
inletOutlet_(ptf.inletOutlet_)
|
||||
{}
|
||||
|
||||
|
||||
Foam::waveAlphaFvPatchScalarField::waveAlphaFvPatchScalarField
|
||||
(
|
||||
const waveAlphaFvPatchScalarField& ptf
|
||||
)
|
||||
:
|
||||
mixedFvPatchScalarField(ptf),
|
||||
UName_(ptf.UName_),
|
||||
liquid_(ptf.liquid_),
|
||||
inletOutlet_(ptf.inletOutlet_)
|
||||
{}
|
||||
|
||||
Foam::waveAlphaFvPatchScalarField::waveAlphaFvPatchScalarField
|
||||
(
|
||||
const waveAlphaFvPatchScalarField& ptf,
|
||||
const DimensionedField<scalar, volMesh>& iF
|
||||
)
|
||||
:
|
||||
mixedFvPatchScalarField(ptf, iF),
|
||||
UName_(ptf.UName_),
|
||||
liquid_(ptf.liquid_),
|
||||
inletOutlet_(ptf.inletOutlet_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::waveAlphaFvPatchScalarField::updateCoeffs()
|
||||
{
|
||||
if (updated())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
refValue() = alpha();
|
||||
|
||||
if (inletOutlet_)
|
||||
{
|
||||
const scalarField& phip =
|
||||
patch().lookupPatchField<surfaceScalarField, scalar>("phi");
|
||||
|
||||
valueFraction() = 1 - pos(phip);
|
||||
}
|
||||
else
|
||||
{
|
||||
valueFraction() = 1;
|
||||
}
|
||||
|
||||
mixedFvPatchScalarField::updateCoeffs();
|
||||
}
|
||||
|
||||
|
||||
void Foam::waveAlphaFvPatchScalarField::write
|
||||
(
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
mixedFvPatchScalarField::write(os);
|
||||
writeEntryIfDifferent<word>(os, "U", "U", UName_);
|
||||
writeEntryIfDifferent<bool>(os, "inletOutlet", true, inletOutlet_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Build Macro Function * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
makePatchTypeField(fvPatchScalarField, waveAlphaFvPatchScalarField);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,196 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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::waveAlphaFvPatchScalarField
|
||||
|
||||
Group
|
||||
grpGenericBoundaryConditions
|
||||
|
||||
Description
|
||||
This boundary condition provides a waveAlpha condition. This sets the phase
|
||||
fraction to that specified by a superposition of wave models. All the
|
||||
parameters are looked up from the corresponding velocity condition.
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Req'd? | Default
|
||||
U | name of the velocity field | no | U
|
||||
liquid | is the alpha field that of the liquid | no | true
|
||||
inletOutlet | does the condition behave like inletOutlet | no | true
|
||||
\endtable
|
||||
|
||||
Example of the boundary condition specification:
|
||||
\verbatim
|
||||
<patchName>
|
||||
{
|
||||
type waveAlpha;
|
||||
U U;
|
||||
inletOutlet true;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
waveAlphaFvPatchScalarField.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef waveAlphaFvPatchScalarField_H
|
||||
#define waveAlphaFvPatchScalarField_H
|
||||
|
||||
#include "mixedFvPatchFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class waveAlphaFvPatchScalarField Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class waveAlphaFvPatchScalarField
|
||||
:
|
||||
public mixedFvPatchScalarField
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Name of the velocity field
|
||||
word UName_;
|
||||
|
||||
//- Is this alpha field that of the liquid under the wave?
|
||||
const bool liquid_;
|
||||
|
||||
//- Act as an inlet/outlet patch? If false, the alpha field will be set
|
||||
// by the wave model even during outflow. This may apply the wave model
|
||||
// more accurately, but it might also be unstable. If true, the alpha
|
||||
// boundary condition will be zero gradient when the flow reverses, as
|
||||
// is usual.
|
||||
const bool inletOutlet_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Return the current modelled phase fraction field
|
||||
tmp<scalarField> alpha() const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("waveAlpha");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from patch and internal field
|
||||
waveAlphaFvPatchScalarField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<scalar, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct from patch, internal field and dictionary
|
||||
waveAlphaFvPatchScalarField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<scalar, volMesh>&,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
//- Construct by mapping given mixedTypeFvPatchField onto a new patch
|
||||
waveAlphaFvPatchScalarField
|
||||
(
|
||||
const waveAlphaFvPatchScalarField&,
|
||||
const fvPatch&,
|
||||
const DimensionedField<scalar, volMesh>&,
|
||||
const fvPatchFieldMapper&
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
waveAlphaFvPatchScalarField
|
||||
(
|
||||
const waveAlphaFvPatchScalarField&
|
||||
);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<fvPatchScalarField> clone() const
|
||||
{
|
||||
return tmp<fvPatchScalarField>
|
||||
(
|
||||
new waveAlphaFvPatchScalarField(*this)
|
||||
);
|
||||
}
|
||||
|
||||
//- Construct as copy setting internal field reference
|
||||
waveAlphaFvPatchScalarField
|
||||
(
|
||||
const waveAlphaFvPatchScalarField&,
|
||||
const DimensionedField<scalar, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct and return a clone setting internal field reference
|
||||
virtual tmp<fvPatchScalarField> clone
|
||||
(
|
||||
const DimensionedField<scalar, volMesh>& iF
|
||||
) const
|
||||
{
|
||||
return tmp<fvPatchScalarField>
|
||||
(
|
||||
new waveAlphaFvPatchScalarField(*this, iF)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Access the liquid flag
|
||||
bool liquid() const
|
||||
{
|
||||
return liquid_;
|
||||
}
|
||||
|
||||
|
||||
// Evaluation functions
|
||||
|
||||
//- Update the coefficients associated with the patch field
|
||||
virtual void updateCoeffs();
|
||||
|
||||
|
||||
//- Write
|
||||
virtual void write(Ostream&) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,173 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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 "waveVelocityFvPatchVectorField.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "levelSet.H"
|
||||
#include "surfaceFields.H"
|
||||
#include "volFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::tmp<Foam::vectorField> Foam::waveVelocityFvPatchVectorField::U() const
|
||||
{
|
||||
const scalar t = db().time().timeOutputValue();
|
||||
|
||||
return
|
||||
levelSetAverage
|
||||
(
|
||||
patch(),
|
||||
waves_.height(t, patch().Cf()),
|
||||
waves_.height(t, patch().patch().localPoints()),
|
||||
waves_.UGas(t, patch().Cf())(),
|
||||
waves_.UGas(t, patch().patch().localPoints())(),
|
||||
waves_.ULiquid(t, patch().Cf())(),
|
||||
waves_.ULiquid(t, patch().patch().localPoints())()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveVelocityFvPatchVectorField::waveVelocityFvPatchVectorField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<vector, volMesh>& iF
|
||||
)
|
||||
:
|
||||
directionMixedFvPatchVectorField(p, iF),
|
||||
waves_(db())
|
||||
{
|
||||
refValue() = Zero;
|
||||
refGrad() = Zero;
|
||||
valueFraction() = Zero;
|
||||
}
|
||||
|
||||
|
||||
Foam::waveVelocityFvPatchVectorField::waveVelocityFvPatchVectorField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<vector, volMesh>& iF,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
directionMixedFvPatchVectorField(p, iF),
|
||||
waves_(db(), dict)
|
||||
{
|
||||
if (dict.found("value"))
|
||||
{
|
||||
fvPatchVectorField::operator=(vectorField("value", dict, p.size()));
|
||||
}
|
||||
else
|
||||
{
|
||||
fvPatchVectorField::operator=(patchInternalField());
|
||||
}
|
||||
|
||||
refValue() = *this;
|
||||
refGrad() = Zero;
|
||||
valueFraction() = Zero;
|
||||
}
|
||||
|
||||
|
||||
Foam::waveVelocityFvPatchVectorField::waveVelocityFvPatchVectorField
|
||||
(
|
||||
const waveVelocityFvPatchVectorField& ptf,
|
||||
const fvPatch& p,
|
||||
const DimensionedField<vector, volMesh>& iF,
|
||||
const fvPatchFieldMapper& mapper
|
||||
)
|
||||
:
|
||||
directionMixedFvPatchVectorField(ptf, p, iF, mapper),
|
||||
waves_(ptf.waves_)
|
||||
{}
|
||||
|
||||
|
||||
Foam::waveVelocityFvPatchVectorField::waveVelocityFvPatchVectorField
|
||||
(
|
||||
const waveVelocityFvPatchVectorField& ptf
|
||||
)
|
||||
:
|
||||
directionMixedFvPatchVectorField(ptf),
|
||||
waves_(ptf.waves_)
|
||||
{}
|
||||
|
||||
|
||||
Foam::waveVelocityFvPatchVectorField::waveVelocityFvPatchVectorField
|
||||
(
|
||||
const waveVelocityFvPatchVectorField& ptf,
|
||||
const DimensionedField<vector, volMesh>& iF
|
||||
)
|
||||
:
|
||||
directionMixedFvPatchVectorField(ptf, iF),
|
||||
waves_(ptf.waves_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::waveVelocityFvPatchVectorField::updateCoeffs()
|
||||
{
|
||||
if (updated())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
refValue() = U();
|
||||
|
||||
const scalarField& phip =
|
||||
patch().lookupPatchField<surfaceScalarField, scalar>("phi");
|
||||
|
||||
const symmTensorField nnp(sqr(patch().nf()));
|
||||
|
||||
// Fix all components if inflow, just normal if outflow
|
||||
valueFraction() = (1 - pos(phip))*I + pos(phip)*nnp;
|
||||
|
||||
directionMixedFvPatchVectorField::updateCoeffs();
|
||||
directionMixedFvPatchVectorField::evaluate();
|
||||
}
|
||||
|
||||
|
||||
void Foam::waveVelocityFvPatchVectorField::write
|
||||
(
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
directionMixedFvPatchVectorField::write(os);
|
||||
waves_.write(os);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Build Macro Function * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
makePatchTypeField
|
||||
(
|
||||
fvPatchVectorField,
|
||||
waveVelocityFvPatchVectorField
|
||||
);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,211 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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::waveVelocityFvPatchVectorField
|
||||
|
||||
Group
|
||||
grpGenericBoundaryConditions
|
||||
|
||||
Description
|
||||
This boundary condition provides a waveVelocity condition. This sets the
|
||||
velocity to that specified by a superposition of wave models. The
|
||||
corresponding phase fraction condition looks this condition up and re-uses
|
||||
the wave modelling.
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Req'd? | Default
|
||||
origin | origin of the wave coordinate system | yes |
|
||||
direction | direction of the mean flow | yes |
|
||||
speed | speed of the mean flow | yes |
|
||||
waves | list of wave models to superimpose | yes |
|
||||
scale | scale factor along the mean flow direction | no | None
|
||||
crossScale | scale factor across the mean flow direction | no | None
|
||||
\endtable
|
||||
|
||||
Example of the boundary condition specification:
|
||||
\verbatim
|
||||
<patchName>
|
||||
{
|
||||
type waveVelocity;
|
||||
origin (0 25 0);
|
||||
direction (1 0 0);
|
||||
speed 2;
|
||||
waves
|
||||
(
|
||||
Airy
|
||||
{
|
||||
length 40;
|
||||
amplitude 0.5;
|
||||
phase 0;
|
||||
angle 0;
|
||||
}
|
||||
Airy
|
||||
{
|
||||
length 20;
|
||||
amplitude 0.25;
|
||||
phase 1.5708;
|
||||
angle 0;
|
||||
}
|
||||
);
|
||||
scale table ((100 1) (200 0));
|
||||
crossScale constant 1;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
waveVelocityFvPatchVectorField.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef waveVelocityFvPatchVectorField_H
|
||||
#define waveVelocityFvPatchVectorField_H
|
||||
|
||||
#include "directionMixedFvPatchFields.H"
|
||||
#include "waveSuperposition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class waveVelocityFvPatchVectorField Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class waveVelocityFvPatchVectorField
|
||||
:
|
||||
public directionMixedFvPatchVectorField
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Wave superposition
|
||||
const waveSuperposition waves_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Return the current modelled velocity field
|
||||
tmp<vectorField> U() const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("waveVelocity");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from patch and internal field
|
||||
waveVelocityFvPatchVectorField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<vector, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct from patch, internal field and dictionary
|
||||
waveVelocityFvPatchVectorField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<vector, volMesh>&,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
//- Construct by mapping given mixedTypeFvPatchField onto a new patch
|
||||
waveVelocityFvPatchVectorField
|
||||
(
|
||||
const waveVelocityFvPatchVectorField&,
|
||||
const fvPatch&,
|
||||
const DimensionedField<vector, volMesh>&,
|
||||
const fvPatchFieldMapper&
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
waveVelocityFvPatchVectorField
|
||||
(
|
||||
const waveVelocityFvPatchVectorField&
|
||||
);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<fvPatchVectorField> clone() const
|
||||
{
|
||||
return tmp<fvPatchVectorField>
|
||||
(
|
||||
new waveVelocityFvPatchVectorField(*this)
|
||||
);
|
||||
}
|
||||
|
||||
//- Construct as copy setting internal field reference
|
||||
waveVelocityFvPatchVectorField
|
||||
(
|
||||
const waveVelocityFvPatchVectorField&,
|
||||
const DimensionedField<vector, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct and return a clone setting internal field reference
|
||||
virtual tmp<fvPatchVectorField> clone
|
||||
(
|
||||
const DimensionedField<vector, volMesh>& iF
|
||||
) const
|
||||
{
|
||||
return tmp<fvPatchVectorField>
|
||||
(
|
||||
new waveVelocityFvPatchVectorField(*this, iF)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Access the wave models
|
||||
const waveSuperposition& waves() const
|
||||
{
|
||||
return waves_;
|
||||
}
|
||||
|
||||
|
||||
// Evaluation functions
|
||||
|
||||
//- Update the coefficients associated with the patch field
|
||||
virtual void updateCoeffs();
|
||||
|
||||
|
||||
//- Write
|
||||
virtual void write(Ostream&) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
99
src/waves/waveModels/Airy/Airy.C
Normal file
99
src/waves/waveModels/Airy/Airy.C
Normal file
@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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 "Airy.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace waveModels
|
||||
{
|
||||
defineTypeNameAndDebug(Airy, 0);
|
||||
addToRunTimeSelectionTable(waveModel, Airy, objectRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveModels::Airy::Airy
|
||||
(
|
||||
const objectRegistry& db,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
waveModel(db, dict)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveModels::Airy::~Airy()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::waveModels::Airy::elevation
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const scalarField& x
|
||||
) const
|
||||
{
|
||||
return amplitude(t)*cos(angle(t, u, x));
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::vector2DField> Foam::waveModels::Airy::velocity
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const vector2DField& xz
|
||||
) const
|
||||
{
|
||||
const scalarField x(xz.component(0));
|
||||
const scalarField z(xz.component(1));
|
||||
|
||||
const scalarField phi(angle(t, u, x));
|
||||
const scalarField kz(- k()*mag(z - elevation(t, u, x)));
|
||||
const scalar wa = omega(u)*amplitude(t);
|
||||
|
||||
if (shallow())
|
||||
{
|
||||
const scalar kh = k()*depth();
|
||||
const scalarField khz((kh + kz)*pos(kh + kz));
|
||||
return wa*zip(cosh(khz)*cos(phi), sinh(khz)*sin(phi))/sinh(kh);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wa*exp(kz)*zip(cos(phi), sin(phi));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
117
src/waves/waveModels/Airy/Airy.H
Normal file
117
src/waves/waveModels/Airy/Airy.H
Normal file
@ -0,0 +1,117 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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::waveModels::Airy
|
||||
|
||||
Description
|
||||
First-order wave model.
|
||||
|
||||
Reference:
|
||||
\verbatim
|
||||
"On the Theory of Oscillatory Waves"
|
||||
G G Stokes
|
||||
Transactions of the Cambridge Philosophical Society (1847), Volume 8,
|
||||
Pages 441-455, Equations 18 and 19 (leading terms only)
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
Airy.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Airy_H
|
||||
#define Airy_H
|
||||
|
||||
#include "waveModel.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace waveModels
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Airy Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class Airy
|
||||
:
|
||||
public waveModel
|
||||
{
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("Airy");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from a database and a dictionary
|
||||
Airy(const objectRegistry& db, const dictionary& dict);
|
||||
|
||||
//- Construct a clone
|
||||
virtual autoPtr<waveModel> clone() const
|
||||
{
|
||||
return autoPtr<waveModel>(new Airy(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~Airy();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Get the wave elevation at a given time, mean velocity and local
|
||||
// coordinates. Local x is aligned with the mean velocity.
|
||||
virtual tmp<scalarField> elevation
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const scalarField& x
|
||||
) const;
|
||||
|
||||
//- Get the wave velocity at a given time, mean velocity and local
|
||||
// coordinates. Local x is aligned with the mean velocity, and z with
|
||||
// negative gravity.
|
||||
virtual tmp<vector2DField> velocity
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const vector2DField& xz
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace waveModels
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
116
src/waves/waveModels/Stokes2/Stokes2.C
Normal file
116
src/waves/waveModels/Stokes2/Stokes2.C
Normal file
@ -0,0 +1,116 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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 "Stokes2.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace waveModels
|
||||
{
|
||||
defineTypeNameAndDebug(Stokes2, 0);
|
||||
addToRunTimeSelectionTable(waveModel, Stokes2, objectRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveModels::Stokes2::Stokes2
|
||||
(
|
||||
const objectRegistry& db,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Airy(db, dict)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveModels::Stokes2::~Stokes2()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::waveModels::Stokes2::elevation
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const scalarField& x
|
||||
) const
|
||||
{
|
||||
const scalar kh = k()*depth();
|
||||
const scalarField correction(k()*sqr(amplitude(t))*cos(2*angle(t, u, x))/2);
|
||||
|
||||
if (shallow())
|
||||
{
|
||||
const scalar factor((3/sqr(tanh(kh)) - 1)/tanh(kh)/2);
|
||||
return Airy::elevation(t, u, x) + factor*correction;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Airy::elevation(t, u, x) + correction;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::vector2DField> Foam::waveModels::Stokes2::velocity
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const vector2DField& xz
|
||||
) const
|
||||
{
|
||||
if (shallow())
|
||||
{
|
||||
const scalarField x(xz.component(0));
|
||||
const scalarField z(xz.component(1));
|
||||
|
||||
const scalarField phi(angle(t, u, x));
|
||||
const scalarField kz(- k()*mag(z - elevation(t, u, x)));
|
||||
const scalar kh = k()*depth();
|
||||
const scalarField khz((kh + kz)*pos(kh + kz));
|
||||
const scalar kwaa = k()*omega(u)*sqr(amplitude(t));
|
||||
|
||||
return
|
||||
Airy::velocity(t, u, xz)
|
||||
+ 6*kwaa*zip
|
||||
(
|
||||
cosh(2*khz)*cos(2*phi),
|
||||
sinh(2*khz)*sin(2*phi)
|
||||
)/pow4(sinh(kh));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Airy::velocity(t, u, xz);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
117
src/waves/waveModels/Stokes2/Stokes2.H
Normal file
117
src/waves/waveModels/Stokes2/Stokes2.H
Normal file
@ -0,0 +1,117 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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::waveModels::Stokes2
|
||||
|
||||
Description
|
||||
Second-order wave model.
|
||||
|
||||
Reference:
|
||||
\verbatim
|
||||
"On the Theory of Oscillatory Waves"
|
||||
G G Stokes
|
||||
Transactions of the Cambridge Philosophical Society (1847), Volume 8,
|
||||
Pages 441-455, Equations 18 and 19
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
Stokes2.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Stokes2_H
|
||||
#define Stokes2_H
|
||||
|
||||
#include "Airy.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace waveModels
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Stokes2 Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class Stokes2
|
||||
:
|
||||
public Airy
|
||||
{
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("Stokes2");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from a database and a dictionary
|
||||
Stokes2(const objectRegistry& db, const dictionary& dict);
|
||||
|
||||
//- Construct a clone
|
||||
virtual autoPtr<waveModel> clone() const
|
||||
{
|
||||
return autoPtr<waveModel>(new Stokes2(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~Stokes2();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Get the wave elevation at a given time, mean velocity and local
|
||||
// coordinates. Local x is aligned with the mean velocity.
|
||||
virtual tmp<scalarField> elevation
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const scalarField& x
|
||||
) const;
|
||||
|
||||
//- Get the wave velocity at a given time, mean velocity and local
|
||||
// coordinates. Local x is aligned with the mean velocity, and z with
|
||||
// negative gravity.
|
||||
virtual tmp<vector2DField> velocity
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const vector2DField& xz
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
} // End namespace waveModels
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
68
src/waves/waveModels/waveModel/newWaveModel.C
Normal file
68
src/waves/waveModels/waveModel/newWaveModel.C
Normal file
@ -0,0 +1,68 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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 "waveModel.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::waveModel> Foam::waveModel::New
|
||||
(
|
||||
const objectRegistry& db,
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
return waveModel::New(dict.lookup("type"), db, dict);
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<Foam::waveModel> Foam::waveModel::New
|
||||
(
|
||||
const word& type,
|
||||
const objectRegistry& db,
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "Selecting " << waveModel::typeName << " " << type << endl;
|
||||
}
|
||||
|
||||
objectRegistryConstructorTable::iterator cstrIter =
|
||||
objectRegistryConstructorTablePtr_->find(type);
|
||||
|
||||
if (cstrIter == objectRegistryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown " << waveModel::typeName << " " << type << nl << nl
|
||||
<< "Valid model types are:" << nl
|
||||
<< objectRegistryConstructorTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return cstrIter()(db, dict);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
119
src/waves/waveModels/waveModel/waveModel.C
Normal file
119
src/waves/waveModels/waveModel/waveModel.C
Normal file
@ -0,0 +1,119 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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 "waveModel.H"
|
||||
#include "mathematicalConstants.H"
|
||||
#include "Time.H"
|
||||
#include "uniformDimensionedFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(waveModel, 0);
|
||||
defineRunTimeSelectionTable(waveModel, objectRegistry);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::scalar Foam::waveModel::k() const
|
||||
{
|
||||
return 2*Foam::constant::mathematical::pi/length_;
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::waveModel::sigma() const
|
||||
{
|
||||
const uniformDimensionedVectorField& g =
|
||||
db_.lookupObject<uniformDimensionedVectorField>("g");
|
||||
|
||||
return sqrt(mag(g.value())*k()*tanh(k()*depth()));
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::waveModel::omega(const scalar u) const
|
||||
{
|
||||
return sigma() + k()*u;
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::waveModel::angle
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const scalarField& x
|
||||
) const
|
||||
{
|
||||
return k()*x - omega(u)*t;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::waveModel::shallow() const
|
||||
{
|
||||
return k()*depth() < log(GREAT);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveModel::waveModel(const waveModel& wave)
|
||||
:
|
||||
db_(wave.db_),
|
||||
length_(wave.length_),
|
||||
amplitude_(wave.amplitude_, false),
|
||||
phase_(wave.phase_),
|
||||
depth_(wave.depth_)
|
||||
{}
|
||||
|
||||
|
||||
Foam::waveModel::waveModel(const objectRegistry& db, const dictionary& dict)
|
||||
:
|
||||
db_(db),
|
||||
length_(readScalar(dict.lookup("length"))),
|
||||
amplitude_(Function1<scalar>::New("amplitude", dict)),
|
||||
phase_(readScalar(dict.lookup("phase"))),
|
||||
depth_(dict.lookupOrDefault<scalar>("depth", GREAT))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveModel::~waveModel()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::waveModel::write(Ostream& os) const
|
||||
{
|
||||
os.writeKeyword("length") << length_ << token::END_STATEMENT << nl;
|
||||
amplitude_->writeData(os);
|
||||
os.writeKeyword("phase") << phase_ << token::END_STATEMENT << nl;
|
||||
os.writeKeyword("depth") << depth_ << token::END_STATEMENT << nl;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
212
src/waves/waveModels/waveModel/waveModel.H
Normal file
212
src/waves/waveModels/waveModel/waveModel.H
Normal file
@ -0,0 +1,212 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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::waveModel
|
||||
|
||||
Description
|
||||
Generic base class for waves. Derived classes must implement field
|
||||
functions which return the elevation above the wave surface and the
|
||||
velocity field, both as a function of position.
|
||||
|
||||
SourceFiles
|
||||
waveModel.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef waveModel_H
|
||||
#define waveModel_H
|
||||
|
||||
#include "objectRegistry.H"
|
||||
#include "dictionary.H"
|
||||
#include "Function1.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
#include "vectorField.H"
|
||||
#include "vector2DField.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class waveModel Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class waveModel
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Reference to the database
|
||||
const objectRegistry& db_;
|
||||
|
||||
//- Peak-to-peak length [m]
|
||||
const scalar length_;
|
||||
|
||||
//- Peak-to-mean amplitude [m]
|
||||
autoPtr<Function1<scalar>> amplitude_;
|
||||
|
||||
//- Phase offset [rad]
|
||||
const scalar phase_;
|
||||
|
||||
//- Depth [m]
|
||||
const scalar depth_;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- The angular wavenumber [rad/m]
|
||||
scalar k() const;
|
||||
|
||||
//- The intrinsic angular frequency [rad/s]
|
||||
scalar sigma() const;
|
||||
|
||||
//- The observed angular frequency [rad/s]
|
||||
scalar omega(const scalar u) const;
|
||||
|
||||
//- Angle of the oscillation [rad]
|
||||
tmp<scalarField> angle
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const scalarField& x
|
||||
) const;
|
||||
|
||||
//- Return whether shallow effects are to be included
|
||||
bool shallow() const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("waveModel");
|
||||
|
||||
|
||||
// Declare runtime construction
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
waveModel,
|
||||
objectRegistry,
|
||||
(const objectRegistry& db, const dictionary& dict),
|
||||
(db, dict)
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct a copy
|
||||
waveModel(const waveModel& wave);
|
||||
|
||||
//- Construct from a database and a dictionary
|
||||
waveModel(const objectRegistry& db, const dictionary& dict);
|
||||
|
||||
//- Construct a clone
|
||||
virtual autoPtr<waveModel> clone() const = 0;
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Select
|
||||
static autoPtr<waveModel> New
|
||||
(
|
||||
const objectRegistry& db,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
//- Select
|
||||
static autoPtr<waveModel> New
|
||||
(
|
||||
const word& type,
|
||||
const objectRegistry& db,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~waveModel();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Get the length
|
||||
scalar length() const
|
||||
{
|
||||
return length_;
|
||||
}
|
||||
|
||||
//- Get the amplitude
|
||||
scalar amplitude(const scalar t) const
|
||||
{
|
||||
return amplitude_->value(t);
|
||||
}
|
||||
|
||||
//- Get the phase
|
||||
scalar phase() const
|
||||
{
|
||||
return phase_;
|
||||
}
|
||||
|
||||
//- Get the depth
|
||||
scalar depth() const
|
||||
{
|
||||
return depth_;
|
||||
}
|
||||
|
||||
//- Get the wave elevation at a given time, mean velocity and local
|
||||
// coordinates. Local x is aligned with the mean velocity.
|
||||
virtual tmp<scalarField> elevation
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const scalarField& x
|
||||
) const = 0;
|
||||
|
||||
//- Get the wave velocity at a given time, mean velocity and local
|
||||
// coordinates. Local x is aligned with the mean velocity, and z with
|
||||
// negative gravity.
|
||||
virtual tmp<vector2DField> velocity
|
||||
(
|
||||
const scalar t,
|
||||
const scalar u,
|
||||
const vector2DField& xz
|
||||
) const = 0;
|
||||
|
||||
//- Write
|
||||
virtual void write(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
295
src/waves/waveSuperposition/waveSuperposition.C
Normal file
295
src/waves/waveSuperposition/waveSuperposition.C
Normal file
@ -0,0 +1,295 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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 "waveSuperposition.H"
|
||||
#include "uniformDimensionedFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::waveSuperposition::transformation
|
||||
(
|
||||
const vectorField& p,
|
||||
tensor& axes,
|
||||
scalar& u,
|
||||
vectorField& xyz
|
||||
) const
|
||||
{
|
||||
const uniformDimensionedVectorField& g =
|
||||
db_.lookupObject<uniformDimensionedVectorField>("g");
|
||||
const scalar magG = mag(g.value());
|
||||
const vector gHat = g.value()/magG;
|
||||
|
||||
const vector dSurf = direction_ - gHat*(gHat & direction_);
|
||||
const scalar magDSurf = mag(dSurf);
|
||||
const vector dSurfHat = direction_/magDSurf;
|
||||
|
||||
axes = tensor(dSurfHat, - gHat ^ dSurfHat, - gHat);
|
||||
|
||||
u = speed_*magDSurf;
|
||||
|
||||
xyz = axes & (p - origin_);
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::waveSuperposition::elevation
|
||||
(
|
||||
const scalar t,
|
||||
const vector2DField& xy
|
||||
) const
|
||||
{
|
||||
scalarField result(xy.size(), 0);
|
||||
|
||||
forAll(waveModels_, wavei)
|
||||
{
|
||||
const vector2D d(cos(waveAngles_[wavei]), sin(waveAngles_[wavei]));
|
||||
result += waveModels_[wavei].elevation(t, d.x()*speed_, d & xy);
|
||||
}
|
||||
|
||||
return scale(xy)*result;
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::vectorField> Foam::waveSuperposition::velocity
|
||||
(
|
||||
const scalar t,
|
||||
const vectorField& xyz
|
||||
) const
|
||||
{
|
||||
vectorField result(xyz.size(), vector::zero);
|
||||
|
||||
forAll(waveModels_, wavei)
|
||||
{
|
||||
const vector2D d(cos(waveAngles_[wavei]), sin(waveAngles_[wavei]));
|
||||
const vector2DField xz
|
||||
(
|
||||
zip
|
||||
(
|
||||
d & zip(xyz.component(0), xyz.component(1)),
|
||||
tmp<scalarField>(xyz.component(2))
|
||||
)
|
||||
);
|
||||
const vector2DField uw
|
||||
(
|
||||
waveModels_[wavei].velocity(t, d.x()*speed_, xz)
|
||||
);
|
||||
result += zip
|
||||
(
|
||||
d.x()*uw.component(0),
|
||||
d.y()*uw.component(0),
|
||||
uw.component(1)
|
||||
);
|
||||
}
|
||||
|
||||
tmp<scalarField> s = scale(zip(xyz.component(0), xyz.component(1)));
|
||||
|
||||
return s*result;
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::waveSuperposition::scale
|
||||
(
|
||||
const vector2DField& xy
|
||||
) const
|
||||
{
|
||||
tmp<scalarField> tResult(new scalarField(xy.size(), 1));
|
||||
scalarField& result = tResult.ref();
|
||||
|
||||
if (scale_.valid())
|
||||
{
|
||||
const scalarField x(xy.component(0));
|
||||
forAll(result, i)
|
||||
{
|
||||
result[i] *= scale_->value(x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (crossScale_.valid())
|
||||
{
|
||||
const scalarField y(xy.component(1));
|
||||
forAll(result, i)
|
||||
{
|
||||
result[i] *= crossScale_->value(y[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return tResult;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveSuperposition::waveSuperposition(const objectRegistry& db)
|
||||
:
|
||||
db_(db),
|
||||
origin_(vector::zero),
|
||||
direction_(vector(1, 0, 0)),
|
||||
speed_(0),
|
||||
waveModels_(),
|
||||
waveAngles_(),
|
||||
scale_(),
|
||||
crossScale_()
|
||||
{}
|
||||
|
||||
|
||||
Foam::waveSuperposition::waveSuperposition(const waveSuperposition& waves)
|
||||
:
|
||||
db_(waves.db_),
|
||||
origin_(waves.origin_),
|
||||
direction_(waves.direction_),
|
||||
speed_(waves.speed_),
|
||||
waveModels_(waves.waveModels_),
|
||||
waveAngles_(waves.waveAngles_),
|
||||
scale_(waves.scale_, false),
|
||||
crossScale_(waves.crossScale_, false)
|
||||
{}
|
||||
|
||||
|
||||
Foam::waveSuperposition::waveSuperposition
|
||||
(
|
||||
const objectRegistry& db,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
db_(db),
|
||||
origin_(dict.lookup("origin")),
|
||||
direction_(dict.lookup("direction")),
|
||||
speed_(readScalar(dict.lookup("speed"))),
|
||||
waveModels_(),
|
||||
waveAngles_(),
|
||||
scale_
|
||||
(
|
||||
dict.found("scale")
|
||||
? Function1<scalar>::New("scale", dict)
|
||||
: autoPtr<Function1<scalar>>()
|
||||
),
|
||||
crossScale_
|
||||
(
|
||||
dict.found("crossScale")
|
||||
? Function1<scalar>::New("crossScale", dict)
|
||||
: autoPtr<Function1<scalar>>()
|
||||
)
|
||||
{
|
||||
const PtrList<entry> waveEntries(dict.lookup("waves"));
|
||||
|
||||
waveModels_.setSize(waveEntries.size());
|
||||
waveAngles_.setSize(waveEntries.size());
|
||||
|
||||
forAll(waveEntries, wavei)
|
||||
{
|
||||
const dictionary waveDict = waveEntries[wavei].dict();
|
||||
waveModels_.set
|
||||
(
|
||||
wavei,
|
||||
waveModel::New(waveDict.dictName(), db, waveDict)
|
||||
);
|
||||
waveAngles_[wavei] = readScalar(waveDict.lookup("angle"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::waveSuperposition::~waveSuperposition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::tmp<Foam::scalarField> Foam::waveSuperposition::height
|
||||
(
|
||||
const scalar t,
|
||||
const vectorField& p
|
||||
) const
|
||||
{
|
||||
tensor axes;
|
||||
scalar u;
|
||||
vectorField xyz(p.size());
|
||||
transformation(p, axes, u, xyz);
|
||||
|
||||
return
|
||||
xyz.component(2)
|
||||
- elevation(t, zip(xyz.component(0), xyz.component(1)));
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::vectorField> Foam::waveSuperposition::ULiquid
|
||||
(
|
||||
const scalar t,
|
||||
const vectorField& p
|
||||
) const
|
||||
{
|
||||
tensor axes;
|
||||
scalar u;
|
||||
vectorField xyz(p.size());
|
||||
transformation(p, axes, u, xyz);
|
||||
|
||||
return direction_*speed_ + (velocity(t, xyz) & axes);
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::vectorField> Foam::waveSuperposition::UGas
|
||||
(
|
||||
const scalar t,
|
||||
const vectorField& p
|
||||
) const
|
||||
{
|
||||
tensor axes;
|
||||
scalar u;
|
||||
vectorField xyz(p.size());
|
||||
transformation(p, axes, u, xyz);
|
||||
|
||||
axes = tensor(- axes.x(), - axes.y(), axes.z());
|
||||
|
||||
return direction_*speed_ + (velocity(t, xyz) & axes);
|
||||
}
|
||||
|
||||
|
||||
void Foam::waveSuperposition::write(Ostream& os) const
|
||||
{
|
||||
os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
|
||||
os.writeKeyword("direction") << direction_ << token::END_STATEMENT << nl;
|
||||
os.writeKeyword("speed") << speed_ << token::END_STATEMENT << nl;
|
||||
os.writeKeyword("waves") << nl << token::BEGIN_LIST << nl << incrIndent;
|
||||
forAll(waveModels_, wavei)
|
||||
{
|
||||
os.writeKeyword(waveModels_[wavei].type()) << nl << indent
|
||||
<< token::BEGIN_BLOCK << nl << incrIndent;
|
||||
waveModels_[wavei].write(os);
|
||||
os.writeKeyword("angle") << waveAngles_[wavei] << token::END_STATEMENT
|
||||
<< nl << decrIndent << indent << token::END_BLOCK << nl;
|
||||
}
|
||||
os << decrIndent << token::END_LIST << token::END_STATEMENT << nl;
|
||||
if (scale_.valid())
|
||||
{
|
||||
scale_->writeData(os);
|
||||
}
|
||||
if (crossScale_.valid())
|
||||
{
|
||||
crossScale_->writeData(os);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
155
src/waves/waveSuperposition/waveSuperposition.H
Normal file
155
src/waves/waveSuperposition/waveSuperposition.H
Normal file
@ -0,0 +1,155 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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::waveSuperposition
|
||||
|
||||
Description
|
||||
A wrapper around a list of wave models. Superimposes the modelled values
|
||||
of elevation and velocity.
|
||||
|
||||
SourceFiles
|
||||
waveSuperposition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef waveSuperposition_H
|
||||
#define waveSuperposition_H
|
||||
|
||||
#include "waveModel.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class waveSuperposition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class waveSuperposition
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Reference to the database
|
||||
const objectRegistry& db_;
|
||||
|
||||
//- The origin of the wave coordinate system
|
||||
const vector origin_;
|
||||
|
||||
//- The mean flow direction
|
||||
const vector direction_;
|
||||
|
||||
//- The mean flow speed
|
||||
const scalar speed_;
|
||||
|
||||
//- Wave models to superimpose
|
||||
PtrList<waveModel> waveModels_;
|
||||
|
||||
//- The angle relative to the mean velocity at which the waves propagate
|
||||
scalarList waveAngles_;
|
||||
|
||||
//- Scaling in the flow direction
|
||||
const autoPtr<Function1<scalar>> scale_;
|
||||
|
||||
//- Scaling perpendicular to the flow direction
|
||||
const autoPtr<Function1<scalar>> crossScale_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Get the transformation to actual coordinates
|
||||
void transformation
|
||||
(
|
||||
const vectorField& p,
|
||||
tensor& axes,
|
||||
scalar& u,
|
||||
vectorField& xyz
|
||||
) const;
|
||||
|
||||
//- Get the wave elevation relative to the mean at a given time, mean
|
||||
// velocity and local coordinates. Local x is aligned with the mean
|
||||
// velocity, and y is perpendicular to both x and gravity.
|
||||
tmp<scalarField> elevation
|
||||
(
|
||||
const scalar t,
|
||||
const vector2DField& xy
|
||||
) const;
|
||||
|
||||
//- Get the wave velocity at a given time, mean velocity and local
|
||||
// coordinates. Local x is aligned with the mean velocity, z with
|
||||
// negative gravity, and y is perpendicular to both.
|
||||
tmp<vectorField> velocity
|
||||
(
|
||||
const scalar t,
|
||||
const vectorField& xyz
|
||||
) const;
|
||||
|
||||
//- Get the scaling factor, calculated from the optional scaling
|
||||
// functions. X and y are the same as for the elevation method.
|
||||
tmp<scalarField> scale(const vector2DField& xy) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from a database
|
||||
waveSuperposition(const objectRegistry& db);
|
||||
|
||||
//- Construct a copy
|
||||
waveSuperposition(const waveSuperposition& waves);
|
||||
|
||||
//- Construct from a database and gravity
|
||||
waveSuperposition(const objectRegistry& db, const dictionary& dict);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~waveSuperposition();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Get the height above the waves at a given time and global positions
|
||||
tmp<scalarField> height(const scalar t, const vectorField& p) const;
|
||||
|
||||
//- Get the liquid velocity at a given time and global positions
|
||||
tmp<vectorField> ULiquid(const scalar t, const vectorField& p) const;
|
||||
|
||||
//- Get the gas velocity at a given time and global positions
|
||||
tmp<vectorField> UGas(const scalar t, const vectorField& p) const;
|
||||
|
||||
//- Write
|
||||
void write(Ostream&) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user