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-2016 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  shallowCopy(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  {
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 {
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 {
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 // ************************************************************************* //
virtual void updateRefs()
Update references to storedPoints/storedFaces.
Definition: surfMesh.C:247
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
virtual const surfZoneList & surfZones() const
Return surface zones.
Definition: surfMesh.H:223
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
faceCompactIOList & storedIOFaces()
Non-const access to the faces.
A class for handling file names.
Definition: fileName.H:69
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:221
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual const faceList & faces() const
Return faces.
Definition: surfMesh.C:345
virtual void updatePointsRef()
Update references to storedPoints.
Definition: surfMesh.C:230
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
surfZoneList & storedZones()
Non-const access to the zones.
Definition: surfMesh.H:123
A surface zone on a MeshedSurface.
Definition: surfZone.H:62
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
List< face > faceList
Definition: faceListFwd.H:43
faceList & storedFaces()
Non-const access to the faces.
Definition: surfMesh.H:117
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
void addZones(const List< surfZone > &, const bool validate=true)
Add surface zones.
Definition: surfMesh.C:391
const Field< point > & points() const
Return reference to global points.
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
pointIOField & storedIOPoints()
Non-const access to the points.
surfZoneList & storedZones()
Non-const access to the zones.
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: surfMesh.C:315
Wraps the normal objectRegistry with a local instance for surfaces.
fileName path() const
Return complete path.
Definition: IOobject.C:275
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Xfer< MeshedSurface< face > > xfer()
Transfer contents to the Xfer container as a MeshedSurface.
Definition: surfMesh.C:291
List< Face > & storedFaces()
Non-const access to the faces.
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:152
A class for handling words, derived from string.
Definition: word.H:59
pointField & storedPoints()
Non-const access to global points.
virtual void updateFacesRef()
Update references to storedFaces.
Definition: surfMesh.C:240
const fileName & local() const
Definition: IOobject.H:347
surfZoneIOList & storedIOZones()
Non-const access to the zones.
void removeZones()
Update the mesh corresponding to given map.
Definition: surfMeshClear.C:32
A helper class for storing points, faces and zones with IO capabilities.
A surface mesh consisting of general polygon faces.
Definition: surfMesh.H:55
static const char nl
Definition: Ostream.H:262
defineTypeNameAndDebug(combustionModel, 0)
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:73
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: surfMesh.C:309
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
List< surfZone > surfZoneList
Definition: surfZoneList.H:45
virtual label nPoints() const
Return the number of raw points.
Definition: surfMesh.C:327
virtual label size() const
Return number of faces.
Definition: surfMesh.H:210
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:46
Template functions to aid in the implementation of demand driven data.
void shallowCopy(const UList< face > &)
Copy the pointer held by the given UList.
void transfer(MeshedSurface< face > &)
Transfer the contents of the argument and annul the argument.
Definition: surfMesh.C:276
#define WarningInFunction
Report a warning using Foam::Warning.
void reset(const Xfer< pointField > &points, const Xfer< faceList > &faces, const Xfer< surfZoneList > &zones)
Reset primitive data (points, faces and zones)
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
virtual bool write() const
Write using setting from DB.
pointField & storedPoints()
Non-const access to global points.
Definition: surfMesh.H:111
messageStream Info
void checkZones()
Check the surface zone definitions.
Definition: surfMesh.C:351
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
virtual label nFaces() const
Return the number of raw faces.
Definition: surfMesh.C:333
virtual ~surfMesh()
Destructor.
Definition: surfMesh.C:221
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Definition: POSIX.C:819
T & last()
Return the last element of the list.
Definition: UListI.H:128
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const fileName & instance() const
Definition: IOobject.H:337
void removeFiles() const
Remove all files from mesh instance()
Definition: surfMesh.C:420
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:365
const word & name() const
Return name.
Definition: IOobject.H:260
Namespace for OpenFOAM.