/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation ------------------------------------------------------------------------------- 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 . \*---------------------------------------------------------------------------*/ #include "MeshObject.H" #include "objectRegistry.H" #include "IOstreams.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template class MeshObjectType, class Type> Foam::MeshObject::MeshObject(const Mesh& mesh) : MeshObjectType(Type::typeName, mesh.thisDb()), mesh_(mesh) {} // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // template class MeshObjectType, class Type> template const Type& Foam::MeshObject::New ( const Mesh& mesh, Args&&... args ) { const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject ( Type::typeName ); if (ptr) { return *ptr; } if (meshObject::debug) { Pout<< "MeshObject::New(const " << Mesh::typeName << "&, ...) : constructing " << Type::typeName << " for region " << mesh.name() << endl; } Type* objectPtr = new Type(mesh, std::forward(args)...); regIOobject::store(static_cast*>(objectPtr)); return *objectPtr; } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * // template class MeshObjectType, class Type> bool Foam::MeshObject::Delete(const Mesh& mesh) { Type* ptr = mesh.thisDb().objectRegistry::template getObjectPtr ( Type::typeName ); if (ptr) { if (meshObject::debug) { Pout<< "MeshObject::Delete(const Mesh&) : deleting " << Type::typeName << endl; } return mesh.thisDb().checkOut(*ptr); } return false; } template class MeshObjectType, class Type> Foam::MeshObject::~MeshObject() { // We should not do a 'release' at this point since that will upset // the destructor of regIOobject itself (which gets called after this). // However this is only a problem for Time-based MeshObject. MeshObjectType::release(); } template void Foam::meshObject::movePoints(objectRegistry& obr) { HashTable*> meshObjects ( obr.lookupClass>() ); if (meshObject::debug) { Pout<< "meshObject::movePoints(objectRegistry&) :" << " moving " << Mesh::typeName << " meshObjects for region " << obr.name() << endl; } forAllIters(meshObjects, iter) { // Same as (isA>(*iter())) auto* objectPtr = dynamic_cast*>(iter()); if (objectPtr) { if (meshObject::debug) { Pout<< " Moving " << iter->name() << endl; } objectPtr->movePoints(); } else { if (meshObject::debug) { Pout<< " Destroying " << iter->name() << endl; } obr.checkOut(*iter()); } } } template void Foam::meshObject::updateMesh(objectRegistry& obr, const mapPolyMesh& mpm) { HashTable*> meshObjects ( obr.lookupClass>() ); if (meshObject::debug) { Pout<< "meshObject::updateMesh(objectRegistry&, " "const mapPolyMesh& mpm) : updating " << Mesh::typeName << " meshObjects for region " << obr.name() << endl; } forAllIters(meshObjects, iter) { // Same as (isA>(*iter())) auto* objectPtr = dynamic_cast*>(iter()); if (objectPtr) { if (meshObject::debug) { Pout<< " Updating " << iter->name() << endl; } objectPtr->updateMesh(mpm); } else { if (meshObject::debug) { Pout<< " Destroying " << iter->name() << endl; } obr.checkOut(*iter()); } } } template class MeshObjectType> void Foam::meshObject::clear(objectRegistry& obr) { HashTable*> meshObjects ( obr.lookupClass>() ); if (meshObject::debug) { Pout<< "meshObject::clear(objectRegistry&) :" << " clearing " << Mesh::typeName << " meshObjects for region " << obr.name() << endl; } forAllIters(meshObjects, iter) { if (meshObject::debug) { Pout<< " Destroying " << iter->name() << endl; } obr.checkOut(*iter()); } } template < class Mesh, template class FromType, template class ToType > void Foam::meshObject::clearUpto(objectRegistry& obr) { HashTable*> meshObjects ( obr.lookupClass>() ); if (meshObject::debug) { Pout<< "meshObject::clearUpto(objectRegistry&) :" << " clearing " << Mesh::typeName << " meshObjects for region " << obr.name() << endl; } forAllIters(meshObjects, iter) { if (!isA>(*iter())) { if (meshObject::debug) { Pout<< " Destroying " << iter->name() << endl; } obr.checkOut(*iter()); } } } // ************************************************************************* //