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-------------------------------------------------------------------------------
10License
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
34namespace Foam
35{
37}
38
40
41
42// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43
44void 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
86:
88 (
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
112(
113 const word& surfName,
114 const objectRegistry& obr,
115 bool doCheckIn
116)
117:
119 (
121 (
122 surfName,
123 obr.time().constant(),
124 obr,
125 IOobject::NO_READ,
126 IOobject::NO_WRITE,
127 true
128 ),
129 doCheckIn
130 )
131{}
132
133
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
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
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
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 {
222 where |= FieldAssociation::FACE_DATA;
223 }
224 }
225
226 // Point Data
227 {
228 const objectRegistry* regptr =
229 cfindObject<objectRegistry>(pointDataName);
230
231 if (regptr && regptr->found(fieldName))
232 {
233 where |= FieldAssociation::POINT_DATA;
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(
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(
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
447namespace Foam
448{
449
450template<>
451const 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
461template<>
462const 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
482template<>
483const 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
500template<>
501const 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// ************************************************************************* //
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: MeshedSurface.H:99
const surfZoneList & surfZones() const
Const access to the surface zones.
pointField & storedPoints()
Non-const access to global points.
const List< Face > & surfFaces() const
Return const access to the faces.
List< Face > & storedFaces()
Non-const access to the faces.
A special purpose MeshedSurface that exposes the stored values for direct modification.
const Field< point_type > & points() const noexcept
Return reference to global points.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:50
virtual const faceList & faces() const =0
The faces used for the surface.
virtual const labelList & zoneIds() const
Per-face zone/region information.
Definition: meshedSurf.H:77
virtual const pointField & points() const =0
The points used for the surface.
Registry of regIOobjects.
const objectRegistry & subRegistry(const word &name, const bool forceCreate=false, const bool recursive=false) const
Lookup and return a const sub-objectRegistry.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
bool found(const word &name, const bool recursive=false) const
Can the regIOobject object be found (by name).
constant condensation/saturation model.
A surface mesh consisting of general polygon faces and capable of holding fields.
Definition: polySurface.H:71
virtual label size() const
Return number of faces.
Definition: polySurface.H:225
const objectRegistry & faceData() const
Face data are stored directly on the registry.
Definition: polySurface.C:198
void copySurface(const pointField &points, const faceList &faces, bool unused=false)
Update with new contents.
Definition: polySurface.C:280
label nFaceData() const
Number of main entries, without PointData sub-registry.
Definition: polySurface.C:170
virtual ~polySurface()
Destructor.
Definition: polySurface.C:162
const objectRegistry & pointData() const
Point data are stored in a sub-registry.
Definition: polySurface.C:204
label nPointData() const
Number of entries on PointData sub-registry (if it exists)
Definition: polySurface.C:184
FieldAssociation
Enumeration for the field association.
Definition: polySurface.H:76
void transfer(pointField &&points, faceList &&faces, labelList &&zoneIds=labelList())
Transfer the contents of the argument and annul the argument.
Definition: polySurface.C:371
FieldAssociation queryFieldAssociation(const word &fieldName) const
Query the field association (FACE or POINT)
Definition: polySurface.C:212
static const word pointDataName
Name for point fields sub-registry.
Definition: polySurface.H:149
const regIOobject * findFieldObject(const word &fieldName, const FieldAssociation association) const
Definition: polySurface.C:242
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const pointField & points
label nPoints
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130