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