diff --git a/applications/utilities/preProcessing/setWaves/setWaves.C b/applications/utilities/preProcessing/setWaves/setWaves.C index 0a9afe7651..d7221bfa06 100644 --- a/applications/utilities/preProcessing/setWaves/setWaves.C +++ b/applications/utilities/preProcessing/setWaves/setWaves.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -72,6 +72,7 @@ int main(int argc, char *argv[]) forAll(timeDirs, timeI) { runTime.setTime(timeDirs[timeI], timeI); + const scalar t = runTime.value(); Info<< "Time = " << runTime.timeName() << nl << endl; @@ -188,17 +189,16 @@ int main(int argc, char *argv[]) } liquid = liquidp; - const scalar t = runTime.value(); const pointField& ccs = mesh.cellCentres(); const pointField& pts = mesh.points(); // Internal field superposition h.primitiveFieldRef() += waves.height(t, ccs); hp.primitiveFieldRef() += waves.height(t, pts); - uGas.primitiveFieldRef() += waves.UGas(t, ccs) - waves.UMean(); - uGasp.primitiveFieldRef() += waves.UGas(t, pts) - waves.UMean(); - uLiq.primitiveFieldRef() += waves.ULiquid(t, ccs) - waves.UMean(); - uLiqp.primitiveFieldRef() += waves.ULiquid(t, pts) - waves.UMean(); + uGas.primitiveFieldRef() += waves.UGas(t, ccs) - waves.UMean(t); + uGasp.primitiveFieldRef() += waves.UGas(t, pts) - waves.UMean(t); + uLiq.primitiveFieldRef() += waves.ULiquid(t, ccs) - waves.UMean(t); + uLiqp.primitiveFieldRef() += waves.ULiquid(t, pts) - waves.UMean(t); // Boundary field superposition forAll(mesh.boundary(), patchj) @@ -206,9 +206,9 @@ int main(int argc, char *argv[]) const pointField& fcs = mesh.boundary()[patchj].Cf(); h.boundaryFieldRef()[patchj] += waves.height(t, fcs); uGas.boundaryFieldRef()[patchj] += - waves.UGas(t, fcs) - waves.UMean(); + waves.UGas(t, fcs) - waves.UMean(t); uLiq.boundaryFieldRef()[patchj] += - waves.ULiquid(t, fcs) - waves.UMean(); + waves.ULiquid(t, fcs) - waves.UMean(t); } ++ nWaves; @@ -246,7 +246,8 @@ int main(int argc, char *argv[]) const waveSuperposition& waves = refCast(Up).waves(); - UMean == dimensionedVector("UMean", dimVelocity, waves.UMean()); + UMean == + dimensionedVector("UMean", dimVelocity, waves.UMean(t)); } } else if (nWaves > 1) @@ -290,7 +291,7 @@ int main(int argc, char *argv[]) weight += w; weightUMean += - w*dimensionedVector("wUMean", dimVelocity, waves.UMean()); + w*dimensionedVector("wUMean", dimVelocity, waves.UMean(t)); } // Complete the average for the mean velocity diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.C index 4004a66362..0063b7d578 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -40,6 +40,7 @@ Foam::outletPhaseMeanVelocityFvPatchVectorField : mixedFvPatchField(p, iF), Umean_(0), + ramp_(), alphaName_("none") { refValue() = Zero; @@ -59,6 +60,7 @@ Foam::outletPhaseMeanVelocityFvPatchVectorField : mixedFvPatchField(ptf, p, iF, mapper), Umean_(ptf.Umean_), + ramp_(ptf.ramp_, false), alphaName_(ptf.alphaName_) {} @@ -73,6 +75,12 @@ Foam::outletPhaseMeanVelocityFvPatchVectorField : mixedFvPatchField(p, iF), Umean_(readScalar(dict.lookup("Umean"))), + ramp_ + ( + dict.found("ramp") + ? Function1::New("ramp", dict) + : autoPtr>() + ), alphaName_(dict.lookup("alpha")) { refValue() = Zero; @@ -101,6 +109,7 @@ Foam::outletPhaseMeanVelocityFvPatchVectorField : mixedFvPatchField(ptf), Umean_(ptf.Umean_), + ramp_(ptf.ramp_, false), alphaName_(ptf.alphaName_) {} @@ -114,6 +123,7 @@ Foam::outletPhaseMeanVelocityFvPatchVectorField : mixedFvPatchField(ptf, iF), Umean_(ptf.Umean_), + ramp_(ptf.ramp_, false), alphaName_(ptf.alphaName_) {} @@ -127,6 +137,8 @@ void Foam::outletPhaseMeanVelocityFvPatchVectorField::updateCoeffs() return; } + const scalar t = this->db().time().timeOutputValue(); + scalarField alphap = patch().lookupPatchField(alphaName_); @@ -143,15 +155,16 @@ void Foam::outletPhaseMeanVelocityFvPatchVectorField::updateCoeffs() // Set the refValue and valueFraction to adjust the boundary field // such that the phase mean is Umean_ - if (Uzgmean >= Umean_) + const scalar Umean = (ramp_.valid() ? ramp_->value(t) : 1)*Umean_; + if (Uzgmean >= Umean) { refValue() = Zero; - valueFraction() = 1.0 - Umean_/Uzgmean; + valueFraction() = 1.0 - Umean/Uzgmean; } else { - refValue() = (Umean_ + Uzgmean)*patch().nf(); - valueFraction() = 1.0 - Uzgmean/Umean_; + refValue() = (Umean + Uzgmean)*patch().nf(); + valueFraction() = 1.0 - Uzgmean/Umean; } mixedFvPatchField::updateCoeffs(); @@ -165,10 +178,12 @@ void Foam::outletPhaseMeanVelocityFvPatchVectorField::write { fvPatchField::write(os); - os.writeKeyword("Umean") << Umean_ - << token::END_STATEMENT << nl; - os.writeKeyword("alpha") << alphaName_ - << token::END_STATEMENT << nl; + os.writeKeyword("Umean") << Umean_ << token::END_STATEMENT << nl; + if (ramp_.valid()) + { + ramp_->writeData(os); + } + os.writeKeyword("alpha") << alphaName_ << token::END_STATEMENT << nl; writeEntry("value", os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.H index bafe020554..d9e771257c 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/outletPhaseMeanVelocity/outletPhaseMeanVelocityFvPatchVectorField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,6 +39,7 @@ Usage \table Property | Description | Required | Default value Umean | mean velocity normal to the boundary [m/s] | yes | + ramp | ramping function for the mean flow speed | no | None alpha | phase-fraction field | yes | \endtable @@ -66,6 +67,7 @@ SourceFiles #define outletPhaseMeanVelocityFvPatchVectorField_H #include "mixedFvPatchFields.H" +#include "Function1.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -84,6 +86,9 @@ class outletPhaseMeanVelocityFvPatchVectorField //- Inlet integral flow rate scalar Umean_; + //- Ramp for the mean flow rate + autoPtr> ramp_; + //- Name of the phase-fraction field word alphaName_; @@ -163,21 +168,6 @@ public: // Member functions - // Access - - //- Return the flux - scalar Umean() const - { - return Umean_; - } - - //- Return reference to the flux to allow adjustment - scalar& Umean() - { - return Umean_; - } - - //- Update the coefficients associated with the patch field virtual void updateCoeffs(); diff --git a/src/fvOptions/Make/files b/src/fvOptions/Make/files index 1b016d41aa..314860b78e 100644 --- a/src/fvOptions/Make/files +++ b/src/fvOptions/Make/files @@ -39,6 +39,7 @@ $(derivedSources)/buoyancyEnergy/buoyancyEnergy.C $(derivedSources)/buoyancyEnergy/buoyancyEnergyIO.C $(derivedSources)/verticalDamping/verticalDamping.C $(derivedSources)/phaseLimitStabilization/phaseLimitStabilization.C +$(derivedSources)/velocityRamping/velocityRamping.C interRegion = sources/interRegion $(interRegion)/interRegionHeatTransfer/interRegionHeatTransferModel/interRegionHeatTransferModel.C diff --git a/src/fvOptions/sources/derived/velocityRamping/velocityRamping.C b/src/fvOptions/sources/derived/velocityRamping/velocityRamping.C new file mode 100644 index 0000000000..096476f79c --- /dev/null +++ b/src/fvOptions/sources/derived/velocityRamping/velocityRamping.C @@ -0,0 +1,118 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +\*---------------------------------------------------------------------------*/ + +#include "fvMesh.H" +#include "fvMatrix.H" +#include "geometricOneField.H" +#include "velocityRamping.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fv +{ + defineTypeNameAndDebug(velocityRamping, 0); + addToRunTimeSelectionTable(option, velocityRamping, dictionary); +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fv::velocityRamping::velocityRamping +( + const word& name, + const word& modelType, + const dictionary& dict, + const fvMesh& mesh +) +: + cellSetOption(name, modelType, dict, mesh), + velocity_(vector::zero), + ramp_(nullptr) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::fv::velocityRamping::addSup +( + fvMatrix& eqn, + const label fieldi +) +{ + add(geometricOneField(), eqn, fieldi); +} + + +void Foam::fv::velocityRamping::addSup +( + const volScalarField& rho, + fvMatrix& eqn, + const label fieldi +) +{ + add(rho, eqn, fieldi); +} + + +void Foam::fv::velocityRamping::addSup +( + const volScalarField& alpha, + const volScalarField& rho, + fvMatrix& eqn, + const label fieldi +) +{ + add((alpha*rho)(), eqn, fieldi); +} + + +bool Foam::fv::velocityRamping::read(const dictionary& dict) +{ + if (cellSetOption::read(dict)) + { + fieldNames_ = wordList(1, coeffs_.lookupOrDefault("U", "U")); + + applied_.setSize(1, false); + + velocity_ = dict.lookupType("velocity"); + + ramp_ = Function1::New("ramp", dict); + + return true; + } + else + { + return false; + } +} + + +// ************************************************************************* // diff --git a/src/fvOptions/sources/derived/velocityRamping/velocityRamping.H b/src/fvOptions/sources/derived/velocityRamping/velocityRamping.H new file mode 100644 index 0000000000..9d92e09c99 --- /dev/null +++ b/src/fvOptions/sources/derived/velocityRamping/velocityRamping.H @@ -0,0 +1,173 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +Class + Foam::fv::velocityRamping + +Description + This fvOption applies an explicit acceleration force to components of the + velocity field. + +Usage + Example usage: + \verbatim + velocityRamping + { + type velocityRamping; + active on; + selectionMode all; + U U; + velocity (-2.572 0 0); + ramp + { + type quarterSineRamp; + start 0; + duration 10; + } + } + \endverbatim + +SourceFiles + velocityRamping.C + +\*---------------------------------------------------------------------------*/ + +#ifndef velocityRamping_H +#define velocityRamping_H + +#include "cellSetOption.H" +#include "Function1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class velocityRamping Declaration +\*---------------------------------------------------------------------------*/ + +class velocityRamping +: + public cellSetOption +{ +private: + + // Private data + + //- Velocity at the end of the ramp + vector velocity_; + + //- Ramp function + autoPtr> ramp_; + + + // Private Member Functions + + //- Source term to momentum equation + template + void add + ( + const AlphaRhoFieldType& rho, + fvMatrix& eqn, + const label fieldi + ); + + +public: + + //- Runtime type information + TypeName("velocityRamping"); + + + // Constructors + + //- Construct from components + velocityRamping + ( + const word& name, + const word& modelType, + const dictionary& dict, + const fvMesh& mesh + ); + + + //- Destructor + virtual ~velocityRamping() + {} + + + // Member Functions + + // Add explicit and implicit contributions + + //- Source term to momentum equation + virtual void addSup + ( + fvMatrix& eqn, + const label fieldi + ); + + //- Source term to compressible momentum equation + virtual void addSup + ( + const volScalarField& rho, + fvMatrix& eqn, + const label fieldi + ); + + //- Source term to phase momentum equation + virtual void addSup + ( + const volScalarField& alpha, + const volScalarField& rho, + fvMatrix& eqn, + const label fieldi + ); + + + // IO + + //- Read dictionary + virtual bool read(const dictionary& dict); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "velocityRampingTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fvOptions/sources/derived/velocityRamping/velocityRampingTemplates.C b/src/fvOptions/sources/derived/velocityRamping/velocityRampingTemplates.C new file mode 100644 index 0000000000..763c5bded6 --- /dev/null +++ b/src/fvOptions/sources/derived/velocityRamping/velocityRampingTemplates.C @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +void Foam::fv::velocityRamping::add +( + const AlphaRhoFieldType& alphaRho, + fvMatrix& eqn, + const label fieldi +) +{ + const DimensionedField& V = mesh_.V(); + + const scalar t = mesh_.time().value(); + const scalar dt = mesh_.time().deltaTValue(); + const vector dU = velocity_*(ramp_->value(t) - ramp_->value(t - dt)); + const vector a = dU/mesh_.time().deltaTValue(); + + forAll(cells_, i) + { + const label c = cells_[i]; + eqn.source()[c] -= V[c]*alphaRho[c]*a; + } +} + + +// ************************************************************************* // diff --git a/src/waves/derivedFvPatchFields/waveVelocity/waveVelocityFvPatchVectorField.H b/src/waves/derivedFvPatchFields/waveVelocity/waveVelocityFvPatchVectorField.H index 9089d902da..eff095204c 100644 --- a/src/waves/derivedFvPatchFields/waveVelocity/waveVelocityFvPatchVectorField.H +++ b/src/waves/derivedFvPatchFields/waveVelocity/waveVelocityFvPatchVectorField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -60,6 +60,7 @@ Usage direction | direction of the mean flow | yes | speed | speed of the mean flow | yes | waves | list of wave models to superimpose | yes | + ramp | ramping function for the mean flow speed | no | None scale | scale factor along the mean flow direction | no | None crossScale | scale factor across the mean flow direction | no | None phi | Name of the flux field | no | phi @@ -91,6 +92,7 @@ Usage angle 0; } ); + ramp constant 1; scale table ((100 1) (200 0)); crossScale constant 1; } diff --git a/src/waves/waveSuperposition/waveSuperposition.C b/src/waves/waveSuperposition/waveSuperposition.C index 90aeb15024..62b9a47317 100644 --- a/src/waves/waveSuperposition/waveSuperposition.C +++ b/src/waves/waveSuperposition/waveSuperposition.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -180,6 +180,7 @@ Foam::waveSuperposition::waveSuperposition(const objectRegistry& db) speed_(0), waveModels_(), waveAngles_(), + ramp_(), scale_(), crossScale_() {} @@ -193,6 +194,7 @@ Foam::waveSuperposition::waveSuperposition(const waveSuperposition& waves) speed_(waves.speed_), waveModels_(waves.waveModels_), waveAngles_(waves.waveAngles_), + ramp_(waves.ramp_, false), scale_(waves.scale_, false), crossScale_(waves.crossScale_, false) {} @@ -210,6 +212,12 @@ Foam::waveSuperposition::waveSuperposition speed_(readScalar(dict.lookup("speed"))), waveModels_(), waveAngles_(), + ramp_ + ( + dict.found("ramp") + ? Function1::New("ramp", dict) + : autoPtr>() + ), scale_ ( dict.found("scale") @@ -277,7 +285,7 @@ Foam::tmp Foam::waveSuperposition::ULiquid vectorField xyz(p.size()); transformation(p, axes, u, xyz); - return UMean() + (velocity(t, xyz) & axes); + return UMean(t) + (velocity(t, xyz) & axes); } @@ -294,7 +302,7 @@ Foam::tmp Foam::waveSuperposition::UGas axes = tensor(- axes.x(), - axes.y(), axes.z()); - return UMean() + (velocity(t, xyz) & axes); + return UMean(t) + (velocity(t, xyz) & axes); } @@ -338,6 +346,10 @@ void Foam::waveSuperposition::write(Ostream& os) const << nl << decrIndent << indent << token::END_BLOCK << nl; } os << decrIndent << token::END_LIST << token::END_STATEMENT << nl; + if (ramp_.valid()) + { + ramp_->writeData(os); + } if (scale_.valid()) { scale_->writeData(os); diff --git a/src/waves/waveSuperposition/waveSuperposition.H b/src/waves/waveSuperposition/waveSuperposition.H index e5f802141d..4bb0e638c5 100644 --- a/src/waves/waveSuperposition/waveSuperposition.H +++ b/src/waves/waveSuperposition/waveSuperposition.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -69,6 +69,9 @@ class waveSuperposition //- The angle relative to the mean velocity at which the waves propagate scalarList waveAngles_; + //- Ramp for the mean flow speed + const autoPtr> ramp_; + //- Scaling in the flow direction const autoPtr> scale_; @@ -147,9 +150,9 @@ public: tmp pGas(const scalar t, const vectorField& p) const; //- Get the mean flow velocity - inline vector UMean() const + inline vector UMean(const scalar t) const { - return direction_*speed_; + return (ramp_.valid() ? ramp_->value(t) : 1)*direction_*speed_; } //- Write