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-2014 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 
42 Foam::word Foam::surfMesh::meshSubDir = "surfMesh";
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 
111 Foam::surfMesh::surfMesh
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 
157 Foam::surfMesh::surfMesh
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.
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.
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.
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
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  {
372  WarningIn
373  (
374  "surfMesh::checkZones()\n"
375  )
376  << "more faces " << nFaces() << " than zones " << count
377  << " ... extending final zone"
378  << endl;
379 
380  zones.last().size() += count - nFaces();
381  }
382  else if (count > size())
383  {
385  (
386  "surfMesh::checkZones()\n"
387  )
388  << "more zones " << count << " than faces " << nFaces()
389  << exit(FatalError);
390  }
391  }
392 }
393 
394 
395 // Add boundary patches. Constructor helper
397 (
398  const surfZoneList& srfZones,
399  const bool validate
400 )
401 {
403 
404  forAll(zones, zoneI)
405  {
406  zones[zoneI] = surfZone(srfZones[zoneI], zoneI);
407  }
408 
409  if (validate)
410  {
411  checkZones();
412  }
413 }
414 
415 
416 // Remove all files and some subdirs (eg, sets)
417 void Foam::surfMesh::removeFiles(const fileName& instanceDir) const
418 {
419  fileName meshFilesPath = db().path()/instanceDir/meshSubDir;
420 
421  rm(meshFilesPath/"points");
422  rm(meshFilesPath/"faces");
423  rm(meshFilesPath/"surfZones");
424 }
425 
427 {
429 }
430 
431 
432 void Foam::surfMesh::write(const fileName& name, const surfMesh& surf)
433 {
435  (
436  surf.points(),
437  surf.faces(),
438  surf.surfZones()
439  ).write(name);
440 }
441 
442 
444 {
445  write(name, *this);
446 }
447 
448 
449 // ************************************************************************* //
surfZoneIOList & storedIOZones()
Non-const access to the zones.
A surface mesh consisting of general polygon faces.
Definition: surfMesh.H:55
Wraps the normal objectRegistry with a local instance for surfaces.
List< surfZone > surfZoneList
Definition: surfZoneList.H:45
pointField & storedPoints()
Non-const access to global points.
Definition: surfMesh.H:111
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
surfZoneList & storedZones()
Non-const access to the zones.
Definition: surfMesh.H:123
T & last()
Return the last element of the list.
Definition: UListI.H:131
Xfer< MeshedSurface< face > > xfer()
Transfer contents to the Xfer container as a MeshedSurface.
Definition: surfMesh.C:291
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:73
void removeZones()
Update the mesh corresponding to given map.
Definition: surfMeshClear.C:32
virtual label size() const
Return number of faces.
Definition: surfMesh.H:210
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
const fileName & local() const
Definition: IOobject.H:347
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual void updateFacesRef()
Update references to storedFaces.
Definition: surfMesh.C:240
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const fileName & instance() const
Definition: IOobject.H:337
void addZones(const List< surfZone > &, const bool validate=true)
Add surface zones.
Definition: surfMesh.C:397
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:46
messageStream Info
List< face > faceList
Definition: faceListFwd.H:43
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Definition: POSIX.C:955
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
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
Namespace for OpenFOAM.
pointField & storedPoints()
Non-const access to global points.
virtual bool write() const
Write using setting from DB.
A helper class for storing points, faces and zones with IO capabilities.
fileName path() const
Return complete path.
Definition: IOobject.C:299
virtual const surfZoneList & surfZones() const
Return surface zones.
Definition: surfMesh.H:223
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define WarningIn(functionName)
Report a warning using Foam::Warning.
#define forAll(list, i)
Definition: UList.H:421
surfZoneList & storedZones()
Non-const access to the zones.
Template functions to aid in the implementation of demand driven data.
void removeFiles() const
Remove all files from mesh instance()
Definition: surfMesh.C:426
const word & name() const
Return name.
Definition: IOobject.H:260
A surface zone on a MeshedSurface.
Definition: surfZone.H:62
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
const fileName & facesInstance() const
Return the current instance directory for faces.
Definition: surfMesh.C:321
virtual const pointField & points() const
Return points.
Definition: surfMesh.C:339
virtual void updateRefs()
Update references to storedPoints/storedFaces.
Definition: surfMesh.C:247
virtual label nFaces() const
Return the number of raw faces.
Definition: surfMesh.C:333
error FatalError
A class for handling file names.
Definition: fileName.H:69
pointIOField & storedIOPoints()
Non-const access to the points.
void transfer(MeshedSurface< face > &)
Transfer the contents of the argument and annul the argument.
Definition: surfMesh.C:276
virtual void updatePointsRef()
Update references to storedPoints.
Definition: surfMesh.C:230
List< Face > & storedFaces()
Non-const access to the faces.
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: surfMesh.C:315
virtual const faceList & faces() const
Return faces.
Definition: surfMesh.C:345
void checkZones()
Check the surface zone definitions.
Definition: surfMesh.C:351
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:245
virtual ~surfMesh()
Destructor.
Definition: surfMesh.C:221
virtual label nPoints() const
Return the number of raw points.
Definition: surfMesh.C:327
void reset(const Xfer< pointField > &points, const Xfer< faceList > &faces, const Xfer< surfZoneList > &zones)
Reset primitive data (points, faces and zones)
faceCompactIOList & storedIOFaces()
Non-const access to the faces.
const Field< point > & points() const
Return reference to global points.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: surfMesh.C:309
defineTypeNameAndDebug(combustionModel, 0)
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:152
faceList & storedFaces()
Non-const access to the faces.
Definition: surfMesh.H:117