28 #include "surfaceInterpolate.H" 50 const unsigned int val
78 if (protectedCell_.empty())
80 unrefineableCell.
clear();
84 const labelList& cellLevel = meshCutter_.cellLevel();
86 unrefineableCell = protectedCell_;
89 labelList neiLevel(nFaces()-nInternalFaces());
91 for (
label facei = nInternalFaces(); facei < nFaces(); facei++)
93 neiLevel[facei-nInternalFaces()] = cellLevel[faceOwner()[facei]];
103 forAll(faceNeighbour(), facei)
105 label own = faceOwner()[facei];
106 bool ownProtected = unrefineableCell.
get(own);
107 label nei = faceNeighbour()[facei];
108 bool neiProtected = unrefineableCell.
get(nei);
110 if (ownProtected && (cellLevel[nei] > cellLevel[own]))
112 seedFace[facei] =
true;
114 else if (neiProtected && (cellLevel[own] > cellLevel[nei]))
116 seedFace[facei] =
true;
119 for (
label facei = nInternalFaces(); facei < nFaces(); facei++)
121 label own = faceOwner()[facei];
122 bool ownProtected = unrefineableCell.
get(own);
126 && (neiLevel[facei-nInternalFaces()] > cellLevel[own])
129 seedFace[facei] =
true;
137 bool hasExtended =
false;
139 for (
label facei = 0; facei < nInternalFaces(); facei++)
143 label own = faceOwner()[facei];
144 if (unrefineableCell.
get(own) == 0)
146 unrefineableCell.
set(own, 1);
150 label nei = faceNeighbour()[facei];
151 if (unrefineableCell.
get(nei) == 0)
153 unrefineableCell.
set(nei, 1);
158 for (
label facei = nInternalFaces(); facei < nFaces(); facei++)
162 label own = faceOwner()[facei];
163 if (unrefineableCell.
get(own) == 0)
165 unrefineableCell.
set(own, 1);
183 dynamicMeshDict().optionalSubDict(typeName +
"Coeffs")
188 refineDict.
lookup(
"correctFluxes")
194 correctFluxes_.insert(fluxVelocities[i][0], fluxVelocities[i][1]);
212 meshCutter_.setRefinement(cellsToRefine, meshMod);
218 Info<<
"Refined from " 220 <<
" to " << globalData().nTotalCells() <<
" cells." <<
endl;
225 for (
label facei = 0; facei < nInternalFaces(); facei++)
227 label oldFacei = map().faceMap()[facei];
229 if (oldFacei >= nInternalFaces())
232 <<
"New internal face:" << facei
233 <<
" fc:" << faceCentres()[facei]
234 <<
" originates from boundary oldFace:" << oldFacei
267 const labelList& reverseFaceMap = map().reverseFaceMap();
276 label oldFacei = faceMap[facei];
280 label masterFacei = reverseFaceMap[oldFacei];
285 <<
"Problem: should not have removed faces" 289 else if (masterFacei != facei)
291 masterFaces.insert(masterFacei);
297 Pout<<
"Found " << masterFaces.size() <<
" split faces " <<
endl;
302 lookupClass<surfaceScalarField>()
306 if (!correctFluxes_.found(iter.key()))
309 <<
"Cannot find surfaceScalarField " << iter.key()
310 <<
" in user-provided flux mapping table " 311 << correctFluxes_ <<
endl 312 <<
" The flux mapping table is used to recreate the" 313 <<
" flux on newly created faces." <<
endl 314 <<
" Either add the entry if it is a flux or use (" 315 << iter.key() <<
" none) to suppress this warning." 320 const word& UName = correctFluxes_[iter.key()];
329 Pout<<
"Setting surfaceScalarField " << iter.key()
330 <<
" to NaN" <<
endl;
341 Pout<<
"Mapping flux " << iter.key()
342 <<
" using interpolated flux " << UName
351 lookupObject<volVectorField>(UName)
357 for (
label facei = 0; facei < nInternalFaces(); facei++)
359 label oldFacei = faceMap[facei];
364 phi[facei] = phiU[facei];
366 else if (reverseFaceMap[oldFacei] != facei)
369 phi[facei] = phiU[facei];
374 surfaceScalarField::Boundary& phiBf =
386 label oldFacei = faceMap[facei];
391 patchPhi[i] = patchPhiU[i];
393 else if (reverseFaceMap[oldFacei] != facei)
396 patchPhi[i] = patchPhiU[i];
406 label facei = iter.key();
408 if (isInternalFace(facei))
410 phi[facei] = phiU[facei];
422 patchPhi[i] = patchPhiU[i];
431 meshCutter_.updateMesh(map);
434 if (protectedCell_.size())
438 forAll(newProtectedCell, celli)
440 label oldCelli = map().cellMap()[celli];
441 newProtectedCell.
set(celli, protectedCell_.get(oldCelli));
443 protectedCell_.transfer(newProtectedCell);
447 meshCutter_.checkRefinementLevels(-1,
labelList(0));
462 meshCutter_.setUnrefinement(splitPoints, meshMod);
476 label pointi = splitPoints[i];
478 const labelList& pEdges = pointEdges()[pointi];
482 label otherPointi = edges()[pEdges[j]].otherVertex(pointi);
488 faceToSplitPoint.insert(pFaces[pFacei], otherPointi);
499 Info<<
"Unrefined from " 501 <<
" to " << globalData().nTotalCells() <<
" cells." 524 const labelList& reversePointMap = map().reversePointMap();
525 const labelList& reverseFaceMap = map().reverseFaceMap();
529 lookupClass<surfaceScalarField>()
533 if (!correctFluxes_.found(iter.key()))
536 <<
"Cannot find surfaceScalarField " << iter.key()
537 <<
" in user-provided flux mapping table " 538 << correctFluxes_ <<
endl 539 <<
" The flux mapping table is used to recreate the" 540 <<
" flux on newly created faces." <<
endl 541 <<
" Either add the entry if it is a flux or use (" 542 << iter.key() <<
" none) to suppress this warning." 547 const word& UName = correctFluxes_[iter.key()];
556 Info<<
"Mapping flux " << iter.key()
557 <<
" using interpolated flux " << UName
562 surfaceScalarField::Boundary& phiBf =
569 lookupObject<volVectorField>(UName)
577 label oldFacei = iter.key();
578 label oldPointi = iter();
580 if (reversePointMap[oldPointi] < 0)
583 label facei = reverseFaceMap[oldFacei];
587 if (isInternalFace(facei))
589 phi[facei] = phiU[facei];
599 patchPhi[i] = patchPhiU[i];
609 meshCutter_.updateMesh(map);
612 if (protectedCell_.size())
616 forAll(newProtectedCell, celli)
618 label oldCelli = map().cellMap()[celli];
621 newProtectedCell.
set(celli, protectedCell_.get(oldCelli));
624 protectedCell_.transfer(newProtectedCell);
628 meshCutter_.checkRefinementLevels(-1,
labelList(0));
639 forAll(pointCells(), pointi)
641 const labelList& pCells = pointCells()[pointi];
645 vFld[pCells[i]] =
max(vFld[pCells[i]], pFld[pointi]);
657 forAll(pointCells(), pointi)
659 const labelList& pCells = pointCells()[pointi];
663 pFld[pointi] =
max(pFld[pointi], vFld[pCells[i]]);
675 forAll(pointCells(), pointi)
677 const labelList& pCells = pointCells()[pointi];
682 sum += vFld[pCells[i]];
684 pFld[pointi] = sum/pCells.
size();
693 const scalar minLevel,
694 const scalar maxLevel
701 scalar err =
min(fld[i]-minLevel, maxLevel-fld[i]);
714 const scalar lowerRefineLevel,
715 const scalar upperRefineLevel,
738 if (cellError[celli] > 0)
740 candidateCell.
set(celli, 1);
748 const label maxCells,
749 const label maxRefinement,
754 label nTotToRefine = (maxCells - globalData().nTotalCells()) / 7;
756 const labelList& cellLevel = meshCutter_.cellLevel();
761 calculateProtectedCells(unrefineableCell);
764 label nLocalCandidates = count(candidateCell, 1);
770 if (nCandidates < nTotToRefine)
772 forAll(candidateCell, celli)
776 cellLevel[celli] < maxRefinement
777 && candidateCell.
get(celli)
779 unrefineableCell.
empty()
780 || !unrefineableCell.
get(celli)
791 for (
label level = 0; level < maxRefinement; level++)
793 forAll(candidateCell, celli)
797 cellLevel[celli] == level
798 && candidateCell.
get(celli)
800 unrefineableCell.
empty()
801 || !unrefineableCell.
get(celli)
819 meshCutter_.consistentRefinement
827 <<
" cells for refinement out of " << globalData().nTotalCells()
830 return consistentSet;
836 const scalar unrefineLevel,
842 const labelList splitPoints(meshCutter_.getSplitPoints());
848 label pointi = splitPoints[i];
850 if (pFld[pointi] < unrefineLevel)
853 const labelList& pCells = pointCells()[pointi];
855 bool hasMarked =
false;
859 if (markedCell.
get(pCells[pCelli]))
868 newSplitPoints.append(pointi);
874 newSplitPoints.shrink();
879 meshCutter_.consistentUnrefinement
886 <<
" split points out of a possible " 890 return consistentSet;
900 boolList markedFace(nFaces(),
false);
904 if (markedCell.
get(celli))
910 markedFace[cFaces[i]] =
true;
918 for (
label facei = 0; facei < nInternalFaces(); facei++)
920 if (markedFace[facei])
922 markedCell.
set(faceOwner()[facei], 1);
923 markedCell.
set(faceNeighbour()[facei], 1);
926 for (
label facei = nInternalFaces(); facei < nFaces(); facei++)
928 if (markedFace[facei])
930 markedCell.
set(faceOwner()[facei], 1);
942 const labelList& cellLevel = meshCutter_.cellLevel();
943 const labelList& pointLevel = meshCutter_.pointLevel();
947 forAll(pointLevel, pointi)
949 const labelList& pCells = pointCells(pointi);
953 label celli = pCells[pCelli];
955 if (pointLevel[pointi] <= cellLevel[celli])
958 if (nAnchorPoints[celli] == 8)
960 if (protectedCell.
set(celli,
true))
966 if (!protectedCell[celli])
968 nAnchorPoints[celli]++;
975 forAll(protectedCell, celli)
977 if (!protectedCell[celli] && nAnchorPoints[celli] != 8)
979 protectedCell.
set(celli,
true);
993 nRefinementIterations_(0),
994 protectedCell_(nCells(), 0)
1013 label nProtected = 0;
1021 label celli = pCells[i];
1025 if (pointLevel[pointi] <= cellLevel[celli])
1029 if (nAnchors[celli] > 8)
1054 neiLevel[facei] = cellLevel[
faceOwner()[facei]];
1075 if (pointLevel[f[fp]] <= faceLevel)
1081 protectedFace[facei] =
true;
1092 if (protectedFace[facei])
1102 if (protectedFace[facei])
1114 if (cFaces.
size() < 6)
1148 cellSet protectedCells(*
this,
"protectedCells", nProtected);
1153 protectedCells.
insert(celli);
1158 <<
" cells that are protected from refinement." 1159 <<
" Writing these to cellSet " 1160 << protectedCells.
name()
1163 protectedCells.
write();
1188 bool hasChanged =
false;
1190 if (refineInterval == 0)
1196 else if (refineInterval < 0)
1199 <<
"Illegal refineInterval " << refineInterval <<
nl 1200 <<
"The refineInterval setting in the dynamicMeshDict should" 1201 <<
" be >= 1." <<
nl 1215 <<
"Illegal maximum number of cells " << maxCells <<
nl 1216 <<
"The maxCells setting in the dynamicMeshDict should" 1223 if (maxRefinement <= 0)
1226 <<
"Illegal maximum refinement level " << maxRefinement <<
nl 1227 <<
"The maxCells setting in the dynamicMeshDict should" 1232 const word fieldName(refineDict.
lookup(
"field"));
1234 const volScalarField& vFld = lookupObject<volScalarField>(fieldName);
1236 const scalar lowerRefineLevel =
1238 const scalar upperRefineLevel =
1245 const label nBufferLayers =
1279 if (nCellsToRefine > 0)
1287 const labelList& cellMap = map().cellMap();
1288 const labelList& reverseCellMap = map().reverseCellMap();
1294 label oldCelli = cellMap[celli];
1298 newRefineCell.set(celli, 1);
1300 else if (reverseCellMap[oldCelli] != celli)
1302 newRefineCell.set(celli, 1);
1306 newRefineCell.set(celli, refineCell.get(oldCelli));
1309 refineCell.
transfer(newRefineCell);
1314 for (
label i = 0; i < nBufferLayers; i++)
1338 pointsToUnrefine.
size(),
1342 if (nSplitPoints > 0)
1411 scalarCellLevel[celli] = cellLevel[celli];
1414 writeOk = writeOk && scalarCellLevel.
write();
const refinementHistory & history() const
#define forAll(list, i)
Loop across all elements in list.
virtual labelList selectRefineCells(const label maxCells, const label maxRefinement, const PackedBoolList &candidateCell) const
Subset candidate cells for refinement.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const word & name() const
Return name.
scalarField maxPointField(const scalarField &) const
Get per cell max of connected point.
static label count(const PackedBoolList &, const unsigned int)
Count set/unset elements in packedlist.
bool moving() const
Is mesh moving.
const hexRef8 & meshCutter() const
Direct access to the refinement engine.
errorManipArg< error, int > exit(error &err, const int errNo=1)
PackedBoolList protectedCell_
Protected cells (usually since not hexes)
unsigned int get(const label) const
Get value at index I.
A face is a list of labels corresponding to mesh vertices.
const labelIOList & pointLevel() const
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 label start() const
Return start label of this patch in the polyMesh face list.
label nInternalFaces() const
virtual const labelList & faceNeighbour() const
Return face neighbour.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
scalarField cellToPoint(const scalarField &vFld) const
#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.
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/any.
void checkEightAnchorPoints(PackedBoolList &protectedCell, label &nProtected) const
Check all cells have 8 anchor points.
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write using given format, version and compression.
const cellList & cells() const
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
const Time & time() const
Return the top-level database.
void resize(const label)
Alias for setSize(const label)
bool insert(const Key &key)
Insert a new entry.
void calculateProtectedCells(PackedBoolList &unrefineableCell) const
Calculate cells that cannot be refined since would trigger.
label size() const
Return number of elements in table.
Macros for easy insertion into run-time selection tables.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write the underlying polyMesh and other data.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Class to handle errors and exceptions in a simple, consistent stream-based manner.
virtual bool update()
Update the mesh for both mesh motion and topology change.
void set(const PackedList< 1 > &)
Set specified bits.
autoPtr< mapPolyMesh > unrefine(const labelList &)
Unrefine cells. Gets passed in centre points of cells to combine.
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Refinement of (split) hexes using polyTopoChange.
A class for handling words, derived from string.
hexRef8 meshCutter_
Mesh cutting engine.
void extendMarkedCells(PackedBoolList &markedCell) const
Extend markedCell with cell-face-cell.
bool write(const bool write=true) const
Force writing refinement+history to polyMesh directory.
virtual const labelList & faceOwner() const
Return face owner.
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.
const globalMeshData & globalData() const
Return parallel info.
List< label > labelList
A List of labels.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
virtual const faceList & faces() const
Return raw faces.
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)
const labelListList & pointCells() const
compressionType
Enumeration for the format of data in the stream.
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)
defineTypeNameAndDebug(combustionModel, 0)
A topoSetSource to select points based on usage in cells.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
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 void selectRefineCandidates(const scalar lowerRefineLevel, const scalar upperRefineLevel, const scalarField &vFld, PackedBoolList &candidateCell) const
Select candidate cells for refinement.
const fvPatch & patch() const
Return patch.
void readDict()
Read the projection parameters from dictionary.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define WarningInFunction
Report a warning using Foam::Warning.
virtual labelList selectUnrefinePoints(const scalar unrefineLevel, const PackedBoolList &markedCell, const scalarField &pFld) const
Select points that can be unrefined.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dynamicRefineFvMesh(const IOobject &io)
Construct from IOobject.
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.
prefixOSstream Pout(cout, "Pout")
Direct mesh changes based on v1.3 polyTopoChange syntax.
const dimensionedScalar c
Speed of light in a vacuum.
bool topoChanging() const
Is mesh topology changing.
virtual ~dynamicRefineFvMesh()
Destructor.
bool empty() const
Return true if the list is empty (ie, size() is zero).
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.
virtual bool write(const bool write=true) const
Write using setting from DB.
All refinement history. Used in unrefinement.
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]
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
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.
scalarField error(const scalarField &fld, const scalar minLevel, const scalar maxLevel) const
const labelIOList & cellLevel() const
Switch dumpLevel_
Dump cellLevel for postprocessing.
scalarField maxCellField(const volScalarField &) const
Get point max of connected cell.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
const dictionary & dynamicMeshDict() const
Return the dynamicMeshDict.