diff --git a/src/OpenFOAM/meshes/meshObjects/DemandDrivenMeshObject.C b/src/OpenFOAM/meshes/meshObjects/DemandDrivenMeshObject.C index b8e8a37685..bf0462e974 100644 --- a/src/OpenFOAM/meshes/meshObjects/DemandDrivenMeshObject.C +++ b/src/OpenFOAM/meshes/meshObjects/DemandDrivenMeshObject.C @@ -31,19 +31,12 @@ License template class MeshObjectType, class Type> Foam::DemandDrivenMeshObject::DemandDrivenMeshObject ( + const IOobject& io, const Mesh& mesh ) : - regIOobject - ( - IOobject - ( - Type::typeName, - mesh.thisDb().instance(), - mesh.thisDb() - ) - ), - MeshObjectType(*this, mesh), + regIOobject(io), + MeshObjectType(*this), mesh_(mesh) {} @@ -51,18 +44,67 @@ Foam::DemandDrivenMeshObject::DemandDrivenMeshObject template class MeshObjectType, class Type> Foam::DemandDrivenMeshObject::DemandDrivenMeshObject ( - const Mesh& mesh, - const IOobject& io + const word& name, + const Mesh& mesh ) : - regIOobject(io), - MeshObjectType(*this, mesh), + regIOobject + ( + IOobject + ( + name, + mesh.thisDb().instance(), + mesh.thisDb() + ) + ), + MeshObjectType(*this), mesh_(mesh) {} +template class MeshObjectType, class Type> +Foam::DemandDrivenMeshObject::DemandDrivenMeshObject +( + const Mesh& mesh +) +: + DemandDrivenMeshObject(Type::typeName, mesh) +{} + + // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // +template class MeshObjectType, class Type> +Type& Foam::DemandDrivenMeshObject::New +( + const word& name, + const Mesh& mesh +) +{ + if (found(name, mesh)) + { + return mesh.thisDb().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 MeshObjectType, class Type> Type& Foam::DemandDrivenMeshObject::New ( @@ -92,6 +134,39 @@ Type& Foam::DemandDrivenMeshObject::New } +template class MeshObjectType, class Type> +template +Type& Foam::DemandDrivenMeshObject::New +( + const word& name, + const Mesh& mesh, + const Args&... args +) +{ + if (found(name, mesh)) + { + return mesh.thisDb().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 MeshObjectType, class Type> template Type& Foam::DemandDrivenMeshObject::New @@ -125,38 +200,6 @@ Type& Foam::DemandDrivenMeshObject::New // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * // -template class MeshObjectType, class Type> -bool Foam::DemandDrivenMeshObject::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 - ( - mesh.thisDb().objectRegistry::template lookupObject - ( - Type::typeName - ) - ) - ); - } - else - { - return false; - } -} - - template class MeshObjectType, class Type> Foam::DemandDrivenMeshObject:: ~DemandDrivenMeshObject() @@ -178,13 +221,21 @@ Foam::DemandDrivenMeshObject::type() const template class MeshObjectType, class Type> bool Foam::DemandDrivenMeshObject::found ( + const word& name, const Mesh& mesh ) { - return mesh.thisDb().objectRegistry::template foundObject - ( - Type::typeName - ); + return mesh.thisDb().objectRegistry::template foundObject(name); +} + + +template class MeshObjectType, class Type> +bool Foam::DemandDrivenMeshObject::found +( + const Mesh& mesh +) +{ + return found(Type::typeName, mesh); } diff --git a/src/OpenFOAM/meshes/meshObjects/DemandDrivenMeshObject.H b/src/OpenFOAM/meshes/meshObjects/DemandDrivenMeshObject.H index a5003a0d50..897338d6a9 100644 --- a/src/OpenFOAM/meshes/meshObjects/DemandDrivenMeshObject.H +++ b/src/OpenFOAM/meshes/meshObjects/DemandDrivenMeshObject.H @@ -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 + 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 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 diff --git a/src/OpenFOAM/meshes/meshObjects/MeshObjects.H b/src/OpenFOAM/meshes/meshObjects/MeshObjects.H index 4fe3659b85..03ac44e3dc 100644 --- a/src/OpenFOAM/meshes/meshObjects/MeshObjects.H +++ b/src/OpenFOAM/meshes/meshObjects/MeshObjects.H @@ -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 + 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 + MoveableMeshObject(Type& mo) : - DeletableMeshObject(io, mesh) + DeletableMeshObject(mo) {} //- Update for mesh motion @@ -116,9 +118,10 @@ class DistributeableMeshObject { public: - DistributeableMeshObject(regIOobject& io, const Mesh& mesh) + template + DistributeableMeshObject(Type& mo) : - MoveableMeshObject(io, mesh) + MoveableMeshObject(mo) {} //- Redistribute or update using the given distribution map @@ -137,9 +140,10 @@ class TopoChangeableMeshObject { public: - TopoChangeableMeshObject(regIOobject& io, const Mesh& mesh) + template + TopoChangeableMeshObject(Type& mo) : - DistributeableMeshObject(io, mesh) + DistributeableMeshObject(mo) {} //- Update topology using the given map @@ -161,9 +165,10 @@ class RepatchableMeshObject { public: - RepatchableMeshObject(regIOobject& io, const Mesh& mesh) + template + RepatchableMeshObject(Type& mo) : - TopoChangeableMeshObject(io, mesh) + TopoChangeableMeshObject(mo) {} //- Reordered/removed trailing patches. If validBoundary call is parallel diff --git a/src/OpenFOAM/meshes/meshObjects/meshObjects.H b/src/OpenFOAM/meshes/meshObjects/meshObjects.H index cd39b39480..6f121a24ef 100644 --- a/src/OpenFOAM/meshes/meshObjects/meshObjects.H +++ b/src/OpenFOAM/meshes/meshObjects/meshObjects.H @@ -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 diff --git a/src/ThermophysicalTransportModels/fluid/laminar/Fickian/Fickian.C b/src/ThermophysicalTransportModels/fluid/laminar/Fickian/Fickian.C index e05dabd5ce..759527dfc2 100644 --- a/src/ThermophysicalTransportModels/fluid/laminar/Fickian/Fickian.C +++ b/src/ThermophysicalTransportModels/fluid/laminar/Fickian/Fickian.C @@ -141,7 +141,7 @@ Fickian::Fickian thermo ), - TopoChangeableMeshObject(*this, thermo.mesh()), + TopoChangeableMeshObject(*this), mixtureDiffusionCoefficients_(true), diff --git a/src/ThermophysicalTransportModels/fluid/laminar/MaxwellStefan/MaxwellStefan.C b/src/ThermophysicalTransportModels/fluid/laminar/MaxwellStefan/MaxwellStefan.C index baeb0e3477..dbb021864d 100644 --- a/src/ThermophysicalTransportModels/fluid/laminar/MaxwellStefan/MaxwellStefan.C +++ b/src/ThermophysicalTransportModels/fluid/laminar/MaxwellStefan/MaxwellStefan.C @@ -361,7 +361,7 @@ MaxwellStefan::MaxwellStefan thermo ), - TopoChangeableMeshObject(*this, thermo.mesh()), + TopoChangeableMeshObject(*this), DFuncs_(this->thermo().species().size()), diff --git a/src/ThermophysicalTransportModels/solid/anisotropic/anisotropic.C b/src/ThermophysicalTransportModels/solid/anisotropic/anisotropic.C index dacf769c4c..939c486403 100644 --- a/src/ThermophysicalTransportModels/solid/anisotropic/anisotropic.C +++ b/src/ThermophysicalTransportModels/solid/anisotropic/anisotropic.C @@ -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::anisotropic ) : SolidThermophysicalTransportModel(typeName, alpha, thermo), - TopoChangeableMeshObject(*this, thermo.mesh()), + TopoChangeableMeshObject(*this), coordinateSystem_(coordinateSystem::New(thermo.mesh(), this->coeffDict())), boundaryAligned_ ( diff --git a/src/finiteVolume/cfdTools/general/fvConstraints/fvConstraints.C b/src/finiteVolume/cfdTools/general/fvConstraints/fvConstraints.C index efaf6d70eb..9d01d5087d 100644 --- a/src/finiteVolume/cfdTools/general/fvConstraints/fvConstraints.C +++ b/src/finiteVolume/cfdTools/general/fvConstraints/fvConstraints.C @@ -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 ( - mesh, - createIOobject(mesh) + createIOobject(mesh), + mesh ), PtrListDictionary(0), checkTimeIndex_(mesh.time().timeIndex() + 1), diff --git a/src/finiteVolume/cfdTools/general/fvModels/fvModels.C b/src/finiteVolume/cfdTools/general/fvModels/fvModels.C index 03a56a4185..7c6f1c7f5f 100644 --- a/src/finiteVolume/cfdTools/general/fvModels/fvModels.C +++ b/src/finiteVolume/cfdTools/general/fvModels/fvModels.C @@ -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 ( - mesh, - createIOobject(mesh) + createIOobject(mesh), + mesh ), PtrListDictionary(0), checkTimeIndex_(mesh.time().timeIndex() + 1), diff --git a/src/finiteVolume/fvMesh/fvMeshDistributors/cpuLoad/cpuLoad.C b/src/finiteVolume/fvMesh/fvMeshDistributors/cpuLoad/cpuLoad.C index 59da26d777..2ddc7047d2 100644 --- a/src/finiteVolume/fvMesh/fvMeshDistributors/cpuLoad/cpuLoad.C +++ b/src/finiteVolume/fvMesh/fvMeshDistributors/cpuLoad/cpuLoad.C @@ -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 ( - 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 - ( - name - ) - ) - { - return mesh.thisDb().objectRegistry::template - lookupObjectRef - ( - 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(mesh)) { - return New(refCast(mesh), name, loadBalancing); + return New(name, refCast(mesh), loadBalancing); } else { diff --git a/src/finiteVolume/fvMesh/fvMeshDistributors/cpuLoad/cpuLoad.H b/src/finiteVolume/fvMesh/fvMeshDistributors/cpuLoad/cpuLoad.H index 8d411d9a82..112990d120 100644 --- a/src/finiteVolume/fvMesh/fvMeshDistributors/cpuLoad/cpuLoad.H +++ b/src/finiteVolume/fvMesh/fvMeshDistributors/cpuLoad/cpuLoad.H @@ -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 diff --git a/src/lagrangian/basic/Cloud/Cloud.C b/src/lagrangian/basic/Cloud/Cloud.C index 1841a79ea3..9448cb63e7 100644 --- a/src/lagrangian/basic/Cloud/Cloud.C +++ b/src/lagrangian/basic/Cloud/Cloud.C @@ -304,7 +304,7 @@ void Foam::Cloud::move optionalCpuLoad& cloudCpuTime ( - optionalCpuLoad::New(pMesh_, name() + ":cpuLoad", cloud.cpuLoad()) + optionalCpuLoad::New(name() + ":cpuLoad", pMesh_, cloud.cpuLoad()) ); // While there are particles to transfer diff --git a/src/meshTools/coordinateSystems/coordinateSystems.C b/src/meshTools/coordinateSystems/coordinateSystems.C index 2d65b0a73d..ee42faf17b 100644 --- a/src/meshTools/coordinateSystems/coordinateSystems.C +++ b/src/meshTools/coordinateSystems/coordinateSystems.C @@ -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() { diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/chemistryModel.C b/src/thermophysicalModels/chemistryModel/chemistryModel/chemistryModel.C index c397cf9669..5b3bbd4baf 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/chemistryModel.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/chemistryModel.C @@ -584,7 +584,7 @@ Foam::scalar Foam::chemistryModel::solve { optionalCpuLoad& chemistryCpuLoad ( - optionalCpuLoad::New(this->mesh(), name() + ":cpuLoad", cpuLoad_) + optionalCpuLoad::New(name() + ":cpuLoad", this->mesh(), cpuLoad_) ); // CPU time logging