Merge branch 'feature-polyhedral-amr' into 'develop'

Draft: ENH: Polyhedral AMR

See merge request Development/openfoam!667
This commit is contained in:
Kutalmış Berçin
2025-10-24 08:12:05 +01:00
69 changed files with 15800 additions and 1153 deletions

View File

@ -1,10 +1,15 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude -I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/dynamicFvMesh/lnInclude
EXE_LIBS = \ EXE_LIBS = \
-lfiniteVolume \ -lfiniteVolume \
-lfvOptions \ -lfvOptions \
-lmeshTools \ -lmeshTools \
-ldynamicMesh \
-ldynamicFvMesh \
-ltopoChangerFvMesh \
-lsampling -lsampling

View File

@ -56,6 +56,7 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "fvCFD.H" #include "fvCFD.H"
#include "dynamicFvMesh.H"
#include "fvOptions.H" #include "fvOptions.H"
#include "simpleControl.H" #include "simpleControl.H"
@ -71,7 +72,7 @@ int main(int argc, char *argv[])
#include "addCheckCaseOptions.H" #include "addCheckCaseOptions.H"
#include "setRootCaseLists.H" #include "setRootCaseLists.H"
#include "createTime.H" #include "createTime.H"
#include "createMesh.H" #include "createDynamicFvMesh.H"
simpleControl simple(mesh); simpleControl simple(mesh);
@ -87,6 +88,16 @@ int main(int argc, char *argv[])
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;
// Do any mesh changes
mesh.controlledUpdate();
if (mesh.changing())
{
// Calculate absolute flux
// from the mapped surface velocity
phi = mesh.Sf() & fvc::interpolate(U);
}
while (simple.correctNonOrthogonal()) while (simple.correctNonOrthogonal())
{ {
fvScalarMatrix TEqn fvScalarMatrix TEqn

View File

@ -43,6 +43,7 @@ Description
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "polyTopoChange.H" #include "polyTopoChange.H"
#include "batchPolyTopoChange.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "edgeCollapser.H" #include "edgeCollapser.H"
#include "perfectInterface.H" #include "perfectInterface.H"
@ -1050,7 +1051,8 @@ int main(int argc, char *argv[])
); );
// Topo change container // Topo change container
polyTopoChange meshMod(mesh); //polyTopoChange meshMod(mesh);
batchPolyTopoChange meshMod(mesh);
perfectStitcher.setRefinement perfectStitcher.setRefinement
( (
@ -1076,7 +1078,9 @@ int main(int argc, char *argv[])
); );
// Construct new mesh from polyTopoChange. // Construct new mesh from polyTopoChange.
autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false); //autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
polyTopoChanger XXX (mesh, IOobject::NO_READ);
autoPtr<mapPolyMesh> map = XXX.changeMesh(mesh, meshMod);
// Update fields // Update fields
mesh.updateMesh(map()); mesh.updateMesh(map());

View File

@ -621,7 +621,7 @@ int main(int argc, char *argv[])
} }
// Execute all polyMeshModifiers // Execute all polyMeshModifiers
autoPtr<mapPolyMesh> morphMap = stitcher.changeMesh(true); autoPtr<mapPolyMesh> morphMap = stitcher.changeMesh();
mesh.movePoints(morphMap->preMotionPoints()); mesh.movePoints(morphMap->preMotionPoints());

View File

@ -79,7 +79,7 @@ renumber/Allwmake $targetType $*
parallel/Allwmake $targetType $* parallel/Allwmake $targetType $*
wmake $targetType dynamicFvMesh wmake $targetType dynamicFvMesh
wmake $targetType topoChangerFvMesh #HJ wmake $targetType topoChangerFvMesh
wmake $targetType sampling wmake $targetType sampling
transportModels/Allwmake $targetType $* transportModels/Allwmake $targetType $*
@ -133,6 +133,9 @@ wmake $targetType rigidBodyMeshMotion
wmake $targetType atmosphericModels wmake $targetType atmosphericModels
wmake $targetType optimisation/adjointOptimisation/adjoint wmake $targetType optimisation/adjointOptimisation/adjoint
# Moved by HJ
wmake $targetType topoChangerFvMesh
# interfaceTracking libs # interfaceTracking libs
dynamicFaMesh/Allwmake $targetType $* dynamicFaMesh/Allwmake $targetType $*

View File

@ -22,6 +22,7 @@ $(polyMeshModifier)/polyMeshModifier.C
$(polyMeshModifier)/polyMeshModifierNew.C $(polyMeshModifier)/polyMeshModifierNew.C
polyTopoChange/polyTopoChanger/polyTopoChanger.C polyTopoChange/polyTopoChanger/polyTopoChanger.C
polyTopoChange/polyTopoChanger/polyTopoChangerChangeMesh.C
polyTopoChange/polyTopoChange/addPatchCellLayer.C polyTopoChange/polyTopoChange/addPatchCellLayer.C
polyTopoChange/polyTopoChange/pointEdgeCollapse/pointEdgeCollapse.C polyTopoChange/polyTopoChange/pointEdgeCollapse/pointEdgeCollapse.C
polyTopoChange/polyTopoChange/edgeCollapser.C polyTopoChange/polyTopoChange/edgeCollapser.C
@ -76,6 +77,10 @@ meshCut/refineCell/refineCell.C
meshCut/wallLayerCells/wallLayerCells.C meshCut/wallLayerCells/wallLayerCells.C
meshCut/wallLayerCells/wallNormalInfo/wallNormalInfo.C meshCut/wallLayerCells/wallNormalInfo/wallNormalInfo.C
refinement/refinement/refinement.C
refinement/polyhedralRefinement/polyhedralRefinement.C
refinement/prismatic2DRefinement/prismatic2DRefinement.C
polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.C polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.C
polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.C polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.C

View File

@ -31,7 +31,7 @@ License
#include "polyMesh.H" #include "polyMesh.H"
#include "Time.H" #include "Time.H"
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -365,7 +365,7 @@ bool Foam::attachDetach::changeTopology() const
} }
void Foam::attachDetach::setRefinement(polyTopoChange& ref) const void Foam::attachDetach::setRefinement(batchPolyTopoChange& ref) const
{ {
// Insert the attach/detach instructions into the topological change // Insert the attach/detach instructions into the topological change

View File

@ -122,10 +122,10 @@ class attachDetach
// Topological changes // Topological changes
//- Attach interface //- Attach interface
void attachInterface(polyTopoChange&) const; void attachInterface(batchPolyTopoChange&) const;
//- Detach interface //- Detach interface
void detachInterface(polyTopoChange&) const; void detachInterface(batchPolyTopoChange&) const;
//- Calculate point match addressing //- Calculate point match addressing
void calcPointMatchMap() const; void calcPointMatchMap() const;
@ -215,7 +215,7 @@ public:
//- Insert the layer addition/removal instructions //- Insert the layer addition/removal instructions
// into the topological change // into the topological change
virtual void setRefinement(polyTopoChange&) const; virtual void setRefinement(batchPolyTopoChange&) const;
//- Modify motion points to comply with the topological change //- Modify motion points to comply with the topological change
virtual void modifyMotionPoints(pointField& motionPoints) const; virtual void modifyMotionPoints(pointField& motionPoints) const;

View File

@ -29,7 +29,7 @@ License
#include "attachDetach.H" #include "attachDetach.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyRemovePoint.H" #include "polyRemovePoint.H"
#include "polyRemoveFace.H" #include "polyRemoveFace.H"
@ -43,7 +43,7 @@ const Foam::scalar Foam::attachDetach::positionDifference_ = 1e-8;
void Foam::attachDetach::attachInterface void Foam::attachDetach::attachInterface
( (
polyTopoChange& ref batchPolyTopoChange& ref
) const ) const
{ {
// Algorithm: // Algorithm:
@ -62,7 +62,7 @@ void Foam::attachDetach::attachInterface
if (debug) if (debug)
{ {
Pout<< "void attachDetach::attachInterface(" Pout<< "void attachDetach::attachInterface("
<< "polyTopoChange& ref) const " << "batchPolyTopoChange& ref) const "
<< " for object " << name() << " : " << " for object " << name() << " : "
<< "Attaching interface" << endl; << "Attaching interface" << endl;
} }
@ -266,7 +266,7 @@ void Foam::attachDetach::attachInterface
if (debug) if (debug)
{ {
Pout<< "void attachDetach::attachInterface(" Pout<< "void attachDetach::attachInterface("
<< "polyTopoChange& ref) const " << "batchPolyTopoChange& ref) const "
<< " for object " << name() << " : " << " for object " << name() << " : "
<< "Finished attaching interface" << endl; << "Finished attaching interface" << endl;
} }

View File

@ -28,7 +28,7 @@ License
#include "attachDetach.H" #include "attachDetach.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyAddPoint.H" #include "polyAddPoint.H"
#include "polyModifyFace.H" #include "polyModifyFace.H"
@ -38,7 +38,7 @@ License
void Foam::attachDetach::detachInterface void Foam::attachDetach::detachInterface
( (
polyTopoChange& ref batchPolyTopoChange& ref
) const ) const
{ {
// Algorithm: // Algorithm:
@ -66,7 +66,7 @@ void Foam::attachDetach::detachInterface
if (debug) if (debug)
{ {
Pout<< "void attachDetach::detachInterface(" Pout<< "void attachDetach::detachInterface("
<< "polyTopoChange& ref) const " << "batchPolyTopoChange& ref) const "
<< " for object " << name() << " : " << " for object " << name() << " : "
<< "Detaching interface" << endl; << "Detaching interface" << endl;
} }
@ -75,7 +75,7 @@ void Foam::attachDetach::detachInterface
const faceZoneMesh& zoneMesh = mesh.faceZones(); const faceZoneMesh& zoneMesh = mesh.faceZones();
// Check that zone is in increasing order (needed since adding faces // Check that zone is in increasing order (needed since adding faces
// in same order - otherwise polyTopoChange face ordering will mess up // in same order - otherwise batchPolyTopoChange face ordering will mess up
// correspondence) // correspondence)
if (debug) if (debug)
{ {
@ -459,7 +459,7 @@ void Foam::attachDetach::detachInterface
if (debug) if (debug)
{ {
Pout<< "void attachDetach::detachInterface(" Pout<< "void attachDetach::detachInterface("
<< "polyTopoChange& ref) const " << "batchPolyTopoChange& ref) const "
<< " for object " << name() << " : " << " for object " << name() << " : "
<< "Finished detaching interface" << endl; << "Finished detaching interface" << endl;
} }

View File

@ -29,7 +29,7 @@ License
#include "layerAdditionRemoval.H" #include "layerAdditionRemoval.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyAddPoint.H" #include "polyAddPoint.H"
#include "polyAddCell.H" #include "polyAddCell.H"
@ -88,7 +88,7 @@ Foam::tmp<Foam::vectorField> Foam::layerAdditionRemoval::extrusionDir() const
void Foam::layerAdditionRemoval::addCellLayer void Foam::layerAdditionRemoval::addCellLayer
( (
polyTopoChange& ref batchPolyTopoChange& ref
) const ) const
{ {
// Insert the layer addition instructions into the topological change // Insert the layer addition instructions into the topological change
@ -108,7 +108,7 @@ void Foam::layerAdditionRemoval::addCellLayer
if (debug) if (debug)
{ {
Pout<< "void layerAdditionRemoval::addCellLayer(" Pout<< "void layerAdditionRemoval::addCellLayer("
<< "polyTopoChange& ref) const for object " << name() << " : " << "batchPolyTopoChange& ref) const for object " << name() << " : "
<< "Adding cell layer" << endl; << "Adding cell layer" << endl;
} }
@ -674,7 +674,7 @@ void Foam::layerAdditionRemoval::addCellLayer
if (debug) if (debug)
{ {
Pout<< "void layerAdditionRemoval::addCellLayer(polyTopoChange&) const " Pout<< "void layerAdditionRemoval::addCellLayer(batchPolyTopoChange&) const "
<< " for object " << name() << ": " << " for object " << name() << ": "
<< "Finished adding cell layer" << endl; << "Finished adding cell layer" << endl;
} }

View File

@ -355,7 +355,7 @@ bool Foam::layerAdditionRemoval::changeTopology() const
} }
void Foam::layerAdditionRemoval::setRefinement(polyTopoChange& ref) const void Foam::layerAdditionRemoval::setRefinement(batchPolyTopoChange& ref) const
{ {
// Insert the layer addition/removal instructions // Insert the layer addition/removal instructions
// into the topological change // into the topological change
@ -367,7 +367,7 @@ void Foam::layerAdditionRemoval::setRefinement(polyTopoChange& ref) const
// Clear addressing. This also resets the addition/removal data // Clear addressing. This also resets the addition/removal data
if (debug) if (debug)
{ {
Pout<< "layerAdditionRemoval::setRefinement(polyTopoChange&) " Pout<< "layerAdditionRemoval::setRefinement(batchPolyTopoChange&) "
<< "for object " << name() << " : " << "for object " << name() << " : "
<< "Clearing addressing after layer removal" << endl; << "Clearing addressing after layer removal" << endl;
} }
@ -383,7 +383,7 @@ void Foam::layerAdditionRemoval::setRefinement(polyTopoChange& ref) const
// Clear addressing. This also resets the addition/removal data // Clear addressing. This also resets the addition/removal data
if (debug) if (debug)
{ {
Pout<< "layerAdditionRemoval::setRefinement(polyTopoChange&) " Pout<< "layerAdditionRemoval::setRefinement(batchPolyTopoChange&) "
<< "for object " << name() << " : " << "for object " << name() << " : "
<< "Clearing addressing after layer addition" << endl; << "Clearing addressing after layer addition" << endl;
} }

View File

@ -119,10 +119,10 @@ class layerAdditionRemoval
tmp<vectorField> extrusionDir() const; tmp<vectorField> extrusionDir() const;
//- Add a layer of cells //- Add a layer of cells
void addCellLayer(polyTopoChange&) const; void addCellLayer(batchPolyTopoChange&) const;
//- Remove a layer of cells //- Remove a layer of cells
void removeCellLayer(polyTopoChange&) const; void removeCellLayer(batchPolyTopoChange&) const;
//- Clear addressing //- Clear addressing
void clearAddressing() const; void clearAddressing() const;
@ -179,7 +179,7 @@ public:
//- Insert the layer addition/removal instructions //- Insert the layer addition/removal instructions
// into the topological change // into the topological change
virtual void setRefinement(polyTopoChange&) const; virtual void setRefinement(batchPolyTopoChange&) const;
//- Modify motion points to comply with the topological change //- Modify motion points to comply with the topological change
virtual void modifyMotionPoints(pointField& motionPoints) const; virtual void modifyMotionPoints(pointField& motionPoints) const;

View File

@ -29,7 +29,7 @@ License
#include "layerAdditionRemoval.H" #include "layerAdditionRemoval.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "oppositeFace.H" #include "oppositeFace.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyRemoveCell.H" #include "polyRemoveCell.H"
@ -83,7 +83,7 @@ bool Foam::layerAdditionRemoval::validCollapse() const
void Foam::layerAdditionRemoval::removeCellLayer void Foam::layerAdditionRemoval::removeCellLayer
( (
polyTopoChange& ref batchPolyTopoChange& ref
) const ) const
{ {
// Algorithm for layer removal. Second phase: topological change // Algorithm for layer removal. Second phase: topological change

View File

@ -33,7 +33,7 @@ Description
#include "perfectInterface.H" #include "perfectInterface.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "mapPolyMesh.H" #include "mapPolyMesh.H"
#include "matchPoints.H" #include "matchPoints.H"
@ -154,7 +154,7 @@ void Foam::perfectInterface::setRefinement
( (
const indirectPrimitivePatch& pp0, const indirectPrimitivePatch& pp0,
const indirectPrimitivePatch& pp1, const indirectPrimitivePatch& pp1,
polyTopoChange& ref batchPolyTopoChange& ref
) const ) const
{ {
const polyMesh& mesh = topoChanger().mesh(); const polyMesh& mesh = topoChanger().mesh();
@ -423,11 +423,11 @@ void Foam::perfectInterface::setRefinement
} }
void Foam::perfectInterface::setRefinement(polyTopoChange& ref) const void Foam::perfectInterface::setRefinement(batchPolyTopoChange& ref) const
{ {
if (debug) if (debug)
{ {
Pout<< "bool perfectInterface::setRefinement(polyTopoChange&) const : " Pout<< "bool perfectInterface::setRefinement(batchPolyTopoChange&) const : "
<< "for object " << name() << " : " << "for object " << name() << " : "
<< "masterPatchID_:" << masterPatchID_ << "masterPatchID_:" << masterPatchID_
<< " slavePatchID_:" << slavePatchID_ << " slavePatchID_:" << slavePatchID_

View File

@ -129,7 +129,7 @@ public:
//- Insert the layer addition/removal instructions //- Insert the layer addition/removal instructions
// into the topological change // into the topological change
virtual void setRefinement(polyTopoChange&) const; virtual void setRefinement(batchPolyTopoChange&) const;
//- Insert the layer addition/removal instructions //- Insert the layer addition/removal instructions
// into the topological change. Uses only mesh, not any of the // into the topological change. Uses only mesh, not any of the
@ -139,7 +139,7 @@ public:
( (
const indirectPrimitivePatch& pp0, const indirectPrimitivePatch& pp0,
const indirectPrimitivePatch& pp1, const indirectPrimitivePatch& pp1,
polyTopoChange& batchPolyTopoChange&
) const; ) const;
//- Modify motion points to comply with the topological change //- Modify motion points to comply with the topological change

View File

@ -65,7 +65,10 @@ void Foam::attachPolyTopoChanger::attach(const bool removeEmptyPatches)
const fileName oldInst = mesh_.facesInstance(); const fileName oldInst = mesh_.facesInstance();
// Execute all polyMeshModifiers // Execute all polyMeshModifiers
changeMesh(false); // no inflation // DISABLED - this functionality is lost
// Bad rewrite by Mattijs Janssens - completely misunderstood the interface
// Needs to use polyTopoChange, and not changer.
// changeMesh(false); // no inflation
const pointField p = mesh_.oldPoints(); const pointField p = mesh_.oldPoints();

View File

@ -55,7 +55,7 @@ namespace Foam
// Forward Declarations // Forward Declarations
class polyTopoChanger; class polyTopoChanger;
class polyTopoChange; class batchPolyTopoChange;
class mapPolyMesh; class mapPolyMesh;
class polyMeshModifier; class polyMeshModifier;
@ -166,7 +166,7 @@ public:
virtual bool changeTopology() const = 0; virtual bool changeTopology() const = 0;
//- Insert the topological change instructions //- Insert the topological change instructions
virtual void setRefinement(polyTopoChange&) const = 0; virtual void setRefinement(batchPolyTopoChange&) const = 0;
//- Modify motion points to comply with the topological change //- Modify motion points to comply with the topological change
virtual void modifyMotionPoints(pointField& motionPoints) const = 0; virtual void modifyMotionPoints(pointField& motionPoints) const = 0;

File diff suppressed because it is too large Load Diff

View File

@ -86,6 +86,19 @@ class removeFaces
labelList& cellRegion labelList& cellRegion
) const; ) const;
//- Changes region of connected set of faces. Returns number of changed
// faces. For use with batch topo change
label changeFaceRegion
(
const labelList& cellRegion,
const boolList& removedFace,
const labelList& nFacesPerEdge,
const label faceI,
const label newRegion,
labelList& faceRegion
) const;
//- Changes region of connected set of faces //- Changes region of connected set of faces
label changeFaceRegion label changeFaceRegion
( (
@ -119,13 +132,15 @@ class removeFaces
); );
//- Merge faceLabels into single face. //- Merge faceLabels into single face.
template<class TopoChangeEngine>
void mergeFaces void mergeFaces
( (
const labelList& cellRegion, const labelList& cellRegion,
const labelList& cellRegionMaster, const labelList& cellRegionMaster,
const labelHashSet& pointsToRemove, const labelHashSet& pointsToRemove,
const labelList& faceLabels, const labelList& faceLabels,
polyTopoChange& meshMod
TopoChangeEngine& meshMod
) const; ) const;
//- Get patch, zone info for facei //- Get patch, zone info for facei
@ -141,6 +156,7 @@ class removeFaces
face filterFace(const labelHashSet&, const label) const; face filterFace(const labelHashSet&, const label) const;
//- Wrapper for meshMod.modifyFace. Reverses face if own>nei. //- Wrapper for meshMod.modifyFace. Reverses face if own>nei.
template<class TopoChangeEngine>
void modFace void modFace
( (
const face& f, const face& f,
@ -153,11 +169,10 @@ class removeFaces
const label zoneID, const label zoneID,
const bool zoneFlip, const bool zoneFlip,
polyTopoChange& meshMod TopoChangeEngine& meshMod
) const; ) const;
//- No copy construct //- No copy construct
removeFaces(const removeFaces&) = delete; removeFaces(const removeFaces&) = delete;
@ -199,12 +214,15 @@ public:
//- Play commands into polyTopoChange to remove faces. //- Play commands into polyTopoChange to remove faces.
template<class TopoChangeEngine>
void setRefinement void setRefinement
( (
const labelList& piercedFaces, const labelList& piercedFaces,
const labelList& cellRegion, const labelList& cellRegion,
const labelList& cellRegionMaster, // const labelList& pointRegionMaster,
polyTopoChange& labelList& cellRegionMaster,
TopoChangeEngine&
) const; ) const;
//- Force recalculation of locally stored data on topological change //- Force recalculation of locally stored data on topological change
@ -221,6 +239,10 @@ public:
} // End namespace Foam } // End namespace Foam
#ifdef NoRepository
# include "removeFacesTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,9 @@ License
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "mapPolyMesh.H"
#include "polyTopoChange.H" #include "polyTopoChange.H"
#include "batchPolyTopoChange.H"
#include "Time.H" #include "Time.H"
#include "PtrListOps.H" #include "PtrListOps.H"
@ -192,14 +194,14 @@ bool Foam::polyTopoChanger::changeTopology() const
} }
Foam::autoPtr<Foam::polyTopoChange> Foam::autoPtr<Foam::batchPolyTopoChange>
Foam::polyTopoChanger::topoChangeRequest() const Foam::polyTopoChanger::topoChangeRequest() const
{ {
// Collect changes from all modifiers // Collect changes from all modifiers
const PtrList<polyMeshModifier>& topoChanges = *this; const PtrList<polyMeshModifier>& topoChanges = *this;
auto ptr = autoPtr<polyTopoChange>::New(mesh()); auto ptr = autoPtr<batchPolyTopoChange>::New(mesh());
polyTopoChange& ref = ptr.ref(); batchPolyTopoChange& ref = ptr.ref();
forAll(topoChanges, morphI) forAll(topoChanges, morphI)
{ {
@ -245,35 +247,35 @@ void Foam::polyTopoChanger::update(const mapPolyMesh& m)
} }
Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChanger::changeMesh // Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChanger::changeMesh
( // (
const bool inflate, // const bool inflate,
const bool syncParallel, // const bool syncParallel,
const bool orderCells, // const bool orderCells,
const bool orderPoints // const bool orderPoints
) // )
{ // {
if (changeTopology()) // if (changeTopology())
{ // {
autoPtr<polyTopoChange> ref = topoChangeRequest(); // autoPtr<polyTopoChange> ref = topoChangeRequest();
autoPtr<mapPolyMesh> topoChangeMap = ref().changeMesh // autoPtr<mapPolyMesh> topoChangeMap = ref().changeMesh
( // (
mesh_, // mesh_,
inflate, // inflate,
syncParallel, // syncParallel,
orderCells, // orderCells,
orderPoints // orderPoints
); // );
update(topoChangeMap()); // update(topoChangeMap());
mesh_.updateMesh(topoChangeMap()); // mesh_.updateMesh(topoChangeMap());
return topoChangeMap; // return topoChangeMap;
} // }
mesh_.topoChanging(false); // mesh_.topoChanging(false);
return nullptr; // return nullptr;
} // }
void Foam::polyTopoChanger::addTopologyModifiers void Foam::polyTopoChanger::addTopologyModifiers
@ -326,6 +328,13 @@ Foam::label Foam::polyTopoChanger::findModifierID
} }
Foam::label Foam::polyTopoChanger::morphIndex() const
{
return morphIndex_;
}
// writeData member function required by regIOobject
bool Foam::polyTopoChanger::writeData(Ostream& os) const bool Foam::polyTopoChanger::writeData(Ostream& os) const
{ {
os << *this; os << *this;

View File

@ -51,6 +51,7 @@ namespace Foam
class polyMesh; class polyMesh;
class mapPolyMesh; class mapPolyMesh;
class polyBoundaryMesh; class polyBoundaryMesh;
class polyTopoChange;
class polyTopoChanger; class polyTopoChanger;
Ostream& operator<<(Ostream&, const polyTopoChanger&); Ostream& operator<<(Ostream&, const polyTopoChanger&);
@ -65,6 +66,12 @@ class polyTopoChanger
public PtrList<polyMeshModifier>, public PtrList<polyMeshModifier>,
public regIOobject public regIOobject
{ {
// Private data
//- Current time index for mesh morph
label morphIndex_;
// Private Member Functions // Private Member Functions
//- Read if IOobject flags set, set modifiers. Return true if read. //- Read if IOobject flags set, set modifiers. Return true if read.
@ -84,6 +91,33 @@ protected:
//- Reference to mesh //- Reference to mesh
polyMesh& mesh_; polyMesh& mesh_;
// Protected Member Functions
// Topology changes
//- Rotate a face nShift positions in anticlockwise direction
static face rotateFace(const face& f, const label nShift);
//- Determine ordering of faces in coupled patches.
// Calculate mapping to shuffle faces inside coupled patches and
// rotation to make 0th vertex in faces align.
static bool reorderCoupledPatches
(
const polyBoundaryMesh& boundary,
const labelList& patchStarts,
const labelList& patchSizes,
const faceList& faces,
const pointField& points,
labelList& faceMap,
labelList& rotation
);
//- Sync communications required for couple patch reordering when
// there is no local topological change
void syncCoupledPatches();
public: public:
//- Runtime type information //- Runtime type information
@ -125,19 +159,27 @@ public:
bool changeTopology() const; bool changeTopology() const;
//- Return topology change request //- Return topology change request
autoPtr<polyTopoChange> topoChangeRequest() const; autoPtr<batchPolyTopoChange> topoChangeRequest() const;
//- Modify point motion //- Modify point motion
void modifyMotionPoints(pointField&) const; void modifyMotionPoints(pointField&) const;
autoPtr<mapPolyMesh> changeMesh // autoPtr<mapPolyMesh> changeMesh
// (
// const bool inflate,
// const bool syncParallel = true,
// const bool orderCells = false,
// const bool orderPoints = false
// );
static autoPtr<mapPolyMesh> changeMesh
( (
const bool inflate, polyMesh&,
const bool syncParallel = true, const batchPolyTopoChange&
const bool orderCells = false,
const bool orderPoints = false
); );
autoPtr<mapPolyMesh> changeMesh();
//- Force recalculation of locally stored data on topological change //- Force recalculation of locally stored data on topological change
void update(const mapPolyMesh& m); void update(const mapPolyMesh& m);
@ -147,6 +189,9 @@ public:
//- Find modifier given a name //- Find modifier given a name
label findModifierID(const word& modName) const; label findModifierID(const word& modName) const;
//- Return morph index
label morphIndex() const;
//- writeData member function required by regIOobject //- writeData member function required by regIOobject
bool writeData(Ostream&) const; bool writeData(Ostream&) const;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,246 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::polyhedralRefinement
Description
Isotropic refinement of polyhedral cells using the mesh modifier engine
Each polyhedral cell is split by the following procedure:
1. Adding points at the edge centre, face centre and cell centre,
2. Adding cells n cells where n is the number of points of the cell,
3. Splitting each face into multiple faces going from:
existing corner point -> new edge centre point -> new face centre
point -> other new edge centre point (sharing the same corner point)
4. Adding internal faces going from:
new edge centre point -> new face centre point -> new cell centre
point -> other new face centre point (sharing the same edge)
SourceFiles
polyhedralRefinement.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
Rewrite, porting and changes by Hrvoje Jasak, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef polyhedralRefinement_H
#define polyhedralRefinement_H
#include "refinement.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class polyhedralRefinement Declaration
\*---------------------------------------------------------------------------*/
class polyhedralRefinement
:
public refinement
{
private:
// Private Member Functions
// Helper functions
//- Get least cell level such that the face has at least three
// points smaller than the level
label getAnchorLevel(const label faceI) const;
// Local topology modification functions (operate on cells/faces)
//- Create all internal faces of split cellI into n cells
// where n is the number of cell points
void createInternalFaces
(
const labelListList& cellAnchorPoints,
const labelListList& cellAddedCells,
const labelList& cellMidPoint,
const labelList& faceMidPoint,
const labelList& faceAnchorLevel,
const labelList& edgeMidPoint,
const label cellI,
batchPolyTopoChange& ref
) const;
// Topological change helper functions
//- Get cell added to point of cellI (if any)
label getAnchorCell
(
const labelListList& cellAnchorPoints,
const labelListList& cellAddedCells,
const label cellI,
const label faceI,
const label pointI
) const;
//- Set new owner and neighbour (in unspecified order) of pointI
// on faceI
void setNewFaceNeighbours
(
const labelListList& cellAnchorPoints,
const labelListList& cellAddedCells,
const label faceI,
const label pointI,
label& own,
label& nei
) const;
//- Find index of point with wantedLevel, starting from fp
label findLevel
(
const face& f,
const label startFp,
const bool searchForward,
const label wantedLevel
) const;
//- Store in maps correspondence from midpoint to anchors and
// faces. Used when creating internal faces
label storeMidPointInfo
(
const labelListList& cellAnchorPoints,
const labelListList& cellAddedCells,
const labelList& cellMidPoint,
const labelList& edgeMidPoint,
const label cellI,
const label faceI,
const bool faceOrder,
const label midPointI,
const label anchorPointI,
const label faceMidPointI,
Map<edge>& midPointToAnchors,
Map<edge>& midPointToFaceMids,
batchPolyTopoChange& ref
) const;
//- If p0 and p1 are existing vertices check if edge is split
// and insert splitPoint. Used with storing mid point
void insertEdgeSplit
(
const labelList& edgeMidPoint,
const label p0,
const label p1,
DynamicList<label>& verts
) const;
// Copy control
//- Disallow default bitwise copy construct
polyhedralRefinement(const polyhedralRefinement&) = delete;
//- Disallow default bitwise assignment
void operator=(const polyhedralRefinement&) = delete;
protected:
// Protected Pure Virtual Member Functions
// Global topology modification functions (operate on whole polyMesh)
//- Set refinement instruction
virtual void setRefinementInstruction
(
batchPolyTopoChange& ref
) const;
//- Set unrefinement instruction
virtual void setUnrefinementInstruction
(
batchPolyTopoChange& ref
) const;
public:
//- Runtime type information
TypeName("polyhedralRefinement");
// Constructors
//- Construct from dictionary
polyhedralRefinement
(
const word& name,
const dictionary& dict,
const label index,
const polyTopoChanger& mme
);
//- Destructor
virtual ~polyhedralRefinement() = default;
// Member Functions
// Edit
//- Set cells to refine given a list of refinement
// candidates. Refinement candidates are extended within the
// function due to possible 4:1 conflicts and specified number of
// buffer layers.
// Note: must be called BEFORE setSplitPointsToUnrefine
virtual void setCellsToRefine
(
const labelList& refinementCellCandidates
);
//- Set split points to unrefine given a list of all mesh points
// that are candidates for unrefinement. Split points are
// determined as a subset of unrefinement candidates, avoiding
// splitting points of cells that are going to be refined at the
// same time and ensuring consistent unrefinement.
// Note: must be called AFTER setCellsToRefine
virtual void setSplitPointsToUnrefine
(
const labelList& unrefinementPointCandidates
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,254 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::prismatic2DRefinement
Description
Isotropic refinement of prismatic cells in 2D using the mesh modifier
engine. Used for 2D cases instead of polyhedralRefinement which carries
unnecessary overhead in terms of number of cells since it splits the cell in
all directions.
Each prismatic cell is split by the following procedure:
1. Adding points at the face centres and edge centres of all faces found on
an special patch: empty or wedge.
2. Adding n cells per existing cell where n is the number of corner points
at the face on special patch (empty or wedge).
3. Splitting each of the faces on special patch (empty or wedge) into
multiple faces going from: existing corner point -> new edge centre point
-> new face centre point -> other new edge centre point (sharing the same
corner point)
4. Spliiting each of the faces not on an special patch (empty or wedge) into
two faces going from: existing corner point -> existing corner point on
the other side -> new edge centre point on the other side -> new edge
centre point on my side
4. Adding internal faces going from:
new edge centre point -> new face centre point -> new other face
centre point on the other side -> new other edge mid point on the other
side
It is an error to try and run this on anything except a 2D mesh.
SourceFiles
prismatic2DRefinement.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef prismatic2DRefinement_H
#define prismatic2DRefinement_H
#include "refinement.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class prismatic2DRefinement Declaration
\*---------------------------------------------------------------------------*/
class prismatic2DRefinement
:
public refinement
{
private:
// Private Member Functions
// Helper functions
//- Get least cell level such that the face has at least nPoints
// points smaller than the level
label getAnchorLevel
(
const label faceI,
const label nPoints
) const;
//- Append given face into a dynamic list containing split faces
// that will be split into two faces (third parameter). Additionaly
// append information on which of the two edges of the face are on
// special patch into a dynamic list (fourth parameter)
void appendFaceSplitInfo
(
const label& faceI,
const boolList& edgeOnEmptyPatch,
const labelList& edgeMidPoint,
DynamicList<label>& splitFacesIntoTwo,
DynamicList<Pair<label> >& splitFacesEmptyEdges
) const;
// Topological change helper functions
//- Set new owner and neighbour given anchor pointI, faceI and the
// necessary mapping
void setNewFaceNeighbours
(
const HashTable
<
label,
Pair<label>,
Hash<FixedList<label, 2> >
>& pointCellToAddedCellMap,
const labelListList& cellAddedCells,
const label& faceI,
const label& pointI,
label& own,
label& nei
) const;
//- Get index of point with minimum point level of a face across two
// connected edges starting from a local point index.
// Example: starting from point with level 1 in the upper left
// corner, finds point index of the point with level 0 which is on
// the same face, connected with edge to original point
// 1------1
// |
// |
// 0
// Note: passing face edges and mesh edges as parameters to avoid
// fetching them from mesh due to lazy evaluation
label findMinEdgeConnectedLevel
(
const label& fpI,
const label& faceI,
const face& f,
const labelList& fEdges,
const edgeList& meshEdges
) const;
//- Store two face mids when adding internal faces
void addFaceMids
(
const labelList& faceMidPoint,
const boolList& faceOnEmptyPatch,
const label& faceI,
const label& cellI,
face& newFace
) const;
// Debug functions
//- Check orientation of a split face
void checkNewFaceOrientation
(
batchPolyTopoChange& ref,
const label& faceI,
const face& newFace
) const;
// Copy control
//- Disallow default bitwise copy construct
prismatic2DRefinement(const prismatic2DRefinement&) = delete;
//- Disallow default bitwise assignment
void operator=(const prismatic2DRefinement&) = delete;
protected:
// Protected Pure Virtual Member Functions
// Global topology modification functions (operate on whole polyMesh)
//- Set refinement instruction
virtual void setRefinementInstruction
(
batchPolyTopoChange& ref
) const;
//- Set unrefinement instruction
virtual void setUnrefinementInstruction
(
batchPolyTopoChange& ref
) const;
public:
//- Runtime type information
TypeName("prismatic2DRefinement");
// Constructors
//- Construct from dictionary
prismatic2DRefinement
(
const word& name,
const dictionary& dict,
const label index,
const polyTopoChanger& mme
);
//- Destructor
virtual ~prismatic2DRefinement();
// Member Functions
// Edit
//- Set cells to refine given a list of refinement
// candidates. Refinement candidates are extended within the
// function due to possible 4:1 conflicts and specified number of
// buffer layers.
// Note: must be called BEFORE setSplitPointsToUnrefine
virtual void setCellsToRefine
(
const labelList& refinementCellCandidates
);
//- Set split points to unrefine given a list of all mesh points
// that are candidates for unrefinement. Split points are
// determined as a subset of unrefinement candidates, avoiding
// splitting points of cells that are going to be refined at the
// same time and ensuring consistent unrefinement.
// Note: must be called AFTER setCellsToRefine
void setSplitPointsToUnrefine
(
const labelList& unrefinementPointCandidates
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,392 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::refinement
Description
Abstract base class for adaptive mesh refinement using the mesh modifier
engine. The class provides common interface and functionalities for 3D
polyhedral refinement and 2D prismatic refinement.
The common interface includes (pure virtuals) following member functions:
- setCellsToRefine
- setSplitPointsToUnrefine
With a lot of ordinary protected member functions which are used by both
derived classes.
Note: I've written it this way in order to avoid unnecesasry code
duplication, but I'm 99% sure that if someone else wants to write additional
refinement strategy (e.g. directional refinement) as derived class, the
interface will need to change.
SourceFiles
refinement.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
Notes
Generalisation of hexRef8 for polyhedral cells and refactorisation using
polyMesh modifier engine.
\*---------------------------------------------------------------------------*/
#ifndef refinement_H
#define refinement_H
#include "polyMeshModifier.H"
#include "labelIOField.H"
#include "removeFaces.H"
#include "batchPolyTopoChange.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class refinement Declaration
\*---------------------------------------------------------------------------*/
class refinement
:
public polyMeshModifier
{
protected:
// Protected enumeration for refinement status
enum refinementStatus
{
UNREFINED = -1,
UNCHANGED = 0,
REFINED = 1
};
static const scalar nonOrthThreshold_;
// Protected data
//- Reference to polyMesh for easy access in helper functions
const polyMesh& mesh_;
// Refinement control and handling
//- List of cells to refine in this time step
mutable labelList cellsToRefine_;
//- List of split point labels to unrefine in this time step
mutable labelList splitPointsToUnrefine_;
//- Cell refinement level
mutable labelIOField cellLevel_;
//- Point refinement level
mutable labelIOField pointLevel_;
//- Helper list for original (old) cells that will be refined or
// unrefined. The list is updated in setPolyhedralRefinement and
// setPolyhedralUnfereinement and is used in updateMesh to update
// the cellLevel on the new mesh.
// Values stored in the list are:
// a) UNREFINED = -1 = cell is unrefined
// b) UNCHANGED = 0 = cell is untouched
// c) REFINED = +1 = cell is refined
mutable labelList refinementLevelIndicator_;
//- Face remover engine
mutable removeFaces faceRemover_;
//- Maximum number of cells in the mesh. Note: not strictly enforced
label maxCells_;
//- Maximum number of refinement levels for a given cell
label maxRefinementLevel_;
//- Switch whether to use edge based consistency on refinement
Switch edgeBasedConsistency_;
//- Number of buffer layers for refinement
label nRefinementBufferLayers_;
//- Number of buffer layers for unrefinement, controlling how far
// the unrefinement region needs to be from current refinement
// region
label nUnrefinementBufferLayers_;
// Protected Pure Virtual Member Functions
// Global topology modification functions (operate on whole polyMesh)
//- Set refinement instruction
virtual void setRefinementInstruction
(
batchPolyTopoChange& ref
) const = 0;
//- Set unrefinement instruction
virtual void setUnrefinementInstruction
(
batchPolyTopoChange& ref
) const = 0;
// Protected Member Functions
// Useful helper functions used by derived classes
//- Set file instance for cellLevel_ and pointLevel_
void setInstance(const fileName& inst) const;
// Local topology modification functions (operate on cells/faces)
//- Adds a face on top of existing faceI. Reverses if nessecary
label addFace
(
batchPolyTopoChange& ref,
const label faceI,
const face& newFace,
const label own,
const label nei
) const;
//- Adds internal face from point. No checks on reversal
label addInternalFace
(
batchPolyTopoChange& ref,
const label meshFaceI,
const label meshPointI,
const face& newFace,
const label own,
const label nei
) const;
//- Modifies existing faceI for either new owner/neighbour or new
// face points. Reverses if nessecary
void modifyFace
(
batchPolyTopoChange& ref,
const label faceI,
const face& newFace,
const label own,
const label nei
) const;
// Topological change helper functions
//- Store vertices from startFp up to face split point.
// Used when splitting face into n faces where n is the number of
// points in a face (or number of edges)
void walkFaceToMid
(
const labelList& edgeMidPoint,
const label cLevel,
const label faceI,
const label startFp,
DynamicList<label>& faceVerts
) const;
//- Same as walkFaceToMid but now walk back
void walkFaceFromMid
(
const labelList& edgeMidPoint,
const label cLevel,
const label faceI,
const label startFp,
DynamicList<label>& faceVerts
) const;
//- Get index of point with minimum point level
label findMinLevel(const labelList& f) const;
//- Get index of point with maximum point level
label findMaxLevel(const labelList& f) const;
//- Count number of vertices <= anchorLevel for a given face
label countAnchors
(
const labelList& f,
const label anchorLevel
) const;
//- Adjust cell refinement level after topo change
void adjustRefLevel
(
label& curNewCellLevel,
const label oldCellI
);
// Debug functions
//- Check orientation of added internal face
void checkInternalOrientation
(
batchPolyTopoChange& ref,
const label cellI,
const label faceI,
const point& ownPt,
const point& neiPt,
const face& newFace
) const;
//- Check orientation of a new boundary face
void checkBoundaryOrientation
(
batchPolyTopoChange& ref,
const label cellI,
const label faceI,
const point& ownPt,
const point& boundaryPt,
const face& newFace
) const;
// Refinement/unrefinement consistency checks
//- Updates cellsToRefine such that a face consistent 2:1 refinement
// is obtained. Returns local number of cells changed
label faceConsistentRefinement(boolList& cellsToRefine) const;
//- Updates cellsToRefine such that an edge consistent 4:1 refinement
// is obtained. Returns local number of cells changed
label edgeConsistentRefinement(boolList& cellsToRefine) const;
//- Updates cellsToUnrefine such that a face consistent 2:1
// unrefinement is obtained. Returns local number of cells changed
label faceConsistentUnrefinement(boolList& cellsToUnrefine) const;
//- Updates cellsToUnrefine such that an edge consistent 4:1
// unrefinement is obtained. Returns local number of cells changed
label edgeConsistentUnrefinement(boolList& cellsToUnrefine) const;
// Copy control
//- Disallow default bitwise copy construct
refinement(const refinement&);
//- Disallow default bitwise assignment
void operator=(const refinement&);
public:
//- Runtime type information
TypeName("refinement");
// Constructors
//- Construct from dictionary
refinement
(
const word& name,
const dictionary& dict,
const label index,
const polyTopoChanger& mme
);
//- Destructor
virtual ~refinement() = default;
// Member Functions
// Access
//- Return refinement cell level
const labelIOField& cellLevel() const
{
return cellLevel_;
}
//- Return refinement point level
const labelIOField& pointLevel() const
{
return pointLevel_;
}
// Edit
//- Set cells to refine given a list of refinement
// candidates. Refinement candidates are extended within the
// function due to possible 4:1 conflicts and specified number of
// buffer layers.
// Note: must be called BEFORE setSplitPointsToUnrefine
virtual void setCellsToRefine
(
const labelList& refinementCellCandidates
) = 0;
//- Set split points to unrefine given a list of all mesh points
// that are candidates for unrefinement. Split points are
// determined as a subset of unrefinement candidates, avoiding
// splitting points of cells that are going to be refined at the
// same time and ensuring consistent unrefinement.
// Note: must be called AFTER setCellsToRefine
virtual void setSplitPointsToUnrefine
(
const labelList& unrefinementPointCandidates
) = 0;
// Inherited interface from polyMeshModifier
//- Check for topology change
virtual bool changeTopology() const;
//- Insert the polyhedral refinement/unrefinement into the
// topological change
virtual void setRefinement(batchPolyTopoChange&) const;
//- Modify motion points to comply with the topological change
virtual void modifyMotionPoints(pointField& motionPoints) const;
//- Force recalculation of locally stored data on topological change
virtual void updateMesh(const mapPolyMesh&);
//- Write
virtual void write(Ostream&) const;
//- Write dictionary
virtual void writeDict(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,351 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Namespace
Foam::refinementTools
Description
Collection of static functions to do various simple mesh related things.
SourceFiles
refinementTools.C
\*---------------------------------------------------------------------------*/
#ifndef refinementTools_H
#define refinementTools_H
#include "vector.H"
#include "label.H"
#include "labelList.H"
#include "pointField.H"
#include "faceList.H"
#include "cellList.H"
#include "primitivePatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class primitiveMesh;
class polyMesh;
/*---------------------------------------------------------------------------*\
Namespace refinementTools Declaration
\*---------------------------------------------------------------------------*/
namespace refinementTools
{
// Bit identifiers for octants (p=plus, m=min e.g. plusXminYminZ)
static const label mXmYmZ = 0;
static const label pXmYmZ = 1;
static const label mXpYmZ = 2;
static const label pXpYmZ = 3;
static const label mXmYpZ = 4;
static const label pXmYpZ = 5;
static const label mXpYpZ = 6;
static const label pXpYpZ = 7;
static const label mXmYmZMask = 1 << mXmYmZ;
static const label pXmYmZMask = 1 << pXmYmZ;
static const label mXpYmZMask = 1 << mXpYmZ;
static const label pXpYmZMask = 1 << pXpYmZ;
static const label mXmYpZMask = 1 << mXmYpZ;
static const label pXmYpZMask = 1 << pXmYpZ;
static const label mXpYpZMask = 1 << mXpYpZ;
static const label pXpYpZMask = 1 << pXpYpZ;
// Normal handling
//- Check if n is in same direction as normals of all faceLabels
bool visNormal
(
const vector& n,
const vectorField& faceNormals,
const labelList& faceLabels
);
//- Calculate point normals on a 'box' mesh (all edges aligned with
// coordinate axes)
vectorField calcBoxPointNormals(const primitivePatch& pp);
//- Normalized edge vector
vector normEdgeVec(const primitiveMesh&, const label edgeI);
// OBJ writing
//- Write obj representation of point
void writeOBJ
(
Ostream& os,
const point& pt
);
//- Write obj representation of faces subset
void writeOBJ
(
Ostream& os,
const faceList&,
const pointField&,
const labelList& faceLabels
);
//- Write obj representation of faces
void writeOBJ
(
Ostream& os,
const faceList&,
const pointField&
);
//- Write obj representation of cell subset
void writeOBJ
(
Ostream& os,
const cellList&,
const faceList&,
const pointField&,
const labelList& cellLabels
);
// Cell/face/edge walking
//- Is edge used by cell
bool edgeOnCell
(
const primitiveMesh&,
const label cellI,
const label edgeI
);
//- Is edge used by face
bool edgeOnFace
(
const primitiveMesh&,
const label faceI,
const label edgeI
);
//- Is face used by cell
bool faceOnCell
(
const primitiveMesh&,
const label cellI,
const label faceI
);
//- Return edge among candidates that uses the two vertices.
label findEdge
(
const edgeList& edges,
const labelList& candidates,
const label v0,
const label v1
);
//- Return edge between two vertices. Returns -1 if no edge.
label findEdge
(
const primitiveMesh&,
const label v0,
const label v1
);
//- Return edge shared by two faces. Throws error if no edge found.
label getSharedEdge
(
const primitiveMesh&,
const label f0,
const label f1
);
//- Return face shared by two cells. Throws error if none found.
label getSharedFace
(
const primitiveMesh&,
const label cell0,
const label cell1
);
//- Get faces on cell using edgeI. Throws error if no two found.
void getEdgeFaces
(
const primitiveMesh&,
const label cellI,
const label edgeI,
label& face0,
label& face1
);
//- Return label of other edge (out of candidates edgeLabels)
// connected to vertex but not edgeI. Throws error if none found.
label otherEdge
(
const primitiveMesh&,
const labelList& edgeLabels,
const label edgeI,
const label vertI
);
//- Return face on cell using edgeI but not faceI. Throws error
// if none found.
label otherFace
(
const primitiveMesh&,
const label cellI,
const label faceI,
const label edgeI
);
//- Return cell on other side of face. Throws error
// if face not internal.
label otherCell
(
const primitiveMesh&,
const label cellI,
const label faceI
);
//- Returns label of edge nEdges away from startEdge (in the direction
// of startVertI)
label walkFace
(
const primitiveMesh&,
const label faceI,
const label startEdgeI,
const label startVertI,
const label nEdges
);
// Constraints on position
//- Set the constrained components of position to mesh centre
void constrainToMeshCentre
(
const polyMesh& mesh,
point& pt
);
void constrainToMeshCentre
(
const polyMesh& mesh,
pointField& pt
);
//- Set the constrained components of directions/velocity to zero
void constrainDirection
(
const polyMesh& mesh,
const Vector<label>& dirs,
vector& d
);
void constrainDirection
(
const polyMesh& mesh,
const Vector<label>& dirs,
vectorField& d
);
// Hex only functionality
//- Given edge on hex find other 'parallel', non-connected edges.
void getParallelEdges
(
const primitiveMesh&,
const label cellI,
const label e0,
label&,
label&,
label&
);
//- Given edge on hex find all 'parallel' (i.e. non-connected)
// edges and average direction of them
vector edgeToCutDir
(
const primitiveMesh&,
const label cellI,
const label edgeI
);
//- Reverse of edgeToCutDir: given direction find edge bundle and
// return one of them.
label cutDirToEdge
(
const primitiveMesh&,
const label cellI,
const vector& cutDir
);
// Face information
//- Set face information: patch, zone and zone flip for a face
void setFaceInfo
(
const polyMesh& mesh,
const label faceI,
label& patchID,
label& zoneID,
label& zoneFlip
);
// Mark-up of mesh bits. Relocated from refinement polyMeshModifier
//- Extend marked cells across faces given a bool list of already marked
// cells
void extendMarkedCellsAcrossFaces
(
const polyMesh& mesh,
boolList& markedCell
);
//- Extend marked cells across points given a bool list of already
// marked cells
void extendMarkedCellsAcrossPoints
(
const polyMesh& mesh,
boolList& markedCell
);
} // End namespace refinementTools
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -27,7 +27,7 @@ License
#include "setUpdater.H" #include "setUpdater.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "mapPolyMesh.H" #include "mapPolyMesh.H"
#include "cellSet.H" #include "cellSet.H"
@ -71,7 +71,7 @@ bool Foam::setUpdater::changeTopology() const
} }
void Foam::setUpdater::setRefinement(polyTopoChange&) const void Foam::setUpdater::setRefinement(batchPolyTopoChange&) const
{} {}

View File

@ -97,7 +97,7 @@ public:
//- Insert the layer addition/removal instructions //- Insert the layer addition/removal instructions
// into the topological change // into the topological change
virtual void setRefinement(polyTopoChange&) const; virtual void setRefinement(batchPolyTopoChange&) const;
//- Modify motion points to comply with the topological change //- Modify motion points to comply with the topological change
virtual void modifyMotionPoints(pointField& motionPoints) const; virtual void modifyMotionPoints(pointField& motionPoints) const;

View File

@ -27,7 +27,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "slidingInterface.H" #include "slidingInterface.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "enrichedPatch.H" #include "enrichedPatch.H"
@ -69,7 +69,7 @@ const Foam::scalar Foam::slidingInterface::edgeCoPlanarTolDefault_ = 0.8;
// - - missed master edge in cut // - - missed master edge in cut
// u - edge already used in cutting // u - edge already used in cutting
void Foam::slidingInterface::coupleInterface(polyTopoChange& ref) const void Foam::slidingInterface::coupleInterface(batchPolyTopoChange& ref) const
{ {
if (debug) if (debug)
{ {

View File

@ -29,7 +29,7 @@ License
#include "slidingInterface.H" #include "slidingInterface.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyModifyFace.H" #include "polyModifyFace.H"
#include "polyModifyPoint.H" #include "polyModifyPoint.H"
@ -38,7 +38,7 @@ License
void Foam::slidingInterface::decoupleInterface void Foam::slidingInterface::decoupleInterface
( (
polyTopoChange& ref batchPolyTopoChange& ref
) const ) const
{ {
if (debug) if (debug)

View File

@ -29,7 +29,7 @@ License
#include "slidingInterface.H" #include "slidingInterface.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "plane.H" #include "plane.H"
@ -367,7 +367,7 @@ bool Foam::slidingInterface::changeTopology() const
} }
void Foam::slidingInterface::setRefinement(polyTopoChange& ref) const void Foam::slidingInterface::setRefinement(batchPolyTopoChange& ref) const
{ {
if (coupleDecouple_) if (coupleDecouple_)
{ {

View File

@ -264,19 +264,19 @@ private:
bool projectPoints() const; bool projectPoints() const;
//- Couple sliding interface //- Couple sliding interface
void coupleInterface(polyTopoChange& ref) const; void coupleInterface(batchPolyTopoChange& ref) const;
//- Clear projection //- Clear projection
void clearPointProjection() const; void clearPointProjection() const;
//- Clear old couple //- Clear old couple
void clearCouple(polyTopoChange& ref) const; void clearCouple(batchPolyTopoChange& ref) const;
//- Decouple interface (returns it to decoupled state) //- Decouple interface (returns it to decoupled state)
// Note: this should not be used in normal operation of the // Note: this should not be used in normal operation of the
// sliding mesh, but only to return the mesh to its // sliding mesh, but only to return the mesh to its
// original state // original state
void decoupleInterface(polyTopoChange& ref) const; void decoupleInterface(batchPolyTopoChange& ref) const;
// Static data members // Static data members
@ -364,7 +364,7 @@ public:
//- Insert the layer addition/removal instructions //- Insert the layer addition/removal instructions
// into the topological change // into the topological change
virtual void setRefinement(polyTopoChange&) const; virtual void setRefinement(batchPolyTopoChange&) const;
//- Modify motion points to comply with the topological change //- Modify motion points to comply with the topological change
virtual void modifyMotionPoints(pointField& motionPoints) const; virtual void modifyMotionPoints(pointField& motionPoints) const;

View File

@ -27,7 +27,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "slidingInterface.H" #include "slidingInterface.H"
#include "polyTopoChange.H" #include "batchPolyTopoChange.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "polyTopoChanger.H" #include "polyTopoChanger.H"
#include "polyRemovePoint.H" #include "polyRemovePoint.H"
@ -37,7 +37,7 @@ License
void Foam::slidingInterface::clearCouple void Foam::slidingInterface::clearCouple
( (
polyTopoChange& ref batchPolyTopoChange& ref
) const ) const
{ {
if (debug) if (debug)

View File

@ -976,34 +976,41 @@ void Foam::fvMesh::updateMesh(const mapPolyMesh& mpm)
if (VPtr_) if (VPtr_)
{ {
// Grab old time volumes if the time has been incremented if (mpm.hasOldCellVolumes())
// This will update V0, V00 {
storeOldVol(mpm.oldCellVolumes()); // Grab old time volumes if the time has been incremented
// This will update V0, V00
storeOldVol(mpm.oldCellVolumes());
// Few checks // Few checks
if (VPtr_ && (VPtr_->size() != mpm.nOldCells())) if (VPtr_ && (VPtr_->size() != mpm.nOldCells()))
{ {
FatalErrorInFunction FatalErrorInFunction
<< "V:" << VPtr_->size() << "V:" << VPtr_->size()
<< " not equal to the number of old cells " << " not equal to the number of old cells "
<< mpm.nOldCells() << mpm.nOldCells()
<< exit(FatalError); << exit(FatalError);
}
if (V0Ptr_ && (V0Ptr_->size() != mpm.nOldCells()))
{
FatalErrorInFunction
<< "V0:" << V0Ptr_->size()
<< " not equal to the number of old cells "
<< mpm.nOldCells()
<< exit(FatalError);
}
if (V00Ptr_ && (V00Ptr_->size() != mpm.nOldCells()))
{
FatalErrorInFunction
<< "V0:" << V00Ptr_->size()
<< " not equal to the number of old cells "
<< mpm.nOldCells()
<< exit(FatalError);
}
} }
if (V0Ptr_ && (V0Ptr_->size() != mpm.nOldCells())) else
{ {
FatalErrorInFunction deleteDemandDrivenData(VPtr_);
<< "V0:" << V0Ptr_->size()
<< " not equal to the number of old cells "
<< mpm.nOldCells()
<< exit(FatalError);
}
if (V00Ptr_ && (V00Ptr_->size() != mpm.nOldCells()))
{
FatalErrorInFunction
<< "V0:" << V00Ptr_->size()
<< " not equal to the number of old cells "
<< mpm.nOldCells()
<< exit(FatalError);
} }
} }

View File

@ -328,6 +328,8 @@ mappedPatches/mappedPolyPatch/mappedVariableThicknessWallPolyPatch.C
mappedPatches/mappedPointPatch/mappedPointPatch.C mappedPatches/mappedPointPatch/mappedPointPatch.C
mappedPatches/mappedPointPatch/mappedWallPointPatch.C mappedPatches/mappedPointPatch/mappedWallPointPatch.C
batchPolyTopoChange/batchPolyTopoChange.C
polyTopoChange/topoAction/topoActions.C polyTopoChange/topoAction/topoActions.C
polyTopoChange/polyTopoChange.C polyTopoChange/polyTopoChange.C

View File

@ -0,0 +1,417 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "batchPolyTopoChange.H"
#include "polyMesh.H"
#include "primitiveMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::label Foam::batchPolyTopoChange::minListSize = 100;
const Foam::label Foam::batchPolyTopoChange::pointFraction = 10;
const Foam::label Foam::batchPolyTopoChange::faceFraction = 10;
const Foam::label Foam::batchPolyTopoChange::cellFraction = 10;
namespace Foam
{
defineTypeNameAndDebug(batchPolyTopoChange, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from mesh reference
Foam::batchPolyTopoChange::batchPolyTopoChange(const polyMesh& mesh)
:
mesh_(mesh),
addedPoints_(minListSize),
modifiedPoints_(minListSize),
removedPoints_
(
Foam::max(mesh.points().size()/pointFraction, minListSize)
),
addedFaces_(minListSize),
modifiedFaces_(minListSize),
removedFaces_(Foam::max(mesh.faces().size()/faceFraction, minListSize)),
addedCells_(minListSize),
removedCells_(Foam::max(mesh.nCells()/cellFraction, minListSize))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::batchPolyTopoChange::setAction(const topoAction& action)
{
if (isType<polyAddPoint>(action))
{
addedPoints_.append(refCast<const polyAddPoint>(action));
return mesh_.points().size() + addedPoints_.size() - 1;
}
else if (isType<polyModifyPoint>(action))
{
const polyModifyPoint& pmp = refCast<const polyModifyPoint>(action);
if (debug)
{
if (removedPoints_.find(pmp.pointID()) != removedPoints_.end())
{
FatalErrorInFunction
<< "Modifying point " << pmp.pointID()
<< " for the second time or modifying a removed point. "
<< "This is not allowed."
<< abort(FatalError);
}
}
modifiedPoints_.append(pmp);
removedPoints_.insert(pmp.pointID());
return -1;
}
else if (isType<polyRemovePoint>(action))
{
const polyRemovePoint& prp = refCast<const polyRemovePoint>(action);
if (debug)
{
if (removedPoints_.find(prp.pointID()) != removedPoints_.end())
{
FatalErrorInFunction
<< "Removing point " << prp.pointID()
<< " for the second time or removing a modified point. "
<< "This is not allowed."
<< abort(FatalError);
}
}
removedPoints_.insert(prp.pointID());
return -1;
}
else if (isType<polyAddFace>(action))
{
addedFaces_.append(refCast<const polyAddFace>(action));
return mesh_.faces().size() + addedFaces_.size() - 1;
}
else if (isType<polyModifyFace>(action))
{
const polyModifyFace& pmf = refCast<const polyModifyFace>(action);
if (debug)
{
if (removedFaces_.find(pmf.faceID()) != removedFaces_.end())
{
FatalErrorInFunction
<< "Modifying face " << pmf.faceID()
<< " for the second time or modifying a removed face. "
<< "This is not allowed."
<< abort(FatalError);
}
}
modifiedFaces_.append(pmf);
removedFaces_.insert(pmf.faceID());
return -1;
}
else if (isType<polyRemoveFace>(action))
{
const polyRemoveFace& prf = refCast<const polyRemoveFace>(action);
if (debug)
{
if (removedFaces_.find(prf.faceID()) != removedFaces_.end())
{
FatalErrorInFunction
<< "Removing face " << prf.faceID()
<< " for the second time or removing a modified face. "
<< "This is not allowed."
<< abort(FatalError);
}
}
removedFaces_.insert(prf.faceID());
return -1;
}
else if (isType<polyAddCell>(action))
{
addedCells_.append(refCast<const polyAddCell>(action));
return mesh_.nCells() + addedCells_.size() - 1;
}
else if (isType<polyModifyCell>(action))
{
const polyModifyCell& pmc = refCast<const polyModifyCell>(action);
modifiedCells_.append(pmc);
return -1;
}
else if (isType<polyRemoveCell>(action))
{
const polyRemoveCell& prc = refCast<const polyRemoveCell>(action);
if (debug)
{
if (removedCells_.find(prc.cellID()) != removedCells_.end())
{
FatalErrorInFunction
<< "Removing cell " << prc.cellID()
<< " for the second time. This is not allowed."
<< abort(FatalError);
}
}
removedCells_.insert(prc.cellID());
return -1;
}
else
{
FatalErrorInFunction
<< "Unknown type of topoChange: " << action.type()
<< abort(FatalError);
// Dummy return to keep compiler happy
return -1;
}
}
bool Foam::batchPolyTopoChange::check() const
{
if (debug)
{
Info<< "Points: added = " << addedPoints_.size()
<< " modified = " << modifiedPoints_.size()
<< " removed = " << removedPoints_.size() - modifiedPoints_.size()
<< " balance = " << pointBalance()
<< endl;
Info<< "Faces: added = " << addedFaces_.size()
<< " modified = " << modifiedFaces_.size()
<< " removed = " << removedFaces_.size() - modifiedFaces_.size()
<< " balance = " << faceBalance()
<< endl;
Info<< "Cells: added = " << addedCells_.size()
<< " modified = " << modifiedCells_.size()
<< " removed = " << removedCells_.size() - modifiedCells_.size()
<< " balance = " << cellBalance()
<< endl;
}
label nErrors = 0;
// Check points
if (mesh_.points().size() + pointBalance() < 4)
{
WarningInFunction
<< "Less than 4 points in the mesh. This cannot be a valid mesh."
<< endl;
nErrors++;
}
// Collect zone-only and removed points
labelHashSet zoneOnlyPoints(removedPoints_);
forAll (modifiedPoints_, mpI)
{
if (modifiedPoints_[mpI].inCell())
{
// Point is live; remove from lookup
zoneOnlyPoints.erase
(
zoneOnlyPoints.find(modifiedPoints_[mpI].pointID())
);
}
}
forAll (addedPoints_, apI)
{
if (!addedPoints_[apI].inCell())
{
zoneOnlyPoints.insert(mesh_.points().size() + apI);
}
}
// Check faces
label nFaceErrors = 0;
label nCurFaceError = 0;
// For all live modified and added faces, check that points are also live
// Collect zone-only faces
labelHashSet zoneOnlyFaces(removedFaces_);
// Modified faces
forAll (modifiedFaces_, mfI)
{
if (!modifiedFaces_[mfI].onlyInZone())
{
// Face is live; remove from lookup
zoneOnlyFaces.erase
(
zoneOnlyFaces.find(modifiedFaces_[mfI].faceID())
);
// Count errors in current face
nCurFaceError = 0;
const face& curFace = modifiedFaces_[mfI].newFace();
forAll (curFace, pointI)
{
if (zoneOnlyPoints.found(curFace[pointI]))
{
nCurFaceError++;
}
}
if (nCurFaceError > 0)
{
if (debug)
{
Info<< "Modified face no " << mfI << " is active but uses "
<< nCurFaceError << " zone-only or removed points. "
<< "Face: " << curFace << " Problem points:";
forAll (curFace, pointI)
{
if (zoneOnlyPoints.found(curFace[pointI]))
{
Info << " " << curFace[pointI];
}
}
Info << endl;
}
nFaceErrors++;
}
}
}
// Added faces
forAll (addedFaces_, afI)
{
if (addedFaces_[afI].onlyInZone())
{
// Zone-only face; add to hash set
zoneOnlyFaces.insert(mesh_.faces().size() + afI);
}
else
{
// Count errors in current face
nCurFaceError = 0;
const face& curFace = addedFaces_[afI].newFace();
forAll (curFace, pointI)
{
if (zoneOnlyPoints.found(curFace[pointI]))
{
nCurFaceError++;
}
}
if (nCurFaceError > 0)
{
if (debug)
{
Info<< "Added face no " << afI << " is active but uses "
<< nCurFaceError << " zone-only or removed points. "
<< "Face: " << curFace << " Problem points:";
forAll (curFace, pointI)
{
if (zoneOnlyPoints.found(curFace[pointI]))
{
Info << " " << curFace[pointI];
}
}
Info << endl;
}
nFaceErrors++;
}
}
}
// Check cells?
if (nErrors == 0)
{
if (debug)
{
Info << "batchPolyTopoChange OK" << endl;
}
return false;
}
else
{
if (debug)
{
Info<< "bool batchPolyTopoChange::check() const : "
<< "Detected " << nErrors << " errors."
<< endl;
}
return true;
}
}
void Foam::batchPolyTopoChange::clear()
{
if (debug)
{
Info<< "void Foam::batchPolyTopoChange::clear() : "
<< "clearing topological change request" << endl;
}
// Clear all contents
addedPoints_.clear();
modifiedPoints_.clear();
removedPoints_.clear();
addedFaces_.clear();
modifiedFaces_.clear();
removedFaces_.clear();
addedCells_.clear();
removedCells_.clear();
}
// ************************************************************************* //

View File

@ -0,0 +1,256 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
batchPolyTopoChange
Description
Class accumulates information on how to perform mesh refinement.
Once the refinement request is completed, polyMesh modifies the mesh
topology.
SourceFiles
batchPolyTopoChange.C
\*---------------------------------------------------------------------------*/
#ifndef batchPolyTopoChange_H
#define batchPolyTopoChange_H
#include "DynamicList.H"
#include "HashSet.H"
#include "polyAddPoint.H"
#include "polyModifyPoint.H"
#include "polyRemovePoint.H"
#include "polyAddFace.H"
#include "polyModifyFace.H"
#include "polyRemoveFace.H"
#include "polyAddCell.H"
#include "polyModifyCell.H"
#include "polyRemoveCell.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class polyMesh;
/*---------------------------------------------------------------------------*\
Class batchPolyTopoChange Declaration
\*---------------------------------------------------------------------------*/
class batchPolyTopoChange
{
// Private data
//- Reference to mesh to be refined
const polyMesh& mesh_;
//- Points to add
DynamicList<polyAddPoint> addedPoints_;
//- Points to modify
DynamicList<polyModifyPoint> modifiedPoints_;
//- Points to remove
labelHashSet removedPoints_;
//- Faces to add
DynamicList<polyAddFace> addedFaces_;
//- Faces to modify
DynamicList<polyModifyFace> modifiedFaces_;
//- Faces to remove
labelHashSet removedFaces_;
//- Number of cells to add
DynamicList<polyAddCell> addedCells_;
//- Cells to modify
DynamicList<polyModifyCell> modifiedCells_;
//- Cells to remove
labelHashSet removedCells_;
// Private Member Functions
//- Disallow default bitwise copy construct
batchPolyTopoChange(const batchPolyTopoChange&) = delete;
//- Disallow default bitwise assignment
void operator=(const batchPolyTopoChange&) = delete;
// Private static data
//- Minimum dynamic list size for object insertion
static const label minListSize;
//- Estimated fraction of removed points
static const label pointFraction;
//- Estimated fraction of removed faces
static const label faceFraction;
//- Estimated fraction of removed cells
static const label cellFraction;
public:
//- Runtime type information
ClassName("batchPolyTopoChange");
// Constructors
//- Construct from mesh reference
batchPolyTopoChange(const polyMesh&);
//- Destructor
~batchPolyTopoChange() = default;
// Member Functions
// Definition of topological change
//- Set topological action
label setAction(const topoAction& action);
// Topology morph data
//- Is point removed?
inline bool pointRemoved(const label pointI) const;
//- Is face removed?
inline bool faceRemoved(const label faceI) const;
//- Is cell removed?
inline bool cellRemoved(const label cellI) const;
//- Point balance (added - removed)
label pointBalance() const
{
return
addedPoints_.size()
+ modifiedPoints_.size()
- removedPoints_.size();
}
//- Face balance (added - removed)
label faceBalance() const
{
return
addedFaces_.size()
+ modifiedFaces_.size()
- removedFaces_.size();
}
//- Cell balance (added - removed)
label cellBalance() const
{
return addedCells_.size() - removedCells_.size();
}
//- Added points
const DynamicList<polyAddPoint>& addedPoints() const
{
return addedPoints_;
}
//- Modified points
const DynamicList<polyModifyPoint>& modifiedPoints() const
{
return modifiedPoints_;
}
//- Map of removed points
const labelHashSet& removedPoints() const
{
return removedPoints_;
}
//- Added faces
const DynamicList<polyAddFace>& addedFaces() const
{
return addedFaces_;
}
//- Modified faces
const DynamicList<polyModifyFace>& modifiedFaces() const
{
return modifiedFaces_;
}
//- Map of removed faces
const labelHashSet& removedFaces() const
{
return removedFaces_;
}
//- Added cells
const DynamicList<polyAddCell>& addedCells() const
{
return addedCells_;
}
//- Modified cells
const DynamicList<polyModifyCell>& modifiedCells() const
{
return modifiedCells_;
}
//- Map of removed cells
const labelHashSet& removedCells() const
{
return removedCells_;
}
//- Check for consistency and report status
// Returns false for no error.
bool check() const;
//- Clear all contents
void clear();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "batchPolyTopoChangeI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,47 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline bool Foam::batchPolyTopoChange::pointRemoved(const label pointI) const
{
return removedPoints().found(pointI);
}
inline bool Foam::batchPolyTopoChange::faceRemoved(const label faceI) const
{
return removedFaces().found(faceI);
}
inline bool Foam::batchPolyTopoChange::cellRemoved(const label cellI) const
{
return removedCells().found(cellI);
}
// ************************************************************************* //

View File

@ -30,6 +30,7 @@ License
#include "polyMesh.H" #include "polyMesh.H"
#include "hexMatcher.H" #include "hexMatcher.H"
#include "treeBoundBox.H" #include "treeBoundBox.H"
#include "syncTools.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -878,4 +879,157 @@ Foam::label Foam::meshTools::cutDirToEdge
} }
void Foam::meshTools::setFaceInfo
(
const polyMesh& mesh,
const label faceI,
label& patchID,
label& zoneID,
label& zoneFlip
)
{
patchID = -1;
if (!mesh.isInternalFace(faceI))
{
patchID = mesh.boundaryMesh().whichPatch(faceI);
}
zoneID = mesh.faceZones().whichZone(faceI);
zoneFlip = false;
if (zoneID > -1)
{
const faceZone& fZone = mesh.faceZones()[zoneID];
zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
}
}
void Foam::meshTools::extendMarkedCellsAcrossFaces
(
const polyMesh& mesh,
boolList& markedCell
)
{
// Mark all faces for all marked cells
const label nFaces = mesh.nFaces();
boolList markedFace(nFaces, false);
// Get mesh cells
const cellList& meshCells = mesh.cells();
// Loop through all cells
forAll (markedCell, cellI)
{
if (markedCell[cellI])
{
// This cell is marked, get its faces
const cell& cFaces = meshCells[cellI];
forAll (cFaces, i)
{
markedFace[cFaces[i]] = true;
}
}
}
// Snyc the face list across processor boundaries
syncTools::syncFaceList(mesh, markedFace, orEqOp<bool>());//HJ
// Get necessary mesh data
const label nInternalFaces = mesh.nInternalFaces();
const labelList& owner = mesh.faceOwner();
const labelList& neighbour = mesh.faceNeighbour();
// Internal faces
for (label faceI = 0; faceI < nInternalFaces; ++faceI)
{
if (markedFace[faceI])
{
// Face is marked, mark both owner and neighbour
const label& own = owner[faceI];
const label& nei = neighbour[faceI];
// Mark owner and neighbour cells
markedCell[own] = true;
markedCell[nei] = true;
}
}
// Boundary faces
for (label faceI = nInternalFaces; faceI < nFaces; ++faceI)
{
if (markedFace[faceI])
{
// Face is marked, mark owner
const label& own = owner[faceI];
// Mark owner
markedCell[own] = true;
}
}
}
void Foam::meshTools::extendMarkedCellsAcrossPoints
(
const polyMesh& mesh,
boolList& markedCell
)
{
// Mark all points for all marked cells
const label nPoints = mesh.nPoints();
boolList markedPoint(nPoints, false);
// Get cell points
const labelListList& meshCellPoints = mesh.cellPoints();
// Loop through all cells
forAll (markedCell, cellI)
{
if (markedCell[cellI])
{
// This cell is marked, get its points
const labelList& cPoints = meshCellPoints[cellI];
forAll (cPoints, i)
{
markedPoint[cPoints[i]] = true;
}
}
}
// Snyc point list across processor boundaries
syncTools::syncPointList
(
mesh,
markedPoint,
orEqOp<bool>(),
true // Default value
// true // Apply separation for parallel cyclics //HJ
);
// Get point cells
const labelListList& meshPointCells = mesh.pointCells();
// Loop through all points
forAll (markedPoint, pointI)
{
if (markedPoint[pointI])
{
// This point is marked, mark all of its cells
const labelList& pCells = meshPointCells[pointI];
forAll (pCells, i)
{
markedCell[pCells[i]] = true;
}
}
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -352,6 +352,37 @@ namespace meshTools
const vector& cutDir const vector& cutDir
); );
// Face information
//- Set face information: patch, zone and zone flip for a face
void setFaceInfo
(
const polyMesh& mesh,
const label faceI,
label& patchID,
label& zoneID,
label& zoneFlip
);
// Mark-up of mesh bits. Relocated from refinement polyMeshModifier
//- Extend marked cells across faces given a bool list of already marked
// cells
void extendMarkedCellsAcrossFaces
(
const polyMesh& mesh,
boolList& markedCell
);
//- Extend marked cells across points given a bool list of already
// marked cells
void extendMarkedCellsAcrossPoints
(
const polyMesh& mesh,
boolList& markedCell
);
} // End namespace meshTools } // End namespace meshTools

View File

@ -11,4 +11,14 @@ movingConeTopoFvMesh/movingConeTopoFvMesh.C
mixerFvMesh/mixerFvMesh.C mixerFvMesh/mixerFvMesh.C
*/ */
dynamicPolyRefinementFvMesh/dynamicPolyRefinementFvMesh.C
dynamicPolyRefinementFvMesh/refinementSelection/refinementSelection/refinementSelection.C
dynamicPolyRefinementFvMesh/refinementSelection/fieldBoundsRefinement/fieldBoundsRefinement.C
dynamicPolyRefinementFvMesh/refinementSelection/minCellVolumeRefinement/minCellVolumeRefinement.C
dynamicPolyRefinementFvMesh/refinementSelection/minCellSizeRefinement/minCellSizeRefinement.C
dynamicPolyRefinementFvMesh/refinementSelection/minPatchDistanceRefinement/minPatchDistanceRefinement.C
dynamicPolyRefinementFvMesh/refinementSelection/protectedInitialRefinement/protectedInitialRefinement.C
dynamicPolyRefinementFvMesh/refinementSelection/minFaceArea2DRefinement/minFaceArea2DRefinement.C
dynamicPolyRefinementFvMesh/refinementSelection/compositeRefinementSelection/compositeRefinementSelection.C
LIB = $(FOAM_LIBBIN)/libtopoChangerFvMesh LIB = $(FOAM_LIBBIN)/libtopoChangerFvMesh

View File

@ -1,5 +1,6 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/optimisation/adjointOptimisation/adjoint/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude \ -I$(LIB_SRC)/surfMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
@ -8,6 +9,7 @@ EXE_INC = \
LIB_LIBS = \ LIB_LIBS = \
-lfiniteVolume \ -lfiniteVolume \
-l adjointOptimisation \
-lfileFormats \ -lfileFormats \
-lsurfMesh \ -lsurfMesh \
-lmeshTools \ -lmeshTools \

View File

@ -100,7 +100,7 @@ bool Foam::dynamicMotionSolverTopoFvMesh::update()
// (TBD: should be in changeMesh if no inflation?) // (TBD: should be in changeMesh if no inflation?)
moving(false); moving(false);
// Do mesh changes (not using inflation - points added directly into mesh) // Do mesh changes (not using inflation - points added directly into mesh)
autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(false); autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
if (topoChangeMap) if (topoChangeMap)
{ {

View File

@ -0,0 +1,73 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | foam-extend: Open Source CFD |
| \\ / O peration | Version: 5.0 |
| \\ / A nd | Web: http://www.foam-extend.org |
| \\/ M anipulation | For copyright notice see file Copyright |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object dynamicMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dynamicFvMesh dynamicPolyRefinementFvMesh;
dynamicPolyRefinementFvMeshCoeffs
{
// Dynamic mesh procedure controls
// Refine every refineInterval step
refineInterval 1;
// Unrefine every unrefineInterval step
unrefineInterval 1;
// Separate refinement/unrefinement steps. In case this is switched on,
// if both refinement and unrefinement should have been performed in a
// single step, unrefinement is skipped. Switched off by default, meaning
// that it should be safe to perform both at the same time
separateUpdates false;
// Refinement selection criteria
refinementSelection
{
// Refines all cells with 0.001 < alpha < 0.999, otherwise unrefines
// previously refined cells
type fieldBoundsRefinement;
fieldName alpha;
lowerBound 0.001;
upperBound 0.999;
// Whether to use cell-point-cell smoothing for selecting refinement
// candidates. Off by default
cellPointCellSmoothing off;
}
// Polyhedral refinement engine controls
active yes;
// Maximum number of cells to allow (not strictly controlled)
maxCells 2000000;
// Maximum refinement level
maxRefinementLevel 3;
// Number of buffer layers between refinement levels
nRefinementBufferLayers 1;
// Number of buffer layers for unrefinement in order to run away from the
// region that is getting refined at the same time in order to avoid point
// level inconsistencies
nUnrefinementBufferLayers 4;
// Whether to use edge based consistency check. Needed when one allows more
// than 2 refinement levels (automatically switched on)
edgeBasedConsistency yes;
}
// ************************************************************************* //

View File

@ -0,0 +1,366 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "dynamicPolyRefinementFvMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "refinementSelection.H"
#include "prismatic2DRefinement.H"
#include "polyhedralRefinement.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(dynamicPolyRefinementFvMesh, 0);
addToRunTimeSelectionTable
(
dynamicFvMesh,
dynamicPolyRefinementFvMesh,
IOobject
);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::dynamicPolyRefinementFvMesh::readDict()
{
// Read and check refinement and unrefinement intervals
refineInterval_ = readLabel(refinementDict_.lookup("refineInterval"));
if (refineInterval_ < 1)
{
FatalErrorInFunction
<< "Illegal refineInterval found: " << refineInterval_ << nl
<< "The refineInterval controls the refinement"
<< " trigerring within a certain time step and should be > 0"
<< exit(FatalError);
}
unrefineInterval_ = readLabel(refinementDict_.lookup("unrefineInterval"));
if (refineInterval_ < 1)
{
FatalErrorInFunction
<< "Illegal unrefineInterval found: " << refineInterval_ << nl
<< "The unrefineInterval controls the unrefinement"
<< " trigerring within a certain time step and should be > 0"
<< exit(FatalError);
}
// Read separate updates switch
separateUpdates_ =
refinementDict_.lookupOrDefault<Switch>("separateUpdates", false);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dynamicPolyRefinementFvMesh::dynamicPolyRefinementFvMesh
(
const IOobject& io,
const word subDictName
)
:
topoChangerFvMesh(io),
refinementDict_
(
IOdictionary
(
IOobject
(
"dynamicMeshDict",
time().constant(),
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
).subDict(subDictName + "Coeffs")
),
refineInterval_(readLabel(refinementDict_.lookup("refineInterval"))),
unrefineInterval_(readLabel(refinementDict_.lookup("unrefineInterval"))),
separateUpdates_
(
refinementDict_.lookupOrDefault<Switch>("separateUpdates", false)
),
curTimeIndex_(-1),
// Note: initialize refinement selection algorithm after the refinement
// polyMeshModifier has been set. It is possible that the selection
// algorithm needs cellLevel and pointLevel (see e.g.
// protectedInitialRefinement)
refinementSelectionPtr_()
{
// Check whether we read polyMeshModifiers from
// constant/polyMesh/meshModifiers file in the base class
if (!topoChanger_.empty())
{
// Already initialized, warn the user that we'll neglect it
WarningInFunction
<< "Using controls from constant/dynamicMeshDict instead of"
<< " constant/polyMesh/meshModifiers."
<< nl
<< "To supress this warning, delete meshModifiers file."
<< endl;
// Clear the list
topoChanger_.clear();
}
// Only one topo changer engine
topoChanger_.setSize(1);
// Get number of valid geometric dimensions
const label nGeometricDirs = this->nGeometricD();
switch (nGeometricDirs)
{
case 3:
// Add the polyhedralRefinement engine for
// 3D isotropic refinement
Info<< "3D case detected. "
<< "Adding polyhedralRefinement topology modifier" << endl;
topoChanger_.set
(
0,
new polyhedralRefinement
(
"polyhedralRefinement",
refinementDict_,
0,
topoChanger_
)
);
break;
case 2:
// Add the prismatic2DRefinement engine for
// 2D isotropic refinement
Info<< "2D case detected. "
<< "Adding prismatic2DRefinement topology modifier" << endl;
topoChanger_.set
(
0,
new prismatic2DRefinement
(
"prismatic2DRefinement",
refinementDict_,
0,
topoChanger_
)
);
break;
case 1:
FatalErrorInFunction
<< "1D case detected. No valid refinement strategy is"
<< " available for 1D cases."
<< abort(FatalError);
break;
default:
FatalErrorInFunction
<< "Invalid number of geometric meshes detected: "
<< nGeometricDirs
<< nl << "It appears that this mesh is neither 1D, 2D or 3D."
<< abort(FatalError);
}
// Write mesh and modifiers
topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
topoChanger_.write();
write();
// Initialize refinement selection algorithm after modifiers
refinementSelectionPtr_ = refinementSelection::New(*this, refinementDict_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::dynamicPolyRefinementFvMesh::firstUpdate() const
{
return curTimeIndex_ < time().timeIndex();
}
bool Foam::dynamicPolyRefinementFvMesh::update()
{
// Re-read the data from dictionary for on-the-fly changes
readDict();
// Performing refinement/unrefinement when:
// 1. We are at the first time step
// 2. Only once per time step
// 3. Time step is a multiplier of specified refineInterval or
// unrefineInterval
// Get time index
const label timeID = time().timeIndex();
// Check whether to perform refinement and/or unrefinement
const bool performRefinement = timeID % refineInterval_ == 0;
// Skip performing refinement/unrefinement in the same step if
// separateUpdates flag is switched on
bool performUnrefinement = timeID % unrefineInterval_ == 0;
if (performRefinement && separateUpdates_)
{
performUnrefinement = false;
}
if
(
timeID > 0
&& curTimeIndex_ < timeID
&& (performRefinement || performUnrefinement)
)
{
// Update current time index to skip multiple topo changes per single
// time step
curTimeIndex_ = time().timeIndex();
// Get reference to base class refinement polyMeshModifier
refinement& refModifier = refCast<refinement>(topoChanger_[0]);
// Create empty list for refinement candidates
labelList refCandidates;
// Collect refinement candidates from refinement selection algorithm in
// case the refinement should be performed in this time step
if (performRefinement)
{
// Note: return type is Xfer<labelList> so there's no copying (two
// transfers are occuring)
refCandidates =
refinementSelectionPtr_->refinementCellCandidates();
Info<< "Selected " << refCandidates.size()
<< " refinement candidates."
<< endl;
}
else
{
Info<< "Skipping refinement for this time-step..." << endl;
}
// Set cells to refine. Note: refinement needs to make sure that face
// and point consistent refinement is performed
refModifier.setCellsToRefine(refCandidates);
// Create empty list for unrefinement candidates
labelList unrefCandidates;
// Collect unrefinement candidates from refinement selection algorithm
// in case the unrefinement should be performed in this time step
if (performUnrefinement)
{
// Note: return type is Xfer<labelList> so there's no copying (two
// transfers are occuring)
unrefCandidates =
refinementSelectionPtr_->unrefinementPointCandidates();
Info<< "Selected " << unrefCandidates.size()
<< " unrefinement candidates."
<< endl;
}
else
{
Info<< "Skipping unrefinement for this time-step..." << endl;
}
// Set split points to unrefine around.
// Notes:
// 1. refinement needs to make sure that only a consistent set of split
// points is used for unrefinement
// 2. Must be called after refinement::setCellsToRefine
refModifier.setSplitPointsToUnrefine(unrefCandidates);
// Activate the polyhedral refinement engine if there are some cells to
// refine or there are some split points to unrefine around
bool enableTopoChange =
!refCandidates.empty() || !unrefCandidates.empty();
// Note: must enable topo change for all processors since face and point
// consistent refinement must be ensured across coupled patches
reduce(enableTopoChange, orOp<bool>());
if (enableTopoChange)
{
refModifier.enable();
}
else
{
refModifier.disable();
}
// Perform refinement and unrefinement in one go
autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
// Output cell balance if the topo change has been performed
const label nOldCells =
returnReduce(topoChangeMap->nOldCells(), sumOp<label>());
const label sizeCellMap =
returnReduce(topoChangeMap->cellMap().size(), sumOp<label>());
// If the size of cell map is different than zero, we actually performed
// some topo changes
if (sizeCellMap)
{
Info<< "Successfully performed polyhedral refinement. "
<< "Changed from " << nOldCells << " to " << sizeCellMap
<< " cells." << endl;
}
else
{
Info<< "Refinement/unrefinement not performed in this time step "
<< "since no cells were selected." << endl;
}
return true;
// Note: OpenFOAM does not have a morphing signalling
// return topoChangeMap->morphing();
}
else
{
// Update current time index to skip multiple topo change checks
// per time step
curTimeIndex_ = time().timeIndex();
}
Info<< "No refinement/unrefinement" << endl;
// No refinement/unrefinement at this time step. Return false
return false;
}
// ************************************************************************* //

View File

@ -0,0 +1,158 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::dynamicPolyRefinementFvMesh
Description
Adaptive mesh refinement for isotropic refinement of arbitrary polyhedral
cells in 3D and arbitrary prismatic cells in 2D.
Automatically switches between:
- 3D refinement uses polyhedralRefinement engine
- 2D refinement uses prismatic2DRefinement engine
SourceFiles
dynamicPolyRefinementFvMesh.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved
Rewrite and updates by Hrvoje Jasak, Wikki Ltd. All rights reserved
Notes
Generalisation and refactorisation of dynamicRefineMesh for polyhedral cells
in 3D and prismatic cells in 2D.
\*---------------------------------------------------------------------------*/
#ifndef dynamicPolyRefinementFvMesh_H
#define dynamicPolyRefinementFvMesh_H
#include "topoChangerFvMesh.H"
#include "refinementSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class dynamicPolyRefinementFvMesh Declaration
\*---------------------------------------------------------------------------*/
class dynamicPolyRefinementFvMesh
:
public topoChangerFvMesh
{
protected:
// Protected data
//- Dictionary containing dynamic mesh coefficient controls
dictionary refinementDict_;
private:
// Private data
//- Refinement interval
label refineInterval_;
//- Unrefinement interval
label unrefineInterval_;
//- Separate refinement/unrefinement: off by default, meaning that
// refinement and unrefinement can be performed in the same step
Switch separateUpdates_;
//- Current time index (helper variable to skip multiple topo changes in
// a single time step)
label curTimeIndex_;
//- Refinement selection algorithm that has two jobs:
// 1. Selects cells to refine from all cells
// 2. Selects split points that are ok to refine based on given set of
// all split points
autoPtr<refinementSelection> refinementSelectionPtr_;
// Private Member Functions
//- Helper function for reading the dictionary and updating the data
void readDict();
// Copy control
//- Disallow default bitwise copy construct
dynamicPolyRefinementFvMesh
(
const dynamicPolyRefinementFvMesh&
) = delete;
//- Disallow default bitwise assignment
void operator=(const dynamicPolyRefinementFvMesh&) = delete;
public:
//- Runtime type information
TypeName("dynamicPolyRefinementFvMesh");
// Constructors
//- Construct from IOobject and optional name for the subdictionary
// containing the refinement (and possibly other controls). The second
// parameter is useful if we derive another dynamic mesh class from
// this one instead of topoChangerFvMesh base class. VV, 17/May/2018.
dynamicPolyRefinementFvMesh
(
const IOobject& io,
const word subDictName = typeName
);
//- Destructor
virtual ~dynamicPolyRefinementFvMesh() = default;
// Member Functions
//- Is this the first update in the current time-step?
bool firstUpdate() const;
//- Update the mesh for topology change
virtual bool update();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,206 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "compositeRefinementSelection.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(compositeRefinementSelection, 0);
addToRunTimeSelectionTable
(
refinementSelection,
compositeRefinementSelection,
dictionary
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::compositeRefinementSelection::compositeRefinementSelection
(
const fvMesh& mesh,
const dictionary& dict
)
:
refinementSelection(mesh, dict),
baseRefinementSelections_()
{
// Read basic refinement selections
PtrList<entry> baseRefSelectionEntries
(
coeffDict().lookup("baseRefinementSelections")
);
baseRefinementSelections_.setSize(baseRefSelectionEntries.size());
forAll (baseRefinementSelections_, brsI)
{
baseRefinementSelections_.set
(
brsI,
refinementSelection::New
(
mesh,
baseRefSelectionEntries[brsI].dict()
)
);
}
}
// * * * * * * * * * * * * * * * * Destructor* * * * * * * * * * * * * * * * //
Foam::compositeRefinementSelection::~compositeRefinementSelection()
{}
// * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * * //
Foam::labelList
Foam::compositeRefinementSelection::refinementCellCandidates() const
{
// Final refinement cell candidates are defined as the intersection of all
// sets (obtained with different refinement selection algorithms)
// In order to define the intersection in a straightforward and efficient
// way, we will create a labelField for all cells counting the number of
// times this cell has been selected for refinement. If all selection
// algorithms have selected the cell, this cell is marked as a final
// refinement candidate.
// Create field counting the number of selections
labelField nSelections(mesh().nCells(), 0);
// Loop through all base refinement selections
forAll (baseRefinementSelections_, brsI)
{
// Get refinement candidates from this base selection algorithm. Note:
// list is transferred
const labelList curRefCandidates
(
baseRefinementSelections_[brsI].refinementCellCandidates()
);
// Increment the number of selections for selected cells
forAll (curRefCandidates, i)
{
++nSelections[curRefCandidates[i]];
}
}
// Create storage for collection of final cell candidates. Assume that
// one fifth of the cells will be marked to prevent excessive resizing
DynamicList<label> refinementCandidates(mesh().nCells()/5);
// Get number of active selection algorithms
const label nBaseSelections = baseRefinementSelections_.size();
// Loop through all cells and collect final refinement candidates
forAll (nSelections, cellI)
{
if (nSelections[cellI] == nBaseSelections)
{
// Cell has been marked by all selection algorithms, append it
refinementCandidates.append(cellI);
}
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(refinementCandidates.size(), sumOp<label>())
<< " cells as refinement candidates."
<< endl;
return refinementCandidates;
}
Foam::labelList
Foam::compositeRefinementSelection::unrefinementPointCandidates() const
{
// Final unrefinement point candidates are defined as the intersection of
// all sets (obtained with different refinement selection algorithms) In
// order to define the intersection in a straightforward and efficient way,
// we will create a labelField for all points counting the number of times
// this point has been selected for unrefinement. If all selection
// algorithms have selected the point, this point is marked as a final
// unrefinement split point candidate.
// Create a field counting the number of selections
labelField nSelections(mesh().nPoints(), 0);
// Loop through all base refinement selections
forAll (baseRefinementSelections_, brsI)
{
// Get unrefinement candidates from this base selection algorithm. Note:
// list is transferred
const labelList curUnrefCandidates
(
baseRefinementSelections_[brsI].unrefinementPointCandidates()
);
// Increment the number of selections for selected points
forAll (curUnrefCandidates, i)
{
++nSelections[curUnrefCandidates[i]];
}
}
// Create storage for collection of final point candidates. Assume that one
// tenth of the points will be marked to prevent excessive resizing
DynamicList<label> unrefinementCandidates(mesh().nPoints()/10);
// Get number of active selection algorithms
const label nBaseSelections = baseRefinementSelections_.size();
// Loop through all points and collect final unrefinement candidates
forAll (nSelections, pointI)
{
if (nSelections[pointI] == nBaseSelections)
{
// Point has been marked by all selection algorithms, append it
unrefinementCandidates.append(pointI);
}
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(unrefinementCandidates.size(), sumOp<label>())
<< " points as unrefinement candidates."
<< endl;
return unrefinementCandidates;
}
// ************************************************************************* //

View File

@ -0,0 +1,112 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::compositeRefinementSelection
Description
Selection of refinement cells based on an arbitrary number of combined
"basic" selection algorithms.
SourceFiles
compositeRefinementSelection.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef compositeRefinementSelection_H
#define compositeRefinementSelection_H
#include "refinementSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class compositeRefinementSelection Declaration
\*---------------------------------------------------------------------------*/
class compositeRefinementSelection
:
public refinementSelection
{
// Private data
//- List of basic refinement selection algorithms
PtrList<refinementSelection> baseRefinementSelections_;
// Private Member Functions
//- Disallow default bitwise copy construct
compositeRefinementSelection(const compositeRefinementSelection&);
//- Disallow default bitwise assignment
void operator=(const compositeRefinementSelection&);
public:
//- Runtime type information
TypeName("compositeRefinementSelection");
// Constructors
//- Construct from components
compositeRefinementSelection
(
const fvMesh& mesh,
const dictionary& dict
);
//- Destructor
virtual ~compositeRefinementSelection();
// Member Functions
// Selection of refinement/unrefinement candidates
//- Return transferable list of cells to refine
virtual labelList refinementCellCandidates() const;
//- Return transferable list of split points to unrefine
virtual labelList unrefinementPointCandidates() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,187 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "fieldBoundsRefinement.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
#include "pointFields.H"
#include "volPointInterpolation.H"
#include "pointVolInterpolation.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(fieldBoundsRefinement, 0);
addToRunTimeSelectionTable
(
refinementSelection,
fieldBoundsRefinement,
dictionary
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fieldBoundsRefinement::fieldBoundsRefinement
(
const fvMesh& mesh,
const dictionary& dict
)
:
refinementSelection(mesh, dict),
fieldName_(coeffDict().lookup("fieldName")),
lowerBound_(readScalar(coeffDict().lookup("lowerBound"))),
upperBound_(readScalar(coeffDict().lookup("upperBound"))),
cellPointCellSmoothing_
(
coeffDict().lookupOrDefault<Switch>("cellPointCellSmoothing", false)
)
{}
// * * * * * * * * * * * * * * * * Destructor* * * * * * * * * * * * * * * * //
Foam::fieldBoundsRefinement::~fieldBoundsRefinement()
{}
// * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * * //
Foam::labelList
Foam::fieldBoundsRefinement::refinementCellCandidates() const
{
// Get the field
const volScalarField& vField =
mesh().lookupObject<volScalarField>(fieldName_);
// Create temporary for the field (sharing the reference to volume field)
tmp<volScalarField> tvf(vField);
// Use cell-point-cell interpolation to smooth out the field
if (cellPointCellSmoothing_)
{
// Create volume to point interpolation object
const volPointInterpolation& vpi = volPointInterpolation::New(mesh());
// Interpolate from cell centres to points
pointScalarField pField(vpi.interpolate(vField));
// Create point to volume interpolation object
const pointMesh& pMesh = pointMesh::New(mesh());
const pointVolInterpolation pvi(pMesh, mesh());
// Interpolate from points back to cell centres
tmp<volScalarField> tInterpolatedVf = pvi.interpolate(pField);
// Assign to the temporary object
tvf = tInterpolatedVf;
}
// Get const reference to (possibly smoothed volume field)
const volScalarField& vf = tvf();
// Create storage for collection of cells. Assume that one in five cells
// will be refined to prevent excessive resizing.
DynamicList<label> refinementCandidates(Foam::max(100, mesh().nCells()/5));
// Loop through internal field and collect cells to refine
const scalarField& vfIn = vf.internalField();
forAll (vfIn, cellI)
{
// Get current cell value
const scalar& cellValue = vfIn[cellI];
if (cellValue > lowerBound_ && cellValue < upperBound_)
{
// Cell value is within the bounds, append cell for potential
// refinement
refinementCandidates.append(cellI);
}
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(refinementCandidates.size(), sumOp<label>())
<< " cells as refinement candidates."
<< endl;
return refinementCandidates;
}
Foam::labelList
Foam::fieldBoundsRefinement::unrefinementPointCandidates() const
{
// Get the field
const volScalarField& vField =
mesh().lookupObject<volScalarField>(fieldName_);
// Create volume to point interpolation object
const volPointInterpolation& vpi = volPointInterpolation::New(mesh());
// Interpolate the volume field from cell centres to points and get the
// internal point field
pointScalarField pField(vpi.interpolate(vField));
const scalarField& pFieldIn = pField.internalField();
// Create storage for collection of candidates. Assume that one in ten
// mesh points will be unrefined to prevent excessive resizing
DynamicList<label> unrefinementCandidates
(
Foam::max(100, mesh().nPoints()/10)
);
// Loop through all split points and select candidates to unrefine
forAll (pField, pointI)
{
// Get point value
const scalar pointValue = pFieldIn[pointI];
if (pointValue > upperBound_ || pointValue < lowerBound_)
{
// Point value is outside of bounds, append point for potential
// unrefinement
unrefinementCandidates.append(pointI);
}
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(unrefinementCandidates.size(), sumOp<label>())
<< " points as unrefinement candidates."
<< endl;
return unrefinementCandidates;
}
// ************************************************************************* //

View File

@ -0,0 +1,120 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::fieldBoundsRefinement
Description
Selection of refinement cells based on a given scalar field bounds:
if a given (scalar) field is between lowerBound and upperBound, cell will
be marked for refinement.
SourceFiles
fieldBoundsRefinement.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef fieldBoundsRefinement_H
#define fieldBoundsRefinement_H
#include "refinementSelection.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class fieldBoundsRefinement Declaration
\*---------------------------------------------------------------------------*/
class fieldBoundsRefinement
:
public refinementSelection
{
// Private data
//- Name of the field to refine
word fieldName_;
//- Lower bound for the field
scalar lowerBound_;
//- Upper bound for the field
scalar upperBound_;
//- Whether to use cell-point-cell interpolation to smooth out the field
// before selection. Switched off by default
Switch cellPointCellSmoothing_;
// Private Member Functions
//- Disallow default bitwise copy construct
fieldBoundsRefinement(const fieldBoundsRefinement&);
//- Disallow default bitwise assignment
void operator=(const fieldBoundsRefinement&);
public:
//- Runtime type information
TypeName("fieldBoundsRefinement");
// Constructors
//- Construct from components
fieldBoundsRefinement(const fvMesh& mesh, const dictionary& dict);
//- Destructor
virtual ~fieldBoundsRefinement();
// Member Functions
// Selection of refinement/unrefinement candidates
//- Return transferable list of cells to refine
virtual labelList refinementCellCandidates() const;
//- Return transferable list of split points to unrefine
virtual labelList unrefinementPointCandidates() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,125 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "minCellSizeRefinement.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(minCellSizeRefinement, 0);
addToRunTimeSelectionTable
(
refinementSelection,
minCellSizeRefinement,
dictionary
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::minCellSizeRefinement::minCellSizeRefinement
(
const fvMesh& mesh,
const dictionary& dict
)
:
refinementSelection(mesh, dict),
minDelta_(readScalar(coeffDict().lookup("minCellSize")))
{}
// * * * * * * * * * * * * * * * * Destructor* * * * * * * * * * * * * * * * //
Foam::minCellSizeRefinement::~minCellSizeRefinement()
{}
// * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * * //
Foam::labelList
Foam::minCellSizeRefinement::refinementCellCandidates() const
{
// Get cell sizes: cube root of cell volume (assuming cube cells)
const scalarField cellSize(pow(mesh().V().field(), 1.0/3.0));
// Create storage for collection of cells. Assume that almost all of the
// cells will be marked to prevent excessive resizing.
DynamicList<label> refinementCandidates(mesh().nCells());
// Loop through cells and collect refinement candidates
forAll (cellSize, cellI)
{
if (cellSize[cellI] > minDelta_)
{
// Cell is larger than the specified minimum, append cell for
// potential refinement
refinementCandidates.append(cellI);
}
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(refinementCandidates.size(), sumOp<label>())
<< " cells as refinement candidates."
<< endl;
return refinementCandidates;
}
Foam::labelList
Foam::minCellSizeRefinement::unrefinementPointCandidates() const
{
// Mark all points as unrefinement candidates since only split points may be
// considered for actual unrefinement and since this refinement criterion
// will be usually used in combination with others. VV, 15/Mar/2018.
// All points are unrefinement candidates
labelList unrefinementCandidates(mesh().nPoints());
forAll (unrefinementCandidates, pointI)
{
unrefinementCandidates[pointI] = pointI;
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(unrefinementCandidates.size(), sumOp<label>())
<< " points as unrefinement candidates."
<< endl;
return unrefinementCandidates;
}
// ************************************************************************* //

View File

@ -0,0 +1,110 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::minCellSizeRefinement
Description
Selection of refinement cells based on a minimum cell size. Assumes that
cells are mostly cubic and compares the minimum cell size with V^1/3, where
V is the cell volume. If the cell size is larger than the specified one,
cell gets selected for refinement.
SourceFiles
minCellSizeRefinement.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef minCellSizeRefinement_H
#define minCellSizeRefinement_H
#include "refinementSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class minCellSizeRefinement Declaration
\*---------------------------------------------------------------------------*/
class minCellSizeRefinement
:
public refinementSelection
{
// Private data
//- Minimum cell size
scalar minDelta_;
// Private Member Functions
//- Disallow default bitwise copy construct
minCellSizeRefinement(const minCellSizeRefinement&) = delete;
//- Disallow default bitwise assignment
void operator=(const minCellSizeRefinement&) = delete;
public:
//- Runtime type information
TypeName("minCellSizeRefinement");
// Constructors
//- Construct from components
minCellSizeRefinement(const fvMesh& mesh, const dictionary& dict);
//- Destructor
virtual ~minCellSizeRefinement();
// Member Functions
// Selection of refinement/unrefinement candidates
//- Return transferable list of cells to refine
virtual labelList refinementCellCandidates() const;
//- Return transferable list of split points to unrefine
virtual labelList unrefinementPointCandidates() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,125 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "minCellVolumeRefinement.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(minCellVolumeRefinement, 0);
addToRunTimeSelectionTable
(
refinementSelection,
minCellVolumeRefinement,
dictionary
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::minCellVolumeRefinement::minCellVolumeRefinement
(
const fvMesh& mesh,
const dictionary& dict
)
:
refinementSelection(mesh, dict),
minCellV_(readScalar(coeffDict().lookup("minCellVolume")))
{}
// * * * * * * * * * * * * * * * * Destructor* * * * * * * * * * * * * * * * //
Foam::minCellVolumeRefinement::~minCellVolumeRefinement()
{}
// * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * * //
Foam::labelList
Foam::minCellVolumeRefinement::refinementCellCandidates() const
{
// Get mesh volumes
const scalarField& cellV = mesh().V().field();
// Create storage for collection of cells. Assume that almost all of the
// cells will be marked to prevent excessive resizing.
DynamicList<label> refinementCandidates(mesh().nCells());
// Loop through cells and collect refinement candidates
forAll (cellV, cellI)
{
if (cellV[cellI] > minCellV_)
{
// Cell is larger than the specified minimum, append cell for
// potential refinement
refinementCandidates.append(cellI);
}
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(refinementCandidates.size(), sumOp<label>())
<< " cells as refinement candidates."
<< endl;
return refinementCandidates;
}
Foam::labelList
Foam::minCellVolumeRefinement::unrefinementPointCandidates() const
{
// Mark all points as unrefinement candidates since only split points may be
// considered for actual unrefinement and since this refinement criterion
// will be usually used in combination with others. VV, 15/Mar/2018.
// All points are unrefinement candidates
labelList unrefinementCandidates(mesh().nPoints());
forAll (unrefinementCandidates, pointI)
{
unrefinementCandidates[pointI] = pointI;
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(unrefinementCandidates.size(), sumOp<label>())
<< " points as unrefinement candidates."
<< endl;
return unrefinementCandidates;
}
// ************************************************************************* //

View File

@ -0,0 +1,108 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::minCellVolumeRefinement
Description
Selection of refinement cells based on a minimum cell volume. All cells
with volume larger than specified minimum get selected.
SourceFiles
minCellVolumeRefinement.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef minCellVolumeRefinement_H
#define minCellVolumeRefinement_H
#include "refinementSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class minCellVolumeRefinement Declaration
\*---------------------------------------------------------------------------*/
class minCellVolumeRefinement
:
public refinementSelection
{
// Private data
//- Minimum cell volume
scalar minCellV_;
// Private Member Functions
//- Disallow default bitwise copy construct
minCellVolumeRefinement(const minCellVolumeRefinement&);
//- Disallow default bitwise assignment
void operator=(const minCellVolumeRefinement&);
public:
//- Runtime type information
TypeName("minCellVolumeRefinement");
// Constructors
//- Construct from components
minCellVolumeRefinement(const fvMesh& mesh, const dictionary& dict);
//- Destructor
virtual ~minCellVolumeRefinement();
// Member Functions
// Selection of refinement/unrefinement candidates
//- Return transferable list of cells to refine
virtual labelList refinementCellCandidates() const;
//- Return transferable list of split points to unrefine
virtual labelList unrefinementPointCandidates() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,200 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "minFaceArea2DRefinement.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
#include "emptyPolyPatch.H"
#include "wedgePolyPatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(minFaceArea2DRefinement, 0);
addToRunTimeSelectionTable
(
refinementSelection,
minFaceArea2DRefinement,
dictionary
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::minFaceArea2DRefinement::minFaceArea2DRefinement
(
const fvMesh& mesh,
const dictionary& dict
)
:
refinementSelection(mesh, dict),
minFaceA_(readScalar(coeffDict().lookup("minFaceArea")))
{
// It is an error to use this selection algorithm for 3D or 1D cases
if (mesh.nGeometricD() != 2)
{
FatalErrorIn
(
"minFaceArea2DRefinement::minFaceArea2DRefinement"
"\n("
"\n const fvMesh& mesh,"
"\n const dictionary& dict,"
"\n)"
) << "You are trying to use minFaceArea2DRefinement selection"
<< " algorithm for a case which is not 2D case."
<< nl
<< "This is not allowed."
<< abort(FatalError);
}
}
// * * * * * * * * * * * * * * * * Destructor* * * * * * * * * * * * * * * * //
Foam::minFaceArea2DRefinement::~minFaceArea2DRefinement()
{}
// * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * * //
Foam::labelList
Foam::minFaceArea2DRefinement::refinementCellCandidates() const
{
// Get face areas (from polyMesh)
const scalarField faceArea(mag(mesh().faceAreas()));
// Mark empty or wedge faces
boolList faceOnEmptyPatch(mesh().nFaces(), false);
// Loop through all patches
const polyBoundaryMesh& bMesh = mesh().boundaryMesh();
forAll (bMesh, patchI)
{
const polyPatch& curPatch = bMesh[patchI];
if (isA<emptyPolyPatch>(curPatch) || isA<wedgePolyPatch>(curPatch))
{
// Faces on this patch need to be marked
const label startFaceI = curPatch.start();
const label endFaceI = startFaceI + curPatch.size();
// Loop through all the faces and marke them
for (label faceI = startFaceI; faceI < endFaceI; ++faceI)
{
faceOnEmptyPatch[faceI] = true;
}
}
}
// Create field that contains maximum face area on empty patch per cell
scalarField maxEmptyPatchFaceArea(mesh().nCells(), 0.0);
// Get cells from the mesh
const cellList& cells = mesh().cells();
forAll (cells, cellI)
{
// Get current cell
const cell& cellFaces = cells[cellI];
// Loop through faces of the cell
forAll (cellFaces, i)
{
// Get face index
const label& faceI = cellFaces[i];
if (faceOnEmptyPatch[faceI])
{
// This face is on empty patch, set maximum face area to the new
// value if it's larger than the old value
maxEmptyPatchFaceArea[cellI] =
max
(
maxEmptyPatchFaceArea[cellI],
faceArea[faceI]
);
}
}
}
// Create storage for collection of cells. Assume that almost all of the
// cells will be marked to prevent excessive resizing.
DynamicList<label> refinementCandidates(mesh().nCells());
// Loop through cells and collect refinement candidates
forAll (maxEmptyPatchFaceArea, cellI)
{
if (maxEmptyPatchFaceArea[cellI] > minFaceA_)
{
// Face area on empty patch is larger than the specified minimum,
// append cell for potential refinement
refinementCandidates.append(cellI);
}
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(refinementCandidates.size(), sumOp<label>())
<< " cells as refinement candidates."
<< endl;
return refinementCandidates;
}
Foam::labelList
Foam::minFaceArea2DRefinement::unrefinementPointCandidates() const
{
// Mark all points as unrefinement candidates since only split points may be
// considered for actual unrefinement and since this refinement criterion
// will be usually used in combination with others. VV, 4/Sep/2018.
// All points are unrefinement candidates
labelList unrefinementCandidates(mesh().nPoints());
forAll (unrefinementCandidates, pointI)
{
unrefinementCandidates[pointI] = pointI;
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(unrefinementCandidates.size(), sumOp<label>())
<< " points as unrefinement candidates."
<< endl;
return unrefinementCandidates;
}
// ************************************************************************* //

View File

@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::minFaceArea2DRefinement
Description
Selection of refinement cells based on a minimum face area of empty (or
wedge) patches. All cells containing a face on empty (or wedge) patch larger
than specified minimum area get selected.
Useful as a 2D substitute for minCellVolume selection for wedge geometries.
SourceFiles
minFaceArea2DRefinement.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef minFaceArea2DRefinement_H
#define minFaceArea2DRefinement_H
#include "refinementSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class minFaceArea2DRefinement Declaration
\*---------------------------------------------------------------------------*/
class minFaceArea2DRefinement
:
public refinementSelection
{
// Private data
//- Minimum face area on empty (or wedge) patches
scalar minFaceA_;
// Private Member Functions
//- Disallow default bitwise copy construct
minFaceArea2DRefinement(const minFaceArea2DRefinement&);
//- Disallow default bitwise assignment
void operator=(const minFaceArea2DRefinement&);
public:
//- Runtime type information
TypeName("minFaceArea2DRefinement");
// Constructors
//- Construct from components
minFaceArea2DRefinement(const fvMesh& mesh, const dictionary& dict);
//- Destructor
virtual ~minFaceArea2DRefinement();
// Member Functions
// Selection of refinement/unrefinement candidates
//- Return transferable list of cells to refine
virtual labelList refinementCellCandidates() const;
//- Return transferable list of split points to unrefine
virtual labelList unrefinementPointCandidates() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,154 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "minPatchDistanceRefinement.H"
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
#include "patchWave.H"
#include "polyPatchID.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(minPatchDistanceRefinement, 0);
addToRunTimeSelectionTable
(
refinementSelection,
minPatchDistanceRefinement,
dictionary
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::minPatchDistanceRefinement::minPatchDistanceRefinement
(
const fvMesh& mesh,
const dictionary& dict
)
:
refinementSelection(mesh, dict),
minPatchDistance_(readScalar(coeffDict().lookup("minPatchDistance")))
{}
// * * * * * * * * * * * * * * * * Destructor* * * * * * * * * * * * * * * * //
Foam::minPatchDistanceRefinement::~minPatchDistanceRefinement()
{}
// * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * * //
Foam::labelList
Foam::minPatchDistanceRefinement::refinementCellCandidates() const
{
// Note: recalculate distance every time due to probable topo changes
// Read patch names from dictionary
const wordList patchNames(coeffDict().lookup("distancePatches"));
// Collect patchIDs into a hash set
labelHashSet patchIDs(patchNames.size());
forAll (patchNames, patchI)
{
// Get polyPatchID
const polyPatchID pID(patchNames[patchI], mesh().boundaryMesh());
if (pID.active())
{
patchIDs.insert(pID.index());
}
else
{
FatalIOErrorInFunction(coeffDict())
<< "Cannot find patch " << patchNames[patchI]
<< " in the mesh." << nl
<< "Available patches are: " << mesh().boundaryMesh().names()
<< abort(FatalIOError);
}
}
// Calculate distance from specified patches and do not correct for accurate
// near wall distance (false argument)
patchWave waveDistance(mesh(), patchIDs, false);
const scalarField& patchDistance = waveDistance.distance();
// Create storage for collection of cells. Assume that almost all of the
// cells will be marked to prevent excessive resizing.
DynamicList<label> refinementCandidates(mesh().nCells());
// Loop through cells and collect refinement candidates
forAll (patchDistance, cellI)
{
if (patchDistance[cellI] > minPatchDistance_)
{
// Cell is far from the patches, append it for potential refinement
refinementCandidates.append(cellI);
}
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(refinementCandidates.size(), sumOp<label>())
<< " cells as refinement candidates."
<< endl;
return refinementCandidates;
}
Foam::labelList
Foam::minPatchDistanceRefinement::unrefinementPointCandidates() const
{
// Mark all points as unrefinement candidates since only split points may be
// considered for actual unrefinement and since this refinement criterion
// will be usually used in combination with others. VV, 15/Mar/2018.
// All points are unrefinement candidates
labelList unrefinementCandidates(mesh().nPoints());
forAll (unrefinementCandidates, pointI)
{
unrefinementCandidates[pointI] = pointI;
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(unrefinementCandidates.size(), sumOp<label>())
<< " points as unrefinement candidates."
<< endl;
return unrefinementCandidates;
}
// ************************************************************************* //

View File

@ -0,0 +1,108 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::minPatchDistanceRefinement
Description
Selection of refinement cells based on a minimum distance from a set of
patches. All cells farther away from the minimum distance get selected.
SourceFiles
minPatchDistanceRefinement.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef minPatchDistanceRefinement_H
#define minPatchDistanceRefinement_H
#include "refinementSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class minPatchDistanceRefinement Declaration
\*---------------------------------------------------------------------------*/
class minPatchDistanceRefinement
:
public refinementSelection
{
// Private data
//- Minimum distance to patch
scalar minPatchDistance_;
// Private Member Functions
//- Disallow default bitwise copy construct
minPatchDistanceRefinement(const minPatchDistanceRefinement&);
//- Disallow default bitwise assignment
void operator=(const minPatchDistanceRefinement&);
public:
//- Runtime type information
TypeName("minPatchDistanceRefinement");
// Constructors
//- Construct from components
minPatchDistanceRefinement(const fvMesh& mesh, const dictionary& dict);
//- Destructor
virtual ~minPatchDistanceRefinement();
// Member Functions
// Selection of refinement/unrefinement candidates
//- Return transferable list of cells to refine
virtual labelList refinementCellCandidates() const;
//- Return transferable list of split points to unrefine
virtual labelList unrefinementPointCandidates() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,224 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "protectedInitialRefinement.H"
#include "labelIOField.H"
#include "zeroGradientFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(protectedInitialRefinement, 0);
addToRunTimeSelectionTable
(
refinementSelection,
protectedInitialRefinement,
dictionary
);
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField>
Foam::protectedInitialRefinement::cellLevelAsField() const
{
// Get cell level
const labelIOField& cLevel = mesh().lookupObject<labelIOField>("cellLevel");
// Create cell level field as volScalarField
tmp<volScalarField> tcellLevelField
(
new volScalarField
(
IOobject
(
"cellLevel",
mesh().time().timeName(),
mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh(),
dimensionedScalar("zero", dimless, 0.0),
zeroGradientFvPatchScalarField::typeName
)
);
scalarField& cellLevelFieldIn = tcellLevelField->internalFieldRef();
// Set the field
forAll (cLevel, cellI)
{
cellLevelFieldIn[cellI] = cLevel[cellI];
}
tcellLevelField->correctBoundaryConditions();
return tcellLevelField;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::protectedInitialRefinement::protectedInitialRefinement
(
const fvMesh& mesh,
const dictionary& dict
)
:
refinementSelection(mesh, dict),
initialCellLevel_
(
IOobject
(
"initialCellLevel",
mesh.time().timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
cellLevelAsField()()
),
// Note: conversion from label to scalar
minProtectedLevel_
(
coeffDict().lookupOrDefault<label>("minProtectedLevel", 0)
)
{
Info<< "Will not allow initial refinement below level: "
<< minProtectedLevel_ << endl;
}
// * * * * * * * * * * * * * * * * Destructor* * * * * * * * * * * * * * * * //
Foam::protectedInitialRefinement::~protectedInitialRefinement()
{}
// * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * * //
Foam::labelList
Foam::protectedInitialRefinement::refinementCellCandidates() const
{
// All cells are candidates for refinement
labelList refinementCandidates(mesh().nCells());
forAll (refinementCandidates, cellI)
{
refinementCandidates[cellI] = cellI;
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(refinementCandidates.size(), sumOp<label>())
<< " (all) cells as refinement candidates."
<< endl;
return refinementCandidates;
}
Foam::labelList
Foam::protectedInitialRefinement::unrefinementPointCandidates() const
{
// Create mark-up field for points that are found on initially refined cells
// Note: this can be done more intelligently by either cacheing until load
// balancing actually occurs or holding pointLevel as data member and
// updating it on load balancing. The overall overhead compared to AMR and
// DLB is really small, so there's no need to worry about this yet.
// VV, 10/July/2018
boolList pointsOnRefinedCells(mesh().nPoints(), false);
// Get initial cell level and mesh data
const scalarField& initialCellLevelIn = initialCellLevel_.internalField();
const labelListList& meshCellPoints = mesh().cellPoints();
// Loop through all cells and count number of protected points
label nProtectedPoints = 0;
// Get current cell level
const labelIOField& curCellLevel =
mesh().lookupObject<labelIOField>("cellLevel");
forAll (initialCellLevelIn, cellI)
{
const scalar& cl = initialCellLevelIn[cellI];
const scalar& curcl = curCellLevel[cellI];
if
(
(cl > SMALL)
&& (curcl - minProtectedLevel_ < 0.5)
)
{
// Cell has been refined during meshing and the original level is
// equal to the current level, mark all of its points
const labelList& curCellPoints = meshCellPoints[cellI];
forAll (curCellPoints, i)
{
// Get marker for this point
bool& ptOnRefCell = pointsOnRefinedCells[curCellPoints[i]];
if (!ptOnRefCell)
{
// This points has not been marked yet, mark it and
// increment the counter for protected points
ptOnRefCell = true;
++nProtectedPoints;
}
}
}
}
// Create the list for unrefinement candidates
labelList unrefinementCandidates(mesh().nPoints() - nProtectedPoints);
label nUnrefPoints = 0;
forAll (pointsOnRefinedCells, pointI)
{
if (!pointsOnRefinedCells[pointI])
{
// This point is an unrefinement candidate, set it and increment
unrefinementCandidates[nUnrefPoints++] = pointI;
}
}
// Print out some information
Info<< "Selection algorithm " << type() << " selected "
<< returnReduce(unrefinementCandidates.size(), sumOp<label>())
<< " points as unrefinement candidates."
<< endl;
return unrefinementCandidates;
}
// ************************************************************************* //

View File

@ -0,0 +1,130 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::protectedInitialRefinement
Description
This refinement strategy is just a protection to avoid unrefining cells that
are refined during the snappyHexMesh meshing process. It's intended use is
alongside some other refinement strategy as a part of a composite scheme.
Therefore: refinementCellCandidates returns all cells as refinement
candidates, while unrefinementPointCandidates returns all points that don't
touch any of the initially refined cells.
Since snappyHexMesh writes down cellLevel and pointLevel, cells refined in
during meshing could be unrefined, but this is not what we would like to
achieve (after all, if we have included refinement regions in meshing, then
we probably had a good reason for it).
SourceFiles
protectedInitialRefinement.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef protectedInitialRefinement_H
#define protectedInitialRefinement_H
#include "refinementSelection.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class protectedInitialRefinement Declaration
\*---------------------------------------------------------------------------*/
class protectedInitialRefinement
:
public refinementSelection
{
// Private data
//- Initial cellLevel as volScalarField in order to simplify data
// transfer for dynamic load balancing
volScalarField initialCellLevel_;
//- Minimum refinement level to protect
scalar minProtectedLevel_;
// Private Member Functions
// Copy control
//- Disallow default bitwise copy construct
protectedInitialRefinement(const protectedInitialRefinement&);
//- Disallow default bitwise assignment
void operator=(const protectedInitialRefinement&);
// Constructor helper
//- Create and return volScalarField from cellLevel
tmp<volScalarField> cellLevelAsField() const;
public:
//- Runtime type information
TypeName("protectedInitialRefinement");
// Constructors
//- Construct from components
protectedInitialRefinement(const fvMesh& mesh, const dictionary& dict);
//- Destructor
virtual ~protectedInitialRefinement();
// Member Functions
// Selection of refinement/unrefinement candidates
//- Return transferable list of cells to refine
virtual labelList refinementCellCandidates() const;
//- Return transferable list of split points to unrefine
virtual labelList unrefinementPointCandidates() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,87 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#include "refinementSelection.H"
#include "fvMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(refinementSelection, 0);
defineRunTimeSelectionTable(refinementSelection, dictionary);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::refinementSelection::refinementSelection
(
const fvMesh& mesh,
const dictionary& dict
)
:
mesh_(mesh),
coeffDict_(dict.subDict("refinementSelection"))
{}
// * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::refinementSelection> Foam::refinementSelection::New
(
const fvMesh& mesh,
const dictionary& dict
)
{
// Get subdictionary from the dictionary
const dictionary coeffDict(dict.subDict("refinementSelection"));
// Get the name of the desired refinement selection algorithm
const word refinementSelectionTypeName(coeffDict.lookup("type"));
Info<< "Creating refinementSelection " << refinementSelectionTypeName << endl;
auto* ctorPtr =
dictionaryConstructorTable(refinementSelectionTypeName);
if (!ctorPtr)
{
FatalErrorInLookup
(
"refinementSelection",
refinementSelectionTypeName,
*dictionaryConstructorTablePtr_
) << exit(FatalError);
}
return autoPtr<refinementSelection>(ctorPtr(mesh, dict));
}
// ************************************************************************* //

View File

@ -0,0 +1,171 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 5.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::refinementSelection
Description
An abstract base class for providing an interface for refinement selection
algorithms. The interface provides two functionalities:
1. Selects candidate cells to refine based on chosen criteria through
refinementCellCandidates() member function. Returns a list of all cells
that satisfy given criteria,
2. Selects candidate split points to unrefine based on chosen criteria
through unrefinementPointCandidates() member function. Returns a list of
all points (not just split points!) that satisfy the criteria.
Note: Here, we do not check that the unrefinement point candidates do not
clash the points of cells marked as candidates for refinement. This is taken
care of in polyhedralRefinement class.
SourceFiles
refinementSelection.C
Author
Vuko Vukcevic, Wikki Ltd. All rights reserved.
\*---------------------------------------------------------------------------*/
#ifndef refinementSelection_H
#define refinementSelection_H
#include "dictionary.H"
#include "labelList.H"
#include "autoPtr.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class fvMesh;
/*---------------------------------------------------------------------------*\
Class refinementSelection Declaration
\*---------------------------------------------------------------------------*/
class refinementSelection
{
// Private data
//- Const reference to fvMesh
const fvMesh& mesh_;
//- Refinement selection dictionary (subdictionary of
// dynamicPolyRefinementFvMeshCoeffs dictionary)
const dictionary coeffDict_;
// Private Member Functions
//- Disallow default bitwise copy construct
refinementSelection(const refinementSelection&) = delete;
//- Disallow default bitwise assignment
void operator=(const refinementSelection&) = delete;
protected:
// Protected member functions
// Access functions for derived classes
//- Const access to the fvMesh
const fvMesh& mesh() const
{
return mesh_;
}
//- Const access to the coefficient dictionary
const dictionary& coeffDict() const
{
return coeffDict_;
}
public:
//- Runtime type information
TypeName("refinementSelection");
// Declare run-time constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
refinementSelection,
dictionary,
(
const fvMesh& mesh,
const dictionary& dict
),
(mesh, dict)
);
// Constructors
//- Construct from components
refinementSelection(const fvMesh& mesh, const dictionary& dict);
// Selectors
//- Return an autoPtr to the selected refinementSelection
static autoPtr<refinementSelection> New
(
const fvMesh& mesh,
const dictionary& dict
);
//- Destructor
virtual ~refinementSelection() = default;
// Member Functions
// Selection of refinement/unrefinement candidates
//- Return transferable list of refinement cell candidates
virtual labelList refinementCellCandidates() const = 0;
//- Return transferable list of unrefinement split point candidates
virtual labelList unrefinementPointCandidates() const = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -326,7 +326,7 @@ Foam::movingConeTopoFvMesh::~movingConeTopoFvMesh()
bool Foam::movingConeTopoFvMesh::update() bool Foam::movingConeTopoFvMesh::update()
{ {
// Do mesh changes (use inflation - put new points in topoChangeMap) // Do mesh changes (use inflation - put new points in topoChangeMap)
autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true); autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
// Calculate the new point positions depending on whether the // Calculate the new point positions depending on whether the
// topological change has happened or not // topological change has happened or not

View File

@ -77,8 +77,8 @@ bool Foam::rawTopoChangerFvMesh::update()
moving(false); moving(false);
topoChanging(false); topoChanging(false);
// Do any topology changes. Sets topoChanging (through polyTopoChange) // Do any topology changes. Sets topoChanging (through batchPolyTopoChange)
autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true); autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
const bool hasChanged = bool(topoChangeMap); const bool hasChanged = bool(topoChangeMap);