diff --git a/applications/test/sort/Test-sortList.cxx b/applications/test/sort/Test-sortList.cxx index 907f6436c9..1269c2cb8b 100644 --- a/applications/test/sort/Test-sortList.cxx +++ b/applications/test/sort/Test-sortList.cxx @@ -296,7 +296,7 @@ int main(int argc, char *argv[]) ( strings, order, - stringOps::natural_sort::less(strings) + stringOps::natural_sort::list_less(strings) ); Info<< "natural sortedOrder: " << flatOutput(order) << endl; } @@ -321,7 +321,7 @@ int main(int argc, char *argv[]) /// sortable = hashed.toc(); /// sortable.sort /// ( - /// stringOps::natural_sort::less(sortable) + /// stringOps::natural_sort::list_less(sortable) /// ); /// Info<< nl << "natural:" << sortable << endl; @@ -329,7 +329,7 @@ int main(int argc, char *argv[]) /// sortable = hashed.toc(); /// sortable.sort /// ( - /// stringOps::natural_sort::greater(sortable) + /// stringOps::natural_sort::list_greater(sortable) /// ); /// Info<< nl << "natural:" << sortable << endl; } diff --git a/src/OpenFOAM/db/IOstreams/memory/memoryStreamBuffer.H b/src/OpenFOAM/db/IOstreams/memory/memoryStreamBuffer.H index 446053a890..5c49b1d5b5 100644 --- a/src/OpenFOAM/db/IOstreams/memory/memoryStreamBuffer.H +++ b/src/OpenFOAM/db/IOstreams/memory/memoryStreamBuffer.H @@ -38,6 +38,7 @@ Description #include "DynamicList.H" #include +#include #include #include diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 67f771e3d2..38ded49d1d 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -113,6 +113,7 @@ SeeAlso #include "label.H" #include "scalar.H" #include "regExpFwd.H" +#include "Switch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/error/messageStream.H b/src/OpenFOAM/db/error/messageStream.H index e07345bb05..0f55064928 100644 --- a/src/OpenFOAM/db/error/messageStream.H +++ b/src/OpenFOAM/db/error/messageStream.H @@ -55,6 +55,8 @@ SourceFiles #include "label.H" #include "word.H" + +#include #include #include diff --git a/src/OpenFOAM/global/debug/simpleObjectRegistry.H b/src/OpenFOAM/global/debug/simpleObjectRegistry.H index 5823c5a516..a7fc5a4139 100644 --- a/src/OpenFOAM/global/debug/simpleObjectRegistry.H +++ b/src/OpenFOAM/global/debug/simpleObjectRegistry.H @@ -40,6 +40,7 @@ SourceFiles #include "Dictionary.H" #include "simpleRegIOobject.H" +#include #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C index dd39a58954..b9eecd144f 100644 --- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C +++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C @@ -333,7 +333,7 @@ Foam::fileMonitor& Foam::fileOperation::monitor() const void Foam::fileOperation::mergeTimes ( - const instantList& extraTimes, + const UList& extraTimes, const word& constantName, instantList& times ) diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H index bd19e08c25..27e931ef02 100644 --- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H +++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H @@ -198,8 +198,10 @@ protected: //- Merge two times static void mergeTimes ( - const instantList& extraTimes, + const UList& extraTimes, + //! The "constant" name const word& constantName, + //! [in,out] Updated with any extra times instantList& times ); @@ -870,7 +872,13 @@ public: ) const; //- Get sorted list of times - virtual instantList findTimes(const fileName&, const word&) const; + virtual instantList findTimes + ( + //! The directory to search + const fileName& directory, + //! The "constant" name + const word& constantName = "constant" + ) const; //- Find time instance where IOobject is located. //- The name of the IOobject can be empty, in which case only the diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H index 37f49fc1ed..c68ea352dc 100644 --- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H +++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H @@ -748,7 +748,13 @@ public: // Other //- Get sorted list of times - virtual instantList findTimes(const fileName&, const word&) const; + virtual instantList findTimes + ( + //! The directory to search + const fileName& directory, + //! The "constant" name + const word& constantName = "constant" + ) const; //- Find time instance where IOobject is located. //- The name of the IOobject can be empty, in which case only the diff --git a/src/OpenFOAM/include/addAllRegionOptions.H b/src/OpenFOAM/include/addAllRegionOptions.H index 67e10b234e..fb9eced092 100644 --- a/src/OpenFOAM/include/addAllRegionOptions.H +++ b/src/OpenFOAM/include/addAllRegionOptions.H @@ -11,7 +11,10 @@ License This file is part of OpenFOAM, distributed under GPL-3.0-or-later. Description - Add multi-region command-line options: -allRegions, -regions, -region + Add multi-region command-line options: + -allRegions | -all-regions + -regions + -region Required Classes - Foam::argList @@ -24,10 +27,10 @@ See Also { Foam::argList::addBoolOption ( - "all-regions", + "allRegions", "Use all regions in regionProperties" ); - Foam::argList::addOptionCompat("all-regions", { "allRegions", -2506 }); + Foam::argList::addOptionCompat("allRegions", { "all-regions", 0 }); Foam::argList::addOption ( diff --git a/src/OpenFOAM/include/getAllRegionOptions.H b/src/OpenFOAM/include/getAllRegionOptions.H index 887646b9d6..dcea9facdc 100644 --- a/src/OpenFOAM/include/getAllRegionOptions.H +++ b/src/OpenFOAM/include/getAllRegionOptions.H @@ -45,12 +45,19 @@ See Also wordList regionNames; { - // Local alias - auto& names = regionNames; // Exit or fallback if nothing matches constexpr bool exitOnNoMatches = true; - if (args.found("all-regions")) + // Local aliases + auto& names = regionNames; + const auto& fallback = Foam::polyMesh::defaultRegion; + + if + ( + // Handle both here (independent of which is an alias) + args.found("all-regions") + || args.found("allRegions") + ) { names = ( @@ -81,11 +88,11 @@ wordList regionNames; { select.uniq(); // Normally a no-op - if (select.size() == 1 && select.front().isLiteral()) + if (select.size() == 1 && select[0].isLiteral()) { // Identical to -region NAME names.resize(1); - names.front() = select.front(); + names[0] = select[0]; } else if (select.size()) { @@ -116,12 +123,12 @@ wordList regionNames; } else { - InfoErr<< "... ignoring and using default region" + InfoErr + << "... ignoring and using default region" << nl << endl; - // Arbitrary fallback, but can handle this further on names.resize(1); - names.front() = Foam::polyMesh::defaultRegion; + names[0] = fallback; } } else @@ -160,7 +167,7 @@ wordList regionNames; else { names.resize(1); - names.front() = Foam::polyMesh::defaultRegion; + names[0] = fallback; InfoErr << "Warning: No regionProperties, " @@ -169,17 +176,30 @@ wordList regionNames; } } } - else if (args.found("region")) + else { + // Single region option or fallback names.resize(1); - names.front() = args.get("region"); + auto& name = names[0]; + + if + ( + !args.readIfPresent("region", name) + ) + { + name = fallback; + } } - // Fallback to defaultRegion + // Final sanity checks and/or fallback if (names.empty()) { names.resize(1); - names.front() = Foam::polyMesh::defaultRegion; + names[0] = fallback; + } + else if (names.size() == 1 && names[0].empty()) + { + names[0] = fallback; } } diff --git a/src/OpenFOAM/primitives/bools/Switch/Switch.H b/src/OpenFOAM/primitives/bools/Switch/Switch.H index ddef797909..af8effc2f1 100644 --- a/src/OpenFOAM/primitives/bools/Switch/Switch.H +++ b/src/OpenFOAM/primitives/bools/Switch/Switch.H @@ -43,6 +43,9 @@ SourceFiles #include "bool.H" #include "stdFoam.H" +#include +#include + // Avoid any pre-processor conflicts with enum names #undef FALSE #undef TRUE diff --git a/src/OpenFOAM/primitives/strings/lists/CStringList.H b/src/OpenFOAM/primitives/strings/lists/CStringList.H index fd24374be1..1e88bc84a2 100644 --- a/src/OpenFOAM/primitives/strings/lists/CStringList.H +++ b/src/OpenFOAM/primitives/strings/lists/CStringList.H @@ -60,6 +60,7 @@ Description #include // std::initializer_list #include #include +#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/lists/SubStrings.H b/src/OpenFOAM/primitives/strings/lists/SubStrings.H index eb98de37ee..dcb8b6b943 100644 --- a/src/OpenFOAM/primitives/strings/lists/SubStrings.H +++ b/src/OpenFOAM/primitives/strings/lists/SubStrings.H @@ -37,6 +37,7 @@ Description #include // For std::ssub_match #include +#include #include #include diff --git a/src/OpenFOAM/primitives/strings/regex/regExpCxx.H b/src/OpenFOAM/primitives/strings/regex/regExpCxx.H index d2f288e1be..49e523d89f 100644 --- a/src/OpenFOAM/primitives/strings/regex/regExpCxx.H +++ b/src/OpenFOAM/primitives/strings/regex/regExpCxx.H @@ -69,6 +69,7 @@ SourceFiles #define Foam_regExpCxx_H #include +#include #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index 878028e6b8..14d0de250b 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -54,6 +54,7 @@ SourceFiles #include "Hasher.H" #include #include +#include #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOpsSort.H b/src/OpenFOAM/primitives/strings/stringOps/stringOpsSort.H index 3574b3e6b6..6c169f3f93 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOpsSort.H +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOpsSort.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,85 +46,106 @@ namespace Foam namespace stringOps { - //- 'Natural' compare for C-strings - // Uses algorithm and code from Jan-Marten Spit - // - // In the 'natural' comparison, strings are compared alphabetically - // and numerically. Thus 'file010.txt' sorts after 'file2.txt' - // - // \param s1 left string - // \param s2 right string +//- 'Natural' compare for C-strings +// Uses algorithm and code from Jan-Marten Spit +// +// In the 'natural' comparison, strings are compared alphabetically +// and numerically. Thus 'file010.txt' sorts after 'file2.txt' +// +// \param s1 left string +// \param s2 right string +// \return -1 when s1 < s2, 0 when s1 == s2, 1 when s1 > s2 +int natstrcmp(const char* s1, const char* s2); + + +//- Encapsulation of natural order sorting for algorithms +struct natural_sort +{ + //- Natural compare for std::string // \return -1 when s1 < s2, 0 when s1 == s2, 1 when s1 > s2 - int natstrcmp(const char* s1, const char* s2); - - - //- Encapsulation of natural order sorting for algorithms - struct natural_sort + static inline int compare + ( + const std::string& s1, + const std::string& s2 + ) { - //- Natural compare for std::string - // \return -1 when s1 < s2, 0 when s1 == s2, 1 when s1 > s2 - static inline int compare - ( - const std::string& s1, - const std::string& s2 - ) - { - return natstrcmp(s1.data(), s2.data()); - } + return stringOps::natstrcmp(s1.data(), s2.data()); + } - //- Default (forward) natural sorting + //- Natural compare two strings for a less-than relationship + static inline bool less + ( + const std::string& s1, + const std::string& s2 + ) + { + return (natural_sort::compare(s1, s2) < 0); + } + + //- Natural compare two strings for a greater-than relationship + static inline bool greater + ( + const std::string& s1, + const std::string& s2 + ) + { + return (natural_sort::compare(s1, s2) > 0); + } + + //- Default (forward) natural sorting + bool operator()(const std::string& s1, const std::string& s2) const + { + return (natural_sort::compare(s1, s2) < 0); + } + + //- Reverse natural sorting + struct reverse + { + //- Reverse natural sorting bool operator()(const std::string& s1, const std::string& s2) const { - return natural_sort::compare(s1, s2) < 0; + return (natural_sort::compare(s1, s2) > 0); } - - //- Reverse natural sorting - struct reverse - { - //- Reverse natural sorting - bool operator()(const std::string& s1, const std::string& s2) const - { - return natural_sort::compare(s1, s2) > 0; - } - }; - - - //- A list compare binary predicate for natural sort - template - struct less - { - const UList& values; - - less(const UList& list) - : - values(list) - {} - - bool operator()(const label a, const label b) const - { - return natural_sort::compare(values[a], values[b]) < 0; - } - }; - - - //- A list compare binary predicate for reverse natural sort - template - struct greater - { - const UList& values; - - greater(const UList& list) - : - values(list) - {} - - bool operator()(const label a, const label b) const - { - return natural_sort::compare(values[a], values[b]) > 0; - } - }; }; + + //- A UList compare binary predicate for natural sort + template + struct list_less + { + const UList& values; + + list_less(const UList& list) noexcept + : + values(list) + {} + + bool operator()(label a, label b) const + { + return (natural_sort::compare(values[a], values[b]) < 0); + } + }; + + + //- A Ulist compare binary predicate for reverse natural sort + template + struct list_greater + { + const UList& values; + + list_greater(const UList& list) noexcept + : + values(list) + {} + + bool operator()(label a, label b) const + { + return (natural_sort::compare(values[a], values[b]) > 0); + } + }; +}; + + } // End namespace stringOps } // End namespace Foam diff --git a/src/fileFormats/vtk/file/foamVtkSeriesWriter.C b/src/fileFormats/vtk/file/foamVtkSeriesWriter.C index 0950fe2a59..7a2a85c5c2 100644 --- a/src/fileFormats/vtk/file/foamVtkSeriesWriter.C +++ b/src/fileFormats/vtk/file/foamVtkSeriesWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -64,13 +64,17 @@ namespace Foam // 2. natural sort (name) struct seriesLess { - bool operator()(const fileNameInstant a, const fileNameInstant b) const + template + bool operator() + ( + const Instant& a, + const Instant& b + ) const { scalar val = compareOp()(a.value(), b.value()); if (val == 0) { - return - stringOps::natural_sort::compare(a.name(), b.name()) < 0; + return stringOps::natural_sort::less(a.name(), b.name()); } return val < 0; } @@ -78,7 +82,7 @@ namespace Foam // Check if value is less than upper, with some tolerance. - static inline bool lessThan(const scalar& val, const scalar& upper) + static inline bool lessThan(scalar val, scalar upper) { return (val < upper && Foam::mag(val - upper) > ROOTVSMALL); } diff --git a/src/finiteArea/include/addAllFaRegionOptions.H b/src/finiteArea/include/addAllFaRegionOptions.H index cefac98abc..9b203ebba0 100644 --- a/src/finiteArea/include/addAllFaRegionOptions.H +++ b/src/finiteArea/include/addAllFaRegionOptions.H @@ -12,7 +12,9 @@ License Description Add multi-region command-line options: - -all-area-regions, -area-regions, -area-region + -allAreas | -all-area-regions + -area-regions + -area-region Required Classes - Foam::argList @@ -25,9 +27,10 @@ See Also { Foam::argList::addBoolOption ( - "all-area-regions", + "allAreas", "Use all regions in finite-area regionProperties" ); + Foam::argList::addOptionCompat("allAreas", { "all-area-regions", 0 }); Foam::argList::addOption ( @@ -41,8 +44,11 @@ See Also ( "area-region", "name", - "Specify area-mesh region. Eg, -region shell" + "Specify area-mesh region. Eg, -area-region shell" ); + + // TBD: + //? Foam::argList::addOptionCompat("area-region", { "areaRegion", 0 }); } diff --git a/src/finiteArea/include/getAllFaRegionOptions.H b/src/finiteArea/include/getAllFaRegionOptions.H index 7e456a6d00..bd1cd32991 100644 --- a/src/finiteArea/include/getAllFaRegionOptions.H +++ b/src/finiteArea/include/getAllFaRegionOptions.H @@ -15,7 +15,7 @@ Description (-all-area-regions | -area-regions | -area-region) Priority - 1. -all-area-regions + 1. -all-area-regions (-allAreas) 2. -area-regions = specify multiple area regions to select, or a single area region 3. -area-region = specify a single area region @@ -46,12 +46,19 @@ See Also wordList areaRegionNames; { - // Local alias - auto& names = areaRegionNames; // Exit or fallback if nothing matches constexpr bool exitOnNoMatches = false; - if (args.found("all-area-regions")) + // Local aliases + auto& names = areaRegionNames; + const auto& fallback = Foam::polyMesh::defaultRegion; + + if + ( + // Handle both here (independent of which is an alias) + args.found("all-area-regions") + || args.found("allAreas") + ) { names = ( @@ -78,16 +85,20 @@ wordList areaRegionNames; else if ( wordRes select; - args.readListIfPresent("area-regions", select) + ( + // Handle both here (independent of which is an alias) + args.readListIfPresent("area-regions", select) + || args.readListIfPresent("areaRegions", select) + ) ) { select.uniq(); // Normally a no-op - if (select.size() == 1 && select.front().isLiteral()) + if (select.size() == 1 && select[0].isLiteral()) { // Identical to -area-region NAME names.resize(1); - names.front() = select.front(); + names[0] = select[0]; } else if (select.size()) { @@ -119,12 +130,12 @@ wordList areaRegionNames; } else { - InfoErr<< "... ignoring and using default region" + InfoErr + << "... ignoring and using default region" << nl << endl; - // Arbitrary fallback, but can handle this further on names.resize(1); - names.front() = Foam::polyMesh::defaultRegion; + names[0] = fallback; } } else @@ -162,7 +173,7 @@ wordList areaRegionNames; else { names.resize(1); - names.front() = Foam::polyMesh::defaultRegion; + names[0] = fallback; InfoErr << "Warning: No finite-area regionProperties, " @@ -171,17 +182,32 @@ wordList areaRegionNames; } } } - else if (args.found("area-region")) + else { + // Single region option or fallback names.resize(1); - names.front() = args.get("area-region"); + auto& name = names[0]; + + if + ( + // Handle both here (independent of which is an alias) + !args.readIfPresent("area-region", name) + && !args.readIfPresent("areaRegion", name) + ) + { + name = fallback; + } } - // Fallback to defaultRegion + // Final sanity checks and/or fallback if (names.empty()) { names.resize(1); - names.front() = Foam::polyMesh::defaultRegion; + names[0] = fallback; + } + else if (names.size() == 1 && names[0].empty()) + { + names[0] = fallback; } }