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];
69 const auto iter = splitMap.cfind(refCell.cellNo());
74 <<
"Problem : cannot find added cell for cell "
75 << refCell.cellNo() <<
endl
79 refCells[newRefI++] = refineCell(iter.val(), refCell.direction());
86 void Foam::multiDirRefinement::update
88 const Map<label>& splitMap,
102 void Foam::multiDirRefinement::addCells
104 const Map<label>& splitMap,
108 label newCelli = labels.size();
110 labels.setSize(labels.size() + splitMap.size());
114 labels[newCelli++] = iter.val();
121 void Foam::multiDirRefinement::addCells
123 const primitiveMesh&
mesh,
124 const Map<label>& splitMap
130 forAll(addedCells_, celli)
132 const labelList& added = addedCells_[celli];
136 label slave = added[i];
138 if (origCell[slave] == -1)
140 origCell[slave] = celli;
142 else if (origCell[slave] != celli)
145 <<
"Added cell " << slave <<
" has two different masters:"
146 << origCell[slave] <<
" , " << celli
155 label masterI = iter.key();
156 const label newCelli = iter.val();
158 while (origCell[masterI] != -1 && origCell[masterI] != masterI)
160 masterI = origCell[masterI];
163 if (masterI >= addedCells_.size())
166 <<
"Map of added cells contains master cell " << masterI
167 <<
" which is not a valid cell number" <<
endl
168 <<
"This means that the mesh is not consistent with the"
169 <<
" done refinement" <<
endl
181 else if (!added.found(newCelli))
183 const label sz = added.size();
184 added.setSize(sz + 1);
185 added[sz] = newCelli;
199 labelList nonHexLabels(cellLabels_.size());
207 label celli = cellLabels_[i];
211 hexLabels[hexI++] = celli;
215 nonHexLabels[nonHexI++] = celli;
219 nonHexLabels.setSize(nonHexI);
221 cellLabels_.transfer(nonHexLabels);
223 hexLabels.setSize(hexI);
229 void Foam::multiDirRefinement::refineHex8
238 Pout<<
"multiDirRefinement : Refining hexes " << hexCells.size()
259 List<refinementHistory::splitCell8>(0),
265 polyTopoChange meshMod(
mesh);
269 hexRefiner.consistentRefinement
279 Map<label> hexCellSet(2*hexCells.size());
282 hexCellSet.insert(hexCells[i], 1);
286 forAll(consistentCells, i)
288 const label celli = consistentCells[i];
290 auto iter = hexCellSet.find(celli);
299 <<
"Resulting mesh would not satisfy 2:1 ratio"
311 <<
"Resulting mesh would not satisfy 2:1 ratio"
312 <<
" when refining cell " << iter.key()
319 hexRefiner.setRefinement(consistentCells, meshMod);
322 autoPtr<mapPolyMesh> morphMapPtr = meshMod.changeMesh(
mesh,
false,
true);
323 const mapPolyMesh& morphMap = morphMapPtr();
325 if (morphMap.hasMotionPoints())
337 Pout<<
"multiDirRefinement : updated mesh at time "
341 hexRefiner.updateMesh(morphMap);
345 forAll(consistentCells, i)
347 addedCells_[consistentCells[i]].setSize(8);
351 const labelList& cellMap = morphMap.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 const 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 const bool pureGeomCut(
dict.
get<
bool>(
"geometricCut"));
459 autoPtr<cellLooper> cellWalker;
462 cellWalker.reset(
new geomCellLooper(
mesh));
466 cellWalker.reset(
new hexCellLooper(
mesh));
473 undoableMeshCutter cutter(
mesh,
false);
475 refineAllDirs(
mesh, cellDirections, cellWalker(), cutter, writeMesh);
483 Foam::multiDirRefinement::multiDirRefinement
490 cellLabels_(cellLabels),
491 addedCells_(
mesh.nCells())
493 const bool useHex(
dict.get<
bool>(
"useHexTopology"));
495 const bool writeMesh(
dict.get<
bool>(
"writeMesh"));
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);
525 Foam::multiDirRefinement::multiDirRefinement
529 const List<vectorField>& cellDirs,
530 const dictionary&
dict
533 cellLabels_(cellLabels),
534 addedCells_(
mesh.nCells())
536 const bool useHex(
dict.get<
bool>(
"useHexTopology"));
538 const bool writeMesh(
dict.get<
bool>(
"writeMesh"));
542 if (useHex && dirNames.size() == 3)
547 refineHex8(
mesh, hexCells, writeMesh);
550 label nRemainingCells = cellLabels_.size();
552 reduce(nRemainingCells, sumOp<label>());
554 if (nRemainingCells > 0)
559 List<vectorField> cellDirections(cellDirs);
561 refineFromDict(
mesh, cellDirections,
dict, writeMesh);
567 Foam::multiDirRefinement::multiDirRefinement
570 undoableMeshCutter& cutter,
571 const cellLooper& cellWalker,
574 const List<vectorField>& cellDirs,
578 cellLabels_(cellLabels),
579 addedCells_(
mesh.nCells())
582 List<vectorField> cellDirections(cellDirs);
584 refineAllDirs(
mesh, cellDirections, cellWalker, cutter, writeMesh);