From 39d244ad918cab9e19c5a5e68ac6ebaad9c67bb6 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 17 Nov 2021 19:51:22 +0100 Subject: [PATCH] ENH: add check for isTimeDb() into objectRegistry - add missing time() into pointMesh STYLE: use static_cast instead of dynamic_cast for Time -> objectRegistry --- .../test/objectRegistry/Test-objectRegistry.C | 5 ++++- src/OpenFOAM/db/objectRegistry/objectRegistry.C | 10 ++++++++-- src/OpenFOAM/db/objectRegistry/objectRegistry.H | 17 ++++++++++------- src/OpenFOAM/meshes/pointMesh/pointMesh.C | 2 +- src/OpenFOAM/meshes/pointMesh/pointMesh.H | 9 ++++++++- .../surfactantProperties.H | 2 +- .../cyclicAMIPointPatch/cyclicAMIPointPatch.C | 2 +- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/applications/test/objectRegistry/Test-objectRegistry.C b/applications/test/objectRegistry/Test-objectRegistry.C index ecea969e82..5c3078b2d9 100644 --- a/applications/test/objectRegistry/Test-objectRegistry.C +++ b/applications/test/objectRegistry/Test-objectRegistry.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -146,6 +146,9 @@ int main(int argc, char *argv[]) const objectRegistry& db = (optMesh ? mesh.thisDb() : runTime); Info<<"## start ##" << nl; + Info<< "db isTime:" << db.isTimeDb() << " addr:" << Foam::name(&db) + << " time: " << Foam::name(&(db.time())) << nl; + printRegistry(Info, db); Info<< nl; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index 1d8c2a8e4b..7ec979ae37 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -71,9 +71,9 @@ static label eraseImpl(objectRegistry& obr, InputIter first, InputIter last) // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -bool Foam::objectRegistry::parentNotTime() const +bool Foam::objectRegistry::parentNotTime() const noexcept { - return (&parent_ != dynamic_cast(&time_)); + return (&parent_ != static_cast(&time_)); } @@ -125,6 +125,12 @@ Foam::objectRegistry::~objectRegistry() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +bool Foam::objectRegistry::isTimeDb() const noexcept +{ + return (this == &static_cast(time_)); +} + + Foam::HashTable Foam::objectRegistry::classes() const { return classesImpl(*this, predicates::always()); diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index 0af9263b4e..fbdec2463b 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -82,7 +82,7 @@ class objectRegistry //- Is the objectRegistry parent_ different from time_ // Used to terminate searching within the ancestors - bool parentNotTime() const; + bool parentNotTime() const noexcept; //- Templated implementation for count() // The number of items with a matching class @@ -169,17 +169,20 @@ public: return *this; } + //- Return the parent objectRegistry + const objectRegistry& parent() const noexcept + { + return parent_; + } + //- Return time registry const Time& time() const noexcept { return time_; } - //- Return the parent objectRegistry - const objectRegistry& parent() const noexcept - { - return parent_; - } + //- True if the registry is Time + bool isTimeDb() const noexcept; //- Local directory path of this objectRegistry relative to the time virtual const fileName& dbDir() const diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.C b/src/OpenFOAM/meshes/pointMesh/pointMesh.C index 383cf15dd1..fec7502d4b 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.C +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.C @@ -94,7 +94,7 @@ bool Foam::pointMesh::movePoints() { if (debug) { - Pout<< "pointMesh::movePoints(const pointField&): " + Pout<< "pointMesh::movePoints(): " << "Moving points." << endl; } diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.H b/src/OpenFOAM/meshes/pointMesh/pointMesh.H index a651a74424..4fb0831867 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.H +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -53,7 +54,7 @@ class pointMesh public MeshObject, public GeoMesh { - // Permanent data + // Permanent Data //- Boundary mesh pointBoundaryMesh boundary_; @@ -123,6 +124,12 @@ public: return GeoMesh::mesh_.thisDb(); } + //- Return Time from polyMesh. + const Time& time() const + { + return GeoMesh::mesh_.time(); + } + // Mesh motion diff --git a/src/dynamicFaMesh/interfaceTrackingFvMesh/surfactantProperties.H b/src/dynamicFaMesh/interfaceTrackingFvMesh/surfactantProperties.H index 3806a61d20..47e997fec7 100644 --- a/src/dynamicFaMesh/interfaceTrackingFvMesh/surfactantProperties.H +++ b/src/dynamicFaMesh/interfaceTrackingFvMesh/surfactantProperties.H @@ -183,7 +183,7 @@ public: IOobject ( "dSigma", - surfactConc.mesh().mesh().time().timeName(), + surfactConc.mesh().time().timeName(), surfactConc.mesh().mesh(), IOobject::NO_READ, IOobject::NO_WRITE diff --git a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPointPatch/cyclicAMIPointPatch.C b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPointPatch/cyclicAMIPointPatch.C index f4cecf6275..e35103afd3 100644 --- a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPointPatch/cyclicAMIPointPatch.C +++ b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPointPatch/cyclicAMIPointPatch.C @@ -113,7 +113,7 @@ bool Foam::cyclicAMIPointPatch::coupled() const { return Pstream::parRun() - || !this->boundaryMesh().mesh().mesh().time().processorCase(); + || !this->boundaryMesh().mesh().time().processorCase(); }