surfMesh.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-2016 OpenFOAM Foundation
9 Copyright (C) 2016-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "surfMesh.H"
30#include "meshedSurf.H"
31#include "MeshedSurfaceProxy.H"
32
33#include "Time.H"
34#include "OSspecific.H"
35#include "MeshedSurface.H"
36
37// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38
39namespace Foam
40{
42}
43
45
46
47// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48
49// void Foam::surfMesh::oneZone()
50// {
51// word zoneName;
52//
53// if (surfZones_.size())
54// {
55// zoneName = surfZones_[0].name();
56// }
57// if (zoneName.empty())
58// {
59// zoneName = "zone0";
60// }
61//
62// // Set single default zone with nFaces
63// surfZones_.resize(1);
64// surfZones_[0] = surfZone(zoneName, nFaces());
65// }
66
67
68// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
69
71{
72 // Synchronize UList reference to the faces
73 static_cast<MeshReference&>(*this).shallowCopy
74 (
75 this->storedFaces()
76 );
77}
78
79
80// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81
83:
84 surfMesh(io, io.name())
85{}
86
87
88Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
89:
90 surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
92 (
94 (
95 "points",
96 time().findInstance(meshDir(), "points"),
97 meshSubDir,
98 *this,
99 IOobject::MUST_READ,
100 IOobject::NO_WRITE
101 ),
103 (
104 "faces",
105 time().findInstance(meshDir(), "faces"),
106 meshSubDir,
107 *this,
108 IOobject::MUST_READ,
109 IOobject::NO_WRITE
110 )
111 ),
112 MeshReference(this->storedIOFaces(), this->storedIOPoints()),
113
114 surfZones_
115 (
117 (
118 "surfZones",
119 time().findInstance(meshDir(), "surfZones"),
120 meshSubDir,
121 *this,
122 IOobject::READ_IF_PRESENT,
123 IOobject::NO_WRITE
124 )
125 )
126{}
127
128
130(
131 const word& surfName,
132 const objectRegistry& obr
133)
134:
135 surfaceRegistry(obr, surfName),
137 (
139 (
140 "points",
141 instance(),
142 meshSubDir,
143 *this,
144 IOobject::NO_READ,
145 IOobject::NO_WRITE
146 ),
148 (
149 "faces",
150 instance(),
151 meshSubDir,
152 *this,
153 IOobject::NO_READ,
154 IOobject::NO_WRITE
155 )
156 ),
157 MeshReference(this->storedIOFaces(), this->storedIOPoints()),
158
159 surfZones_
160 (
162 (
163 "surfZones",
164 instance(),
165 meshSubDir,
166 *this,
167 IOobject::NO_READ,
168 IOobject::NO_WRITE
169 )
170 )
171{}
172
173
175(
176 const IOobject& io,
177 const MeshedSurface<face>& surf,
178 const word& surfName
179)
180:
181 surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
183 (
185 (
186 "points",
187 instance(),
188 meshSubDir,
189 *this,
190 IOobject::NO_READ,
191 io.writeOpt()
192 ),
194 (
195 "faces",
196 instance(),
197 meshSubDir,
198 *this,
199 IOobject::NO_READ,
200 io.writeOpt()
201 )
202 ),
203 MeshReference(this->storedIOFaces(), this->storedIOPoints()),
204
205 surfZones_
206 (
208 (
209 "surfZones",
210 instance(),
211 meshSubDir,
212 *this,
213 IOobject::NO_READ,
214 io.writeOpt()
215 )
216 )
217{
219 <<"IOobject: " << io.path() << nl
220 <<" name: " << io.name()
221 <<" instance: " << io.instance()
222 <<" local: " << io.local()
223 <<" dbDir: " << io.db().dbDir() << nl
224 <<"creating surfMesh at instance " << instance() << endl;
225
226 copySurface(surf);
227}
228
229
231(
232 const IOobject& io,
233 MeshedSurface<face>&& surf,
234 const word& surfName
235)
236:
237 surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
239 (
241 (
242 "points",
243 instance(),
244 meshSubDir,
245 *this,
246 io.readOpt(),
247 io.writeOpt()
248 ),
250 (
251 "faces",
252 instance(),
253 meshSubDir,
254 *this,
255 io.readOpt(),
256 io.writeOpt()
257 )
258 ),
259 MeshReference(this->storedIOFaces(), this->storedIOPoints()),
260
261 surfZones_
262 (
264 (
265 "surfZones",
266 instance(),
267 meshSubDir,
268 *this,
269 io.readOpt(),
270 io.writeOpt()
271 )
272 )
273{
275 <<"IOobject: " << io.path() << nl
276 <<" name: " << io.name()
277 <<" instance: " << io.instance()
278 <<" local: " << io.local()
279 <<" dbDir: " << io.db().dbDir() << nl
280 <<"creating surfMesh at instance " << instance() << nl
281 <<"timeName: " << instance() << endl;
282
283 transfer(surf);
284}
285
286
287// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
288
290{
291 clearOut(); // Clear addressing
292}
293
294
295// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
296
298(
299 const pointField& points,
300 const faceList& faces,
301 bool validate
302)
303{
304 clearOut(); // Clear addressing
305
306 if
307 (
308 this->nPoints() != points.size()
309 || this->nFaces() != faces.size()
310 )
311 {
312 // Geometry changed
313 clearFields();
314 }
315
316 this->storedIOPoints() = points;
317 this->storedIOFaces() = faces;
318 surfZones_.clear();
319
320 this->updateRefs();
321
322 // No zones
323}
324
325
327(
328 const meshedSurf& surf,
329 bool validate
330)
331{
332 clearOut(); // Clear addressing
333
334 if
335 (
336 this->nPoints() != surf.points().size()
337 || this->nFaces() != surf.faces().size()
338 )
339 {
340 // Geometry changed
341 clearFields();
342 }
343
344 this->storedIOPoints() = surf.points();
345 this->storedIOFaces() = surf.faces();
346 surfZones_.clear();
347
348 this->updateRefs();
349
350 // No zones
351}
352
353
355(
356 const MeshedSurface<face>& surf,
357 bool validate
358)
359{
360 clearOut(); // Clear addressing
361
362 if
363 (
364 this->nPoints() != surf.points().size()
365 || this->nFaces() != surf.surfFaces().size()
366 )
367 {
368 // Geometry changed
369 clearFields();
370 }
371
372 this->storedIOPoints() = surf.points();
373 this->storedIOFaces() = surf.surfFaces();
374 surfZones_ = surf.surfZones();
375
376 this->updateRefs();
377
378 if (validate)
379 {
380 checkZones();
381 }
382}
383
384
386(
388 bool validate
389)
390{
391 clearOut(); // Clear addressing
392
393 this->storedPoints().transfer(surf.storedPoints());
394 this->storedFaces().transfer(surf.storedFaces());
395 this->storedZones().transfer(surf.storedZones());
396
397 this->updateRefs();
398
399 if (validate)
400 {
401 checkZones();
402 }
403}
404
405
408{
409 clearOut(); // Clear addressing
410 clearFields();
411
412 // Start with an empty geometry
414
415 // Transfer in content
416 aptr->storedPoints().transfer(this->storedPoints());
417 aptr->storedFaces().transfer(this->storedFaces());
418 aptr->storedZones().transfer(this->storedZones());
419
420 this->updateRefs(); // This may not be needed...
421
422 return aptr;
423}
424
425
427{
428 return dbDir()/meshSubDir;
429}
430
431
433{
434 return this->storedIOPoints().instance();
435}
436
437
439{
440 return this->storedIOFaces().instance();
441}
442
443
444Foam::label Foam::surfMesh::nPoints() const
445{
446 return this->points().size();
447}
448
449
450Foam::label Foam::surfMesh::nFaces() const
451{
452 return this->faces().size();
453}
454
455
457{
458 return this->storedIOPoints();
459}
460
461
463{
464 return this->storedIOFaces();
465}
466
467
468void Foam::surfMesh::checkZones(const bool verbose)
469{
470 auto& zones = this->storedZones();
471
472 if (zones.size() <= 1)
473 {
474 removeZones();
475 return;
476 }
477
478 // Check that zones cover all faces exactly
479 // - fix each start silently
480
481 bool zonesTooBig(false);
482
483 const label maxCount = this->nFaces();
484
485 label start = 0;
486 for (surfZone& zn : zones)
487 {
488 zn.start() = start;
489 start += zn.size();
490 if (start > maxCount)
491 {
492 zonesTooBig = true; // Zones exceed what is required
493 zn.size() = (maxCount - zn.start());
494 start = (zn.start() + zn.size());
495 }
496 }
497
498 if (!zones.empty())
499 {
500 surfZone& zn = zones.last();
501
502 if ((zn.start() + zn.size()) < maxCount)
503 {
504 // Zones address less than expected - extend final zone
505 zn.size() += maxCount - zn.start();
506
507 if (verbose)
508 {
510 << "Surface has more faces " << maxCount
511 << " than zone addressing ... extending final zone" << nl;
512 }
513 }
514 else if (zonesTooBig)
515 {
516 if (verbose)
517 {
519 << "Surface has more zone addressing than faces "
520 << maxCount
521 << " ... trucated/resized accordingly" << nl;
522 }
523 }
524 }
525}
526
527
528// Add boundary patches. Constructor helper
530(
531 const surfZoneList& zones,
532 const bool validate
533)
534{
535 removeZones();
536
537 forAll(surfZones_, zonei)
538 {
539 surfZones_[zonei] = surfZone(zones[zonei], zonei);
540 }
541
542 if (validate)
543 {
544 checkZones();
545 }
546}
547
548
549// Remove all files and some subdirs (eg, sets)
550void Foam::surfMesh::removeFiles(const fileName& instanceDir) const
551{
552 fileName meshFilesPath = db().path()/instanceDir/meshSubDir;
553
554 rm(meshFilesPath/"points");
555 rm(meshFilesPath/"faces");
556 rm(meshFilesPath/"surfZones");
557}
558
559
561{
562 removeFiles(instance());
563}
564
565
567(
568 const fileName& name,
569 IOstreamOption streamOpt,
570 const dictionary& options
571) const
572{
573 write(name, name.ext(), streamOpt, options);
574}
575
576
578(
579 const fileName& name,
580 const word& fileType,
581 IOstreamOption streamOpt,
582 const dictionary& options
583) const
584{
586 (
587 this->points(),
588 this->faces(),
589 this->surfZones()
590 ).write(name, fileType, streamOpt, options);
591}
592
593
594// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A helper class for storing points and faces with IO capabilities.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition: IOobject.C:500
const fileName & local() const noexcept
Read access to local path component.
Definition: IOobjectI.H:208
const fileName & instance() const noexcept
Read access to instance path component.
Definition: IOobjectI.H:196
fileName path() const
The complete path.
Definition: IOobject.C:524
The IOstreamOption is a simple container for options an IOstream can normally have.
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
static void write(const fileName &name, const MeshedSurfaceProxy &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
Write to file, select based on its extension.
A surface geometry mesh with zone information, not to be confused with the similarly named surfaceMes...
Definition: MeshedSurface.H:99
surfZoneList & storedZones()
Non-const access to the zones.
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.
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
void shallowCopy(const UList< T > &list)
Copy the pointer and size held by the given UList.
Definition: UListI.H:272
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
static std::string path(const std::string &str)
Return directory path name (part before last /)
Definition: fileNameI.H:176
virtual bool write()
Write the output fields.
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 pointField & points() const =0
The points used for the surface.
Registry of regIOobjects.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
A surface mesh consisting of general polygon faces that has IO capabilities and a registry for storin...
Definition: surfMesh.H:68
autoPtr< MeshedSurface< face > > releaseGeom()
Release the geometry and return as a MeshedSurface<face>.
Definition: surfMesh.C:407
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: surfMesh.C:438
void copySurface(const pointField &points, const faceList &faces, bool validate=false)
Update with new contents.
Definition: surfMesh.C:298
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: surfMesh.C:426
virtual const faceList & faces() const
Return faces.
Definition: surfMesh.C:462
faceList & storedFaces()
Non-const access to the faces.
Definition: surfMesh.H:123
virtual ~surfMesh()
Destructor.
Definition: surfMesh.C:289
void updateRefs()
Update point/face references.
Definition: surfMesh.C:70
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: surfMesh.C:432
void checkZones(const bool verbose=true)
Check the surface zone definitions.
Definition: surfMesh.C:468
virtual const pointField & points() const
Return points.
Definition: surfMesh.C:456
void removeFiles() const
Remove all files from mesh instance()
Definition: surfMesh.C:560
virtual label nPoints() const
Return the number of raw points.
Definition: surfMesh.C:444
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:153
void transfer(MeshedSurface< face > &surf, bool validate=false)
Transfer the contents of the argument and annul the argument.
Definition: surfMesh.C:386
void addZones(const surfZoneList &zones, bool validate=true)
Add surface zones, optionally validating the zone coverage.
Definition: surfMesh.C:530
virtual label nFaces() const
Return the number of raw faces.
Definition: surfMesh.C:450
A surface zone on a MeshedSurface.
Definition: surfZone.H:59
label start() const
The start label of this zone in the face list.
Definition: surfZone.H:128
label size() const
The size of this zone in the face list.
Definition: surfZone.H:140
Wraps the normal objectRegistry with a local instance for surfaces.
A class for handling words, derived from Foam::string.
Definition: word.H:68
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
const pointField & points
label nPoints
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Definition: MSwindows.C:1012
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
runTime write()
thermo validate(args.executable(), "h")
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333