momentumError.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "momentumError.H"
29 #include "fvcDiv.H"
30 #include "fvcGrad.H"
31 #include "fvcLaplacian.H"
32 #include "turbulenceModel.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 namespace functionObjects
42 {
43  defineTypeNameAndDebug(momentumError, 0);
44  addToRunTimeSelectionTable(functionObject, momentumError, dictionary);
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
50 
53 {
54  typedef compressible::turbulenceModel cmpTurbModel;
55  typedef incompressible::turbulenceModel icoTurbModel;
56 
57  {
58  auto* turb = findObject<cmpTurbModel>
59  (
61  );
62 
63  if (turb)
64  {
66  (
67  "divDevRhoReff",
68  - fvc::div
69  (
70  (turb->rho()*turb->nuEff())
71  *dev2(T(fvc::grad(turb->U()))),
72  "div(((rho*nuEff)*dev2(T(grad(U)))))"
73  )
75  (
76  turb->rho()*turb->nuEff(),
77  turb->U(),
78  "laplacian(nuEff,U)"
79  )
80  );
81  }
82  }
83 
84  {
85  const auto* turb = findObject<icoTurbModel>
86  (
88  );
89 
90  if (turb)
91  {
93  (
94  "divDevReff",
95  - fvc::div
96  (
97  (turb->nuEff())*dev2(T(fvc::grad(turb->U()))),
98  "div((nuEff*dev2(T(grad(U)))))"
99  )
101  (
102  turb->nuEff(), turb->U(), "laplacian(nuEff,U)"
103  )
104  );
105  }
106  }
107 
108  return volVectorField::null();
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113 
115 (
116  const word& name,
117  const Time& runTime,
118  const dictionary& dict
119 )
120 :
122  pName_("p"),
123  UName_("U"),
124  phiName_("phi")
125 {
126  read(dict);
127 
128  const surfaceScalarField& phi =
129  lookupObject<surfaceScalarField>(phiName_);
130 
131  volVectorField* momentPtr
132  (
133  new volVectorField
134  (
135  IOobject
136  (
137  "momentError",
138  time_.timeName(),
139  mesh_,
142  ),
143  mesh_,
145  )
146  );
147 
148  mesh_.objectRegistry::store(momentPtr);
149 }
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
154 {
156 
157  Info<< type() << " " << name() << ":" << nl;
158 
159  // Optional field name entries
160  if (dict.readIfPresent<word>("p", pName_))
161  {
162  Info<< " p: " << pName_ << endl;
163  }
164  if (dict.readIfPresent<word>("U", UName_))
165  {
166  Info<< " U: " << UName_ << endl;
167  }
168 
169  if (dict.readIfPresent<word>("phi", phiName_))
170  {
171  Info<< " phi: " << phiName_ << endl;
172  }
173 
174  return true;
175 }
176 
177 
179 {
180 
181  volVectorField& momentErr =
182  lookupObjectRef<volVectorField>("momentError");
183 
184  const volScalarField& p = lookupObject<volScalarField>(pName_);
185  const volVectorField& U = lookupObject<volVectorField>(UName_);
186  const surfaceScalarField& phi =
187  lookupObject<surfaceScalarField>(phiName_);
188 
189  momentErr = divDevRhoReff() + fvc::div(phi, U) + fvc::grad(p);
190 
191 }
192 
193 
195 {
196  calcMomentError();
197 
198  return true;
199 }
200 
201 
203 {
204  const volVectorField& momentErr =
205  lookupObjectRef<volVectorField>("momentError");
206 
207  momentErr.write();
208 
209  return true;
210 }
211 
212 
213 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::functionObjects::momentumError::divDevRhoReff
tmp< volVectorField > divDevRhoReff()
Return the effective viscous stress (laminar + turbulent).
Definition: momentumError.C:52
p
volScalarField & p
Definition: createFieldRefs.H:8
momentumError.H
Foam::fvc::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:54
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::dimVelocity
const dimensionSet dimVelocity
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
turbulentTransportModel.H
Foam::turbulenceModel::propertiesName
static const word propertiesName
Default name of the turbulence properties dictionary.
Definition: turbulenceModel.H:100
fvcDiv.H
Calculate the divergence of the given field.
Foam::fvc::div
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:49
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::functionObjects::momentumError::calcMomentError
void calcMomentError()
Calculate the momentum error.
Definition: momentumError.C:178
Foam::dev2
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:117
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:50
Foam::functionObjects::momentumError::execute
virtual bool execute()
Execute.
Definition: momentumError.C:194
Foam::fvc::laplacian
tmp< GeometricField< Type, fvPatchField, volMesh > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcLaplacian.C:47
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::functionObjects::momentumError::read
virtual bool read(const dictionary &)
Read the forces data.
Definition: momentumError.C:153
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
U
U
Definition: pEqn.H:72
fvcLaplacian.H
Calculate the laplacian of the given field.
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::ThermalDiffusivity
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Definition: phaseCompressibleTurbulenceModelFwd.H:47
fvcGrad.H
Calculate the gradient of the given field.
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::IncompressibleTurbulenceModel
Templated abstract base class for single-phase incompressible turbulence models.
Definition: IncompressibleTurbulenceModel.H:55
Foam::GeometricField< vector, fvPatchField, volMesh >::null
static const GeometricField< vector, fvPatchField, volMesh > & null()
Return a null geometric field.
Definition: GeometricFieldI.H:32
Foam::dimVolume
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:61
Foam::GeometricField< scalar, fvsPatchField, surfaceMesh >
turb
compressible::turbulenceModel & turb
Definition: setRegionFluidFields.H:10
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::functionObjects::momentumError::write
virtual bool write()
Write.
Definition: momentumError.C:202
turbulenceModel.H
turbulentFluidThermoModel.H
Foam::functionObjects::momentumError::momentumError
momentumError(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: momentumError.C:115