Skip to content
Snippets Groups Projects
Commit 0b7c2ee4 authored by Henry's avatar Henry
Browse files

registerSwitch: rationalization of info and optimization switch registration

plus support for other than integer types
parent 8e77fbc2
Branches
Tags
No related merge requests found
......@@ -25,7 +25,7 @@ License
#include "UPstream.H"
#include "debug.H"
#include "registerOptSwitch.H"
#include "registerSwitch.H"
#include "dictionary.H"
#include "IOstreams.H"
......@@ -424,32 +424,32 @@ Foam::UPstream::communicator serialComm
// in accuracy
bool Foam::UPstream::floatTransfer
(
debug::optimisationSwitch("floatTransfer", 0)
Foam::debug::optimisationSwitch("floatTransfer", 0)
);
registerOptSwitchWithName
registerOptSwitch
(
Foam::UPstream::floatTransfer,
floatTransfer,
"floatTransfer"
"floatTransfer",
bool,
Foam::UPstream::floatTransfer
);
// Number of processors at which the reduce algorithm changes from linear to
// tree
int Foam::UPstream::nProcsSimpleSum
(
debug::optimisationSwitch("nProcsSimpleSum", 16)
Foam::debug::optimisationSwitch("nProcsSimpleSum", 16)
);
registerOptSwitchWithName
registerOptSwitch
(
Foam::UPstream::nProcsSimpleSum,
nProcsSimpleSum,
"nProcsSimpleSum"
"nProcsSimpleSum",
int,
Foam::UPstream::nProcsSimpleSum
);
// Default commsType
Foam::UPstream::commsTypes Foam::UPstream::defaultCommsType
(
commsTypeNames.read(debug::optimisationSwitches().lookup("commsType"))
commsTypeNames.read(Foam::debug::optimisationSwitches().lookup("commsType"))
);
// Register re-reader
class addcommsTypeToOpt
......@@ -489,13 +489,14 @@ Foam::label Foam::UPstream::warnComm(-1);
// Number of polling cycles in processor updates
int Foam::UPstream::nPollProcInterfaces
(
debug::optimisationSwitch("nPollProcInterfaces", 0)
Foam::debug::optimisationSwitch("nPollProcInterfaces", 0)
);
registerOptSwitchWithName
registerOptSwitch
(
Foam::UPstream::nPollProcInterfaces,
nPollProcInterfaces,
"nPollProcInterfaces"
"nPollProcInterfaces",
int,
Foam::UPstream::nPollProcInterfaces
);
// ************************************************************************* //
......@@ -26,7 +26,7 @@ License
#include "regIOobject.H"
#include "Time.H"
#include "polyMesh.H"
#include "registerOptSwitch.H"
#include "registerSwitch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -34,18 +34,6 @@ namespace Foam
{
defineTypeNameAndDebug(regIOobject, 0);
int regIOobject::fileModificationSkew
(
debug::optimisationSwitch("fileModificationSkew", 30)
);
registerOptSwitchWithName
(
Foam::regIOobject::fileModificationSkew,
fileModificationSkew,
"fileModificationSkew"
);
template<>
const char* NamedEnum
<
......@@ -60,6 +48,17 @@ namespace Foam
};
}
int Foam::regIOobject::fileModificationSkew
(
Foam::debug::optimisationSwitch("fileModificationSkew", 30)
);
registerOptSwitch
(
"fileModificationSkew",
int,
Foam::regIOobject::fileModificationSkew
);
const Foam::NamedEnum<Foam::regIOobject::fileCheckTypes, 4>
Foam::regIOobject::fileCheckTypesNames;
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
\\/ 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/>.
Description
Macro definitions for optimization switches.
\*---------------------------------------------------------------------------*/
#ifndef registerOptSwitch_H
#define registerOptSwitch_H
#include "simpleRegIOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Register optimisation switch (if int), lookup as \a Name
#define registerOptSwitchWithName(Switch,Tag,Name) \
class add##Tag##ToOpt \
: \
public ::Foam::simpleRegIOobject \
{ \
public: \
add##Tag##ToOpt(const char* name) \
: \
::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject,name)\
{} \
virtual ~add##Tag##ToOpt() \
{} \
virtual void readData(Foam::Istream& is) \
{ \
Switch = readLabel(is); \
} \
virtual void writeData(Foam::Ostream& os) const \
{ \
os << Switch; \
} \
}; \
add##Tag##ToOpt add##Tag##ToOpt_(Name)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -22,40 +22,65 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Macro definitions for info switches.
Class and registration macros for InfoSwitches and OptimisationSwitches
to support reading from system/controlDict and dynamic update.
\*---------------------------------------------------------------------------*/
#ifndef registerInfoSwitch_H
#define registerInfoSwitch_H
#ifndef registerSwitch_H
#define registerSwitch_H
#include "simpleRegIOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Register info switch (if int), lookup as \a Name
#define registerInfoSwitchWithName(Switch,Tag,Name) \
class add##Tag##ToInfo \
: \
public ::Foam::simpleRegIOobject \
{ \
public: \
add##Tag##ToInfo(const char* name) \
: \
::Foam::simpleRegIOobject(Foam::debug::addInfoObject, name) \
{} \
virtual ~add##Tag##ToInfo() \
{} \
virtual void readData(Foam::Istream& is) \
{ \
Switch = readLabel(is); \
} \
virtual void writeData(Foam::Ostream& os) const \
{ \
os << Switch; \
} \
}; \
add##Tag##ToInfo add##Tag##ToInfo_(Name)
template<class Type>
class RegisterSwitch
:
public ::Foam::simpleRegIOobject
{
Type& optSwitch_;
public:
RegisterSwitch
(
void (*registryFn)(const char* name, simpleRegIOobject*),
const char* name,
Type& optSwitch
)
:
::Foam::simpleRegIOobject(registryFn, name),
optSwitch_(optSwitch)
{}
virtual ~RegisterSwitch()
{}
virtual void readData(Foam::Istream& is)
{
is >> optSwitch_;
}
virtual void writeData(Foam::Ostream& os) const
{
os << optSwitch_;
}
};
#define CONCAT(x, y) x ## y
#define CONCAT2(x, y) CONCAT(x, y)
#define FILE_UNIQUE(x) CONCAT2(x, __LINE__)
#define registerOptSwitch(Name, Type, Switch) \
static RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
(Foam::debug::addOptimisationObject, Name, Switch)
#define registerInfoSwitch(Name, Type, Switch) \
static RegisterSwitch<Type> FILE_UNIQUE(_addToOpt_) \
(Foam::debug::addInfoObject, Name, Switch)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment