28 #include "surfaceInterpolate.H" 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())
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];
298 <<
"Problem: should not have removed faces" 302 else if (masterFacei != facei)
304 masterFaces.insert(masterFacei);
310 Pout<<
"Found " << masterFaces.size() <<
" split faces " <<
endl;
315 lookupClass<surfaceScalarField>()
319 if (!correctFluxes_.found(iter.key()))
322 <<
"Cannot find surfaceScalarField " << iter.key()
323 <<
" in user-provided flux mapping table " 324 << correctFluxes_ <<
endl 325 <<
" The flux mapping table is used to recreate the" 326 <<
" flux on newly created faces." <<
endl 327 <<
" Either add the entry if it is a flux or use (" 328 << iter.key() <<
" none) to suppress this warning." 333 const word& UName = correctFluxes_[iter.key()];
342 Pout<<
"Setting surfaceScalarField " << iter.key()
343 <<
" to NaN" <<
endl;
354 Pout<<
"Mapping flux " << iter.key()
355 <<
" using interpolated flux " << UName
364 lookupObject<volVectorField>(UName)
370 for (
label facei = 0; facei < nInternalFaces(); facei++)
372 label oldFacei = faceMap[facei];
377 phi[facei] = phiU[facei];
379 else if (reverseFaceMap[oldFacei] != facei)
382 phi[facei] = phiU[facei];
387 surfaceScalarField::Boundary& phiBf =
399 label oldFacei = faceMap[facei];
404 patchPhi[i] = patchPhiU[i];
406 else if (reverseFaceMap[oldFacei] != facei)
409 patchPhi[i] = patchPhiU[i];
419 label facei = iter.key();
421 if (isInternalFace(facei))
423 phi[facei] = phiU[facei];
435 patchPhi[i] = patchPhiU[i];
444 meshCutter_.updateMesh(map);
447 if (protectedCell_.size())
451 forAll(newProtectedCell, celli)
453 label oldCelli = map().cellMap()[celli];
454 newProtectedCell.
set(celli, protectedCell_.get(oldCelli));
456 protectedCell_.transfer(newProtectedCell);
460 meshCutter_.checkRefinementLevels(-1,
labelList(0));
477 meshCutter_.setUnrefinement(splitPoints, meshMod);
491 label pointi = splitPoints[i];
493 const labelList& pEdges = pointEdges()[pointi];
497 label otherPointi = edges()[pEdges[j]].otherVertex(pointi);
503 faceToSplitPoint.insert(pFaces[pFacei], otherPointi);
514 Info<<
"Unrefined from " 516 <<
" to " << globalData().nTotalCells() <<
" cells." 539 const labelList& reversePointMap = map().reversePointMap();
540 const labelList& reverseFaceMap = map().reverseFaceMap();
544 lookupClass<surfaceScalarField>()
548 if (!correctFluxes_.found(iter.key()))
551 <<
"Cannot find surfaceScalarField " << iter.key()
552 <<
" in user-provided flux mapping table " 553 << correctFluxes_ <<
endl 554 <<
" The flux mapping table is used to recreate the" 555 <<
" flux on newly created faces." <<
endl 556 <<
" Either add the entry if it is a flux or use (" 557 << iter.key() <<
" none) to suppress this warning." 562 const word& UName = correctFluxes_[iter.key()];
571 Info<<
"Mapping flux " << iter.key()
572 <<
" using interpolated flux " << UName
577 surfaceScalarField::Boundary& phiBf =
584 lookupObject<volVectorField>(UName)
592 label oldFacei = iter.key();
593 label oldPointi = iter();
595 if (reversePointMap[oldPointi] < 0)
598 label facei = reverseFaceMap[oldFacei];
602 if (isInternalFace(facei))
604 phi[facei] = phiU[facei];
614 patchPhi[i] = patchPhiU[i];
624 meshCutter_.updateMesh(map);
627 if (protectedCell_.size())
631 forAll(newProtectedCell, celli)
633 label oldCelli = map().cellMap()[celli];
636 newProtectedCell.
set(celli, protectedCell_.get(oldCelli));
639 protectedCell_.transfer(newProtectedCell);
643 meshCutter_.checkRefinementLevels(-1,
labelList(0));
655 forAll(pointCells(), pointi)
657 const labelList& pCells = pointCells()[pointi];
661 vFld[pCells[i]] =
max(vFld[pCells[i]], pFld[pointi]);
674 forAll(pointCells(), pointi)
676 const labelList& pCells = pointCells()[pointi];
680 pFld[pointi] =
max(pFld[pointi], vFld[pCells[i]]);
693 forAll(pointCells(), pointi)
695 const labelList& pCells = pointCells()[pointi];
700 sum += vFld[pCells[i]];
702 pFld[pointi] = sum/pCells.
size();
712 const scalar minLevel,
713 const scalar maxLevel
720 scalar err =
min(fld[i]-minLevel, maxLevel-fld[i]);
733 const scalar lowerRefineLevel,
734 const scalar upperRefineLevel,
757 if (cellError[celli] > 0)
759 candidateCell.
set(celli, 1);
767 const label maxCells,
768 const label maxRefinement,
773 label nTotToRefine = (maxCells - globalData().nTotalCells()) / 7;
775 const labelList& cellLevel = meshCutter_.cellLevel();
780 calculateProtectedCells(unrefineableCell);
783 label nLocalCandidates = count(candidateCell, 1);
789 if (nCandidates < nTotToRefine)
791 forAll(candidateCell, celli)
795 cellLevel[celli] < maxRefinement
796 && candidateCell.
get(celli)
798 unrefineableCell.
empty()
799 || !unrefineableCell.
get(celli)
810 for (
label level = 0; level < maxRefinement; level++)
812 forAll(candidateCell, celli)
816 cellLevel[celli] == level
817 && candidateCell.
get(celli)
819 unrefineableCell.
empty()
820 || !unrefineableCell.
get(celli)
838 meshCutter_.consistentRefinement
846 <<
" cells for refinement out of " << globalData().nTotalCells()
849 return consistentSet;
855 const scalar unrefineLevel,
861 const labelList splitPoints(meshCutter_.getSplitPoints());
867 label pointi = splitPoints[i];
869 if (pFld[pointi] < unrefineLevel)
872 const labelList& pCells = pointCells()[pointi];
874 bool hasMarked =
false;
878 if (markedCell.
get(pCells[pCelli]))
887 newSplitPoints.append(pointi);
893 newSplitPoints.shrink();
898 meshCutter_.consistentUnrefinement
905 <<
" split points out of a possible " 909 return consistentSet;
919 boolList markedFace(nFaces(),
false);
923 if (markedCell.
get(celli))
929 markedFace[cFaces[i]] =
true;
937 for (
label facei = 0; facei < nInternalFaces(); facei++)
939 if (markedFace[facei])
941 markedCell.
set(faceOwner()[facei], 1);
942 markedCell.
set(faceNeighbour()[facei], 1);
945 for (
label facei = nInternalFaces(); facei < nFaces(); facei++)
947 if (markedFace[facei])
949 markedCell.
set(faceOwner()[facei], 1);
961 const labelList& cellLevel = meshCutter_.cellLevel();
962 const labelList& pointLevel = meshCutter_.pointLevel();
966 forAll(pointLevel, pointi)
968 const labelList& pCells = pointCells(pointi);
972 label celli = pCells[pCelli];
974 if (pointLevel[pointi] <= cellLevel[celli])
977 if (nAnchorPoints[celli] == 8)
979 if (protectedCell.
set(celli,
true))
985 if (!protectedCell[celli])
987 nAnchorPoints[celli]++;
994 forAll(protectedCell, celli)
996 if (!protectedCell[celli] && nAnchorPoints[celli] != 8)
998 protectedCell.
set(celli,
true);
1007 Foam::dynamicRefineFvMesh::dynamicRefineFvMesh(
const IOobject& io)
1012 nRefinementIterations_(0),
1013 protectedCell_(nCells(), 0)
1032 label nProtected = 0;
1040 label celli = pCells[i];
1044 if (pointLevel[pointi] <= cellLevel[celli])
1048 if (nAnchors[celli] > 8)
1073 neiLevel[facei] = cellLevel[
faceOwner()[facei]];
1094 if (pointLevel[f[fp]] <= faceLevel)
1100 protectedFace[facei] =
true;
1111 if (protectedFace[facei])
1121 if (protectedFace[facei])
1133 if (cFaces.
size() < 6)
1167 cellSet protectedCells(*
this,
"protectedCells", nProtected);
1172 protectedCells.
insert(celli);
1177 <<
" cells that are protected from refinement." 1178 <<
" Writing these to cellSet " 1179 << protectedCells.
name()
1182 protectedCells.
write();
1213 ).
subDict(typeName +
"Coeffs")
1218 bool hasChanged =
false;
1220 if (refineInterval == 0)
1226 else if (refineInterval < 0)
1229 <<
"Illegal refineInterval " << refineInterval <<
nl 1230 <<
"The refineInterval setting in the dynamicMeshDict should" 1231 <<
" be >= 1." <<
nl 1248 <<
"Illegal maximum number of cells " << maxCells <<
nl 1249 <<
"The maxCells setting in the dynamicMeshDict should" 1256 if (maxRefinement <= 0)
1259 <<
"Illegal maximum refinement level " << maxRefinement <<
nl 1260 <<
"The maxCells setting in the dynamicMeshDict should" 1265 const word fieldName(refineDict.
lookup(
"field"));
1267 const volScalarField& vFld = lookupObject<volScalarField>(fieldName);
1269 const scalar lowerRefineLevel =
1271 const scalar upperRefineLevel =
1278 const label nBufferLayers =
1312 if (nCellsToRefine > 0)
1320 const labelList& cellMap = map().cellMap();
1321 const labelList& reverseCellMap = map().reverseCellMap();
1327 label oldCelli = cellMap[celli];
1331 newRefineCell.set(celli, 1);
1333 else if (reverseCellMap[oldCelli] != celli)
1335 newRefineCell.set(celli, 1);
1339 newRefineCell.set(celli, refineCell.get(oldCelli));
1342 refineCell.
transfer(newRefineCell);
1347 for (
label i = 0; i < nBufferLayers; i++)
1371 pointsToUnrefine.
size(),
1375 if (nSplitPoints > 0)
1443 scalarCellLevel[celli] = cellLevel[celli];
1446 writeOk = writeOk && scalarCellLevel.
write();
const refinementHistory & history() const
virtual bool writeObjects(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write the underlying polyMesh and other data.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
virtual labelList selectUnrefinePoints(const scalar unrefineLevel, const PackedBoolList &markedCell, const scalarField &pFld) const
Select points that can be unrefined.
static label count(const PackedBoolList &, const unsigned int)
Count set/unset elements in packedlist.
errorManipArg< error, int > exit(error &err, const int errNo=1)
PackedBoolList protectedCell_
Protected cells (usually since not hexes)
A face is a list of labels corresponding to mesh vertices.
A list of keyword definitions, which are a keyword followed by any number of values (e...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual labelList selectRefineCells(const label maxCells, const label maxRefinement, const PackedBoolList &candidateCell) const
Subset candidate cells for refinement.
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
void size(const label)
Override size to be inconsistent with allocated storage.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
Ostream & endl(Ostream &os)
Add newline and flush stream.
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.
scalarField maxPointField(const scalarField &) const
Get per cell max of connected point.
const labelIOList & cellLevel() const
label size() const
Return number of elements in table.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
void resize(const label)
Alias for setSize(const label)
bool insert(const Key &key)
Insert a new entry.
const cellList & cells() const
Macros for easy insertion into run-time selection tables.
void calculateProtectedCells(PackedBoolList &unrefineableCell) const
Calculate cells that cannot be refined since would trigger.
void extendMarkedCells(PackedBoolList &markedCell) const
Extend markedCell with cell-face-cell.
bool moving() const
Is mesh moving.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
bool write() const
Force writing refinement+history to polyMesh directory.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
bool empty() const
Return true if the list is empty (ie, size() is zero).
virtual bool update()
Update the mesh for both mesh motion and topology change.
const labelListList & pointCells() const
void set(const PackedList< 1 > &)
Set specified bits.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
autoPtr< mapPolyMesh > unrefine(const labelList &)
Unrefine cells. Gets passed in centre points of cells to combine.
Refinement of (split) hexes using polyTopoChange.
A class for handling words, derived from string.
hexRef8 meshCutter_
Mesh cutting engine.
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]
streamFormat
Enumeration for the format of data in the stream.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
autoPtr< mapPolyMesh > refine(const labelList &)
Refine cells. Update mesh and fields.
List< label > labelList
A List of labels.
scalarField maxCellField(const volScalarField &) const
Get point max of connected cell.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
static void fillNan(UList< scalar > &)
Fill block of data with NaN.
Container with cells to refine. Refinement given as single direction.
An STL-conforming hash table.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
void clear()
Clear the list, i.e. set addressable size to zero.
label readLabel(Istream &is)
void checkEightAnchorPoints(PackedBoolList &protectedCell, label &nProtected) const
Check all cells have 8 anchor points.
const globalMeshData & globalData() const
Return parallel info.
compressionType
Enumeration for the format of data in the stream.
prefixOSstream Pout(cout,"Pout")
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
scalarField cellToPoint(const scalarField &vFld) const
defineTypeNameAndDebug(combustionModel, 0)
A topoSetSource to select points based on usage in cells.
const fvPatch & patch() const
Return patch.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
const labelIOList & pointLevel() const
label nRefinementIterations_
Number of refinement/unrefinement steps done so far.
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
void setInstance(const fileName &)
Set the instance for mesh files.
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write using given format, version and compression.
void readDict()
Read the projection parameters from dictionary.
bool topoChanging() const
Is mesh topology changing.
virtual const labelList & faceNeighbour() const
Return face neighbour.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
Constant dispersed-phase particle diameter model.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Abstract base class for geometry and/or topology changing fvMesh.
A cell is defined as a list of faces with extra functionality.
A collection of cell labels.
Direct mesh changes based on v1.3 polyTopoChange syntax.
const dimensionedScalar c
Speed of light in a vacuum.
scalarField error(const scalarField &fld, const scalar minLevel, const scalar maxLevel) const
virtual bool write() const
Write using setting from DB.
virtual ~dynamicRefineFvMesh()
Destructor.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
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.
All refinement history. Used in unrefinement.
virtual const labelList & faceOwner() const
Return face owner.
virtual void selectRefineCandidates(const scalar lowerRefineLevel, const scalar upperRefineLevel, const scalarField &vFld, PackedBoolList &candidateCell) const
Select candidate cells for refinement.
virtual const faceList & faces() const
Return raw faces.
label start() const
Return start label of this patch in the polyMesh face list.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
label nInternalFaces() const
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
const hexRef8 & meshCutter() const
Direct access to the refinement engine.
const word & name() const
Return name.
Switch dumpLevel_
Dump cellLevel for postprocessing.
const Time & time() const
Return the top-level database.
unsigned int get(const label) const
Get value at index I.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.