polySurface.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) 2019 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 "polySurface.H"
29 #include "Time.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(polySurface, 0);
37 }
38 
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::polySurface::calculateZoneIds(const UList<surfZone>& zones)
45 {
46  if (returnReduce(zones.empty(), andOp<bool>()))
47  {
48  zoneIds_.clear();
49  return;
50  }
51 
52  // Extra safety, ensure we have at some zones
53  // and they cover all the faces - fix start silently
54 
55  zoneIds_.resize(size(), Zero);
56 
57  label off = 0;
58  for (const surfZone& zn : zones)
59  {
60  const label sz = zn.size();
61 
62  SubList<label>(zoneIds_, sz, off) = zn.index();
63 
64  off += zn.size();
65  }
66 
67  if (off < size())
68  {
70  << "More faces " << size() << " than zones " << off << endl;
71 
72  SubList<label>(zoneIds_, size()-off, off) = zones.last().index();
73  }
74  else if (size() < off)
75  {
77  << "More zones " << off << " than faces " << size()
78  << exit(FatalError);
79  }
80 }
81 
82 
83 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
84 
85 Foam::polySurface::polySurface(const IOobject& io, bool doCheckIn)
86 :
88  (
89  IOobject
90  (
91  io.name(),
92  io.db().time().constant(),
93  io.db(),
94  IOobject::NO_READ,
95  IOobject::NO_WRITE,
96  true
97  )
98  ),
100  zoneIds_()
101 {
102  // Created without a point field sub-registry
103 
104  if (doCheckIn)
105  {
106  this->store();
107  }
108 }
109 
110 
111 Foam::polySurface::polySurface
112 (
113  const word& surfName,
114  const objectRegistry& obr,
115  bool doCheckIn
116 )
117 :
119  (
120  IOobject
121  (
122  surfName,
123  obr.time().constant(),
124  obr,
127  true
128  ),
129  doCheckIn
130  )
131 {}
132 
133 
134 Foam::polySurface::polySurface
135 (
136  const IOobject& io,
137  const MeshedSurface<face>& surf,
138  bool doCheckIn
139 )
140 :
141  polySurface(io, doCheckIn)
142 {
143  copySurface(surf);
144 }
145 
146 
147 Foam::polySurface::polySurface
148 (
149  const IOobject& io,
150  MeshedSurface<face>&& surf,
151  bool doCheckIn
152 )
153 :
154  polySurface(io, doCheckIn)
155 {
156  transfer(surf);
157 }
158 
159 
160 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
161 
163 {
165 }
166 
167 
168 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
169 
170 Foam::label Foam::polySurface::nFaceData() const
171 {
172  label count = objectRegistry::size();
173 
174  // Remove PointData sub-registry from being included in the count
175  if (objectRegistry::foundObject<objectRegistry>(pointDataName))
176  {
177  --count;
178  }
179 
180  return count;
181 }
182 
183 
184 Foam::label Foam::polySurface::nPointData() const
185 {
186  const objectRegistry* subreg =
187  objectRegistry::cfindObject<objectRegistry>(pointDataName);
188 
189  if (subreg)
190  {
191  return subreg->size();
192  }
193 
194  return 0;
195 }
196 
197 
199 {
200  return static_cast<const objectRegistry&>(*this);
201 }
202 
203 
205 {
206  // Force create on access
207  return objectRegistry::subRegistry(pointDataName, true);
208 }
209 
210 
213 {
214  unsigned where(FieldAssociation::NO_DATA);
215 
216  // Face Data
217  {
218  const objectRegistry* regptr = this;
219 
220  if (regptr && regptr->found(fieldName))
221  {
223  }
224  }
225 
226  // Point Data
227  {
228  const objectRegistry* regptr =
229  cfindObject<objectRegistry>(pointDataName);
230 
231  if (regptr && regptr->found(fieldName))
232  {
234  }
235  }
236 
237  return FieldAssociation(where);
238 }
239 
240 
242 (
243  const word& fieldName,
244  enum FieldAssociation association
245 ) const
246 {
247  const unsigned where(association);
248 
249 
250  const regIOobject* ioptr = nullptr;
251 
252  // Face Data
253  if (where & FieldAssociation::FACE_DATA)
254  {
255  const objectRegistry* regptr = this;
256 
257  if (regptr && (ioptr = regptr->cfindObject<regIOobject>(fieldName)))
258  {
259  return ioptr;
260  }
261  }
262 
263  // Point Data
264  if (where & FieldAssociation::POINT_DATA)
265  {
266  const objectRegistry* regptr =
267  cfindObject<objectRegistry>(pointDataName);
268 
269  if (regptr && (ioptr = regptr->cfindObject<regIOobject>(fieldName)))
270  {
271  return ioptr;
272  }
273  }
274 
275  return ioptr;
276 }
277 
278 
280 (
281  const pointField& points,
282  const faceList& faces,
283  bool unused
284 )
285 {
286  clearOut(); // Clear addressing
287 
288  if
289  (
290  this->nPoints() != points.size()
291  || this->nFaces() != faces.size()
292  )
293  {
294  // Geometry changed
295  clearFields();
296  }
297 
298  this->storedPoints() = points;
299  this->storedFaces() = faces;
300 
301  zoneIds_.clear();
302 
303  // if (validate)
304  // {
305  // checkZones();
306  // }
307 }
308 
309 
311 (
312  const meshedSurf& surf,
313  bool unused
314 )
315 {
316  clearOut(); // Clear addressing
317 
318  if
319  (
320  this->nPoints() != surf.points().size()
321  || this->nFaces() != surf.faces().size()
322  )
323  {
324  // Geometry changed
325  clearFields();
326  }
327 
328  this->storedPoints() = surf.points();
329  this->storedFaces() = surf.faces();
330 
331  zoneIds_ = surf.zoneIds();
332 
333  // if (validate)
334  // {
335  // checkZones();
336  // }
337 }
338 
339 
341 (
342  const MeshedSurface<face>& surf,
343  bool unused
344 )
345 {
346  clearOut(); // Clear addressing
347 
348  if
349  (
350  this->nPoints() != surf.points().size()
351  || this->nFaces() != surf.surfFaces().size()
352  )
353  {
354  // Geometry changed
355  clearFields();
356  }
357 
358  this->storedPoints() = surf.points();
359  this->storedFaces() = surf.surfFaces();
360 
361  calculateZoneIds(surf.surfZones());
362 
363  // if (validate)
364  // {
365  // checkZones();
366  // }
367 }
368 
369 
371 (
372  pointField&& points,
373  faceList&& faces,
374  labelList&& zoneIds
375 )
376 {
377  clearOut(); // Clear addressing
378  clearFields();
379 
380  this->storedPoints().transfer(points);
381  this->storedFaces().transfer(faces);
382  zoneIds_.transfer(zoneIds);
383 }
384 
385 
387 (
388  MeshedSurface<face>& surf,
389  bool unused
390 )
391 {
392  clearOut(); // Clear addressing
393  clearFields();
394 
395  ModifiableMeshedSurface<face> tsurf(std::move(surf));
396 
397  this->storedPoints().transfer(tsurf.storedPoints());
398  this->storedFaces().transfer(tsurf.storedFaces());
399 
400  calculateZoneIds(tsurf.surfZones());
401 
402  // if (validate)
403  // {
404  // checkZones();
405  // }
406 }
407 
408 
409 // void Foam::polySurface::checkZones()
410 // {
411 // // Extra safety, ensure we have at some zones
412 // // and they cover all the faces - fix start silently
413 //
414 // if (surfZones_.size() <= 1)
415 // {
416 // removeZones();
417 // return;
418 // }
419 //
420 // label count = 0;
421 // for (surfZone& zn : surfZones_)
422 // {
423 // zn.start() = count;
424 // count += zn.size();
425 // }
426 //
427 // if (count < nFaces())
428 // {
429 // WarningInFunction
430 // << "More faces " << nFaces() << " than zones " << count
431 // << " ... extending final zone"
432 // << endl;
433 //
434 // surfZones_.last().size() += count - nFaces();
435 // }
436 // else if (size() < count)
437 // {
438 // FatalErrorInFunction
439 // << "More zones " << count << " than faces " << nFaces()
440 // << exit(FatalError);
441 // }
442 // }
443 
444 
445 // * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * //
446 
447 namespace Foam
448 {
449 
450 template<>
451 const regIOobject* polySurface::findFieldObject<polySurfaceGeoMesh>
452 (
453  const word& fieldName
454 ) const
455 {
456  // Face Data (main registry)
457  return cfindObject<regIOobject>(fieldName);
458 }
459 
460 
461 template<>
462 const regIOobject* polySurface::findFieldObject<polySurfacePointGeoMesh>
463 (
464  const word& fieldName
465 ) const
466 {
467  // Point Data (sub-registry)
468 
469  const objectRegistry* subreg =
470  objectRegistry::cfindObject<objectRegistry>(pointDataName);
471 
472  if (subreg)
473  {
474  return subreg->cfindObject<regIOobject>(fieldName);
475  }
476 
477  return nullptr;
478 }
479 
480 
481 
482 template<>
483 const objectRegistry* polySurface::whichRegistry<polySurfaceGeoMesh>
484 (
485  const word& fieldName
486 ) const
487 {
488  // Face Data (main registry)
489  const objectRegistry* subreg = this;
490 
491  if (subreg->found(fieldName))
492  {
493  return subreg;
494  }
495 
496  return nullptr;
497 }
498 
499 
500 template<>
501 const objectRegistry* polySurface::whichRegistry<polySurfacePointGeoMesh>
502 (
503  const word& fieldName
504 ) const
505 {
506  // Point Data (sub registry)
507 
508  const objectRegistry* subreg =
509  objectRegistry::cfindObject<objectRegistry>(pointDataName);
510 
511  if (subreg && subreg->found(fieldName))
512  {
513  return subreg;
514  }
515 
516  return nullptr;
517 }
518 
519 } // End of namespace
520 
521 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::HashTable< regIOobject * >::size
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::MeshedSurface::surfZones
const surfZoneList & surfZones() const
Const access to the surface zones.
Definition: MeshedSurface.H:429
Foam::polySurface::nFaceData
label nFaceData() const
Number of main entries, without PointData sub-registry.
Definition: polySurface.C:170
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::MeshedSurface::storedFaces
List< Face > & storedFaces()
Non-const access to the faces.
Definition: MeshedSurface.H:173
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
ModifiableMeshedSurface.H
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
polySurface.H
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::polySurface::findFieldObject
const regIOobject * findFieldObject(const word &fieldName, const FieldAssociation association) const
Definition: polySurface.C:242
Foam::MeshedSurface::storedPoints
pointField & storedPoints()
Non-const access to global points.
Definition: MeshedSurface.H:167
Foam::polySurface::faceData
const objectRegistry & faceData() const
Face data are stored directly on the registry.
Definition: polySurface.C:198
Foam::polySurface::~polySurface
virtual ~polySurface()
Destructor.
Definition: polySurface.C:162
Foam::polySurface::FieldAssociation
FieldAssociation
Enumeration for the field association.
Definition: polySurface.H:76
Foam::expressions::NO_DATA
No data.
Definition: exprFieldAssociation.H:45
Foam::polySurface::transfer
void transfer(pointField &&points, faceList &&faces, labelList &&zoneIds=labelList())
Transfer the contents of the argument and annul the argument.
Definition: polySurface.C:371
Foam::meshedSurf::faces
virtual const faceList & faces() const =0
The faces used for the surface.
Foam::meshedSurf
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:49
Foam::MeshedSurface::surfFaces
const List< Face > & surfFaces() const
Return const access to the faces.
Definition: MeshedSurface.H:413
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::regIOobject::store
bool store()
Definition: regIOobjectI.H:37
Foam::expressions::FieldAssociation
FieldAssociation
Definition: exprFieldAssociation.H:43
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::polySurface
A surface mesh consisting of general polygon faces and capable of holding fields.
Definition: polySurface.H:67
Foam::expressions::FACE_DATA
Face data.
Definition: exprFieldAssociation.H:47
Foam::Field< vector >
Foam::polySurface::copySurface
void copySurface(const pointField &points, const faceList &faces, bool unused=false)
Update with new contents.
Definition: polySurface.C:280
Foam::polySurface::pointDataName
static const word pointDataName
Name for point fields sub-registry.
Definition: polySurface.H:150
Foam::meshedSurf::points
virtual const pointField & points() const =0
The points used for the surface.
Foam::FatalError
error FatalError
Foam::objectRegistry::found
bool found(const word &name, const bool recursive=false) const
Can the regIOobject object be found (by name).
Definition: objectRegistry.C:432
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polySurface::queryFieldAssociation
FieldAssociation queryFieldAssociation(const word &fieldName) const
Query the field association (FACE or POINT)
Definition: polySurface.C:212
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Time.H
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::objectRegistry::cfindObject
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Definition: objectRegistryTemplates.C:390
Foam::objectRegistry::subRegistry
const objectRegistry & subRegistry(const word &name, const bool forceCreate=false, const bool recursive=false) const
Lookup and return a const sub-objectRegistry.
Definition: objectRegistry.C:174
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::List< face >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
Foam::expressions::POINT_DATA
Point data.
Definition: exprFieldAssociation.H:46
Foam::meshedSurf::zoneIds
virtual const labelList & zoneIds() const
Per-face zone/region information.
Definition: meshedSurf.H:77
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::polySurface::pointData
const objectRegistry & pointData() const
Point data are stored in a sub-registry.
Definition: polySurface.C:204
Foam::polySurface::size
virtual label size() const
Return number of faces.
Definition: polySurface.H:226
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
Foam::MeshedSurface< face >
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::ModifiableMeshedSurface
A special purpose MeshedSurface that exposes the stored values for direct modification.
Definition: ModifiableMeshedSurface.H:52
constant
constant condensation/saturation model.
Foam::MeshedSurface::size
label size() const
The surface size is the number of faces.
Definition: MeshedSurface.H:407
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178
Foam::PrimitivePatch<::Foam::List< face >, pointField >
Foam::polySurface::nPointData
label nPointData() const
Number of entries on PointData sub-registry (if it exists)
Definition: polySurface.C:184