Skip to content
Snippets Groups Projects
Commit 4f4ed087 authored by mattijs's avatar mattijs
Browse files

ENH: debug: added more to run-time reading

parent 59c1c382
Branches
Tags
No related merge requests found
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -31,11 +31,41 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// Signal number to catch
int Foam::sigStopAtWriteNow::signal_
int sigStopAtWriteNow::signal_
(
debug::optimisationSwitch("stopAtWriteNowSignal", -1)
);
// Register re-reader
class addstopAtWriteNowSignalToOpt
:
public ::Foam::simpleRegIOobject
{
public:
addstopAtWriteNowSignalToOpt(const char* name)
:
::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
{}
virtual ~addstopAtWriteNowSignalToOpt()
{}
virtual void readData(Foam::Istream& is)
{
sigStopAtWriteNow::signal_ = readLabel(is);
sigStopAtWriteNow::set(true);
}
virtual void writeData(Foam::Ostream& os) const
{
os << sigStopAtWriteNow::signal_;
}
};
addstopAtWriteNowSignalToOpt addstopAtWriteNowSignalToOpt_
(
"stopAtWriteNowSignal"
);
}
static Foam::Time const* runTimePtr_ = NULL;
......@@ -80,6 +110,36 @@ Foam::sigStopAtWriteNow::sigStopAtWriteNow
const bool verbose,
const Time& runTime
)
{
// Store runTime
runTimePtr_ = &runTime;
set(verbose);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::sigStopAtWriteNow::~sigStopAtWriteNow()
{
// Reset old handling
if (signal_ > 0)
{
if (sigaction(signal_, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigStopAtWriteNow::~sigStopAtWriteNow()"
) << "Cannot reset " << signal_ << " trapping"
<< abort(FatalError);
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigStopAtWriteNow::set(const bool verbose)
{
if (signal_ > 0)
{
......@@ -98,9 +158,6 @@ Foam::sigStopAtWriteNow::sigStopAtWriteNow
}
// Store runTime
runTimePtr_ = &runTime;
struct sigaction newAction;
newAction.sa_handler = sigHandler;
newAction.sa_flags = SA_NODEFER;
......@@ -125,27 +182,6 @@ Foam::sigStopAtWriteNow::sigStopAtWriteNow
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::sigStopAtWriteNow::~sigStopAtWriteNow()
{
// Reset old handling
if (signal_ > 0)
{
if (sigaction(signal_, &oldAction_, NULL) < 0)
{
FatalErrorIn
(
"Foam::sigStopAtWriteNow::~sigStopAtWriteNow()"
) << "Cannot reset " << signal_ << " trapping"
<< abort(FatalError);
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::sigStopAtWriteNow::active() const
{
return signal_ > 0;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -68,6 +68,9 @@ class sigStopAtWriteNow
public:
//- wip. Have setter have access to signal_
friend class addstopAtWriteNowSignalToOpt;
// Constructors
//- Construct null
......@@ -83,6 +86,9 @@ public:
// Member functions
//- (re)set signal catcher
static void set(const bool verbose);
//- Is active?
bool active() const;
};
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -31,11 +31,39 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// Signal number to catch
int Foam::sigWriteNow::signal_
int sigWriteNow::signal_
(
debug::optimisationSwitch("writeNowSignal", -1)
);
// Register re-reader
class addwriteNowSignalToOpt
:
public ::Foam::simpleRegIOobject
{
public:
addwriteNowSignalToOpt(const char* name)
:
::Foam::simpleRegIOobject(Foam::debug::addOptimisationObject, name)
{}
virtual ~addwriteNowSignalToOpt()
{}
virtual void readData(Foam::Istream& is)
{
sigWriteNow::signal_ = readLabel(is);
sigWriteNow::set(true);
}
virtual void writeData(Foam::Ostream& os) const
{
os << sigWriteNow::signal_;
}
};
addwriteNowSignalToOpt addwriteNowSignalToOpt_("writeNowSignal");
}
static Foam::Time* runTimePtr_ = NULL;
......@@ -64,31 +92,10 @@ Foam::sigWriteNow::sigWriteNow()
Foam::sigWriteNow::sigWriteNow(const bool verbose, Time& runTime)
{
if (signal_ >= 0)
{
// Store runTime
runTimePtr_ = &runTime;
// Store runTime
runTimePtr_ = &runTime;
struct sigaction newAction;
newAction.sa_handler = sigHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(signal_, &newAction, &oldAction_) < 0)
{
FatalErrorIn
(
"Foam::sigWriteNow::sigWriteNow(const bool, const Time&)"
) << "Cannot set " << signal_ << " trapping"
<< abort(FatalError);
}
if (verbose)
{
Info<< "sigWriteNow :"
<< " Enabling writing upon signal " << signal_
<< endl;
}
}
set(verbose);
}
......@@ -113,6 +120,33 @@ Foam::sigWriteNow::~sigWriteNow()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigWriteNow::set(const bool verbose)
{
if (signal_ >= 0)
{
struct sigaction newAction;
newAction.sa_handler = sigHandler;
newAction.sa_flags = SA_NODEFER;
sigemptyset(&newAction.sa_mask);
if (sigaction(signal_, &newAction, &oldAction_) < 0)
{
FatalErrorIn
(
"Foam::sigWriteNow::sigWriteNow(const bool, const Time&)"
) << "Cannot set " << signal_ << " trapping"
<< abort(FatalError);
}
if (verbose)
{
Info<< "sigWriteNow :"
<< " Enabling writing upon signal " << signal_
<< endl;
}
}
}
bool Foam::sigWriteNow::active() const
{
return signal_ > 0;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -69,6 +69,9 @@ public:
friend class sigStopAtWriteNow;
//- wip. Have setter have access to signal_
friend class addwriteNowSignalToOpt;
// Constructors
//- Construct null
......@@ -84,6 +87,9 @@ public:
// Member functions
//- (re)set signal catcher
static void set(const bool verbose);
//- Is active?
bool active() const;
......
......@@ -40,6 +40,9 @@ void Foam::Time::readDict()
// Check for local switches and settings
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Debug switches
if (controlDict_.found("DebugSwitches"))
{
simpleObjectRegistry& objects = debug::debugObjects();
......@@ -50,8 +53,8 @@ void Foam::Time::readDict()
simpleObjectRegistry::iterator fnd = objects.find(name);
if (fnd != objects.end())
{
Info<< controlDict_.name() << " : overriding debug switch "
<< name << " to " << fnd() << endl;
Info<< controlDict_.name() << " : overriding debug switch : "
<< iter() << endl;
if (iter().isDict())
{
......@@ -67,6 +70,8 @@ void Foam::Time::readDict()
}
}
}
// Dimension sets
if (controlDict_.found("DimensionSets"))
{
dictionary dict(Foam::dimensionSystems());
......@@ -84,6 +89,8 @@ void Foam::Time::readDict()
fnd()->readData(is);
}
}
// Optimisation Switches
if (controlDict_.found("OptimisationSwitches"))
{
simpleObjectRegistry& objects = debug::optimisationObjects();
......@@ -98,8 +105,7 @@ void Foam::Time::readDict()
if (fnd != objects.end())
{
Info<< controlDict_.name()
<< " : overriding optimisation switch "
<< name << " to " << fnd() << endl;
<< " : overriding optimisation switch : " << iter() << endl;
if (iter().isDict())
{
......
......@@ -89,6 +89,7 @@ Description
}; \
add##Tag##ToInfo add##Tag##ToInfo_(Name)
//- Register optimisation switch (if int), lookup as \a Name
#define registerOptSwitchWithName(Switch,Tag,Name) \
class add##Tag##ToOpt \
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -174,8 +174,6 @@ public:
private:
TypeName("refinementHistory");
// Private data
//- Storage for splitCells
......@@ -230,6 +228,10 @@ private:
public:
// Declare name of the class and its debug switch
TypeName("refinementHistory");
// Constructors
//- Construct (read) given an IOobject
......
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