//----------------------------------------------------------------------------- double dolfin::normalize(GenericVector& x, std::string normalization_type) { if (x.empty()) { dolfin_error("solve.cpp", "normalize vector", "Cannot normalize vector of zero length"); } double c = 0.0; if (normalization_type == "l2") { c = x.norm("l2"); x /= c; } else if (normalization_type == "average") { c = x.sum()/static_cast<double>(x.size()); x -= c; } else { dolfin_error("solve.cpp", "normalize vector", "Unknown normalization type (\"%s\")", normalization_type.c_str()); } return c; }
//----------------------------------------------------------------------------- bool NewtonSolver::converged(const GenericVector& r, const NonlinearProblem& nonlinear_problem, std::size_t newton_iteration) { const double rtol = parameters["relative_tolerance"]; const double atol = parameters["absolute_tolerance"]; const bool report = parameters["report"]; _residual = r.norm("l2"); // If this is the first iteration step, set initial residual if (newton_iteration == 0) _residual0 = _residual; // Relative residual const double relative_residual = _residual/_residual0; // Output iteration number and residual if (report && dolfin::MPI::rank(_mpi_comm) == 0) { info("Newton iteration %d: r (abs) = %.3e (tol = %.3e) r (rel) = %.3e (tol = %.3e)", newton_iteration, _residual, atol, relative_residual, rtol); } // Return true if convergence criterion is met if (relative_residual < rtol || _residual < atol) return true; else return false; }
//----------------------------------------------------------------------------- double dolfin::norm(const GenericVector& x, std::string norm_type) { return x.norm(norm_type); }