cellMapper.C
Go to the documentation of this file.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 "cellMapper.H"
00028 #include "demandDrivenData.H"
00029 #include "polyMesh.H"
00030 #include "mapPolyMesh.H"
00031
00032
00033
00034
00035
00036
00037 void Foam::cellMapper::calcAddressing() const
00038 {
00039 if
00040 (
00041 directAddrPtr_
00042 || interpolationAddrPtr_
00043 || weightsPtr_
00044 || insertedCellLabelsPtr_
00045 )
00046 {
00047 FatalErrorIn("void cellMapper::calcAddressing() const")
00048 << "Addressing already calculated."
00049 << abort(FatalError);
00050 }
00051
00052 if (direct())
00053 {
00054
00055
00056 directAddrPtr_ = new labelList(mpm_.cellMap());
00057 labelList& directAddr = *directAddrPtr_;
00058
00059
00060
00061
00062 insertedCellLabelsPtr_ = new labelList(mesh_.nCells());
00063 labelList& insertedCells = *insertedCellLabelsPtr_;
00064
00065 label nInsertedCells = 0;
00066
00067 forAll (directAddr, cellI)
00068 {
00069 if (directAddr[cellI] < 0)
00070 {
00071
00072 directAddr[cellI] = 0;
00073 insertedCells[nInsertedCells] = cellI;
00074 nInsertedCells++;
00075 }
00076 }
00077
00078 insertedCells.setSize(nInsertedCells);
00079 }
00080 else
00081 {
00082
00083
00084 interpolationAddrPtr_ = new labelListList(mesh_.nCells());
00085 labelListList& addr = *interpolationAddrPtr_;
00086
00087 weightsPtr_ = new scalarListList(mesh_.nCells());
00088 scalarListList& w = *weightsPtr_;
00089
00090 const List<objectMap>& cfp = mpm_.cellsFromPointsMap();
00091
00092 forAll (cfp, cfpI)
00093 {
00094
00095 const labelList& mo = cfp[cfpI].masterObjects();
00096
00097 label cellI = cfp[cfpI].index();
00098
00099 if (addr[cellI].size())
00100 {
00101 FatalErrorIn("void cellMapper::calcAddressing() const")
00102 << "Master cell " << cellI
00103 << " mapped from point cells " << mo
00104 << " already destination of mapping." << abort(FatalError);
00105 }
00106
00107
00108 addr[cellI] = mo;
00109 w[cellI] = scalarList(mo.size(), 1.0/mo.size());
00110 }
00111
00112 const List<objectMap>& cfe = mpm_.cellsFromEdgesMap();
00113
00114 forAll (cfe, cfeI)
00115 {
00116
00117 const labelList& mo = cfe[cfeI].masterObjects();
00118
00119 label cellI = cfe[cfeI].index();
00120
00121 if (addr[cellI].size())
00122 {
00123 FatalErrorIn("void cellMapper::calcAddressing() const")
00124 << "Master cell " << cellI
00125 << " mapped from edge cells " << mo
00126 << " already destination of mapping." << abort(FatalError);
00127 }
00128
00129
00130 addr[cellI] = mo;
00131 w[cellI] = scalarList(mo.size(), 1.0/mo.size());
00132 }
00133
00134 const List<objectMap>& cff = mpm_.cellsFromFacesMap();
00135
00136 forAll (cff, cffI)
00137 {
00138
00139 const labelList& mo = cff[cffI].masterObjects();
00140
00141 label cellI = cff[cffI].index();
00142
00143 if (addr[cellI].size())
00144 {
00145 FatalErrorIn("void cellMapper::calcAddressing() const")
00146 << "Master cell " << cellI
00147 << " mapped from face cells " << mo
00148 << " already destination of mapping." << abort(FatalError);
00149 }
00150
00151
00152 addr[cellI] = mo;
00153 w[cellI] = scalarList(mo.size(), 1.0/mo.size());
00154 }
00155
00156 const List<objectMap>& cfc = mpm_.cellsFromCellsMap();
00157
00158 forAll (cfc, cfcI)
00159 {
00160
00161 const labelList& mo = cfc[cfcI].masterObjects();
00162
00163 label cellI = cfc[cfcI].index();
00164
00165 if (addr[cellI].size())
00166 {
00167 FatalErrorIn("void cellMapper::calcAddressing() const")
00168 << "Master cell " << cellI
00169 << " mapped from cell cells " << mo
00170 << " already destination of mapping." << abort(FatalError);
00171 }
00172
00173
00174 addr[cellI] = mo;
00175 w[cellI] = scalarList(mo.size(), 1.0/mo.size());
00176 }
00177
00178
00179
00180
00181
00182 const labelList& cm = mpm_.cellMap();
00183
00184 forAll (cm, cellI)
00185 {
00186 if (cm[cellI] > -1 && addr[cellI].empty())
00187 {
00188
00189 addr[cellI] = labelList(1, cm[cellI]);
00190 w[cellI] = scalarList(1, 1.0);
00191 }
00192 }
00193
00194
00195
00196 insertedCellLabelsPtr_ = new labelList(mesh_.nCells());
00197 labelList& insertedCells = *insertedCellLabelsPtr_;
00198
00199 label nInsertedCells = 0;
00200
00201 forAll (addr, cellI)
00202 {
00203 if (addr[cellI].empty())
00204 {
00205
00206 addr[cellI] = labelList(1, 0);
00207 w[cellI] = scalarList(1, 1.0);
00208
00209 insertedCells[nInsertedCells] = cellI;
00210 nInsertedCells++;
00211 }
00212 }
00213
00214 insertedCells.setSize(nInsertedCells);
00215 }
00216 }
00217
00218
00219 void Foam::cellMapper::clearOut()
00220 {
00221 deleteDemandDrivenData(directAddrPtr_);
00222 deleteDemandDrivenData(interpolationAddrPtr_);
00223 deleteDemandDrivenData(weightsPtr_);
00224 deleteDemandDrivenData(insertedCellLabelsPtr_);
00225 }
00226
00227
00228
00229
00230
00231 Foam::cellMapper::cellMapper(const mapPolyMesh& mpm)
00232 :
00233 mesh_(mpm.mesh()),
00234 mpm_(mpm),
00235 insertedCells_(true),
00236 direct_(false),
00237 directAddrPtr_(NULL),
00238 interpolationAddrPtr_(NULL),
00239 weightsPtr_(NULL),
00240 insertedCellLabelsPtr_(NULL)
00241 {
00242
00243 if
00244 (
00245 mpm_.cellsFromPointsMap().empty()
00246 && mpm_.cellsFromEdgesMap().empty()
00247 && mpm_.cellsFromFacesMap().empty()
00248 && mpm_.cellsFromCellsMap().empty()
00249 )
00250 {
00251 direct_ = true;
00252 }
00253 else
00254 {
00255 direct_ = false;
00256 }
00257
00258
00259 if (direct_ && (mpm_.cellMap().empty() || min(mpm_.cellMap()) > -1))
00260 {
00261 insertedCells_ = false;
00262 }
00263 else
00264 {
00265
00266
00267
00268
00269
00270 labelList cm(mesh_.nCells(), -1);
00271
00272 const List<objectMap>& cfp = mpm_.cellsFromPointsMap();
00273
00274 forAll (cfp, cfpI)
00275 {
00276 cm[cfp[cfpI].index()] = 0;
00277 }
00278
00279 const List<objectMap>& cfe = mpm_.cellsFromEdgesMap();
00280
00281 forAll (cfe, cfeI)
00282 {
00283 cm[cfe[cfeI].index()] = 0;
00284 }
00285
00286 const List<objectMap>& cff = mpm_.cellsFromFacesMap();
00287
00288 forAll (cff, cffI)
00289 {
00290 cm[cff[cffI].index()] = 0;
00291 }
00292
00293 const List<objectMap>& cfc = mpm_.cellsFromCellsMap();
00294
00295 forAll (cfc, cfcI)
00296 {
00297 cm[cfc[cfcI].index()] = 0;
00298 }
00299
00300 if (min(cm) < 0)
00301 {
00302 insertedCells_ = true;
00303 }
00304 }
00305 }
00306
00307
00308
00309
00310 Foam::cellMapper::~cellMapper()
00311 {
00312 clearOut();
00313 }
00314
00315
00316
00317
00318 Foam::label Foam::cellMapper::size() const
00319 {
00320 return mpm_.cellMap().size();
00321 }
00322
00323
00324 Foam::label Foam::cellMapper::sizeBeforeMapping() const
00325 {
00326 return mpm_.nOldCells();
00327 }
00328
00329
00330 const Foam::unallocLabelList& Foam::cellMapper::directAddressing() const
00331 {
00332 if (!direct())
00333 {
00334 FatalErrorIn
00335 (
00336 "const unallocLabelList& cellMapper::directAddressing() const"
00337 ) << "Requested direct addressing for an interpolative mapper."
00338 << abort(FatalError);
00339 }
00340
00341 if (!insertedObjects())
00342 {
00343
00344 return mpm_.cellMap();
00345 }
00346 else
00347 {
00348 if (!directAddrPtr_)
00349 {
00350 calcAddressing();
00351 }
00352
00353 return *directAddrPtr_;
00354 }
00355 }
00356
00357
00358 const Foam::labelListList& Foam::cellMapper::addressing() const
00359 {
00360 if (direct())
00361 {
00362 FatalErrorIn
00363 (
00364 "const labelListList& cellMapper::addressing() const"
00365 ) << "Requested interpolative addressing for a direct mapper."
00366 << abort(FatalError);
00367 }
00368
00369 if (!interpolationAddrPtr_)
00370 {
00371 calcAddressing();
00372 }
00373
00374 return *interpolationAddrPtr_;
00375 }
00376
00377
00378 const Foam::scalarListList& Foam::cellMapper::weights() const
00379 {
00380 if (direct())
00381 {
00382 FatalErrorIn
00383 (
00384 "const scalarListList& cellMapper::weights() const"
00385 ) << "Requested interpolative weights for a direct mapper."
00386 << abort(FatalError);
00387 }
00388
00389 if (!weightsPtr_)
00390 {
00391 calcAddressing();
00392 }
00393
00394 return *weightsPtr_;
00395 }
00396
00397
00398 const Foam::labelList& Foam::cellMapper::insertedObjectLabels() const
00399 {
00400 if (!insertedCellLabelsPtr_)
00401 {
00402 if (!insertedObjects())
00403 {
00404
00405 insertedCellLabelsPtr_ = new labelList(0);
00406 }
00407 else
00408 {
00409 calcAddressing();
00410 }
00411 }
00412
00413 return *insertedCellLabelsPtr_;
00414 }
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
Copyright © 2000-2009 OpenCFD Ltd