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-2021 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  const auto& U = lookupObject<volVectorField>(UName_);
59 
60  {
61  auto* turb = findObject<cmpTurbModel>
62  (
64  );
65 
66  if (turb)
67  {
68  tmp<volScalarField> trho = turb->rho();
69  tmp<volScalarField> tnuEff = turb->nuEff();
70 
71  if (zoneSubSetPtr_)
72  {
73  const fvMeshSubset& subsetter = zoneSubSetPtr_->subsetter();
74 
75  tU = subsetter.interpolate(U, false);
76  trho = subsetter.interpolate(turb->rho(), false);
77  tnuEff = subsetter.interpolate(turb->nuEff()(), false);
78  }
79 
81  (
82  "divDevRhoReff",
83  - fvc::div
84  (
85  (trho()*tnuEff())
86  *dev2(T(fvc::grad(tU()))),
87  "div(((rho*nuEff)*dev2(T(grad(U)))))"
88  )
90  (
91  trho()*tnuEff(),
92  tU(),
93  "laplacian(nuEff,U)"
94  )
95  );
96  }
97  }
98 
99  {
100  const auto* turb = findObject<icoTurbModel>
101  (
103  );
104 
105  if (turb)
106  {
107  tmp<volScalarField> tnuEff = turb->nuEff();
108 
109  if (zoneSubSetPtr_)
110  {
111  const fvMeshSubset& subsetter = zoneSubSetPtr_->subsetter();
112 
113  tU = subsetter.interpolate(U, false);
114  tnuEff = subsetter.interpolate(turb->nuEff()(), false);
115  }
116 
118  (
119  "divDevRhoReff",
120  - fvc::div
121  (
122  tnuEff()*dev2(T(fvc::grad(tU()))),
123  "div((nuEff*dev2(T(grad(U)))))"
124  )
125  - fvc::laplacian(tnuEff(), tU(), "laplacian(nuEff,U)")
126  );
127  }
128  }
129 
130  return volVectorField::null();
131 }
132 
133 
134 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
135 
137 (
138  const word& name,
139  const Time& runTime,
140  const dictionary& dict
141 )
142 :
144  pName_("p"),
145  UName_("U"),
146  phiName_("phi")
147 {
148  read(dict);
149 
150  const auto& phi =lookupObject<surfaceScalarField>(phiName_);
151 
152  const dimensionSet momDims
153  (
154  phi.dimensions()*dimVelocity/dimVolume
155  );
156 
157 
158  volVectorField* momentPtr = nullptr;
159 
160  word momName(scopedName("momentError"));
161 
162  if (zoneSubSetPtr_)
163  {
164  const fvMesh& subMesh = zoneSubSetPtr_->subsetter().subMesh();
165 
166  // momentErrorMap
167 
168  momentPtr = new volVectorField
169  (
170  IOobject
171  (
172  scopedName("momentErrorMap"),
173  subMesh.time().timeName(),
174  subMesh,
177  ),
178  subMesh,
179  dimensionedVector(momDims)
180  );
181 
182  subMesh.objectRegistry::store(momentPtr);
183 
184  momName = scopedName("momentErrorZone");
185  }
186 
187  momentPtr = new volVectorField
188  (
189  IOobject
190  (
191  momName,
192  time_.timeName(),
193  mesh_,
196  ),
197  mesh_,
198  dimensionedVector(momDims)
199  );
200 
201  mesh_.objectRegistry::store(momentPtr);
202 }
203 
204 
205 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
206 
208 {
210  {
211  Info<< type() << ' ' << name() << ':' << nl;
212 
213  // Optional field name entries
214  if (dict.readIfPresent<word>("p", pName_))
215  {
216  Info<< " p: " << pName_ << endl;
217  }
218  if (dict.readIfPresent<word>("U", UName_))
219  {
220  Info<< " U: " << UName_ << endl;
221  }
222 
223  if (dict.readIfPresent<word>("phi", phiName_))
224  {
225  Info<< " phi: " << phiName_ << endl;
226  }
227 
228  if (dict.found("cellZones"))
229  {
230  zoneSubSetPtr_.reset(new Detail::zoneSubSet(mesh_, dict));
231  }
232  else
233  {
234  zoneSubSetPtr_.reset(nullptr);
235  }
236 
237  return true;
238  }
239 
240  return false;
241 }
242 
243 
245 {
246  const auto& p = lookupObject<volScalarField>(pName_);
247  const auto& U = lookupObject<volVectorField>(UName_);
248  const auto& phi = lookupObject<surfaceScalarField>(phiName_);
249 
250  if (zoneSubSetPtr_)
251  {
252  const fvMeshSubset& subsetter = zoneSubSetPtr_->subsetter();
253 
254  fvMesh& subMesh = zoneSubSetPtr_->subsetter().subMesh();
255 
256  subMesh.fvSchemes::readOpt() = mesh_.fvSchemes::readOpt();
257  subMesh.fvSchemes::read();
258 
259  auto& momentErrMap =
261  (
262  scopedName("momentErrorMap")
263  );
264 
265  tmp<volScalarField> tp = subsetter.interpolate(p, false);
266  tmp<volVectorField> tU = subsetter.interpolate(U, false);
267  tmp<surfaceScalarField> tphi = subsetter.interpolate(phi, false);
268 
269  momentErrMap =
270  (
271  divDevRhoReff()
272  + fvc::div(tphi, tU, "div(phi,U)")
273  + fvc::grad(tp, "grad(p)")
274  );
275  }
276  else
277  {
278  auto& momentErr =
279  lookupObjectRef<volVectorField>(scopedName("momentError"));
280 
281  momentErr = fvc::div(phi, U) + fvc::grad(p) + divDevRhoReff();
282  }
283 }
284 
285 
287 {
288  calcMomentError();
289 
290  return true;
291 }
292 
293 
295 {
296  Log << " functionObjects::" << type() << " " << name();
297 
298  if (!zoneSubSetPtr_)
299  {
300  Log << " writing field: " << scopedName("momentError") << endl;
301 
302  const auto& momentErr =
303  lookupObjectRef<volVectorField>(scopedName("momentError"));
304 
305  momentErr.write();
306  }
307  else
308  {
309  Log << " writing field: " << scopedName("momentErrorMap") << endl;
310 
311  const fvMeshSubset& subsetter = zoneSubSetPtr_->subsetter();
312  const fvMesh& subMesh = subsetter.subMesh();
313 
314  const auto& momentErrMap =
316  (
317  scopedName("momentErrorMap")
318  );
319 
320  tmp<volVectorField> mapMomErr =
321  zoneSubSetPtr_->mapToZone<vector>(momentErrMap);
322 
323  mapMomErr().write();
324  }
325 
326  return true;
327 }
328 
329 
330 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
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:169
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
Log
#define Log
Definition: PDRblock.C:35
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:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::fvMeshSubset
Given the original mesh and the list of selected cells, it creates the mesh consisting only of the de...
Definition: fvMeshSubset.H:73
Foam::dimVelocity
const dimensionSet dimVelocity
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
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:369
Foam::functionObjects::momentumError::calcMomentError
void calcMomentError()
Calculate the momentum error.
Definition: momentumError.C:244
Foam::dimensionSet
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:108
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:286
Foam::fvc::laplacian
tmp< GeometricField< Type, fvPatchField, volMesh > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcLaplacian.C:47
trho
tmp< volScalarField > trho
Definition: setRegionSolidFields.H:4
Foam::Detail::zoneSubSet
Definition: zoneSubSet.H:98
Foam::fvMeshSubset::subMesh
const fvMesh & subMesh() const
Return reference to subset mesh.
Definition: fvMeshSubsetI.H:48
Foam::functionObjects::momentumError::zoneSubSetPtr_
autoPtr< Detail::zoneSubSet > zoneSubSetPtr_
Sub-set mesh.
Definition: momentumError.H:181
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
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:207
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::momentumError::UName_
word UName_
Name of velocity field.
Definition: momentumError.H:175
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
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::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::objectRegistry::lookupObjectRef
Type & lookupObjectRef(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:478
Foam::volVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:62
U
U
Definition: pEqn.H:72
Foam::fvMeshSubset::interpolate
static tmp< GeometricField< Type, fvPatchField, volMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &, const fvMesh &sMesh, const labelUList &patchMap, const labelUList &cellMap, const labelUList &faceMap, const bool allowUnmapped=false)
Map volume field. Optionally allow unmapped faces not to produce.
fvcLaplacian.H
Calculate the laplacian of the given field.
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::Vector< scalar >
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::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
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:60
Foam::GeometricField< vector, fvPatchField, volMesh >
turb
compressible::turbulenceModel & turb
Definition: setRegionFluidFields.H:10
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::functionObjects::momentumError::write
virtual bool write()
Write.
Definition: momentumError.C:294
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:137