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