From 13352861c8af4535f25c7def41ad382730fac504 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 7 Dec 2023 09:53:59 +0100 Subject: [PATCH] ENH: improve consistency in handling of global IOobjects (#3045) - replace typeGlobal() global function with is_globalIOobject traits for more consistent and easier overriding. - relocate typeFilePath() global function as a member of IOobject for consistency with typeHeaderOk. BUG: faSchemes, fvSchemes not marked as global file types - caused issues with collated --- applications/test/IOField/Make/files | 2 +- .../{Test-IOField.C => Test-IOField.cxx} | 16 +++ applications/test/IOobject-type/Make/files | 3 + applications/test/IOobject-type/Make/options | 9 ++ .../test/IOobject-type/Test-IOobject-type.cxx | 80 +++++++++++ .../foamUpgradeCyclics/foamUpgradeCyclics.C | 4 +- .../surfaceRedistributePar.C | 2 +- src/OpenFOAM/db/IOobject/IOobject.C | 11 ++ src/OpenFOAM/db/IOobject/IOobject.H | 62 +++++--- src/OpenFOAM/db/IOobject/IOobjectReadHeader.C | 136 +++++++++++++++++- src/OpenFOAM/db/IOobject/IOobjectTemplates.C | 90 +++--------- .../db/IOobjects/GlobalIOList/GlobalIOList.H | 9 +- .../db/IOobjects/GlobalIOList/globalIOLists.H | 41 +----- src/OpenFOAM/db/IOobjects/IOMap/IOMap.H | 7 + src/OpenFOAM/db/IOobjects/IOMap/IOMaps.C | 19 +-- .../db/IOobjects/IOdictionary/IOdictionary.H | 7 +- .../IOdictionary/unwatchedIOdictionary.H | 7 +- .../Fields/globalFields/globalIOFields.H | 37 +---- .../UniformDimensionedField.H | 7 + .../uniformDimensionedFieldsFwd.H | 34 ----- src/OpenFOAM/matrices/schemes/schemesLookup.H | 7 + .../coordinate/systems/coordinateSystems.H | 7 + .../componentDisplacementMotionSolver.C | 29 ++-- .../points0/points0MotionSolver.C | 29 ++-- .../finiteArea/faSchemes/faSchemes.H | 7 + .../porosityModel/porosityModel.H | 11 +- .../finiteVolume/fvSchemes/fvSchemes.H | 7 + .../refinementFeatures/refinementFeatures.C | 10 +- .../edgeFormats/edgeMesh/edgeMeshFormat.C | 2 +- .../extendedEdgeMesh/extendedEdgeMeshFormat.C | 2 +- .../extendedFeatureEdgeMesh.H | 9 +- .../featureEdgeMesh/featureEdgeMesh.H | 9 +- .../searchableSurface/searchableSurface.H | 9 +- .../triSurfaceMesh/triSurfaceMesh.C | 10 ++ .../triSurfaceMesh/triSurfaceMesh.H | 9 +- .../cellSources/fieldToCell/fieldToCell.C | 4 +- .../distributedTriSurfaceMesh.H | 9 +- 37 files changed, 453 insertions(+), 300 deletions(-) rename applications/test/IOField/{Test-IOField.C => Test-IOField.cxx} (94%) create mode 100644 applications/test/IOobject-type/Make/files create mode 100644 applications/test/IOobject-type/Make/options create mode 100644 applications/test/IOobject-type/Test-IOobject-type.cxx diff --git a/applications/test/IOField/Make/files b/applications/test/IOField/Make/files index 74e614deae5..4b70c3321ee 100644 --- a/applications/test/IOField/Make/files +++ b/applications/test/IOField/Make/files @@ -1,3 +1,3 @@ -Test-IOField.C +Test-IOField.cxx EXE = $(FOAM_USER_APPBIN)/Test-IOField diff --git a/applications/test/IOField/Test-IOField.C b/applications/test/IOField/Test-IOField.cxx similarity index 94% rename from applications/test/IOField/Test-IOField.C rename to applications/test/IOField/Test-IOField.cxx index d921dc09b0b..d9bfc1e0772 100644 --- a/applications/test/IOField/Test-IOField.C +++ b/applications/test/IOField/Test-IOField.cxx @@ -206,6 +206,22 @@ int main(int argc, char *argv[]) Info<< "Serial: using " << sz << nl; } + { + IOobject io + ( + "points", + mesh.time().constant(), + polyMesh::meshSubDir, + mesh + ); + + Info<< "points path: " << io.typeFilePath<labelIOList>() << nl; + Info<< "points path: " << io.typeFilePath<void>() << nl; + + io.resetHeader("bad-points"); + Info<< "bad path: " << io.typeFilePath<void>() << nl; + } + IOobject io ( "bla", diff --git a/applications/test/IOobject-type/Make/files b/applications/test/IOobject-type/Make/files new file mode 100644 index 00000000000..9956aabe125 --- /dev/null +++ b/applications/test/IOobject-type/Make/files @@ -0,0 +1,3 @@ +Test-IOobject-type.cxx + +EXE = $(FOAM_USER_APPBIN)/Test-IOobject-type diff --git a/applications/test/IOobject-type/Make/options b/applications/test/IOobject-type/Make/options new file mode 100644 index 00000000000..2526f4eb0e6 --- /dev/null +++ b/applications/test/IOobject-type/Make/options @@ -0,0 +1,9 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteArea/lnInclude \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +EXE_LIBS = \ + -lfiniteArea \ + -lfiniteVolume \ + -lmeshTools diff --git a/applications/test/IOobject-type/Test-IOobject-type.cxx b/applications/test/IOobject-type/Test-IOobject-type.cxx new file mode 100644 index 00000000000..a315fdca69e --- /dev/null +++ b/applications/test/IOobject-type/Test-IOobject-type.cxx @@ -0,0 +1,80 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2023 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/>. + +Description + Report global/local path for various types + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "Time.H" +#include "IOobject.H" +#include "IOdictionary.H" +#include "IOMap.H" +#include "coordinateSystems.H" +#include "faSchemes.H" +#include "fvSchemes.H" +#include "schemesLookup.H" +#include "scalarIOList.H" + +using namespace Foam; + + +template<class Type> +word report() +{ + if (is_globalIOobject<Type>::value) + { + return "global"; + } + else + { + return "local"; + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + Info<< "void: " << report<void>() << nl; + Info<< "IOobject: " << report<IOobject>() << nl; + Info<< "IOdictionary: " << report<IOdictionary>() << nl; + Info<< "faSchemes: " << report<faSchemes>() << nl; + Info<< "fvSchemes: " << report<fvSchemes>() << nl; + Info<< "schemesLookup: " << report<schemesLookup>() << nl; + Info<< "coordinateSystems: " << report<coordinateSystems>() << nl; + Info<< "IOMap<labelList>: " << report<IOMap<labelList>>() << nl; + Info<< "IOMap<dictionary>: " << report<IOMap<dictionary>>() << nl; + + Info<< "\nEnd\n" << endl; + + return 0; +} + + +// ************************************************************************* // diff --git a/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C b/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C index 18552515925..bb2c66d7845 100644 --- a/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C +++ b/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C @@ -79,8 +79,8 @@ void rewriteBoundary HashTable<word>& nbrNames ) { - Info<< "Reading boundary from " << typeFilePath<IOPtrList<entry>>(io) - << endl; + Info<< "Reading boundary from " + << io.typeFilePath<IOPtrList<entry>>() << nl; // Read PtrList of dictionary. const word oldTypeName = IOPtrList<entry>::typeName; diff --git a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C index 83f7fb66445..e1f6df76980 100644 --- a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C +++ b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C @@ -211,7 +211,7 @@ int main(int argc, char *argv[]) ); // Look for file (using searchableSurface rules) - const fileName actualPath(typeFilePath<searchableSurface>(io)); + const fileName actualPath(io.typeFilePath<searchableSurface>()); fileName localPath(actualPath); localPath.replace(runTime.rootPath() + '/', ""); diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index 055d69f76f8..33c50de2f20 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -561,6 +561,17 @@ Foam::fileName Foam::IOobject::globalFilePath } +// Foam::fileName Foam::IOobject::filePath +// ( +// const bool isGlobal, +// const word& typeName, +// const bool search +// ) const +// { +// return fileHandler().filePath(isGlobal, *this, typeName, search); +// } + + void Foam::IOobject::setBad(const string& s) { if (objState_ != objectState::GOOD) diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index 7379595e15c..0ae8fc61a40 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -105,6 +105,7 @@ SourceFiles #include "InfoProxy.H" #include "IOobjectOption.H" #include "IOstreamOption.H" +#include <type_traits> // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -196,6 +197,19 @@ private: //- Construct from registry, io options. Without name, instance, local IOobject(const objectRegistry& registry, IOobjectOption ioOpt); + //- Read header and check its info. + // Optionally checks headerClassName against the type-name. + // When search is false, simply use the current instance, + // otherwise search previous instances. + bool readAndCheckHeader + ( + const bool isGlobal, + const word& typeName, + const bool checkType = true, + const bool search = true, + const bool verbose = true + ); + protected: @@ -621,22 +635,42 @@ public: // Saves the header content in the given dictionary. bool readHeader(dictionary& headerDict, Istream& is); - //- Read header (uses typeFilePath to find file) and check its info. - // Optionally checks headerClassName against the type-name. - // When search is false, simply use the current instance, - // otherwise search previous instances. + //- Read header (respects is_globalIOobject trait) and check its info. template<class Type> bool typeHeaderOk ( + //! Check headerClassName against the type-name const bool checkType = true, + //! Also search previous instances if not found at current instance const bool search = true, + //! Report any check-type failures const bool verbose = true ); + //- Call localFilePath or globalFilePath for given type + //- depending on its is_globalIOobject trait. + template<class Type> + fileName typeFilePath(const bool search = true) const; + //- Helper: warn that type does not support re-reading template<class Type> void warnNoRereading() const; + //- Read header (localFilePath only) with optional searching + template<> + bool typeHeaderOk<void> + ( + //! ignored for \c void + const bool checkType, + const bool search, + //! ignored for \c void + const bool verbose + ); + + //- Call localFilePath for \c void type + template<> + fileName typeFilePath<void>(const bool search) const; + // Writing @@ -701,25 +735,9 @@ inline bool IOobject::isHeaderClass<void>() const } -//- Template function for obtaining global vs. local status +//- Trait for specifying global vs. local file types template<class T> -inline bool typeGlobal() -{ - return false; -} - - -//- Template function for obtaining local or global filePath -template<class T> -inline fileName typeFilePath(const IOobject& io, const bool search = true) -{ - return - ( - typeGlobal<T>() - ? io.globalFilePath(T::typeName, search) - : io.localFilePath(T::typeName, search) - ); -} +struct is_globalIOobject : std::false_type {}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index 94d764f079c..c100acdbfff 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2022 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,6 +29,8 @@ License #include "IOobject.H" #include "dictionary.H" #include "foamVersion.H" +#include "fileOperation.H" +#include "Pstream.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -171,4 +173,136 @@ bool Foam::IOobject::readHeader(Istream& is) } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::IOobject::readAndCheckHeader +( + const bool isGlobal, + const word& typeName, + const bool checkType, + const bool search, + const bool verbose +) +{ + // Mark as not yet read. cf, IOobject::readHeader() + headerClassName_.clear(); + + // Everyone check or just master + const bool masterOnly + ( + isGlobal + && ( + IOobject::fileModificationChecking == IOobject::timeStampMaster + || IOobject::fileModificationChecking == IOobject::inotifyMaster + ) + ); + + const auto& handler = Foam::fileHandler(); + + // Determine local status + bool ok = false; + + if (masterOnly) + { + if (UPstream::master()) + { + // Force master-only header reading + const bool oldParRun = UPstream::parRun(false); + const fileName fName + ( + handler.filePath(isGlobal, *this, typeName, search) + ); + ok = handler.readHeader(*this, fName, typeName); + UPstream::parRun(oldParRun); + + if + ( + ok && checkType + && !typeName.empty() && headerClassName_ != typeName + ) + { + ok = false; + if (verbose) + { + WarningInFunction + << "Unexpected class name \"" << headerClassName_ + << "\" expected \"" << typeName + << "\" when reading " << fName << endl; + } + } + } + + // If masterOnly make sure all processors know about the read + // information. Note: should ideally be inside fileHandler... + Pstream::broadcasts + ( + UPstream::worldComm, + ok, + headerClassName_, + note_ + ); + } + else + { + // All read header + const fileName fName + ( + handler.filePath(isGlobal, *this, typeName, search) + ); + ok = handler.readHeader(*this, fName, typeName); + + if + ( + ok && checkType + && !typeName.empty() && headerClassName_ != typeName + ) + { + ok = false; + if (verbose) + { + WarningInFunction + << "Unexpected class name \"" << headerClassName_ + << "\" expected \"" << typeName + << "\" when reading " << fName << endl; + } + } + } + + return ok; +} + + +// * * * * * * * * * * * * Template Specializations * * * * * * * * * * * * // + +namespace Foam +{ + +template<> +bool IOobject::typeHeaderOk<void> +( + const bool checkType, + const bool search, + const bool verbose +) +{ + return readAndCheckHeader + ( + false, // global = false + word::null, + false, // checkType = false (not meaningful) + search, + false // verbose = false (not meaningful) + ); +} + + +template<> +fileName IOobject::typeFilePath<void>(const bool search) const +{ + return this->localFilePath(word::null, search); +} + +} // End namespace Foam + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobject/IOobjectTemplates.C b/src/OpenFOAM/db/IOobject/IOobjectTemplates.C index 1ad0a63a308..635d0065b3e 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectTemplates.C +++ b/src/OpenFOAM/db/IOobject/IOobjectTemplates.C @@ -27,10 +27,10 @@ License \*---------------------------------------------------------------------------*/ #include "IOobject.H" -#include "fileOperation.H" -#include "Istream.H" #include "IOstreams.H" -#include "Pstream.H" +#include "fileOperation.H" // legacy include +#include "Istream.H" // legacy include +#include "Pstream.H" // legacy include // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -42,78 +42,26 @@ bool Foam::IOobject::typeHeaderOk const bool verbose ) { - // Mark as not yet read. cf, IOobject::readHeader() - headerClassName_.clear(); - - // Everyone check or just master - const bool masterOnly + return readAndCheckHeader ( - typeGlobal<Type>() - && ( - IOobject::fileModificationChecking == IOobject::timeStampMaster - || IOobject::fileModificationChecking == IOobject::inotifyMaster - ) + is_globalIOobject<Type>::value, + Type::typeName, + checkType, + search, + verbose ); +} - const fileOperation& fp = Foam::fileHandler(); - - // Determine local status - bool ok = false; - - if (masterOnly) - { - if (UPstream::master()) - { - // Force master-only header reading - const bool oldParRun = UPstream::parRun(false); - const fileName fName(typeFilePath<Type>(*this, search)); - ok = fp.readHeader(*this, fName, Type::typeName); - UPstream::parRun(oldParRun); - - if (ok && checkType && headerClassName_ != Type::typeName) - { - ok = false; - if (verbose) - { - WarningInFunction - << "Unexpected class name \"" << headerClassName_ - << "\" expected \"" << Type::typeName - << "\" when reading " << fName << endl; - } - } - } - - // If masterOnly make sure all processors know about the read - // information. Note: should ideally be inside fileHandler... - Pstream::broadcasts - ( - UPstream::worldComm, - ok, - headerClassName_, - note_ - ); - } - else - { - const fileName fName(typeFilePath<Type>(*this, search)); - - // All read header - ok = fp.readHeader(*this, fName, Type::typeName); - - if (ok && checkType && headerClassName_ != Type::typeName) - { - ok = false; - if (verbose) - { - WarningInFunction - << "Unexpected class name \"" << headerClassName_ - << "\" expected \"" << Type::typeName - << "\" when reading " << fName << endl; - } - } - } - return ok; +template<class Type> +Foam::fileName Foam::IOobject::typeFilePath(const bool search) const +{ + return + ( + is_globalIOobject<Type>::value + ? this->globalFilePath(Type::typeName, search) + : this->localFilePath(Type::typeName, search) + ); } diff --git a/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.H b/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.H index 666a02bb529..966a5976d98 100644 --- a/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.H +++ b/src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015-2017 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -121,6 +121,13 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for GlobalIOList +template<class T> +struct is_globalIOobject<GlobalIOList<T>> : std::true_type {}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/db/IOobjects/GlobalIOList/globalIOLists.H b/src/OpenFOAM/db/IOobjects/GlobalIOList/globalIOLists.H index 3f3cc0e1fc9..3a5278070b2 100644 --- a/src/OpenFOAM/db/IOobjects/GlobalIOList/globalIOLists.H +++ b/src/OpenFOAM/db/IOobjects/GlobalIOList/globalIOLists.H @@ -32,8 +32,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef globalIOLists_H -#define globalIOLists_H +#ifndef Foam_globalIOLists_H +#define Foam_globalIOLists_H #include "primitiveFields.H" #include "GlobalIOList.H" @@ -48,43 +48,6 @@ namespace Foam typedef GlobalIOList<sphericalTensor> sphericalTensorGlobalIOList; typedef GlobalIOList<symmTensor> symmTensorGlobalIOList; typedef GlobalIOList<tensor> tensorGlobalIOList; - - //- Template function for obtaining global status - template<> - inline bool typeGlobal<labelGlobalIOList>() - { - return true; - } - - template<> - inline bool typeGlobal<scalarGlobalIOList>() - { - return true; - } - - template<> - inline bool typeGlobal<vectorGlobalIOList>() - { - return true; - } - - template<> - inline bool typeGlobal<sphericalTensorGlobalIOList>() - { - return true; - } - - template<> - inline bool typeGlobal<symmTensorGlobalIOList>() - { - return true; - } - - template<> - inline bool typeGlobal<tensorGlobalIOList>() - { - return true; - } } diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H index 637c302a240..9cf43adee26 100644 --- a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H +++ b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H @@ -127,6 +127,13 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for IOMap +template<class T> +struct is_globalIOobject<IOMap<T>> : std::true_type {}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMaps.C b/src/OpenFOAM/db/IOobjects/IOMap/IOMaps.C index 97c84eb0d91..5d99f1940f5 100644 --- a/src/OpenFOAM/db/IOobjects/IOMap/IOMaps.C +++ b/src/OpenFOAM/db/IOobjects/IOMap/IOMaps.C @@ -29,27 +29,10 @@ License #include "IOMap.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + namespace Foam { defineTemplateTypeNameAndDebug(IOMap<dictionary>, 0); - - //- Template specialization for global status - template<> - bool typeGlobal<IOMap<dictionary>>() - { - return true; - } - - //- Template specialisation for obtaining filePath - template<> - fileName typeFilePath<IOMap<dictionary>> - ( - const IOobject& io, - const bool search - ) - { - return io.globalFilePath(IOMap<dictionary>::typeName, search); - } } diff --git a/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.H b/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.H index a10a3e25279..5c10205622c 100644 --- a/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.H +++ b/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionary.H @@ -116,12 +116,9 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -//- Template function for obtaining global status +//- Global file type for IOdictionary template<> -inline bool typeGlobal<IOdictionary>() -{ - return true; -} +struct is_globalIOobject<IOdictionary> : std::true_type {}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/IOobjects/IOdictionary/unwatchedIOdictionary.H b/src/OpenFOAM/db/IOobjects/IOdictionary/unwatchedIOdictionary.H index 549666a0278..bded2b07770 100644 --- a/src/OpenFOAM/db/IOobjects/IOdictionary/unwatchedIOdictionary.H +++ b/src/OpenFOAM/db/IOobjects/IOdictionary/unwatchedIOdictionary.H @@ -137,12 +137,9 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -//- Template function for obtaining global status +//- Global file type for unwatchedIOdictionary template<> -inline bool typeGlobal<unwatchedIOdictionary>() -{ - return true; -} +struct is_globalIOobject<unwatchedIOdictionary> : std::true_type {}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/Fields/globalFields/globalIOFields.H b/src/OpenFOAM/fields/Fields/globalFields/globalIOFields.H index 179a55cb19f..a5c249d1da2 100644 --- a/src/OpenFOAM/fields/Fields/globalFields/globalIOFields.H +++ b/src/OpenFOAM/fields/Fields/globalFields/globalIOFields.H @@ -32,8 +32,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef globalIOFields_H -#define globalIOFields_H +#ifndef Foam_globalIOFields_H +#define Foam_globalIOFields_H #include "primitiveFields.H" #include "GlobalIOField.H" @@ -48,39 +48,6 @@ namespace Foam typedef GlobalIOField<sphericalTensor> sphericalTensorGlobalIOField; typedef GlobalIOField<symmTensor> symmTensorGlobalIOField; typedef GlobalIOField<tensor> tensorGlobalIOField; - - //- Template function for obtaining global status - template<> - inline bool typeGlobal<labelGlobalIOField>() - { - return true; - } - template<> - inline bool typeGlobal<scalarGlobalIOField>() - { - return true; - } - template<> - inline bool typeGlobal<vectorGlobalIOField>() - { - return true; - } - template<> - inline bool typeGlobal<sphericalTensorGlobalIOField>() - { - return true; - } - template<> - inline bool typeGlobal<symmTensorGlobalIOField>() - { - return true; - } - template<> - inline bool typeGlobal<tensorGlobalIOField>() - { - return true; - } - } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/UniformDimensionedFields/UniformDimensionedField.H b/src/OpenFOAM/fields/UniformDimensionedFields/UniformDimensionedField.H index 0bd5ff35d39..c970ca0c413 100644 --- a/src/OpenFOAM/fields/UniformDimensionedFields/UniformDimensionedField.H +++ b/src/OpenFOAM/fields/UniformDimensionedFields/UniformDimensionedField.H @@ -152,6 +152,13 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for UniformDimensionedField +template<class Type> +struct is_globalIOobject<UniformDimensionedField<Type>> : std::true_type {}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/fields/UniformDimensionedFields/uniformDimensionedFieldsFwd.H b/src/OpenFOAM/fields/UniformDimensionedFields/uniformDimensionedFieldsFwd.H index 13b8d8c76f7..b288240f02d 100644 --- a/src/OpenFOAM/fields/UniformDimensionedFields/uniformDimensionedFieldsFwd.H +++ b/src/OpenFOAM/fields/UniformDimensionedFields/uniformDimensionedFieldsFwd.H @@ -73,40 +73,6 @@ typedef uniformDimensionedTensorField; -// Global file status - -template<> -inline bool typeGlobal<uniformDimensionedLabelField>() -{ - return true; -} -template<> -inline bool typeGlobal<uniformDimensionedScalarField>() -{ - return true; -} -template<> -inline bool typeGlobal<uniformDimensionedVectorField>() -{ - return true; -} -template<> -inline bool typeGlobal<uniformDimensionedSphericalTensorField>() -{ - return true; -} -template<> -inline bool typeGlobal<uniformDimensionedSymmTensorField>() -{ - return true; -} -template<> -inline bool typeGlobal<uniformDimensionedTensorField>() -{ - return true; -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/matrices/schemes/schemesLookup.H b/src/OpenFOAM/matrices/schemes/schemesLookup.H index 357dbc1070f..7c32e55be7d 100644 --- a/src/OpenFOAM/matrices/schemes/schemesLookup.H +++ b/src/OpenFOAM/matrices/schemes/schemesLookup.H @@ -385,6 +385,13 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for schemesLookup - same content for all ranks +template<> +struct is_globalIOobject<schemesLookup> : std::true_type {}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystems.H b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystems.H index 3f4b483f8a7..6dcce33a900 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystems.H +++ b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystems.H @@ -208,6 +208,13 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for coordinateSystems - same content for all ranks +template<> +struct is_globalIOobject<coordinateSystems> : std::true_type {}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/dynamicMesh/motionSolvers/componentDisplacement/componentDisplacementMotionSolver.C b/src/dynamicMesh/motionSolvers/componentDisplacement/componentDisplacementMotionSolver.C index 76ea901109e..b0a98da1995 100644 --- a/src/dynamicMesh/motionSolvers/componentDisplacement/componentDisplacementMotionSolver.C +++ b/src/dynamicMesh/motionSolvers/componentDisplacement/componentDisplacementMotionSolver.C @@ -110,23 +110,24 @@ Foam::componentDisplacementMotionSolver::componentDisplacementMotionSolver { if (points0_.size() != mesh.nPoints()) { + const fileName fName + ( + IOobject + ( + "points", + mesh.time().constant(), + polyMesh::meshSubDir, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER + ).typeFilePath<pointIOField>() + ); + FatalErrorInFunction << "Number of points in mesh " << mesh.nPoints() << " differs from number of points " << points0_.size() - << " read from file " - << typeFilePath<pointIOField> - ( - IOobject - ( - "points", - mesh.time().constant(), - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE, - IOobject::NO_REGISTER - ) - ) + << " read from file " << fName << nl << exit(FatalError); } } diff --git a/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C b/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C index f79067ef29e..4e3381d0e83 100644 --- a/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C +++ b/src/dynamicMesh/motionSolvers/displacement/points0/points0MotionSolver.C @@ -97,23 +97,24 @@ Foam::points0MotionSolver::points0MotionSolver } else if (points0_.size() != mesh.nPoints()) { + const fileName fName + ( + IOobject + ( + "points", + time().constant(), + polyMesh::meshSubDir, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER + ).typeFilePath<pointIOField>() + ); + FatalErrorInFunction << "Number of points in mesh " << mesh.nPoints() << " differs from number of points " << points0_.size() - << " read from file " - << typeFilePath<pointIOField> - ( - IOobject - ( - "points", - time().constant(), - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE, - IOobject::NO_REGISTER - ) - ) + << " read from file " << fName << nl << exit(FatalError); } } diff --git a/src/finiteArea/finiteArea/faSchemes/faSchemes.H b/src/finiteArea/finiteArea/faSchemes/faSchemes.H index 3c2b345e8eb..43cc9140343 100644 --- a/src/finiteArea/finiteArea/faSchemes/faSchemes.H +++ b/src/finiteArea/finiteArea/faSchemes/faSchemes.H @@ -129,6 +129,13 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for faSchemes - same content for all ranks +template<> +struct is_globalIOobject<faSchemes> : std::true_type {}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H index e6a8d62deff..1d6bb1f6103 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H +++ b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2018 OpenFOAM Foundation - Copyright (C) 2021-2022 OpenCFD Ltd. + Copyright (C) 2021-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -287,12 +287,11 @@ public: }; -//- Template function for obtaining global status +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for porosityModel template<> -inline bool typeGlobal<porosityModel>() -{ - return true; -} +struct is_globalIOobject<porosityModel> : std::true_type {}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.H b/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.H index a1d8bb401a7..fe49cd90923 100644 --- a/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.H +++ b/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.H @@ -129,6 +129,13 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for fvSchemes - same content for all ranks +template<> +struct is_globalIOobject<fvSchemes> : std::true_type {}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C b/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C index 4522e3e3a23..45e3db5e568 100644 --- a/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C +++ b/src/mesh/snappyHexMesh/refinementFeatures/refinementFeatures.C @@ -71,7 +71,10 @@ void Foam::refinementFeatures::read IOobject::NO_REGISTER ); - const fileName fName(typeFilePath<extendedFeatureEdgeMesh>(extFeatObj)); + const fileName fName + ( + extFeatObj.typeFilePath<extendedFeatureEdgeMesh>() + ); if (!fName.empty() && extendedEdgeMesh::canRead(fName)) { @@ -105,7 +108,10 @@ void Foam::refinementFeatures::read IOobject::NO_REGISTER ); - const fileName fName(typeFilePath<featureEdgeMesh>(featObj)); + const fileName fName + ( + featObj.typeFilePath<featureEdgeMesh>() + ); if (fName.empty()) { diff --git a/src/meshTools/edgeMesh/edgeFormats/edgeMesh/edgeMeshFormat.C b/src/meshTools/edgeMesh/edgeFormats/edgeMesh/edgeMeshFormat.C index 19790815700..1fd4d01a58e 100644 --- a/src/meshTools/edgeMesh/edgeFormats/edgeMesh/edgeMeshFormat.C +++ b/src/meshTools/edgeMesh/edgeFormats/edgeMesh/edgeMeshFormat.C @@ -74,7 +74,7 @@ bool Foam::fileFormats::edgeMeshFormat::read << exit(FatalError); } - const fileName fName(typeFilePath<featureEdgeMesh>(io)); + const fileName fName(io.typeFilePath<featureEdgeMesh>()); autoPtr<IFstream> isPtr(new IFstream(fName)); bool ok = false; diff --git a/src/meshTools/edgeMesh/extendedEdgeMesh/extendedEdgeMeshFormat.C b/src/meshTools/edgeMesh/extendedEdgeMesh/extendedEdgeMeshFormat.C index f33e32215b4..52c80805959 100644 --- a/src/meshTools/edgeMesh/extendedEdgeMesh/extendedEdgeMeshFormat.C +++ b/src/meshTools/edgeMesh/extendedEdgeMesh/extendedEdgeMeshFormat.C @@ -72,7 +72,7 @@ bool Foam::fileFormats::extendedEdgeMeshFormat::read << exit(FatalError); } - const fileName fName(typeFilePath<extendedFeatureEdgeMesh>(io)); + const fileName fName(io.typeFilePath<extendedFeatureEdgeMesh>()); autoPtr<IFstream> isPtr(new IFstream(fName)); bool ok = false; diff --git a/src/meshTools/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.H b/src/meshTools/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.H index 26190e2f1a8..b5fdf416241 100644 --- a/src/meshTools/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.H +++ b/src/meshTools/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.H @@ -154,12 +154,11 @@ public: }; -//- Template function for obtaining global status +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for extendedFeatureEdgeMesh template<> -inline bool typeGlobal<extendedFeatureEdgeMesh>() -{ - return true; -} +struct is_globalIOobject<extendedFeatureEdgeMesh> : std::true_type {}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/meshTools/edgeMesh/featureEdgeMesh/featureEdgeMesh.H b/src/meshTools/edgeMesh/featureEdgeMesh/featureEdgeMesh.H index d89db6b362f..b556f0af1aa 100644 --- a/src/meshTools/edgeMesh/featureEdgeMesh/featureEdgeMesh.H +++ b/src/meshTools/edgeMesh/featureEdgeMesh/featureEdgeMesh.H @@ -102,12 +102,11 @@ public: }; -//- Template function for obtaining global status +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for featureEdgeMesh template<> -inline bool typeGlobal<featureEdgeMesh>() -{ - return true; -} +struct is_globalIOobject<featureEdgeMesh> : std::true_type {}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/meshTools/searchableSurfaces/searchableSurface/searchableSurface.H b/src/meshTools/searchableSurfaces/searchableSurface/searchableSurface.H index a05928b6058..3dd458818bb 100644 --- a/src/meshTools/searchableSurfaces/searchableSurface/searchableSurface.H +++ b/src/meshTools/searchableSurfaces/searchableSurface/searchableSurface.H @@ -393,12 +393,11 @@ public: }; -//- Template function for obtaining global status +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for searchableSurface template<> -inline bool typeGlobal<searchableSurface>() -{ - return true; -} +struct is_globalIOobject<searchableSurface> : std::true_type {}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C index a8347693067..89768879059 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C @@ -431,6 +431,11 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const readAction r) : io.localFilePath(typeName) ); + // const fileName actualFile + // ( + // io.filePath(searchGlobal, typeName) + // ); + if (debug) { Pout<< "triSurfaceMesh(const IOobject& io) :" @@ -537,6 +542,11 @@ Foam::triSurfaceMesh::triSurfaceMesh : io.localFilePath(typeName) ); + // const fileName actualFile + // ( + // io.filePath(searchGlobal, typeName) + // ); + // Reading from supplied file name instead of objectPath/filePath if (dict.readIfPresent("file", fName_, keyType::LITERAL)) { diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H index 79502a40f6e..e5a18bdeb4b 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.H @@ -334,12 +334,11 @@ public: }; -//- Template function for obtaining global status +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for triSurfaceMesh template<> -inline bool typeGlobal<triSurfaceMesh>() -{ - return true; -} +struct is_globalIOobject<triSurfaceMesh> : std::true_type {}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/meshTools/topoSet/cellSources/fieldToCell/fieldToCell.C b/src/meshTools/topoSet/cellSources/fieldToCell/fieldToCell.C index 16e273f6654..f991f2f24b4 100644 --- a/src/meshTools/topoSet/cellSources/fieldToCell/fieldToCell.C +++ b/src/meshTools/topoSet/cellSources/fieldToCell/fieldToCell.C @@ -203,7 +203,7 @@ void Foam::fieldToCell::applyToSet // Note: cannot use volScalarField::typeName since that would // introduce linkage problems (finiteVolume needs meshTools) - IFstream str(typeFilePath<labelIOList>(fieldObject)); + IFstream str(fieldObject.typeFilePath<labelIOList>()); // Read as dictionary fieldDictionary fieldDict(fieldObject, fieldObject.headerClassName()); @@ -217,7 +217,7 @@ void Foam::fieldToCell::applyToSet // Note: cannot use volVectorField::typeName since that would // introduce linkage problems (finiteVolume needs meshTools) - IFstream str(typeFilePath<labelIOList>(fieldObject)); + IFstream str(fieldObject.typeFilePath<labelIOList>()); // Read as dictionary fieldDictionary fieldDict(fieldObject, fieldObject.headerClassName()); diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H index 3a38ad33f5b..05adb82d5c8 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.H @@ -602,12 +602,11 @@ public: }; -//- Template function for obtaining global status +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Global file type for distributedTriSurfaceMesh template<> -inline bool typeGlobal<distributedTriSurfaceMesh>() -{ - return false; -} +struct is_globalIOobject<distributedTriSurfaceMesh> : std::true_type {}; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -- GitLab