1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 "pointMapper.H"
28 #include "demandDrivenData.H"
29 #include "pointMesh.H"
30 #include "mapPolyMesh.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 void Foam::pointMapper::calcAddressing() const
42 || interpolationAddrPtr_
44 || insertedPointLabelsPtr_
47 FatalErrorIn("void pointMapper::calcAddressing() const")
48 << "Addressing already calculated."
54 // Direct addressing, no weights
56 directAddrPtr_ = new labelList(mpm_.pointMap());
57 labelList& directAddr = *directAddrPtr_;
59 // Not necessary to resize the list as there are no retired points
60 // directAddr.setSize(pMesh_.size());
62 insertedPointLabelsPtr_ = new labelList(pMesh_.size());
63 labelList& insertedPoints = *insertedPointLabelsPtr_;
65 label nInsertedPoints = 0;
67 forAll (directAddr, pointI)
69 if (directAddr[pointI] < 0)
71 // Found inserted point
72 directAddr[pointI] = 0;
73 insertedPoints[nInsertedPoints] = pointI;
78 insertedPoints.setSize(nInsertedPoints);
82 // Interpolative addressing
84 interpolationAddrPtr_ = new labelListList(pMesh_.size());
85 labelListList& addr = *interpolationAddrPtr_;
87 weightsPtr_ = new scalarListList(pMesh_.size());
88 scalarListList& w = *weightsPtr_;
90 // Points created from other points (i.e. points merged into it).
91 const List<objectMap>& cfc = mpm_.pointsFromPointsMap();
96 const labelList& mo = cfc[cfcI].masterObjects();
98 label pointI = cfc[cfcI].index();
100 if (addr[pointI].size())
102 FatalErrorIn("void pointMapper::calcAddressing() const")
103 << "Master point " << pointI
104 << " mapped from points " << mo
105 << " already destination of mapping." << abort(FatalError);
108 // Map from masters, uniform weights
110 w[pointI] = scalarList(mo.size(), 1.0/mo.size());
114 // Do mapped points. Note that can already be set from pointsFromPoints
115 // so check if addressing size still zero.
117 const labelList& cm = mpm_.pointMap();
121 if (cm[pointI] > -1 && addr[pointI].empty())
123 // Mapped from a single point
124 addr[pointI] = labelList(1, cm[pointI]);
125 w[pointI] = scalarList(1, 1.0);
129 // Grab inserted points (for them the size of addressing is still zero)
131 insertedPointLabelsPtr_ = new labelList(pMesh_.size());
132 labelList& insertedPoints = *insertedPointLabelsPtr_;
134 label nInsertedPoints = 0;
136 forAll (addr, pointI)
138 if (addr[pointI].empty())
140 // Mapped from a dummy point. Take point 0 with weight 1.
141 addr[pointI] = labelList(1, 0);
142 w[pointI] = scalarList(1, 1.0);
144 insertedPoints[nInsertedPoints] = pointI;
149 insertedPoints.setSize(nInsertedPoints);
154 void Foam::pointMapper::clearOut()
156 deleteDemandDrivenData(directAddrPtr_);
157 deleteDemandDrivenData(interpolationAddrPtr_);
158 deleteDemandDrivenData(weightsPtr_);
159 deleteDemandDrivenData(insertedPointLabelsPtr_);
163 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
165 // Construct from components
166 Foam::pointMapper::pointMapper(const pointMesh& pMesh, const mapPolyMesh& mpm)
170 insertedPoints_(true),
172 directAddrPtr_(NULL),
173 interpolationAddrPtr_(NULL),
175 insertedPointLabelsPtr_(NULL)
177 // Check for possibility of direct mapping
178 if (mpm_.pointsFromPointsMap().empty())
187 // Check for inserted points
188 if (direct_ && (mpm_.pointMap().empty() || min(mpm_.pointMap()) > -1))
190 insertedPoints_ = false;
194 //Check if there are inserted points with no owner
196 // Make a copy of the point map, add the entries for points from points
197 // and check for left-overs
198 labelList cm(pMesh_.size(), -1);
200 const List<objectMap>& cfc = mpm_.pointsFromPointsMap();
204 cm[cfc[cfcI].index()] = 0;
209 insertedPoints_ = true;
215 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
217 Foam::pointMapper::~pointMapper()
223 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
225 Foam::label Foam::pointMapper::size() const
227 return mpm_.pointMap().size();
231 Foam::label Foam::pointMapper::sizeBeforeMapping() const
233 return mpm_.nOldPoints();
237 const Foam::unallocLabelList& Foam::pointMapper::directAddressing() const
243 "const unallocLabelList& pointMapper::directAddressing() const"
244 ) << "Requested direct addressing for an interpolative mapper."
245 << abort(FatalError);
248 if (!insertedObjects())
250 // No inserted points. Re-use pointMap
251 return mpm_.pointMap();
260 return *directAddrPtr_;
265 const Foam::labelListList& Foam::pointMapper::addressing() const
271 "const labelListList& pointMapper::addressing() const"
272 ) << "Requested interpolative addressing for a direct mapper."
273 << abort(FatalError);
276 if (!interpolationAddrPtr_)
281 return *interpolationAddrPtr_;
285 const Foam::scalarListList& Foam::pointMapper::weights() const
291 "const scalarListList& pointMapper::weights() const"
292 ) << "Requested interpolative weights for a direct mapper."
293 << abort(FatalError);
305 const Foam::labelList& Foam::pointMapper::insertedObjectLabels() const
307 if (!insertedPointLabelsPtr_)
309 if (!insertedObjects())
311 // There are no inserted points
312 insertedPointLabelsPtr_ = new labelList(0);
320 return *insertedPointLabelsPtr_;
324 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
327 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
330 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
333 // ************************************************************************* //