ENH: argList improvements

- argList::envExecutable() static method.
  This is identical to getEnv("FOAM_EXECUTABLE"), where the name of
  the executable has typically been set from the argList construction.

  Provides a singleton access to this value from locations that
  do not have knowledge of the originating command args (argList).
  This is a similar rationale as for the argList::envGlobalPath() static.

- additional argList::envRelativePath() static method.

- make -dry-run handling more central and easier to use by adding into
  argList itself.

STYLE: drop handling of -srcDoc (v1706 option)

- replaced with -doc-source for 1712 and never used much anyhow
This commit is contained in:
Mark Olesen
2021-11-01 11:31:56 +01:00
parent a19f03a5cb
commit b364a9e72c
23 changed files with 226 additions and 123 deletions

View File

@ -756,9 +756,8 @@ int main(int argc, char *argv[])
"checkGeometry", "checkGeometry",
"Check all surface geometry for quality" "Check all surface geometry for quality"
); );
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Check case set-up only using a single time step" "Check case set-up only using a single time step"
); );
argList::addOption argList::addOption
@ -789,7 +788,7 @@ int main(int argc, char *argv[])
const bool overwrite = args.found("overwrite"); const bool overwrite = args.found("overwrite");
const bool checkGeometry = args.found("checkGeometry"); const bool checkGeometry = args.found("checkGeometry");
const bool surfaceSimplify = args.found("surfaceSimplify"); const bool surfaceSimplify = args.found("surfaceSimplify");
const bool dryRun = args.found("dry-run"); const bool dryRun = args.dryRun();
if (dryRun) if (dryRun)
{ {

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -228,9 +228,8 @@ int main(int argc, char *argv[])
"In serial mode use times from processor0/ directory, but operate on " "In serial mode use times from processor0/ directory, but operate on "
"processor\\d+ directories" "processor\\d+ directories"
); );
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Report action without moving/renaming" "Report action without moving/renaming"
); );
argList::addBoolOption argList::addBoolOption
@ -247,7 +246,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
dryrun = args.found("dry-run"); dryrun = args.dryRun();
verbose = args.found("verbose"); verbose = args.found("verbose");

View File

@ -325,9 +325,8 @@ int main(int argc, char *argv[])
#include "addAllRegionOptions.H" #include "addAllRegionOptions.H"
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Test without writing the decomposition. " "Test without writing the decomposition. "
"Changes -cellDist to only write VTK output." "Changes -cellDist to only write VTK output."
); );
@ -410,7 +409,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
const bool dryrun = args.found("dry-run"); const bool dryrun = args.dryRun();
const bool writeCellDist = args.found("cellDist"); const bool writeCellDist = args.found("cellDist");
const bool verbose = args.found("verbose"); const bool verbose = args.found("verbose");

View File

@ -2488,9 +2488,8 @@ int main(int argc, char *argv[])
#include "addOverwriteOption.H" #include "addOverwriteOption.H"
argList::addBoolOption("decompose", "Decompose case"); argList::addBoolOption("decompose", "Decompose case");
argList::addBoolOption("reconstruct", "Reconstruct case"); argList::addBoolOption("reconstruct", "Reconstruct case");
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Test without writing the decomposition. " "Test without writing the decomposition. "
"Changes -cellDist to only write volScalarField." "Changes -cellDist to only write volScalarField."
); );
@ -2555,7 +2554,7 @@ int main(int argc, char *argv[])
const bool reconstruct = args.found("reconstruct"); const bool reconstruct = args.found("reconstruct");
const bool writeCellDist = args.found("cellDist"); const bool writeCellDist = args.found("cellDist");
const bool dryrun = args.found("dry-run"); const bool dryrun = args.dryRun();
const bool newTimes = args.found("newTimes"); const bool newTimes = args.found("newTimes");
bool decompose = args.found("decompose"); bool decompose = args.found("decompose");

View File

@ -119,9 +119,8 @@ int main(int argc, char *argv[])
"len", "len",
"Visualization length for planes (visualized as triangles)" "Visualization length for planes (visualized as triangles)"
); );
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Test movement without a mesh" "Test movement without a mesh"
); );
argList::addBoolOption argList::addBoolOption
@ -142,7 +141,7 @@ int main(int argc, char *argv[])
const label span = Foam::max(1, args.getOrDefault<label>("span", 1)); const label span = Foam::max(1, args.getOrDefault<label>("span", 1));
// Control parameters // Control parameters
const bool dryrun = args.found("dry-run"); const bool dryrun = args.dryRun();
const bool slave = args.found("slave"); const bool slave = args.found("slave");
const bool removeLock = args.found("removeLock"); const bool removeLock = args.found("removeLock");

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -55,9 +55,8 @@ int main(int argc, char *argv[])
argList::noFunctionObjects(); // Never use function objects argList::noFunctionObjects(); // Never use function objects
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Test initial lumped points state without a mesh" "Test initial lumped points state without a mesh"
); );
argList::addOption argList::addOption
@ -85,15 +84,13 @@ int main(int argc, char *argv[])
const bool noInterpolate = args.found("no-interpolate"); const bool noInterpolate = args.found("no-interpolate");
const bool dryrun = args.found("dry-run");
// const bool verbose = args.found("verbose"); // const bool verbose = args.found("verbose");
args.readIfPresent("visual-length", lumpedPointState::visLength); args.readIfPresent("visual-length", lumpedPointState::visLength);
#include "createTime.H" #include "createTime.H"
if (dryrun) if (args.dryRun())
{ {
// Create without a mesh // Create without a mesh
autoPtr<lumpedPointIOMovement> movement = autoPtr<lumpedPointIOMovement> movement =

View File

@ -74,9 +74,8 @@ int main(int argc, char* argv[])
"Force use of legacy obstacles table" "Force use of legacy obstacles table"
); );
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Read obstacles and write VTK only" "Read obstacles and write VTK only"
); );
@ -90,8 +89,6 @@ int main(int argc, char* argv[])
IOdictionary setFieldsDict(dictIO); IOdictionary setFieldsDict(dictIO);
const bool dryrun = args.found("dry-run");
const fileName& casepath = runTime.globalPath(); const fileName& casepath = runTime.globalPath();
pars.timeName = "0"; pars.timeName = "0";
@ -181,7 +178,7 @@ int main(int argc, char* argv[])
PDRobstacle::generateVtk(casepath/"VTK", obstacles, cylinders); PDRobstacle::generateVtk(casepath/"VTK", obstacles, cylinders);
if (dryrun) if (args.dryRun())
{ {
Info<< nl Info<< nl
<< "dry-run: stopping after reading/writing obstacles" << nl << "dry-run: stopping after reading/writing obstacles" << nl

View File

@ -404,9 +404,8 @@ int main(int argc, char *argv[])
timeSelector::addOptions(); timeSelector::addOptions();
argList::addOptionCompat("dry-run", {"test", 1806}); argList::addOptionCompat("dry-run", {"test", 1806});
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Test only do not change any files" "Test only do not change any files"
); );
argList::addBoolOption argList::addBoolOption

View File

@ -91,16 +91,15 @@ int main(int argc, char *argv[])
"Preserve sub-entry as .backup", "Preserve sub-entry as .backup",
true // Advanced true // Advanced
); );
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Evaluate but do not write" "Evaluate but do not write"
); );
#include "addRegionOption.H" #include "addRegionOption.H"
#include "setRootCase.H" #include "setRootCase.H"
const bool dryrun = args.found("dry-run"); const bool dryrun = args.dryRun();
const bool backup = args.found("backup"); const bool backup = args.found("backup");
const bool cacheFields = args.found("cache-fields"); const bool cacheFields = args.found("cache-fields");

View File

@ -549,9 +549,8 @@ int main(int argc, char *argv[])
"file", "file",
"Alternative dictionary for setExprFieldsDict" "Alternative dictionary for setExprFieldsDict"
); );
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Evaluate but do not write" "Evaluate but do not write"
); );
argList::addBoolOption argList::addBoolOption
@ -663,7 +662,7 @@ int main(int argc, char *argv[])
#include "createTime.H" #include "createTime.H"
const bool dryrun = args.found("dry-run"); const bool dryrun = args.dryRun();
const bool verbose = args.found("verbose"); const bool verbose = args.found("verbose");
const word dictName("setExprFieldsDict"); const word dictName("setExprFieldsDict");

View File

@ -72,8 +72,8 @@ Foam::TimePaths::TimePaths
const word& constantName const word& constantName
) )
: :
processorCase_(args.parRunControl().parRun()), processorCase_(args.runControl().parRun()),
distributed_(args.parRunControl().distributed()), distributed_(args.runControl().distributed()),
rootPath_(args.rootPath()), rootPath_(args.rootPath()),
globalCaseName_(args.globalCaseName()), globalCaseName_(args.globalCaseName()),
case_(args.caseName()), case_(args.caseName()),

View File

@ -449,6 +449,16 @@ bool Foam::argList::bannerEnabled()
} }
void Foam::argList::addDryRunOption
(
const string& usage,
bool advanced
)
{
addOption("dry-run", "", usage, advanced);
}
void Foam::argList::noFunctionObjects(bool addWithOption) void Foam::argList::noFunctionObjects(bool addWithOption)
{ {
removeOption("noFunctionObjects"); removeOption("noFunctionObjects");
@ -519,12 +529,33 @@ bool Foam::argList::postProcess(int argc, char *argv[])
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::word Foam::argList::envExecutable()
{
return Foam::getEnv("FOAM_EXECUTABLE");
}
Foam::fileName Foam::argList::envGlobalPath() Foam::fileName Foam::argList::envGlobalPath()
{ {
return Foam::getEnv("FOAM_CASE"); return Foam::getEnv("FOAM_CASE");
} }
Foam::fileName Foam::argList::envRelativePath
(
const fileName& input,
const bool caseTag
)
{
if (input.isAbsolute())
{
return input.relative(envGlobalPath(), caseTag);
}
return input;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::word Foam::argList::optionCompat(const word& optName) Foam::word Foam::argList::optionCompat(const word& optName)
@ -735,6 +766,11 @@ void Foam::argList::setCasePaths()
// Executable name, unless already present in the environment // Executable name, unless already present in the environment
setEnv("FOAM_EXECUTABLE", executable_, false); setEnv("FOAM_EXECUTABLE", executable_, false);
if (validOptions.found("dry-run") && options_.found("dry-run"))
{
runControl_.dryRun(true);
}
} }
@ -796,7 +832,7 @@ Foam::argList::argList
if (validParOptions.found(optName)) if (validParOptions.found(optName))
{ {
parRunControl_.runPar(argc, argv, needsThread); runControl_.runPar(argc, argv, needsThread);
break; break;
} }
} }
@ -921,7 +957,7 @@ Foam::argList::argList
bool initialise bool initialise
) )
: :
parRunControl_(args.parRunControl_), runControl_(args.runControl_),
args_(args.args_), args_(args.args_),
options_(options), options_(options),
libs_(), libs_(),
@ -957,11 +993,7 @@ void Foam::argList::parse
displayDoc(false); displayDoc(false);
quickExit = true; quickExit = true;
} }
else if else if (options_.found("doc-source"))
(
options_.found("doc-source")
|| options_.found("srcDoc") // Compat 1706
)
{ {
displayDoc(true); displayDoc(true);
quickExit = true; quickExit = true;
@ -1103,7 +1135,7 @@ void Foam::argList::parse
const int writeHostsSwitch = Foam::debug::infoSwitch("writeHosts", 1); const int writeHostsSwitch = Foam::debug::infoSwitch("writeHosts", 1);
// Collect machine/pid, and check that the build is identical // Collect machine/pid, and check that the build is identical
if (parRunControl_.parRun()) if (runControl_.parRun())
{ {
if (Pstream::master()) if (Pstream::master())
{ {
@ -1151,7 +1183,7 @@ void Foam::argList::parse
fileNameList roots; fileNameList roots;
// If this actually is a parallel run // If this actually is a parallel run
if (parRunControl_.parRun()) if (runControl_.parRun())
{ {
// For the master // For the master
if (Pstream::master()) if (Pstream::master())
@ -1192,7 +1224,7 @@ void Foam::argList::parse
if (this->readListIfPresent("roots", roots)) if (this->readListIfPresent("roots", roots))
{ {
source = "-roots"; source = "-roots";
parRunControl_.distributed(true); runControl_.distributed(true);
if (roots.size() != 1) if (roots.size() != 1)
{ {
dictNProcs = roots.size()+1; dictNProcs = roots.size()+1;
@ -1276,7 +1308,7 @@ void Foam::argList::parse
if (decompDict.getOrDefault("distributed", false)) if (decompDict.getOrDefault("distributed", false))
{ {
nDomainsMandatory = true; nDomainsMandatory = true;
parRunControl_.distributed(true); runControl_.distributed(true);
decompDict.readEntry("roots", roots); decompDict.readEntry("roots", roots);
} }
@ -1446,7 +1478,7 @@ void Foam::argList::parse
); );
fromMaster >> args_ >> options_ >> nroots; fromMaster >> args_ >> options_ >> nroots;
parRunControl_.distributed(nroots); runControl_.distributed(nroots);
// Establish rootPath_/globalCase_/case_ for sub-process // Establish rootPath_/globalCase_/case_ for sub-process
setCasePaths(); setCasePaths();
@ -1470,7 +1502,7 @@ void Foam::argList::parse
} }
// If needed, adjust fileHandler for distributed roots // If needed, adjust fileHandler for distributed roots
if (parRunControl_.distributed()) if (runControl_.distributed())
{ {
if (fileOperation::fileHandlerPtr_) if (fileOperation::fileHandlerPtr_)
{ {
@ -1479,7 +1511,7 @@ void Foam::argList::parse
} }
// Keep/discard sub-process host/root information for reporting: // Keep/discard sub-process host/root information for reporting:
if (Pstream::master() && parRunControl_.parRun()) if (Pstream::master() && runControl_.parRun())
{ {
if (!writeHostsSwitch) if (!writeHostsSwitch)
{ {
@ -1497,7 +1529,7 @@ void Foam::argList::parse
Info<< "Case : " << (rootPath_/globalCase_).c_str() << nl Info<< "Case : " << (rootPath_/globalCase_).c_str() << nl
<< "nProcs : " << nProcs << nl; << "nProcs : " << nProcs << nl;
if (parRunControl_.parRun()) if (runControl_.parRun())
{ {
if (hostProcs.size()) if (hostProcs.size())
{ {

View File

@ -103,7 +103,7 @@ SourceFiles
#include "SLList.H" #include "SLList.H"
#include "HashSet.H" #include "HashSet.H"
#include "fileName.H" #include "fileName.H"
#include "parRun.H" #include "parRun.H" // "ParRunControl"
#include "ITstream.H" #include "ITstream.H"
#include "dlLibraryTable.H" #include "dlLibraryTable.H"
#include "OSspecific.H" #include "OSspecific.H"
@ -131,9 +131,9 @@ class argList
//- Track enabled/disabled checking of processor directories state //- Track enabled/disabled checking of processor directories state
static bool checkProcessorDirectories_; static bool checkProcessorDirectories_;
//- Switch on/off parallel mode. //- Switch on/off parallel mode, dry-run etc.
// Construct first so destructor is done last. // Construct first so destructor is done last.
ParRunControl parRunControl_; ParRunControl runControl_;
//- The arguments after removing known options //- The arguments after removing known options
stringList args_; stringList args_;
@ -183,9 +183,11 @@ class argList
// * [-case dir] // * [-case dir]
// * cwd // * cwd
// //
// Also export FOAM_CASE and FOAM_CASENAME environment variables // Exports FOAM_CASE and FOAM_CASENAME env variables so they can
// so they can be used immediately (eg, in decomposeParDict), as well // be used immediately (eg, in decomposeParDict).
// as the FOAM_EXECUTABLE environment. // Exports FOAM_EXECUTABLE env variable.
//
// Detects -dry-run option
void setCasePaths(); void setCasePaths();
//- Transcribe argv into internal args_. //- Transcribe argv into internal args_.
@ -284,6 +286,15 @@ public:
// Environment // Environment
//- Name of the executable from environment variable
//
// Returns the contents of the \c FOAM_EXECUTABLE variable,
// which has previously been set by argList.
//
// This will normally be identical to the value of executable(),
// but obtained from the environment.
static word envExecutable();
//- Global case (directory) from environment variable //- Global case (directory) from environment variable
// //
// Returns the contents of the \c FOAM_CASE variable, // Returns the contents of the \c FOAM_CASE variable,
@ -293,6 +304,19 @@ public:
// but obtained via the environment. // but obtained via the environment.
static fileName envGlobalPath(); static fileName envGlobalPath();
//- Return the input relative to the globalPath by stripping off
//- a leading value of the envGlobalPath
//
// \param input the directory or filename to make case-relative
// \param caseTag replace globalPath with \<case\> for later
// use with expand(), or prefix \<case\> if the file name was
// not an absolute location
static fileName envRelativePath
(
const fileName& input,
const bool caseTag = false
);
// Low-level // Low-level
@ -304,19 +328,19 @@ public:
// Access // Access
//- Name of executable without the path //- Name of executable without the path
inline const word& executable() const; inline const word& executable() const noexcept;
//- The command line options and arguments concatenated as a string //- The command line options and arguments concatenated as a string
inline const string& commandLine() const; inline const string& commandLine() const noexcept;
//- Return root path //- Return root path
inline const fileName& rootPath() const; inline const fileName& rootPath() const noexcept;
//- Return case name (parallel run) or global case (serial run) //- Return case name (parallel run) or global case (serial run)
inline const fileName& caseName() const; inline const fileName& caseName() const noexcept;
//- Return global case name //- Return global case name
inline const fileName& globalCaseName() const; inline const fileName& globalCaseName() const noexcept;
//- Return the full path to the (processor local) case //- Return the full path to the (processor local) case
// \note This is guaranteed to be an absolute path // \note This is guaranteed to be an absolute path
@ -339,30 +363,36 @@ public:
const bool caseTag = false const bool caseTag = false
) const; ) const;
//- Return the run control (parallel, dry-run etc)
inline const ParRunControl& runControl() const noexcept;
//- Return the dryRun flag
inline bool dryRun() const noexcept;
//- Modify the dryRun flag
inline bool dryRun(const bool on) noexcept;
//- Return distributed flag //- Return distributed flag
//- (i.e. are rootPaths different on different machines) //- (i.e. are rootPaths different on different machines)
inline bool distributed() const; inline bool distributed() const noexcept;
//- Return the ParRunControl
inline const ParRunControl& parRunControl() const;
//- Mutable access to the loaded dynamic libraries //- Mutable access to the loaded dynamic libraries
inline dlLibraryTable& libs() const; inline dlLibraryTable& libs() const noexcept;
//- The number of arguments //- The number of arguments
inline label size() const noexcept; inline label size() const noexcept;
//- Return arguments //- Return arguments
inline const stringList& args() const; inline const stringList& args() const noexcept;
//- Non-const access to the command arguments (non-options) //- Non-const access to the command arguments (non-options)
inline stringList& args(); inline stringList& args() noexcept;
//- Return options //- Return options
inline const HashTable<string>& options() const; inline const HashTable<string>& options() const noexcept;
//- Return non-const access to the command options //- Return non-const access to the command options
inline HashTable<string>& options(); inline HashTable<string>& options() noexcept;
//- Return true if the named option is found //- Return true if the named option is found
inline bool found(const word& optName) const; inline bool found(const word& optName) const;
@ -573,6 +603,13 @@ public:
// Queries the Foam::infoDetailLevel flag. // Queries the Foam::infoDetailLevel flag.
static bool bannerEnabled(); static bool bannerEnabled();
//- Add a 'dry-run' bool option to validOptions with usage information
static void addDryRunOption
(
const string& usage, //! usage information (mandatory)
bool advanced = false
);
//- Remove '-noFunctionObjects' option and ignore any occurrences. //- Remove '-noFunctionObjects' option and ignore any occurrences.
// Optionally add a '-withFunctionObjects' option instead // Optionally add a '-withFunctionObjects' option instead
static void noFunctionObjects(bool addWithOption = false); static void noFunctionObjects(bool addWithOption = false);
@ -687,6 +724,9 @@ public:
return this->getOrDefault<T>(optName, deflt); return this->getOrDefault<T>(optName, deflt);
} }
//- Same as runControl() - v2106 and earlier
const ParRunControl& parRunControl() const { return runControl_; }
// Older style access (including 1712 release) // Older style access (including 1712 release)

View File

@ -48,31 +48,31 @@ inline void Foam::argList::readList(ITstream& is, List<T>& list)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::word& Foam::argList::executable() const inline const Foam::word& Foam::argList::executable() const noexcept
{ {
return executable_; return executable_;
} }
inline const Foam::string& Foam::argList::commandLine() const inline const Foam::string& Foam::argList::commandLine() const noexcept
{ {
return commandLine_; return commandLine_;
} }
inline const Foam::fileName& Foam::argList::rootPath() const inline const Foam::fileName& Foam::argList::rootPath() const noexcept
{ {
return rootPath_; return rootPath_;
} }
inline const Foam::fileName& Foam::argList::caseName() const inline const Foam::fileName& Foam::argList::caseName() const noexcept
{ {
return case_; return case_;
} }
inline const Foam::fileName& Foam::argList::globalCaseName() const inline const Foam::fileName& Foam::argList::globalCaseName() const noexcept
{ {
return globalCase_; return globalCase_;
} }
@ -100,19 +100,32 @@ inline Foam::fileName Foam::argList::relativePath
} }
inline bool Foam::argList::distributed() const inline const Foam::ParRunControl&
Foam::argList::runControl() const noexcept
{ {
return parRunControl_.distributed(); return runControl_;
} }
inline const Foam::ParRunControl& Foam::argList::parRunControl() const inline bool Foam::argList::dryRun() const noexcept
{ {
return parRunControl_; return runControl_.dryRun();
} }
inline Foam::dlLibraryTable& Foam::argList::libs() const inline bool Foam::argList::dryRun(const bool on) noexcept
{
return runControl_.dryRun(on);
}
inline bool Foam::argList::distributed() const noexcept
{
return runControl_.distributed();
}
inline Foam::dlLibraryTable& Foam::argList::libs() const noexcept
{ {
return libs_; return libs_;
} }
@ -124,25 +137,27 @@ inline Foam::label Foam::argList::size() const noexcept
} }
inline const Foam::stringList& Foam::argList::args() const inline const Foam::stringList& Foam::argList::args() const noexcept
{ {
return args_; return args_;
} }
inline Foam::stringList& Foam::argList::args() inline Foam::stringList& Foam::argList::args() noexcept
{ {
return args_; return args_;
} }
inline const Foam::HashTable<Foam::string>& Foam::argList::options() const inline const Foam::HashTable<Foam::string>&
Foam::argList::options() const noexcept
{ {
return options_; return options_;
} }
inline Foam::HashTable<Foam::string>& Foam::argList::options() inline Foam::HashTable<Foam::string>&
Foam::argList::options() noexcept
{ {
return options_; return options_;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,13 +28,17 @@ Class
Foam::ParRunControl Foam::ParRunControl
Description Description
Helper class for initializing parallel jobs from the command arguments. Helper class for initializing parallel jobs from the command arguments,
storing 'dry-run' state etc.
Also handles cleanup of parallel (or serial) jobs. Also handles cleanup of parallel (or serial) jobs.
Note
In the meantime the class name may be slightly misleading.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef parRun_H #ifndef argListRunControl_H
#define parRun_H #define argListRunControl_H
#include "Pstream.H" #include "Pstream.H"
#include "IOstreams.H" #include "IOstreams.H"
@ -45,11 +49,12 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class ParRunControl Declaration Class ParRunControl Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class ParRunControl class ParRunControl
{ {
bool dryRun_;
bool parallel_; bool parallel_;
bool distributed_; bool distributed_;
@ -58,6 +63,7 @@ public:
//- Default construct //- Default construct
ParRunControl() ParRunControl()
: :
dryRun_(false),
parallel_(false), parallel_(false),
distributed_(false) distributed_(false)
{} {}
@ -69,38 +75,52 @@ public:
{ {
Info<< "Finalising parallel run" << endl; Info<< "Finalising parallel run" << endl;
} }
UPstream::shutdown();
Pstream::shutdown();
} }
//- Initialize Pstream for a parallel run //- Initialize Pstream for a parallel run
void runPar(int& argc, char**& argv, bool needsThread) void runPar(int& argc, char**& argv, bool needsThread)
{ {
if (!Pstream::init(argc, argv, needsThread)) if (!UPstream::init(argc, argv, needsThread))
{ {
Info<< "Failed to start parallel run" << endl; Info<< "Failed to start parallel run" << endl;
Pstream::exit(1); UPstream::exit(1);
} }
parallel_ = true; parallel_ = true;
} }
//- True if this is parallel run.
bool parRun() const //- True if set as 'dry-run'
bool dryRun() const noexcept
{
return dryRun_;
}
//- Set as 'dry-run', return old value
bool dryRun(bool on) noexcept
{
bool old(dryRun_);
dryRun_ = on;
return old;
}
//- True if this is a parallel run
bool parRun() const noexcept
{ {
return parallel_; return parallel_;
} }
//- True if this is a parallel run and uses distributed roots. //- True if this is a parallel run and uses distributed roots.
bool distributed() const bool distributed() const noexcept
{ {
return parallel_ && distributed_; return (parallel_ && distributed_);
} }
//- Set use of distributed roots. //- Set use of distributed roots, but only if actually parallel
void distributed(bool on) void distributed(bool on) noexcept
{ {
distributed_ = (parallel_ ? on : false); distributed_ = (parallel_ && on);
} }
}; };

View File

@ -38,9 +38,6 @@ Description
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace
{
// Extract value from "key=<digits>", eg "LSB;label=32;scalar=64" // Extract value from "key=<digits>", eg "LSB;label=32;scalar=64"
// The 'tag' string includes the '=' for additional safety. // The 'tag' string includes the '=' for additional safety.
// Return 0 on any errors // Return 0 on any errors
@ -59,8 +56,6 @@ static inline unsigned getTaggedSize(const char* tag, const std::string& s)
return std::stoul(s.substr(first, last)); return std::stoul(s.substr(first, last));
} }
} // End namespace anonymous
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

View File

@ -1,6 +1,25 @@
Foam::argList::addBoolOption /*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Add -dry-run and -dry-run-write options
Required Classes
- Foam::argList
\*---------------------------------------------------------------------------*/
Foam::argList::addDryRunOption
( (
"dry-run",
"Check case set-up only using a single time step" "Check case set-up only using a single time step"
); );
Foam::argList::addBoolOption Foam::argList::addBoolOption
@ -8,3 +27,5 @@ Foam::argList::addBoolOption
"dry-run-write", "dry-run-write",
"Check case set-up and write only using a single time step" "Check case set-up and write only using a single time step"
); );
// ************************************************************************* //

View File

@ -28,7 +28,7 @@ Provided Variables
Foam::autoPtr<Foam::fvMesh> meshPtr(nullptr); Foam::autoPtr<Foam::fvMesh> meshPtr(nullptr);
Foam::word regionName(Foam::polyMesh::defaultRegion); Foam::word regionName(Foam::polyMesh::defaultRegion);
if (args.found("dry-run") || args.found("dry-run-write")) if (args.dryRun() || args.found("dry-run-write"))
{ {
Foam::Info Foam::Info
<< "Operating in 'dry-run' mode: case will run for 1 time step. " << "Operating in 'dry-run' mode: case will run for 1 time step. "

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -125,7 +125,7 @@ Foam::autoPtr<Foam::dynamicFvMesh> Foam::dynamicFvMesh::New
const Time& runTime const Time& runTime
) )
{ {
if (args.found("dry-run") || args.found("dry-run-write")) if (args.dryRun() || args.found("dry-run-write"))
{ {
Info Info
<< "Operating in 'dry-run' mode: case will run for 1 time step. " << "Operating in 'dry-run' mode: case will run for 1 time step. "

View File

@ -1,8 +1,6 @@
#ifndef faCFD_H #ifndef faCFD_H
#define faCFD_H #define faCFD_H
#include "parRun.H"
#include "Time.H" #include "Time.H"
#include "faMesh.H" #include "faMesh.H"
#include "areaFields.H" #include "areaFields.H"

View File

@ -1,8 +1,6 @@
#ifndef fvCFD_H #ifndef fvCFD_H
#define fvCFD_H #define fvCFD_H
#include "parRun.H"
#include "Time.H" #include "Time.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "fvc.H" #include "fvc.H"

View File

@ -194,9 +194,8 @@ int main(int argc, char *argv[])
); );
// Run controls // Run controls
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Test movement without a mesh" "Test movement without a mesh"
); );
argList::addBoolOption argList::addBoolOption
@ -232,7 +231,7 @@ int main(int argc, char *argv[])
// Control parameters // Control parameters
const bool dryrun = args.found("dry-run"); const bool dryrun = args.dryRun();
const bool slave = args.found("slave"); const bool slave = args.found("slave");
const bool removeLock = args.found("removeLock"); const bool removeLock = args.found("removeLock");

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -246,9 +246,8 @@ int main(int argc, char *argv[])
); );
// Run controls // Run controls
argList::addBoolOption argList::addDryRunOption
( (
"dry-run",
"Test movement without a mesh" "Test movement without a mesh"
); );
argList::addBoolOption argList::addBoolOption
@ -273,7 +272,7 @@ int main(int argc, char *argv[])
// Control parameters // Control parameters
const bool dryrun = args.found("dry-run"); const bool dryrun = args.dryRun();
const bool slave = args.found("slave"); const bool slave = args.found("slave");
const bool removeLock = args.found("removeLock"); const bool removeLock = args.found("removeLock");