ENH: adding momemtumErro FO

This commit is contained in:
sergio
2020-04-08 12:18:31 -07:00
parent f01ad2f187
commit 5425de66e4
4 changed files with 393 additions and 0 deletions

View File

@ -74,6 +74,7 @@ CourantNo/CourantNo.C
PecletNo/PecletNo.C PecletNo/PecletNo.C
blendingFactor/blendingFactor.C blendingFactor/blendingFactor.C
momentum/momentum.C momentum/momentum.C
momentumError/momentumError.C
pressure/pressure.C pressure/pressure.C
MachNo/MachNo.C MachNo/MachNo.C
Curle/Curle.C Curle/Curle.C

View File

@ -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;
}
// ************************************************************************* //

View File

@ -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
// ************************************************************************* //

View File

@ -45,5 +45,26 @@ timePrecision 6;
runTimeModifiable true; runTimeModifiable true;
functions
{
momErr
{
type momentumError;
executeControl writeTime;
writeControl writeTime;
libs (libfieldFunctionObjects);
}
contErr
{
libs (libfieldFunctionObjects);
type div;
field phi;
executeControl writeTime;
writeControl writeTime;
}
}
// ************************************************************************* // // ************************************************************************* //