42 void Foam::refinementHistory::writeEntry
44 const List<splitCell8>& splitCells,
45 const splitCell8& split
49 if (split.addedCellsPtr_.valid())
51 Pout<<
"parent:" << split.parent_
52 <<
" subCells:" << split.addedCellsPtr_()
57 Pout<<
"parent:" << split.parent_
62 if (split.parent_ >= 0)
77 const List<splitCell8>& splitCells
83 forAll(visibleCells, celli)
85 label index = visibleCells[celli];
89 Pout<<
"Cell from refinement:" << celli <<
" index:" << index
99 Pout<<
"Unrefined cell:" << celli <<
" index:" << index <<
endl;
111 addedCellsPtr_(nullptr)
118 addedCellsPtr_(nullptr)
133 sc.addedCellsPtr_.
valid()
149 FatalErrorIn(
"splitCell8::operator=(const Foam::splitCell8&)")
150 <<
"Attempted assignment to self"
158 s.addedCellsPtr_.valid()
167 if (addedCellsPtr_.valid() !=
s.addedCellsPtr_.valid())
171 else if (parent_ !=
s.parent_)
175 else if (addedCellsPtr_.valid())
177 return addedCellsPtr_() ==
s.addedCellsPtr_();
198 is >> sc.
parent_ >> addedCells;
200 if (addedCells.
size())
223 if (sc.addedCellsPtr_.valid())
239 void Foam::refinementHistory::checkIndices()
const
244 if (visibleCells_[i] < 0 && visibleCells_[i] >= splitCells_.size())
247 <<
"Illegal entry " << visibleCells_[i]
248 <<
" in visibleCells at location" << i <<
nl
249 <<
"It points outside the range of splitCells : 0.."
250 << splitCells_.size()-1
257 Foam::label Foam::refinementHistory::allocateSplitCell
265 if (freeSplitCells_.
size())
267 index = freeSplitCells_.
remove();
269 splitCells_[index] = splitCell8(parent);
273 index = splitCells_.size();
275 splitCells_.append(splitCell8(parent));
282 splitCell8& parentSplit = splitCells_[parent];
284 if (parentSplit.addedCellsPtr_.empty())
287 parentSplit.addedCellsPtr_.reset(
new FixedList<label, 8>(-1));
292 FixedList<label, 8>& parentSplits = parentSplit.addedCellsPtr_();
294 parentSplits[i] = index;
301 void Foam::refinementHistory::freeSplitCell(
const label index)
303 splitCell8& split = splitCells_[index];
306 if (split.parent_ >= 0)
308 autoPtr<FixedList<label, 8>>& subCellsPtr =
309 splitCells_[split.parent_].addedCellsPtr_;
311 if (subCellsPtr.valid())
313 FixedList<label, 8>& subCells = subCellsPtr();
320 <<
"Problem: cannot find myself in"
325 subCells[myPos] = -1;
334 freeSplitCells_.
append(index);
338 void Foam::refinementHistory::markSplit
342 DynamicList<splitCell8>& newSplitCells
345 if (oldToNew[index] == -1)
349 const splitCell8& split = splitCells_[index];
351 oldToNew[index] = newSplitCells.size();
352 newSplitCells.append(split);
354 if (split.parent_ >= 0)
356 markSplit(split.parent_, oldToNew, newSplitCells);
358 if (split.addedCellsPtr_.valid())
360 const FixedList<label, 8>& splits = split.addedCellsPtr_();
366 markSplit(splits[i], oldToNew, newSplitCells);
374 void Foam::refinementHistory::mark
381 splitToVal[index] = val;
383 const splitCell8& split = splitCells_[index];
385 if (split.addedCellsPtr_.valid())
387 const FixedList<label, 8>& splits = split.addedCellsPtr_();
393 mark(val, splits[i], splitToVal);
400 Foam::label Foam::refinementHistory::markCommonCells
407 labelList splitToCluster(splitCells_.size(), -1);
410 forAll(visibleCells_, cellI)
412 label index = visibleCells_[cellI];
417 while (splitCells_[index].parent_ != -1)
419 index = splitCells_[index].parent_;
423 if (splitToCluster[index] == -1)
425 mark(clusterI, index, splitToCluster);
432 cellToCluster.setSize(visibleCells_.
size(), -1);
434 forAll(visibleCells_, cellI)
436 label index = visibleCells_[cellI];
440 cellToCluster[cellI] = splitToCluster[index];
462 markCommonCells(cellToCluster);
467 label nUnblocked = 0;
474 if (ownCluster != -1 && ownCluster == neiCluster)
476 if (blockedFace[faceI])
478 blockedFace[faceI] =
false;
484 if (refinementHistory::debug)
487 Info<<
type() <<
" : unblocked " << nUnblocked <<
" faces" <<
endl;
507 label nClusters = markCommonCells(cellToCluster);
521 label ownCluster = cellToCluster[own];
522 label neiCluster = cellToCluster[nei];
524 if (ownCluster != -1 && ownCluster == neiCluster)
526 if (clusterToProc[ownCluster] == -1)
528 clusterToProc[ownCluster] = decomposition[own];
531 if (decomposition[own] != clusterToProc[ownCluster])
533 decomposition[own] = clusterToProc[ownCluster];
536 if (decomposition[nei] != clusterToProc[ownCluster])
538 decomposition[nei] = clusterToProc[ownCluster];
544 if (refinementHistory::debug)
547 Info<<
type() <<
" : changed decomposition on " << nChanged
564 <<
"Specified IOobject::MUST_READ_IF_MODIFIED but class"
565 <<
" does not support automatic rereading."
587 Pout<<
"refinementHistory::refinementHistory :"
588 <<
" constructed history from IOobject :"
589 <<
" splitCells:" << splitCells_.size()
590 <<
" visibleCells:" << visibleCells_.
size()
591 <<
" active:" << active_
607 splitCells_(splitCells),
609 visibleCells_(visibleCells)
615 <<
"Specified IOobject::MUST_READ_IF_MODIFIED but class"
616 <<
" does not support automatic rereading."
636 Pout<<
"refinementHistory::refinementHistory :"
637 <<
" constructed history from IOobject or components :"
638 <<
" splitCells:" << splitCells_.size()
639 <<
" visibleCells:" << visibleCells_.
size()
640 <<
" active:" << active_
660 <<
"Specified IOobject::MUST_READ_IF_MODIFIED but class"
661 <<
" does not support automatic rereading."
678 splitCells_.setCapacity(nCells);
680 for (
label cellI = 0; cellI < nCells; cellI++)
682 visibleCells_[cellI] = cellI;
695 Pout<<
"refinementHistory::refinementHistory :"
696 <<
" constructed history from IOobject or initial size :"
697 <<
" splitCells:" << splitCells_.size()
698 <<
" visibleCells:" << visibleCells_.
size()
699 <<
" active:" << active_
721 <<
"Specified IOobject::MUST_READ_IF_MODIFIED but class"
722 <<
" does not support automatic rereading."
739 splitCells_.setCapacity(nCells);
741 for (
label celli = 0; celli < nCells; celli++)
743 visibleCells_[celli] = celli;
753 Pout<<
"refinementHistory::refinementHistory :"
754 <<
" constructed history from IOobject or initial size :"
755 <<
" splitCells:" << splitCells_.size()
756 <<
" visibleCells:" << visibleCells_.
size()
757 <<
" active:" << active_
771 splitCells_(rh.splitCells()),
772 freeSplitCells_(rh.freeSplitCells()),
773 visibleCells_(rh.visibleCells())
777 Pout<<
"refinementHistory::refinementHistory : constructed initial"
778 <<
" history." <<
endl;
802 "refinementHistory::refinementHistory(const IOobject&"
803 ", const labelListList&, const PtrList<refinementHistory>&)"
804 ) <<
"read option IOobject::MUST_READ, READ_IF_PRESENT or "
805 <<
"MUST_READ_IF_MODIFIED"
806 <<
" suggests that a read constructor would be more appropriate."
819 offsets[refI+1] = offsets[refI]+subSplits.
size();
823 splitCells_.setSize(offsets.
last());
829 splitCell8& newSplit = splitCells_[offsets[refI]+i];
832 newSplit = subSplits[i];
837 newSplit.
parent_ += offsets[refI];
848 splits[i] += offsets[refI];
860 const labelList& cellMap = cellMaps[refI];
861 const labelList& subVis = refs[refI].visibleCells();
865 label& newVis = visibleCells_[cellMap[i]];
870 newVis += offsets[refI];
893 Pout<<
"refinementHistory::refinementHistory :"
894 <<
" constructed history from multiple refinementHistories :"
895 <<
" splitCells:" << splitCells_.size()
896 <<
" visibleCells:" << visibleCells_.
size()
916 Pout<<
"refinementHistory::refinementHistory :"
917 <<
" constructed history from Istream"
918 <<
" splitCells:" << splitCells_.size()
919 <<
" visibleCells:" << visibleCells_.
size()
943 oldToNewSplit.
setSize(splitCells_.size());
952 forAll(splitCells_, index)
954 if (splitCellProc[index] == procI && splitCellNum[index] == 8)
957 oldToNewSplit[index] = newSplitCells.
size();
958 newSplitCells.
append(splitCells_[index]);
963 forAll(visibleCells_, cellI)
965 label index = visibleCells_[cellI];
967 if (index >= 0 && decomposition[cellI] == procI)
969 label parent = splitCells_[index].parent_;
972 oldToNewSplit[index] = newSplitCells.
size();
986 forAll(newSplitCells, index)
1002 splits[i] = oldToNewSplit[splits[i]];
1011 forAll(decomposition, cellI)
1013 if (decomposition[cellI] == procI)
1022 forAll(visibleCells_, cellI)
1024 if (decomposition[cellI] == procI)
1026 label index = visibleCells_[cellI];
1029 index = oldToNewSplit[index];
1031 newVisibleCells[nSub++] = index;
1057 labelList decomposition(visibleCells_.size(), 0);
1060 decomposition[cellMap[i]] = 1;
1065 labelList splitCellProc(splitCells_.size(), -1);
1068 labelList splitCellNum(splitCells_.size(), 0);
1070 forAll(visibleCells_, cellI)
1072 label index = visibleCells_[cellI];
1078 splitCells_[index].parent_,
1079 decomposition[cellI],
1115 label oldSize = visibleCells_.size();
1119 Pout<<
"refinementHistory::resize from " << oldSize <<
" to " << size
1120 <<
" cells" <<
endl;
1123 visibleCells_.setSize(size);
1126 for (
label i = oldSize; i < visibleCells_.size(); i++)
1128 visibleCells_[i] = -1;
1143 forAll(visibleCells_, celli)
1145 if (visibleCells_[celli] != -1)
1147 label index = visibleCells_[celli];
1150 if (splitCells_[index].addedCellsPtr_.valid())
1156 label newCelli = reverseCellMap[celli];
1160 newVisibleCells[newCelli] = index;
1167 Pout<<
"refinementHistory::topoChange : from "
1168 << visibleCells_.size()
1169 <<
" to " << newVisibleCells.
size()
1170 <<
" cells" <<
endl;
1173 visibleCells_.transfer(newVisibleCells);
1189 forAll(newVisibleCells, celli)
1191 label oldCelli = cellMap[celli];
1193 label index = visibleCells_[oldCelli];
1196 if (index >= 0 && splitCells_[index].addedCellsPtr_.valid())
1202 newVisibleCells[celli] = index;
1207 Pout<<
"refinementHistory::topoChange : from "
1208 << visibleCells_.size()
1209 <<
" to " << newVisibleCells.
size()
1210 <<
" cells" <<
endl;
1213 visibleCells_.transfer(newVisibleCells);
1218 void Foam::refinementHistory::countProc
1221 const label newProcNo,
1226 if (splitCellProc[index] != newProcNo)
1230 splitCellProc[index] = newProcNo;
1231 splitCellNum[index] = 1;
1235 splitCellNum[index]++;
1238 if (splitCellNum[index] == 8)
1242 Pout<<
"Moving " << splitCellNum[index]
1243 <<
" cells originating from cell " << index
1245 <<
" to processor " << splitCellProc[index]
1249 label parent = splitCells_[index].parent_;
1253 countProc(parent, newProcNo, splitCellProc, splitCellNum);
1293 labelList destination(visibleCells_.size());
1297 forAll(subCellMap, proci)
1299 const labelList& newToOld = subCellMap[proci];
1303 label oldCelli = newToOld[i];
1305 destination[oldCelli] = proci;
1310 labelList splitCellProc(splitCells_.size(), -1);
1312 labelList splitCellNum(splitCells_.size(), 0);
1314 forAll(visibleCells_, celli)
1316 label index = visibleCells_[celli];
1322 splitCells_[index].parent_,
1344 labelList oldToNew(splitCells_.size(), -1);
1352 forAll(splitCells_, index)
1354 if (splitCellProc[index] == proci && splitCellNum[index] == 8)
1357 oldToNew[index] = newSplitCells.
size();
1358 newSplitCells.
append(splitCells_[index]);
1363 forAll(visibleCells_, celli)
1365 label index = visibleCells_[celli];
1367 if (index >= 0 && destination[celli] == proci)
1369 label parent = splitCells_[index].parent_;
1372 oldToNew[index] = newSplitCells.
size();
1386 forAll(newSplitCells, index)
1402 splits[i] = oldToNew[splits[i]];
1409 const labelList& subMap = subCellMap[proci];
1416 label oldCelli = subMap[newCelli];
1418 label oldIndex = visibleCells_[oldCelli];
1422 newVisibleCells[newCelli] = oldToNew[oldIndex];
1433 toNbr << newSplitCells << newVisibleCells;
1441 splitCells_.
clear();
1445 visibleCells_.setSize(mesh.
nCells());
1466 forAll(newSplitCells, index)
1487 splitCells_.append(split);
1494 forAll(newVisibleCells, i)
1496 if (newVisibleCells[i] >= 0)
1498 visibleCells_[constructMap[i]] = newVisibleCells[i] +
offset;
1502 splitCells_.shrink();
1514 Pout<<
"refinementHistory::compact() Entering with:"
1515 <<
" freeSplitCells_:" << freeSplitCells_.size()
1516 <<
" splitCells_:" << splitCells_.size()
1517 <<
" visibleCells_:" << visibleCells_.size()
1521 forAll(freeSplitCells_, i)
1523 label index = freeSplitCells_[i];
1525 if (splitCells_[index].parent_ != -2)
1528 <<
"Problem index:" << index
1534 forAll(visibleCells_, celli)
1538 visibleCells_[celli] >= 0
1539 && splitCells_[visibleCells_[celli]].parent_ == -2
1543 <<
"Problem : visible cell:" << celli
1552 labelList oldToNew(splitCells_.size(), -1);
1558 forAll(visibleCells_, celli)
1560 label index = visibleCells_[celli];
1568 splitCells_[index].parent_ != -1
1569 || splitCells_[index].addedCellsPtr_.valid()
1572 markSplit(index, oldToNew, newSplitCells);
1578 forAll(splitCells_, index)
1580 if (splitCells_[index].parent_ == -2)
1586 splitCells_[index].parent_ == -1
1587 && splitCells_[index].addedCellsPtr_.empty()
1596 markSplit(index, oldToNew, newSplitCells);
1604 forAll(newSplitCells, index)
1620 splits[i] = oldToNew[splits[i]];
1629 Pout<<
"refinementHistory::compact : compacted splitCells from "
1630 << splitCells_.size() <<
" to " << newSplitCells.
size() <<
endl;
1633 splitCells_.transfer(newSplitCells);
1634 freeSplitCells_.clearStorage();
1639 Pout<<
"refinementHistory::compact() NOW:"
1640 <<
" freeSplitCells_:" << freeSplitCells_.size()
1641 <<
" splitCells_:" << splitCells_.size()
1642 <<
" newSplitCells:" << newSplitCells.
size()
1643 <<
" visibleCells_:" << visibleCells_.size()
1649 forAll(visibleCells_, celli)
1651 label index = visibleCells_[celli];
1656 visibleCells_[celli] = oldToNew[index];
1668 writeDebug(visibleCells_, splitCells_);
1678 label parentIndex = -1;
1680 if (visibleCells_[celli] != -1)
1685 parentIndex = visibleCells_[celli];
1689 visibleCells_[celli] = -1;
1694 parentIndex = allocateSplitCell(-1, -1);
1701 label addedCelli = addedCells[i];
1705 visibleCells_[addedCelli] = allocateSplitCell(parentIndex, i);
1712 const label masterCelli,
1717 label parentIndex = splitCells_[visibleCells_[masterCelli]].parent_;
1722 label celli = combinedCells[i];
1724 freeSplitCell(visibleCells_[celli]);
1725 visibleCells_[celli] = -1;
1728 splitCell8& parentSplit = splitCells_[parentIndex];
1730 visibleCells_[masterCelli] = parentIndex;
1736 bool ok = readData(readStream(typeName));
1766 is >> rh.splitCells_ >> rh.visibleCells_;
1779 return os <<
"// splitCells" <<
nl
1780 << rh.splitCells_ <<
nl
1781 <<
"// visibleCells" <<
nl
1782 << rh.visibleCells_;
#define forAll(list, i)
Loop across all elements in list.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
T remove()
Remove and return the top element.
void clearStorage()
Clear the list and delete storage.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
A 1D vector of objects of type <T> with a fixed size <Size>.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
const objectRegistry & db() const
Return the local objectRegistry.
readOption readOpt() const
autoPtr< IOobject > clone() const
Clone.
bool bad() const
Return true if stream is corrupted.
bool good() const
Return true if next operation might succeed.
Input inter-processor communications stream.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void size(const label)
Override size to be inconsistent with allocated storage.
void clear()
Clear the list, i.e. set size to zero.
void setSize(const label)
Reset size of List.
Output inter-processor communications stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
T & last()
Return the last element of the list.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static bool & parRun()
Is this a parallel run?
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
label size() const
Return the number of elements in the UPtrList.
const labelListList & constructMap() const
From subsetted data to new reconstructed data.
const labelListList & subMap() const
From subsetted data back to original data.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
const distributionMap & cellMap() const
Cell distribute map.
Mesh consisting of general polyhedral cells.
virtual const labelList & faceOwner() const
Return face owner.
virtual const labelList & faceNeighbour() const
Return face neighbour.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & cellMap() const
Old cell map.
const labelList & reverseCellMap() const
Reverse cell map.
const string & prefix() const
Return the prefix of the stream.
splitCell8()
Construct null (parent = -1)
bool operator==(const splitCell8 &s) const
void operator=(const splitCell8 &s)
Copy operator since autoPtr otherwise 'steals' storage.
autoPtr< FixedList< label, 8 > > addedCellsPtr_
Cells this cell was refined into.
bool operator!=(const splitCell8 &s) const
All refinement history. Used in unrefinement.
void compact()
Compact splitCells_. Removes all freeSplitCells_ elements.
const DynamicList< splitCell8 > & splitCells() const
Storage for splitCell8s.
void writeDebug() const
Debug write.
virtual bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
void storeSplit(const label celli, const labelList &addedCells)
Store splitting of cell into 8.
void apply(const boolList &blockedFace, const PtrList< labelList > &specifiedProcessorFaces, const labelList &specifiedProcessor, const List< labelPair > &explicitConnections, labelList &decomposition) const
Apply any additional post-decomposition constraints.
void topoChange(const polyTopoChangeMap &)
Update numbering for mesh changes.
void add(boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my decomposition constraints.
void distribute(const polyDistributionMap &)
Update local numbering for mesh redistribution.
void resize(const label nCells)
Extend/shrink storage. additional visibleCells_ elements get.
refinementHistory(const IOobject &)
Construct (read) given an IOobject. If global number of visible.
virtual bool readData(Istream &)
ReadData function required for regIOobject read operation. Note:
bool active() const
Is there unrefinement history?
void subset(const labelList &pointMap, const labelList &faceMap, const labelList &cellMap)
Update numbering for subsetting.
virtual bool read()
Read object. If global number of visible cells > 0 becomes active.
void combineCells(const label masterCelli, const labelList &combinedCells)
Store combining 8 cells into master.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
void close()
Close Istream.
bool headerOk()
Read and check header info.
Istream & readStream(const word &, const bool read=true)
Return Istream and check object type against that given.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define WarningInFunction
Report a warning using Foam::Warning.
#define WarningIn(functionName)
Report a warning using Foam::Warning.
bool valid(const PtrList< ModelType > &l)
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Istream & operator>>(Istream &, pistonPointEdgeData &)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
defineTypeNameAndDebug(combustionModel, 0)
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
prefixOSstream Pout(cout, "Pout")
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
void offset(label &lst, const label o)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.