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 "cellZoneSet.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(cellZoneSet, 0);
00042
00043 addToRunTimeSelectionTable(topoSet, cellZoneSet, word);
00044 addToRunTimeSelectionTable(topoSet, cellZoneSet, size);
00045 addToRunTimeSelectionTable(topoSet, cellZoneSet, set);
00046
00047
00048
00049
00050 void cellZoneSet::updateSet()
00051 {
00052 labelList order;
00053 sortedOrder(addressing_, order);
00054 inplaceReorder(order, addressing_);
00055
00056 cellSet::clearStorage();
00057 cellSet::resize(2*addressing_.size());
00058 forAll(addressing_, i)
00059 {
00060 cellSet::insert(addressing_[i]);
00061 }
00062 }
00063
00064
00065
00066
00067 cellZoneSet::cellZoneSet
00068 (
00069 const polyMesh& mesh,
00070 const word& name,
00071 readOption r,
00072 writeOption w
00073 )
00074 :
00075 cellSet(mesh, name, 1000),
00076 mesh_(mesh),
00077 addressing_(0)
00078 {
00079 const cellZoneMesh& cellZones = mesh.cellZones();
00080 label zoneID = cellZones.findZoneID(name);
00081
00082 if
00083 (
00084 (r == IOobject::MUST_READ)
00085 || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
00086 )
00087 {
00088 const cellZone& fz = cellZones[zoneID];
00089 addressing_ = fz;
00090 }
00091
00092 updateSet();
00093
00094 check(mesh.nCells());
00095 }
00096
00097
00098 cellZoneSet::cellZoneSet
00099 (
00100 const polyMesh& mesh,
00101 const word& name,
00102 const label size,
00103 writeOption w
00104 )
00105 :
00106 cellSet(mesh, name, size, w),
00107 mesh_(mesh),
00108 addressing_(0)
00109 {
00110 updateSet();
00111 }
00112
00113
00114 cellZoneSet::cellZoneSet
00115 (
00116 const polyMesh& mesh,
00117 const word& name,
00118 const topoSet& set,
00119 writeOption w
00120 )
00121 :
00122 cellSet(mesh, name, set.size(), w),
00123 mesh_(mesh),
00124 addressing_(refCast<const cellZoneSet>(set).addressing())
00125 {
00126 updateSet();
00127 }
00128
00129
00130
00131
00132 cellZoneSet::~cellZoneSet()
00133 {}
00134
00135
00136
00137
00138 void cellZoneSet::invert(const label maxLen)
00139 {
00140 label n = 0;
00141
00142 for (label cellI = 0; cellI < maxLen; cellI++)
00143 {
00144 if (!found(cellI))
00145 {
00146 addressing_[n] = cellI;
00147 n++;
00148 }
00149 }
00150 addressing_.setSize(n);
00151 updateSet();
00152 }
00153
00154
00155 void cellZoneSet::subset(const topoSet& set)
00156 {
00157 DynamicList<label> newAddressing(addressing_.size());
00158
00159 const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
00160
00161 forAll(fSet.addressing(), i)
00162 {
00163 label cellI = fSet.addressing()[i];
00164
00165 if (found(cellI))
00166 {
00167 newAddressing.append(cellI);
00168 }
00169 }
00170
00171 addressing_.transfer(newAddressing);
00172 updateSet();
00173 }
00174
00175
00176 void cellZoneSet::addSet(const topoSet& set)
00177 {
00178 DynamicList<label> newAddressing(addressing_);
00179
00180 const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
00181
00182 forAll(fSet.addressing(), i)
00183 {
00184 label cellI = fSet.addressing()[i];
00185
00186 if (!found(cellI))
00187 {
00188 newAddressing.append(cellI);
00189 }
00190 }
00191
00192 addressing_.transfer(newAddressing);
00193 updateSet();
00194 }
00195
00196
00197 void cellZoneSet::deleteSet(const topoSet& set)
00198 {
00199 DynamicList<label> newAddressing(addressing_.size());
00200
00201 const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
00202
00203 forAll(addressing_, i)
00204 {
00205 label cellI = addressing_[i];
00206
00207 if (!fSet.found(cellI))
00208 {
00209
00210 newAddressing.append(cellI);
00211 }
00212 }
00213
00214 addressing_.transfer(newAddressing);
00215 updateSet();
00216 }
00217
00218
00219 void cellZoneSet::sync(const polyMesh& mesh)
00220 {}
00221
00222
00223 label cellZoneSet::maxSize(const polyMesh& mesh) const
00224 {
00225 return mesh.nCells();
00226 }
00227
00228
00229
00230 bool cellZoneSet::writeObject
00231 (
00232 IOstream::streamFormat s,
00233 IOstream::versionNumber v,
00234 IOstream::compressionType c
00235 ) const
00236 {
00237
00238 word oldTypeName = typeName;
00239 const_cast<word&>(type()) = cellSet::typeName;
00240 bool ok = cellSet::writeObject(s, v, c);
00241 const_cast<word&>(type()) = oldTypeName;
00242
00243
00244 cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
00245 label zoneID = cellZones.findZoneID(name());
00246
00247 if (zoneID == -1)
00248 {
00249 zoneID = cellZones.size();
00250
00251 cellZones.setSize(zoneID+1);
00252 cellZones.set
00253 (
00254 zoneID,
00255 new cellZone
00256 (
00257 name(),
00258 addressing_,
00259 zoneID,
00260 cellZones
00261 )
00262 );
00263 }
00264 else
00265 {
00266 cellZones[zoneID] = addressing_;
00267 }
00268 cellZones.clearAddressing();
00269
00270 return ok && cellZones.write();
00271 }
00272
00273
00274 void cellZoneSet::updateMesh(const mapPolyMesh& morphMap)
00275 {
00276
00277 labelList newAddressing(addressing_.size());
00278
00279 label n = 0;
00280 forAll(addressing_, i)
00281 {
00282 label cellI = addressing_[i];
00283 label newCellI = morphMap.reverseCellMap()[cellI];
00284 if (newCellI >= 0)
00285 {
00286 newAddressing[n] = newCellI;
00287 n++;
00288 }
00289 }
00290 newAddressing.setSize(n);
00291
00292 addressing_.transfer(newAddressing);
00293
00294 updateSet();
00295 }
00296
00297
00298 void cellZoneSet::writeDebug
00299 (
00300 Ostream& os,
00301 const primitiveMesh& mesh,
00302 const label maxLen
00303 ) const
00304 {
00305 cellSet::writeDebug(os, mesh, maxLen);
00306 }
00307
00308
00309
00310
00311 }
00312
00313