mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
ENH: add flexible command options for setting Debug and Info switches #1467
For example, $ someSolver -info-switch writeOptionalEntries - note that values changed via the command-line are changed after the etc/controlDict entries, but *before* any case-local system/controlDict entries. However, in many testing cases the command-line options eliminate the need for such local file modifications. ENH: cleanup handling of local debug switches in Time - add as methods directly on simpleObjectRegistry to avoid code duplication STYLE: adjust internal naming of ITstream parameters
This commit is contained in:
committed by
Andrew Heather
parent
b0a999ca59
commit
da33222970
@ -3,7 +3,7 @@
|
||||
# ========= |
|
||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
# \\ / O peration |
|
||||
# \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
# \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
# \\/ M anipulation |
|
||||
#------------------------------------------------------------------------------
|
||||
# License
|
||||
@ -146,6 +146,7 @@ HEADER
|
||||
# -help-man Internal option
|
||||
# -hostRoots Advanced distributed run option
|
||||
# -roots Advanced distributed run option
|
||||
# -debug-switch, -opt-switch, -info-switch, -lib Advanced options
|
||||
#
|
||||
# Begin parsing after first appearance of "^[Oo]ptions:"
|
||||
# Terminate parsing on first appearance of "-help-full"
|
||||
@ -159,6 +160,8 @@ extractOptions()
|
||||
sed -ne '1,/^[Oo]ptions:/d' \
|
||||
-e 's/^ *//; /^$/d; /^[^-]/d; /^--/d; /^-help-man/d;' \
|
||||
-e '/^-hostRoots /d; /^-roots /d;' \
|
||||
-e '/^-lib /d;' \
|
||||
-e '/^-[a-z]*-switch /d;' \
|
||||
-e 'y/,/ /; s/=.*$/=/;' \
|
||||
-e '/^-[^ ]* </{ s/^\(-[^ ]* <\).*$/\1/; p; d }' \
|
||||
-e 's/^\(-[^ ]*\).*$/\1/; p; /^-help-full/q;' \
|
||||
|
||||
@ -7,6 +7,7 @@ global/clock/clock.C
|
||||
global/clockTime/clockTime.C
|
||||
global/clockValue/clockValue.C
|
||||
global/cpuTime/cpuTimeCxx.C
|
||||
global/debug/simpleObjectRegistry.C
|
||||
global/profiling/profiling.C
|
||||
global/profiling/profilingInformation.C
|
||||
global/profiling/profilingSysInfo.C
|
||||
|
||||
@ -149,11 +149,11 @@ public:
|
||||
|
||||
|
||||
//- Construct as copy
|
||||
ITstream(const ITstream& its)
|
||||
ITstream(const ITstream& is)
|
||||
:
|
||||
Istream(ASCII, currentVersion),
|
||||
tokenList(its),
|
||||
name_(its.name_),
|
||||
tokenList(is),
|
||||
name_(is.name_),
|
||||
tokenIndex_(0)
|
||||
{
|
||||
setOpened();
|
||||
|
||||
@ -87,7 +87,6 @@ int Foam::Time::printExecutionFormat_
|
||||
Foam::debug::infoSwitch("printExecutionFormat", 0)
|
||||
);
|
||||
|
||||
|
||||
registerInfoSwitch
|
||||
(
|
||||
"printExecutionFormat",
|
||||
|
||||
@ -109,39 +109,7 @@ void Foam::Time::readDict()
|
||||
<< "Overriding DebugSwitches according to "
|
||||
<< controlDict_.name() << nl;
|
||||
|
||||
simpleObjectRegistry& objs = debug::debugObjects();
|
||||
|
||||
for (const entry& dEntry : *localDict)
|
||||
{
|
||||
const word& name = dEntry.keyword();
|
||||
|
||||
simpleObjectRegistryEntry* objPtr = objs.lookupPtr(name);
|
||||
|
||||
if (objPtr)
|
||||
{
|
||||
const List<simpleRegIOobject*>& objects = *objPtr;
|
||||
|
||||
DetailInfo << " " << dEntry << nl;
|
||||
|
||||
if (dEntry.isDict())
|
||||
{
|
||||
for (simpleRegIOobject* obj : objects)
|
||||
{
|
||||
OStringStream os(IOstream::ASCII);
|
||||
os << dEntry.dict();
|
||||
IStringStream is(os.str());
|
||||
obj->readData(is);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (simpleRegIOobject* obj : objects)
|
||||
{
|
||||
obj->readData(dEntry.stream());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
debug::debugObjects().setValues(*localDict, true);
|
||||
}
|
||||
|
||||
|
||||
@ -156,39 +124,7 @@ void Foam::Time::readDict()
|
||||
<< "Overriding InfoSwitches according to "
|
||||
<< controlDict_.name() << nl;
|
||||
|
||||
simpleObjectRegistry& objs = debug::infoObjects();
|
||||
|
||||
for (const entry& dEntry : *localDict)
|
||||
{
|
||||
const word& name = dEntry.keyword();
|
||||
|
||||
simpleObjectRegistryEntry* objPtr = objs.lookupPtr(name);
|
||||
|
||||
if (objPtr)
|
||||
{
|
||||
const List<simpleRegIOobject*>& objects = *objPtr;
|
||||
|
||||
DetailInfo << " " << dEntry << nl;
|
||||
|
||||
if (dEntry.isDict())
|
||||
{
|
||||
for (simpleRegIOobject* obj : objects)
|
||||
{
|
||||
OStringStream os(IOstream::ASCII);
|
||||
os << dEntry.dict();
|
||||
IStringStream is(os.str());
|
||||
obj->readData(is);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (simpleRegIOobject* obj : objects)
|
||||
{
|
||||
obj->readData(dEntry.stream());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
debug::infoObjects().setValues(*localDict, true);
|
||||
}
|
||||
|
||||
// OptimisationSwitches
|
||||
@ -202,39 +138,7 @@ void Foam::Time::readDict()
|
||||
<< "Overriding OptimisationSwitches according to "
|
||||
<< controlDict_.name() << nl;
|
||||
|
||||
simpleObjectRegistry& objs = debug::optimisationObjects();
|
||||
|
||||
for (const entry& dEntry : *localDict)
|
||||
{
|
||||
const word& name = dEntry.keyword();
|
||||
|
||||
simpleObjectRegistryEntry* objPtr = objs.lookupPtr(name);
|
||||
|
||||
if (objPtr)
|
||||
{
|
||||
DetailInfo << " " << dEntry << nl;
|
||||
|
||||
const List<simpleRegIOobject*>& objects = *objPtr;
|
||||
|
||||
if (dEntry.isDict())
|
||||
{
|
||||
for (simpleRegIOobject* obj : objects)
|
||||
{
|
||||
OStringStream os(IOstream::ASCII);
|
||||
os << dEntry.dict();
|
||||
IStringStream is(os.str());
|
||||
obj->readData(is);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (simpleRegIOobject* obj : objects)
|
||||
{
|
||||
obj->readData(dEntry.stream());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
debug::optimisationObjects().setValues(*localDict, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ License
|
||||
#include "labelList.H"
|
||||
#include "regIOobject.H"
|
||||
#include "dynamicCode.H"
|
||||
#include "simpleObjectRegistry.H"
|
||||
#include "sigFpe.H"
|
||||
#include "sigInt.H"
|
||||
#include "sigQuit.H"
|
||||
@ -80,7 +81,38 @@ Foam::argList::initValidTables::initValidTables()
|
||||
(
|
||||
"lib",
|
||||
"name",
|
||||
"Additional library/libraries to load (can be used multiple times)",
|
||||
"Additional library or library list to load"
|
||||
" (can be used multiple times)",
|
||||
true // advanced option
|
||||
);
|
||||
|
||||
argList::addOption
|
||||
(
|
||||
"debug-switch",
|
||||
"name=val",
|
||||
"Specify the value of a registered debug switch."
|
||||
" Default is 1 if the value is omitted."
|
||||
" (Can be used multiple times)",
|
||||
true // advanced option
|
||||
);
|
||||
|
||||
argList::addOption
|
||||
(
|
||||
"info-switch",
|
||||
"name=val",
|
||||
"Specify the value of a registered info switch."
|
||||
" Default is 1 if the value is omitted."
|
||||
" (Can be used multiple times)",
|
||||
true // advanced option
|
||||
);
|
||||
|
||||
argList::addOption
|
||||
(
|
||||
"opt-switch",
|
||||
"name=val",
|
||||
"Specify the value of a registered optimisation switch (int/bool)."
|
||||
" Default is 1 if the value is omitted."
|
||||
" (Can be used multiple times)",
|
||||
true // advanced option
|
||||
);
|
||||
|
||||
@ -815,6 +847,30 @@ Foam::argList::argList
|
||||
// Append name(s) to libs_ for later opening
|
||||
libs_.append(this->getList<fileName>(argi));
|
||||
}
|
||||
else if (strcmp(optName, "debug-switch") == 0)
|
||||
{
|
||||
// The '-debug-switch' option:
|
||||
// change registered debug switch
|
||||
DetailInfo << "DebugSwitch ";
|
||||
debug::debugObjects()
|
||||
.setNamedInt(args_[argi], 1, true);
|
||||
}
|
||||
else if (strcmp(optName, "info-switch") == 0)
|
||||
{
|
||||
// The '-info-switch' option:
|
||||
// change registered info switch
|
||||
DetailInfo << "InfoSwitch ";
|
||||
debug::infoObjects()
|
||||
.setNamedInt(args_[argi], 1, true);
|
||||
}
|
||||
else if (strcmp(optName, "opt-switch") == 0)
|
||||
{
|
||||
// The '-opt-switch' option:
|
||||
// change registered optimisation switch
|
||||
DetailInfo << "OptimisationSwitch ";
|
||||
debug::optimisationObjects()
|
||||
.setNamedInt(args_[argi], 1, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Regular option:
|
||||
|
||||
@ -92,7 +92,7 @@ deleteControlDictPtr deleteControlDictPtr_;
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Like dictionary getOrAdd (default), but circumventing
|
||||
// Like dictionary getOrAdd with LITERAL, but circumventing
|
||||
// writeOptionalEntries to avoid extremely noisy output
|
||||
template<class T>
|
||||
static inline T getOrAdd
|
||||
@ -113,6 +113,26 @@ static inline T getOrAdd
|
||||
return deflt;
|
||||
}
|
||||
|
||||
|
||||
// Append object to a registry
|
||||
static inline void appendNamedEntry
|
||||
(
|
||||
simpleObjectRegistry& obr,
|
||||
const char* name,
|
||||
simpleRegIOobject* obj
|
||||
)
|
||||
{
|
||||
simpleObjectRegistryEntry* ptr = obr.lookupPtr(name);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->append(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
obr.append(name, new simpleObjectRegistryEntry(obj));
|
||||
}
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
@ -133,19 +153,19 @@ Foam::dictionary& Foam::debug::controlDict()
|
||||
{
|
||||
fileNameList controlDictFiles = findEtcFiles("controlDict", true);
|
||||
controlDictPtr_ = new dictionary();
|
||||
forAllReverse(controlDictFiles, cdfi)
|
||||
forAllReverse(controlDictFiles, i)
|
||||
{
|
||||
IFstream ifs(controlDictFiles[cdfi]);
|
||||
IFstream is(controlDictFiles[i]);
|
||||
|
||||
if (!ifs.good())
|
||||
if (!is.good())
|
||||
{
|
||||
SafeFatalIOErrorInFunction
|
||||
(
|
||||
ifs,
|
||||
is,
|
||||
"Cannot open controlDict"
|
||||
);
|
||||
}
|
||||
controlDictPtr_->merge(dictionary(ifs));
|
||||
controlDictPtr_->merge(dictionary(is));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,11 +238,7 @@ int Foam::debug::optimisationSwitch(const char* name, const int deflt)
|
||||
}
|
||||
|
||||
|
||||
float Foam::debug::floatOptimisationSwitch
|
||||
(
|
||||
const char* name,
|
||||
const float deflt
|
||||
)
|
||||
float Foam::debug::floatOptimisationSwitch(const char* name, const float deflt)
|
||||
{
|
||||
return getOrAdd(optimisationSwitches(), name, deflt);
|
||||
}
|
||||
@ -230,43 +246,13 @@ float Foam::debug::floatOptimisationSwitch
|
||||
|
||||
void Foam::debug::addDebugObject(const char* name, simpleRegIOobject* obj)
|
||||
{
|
||||
simpleObjectRegistryEntry* ptr = debugObjects().lookupPtr(name);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->append(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
debugObjects().append
|
||||
(
|
||||
name,
|
||||
new simpleObjectRegistryEntry
|
||||
(
|
||||
List<simpleRegIOobject*>(1, obj)
|
||||
)
|
||||
);
|
||||
}
|
||||
appendNamedEntry(debugObjects(), name, obj);
|
||||
}
|
||||
|
||||
|
||||
void Foam::debug::addInfoObject(const char* name, simpleRegIOobject* obj)
|
||||
{
|
||||
simpleObjectRegistryEntry* ptr = infoObjects().lookupPtr(name);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->append(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
infoObjects().append
|
||||
(
|
||||
name,
|
||||
new simpleObjectRegistryEntry
|
||||
(
|
||||
List<simpleRegIOobject*>(1, obj)
|
||||
)
|
||||
);
|
||||
}
|
||||
appendNamedEntry(infoObjects(), name, obj);
|
||||
}
|
||||
|
||||
|
||||
@ -276,22 +262,7 @@ void Foam::debug::addOptimisationObject
|
||||
simpleRegIOobject* obj
|
||||
)
|
||||
{
|
||||
simpleObjectRegistryEntry* ptr = optimisationObjects().lookupPtr(name);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->append(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
optimisationObjects().append
|
||||
(
|
||||
name,
|
||||
new simpleObjectRegistryEntry
|
||||
(
|
||||
List<simpleRegIOobject*>(1, obj)
|
||||
)
|
||||
);
|
||||
}
|
||||
appendNamedEntry(optimisationObjects(), name, obj);
|
||||
}
|
||||
|
||||
|
||||
@ -301,22 +272,7 @@ void Foam::debug::addDimensionSetObject
|
||||
simpleRegIOobject* obj
|
||||
)
|
||||
{
|
||||
simpleObjectRegistryEntry* ptr = dimensionSetObjects().lookupPtr(name);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->append(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
dimensionSetObjects().append
|
||||
(
|
||||
name,
|
||||
new simpleObjectRegistryEntry
|
||||
(
|
||||
List<simpleRegIOobject*>(1, obj)
|
||||
)
|
||||
);
|
||||
}
|
||||
appendNamedEntry(dimensionSetObjects(), name, obj);
|
||||
}
|
||||
|
||||
|
||||
@ -326,25 +282,7 @@ void Foam::debug::addDimensionedConstantObject
|
||||
simpleRegIOobject* obj
|
||||
)
|
||||
{
|
||||
simpleObjectRegistryEntry* ptr = dimensionedConstantObjects().lookupPtr
|
||||
(
|
||||
name
|
||||
);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->append(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
dimensionedConstantObjects().append
|
||||
(
|
||||
name,
|
||||
new simpleObjectRegistryEntry
|
||||
(
|
||||
List<simpleRegIOobject*>(1, obj)
|
||||
)
|
||||
);
|
||||
}
|
||||
appendNamedEntry(dimensionedConstantObjects(), name, obj);
|
||||
}
|
||||
|
||||
|
||||
@ -406,6 +344,10 @@ Foam::simpleObjectRegistry& Foam::debug::dimensionedConstantObjects()
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Write the switch names.
|
||||
//
|
||||
// Use flatOutput with -1 for the length to ensure we always have newlines,
|
||||
// even if the lists are short
|
||||
static void listSwitches
|
||||
(
|
||||
const wordList& debugSwitches,
|
||||
@ -418,48 +360,50 @@ static void listSwitches
|
||||
{
|
||||
fileNameList controlDictFiles = findEtcFiles("controlDict", true);
|
||||
dictionary controlDict;
|
||||
forAllReverse(controlDictFiles, cdfi)
|
||||
forAllReverse(controlDictFiles, i)
|
||||
{
|
||||
controlDict.merge(dictionary(IFstream(controlDictFiles[cdfi])()));
|
||||
IFstream is(controlDictFiles[i]);
|
||||
|
||||
controlDict.merge(dictionary(is));
|
||||
}
|
||||
|
||||
wordHashSet controlDictDebug
|
||||
(
|
||||
controlDict.subDict("DebugSwitches").toc()
|
||||
);
|
||||
|
||||
wordHashSet controlDictInfo
|
||||
(
|
||||
controlDict.subDict("InfoSwitches").toc()
|
||||
);
|
||||
|
||||
wordHashSet controlDictOpt
|
||||
(
|
||||
controlDict.subDict("OptimisationSwitches").toc()
|
||||
);
|
||||
|
||||
|
||||
IOobject::writeDivider(Info);
|
||||
|
||||
wordHashSet hashset;
|
||||
hashset = debugSwitches;
|
||||
hashset -= controlDictDebug;
|
||||
Info<< "Unset DebugSwitches" << hashset.sortedToc() << nl;
|
||||
// Use a HashSet to track switches that have not been set
|
||||
wordHashSet hashed;
|
||||
|
||||
hashset = infoSwitches;
|
||||
hashset -= controlDictInfo;
|
||||
Info<< "Unset InfoSwitches" << hashset.sortedToc() << nl;
|
||||
// DebugSwitches
|
||||
hashed = debugSwitches;
|
||||
hashed.unset(controlDict.subDict("DebugSwitches").toc());
|
||||
|
||||
hashset = optSwitches;
|
||||
hashset -= controlDictOpt;
|
||||
Info<< "Unset OptimisationSwitches" << hashset.sortedToc() << nl;
|
||||
Info<< "Unset DebugSwitches"
|
||||
<< flatOutput(hashed.sortedToc(), -1) << nl;
|
||||
|
||||
|
||||
// InfoSwitches
|
||||
hashed = infoSwitches;
|
||||
hashed.unset(controlDict.subDict("InfoSwitches").toc());
|
||||
|
||||
Info<< "Unset InfoSwitches"
|
||||
<< flatOutput(hashed.sortedToc(), -1) << nl;
|
||||
|
||||
|
||||
// OptimisationSwitches
|
||||
hashed = optSwitches;
|
||||
hashed.unset(controlDict.subDict("OptimisationSwitches").toc());
|
||||
|
||||
Info<< "Unset OptimisationSwitches"
|
||||
<< flatOutput(hashed.sortedToc(), -1) << nl;
|
||||
}
|
||||
else
|
||||
{
|
||||
IOobject::writeDivider(Info);
|
||||
Info<< "DebugSwitches" << debugSwitches << nl
|
||||
<< "InfoSwitches" << infoSwitches << nl
|
||||
<< "OptimisationSwitches" << optSwitches << nl;
|
||||
Info<< "DebugSwitches"
|
||||
<< flatOutput(debugSwitches, -1) << nl
|
||||
<< "InfoSwitches"
|
||||
<< flatOutput(infoSwitches, -1) << nl
|
||||
<< "OptimisationSwitches"
|
||||
<< flatOutput(optSwitches, -1) << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -68,13 +68,13 @@ namespace debug
|
||||
// \sa Foam::findEtcFile()
|
||||
dictionary& controlDict();
|
||||
|
||||
//- The DebugSwitches sub-dictionary in the central controlDict.
|
||||
//- The DebugSwitches sub-dictionary in the central controlDict(s).
|
||||
dictionary& debugSwitches();
|
||||
|
||||
//- The InfoSwitches sub-dictionary in the central controlDict.
|
||||
//- The InfoSwitches sub-dictionary in the central controlDict(s).
|
||||
dictionary& infoSwitches();
|
||||
|
||||
//- The OptimisationSwitches sub-dictionary in the central controlDict.
|
||||
//- The OptimisationSwitches sub-dictionary in the central controlDict(s).
|
||||
dictionary& optimisationSwitches();
|
||||
|
||||
//- Lookup debug switch or add default value.
|
||||
@ -114,22 +114,22 @@ namespace debug
|
||||
void addDimensionedConstantObject(const char* name, simpleRegIOobject*);
|
||||
|
||||
|
||||
//- Get access to registered debug switch objects
|
||||
//- Access to registered DebugSwitch objects
|
||||
simpleObjectRegistry& debugObjects();
|
||||
|
||||
//- Get access to registered info switch objects
|
||||
//- Access to registered InfoSwitch objects
|
||||
simpleObjectRegistry& infoObjects();
|
||||
|
||||
//- Get access to registered optimisation switch objects
|
||||
//- Access to registered OptimisationSwitch objects
|
||||
simpleObjectRegistry& optimisationObjects();
|
||||
|
||||
//- Get access to registered dimensionSets switch objects
|
||||
//- Access to registered DimensionSets objects
|
||||
simpleObjectRegistry& dimensionSetObjects();
|
||||
|
||||
//- Get access to registered dimensionedConstant switch objects
|
||||
//- Access to registered DimensionedConstants objects
|
||||
simpleObjectRegistry& dimensionedConstantObjects();
|
||||
|
||||
//- List registered debug switches
|
||||
//- List registered debug/info/optimisation switches
|
||||
void listRegisteredSwitches(const bool unset);
|
||||
|
||||
} // End namespace debug
|
||||
|
||||
@ -33,14 +33,14 @@ Description
|
||||
|
||||
#include "simpleRegIOobject.H"
|
||||
#include "debug.H"
|
||||
#include "label.H"
|
||||
#include "label.H" // Also for defining Foam::word etc.
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
//- Define the debug information, lookup as \a Name
|
||||
//- Define the debug information, lookup as \a name
|
||||
template<class Type>
|
||||
class RegisterDebugSwitch
|
||||
:
|
||||
@ -58,12 +58,12 @@ public:
|
||||
|
||||
virtual ~RegisterDebugSwitch() = default;
|
||||
|
||||
virtual void readData(Foam::Istream& is)
|
||||
virtual void readData(Istream& is)
|
||||
{
|
||||
Type::debug = readLabel(is);
|
||||
is >> Type::debug;
|
||||
}
|
||||
|
||||
virtual void writeData(Foam::Ostream& os) const
|
||||
virtual void writeData(Ostream& os) const
|
||||
{
|
||||
os << Type::debug;
|
||||
}
|
||||
@ -76,7 +76,7 @@ public:
|
||||
#define registerTemplateDebugSwitchWithName(Type,Name) \
|
||||
template<> \
|
||||
const Foam::RegisterDebugSwitch<Type> \
|
||||
Foam::RegisterDebugSwitch<Type>::registerDebugSwitch(Name)
|
||||
Foam::RegisterDebugSwitch<Type>::registerDebugSwitch(Name)
|
||||
|
||||
|
||||
//- Define the debug information, lookup as \a Name
|
||||
@ -88,15 +88,14 @@ public:
|
||||
public: \
|
||||
add##Tag##ToDebug(const char* name) \
|
||||
: \
|
||||
::Foam::simpleRegIOobject(Foam::debug::addDebugObject, name) \
|
||||
::Foam::simpleRegIOobject(::Foam::debug::addDebugObject, name) \
|
||||
{} \
|
||||
virtual ~add##Tag##ToDebug() \
|
||||
{} \
|
||||
virtual void readData(Foam::Istream& is) \
|
||||
virtual ~add##Tag##ToDebug() = default; \
|
||||
virtual void readData(::Foam::Istream& is) \
|
||||
{ \
|
||||
Type::debug = readLabel(is); \
|
||||
is >> Type::debug; \
|
||||
} \
|
||||
virtual void writeData(Foam::Ostream& os) const \
|
||||
virtual void writeData(::Foam::Ostream& os) const \
|
||||
{ \
|
||||
os << Type::debug; \
|
||||
} \
|
||||
@ -105,44 +104,44 @@ public:
|
||||
|
||||
|
||||
//- Define the debug information, lookup as \a Name
|
||||
#define defineDebugSwitchWithName(Type, Name, DebugSwitch) \
|
||||
int Type::debug(::Foam::debug::debugSwitch(Name, DebugSwitch))
|
||||
#define defineDebugSwitchWithName(Type, Name, Value) \
|
||||
int Type::debug(::Foam::debug::debugSwitch(Name, Value))
|
||||
|
||||
//- Define the debug information
|
||||
#define defineDebugSwitch(Type, DebugSwitch) \
|
||||
defineDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch); \
|
||||
#define defineDebugSwitch(Type, Value) \
|
||||
defineDebugSwitchWithName(Type, Type::typeName_(), Value); \
|
||||
registerDebugSwitchWithName(Type, Type, Type::typeName_())
|
||||
|
||||
//- Define the debug information for templates, lookup as \a Name
|
||||
#define defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch) \
|
||||
#define defineTemplateDebugSwitchWithName(Type, Name, Value) \
|
||||
template<> \
|
||||
defineDebugSwitchWithName(Type, Name, DebugSwitch); \
|
||||
defineDebugSwitchWithName(Type, Name, Value); \
|
||||
registerTemplateDebugSwitchWithName(Type, Name)
|
||||
|
||||
//- Define the debug information for templates sub-classes, lookup as \a Name
|
||||
#define defineTemplate2DebugSwitchWithName(Type, Name, DebugSwitch) \
|
||||
#define defineTemplate2DebugSwitchWithName(Type, Name, Value) \
|
||||
template<> \
|
||||
defineDebugSwitchWithName(Type, Name, DebugSwitch); \
|
||||
defineDebugSwitchWithName(Type, Name, Value); \
|
||||
registerTemplateDebugSwitchWithName(Type, Name)
|
||||
|
||||
//- Define the debug information for templates
|
||||
// Useful with typedefs
|
||||
#define defineTemplateDebugSwitch(Type, DebugSwitch) \
|
||||
defineTemplateDebugSwitchWithName(Type, #Type, DebugSwitch)
|
||||
#define defineTemplateDebugSwitch(Type, Value) \
|
||||
defineTemplateDebugSwitchWithName(Type, #Type, Value)
|
||||
|
||||
//- Define the debug information directly for templates
|
||||
#define defineNamedTemplateDebugSwitch(Type, DebugSwitch) \
|
||||
defineTemplateDebugSwitchWithName(Type, Type::typeName_(), DebugSwitch)
|
||||
#define defineNamedTemplateDebugSwitch(Type, Value) \
|
||||
defineTemplateDebugSwitchWithName(Type, Type::typeName_(), Value)
|
||||
|
||||
|
||||
//- Define the debug information for templates
|
||||
// Useful with typedefs
|
||||
#define defineTemplate2DebugSwitch(Type, DebugSwitch) \
|
||||
defineTemplate2DebugSwitchWithName(Type, #Type, DebugSwitch)
|
||||
#define defineTemplate2DebugSwitch(Type, Value) \
|
||||
defineTemplate2DebugSwitchWithName(Type, #Type, Value)
|
||||
|
||||
//- Define the debug information directly for templates
|
||||
#define defineNamedTemplate2DebugSwitch(Type, DebugSwitch) \
|
||||
defineTemplate2DebugSwitchWithName(Type, Type::typeName_(), DebugSwitch)
|
||||
#define defineNamedTemplate2DebugSwitch(Type, Value) \
|
||||
defineTemplate2DebugSwitchWithName(Type, Type::typeName_(), Value)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -52,31 +52,32 @@ class RegisterSwitch
|
||||
:
|
||||
public simpleRegIOobject
|
||||
{
|
||||
Type& optSwitch_;
|
||||
|
||||
public:
|
||||
|
||||
//- Reference to the switch variable that has been registered
|
||||
Type& value;
|
||||
|
||||
RegisterSwitch
|
||||
(
|
||||
void (*registryFn)(const char* name, simpleRegIOobject*),
|
||||
const char* name,
|
||||
Type& optSwitch
|
||||
Type& switchVar
|
||||
)
|
||||
:
|
||||
simpleRegIOobject(registryFn, name),
|
||||
optSwitch_(optSwitch)
|
||||
value(switchVar)
|
||||
{}
|
||||
|
||||
virtual ~RegisterSwitch() = default;
|
||||
|
||||
virtual void readData(Foam::Istream& is)
|
||||
virtual void readData(Istream& is)
|
||||
{
|
||||
is >> optSwitch_;
|
||||
is >> value;
|
||||
}
|
||||
|
||||
virtual void writeData(Foam::Ostream& os) const
|
||||
virtual void writeData(Ostream& os) const
|
||||
{
|
||||
os << optSwitch_;
|
||||
os << value;
|
||||
}
|
||||
};
|
||||
|
||||
@ -87,14 +88,14 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#define registerOptSwitch(Name, Type, Switch) \
|
||||
#define registerOptSwitch(Name, Type, SwitchVar) \
|
||||
static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
|
||||
(Foam::debug::addOptimisationObject, Name, Switch)
|
||||
(Foam::debug::addOptimisationObject, Name, SwitchVar)
|
||||
|
||||
|
||||
#define registerInfoSwitch(Name, Type, Switch) \
|
||||
#define registerInfoSwitch(Name, Type, SwitchVar) \
|
||||
static Foam::RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
|
||||
(Foam::debug::addInfoObject, Name, Switch)
|
||||
(Foam::debug::addInfoObject, Name, SwitchVar)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
144
src/OpenFOAM/global/debug/simpleObjectRegistry.C
Normal file
144
src/OpenFOAM/global/debug/simpleObjectRegistry.C
Normal file
@ -0,0 +1,144 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "simpleObjectRegistry.H"
|
||||
#include "dictionary.H"
|
||||
#include "StringStream.H"
|
||||
#include "int.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::simpleObjectRegistry::setValues
|
||||
(
|
||||
const dictionary& dict,
|
||||
bool report
|
||||
)
|
||||
{
|
||||
// Report enables output, but respect DetailInfo state as well.
|
||||
// The local log variable captures this logic.
|
||||
|
||||
const bool log = (report && Foam::infoDetailLevel > 0);
|
||||
|
||||
for (const entry& dEntry : dict)
|
||||
{
|
||||
const word& name = dEntry.keyword();
|
||||
|
||||
simpleObjectRegistryEntry* objPtr = this->lookupPtr(name);
|
||||
|
||||
if (objPtr)
|
||||
{
|
||||
Log << " " << dEntry << nl;
|
||||
|
||||
const List<simpleRegIOobject*>& objects = *objPtr;
|
||||
|
||||
if (dEntry.isDict())
|
||||
{
|
||||
OStringStream os(IOstream::ASCII);
|
||||
os << dEntry.dict();
|
||||
IStringStream is(os.str());
|
||||
|
||||
// Or alternatively?
|
||||
// ITstream is(name, dEntry.dict().tokens());
|
||||
|
||||
for (simpleRegIOobject* obj : objects)
|
||||
{
|
||||
is.rewind();
|
||||
obj->readData(is);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (simpleRegIOobject* obj : objects)
|
||||
{
|
||||
obj->readData(dEntry.stream());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log << " " << name << " (unregistered)" << nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::simpleObjectRegistry::setNamedInt
|
||||
(
|
||||
std::string name,
|
||||
int val,
|
||||
bool report
|
||||
)
|
||||
{
|
||||
// Report enables output, but respect DetailInfo state as well.
|
||||
// The local log variable captures this logic.
|
||||
|
||||
const bool log = (report && Foam::infoDetailLevel > 0);
|
||||
|
||||
|
||||
// Handle name=value
|
||||
const auto eq = name.find('=');
|
||||
|
||||
if (eq != std::string::npos)
|
||||
{
|
||||
int intval = 0;
|
||||
|
||||
if (readInt(name.substr(eq+1), intval))
|
||||
{
|
||||
val = intval;
|
||||
}
|
||||
// Could warn about bad entry
|
||||
|
||||
name.resize(eq); // Truncate the name
|
||||
}
|
||||
|
||||
|
||||
simpleObjectRegistryEntry* objPtr = this->lookupPtr(name.c_str());
|
||||
|
||||
if (objPtr)
|
||||
{
|
||||
// The generic interface requires an Istream.
|
||||
IStringStream is(std::to_string(val));
|
||||
|
||||
// Or alternatively?
|
||||
// ITstream is("input", tokenList(1, token(label(val))));
|
||||
|
||||
Log << name.c_str() << '=' << val << nl;
|
||||
|
||||
const List<simpleRegIOobject*>& objects = *objPtr;
|
||||
|
||||
for (simpleRegIOobject* obj : objects)
|
||||
{
|
||||
is.rewind();
|
||||
obj->readData(is);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log << name.c_str() << " (unregistered)" << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -30,6 +30,7 @@ Description
|
||||
Object registry for simpleRegIOobject. Maintains ordering.
|
||||
|
||||
SourceFiles
|
||||
simpleObjectRegistry.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -38,12 +39,16 @@ SourceFiles
|
||||
|
||||
#include "Dictionary.H"
|
||||
#include "simpleRegIOobject.H"
|
||||
#include <string>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
class dictionary;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class simpleObjectRegistryEntry Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -55,7 +60,14 @@ class simpleObjectRegistryEntry
|
||||
{
|
||||
public:
|
||||
|
||||
simpleObjectRegistryEntry(const List<simpleRegIOobject*>& data)
|
||||
//- Construct with a single object (list size == 1)
|
||||
explicit simpleObjectRegistryEntry(simpleRegIOobject* obj)
|
||||
:
|
||||
List<simpleRegIOobject*>(label(1), obj)
|
||||
{}
|
||||
|
||||
//- Construct with a List of objects
|
||||
explicit simpleObjectRegistryEntry(const List<simpleRegIOobject*>& data)
|
||||
:
|
||||
List<simpleRegIOobject*>(data)
|
||||
{}
|
||||
@ -79,6 +91,17 @@ public:
|
||||
:
|
||||
Dictionary<simpleObjectRegistryEntry>(size)
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Set values (invoke callbacks) from dictionary entries
|
||||
// Reporting honours the infoDetailLevel
|
||||
void setValues(const dictionary& dict, bool report=false);
|
||||
|
||||
//- Set named value, but also handle embedded name=value syntax
|
||||
// Reporting honours the infoDetailLevel
|
||||
void setNamedInt(std::string name, int val, bool report=false);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
// Forward declarations
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
@ -74,11 +74,10 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Read
|
||||
virtual void readData(Istream&) = 0;
|
||||
virtual void readData(Istream& is) = 0;
|
||||
|
||||
//- Write
|
||||
virtual void writeData(Ostream&) const = 0;
|
||||
|
||||
virtual void writeData(Ostream& os) const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
| Copyright (C) 2016 OpenFOAM Foundation
|
||||
|
||||
Reference in New Issue
Block a user