53void 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());
88 const Map<label>& splitMap,
102void 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();
121void 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);
229void 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;
365void 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
448void 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);
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);
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();
554 if (nRemainingCells > 0)
561 refineFromDict(
mesh, cellDirections,
dict, writeMesh);
578 cellLabels_(cellLabels),
579 addedCells_(
mesh.nCells())
584 refineAllDirs(
mesh, cellDirections, cellWalker, cutter, writeMesh);
void setSize(const label n)
Alias for resize()
static word timeName(const scalar t, const int precision=precision_)
void size(const label n)
Older name for setAddressableSize.
Abstract base class. Concrete implementations know how to cut a cell (i.e. determine a loop around th...
reference ref() const
A reference to the entry (Error if not found)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Set of directions for each cell in the mesh. Either uniform and size=1 or one set of directions per c...
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
const Time & time() const
Return the top-level database.
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
virtual bool update()
Update the mesh for both mesh motion and topology change.
Does multiple pass refinement to refine cells in multiple directions.
Mesh consisting of general polyhedral cells.
const fileName & facesInstance() const
Return the current instance directory for faces.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
const cellShapeList & cellShapes() const
Return cell shapes.
label nPoints() const noexcept
Number of mesh points.
label nCells() const noexcept
Number of mesh cells.
The main refinement handler. Gets cellCuts which is structure that describes which cells are to be cu...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
List< label > labelList
A List of labels.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
errorManip< error > abort(error &err)
Field< vector > vectorField
Specialisation of Field<T> for vector.
static constexpr const zero Zero
Global zero (0)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.