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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cellMapper.H"
27 #include "demandDrivenData.H"
29 #include "mapPolyMesh.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 void Foam::cellMapper::calcAddressing() const
41 || interpolationAddrPtr_
43 || insertedCellLabelsPtr_
46 FatalErrorIn("void cellMapper::calcAddressing() const")
47 << "Addressing already calculated."
53 // Direct addressing, no weights
55 directAddrPtr_ = new labelList(mpm_.cellMap());
56 labelList& directAddr = *directAddrPtr_;
58 // Not necessary to resize the list as there are no retired cells
59 // directAddr.setSize(mesh_.nCells());
61 insertedCellLabelsPtr_ = new labelList(mesh_.nCells());
62 labelList& insertedCells = *insertedCellLabelsPtr_;
64 label nInsertedCells = 0;
66 forAll (directAddr, cellI)
68 if (directAddr[cellI] < 0)
70 // Found inserted cell
71 directAddr[cellI] = 0;
72 insertedCells[nInsertedCells] = cellI;
77 insertedCells.setSize(nInsertedCells);
81 // Interpolative addressing
83 interpolationAddrPtr_ = new labelListList(mesh_.nCells());
84 labelListList& addr = *interpolationAddrPtr_;
86 weightsPtr_ = new scalarListList(mesh_.nCells());
87 scalarListList& w = *weightsPtr_;
89 const List<objectMap>& cfp = mpm_.cellsFromPointsMap();
94 const labelList& mo = cfp[cfpI].masterObjects();
96 label cellI = cfp[cfpI].index();
98 if (addr[cellI].size())
100 FatalErrorIn("void cellMapper::calcAddressing() const")
101 << "Master cell " << cellI
102 << " mapped from point cells " << mo
103 << " already destination of mapping." << abort(FatalError);
106 // Map from masters, uniform weights
108 w[cellI] = scalarList(mo.size(), 1.0/mo.size());
111 const List<objectMap>& cfe = mpm_.cellsFromEdgesMap();
116 const labelList& mo = cfe[cfeI].masterObjects();
118 label cellI = cfe[cfeI].index();
120 if (addr[cellI].size())
122 FatalErrorIn("void cellMapper::calcAddressing() const")
123 << "Master cell " << cellI
124 << " mapped from edge cells " << mo
125 << " already destination of mapping." << abort(FatalError);
128 // Map from masters, uniform weights
130 w[cellI] = scalarList(mo.size(), 1.0/mo.size());
133 const List<objectMap>& cff = mpm_.cellsFromFacesMap();
138 const labelList& mo = cff[cffI].masterObjects();
140 label cellI = cff[cffI].index();
142 if (addr[cellI].size())
144 FatalErrorIn("void cellMapper::calcAddressing() const")
145 << "Master cell " << cellI
146 << " mapped from face cells " << mo
147 << " already destination of mapping." << abort(FatalError);
150 // Map from masters, uniform weights
152 w[cellI] = scalarList(mo.size(), 1.0/mo.size());
155 const List<objectMap>& cfc = mpm_.cellsFromCellsMap();
160 const labelList& mo = cfc[cfcI].masterObjects();
162 label cellI = cfc[cfcI].index();
164 if (addr[cellI].size())
166 FatalErrorIn("void cellMapper::calcAddressing() const")
167 << "Master cell " << cellI
168 << " mapped from cell cells " << mo
169 << " already destination of mapping." << abort(FatalError);
172 // Map from masters, uniform weights
174 w[cellI] = scalarList(mo.size(), 1.0/mo.size());
178 // Do mapped faces. Note that can already be set from cellsFromCells
179 // so check if addressing size still zero.
181 const labelList& cm = mpm_.cellMap();
185 if (cm[cellI] > -1 && addr[cellI].empty())
187 // Mapped from a single cell
188 addr[cellI] = labelList(1, cm[cellI]);
189 w[cellI] = scalarList(1, 1.0);
193 // Grab inserted points (for them the size of addressing is still zero)
195 insertedCellLabelsPtr_ = new labelList(mesh_.nCells());
196 labelList& insertedCells = *insertedCellLabelsPtr_;
198 label nInsertedCells = 0;
202 if (addr[cellI].empty())
204 // Mapped from a dummy cell
205 addr[cellI] = labelList(1, 0);
206 w[cellI] = scalarList(1, 1.0);
208 insertedCells[nInsertedCells] = cellI;
213 insertedCells.setSize(nInsertedCells);
218 void Foam::cellMapper::clearOut()
220 deleteDemandDrivenData(directAddrPtr_);
221 deleteDemandDrivenData(interpolationAddrPtr_);
222 deleteDemandDrivenData(weightsPtr_);
223 deleteDemandDrivenData(insertedCellLabelsPtr_);
227 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
229 // Construct from components
230 Foam::cellMapper::cellMapper(const mapPolyMesh& mpm)
234 insertedCells_(true),
236 directAddrPtr_(NULL),
237 interpolationAddrPtr_(NULL),
239 insertedCellLabelsPtr_(NULL)
241 // Check for possibility of direct mapping
244 mpm_.cellsFromPointsMap().empty()
245 && mpm_.cellsFromEdgesMap().empty()
246 && mpm_.cellsFromFacesMap().empty()
247 && mpm_.cellsFromCellsMap().empty()
257 // Check for inserted cells
258 // HJ, different criterion in faces: this is due to the fact that
259 // I can retire faces but cannot retire cells
261 if (direct_ && (mpm_.cellMap().size() == 0 || min(mpm_.cellMap()) > -1))
263 insertedCells_ = false;
267 // Need to check all 3 lists to see if there are inserted cells
270 // Make a copy of the cell map, add the entried for cells from points,
271 // cells from edges and cells from faces and check for left-overs
272 labelList cm(mesh_.nCells(), -1);
274 const List<objectMap>& cfp = mpm_.cellsFromPointsMap();
278 cm[cfp[cfpI].index()] = 0;
281 const List<objectMap>& cfe = mpm_.cellsFromEdgesMap();
285 cm[cfe[cfeI].index()] = 0;
288 const List<objectMap>& cff = mpm_.cellsFromFacesMap();
292 cm[cff[cffI].index()] = 0;
295 const List<objectMap>& cfc = mpm_.cellsFromCellsMap();
299 cm[cfc[cfcI].index()] = 0;
304 insertedCells_ = true;
310 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
312 Foam::cellMapper::~cellMapper()
318 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
320 Foam::label Foam::cellMapper::size() const
322 return mpm_.cellMap().size();
326 Foam::label Foam::cellMapper::sizeBeforeMapping() const
328 return mpm_.nOldCells();
332 const Foam::unallocLabelList& Foam::cellMapper::directAddressing() const
338 "const unallocLabelList& cellMapper::directAddressing() const"
339 ) << "Requested direct addressing for an interpolative mapper."
340 << abort(FatalError);
343 if (!insertedObjects())
345 // No inserted cells. Re-use cellMap
346 return mpm_.cellMap();
355 return *directAddrPtr_;
360 const Foam::labelListList& Foam::cellMapper::addressing() const
366 "const labelListList& cellMapper::addressing() const"
367 ) << "Requested interpolative addressing for a direct mapper."
368 << abort(FatalError);
371 if (!interpolationAddrPtr_)
376 return *interpolationAddrPtr_;
380 const Foam::scalarListList& Foam::cellMapper::weights() const
386 "const scalarListList& cellMapper::weights() const"
387 ) << "Requested interpolative weights for a direct mapper."
388 << abort(FatalError);
400 const Foam::labelList& Foam::cellMapper::insertedObjectLabels() const
402 if (!insertedCellLabelsPtr_)
404 if (!insertedObjects())
406 // There are no inserted cells
407 insertedCellLabelsPtr_ = new labelList(0);
415 return *insertedCellLabelsPtr_;
419 // ************************************************************************* //