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 | Copyright (C) 2011-2015 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 "surfMesh.H"
27 #include "MeshedSurfaceProxy.H"
28 
29 #include "Time.H"
30 #include "OSspecific.H"
31 #include "MeshedSurface.H"
32 #include "demandDrivenData.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 defineTypeNameAndDebug(surfMesh, 0);
39 }
40 
41 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 // void Foam::surfMesh::oneZone()
47 // {
48 // word zoneName;
49 //
50 // surfZoneList& zones = Allocator::storedIOZones();
51 // if (zones.size())
52 // {
53 // zoneName = zones[0].name();
54 // }
55 // if (zoneName.empty())
56 // {
57 // zoneName = "zone0";
58 // }
59 //
60 // // set single default zone
61 // zones.setSize(1);
62 // zones[0] = surfZone
63 // (
64 // zoneName,
65 // nFaces(), // zone size
66 // 0, // zone start
67 // 0 // zone index
68 // );
69 // }
70 
71 
72 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
73 
74 Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
75 :
76  surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
77  Allocator
78  (
79  IOobject
80  (
81  "points",
82  time().findInstance(meshDir(), "points"),
83  meshSubDir,
84  *this,
85  IOobject::MUST_READ,
86  IOobject::NO_WRITE
87  ),
88  IOobject
89  (
90  "faces",
91  time().findInstance(meshDir(), "faces"),
92  meshSubDir,
93  *this,
94  IOobject::MUST_READ,
95  IOobject::NO_WRITE
96  ),
97  IOobject
98  (
99  "surfZones",
100  time().findInstance(meshDir(), "surfZones"),
101  meshSubDir,
102  *this,
103  IOobject::MUST_READ,
104  IOobject::NO_WRITE
105  )
106  ),
107  MeshReference(this->storedIOFaces(), this->storedIOPoints())
108 {}
109 
110 
112 (
113  const IOobject& io,
114  const Xfer<pointField>& pointLst,
115  const Xfer<faceList>& faceLst,
116  const word& surfName
117 )
118 :
119  surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
120  Allocator
121  (
122  IOobject
123  (
124  "points",
125  instance(),
126  meshSubDir,
127  *this,
130  ),
131  pointLst,
132  IOobject
133  (
134  "faces",
135  instance(),
136  meshSubDir,
137  *this,
140  ),
141  faceLst,
142  IOobject
143  (
144  "surfZones",
145  instance(),
146  meshSubDir,
147  *this,
150  ),
152  ),
153  MeshReference(this->storedIOFaces(), this->storedIOPoints())
154 {}
155 
156 
158 (
159  const IOobject& io,
160  const Xfer<MeshedSurface<face> >& surf,
161  const word& surfName
162 )
163 :
164  surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
165  Allocator
166  (
167  IOobject
168  (
169  "points",
170  instance(),
171  meshSubDir,
172  *this,
175  ),
176  pointField(),
177  IOobject
178  (
179  "faces",
180  instance(),
181  meshSubDir,
182  *this,
185  ),
186  faceList(),
187  IOobject
188  (
189  "surfZones",
190  instance(),
191  meshSubDir,
192  *this,
195  ),
196  surfZoneList()
197  ),
198  MeshReference(this->storedIOFaces(), this->storedIOPoints())
199 {
200  if (debug)
201  {
202  Info<<"IOobject: " << io.path() << nl
203  <<" name: " << io.name()
204  <<" instance: " << io.instance()
205  <<" local: " << io.local()
206  <<" dbDir: " << io.db().dbDir() << endl;
207  Info<<"creating surfMesh at instance " << instance() << endl;
208  Info<<"timeName: " << instance() << endl;
209  }
210 
211  // We can also send Xfer<..>::null just to initialize without allocating
212  if (notNull(surf))
213  {
214  transfer(surf());
215  }
216 }
217 
218 
219 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
220 
222 {
223  // clearOut();
224  // resetMotion();
225 }
226 
227 
228 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
229 
231 {
232  // assign the reference to the points (this is truly ugly)
233  reinterpret_cast<SubField<point>&>
234  (
235  const_cast<Field<point>&>(MeshReference::points())
236  ) = reinterpret_cast<SubField<point>&>(this->storedPoints());
237 }
238 
239 
241 {
242  // assign the reference to the faces
243  static_cast<UList<face>&>(*this) = this->storedFaces();
244 }
245 
246 
248 {
249  this->updatePointsRef();
250  this->updateFacesRef();
251 }
252 
253 
255 (
256  const Xfer<pointField>& points,
257  const Xfer<faceList>& faces,
258  const Xfer<surfZoneList>& zones,
259  const bool validate
260 )
261 {
262  // Clear addressing.
263  MeshReference::clearGeom();
264 
265  Allocator::reset(points, faces, zones);
266  this->updateRefs();
267 
268  if (validate)
269  {
270  checkZones();
271  }
272 }
273 
274 
276 (
277  MeshedSurface<face>& surf
278 )
279 {
280  // Clear addressing.
281  MeshReference::clearGeom();
282 
283  this->storedIOPoints().transfer(surf.storedPoints());
284  this->storedIOFaces().transfer(surf.storedFaces());
285  this->storedIOZones().transfer(surf.storedZones());
286 
287  this->updateRefs();
288 }
289 
290 
292 {
294 
295  xf().storedPoints().transfer(this->storedPoints());
296  xf().storedFaces().transfer(this->storedFaces());
297  xf().storedZones().transfer(this->storedZones());
298 
299  // is this needed?
300  this->updateRefs();
301 
302  // Clear addressing.
303  MeshReference::clearGeom();
304 
305  return xf;
306 }
307 
308 
310 {
311  return dbDir()/meshSubDir;
312 }
313 
314 
316 {
317  return this->storedIOPoints().instance();
318 }
319 
320 
322 {
323  return this->storedIOFaces().instance();
324 }
325 
326 
328 {
329  return this->points().size();
330 }
331 
332 
334 {
335  return this->faces().size();
336 }
337 
338 
340 {
341  return this->storedIOPoints();
342 }
343 
344 
346 {
347  return this->storedIOFaces();
348 }
349 
350 
352 {
353  // extra safety, ensure we have at some zones
354  // and they cover all the faces - fix start silently
355  surfZoneList& zones = Allocator::storedIOZones();
356 
357  if (zones.size() <= 1)
358  {
359  removeZones();
360  }
361  else
362  {
363  label count = 0;
364  forAll(zones, zoneI)
365  {
366  zones[zoneI].start() = count;
367  count += zones[zoneI].size();
368  }
369 
370  if (count < nFaces())
371  {
373  << "more faces " << nFaces() << " than zones " << count
374  << " ... extending final zone"
375  << endl;
376 
377  zones.last().size() += count - nFaces();
378  }
379  else if (count > size())
380  {
382  << "more zones " << count << " than faces " << nFaces()
383  << exit(FatalError);
384  }
385  }
386 }
387 
388 
389 // Add boundary patches. Constructor helper
391 (
392  const surfZoneList& srfZones,
393  const bool validate
394 )
395 {
396  surfZoneList& zones = Allocator::storedIOZones();
397 
398  forAll(zones, zoneI)
399  {
400  zones[zoneI] = surfZone(srfZones[zoneI], zoneI);
401  }
402 
403  if (validate)
404  {
405  checkZones();
406  }
407 }
408 
409 
410 // Remove all files and some subdirs (eg, sets)
411 void Foam::surfMesh::removeFiles(const fileName& instanceDir) const
412 {
413  fileName meshFilesPath = db().path()/instanceDir/meshSubDir;
414 
415  rm(meshFilesPath/"points");
416  rm(meshFilesPath/"faces");
417  rm(meshFilesPath/"surfZones");
418 }
419 
421 {
422  removeFiles(instance());
423 }
424 
425 
426 void Foam::surfMesh::write(const fileName& name, const surfMesh& surf)
427 {
429  (
430  surf.points(),
431  surf.faces(),
432  surf.surfZones()
433  ).write(name);
434 }
435 
436 
438 {
439  write(name, *this);
440 }
441 
442 
443 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Foam::surfMesh::pointsInstance
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: surfMesh.C:315
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::surfMesh::updatePointsRef
virtual void updatePointsRef()
Update references to storedPoints.
Definition: surfMesh.C:230
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
MeshedSurfaceProxy.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::MeshedSurface::storedFaces
List< Face > & storedFaces()
Non-const access to the faces.
Definition: MeshedSurface.H:133
Foam::surfaceRegistry
Wraps the normal objectRegistry with a local instance for surfaces.
Definition: surfaceRegistry.H:48
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::notNull
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:46
Foam::MeshedSurface::storedPoints
pointField & storedPoints()
Non-const access to global points.
Definition: MeshedSurface.H:127
Foam::rm
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Definition: POSIX.C:954
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::MeshedSurfaceProxy::write
static void write(const fileName &, const MeshedSurfaceProxy< Face > &)
Write to file.
Foam::surfMesh::updateRefs
virtual void updateRefs()
Update references to storedPoints/storedFaces.
Definition: surfMesh.C:247
Foam::surfMesh::addZones
void addZones(const List< surfZone > &, const bool validate=true)
Add surface zones.
Definition: surfMesh.C:391
Foam::fileName::path
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:293
Foam::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
Foam::surfMesh
A surface mesh consisting of general polygon faces.
Definition: surfMesh.H:55
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobject.H:350
Foam::MeshedSurfaceProxy
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
Definition: MeshedSurface.H:73
Foam::surfMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:152
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Foam::IOobject::db
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:239
Foam::surfMesh::xfer
Xfer< MeshedSurface< face > > xfer()
Transfer contents to the Xfer container as a MeshedSurface.
Definition: surfMesh.C:291
Foam::SubField< point >
Foam::objectRegistry::dbDir
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
Definition: objectRegistry.H:129
Foam::MeshedSurface::storedZones
surfZoneList & storedZones()
Non-const access to the zones.
Definition: MeshedSurface.H:139
Foam::surfMesh::surfMesh
surfMesh(const surfMesh &)
Disallow construct as copy.
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field< point >
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::surfMesh::faces
virtual const faceList & faces() const
Return faces.
Definition: surfMesh.C:345
Foam::FatalError
error FatalError
surfMesh.H
Foam::surfMesh::nPoints
virtual label nPoints() const
Return the number of raw points.
Definition: surfMesh.C:327
Foam::surfMesh::removeFiles
void removeFiles() const
Remove all files from mesh instance()
Definition: surfMesh.C:420
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::surfMesh::updateFacesRef
virtual void updateFacesRef()
Update references to storedFaces.
Definition: surfMesh.C:240
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::surfMesh::~surfMesh
virtual ~surfMesh()
Destructor.
Definition: surfMesh.C:221
Foam::surfMesh::surfZones
virtual const surfZoneList & surfZones() const
Return surface zones.
Definition: surfMesh.H:223
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::surfMesh::points
virtual const pointField & points() const
Return points.
Definition: surfMesh.C:339
Foam::faceList
List< face > faceList
Definition: faceListFwd.H:43
Foam::surfMesh::meshDir
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: surfMesh.C:309
Foam::MeshedSurfaceIOAllocator
A helper class for storing points, faces and zones with IO capabilities.
Definition: MeshedSurfaceIOAllocator.H:50
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:62
Foam::UList< face >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::surfZoneList
List< surfZone > surfZoneList
Definition: surfZoneList.H:45
validate
thermo validate(args.executable(), "h", "e")
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::MeshedSurface< face >
Foam::surfMesh::checkZones
void checkZones()
Check the surface zone definitions.
Definition: surfMesh.C:351
Foam::IOobject::path
fileName path() const
Return complete path.
Definition: IOobject.C:293
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::surfMesh::nFaces
virtual label nFaces() const
Return the number of raw faces.
Definition: surfMesh.C:333
Foam::surfMesh::transfer
void transfer(MeshedSurface< face > &)
Transfer the contents of the argument and annul the argument.
Definition: surfMesh.C:276
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::IOobject::local
const fileName & local() const
Definition: IOobject.H:360
Foam::surfMesh::resetPrimitives
void resetPrimitives(const Xfer< pointField > &points, const Xfer< faceList > &faces, const Xfer< surfZoneList > &zones, const bool validate=true)
Reset mesh primitive data.
Definition: surfMesh.C:255
write
Tcoeff write()
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::surfMesh::facesInstance
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: surfMesh.C:321
MeshedSurface.H
Foam::PrimitivePatch< face, ::Foam::UList, ::Foam::SubField< point >, point >