1414#include < Core/Math/ILapack.h> // needed for solution of linear system with Lapack
1515#include < Core/Math/Constants.h> // definitializeion of constants like uround
1616
17+ #ifdef USE_LOGGER
18+ #define LOG_VEC (algLoop, name, vec, lc, ll ) LogVec(algLoop, name, vec, lc, ll)
19+ #else
20+ #define LOG_VEC (algLoop, name, vec, lc, ll )
21+ #endif
22+
1723template <typename S, typename T>
18- static inline void LogSysVec (IAlgLoop* algLoop, S name, T vec[]) {
19- if (Logger::getInstance ()->isOutput (LC_NLS, LL_DEBUG)) {
24+ static inline void LogVec (IAlgLoop* algLoop, S name, T vec[],
25+ LogCategory lc, LogLevel ll) {
26+ if (LOGGER_IS_SET (lc, ll)) {
2027 std::stringstream ss;
21- ss << " Newton: eq" << to_string (algLoop->getEquationIndex ());
22- ss << " , time " << algLoop->getSimTime () << " : " << name << " = {" ;
28+ ss << name << " = {" ;
2329 for (int i = 0 ; i < algLoop->getDimReal (); i++)
2430 ss << (i > 0 ? " , " : " " ) << vec[i];
2531 ss << " }" ;
26- Logger::write (ss.str (), LC_NLS, LL_DEBUG );
32+ LOGGER_WRITE (ss.str (), lc, ll );
2733 }
2834}
2935
@@ -46,6 +52,7 @@ Newton::Newton(IAlgLoop* algLoop, INonLinSolverSettings* settings)
4652 , _dimSys (0 )
4753 , _firstCall (true )
4854 , _iterationStatus (CONTINUE)
55+ , _lc (algLoop->isLinear ()? LC_LS: LC_NLS)
4956{
5057}
5158
@@ -123,11 +130,10 @@ void Newton::initialize()
123130 _iterationStatus = SOLVERERROR;
124131 }
125132 }
126- if (Logger::getInstance ()->isOutput (LC_NLS, LL_DEBUG)) {
127- Logger::write (" Newton: eq" + to_string (_algLoop->getEquationIndex ())
128- + " initialized" , LC_NLS, LL_DEBUG);
129- LogSysVec (_algLoop, " names" , _yNames);
130- }
133+ LOGGER_WRITE_BEGIN (" Newton: eq" + to_string (_algLoop->getEquationIndex ()) +
134+ " initialized" , _lc, LL_DEBUG);
135+ LOG_VEC (_algLoop, " names" , _yNames, _lc, LL_DEBUG);
136+ LOGGER_WRITE_END (_lc, LL_DEBUG);
131137}
132138
133139void Newton::solve ()
@@ -153,6 +159,10 @@ void Newton::solve()
153159 // Reset status flag
154160 _iterationStatus = CONTINUE;
155161
162+ LOGGER_WRITE_BEGIN (" Newton: eq" + to_string (_algLoop->getEquationIndex ()) +
163+ " at time " + to_string (_algLoop->getSimTime ()) + " :" ,
164+ _lc, LL_DEBUG);
165+
156166 while (_iterationStatus == CONTINUE) {
157167 // Check stopping criterion
158168 if (!_algLoop->isLinear ()) {
@@ -205,8 +215,8 @@ void Newton::solve()
205215
206216 // Determination of Jacobian for non-linear system
207217 else {
208- LogSysVec (_algLoop, " y" + to_string (totSteps), _y);
209- LogSysVec (_algLoop, " f" + to_string (totSteps), _f);
218+ LOG_VEC (_algLoop, " y" + to_string (totSteps), _y, _lc, LL_DEBUG );
219+ LOG_VEC (_algLoop, " f" + to_string (totSteps), _f, _lc, LL_DEBUG );
210220 double phi = 0.0 ; // line search function
211221 for (int i = 0 ; i < _dimSys; ++i) {
212222 phi += _f[i] * _f[i];
@@ -305,14 +315,10 @@ void Newton::solve()
305315 phiHelp += _fHelp[i] * _fHelp[i];
306316 }
307317 }
308- if (Logger::getInstance ()->isOutput (LC_NLS, LL_DEBUG)) {
309- std::stringstream ss;
310- ss << " Newton: eq" << to_string (_algLoop->getEquationIndex ());
311- ss << " , time " << _algLoop->getSimTime ();
312- ss << " : lambda = " << lambda;
313- ss << " , phi = " << phi << " --> " << phiHelp;
314- Logger::write (ss.str (), LC_NLS, LL_DEBUG);
315- }
318+ LOGGER_WRITE (" lambda = " + to_string (lambda) +
319+ " , phi = " + to_string (phi) +
320+ " --> " + to_string (phiHelp),
321+ _lc, LL_DEBUG);
316322 }
317323 // check for sufficient decrease
318324 if (phiHelp <= (1.0 - alpha * lambda) * phi)
@@ -329,7 +335,9 @@ void Newton::solve()
329335 " error solving nonlinear system (iteration limit: " + to_string (totSteps) + " )" );
330336 }
331337 } // end while
332- LogSysVec (_algLoop, " y*" , _y);
338+
339+ LOG_VEC (_algLoop, " y*" , _y, _lc, LL_DEBUG);
340+ LOGGER_WRITE_END (_lc, LL_DEBUG);
333341}
334342
335343IAlgLoopSolver::ITERATIONSTATUS Newton::getIterationStatus ()
0 commit comments