fvPatchMapper.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 "fvPatchMapper.H"
00028 #include "fvPatch.H"
00029 #include "fvBoundaryMesh.H"
00030 #include "fvMesh.H"
00031 #include "mapPolyMesh.H"
00032 #include "faceMapper.H"
00033
00034
00035
00036 void Foam::fvPatchMapper::calcAddressing() const
00037 {
00038 if
00039 (
00040 directAddrPtr_
00041 || interpolationAddrPtr_
00042 || weightsPtr_
00043 )
00044 {
00045 FatalErrorIn
00046 (
00047 "void fvPatchMapper::calcAddressing() const)"
00048 ) << "Addressing already calculated"
00049 << abort(FatalError);
00050 }
00051
00052
00053 const label oldPatchStart =
00054 faceMap_.oldPatchStarts()[patch_.index()];
00055
00056 const label oldPatchEnd =
00057 oldPatchStart + faceMap_.oldPatchSizes()[patch_.index()];
00058
00059
00060 if (direct())
00061 {
00062
00063 directAddrPtr_ = new labelList
00064 (
00065 patch_.patchSlice
00066 (
00067 static_cast<const labelList&>(faceMap_.directAddressing())
00068 )
00069 );
00070 labelList& addr = *directAddrPtr_;
00071
00072
00073
00074 forAll (addr, faceI)
00075 {
00076 if
00077 (
00078 addr[faceI] >= oldPatchStart
00079 && addr[faceI] < oldPatchEnd
00080 )
00081 {
00082 addr[faceI] -= oldPatchStart;
00083 }
00084 else
00085 {
00086 addr[faceI] = 0;
00087 }
00088 }
00089
00090 if (fvMesh::debug)
00091 {
00092 if (min(addr) < 0)
00093 {
00094 FatalErrorIn
00095 (
00096 "void fvPatchMapper::calcAddressing() const"
00097 ) << "Error in patch mapping for patch "
00098 << patch_.index() << " named " << patch_.name()
00099 << abort(FatalError);
00100 }
00101 }
00102 }
00103 else
00104 {
00105
00106 interpolationAddrPtr_ =
00107 new labelListList
00108 (
00109 patch_.patchSlice(faceMap_.addressing())
00110 );
00111 labelListList& addr = *interpolationAddrPtr_;
00112
00113 weightsPtr_ =
00114 new scalarListList
00115 (
00116 patch_.patchSlice(faceMap_.weights())
00117 );
00118 scalarListList& w = *weightsPtr_;
00119
00120
00121
00122 forAll (addr, faceI)
00123 {
00124 labelList& curAddr = addr[faceI];
00125 scalarList& curW = w[faceI];
00126
00127 if
00128 (
00129 min(curAddr) >= oldPatchStart
00130 && max(curAddr) < oldPatchEnd
00131 )
00132 {
00133
00134 forAll (curAddr, i)
00135 {
00136 curAddr[i] -= oldPatchStart;
00137 }
00138 }
00139 else
00140 {
00141
00142 labelList newAddr(curAddr.size(), false);
00143 scalarField newWeights(curAddr.size());
00144 label nActive = 0;
00145
00146 forAll (curAddr, lfI)
00147 {
00148 if
00149 (
00150 curAddr[lfI] >= oldPatchStart
00151 && curAddr[lfI] < oldPatchEnd
00152 )
00153 {
00154 newAddr[nActive] = curAddr[lfI] - oldPatchStart;
00155 newWeights[nActive] = curW[lfI];
00156 nActive++;
00157 }
00158 }
00159
00160
00161 if (nActive == 0)
00162 {
00163 newAddr[nActive] = 0;
00164 newWeights[nActive] = 1;
00165 nActive++;
00166 }
00167
00168 newAddr.setSize(nActive);
00169 newWeights.setSize(nActive);
00170
00171
00172 newWeights /= sum(newWeights);
00173
00174
00175 curAddr = newAddr;
00176 curW = newWeights;
00177 }
00178 }
00179
00180 if (fvMesh::debug)
00181 {
00182 forAll (addr, i)
00183 {
00184 if (min(addr[i]) < 0)
00185 {
00186 FatalErrorIn
00187 (
00188 "void fvPatchMapper::calcAddressing() const"
00189 ) << "Error in patch mapping for patch "
00190 << patch_.index() << " named " << patch_.name()
00191 << abort(FatalError);
00192 }
00193 }
00194 }
00195 }
00196 }
00197
00198
00199 void Foam::fvPatchMapper::clearOut()
00200 {
00201 deleteDemandDrivenData(directAddrPtr_);
00202 deleteDemandDrivenData(interpolationAddrPtr_);
00203 deleteDemandDrivenData(weightsPtr_);
00204 }
00205
00206
00207
00208
00209
00210 Foam::fvPatchMapper::fvPatchMapper
00211 (
00212 const fvPatch& patch,
00213 const faceMapper& faceMap
00214 )
00215 :
00216 patch_(patch),
00217 faceMap_(faceMap),
00218 sizeBeforeMapping_(faceMap.oldPatchSizes()[patch_.index()]),
00219 directAddrPtr_(NULL),
00220 interpolationAddrPtr_(NULL),
00221 weightsPtr_(NULL)
00222 {}
00223
00224
00225
00226
00227 Foam::fvPatchMapper::~fvPatchMapper()
00228 {
00229 clearOut();
00230 }
00231
00232
00233
00234
00235 const Foam::unallocLabelList& Foam::fvPatchMapper::directAddressing() const
00236 {
00237 if (!direct())
00238 {
00239 FatalErrorIn
00240 (
00241 "const unallocLabelList& fvPatchMapper::directAddressing() const"
00242 ) << "Requested direct addressing for an interpolative mapper."
00243 << abort(FatalError);
00244 }
00245
00246 if (!directAddrPtr_)
00247 {
00248 calcAddressing();
00249 }
00250
00251 return *directAddrPtr_;
00252 }
00253
00254
00255 const Foam::labelListList& Foam::fvPatchMapper::addressing() const
00256 {
00257 if (direct())
00258 {
00259 FatalErrorIn
00260 (
00261 "const labelListList& fvPatchMapper::addressing() const"
00262 ) << "Requested interpolative addressing for a direct mapper."
00263 << abort(FatalError);
00264 }
00265
00266 if (!interpolationAddrPtr_)
00267 {
00268 calcAddressing();
00269 }
00270
00271 return *interpolationAddrPtr_;
00272 }
00273
00274
00275 const Foam::scalarListList& Foam::fvPatchMapper::weights() const
00276 {
00277 if (direct())
00278 {
00279 FatalErrorIn
00280 (
00281 "const scalarListList& fvPatchMapper::weights() const"
00282 ) << "Requested interpolative weights for a direct mapper."
00283 << abort(FatalError);
00284 }
00285
00286 if (!weightsPtr_)
00287 {
00288 calcAddressing();
00289 }
00290
00291 return *weightsPtr_;
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
Copyright © 2000-2009 OpenCFD Ltd