1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
29 #include "demandDrivenData.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 template<class ZoneType, class MeshType>
39 void ZoneMesh<ZoneType, MeshType>::calcZoneMap() const
41 // It is an error to attempt to recalculate cellEdges
42 // if the pointer is already set
45 FatalErrorIn("void ZoneMesh<ZoneType>::calcZoneMap() const")
46 << "zone map already calculated"
51 // Count number of objects in all zones
56 nObjects += this->operator[](zoneI).size();
59 zoneMapPtr_ = new Map<label>(2*nObjects);
60 Map<label>& zm = *zoneMapPtr_;
62 // Fill in objects of all zones into the map. The key is the global
63 // object index and the result is the zone index
66 const labelList& zoneObjects = this->operator[](zoneI);
68 forAll (zoneObjects, objI)
70 zm.insert(zoneObjects[objI], zoneI);
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79 // Read constructor given IOobject and a MeshType reference
80 template<class ZoneType, class MeshType>
81 ZoneMesh<ZoneType, MeshType>::ZoneMesh
94 readOpt() == IOobject::MUST_READ
95 || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
98 PtrList<ZoneType>& zones = *this;
101 Istream& is = readStream(typeName);
103 PtrList<entry> patchEntries(is);
104 zones.setSize(patchEntries.size());
113 patchEntries[zoneI].keyword(),
114 patchEntries[zoneI].dict(),
121 // Check state of IOstream
125 "(const IOobject&, const MeshType&)"
132 // No files found. Force a write of zero-sized zones
138 // Construct given size. Zones will be set later
139 template<class ZoneType, class MeshType>
140 ZoneMesh<ZoneType, MeshType>::ZoneMesh
143 const MeshType& mesh,
147 PtrList<ZoneType>(size),
154 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 template<class ZoneType, class MeshType>
157 ZoneMesh<ZoneType, MeshType>::~ZoneMesh()
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 // Map of zones for quick zone lookup
166 template<class ZoneType, class MeshType>
167 const Map<label>& ZoneMesh<ZoneType, MeshType>::zoneMap() const
178 // Given a global object index, return the zone it is in.
179 // If object does not belong to any zones, return -1
180 template<class ZoneType, class MeshType>
181 label ZoneMesh<ZoneType, MeshType>::whichZone(const label objectIndex) const
183 const Map<label>& zm = zoneMap();
184 Map<label>::const_iterator zmIter = zm.find(objectIndex);
186 if (zmIter == zm.end())
197 // Return a list of zone names
198 template<class ZoneType, class MeshType>
199 wordList ZoneMesh<ZoneType, MeshType>::types() const
201 const PtrList<ZoneType>& zones = *this;
203 wordList t(zones.size());
205 forAll (zones, zoneI)
207 t[zoneI] = zones[zoneI].type();
214 // Return a list of zone names
215 template<class ZoneType, class MeshType>
216 wordList ZoneMesh<ZoneType, MeshType>::names() const
218 const PtrList<ZoneType>& zones = *this;
220 wordList t(zones.size());
222 forAll (zones, zoneI)
224 t[zoneI] = zones[zoneI].name();
231 template<class ZoneType, class MeshType>
232 label ZoneMesh<ZoneType, MeshType>::findZoneID(const word& zoneName) const
234 const PtrList<ZoneType>& zones = *this;
236 forAll (zones, zoneI)
238 if (zones[zoneI].name() == zoneName)
247 Info<< "label ZoneMesh<ZoneType>::findZoneID(const word& "
248 << "zoneName) const : "
249 << "Zone named " << zoneName << " not found. "
250 << "List of available zone names: " << names() << endl;
253 // A dummy return to kep the compiler happy
258 template<class ZoneType, class MeshType>
259 void ZoneMesh<ZoneType, MeshType>::clearAddressing()
261 deleteDemandDrivenData(zoneMapPtr_);
263 PtrList<ZoneType>& zones = *this;
265 forAll (zones, zoneI)
267 zones[zoneI].clearAddressing();
272 template<class ZoneType, class MeshType>
273 void ZoneMesh<ZoneType, MeshType>::clear()
276 PtrList<ZoneType>::clear();
280 // Check zone definition
281 template<class ZoneType, class MeshType>
282 bool ZoneMesh<ZoneType, MeshType>::checkDefinition(const bool report) const
284 bool inError = false;
286 const PtrList<ZoneType>& zones = *this;
288 forAll (zones, zoneI)
290 inError |= zones[zoneI].checkDefinition(report);
296 // Correct zone mesh after moving points
297 template<class ZoneType, class MeshType>
298 void ZoneMesh<ZoneType, MeshType>::movePoints(const pointField& p)
300 PtrList<ZoneType>& zones = *this;
302 forAll (zones, zoneI)
304 zones[zoneI].movePoints(p);
309 // writeData member function required by regIOobject
310 template<class ZoneType, class MeshType>
311 bool ZoneMesh<ZoneType, MeshType>::writeData(Ostream& os) const
318 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
320 template<class ZoneType, class MeshType>
321 Ostream& operator<<(Ostream& os, const ZoneMesh<ZoneType, MeshType>& zones)
323 os << zones.size() << nl << token::BEGIN_LIST;
327 zones[zoneI].writeDict(os);
330 os << token::END_LIST;
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 } // End namespace Foam
340 // ************************************************************************* //