52 const unsigned int val
80 if (protectedCell_.empty())
82 unrefineableCell.
clear();
86 const labelList& cellLevel = meshCutter_.cellLevel();
88 unrefineableCell = protectedCell_;
91 labelList neiLevel(nFaces()-nInternalFaces());
93 for (
label faceI = nInternalFaces(); faceI < nFaces(); faceI++)
95 neiLevel[faceI-nInternalFaces()] = cellLevel[faceOwner()[faceI]];
105 forAll(faceNeighbour(), faceI)
107 label own = faceOwner()[faceI];
108 bool ownProtected = unrefineableCell.
get(own);
109 label nei = faceNeighbour()[faceI];
110 bool neiProtected = unrefineableCell.
get(nei);
112 if (ownProtected && (cellLevel[nei] > cellLevel[own]))
114 seedFace[faceI] =
true;
116 else if (neiProtected && (cellLevel[own] > cellLevel[nei]))
118 seedFace[faceI] =
true;
121 for (
label faceI = nInternalFaces(); faceI < nFaces(); faceI++)
123 label own = faceOwner()[faceI];
124 bool ownProtected = unrefineableCell.
get(own);
128 && (neiLevel[faceI-nInternalFaces()] > cellLevel[own])
131 seedFace[faceI] =
true;
139 bool hasExtended =
false;
141 for (
label faceI = 0; faceI < nInternalFaces(); faceI++)
145 label own = faceOwner()[faceI];
146 if (unrefineableCell.
get(own) == 0)
148 unrefineableCell.
set(own, 1);
152 label nei = faceNeighbour()[faceI];
153 if (unrefineableCell.
get(nei) == 0)
155 unrefineableCell.
set(nei, 1);
160 for (
label faceI = nInternalFaces(); faceI < nFaces(); faceI++)
164 label own = faceOwner()[faceI];
165 if (unrefineableCell.
get(own) == 0)
167 unrefineableCell.
set(own, 1);
196 ).subDict(typeName +
"Coeffs")
201 refineDict.
lookup(
"correctFluxes")
207 correctFluxes_.insert(fluxVelocities[i][0], fluxVelocities[i][1]);
225 meshCutter_.setRefinement(cellsToRefine, meshMod);
231 Info<<
"Refined from " 233 <<
" to " << globalData().nTotalCells() <<
" cells." <<
endl;
238 for (
label faceI = 0; faceI < nInternalFaces(); faceI++)
240 label oldFaceI = map().faceMap()[faceI];
242 if (oldFaceI >= nInternalFaces())
244 FatalErrorIn(
"dynamicRefineFvMesh::refine(const labelList&)")
245 <<
"New internal face:" << faceI
246 <<
" fc:" << faceCentres()[faceI]
247 <<
" originates from boundary oldFace:" << oldFaceI
280 const labelList& reverseFaceMap = map().reverseFaceMap();
289 label oldFaceI = faceMap[faceI];
293 label masterFaceI = reverseFaceMap[oldFaceI];
299 "dynamicRefineFvMesh::refine(const labelList&)" 300 ) <<
"Problem: should not have removed faces" 304 else if (masterFaceI != faceI)
306 masterFaces.insert(masterFaceI);
312 Pout<<
"Found " << masterFaces.size() <<
" split faces " <<
endl;
317 lookupClass<surfaceScalarField>()
321 if (!correctFluxes_.found(iter.key()))
323 WarningIn(
"dynamicRefineFvMesh::refine(const labelList&)")
324 <<
"Cannot find surfaceScalarField " << iter.key()
325 <<
" in user-provided flux mapping table " 326 << correctFluxes_ <<
endl 327 <<
" The flux mapping table is used to recreate the" 328 <<
" flux on newly created faces." <<
endl 329 <<
" Either add the entry if it is a flux or use (" 330 << iter.key() <<
" none) to suppress this warning." 335 const word& UName = correctFluxes_[iter.key()];
344 Pout<<
"Setting surfaceScalarField " << iter.key()
345 <<
" to NaN" <<
endl;
356 Pout<<
"Mapping flux " << iter.key()
357 <<
" using interpolated flux " << UName
366 lookupObject<volVectorField>(UName)
372 for (
label faceI = 0; faceI < nInternalFaces(); faceI++)
374 label oldFaceI = faceMap[faceI];
379 phi[faceI] = phiU[faceI];
381 else if (reverseFaceMap[oldFaceI] != faceI)
384 phi[faceI] = phiU[faceI];
389 surfaceScalarField::GeometricBoundaryField& bphi =
401 label oldFaceI = faceMap[faceI];
406 patchPhi[i] = patchPhiU[i];
408 else if (reverseFaceMap[oldFaceI] != faceI)
411 patchPhi[i] = patchPhiU[i];
421 label faceI = iter.key();
423 if (isInternalFace(faceI))
425 phi[faceI] = phiU[faceI];
437 patchPhi[i] = patchPhiU[i];
446 meshCutter_.updateMesh(map);
449 if (protectedCell_.size())
453 forAll(newProtectedCell, cellI)
455 label oldCellI = map().cellMap()[cellI];
456 newProtectedCell.
set(cellI, protectedCell_.get(oldCellI));
458 protectedCell_.transfer(newProtectedCell);
462 meshCutter_.checkRefinementLevels(-1,
labelList(0));
479 meshCutter_.setUnrefinement(splitPoints, meshMod);
493 label pointI = splitPoints[i];
495 const labelList& pEdges = pointEdges()[pointI];
499 label otherPointI = edges()[pEdges[j]].otherVertex(pointI);
505 faceToSplitPoint.insert(pFaces[pFaceI], otherPointI);
516 Info<<
"Unrefined from " 518 <<
" to " << globalData().nTotalCells() <<
" cells." 541 const labelList& reversePointMap = map().reversePointMap();
542 const labelList& reverseFaceMap = map().reverseFaceMap();
546 lookupClass<surfaceScalarField>()
550 if (!correctFluxes_.found(iter.key()))
552 WarningIn(
"dynamicRefineFvMesh::refine(const labelList&)")
553 <<
"Cannot find surfaceScalarField " << iter.key()
554 <<
" in user-provided flux mapping table " 555 << correctFluxes_ <<
endl 556 <<
" The flux mapping table is used to recreate the" 557 <<
" flux on newly created faces." <<
endl 558 <<
" Either add the entry if it is a flux or use (" 559 << iter.key() <<
" none) to suppress this warning." 564 const word& UName = correctFluxes_[iter.key()];
573 Info<<
"Mapping flux " << iter.key()
574 <<
" using interpolated flux " << UName
579 surfaceScalarField::GeometricBoundaryField& bphi =
586 lookupObject<volVectorField>(UName)
594 label oldFaceI = iter.key();
595 label oldPointI = iter();
597 if (reversePointMap[oldPointI] < 0)
600 label faceI = reverseFaceMap[oldFaceI];
604 if (isInternalFace(faceI))
606 phi[faceI] = phiU[faceI];
616 patchPhi[i] = patchPhiU[i];
626 meshCutter_.updateMesh(map);
629 if (protectedCell_.size())
633 forAll(newProtectedCell, cellI)
635 label oldCellI = map().cellMap()[cellI];
638 newProtectedCell.
set(cellI, protectedCell_.get(oldCellI));
641 protectedCell_.transfer(newProtectedCell);
645 meshCutter_.checkRefinementLevels(-1,
labelList(0));
657 forAll(pointCells(), pointI)
659 const labelList& pCells = pointCells()[pointI];
663 vFld[pCells[i]] =
max(vFld[pCells[i]], pFld[pointI]);
676 forAll(pointCells(), pointI)
678 const labelList& pCells = pointCells()[pointI];
682 pFld[pointI] =
max(pFld[pointI], vFld[pCells[i]]);
695 forAll(pointCells(), pointI)
697 const labelList& pCells = pointCells()[pointI];
702 sum += vFld[pCells[i]];
704 pFld[pointI] = sum/pCells.
size();
714 const scalar minLevel,
715 const scalar maxLevel
722 scalar err =
min(fld[i]-minLevel, maxLevel-fld[i]);
735 const scalar lowerRefineLevel,
736 const scalar upperRefineLevel,
759 if (cellError[cellI] > 0)
761 candidateCell.
set(cellI, 1);
769 const label maxCells,
770 const label maxRefinement,
775 label nTotToRefine = (maxCells - globalData().nTotalCells()) / 7;
777 const labelList& cellLevel = meshCutter_.cellLevel();
782 calculateProtectedCells(unrefineableCell);
785 label nLocalCandidates = count(candidateCell, 1);
791 if (nCandidates < nTotToRefine)
793 forAll(candidateCell, cellI)
797 cellLevel[cellI] < maxRefinement
798 && candidateCell.
get(cellI)
800 unrefineableCell.
empty()
801 || !unrefineableCell.
get(cellI)
812 for (
label level = 0; level < maxRefinement; level++)
814 forAll(candidateCell, cellI)
818 cellLevel[cellI] == level
819 && candidateCell.
get(cellI)
821 unrefineableCell.
empty()
822 || !unrefineableCell.
get(cellI)
840 meshCutter_.consistentRefinement
848 <<
" cells for refinement out of " << globalData().nTotalCells()
851 return consistentSet;
857 const scalar unrefineLevel,
863 const labelList splitPoints(meshCutter_.getSplitPoints());
869 label pointI = splitPoints[i];
871 if (pFld[pointI] < unrefineLevel)
874 const labelList& pCells = pointCells()[pointI];
876 bool hasMarked =
false;
880 if (markedCell.
get(pCells[pCellI]))
889 newSplitPoints.append(pointI);
895 newSplitPoints.shrink();
900 meshCutter_.consistentUnrefinement
907 <<
" split points out of a possible " 911 return consistentSet;
921 boolList markedFace(nFaces(),
false);
925 if (markedCell.
get(cellI))
931 markedFace[cFaces[i]] =
true;
939 for (
label faceI = 0; faceI < nInternalFaces(); faceI++)
941 if (markedFace[faceI])
943 markedCell.
set(faceOwner()[faceI], 1);
944 markedCell.
set(faceNeighbour()[faceI], 1);
947 for (
label faceI = nInternalFaces(); faceI < nFaces(); faceI++)
949 if (markedFace[faceI])
951 markedCell.
set(faceOwner()[faceI], 1);
963 const labelList& cellLevel = meshCutter_.cellLevel();
964 const labelList& pointLevel = meshCutter_.pointLevel();
968 forAll(pointLevel, pointI)
970 const labelList& pCells = pointCells(pointI);
974 label cellI = pCells[pCellI];
976 if (pointLevel[pointI] <= cellLevel[cellI])
979 if (nAnchorPoints[cellI] == 8)
981 if (protectedCell.
set(cellI,
true))
987 if (!protectedCell[cellI])
989 nAnchorPoints[cellI]++;
996 forAll(protectedCell, cellI)
998 if (!protectedCell[cellI] && nAnchorPoints[cellI] != 8)
1000 protectedCell.
set(cellI,
true);
1009 Foam::dynamicRefineFvMesh::dynamicRefineFvMesh(
const IOobject& io)
1014 nRefinementIterations_(0),
1015 protectedCell_(nCells(), 0)
1034 label nProtected = 0;
1042 label cellI = pCells[i];
1046 if (pointLevel[pointI] <= cellLevel[cellI])
1050 if (nAnchors[cellI] > 8)
1075 neiLevel[faceI] = cellLevel[
faceOwner()[faceI]];
1096 if (pointLevel[f[fp]] <= faceLevel)
1102 protectedFace[faceI] =
true;
1113 if (protectedFace[faceI])
1123 if (protectedFace[faceI])
1135 if (cFaces.
size() < 6)
1169 cellSet protectedCells(*
this,
"protectedCells", nProtected);
1174 protectedCells.
insert(cellI);
1179 <<
" cells that are protected from refinement." 1180 <<
" Writing these to cellSet " 1181 << protectedCells.
name()
1184 protectedCells.
write();
1215 ).
subDict(typeName +
"Coeffs")
1220 bool hasChanged =
false;
1222 if (refineInterval == 0)
1228 else if (refineInterval < 0)
1231 <<
"Illegal refineInterval " << refineInterval <<
nl 1232 <<
"The refineInterval setting in the dynamicMeshDict should" 1233 <<
" be >= 1." <<
nl 1250 <<
"Illegal maximum number of cells " << maxCells <<
nl 1251 <<
"The maxCells setting in the dynamicMeshDict should" 1258 if (maxRefinement <= 0)
1261 <<
"Illegal maximum refinement level " << maxRefinement <<
nl 1262 <<
"The maxCells setting in the dynamicMeshDict should" 1267 const word fieldName(refineDict.
lookup(
"field"));
1269 const volScalarField& vFld = lookupObject<volScalarField>(fieldName);
1271 const scalar lowerRefineLevel =
1273 const scalar upperRefineLevel =
1280 const label nBufferLayers =
1314 if (nCellsToRefine > 0)
1322 const labelList& cellMap = map().cellMap();
1323 const labelList& reverseCellMap = map().reverseCellMap();
1329 label oldCellI = cellMap[cellI];
1333 newRefineCell.set(cellI, 1);
1335 else if (reverseCellMap[oldCellI] != cellI)
1337 newRefineCell.set(cellI, 1);
1341 newRefineCell.set(cellI, refineCell.get(oldCellI));
1344 refineCell.
transfer(newRefineCell);
1349 for (
label i = 0; i < nBufferLayers; i++)
1373 pointsToUnrefine.
size(),
1377 if (nSplitPoints > 0)
1445 scalarCellLevel[cellI] = cellLevel[cellI];
1448 writeOk = writeOk && scalarCellLevel.
write();
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &vf, const surfaceScalarField &faceFlux, Istream &schemeData)
Container with cells to refine. Refinement given as single direction.
const refinementHistory & history() const
PackedBoolList protectedCell_
Protected cells (usually since not hexes)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
virtual bool writeObjects(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write the underlying polyMesh and other data.
autoPtr< mapPolyMesh > refine(const labelList &)
Refine cells. Update mesh and fields.
void setInstance(const fileName &)
Set the instance for mesh files.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
A cell is defined as a list of faces with extra functionality.
scalarField maxCellField(const volScalarField &) const
Get point max of connected cell.
const fvPatch & patch() const
Return patch.
void extendMarkedCells(PackedBoolList &markedCell) const
Extend markedCell with cell-face-cell.
An STL-conforming hash table.
void set(const PackedList< 1 > &)
Set specified bits.
#define forAllIter(Container, container, iter)
A collection of cell labels.
A class for handling words, derived from string.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
label nRefinementIterations_
Number of refinement/unrefinement steps done so far.
bool topoChanging() const
Is mesh topology changing.
void size(const label)
Override size to be inconsistent with allocated storage.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
errorManipArg< error, int > exit(error &err, const int errNo=1)
InternalField & internalField()
Return internal field.
const cellList & cells() const
Refinement of (split) hexes using polyTopoChange.
const labelListList & pointCells() const
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
All refinement history. Used in unrefinement.
A list of keyword definitions, which are a keyword followed by any number of values (e...
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
virtual void selectRefineCandidates(const scalar lowerRefineLevel, const scalar upperRefineLevel, const scalarField &vFld, PackedBoolList &candidateCell) const
Select candidate cells for refinement.
static void syncFaceList(const polyMesh &mesh, UList< T > &l, const CombineOp &cop)
Synchronize values on all mesh faces.
label readLabel(Istream &is)
const Time & time() const
Return the top-level database.
void calculateProtectedCells(PackedBoolList &unrefineableCell) const
Calculate cells that cannot be refined since would trigger.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
virtual bool write() const
Write using setting from DB.
const hexRef8 & meshCutter() const
Direct access to the refinement engine.
A face is a list of labels corresponding to mesh vertices.
scalarField cellToPoint(const scalarField &vFld) const
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write using given format, version and compression.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const labelIOList & cellLevel() const
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
#define WarningIn(functionName)
Report a warning using Foam::Warning.
const labelIOList & pointLevel() const
bool write() const
Force writing refinement+history to polyMesh directory.
streamFormat
Enumeration for the format of data in the stream.
Switch dumpLevel_
Dump cellLevel for postprocessing.
static label count(const PackedBoolList &, const unsigned int)
Count set/unset elements in packedlist.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
static void fillNan(UList< scalar > &)
Fill block of data with NaN.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Macros for easy insertion into run-time selection tables.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
label size() const
Return number of elements in table.
void readDict()
Read the projection parameters from dictionary.
errorManip< error > abort(error &err)
const word & name() const
Return name.
virtual const labelList & faceOwner() const
Return face owner.
virtual labelList selectRefineCells(const label maxCells, const label maxRefinement, const PackedBoolList &candidateCell) const
Subset candidate cells for refinement.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
compressionType
Enumeration for the format of data in the stream.
const cellShapeList & cells
label nInternalFaces() const
virtual ~dynamicRefineFvMesh()
Destructor.
A topoSetSource to select points based on usage in cells.
void resize(const label)
Alias for setSize(const label)
hexRef8 meshCutter_
Mesh cutting engine.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
void clear()
Clear the list, i.e. set addressable size to zero.
Constant dispersed-phase particle diameter model.
scalarField maxPointField(const scalarField &) const
Get per cell max of connected point.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
List< label > labelList
A List of labels.
const dimensionedScalar c
Speed of light in a vacuum.
Direct mesh changes based on v1.3 polyTopoChange syntax.
virtual bool update()
Update the mesh for both mesh motion and topology change.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
virtual const faceList & faces() const
Return raw faces.
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints,-1);const cellModel &hex=*(cellModeller::lookup("hex"));labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){pointMap[i]=i;}for(label i=0;i< nPoints;i++){if(f[i] > 0.0){hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells]=cellShape(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei){if(edges[ei].mag(points)< SMALL){label start=pointMap[edges[ei].start()];while(start!=pointMap[start]){start=pointMap[start];}label end=pointMap[edges[ei].end()];while(end!=pointMap[end]){end=pointMap[end];}label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;}}cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){cellShape &cs=cellShapes[celli];forAll(cs, i){cs[i]=pointMap[cs[i]];}cs.collapse();}label bcIDs[11]={-1, 0, 2, 4,-1, 5,-1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={&wallPolyPatch::typeName,&wallPolyPatch::typeName,&wallPolyPatch::typeName,&wallPolyPatch::typeName,&symmetryPolyPatch::typeName,&wedgePolyPatch::typeName,&polyPatch::typeName,&polyPatch::typeName,&polyPatch::typeName,&polyPatch::typeName,&symmetryPolyPatch::typeName,&oldCyclicPolyPatch::typeName};enum patchTypeNames{PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={"piston","valve","liner","cylinderHead","axis","wedge","inflow","outflow","presin","presout","symmetryPlane","cyclic"};List< SLList< face > > pFaces[nBCs]
Abstract base class for geometry and/or topology changing fvMesh.
scalarField error(const scalarField &fld, const scalar minLevel, const scalar maxLevel) const
void checkEightAnchorPoints(PackedBoolList &protectedCell, label &nProtected) const
Check all cells have 8 anchor points.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
virtual const labelList & faceNeighbour() const
Return face neighbour.
static void swapFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled face values.
autoPtr< mapPolyMesh > unrefine(const labelList &)
Unrefine cells. Gets passed in centre points of cells to combine.
bool empty() const
Return true if the list is empty (ie, size() is zero).
bool moving() const
Is mesh moving.
label start() const
Return start label of this patch in the polyMesh face list.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
virtual labelList selectUnrefinePoints(const scalar unrefineLevel, const PackedBoolList &markedCell, const scalarField &pFld) const
Select points that can be unrefined.
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
const globalMeshData & globalData() const
Return parallel info.
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout,"Pout")
unsigned int get(const label) const
Get value at index I.
bool insert(const Key &key)
Insert a new entry.