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>(),
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);
515 refineFromDict(
mesh, cellDirections,
dict, writeMesh);
521 Foam::multiDirRefinement::multiDirRefinement
525 const List<vectorField>& cellDirs,
526 const dictionary&
dict 529 cellLabels_(cellLabels),
530 addedCells_(
mesh.nCells())
532 const bool useHex(
dict.get<
bool>(
"useHexTopology"));
534 const bool writeMesh(
dict.get<
bool>(
"writeMesh"));
538 if (useHex && dirNames.size() == 3)
543 refineHex8(
mesh, hexCells, writeMesh);
551 List<vectorField> cellDirections(cellDirs);
553 refineFromDict(
mesh, cellDirections,
dict, writeMesh);
559 Foam::multiDirRefinement::multiDirRefinement
562 undoableMeshCutter& cutter,
563 const cellLooper& cellWalker,
566 const List<vectorField>& cellDirs,
570 cellLabels_(cellLabels),
571 addedCells_(
mesh.nCells())
574 List<vectorField> cellDirections(cellDirs);
576 refineAllDirs(
mesh, cellDirections, cellWalker, cutter, writeMesh);
void size(const label n)
Older name for setAddressableSize.
const fileName & facesInstance() const
Return the current instance directory for faces.
label nPoints() const noexcept
Number of mesh points.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
IOstream & hex(IOstream &io)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
constexpr char nl
The newline '\n' character (0x0a)
const cellShapeList & cellShapes() const
Return cell shapes.
Set of directions for each cell in the mesh. Either uniform and size=1 or one set of directions per c...
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
List< cellShape > cellShapeList
List of cellShape.
Ignore writing from objectRegistry::writeObject()
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
const Time & time() const
Return the top-level database.
#define forAll(list, i)
Loop across all elements in list.
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
void setSize(const label n)
Alias for resize()
errorManip< error > abort(error &err)
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
List< word > wordList
List of word.
label nCells() const noexcept
Number of mesh cells.
Field< vector > vectorField
Specialisation of Field<T> for vector.
Mesh consisting of general polyhedral cells.
List< label > labelList
A List of labels.
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Do not request registration (bool: false)
forAllConstIters(mixture.phases(), phase)
static constexpr const zero Zero
Global zero (0)