meshObjects: Formalise support for multiple named meshObjects of the same type
This commit is contained in:
@ -31,19 +31,12 @@ License
|
||||
template<class Mesh, template<class> class MeshObjectType, class Type>
|
||||
Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::DemandDrivenMeshObject
|
||||
(
|
||||
const IOobject& io,
|
||||
const Mesh& mesh
|
||||
)
|
||||
:
|
||||
regIOobject
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
Type::typeName,
|
||||
mesh.thisDb().instance(),
|
||||
mesh.thisDb()
|
||||
)
|
||||
),
|
||||
MeshObjectType<Mesh>(*this, mesh),
|
||||
regIOobject(io),
|
||||
MeshObjectType<Mesh>(*this),
|
||||
mesh_(mesh)
|
||||
{}
|
||||
|
||||
@ -51,18 +44,67 @@ Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::DemandDrivenMeshObject
|
||||
template<class Mesh, template<class> class MeshObjectType, class Type>
|
||||
Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::DemandDrivenMeshObject
|
||||
(
|
||||
const Mesh& mesh,
|
||||
const IOobject& io
|
||||
const word& name,
|
||||
const Mesh& mesh
|
||||
)
|
||||
:
|
||||
regIOobject(io),
|
||||
MeshObjectType<Mesh>(*this, mesh),
|
||||
regIOobject
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
name,
|
||||
mesh.thisDb().instance(),
|
||||
mesh.thisDb()
|
||||
)
|
||||
),
|
||||
MeshObjectType<Mesh>(*this),
|
||||
mesh_(mesh)
|
||||
{}
|
||||
|
||||
|
||||
template<class Mesh, template<class> class MeshObjectType, class Type>
|
||||
Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::DemandDrivenMeshObject
|
||||
(
|
||||
const Mesh& mesh
|
||||
)
|
||||
:
|
||||
DemandDrivenMeshObject<Mesh, MeshObjectType, Type>(Type::typeName, mesh)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Mesh, template<class> class MeshObjectType, class Type>
|
||||
Type& Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::New
|
||||
(
|
||||
const word& name,
|
||||
const Mesh& mesh
|
||||
)
|
||||
{
|
||||
if (found(name, mesh))
|
||||
{
|
||||
return mesh.thisDb().objectRegistry::template lookupObjectRef<Type>
|
||||
(
|
||||
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> class MeshObjectType, class Type>
|
||||
Type& Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::New
|
||||
(
|
||||
@ -92,6 +134,39 @@ Type& Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::New
|
||||
}
|
||||
|
||||
|
||||
template<class Mesh, template<class> class MeshObjectType, class Type>
|
||||
template<class... Args>
|
||||
Type& Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::New
|
||||
(
|
||||
const word& name,
|
||||
const Mesh& mesh,
|
||||
const Args&... args
|
||||
)
|
||||
{
|
||||
if (found(name, mesh))
|
||||
{
|
||||
return mesh.thisDb().objectRegistry::template lookupObjectRef<Type>
|
||||
(
|
||||
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> class MeshObjectType, class Type>
|
||||
template<class... Args>
|
||||
Type& Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::New
|
||||
@ -125,38 +200,6 @@ Type& Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::New
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Mesh, template<class> class MeshObjectType, class Type>
|
||||
bool Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::Delete
|
||||
(
|
||||
const Mesh& mesh
|
||||
)
|
||||
{
|
||||
if (found(mesh))
|
||||
{
|
||||
if (meshObjects::debug)
|
||||
{
|
||||
Pout<< "DemandDrivenMeshObject::Delete(const Mesh&) : deleting "
|
||||
<< Type::typeName << endl;
|
||||
}
|
||||
|
||||
return mesh.thisDb().checkOut
|
||||
(
|
||||
const_cast<Type&>
|
||||
(
|
||||
mesh.thisDb().objectRegistry::template lookupObject<Type>
|
||||
(
|
||||
Type::typeName
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Mesh, template<class> class MeshObjectType, class Type>
|
||||
Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::
|
||||
~DemandDrivenMeshObject()
|
||||
@ -178,13 +221,21 @@ Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::type() const
|
||||
template<class Mesh, template<class> class MeshObjectType, class Type>
|
||||
bool Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::found
|
||||
(
|
||||
const word& name,
|
||||
const Mesh& mesh
|
||||
)
|
||||
{
|
||||
return mesh.thisDb().objectRegistry::template foundObject<Type>
|
||||
(
|
||||
Type::typeName
|
||||
);
|
||||
return mesh.thisDb().objectRegistry::template foundObject<Type>(name);
|
||||
}
|
||||
|
||||
|
||||
template<class Mesh, template<class> class MeshObjectType, class Type>
|
||||
bool Foam::DemandDrivenMeshObject<Mesh, MeshObjectType, Type>::found
|
||||
(
|
||||
const Mesh& mesh
|
||||
)
|
||||
{
|
||||
return found(Type::typeName, mesh);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -109,13 +109,17 @@ protected:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from mesh
|
||||
// Only derived classes can construct DemandDrivenMeshObject
|
||||
DemandDrivenMeshObject(const Mesh& mesh);
|
||||
|
||||
//- Construct from mesh and IOobject
|
||||
// Only derived classes can construct DemandDrivenMeshObject
|
||||
DemandDrivenMeshObject(const Mesh& mesh, const IOobject& io);
|
||||
DemandDrivenMeshObject(const IOobject& io, const Mesh& mesh);
|
||||
|
||||
//- Construct from mesh and name
|
||||
// Only derived classes can construct DemandDrivenMeshObject
|
||||
DemandDrivenMeshObject(const word& name, const Mesh& mesh);
|
||||
|
||||
//- Construct from mesh, the name is set to Type::typeName
|
||||
// Only derived classes can construct DemandDrivenMeshObject
|
||||
DemandDrivenMeshObject(const Mesh& mesh);
|
||||
|
||||
|
||||
public:
|
||||
@ -126,8 +130,24 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct and return the named DemandDrivenMeshObject
|
||||
static Type& New(const word& name, const Mesh& mesh);
|
||||
|
||||
//- Construct and return the DemandDrivenMeshObject named Type::typeName
|
||||
static Type& New(const Mesh& mesh);
|
||||
|
||||
//- Construct and return the named DemandDrivenMeshObject
|
||||
// with the additional arguments
|
||||
template<class... Args>
|
||||
static Type& New
|
||||
(
|
||||
const word& name,
|
||||
const Mesh& mesh,
|
||||
const Args&... args
|
||||
);
|
||||
|
||||
//- Construct and return the DemandDrivenMeshObject named Type::typeName
|
||||
// with the additional arguments
|
||||
template<class... Args>
|
||||
static Type& New
|
||||
(
|
||||
@ -140,14 +160,15 @@ public:
|
||||
|
||||
virtual ~DemandDrivenMeshObject();
|
||||
|
||||
//- Lookup DemandDrivenMeshObject and delete
|
||||
static bool Delete(const Mesh& mesh);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return true if this DemandDrivenMeshObject is found
|
||||
// in the mesh registry
|
||||
//- Return true if the DemandDrivenMeshObject with the given name
|
||||
// is found in the mesh registry
|
||||
static bool found(const word& name, const Mesh& mesh);
|
||||
|
||||
//- Return true if the DemandDrivenMeshObject named Type::typeName
|
||||
// is found in the mesh registry
|
||||
static bool found(const Mesh& mesh);
|
||||
|
||||
const Mesh& mesh() const
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -74,9 +74,10 @@ class DeletableMeshObject
|
||||
|
||||
public:
|
||||
|
||||
DeletableMeshObject(regIOobject& io, const Mesh& mesh)
|
||||
template<class Type>
|
||||
DeletableMeshObject(Type& mo)
|
||||
:
|
||||
io_(io)
|
||||
io_(mo)
|
||||
{}
|
||||
|
||||
//- Virtual destructor to make class polymorphic
|
||||
@ -95,9 +96,10 @@ class MoveableMeshObject
|
||||
{
|
||||
public:
|
||||
|
||||
MoveableMeshObject(regIOobject& io, const Mesh& mesh)
|
||||
template<class Type>
|
||||
MoveableMeshObject(Type& mo)
|
||||
:
|
||||
DeletableMeshObject<Mesh>(io, mesh)
|
||||
DeletableMeshObject<Mesh>(mo)
|
||||
{}
|
||||
|
||||
//- Update for mesh motion
|
||||
@ -116,9 +118,10 @@ class DistributeableMeshObject
|
||||
{
|
||||
public:
|
||||
|
||||
DistributeableMeshObject(regIOobject& io, const Mesh& mesh)
|
||||
template<class Type>
|
||||
DistributeableMeshObject(Type& mo)
|
||||
:
|
||||
MoveableMeshObject<Mesh>(io, mesh)
|
||||
MoveableMeshObject<Mesh>(mo)
|
||||
{}
|
||||
|
||||
//- Redistribute or update using the given distribution map
|
||||
@ -137,9 +140,10 @@ class TopoChangeableMeshObject
|
||||
{
|
||||
public:
|
||||
|
||||
TopoChangeableMeshObject(regIOobject& io, const Mesh& mesh)
|
||||
template<class Type>
|
||||
TopoChangeableMeshObject(Type& mo)
|
||||
:
|
||||
DistributeableMeshObject<Mesh>(io, mesh)
|
||||
DistributeableMeshObject<Mesh>(mo)
|
||||
{}
|
||||
|
||||
//- Update topology using the given map
|
||||
@ -161,9 +165,10 @@ class RepatchableMeshObject
|
||||
{
|
||||
public:
|
||||
|
||||
RepatchableMeshObject(regIOobject& io, const Mesh& mesh)
|
||||
template<class Type>
|
||||
RepatchableMeshObject(Type& mo)
|
||||
:
|
||||
TopoChangeableMeshObject<Mesh>(io, mesh)
|
||||
TopoChangeableMeshObject<Mesh>(mo)
|
||||
{}
|
||||
|
||||
//- Reordered/removed trailing patches. If validBoundary call is parallel
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2022-2024 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -94,8 +94,6 @@ class polyDistributionMap;
|
||||
|
||||
class meshObjects
|
||||
{
|
||||
private:
|
||||
|
||||
//- Checkout and delete object if owned by registry
|
||||
// otherwise error
|
||||
template<class Mesh>
|
||||
|
||||
@ -141,7 +141,7 @@ Fickian<BasicThermophysicalTransportModel>::Fickian
|
||||
thermo
|
||||
),
|
||||
|
||||
TopoChangeableMeshObject(*this, thermo.mesh()),
|
||||
TopoChangeableMeshObject(*this),
|
||||
|
||||
mixtureDiffusionCoefficients_(true),
|
||||
|
||||
|
||||
@ -361,7 +361,7 @@ MaxwellStefan<BasicThermophysicalTransportModel>::MaxwellStefan
|
||||
thermo
|
||||
),
|
||||
|
||||
TopoChangeableMeshObject(*this, thermo.mesh()),
|
||||
TopoChangeableMeshObject(*this),
|
||||
|
||||
DFuncs_(this->thermo().species().size()),
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2022-2024 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -104,7 +104,7 @@ anisotropic<SolidThermophysicalTransportModel>::anisotropic
|
||||
)
|
||||
:
|
||||
SolidThermophysicalTransportModel(typeName, alpha, thermo),
|
||||
TopoChangeableMeshObject(*this, thermo.mesh()),
|
||||
TopoChangeableMeshObject(*this),
|
||||
coordinateSystem_(coordinateSystem::New(thermo.mesh(), this->coeffDict())),
|
||||
boundaryAligned_
|
||||
(
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2021-2024 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -142,8 +142,8 @@ Foam::fvConstraints::fvConstraints
|
||||
:
|
||||
DemandDrivenMeshObject<fvMesh, TopoChangeableMeshObject, fvConstraints>
|
||||
(
|
||||
mesh,
|
||||
createIOobject(mesh)
|
||||
createIOobject(mesh),
|
||||
mesh
|
||||
),
|
||||
PtrListDictionary<fvConstraint>(0),
|
||||
checkTimeIndex_(mesh.time().timeIndex() + 1),
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2021-2023 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2021-2024 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -147,8 +147,8 @@ Foam::fvModels::fvModels
|
||||
:
|
||||
DemandDrivenMeshObject<fvMesh, TopoChangeableMeshObject, fvModels>
|
||||
(
|
||||
mesh,
|
||||
createIOobject(mesh)
|
||||
createIOobject(mesh),
|
||||
mesh
|
||||
),
|
||||
PtrListDictionary<fvModel>(0),
|
||||
checkTimeIndex_(mesh.time().timeIndex() + 1),
|
||||
|
||||
@ -40,17 +40,12 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::cpuLoad::cpuLoad(const fvMesh& mesh, const word& name)
|
||||
Foam::cpuLoad::cpuLoad( const word& name, const fvMesh& mesh)
|
||||
:
|
||||
DemandDrivenMeshObject<fvMesh, TopoChangeableMeshObject, cpuLoad>
|
||||
(
|
||||
mesh,
|
||||
IOobject
|
||||
(
|
||||
name,
|
||||
mesh.time().name(),
|
||||
mesh
|
||||
)
|
||||
name,
|
||||
mesh
|
||||
),
|
||||
scalarField(mesh.nCells(), 0.0)
|
||||
{}
|
||||
@ -66,43 +61,19 @@ Foam::cpuLoad::~cpuLoad()
|
||||
|
||||
Foam::optionalCpuLoad& Foam::optionalCpuLoad::New
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const word& name,
|
||||
const fvMesh& mesh,
|
||||
const bool loadBalancing
|
||||
)
|
||||
{
|
||||
if (loadBalancing)
|
||||
{
|
||||
if
|
||||
(
|
||||
mesh.thisDb().objectRegistry::template
|
||||
foundObject<cpuLoad>
|
||||
(
|
||||
name
|
||||
)
|
||||
)
|
||||
{
|
||||
return mesh.thisDb().objectRegistry::template
|
||||
lookupObjectRef<cpuLoad>
|
||||
(
|
||||
name
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cpuLoad::debug)
|
||||
{
|
||||
InfoInFunction
|
||||
<< "constructing " << name
|
||||
<< " for region " << mesh.name() << endl;
|
||||
}
|
||||
|
||||
cpuLoad* cpuLoadPtr(new cpuLoad(mesh, name));
|
||||
|
||||
regIOobject::store(cpuLoadPtr);
|
||||
|
||||
return *cpuLoadPtr;
|
||||
}
|
||||
return DemandDrivenMeshObject
|
||||
<
|
||||
fvMesh,
|
||||
TopoChangeableMeshObject,
|
||||
cpuLoad
|
||||
>::New(name, mesh);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -113,14 +84,14 @@ Foam::optionalCpuLoad& Foam::optionalCpuLoad::New
|
||||
|
||||
Foam::optionalCpuLoad& Foam::optionalCpuLoad::New
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const word& name,
|
||||
const polyMesh& mesh,
|
||||
const bool loadBalancing
|
||||
)
|
||||
{
|
||||
if (loadBalancing && isA<fvMesh>(mesh))
|
||||
{
|
||||
return New(refCast<const fvMesh>(mesh), name, loadBalancing);
|
||||
return New(name, refCast<const fvMesh>(mesh), loadBalancing);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -83,8 +83,8 @@ public:
|
||||
// otherwise return the dummy optionalCpuLoad
|
||||
static optionalCpuLoad& New
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const word& name,
|
||||
const fvMesh& mesh,
|
||||
const bool loadBalancing
|
||||
);
|
||||
|
||||
@ -92,8 +92,8 @@ public:
|
||||
// otherwise return the dummy optionalCpuLoad
|
||||
static optionalCpuLoad& New
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const word& name,
|
||||
const polyMesh& mesh,
|
||||
const bool loadBalancing
|
||||
);
|
||||
|
||||
@ -151,8 +151,8 @@ public:
|
||||
//- Construct from mesh, name and switch
|
||||
cpuLoad
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const word& name
|
||||
const word& name,
|
||||
const fvMesh& mesh
|
||||
);
|
||||
|
||||
//- Disallow default bitwise copy construction
|
||||
|
||||
@ -304,7 +304,7 @@ void Foam::Cloud<ParticleType>::move
|
||||
|
||||
optionalCpuLoad& cloudCpuTime
|
||||
(
|
||||
optionalCpuLoad::New(pMesh_, name() + ":cpuLoad", cloud.cpuLoad())
|
||||
optionalCpuLoad::New(name() + ":cpuLoad", pMesh_, cloud.cpuLoad())
|
||||
);
|
||||
|
||||
// While there are particles to transfer
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -51,7 +51,6 @@ Foam::coordinateSystems::coordinateSystems::coordinateSystems
|
||||
coordinateSystems
|
||||
>
|
||||
(
|
||||
obr,
|
||||
IOobject
|
||||
(
|
||||
typeName,
|
||||
@ -59,7 +58,8 @@ Foam::coordinateSystems::coordinateSystems::coordinateSystems
|
||||
obr,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE
|
||||
)
|
||||
),
|
||||
obr
|
||||
),
|
||||
PtrDictionary<coordinateSystem>()
|
||||
{
|
||||
|
||||
@ -584,7 +584,7 @@ Foam::scalar Foam::chemistryModel<ThermoType>::solve
|
||||
{
|
||||
optionalCpuLoad& chemistryCpuLoad
|
||||
(
|
||||
optionalCpuLoad::New(this->mesh(), name() + ":cpuLoad", cpuLoad_)
|
||||
optionalCpuLoad::New(name() + ":cpuLoad", this->mesh(), cpuLoad_)
|
||||
);
|
||||
|
||||
// CPU time logging
|
||||
|
||||
Reference in New Issue
Block a user