Skip to content
Snippets Groups Projects
Commit 7c401a94 authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[NL] more output from nonlinear solver

parent 7c43841a
No related branches found
No related tags found
No related merge requests found
...@@ -47,7 +47,8 @@ solve(Vector &x) ...@@ -47,7 +47,8 @@ solve(Vector &x)
BLAS::copy(x, x_new); // set initial guess, TODO save the copy BLAS::copy(x, x_new); // set initial guess, TODO save the copy
for (unsigned iteration=1; iteration<_maxiter; ++iteration) unsigned iteration=1;
for (; iteration<=_maxiter; ++iteration)
{ {
sys.preIteration(iteration, x); sys.preIteration(iteration, x);
...@@ -65,7 +66,7 @@ solve(Vector &x) ...@@ -65,7 +66,7 @@ solve(Vector &x)
if (!iteration_succeeded) if (!iteration_succeeded)
{ {
ERR("The linear solver failed."); ERR("Picard: The linear solver failed.");
} }
else else
{ {
...@@ -76,12 +77,15 @@ solve(Vector &x) ...@@ -76,12 +77,15 @@ solve(Vector &x)
// Although currently it is not. // Although currently it is not.
break; break;
case IterationResult::FAILURE: case IterationResult::FAILURE:
ERR("Picard: The postIteration() hook reported a non-recoverable error.");
iteration_succeeded = false; iteration_succeeded = false;
// Copy new solution to x. // Copy new solution to x.
// Thereby the failed solution can be used by the caller for debugging purposes. // Thereby the failed solution can be used by the caller for debugging purposes.
BLAS::copy(x_new, x); BLAS::copy(x_new, x);
break; break;
case IterationResult::REPEAT_ITERATION: case IterationResult::REPEAT_ITERATION:
INFO("Picard: The postIteration() hook decided that this iteration"
" has to be repeated.");
continue; // That throws the iteration result away. continue; // That throws the iteration result away.
} }
} }
...@@ -94,24 +98,29 @@ solve(Vector &x) ...@@ -94,24 +98,29 @@ solve(Vector &x)
// x is used as delta_x in order to compute the error. // x is used as delta_x in order to compute the error.
BLAS::aypx(x, -1.0, x_new); // x = _x_new - x BLAS::aypx(x, -1.0, x_new); // x = _x_new - x
auto const error = BLAS::norm2(x); auto const error_dx = BLAS::norm2(x);
// INFO(" picard iteration %u error: %e", iteration, error); INFO("Picard: Iteration #%u error_dx: %g, tolerance %g",
iteration, error_dx, _tol);
// Update x s.t. in the next iteration we will compute the right delta x // Update x s.t. in the next iteration we will compute the right delta x
BLAS::copy(x_new, x); BLAS::copy(x_new, x);
if (error < _tol) { if (error_dx < _tol) {
error_norms_met = true; error_norms_met = true;
break; break;
} }
if (sys.isLinear()) { if (sys.isLinear()) {
// INFO(" picard linear system. not looping");
error_norms_met = true; error_norms_met = true;
break; break;
} }
} }
if (iteration > _maxiter) {
ERR("Picard: Could not solve the given nonlinear system within %u iterations",
_maxiter);
}
MathLib::GlobalMatrixProvider<Matrix>::provider.releaseMatrix(A); MathLib::GlobalMatrixProvider<Matrix>::provider.releaseMatrix(A);
MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(rhs); MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(rhs);
MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(x_new); MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(x_new);
...@@ -153,7 +162,8 @@ solve(Vector &x) ...@@ -153,7 +162,8 @@ solve(Vector &x)
BLAS::copy(x, minus_delta_x); BLAS::copy(x, minus_delta_x);
minus_delta_x.setZero(); minus_delta_x.setZero();
for (unsigned iteration=1; iteration<_maxiter; ++iteration) unsigned iteration=1;
for (; iteration<_maxiter; ++iteration)
{ {
sys.preIteration(iteration, x); sys.preIteration(iteration, x);
...@@ -172,7 +182,7 @@ solve(Vector &x) ...@@ -172,7 +182,7 @@ solve(Vector &x)
if (!iteration_succeeded) if (!iteration_succeeded)
{ {
ERR("The linear solver failed."); ERR("Newton: The linear solver failed.");
} }
else else
{ {
...@@ -187,9 +197,12 @@ solve(Vector &x) ...@@ -187,9 +197,12 @@ solve(Vector &x)
case IterationResult::SUCCESS: case IterationResult::SUCCESS:
break; break;
case IterationResult::FAILURE: case IterationResult::FAILURE:
ERR("Newton: The postIteration() hook reported a non-recoverable error.");
iteration_succeeded = false; iteration_succeeded = false;
break; break;
case IterationResult::REPEAT_ITERATION: case IterationResult::REPEAT_ITERATION:
INFO("Newton: The postIteration() hook decided that this iteration"
" has to be repeated.");
// TODO introduce some onDestroy hook. // TODO introduce some onDestroy hook.
MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(x_new); MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(x_new);
continue; // That throws the iteration result away. continue; // That throws the iteration result away.
...@@ -208,8 +221,9 @@ solve(Vector &x) ...@@ -208,8 +221,9 @@ solve(Vector &x)
} }
auto const error_dx = BLAS::norm2(minus_delta_x); auto const error_dx = BLAS::norm2(minus_delta_x);
DBUG("error of -delta_x %g and of residual %g,", error_dx, error_res); INFO("Newton: Iteration #%u error of -delta_x %g (tolerance %g)"
(void) error_res; // avoid compiler warning when not in debug build " and of residual %g,",
iteration, error_dx, _tol, error_res);
if (error_dx < _tol) { if (error_dx < _tol) {
error_norms_met = true; error_norms_met = true;
...@@ -217,12 +231,16 @@ solve(Vector &x) ...@@ -217,12 +231,16 @@ solve(Vector &x)
} }
if (sys.isLinear()) { if (sys.isLinear()) {
// INFO(" newton linear system. not looping");
error_norms_met = true; error_norms_met = true;
break; break;
} }
} }
if (iteration > _maxiter) {
ERR("Newton: Could not solve the given nonlinear system within %u iterations",
_maxiter);
}
MathLib::GlobalMatrixProvider<Matrix>::provider.releaseMatrix(J); MathLib::GlobalMatrixProvider<Matrix>::provider.releaseMatrix(J);
MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(res); MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(res);
MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(minus_delta_x); MathLib::GlobalVectorProvider<Vector>::provider.releaseVector(minus_delta_x);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment