50 void Foam::multiDirRefinement::addCells
52 const Map<label>& splitMap,
53 List<refineCell>& refCells
56 label newRefI = refCells.size();
58 label oldSize = refCells.size();
60 refCells.setSize(newRefI + splitMap.size());
62 for (
label refI = 0; refI < oldSize; refI++)
64 const refineCell& refCell = refCells[refI];
68 if (iter == splitMap.end())
71 <<
"Problem : cannot find added cell for cell "
75 refCells[newRefI++] = refineCell(iter(), refCell.direction());
80 void Foam::multiDirRefinement::update
82 const Map<label>& splitMap,
86 field.setSize(field.size() + splitMap.size());
90 field[iter()] = field[iter.key()];
95 void Foam::multiDirRefinement::addCells
97 const Map<label>& splitMap,
101 label newCelli = labels.size();
103 labels.setSize(labels.size() + splitMap.size());
107 labels[newCelli++] = iter();
114 void Foam::multiDirRefinement::addCells
116 const primitiveMesh&
mesh,
117 const Map<label>& splitMap
123 forAll(addedCells_, celli)
125 const labelList& added = addedCells_[celli];
129 label slave = added[i];
131 if (origCell[slave] == -1)
133 origCell[slave] = celli;
135 else if (origCell[slave] != celli)
138 <<
"Added cell " << slave <<
" has two different masters:"
139 << origCell[slave] <<
" , " << celli
148 label masterI = iter.key();
149 label newCelli = iter();
151 while (origCell[masterI] != -1 && origCell[masterI] != masterI)
153 masterI = origCell[masterI];
156 if (masterI >= addedCells_.size())
159 <<
"Map of added cells contains master cell " << masterI
160 <<
" which is not a valid cell number" <<
endl
161 <<
"This means that the mesh is not consistent with the"
162 <<
" done refinement" <<
endl
174 else if (
findIndex(added, newCelli) == -1)
176 label sz = added.size();
177 added.setSize(sz + 1);
178 added[sz] = newCelli;
192 labelList nonHexLabels(cellLabels_.size());
200 label celli = cellLabels_[i];
204 hexLabels[hexI++] = celli;
208 nonHexLabels[nonHexI++] = celli;
212 nonHexLabels.setSize(nonHexI);
214 cellLabels_.transfer(nonHexLabels);
216 hexLabels.setSize(hexI);
222 void Foam::multiDirRefinement::refineHex8
231 Pout<<
"multiDirRefinement : Refining hexes " << hexCells.size()
252 List<refinementHistory::splitCell8>(0),
258 polyTopoChange meshMod(
mesh);
262 hexRefiner.consistentRefinement
272 Map<label> hexCellSet(2*hexCells.size());
275 hexCellSet.insert(hexCells[i], 1);
279 forAll(consistentCells, i)
281 const label celli = consistentCells[i];
285 if (iter == hexCellSet.end())
288 <<
"Resulting mesh would not satisfy 2:1 ratio"
304 <<
"Resulting mesh would not satisfy 2:1 ratio"
305 <<
" when refining cell " << iter.key()
312 hexRefiner.setRefinement(consistentCells, meshMod);
315 autoPtr<polyTopoChangeMap> mapPtr = meshMod.changeMesh(
mesh,
true);
316 const polyTopoChangeMap& map = mapPtr();
325 Pout<<
"multiDirRefinement : updated mesh at time "
329 hexRefiner.topoChange(map);
333 forAll(consistentCells, i)
335 addedCells_[consistentCells[i]].setSize(8);
337 labelList nAddedCells(addedCells_.size(), 0);
339 const labelList& cellMap = map.cellMap();
343 const label oldCelli = cellMap[celli];
345 if (addedCells_[oldCelli].size())
347 addedCells_[oldCelli][nAddedCells[oldCelli]++] = celli;
353 void Foam::multiDirRefinement::refineAllDirs
356 List<vectorField>& cellDirections,
357 const cellLooper& cellWalker,
358 undoableMeshCutter& cutter,
363 refinementIterator refiner(
mesh, cutter, cellWalker, writeMesh);
365 forAll(cellDirections, dirI)
369 Pout<<
"multiDirRefinement : Refining " << cellLabels_.size()
370 <<
" cells in direction " << dirI <<
endl
374 const vectorField& dirField = cellDirections[dirI];
379 List<refineCell> refCells(cellLabels_.size());
381 if (dirField.size() == 1)
386 Pout<<
"multiDirRefinement : Uniform refinement:"
387 << dirField[0] <<
endl;
392 label celli = cellLabels_[refI];
394 refCells[refI] = refineCell(celli, dirField[0]);
402 const label celli = cellLabels_[refI];
404 refCells[refI] = refineCell(celli, dirField[celli]);
409 Map<label> splitMap = refiner.setRefinement(refCells);
412 addCells(
mesh, splitMap);
415 addCells(splitMap, cellLabels_);
418 if (dirField.size() != 1)
422 update(splitMap, cellDirections[i]);
428 Pout<<
"multiDirRefinement : Done refining direction " << dirI
429 <<
" resulting in " << cellLabels_.size() <<
" cells" <<
nl
436 void Foam::multiDirRefinement::refineFromDict
439 List<vectorField>& cellDirections,
440 const dictionary&
dict,
447 autoPtr<cellLooper> cellWalker(
nullptr);
450 cellWalker.reset(
new geomCellLooper(
mesh));
454 cellWalker.reset(
new hexCellLooper(
mesh));
461 undoableMeshCutter cutter(
mesh,
false);
463 refineAllDirs(
mesh, cellDirections, cellWalker(), cutter, writeMesh);
477 cellLabels_(cellLabels),
478 addedCells_(
mesh.nCells())
480 Switch useHex(
dict.lookupOrDefault(
"useHexTopology",
false));
482 Switch writeMesh(
dict.lookupOrDefault(
"writeMesh",
false));
486 if (useHex && dirNames.
size() == 3)
491 refineHex8(
mesh, hexCells, writeMesh);
494 label nRemainingCells = cellLabels_.
size();
498 if (nRemainingCells > 0)
506 refineFromDict(
mesh, cellDirections,
dict, writeMesh);
520 cellLabels_(cellLabels),
521 addedCells_(
mesh.nCells())
523 Switch useHex(
dict.lookupOrDefault(
"useHexTopology",
false));
525 Switch writeMesh(
dict.lookupOrDefault(
"writeMesh",
false));
529 if (useHex && dirNames.
size() == 3)
534 refineHex8(
mesh, hexCells, writeMesh);
537 label nRemainingCells = cellLabels_.
size();
541 if (nRemainingCells > 0)
548 refineFromDict(
mesh, cellDirections,
dict, writeMesh);
564 cellLabels_(cellLabels),
565 addedCells_(
mesh.nCells())
570 refineAllDirs(
mesh, cellDirections, cellWalker, cutter, writeMesh);
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
friend class iterator
Declare friendship with the iterator.
friend class const_iterator
Declare friendship with the const_iterator.
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Abstract base class. Concrete implementations know how to cut a cell (i.e. determine a loop around th...
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
T lookupOrDefault(const word &, const T &, const bool writeDefault=writeOptionalEntries > 0) const
Find and return a T, if not found return the given default.
const word & name() const
Return const reference to name.
Set of directions for each cell in the mesh. Either uniform and size=1 or one set of directions per c...
const Time & time() const
Return the top-level database.
virtual bool write(const bool write=true) const
Write mesh using IO settings from time.
Does multiple pass refinement to refine cells in multiple directions.
multiDirRefinement(polyMesh &mesh, const labelList &cellLabels, const dictionary &dict, const dictionary &coordinatesDict)
Construct from dictionary. After construction all refinement will.
Mesh consisting of general polyhedral cells.
const fileName & facesInstance() const
Return the current instance directory for faces.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
const cellShapeList & cellShapes() const
Return cell shapes.
The main refinement handler. Gets cellCuts which is structure that describes which cells are to be cu...
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const cellShapeList & cellShapes
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
IOstream & hex(IOstream &io)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
defineTypeNameAndDebug(combustionModel, 0)
Field< vector > vectorField
Specialisation of Field<T> for vector.
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,.