diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index ab1157350a6ad0cc1f07d4678db368fc6ceac5b2..649176d1f43f1d8f2e7d80b8f98cdccf9ccbb4cb 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -74,6 +74,7 @@ CourantNo/CourantNo.C PecletNo/PecletNo.C blendingFactor/blendingFactor.C momentum/momentum.C +momentumError/momentumError.C pressure/pressure.C MachNo/MachNo.C Curle/Curle.C diff --git a/src/functionObjects/field/momentumError/momentumError.C b/src/functionObjects/field/momentumError/momentumError.C new file mode 100644 index 0000000000000000000000000000000000000000..866a8fe18b7c0f518b317e5950f51e6ae3df80c0 --- /dev/null +++ b/src/functionObjects/field/momentumError/momentumError.C @@ -0,0 +1,216 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 "momentumError.H" + +#include "fvcDiv.H" +#include "fvcGrad.H" +#include "fvcLaplacian.H" + +#include "turbulenceModel.H" +#include "turbulentTransportModel.H" +#include "turbulentFluidThermoModel.H" +#include "addToRunTimeSelectionTable.H" + + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(momentumError, 0); + addToRunTimeSelectionTable(functionObject, momentumError, dictionary); +} +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +Foam::tmp<Foam::volVectorField> +Foam::functionObjects::momentumError::divDevRhoReff() +{ + typedef compressible::turbulenceModel cmpTurbModel; + typedef incompressible::turbulenceModel icoTurbModel; + + { + auto* turb = findObject<cmpTurbModel> + ( + turbulenceModel::propertiesName + ); + + if (turb) + { + return tmp<volVectorField>::New + ( + "divDevRhoReff", + - fvc::div + ( + (turb->rho()*turb->nuEff()) + *dev2(T(fvc::grad(turb->U()))), + "div(((rho*nuEff)*dev2(T(grad(U)))))" + ) + - fvc::laplacian + ( + turb->rho()*turb->nuEff(), + turb->U(), + "laplacian(nuEff,U)" + ) + ); + } + } + + { + const auto* turb = findObject<icoTurbModel> + ( + turbulenceModel::propertiesName + ); + + if (turb) + { + return tmp<volVectorField>::New + ( + "divDevReff", + - fvc::div + ( + (turb->nuEff())*dev2(T(fvc::grad(turb->U()))), + "div((nuEff*dev2(T(grad(U)))))" + ) + - fvc::laplacian + ( + turb->nuEff(), turb->U(), "laplacian(nuEff,U)" + ) + ); + } + } + + return volVectorField::null(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::momentumError::momentumError +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fvMeshFunctionObject(name, runTime, dict), + pName_("p"), + UName_("U"), + phiName_("phi") +{ + read(dict); + + const surfaceScalarField& phi = + lookupObject<surfaceScalarField>(phiName_); + + volVectorField* momentPtr + ( + new volVectorField + ( + IOobject + ( + "momentError", + time_.timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedVector(phi.dimensions()*dimVelocity/dimVolume, Zero) + ) + ); + + mesh_.objectRegistry::store(momentPtr); +} + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::momentumError::read(const dictionary& dict) +{ + fvMeshFunctionObject::read(dict); + + Info<< type() << " " << name() << ":" << nl; + + // Optional field name entries + if (dict.readIfPresent<word>("p", pName_)) + { + Info<< " p: " << pName_ << endl; + } + if (dict.readIfPresent<word>("U", UName_)) + { + Info<< " U: " << UName_ << endl; + } + + if (dict.readIfPresent<word>("phi", phiName_)) + { + Info<< " phi: " << phiName_ << endl; + } + + return true; +} + + +void Foam::functionObjects::momentumError::calcMomentError() +{ + + volVectorField& momentErr = + lookupObjectRef<volVectorField>("momentError"); + + const volScalarField& p = lookupObject<volScalarField>(pName_); + const volVectorField& U = lookupObject<volVectorField>(UName_); + const surfaceScalarField& phi = + lookupObject<surfaceScalarField>(phiName_); + + momentErr = divDevRhoReff() + fvc::div(phi, U) + fvc::grad(p); + +} + + +bool Foam::functionObjects::momentumError::execute() +{ + calcMomentError(); + + return true; +} + + +bool Foam::functionObjects::momentumError::write() +{ + const volVectorField& momentErr = + lookupObjectRef<volVectorField>("momentError"); + + momentErr.write(); + + return true; +} + +// ************************************************************************* // diff --git a/src/functionObjects/field/momentumError/momentumError.H b/src/functionObjects/field/momentumError/momentumError.H new file mode 100644 index 0000000000000000000000000000000000000000..98c78dad7c667a7c810448a8a113f0af71ce84ef --- /dev/null +++ b/src/functionObjects/field/momentumError/momentumError.H @@ -0,0 +1,155 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2020 OpenCFD Ltd. +------------------------------------------------------------------------------- +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::functionObjects::momentumError + +Group + grpForcesFunctionObjects + +Description + Produces a balance terms result for the steady momentum equation + +Usage + Example of function object specification: + \verbatim + momErr + { + type momentumError; + } + \endverbatim + + Where the entries comprise: + \table + Property | Description | Required | Default value + type | Type name: momentumError| yes | + p | Pressure field name | no | p + U | Velocity field name | no | U + phi | Flux field name | no | phi + \endtable +See also + Foam::functionObject + Foam::functionObjects::fvMeshFunctionObject + +SourceFiles + momentumError.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_momentumError_H +#define functionObjects_momentumError_H + +#include "fvMeshFunctionObject.H" +#include "volFieldsFwd.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class momentumError Declaration +\*---------------------------------------------------------------------------*/ + +class momentumError +: + public fvMeshFunctionObject +{ + +protected: + + // Protected data + + // Read from dictionary + + //- Name of pressure field + word pName_; + + //- Name of velocity field + word UName_; + + //- Flux + word phiName_; + + + // Protected Member Functions + + //- Return the effective viscous stress (laminar + turbulent). + tmp<volVectorField> divDevRhoReff(); + + //- No copy construct + momentumError(const momentumError&) = delete; + + //- No copy assignment + void operator=(const momentumError&) = delete; + + +public: + + //- Runtime type information + TypeName("momentumError"); + + + // Constructors + + //- Construct from Time and dictionary + momentumError + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); + + //- Destructor + virtual ~momentumError() = default; + + // Member Functions + + //- Read the forces data + virtual bool read(const dictionary&); + + //- Execute + virtual bool execute(); + + //- Write + virtual bool write(); + + //- Calculate the momentum error + void calcMomentError(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/airFoil2D/system/controlDict b/tutorials/incompressible/simpleFoam/airFoil2D/system/controlDict index 5b0620215c3176633e358e2c8d7b099cf5b8f7da..7074601dbd862d9901ac68164d47a8b35c18f1b1 100644 --- a/tutorials/incompressible/simpleFoam/airFoil2D/system/controlDict +++ b/tutorials/incompressible/simpleFoam/airFoil2D/system/controlDict @@ -45,5 +45,26 @@ timePrecision 6; runTimeModifiable true; +functions +{ + momErr + { + type momentumError; + executeControl writeTime; + writeControl writeTime; + libs (libfieldFunctionObjects); + } + + contErr + { + libs (libfieldFunctionObjects); + type div; + field phi; + executeControl writeTime; + writeControl writeTime; + } + +} + // ************************************************************************* //