ENH: improved argList handling of libs, functionObjects

- include -no-libs option by default, similar to '-lib',
  which makes it available to all solvers/utilities.
  Add argList allowLibs() method to query it.

- relocate with/no functionObjects logic from Time to argList
  itself as argList allowFunctionObjects()

- add libs/functionObjects override handling to decomposePar etc

ENH: report the stream relativeName for IOerrors (see c9333a5ac8)
This commit is contained in:
Mark Olesen 2022-09-22 10:17:11 +02:00
parent c031f7d00a
commit 88061f3b28
18 changed files with 73 additions and 37 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -46,8 +46,8 @@ int main(int argc, char *argv[])
profiling::disable(); // No profiling output
argList::noBanner();
argList::noParallel();
argList::noFunctionObjects();
argList::removeOption("case");
argList::removeOption("noFunctionObjects");
argList::addBoolOption("no-close", "Skip dlclose");
argList::addBoolOption("quiet", "Disable verbosity");

View File

@ -63,7 +63,6 @@ int main(int argc, char *argv[])
argList::addNote("Test timeSelector and TimePaths");
timeSelector::addOptions(true, true);
argList::noLibs();
argList::noFunctionObjects();
argList::addOption("relative", "PATH", "Test relativePath");

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -65,8 +65,8 @@ int main(int argc, char *argv[])
profiling::disable(); // No profiling output
argList::noBanner();
argList::noParallel();
argList::noFunctionObjects();
argList::removeOption("case");
argList::removeOption("noFunctionObjects");
argList::addBoolOption
(
"or",

View File

@ -1014,7 +1014,9 @@ int main(int argc, char *argv[])
Time::controlDictName,
args.rootPath(),
args.caseName()
/ ("processor" + Foam::name(proci))
/ ("processor" + Foam::name(proci)),
args.allowFunctionObjects(),
args.allowLibs()
)
);
}

View File

@ -244,7 +244,9 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
args.rootPath(),
args.caseName()/("processor" + Foam::name(proci))
args.caseName()/("processor" + Foam::name(proci)),
args.allowFunctionObjects(),
args.allowLibs()
)
);
}

View File

@ -731,7 +731,9 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
args.rootPath(),
args.caseName()/("processor" + Foam::name(proci))
args.caseName()/("processor" + Foam::name(proci)),
args.allowFunctionObjects(),
args.allowLibs()
)
);
}

View File

@ -168,7 +168,6 @@ int main(int argc, char *argv[])
// Less frequently used - reduce some clutter
argList::setAdvanced("decomposeParDict");
argList::setAdvanced("noFunctionObjects");
argList::addVerboseOption("Additional verbosity");

View File

@ -268,7 +268,6 @@ int main(int argc, char *argv[])
// Less frequently used - reduce some clutter
argList::setAdvanced("decomposeParDict");
argList::setAdvanced("noFunctionObjects");
argList::addVerboseOption("Additional verbosity");

View File

@ -87,7 +87,6 @@ int main(int argc, char *argv[])
// Less frequently used - reduce some clutter
argList::setAdvanced("decomposeParDict");
argList::setAdvanced("noFunctionObjects");
argList::addOption
(

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -100,7 +100,9 @@ int main(int argc, char *argv[])
(
Time::controlDictName,
args.rootPath(),
args.caseName()/("processor" + Foam::name(proci))
args.caseName()/("processor" + Foam::name(proci)),
args.allowFunctionObjects(),
args.allowLibs()
)
);
}

View File

@ -56,6 +56,7 @@ using namespace Foam;
int main(int argc, char *argv[])
{
// Normally without functionObjects, with -withFunctionObjects to enable
argList::noFunctionObjects(true);
// No -constant, no special treatment for 0/

View File

@ -494,6 +494,7 @@ void evaluate
int main(int argc, char *argv[])
{
// Normally without functionObjects, with -withFunctionObjects to enable
argList::noFunctionObjects(true);
// No -constant, no special treatment for 0/
@ -741,7 +742,7 @@ int main(int argc, char *argv[])
);
}
if (args.found("withFunctionObjects"))
if (args.allowFunctionObjects())
{
runTime.functionObjects().start();
}

View File

@ -120,7 +120,6 @@ int main(int argc, char *argv[])
// Less frequently used - reduce some clutter
argList::setAdvanced("decomposeParDict");
argList::setAdvanced("noFunctionObjects");
argList::addArgument("output", "The output surface file");

View File

@ -535,25 +535,15 @@ Foam::Time::Time
// * '-withFunctionObjects' exists and used = enable
// * '-noFunctionObjects' exists and used = disable
// * default: no functions if there is no way to enable/disable them
if
(
argList::validOptions.found("withFunctionObjects")
? args.found("withFunctionObjects")
: argList::validOptions.found("noFunctionObjects")
? !args.found("noFunctionObjects")
: false
)
if (enableFunctionObjects && args.allowFunctionObjects())
{
if (enableFunctionObjects)
{
functionObjects_.on();
}
functionObjects_.on();
}
// Libraries
//
// * enable by default unless '-no-libs' option was used
if (enableLibs && !args.found("no-libs"))
if (enableLibs && args.allowLibs())
{
libs_.open("libs", controlDict_);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -261,7 +261,7 @@ Foam::OSstream& Foam::messageStream::operator()
functionName,
sourceFileName,
sourceFileLineNumber,
ioStream.name(),
ioStream.relativeName(),
ioStream.lineNumber(),
-1 // No known endLineNumber
);

View File

@ -50,8 +50,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef messageStream_H
#define messageStream_H
#ifndef Foam_messageStream_H
#define Foam_messageStream_H
#include "label.H"
#include "string.H"

View File

@ -82,8 +82,14 @@ Foam::argList::initValidTables::initValidTables()
(
"lib",
"name",
"Additional library or library list to load"
" (can be used multiple times)",
"Additional library or library list to load."
" (Can be used multiple times)",
true // advanced option
);
argList::addBoolOption
(
"no-libs",
"Disable use of the controlDict 'libs' entry",
true // advanced option
);
@ -483,8 +489,8 @@ void Foam::argList::noFunctionObjects(bool addWithOption)
argList::addBoolOption
(
"withFunctionObjects",
"Execute functionObjects",
true // advanced option
"Execute functionObjects"
// An advanced option, but seldom used so expose it more
);
}
}
@ -1755,6 +1761,32 @@ Foam::argList::~argList()
}
// * * * * * * * * * * * * * * * Capabilities * * * * * * * * * * * * * * * //
bool Foam::argList::allowFunctionObjects() const
{
if (validOptions.found("withFunctionObjects"))
{
// '-withFunctionObjects' is available and explicitly enabled
return options_.found("withFunctionObjects");
}
else if (validOptions.found("noFunctionObjects"))
{
// '-noFunctionObjects' is available and not explicitly disabled
return !options_.found("noFunctionObjects");
}
// Disallow functions if there is no way to enable/disable them
return false;
}
bool Foam::argList::allowLibs() const
{
return !options_.found("no-libs");
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::argList::count(const UList<word>& optionNames) const

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -382,6 +382,15 @@ public:
//- Modify the verbose flag
inline int verbose(const int level) noexcept;
//- The controlDict 'functions' entry is allowed to be used.
// There must be a command-line option to enable/disable
// (-withFunctionObjects, -noFunctionObjects)
// and has not been explicitly disabled
bool allowFunctionObjects() const;
//- The controlDict 'libs' entry is allowed to be used.
//- (eg, has not been disabled by the -no-libs option)
bool allowLibs() const;
//- Mutable access to the loaded dynamic libraries
inline dlLibraryTable& libs() const noexcept;