pointMapper.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 "pointMapper.H"
00028 #include "demandDrivenData.H"
00029 #include "pointMesh.H"
00030 #include "mapPolyMesh.H"
00031
00032
00033
00034
00035
00036
00037 void Foam::pointMapper::calcAddressing() const
00038 {
00039 if
00040 (
00041 directAddrPtr_
00042 || interpolationAddrPtr_
00043 || weightsPtr_
00044 || insertedPointLabelsPtr_
00045 )
00046 {
00047 FatalErrorIn("void pointMapper::calcAddressing() const")
00048 << "Addressing already calculated."
00049 << abort(FatalError);
00050 }
00051
00052 if (direct())
00053 {
00054
00055
00056 directAddrPtr_ = new labelList(mpm_.pointMap());
00057 labelList& directAddr = *directAddrPtr_;
00058
00059
00060
00061
00062 insertedPointLabelsPtr_ = new labelList(pMesh_.size());
00063 labelList& insertedPoints = *insertedPointLabelsPtr_;
00064
00065 label nInsertedPoints = 0;
00066
00067 forAll (directAddr, pointI)
00068 {
00069 if (directAddr[pointI] < 0)
00070 {
00071
00072 directAddr[pointI] = 0;
00073 insertedPoints[nInsertedPoints] = pointI;
00074 nInsertedPoints++;
00075 }
00076 }
00077
00078 insertedPoints.setSize(nInsertedPoints);
00079 }
00080 else
00081 {
00082
00083
00084 interpolationAddrPtr_ = new labelListList(pMesh_.size());
00085 labelListList& addr = *interpolationAddrPtr_;
00086
00087 weightsPtr_ = new scalarListList(pMesh_.size());
00088 scalarListList& w = *weightsPtr_;
00089
00090
00091 const List<objectMap>& cfc = mpm_.pointsFromPointsMap();
00092
00093 forAll (cfc, cfcI)
00094 {
00095
00096 const labelList& mo = cfc[cfcI].masterObjects();
00097
00098 label pointI = cfc[cfcI].index();
00099
00100 if (addr[pointI].size())
00101 {
00102 FatalErrorIn("void pointMapper::calcAddressing() const")
00103 << "Master point " << pointI
00104 << " mapped from points " << mo
00105 << " already destination of mapping." << abort(FatalError);
00106 }
00107
00108
00109 addr[pointI] = mo;
00110 w[pointI] = scalarList(mo.size(), 1.0/mo.size());
00111 }
00112
00113
00114
00115
00116
00117 const labelList& cm = mpm_.pointMap();
00118
00119 forAll (cm, pointI)
00120 {
00121 if (cm[pointI] > -1 && addr[pointI].empty())
00122 {
00123
00124 addr[pointI] = labelList(1, cm[pointI]);
00125 w[pointI] = scalarList(1, 1.0);
00126 }
00127 }
00128
00129
00130
00131 insertedPointLabelsPtr_ = new labelList(pMesh_.size());
00132 labelList& insertedPoints = *insertedPointLabelsPtr_;
00133
00134 label nInsertedPoints = 0;
00135
00136 forAll (addr, pointI)
00137 {
00138 if (addr[pointI].empty())
00139 {
00140
00141 addr[pointI] = labelList(1, 0);
00142 w[pointI] = scalarList(1, 1.0);
00143
00144 insertedPoints[nInsertedPoints] = pointI;
00145 nInsertedPoints++;
00146 }
00147 }
00148
00149 insertedPoints.setSize(nInsertedPoints);
00150 }
00151 }
00152
00153
00154 void Foam::pointMapper::clearOut()
00155 {
00156 deleteDemandDrivenData(directAddrPtr_);
00157 deleteDemandDrivenData(interpolationAddrPtr_);
00158 deleteDemandDrivenData(weightsPtr_);
00159 deleteDemandDrivenData(insertedPointLabelsPtr_);
00160 }
00161
00162
00163
00164
00165
00166 Foam::pointMapper::pointMapper(const pointMesh& pMesh, const mapPolyMesh& mpm)
00167 :
00168 pMesh_(pMesh),
00169 mpm_(mpm),
00170 insertedPoints_(true),
00171 direct_(false),
00172 directAddrPtr_(NULL),
00173 interpolationAddrPtr_(NULL),
00174 weightsPtr_(NULL),
00175 insertedPointLabelsPtr_(NULL)
00176 {
00177
00178 if (mpm_.pointsFromPointsMap().empty())
00179 {
00180 direct_ = true;
00181 }
00182 else
00183 {
00184 direct_ = false;
00185 }
00186
00187
00188 if (direct_ && (mpm_.pointMap().empty() || min(mpm_.pointMap()) > -1))
00189 {
00190 insertedPoints_ = false;
00191 }
00192 else
00193 {
00194
00195
00196
00197
00198 labelList cm(pMesh_.size(), -1);
00199
00200 const List<objectMap>& cfc = mpm_.pointsFromPointsMap();
00201
00202 forAll (cfc, cfcI)
00203 {
00204 cm[cfc[cfcI].index()] = 0;
00205 }
00206
00207 if (min(cm) < 0)
00208 {
00209 insertedPoints_ = true;
00210 }
00211 }
00212 }
00213
00214
00215
00216
00217 Foam::pointMapper::~pointMapper()
00218 {
00219 clearOut();
00220 }
00221
00222
00223
00224
00225 Foam::label Foam::pointMapper::size() const
00226 {
00227 return mpm_.pointMap().size();
00228 }
00229
00230
00231 Foam::label Foam::pointMapper::sizeBeforeMapping() const
00232 {
00233 return mpm_.nOldPoints();
00234 }
00235
00236
00237 const Foam::unallocLabelList& Foam::pointMapper::directAddressing() const
00238 {
00239 if (!direct())
00240 {
00241 FatalErrorIn
00242 (
00243 "const unallocLabelList& pointMapper::directAddressing() const"
00244 ) << "Requested direct addressing for an interpolative mapper."
00245 << abort(FatalError);
00246 }
00247
00248 if (!insertedObjects())
00249 {
00250
00251 return mpm_.pointMap();
00252 }
00253 else
00254 {
00255 if (!directAddrPtr_)
00256 {
00257 calcAddressing();
00258 }
00259
00260 return *directAddrPtr_;
00261 }
00262 }
00263
00264
00265 const Foam::labelListList& Foam::pointMapper::addressing() const
00266 {
00267 if (direct())
00268 {
00269 FatalErrorIn
00270 (
00271 "const labelListList& pointMapper::addressing() const"
00272 ) << "Requested interpolative addressing for a direct mapper."
00273 << abort(FatalError);
00274 }
00275
00276 if (!interpolationAddrPtr_)
00277 {
00278 calcAddressing();
00279 }
00280
00281 return *interpolationAddrPtr_;
00282 }
00283
00284
00285 const Foam::scalarListList& Foam::pointMapper::weights() const
00286 {
00287 if (direct())
00288 {
00289 FatalErrorIn
00290 (
00291 "const scalarListList& pointMapper::weights() const"
00292 ) << "Requested interpolative weights for a direct mapper."
00293 << abort(FatalError);
00294 }
00295
00296 if (!weightsPtr_)
00297 {
00298 calcAddressing();
00299 }
00300
00301 return *weightsPtr_;
00302 }
00303
00304
00305 const Foam::labelList& Foam::pointMapper::insertedObjectLabels() const
00306 {
00307 if (!insertedPointLabelsPtr_)
00308 {
00309 if (!insertedObjects())
00310 {
00311
00312 insertedPointLabelsPtr_ = new labelList(0);
00313 }
00314 else
00315 {
00316 calcAddressing();
00317 }
00318 }
00319
00320 return *insertedPointLabelsPtr_;
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
Copyright © 2000-2009 OpenCFD Ltd