00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "ZoneMesh.H"
00027 #include <OpenFOAM/entry.H>
00028 #include <OpenFOAM/demandDrivenData.H>
00029
00030
00031
00032 namespace Foam
00033 {
00034
00035
00036
00037 template<class ZoneType, class MeshType>
00038 void ZoneMesh<ZoneType, MeshType>::calcZoneMap() const
00039 {
00040
00041
00042 if (zoneMapPtr_)
00043 {
00044 FatalErrorIn("void ZoneMesh<ZoneType>::calcZoneMap() const")
00045 << "zone map already calculated"
00046 << abort(FatalError);
00047 }
00048 else
00049 {
00050
00051 label nObjects = 0;
00052
00053 forAll (*this, zoneI)
00054 {
00055 nObjects += this->operator[](zoneI).size();
00056 }
00057
00058 zoneMapPtr_ = new Map<label>(2*nObjects);
00059 Map<label>& zm = *zoneMapPtr_;
00060
00061
00062
00063 forAll (*this, zoneI)
00064 {
00065 const labelList& zoneObjects = this->operator[](zoneI);
00066
00067 forAll (zoneObjects, objI)
00068 {
00069 zm.insert(zoneObjects[objI], zoneI);
00070 }
00071 }
00072 }
00073 }
00074
00075
00076
00077
00078
00079 template<class ZoneType, class MeshType>
00080 ZoneMesh<ZoneType, MeshType>::ZoneMesh
00081 (
00082 const IOobject& io,
00083 const MeshType& mesh
00084 )
00085 :
00086 PtrList<ZoneType>(),
00087 regIOobject(io),
00088 mesh_(mesh),
00089 zoneMapPtr_(NULL)
00090 {
00091 if
00092 (
00093 readOpt() == IOobject::MUST_READ
00094 || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
00095 )
00096 {
00097 PtrList<ZoneType>& zones = *this;
00098
00099
00100 Istream& is = readStream(typeName);
00101
00102 PtrList<entry> patchEntries(is);
00103 zones.setSize(patchEntries.size());
00104
00105 forAll(zones, zoneI)
00106 {
00107 zones.set
00108 (
00109 zoneI,
00110 ZoneType::New
00111 (
00112 patchEntries[zoneI].keyword(),
00113 patchEntries[zoneI].dict(),
00114 zoneI,
00115 *this
00116 )
00117 );
00118 }
00119
00120
00121 is.check
00122 (
00123 "ZoneMesh::ZoneMesh"
00124 "(const IOobject&, const MeshType&)"
00125 );
00126
00127 close();
00128 }
00129 else
00130 {
00131
00132
00133 }
00134 }
00135
00136
00137
00138 template<class ZoneType, class MeshType>
00139 ZoneMesh<ZoneType, MeshType>::ZoneMesh
00140 (
00141 const IOobject& io,
00142 const MeshType& mesh,
00143 const label size
00144 )
00145 :
00146 PtrList<ZoneType>(size),
00147 regIOobject(io),
00148 mesh_(mesh),
00149 zoneMapPtr_(NULL)
00150 {}
00151
00152
00153
00154
00155 template<class ZoneType, class MeshType>
00156 ZoneMesh<ZoneType, MeshType>::~ZoneMesh()
00157 {
00158 clearAddressing();
00159 }
00160
00161
00162
00163
00164
00165 template<class ZoneType, class MeshType>
00166 const Map<label>& ZoneMesh<ZoneType, MeshType>::zoneMap() const
00167 {
00168 if (!zoneMapPtr_)
00169 {
00170 calcZoneMap();
00171 }
00172
00173 return *zoneMapPtr_;
00174 }
00175
00176
00177
00178
00179 template<class ZoneType, class MeshType>
00180 label ZoneMesh<ZoneType, MeshType>::whichZone(const label objectIndex) const
00181 {
00182 const Map<label>& zm = zoneMap();
00183 Map<label>::const_iterator zmIter = zm.find(objectIndex);
00184
00185 if (zmIter == zm.end())
00186 {
00187 return -1;
00188 }
00189 else
00190 {
00191 return zmIter();
00192 }
00193 }
00194
00195
00196
00197 template<class ZoneType, class MeshType>
00198 wordList ZoneMesh<ZoneType, MeshType>::types() const
00199 {
00200 const PtrList<ZoneType>& zones = *this;
00201
00202 wordList t(zones.size());
00203
00204 forAll (zones, zoneI)
00205 {
00206 t[zoneI] = zones[zoneI].type();
00207 }
00208
00209 return t;
00210 }
00211
00212
00213
00214 template<class ZoneType, class MeshType>
00215 wordList ZoneMesh<ZoneType, MeshType>::names() const
00216 {
00217 const PtrList<ZoneType>& zones = *this;
00218
00219 wordList t(zones.size());
00220
00221 forAll (zones, zoneI)
00222 {
00223 t[zoneI] = zones[zoneI].name();
00224 }
00225
00226 return t;
00227 }
00228
00229
00230 template<class ZoneType, class MeshType>
00231 label ZoneMesh<ZoneType, MeshType>::findZoneID(const word& zoneName) const
00232 {
00233 const PtrList<ZoneType>& zones = *this;
00234
00235 forAll (zones, zoneI)
00236 {
00237 if (zones[zoneI].name() == zoneName)
00238 {
00239 return zoneI;
00240 }
00241 }
00242
00243
00244 if (debug)
00245 {
00246 Info<< "label ZoneMesh<ZoneType>::findZoneID(const word& "
00247 << "zoneName) const : "
00248 << "Zone named " << zoneName << " not found. "
00249 << "List of available zone names: " << names() << endl;
00250 }
00251
00252
00253 return -1;
00254 }
00255
00256
00257 template<class ZoneType, class MeshType>
00258 void ZoneMesh<ZoneType, MeshType>::clearAddressing()
00259 {
00260 deleteDemandDrivenData(zoneMapPtr_);
00261
00262 PtrList<ZoneType>& zones = *this;
00263
00264 forAll (zones, zoneI)
00265 {
00266 zones[zoneI].clearAddressing();
00267 }
00268 }
00269
00270
00271 template<class ZoneType, class MeshType>
00272 void ZoneMesh<ZoneType, MeshType>::clear()
00273 {
00274 clearAddressing();
00275 PtrList<ZoneType>::clear();
00276 }
00277
00278
00279
00280 template<class ZoneType, class MeshType>
00281 bool ZoneMesh<ZoneType, MeshType>::checkDefinition(const bool report) const
00282 {
00283 bool inError = false;
00284
00285 const PtrList<ZoneType>& zones = *this;
00286
00287 forAll (zones, zoneI)
00288 {
00289 inError |= zones[zoneI].checkDefinition(report);
00290 }
00291 return inError;
00292 }
00293
00294
00295
00296 template<class ZoneType, class MeshType>
00297 void ZoneMesh<ZoneType, MeshType>::movePoints(const pointField& p)
00298 {
00299 PtrList<ZoneType>& zones = *this;
00300
00301 forAll (zones, zoneI)
00302 {
00303 zones[zoneI].movePoints(p);
00304 }
00305 }
00306
00307
00308
00309 template<class ZoneType, class MeshType>
00310 bool ZoneMesh<ZoneType, MeshType>::writeData(Ostream& os) const
00311 {
00312 os << *this;
00313 return os.good();
00314 }
00315
00316
00317
00318
00319 template<class ZoneType, class MeshType>
00320 Ostream& operator<<(Ostream& os, const ZoneMesh<ZoneType, MeshType>& zones)
00321 {
00322 os << zones.size() << nl << token::BEGIN_LIST;
00323
00324 forAll(zones, zoneI)
00325 {
00326 zones[zoneI].writeDict(os);
00327 }
00328
00329 os << token::END_LIST;
00330
00331 return os;
00332 }
00333
00334
00335
00336
00337 }
00338
00339