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];
208 if (cellShapes[celli].model() == hex)
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<mapPolyMesh> morphMapPtr = meshMod.changeMesh(mesh,
false,
true);
322 const mapPolyMesh& morphMap = morphMapPtr();
324 if (morphMap.hasMotionPoints())
326 mesh.movePoints(morphMap.preMotionPoints());
336 Pout<<
"multiDirRefinement : updated mesh at time " 337 << mesh.time().timeName() <<
endl;
340 hexRefiner.updateMesh(morphMap);
344 forAll(consistentCells, i)
346 addedCells_[consistentCells[i]].setSize(8);
348 labelList nAddedCells(addedCells_.size(), 0);
350 const labelList& cellMap = morphMap.cellMap();
354 const label oldCelli = cellMap[celli];
356 if (addedCells_[oldCelli].size())
358 addedCells_[oldCelli][nAddedCells[oldCelli]++] = celli;
364 void Foam::multiDirRefinement::refineAllDirs
367 List<vectorField>& cellDirections,
368 const cellLooper& cellWalker,
369 undoableMeshCutter& cutter,
374 refinementIterator refiner(mesh, cutter, cellWalker, writeMesh);
376 forAll(cellDirections, dirI)
380 Pout<<
"multiDirRefinement : Refining " << cellLabels_.size()
381 <<
" cells in direction " << dirI <<
endl 385 const vectorField& dirField = cellDirections[dirI];
390 List<refineCell> refCells(cellLabels_.size());
392 if (dirField.size() == 1)
397 Pout<<
"multiDirRefinement : Uniform refinement:" 398 << dirField[0] <<
endl;
403 label celli = cellLabels_[refI];
405 refCells[refI] = refineCell(celli, dirField[0]);
413 const label celli = cellLabels_[refI];
415 refCells[refI] = refineCell(celli, dirField[celli]);
420 Map<label> splitMap = refiner.setRefinement(refCells);
423 addCells(mesh, splitMap);
426 addCells(splitMap, cellLabels_);
429 if (dirField.size() != 1)
433 update(splitMap, cellDirections[i]);
439 Pout<<
"multiDirRefinement : Done refining direction " << dirI
440 <<
" resulting in " << cellLabels_.size() <<
" cells" <<
nl 447 void Foam::multiDirRefinement::refineFromDict
450 List<vectorField>& cellDirections,
451 const dictionary& dict,
456 Switch pureGeomCut(dict.lookup(
"geometricCut"));
458 autoPtr<cellLooper> cellWalker(
nullptr);
461 cellWalker.reset(
new geomCellLooper(mesh));
465 cellWalker.reset(
new hexCellLooper(mesh));
472 undoableMeshCutter cutter(mesh,
false);
474 refineAllDirs(mesh, cellDirections, cellWalker(), cutter, writeMesh);
489 cellLabels_(cellLabels),
490 addedCells_(mesh.
nCells())
498 if (useHex && dirNames.size() == 3)
503 refineHex8(mesh, hexCells, writeMesh);
506 label nRemainingCells = cellLabels_.size();
510 if (nRemainingCells > 0)
518 refineFromDict(mesh, cellDirections, dict, writeMesh);
532 cellLabels_(cellLabels),
533 addedCells_(mesh.
nCells())
541 if (useHex && dirNames.size() == 3)
546 refineHex8(mesh, hexCells, writeMesh);
549 label nRemainingCells = cellLabels_.size();
553 if (nRemainingCells > 0)
560 refineFromDict(mesh, cellDirections, dict, writeMesh);
577 cellLabels_(cellLabels),
578 addedCells_(mesh.
nCells())
583 refineAllDirs(mesh, cellDirections, cellWalker, cutter, writeMesh);
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
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...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
HashTable< label, label, Hash< label > >::iterator iterator
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Set of directions for each cell in the mesh. Either uniform and size=1 or one set of directions per c...
Ostream & endl(Ostream &os)
Add newline and flush stream.
Abstract base class. Concrete implementations know how to cut a cell (i.e. determine a loop around th...
The main refinement handler. Gets cellCuts which is structure that describes which cells are to be cu...
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
HashTable< label, label, Hash< label > >::const_iterator const_iterator
Various functions to operate on Lists.
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
List< label > labelList
A List of labels.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
multiDirRefinement(polyMesh &mesh, const labelList &cellLabels, const dictionary &dict)
Construct from dictionary. After construction all refinement will.
defineTypeNameAndDebug(combustionModel, 0)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
void setSize(const label)
Reset size of List.
prefixOSstream Pout(cout, "Pout")
Field< vector > vectorField
Specialisation of Field<T> for vector.
Mesh consisting of general polyhedral cells.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.