53 void Foam::multiDirRefinement::addCells
55 const Map<label>& splitMap,
56 List<refineCell>& refCells
59 label newRefI = refCells.size();
61 label oldSize = refCells.size();
63 refCells.setSize(newRefI + splitMap.size());
65 for (
label refI = 0; refI < oldSize; refI++)
67 const refineCell& refCell = refCells[refI];
71 if (iter == splitMap.end())
74 <<
"Problem : cannot find added cell for cell "
78 refCells[newRefI++] = refineCell(iter(), refCell.direction());
85 void Foam::multiDirRefinement::update
87 const Map<label>& splitMap,
91 field.setSize(field.size() + splitMap.size());
95 field[iter()] = field[iter.key()];
101 void Foam::multiDirRefinement::addCells
103 const Map<label>& splitMap,
107 label newCelli = labels.size();
109 labels.setSize(labels.size() + splitMap.size());
113 labels[newCelli++] = iter();
120 void Foam::multiDirRefinement::addCells
122 const primitiveMesh& mesh,
123 const Map<label>& splitMap
129 forAll(addedCells_, celli)
131 const labelList& added = addedCells_[celli];
135 label slave = added[i];
137 if (origCell[slave] == -1)
139 origCell[slave] = celli;
141 else if (origCell[slave] != celli)
144 <<
"Added cell " << slave <<
" has two different masters:"
145 << origCell[slave] <<
" , " << celli
154 label masterI = iter.key();
155 label newCelli = iter();
157 while (origCell[masterI] != -1 && origCell[masterI] != masterI)
159 masterI = origCell[masterI];
162 if (masterI >= addedCells_.size())
165 <<
"Map of added cells contains master cell " << masterI
166 <<
" which is not a valid cell number" <<
endl
167 <<
"This means that the mesh is not consistent with the"
168 <<
" done refinement" <<
endl
180 else if (
findIndex(added, newCelli) == -1)
182 label sz = added.size();
183 added.setSize(sz + 1);
184 added[sz] = newCelli;
190 Foam::labelList Foam::multiDirRefinement::splitOffHex(
const primitiveMesh& mesh)
198 labelList nonHexLabels(cellLabels_.size());
206 label celli = cellLabels_[i];
210 hexLabels[hexI++] = celli;
214 nonHexLabels[nonHexI++] = celli;
218 nonHexLabels.setSize(nonHexI);
220 cellLabels_.transfer(nonHexLabels);
222 hexLabels.setSize(hexI);
228 void Foam::multiDirRefinement::refineHex8
237 Pout<<
"multiDirRefinement : Refining hexes " << hexCells.size()
251 mesh.facesInstance(),
258 List<refinementHistory::splitCell8>(0),
264 polyTopoChange meshMod(mesh);
268 hexRefiner.consistentRefinement
278 Map<label> hexCellSet(2*hexCells.size());
281 hexCellSet.insert(hexCells[i], 1);
285 forAll(consistentCells, i)
287 const label celli = consistentCells[i];
291 if (iter == hexCellSet.end())
294 <<
"Resulting mesh would not satisfy 2:1 ratio"
310 <<
"Resulting mesh would not satisfy 2:1 ratio"
311 <<
" when refining cell " << iter.key()
318 hexRefiner.setRefinement(consistentCells, meshMod);
321 autoPtr<polyTopoChangeMap> mapPtr =
322 meshMod.changeMesh(mesh,
false,
true);
323 const polyTopoChangeMap& map = mapPtr();
325 if (map.hasMotionPoints())
327 mesh.movePoints(map.preMotionPoints());
337 Pout<<
"multiDirRefinement : updated mesh at time "
341 hexRefiner.topoChange(map);
345 forAll(consistentCells, i)
347 addedCells_[consistentCells[i]].setSize(8);
349 labelList nAddedCells(addedCells_.size(), 0);
351 const labelList& cellMap = map.cellMap();
355 const label oldCelli = cellMap[celli];
357 if (addedCells_[oldCelli].size())
359 addedCells_[oldCelli][nAddedCells[oldCelli]++] = celli;
365 void Foam::multiDirRefinement::refineAllDirs
368 List<vectorField>& cellDirections,
369 const cellLooper& cellWalker,
370 undoableMeshCutter& cutter,
375 refinementIterator refiner(mesh, cutter, cellWalker, writeMesh);
377 forAll(cellDirections, dirI)
381 Pout<<
"multiDirRefinement : Refining " << cellLabels_.size()
382 <<
" cells in direction " << dirI <<
endl
386 const vectorField& dirField = cellDirections[dirI];
391 List<refineCell> refCells(cellLabels_.size());
393 if (dirField.size() == 1)
398 Pout<<
"multiDirRefinement : Uniform refinement:"
399 << dirField[0] <<
endl;
404 label celli = cellLabels_[refI];
406 refCells[refI] = refineCell(celli, dirField[0]);
414 const label celli = cellLabels_[refI];
416 refCells[refI] = refineCell(celli, dirField[celli]);
421 Map<label> splitMap = refiner.setRefinement(refCells);
424 addCells(mesh, splitMap);
427 addCells(splitMap, cellLabels_);
430 if (dirField.size() != 1)
434 update(splitMap, cellDirections[i]);
440 Pout<<
"multiDirRefinement : Done refining direction " << dirI
441 <<
" resulting in " << cellLabels_.size() <<
" cells" <<
nl
448 void Foam::multiDirRefinement::refineFromDict
451 List<vectorField>& cellDirections,
452 const dictionary&
dict,
457 Switch pureGeomCut(
dict.
lookup(
"geometricCut"));
459 autoPtr<cellLooper> cellWalker(
nullptr);
462 cellWalker.reset(
new geomCellLooper(mesh));
466 cellWalker.reset(
new hexCellLooper(mesh));
473 undoableMeshCutter cutter(mesh,
false);
475 refineAllDirs(mesh, cellDirections, cellWalker(), cutter, writeMesh);
490 cellLabels_(cellLabels),
491 addedCells_(mesh.nCells())
499 if (useHex && dirNames.
size() == 3)
504 refineHex8(mesh, hexCells, writeMesh);
507 label nRemainingCells = cellLabels_.
size();
511 if (nRemainingCells > 0)
519 refineFromDict(mesh, cellDirections,
dict, writeMesh);
533 cellLabels_(cellLabels),
534 addedCells_(mesh.nCells())
542 if (useHex && dirNames.
size() == 3)
547 refineHex8(mesh, hexCells, writeMesh);
550 label nRemainingCells = cellLabels_.
size();
554 if (nRemainingCells > 0)
561 refineFromDict(mesh, cellDirections,
dict, writeMesh);
578 cellLabels_(cellLabels),
579 addedCells_(mesh.nCells())
584 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.
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
HashTable< label, label, Hash< label > >::iterator iterator
HashTable< label, label, Hash< label > >::const_iterator const_iterator
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,.