1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 PolyPatch mapper for the face tetFem decomposition
27 \*---------------------------------------------------------------------------*/
29 #include "tetPolyPatchMapper.H"
30 #include "tetPolyPatch.H"
31 #include "tetPolyBoundaryMesh.H"
32 #include "tetPolyMesh.H"
33 #include "mapPolyMesh.H"
34 #include "pointMapper.H"
35 #include "faceMapper.H"
36 #include "faceTetPolyPatch.H"
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 void Foam::tetPolyPatchMapper::calcAddressing() const
46 || interpolationAddrPtr_
52 "void tetPolyPatchMapper::calcAddressing() const)"
53 ) << "Addressing already calculated"
59 // Calculate direct (if all are direct)
60 directPtr_ = new bool(pMapper_.direct() && fMapper_.direct());
62 const labelList& curPatchPointMap = mpm_.patchPointMap()[patch_.index()];
64 const label patchOffset = mpm_.oldPatchStarts()[patch_.index()];
65 const label oldPatchFaceOffset = mpm_.oldPatchNMeshPoints()[patch_.index()];
68 // If it's a face patch, insert the faces
70 refCast<const faceTetPolyPatch>(patch_).patch();
72 const label curPatchStart = p.start();
73 const label curPatchEnd = curPatchStart + p.size();
76 const label oldPatchStart = mpm_.oldPatchStarts()[patch_.index()];
78 const label oldPatchEnd =
79 oldPatchStart + mpm_.oldPatchSizes()[patch_.index()];
85 directAddrPtr_ = new labelList(size());
86 labelList& addr = *directAddrPtr_;
89 forAll (curPatchPointMap, pointI)
91 if (curPatchPointMap[pointI] > -1)
93 addr[nAddr] = curPatchPointMap[pointI];
102 const labelList& mappedFaces = fMapper_.directAddressing();
105 for (label faceI = curPatchStart; faceI < curPatchEnd; faceI++)
109 mappedFaces[faceI] >= oldPatchStart
110 && mappedFaces[faceI] < oldPatchEnd
114 mappedFaces[faceI] - patchOffset + oldPatchFaceOffset;
126 // Interpolative mapping
127 interpolationAddrPtr_ = new labelListList(size());
128 labelListList& addr = *interpolationAddrPtr_;
130 weightsPtr_ = new scalarListList(size());
131 scalarListList& w = *weightsPtr_;
137 forAll (curPatchPointMap, pointI)
139 if (curPatchPointMap[pointI] > -1)
141 addr[nAddr] = labelList(1, curPatchPointMap[pointI]);
145 addr[nAddr] = labelList(1, 0);
148 w[nAddr] = scalarList(1, 1.0);
152 const labelListList& mappedFaces = fMapper_.addressing();
153 const scalarListList& faceWeights = fMapper_.weights();
156 for (label faceI = curPatchStart; faceI < curPatchEnd; faceI++)
158 labelList& curAddr = addr[nAddr];
159 scalarList& curW = w[nAddr];
162 const labelList& curMf = mappedFaces[faceI];
163 curAddr.setSize(curMf.size());
165 const scalarList& curMfWeights = faceWeights[faceI];
166 curW.setSize(curMfWeights.size());
172 curMf[lfI] >= oldPatchStart
173 && curMf[lfI] < oldPatchEnd
177 curMf[lfI] - patchOffset + oldPatchFaceOffset;
179 curW[nActive] = curMfWeights[lfI];
185 // Cater for bad mapping
188 curAddr[nActive] = 0;
193 curAddr.setSize(nActive);
194 curW.setSize(nActive);
196 // Re-scale the weights
197 scalar sumW = sum(curW);
210 void Foam::tetPolyPatchMapper::clearOut()
212 deleteDemandDrivenData(directPtr_);
213 deleteDemandDrivenData(directAddrPtr_);
214 deleteDemandDrivenData(interpolationAddrPtr_);
215 deleteDemandDrivenData(weightsPtr_);
219 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
221 // Construct from components
222 Foam::tetPolyPatchMapper::tetPolyPatchMapper
224 const tetPolyPatch& patch,
225 const mapPolyMesh& meshMap,
226 const pointMapper& pMapper,
227 const faceMapper& fMapper
235 directAddrPtr_(NULL),
236 interpolationAddrPtr_(NULL),
241 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
243 Foam::tetPolyPatchMapper::~tetPolyPatchMapper()
249 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
251 Foam::label Foam::tetPolyPatchMapper::size() const
253 return patch_.size();
257 Foam::label Foam::tetPolyPatchMapper::sizeBeforeMapping() const
260 mpm_.oldPatchSizes()[patch_.index()]
261 + mpm_.oldPatchNMeshPoints()[patch_.index()];
265 bool Foam::tetPolyPatchMapper::direct() const
276 const Foam::unallocLabelList&
277 Foam::tetPolyPatchMapper::directAddressing() const
283 "const unallocLabelList& tetPolyPatchMapper::"
284 "directAddressing() const"
285 ) << "Requested direct addressing for an interpolative mapper."
286 << abort(FatalError);
294 return *directAddrPtr_;
298 const Foam::labelListList&
299 Foam::tetPolyPatchMapper::addressing() const
305 "const labelListList& tetPolyPatchMapper::"
307 ) << "Requested interpolative addressing for a direct mapper."
308 << abort(FatalError);
311 if (!interpolationAddrPtr_)
316 return *interpolationAddrPtr_;
320 const Foam::scalarListList& Foam::tetPolyPatchMapper::weights() const
326 "const scalarListList& tetPolyPatchMapper::"
328 ) << "Requested interpolative weights for a direct mapper."
329 << abort(FatalError);
341 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
344 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
347 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
350 // ************************************************************************* //