Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
Henry Weller
committed
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM 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.
OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "MeshObject.H"
#include "objectRegistry.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Henry
committed
template<class Mesh, template<class> class MeshObjectType, class Type>
Foam::MeshObject<Mesh, MeshObjectType, Type>::MeshObject(const Mesh& mesh)
Henry
committed
MeshObjectType<Mesh>(Type::typeName, mesh.thisDb()),
mesh_(mesh)
{}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
Henry
committed
template<class Mesh, template<class> class MeshObjectType, class Type>
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
(
const Mesh& mesh
)
{
const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
Type::typeName
);
if (ptr)
Pout<< "MeshObject::New(const " << Mesh::typeName
<< "&) : constructing " << Type::typeName
<< " for region " << mesh.name() << endl;
Type* objectPtr = new Type(mesh);
regIOobject::store(static_cast<MeshObjectType<Mesh>*>(objectPtr));
return *objectPtr;
Henry
committed
template<class Mesh, template<class> class MeshObjectType, class Type>
Henry
committed
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
Type::typeName
);
if (ptr)
Pout<< "MeshObject::New(const " << Mesh::typeName
<< "&, const Data1&) : constructing " << Type::typeName
<< " for region " << mesh.name() << endl;
Type* objectPtr = new Type(mesh, d);
regIOobject::store(static_cast<MeshObjectType<Mesh>*>(objectPtr));
return *objectPtr;
Henry
committed
template<class Mesh, template<class> class MeshObjectType, class Type>
Henry
committed
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
(
const Mesh& mesh,
const Data1& d1,
const Data2& d2
)
{
const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
Type::typeName
);
if (ptr)
Pout<< "MeshObject::New(const " << Mesh::typeName
<< "&, const Data[1-2]&) : constructing " << Type::typeName
<< " for region " << mesh.name() << endl;
Type* objectPtr = new Type(mesh, d1, d2);
// Make sure to register the top level regIOobject for if Type itself
// is a regIOobject
regIOobject::store(static_cast<MeshObjectType<Mesh>*>(objectPtr));
return *objectPtr;
Henry
committed
template<class Mesh, template<class> class MeshObjectType, class Type>
Henry
committed
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
(
const Mesh& mesh,
const Data1& d1,
const Data2& d2,
const Data3& d3
)
{
const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
Type::typeName
);
if (ptr)
Pout<< "MeshObject::New(const " << Mesh::typeName
<< "&, const Data[1-3]&) : constructing " << Type::typeName
<< " for region " << mesh.name() << endl;
Type* objectPtr = new Type(mesh, d1, d2, d3);
regIOobject::store(static_cast<MeshObjectType<Mesh>*>(objectPtr));
return *objectPtr;
Henry
committed
template<class Mesh, template<class> class MeshObjectType, class Type>
template<class Data1, class Data2, class Data3, class Data4>
Henry
committed
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
(
const Mesh& mesh,
const Data1& d1,
const Data2& d2,
const Data3& d3,
const Data4& d4
)
{
const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
Type::typeName
);
if (ptr)
Pout<< "MeshObject::New(const " << Mesh::typeName
<< "&, const Data[1-4]&) : constructing " << Type::typeName
<< " for region " << mesh.name() << endl;
Type* objectPtr = new Type(mesh, d1, d2, d3, d4);
regIOobject::store(static_cast<MeshObjectType<Mesh>*>(objectPtr));
return *objectPtr;
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
Henry
committed
template<class Mesh, template<class> class MeshObjectType, class Type>
bool Foam::MeshObject<Mesh, MeshObjectType, Type>::Delete(const Mesh& mesh)
const Type* ptr = mesh.thisDb().objectRegistry::template findObject<Type>
Type::typeName
);
if (ptr)
if (meshObject::debug)
{
Pout<< "MeshObject::Delete(const Mesh&) : deleting "
<< Type::typeName << endl;
}
return mesh.thisDb().checkOut(const_cast<Type&>(*ptr));
}
else
{
return false;
}
}
Henry
committed
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)
Henry
committed
HashTable<GeometricMeshObject<Mesh>*> meshObjects
(
Henry Weller
committed
obr.lookupClass<GeometricMeshObject<Mesh>>()
Henry
committed
);
if (meshObject::debug)
{
Pout<< "meshObject::movePoints(objectRegistry&) :"
<< " moving " << Mesh::typeName
<< " meshObjects for region " << obr.name() << endl;
}
Henry
committed
forAllIter
(
typename HashTable<GeometricMeshObject<Mesh>*>,
meshObjects,
iter
)
{
Henry Weller
committed
if (isA<MoveableMeshObject<Mesh>>(*iter()))
Henry
committed
{
Henry
committed
dynamic_cast<MoveableMeshObject<Mesh>*>(iter())->movePoints();
}
else
{
Pout<< " Destroying " << iter()->name() << endl;
Henry
committed
obr.checkOut(*iter());
}
}
}
template<class Mesh>
void Foam::meshObject::updateMesh(objectRegistry& obr, const mapPolyMesh& mpm)
{
HashTable<GeometricMeshObject<Mesh>*> meshObjects
(
Henry Weller
committed
obr.lookupClass<GeometricMeshObject<Mesh>>()
Henry
committed
);
if (meshObject::debug)
{
Pout<< "meshObject::updateMesh(objectRegistry&, "
"const mapPolyMesh& mpm) : updating " << Mesh::typeName
<< " meshObjects for region " << obr.name() << endl;
}
Henry
committed
forAllIter
(
typename HashTable<GeometricMeshObject<Mesh>*>,
meshObjects,
iter
)
{
Henry Weller
committed
if (isA<UpdateableMeshObject<Mesh>>(*iter()))
Henry
committed
{
Henry
committed
dynamic_cast<UpdateableMeshObject<Mesh>*>(iter())->updateMesh(mpm);
}
else
{
Pout<< " Destroying " << iter()->name() << endl;
Henry
committed
obr.checkOut(*iter());
}
}
}
template<class Mesh, template<class> class MeshObjectType>
void Foam::meshObject::clear(objectRegistry& obr)
{
HashTable<MeshObjectType<Mesh>*> meshObjects
(
Henry Weller
committed
obr.lookupClass<MeshObjectType<Mesh>>()
Henry
committed
);
if (meshObject::debug)
{
Pout<< "meshObject::clear(objectRegistry&) :"
<< " clearing " << Mesh::typeName
<< " meshObjects for region " << obr.name() << endl;
}
Henry
committed
forAllIter(typename HashTable<MeshObjectType<Mesh>*>, meshObjects, iter)
{
Pout<< " Destroying " << iter()->name() << endl;
Henry
committed
obr.checkOut(*iter());
}
template
<
class Mesh,
template<class> class FromType,
template<class> class ToType
>
void Foam::meshObject::clearUpto(objectRegistry& obr)
{
HashTable<FromType<Mesh>*> meshObjects
(
Henry Weller
committed
obr.lookupClass<FromType<Mesh>>()
if (meshObject::debug)
{
Pout<< "meshObject::clearUpto(objectRegistry&) :"
<< " clearing " << Mesh::typeName
<< " meshObjects for region " << obr.name() << endl;
}
forAllIter(typename HashTable<FromType<Mesh>*>, meshObjects, iter)
{
Henry Weller
committed
if (!isA<ToType<Mesh>>(*iter()))
{
if (meshObject::debug)
{
Pout<< " Destroying " << iter()->name() << endl;
}
obr.checkOut(*iter());
}
}
}
// ************************************************************************* //