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());
280 for (
const label celli : hexCells)
282 hexCellSet.insert(celli, 1);
286 for (
const label celli : consistentCells)
288 auto iter = hexCellSet.
find(celli);
297 <<
"Resulting mesh would not satisfy 2:1 ratio" 309 <<
"Resulting mesh would not satisfy 2:1 ratio" 310 <<
" when refining cell " << iter.key()
317 hexRefiner.setRefinement(consistentCells, meshMod);
320 autoPtr<mapPolyMesh> morphMapPtr = meshMod.changeMesh(
mesh,
false,
true);
321 const mapPolyMesh& morphMap = morphMapPtr();
323 if (morphMap.hasMotionPoints())
335 Pout<<
"multiDirRefinement : updated mesh at time " 339 hexRefiner.updateMesh(morphMap);
343 forAll(consistentCells, i)
345 addedCells_[consistentCells[i]].setSize(8);
349 const labelList& cellMap = morphMap.cellMap();
353 const label oldCelli = cellMap[celli];
355 if (addedCells_[oldCelli].size())
357 addedCells_[oldCelli][nAddedCells[oldCelli]++] = celli;
363 void Foam::multiDirRefinement::refineAllDirs
366 List<vectorField>& cellDirections,
367 const cellLooper& cellWalker,
368 undoableMeshCutter& cutter,
373 refinementIterator refiner(
mesh, cutter, cellWalker, writeMesh);
375 forAll(cellDirections, dirI)
379 Pout<<
"multiDirRefinement : Refining " << cellLabels_.size()
380 <<
" cells in direction " << dirI <<
endl 384 const vectorField& dirField = cellDirections[dirI];
389 List<refineCell> refCells(cellLabels_.size());
391 if (dirField.size() == 1)
396 Pout<<
"multiDirRefinement : Uniform refinement:" 397 << dirField[0] <<
endl;
402 const label celli = cellLabels_[refI];
404 refCells[refI] = refineCell(celli, dirField[0]);
412 const label celli = cellLabels_[refI];
414 refCells[refI] = refineCell(celli, dirField[celli]);
419 Map<label> splitMap = refiner.setRefinement(refCells);
422 addCells(
mesh, splitMap);
425 addCells(splitMap, cellLabels_);
428 if (dirField.size() != 1)
432 update(splitMap, cellDirections[i]);
438 Pout<<
"multiDirRefinement : Done refining direction " << dirI
439 <<
" resulting in " << cellLabels_.size() <<
" cells" <<
nl 446 void Foam::multiDirRefinement::refineFromDict
449 List<vectorField>& cellDirections,
450 const dictionary&
dict,
455 const bool pureGeomCut(
dict.
get<
bool>(
"geometricCut"));
457 autoPtr<cellLooper> cellWalker;
460 cellWalker.reset(
new geomCellLooper(
mesh));
464 cellWalker.reset(
new hexCellLooper(
mesh));
471 undoableMeshCutter cutter(
mesh,
false);
473 refineAllDirs(
mesh, cellDirections, cellWalker(), cutter, writeMesh);
481 Foam::multiDirRefinement::multiDirRefinement
488 cellLabels_(cellLabels),
489 addedCells_(
mesh.nCells())
491 const bool useHex(
dict.get<
bool>(
"useHexTopology"));
493 const bool writeMesh(
dict.get<
bool>(
"writeMesh"));
497 if (useHex && dirNames.
size() == 3)
502 refineHex8(
mesh, hexCells, writeMesh);
513 refineFromDict(
mesh, cellDirections,
dict, writeMesh);
519 Foam::multiDirRefinement::multiDirRefinement
523 const List<vectorField>& cellDirs,
524 const dictionary&
dict 527 cellLabels_(cellLabels),
528 addedCells_(
mesh.nCells())
530 const bool useHex(
dict.get<
bool>(
"useHexTopology"));
532 const bool writeMesh(
dict.get<
bool>(
"writeMesh"));
536 if (useHex && dirNames.size() == 3)
541 refineHex8(
mesh, hexCells, writeMesh);
549 List<vectorField> cellDirections(cellDirs);
551 refineFromDict(
mesh, cellDirections,
dict, writeMesh);
557 Foam::multiDirRefinement::multiDirRefinement
560 undoableMeshCutter& cutter,
561 const cellLooper& cellWalker,
564 const List<vectorField>& cellDirs,
568 cellLabels_(cellLabels),
569 addedCells_(
mesh.nCells())
572 List<vectorField> cellDirections(cellDirs);
574 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)
label find(const T &val) const
Find index of the first occurrence of the value.
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 a time name for the given scalar time value 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)