diff --git a/applications/test/argList/Test-argList.C b/applications/test/argList/Test-argList.C index 008e8421c4..06f8c408d4 100644 --- a/applications/test/argList/Test-argList.C +++ b/applications/test/argList/Test-argList.C @@ -123,15 +123,12 @@ int main(int argc, char *argv[]) argList::addDryRunOption("Just for testing"); argList::addVerboseOption("Increase verbosity"); - // Check -verbose before initialisation - UPstream::debug = argList::verbose(argc, argv); - #include "setRootCase.H" Pout<< "command-line (" << args.options().size() << " options, " << args.args().size() << " args)" << nl - << " " << args.commandLine().c_str() << nl << nl; + << " " << args.commandLine().data() << nl << nl; Pout<< "rootPath: " << args.rootPath() << nl << "globalCase: " << args.globalCaseName() << nl diff --git a/applications/test/parallel-comm0/Test-parallel-comm0.C b/applications/test/parallel-comm0/Test-parallel-comm0.C index e8c8a1e5b9..9185ff4cb4 100644 --- a/applications/test/parallel-comm0/Test-parallel-comm0.C +++ b/applications/test/parallel-comm0/Test-parallel-comm0.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022-2023 OpenCFD Ltd. + Copyright (C) 2022-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -67,10 +67,6 @@ int main(int argc, char *argv[]) { argList::noBanner(); argList::noCheckProcessorDirectories(); - argList::addVerboseOption("Set UPstream::debug level"); - - // Check -verbose before initialisation - UPstream::debug = argList::verbose(argc, argv); #include "setRootCase.H" diff --git a/applications/test/parallel-comm2/Test-parallel-comm2.C b/applications/test/parallel-comm2/Test-parallel-comm2.C index 5b28c75b7c..38fc45361f 100644 --- a/applications/test/parallel-comm2/Test-parallel-comm2.C +++ b/applications/test/parallel-comm2/Test-parallel-comm2.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022-2023 OpenCFD Ltd. + Copyright (C) 2022-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,7 +66,6 @@ int main(int argc, char *argv[]) { argList::noBanner(); argList::noCheckProcessorDirectories(); - argList::addVerboseOption("Set UPstream::debug level"); argList::addBoolOption("info", "information"); argList::addBoolOption("print-tree", "Report tree(s) as graph"); argList::addBoolOption("comm-split", "Test simple comm split"); @@ -74,9 +73,6 @@ int main(int argc, char *argv[]) argList::addBoolOption("host-comm", "Test Pstream host-comm"); argList::addBoolOption("host-broadcast", "Test host-base broadcasts"); - // Check -verbose before initialisation - UPstream::debug = argList::verbose(argc, argv); - #include "setRootCase.H" const bool optPrintTree = args.found("print-tree"); diff --git a/applications/test/parallel-external-init/Test-parallel-external-init.C b/applications/test/parallel-external-init/Test-parallel-external-init.C index 626c4902bb..5d6cef4bea 100644 --- a/applications/test/parallel-external-init/Test-parallel-external-init.C +++ b/applications/test/parallel-external-init/Test-parallel-external-init.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -125,13 +125,16 @@ int main(int argc, char *argv[]) argList::addVerboseOption("Set UPstream::debug level"); // Check -verbose before initialisation - UPstream::debug = argList::verbose(argc, argv); + if (!UPstream::debug) + { + UPstream::debug = argList::verbose(argc, argv); + } startMPI(); #include "setRootCase.H" - Pout<< message().c_str(); + Pout<< message().data(); stopMPI(); diff --git a/applications/test/processorTopology/Test-processorTopology.C b/applications/test/processorTopology/Test-processorTopology.C index ef3622556c..4c94445319 100644 --- a/applications/test/processorTopology/Test-processorTopology.C +++ b/applications/test/processorTopology/Test-processorTopology.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022-2023 OpenCFD Ltd. + Copyright (C) 2022-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -44,19 +44,15 @@ using namespace Foam; int main(int argc, char *argv[]) { argList::noFunctionObjects(); - argList::addVerboseOption("Set UPstream::debug level"); argList::addBoolOption("comm-graph", "Test simple graph communicator"); argList::addNote ( "Create graph of OpenFOAM mesh connections" ); - // Check -verbose before initialisation - UPstream::debug = argList::verbose(argc, argv); - #include "setRootCase.H" - if (!Pstream::parRun()) + if (!UPstream::parRun()) { FatalErrorInFunction << "Only meaningful in parallel" diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 557d4614a5..1e316317e5 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2024 OpenCFD Ltd. + Copyright (C) 2015-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -916,6 +916,8 @@ Foam::argList::argList // Pre-scan for some options needed for initial setup: // -fileHandler (takes an argument) // -mpi-threads (bool option) + // -debug-switch, -info-switch, -opt-switch + // so their values can also influence the initial setup // // Also handle -dry-run and -verbose counting // (it is left to the application to decide what to do with them). @@ -963,6 +965,53 @@ Foam::argList::argList emitErrorMessage = true; } } + else if (strcmp(optName, "debug-switch") == 0) + { + // The '-debug-switch' option: + // change registered debug switch + if (argi < argc-1) + { + ++argi; + debug::debugObjects() + .setNamedValue(argv[argi], 1); // silent + } + else + { + // emit error on the second pass + } + } + else if (strcmp(optName, "info-switch") == 0) + { + // The '-info-switch' option: + // change registered info switch + if (argi < argc-1) + { + ++argi; + DetailInfo << "info-switch "; + debug::infoObjects() + .setNamedValue(argv[argi], 1); // silent + } + else + { + // emit error on the second pass + } + } + else if (strcmp(optName, "opt-switch") == 0) + { + // The '-opt-switch' option: + // change registered optimisation switch + if (argi < argc-1) + { + ++argi; + DetailInfo << "opt-switch "; + debug::optimisationObjects() + .setNamedValue(argv[argi], 1); // silent + } + else + { + // emit error on the second pass + } + } else if (validParOptions.contains(optName)) { // Contains a parallel run option @@ -977,8 +1026,6 @@ Foam::argList::argList Info<< nl << "Error: option '-" << optName << "' requires an argument" << nl << nl; - - //NO: UPstream::exit(1); // works for serial and parallel } } } @@ -1102,26 +1149,26 @@ Foam::argList::argList else if (strcmp(optName, "debug-switch") == 0) { // The '-debug-switch' option: - // change registered debug switch + // dryrun reporting only (already set above) DetailInfo << "debug-switch "; debug::debugObjects() - .setNamedValue(args_[argi], 1, true); + .setNamedValue(args_[argi], 1, true, true); // dryrun } else if (strcmp(optName, "info-switch") == 0) { // The '-info-switch' option: - // change registered info switch + // dryrun reporting only (already set above) DetailInfo << "info-switch "; debug::infoObjects() - .setNamedValue(args_[argi], 1, true); + .setNamedValue(args_[argi], 1, true, true); // dryrun } else if (strcmp(optName, "opt-switch") == 0) { // The '-opt-switch' option: - // change registered optimisation switch + // dryrun reporting only (already set above) DetailInfo << "opt-switch "; debug::optimisationObjects() - .setNamedValue(args_[argi], 1, true); + .setNamedValue(args_[argi], 1, true, true); // dryrun } else { diff --git a/src/OpenFOAM/global/debug/simpleObjectRegistry.C b/src/OpenFOAM/global/debug/simpleObjectRegistry.C index 4b032b3570..9b43c0db12 100644 --- a/src/OpenFOAM/global/debug/simpleObjectRegistry.C +++ b/src/OpenFOAM/global/debug/simpleObjectRegistry.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2022 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,13 +38,17 @@ License void Foam::simpleObjectRegistry::setValues ( const dictionary& dict, - bool report + bool verbose, + bool dryrun ) { // Report enables output, but respect DetailInfo state as well. - // The local log variable captures this logic. + verbose = (verbose && Foam::infoDetailLevel > 0); - const bool log = (report && Foam::infoDetailLevel > 0); + if (dryrun && !verbose) + { + return; + } for (const entry& dEntry : dict) { @@ -52,10 +56,24 @@ void Foam::simpleObjectRegistry::setValues simpleObjectRegistryEntry* objPtr = this->find(name); - if (objPtr) + if (verbose) { - Log << " " << dEntry << nl; + if (objPtr) + { + Info<< " " << dEntry << nl; + } + else + { + Info<< " " << name << " (unregistered)" << nl; + } + } + if (dryrun) + { + // Nothing else to do + } + else if (objPtr) + { const List& objects = *objPtr; OCharStream os; @@ -85,66 +103,88 @@ void Foam::simpleObjectRegistry::setValues } } } - else - { - Log << " " << name << " (unregistered)" << nl; - } } } void Foam::simpleObjectRegistry::setNamedValue ( - std::string name, + const std::string_view name, int val, - bool report + bool verbose, + bool dryrun ) { - // Report enables output, but respect DetailInfo state as well. - // The local log variable captures this logic. + // Respect DetailInfo state + verbose = (verbose && Foam::infoDetailLevel > 0); - const bool log = (report && Foam::infoDetailLevel > 0); + if (dryrun && !verbose) + { + return; + } token tok(static_cast