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())
75 "multiDirRefinement::addCells(const Map<label>&"
76 ", List<refineCell>&)"
77 ) <<
"Problem : cannot find added cell for cell "
81 refCells[newRefI++] = refineCell(iter(), refCell.direction());
88 void Foam::multiDirRefinement::update
90 const Map<label>& splitMap,
94 field.setSize(field.size() + splitMap.size());
99 iter != splitMap.end();
103 field[iter()] = field[iter.key()];
109 void Foam::multiDirRefinement::addCells
111 const Map<label>& splitMap,
115 label newCellI = labels.size();
117 labels.setSize(labels.size() + splitMap.size());
122 iter != splitMap.end();
126 labels[newCellI++] = iter();
133 void Foam::multiDirRefinement::addCells
135 const primitiveMesh&
mesh,
136 const Map<label>& splitMap
142 forAll(addedCells_, cellI)
144 const labelList& added = addedCells_[cellI];
148 label slave = added[i];
150 if (origCell[slave] == -1)
152 origCell[slave] = cellI;
154 else if (origCell[slave] != cellI)
158 "multiDirRefinement::addCells(const primitiveMesh&"
159 ", const Map<label>&"
160 ) <<
"Added cell " << slave <<
" has two different masters:"
161 << origCell[slave] <<
" , " << cellI
171 iter != splitMap.end();
175 label masterI = iter.key();
176 label newCellI = iter();
178 while (origCell[masterI] != -1 && origCell[masterI] != masterI)
180 masterI = origCell[masterI];
183 if (masterI >= addedCells_.size())
187 "multiDirRefinement::addCells(const primitiveMesh&"
188 ", const Map<label>&"
189 ) <<
"Map of added cells contains master cell " << masterI
190 <<
" which is not a valid cell number" <<
endl
191 <<
"This means that the mesh is not consistent with the"
192 <<
" done refinement" <<
endl
204 else if (
findIndex(added, newCellI) == -1)
206 label sz = added.size();
207 added.setSize(sz + 1);
208 added[sz] = newCellI;
214 Foam::labelList Foam::multiDirRefinement::splitOffHex(
const primitiveMesh& mesh)
222 labelList nonHexLabels(cellLabels_.size());
230 label cellI = cellLabels_[i];
232 if (cellShapes[cellI].model() == hex)
234 hexLabels[hexI++] = cellI;
238 nonHexLabels[nonHexI++] = cellI;
242 nonHexLabels.setSize(nonHexI);
244 cellLabels_.transfer(nonHexLabels);
246 hexLabels.setSize(hexI);
252 void Foam::multiDirRefinement::refineHex8
261 Pout<<
"multiDirRefinement : Refining hexes " << hexCells.size()
275 mesh.facesInstance(),
282 List<refinementHistory::splitCell8>(0),
287 polyTopoChange meshMod(mesh);
291 hexRefiner.consistentRefinement
301 Map<label> hexCellSet(2*hexCells.size());
304 hexCellSet.insert(hexCells[i], 1);
308 forAll(consistentCells, i)
310 label cellI = consistentCells[i];
314 if (iter == hexCellSet.end())
318 "multiDirRefinement::refineHex8"
319 "(polyMesh&, const labelList&, const bool)"
320 ) <<
"Resulting mesh would not satisfy 2:1 ratio"
337 "multiDirRefinement::refineHex8"
338 "(polyMesh&, const labelList&, const bool)"
339 ) <<
"Resulting mesh would not satisfy 2:1 ratio"
340 <<
" when refining cell " << iter.key()
347 hexRefiner.setRefinement(consistentCells, meshMod);
350 autoPtr<mapPolyMesh> morphMapPtr = meshMod.changeMesh(mesh,
false,
true);
351 const mapPolyMesh& morphMap = morphMapPtr();
353 if (morphMap.hasMotionPoints())
355 mesh.movePoints(morphMap.preMotionPoints());
365 Pout<<
"multiDirRefinement : updated mesh at time "
366 << mesh.time().timeName() <<
endl;
369 hexRefiner.updateMesh(morphMap);
373 forAll(consistentCells, i)
375 addedCells_[consistentCells[i]].setSize(8);
377 labelList nAddedCells(addedCells_.size(), 0);
379 const labelList& cellMap = morphMap.cellMap();
383 label oldCellI = cellMap[cellI];
385 if (addedCells_[oldCellI].size())
387 addedCells_[oldCellI][nAddedCells[oldCellI]++] = cellI;
393 void Foam::multiDirRefinement::refineAllDirs
396 List<vectorField>& cellDirections,
397 const cellLooper& cellWalker,
398 undoableMeshCutter& cutter,
403 refinementIterator refiner(mesh, cutter, cellWalker, writeMesh);
405 forAll(cellDirections, dirI)
409 Pout<<
"multiDirRefinement : Refining " << cellLabels_.size()
410 <<
" cells in direction " << dirI <<
endl
414 const vectorField& dirField = cellDirections[dirI];
419 List<refineCell> refCells(cellLabels_.size());
421 if (dirField.size() == 1)
426 Pout<<
"multiDirRefinement : Uniform refinement:"
427 << dirField[0] <<
endl;
432 label cellI = cellLabels_[refI];
434 refCells[refI] = refineCell(cellI, dirField[0]);
442 label cellI = cellLabels_[refI];
444 refCells[refI] = refineCell(cellI, dirField[cellI]);
449 Map<label> splitMap = refiner.setRefinement(refCells);
452 addCells(mesh, splitMap);
455 addCells(splitMap, cellLabels_);
458 if (dirField.size() != 1)
462 update(splitMap, cellDirections[i]);
468 Pout<<
"multiDirRefinement : Done refining direction " << dirI
469 <<
" resulting in " << cellLabels_.size() <<
" cells" <<
nl
476 void Foam::multiDirRefinement::refineFromDict
479 List<vectorField>& cellDirections,
480 const dictionary& dict,
485 Switch pureGeomCut(dict.lookup(
"geometricCut"));
487 autoPtr<cellLooper> cellWalker(NULL);
490 cellWalker.reset(
new geomCellLooper(mesh));
494 cellWalker.reset(
new hexCellLooper(mesh));
501 undoableMeshCutter cutter(mesh,
false);
503 refineAllDirs(mesh, cellDirections, cellWalker(), cutter, writeMesh);
511 Foam::multiDirRefinement::multiDirRefinement
518 cellLabels_(cellLabels),
519 addedCells_(mesh.
nCells())
527 if (useHex && dirNames.size() == 3)
532 refineHex8(mesh, hexCells, writeMesh);
535 label nRemainingCells = cellLabels_.size();
539 if (nRemainingCells > 0)
547 refineFromDict(mesh, cellDirections, dict, writeMesh);
553 Foam::multiDirRefinement::multiDirRefinement
561 cellLabels_(cellLabels),
562 addedCells_(mesh.
nCells())
570 if (useHex && dirNames.size() == 3)
575 refineHex8(mesh, hexCells, writeMesh);
578 label nRemainingCells = cellLabels_.size();
582 if (nRemainingCells > 0)
589 refineFromDict(mesh, cellDirections, dict, writeMesh);
595 Foam::multiDirRefinement::multiDirRefinement
606 cellLabels_(cellLabels),
607 addedCells_(mesh.
nCells())
612 refineAllDirs(mesh, cellDirections, cellWalker, cutter, writeMesh);