1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "pointMapper.H"
27 #include "demandDrivenData.H"
28 #include "pointMesh.H"
29 #include "mapPolyMesh.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 void Foam::pointMapper::calcAddressing() const
41 || interpolationAddrPtr_
43 || insertedPointLabelsPtr_
46 FatalErrorIn("void pointMapper::calcAddressing() const")
47 << "Addressing already calculated."
53 // Direct addressing, no weights
55 directAddrPtr_ = new labelList(mpm_.pointMap());
56 labelList& directAddr = *directAddrPtr_;
58 // Not necessary to resize the list as there are no retired points
59 // directAddr.setSize(pMesh_.size());
61 insertedPointLabelsPtr_ = new labelList(pMesh_.size());
62 labelList& insertedPoints = *insertedPointLabelsPtr_;
64 label nInsertedPoints = 0;
66 forAll(directAddr, pointI)
68 if (directAddr[pointI] < 0)
70 // Found inserted point
71 directAddr[pointI] = 0;
72 insertedPoints[nInsertedPoints] = pointI;
77 insertedPoints.setSize(nInsertedPoints);
81 // Interpolative addressing
83 interpolationAddrPtr_ = new labelListList(pMesh_.size());
84 labelListList& addr = *interpolationAddrPtr_;
86 weightsPtr_ = new scalarListList(pMesh_.size());
87 scalarListList& w = *weightsPtr_;
89 // Points created from other points (i.e. points merged into it).
90 const List<objectMap>& cfc = mpm_.pointsFromPointsMap();
95 const labelList& mo = cfc[cfcI].masterObjects();
97 label pointI = cfc[cfcI].index();
99 if (addr[pointI].size())
101 FatalErrorIn("void pointMapper::calcAddressing() const")
102 << "Master point " << pointI
103 << " mapped from points " << mo
104 << " already destination of mapping." << abort(FatalError);
107 // Map from masters, uniform weights
109 w[pointI] = scalarList(mo.size(), 1.0/mo.size());
113 // Do mapped points. Note that can already be set from pointsFromPoints
114 // so check if addressing size still zero.
116 const labelList& cm = mpm_.pointMap();
120 if (cm[pointI] > -1 && addr[pointI].empty())
122 // Mapped from a single point
123 addr[pointI] = labelList(1, cm[pointI]);
124 w[pointI] = scalarList(1, 1.0);
128 // Grab inserted points (for them the size of addressing is still zero)
130 insertedPointLabelsPtr_ = new labelList(pMesh_.size());
131 labelList& insertedPoints = *insertedPointLabelsPtr_;
133 label nInsertedPoints = 0;
137 if (addr[pointI].empty())
139 // Mapped from a dummy point. Take point 0 with weight 1.
140 addr[pointI] = labelList(1, 0);
141 w[pointI] = scalarList(1, 1.0);
143 insertedPoints[nInsertedPoints] = pointI;
148 insertedPoints.setSize(nInsertedPoints);
153 void Foam::pointMapper::clearOut()
155 deleteDemandDrivenData(directAddrPtr_);
156 deleteDemandDrivenData(interpolationAddrPtr_);
157 deleteDemandDrivenData(weightsPtr_);
158 deleteDemandDrivenData(insertedPointLabelsPtr_);
162 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
164 // Construct from components
165 Foam::pointMapper::pointMapper(const pointMesh& pMesh, const mapPolyMesh& mpm)
169 insertedPoints_(true),
171 directAddrPtr_(NULL),
172 interpolationAddrPtr_(NULL),
174 insertedPointLabelsPtr_(NULL)
176 // Check for possibility of direct mapping
177 if (mpm_.pointsFromPointsMap().empty())
186 // Check for inserted points
187 if (direct_ && (mpm_.pointMap().empty() || min(mpm_.pointMap()) > -1))
189 insertedPoints_ = false;
193 //Check if there are inserted points with no owner
195 // Make a copy of the point map, add the entries for points from points
196 // and check for left-overs
197 labelList cm(pMesh_.size(), -1);
199 const List<objectMap>& cfc = mpm_.pointsFromPointsMap();
203 cm[cfc[cfcI].index()] = 0;
208 insertedPoints_ = true;
214 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
216 Foam::pointMapper::~pointMapper()
222 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
224 Foam::label Foam::pointMapper::size() const
226 return mpm_.pointMap().size();
230 Foam::label Foam::pointMapper::sizeBeforeMapping() const
232 return mpm_.nOldPoints();
236 const Foam::labelUList& Foam::pointMapper::directAddressing() const
242 "const labelUList& pointMapper::directAddressing() const"
243 ) << "Requested direct addressing for an interpolative mapper."
244 << abort(FatalError);
247 if (!insertedObjects())
249 // No inserted points. Re-use pointMap
250 return mpm_.pointMap();
259 return *directAddrPtr_;
264 const Foam::labelListList& Foam::pointMapper::addressing() const
270 "const labelListList& pointMapper::addressing() const"
271 ) << "Requested interpolative addressing for a direct mapper."
272 << abort(FatalError);
275 if (!interpolationAddrPtr_)
280 return *interpolationAddrPtr_;
284 const Foam::scalarListList& Foam::pointMapper::weights() const
290 "const scalarListList& pointMapper::weights() const"
291 ) << "Requested interpolative weights for a direct mapper."
292 << abort(FatalError);
304 const Foam::labelList& Foam::pointMapper::insertedObjectLabels() const
306 if (!insertedPointLabelsPtr_)
308 if (!insertedObjects())
310 // There are no inserted points
311 insertedPointLabelsPtr_ = new labelList(0);
319 return *insertedPointLabelsPtr_;
323 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
326 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
329 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
332 // ************************************************************************* //