diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/createSolidFields.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/createSolidFields.H index fa5966905b..c67ccb8558 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/createSolidFields.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/createSolidFields.H @@ -35,7 +35,7 @@ ( solidRegions[i], thermos[i], - coordinateSystem::typeName_() + coordinateSystem::typeName ) ); diff --git a/applications/solvers/heatTransfer/solidFoam/createFields.H b/applications/solvers/heatTransfer/solidFoam/createFields.H index 85942bc625..15f9bc5b89 100644 --- a/applications/solvers/heatTransfer/solidFoam/createFields.H +++ b/applications/solvers/heatTransfer/solidFoam/createFields.H @@ -15,7 +15,7 @@ if (!thermo.isotropic()) ( mesh, thermo, - coordinateSystem::typeName_() + coordinateSystem::typeName ); tmp tkappaByCp = thermo.Kappa()/thermo.Cp(); diff --git a/applications/test/coordinateSystem/Test-coordinateSystem.C b/applications/test/coordinateSystem/Test-coordinateSystem.C index 174389b6c6..d105eca379 100644 --- a/applications/test/coordinateSystem/Test-coordinateSystem.C +++ b/applications/test/coordinateSystem/Test-coordinateSystem.C @@ -59,11 +59,11 @@ void basicTests(const coordinateSystem& cs) { cs.writeEntry(cs.name(), Info); - if (const auto* cartptr = isA(cs)) + if ((const auto* cartptr = isA(cs)) != nullptr) { - if (!cartptr->active()) + if (!cartptr->valid()) { - Info<< "inactive cartesian = " << (*cartptr) + Info<< "invalid cartesian = " << (*cartptr) << " with: " << (*cartptr).R() << nl; } } @@ -106,7 +106,7 @@ void doTest(const dictionary& dict) try { - auto cs1ptr = coordinateSystem::New(dict, ""); + auto cs1ptr = coordinateSystem::New(dict, word::null); coordinateSystem& cs1 = *cs1ptr; cs1.rename(dict.dictName()); diff --git a/applications/test/coordinateSystem/testCase1/constant/coordinateSystems b/applications/test/coordinateSystem/testCase1/constant/coordinateSystems index 4dad7d4ad5..b71719a317 100644 --- a/applications/test/coordinateSystem/testCase1/constant/coordinateSystems +++ b/applications/test/coordinateSystem/testCase1/constant/coordinateSystems @@ -51,11 +51,8 @@ cs4 { type cylindrical; origin (0 3 5); - rotation - { - type euler; - angles (90 0 0); - } + rotation euler; + angles (90 0 0); } cyl @@ -75,10 +72,7 @@ cyl ident { origin (0 0 0); - rotation - { - type none; - } + rotation none; } ) diff --git a/applications/test/coordinateSystem/testCsys1 b/applications/test/coordinateSystem/testCsys1 index f09006d94f..a3c76c53cd 100644 --- a/applications/test/coordinateSystem/testCsys1 +++ b/applications/test/coordinateSystem/testCsys1 @@ -26,7 +26,7 @@ rot_x90 rot_x90_axesRotation { origin (0 0 0); - coordinateRotation + rotation { type axesRotation; e1 (1 0 0); @@ -37,7 +37,7 @@ rot_x90_axesRotation rot_x90_axisAngle { origin (0 0 0); - coordinateRotation + rotation { type axisAngle; axis (1 0 0); // non-unit also OK @@ -48,7 +48,7 @@ rot_x90_axisAngle rot_x90_euler { origin (0 0 0); - coordinateRotation + rotation { type euler; angles (0 90 0); // z-x'-z'' @@ -61,7 +61,7 @@ rot_x90_euler rot_z45_axesRotation { origin (0 0 0); - coordinateRotation + rotation { type axesRotation; e1 (1 1 0); @@ -72,7 +72,7 @@ rot_z45_axesRotation rot_z45_axisAngle { origin (0 0 0); - coordinateRotation + rotation { type axisAngle; axis (0 0 10); // non-unit also OK @@ -83,7 +83,7 @@ rot_z45_axisAngle rot_z45_euler { origin (0 0 0); - coordinateRotation + rotation { type euler; angles (45 0 0); // z-x'-z'' @@ -93,7 +93,7 @@ rot_z45_euler rot_z45_starcd { origin (0 0 0); - coordinateRotation + rotation { type starcd; angles (45 0 0); // z-x'-y'' @@ -106,7 +106,7 @@ rot_z45_starcd rot_zm45_axesRotation { origin (0 0 0); - coordinateRotation + rotation { type axesRotation; e1 (1 -1 0); @@ -117,7 +117,7 @@ rot_zm45_axesRotation rot_zm45_axisAngle { origin (0 0 0); - coordinateRotation + rotation { type axisAngle; axis (0 0 10); // non-unit also OK @@ -128,7 +128,7 @@ rot_zm45_axisAngle rot_zm45_euler { origin (0 0 0); - coordinateRotation + rotation { type euler; angles (-45 0 0); // z-x'-z'' @@ -141,7 +141,7 @@ rot_zm45_euler null_axesRotation { origin (0 0 0); - coordinateRotation + rotation { type axesRotation; e1 (1 0 0); @@ -152,7 +152,7 @@ null_axesRotation null_axisAngle0 { origin (0 0 0); - coordinateRotation + rotation { type axisAngle; axis (0 0 0); // non-unit also OK @@ -163,7 +163,7 @@ null_axisAngle0 null_axisAngle1 { origin (0 0 0); - coordinateRotation + rotation { type axisAngle; axis (1 1 1); // non-unit also OK @@ -174,7 +174,7 @@ null_axisAngle1 null_euler { origin (0 0 0); - coordinateRotation + rotation { type euler; angles (0 0 0); // z-x'-z'' diff --git a/src/OpenFOAM/primitives/coordinate/rotation/coordinateRotation.C b/src/OpenFOAM/primitives/coordinate/rotation/coordinateRotation.C index e1c744fd55..2041baf310 100644 --- a/src/OpenFOAM/primitives/coordinate/rotation/coordinateRotation.C +++ b/src/OpenFOAM/primitives/coordinate/rotation/coordinateRotation.C @@ -68,15 +68,19 @@ Foam::vector Foam::coordinateRotation::findOrthogonal(const vector& axis) // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // -Foam::autoPtr Foam::coordinateRotation::New +Foam::autoPtr +Foam::coordinateRotation::New ( - word modelType, + const word& modelType, const dictionary& dict ) { + // Direct dispatch + // - treat missing modelType as 'axes' (eg, e1/e3 specification) + if (modelType.empty()) { - modelType = coordinateRotations::axes::typeName_(); + return autoPtr(new coordinateRotations::axes(dict)); } auto* ctorPtr = dictionaryConstructorTable(modelType); @@ -96,7 +100,8 @@ Foam::autoPtr Foam::coordinateRotation::New } -Foam::autoPtr Foam::coordinateRotation::New +Foam::autoPtr +Foam::coordinateRotation::New ( const dictionary& dict ) diff --git a/src/OpenFOAM/primitives/coordinate/rotation/coordinateRotation.H b/src/OpenFOAM/primitives/coordinate/rotation/coordinateRotation.H index 9af2af452e..32c5e81493 100644 --- a/src/OpenFOAM/primitives/coordinate/rotation/coordinateRotation.H +++ b/src/OpenFOAM/primitives/coordinate/rotation/coordinateRotation.H @@ -65,6 +65,7 @@ SourceFiles #include "vector.H" #include "tensor.H" #include "dictionary.H" +#include "IOobjectOption.H" #include "runTimeSelectionTables.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -119,7 +120,7 @@ public: // An empty modelType will be treated as "axes" (eg, e1/e3) static autoPtr New ( - word modelType, + const word& modelType, const dictionary& dict ); diff --git a/src/OpenFOAM/primitives/coordinate/systems/cartesianCS.C b/src/OpenFOAM/primitives/coordinate/systems/cartesianCS.C index 46574df247..4cdf66579c 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/cartesianCS.C +++ b/src/OpenFOAM/primitives/coordinate/systems/cartesianCS.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,12 +46,6 @@ const Foam::coordSystem::cartesian Foam::coordSystem::cartesian::null; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::coordSystem::cartesian::cartesian() -: - coordinateSystem() -{} - - Foam::coordSystem::cartesian::cartesian(const coordinateSystem& csys) : coordinateSystem(csys) @@ -111,24 +105,19 @@ Foam::coordSystem::cartesian::cartesian Foam::coordSystem::cartesian::cartesian ( - const word& name, - const dictionary& dict + const dictionary& dict, + IOobjectOption::readOption readOrigin ) : - coordinateSystem(name, dict) -{} - - -Foam::coordSystem::cartesian::cartesian(const dictionary& dict) -: - coordinateSystem(dict) + coordinateSystem(dict, readOrigin) {} Foam::coordSystem::cartesian::cartesian ( const dictionary& dict, - const word& dictName + const word& dictName, + IOobjectOption::readOption readOrigin ) : coordinateSystem(dict, dictName) diff --git a/src/OpenFOAM/primitives/coordinate/systems/cartesianCS.H b/src/OpenFOAM/primitives/coordinate/systems/cartesianCS.H index d3387fde48..111db8100e 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/cartesianCS.H +++ b/src/OpenFOAM/primitives/coordinate/systems/cartesianCS.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -75,8 +75,8 @@ public: // Constructors - //- Default construct. This is an identity coordinate system - cartesian(); + //- Default construct. Identity coordinate system. + cartesian() = default; //- Copy construct cartesian(const cartesian& csys) = default; @@ -110,7 +110,7 @@ public: const vector& dirn ); - //- Construct from origin and 2 axes + //- Construct named from origin and 2 axes cartesian ( const word& name, @@ -119,16 +119,32 @@ public: const vector& dirn ); - //- Construct from dictionary with a given name - cartesian(const word& name, const dictionary& dict); - - //- Construct from dictionary without a name - explicit cartesian(const dictionary& dict); - - //- Construct from dictionary with optional subDict lookup. + //- Construct from dictionary with optional + //- read handling for the 'origin' entry (default: MUST_READ). // - // \param dictName If non-empty, the sub-dictionary to use. - cartesian(const dictionary& dict, const word& dictName); + // \note The readOrigin is downgraded to READ_IF_PRESENT + // if the dictionary itself is "coordinateSystem" + explicit cartesian + ( + const dictionary& dict, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ + ); + + //- Construct from dictionary with optional subDict lookup and optional + //- read handling for the 'origin' entry (default: MUST_READ). + // + // \param dictName If non-empty, mandatory sub-dictionary to use. + // + // \note The readOrigin is downgraded to READ_IF_PRESENT + // if the dictionary itself is "coordinateSystem" + // or if a sub-dictionary is being used + cartesian + ( + const dictionary& dict, + const word& dictName, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ + ); + //- Return clone virtual autoPtr clone() const diff --git a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystem.C b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystem.C index bdd56fd1bb..c02f1d787a 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystem.C +++ b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystem.C @@ -48,28 +48,47 @@ Foam::coordinateSystem Foam::coordinateSystem::dummy_(nullptr); // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // -namespace Foam +namespace { - //- Is it cartesian? - // For output, can treat the base class as Cartesian too, - // since it defaults to cartesian on input. - static inline bool isCartesian(const word& modelType) - { - return - ( - modelType == coordinateSystem::typeName_() - || modelType == coordSystem::cartesian::typeName_() - ); - } -} // End namespace Foam +//- Can we ignore the 'type' on output? +// For output, can treat the base class as Cartesian too, +// since it defaults to cartesian on input. +inline bool ignoreOutputCoordType(const std::string& modelType) +{ + return + ( + modelType.empty() + || modelType == Foam::coordSystem::cartesian::typeName + || modelType == Foam::coordinateSystem::typeName + ); +} + +} // End anonymous namespace // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // -void Foam::coordinateSystem::assign(const dictionary& dict) +void Foam::coordinateSystem::assign +( + const dictionary& dict, + IOobjectOption::readOption readOrigin +) { - dict.readEntry("origin", origin_); + origin_ = Zero; + + // The 'origin' is optional if using "coordinateSystem" dictionary itself + if + ( + IOobjectOption::isReadRequired(readOrigin) + && (dict.dictName() == coordinateSystem::typeName) + ) + { + readOrigin = IOobjectOption::READ_IF_PRESENT; + } + + dict.readEntry("origin", origin_, keyType::LITERAL, readOrigin); + note_.clear(); dict.readIfPresent("note", note_); @@ -89,7 +108,8 @@ void Foam::coordinateSystem::assign(const dictionary& dict) } else { - // Use current dict. Type specified by "rotation" entry itself. + // Type specified by "rotation" primitive entry, with the balance + // of the rotation specified within the current dictionary too const word rotationType(finder->get()); spec_.reset(coordinateRotation::New(rotationType, dict)); } @@ -244,43 +264,37 @@ Foam::coordinateSystem::coordinateSystem Foam::coordinateSystem::coordinateSystem ( - const word& name, - const dictionary& dict + const dictionary& dict, + IOobjectOption::readOption readOrigin ) -: - spec_(nullptr), - origin_(Zero), - rot_(sphericalTensor::I), - name_(name), - note_() -{ - assign(dict); -} - - -Foam::coordinateSystem::coordinateSystem(const dictionary& dict) : coordinateSystem(nullptr) { - assign(dict); + assign(dict, readOrigin); } Foam::coordinateSystem::coordinateSystem ( const dictionary& dict, - const word& dictName + const word& dictName, + IOobjectOption::readOption readOrigin ) : coordinateSystem(nullptr) { if (dictName.size()) { - assign(dict.subDict(dictName)); + // Allow 'origin' to be optional if reading from a sub-dict + if (IOobjectOption::isReadRequired(readOrigin)) + { + readOrigin = IOobjectOption::READ_IF_PRESENT; + } + assign(dict.subDict(dictName), readOrigin); } else { - assign(dict); + assign(dict, readOrigin); } } @@ -419,8 +433,8 @@ void Foam::coordinateSystem::write(Ostream& os) const return; } - // Suppress output of type for Cartesian - if (!isCartesian(type())) + // Suppress output of type for 'cartesian', 'coordinateSystem', ... + if (!ignoreOutputCoordType(type())) { os << type() << ' '; } @@ -432,7 +446,7 @@ void Foam::coordinateSystem::write(Ostream& os) const void Foam::coordinateSystem::writeEntry(Ostream& os) const { - writeEntry(coordinateSystem::typeName_(), os); + writeEntry(coordinateSystem::typeName, os); } @@ -449,8 +463,8 @@ void Foam::coordinateSystem::writeEntry(const word& keyword, Ostream& os) const { os.beginBlock(keyword); - // Suppress output of type for Cartesian - if (!isCartesian(type())) + // Suppress output of type for 'cartesian', 'coordinateSystem', ... + if (!ignoreOutputCoordType(type())) { os.writeEntry("type", type()); } diff --git a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystem.H b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystem.H index 1ab249407f..c6879c2fde 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystem.H +++ b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystem.H @@ -105,6 +105,7 @@ Description SourceFiles coordinateSystem.C coordinateSystemNew.C + coordinateSystemTemplates.C coordinateSystemTransform.C \*---------------------------------------------------------------------------*/ @@ -144,6 +145,59 @@ class indirect; class coordinateSystem { + // Private Member Functions + + //- Select construct specified coordinate system type + // + // \param modelType Eg, cartesian, cylindrical, indirect + // An empty modelType will be treated as "cartesian". + // \param dict The specifications + // \param readOrigin The preferred handling for reading 'origin' + // \param obrPtr Optional reference to an objectRegistry + // (for indirect entries). + static autoPtr New + ( + const word& modelType, + const dictionary& dict, + IOobjectOption::readOption readOrigin, + const objectRegistry* obrPtr + ); + + //- Select constructed from dictionary + // + // \param dict The top-level dictionary contents + // \param dictName The sub-dictionary name to use for the + // coordinate system specifications. An empty name invokes + // an implicit search for a "coordinateSystem" sub-dictionary + // which is convenient and provides compatibility with previous + // versions (1806 and earlier). + // \param readOrigin The preferred handling for reading 'origin' + // \param obrPtr The objectRegistry for lookup of indirect entries. + static autoPtr New + ( + const dictionary& dict, + const word& dictName, + IOobjectOption::readOption readOrigin, + const objectRegistry* obrPtr + ); + + //- Optional select construct from dictionary + // + // \param dict The top-level dictionary to search + // \param dictName The sub-dictionary name to select. + // Return nullptr if it does not exist. + // \param obrPtr The objectRegistry for lookup of indirect entries. + // + // Since the specifications are isolated within a sub-dictionary, + // the 'origin' entry is treated as optional + static autoPtr NewIfPresent + ( + const dictionary& dict, + const word& dictName, + const objectRegistry* obrPtr + ); + + protected: //- Friendship with indirect for dispatching to its underlying system @@ -246,9 +300,13 @@ protected: bool translate ) const; - - //- Assign from dictionary content - void assign(const dictionary& dict); + //- Assign from dictionary content with specified read handling + //- of the 'origin' entry + void assign + ( + const dictionary& dict, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ + ); // Constructors @@ -264,7 +322,7 @@ public: TypeName("coordinateSystem"); //- Helper for construction of coordinateSystem PtrList - // The Istream contains a word followed by a dictionary + // The Istream contains a word followed by a dictionary. struct iNew { autoPtr operator()(Istream& is) const @@ -324,7 +382,7 @@ public: const coordinateRotation& crot ); - //- Construct from origin and 2 axes + //- Construct named from origin and 2 axes coordinateSystem ( const word& name, @@ -333,16 +391,31 @@ public: const vector& dirn ); - //- Construct from dictionary with a given name - coordinateSystem(const word& name, const dictionary& dict); - - //- Construct from dictionary without a name - explicit coordinateSystem(const dictionary& dict); - - //- Construct from dictionary with optional subDict lookup. + //- Construct from dictionary with optional + //- read handling for the 'origin' entry (default: MUST_READ). // - // \param dictName If non-empty, the sub-dictionary to use. - coordinateSystem(const dictionary& dict, const word& dictName); + // \note The readOrigin is downgraded to READ_IF_PRESENT + // if the dictionary itself is "coordinateSystem" + explicit coordinateSystem + ( + const dictionary& dict, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ + ); + + //- Construct from dictionary with optional subDict lookup and optional + //- read handling for the 'origin' entry (default: MUST_READ). + // + // \param dictName If non-empty, mandatory sub-dictionary to use. + // + // \note The readOrigin is downgraded to READ_IF_PRESENT + // if the dictionary itself is "coordinateSystem" + // or if a sub-dictionary is being used + coordinateSystem + ( + const dictionary& dict, + const word& dictName, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ + ); //- Return clone @@ -359,9 +432,10 @@ public: coordinateSystem, dictionary, ( - const dictionary& dict + const dictionary& dict, + IOobjectOption::readOption readOrigin ), - (dict) + (dict, readOrigin) ); // Declare run-time constructor selection table @@ -372,9 +446,10 @@ public: registry, ( const objectRegistry& obr, - const dictionary& dict + const dictionary& dict, + IOobjectOption::readOption readOrigin ), - (obr, dict) + (obr, dict, readOrigin) ); @@ -386,9 +461,10 @@ public: // An empty modelType will be treated as "cartesian" static autoPtr New ( - word modelType, + const word& modelType, const objectRegistry& obr, - const dictionary& dict + const dictionary& dict, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ ); //- Select construct the specified coordinate system type @@ -396,8 +472,9 @@ public: // An empty modelType will be treated as "cartesian" static autoPtr New ( - word modelType, - const dictionary& dict + const word& modelType, + const dictionary& dict, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ ); //- Select construct from dictionary with reference to objectRegistry @@ -413,7 +490,8 @@ public: ( const objectRegistry& obr, const dictionary& dict, - const word& dictName = "" + const word& dictName = word::null, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ ); //- Select constructed from dictionary @@ -426,12 +504,50 @@ public: static autoPtr New ( const dictionary& dict, - const word& dictName = "" + const word& dictName = word::null, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ ); //- Select constructed from Istream // Expects a name/dictionary as input - static autoPtr New(Istream& is); + static autoPtr New + ( + Istream& is, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ + ); + + + //- Optional select construct from dictionary, with registry reference + // + // \param obr The objectRegistry (for lookup of indirect entries) + // \param dict The top-level dictionary to search + // \param dictName The sub-dictionary name to select the + // for coordinate system specification + // (default is 'coordinateSystem'). + // + // Since the specifications are isolated within a sub-dictionary, + // the 'origin' entry is treated as optional + static autoPtr NewIfPresent + ( + const objectRegistry& obr, + const dictionary& dict, + const word& dictName = coordinateSystem::typeName + ); + + //- Optional select construct from dictionary + // + // \param dict The top-level dictionary to search + // \param dictName The sub-dictionary name to select the + // for coordinate system specification + // (default is 'coordinateSystem'). + // + // Since the specifications are isolated within a sub-dictionary, + // the 'origin' entry is treated as optional + static autoPtr NewIfPresent + ( + const dictionary& dict, + const word& dictName = coordinateSystem::typeName + ); //- Destructor diff --git a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystemNew.C b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystemNew.C index a7ab9d2f8a..806fade521 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/coordinateSystemNew.C +++ b/src/OpenFOAM/primitives/coordinate/systems/coordinateSystemNew.C @@ -30,34 +30,106 @@ License #include "cartesianCS.H" #include "indirectCS.H" -// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -namespace Foam -{ - -// Handle a 'coordinateSystem' sub-dictionary -// In 1806 and earlier, this was handled (rather poorly) in the -// coordinateSystem constructor itself. -static const dictionary* subDictCompat +Foam::autoPtr +Foam::coordinateSystem::New ( - const word& entryName, - const dictionary* dictPtr + const word& modelType, + const dictionary& dict, + IOobjectOption::readOption readOrigin, + const objectRegistry* obrPtr ) { - if (entryName.empty() || !dictPtr) + // Direct dispatch + // - treat missing modelType as 'cartesian' + + if (modelType.empty()) { - return nullptr; + return autoPtr + ( + new coordSystem::cartesian(dict, readOrigin) + ); } - const auto finder = dictPtr->csearch(entryName, keyType::LITERAL); - if (finder.good()) + // Dispatch with objectRegistry reference (if possible) + if (obrPtr) { + auto* ctorPtr = registryConstructorTable(modelType); + + if (ctorPtr) + { + return autoPtr + ( + ctorPtr(*obrPtr, dict, readOrigin) + ); + } + } + + // Regular dispatch + // Note: everything with a registry constructor also has a + // dictionary constructor, so just need to print those on error. + + auto* ctorPtr = dictionaryConstructorTable(modelType); + + if (!ctorPtr) + { + FatalIOErrorInLookup + ( + dict, + "coordinate system", + modelType, + *dictionaryConstructorTablePtr_ + ) << exit(FatalIOError); + } + + return autoPtr(ctorPtr(dict, readOrigin)); +} + + +Foam::autoPtr +Foam::coordinateSystem::New +( + const dictionary& dict, + const word& dictName, + IOobjectOption::readOption readOrigin, + const objectRegistry* obrPtr +) +{ + const dictionary* dictPtr = nullptr; + + // If dictName is non-empty: treat as mandatory + // Include fallback handling of 'coordinateSystem' sub-dictionary + // In 1806 and earlier, this was handled (rather poorly) in the + // coordinateSystem constructor itself + + if (!dictName.empty()) + { + const auto finder = dict.csearch(dictName, keyType::LITERAL); + if (finder.isDict()) { - return finder.dictPtr(); + dictPtr = finder.dictPtr(); } else + { + // Missing or primitive entry: trigger fatal error + dictPtr = &(dict.subDict(dictName, keyType::LITERAL)); + } + } + else + { + // Search for "coordinateSystem" sub-dictionary + + const auto finder = + dict.csearch(coordinateSystem::typeName, keyType::LITERAL); + + if (finder.isDict()) + { + dictPtr = finder.dictPtr(); + } + else if (finder.good()) { const word csName(finder.ref().stream()); @@ -66,10 +138,10 @@ static const dictionary* subDictCompat { std::cerr << "--> FOAM IOWarning :" << nl - << " Ignoring '" << entryName << "' as a keyword." - " Perhaps you meant this instead?" << nl + << " Ignoring '" << coordinateSystem::typeName + << "' as a keyword. Perhaps you meant this instead?" << nl << '{' << nl - << " type " << coordSystem::indirect::typeName_() + << " type " << coordSystem::indirect::typeName << ';' << nl << " name " << csName << ';' << nl << '}' << nl @@ -80,148 +152,164 @@ static const dictionary* subDictCompat } } - return dictPtr; + + if (dictPtr) + { + // Using a sub-dictionary + // - the 'origin' can be optional + if (IOobjectOption::isReadRequired(readOrigin)) + { + readOrigin = IOobjectOption::READ_IF_PRESENT; + } + } + else + { + // Using top-level dictionary + dictPtr = &dict; + } + + + // The coordinate-system type (if not cartesian) + word modelType; + dictPtr->readIfPresent("type", modelType, keyType::LITERAL); + + return coordinateSystem::New + ( + modelType, + *dictPtr, + readOrigin, + obrPtr + ); } -} // End namespace Foam + +Foam::autoPtr +Foam::coordinateSystem::NewIfPresent +( + const dictionary& dict, + const word& dictName, + const objectRegistry* obrPtr +) +{ + const dictionary* dictPtr = nullptr; + + if + ( + dictName.empty() + || (dictPtr = dict.findDict(dictName, keyType::LITERAL)) == nullptr + ) + { + return nullptr; + } + + // The coordinate-system type (if not cartesian) + word modelType; + dictPtr->readIfPresent("type", modelType, keyType::LITERAL); + + return coordinateSystem::New + ( + modelType, + *dictPtr, + IOobjectOption::READ_IF_PRESENT, + obrPtr + ); +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -Foam::autoPtr Foam::coordinateSystem::New +Foam::autoPtr +Foam::coordinateSystem::New ( - word modelType, - const objectRegistry& obr, - const dictionary& dict + Istream& is, + IOobjectOption::readOption readOrigin ) -{ - if (modelType.empty()) - { - modelType = coordSystem::cartesian::typeName_(); - } - - { - auto* ctorPtr = registryConstructorTable(modelType); - if (ctorPtr) - { - return autoPtr(ctorPtr(obr, dict)); - } - } - - auto* ctorPtr = dictionaryConstructorTable(modelType); - - // Everything with a registry constructor also has a dictionary - // constructor, so just need to print those. - if (!ctorPtr) - { - FatalIOErrorInLookup - ( - dict, - "coordinate system", - modelType, - *dictionaryConstructorTablePtr_ - ) << exit(FatalIOError); - } - - return autoPtr(ctorPtr(dict)); -} - - -Foam::autoPtr Foam::coordinateSystem::New -( - word modelType, - const dictionary& dict -) -{ - if (modelType.empty()) - { - modelType = coordSystem::cartesian::typeName_(); - } - - auto* ctorPtr = dictionaryConstructorTable(modelType); - - if (!ctorPtr) - { - FatalIOErrorInLookup - ( - dict, - "coordinate system", - modelType, - *dictionaryConstructorTablePtr_ - ) << exit(FatalIOError); - } - - return autoPtr(ctorPtr(dict)); -} - - -Foam::autoPtr Foam::coordinateSystem::New -( - const objectRegistry& obr, - const dictionary& dict, - const word& dictName -) -{ - const dictionary* dictPtr = &dict; - - if (dictName.size()) - { - dictPtr = &(dictPtr->subDict(dictName)); - } - else - { - // Fallback: 'coordinateSystem' subDict if present - dictPtr = subDictCompat(coordinateSystem::typeName_(), dictPtr); - } - - word modelType = dictPtr->getOrDefault - ( - "type", - coordSystem::cartesian::typeName_() - ); - - return coordinateSystem::New(modelType, obr, *dictPtr); -} - - -Foam::autoPtr Foam::coordinateSystem::New -( - const dictionary& dict, - const word& dictName -) -{ - const dictionary* dictPtr = &dict; - - if (dictName.size()) - { - dictPtr = &(dictPtr->subDict(dictName)); - } - else - { - // Fallback: 'coordinateSystem' subDict if present - dictPtr = subDictCompat(coordinateSystem::typeName_(), dictPtr); - } - - const word modelType = dictPtr->getOrDefault - ( - "type", - coordSystem::cartesian::typeName_() - ); - - return coordinateSystem::New(modelType, *dictPtr); -} - - -Foam::autoPtr Foam::coordinateSystem::New(Istream& is) { const word csName(is); const dictionary dict(is); - auto cs = coordinateSystem::New(dict, word::null); + // The coordinate-system type (if not cartesian) + word modelType; + dict.readIfPresent("type", modelType, keyType::LITERAL); + + auto cs = coordinateSystem::New(modelType, dict, readOrigin); cs->rename(csName); return cs; } +Foam::autoPtr +Foam::coordinateSystem::New +( + const word& modelType, + const objectRegistry& obr, + const dictionary& dict, + IOobjectOption::readOption readOrigin +) +{ + return New(modelType, dict, readOrigin, &obr); +} + + +Foam::autoPtr +Foam::coordinateSystem::New +( + const word& modelType, + const dictionary& dict, + IOobjectOption::readOption readOrigin +) +{ + return New(modelType, dict, readOrigin, nullptr); +} + + +Foam::autoPtr +Foam::coordinateSystem::New +( + const objectRegistry& obr, + const dictionary& dict, + const word& dictName, + IOobjectOption::readOption readOrigin +) +{ + return New(dict, dictName, readOrigin, &obr); +} + + +Foam::autoPtr +Foam::coordinateSystem::New +( + const dictionary& dict, + const word& dictName, + IOobjectOption::readOption readOrigin +) +{ + return New(dict, dictName, readOrigin, nullptr); +} + + +Foam::autoPtr +Foam::coordinateSystem::NewIfPresent +( + const objectRegistry& obr, + const dictionary& dict, + const word& dictName +) +{ + return NewIfPresent(dict, dictName, &obr); +} + + +Foam::autoPtr +Foam::coordinateSystem::NewIfPresent +( + const dictionary& dict, + const word& dictName +) +{ + return NewIfPresent(dict, dictName, nullptr); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/coordinate/systems/cylindricalCS.C b/src/OpenFOAM/primitives/coordinate/systems/cylindricalCS.C index 11d9584282..6a1dc5b890 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/cylindricalCS.C +++ b/src/OpenFOAM/primitives/coordinate/systems/cylindricalCS.C @@ -50,12 +50,12 @@ const Foam::coordSystem::cylindrical Foam::coordSystem::cylindrical::null; namespace Foam { -// Issue warning if 'degrees' keyword was specified and true. +// Issue warning if 'degrees' keyword was specified // Compatibility change after 1806. static inline void warnCompatDegrees(const Foam::dictionary& dict) { - if (error::master()) + if (dict.found("degrees", keyType::LITERAL) && error::master()) { std::cerr << "--> FOAM IOWarning :" << nl @@ -84,12 +84,6 @@ static inline vector toCartesian(const vector& v) // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::coordSystem::cylindrical::cylindrical() -: - coordinateSystem() -{} - - Foam::coordSystem::cylindrical::cylindrical(const coordinateSystem& csys) : coordinateSystem(csys) @@ -175,46 +169,30 @@ Foam::coordSystem::cylindrical::cylindrical Foam::coordSystem::cylindrical::cylindrical ( - const word& name, - const dictionary& dict + const dictionary& dict, + IOobjectOption::readOption readOrigin ) : - coordinateSystem(name, dict) + coordinateSystem(dict, readOrigin) { - if (dict.getOrDefault("degrees", false)) - { - warnCompatDegrees(dict); - } -} - - -Foam::coordSystem::cylindrical::cylindrical(const dictionary& dict) -: - coordinateSystem(dict) -{ - if (dict.getOrDefault("degrees", false)) - { - warnCompatDegrees(dict); - } + warnCompatDegrees(dict); } Foam::coordSystem::cylindrical::cylindrical ( const dictionary& dict, - const word& dictName + const word& dictName, + IOobjectOption::readOption readOrigin ) : - coordinateSystem(dict, dictName) + coordinateSystem(dict, dictName, readOrigin) { - const dictionary* dictPtr = - ( - dictName.size() - ? &(dict.subDict(dictName)) - : &(dict) - ); - - if (dictPtr->getOrDefault("degrees", false)) + if (dictName.size()) + { + warnCompatDegrees(dict.subDict(dictName)); + } + else { warnCompatDegrees(dict); } @@ -331,5 +309,4 @@ Foam::tmp Foam::coordSystem::cylindrical::globalToLocal } - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/coordinate/systems/cylindricalCS.H b/src/OpenFOAM/primitives/coordinate/systems/cylindricalCS.H index 498aff68a3..47d39e5fa5 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/cylindricalCS.H +++ b/src/OpenFOAM/primitives/coordinate/systems/cylindricalCS.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -114,8 +114,8 @@ public: // Constructors - //- Default construct. This is an identity coordinate system - cylindrical(); + //- Default construct. Identity coordinate system. + cylindrical() = default; //- Copy construct cylindrical(const cylindrical& csys) = default; @@ -141,7 +141,7 @@ public: //- Construct from origin and single axis cylindrical(const point& origin, const vector& axis); - //- Construct from origin and single axis + //- Construct named from origin and single axis cylindrical(const word& name, const point& origin, const vector& axis); //- Construct from origin and two axes @@ -152,7 +152,7 @@ public: const vector& dirn ); - //- Construct from origin and two axes + //- Construct named from origin and two axes cylindrical ( const word& name, @@ -161,16 +161,32 @@ public: const vector& dirn ); - //- Construct from dictionary with a given name - cylindrical(const word& name, const dictionary& dict); - - //- Construct from dictionary without a name - explicit cylindrical(const dictionary& dict); - - //- Construct from dictionary with optional subDict lookup. + //- Construct from dictionary with optional + //- read handling for the 'origin' entry (default: MUST_READ). // - // \param dictName If non-empty, the sub-dictionary to use. - cylindrical(const dictionary& dict, const word& dictName); + // \note The readOrigin is downgraded to READ_IF_PRESENT + // if the dictionary itself is "coordinateSystem" + explicit cylindrical + ( + const dictionary& dict, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ + ); + + //- Construct from dictionary with optional subDict lookup and optional + //- read handling for the 'origin' entry (default: MUST_READ). + // + // \param dictName If non-empty, mandatory sub-dictionary to use. + // + // \note The readOrigin is downgraded to READ_IF_PRESENT + // if the dictionary itself is "coordinateSystem" + // or if a sub-dictionary is being used + cylindrical + ( + const dictionary& dict, + const word& dictName, + IOobjectOption::readOption readOrigin = IOobjectOption::MUST_READ + ); + //- Return clone virtual autoPtr clone() const diff --git a/src/OpenFOAM/primitives/coordinate/systems/indirectCS.C b/src/OpenFOAM/primitives/coordinate/systems/indirectCS.C index 7dd3bbd54d..31d5619637 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/indirectCS.C +++ b/src/OpenFOAM/primitives/coordinate/systems/indirectCS.C @@ -72,7 +72,8 @@ Foam::coordSystem::indirect::indirect Foam::coordSystem::indirect::indirect ( const objectRegistry& obr, - const dictionary& dict + const dictionary& dict, + IOobjectOption::readOption /* (unused) */ ) : indirect(obr, dict.get("name")) @@ -83,13 +84,13 @@ Foam::coordSystem::indirect::indirect void Foam::coordSystem::indirect::write(Ostream& os) const { - writeEntry(coordinateSystem::typeName_(), os); + writeEntry(coordinateSystem::typeName, os); } void Foam::coordSystem::indirect::writeEntry(Ostream& os) const { - writeEntry(coordinateSystem::typeName_(), os); + writeEntry(coordinateSystem::typeName, os); } diff --git a/src/OpenFOAM/primitives/coordinate/systems/indirectCS.H b/src/OpenFOAM/primitives/coordinate/systems/indirectCS.H index 47f0d22fc6..afc6b06888 100644 --- a/src/OpenFOAM/primitives/coordinate/systems/indirectCS.H +++ b/src/OpenFOAM/primitives/coordinate/systems/indirectCS.H @@ -42,8 +42,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef indirectCS_H -#define indirectCS_H +#ifndef Foam_indirectCS_H +#define Foam_indirectCS_H #include "coordinateSystem.H" @@ -137,8 +137,14 @@ public: //- Construct from global lookup indirect(const objectRegistry& obr, const word& name); - //- Construct from global lookup - indirect(const objectRegistry& obr, const dictionary& dict); + //- Construct from global lookup. + // The readOrigin is unused. + indirect + ( + const objectRegistry& obr, + const dictionary& dict, + IOobjectOption::readOption readOrigin = IOobjectOption::NO_READ + ); //- Return clone virtual autoPtr clone() const diff --git a/src/engine/enginePiston/enginePiston.C b/src/engine/enginePiston/enginePiston.C index eed81e24ce..014522c343 100644 --- a/src/engine/enginePiston/enginePiston.C +++ b/src/engine/enginePiston/enginePiston.C @@ -61,7 +61,7 @@ Foam::enginePiston::enginePiston patchID_(dict.lookup("patch"), mesh.boundaryMesh()), csysPtr_ ( - coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_()) + coordinateSystem::New(mesh_, dict, coordinateSystem::typeName) ), minLayer_(dict.get("minLayer")), maxLayer_(dict.get("maxLayer")) diff --git a/src/engine/engineValve/engineValve.C b/src/engine/engineValve/engineValve.C index 5696f88dc1..40ce8b9462 100644 --- a/src/engine/engineValve/engineValve.C +++ b/src/engine/engineValve/engineValve.C @@ -124,7 +124,7 @@ Foam::engineValve::engineValve engineDB_(refCast(mesh_.time())), csysPtr_ ( - coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_()) + coordinateSystem::New(mesh_, dict, coordinateSystem::typeName) ), bottomPatch_ ( diff --git a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C index 157fcae27b..beac5ec969 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C @@ -96,7 +96,7 @@ Foam::porosityModel::porosityModel cellZoneIDs_(), csysPtr_ ( - coordinateSystem::New(mesh, coeffs_, coordinateSystem::typeName_()) + coordinateSystem::New(mesh, coeffs_, coordinateSystem::typeName) ) { if (zoneName_.empty()) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/IntegralScaleBox/IntegralScaleBox.C b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/IntegralScaleBox/IntegralScaleBox.C index efe4967134..47cebe3c6a 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/IntegralScaleBox/IntegralScaleBox.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/IntegralScaleBox/IntegralScaleBox.C @@ -56,17 +56,7 @@ Foam::turbulence::IntegralScaleBox::calcCoordinateSystem const dictionary& dict ) const { - if (dict.found(coordinateSystem::typeName_())) - { - return coordinateSystem::New - ( - p_.patch().boundaryMesh().mesh(), - dict, - coordinateSystem::typeName_() - ); - } - - return nullptr; + return coordinateSystem::NewIfPresent(dict); } diff --git a/src/functionObjects/field/binField/binField.H b/src/functionObjects/field/binField/binField.H index 1fd57a1aed..bb9bf98f7e 100644 --- a/src/functionObjects/field/binField/binField.H +++ b/src/functionObjects/field/binField/binField.H @@ -68,22 +68,21 @@ Usage // Conditional optional entries - // Option-1, i.e. general coordinate system specification + // General coordinate system specification coordinateSystem { - type cartesian; - origin (0 0 0); + type cartesian; + origin (0 0 0); rotation { - type axes; - e3 (0 0 1); - e1 (1 0 0); // (e1, e2) or (e2, e3) or (e3, e1) + type ... + ... } } - // Option-2, i.e. the centre of rotation - // by inherently using e3=(0 0 1) and e1=(1 0 0) - CofR (0 0 0); + // Define the centre of rotation + // with implicit directions e1=(1 0 0) and e3=(0 0 1) + CofR (0 0 0); // Inherited entries ... @@ -102,7 +101,7 @@ Usage decomposePatchValues | Flag to output normal and tangential components | bool | no | false cellZones | Names of operand cell zones | wordRes | no | - - coordinateSystem | Coordinate system specifier | dict | cndtnl | - + coordinateSystem | Coordinate system specifier | dict | cndtnl | - CofR | Centre of rotation | vector | cndtnl | - \endtable @@ -117,6 +116,9 @@ Usage - \link writeFile.H \endlink - \link coordinateSystem.H \endlink +Note + - If a \c coordinateSystem entry exists, it is taken in favour of \c CofR. + SourceFiles binField.C diff --git a/src/functionObjects/field/binField/binModels/binModel/binModel.C b/src/functionObjects/field/binField/binModels/binModel/binModel.C index 13ff87985d..fc31d3e860 100644 --- a/src/functionObjects/field/binField/binModels/binModel/binModel.C +++ b/src/functionObjects/field/binField/binModels/binModel/binModel.C @@ -77,40 +77,27 @@ void Foam::binModel::setCoordinateSystem const word& e1Name ) { - coordSysPtr_.clear(); + point origin(Zero); - if (dict.found(coordinateSystem::typeName_())) + coordSysPtr_ = coordinateSystem::NewIfPresent(dict); + + if (coordSysPtr_) { - coordSysPtr_ = - coordinateSystem::New - ( - mesh_, - dict, - coordinateSystem::typeName_() - ); - Info<< "Setting co-ordinate system:" << nl << " - type : " << coordSysPtr_->name() << nl << " - origin : " << coordSysPtr_->origin() << nl << " - e3 : " << coordSysPtr_->e3() << nl << " - e1 : " << coordSysPtr_->e1() << endl; } - else if (dict.found("CofR")) + else if (dict.readIfPresent("CofR", origin)) { - const vector origin(dict.get("CofR")); - const vector e3 ( - e3Name == word::null - ? vector(0, 0, 1) - : dict.get(e3Name) + e3Name.empty() ? vector(0, 0, 1) : dict.get(e3Name) ); - const vector e1 ( - e1Name == word::null - ? vector(1, 0, 0) - : dict.get(e1Name) + e1Name.empty() ? vector(1, 0, 0) : dict.get(e1Name) ); coordSysPtr_.reset(new coordSystem::cartesian(origin, e3, e1)); diff --git a/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C b/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C index 2ac1d40f51..1520e204b8 100644 --- a/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C +++ b/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C @@ -60,7 +60,7 @@ fieldCoordinateSystemTransform fieldSet_(mesh_), csysPtr_ ( - coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_()) + coordinateSystem::New(mesh_, dict, coordinateSystem::typeName) ) { read(dict); diff --git a/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C b/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C index 96626fda2d..3292d9e2af 100644 --- a/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C +++ b/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C @@ -396,20 +396,13 @@ bool Foam::functionObjects::regionSizeDistribution::read(const dictionary& dict) dict.subOrEmptyDict("formatOptions").optionalSubDict(setFormat) ); - if (dict.found(coordinateSystem::typeName_())) - { - csysPtr_.reset - ( - coordinateSystem::New(obr_, dict, coordinateSystem::typeName_()) - ); + csysPtr_ = coordinateSystem::NewIfPresent(obr_, dict); + if (csysPtr_) + { Info<< "Transforming all vectorFields with coordinate system " << csysPtr_->name() << endl; } - else - { - csysPtr_.clear(); - } if (isoPlanes_) { diff --git a/src/functionObjects/forces/forceCoeffs/forceCoeffs.H b/src/functionObjects/forces/forceCoeffs/forceCoeffs.H index 0e69987608..904ed6e237 100644 --- a/src/functionObjects/forces/forceCoeffs/forceCoeffs.H +++ b/src/functionObjects/forces/forceCoeffs/forceCoeffs.H @@ -107,27 +107,23 @@ Usage // Cartesian coordinate system specification when evaluating // force and moment coefficients, either of the below - // Option-1, i.e. the centre of rotation - // by inherently using e3=(0 0 1) and e1=(1 0 0) - CofR (0 0 0); // Centre of rotation - dragDir (1 0 0); - liftDir (0 0 1); + // Define the centre of rotation + // with implicit directions e1=(1 0 0) and e3=(0 0 1) + CofR (0 0 0); // Centre of rotation - // Option-2, i.e. local coordinate system specification - origin (0 0 0); - e1 (1 0 0); - e3 (0 0 1); // (e1, e2) or (e2, e3) or (e3, e1) + // Define local coordinate system by origin + axes + origin (0 0 0); + e1 (1 0 0); + e3 (0 0 1); // (e1, e2) or (e2, e3) or (e3, e1) - // Option-3, i.e. general coordinate system specification + // General coordinate system specification (always cartesian) coordinateSystem { - type cartesian; - origin (0 0 0); + origin (0 0 0); rotation { - type axes; - e3 (0 0 1); - e1 (1 0 0); // (e1, e2) or (e2, e3) or (e3, e1) + type ...; + ... } } @@ -221,6 +217,8 @@ Note yawAxis | Yaw axis | e3 | (0 0 1) \endtable + - If a \c coordinateSystem entry exists, it is taken in favour of \c CofR. + SourceFiles forceCoeffs.C diff --git a/src/functionObjects/forces/forces/forces.C b/src/functionObjects/forces/forces/forces.C index 4689e00656..2fe3e42352 100644 --- a/src/functionObjects/forces/forces/forces.C +++ b/src/functionObjects/forces/forces/forces.C @@ -55,38 +55,34 @@ void Foam::functionObjects::forces::setCoordinateSystem const word& e1Name ) { - coordSysPtr_.clear(); - point origin(Zero); - if (dict.readIfPresent("CofR", origin)) + + // With objectRegistry for access to indirect (global) coordinate systems + coordSysPtr_ = coordinateSystem::NewIfPresent(obr_, dict); + + if (coordSysPtr_) { - const vector e3 = e3Name == word::null ? - vector(0, 0, 1) : dict.get(e3Name); - const vector e1 = e1Name == word::null ? - vector(1, 0, 0) : dict.get(e1Name); + // Report ... + } + else if (dict.readIfPresent("CofR", origin)) + { + const vector e3 + ( + e3Name.empty() ? vector(0, 0, 1) : dict.get(e3Name) + ); + const vector e1 + ( + e1Name.empty() ? vector(1, 0, 0) : dict.get(e1Name) + ); coordSysPtr_.reset(new coordSystem::cartesian(origin, e3, e1)); } else { - // The 'coordinateSystem' sub-dictionary is optional, - // but enforce use of a cartesian system if not found. + // No 'coordinateSystem' or 'CofR' + // - enforce a cartesian system - if (dict.found(coordinateSystem::typeName_())) - { - // New() for access to indirect (global) coordinate system - coordSysPtr_ = - coordinateSystem::New - ( - obr_, - dict, - coordinateSystem::typeName_() - ); - } - else - { - coordSysPtr_.reset(new coordSystem::cartesian(dict)); - } + coordSysPtr_.reset(new coordSystem::cartesian(dict)); } } diff --git a/src/functionObjects/forces/forces/forces.H b/src/functionObjects/forces/forces/forces.H index 808ba321a8..257b01f5cd 100644 --- a/src/functionObjects/forces/forces/forces.H +++ b/src/functionObjects/forces/forces/forces.H @@ -90,19 +90,18 @@ Usage // Cartesian coordinate system specification when // evaluating forces and moments, either of the below - // Option-1, i.e. the centre of rotation - // by inherently using e3=(0 0 1) and e1=(1 0 0) + // Define the centre of rotation + // with implicit directions e1=(1 0 0) and e3=(0 0 1) CofR (0 0 0); // Centre of rotation - // Option-2, i.e. local coordinate system specification + // Define local coordinate system by origin + axes origin (0 0 0); e1 (1 0 0); e3 (0 0 1); // (e1, e2) or (e2, e3) or (e3, e1) - // Option-3, i.e. general coordinate system specification + // General coordinate system specification (always cartesian) coordinateSystem { - type cartesian; origin (0 0 0); rotation { @@ -137,11 +136,11 @@ Usage porosity | Flag to include porosity contributions | bool | no | false writeFields | Flag to write force and moment fields | bool | no | false useNamePrefix | Flag to include prefix for field names | bool | no | false + coordinateSystem | Coordinate system specifier | dictionary | cndtnl | - CofR | Centre of rotation | vector | cndtnl | - origin | Origin of coordinate system | vector | cndtnl | - e3 | e3 coordinate axis | vector | cndtnl | - e1 | e1 coordinate axis | vector | cndtnl | - - coordinateSystem | Coordinate system specifier | dictionary | cndtnl | - fD | Name of force density field | word | cndtnl | - p | Name of pressure field | word | cndtnl | p U | Name of velocity field | word | cndtnl | U @@ -161,6 +160,7 @@ Note value corresponding to the constant freestream density. - \c writeControl and \c writeInterval entries of function object do control when to output force and moment files and fields. + - If a \c coordinateSystem entry exists, it is taken in favour of \c CofR. SourceFiles forces.C diff --git a/src/fvOptions/sources/derived/jouleHeatingSource/jouleHeatingSource.C b/src/fvOptions/sources/derived/jouleHeatingSource/jouleHeatingSource.C index be59edca20..a57a0d8aa1 100644 --- a/src/fvOptions/sources/derived/jouleHeatingSource/jouleHeatingSource.C +++ b/src/fvOptions/sources/derived/jouleHeatingSource/jouleHeatingSource.C @@ -221,7 +221,7 @@ bool Foam::fv::jouleHeatingSource::read(const dictionary& dict) ( mesh_, coeffs_, - coordinateSystem::typeName_() + coordinateSystem::typeName ); } else diff --git a/src/mesh/blockMesh/blockMesh/blockMesh.C b/src/mesh/blockMesh/blockMesh/blockMesh.C index 1393271291..0e30e3cf21 100644 --- a/src/mesh/blockMesh/blockMesh/blockMesh.C +++ b/src/mesh/blockMesh/blockMesh/blockMesh.C @@ -147,12 +147,14 @@ bool Foam::blockMesh::readPointTransforms(const dictionary& dict) { transformType_ = transformTypes::NO_TRANSFORM; - const dictionary* dictptr; + const dictionary* dictptr = dict.findDict("transform", keyType::LITERAL); - // Optional cartesian coordinate system transform, since JUL-2021 - if ((dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr) + if (dictptr) { - transform_ = coordSystem::cartesian(*dictptr); + // Optional cartesian coordinate system transform, since JUL-2021 + // - 'origin' (READ_IF_PRESENT) + transform_ = + coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT); // Non-zero origin? if (magSqr(transform_.origin()) > ROOTVSMALL) diff --git a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.C b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.C index 9046280efb..2e6c728f58 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.C +++ b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.C @@ -113,12 +113,7 @@ template Foam::tmp Foam::PatchFunction1::localPosition(const pointField& globalPos) const { - if (!coordSys_.active()) - { - return globalPos; - } - - return coordSys_.coordSys()().localPosition(globalPos); + return coordSys_.localPosition(globalPos); } diff --git a/src/meshTools/PatchFunction1/coordinateScaling/coordinateScaling.C b/src/meshTools/PatchFunction1/coordinateScaling/coordinateScaling.C index 3bc88ac84b..6badd8d9e4 100644 --- a/src/meshTools/PatchFunction1/coordinateScaling/coordinateScaling.C +++ b/src/meshTools/PatchFunction1/coordinateScaling/coordinateScaling.C @@ -43,22 +43,19 @@ Foam::coordinateScaling::coordinateScaling const dictionary& dict ) : - coordSys_ - ( - dict.found(coordinateSystem::typeName_()) - ? coordinateSystem::New(obr, dict) - : nullptr - ), - scale_(3), + coordSys_(coordinateSystem::NewIfPresent(obr, dict)), + scale_(label(vector::nComponents)), active_(bool(coordSys_)) { for (direction dir = 0; dir < vector::nComponents; ++dir) { const word key("scale" + Foam::name(dir+1)); - if (dict.found(key)) + auto scaling = Function1::NewIfPresent(key, dict); + + if (scaling) { - scale_.set(dir, Function1::New(key, dict)); + scale_.set(dir, std::move(scaling)); active_ = true; } } @@ -76,6 +73,21 @@ Foam::coordinateScaling::coordinateScaling(const coordinateScaling& rhs) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +Foam::tmp Foam::coordinateScaling::localPosition +( + const pointField& globalPos +) const +{ + if (coordSys_) + { + return coordSys_->localPosition(globalPos); + } + + return globalPos; +} + + template Foam::tmp> Foam::coordinateScaling::transform ( diff --git a/src/meshTools/PatchFunction1/coordinateScaling/coordinateScaling.H b/src/meshTools/PatchFunction1/coordinateScaling/coordinateScaling.H index 3804207e49..4e7d94aa74 100644 --- a/src/meshTools/PatchFunction1/coordinateScaling/coordinateScaling.H +++ b/src/meshTools/PatchFunction1/coordinateScaling/coordinateScaling.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,8 +37,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef coordinateScaling_H -#define coordinateScaling_H +#ifndef Foam_coordinateScaling_H +#define Foam_coordinateScaling_H #include "coordinateSystem.H" #include "Function1.H" @@ -58,7 +58,7 @@ class coordinateScaling // Private Data //- Local coordinate system - const autoPtr coordSys_; + autoPtr coordSys_; //- In local coordinate system component-wise scaling PtrList> scale_; @@ -97,7 +97,7 @@ public: // Member Functions //- Has any scaling or coordinate transformation - bool active() const + bool active() const noexcept { return active_; } @@ -108,6 +108,10 @@ public: return coordSys_; } + //- Convert to local coordinates, + //- pass-through if no coordinate system is active + tmp localPosition(const pointField& globalPos) const; + //- Evaluate virtual tmp> transform ( diff --git a/src/meshTools/searchableSurfaces/searchableSurfaceCollection/searchableSurfaceCollection.C b/src/meshTools/searchableSurfaces/searchableSurfaceCollection/searchableSurfaceCollection.C index f9f39b4c82..27653a2900 100644 --- a/src/meshTools/searchableSurfaces/searchableSurfaceCollection/searchableSurfaceCollection.C +++ b/src/meshTools/searchableSurfaces/searchableSurfaceCollection/searchableSurfaceCollection.C @@ -206,35 +206,12 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection sDict.readEntry("scale", scale_[surfI]); - const dictionary& coordDict = sDict.subDict("transform"); - - const dictionary* compatDict = - coordDict.findDict - ( - coordinateSystem::typeName_(), - keyType::LITERAL - ); - - if (compatDict) - { - // Deprecated form - if (error::master()) - { - std::cerr - << "--> FOAM IOWarning :" << nl - << " Found [v1806] '" - << coordinateSystem::typeName_() - << "' entry within transform dictionary" << nl - << std::endl; - error::warnAboutAge("sub-dictionary", 1806); - } - - transform_.set(surfI, new coordSystem::cartesian(*compatDict)); - } - else - { - transform_.set(surfI, new coordSystem::cartesian(coordDict)); - } + // Mandatory 'transform' sub-dictionary + transform_.set + ( + surfI, + new coordSystem::cartesian(sDict, "transform") + ); const word subGeomName(sDict.get("surface")); //Pout<< "Trying to find " << subGeomName << endl; diff --git a/src/parallel/decompose/decompositionMethods/geomDecomp/geomDecomp.C b/src/parallel/decompose/decompositionMethods/geomDecomp/geomDecomp.C index 8839802b54..15c4a65bfa 100644 --- a/src/parallel/decompose/decompositionMethods/geomDecomp/geomDecomp.C +++ b/src/parallel/decompose/decompositionMethods/geomDecomp/geomDecomp.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -84,12 +84,14 @@ void Foam::geomDecomp::readCoeffs() } setOrder(); - const dictionary* transformDict = + // Optional cartesian coordinate system transform + const dictionary* dictptr = coeffsDict_.findDict("transform", keyType::LITERAL); - if (transformDict) + if (dictptr) { - csys_ = coordinateSystem(*transformDict); + // 'origin' (READ_IF_PRESENT) + csys_ = coordinateSystem(*dictptr, IOobjectOption::READ_IF_PRESENT); } else if (equal(delta_, 0)) { diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C index 3f2c7e8ad6..143e0a7b0e 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C @@ -64,27 +64,24 @@ Foam::plane Foam::sampledCuttingPlane::definePlane const dictionary* dictptr = nullptr; coordSystem::cartesian cs; - if (dict.found(coordinateSystem::typeName_(), keyType::LITERAL)) + // Create with registry to allow lookup from globally defined + // coordinate systems. + + auto csPtr = coordinateSystem::NewIfPresent(mesh, *dictptr); + + if (csPtr) { - // Create with registry to allow lookup from globally defined - // coordinate systems? - - auto csPtr = - coordinateSystem::New(mesh, dict, coordinateSystem::typeName_()); - - if (csPtr) - { - adjust = true; - cs = csPtr(); - } + adjust = true; + cs = csPtr(); } else if ( (dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr ) { + // 'origin' (READ_IF_PRESENT) adjust = true; - cs = coordSystem::cartesian(*dictptr); + cs = coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT); } diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C index 1233385b2a..4604e22965 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C @@ -62,27 +62,24 @@ Foam::plane Foam::sampledPlane::definePlane const dictionary* dictptr = nullptr; coordSystem::cartesian cs; - if (dict.found(coordinateSystem::typeName_(), keyType::LITERAL)) + // Create with registry to allow lookup from globally defined + // coordinate systems. + + auto csPtr = coordinateSystem::NewIfPresent(mesh, dict); + + if (csPtr) { - // Create with registry to allow lookup from globally defined - // coordinate systems? - - auto csPtr = - coordinateSystem::New(mesh, dict, coordinateSystem::typeName_()); - - if (csPtr) - { - adjust = true; - cs = csPtr(); - } + adjust = true; + cs = csPtr(); } else if ( (dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr ) { + // 'origin' (READ_IF_PRESENT) adjust = true; - cs = coordSystem::cartesian(*dictptr); + cs = coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT); } diff --git a/src/surfMesh/writers/common/surfaceWriter.C b/src/surfMesh/writers/common/surfaceWriter.C index bcc4c53536..71d7df16e2 100644 --- a/src/surfMesh/writers/common/surfaceWriter.C +++ b/src/surfMesh/writers/common/surfaceWriter.C @@ -174,13 +174,16 @@ Foam::surfaceWriter::surfaceWriter(const dictionary& options) options.readIfPresent("scale", geometryScale_); - const dictionary* dictptr; - // Optional cartesian coordinate system transform - if ((dictptr = options.findDict("transform", keyType::LITERAL)) != nullptr) + const auto* dictptr = options.findDict("transform", keyType::LITERAL); + + if (dictptr) { dictptr->readIfPresent("rotationCentre", geometryCentre_); - geometryTransform_ = coordSystem::cartesian(*dictptr); + + // 'origin' (READ_IF_PRESENT) + geometryTransform_ = + coordSystem::cartesian(*dictptr, IOobjectOption::READ_IF_PRESENT); } fieldLevel_ = options.subOrEmptyDict("fieldLevel"); diff --git a/src/topoChangerFvMesh/mixerFvMesh/mixerFvMesh.C b/src/topoChangerFvMesh/mixerFvMesh/mixerFvMesh.C index c6ab393752..81a47f7d93 100644 --- a/src/topoChangerFvMesh/mixerFvMesh/mixerFvMesh.C +++ b/src/topoChangerFvMesh/mixerFvMesh/mixerFvMesh.C @@ -273,11 +273,13 @@ Foam::mixerFvMesh::mixerFvMesh rpm_(motionDict_.get("rpm")), movingPointsMaskPtr_(nullptr) { - if (motionDict_.found(coordinateSystem::typeName_())) + // New() for access to indirect (global) coordSystem. + + auto csysPtr = coordinateSystem::NewIfPresent(*this, dict); + + if (csysPtr) { - // New() for access to indirect (global) coordSystem. - static_cast(csys_) = - *coordinateSystem::New(*this, motionDict_); + static_cast(csys_) = csysPtr(); } else { diff --git a/tutorials/compressible/rhoSimpleFoam/squareBend/system/samplingDebug b/tutorials/compressible/rhoSimpleFoam/squareBend/system/samplingDebug index a8138d0be5..40c1bd3db9 100644 --- a/tutorials/compressible/rhoSimpleFoam/squareBend/system/samplingDebug +++ b/tutorials/compressible/rhoSimpleFoam/squareBend/system/samplingDebug @@ -118,7 +118,7 @@ debug { transform { - origin (0 0 0); + // origin (0 0 0); rotationCentre (0.025 0 0); rotation axisAngle; axis (0 1 0);