diff --git a/src/waves/waveModels/Airy/Airy.C b/src/waves/waveModels/Airy/Airy.C index e61702f2ed..e4aa83d3a7 100644 --- a/src/waves/waveModels/Airy/Airy.C +++ b/src/waves/waveModels/Airy/Airy.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -34,7 +34,7 @@ namespace Foam namespace waveModels { defineTypeNameAndDebug(Airy, 0); - addToRunTimeSelectionTable(waveModel, Airy, objectRegistry); + addToRunTimeSelectionTable(waveModel, Airy, dictionary); } } @@ -110,11 +110,11 @@ Foam::waveModels::Airy::Airy(const Airy& wave) Foam::waveModels::Airy::Airy ( - const objectRegistry& db, - const dictionary& dict + const dictionary& dict, + const scalar g ) : - waveModel(db, dict), + waveModel(dict, g), length_(dict.lookup("length")), phase_(dict.lookup("phase")), depth_(dict.lookupOrDefault("depth", log(2*great)/k())) @@ -151,19 +151,6 @@ Foam::tmp Foam::waveModels::Airy::velocity } -Foam::tmp Foam::waveModels::Airy::pressure -( - const scalar t, - const vector2DField& xz -) const -{ - // It is a fluke of the formulation that the time derivative of the velocity - // potential equals the x-derivative multiplied by the celerity. This allows - // for this shortcut in evaluating the unsteady pressure. - return celerity()*velocity(t, xz)->component(0); -} - - void Foam::waveModels::Airy::write(Ostream& os) const { waveModel::write(os); diff --git a/src/waves/waveModels/Airy/Airy.H b/src/waves/waveModels/Airy/Airy.H index 6c3877b3d2..b54d46e67f 100644 --- a/src/waves/waveModels/Airy/Airy.H +++ b/src/waves/waveModels/Airy/Airy.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -113,8 +113,8 @@ public: //- Construct a copy Airy(const Airy& wave); - //- Construct from a database and a dictionary - Airy(const objectRegistry& db, const dictionary& dict); + //- Construct from a dictionary and gravity + Airy(const dictionary& dict, const scalar g); //- Construct a clone virtual autoPtr clone() const @@ -166,15 +166,6 @@ public: const vector2DField& xz ) const; - //- Get the wave pressure at a given time and local coordinates. Local - // x is aligned with the direction of propagation, and z with negative - // gravity. - virtual tmp pressure - ( - const scalar t, - const vector2DField& xz - ) const; - //- Write virtual void write(Ostream& os) const; }; diff --git a/src/waves/waveModels/Stokes2/Stokes2.C b/src/waves/waveModels/Stokes2/Stokes2.C index a71429fa01..8aff5ad476 100644 --- a/src/waves/waveModels/Stokes2/Stokes2.C +++ b/src/waves/waveModels/Stokes2/Stokes2.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,7 +33,7 @@ namespace Foam namespace waveModels { defineTypeNameAndDebug(Stokes2, 0); - addToRunTimeSelectionTable(waveModel, Stokes2, objectRegistry); + addToRunTimeSelectionTable(waveModel, Stokes2, dictionary); } } @@ -42,11 +42,11 @@ namespace waveModels Foam::waveModels::Stokes2::Stokes2 ( - const objectRegistry& db, - const dictionary& dict + const dictionary& dict, + const scalar g ) : - Airy(db, dict) + Airy(dict, g) {} diff --git a/src/waves/waveModels/Stokes2/Stokes2.H b/src/waves/waveModels/Stokes2/Stokes2.H index bd059ec195..51ec4c41bd 100644 --- a/src/waves/waveModels/Stokes2/Stokes2.H +++ b/src/waves/waveModels/Stokes2/Stokes2.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -69,8 +69,8 @@ public: // Constructors - //- Construct from a database and a dictionary - Stokes2(const objectRegistry& db, const dictionary& dict); + //- Construct from a dictionary and gravity + Stokes2(const dictionary& dict, const scalar g); //- Construct a clone virtual autoPtr clone() const diff --git a/src/waves/waveModels/Stokes5/Stokes5.C b/src/waves/waveModels/Stokes5/Stokes5.C index 1cf09c79b1..ed1c923a9b 100644 --- a/src/waves/waveModels/Stokes5/Stokes5.C +++ b/src/waves/waveModels/Stokes5/Stokes5.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,7 +33,7 @@ namespace Foam namespace waveModels { defineTypeNameAndDebug(Stokes5, 0); - addToRunTimeSelectionTable(waveModel, Stokes5, objectRegistry); + addToRunTimeSelectionTable(waveModel, Stokes5, dictionary); } } @@ -42,11 +42,11 @@ namespace waveModels Foam::waveModels::Stokes5::Stokes5 ( - const objectRegistry& db, - const dictionary& dict + const dictionary& dict, + const scalar g ) : - Stokes2(db, dict) + Stokes2(dict, g) {} diff --git a/src/waves/waveModels/Stokes5/Stokes5.H b/src/waves/waveModels/Stokes5/Stokes5.H index f0c00b3abc..a9203e36ce 100644 --- a/src/waves/waveModels/Stokes5/Stokes5.H +++ b/src/waves/waveModels/Stokes5/Stokes5.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -68,8 +68,8 @@ public: // Constructors - //- Construct from a database and a dictionary - Stokes5(const objectRegistry& db, const dictionary& dict); + //- Construct from a dictionary and gravity + Stokes5(const dictionary& dict, const scalar g); //- Construct a clone virtual autoPtr clone() const diff --git a/src/waves/waveModels/solitary/solitary.C b/src/waves/waveModels/solitary/solitary.C index cb73a62314..75e81dbf7e 100644 --- a/src/waves/waveModels/solitary/solitary.C +++ b/src/waves/waveModels/solitary/solitary.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -34,7 +34,7 @@ namespace Foam namespace waveModels { defineTypeNameAndDebug(solitary, 0); - addToRunTimeSelectionTable(waveModel, solitary, objectRegistry); + addToRunTimeSelectionTable(waveModel, solitary, dictionary); } } @@ -93,11 +93,11 @@ Foam::waveModels::solitary::solitary(const solitary& wave) Foam::waveModels::solitary::solitary ( - const objectRegistry& db, - const dictionary& dict + const dictionary& dict, + const scalar g ) : - waveModel(db, dict), + waveModel(dict, g), offset_(dict.lookup("offset")), depth_(dict.lookup("depth")) {} @@ -149,17 +149,6 @@ Foam::tmp Foam::waveModels::solitary::velocity } -Foam::tmp Foam::waveModels::solitary::pressure -( - const scalar t, - const vector2DField& xz -) const -{ - NotImplemented; - return tmp(nullptr); -} - - void Foam::waveModels::solitary::write(Ostream& os) const { waveModel::write(os); diff --git a/src/waves/waveModels/solitary/solitary.H b/src/waves/waveModels/solitary/solitary.H index 5f0045a9f9..3a01f3dd0f 100644 --- a/src/waves/waveModels/solitary/solitary.H +++ b/src/waves/waveModels/solitary/solitary.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -108,8 +108,8 @@ public: //- Construct a copy solitary(const solitary& wave); - //- Construct from a database and a dictionary - solitary(const objectRegistry& db, const dictionary& dict); + //- Construct from a dictionary and gravity + solitary(const dictionary& dict, const scalar g); //- Construct a clone virtual autoPtr clone() const @@ -155,15 +155,6 @@ public: const vector2DField& xz ) const; - //- Get the wave pressure at a given time and local coordinates. Local - // x is aligned with the direction of propagation, and z with negative - // gravity. - virtual tmp pressure - ( - const scalar t, - const vector2DField& xz - ) const; - //- Write virtual void write(Ostream& os) const; }; diff --git a/src/waves/waveModels/waveModel/waveModel.C b/src/waves/waveModels/waveModel/waveModel.C index c7b2a831c4..e97ae4cb77 100644 --- a/src/waves/waveModels/waveModel/waveModel.C +++ b/src/waves/waveModels/waveModel/waveModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,15 +24,13 @@ License \*---------------------------------------------------------------------------*/ #include "waveModel.H" -#include "Time.H" -#include "uniformDimensionedFields.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(waveModel, 0); - defineRunTimeSelectionTable(waveModel, objectRegistry); + defineRunTimeSelectionTable(waveModel, dictionary); } @@ -40,18 +38,18 @@ namespace Foam Foam::waveModel::waveModel(const waveModel& wave) : - db_(wave.db_), + g_(wave.g_), amplitude_(wave.amplitude_, false) {} Foam::waveModel::waveModel ( - const objectRegistry& db, - const dictionary& dict + const dictionary& dict, + const scalar g ) : - db_(db), + g_(g), amplitude_(Function1::New("amplitude", dict)) {} @@ -64,12 +62,6 @@ Foam::waveModel::~waveModel() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -Foam::scalar Foam::waveModel::g() const -{ - return mag(db_.lookupObject("g").value()); -} - - void Foam::waveModel::write(Ostream& os) const { writeEntry(os, amplitude_()); diff --git a/src/waves/waveModels/waveModel/waveModel.H b/src/waves/waveModels/waveModel/waveModel.H index 8703fd4c39..6b11507a93 100644 --- a/src/waves/waveModels/waveModel/waveModel.H +++ b/src/waves/waveModels/waveModel/waveModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -38,7 +38,6 @@ SourceFiles #ifndef waveModel_H #define waveModel_H -#include "objectRegistry.H" #include "dictionary.H" #include "Function1.H" #include "runTimeSelectionTables.H" @@ -58,8 +57,8 @@ class waveModel { // Private Data - //- Reference to the database - const objectRegistry& db_; + //- Gravitational acceleration [m/s^2] + const scalar g_; //- Peak-to-mean amplitude [m] autoPtr> amplitude_; @@ -76,9 +75,9 @@ public: ( autoPtr, waveModel, - objectRegistry, - (const objectRegistry& db, const dictionary& dict), - (db, dict) + dictionary, + (const dictionary& dict, const scalar g), + (dict, g) ); @@ -87,8 +86,8 @@ public: //- Construct a copy waveModel(const waveModel& wave); - //- Construct from a database and a dictionary - waveModel(const objectRegistry& db, const dictionary& dict); + //- Construct from a dictionary and gravity + waveModel(const dictionary& dict, const scalar g); //- Construct a clone virtual autoPtr clone() const = 0; @@ -99,16 +98,16 @@ public: //- Select static autoPtr New ( - const objectRegistry& db, - const dictionary& dict + const dictionary& dict, + const scalar g ); //- Select static autoPtr New ( const word& type, - const objectRegistry& db, - const dictionary& dict + const dictionary& dict, + const scalar g ); @@ -120,15 +119,18 @@ public: // Access + //- Get the value of gravity + scalar g() const + { + return g_; + } + //- Get the amplitude scalar amplitude(const scalar t) const { return amplitude_->value(t); } - //- Get the (scalar) value of gravity. - scalar g() const; - //- Get the wave elevation at a given time and local coordinates. Local // x is aligned with the direction of propagation. virtual tmp elevation @@ -146,15 +148,6 @@ public: const vector2DField& xz ) const = 0; - //- Get the wave pressure at a given time and local coordinates. Local - // x is aligned with the direction of propagation, and z with negative - // gravity. - virtual tmp pressure - ( - const scalar t, - const vector2DField& xz - ) const = 0; - //- Write virtual void write(Ostream& os) const; }; diff --git a/src/waves/waveModels/waveModel/waveModelNew.C b/src/waves/waveModels/waveModel/waveModelNew.C index 89f3c7869b..3440fcc92f 100644 --- a/src/waves/waveModels/waveModel/waveModelNew.C +++ b/src/waves/waveModels/waveModel/waveModelNew.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,19 +29,19 @@ License Foam::autoPtr Foam::waveModel::New ( - const objectRegistry& db, - const dictionary& dict + const dictionary& dict, + const scalar g ) { - return waveModel::New(dict.lookup("type"), db, dict); + return waveModel::New(dict.lookup("type"), dict, g); } Foam::autoPtr Foam::waveModel::New ( const word& type, - const objectRegistry& db, - const dictionary& dict + const dictionary& dict, + const scalar g ) { if (debug) @@ -49,19 +49,19 @@ Foam::autoPtr Foam::waveModel::New Info<< "Selecting " << waveModel::typeName << " " << type << endl; } - objectRegistryConstructorTable::iterator cstrIter = - objectRegistryConstructorTablePtr_->find(type); + dictionaryConstructorTable::iterator cstrIter = + dictionaryConstructorTablePtr_->find(type); - if (cstrIter == objectRegistryConstructorTablePtr_->end()) + if (cstrIter == dictionaryConstructorTablePtr_->end()) { FatalErrorInFunction << "Unknown " << waveModel::typeName << " " << type << nl << nl << "Valid model types are:" << nl - << objectRegistryConstructorTablePtr_->sortedToc() + << dictionaryConstructorTablePtr_->sortedToc() << exit(FatalError); } - return cstrIter()(db, dict); + return cstrIter()(dict, g); } diff --git a/src/waves/waveSuperpositions/waveSuperposition/waveSuperposition.C b/src/waves/waveSuperpositions/waveSuperposition/waveSuperposition.C index e35597c748..0cacc02b00 100644 --- a/src/waves/waveSuperpositions/waveSuperposition/waveSuperposition.C +++ b/src/waves/waveSuperpositions/waveSuperposition/waveSuperposition.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,6 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "waveSuperposition.H" +#include "dimensionedTypes.H" #include "Time.H" #include "uniformDimensionedFields.H" #include "addToRunTimeSelectionTable.H" @@ -125,38 +126,6 @@ Foam::tmp Foam::waveSuperposition::velocity } -Foam::tmp Foam::waveSuperposition::pressure -( - const scalar t, - const vectorField& xyz -) const -{ - scalarField result(xyz.size(), 0); - - 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(xyz.component(2)) - ) - ); - const vector2DField uw - ( - waveModels_[wavei].velocity(t, xz) - ); - result += waveModels_[wavei].pressure(t, xz); - } - - tmp s = scale(zip(xyz.component(0), xyz.component(1))); - - return s*result; -} - - Foam::tmp Foam::waveSuperposition::scale ( const vector2DField& xy @@ -221,6 +190,28 @@ Foam::waveSuperposition::waveSuperposition(const objectRegistry& db) ), heightAboveWave_(lookupOrDefault("heightAboveWave", false)) { + if (!db.foundObject("g")) + { + uniformDimensionedVectorField* gPtr = + new uniformDimensionedVectorField + ( + IOobject + ( + "g", + db.time().constant(), + db, + IOobject::MUST_READ, + IOobject::NO_WRITE + ), + dimensionedVector(dimAcceleration, Zero) + ); + + gPtr->store(); + } + + const uniformDimensionedVectorField& g = + db.lookupObject("g"); + const PtrList waveEntries(lookup("waves")); waveModels_.setSize(waveEntries.size()); @@ -232,7 +223,7 @@ Foam::waveSuperposition::waveSuperposition(const objectRegistry& db) waveModels_.set ( wavei, - waveModel::New(waveDict.dictName(), db, waveDict) + waveModel::New(waveDict.dictName(), waveDict, mag(g.value())) ); waveAngles_[wavei] = waveDict.lookup("angle"); } @@ -305,48 +296,6 @@ Foam::tmp Foam::waveSuperposition::UGas } -Foam::tmp Foam::waveSuperposition::pLiquid -( - const scalar t, - const vectorField& p -) const -{ - tensor axes; - vectorField xyz(p.size()); - transformation(t, p, axes, xyz); - - if (heightAboveWave_) - { - xyz.replace(2, height(t, p)); - } - - return pressure(t, xyz); -} - - -Foam::tmp Foam::waveSuperposition::pGas -( - const scalar t, - const vectorField& p -) const -{ - tensor axes; - vectorField xyz(p.size()); - transformation(t, p, axes, xyz); - - axes = tensor(- axes.x(), - axes.y(), axes.z()); - - if (heightAboveWave_) - { - xyz.replace(2, height(t, p)); - } - - xyz.replace(2, - xyz.component(2)); - - return pressure(t, xyz); -} - - void Foam::waveSuperposition::write(Ostream& os) const { writeEntry(os, "origin", origin_); diff --git a/src/waves/waveSuperpositions/waveSuperposition/waveSuperposition.H b/src/waves/waveSuperpositions/waveSuperposition/waveSuperposition.H index 2a5713c74a..1e16e16a52 100644 --- a/src/waves/waveSuperpositions/waveSuperposition/waveSuperposition.H +++ b/src/waves/waveSuperpositions/waveSuperposition/waveSuperposition.H @@ -151,11 +151,6 @@ protected: // perpendicular to both. tmp velocity(const scalar t, const vectorField& xyz) const; - //- Get the wave pressure at a given time and local coordinates. Local - // x is aligned with the direction, z with negative gravity, and y is - // perpendicular to both. - tmp pressure(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 scale(const vector2DField& xy) const; @@ -224,20 +219,6 @@ public: const vectorField& p ) const; - //- Get the liquid pressure at a given time and global positions - virtual tmp pLiquid - ( - const scalar t, - const vectorField& p - ) const; - - //- Get the gas pressure at a given time and global positions - virtual tmp pGas - ( - const scalar t, - const vectorField& p - ) const; - //- Inherit write from regIOobject using regIOobject::write; diff --git a/tutorials/incompressible/pimpleFoam/RAS/waveSubSurface/system/controlDict b/tutorials/incompressible/pimpleFoam/RAS/waveSubSurface/system/controlDict index 36c8c301f9..f720c24fb8 100644 --- a/tutorials/incompressible/pimpleFoam/RAS/waveSubSurface/system/controlDict +++ b/tutorials/incompressible/pimpleFoam/RAS/waveSubSurface/system/controlDict @@ -53,36 +53,4 @@ libs "libwaves.so" ); -functions -{ - readG - { - libs ("libutilityFunctionObjects.so"); - type coded; - name readG; - enabled yes; - executeControl none; - codeRead - #{ - if (!mesh().template foundObject("g")) - { - Info<< "\nReading g" << endl; - uniformDimensionedVectorField* g = - new uniformDimensionedVectorField - ( - IOobject - ( - "g", - mesh().time().constant(), - mesh(), - IOobject::MUST_READ, - IOobject::NO_WRITE - ) - ); - g->store(); - } - #}; - } -}; - // ************************************************************************* //