Commit 0afb3ab1 authored by Henry's avatar Henry
Browse files

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
parent 0a5508e8
......@@ -159,6 +159,10 @@ public:
template<class Type>
HashTable<const Type*> lookupClass(const bool strict = false) const;
//- Lookup and return all objects of the given Type
template<class Type>
HashTable<Type*> lookupClass(const bool strict = false);
//- Is the named Type found?
template<class Type>
bool foundObject(const word& name) const;
......
......@@ -76,6 +76,34 @@ Foam::HashTable<const Type*> Foam::objectRegistry::lookupClass
}
template<class Type>
Foam::HashTable<Type*> Foam::objectRegistry::lookupClass
(
const bool strict
)
{
HashTable<Type*> objectsOfClass(size());
forAllIter(HashTable<regIOobject*>, *this, iter)
{
if
(
(strict && isType<Type>(*iter()))
|| (!strict && isA<Type>(*iter()))
)
{
objectsOfClass.insert
(
iter()->name(),
dynamic_cast<Type*>(iter())
);
}
}
return objectsOfClass;
}
template<class Type>
bool Foam::objectRegistry::foundObject(const word& name) const
{
......
......@@ -70,7 +70,7 @@ Foam::GAMGAgglomeration::GAMGAgglomeration
const dictionary& controlDict
)
:
MeshObject<lduMesh, GAMGAgglomeration>(mesh),
MeshObject<lduMesh, Foam::TopologicalMeshObject, GAMGAgglomeration>(mesh),
maxLevels_(50),
......
......@@ -58,7 +58,7 @@ class lduMatrix;
class GAMGAgglomeration
:
public MeshObject<lduMesh, GAMGAgglomeration>
public MeshObject<lduMesh, TopologicalMeshObject, GAMGAgglomeration>
{
protected:
......
......@@ -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<class Mesh, class Type>
Foam::MeshObject<Mesh, Type>::MeshObject(const Mesh& mesh)
template<class Mesh, template<class> class MeshObjectType, class Type>
Foam::MeshObject<Mesh, MeshObjectType, Type>::MeshObject(const Mesh& mesh)
:
regIOobject
(
IOobject
(
Type::typeName,
mesh.thisDb().instance(),
mesh.thisDb()
)
),
MeshObjectType<Mesh>(Type::typeName, mesh.thisDb()),
mesh_(mesh)
{}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Mesh, class Type>
const Type& Foam::MeshObject<Mesh, Type>::New
template<class Mesh, template<class> class MeshObjectType, class Type>
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
(
const Mesh& mesh
)
......@@ -67,14 +59,14 @@ const Type& Foam::MeshObject<Mesh, Type>::New
}
else
{
return store(new Type(mesh));
return regIOobject::store(new Type(mesh));
}
}
template<class Mesh, class Type>
template<class Mesh, template<class> class MeshObjectType, class Type>
template<class Data1>
const Type& Foam::MeshObject<Mesh, Type>::New
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
(
const Mesh& mesh,
const Data1& d
......@@ -95,14 +87,14 @@ const Type& Foam::MeshObject<Mesh, Type>::New
}
else
{
return store(new Type(mesh, d));
return regIOobject::store(new Type(mesh, d));
}
}
template<class Mesh, class Type>
template<class Mesh, template<class> class MeshObjectType, class Type>
template<class Data1, class Data2>
const Type& Foam::MeshObject<Mesh, Type>::New
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
(
const Mesh& mesh,
const Data1& d1,
......@@ -124,14 +116,14 @@ const Type& Foam::MeshObject<Mesh, Type>::New
}
else
{
return store(new Type(mesh, d1, d2));
return regIOobject::store(new Type(mesh, d1, d2));
}
}
template<class Mesh, class Type>
template<class Mesh, template<class> class MeshObjectType, class Type>
template<class Data1, class Data2, class Data3>
const Type& Foam::MeshObject<Mesh, Type>::New
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
(
const Mesh& mesh,
const Data1& d1,
......@@ -154,14 +146,14 @@ const Type& Foam::MeshObject<Mesh, Type>::New
}
else
{
return store(new Type(mesh, d1, d2, d3));
return regIOobject::store(new Type(mesh, d1, d2, d3));
}
}
template<class Mesh, class Type>
template<class Mesh, template<class> class MeshObjectType, class Type>
template<class Data1, class Data2, class Data3, class Data4>
const Type& Foam::MeshObject<Mesh, Type>::New
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
(
const Mesh& mesh,
const Data1& d1,
......@@ -185,15 +177,15 @@ const Type& Foam::MeshObject<Mesh, Type>::New
}
else
{
return store(new Type(mesh, d1, d2, d3, d4));
return regIOobject::store(new Type(mesh, d1, d2, d3, d4));
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
template<class Mesh, class Type>
bool Foam::MeshObject<Mesh, Type>::Delete(const Mesh& mesh)
template<class Mesh, template<class> class MeshObjectType, class Type>
bool Foam::MeshObject<Mesh, MeshObjectType, Type>::Delete(const Mesh& mesh)
{
if
(
......@@ -221,10 +213,79 @@ bool Foam::MeshObject<Mesh, Type>::Delete(const Mesh& mesh)
}
template<class Mesh, class Type>
Foam::MeshObject<Mesh, Type>::~MeshObject()
template<class Mesh, template<class> class MeshObjectType, class Type>
Foam::MeshObject<Mesh, MeshObjectType, Type>::~MeshObject()
{
MeshObjectType<Mesh>::release();
}
template<class Mesh>
void Foam::meshObject::movePoints(objectRegistry& obr)
{
release();
HashTable<GeometricMeshObject<Mesh>*> meshObjects
(
obr.lookupClass<GeometricMeshObject<Mesh> >()
);
forAllIter
(
typename HashTable<GeometricMeshObject<Mesh>*>,
meshObjects,
iter
)
{
if (isA<MoveableMeshObject<Mesh> >(*iter()))
{
dynamic_cast<MoveableMeshObject<Mesh>*>(iter())->movePoints();
}
else
{
obr.checkOut(*iter());
}
}
}
template<class Mesh>
void Foam::meshObject::updateMesh(objectRegistry& obr, const mapPolyMesh& mpm)
{
HashTable<GeometricMeshObject<Mesh>*> meshObjects
(
obr.lookupClass<GeometricMeshObject<Mesh> >()
);
forAllIter
(
typename HashTable<GeometricMeshObject<Mesh>*>,
meshObjects,
iter
)
{
if (isA<UpdateableMeshObject<Mesh> >(*iter()))
{
dynamic_cast<UpdateableMeshObject<Mesh>*>(iter())->updateMesh(mpm);
}
else
{
obr.checkOut(*iter());
}
}
}
template<class Mesh, template<class> class MeshObjectType>
void Foam::meshObject::clear(objectRegistry& obr)
{
HashTable<MeshObjectType<Mesh>*> meshObjects
(
obr.lookupClass<MeshObjectType<Mesh> >()
);
forAllIter(typename HashTable<MeshObjectType<Mesh>*>, meshObjects, iter)
{
obr.checkOut(*iter());
}
}
......
......@@ -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<fvMesh, MoveableMeshObject, leastSquaresVectors>
{
.
.
.
//- 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<class Mesh, class Type>
template<class Mesh, template<class> class MeshObjectType, class Type>
class MeshObject
:
public regIOobject
public MeshObjectType<Mesh>
{
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<class Mesh>
static void movePoints(objectRegistry&);
template<class Mesh>
static void updateMesh(objectRegistry&, const mapPolyMesh&);
template<class Mesh, template<class> class MeshObjectType>
static void clear(objectRegistry&);
};
/*---------------------------------------------------------------------------*\
Class TopologicalMeshObject Declaration
\*---------------------------------------------------------------------------*/
template<class Mesh>
class TopologicalMeshObject
:
public meshObject
{
public:
TopologicalMeshObject(const word& typeName, const objectRegistry& obr)
:
meshObject(typeName, obr)
{}
};
/*---------------------------------------------------------------------------*\
Class GeometricMeshObject Declaration
\*---------------------------------------------------------------------------*/
template<class Mesh>
class GeometricMeshObject
:
public TopologicalMeshObject<Mesh>
{
public:
GeometricMeshObject(const word& typeName, const objectRegistry& obr)
:
TopologicalMeshObject<Mesh>(typeName, obr)
{}
};
/*---------------------------------------------------------------------------*\
Class MoveableMeshObject Declaration
\*---------------------------------------------------------------------------*/
template<class Mesh>
class MoveableMeshObject
:
public GeometricMeshObject<Mesh>
{
public:
MoveableMeshObject(const word& typeName, const objectRegistry& obr)
:
GeometricMeshObject<Mesh>(typeName, obr)
{}
virtual bool movePoints() = 0;
};
/*---------------------------------------------------------------------------*\
Class UpdateableMeshObject Declaration
\*---------------------------------------------------------------------------*/
template<class Mesh>
class UpdateableMeshObject
:
public MoveableMeshObject<Mesh>
{
public:
UpdateableMeshObject(const word& typeName, const objectRegistry& obr)
:
MoveableMeshObject<Mesh>(typeName, obr)
{}
virtual void updateMesh(const mapPolyMesh& mpm) = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......
......@@ -72,7 +72,7 @@ void Foam::pointMesh::mapFields(const mapPolyMesh& mpm)
Foam::pointMesh::pointMesh(const polyMesh& pMesh)
:
MeshObject<polyMesh, pointMesh>(pMesh),
MeshObject<polyMesh, Foam::UpdateableMeshObject, pointMesh>(pMesh),
GeoMesh<polyMesh>(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<polyMesh>::mesh_.points());
return true;
}
......
......@@ -48,7 +48,7 @@ namespace Foam
class pointMesh
:
public MeshObject<polyMesh, pointMesh>,
public MeshObject<polyMesh, UpdateableMeshObject, pointMesh>,
public GeoMesh<polyMesh>
{
// 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);
......
......@@ -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::scalarField> Foam::polyMesh::movePoints
geometricD_ = Vector<label>::zero;
solutionD_ = Vector<label>::zero;
// Hack until proper callbacks. Below are all the polyMeh MeshObjects with a
// movePoints function.
// pointMesh
if (thisDb().foundObject<pointMesh>(pointMesh::typeName))
{
const_cast<pointMesh&>
(
thisDb().lookupObject<pointMesh>
(
pointMesh::typeName
)
).movePoints(points_);
}
meshObject::movePoints<polyMesh>(*this);
const_cast<Time&>(time()).functionObjects().movePoints(*this);
......
......@@ -26,8 +26,7 @@ License
#include "polyMesh.H"
#include "primitiveMesh.H"
#include "globalMeshData.H"
#include "pointMesh.H"
#include "Time.H"
#include "MeshObject.H"
#include "indexedOctree.H"
#include "treeDataCell.H"
......@@ -61,6 +60,8 @@ void Foam::polyMesh::clearGeom()
<< endl;
}
meshObject::clear<polyMesh, GeometricMeshObject>(*this);
primitiveMesh::clearGeom();
boundary_.clearGeom();
......@@ -101,6 +102,8 @@ void Foam::polyMesh::clearAddressing()
<< endl;