Skip to content
Snippets Groups Projects
MeshObject.C 10 KiB
Newer Older
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    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"
#include "IOstreams.H"

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

template<class Mesh, template<class> class MeshObjectType, class Type>
Foam::MeshObject<Mesh, MeshObjectType, Type>::MeshObject(const Mesh& mesh)
    MeshObjectType<Mesh>(Type::typeName, mesh.thisDb()),
    mesh_(mesh)
{}


// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //

template<class Mesh, template<class> class MeshObjectType, class Type>
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
    const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
        if (meshObject::debug)
        {
Henry's avatar
Henry committed
            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;
template<class Mesh, template<class> class MeshObjectType, class Type>
mattijs's avatar
mattijs committed
template<class Data1>
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
mattijs's avatar
mattijs committed
    const Data1& d
    const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
        if (meshObject::debug)
        {
Henry's avatar
Henry committed
           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;
template<class Mesh, template<class> class MeshObjectType, class Type>
mattijs's avatar
mattijs committed
template<class Data1, class Data2>
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
mattijs's avatar
mattijs committed
(
    const Mesh& mesh,
    const Data1& d1,
    const Data2& d2
)
{
    const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
mattijs's avatar
mattijs committed
    {
mattijs's avatar
mattijs committed
    }
    else
    {
        if (meshObject::debug)
        {
Henry's avatar
Henry committed
           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;
template<class Mesh, template<class> class MeshObjectType, class Type>
mattijs's avatar
mattijs committed
template<class Data1, class Data2, class Data3>
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
mattijs's avatar
mattijs committed
(
    const Mesh& mesh,
    const Data1& d1,
    const Data2& d2,
    const Data3& d3
)
{
    const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
mattijs's avatar
mattijs committed
    {
mattijs's avatar
mattijs committed
    }
    else
    {
        if (meshObject::debug)
        {
Henry's avatar
Henry committed
           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;
template<class Mesh, template<class> class MeshObjectType, class Type>
mattijs's avatar
mattijs committed
template<class Data1, class Data2, class Data3, class Data4>
const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New
mattijs's avatar
mattijs committed
(
    const Mesh& mesh,
    const Data1& d1,
    const Data2& d2,
    const Data3& d3,
    const Data4& d4
)
{
    const Type* ptr = mesh.thisDb().objectRegistry::template cfindObject<Type>
mattijs's avatar
mattijs committed
    {
mattijs's avatar
mattijs committed
    }
    else
    {
        if (meshObject::debug)
        {
Henry's avatar
Henry committed
            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  * * * * * * * * * * * * * * //

template<class Mesh, template<class> class MeshObjectType, class Type>
bool Foam::MeshObject<Mesh, MeshObjectType, Type>::Delete(const Mesh& mesh)
mattijs's avatar
mattijs committed
{
    const Type* ptr = mesh.thisDb().objectRegistry::template findObject<Type>
mattijs's avatar
mattijs committed
    {
        if (meshObject::debug)
        {
            Pout<< "MeshObject::Delete(const Mesh&) : deleting "
                << Type::typeName << endl;
        }

        return mesh.thisDb().checkOut(const_cast<Type&>(*ptr));
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)
    HashTable<GeometricMeshObject<Mesh>*> meshObjects
    (
Henry's avatar
Henry committed
    if (meshObject::debug)
    {
        Pout<< "meshObject::movePoints(objectRegistry&) :"
            << " moving " << Mesh::typeName
            << " meshObjects for region " << obr.name() << endl;
    }

    forAllIter
    (
        typename HashTable<GeometricMeshObject<Mesh>*>,
        meshObjects,
        iter
    )
    {
            if (meshObject::debug)
            {
Henry's avatar
Henry committed
                Pout<< "    Moving " << iter()->name() << endl;
            dynamic_cast<MoveableMeshObject<Mesh>*>(iter())->movePoints();
        }
        else
        {
            if (meshObject::debug)
            {
Henry's avatar
Henry committed
                Pout<< "    Destroying " << iter()->name() << endl;
            obr.checkOut(*iter());
        }
    }
}


template<class Mesh>
void Foam::meshObject::updateMesh(objectRegistry& obr, const mapPolyMesh& mpm)
{
    HashTable<GeometricMeshObject<Mesh>*> meshObjects
    (
Henry's avatar
Henry committed
    if (meshObject::debug)
    {
        Pout<< "meshObject::updateMesh(objectRegistry&, "
               "const mapPolyMesh& mpm) : updating " << Mesh::typeName
            << " meshObjects for region " << obr.name() << endl;
    }

    forAllIter
    (
        typename HashTable<GeometricMeshObject<Mesh>*>,
        meshObjects,
        iter
    )
    {
            if (meshObject::debug)
            {
Henry's avatar
Henry committed
                Pout<< "    Updating " << iter()->name() << endl;
            dynamic_cast<UpdateableMeshObject<Mesh>*>(iter())->updateMesh(mpm);
        }
        else
        {
            if (meshObject::debug)
            {
Henry's avatar
Henry committed
                Pout<< "    Destroying " << iter()->name() << endl;
            obr.checkOut(*iter());
        }
    }
}


template<class Mesh, template<class> class MeshObjectType>
void Foam::meshObject::clear(objectRegistry& obr)
{
    HashTable<MeshObjectType<Mesh>*> meshObjects
    (
Henry's avatar
Henry committed
    if (meshObject::debug)
    {
        Pout<< "meshObject::clear(objectRegistry&) :"
            << " clearing " << Mesh::typeName
            << " meshObjects for region " << obr.name() << endl;
    }

    forAllIter(typename HashTable<MeshObjectType<Mesh>*>, meshObjects, iter)
    {
        if (meshObject::debug)
        {
Henry's avatar
Henry committed
            Pout<< "    Destroying " << iter()->name() << endl;
template
<
    class Mesh,
    template<class> class FromType,
    template<class> class ToType
>
void Foam::meshObject::clearUpto(objectRegistry& obr)
{
    HashTable<FromType<Mesh>*> meshObjects
    (
Henry's avatar
Henry committed
    if (meshObject::debug)
    {
        Pout<< "meshObject::clearUpto(objectRegistry&) :"
            << " clearing " << Mesh::typeName
            << " meshObjects for region " << obr.name() << endl;
    }

    forAllIter(typename HashTable<FromType<Mesh>*>, meshObjects, iter)
    {
        {
            if (meshObject::debug)
            {
Henry's avatar
Henry committed
                Pout<< "    Destroying " << iter()->name() << endl;
// ************************************************************************* //