46bool Foam::refinementHistory::readContents()
55 readStream(typeName) >> *
this;
64void Foam::refinementHistory::writeEntry
66 const List<splitCell8>& splitCells,
67 const splitCell8&
split
71 if (
split.addedCellsPtr_)
74 <<
" subCells:" <<
split.addedCellsPtr_()
84 if (
split.parent_ >= 0)
90 writeEntry(splitCells, splitCells[
split.parent_]);
99 const List<splitCell8>& splitCells
105 forAll(visibleCells, celli)
107 label index = visibleCells[celli];
111 Pout<<
"Cell from refinement:" << celli <<
" index:" << index
116 writeEntry(splitCells, splitCells[index]);
121 Pout<<
"Unrefined cell:" << celli <<
" index:" << index <<
endl;
133 addedCellsPtr_(nullptr)
140 addedCellsPtr_(nullptr)
154 parent_(rhs.parent_),
155 addedCellsPtr_(rhs.addedCellsPtr_.
clone())
181 if (parent_ != rhs.parent_)
185 if (
bool(addedCellsPtr_) !=
bool(rhs.addedCellsPtr_))
189 else if (addedCellsPtr_)
191 return addedCellsPtr_() == rhs.addedCellsPtr_();
213 is >> sc.
parent_ >> addedCells;
215 if (addedCells.
size())
240 if (sc.addedCellsPtr_)
242 labels = sc.addedCellsPtr_();
251void Foam::refinementHistory::checkIndices()
const
256 if (visibleCells_[i] < 0 && visibleCells_[i] >= splitCells_.size())
259 <<
"Illegal entry " << visibleCells_[i]
260 <<
" in visibleCells at location" << i <<
nl
261 <<
"It points outside the range of splitCells : 0.."
262 << splitCells_.size()-1
269Foam::label Foam::refinementHistory::allocateSplitCell
277 if (freeSplitCells_.
size())
279 index = freeSplitCells_.
remove();
281 splitCells_[index] = splitCell8(parent);
285 index = splitCells_.size();
287 splitCells_.append(splitCell8(parent));
294 splitCell8& parentSplit = splitCells_[parent];
296 if (!parentSplit.addedCellsPtr_)
299 parentSplit.addedCellsPtr_.reset(
new FixedList<label, 8>(-1));
304 FixedList<label, 8>& parentSplits = parentSplit.addedCellsPtr_();
306 parentSplits[i] = index;
313void Foam::refinementHistory::freeSplitCell(
const label index)
315 splitCell8&
split = splitCells_[index];
318 if (
split.parent_ >= 0)
320 autoPtr<FixedList<label, 8>>& subCellsPtr =
321 splitCells_[
split.parent_].addedCellsPtr_;
325 FixedList<label, 8>& subCells = subCellsPtr();
327 label myPos = subCells.find(index);
332 <<
"Problem: cannot find myself in"
337 subCells[myPos] = -1;
346 freeSplitCells_.
append(index);
350void Foam::refinementHistory::markSplit
354 DynamicList<splitCell8>& newSplitCells
357 if (oldToNew[index] == -1)
361 const splitCell8&
split = splitCells_[index];
363 oldToNew[index] = newSplitCells.size();
364 newSplitCells.append(
split);
366 if (
split.parent_ >= 0)
368 markSplit(
split.parent_, oldToNew, newSplitCells);
370 if (
split.addedCellsPtr_)
372 const FixedList<label, 8>& splits =
split.addedCellsPtr_();
378 markSplit(splits[i], oldToNew, newSplitCells);
386void Foam::refinementHistory::mark
393 splitToVal[index] = val;
395 const splitCell8&
split = splitCells_[index];
397 if (
split.addedCellsPtr_)
399 const FixedList<label, 8>& splits =
split.addedCellsPtr_();
405 mark(val, splits[i], splitToVal);
412Foam::label Foam::refinementHistory::markCommonCells
419 labelList splitToCluster(splitCells_.size(), -1);
422 forAll(visibleCells_, cellI)
424 label index = visibleCells_[cellI];
429 while (splitCells_[index].parent_ != -1)
431 index = splitCells_[index].parent_;
435 if (splitToCluster[index] == -1)
437 mark(clusterI, index, splitToCluster);
444 cellToCluster.setSize(visibleCells_.
size(), -1);
446 forAll(visibleCells_, cellI)
448 label index = visibleCells_[cellI];
452 cellToCluster[cellI] = splitToCluster[index];
474 markCommonCells(cellToCluster);
479 label nUnblocked = 0;
486 if (ownCluster != -1 && ownCluster == neiCluster)
488 if (blockedFace[faceI])
490 blockedFace[faceI] =
false;
496 if (refinementHistory::debug)
499 Info<<
type() <<
" : unblocked " << nUnblocked <<
" faces" <<
endl;
519 label nClusters = markCommonCells(cellToCluster);
533 label ownCluster = cellToCluster[own];
534 label neiCluster = cellToCluster[nei];
536 if (ownCluster != -1 && ownCluster == neiCluster)
538 if (clusterToProc[ownCluster] == -1)
540 clusterToProc[ownCluster] = decomposition[own];
543 if (decomposition[own] != clusterToProc[ownCluster])
545 decomposition[own] = clusterToProc[ownCluster];
548 if (decomposition[nei] != clusterToProc[ownCluster])
550 decomposition[nei] = clusterToProc[ownCluster];
556 if (refinementHistory::debug)
559 Info<<
type() <<
" : changed decomposition on " << nChanged
573 warnNoRereading<refinementHistory>();
584 Pout<<
"refinementHistory::refinementHistory :"
585 <<
" constructed history from IOobject :"
586 <<
" splitCells:" << splitCells_.size()
587 <<
" visibleCells:" << visibleCells_.
size()
588 <<
" active:" << active_
604 splitCells_(splitCells),
606 visibleCells_(visibleCells)
609 warnNoRereading<refinementHistory>();
618 Pout<<
"refinementHistory::refinementHistory :"
619 <<
" constructed history from IOobject or components :"
620 <<
" splitCells:" << splitCells_.size()
621 <<
" visibleCells:" << visibleCells_.
size()
622 <<
" active:" << active_
639 warnNoRereading<refinementHistory>();
644 splitCells_.setCapacity(nCells);
646 for (label cellI = 0; cellI < nCells; cellI++)
648 visibleCells_[cellI] = cellI;
661 Pout<<
"refinementHistory::refinementHistory :"
662 <<
" constructed history from IOobject or initial size :"
663 <<
" splitCells:" << splitCells_.size()
664 <<
" visibleCells:" << visibleCells_.
size()
665 <<
" active:" << active_
684 warnNoRereading<refinementHistory>();
689 splitCells_.setCapacity(nCells);
691 for (label celli = 0; celli < nCells; celli++)
693 visibleCells_[celli] = celli;
703 Pout<<
"refinementHistory::refinementHistory :"
704 <<
" constructed history from IOobject or initial size :"
705 <<
" splitCells:" << splitCells_.size()
706 <<
" visibleCells:" << visibleCells_.
size()
707 <<
" active:" << active_
721 splitCells_(rh.splitCells()),
722 freeSplitCells_(rh.freeSplitCells()),
723 visibleCells_(rh.visibleCells())
727 Pout<<
"refinementHistory::refinementHistory : constructed initial"
728 <<
" history." <<
endl;
751 <<
"read option IOobject::MUST_READ, READ_IF_PRESENT or "
752 <<
"MUST_READ_IF_MODIFIED"
753 <<
" suggests that a read constructor would be more appropriate."
766 offsets[refI+1] = offsets[refI]+subSplits.
size();
770 splitCells_.setSize(offsets.
last());
776 splitCell8& newSplit = splitCells_[offsets[refI]+i];
779 newSplit = subSplits[i];
784 newSplit.
parent_ += offsets[refI];
795 splits[i] += offsets[refI];
807 const labelList& cellMap = cellMaps[refI];
808 const labelList& subVis = refs[refI].visibleCells();
812 label& newVis = visibleCells_[cellMap[i]];
817 newVis += offsets[refI];
840 Pout<<
"refinementHistory::refinementHistory :"
841 <<
" constructed history from multiple refinementHistories :"
842 <<
" splitCells:" << splitCells_.size()
843 <<
" visibleCells:" << visibleCells_.
size()
863 Pout<<
"refinementHistory::refinementHistory :"
864 <<
" constructed history from Istream"
865 <<
" splitCells:" << splitCells_.size()
866 <<
" visibleCells:" << visibleCells_.
size()
890 oldToNewSplit.
setSize(splitCells_.size());
899 forAll(splitCells_, index)
901 if (splitCellProc[index] == procI && splitCellNum[index] == 8)
904 oldToNewSplit[index] = newSplitCells.
size();
905 newSplitCells.
append(splitCells_[index]);
910 forAll(visibleCells_, cellI)
912 label index = visibleCells_[cellI];
914 if (index >= 0 && decomposition[cellI] == procI)
916 label parent = splitCells_[index].parent_;
919 oldToNewSplit[index] = newSplitCells.
size();
933 forAll(newSplitCells, index)
937 if (
split.parent_ >= 0)
941 if (
split.addedCellsPtr_)
949 splits[i] = oldToNewSplit[splits[i]];
958 forAll(decomposition, cellI)
960 if (decomposition[cellI] == procI)
969 forAll(visibleCells_, cellI)
971 if (decomposition[cellI] == procI)
973 label index = visibleCells_[cellI];
976 index = oldToNewSplit[index];
978 newVisibleCells[nSub++] = index;
1007 decomposition[cellMap[i]] = 1;
1012 labelList splitCellProc(splitCells_.size(), -1);
1017 forAll(visibleCells_, cellI)
1019 label index = visibleCells_[cellI];
1025 splitCells_[index].parent_,
1026 decomposition[cellI],
1062 label oldSize = visibleCells_.size();
1066 Pout<<
"refinementHistory::resize from " << oldSize <<
" to " << size
1067 <<
" cells" <<
endl;
1070 visibleCells_.setSize(size);
1073 for (label i = oldSize; i < visibleCells_.size(); i++)
1075 visibleCells_[i] = -1;
1090 forAll(visibleCells_, celli)
1092 if (visibleCells_[celli] != -1)
1094 label index = visibleCells_[celli];
1097 if (splitCells_[index].addedCellsPtr_)
1103 label newCelli = reverseCellMap[celli];
1107 newVisibleCells[newCelli] = index;
1114 Pout<<
"refinementHistory::updateMesh : from "
1115 << visibleCells_.size()
1116 <<
" to " << newVisibleCells.
size()
1117 <<
" cells" <<
endl;
1120 visibleCells_.transfer(newVisibleCells);
1136 forAll(newVisibleCells, celli)
1138 label oldCelli = cellMap[celli];
1140 label index = visibleCells_[oldCelli];
1143 if (index >= 0 && splitCells_[index].addedCellsPtr_)
1149 newVisibleCells[celli] = index;
1154 Pout<<
"refinementHistory::updateMesh : from "
1155 << visibleCells_.size()
1156 <<
" to " << newVisibleCells.
size()
1157 <<
" cells" <<
endl;
1160 visibleCells_.transfer(newVisibleCells);
1165void Foam::refinementHistory::countProc
1168 const label newProcNo,
1173 if (splitCellProc[index] != newProcNo)
1177 splitCellProc[index] = newProcNo;
1178 splitCellNum[index] = 1;
1182 splitCellNum[index]++;
1185 if (splitCellNum[index] == 8)
1189 Pout<<
"Moving " << splitCellNum[index]
1190 <<
" cells originating from cell " << index
1192 <<
" to processor " << splitCellProc[index]
1196 label parent = splitCells_[index].parent_;
1200 countProc(parent, newProcNo, splitCellProc, splitCellNum);
1240 labelList destination(visibleCells_.size());
1244 forAll(subCellMap, proci)
1246 const labelList& newToOld = subCellMap[proci];
1250 label oldCelli = newToOld[i];
1252 destination[oldCelli] = proci;
1257 labelList splitCellProc(splitCells_.size(), -1);
1261 forAll(visibleCells_, celli)
1263 label index = visibleCells_[celli];
1269 splitCells_[index].parent_,
1291 labelList oldToNew(splitCells_.size(), -1);
1299 forAll(splitCells_, index)
1301 if (splitCellProc[index] == proci && splitCellNum[index] == 8)
1304 oldToNew[index] = newSplitCells.
size();
1305 newSplitCells.
append(splitCells_[index]);
1310 forAll(visibleCells_, celli)
1312 label index = visibleCells_[celli];
1314 if (index >= 0 && destination[celli] == proci)
1316 label parent = splitCells_[index].parent_;
1319 oldToNew[index] = newSplitCells.
size();
1333 forAll(newSplitCells, index)
1337 if (
split.parent_ >= 0)
1341 if (
split.addedCellsPtr_)
1349 splits[i] = oldToNew[splits[i]];
1356 const labelList& subMap = subCellMap[proci];
1363 label oldCelli = subMap[newCelli];
1365 label oldIndex = visibleCells_[oldCelli];
1369 newVisibleCells[newCelli] = oldToNew[oldIndex];
1380 toNbr << newSplitCells << newVisibleCells;
1388 splitCells_.
clear();
1408 label offset = splitCells_.size();
1413 forAll(newSplitCells, index)
1417 if (
split.parent_ >= 0)
1419 split.parent_ += offset;
1421 if (
split.addedCellsPtr_)
1429 splits[i] += offset;
1434 splitCells_.append(
split);
1441 forAll(newVisibleCells, i)
1443 if (newVisibleCells[i] >= 0)
1445 visibleCells_[constructMap[i]] = newVisibleCells[i] + offset;
1449 splitCells_.shrink();
1461 Pout<<
"refinementHistory::compact() Entering with:"
1462 <<
" freeSplitCells_:" << freeSplitCells_.size()
1463 <<
" splitCells_:" << splitCells_.size()
1464 <<
" visibleCells_:" << visibleCells_.size()
1468 forAll(freeSplitCells_, i)
1470 label index = freeSplitCells_[i];
1472 if (splitCells_[index].parent_ != -2)
1475 <<
"Problem index:" << index
1481 forAll(visibleCells_, celli)
1485 visibleCells_[celli] >= 0
1486 && splitCells_[visibleCells_[celli]].parent_ == -2
1490 <<
"Problem : visible cell:" << celli
1499 labelList oldToNew(splitCells_.size(), -1);
1505 forAll(visibleCells_, celli)
1507 label index = visibleCells_[celli];
1515 splitCells_[index].parent_ != -1
1516 || splitCells_[index].addedCellsPtr_
1519 markSplit(index, oldToNew, newSplitCells);
1525 forAll(splitCells_, index)
1527 if (splitCells_[index].parent_ == -2)
1533 splitCells_[index].parent_ == -1
1534 && !splitCells_[index].addedCellsPtr_
1543 markSplit(index, oldToNew, newSplitCells);
1551 forAll(newSplitCells, index)
1555 if (
split.parent_ >= 0)
1559 if (
split.addedCellsPtr_)
1567 splits[i] = oldToNew[splits[i]];
1576 Pout<<
"refinementHistory::compact : compacted splitCells from "
1577 << splitCells_.size() <<
" to " << newSplitCells.
size() <<
endl;
1580 splitCells_.transfer(newSplitCells);
1581 freeSplitCells_.clearStorage();
1586 Pout<<
"refinementHistory::compact() NOW:"
1587 <<
" freeSplitCells_:" << freeSplitCells_.size()
1588 <<
" splitCells_:" << splitCells_.size()
1589 <<
" newSplitCells:" << newSplitCells.
size()
1590 <<
" visibleCells_:" << visibleCells_.size()
1596 forAll(visibleCells_, celli)
1598 label index = visibleCells_[celli];
1603 visibleCells_[celli] = oldToNew[index];
1615 writeDebug(visibleCells_, splitCells_);
1625 label parentIndex = -1;
1627 if (visibleCells_[celli] != -1)
1632 parentIndex = visibleCells_[celli];
1636 visibleCells_[celli] = -1;
1641 parentIndex = allocateSplitCell(-1, -1);
1648 label addedCelli = addedCells[i];
1652 visibleCells_[addedCelli] = allocateSplitCell(parentIndex, i);
1659 const label masterCelli,
1664 label parentIndex = splitCells_[visibleCells_[masterCelli]].parent_;
1669 label celli = combinedCells[i];
1671 freeSplitCell(visibleCells_[celli]);
1672 visibleCells_[celli] = -1;
1675 splitCell8& parentSplit = splitCells_[parentIndex];
1677 visibleCells_[masterCelli] = parentIndex;
1683 bool ok = readData(readStream(typeName));
1718 if (topoSet::debug)
DebugVar(setsDir);
1720 if (
exists(setsDir/typeName))
1722 rm(setsDir/typeName);
1733 is >> rh.splitCells_ >> rh.visibleCells_;
1746 return os <<
"// splitCells" <<
nl
1747 << rh.splitCells_ <<
nl
1748 <<
"// visibleCells" <<
nl
1749 << rh.visibleCells_;
static bool split(const std::string &line, std::string &key, std::string &val)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
DynamicList< T, SizeMin > & shrink()
Shrink the allocated space to the number of elements used.
T remove()
Remove and return the last element. Fatal on an empty list.
void append(const T &val)
Copy append an element to the end of this list.
void clearStorage()
Clear the list and delete storage.
virtual bool resize()
Resize the ODE solver.
A 1D vector of objects of type <T> with a fixed length <N>.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
readOption readOpt() const noexcept
The read option.
const objectRegistry & db() const noexcept
Return the local objectRegistry.
fileName path() const
The complete path.
autoPtr< IOobject > clone() const
Clone.
bool good() const noexcept
True if next operation might succeed.
bool bad() const noexcept
True if stream is corrupted.
Input inter-processor communications stream.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void setSize(const label n)
Alias for resize()
void clear()
Clear the list, i.e. set size to zero.
Output inter-processor communications stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
UPstream::rangeType allProcs() const noexcept
Range of ranks indices associated with PstreamBuffers.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
void size(const label n)
Older name for setAddressableSize.
T & last()
Return the last element of the list.
static bool & parRun() noexcept
Test if this a parallel run.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
label size() const noexcept
The number of elements in the list.
virtual tmp< fvPatchScalarField > clone() const
Construct and return a clone.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
virtual void apply()=0
Apply bins.
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
void removeFiles() const
Remove all files from mesh instance()
A class for handling file names.
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
const labelListList & constructMap() const noexcept
From subsetted data to new reconstructed data.
const labelListList & subMap() const noexcept
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 mapDistribute & cellMap() const noexcept
Cell distribute map.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & reverseCellMap() const
Reverse cell map.
const labelList & cellMap() const
Old cell map.
void updateMesh()
Update for new mesh topology.
Mesh consisting of general polyhedral cells.
const fileName & facesInstance() const
Return the current instance directory for faces.
virtual const labelList & faceOwner() const
Return face owner.
virtual const labelList & faceNeighbour() const
Return face neighbour.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
const string & prefix() const noexcept
Return the stream prefix.
label nCells() const noexcept
Number of mesh cells.
label nFaces() const noexcept
Number of mesh faces.
int myProcNo() const noexcept
Return processor number.
splitCell8()
Default construct (parent = -1)
autoPtr< FixedList< label, 8 > > addedCellsPtr_
Cells this cell was refined into.
void operator=(const splitCell8 &rhs)
Copy assignment (no autoPtr stealing)
All refinement history. Used in unrefinement.
void compact()
Compact splitCells_. Removes all freeSplitCells_ elements.
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 distribute(const mapDistributePolyMesh &)
Update local numbering for mesh redistribution.
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. Does not check the headerClassName.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugVar(var)
Report a variable name and value.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
List< label > labelList
A List of labels.
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Ostream & endl(Ostream &os)
Add newline and flush stream.
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Istream & operator>>(Istream &, directionInfo &)
errorManip< error > abort(error &err)
static constexpr const zero Zero
Global zero (0)
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.