52 void Foam::multiDirRefinement::addCells
54 const Map<label>& splitMap,
55 List<refineCell>& refCells
58 label newRefI = refCells.size();
60 label oldSize = refCells.size();
62 refCells.setSize(newRefI + splitMap.size());
64 for (
label refI = 0; refI < oldSize; refI++)
66 const refineCell& refCell = refCells[refI];
70 if (iter == splitMap.end())
73 <<
"Problem : cannot find added cell for cell "
77 refCells[newRefI++] = refineCell(iter(), refCell.direction());
84 void Foam::multiDirRefinement::update
86 const Map<label>& splitMap,
90 field.setSize(field.size() + splitMap.size());
94 field[iter()] = field[iter.key()];
100 void Foam::multiDirRefinement::addCells
102 const Map<label>& splitMap,
106 label newCelli = labels.size();
108 labels.setSize(labels.size() + splitMap.size());
112 labels[newCelli++] = iter();
119 void Foam::multiDirRefinement::addCells
121 const primitiveMesh& mesh,
122 const Map<label>& splitMap
128 forAll(addedCells_, celli)
130 const labelList& added = addedCells_[celli];
134 label slave = added[i];
136 if (origCell[slave] == -1)
138 origCell[slave] = celli;
140 else if (origCell[slave] != celli)
143 <<
"Added cell " << slave <<
" has two different masters:"
144 << origCell[slave] <<
" , " << celli
153 label masterI = iter.key();
154 label newCelli = iter();
156 while (origCell[masterI] != -1 && origCell[masterI] != masterI)
158 masterI = origCell[masterI];
161 if (masterI >= addedCells_.size())
164 <<
"Map of added cells contains master cell " << masterI
165 <<
" which is not a valid cell number" <<
endl
166 <<
"This means that the mesh is not consistent with the"
167 <<
" done refinement" <<
endl
179 else if (
findIndex(added, newCelli) == -1)
181 label sz = added.size();
182 added.setSize(sz + 1);
183 added[sz] = newCelli;
189 Foam::labelList Foam::multiDirRefinement::splitOffHex(
const primitiveMesh& mesh)
197 labelList nonHexLabels(cellLabels_.size());
205 label celli = cellLabels_[i];
209 hexLabels[hexI++] = celli;
213 nonHexLabels[nonHexI++] = celli;
217 nonHexLabels.setSize(nonHexI);
219 cellLabels_.transfer(nonHexLabels);
221 hexLabels.setSize(hexI);
227 void Foam::multiDirRefinement::refineHex8
236 Pout<<
"multiDirRefinement : Refining hexes " << hexCells.size()
250 mesh.facesInstance(),
257 List<refinementHistory::splitCell8>(0),
263 polyTopoChange meshMod(mesh);
267 hexRefiner.consistentRefinement
277 Map<label> hexCellSet(2*hexCells.size());
280 hexCellSet.insert(hexCells[i], 1);
284 forAll(consistentCells, i)
286 const label celli = consistentCells[i];
290 if (iter == hexCellSet.end())
293 <<
"Resulting mesh would not satisfy 2:1 ratio"
309 <<
"Resulting mesh would not satisfy 2:1 ratio"
310 <<
" when refining cell " << iter.key()
317 hexRefiner.setRefinement(consistentCells, meshMod);
320 autoPtr<polyTopoChangeMap> mapPtr = meshMod.changeMesh(mesh,
true);
321 const polyTopoChangeMap& map = mapPtr();
330 Pout<<
"multiDirRefinement : updated mesh at time "
334 hexRefiner.topoChange(map);
338 forAll(consistentCells, i)
340 addedCells_[consistentCells[i]].setSize(8);
342 labelList nAddedCells(addedCells_.size(), 0);
344 const labelList& cellMap = map.cellMap();
348 const label oldCelli = cellMap[celli];
350 if (addedCells_[oldCelli].size())
352 addedCells_[oldCelli][nAddedCells[oldCelli]++] = celli;
358 void Foam::multiDirRefinement::refineAllDirs
361 List<vectorField>& cellDirections,
362 const cellLooper& cellWalker,
363 undoableMeshCutter& cutter,
368 refinementIterator refiner(mesh, cutter, cellWalker, writeMesh);
370 forAll(cellDirections, dirI)
374 Pout<<
"multiDirRefinement : Refining " << cellLabels_.size()
375 <<
" cells in direction " << dirI <<
endl
379 const vectorField& dirField = cellDirections[dirI];
384 List<refineCell> refCells(cellLabels_.size());
386 if (dirField.size() == 1)
391 Pout<<
"multiDirRefinement : Uniform refinement:"
392 << dirField[0] <<
endl;
397 label celli = cellLabels_[refI];
399 refCells[refI] = refineCell(celli, dirField[0]);
407 const label celli = cellLabels_[refI];
409 refCells[refI] = refineCell(celli, dirField[celli]);
414 Map<label> splitMap = refiner.setRefinement(refCells);
417 addCells(mesh, splitMap);
420 addCells(splitMap, cellLabels_);
423 if (dirField.size() != 1)
427 update(splitMap, cellDirections[i]);
433 Pout<<
"multiDirRefinement : Done refining direction " << dirI
434 <<
" resulting in " << cellLabels_.size() <<
" cells" <<
nl
441 void Foam::multiDirRefinement::refineFromDict
444 List<vectorField>& cellDirections,
445 const dictionary&
dict,
450 Switch pureGeomCut(
dict.
lookup(
"geometricCut"));
452 autoPtr<cellLooper> cellWalker(
nullptr);
455 cellWalker.reset(
new geomCellLooper(mesh));
459 cellWalker.reset(
new hexCellLooper(mesh));
466 undoableMeshCutter cutter(mesh,
false);
468 refineAllDirs(mesh, cellDirections, cellWalker(), cutter, writeMesh);
482 cellLabels_(cellLabels),
483 addedCells_(mesh.nCells())
491 if (useHex && dirNames.
size() == 3)
496 refineHex8(mesh, hexCells, writeMesh);
499 label nRemainingCells = cellLabels_.
size();
503 if (nRemainingCells > 0)
511 refineFromDict(mesh, cellDirections,
dict, writeMesh);
525 cellLabels_(cellLabels),
526 addedCells_(mesh.nCells())
534 if (useHex && dirNames.
size() == 3)
539 refineHex8(mesh, hexCells, writeMesh);
542 label nRemainingCells = cellLabels_.
size();
546 if (nRemainingCells > 0)
553 refineFromDict(mesh, cellDirections,
dict, writeMesh);
570 cellLabels_(cellLabels),
571 addedCells_(mesh.nCells())
576 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.
virtual const fileName & name() const
Return the name of the stream.
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 keyword definitions, which are a keyword followed by any number of values (e....
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Set of directions for each cell in the mesh. Either uniform and size=1 or one set of directions per c...
Does multiple pass refinement to refine cells in multiple directions.
multiDirRefinement(polyMesh &mesh, const labelList &cellLabels, const dictionary &dict)
Construct from dictionary. After construction all refinement will.
Mesh consisting of general polyhedral cells.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
The main refinement handler. Gets cellCuts which is structure that describes which cells are to be cu...
#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,.