35void Foam::cellMapper::calcAddressing()
const
42 || insertedObjectsPtr_
46 <<
"Addressing already calculated."
54 directAddrPtr_ = std::make_unique<labelList>
59 auto& directAddr = *directAddrPtr_;
61 insertedObjectsPtr_ = std::make_unique<labelList>();
62 auto& inserted = *insertedObjectsPtr_;
65 if (nInsertedObjects_)
67 inserted.resize(nInsertedObjects_);
72 if (directAddr[i] < 0)
76 inserted[nInserted] = i;
81 if (nInsertedObjects_ < nInserted)
84 <<
"Unexpected insert of more than "
85 << nInsertedObjects_ <<
" items\n"
93 if (nInserted < nInsertedObjects_)
96 <<
"Found " << nInserted <<
" instead of "
97 << nInsertedObjects_ <<
" items to insert\n";
101 inserted.resize(nInserted);
108 interpAddrPtr_ = std::make_unique<labelListList>(mapperLen_);
109 auto& addr = *interpAddrPtr_;
111 weightsPtr_ = std::make_unique<scalarListList>(mapperLen_);
112 auto& wght = *weightsPtr_;
116 const auto setAddrWeights = [&]
118 const List<objectMap>& maps,
119 const char *
const nameOfMap
122 for (
const objectMap& map : maps)
125 const label celli = map.index();
126 const labelList& mo = map.masterObjects();
127 if (mo.empty())
continue;
129 if (addr[celli].
size())
132 <<
"Master cell " << celli
133 <<
" already mapped, cannot apply "
140 wght[celli] =
scalarList(mo.size(), 1.0/mo.size());
145 setAddrWeights(mpm_.cellsFromPointsMap(),
"point cells");
146 setAddrWeights(mpm_.cellsFromEdgesMap(),
"edge cells");
147 setAddrWeights(mpm_.cellsFromFacesMap(),
"face cells");
151 const List<objectMap>& cellsFromCells = mpm_.cellsFromCellsMap();
152 setAddrWeights(cellsFromCells,
"cell cells");
154 if (mpm_.hasOldCellVolumes())
163 <<
"cellVolumes size " <<
V.
size()
165 <<
". Are your cellVolumes already mapped?"
166 <<
" (new number of cells " <<
size() <<
")"
170 for (
const auto& map : cellsFromCells)
173 const label celli = map.index();
174 const labelList& mo = map.masterObjects();
175 if (mo.empty())
continue;
178 auto& wght_cell = wght[celli];
183 wght_cell[ci] =
V[mo[ci]];
188 for (
auto& w : wght_cell)
196 wght_cell = (1.0/mo.size());
209 for (label celli = 0; celli < mapperLen_; ++celli)
211 const label mappedi = map[celli];
213 if (mappedi >= 0 && addr[celli].empty())
216 addr[celli].resize(1, mappedi);
217 wght[celli].resize(1, 1.0);
225 insertedObjectsPtr_ = std::make_unique<labelList>();
226 auto& inserted = *insertedObjectsPtr_;
229 if (nInsertedObjects_)
231 inserted.resize(nInsertedObjects_);
239 addr[i].resize(1, 0);
240 wght[i].resize(1, 1.0);
242 inserted[nInserted] = i;
247 if (nInsertedObjects_ < nInserted)
250 <<
"Unexpected insert of more than "
251 << nInsertedObjects_ <<
" items\n"
259 if (nInserted < nInsertedObjects_)
262 <<
"Found " << nInserted <<
" instead of "
263 << nInsertedObjects_ <<
" items to insert\n";
267 inserted.resize(nInserted);
287 mapperLen_(mpm.
mesh().nCells()),
288 nInsertedObjects_(0),
292 mpm.cellsFromPointsMap().empty()
293 && mpm.cellsFromEdgesMap().empty()
294 && mpm.cellsFromFacesMap().empty()
295 && mpm.cellsFromCellsMap().empty()
298 const auto& directMap = mpm_.cellMap();
304 nInsertedObjects_ = 0;
309 nInsertedObjects_ = std::count_if
312 directMap.cbegin(mapperLen_),
313 [](label i) { return (i < 0); }
321 bitSet unmapped(mapperLen_,
true);
323 unmapped.
unset(directMap);
325 for (
const auto& map : mpm_.cellsFromPointsMap())
327 if (!map.empty()) unmapped.
unset(map.index());
330 for (
const auto& map : mpm_.cellsFromEdgesMap())
332 if (!map.empty()) unmapped.
unset(map.index());
335 for (
const auto& map : mpm_.cellsFromFacesMap())
337 if (!map.empty()) unmapped.
unset(map.index());
340 for (
const auto& map : mpm_.cellsFromCellsMap())
342 if (!map.empty()) unmapped.
unset(map.index());
345 nInsertedObjects_ = label(unmapped.
count());
361 return mpm_.cellMap().size();
367 return mpm_.nOldCells();
376 <<
"Requested direct addressing for an interpolative mapper."
380 if (!insertedObjects())
383 return mpm_.cellMap();
392 return *directAddrPtr_;
402 <<
"Requested interpolative addressing for a direct mapper."
411 return *interpAddrPtr_;
420 <<
"Requested interpolative weights for a direct mapper."
435 if (!insertedObjectsPtr_)
437 if (!nInsertedObjects_)
446 return *insertedObjectsPtr_;
auto size() const noexcept
static const List< label > & null() noexcept
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
unsigned int count(const bool on=true) const
Count number of bits set.
bitSet & unset(const bitSet &other)
Unset (subtract) the bits specified in the other bitset, which is a set difference corresponds to the...
cellMapper(const cellMapper &)=delete
No copy construct.
virtual ~cellMapper()
Destructor.
virtual const labelListList & addressing() const
Return interpolated addressing.
virtual const scalarListList & weights() const
Return interpolaion weights.
virtual const labelUList & directAddressing() const
Return direct addressing.
virtual label size() const
The mapper size.
virtual const labelList & insertedObjectLabels() const
Return list of inserted cells.
virtual label sizeBeforeMapping() const
Return size before mapping.
virtual bool insertedObjects() const
Are there any inserted cells.
virtual bool direct() const
Is the mapping direct.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
const expr V(m.psi().mesh().V())
List< scalarList > scalarListList
List of scalarList.
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
errorManip< error > abort(error &err)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
UList< label > labelUList
A UList of labels.
List< scalar > scalarList
List of scalar.
#define forAll(list, i)
Loop across all elements in list.