fvMeshGeometry.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) 2011-2017 OpenFOAM Foundation
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 "fvMesh.H"
29 #include "Time.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 #include "slicedVolFields.H"
33 #include "slicedSurfaceFields.H"
34 #include "SubField.H"
35 #include "cyclicFvPatchFields.H"
36 #include "cyclicAMIFvPatchFields.H"
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
40 void Foam::fvMesh::makeSf() const
41 {
42  if (debug)
43  {
44  InfoInFunction << "Assembling face areas" << endl;
45  }
46 
47  // It is an error to attempt to recalculate
48  // if the pointer is already set
49  if (SfPtr_)
50  {
52  << "face areas already exist"
53  << abort(FatalError);
54  }
55 
56  SfPtr_ = new slicedSurfaceVectorField
57  (
58  IOobject
59  (
60  "S",
62  meshSubDir,
63  *this,
66  false
67  ),
68  *this,
69  dimArea,
70  faceAreas()
71  );
72 
73  SfPtr_->setOriented();
74 }
75 
76 
77 void Foam::fvMesh::makeMagSf() const
78 {
79  if (debug)
80  {
81  InfoInFunction << "Assembling mag face areas" << endl;
82  }
83 
84  // It is an error to attempt to recalculate
85  // if the pointer is already set
86  if (magSfPtr_)
87  {
89  << "mag face areas already exist"
90  << abort(FatalError);
91  }
92 
93  // Note: Added stabilisation for faces with exactly zero area.
94  // These should be caught on mesh checking but at least this stops
95  // the code from producing Nans.
96  magSfPtr_ = new surfaceScalarField
97  (
98  IOobject
99  (
100  "magSf",
101  pointsInstance(),
102  meshSubDir,
103  *this,
106  false
107  ),
108  mag(Sf()) + dimensionedScalar("vs", dimArea, VSMALL)
109  );
110 }
111 
112 
113 void Foam::fvMesh::makeC() const
114 {
115  if (debug)
116  {
117  InfoInFunction << "Assembling cell centres" << endl;
118  }
119 
120  // It is an error to attempt to recalculate
121  // if the pointer is already set
122  if (CPtr_)
123  {
125  << "cell centres already exist"
126  << abort(FatalError);
127  }
128 
129  // Construct as slices. Only preserve processor (not e.g. cyclic)
130 
131  CPtr_ = new slicedVolVectorField
132  (
133  IOobject
134  (
135  "C",
136  pointsInstance(),
137  meshSubDir,
138  *this,
141  false
142  ),
143  *this,
144  dimLength,
145  cellCentres(),
146  faceCentres(),
147  true, //preserveCouples
148  true //preserveProcOnly
149  );
150 }
151 
152 
153 void Foam::fvMesh::makeCf() const
154 {
155  if (debug)
156  {
157  InfoInFunction << "Assembling face centres" << endl;
158  }
159 
160  // It is an error to attempt to recalculate
161  // if the pointer is already set
162  if (CfPtr_)
163  {
165  << "face centres already exist"
166  << abort(FatalError);
167  }
168 
169  CfPtr_ = new slicedSurfaceVectorField
170  (
171  IOobject
172  (
173  "Cf",
174  pointsInstance(),
175  meshSubDir,
176  *this,
179  false
180  ),
181  *this,
182  dimLength,
183  faceCentres()
184  );
185 }
186 
187 
188 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
189 
191 {
192  if (!VPtr_)
193  {
194  if (debug)
195  {
197  << "Constructing from primitiveMesh::cellVolumes()" << endl;
198  }
199 
201  (
202  IOobject
203  (
204  "V",
205  time().timeName(),
206  *this,
209  false
210  ),
211  *this,
212  dimVolume,
213  cellVolumes()
214  );
215  }
216 
217  return *static_cast<slicedVolScalarField::Internal*>(VPtr_);
218 }
219 
220 
222 {
223  if (!V0Ptr_)
224  {
226  << "V0 is not available"
227  << abort(FatalError);
228  }
229 
230  return *V0Ptr_;
231 }
232 
233 
235 {
236  if (!V0Ptr_)
237  {
239  << "V0 is not available"
240  << abort(FatalError);
241  }
242 
243  return *V0Ptr_;
244 }
245 
246 
248 {
249  if (!V00Ptr_)
250  {
251  if (debug)
252  {
253  InfoInFunction << "Constructing from V0" << endl;
254  }
255 
257  (
258  IOobject
259  (
260  "V00",
261  time().timeName(),
262  *this,
265  true
266  ),
267  V0()
268  );
269 
270 
271  // If V00 is used then V0 should be stored for restart
272  V0Ptr_->writeOpt() = IOobject::AUTO_WRITE;
273  }
274 
275  return *V00Ptr_;
276 }
277 
278 
280 {
281  if (!steady() && moving() && time().subCycling())
282  {
283  const TimeState& ts = time();
284  const TimeState& ts0 = time().prevTimeState();
285 
286  scalar tFrac =
287  (
288  ts.value() - (ts0.value() - ts0.deltaTValue())
289  )/ts0.deltaTValue();
290 
291  if (tFrac < (1 - SMALL))
292  {
293  return V0() + tFrac*(V() - V0());
294  }
295  else
296  {
297  return V();
298  }
299  }
300  else
301  {
302  return V();
303  }
304 }
305 
306 
308 {
309  if (!steady() && moving() && time().subCycling())
310  {
311  const TimeState& ts = time();
312  const TimeState& ts0 = time().prevTimeState();
313 
314  scalar t0Frac =
315  (
316  (ts.value() - ts.deltaTValue())
317  - (ts0.value() - ts0.deltaTValue())
318  )/ts0.deltaTValue();
319 
320  if (t0Frac > SMALL)
321  {
322  return V0() + t0Frac*(V() - V0());
323  }
324  else
325  {
326  return V0();
327  }
328  }
329  else
330  {
331  return V0();
332  }
333 }
334 
335 
337 {
338  if (!SfPtr_)
339  {
340  makeSf();
341  }
342 
343  return *SfPtr_;
344 }
345 
346 
348 {
349  if (!magSfPtr_)
350  {
351  makeMagSf();
352  }
353 
354  return *magSfPtr_;
355 }
356 
357 
359 {
360  if (!CPtr_)
361  {
362  makeC();
363  }
364 
365  return *CPtr_;
366 }
367 
368 
370 {
371  if (!CfPtr_)
372  {
373  makeCf();
374  }
375 
376  return *CfPtr_;
377 }
378 
379 
381 {
382  if (debug)
383  {
384  InfoInFunction << "Calculating face deltas" << endl;
385  }
386 
388  (
390  (
391  IOobject
392  (
393  "delta",
394  pointsInstance(),
395  meshSubDir,
396  *this,
399  false
400  ),
401  *this,
402  dimLength
403  )
404  );
405  surfaceVectorField& delta = tdelta.ref();
406  delta.setOriented();
407 
408  const volVectorField& C = this->C();
409  const labelUList& owner = this->owner();
410  const labelUList& neighbour = this->neighbour();
411 
412  forAll(owner, facei)
413  {
414  delta[facei] = C[neighbour[facei]] - C[owner[facei]];
415  }
416 
417  surfaceVectorField::Boundary& deltabf = delta.boundaryFieldRef();
418 
419  forAll(deltabf, patchi)
420  {
421  deltabf[patchi] = boundary()[patchi].delta();
422  }
423 
424  return tdelta;
425 }
426 
427 
429 {
430  if (!phiPtr_)
431  {
433  << "mesh flux field does not exist, is the mesh actually moving?"
434  << abort(FatalError);
435  }
436 
437  // Set zero current time
438  // mesh motion fluxes if the time has been incremented
439  if (!time().subCycling() && phiPtr_->timeIndex() != time().timeIndex())
440  {
441  (*phiPtr_) = dimensionedScalar(dimVolume/dimTime, Zero);
442  }
443 
444  phiPtr_->setOriented();
445 
446  return *phiPtr_;
447 }
448 
449 
451 {
452  if (!phiPtr_)
453  {
455  << "mesh flux field does not exist, is the mesh actually moving?"
456  << abort(FatalError);
457  }
458 
459  return *phiPtr_;
460 }
461 
462 
463 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:316
Foam::slicedSurfaceVectorField
SlicedGeometricField< vector, fvsPatchField, slicedFvsPatchField, surfaceMesh > slicedSurfaceVectorField
Definition: slicedSurfaceFieldsFwd.H:66
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
SubField.H
Foam::slicedVolVectorField
SlicedGeometricField< vector, fvPatchField, slicedFvPatchField, volMesh > slicedVolVectorField
Definition: slicedVolFieldsFwd.H:66
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::fvMesh::Vsc0
tmp< DimensionedField< scalar, volMesh > > Vsc0() const
Return sub-cycle old-time cell volumes.
Definition: fvMeshGeometry.C:307
slicedVolFields.H
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:315
Foam::fvMesh::setPhi
surfaceScalarField & setPhi()
Return cell face motion fluxes.
Definition: fvMeshGeometry.C:450
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
surfaceFields.H
Foam::surfaceFields.
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:404
Foam::fvMesh::V00
const DimensionedField< scalar, volMesh > & V00() const
Return old-old-time cell volumes.
Definition: fvMeshGeometry.C:247
C
volScalarField & C
Definition: readThermalProperties.H:102
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::fvMesh::V0
const DimensionedField< scalar, volMesh > & V0() const
Return old-time cell volumes.
Definition: fvMeshGeometry.C:221
Foam::fvSchemes::debug
static int debug
Debug switch.
Definition: fvSchemes.H:105
Foam::polyMesh::pointsInstance
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:815
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:54
Foam::TimeState
The time value with time-stepping information, user-defined remapping, etc.
Definition: TimeState.H:51
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:258
Foam::dimArea
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:60
Foam::fvMesh::magSf
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
Definition: fvMeshGeometry.C:347
Foam::fvMesh::Vsc
tmp< DimensionedField< scalar, volMesh > > Vsc() const
Return sub-cycle cell volumes.
Definition: fvMeshGeometry.C:279
delta
scalar delta
Definition: LISASMDCalcMethod2.H:8
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::fvMesh::C
const volVectorField & C() const
Return cell centres as volVectorField.
Definition: fvMeshGeometry.C:358
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::FatalError
error FatalError
fvMesh.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::fvMesh::phi
const surfaceScalarField & phi() const
Return cell face motion fluxes.
Definition: fvMeshGeometry.C:428
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::surfaceScalarField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Definition: surfaceFieldsFwd.H:54
Foam::IOobject::IOobject
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:276
Foam::TimeState::deltaTValue
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:42
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::UList< label >
Foam::SlicedGeometricField::Internal
The internalField of a SlicedGeometricField.
Definition: SlicedGeometricField.H:196
slicedSurfaceFields.H
Foam::fvMesh::setV0
DimensionedField< scalar, volMesh > & setV0()
Return old-time cell volumes.
Definition: fvMeshGeometry.C:234
Foam::C
Graphite solid properties.
Definition: C.H:50
Foam::dimVolume
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:61
Foam::GeometricField< vector, fvsPatchField, surfaceMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
cyclicFvPatchFields.H
Foam::fvMesh::Cf
const surfaceVectorField & Cf() const
Return face centres as surfaceVectorField.
Definition: fvMeshGeometry.C:369
boundary
faceListList boundary
Definition: createBlockMesh.H:4
Foam::fvMesh::delta
tmp< surfaceVectorField > delta() const
Return face deltas as surfaceVectorField.
Definition: fvMeshGeometry.C:380
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
cyclicAMIFvPatchFields.H
Foam::fvMesh::V
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
Definition: fvMeshGeometry.C:190
Foam::primitiveMesh::faceAreas
const vectorField & faceAreas() const
Definition: primitiveMeshFaceCentresAndAreas.C:156
Foam::fvMesh::Sf
const surfaceVectorField & Sf() const
Return cell face area vectors.
Definition: fvMeshGeometry.C:336