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 "faceZoneSet.H"
00027 #include <OpenFOAM/mapPolyMesh.H>
00028 #include <OpenFOAM/polyMesh.H>
00029 #include <OpenFOAM/processorPolyPatch.H>
00030 #include <OpenFOAM/cyclicPolyPatch.H>
00031
00032 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00033
00034
00035
00036 namespace Foam
00037 {
00038
00039
00040
00041 defineTypeNameAndDebug(faceZoneSet, 0);
00042
00043 addToRunTimeSelectionTable(topoSet, faceZoneSet, word);
00044 addToRunTimeSelectionTable(topoSet, faceZoneSet, size);
00045 addToRunTimeSelectionTable(topoSet, faceZoneSet, set);
00046
00047
00048
00049
00050 void faceZoneSet::updateSet()
00051 {
00052 labelList order;
00053 sortedOrder(addressing_, order);
00054 inplaceReorder(order, addressing_);
00055 inplaceReorder(order, flipMap_);
00056
00057 faceSet::clearStorage();
00058 faceSet::resize(2*addressing_.size());
00059 forAll(addressing_, i)
00060 {
00061 faceSet::insert(addressing_[i]);
00062 }
00063 }
00064
00065
00066
00067
00068 faceZoneSet::faceZoneSet
00069 (
00070 const polyMesh& mesh,
00071 const word& name,
00072 readOption r,
00073 writeOption w
00074 )
00075 :
00076 faceSet(mesh, name, 1000),
00077 mesh_(mesh),
00078 addressing_(0),
00079 flipMap_(0)
00080 {
00081 const faceZoneMesh& faceZones = mesh.faceZones();
00082 label zoneID = faceZones.findZoneID(name);
00083
00084 if
00085 (
00086 (r == IOobject::MUST_READ)
00087 || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
00088 )
00089 {
00090 const faceZone& fz = faceZones[zoneID];
00091 addressing_ = fz;
00092 flipMap_ = fz.flipMap();
00093 }
00094
00095 updateSet();
00096
00097 check(mesh.nFaces());
00098 }
00099
00100
00101 faceZoneSet::faceZoneSet
00102 (
00103 const polyMesh& mesh,
00104 const word& name,
00105 const label size,
00106 writeOption w
00107 )
00108 :
00109 faceSet(mesh, name, size, w),
00110 mesh_(mesh),
00111 addressing_(0),
00112 flipMap_(0)
00113 {
00114 updateSet();
00115 }
00116
00117
00118 faceZoneSet::faceZoneSet
00119 (
00120 const polyMesh& mesh,
00121 const word& name,
00122 const topoSet& set,
00123 writeOption w
00124 )
00125 :
00126 faceSet(mesh, name, set.size(), w),
00127 mesh_(mesh),
00128 addressing_(refCast<const faceZoneSet>(set).addressing()),
00129 flipMap_(refCast<const faceZoneSet>(set).flipMap())
00130 {
00131 updateSet();
00132 }
00133
00134
00135
00136
00137 faceZoneSet::~faceZoneSet()
00138 {}
00139
00140
00141
00142
00143 void faceZoneSet::invert(const label maxLen)
00144 {
00145 label n = 0;
00146
00147 for (label faceI = 0; faceI < maxLen; faceI++)
00148 {
00149 if (!found(faceI))
00150 {
00151 addressing_[n] = faceI;
00152 flipMap_[n] = false;
00153 n++;
00154 }
00155 }
00156 addressing_.setSize(n);
00157 flipMap_.setSize(n);
00158 updateSet();
00159 }
00160
00161
00162 void faceZoneSet::subset(const topoSet& set)
00163 {
00164 label nConflict = 0;
00165
00166 DynamicList<label> newAddressing(addressing_.size());
00167 DynamicList<bool> newFlipMap(flipMap_.size());
00168
00169 Map<label> faceToIndex(addressing_.size());
00170 forAll(addressing_, i)
00171 {
00172 faceToIndex.insert(addressing_[i], i);
00173 }
00174
00175 const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
00176
00177 forAll(fSet.addressing(), i)
00178 {
00179 label faceI = fSet.addressing()[i];
00180
00181 Map<label>::const_iterator iter = faceToIndex.find(faceI);
00182
00183 if (iter != faceToIndex.end())
00184 {
00185 label index = iter();
00186
00187 if (fSet.flipMap()[i] != flipMap_[index])
00188 {
00189 nConflict++;
00190 }
00191 newAddressing.append(faceI);
00192 newFlipMap.append(flipMap_[index]);
00193 }
00194 }
00195
00196 if (nConflict > 0)
00197 {
00198 WarningIn(" faceZoneSet::subset(const topoSet&)")
00199 << "subset : there are " << nConflict
00200 << " faces with different orientation in faceZonesSets "
00201 << name() << " and " << set.name() << endl;
00202 }
00203
00204 addressing_.transfer(newAddressing);
00205 flipMap_.transfer(newFlipMap);
00206 updateSet();
00207 }
00208
00209
00210 void faceZoneSet::addSet(const topoSet& set)
00211 {
00212 label nConflict = 0;
00213
00214 DynamicList<label> newAddressing(addressing_);
00215 DynamicList<bool> newFlipMap(flipMap_);
00216
00217 Map<label> faceToIndex(addressing_.size());
00218 forAll(addressing_, i)
00219 {
00220 faceToIndex.insert(addressing_[i], i);
00221 }
00222
00223 const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
00224
00225 forAll(fSet.addressing(), i)
00226 {
00227 label faceI = fSet.addressing()[i];
00228
00229 Map<label>::const_iterator iter = faceToIndex.find(faceI);
00230
00231 if (iter != faceToIndex.end())
00232 {
00233 label index = iter();
00234
00235 if (fSet.flipMap()[i] != flipMap_[index])
00236 {
00237 nConflict++;
00238 }
00239 }
00240 else
00241 {
00242 newAddressing.append(faceI);
00243 newFlipMap.append(fSet.flipMap()[i]);
00244 }
00245 }
00246
00247 if (nConflict > 0)
00248 {
00249 WarningIn("faceZoneSet::addSet(const topoSet&)")
00250 << "addSet : there are " << nConflict
00251 << " faces with different orientation in faceZonesSets "
00252 << name() << " and " << set.name() << endl;
00253 }
00254
00255 addressing_.transfer(newAddressing);
00256 flipMap_.transfer(newFlipMap);
00257 updateSet();
00258 }
00259
00260
00261 void faceZoneSet::deleteSet(const topoSet& set)
00262 {
00263 label nConflict = 0;
00264
00265 DynamicList<label> newAddressing(addressing_.size());
00266 DynamicList<bool> newFlipMap(flipMap_.size());
00267
00268 const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
00269
00270 Map<label> faceToIndex(fSet.addressing().size());
00271 forAll(fSet.addressing(), i)
00272 {
00273 faceToIndex.insert(fSet.addressing()[i], i);
00274 }
00275
00276 forAll(addressing_, i)
00277 {
00278 label faceI = addressing_[i];
00279
00280 Map<label>::const_iterator iter = faceToIndex.find(faceI);
00281
00282 if (iter != faceToIndex.end())
00283 {
00284 label index = iter();
00285
00286 if (fSet.flipMap()[index] != flipMap_[i])
00287 {
00288 nConflict++;
00289 }
00290 }
00291 else
00292 {
00293
00294 newAddressing.append(faceI);
00295 newFlipMap.append(fSet.flipMap()[i]);
00296 }
00297 }
00298
00299 if (nConflict > 0)
00300 {
00301 WarningIn("faceZoneSet::deleteSet(const topoSet&)")
00302 << "deleteSet : there are " << nConflict
00303 << " faces with different orientation in faceZonesSets "
00304 << name() << " and " << set.name() << endl;
00305 }
00306
00307 addressing_.transfer(newAddressing);
00308 flipMap_.transfer(newFlipMap);
00309 updateSet();
00310 }
00311
00312
00313 void faceZoneSet::sync(const polyMesh& mesh)
00314 {}
00315
00316
00317 label faceZoneSet::maxSize(const polyMesh& mesh) const
00318 {
00319 return mesh.nFaces();
00320 }
00321
00322
00323
00324 bool faceZoneSet::writeObject
00325 (
00326 IOstream::streamFormat s,
00327 IOstream::versionNumber v,
00328 IOstream::compressionType c
00329 ) const
00330 {
00331
00332 word oldTypeName = typeName;
00333 const_cast<word&>(type()) = faceSet::typeName;
00334 bool ok = faceSet::writeObject(s, v, c);
00335 const_cast<word&>(type()) = oldTypeName;
00336
00337
00338 faceZoneMesh& faceZones = const_cast<polyMesh&>(mesh_).faceZones();
00339 label zoneID = faceZones.findZoneID(name());
00340
00341 if (zoneID == -1)
00342 {
00343 zoneID = faceZones.size();
00344
00345 faceZones.setSize(zoneID+1);
00346 faceZones.set
00347 (
00348 zoneID,
00349 new faceZone
00350 (
00351 name(),
00352 addressing_,
00353 flipMap_,
00354 zoneID,
00355 faceZones
00356 )
00357 );
00358 }
00359 else
00360 {
00361 faceZones[zoneID].resetAddressing(addressing_, flipMap_);
00362 }
00363 faceZones.clearAddressing();
00364
00365 return ok && faceZones.write();
00366 }
00367
00368
00369 void faceZoneSet::updateMesh(const mapPolyMesh& morphMap)
00370 {
00371
00372 labelList newAddressing(addressing_.size());
00373 boolList newFlipMap(flipMap_.size());
00374
00375 label n = 0;
00376 forAll(addressing_, i)
00377 {
00378 label faceI = addressing_[i];
00379 label newFaceI = morphMap.reverseFaceMap()[faceI];
00380 if (newFaceI >= 0)
00381 {
00382 newAddressing[n] = newFaceI;
00383 newFlipMap[n] = flipMap_[i];
00384 n++;
00385 }
00386 }
00387 newAddressing.setSize(n);
00388 newFlipMap.setSize(n);
00389
00390 addressing_.transfer(newAddressing);
00391 flipMap_.transfer(newFlipMap);
00392
00393 updateSet();
00394 }
00395
00396
00397 void faceZoneSet::writeDebug
00398 (
00399 Ostream& os,
00400 const primitiveMesh& mesh,
00401 const label maxLen
00402 ) const
00403 {
00404 faceSet::writeDebug(os, mesh, maxLen);
00405 }
00406
00407
00408
00409
00410 }
00411
00412