/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "DemandDrivenMeshObject.H"
#include "meshObjects.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
Foam::DemandDrivenMeshObject::
DemandDrivenMeshObject
(
const IOobject& io,
const Mesh& mesh
)
:
RegIOobject(io),
MeshObjectType(*this),
mesh_(mesh)
{}
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
Foam::DemandDrivenMeshObject::
DemandDrivenMeshObject
(
const word& name,
const Mesh& mesh
)
:
RegIOobject
(
IOobject
(
name,
mesh.db().instance(),
mesh.db()
)
),
MeshObjectType(*this),
mesh_(mesh)
{}
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
Foam::DemandDrivenMeshObject::
DemandDrivenMeshObject
(
const Mesh& mesh
)
:
DemandDrivenMeshObject
(
Type::typeName,
mesh
)
{}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
Type& Foam::DemandDrivenMeshObject::New
(
const word& name,
const Mesh& mesh
)
{
if (found(name, mesh))
{
return mesh.db().objectRegistry::template lookupObjectRef
(
name
);
}
else
{
if (meshObjects::debug)
{
Pout<< "DemandDrivenMeshObject::New(" << Mesh::typeName
<< "&) : constructing " << name
<< " of type " << Type::typeName
<< " for region " << mesh.name() << endl;
}
Type* objectPtr = new Type(name, mesh);
return regIOobject::store(objectPtr);
}
}
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
Type& Foam::DemandDrivenMeshObject::New
(
const Mesh& mesh
)
{
if (found(mesh))
{
return mesh.db().objectRegistry::template lookupObjectRef
(
Type::typeName
);
}
else
{
if (meshObjects::debug)
{
Pout<< "DemandDrivenMeshObject::New(" << Mesh::typeName
<< "&) : constructing " << Type::typeName
<< " for region " << mesh.name() << endl;
}
Type* objectPtr = new Type(mesh);
return regIOobject::store(objectPtr);
}
}
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
template
Type& Foam::DemandDrivenMeshObject::New
(
const word& name,
const Mesh& mesh,
const Args&... args
)
{
if (found(name, mesh))
{
return mesh.db().objectRegistry::template lookupObjectRef
(
name
);
}
else
{
if (meshObjects::debug)
{
Pout<< "DemandDrivenMeshObject::New(" << Mesh::typeName
<< "&, const Data1&) : constructing " << name
<< " of type " << Type::typeName
<< " for region " << mesh.name() << endl;
}
Type* objectPtr = new Type(name, mesh, args...);
return regIOobject::store(objectPtr);
}
}
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
template
Type& Foam::DemandDrivenMeshObject::New
(
const Mesh& mesh,
const Args&... args
)
{
if (found(mesh))
{
return mesh.db().objectRegistry::template lookupObjectRef
(
Type::typeName
);
}
else
{
if (meshObjects::debug)
{
Pout<< "DemandDrivenMeshObject::New(" << Mesh::typeName
<< "&, const Data1&) : constructing " << Type::typeName
<< " for region " << mesh.name() << endl;
}
Type* objectPtr = new Type(mesh, args...);
return regIOobject::store(objectPtr);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
Foam::DemandDrivenMeshObject::
~DemandDrivenMeshObject()
{
regIOobject::release();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
const Foam::word&
Foam::DemandDrivenMeshObject::
type() const
{
return Type::typeName;
}
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
bool Foam::DemandDrivenMeshObject::
found
(
const word& name,
const Mesh& mesh
)
{
return mesh.db().objectRegistry::template foundObject(name);
}
template
<
class Mesh,
template class MeshObjectType,
class Type,
class RegIOobject
>
bool Foam::DemandDrivenMeshObject::
found
(
const Mesh& mesh
)
{
return found(Type::typeName, mesh);
}
// ************************************************************************* //