messageStream: Removed unused code and corrected communicator handling

This commit is contained in:
Will Bainbridge
2021-08-12 09:40:55 +01:00
parent 9eec6c6be0
commit 4398f57c5e
9 changed files with 62 additions and 150 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -41,15 +41,6 @@ Foam::IOerror::IOerror(const string& title)
{} {}
Foam::IOerror::IOerror(const dictionary& errDict)
:
error(errDict),
ioFileName_(errDict.lookup("ioFileName")),
ioStartLineNumber_(errDict.lookup<label>("ioStartLineNumber")),
ioEndLineNumber_(errDict.lookup<label>("ioEndLineNumber"))
{}
Foam::IOerror::~IOerror() throw() Foam::IOerror::~IOerror() throw()
{} {}
@ -65,6 +56,7 @@ Foam::OSstream& Foam::IOerror::operator()
) )
{ {
error::operator()(functionName, sourceFileName, sourceFileLineNumber); error::operator()(functionName, sourceFileName, sourceFileLineNumber);
ioFileName_ = ioFileName; ioFileName_ = ioFileName;
ioStartLineNumber_ = ioStartLineNumber; ioStartLineNumber_ = ioStartLineNumber;
ioEndLineNumber_ = ioEndLineNumber; ioEndLineNumber_ = ioEndLineNumber;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -54,43 +54,6 @@ Foam::error::error(const string& title)
} }
Foam::error::error(const dictionary& errDict)
:
std::exception(),
messageStream(errDict),
functionName_(errDict.lookup("functionName")),
sourceFileName_(errDict.lookup("sourceFileName")),
sourceFileLineNumber_(errDict.lookup<label>("sourceFileLineNumber")),
abort_(env("FOAM_ABORT")),
throwExceptions_(false),
messageStreamPtr_(new OStringStream())
{
if (!messageStreamPtr_->good())
{
Perr<< endl
<< "error::error(const dictionary& errDict) : "
"cannot open error stream"
<< endl;
exit(1);
}
}
Foam::error::error(const error& err)
:
std::exception(),
messageStream(err),
functionName_(err.functionName_),
sourceFileName_(err.sourceFileName_),
sourceFileLineNumber_(err.sourceFileLineNumber_),
abort_(err.abort_),
throwExceptions_(err.throwExceptions_),
messageStreamPtr_(new OStringStream(*err.messageStreamPtr_))
{
//*messageStreamPtr_ << err.message();
}
Foam::error::~error() throw() Foam::error::~error() throw()
{ {
delete messageStreamPtr_; delete messageStreamPtr_;
@ -128,7 +91,7 @@ Foam::OSstream& Foam::error::operator()
} }
Foam::error::operator Foam::OSstream&() Foam::OSstream& Foam::error::operator()()
{ {
if (!messageStreamPtr_->good()) if (!messageStreamPtr_->good())
{ {

View File

@ -90,12 +90,6 @@ public:
//- Construct from title string //- Construct from title string
error(const string& title); error(const string& title);
//- Construct from dictionary
error(const dictionary&);
//- Copy constructor
error(const error&);
//- Destructor //- Destructor
virtual ~error() throw(); virtual ~error() throw();
@ -148,20 +142,18 @@ public:
const int sourceFileLineNumber = 0 const int sourceFileLineNumber = 0
); );
//- Convert to OSstream
// Prints basic message and returns OSstream for further info.
operator OSstream&();
//- Explicitly convert to OSstream for << operations //- Explicitly convert to OSstream for << operations
OSstream& operator()() OSstream& operator()();
//- Convert to OSstream for << operations
operator OSstream&()
{ {
return operator OSstream&(); return this->operator()();
} }
//- Create and return a dictionary //- Create and return a dictionary
operator dictionary() const; operator dictionary() const;
//- Helper function to print a stack (if OpenFOAM IO not yet //- Helper function to print a stack (if OpenFOAM IO not yet
// initialised) // initialised)
static void safePrintStack(std::ostream&); static void safePrintStack(std::ostream&);
@ -212,9 +204,6 @@ public:
//- Construct from title string //- Construct from title string
IOerror(const string& title); IOerror(const string& title);
//- Construct from dictionary
IOerror(const dictionary&);
//- Destructor //- Destructor
virtual ~IOerror() throw(); virtual ~IOerror() throw();
@ -283,7 +272,6 @@ public:
//- Create and return a dictionary //- Create and return a dictionary
operator dictionary() const; operator dictionary() const;
//- Exit : can be called for any error to exit program //- Exit : can be called for any error to exit program
void exit(const int errNo = 1); void exit(const int errNo = 1);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -36,7 +36,7 @@ int Foam::messageStream::level(Foam::debug::debugSwitch("level", 2));
Foam::messageStream::messageStream Foam::messageStream::messageStream
( (
const string& title, const string& title,
errorSeverity sev, const errorSeverity sev,
const int maxErrors const int maxErrors
) )
: :
@ -47,35 +47,6 @@ Foam::messageStream::messageStream
{} {}
Foam::messageStream::messageStream(const dictionary& dict)
:
title_(dict.lookup("title")),
severity_(FATAL),
maxErrors_(0),
errorCount_(0)
{}
Foam::OSstream& Foam::messageStream::masterStream(const label communicator)
{
if (UPstream::warnComm != -1 && communicator != UPstream::warnComm)
{
Pout<< "** messageStream with comm:" << communicator
<< endl;
error::printStack(Pout);
}
if (communicator == UPstream::worldComm || UPstream::master(communicator))
{
return operator()();
}
else
{
return Snull;
}
}
Foam::OSstream& Foam::messageStream::operator() Foam::OSstream& Foam::messageStream::operator()
( (
const char* functionName, const char* functionName,
@ -185,14 +156,35 @@ Foam::OSstream& Foam::messageStream::operator()
} }
Foam::messageStream::operator Foam::OSstream&() Foam::OSstream& Foam::messageStream::operator()(label communicator)
{ {
if (communicator != -1)
{
if (UPstream::warnComm != -1 && communicator != UPstream::warnComm)
{
Pout<< "** messageStream with comm:" << communicator
<< endl;
error::printStack(Pout);
}
}
else
{
communicator = UPstream::worldComm;
}
if (level) if (level)
{ {
bool collect = (severity_ == INFO || severity_ == WARNING); const bool master = Pstream::master(communicator);
// Report the error const bool collect = severity_ == INFO || severity_ == WARNING;
if (!Pstream::master() && collect)
const bool prefix =
(Pstream::parRun() && !collect)
|| communicator != UPstream::worldComm;
OSstream& os = prefix ? Pout : Sout;
if (!master && collect)
{ {
return Snull; return Snull;
} }
@ -200,14 +192,7 @@ Foam::messageStream::operator Foam::OSstream&()
{ {
if (title().size()) if (title().size())
{ {
if (Pstream::parRun() && !collect) os << title().c_str();
{
Pout<< title().c_str();
}
else
{
Sout<< title().c_str();
}
} }
if (maxErrors_) if (maxErrors_)
@ -222,14 +207,7 @@ Foam::messageStream::operator Foam::OSstream&()
} }
} }
if (Pstream::parRun() && !collect) return os;
{
return Pout;
}
else
{
return Sout;
}
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -104,15 +104,11 @@ public:
messageStream messageStream
( (
const string& title, const string& title,
errorSeverity, const errorSeverity,
const int maxErrors = 0 const int maxErrors = 0
); );
//- Construct from dictionary
messageStream(const dictionary&);
// Member Functions // Member Functions
//- Return the title of this error type //- Return the title of this error type
@ -134,11 +130,6 @@ public:
return maxErrors_; return maxErrors_;
} }
//- Convert to OSstream
// Prints to Pout for the master stream
OSstream& masterStream(const label communicator);
//- Convert to OSstream //- Convert to OSstream
// Prints basic message and returns OSstream for further info. // Prints basic message and returns OSstream for further info.
OSstream& operator() OSstream& operator()
@ -189,13 +180,13 @@ public:
const dictionary& const dictionary&
); );
//- Convert to OSstream for << operations
operator OSstream&();
//- Explicitly convert to OSstream for << operations //- Explicitly convert to OSstream for << operations
OSstream& operator()() OSstream& operator()(const label communicator = -1);
//- Convert to OSstream for << operations
operator OSstream&()
{ {
return operator OSstream&(); return this->operator()();
} }
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -131,7 +131,7 @@ Foam::solverPerformance Foam::GAMGSolver::solve
if (debug >= 2) if (debug >= 2)
{ {
solverPerf.print(Info.masterStream(matrix().mesh().comm())); solverPerf.print(Info(matrix().mesh().comm()));
} }
} while } while
( (
@ -654,7 +654,7 @@ void Foam::GAMGSolver::solveCoarsestLevel
// //
// if (debug >= 2) // if (debug >= 2)
// { // {
// coarseSolverPerf.print(Info.masterStream(coarseComm)); // coarseSolverPerf.print(Info(coarseComm));
// } // }
// //
// Pout<< "procAgglom: coarsestSource :" << coarsestSource << endl; // Pout<< "procAgglom: coarsestSource :" << coarsestSource << endl;
@ -700,7 +700,7 @@ void Foam::GAMGSolver::solveCoarsestLevel
if (debug >= 2) if (debug >= 2)
{ {
coarseSolverPerf.print(Info.masterStream(coarseComm)); coarseSolverPerf.print(Info(coarseComm));
} }
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -132,7 +132,7 @@ Foam::solverPerformance Foam::smoothSolver::solve
if (lduMatrix::debug >= 2) if (lduMatrix::debug >= 2)
{ {
Info.masterStream(matrix().mesh().comm()) Info(matrix().mesh().comm())
<< " Normalisation factor = " << normFactor << endl; << " Normalisation factor = " << normFactor << endl;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -61,7 +61,7 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solve
{ {
if (debug) if (debug)
{ {
Info.masterStream(this->mesh().comm()) Info(this->mesh().comm())
<< "fvMatrix<Type>::solve(const dictionary& solverControls) : " << "fvMatrix<Type>::solve(const dictionary& solverControls) : "
"solving fvMatrix<Type>" "solving fvMatrix<Type>"
<< endl; << endl;
@ -108,7 +108,7 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solveSegregated
{ {
if (debug) if (debug)
{ {
Info.masterStream(this->mesh().comm()) Info(this->mesh().comm())
<< "fvMatrix<Type>::solveSegregated" << "fvMatrix<Type>::solveSegregated"
"(const dictionary& solverControls) : " "(const dictionary& solverControls) : "
"solving fvMatrix<Type>" "solving fvMatrix<Type>"
@ -198,7 +198,7 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solveSegregated
if (SolverPerformance<Type>::debug) if (SolverPerformance<Type>::debug)
{ {
solverPerf.print(Info.masterStream(this->mesh().comm())); solverPerf.print(Info(this->mesh().comm()));
} }
solverPerfVec.replace(cmpt, solverPerf); solverPerfVec.replace(cmpt, solverPerf);
@ -224,7 +224,7 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solveCoupled
{ {
if (debug) if (debug)
{ {
Info.masterStream(this->mesh().comm()) Info(this->mesh().comm())
<< "fvMatrix<Type>::solveCoupled" << "fvMatrix<Type>::solveCoupled"
"(const dictionary& solverControls) : " "(const dictionary& solverControls) : "
"solving fvMatrix<Type>" "solving fvMatrix<Type>"
@ -265,7 +265,7 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solveCoupled
if (SolverPerformance<Type>::debug) if (SolverPerformance<Type>::debug)
{ {
solverPerf.print(Info.masterStream(this->mesh().comm())); solverPerf.print(Info(this->mesh().comm()));
} }
psi.correctBoundaryConditions(); psi.correctBoundaryConditions();

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -62,7 +62,7 @@ Foam::fvMatrix<Foam::scalar>::solver
{ {
if (debug) if (debug)
{ {
Info.masterStream(this->mesh().comm()) Info(this->mesh().comm())
<< "fvMatrix<scalar>::solver(const dictionary& solverControls) : " << "fvMatrix<scalar>::solver(const dictionary& solverControls) : "
"solver for fvMatrix<scalar>" "solver for fvMatrix<scalar>"
<< endl; << endl;
@ -121,7 +121,7 @@ Foam::solverPerformance Foam::fvMatrix<Foam::scalar>::fvSolver::solve
if (solverPerformance::debug) if (solverPerformance::debug)
{ {
solverPerf.print(Info.masterStream(fvMat_.mesh().comm())); solverPerf.print(Info(fvMat_.mesh().comm()));
} }
fvMat_.diag() = saveDiag; fvMat_.diag() = saveDiag;
@ -142,7 +142,7 @@ Foam::solverPerformance Foam::fvMatrix<Foam::scalar>::solveSegregated
{ {
if (debug) if (debug)
{ {
Info.masterStream(this->mesh().comm()) Info(this->mesh().comm())
<< "fvMatrix<scalar>::solveSegregated" << "fvMatrix<scalar>::solveSegregated"
"(const dictionary& solverControls) : " "(const dictionary& solverControls) : "
"solving fvMatrix<scalar>" "solving fvMatrix<scalar>"
@ -171,7 +171,7 @@ Foam::solverPerformance Foam::fvMatrix<Foam::scalar>::solveSegregated
if (solverPerformance::debug) if (solverPerformance::debug)
{ {
solverPerf.print(Info.masterStream(mesh().comm())); solverPerf.print(Info(mesh().comm()));
} }
diag() = saveDiag; diag() = saveDiag;