From 0afb3ab1ac9226244935e96c6b9c3d47724e815d Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 26 Feb 2013 22:19:28 +0000 Subject: [PATCH] MeshObject: extended to support movePoints and updateMesh as an alternative to call-backs All MeshObjects are now handled generically in polyMesh and fvMesh See MeshObject.H for details --- .../db/objectRegistry/objectRegistry.H | 4 + .../objectRegistry/objectRegistryTemplates.C | 28 ++++ .../GAMGAgglomeration/GAMGAgglomeration.C | 2 +- .../GAMGAgglomeration/GAMGAgglomeration.H | 2 +- src/OpenFOAM/meshes/MeshObject/MeshObject.C | 125 ++++++++++---- src/OpenFOAM/meshes/MeshObject/MeshObject.H | 157 +++++++++++++++++- src/OpenFOAM/meshes/pointMesh/pointMesh.C | 8 +- src/OpenFOAM/meshes/pointMesh/pointMesh.H | 4 +- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 30 +--- src/OpenFOAM/meshes/polyMesh/polyMeshClear.C | 12 +- src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C | 17 +- .../dynamicRefineFvMesh/dynamicRefineFvMesh.C | 12 +- .../fvMeshDistributeTemplates.C | 32 ++-- .../fvMeshTools/fvMeshToolsTemplates.C | 57 +++---- .../solutionControlTemplates.C | 6 +- .../LeastSquaresGrad/LeastSquaresVectors.C | 2 +- .../LeastSquaresGrad/LeastSquaresVectors.H | 4 +- .../leastSquaresGrad/leastSquaresVectors.C | 2 +- .../leastSquaresGrad/leastSquaresVectors.H | 2 +- .../centredCECCellToCellStencilObject.H | 14 +- .../centredCFCCellToCellStencilObject.H | 14 +- .../centredCPCCellToCellStencilObject.H | 14 +- .../centredCECCellToFaceStencilObject.H | 14 +- .../centredCFCCellToFaceStencilObject.H | 14 +- .../centredCPCCellToFaceStencilObject.H | 14 +- .../centredFECCellToFaceStencilObject.H | 14 +- .../pureUpwindCFCCellToFaceStencilObject.H | 14 +- .../upwindCECCellToFaceStencilObject.H | 14 +- .../upwindCFCCellToFaceStencilObject.H | 14 +- .../upwindCPCCellToFaceStencilObject.H | 14 +- .../upwindFECCellToFaceStencilObject.H | 14 +- .../centredCFCFaceToCellStencilObject.H | 14 +- src/finiteVolume/fvMesh/fvMesh.C | 100 +---------- .../schemes/FitData/FitData.C | 2 +- .../schemes/FitData/FitData.H | 2 +- .../skewCorrected/skewCorrectionVectors.C | 2 +- .../skewCorrected/skewCorrectionVectors.H | 2 +- .../volPointInterpolation.C | 7 +- .../volPointInterpolation.H | 4 +- .../meshRefinement/meshRefinementTemplates.C | 28 +--- .../meshSearchFACECENTRETETSMeshObject.C | 7 +- .../meshSearchFACECENTRETETSMeshObject.H | 19 +-- .../meshSearch/meshSearchMeshObject.C | 2 +- .../meshSearch/meshSearchMeshObject.H | 14 +- src/meshTools/regionSplit/regionSplit.C | 6 +- src/meshTools/regionSplit/regionSplit.H | 2 +- .../distributedTriSurfaceMeshTemplates.C | 10 +- .../SLGThermo/SLGThermo/SLGThermo.C | 11 +- .../SLGThermo/SLGThermo/SLGThermo.H | 12 +- 49 files changed, 567 insertions(+), 351 deletions(-) diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index 84b295c4d7..d1973aab59 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -159,6 +159,10 @@ public: template HashTable lookupClass(const bool strict = false) const; + //- Lookup and return all objects of the given Type + template + HashTable lookupClass(const bool strict = false); + //- Is the named Type found? template bool foundObject(const word& name) const; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index 960605e049..6a1e4a9a24 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C @@ -76,6 +76,34 @@ Foam::HashTable Foam::objectRegistry::lookupClass } +template +Foam::HashTable Foam::objectRegistry::lookupClass +( + const bool strict +) +{ + HashTable objectsOfClass(size()); + + forAllIter(HashTable, *this, iter) + { + if + ( + (strict && isType(*iter())) + || (!strict && isA(*iter())) + ) + { + objectsOfClass.insert + ( + iter()->name(), + dynamic_cast(iter()) + ); + } + } + + return objectsOfClass; +} + + template bool Foam::objectRegistry::foundObject(const word& name) const { diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.C index 51421910c2..de2b6ffd3b 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.C @@ -70,7 +70,7 @@ Foam::GAMGAgglomeration::GAMGAgglomeration const dictionary& controlDict ) : - MeshObject(mesh), + MeshObject(mesh), maxLevels_(50), diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.H index e35cdd379f..b308124610 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.H +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/GAMGAgglomeration/GAMGAgglomeration.H @@ -58,7 +58,7 @@ class lduMatrix; class GAMGAgglomeration : - public MeshObject + public MeshObject { protected: diff --git a/src/OpenFOAM/meshes/MeshObject/MeshObject.C b/src/OpenFOAM/meshes/MeshObject/MeshObject.C index eed1d7aad8..8f25049242 100644 --- a/src/OpenFOAM/meshes/MeshObject/MeshObject.C +++ b/src/OpenFOAM/meshes/MeshObject/MeshObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,26 +28,18 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -template -Foam::MeshObject::MeshObject(const Mesh& mesh) +template class MeshObjectType, class Type> +Foam::MeshObject::MeshObject(const Mesh& mesh) : - regIOobject - ( - IOobject - ( - Type::typeName, - mesh.thisDb().instance(), - mesh.thisDb() - ) - ), + MeshObjectType(Type::typeName, mesh.thisDb()), mesh_(mesh) {} // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // -template -const Type& Foam::MeshObject::New +template class MeshObjectType, class Type> +const Type& Foam::MeshObject::New ( const Mesh& mesh ) @@ -67,14 +59,14 @@ const Type& Foam::MeshObject::New } else { - return store(new Type(mesh)); + return regIOobject::store(new Type(mesh)); } } -template +template class MeshObjectType, class Type> template -const Type& Foam::MeshObject::New +const Type& Foam::MeshObject::New ( const Mesh& mesh, const Data1& d @@ -95,14 +87,14 @@ const Type& Foam::MeshObject::New } else { - return store(new Type(mesh, d)); + return regIOobject::store(new Type(mesh, d)); } } -template +template class MeshObjectType, class Type> template -const Type& Foam::MeshObject::New +const Type& Foam::MeshObject::New ( const Mesh& mesh, const Data1& d1, @@ -124,14 +116,14 @@ const Type& Foam::MeshObject::New } else { - return store(new Type(mesh, d1, d2)); + return regIOobject::store(new Type(mesh, d1, d2)); } } -template +template class MeshObjectType, class Type> template -const Type& Foam::MeshObject::New +const Type& Foam::MeshObject::New ( const Mesh& mesh, const Data1& d1, @@ -154,14 +146,14 @@ const Type& Foam::MeshObject::New } else { - return store(new Type(mesh, d1, d2, d3)); + return regIOobject::store(new Type(mesh, d1, d2, d3)); } } -template +template class MeshObjectType, class Type> template -const Type& Foam::MeshObject::New +const Type& Foam::MeshObject::New ( const Mesh& mesh, const Data1& d1, @@ -185,15 +177,15 @@ const Type& Foam::MeshObject::New } else { - return store(new Type(mesh, d1, d2, d3, d4)); + return regIOobject::store(new Type(mesh, d1, d2, d3, d4)); } } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * // -template -bool Foam::MeshObject::Delete(const Mesh& mesh) +template class MeshObjectType, class Type> +bool Foam::MeshObject::Delete(const Mesh& mesh) { if ( @@ -221,10 +213,79 @@ bool Foam::MeshObject::Delete(const Mesh& mesh) } -template -Foam::MeshObject::~MeshObject() +template class MeshObjectType, class Type> +Foam::MeshObject::~MeshObject() { - release(); + MeshObjectType::release(); +} + + +template +void Foam::meshObject::movePoints(objectRegistry& obr) +{ + HashTable*> meshObjects + ( + obr.lookupClass >() + ); + + forAllIter + ( + typename HashTable*>, + meshObjects, + iter + ) + { + if (isA >(*iter())) + { + dynamic_cast*>(iter())->movePoints(); + } + else + { + obr.checkOut(*iter()); + } + } +} + + +template +void Foam::meshObject::updateMesh(objectRegistry& obr, const mapPolyMesh& mpm) +{ + HashTable*> meshObjects + ( + obr.lookupClass >() + ); + + forAllIter + ( + typename HashTable*>, + meshObjects, + iter + ) + { + if (isA >(*iter())) + { + dynamic_cast*>(iter())->updateMesh(mpm); + } + else + { + obr.checkOut(*iter()); + } + } +} + + +template class MeshObjectType> +void Foam::meshObject::clear(objectRegistry& obr) +{ + HashTable*> meshObjects + ( + obr.lookupClass >() + ); + + forAllIter(typename HashTable*>, meshObjects, iter) + { + obr.checkOut(*iter()); + } } diff --git a/src/OpenFOAM/meshes/MeshObject/MeshObject.H b/src/OpenFOAM/meshes/MeshObject/MeshObject.H index 95cf9daf2c..8efa89f944 100644 --- a/src/OpenFOAM/meshes/MeshObject/MeshObject.H +++ b/src/OpenFOAM/meshes/MeshObject/MeshObject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,9 +25,36 @@ Class Foam::MeshObject Description - Templated abstract base-class for dynamic mesh objects used to automate + Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh database and the mesh-modifier event-loop. + MeshObject is templated on the type of mesh it is allocated to, the type of + the mesh object (TopologicalMeshObject, GeometricMeshObject, + MoveableMeshObject, UpdateableMeshObject) and the type of the actual object + it is created for example: + + class leastSquaresVectors + : + public MeshObject + { + . + . + . + //- Delete the least square vectors when the mesh moves + virtual bool movePoints(); + }; + + MeshObject types: + + TopologicalMeshObject: mesh object to be deleted on topology change + GeometricMeshObject: mesh object to be deleted on geometry change + MoveableMeshObject: mesh object to be updated in movePoints + UpdateableMeshObject: mesh object to be updated in updateMesh or movePoints + + Note that movePoints must be provided for MeshObjects of type + MoveableMeshObject and both movePoints and updateMesh functions must exist + provided for MeshObjects of type UpdateableMeshObject. + SourceFiles MeshObject.C @@ -37,21 +64,24 @@ SourceFiles #define MeshObject_H #include "regIOobject.H" +#include "objectRegistry.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +// Forward declarations +class mapPolyMesh; + /*---------------------------------------------------------------------------*\ - Class MeshObject Declaration + Class MeshObject Declaration \*---------------------------------------------------------------------------*/ - -template +template class MeshObjectType, class Type> class MeshObject : - public regIOobject + public MeshObjectType { protected: @@ -124,6 +154,121 @@ public: }; +/*---------------------------------------------------------------------------*\ + Class meshObject Declaration +\*---------------------------------------------------------------------------*/ + +class meshObject +: + public regIOobject +{ +public: + + // Constructors + + meshObject(const word& typeName, const objectRegistry& obr) + : + regIOobject + ( + IOobject + ( + typeName, + obr.instance(), + obr + ) + ) + {} + + + // Static member functions + + template + static void movePoints(objectRegistry&); + + template + static void updateMesh(objectRegistry&, const mapPolyMesh&); + + template class MeshObjectType> + static void clear(objectRegistry&); +}; + + +/*---------------------------------------------------------------------------*\ + Class TopologicalMeshObject Declaration +\*---------------------------------------------------------------------------*/ + +template +class TopologicalMeshObject +: + public meshObject +{ +public: + + TopologicalMeshObject(const word& typeName, const objectRegistry& obr) + : + meshObject(typeName, obr) + {} +}; + + +/*---------------------------------------------------------------------------*\ + Class GeometricMeshObject Declaration +\*---------------------------------------------------------------------------*/ + +template +class GeometricMeshObject +: + public TopologicalMeshObject +{ +public: + + GeometricMeshObject(const word& typeName, const objectRegistry& obr) + : + TopologicalMeshObject(typeName, obr) + {} +}; + + +/*---------------------------------------------------------------------------*\ + Class MoveableMeshObject Declaration +\*---------------------------------------------------------------------------*/ + +template +class MoveableMeshObject +: + public GeometricMeshObject +{ +public: + + MoveableMeshObject(const word& typeName, const objectRegistry& obr) + : + GeometricMeshObject(typeName, obr) + {} + + virtual bool movePoints() = 0; +}; + + +/*---------------------------------------------------------------------------*\ + Class UpdateableMeshObject Declaration +\*---------------------------------------------------------------------------*/ + +template +class UpdateableMeshObject +: + public MoveableMeshObject +{ +public: + + UpdateableMeshObject(const word& typeName, const objectRegistry& obr) + : + MoveableMeshObject(typeName, obr) + {} + + virtual void updateMesh(const mapPolyMesh& mpm) = 0; +}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.C b/src/OpenFOAM/meshes/pointMesh/pointMesh.C index f378a5d780..b92d5f8552 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.C +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.C @@ -72,7 +72,7 @@ void Foam::pointMesh::mapFields(const mapPolyMesh& mpm) Foam::pointMesh::pointMesh(const polyMesh& pMesh) : - MeshObject(pMesh), + MeshObject(pMesh), GeoMesh(pMesh), boundary_(*this, pMesh.boundaryMesh()) { @@ -88,7 +88,7 @@ Foam::pointMesh::pointMesh(const polyMesh& pMesh) } -void Foam::pointMesh::movePoints(const pointField& newPoints) +bool Foam::pointMesh::movePoints() { if (debug) { @@ -96,7 +96,9 @@ void Foam::pointMesh::movePoints(const pointField& newPoints) << "Moving points." << endl; } - boundary_.movePoints(newPoints); + boundary_.movePoints(GeoMesh::mesh_.points()); + + return true; } diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.H b/src/OpenFOAM/meshes/pointMesh/pointMesh.H index 25e8af9530..80ed113140 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.H +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.H @@ -48,7 +48,7 @@ namespace Foam class pointMesh : - public MeshObject, + public MeshObject, public GeoMesh { // Permanent data @@ -121,7 +121,7 @@ public: // Mesh motion //- Move points, returns volumes swept by faces in motion - void movePoints(const pointField&); + bool movePoints(); //- Update the mesh corresponding to given map void updateMesh(const mapPolyMesh& mpm); diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index 8201254e0b..c0d74d954f 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -26,30 +26,24 @@ License #include "polyMesh.H" #include "Time.H" #include "cellIOList.H" -#include "SubList.H" #include "wedgePolyPatch.H" #include "emptyPolyPatch.H" #include "globalMeshData.H" #include "processorPolyPatch.H" -#include "OSspecific.H" #include "polyMeshTetDecomposition.H" #include "indexedOctree.H" #include "treeDataCell.H" -#include "SubField.H" +#include "MeshObject.H" -#include "pointMesh.H" -#include "Istream.H" -#include "Ostream.H" -#include "simpleRegIOobject.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { -defineTypeNameAndDebug(polyMesh, 0); + defineTypeNameAndDebug(polyMesh, 0); -word polyMesh::defaultRegion = "region0"; -word polyMesh::meshSubDir = "polyMesh"; + word polyMesh::defaultRegion = "region0"; + word polyMesh::meshSubDir = "polyMesh"; } @@ -1162,21 +1156,7 @@ Foam::tmp Foam::polyMesh::movePoints geometricD_ = Vector