ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / meshes / pointMesh / pointMeshMapper / pointMapper.C
blobc6a26df15e8eda927a025e441f80d27ef5ca1de0
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
38     if
39     (
40         directAddrPtr_
41      || interpolationAddrPtr_
42      || weightsPtr_
43      || insertedPointLabelsPtr_
44     )
45     {
46         FatalErrorIn("void pointMapper::calcAddressing() const")
47             << "Addressing already calculated."
48             << abort(FatalError);
49     }
51     if (direct())
52     {
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)
67         {
68             if (directAddr[pointI] < 0)
69             {
70                 // Found inserted point
71                 directAddr[pointI] = 0;
72                 insertedPoints[nInsertedPoints] = pointI;
73                 nInsertedPoints++;
74             }
75         }
77         insertedPoints.setSize(nInsertedPoints);
78     }
79     else
80     {
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();
92         forAll(cfc, cfcI)
93         {
94             // Get addressing
95             const labelList& mo = cfc[cfcI].masterObjects();
97             label pointI = cfc[cfcI].index();
99             if (addr[pointI].size())
100             {
101                 FatalErrorIn("void pointMapper::calcAddressing() const")
102                     << "Master point " << pointI
103                     << " mapped from points " << mo
104                     << " already destination of mapping." << abort(FatalError);
105             }
107             // Map from masters, uniform weights
108             addr[pointI] = mo;
109             w[pointI] = scalarList(mo.size(), 1.0/mo.size());
110         }
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();
118         forAll(cm, pointI)
119         {
120             if (cm[pointI] > -1 && addr[pointI].empty())
121             {
122                 // Mapped from a single point
123                 addr[pointI] = labelList(1, cm[pointI]);
124                 w[pointI] = scalarList(1, 1.0);
125             }
126         }
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;
135         forAll(addr, pointI)
136         {
137             if (addr[pointI].empty())
138             {
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;
144                 nInsertedPoints++;
145             }
146         }
148         insertedPoints.setSize(nInsertedPoints);
149     }
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)
167     pMesh_(pMesh),
168     mpm_(mpm),
169     insertedPoints_(true),
170     direct_(false),
171     directAddrPtr_(NULL),
172     interpolationAddrPtr_(NULL),
173     weightsPtr_(NULL),
174     insertedPointLabelsPtr_(NULL)
176     // Check for possibility of direct mapping
177     if (mpm_.pointsFromPointsMap().empty())
178     {
179         direct_ = true;
180     }
181     else
182     {
183         direct_ = false;
184     }
186     // Check for inserted points
187     if (direct_ && (mpm_.pointMap().empty() || min(mpm_.pointMap()) > -1))
188     {
189         insertedPoints_ = false;
190     }
191     else
192     {
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();
201         forAll(cfc, cfcI)
202         {
203             cm[cfc[cfcI].index()] = 0;
204         }
206         if (min(cm) < 0)
207         {
208             insertedPoints_ = true;
209         }
210     }
214 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
216 Foam::pointMapper::~pointMapper()
218     clearOut();
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
238     if (!direct())
239     {
240         FatalErrorIn
241         (
242             "const labelUList& pointMapper::directAddressing() const"
243         )   << "Requested direct addressing for an interpolative mapper."
244             << abort(FatalError);
245     }
247     if (!insertedObjects())
248     {
249         // No inserted points.  Re-use pointMap
250         return mpm_.pointMap();
251     }
252     else
253     {
254         if (!directAddrPtr_)
255         {
256             calcAddressing();
257         }
259         return *directAddrPtr_;
260     }
264 const Foam::labelListList& Foam::pointMapper::addressing() const
266     if (direct())
267     {
268         FatalErrorIn
269         (
270             "const labelListList& pointMapper::addressing() const"
271         )   << "Requested interpolative addressing for a direct mapper."
272             << abort(FatalError);
273     }
275     if (!interpolationAddrPtr_)
276     {
277         calcAddressing();
278     }
280     return *interpolationAddrPtr_;
284 const Foam::scalarListList& Foam::pointMapper::weights() const
286     if (direct())
287     {
288         FatalErrorIn
289         (
290             "const scalarListList& pointMapper::weights() const"
291         )   << "Requested interpolative weights for a direct mapper."
292             << abort(FatalError);
293     }
295     if (!weightsPtr_)
296     {
297         calcAddressing();
298     }
300     return *weightsPtr_;
304 const Foam::labelList& Foam::pointMapper::insertedObjectLabels() const
306     if (!insertedPointLabelsPtr_)
307     {
308         if (!insertedObjects())
309         {
310             // There are no inserted points
311             insertedPointLabelsPtr_ = new labelList(0);
312         }
313         else
314         {
315             calcAddressing();
316         }
317     }
319     return *insertedPointLabelsPtr_;
323 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
326 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
329 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
332 // ************************************************************************* //