fvMeshGeometry.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "fvMesh.H"
27 #include "Time.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 #include "slicedVolFields.H"
31 #include "slicedSurfaceFields.H"
32 #include "SubField.H"
33 #include "cyclicFvPatchFields.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 void Foam::fvMesh::makeSf() const
38 {
39  DebugInFunction << "Assembling face areas" << endl;
40 
41  // It is an error to attempt to recalculate
42  // if the pointer is already set
43  if (SfSlicePtr_ || SfPtr_)
44  {
46  << "face areas already exist"
47  << abort(FatalError);
48  }
49 
50  SfSlicePtr_ = new slicedSurfaceVectorField
51  (
52  IOobject
53  (
54  "Sf",
56  meshSubDir,
57  *this,
60  true
61  ),
62  *this,
63  dimArea,
64  faceAreas()
65  );
66 }
67 
68 
69 void Foam::fvMesh::makeMagSf() const
70 {
71  DebugInFunction << "Assembling mag face areas" << endl;
72 
73  // It is an error to attempt to recalculate
74  // if the pointer is already set
75  if (magSfSlicePtr_ || magSfPtr_)
76  {
78  << "mag face areas already exist"
79  << abort(FatalError);
80  }
81 
82  magSfSlicePtr_ = new slicedSurfaceScalarField
83  (
84  IOobject
85  (
86  "magSf",
87  pointsInstance(),
88  meshSubDir,
89  *this,
92  true
93  ),
94  *this,
95  dimArea,
96  magFaceAreas()
97  );
98 }
99 
100 
101 void Foam::fvMesh::makeC() const
102 {
103  DebugInFunction << "Assembling cell centres" << endl;
104 
105  // It is an error to attempt to recalculate
106  // if the pointer is already set
107  if (CSlicePtr_ || CPtr_)
108  {
110  << "cell centres already exist"
111  << abort(FatalError);
112  }
113 
114  // Construct as slices. Only preserve processor (not e.g. cyclic)
115 
116  CSlicePtr_ = new slicedVolVectorField
117  (
118  IOobject
119  (
120  "Cc",
121  pointsInstance(),
122  meshSubDir,
123  *this,
126  true
127  ),
128  *this,
129  dimLength,
130  cellCentres(),
131  faceCentres(),
132  true, // preserveCouples
133  true // preserveProcOnly
134  );
135 }
136 
137 
138 void Foam::fvMesh::makeCf() const
139 {
140  DebugInFunction << "Assembling face centres" << endl;
141 
142  // It is an error to attempt to recalculate
143  // if the pointer is already set
144  if (CfSlicePtr_ || CfPtr_)
145  {
147  << "face centres already exist"
148  << abort(FatalError);
149  }
150 
151  CfSlicePtr_ = new slicedSurfaceVectorField
152  (
153  IOobject
154  (
155  "Cf",
156  pointsInstance(),
157  meshSubDir,
158  *this,
161  true
162  ),
163  *this,
164  dimLength,
165  faceCentres()
166  );
167 }
168 
169 
170 Foam::surfaceVectorField& Foam::fvMesh::SfRef()
171 {
172  if (!SfPtr_)
173  {
174  SfPtr_ = Sf().cloneUnSliced().ptr();
175 
176  deleteDemandDrivenData(SfSlicePtr_);
177  }
178 
179  return *SfPtr_;
180 }
181 
182 
183 Foam::surfaceScalarField& Foam::fvMesh::magSfRef()
184 {
185  if (!magSfPtr_)
186  {
187  magSfPtr_ = magSf().cloneUnSliced().ptr();
188 
189  deleteDemandDrivenData(magSfSlicePtr_);
190  }
191 
192  return *magSfPtr_;
193 }
194 
195 
196 Foam::volVectorField& Foam::fvMesh::CRef()
197 {
198  if (!CPtr_)
199  {
200  CPtr_ = C().cloneUnSliced().ptr();
201 
202  deleteDemandDrivenData(CSlicePtr_);
203  }
204 
205  return *CPtr_;
206 }
207 
208 
209 Foam::surfaceVectorField& Foam::fvMesh::CfRef()
210 {
211  if (!CfPtr_)
212  {
213  CfPtr_ = Cf().cloneUnSliced().ptr();
214 
215  deleteDemandDrivenData(CfSlicePtr_);
216  }
217 
218  return *CfPtr_;
219 }
220 
221 
222 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
223 
225 {
226  if (!VPtr_)
227  {
229  << "Constructing from primitiveMesh::cellVolumes()" << endl;
230 
232  (
233  IOobject
234  (
235  "Vc",
236  time().name(),
237  *this,
240  true
241  ),
242  *this,
243  dimVolume,
244  cellVolumes()
245  );
246  }
247 
248  return *VPtr_;
249 }
250 
251 
253 {
254  if (!V0Ptr_ || Foam::isNull(V0Ptr_))
255  {
257  << "Vc0 is not available"
258  << abort(FatalError);
259  }
260 
261  return *V0Ptr_;
262 }
263 
264 
266 {
267  if (!V00Ptr_)
268  {
269  V00Ptr_ = NullObjectPtr<DimensionedField<scalar, fvMesh>>();
270  }
271 
272  if (Foam::isNull(V00Ptr_))
273  {
274  return V0();
275  }
276 
277  return *V00Ptr_;
278 }
279 
280 
282 {
283  if (moving() && time().subCycling())
284  {
285  const TimeState& ts = time();
286  const TimeState& ts0 = time().prevTimeState();
287 
288  scalar tFrac =
289  (
290  ts.value() - (ts0.value() - ts0.deltaTValue())
291  )/ts0.deltaTValue();
292 
293  if (tFrac < (1 - small))
294  {
295  return V0() + tFrac*(V() - V0());
296  }
297  else
298  {
299  return V();
300  }
301  }
302  else
303  {
304  return V();
305  }
306 }
307 
308 
310 {
311  if (moving() && time().subCycling())
312  {
313  const TimeState& ts = time();
314  const TimeState& ts0 = time().prevTimeState();
315 
316  scalar t0Frac =
317  (
318  (ts.value() - ts.deltaTValue())
319  - (ts0.value() - ts0.deltaTValue())
320  )/ts0.deltaTValue();
321 
322  if (t0Frac > small)
323  {
324  return V0() + t0Frac*(V() - V0());
325  }
326  else
327  {
328  return V0();
329  }
330  }
331  else
332  {
333  return V0();
334  }
335 }
336 
337 
339 {
340  if (SfPtr_)
341  {
342  return *SfPtr_;
343  }
344 
345  if (!SfSlicePtr_)
346  {
347  makeSf();
348  }
349 
350  return *SfSlicePtr_;
351 }
352 
353 
355 {
356  if (magSfPtr_)
357  {
358  return *magSfPtr_;
359  }
360 
361  if (!magSfSlicePtr_)
362  {
363  makeMagSf();
364  }
365 
366  return *magSfSlicePtr_;
367 }
368 
369 
371 {
372  return surfaceVectorField::New("nf", Sf()/magSf());
373 }
374 
375 
377 {
378  if (CPtr_)
379  {
380  return *CPtr_;
381  }
382 
383  if (!CSlicePtr_)
384  {
385  makeC();
386  }
387 
388  return *CSlicePtr_;
389 }
390 
391 
393 {
394  if (CfPtr_)
395  {
396  return *CfPtr_;
397  }
398 
399  if (!CfSlicePtr_)
400  {
401  makeCf();
402  }
403 
404  return *CfSlicePtr_;
405 }
406 
407 
409 {
410  DebugInFunction << "Calculating face deltas" << endl;
411 
413  (
415  (
416  "delta",
417  *this,
418  dimLength
419  )
420  );
421  surfaceVectorField& delta = tdelta.ref();
422 
423  const volVectorField& C = this->C();
424  const labelUList& owner = this->owner();
425  const labelUList& neighbour = this->neighbour();
426 
427  forAll(owner, facei)
428  {
429  delta[facei] = C[neighbour[facei]] - C[owner[facei]];
430  }
431 
433  delta.boundaryFieldRef();
434 
435  forAll(deltabf, patchi)
436  {
437  deltabf[patchi] = boundary()[patchi].delta();
438  }
439 
440  return tdelta;
441 }
442 
443 
445 {
446  if (!phiPtr_)
447  {
449  << "mesh flux field does not exist, is the mesh actually moving?"
450  << abort(FatalError);
451  }
452 
453  // Set zero current time
454  // mesh motion fluxes if the time has been incremented
455  if (!time().subCycling() && phiPtr_->timeIndex() != time().timeIndex())
456  {
457  (*phiPtr_) = dimensionedScalar(dimVolume/dimTime, 0);
458  }
459 
460  return *phiPtr_;
461 }
462 
463 
464 Foam::surfaceScalarField& Foam::fvMesh::phiRef()
465 {
466  if (!phiPtr_)
467  {
469  << "mesh flux field does not exist, is the mesh actually moving?"
470  << abort(FatalError);
471  }
472 
473  return *phiPtr_;
474 }
475 
476 
477 // ************************************************************************* //
scalar delta
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Graphite solid properties.
Definition: C.H:51
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic GeometricBoundaryField class.
Generic GeometricField class.
static tmp< GeometricField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Internal &, const PtrList< Patch > &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
tmp< GeometricField< Type, GeoMesh, PrimitiveField > > cloneUnSliced() const
Clone un-sliced.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
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:164
Specialisation of DimensionedField which holds a slice of a given complete field in such a form that ...
The time value with time-stepping information, user-defined remapping, etc.
Definition: TimeState.H:55
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:34
const Type & value() const
Return const reference to value.
const volVectorField & C() const
Return cell centres.
const DimensionedField< scalar, fvMesh > & V() const
Return cell volumes.
const DimensionedField< scalar, fvMesh > & V00() const
Return old-old-time cell volumes.
const surfaceScalarField & phi() const
Return cell face motion fluxes.
tmp< surfaceVectorField > nf() const
Return cell face normal vectors.
const surfaceVectorField & Cf() const
Return face centres.
const DimensionedField< scalar, fvMesh > & V0() const
Return old-time cell volumes.
const surfaceVectorField & Sf() const
Return cell face area vectors.
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
tmp< DimensionedField< scalar, fvMesh > > Vsc0() const
Return sub-cycle old-time cell volumes.
tmp< surfaceVectorField > delta() const
Return face deltas as surfaceVectorField.
tmp< DimensionedField< scalar, fvMesh > > Vsc() const
Return sub-cycle cell volumes.
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:1006
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:263
const vectorField & faceAreas() const
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
#define DebugInFunction
Report an information message using Foam::Info.
const dimensionSet time
static const coefficient C("C", dimTemperature, 234.5)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
const dimensionSet & dimLength
Definition: dimensions.C:141
void deleteDemandDrivenData(DataType *&dataPtr)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const dimensionSet & dimVolume
Definition: dimensions.C:150
const dimensionSet & dimTime
Definition: dimensions.C:142
SlicedGeometricField< vector, surfaceMesh > slicedSurfaceVectorField
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
bool isNull(const T &t)
Return true if t is a reference to the nullObject of type T.
Definition: nullObjectI.H:58
SlicedGeometricField< scalar, surfaceMesh > slicedSurfaceScalarField
error FatalError
const dimensionSet & dimArea
Definition: dimensions.C:149
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
SlicedGeometricField< vector, fvMesh > slicedVolVectorField
label timeIndex
Definition: getTimeIndex.H:4
faceListList boundary(nPatches)
Foam::surfaceFields.