1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "fvPatchMapper.H"
29 #include "fvBoundaryMesh.H"
31 #include "mapPolyMesh.H"
32 #include "faceMapper.H"
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 void Foam::fvPatchMapper::calcAddressing() const
41 || interpolationAddrPtr_
47 "void fvPatchMapper::calcAddressing() const)"
48 ) << "Addressing already calculated"
53 const label oldPatchStart =
54 faceMap_.oldPatchStarts()[patch_.index()];
56 const label oldPatchEnd =
57 oldPatchStart + faceMap_.oldPatchSizes()[patch_.index()];
59 // Assemble the maps: slice to patch
62 // Direct mapping - slice to size
63 directAddrPtr_ = new labelList
67 static_cast<const labelList&>(faceMap_.directAddressing())
70 labelList& addr = *directAddrPtr_;
72 // Adjust mapping to manage hits into other patches and into
78 addr[faceI] >= oldPatchStart
79 && addr[faceI] < oldPatchEnd
82 addr[faceI] -= oldPatchStart;
92 if (addr.size() > 0 && min(addr) < 0)
96 "void fvPatchMapper::calcAddressing() const"
97 ) << "Error in patch mapping for patch "
98 << patch_.index() << " named " << patch_.name()
105 // Interpolative mapping
106 interpolationAddrPtr_ =
109 patch_.patchSlice(faceMap_.addressing())
111 labelListList& addr = *interpolationAddrPtr_;
116 patch_.patchSlice(faceMap_.weights())
118 scalarListList& w = *weightsPtr_;
120 // Adjust mapping to manage hits into other patches and into
124 labelList& curAddr = addr[faceI];
125 scalarList& curW = w[faceI];
129 min(curAddr) >= oldPatchStart
130 && max(curAddr) < oldPatchEnd
133 // No adjustment of weights, just subtract patch start
136 curAddr[i] -= oldPatchStart;
141 // Need to recalculate weights to exclude hits into internal
142 labelList newAddr(curAddr.size(), false);
143 scalarField newWeights(curAddr.size());
146 forAll (curAddr, lfI)
150 curAddr[lfI] >= oldPatchStart
151 && curAddr[lfI] < oldPatchEnd
154 newAddr[nActive] = curAddr[lfI] - oldPatchStart;
155 newWeights[nActive] = curW[lfI];
160 // Cater for bad mapping
163 newAddr[nActive] = 0;
164 newWeights[nActive] = 1;
168 newAddr.setSize(nActive);
169 newWeights.setSize(nActive);
171 // Re-scale the weights
172 newWeights /= sum(newWeights);
174 // Reset addressing and weights
184 if (min(addr[faceI]) < 0)
188 "void fvPatchMapper::calcAddressing() const"
189 ) << "Error in patch mapping for patch "
190 << patch_.index() << " named " << patch_.name()
192 << abort(FatalError);
200 void Foam::fvPatchMapper::clearOut()
202 deleteDemandDrivenData(directAddrPtr_);
203 deleteDemandDrivenData(interpolationAddrPtr_);
204 deleteDemandDrivenData(weightsPtr_);
208 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
210 // Construct from components
211 Foam::fvPatchMapper::fvPatchMapper
213 const fvPatch& patch,
214 const faceMapper& faceMap
219 sizeBeforeMapping_(faceMap.oldPatchSizes()[patch_.index()]),
221 directAddrPtr_(NULL),
222 interpolationAddrPtr_(NULL),
227 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
229 Foam::fvPatchMapper::~fvPatchMapper()
235 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
237 const Foam::unallocLabelList& Foam::fvPatchMapper::directAddressing() const
243 "const unallocLabelList& fvPatchMapper::directAddressing() const"
244 ) << "Requested direct addressing for an interpolative mapper."
245 << abort(FatalError);
253 return *directAddrPtr_;
257 const Foam::labelListList& Foam::fvPatchMapper::addressing() const
263 "const labelListList& fvPatchMapper::addressing() const"
264 ) << "Requested interpolative addressing for a direct mapper."
265 << abort(FatalError);
268 if (!interpolationAddrPtr_)
273 return *interpolationAddrPtr_;
277 const Foam::scalarListList& Foam::fvPatchMapper::weights() const
283 "const scalarListList& fvPatchMapper::weights() const"
284 ) << "Requested interpolative weights for a direct mapper."
285 << abort(FatalError);
297 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
300 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
303 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
306 // ************************************************************************* //