Loading...
Searching...
No Matches
NewtonSolver.h
// Copyright (C) 2005-2008 Garth N. Wells
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// Modified by Anders Logg 2006-2011
// Modified by Anders E. Johansen 2011
//
// First added: 2005-10-23
// Last changed: 2013-11-20
#ifndef __NEWTON_SOLVER_H
#define __NEWTON_SOLVER_H
#include <utility>
#include <memory>
#include <dolfin/common/MPI.h>
#include <dolfin/common/Variable.h>
namespace dolfin
{
// Forward declarations
class GenericLinearSolver;
class GenericLinearAlgebraFactory;
class GenericMatrix;
class GenericVector;
class NonlinearProblem;
class MixedNonlinearProblem;
class NewtonSolver : public Variable
{
public:
explicit NewtonSolver(MPI_Comm comm=MPI_COMM_WORLD);
NewtonSolver(MPI_Comm comm, std::shared_ptr<GenericLinearSolver> solver,
GenericLinearAlgebraFactory& factory);
virtual ~NewtonSolver();
std::pair<std::size_t, bool> solve(NonlinearProblem& nonlinear_function,
GenericVector& x);
std::size_t iteration() const;
std::size_t krylov_iterations() const;
double residual() const;
double residual0() const;
double relative_residual() const;
GenericLinearSolver& linear_solver() const;
static Parameters default_parameters();
void set_relaxation_parameter(double relaxation_parameter)
{ _relaxation_parameter = relaxation_parameter; }
double get_relaxation_parameter()
{ return _relaxation_parameter; }
protected:
virtual bool converged(const GenericVector& r,
const NonlinearProblem& nonlinear_problem,
std::size_t iteration);
virtual void solver_setup(std::shared_ptr<const GenericMatrix> A,
std::shared_ptr<const GenericMatrix> P,
const NonlinearProblem& nonlinear_problem,
std::size_t iteration);
virtual void update_solution(GenericVector& x,
const GenericVector& dx,
double relaxation_parameter,
const NonlinearProblem& nonlinear_problem,
std::size_t iteration);
private:
// Current number of Newton iterations
std::size_t _newton_iteration;
// Accumulated number of Krylov iterations since solve began
std::size_t _krylov_iterations;
// Relaxation parameter
double _relaxation_parameter;
// Most recent residual and initial residual
double _residual, _residual0;
// Solver
std::shared_ptr<GenericLinearSolver> _solver;
// Jacobian matrix
std::shared_ptr<GenericMatrix> _matA;
// Preconditioner matrix
std::shared_ptr<GenericMatrix> _matP;
// Solution vector
std::shared_ptr<GenericVector> _dx;
// Residual vector
std::shared_ptr<GenericVector> _b;
// MPI communicator
dolfin::MPI::Comm _mpi_comm;
};
}
#endif
dolfin::GenericLinearAlgebraFactory
Base class for LinearAlgebra factories.
Definition GenericLinearAlgebraFactory.h:47
dolfin::GenericLinearSolver
This class provides a general solver for linear systems Ax = b.
Definition GenericLinearSolver.h:38
dolfin::GenericMatrix
This class defines a common interface for matrices.
Definition GenericMatrix.h:47
dolfin::GenericVector
This class defines a common interface for vectors.
Definition GenericVector.h:48
dolfin::MPI::Comm
Definition MPI.h:77
dolfin::NewtonSolver::residual0
double residual0() const
Definition NewtonSolver.cpp:277
dolfin::NewtonSolver::residual
double residual() const
Definition NewtonSolver.cpp:272
dolfin::NewtonSolver::solve
std::pair< std::size_t, bool > solve(NonlinearProblem &nonlinear_function, GenericVector &x)
Definition NewtonSolver.cpp:102
dolfin::NewtonSolver::converged
virtual bool converged(const GenericVector &r, const NonlinearProblem &nonlinear_problem, std::size_t iteration)
Definition NewtonSolver.cpp:301
dolfin::NewtonSolver::relative_residual
double relative_residual() const
Definition NewtonSolver.cpp:282
dolfin::NewtonSolver::~NewtonSolver
virtual ~NewtonSolver()
Destructor.
Definition NewtonSolver.cpp:96
dolfin::NewtonSolver::NewtonSolver
NewtonSolver(MPI_Comm comm=MPI_COMM_WORLD)
Create nonlinear solver.
Definition NewtonSolver.cpp:90
dolfin::NewtonSolver::set_relaxation_parameter
void set_relaxation_parameter(double relaxation_parameter)
Definition NewtonSolver.h:141
dolfin::NewtonSolver::krylov_iterations
std::size_t krylov_iterations() const
Definition NewtonSolver.cpp:267
dolfin::NewtonSolver::solver_setup
virtual void solver_setup(std::shared_ptr< const GenericMatrix > A, std::shared_ptr< const GenericMatrix > P, const NonlinearProblem &nonlinear_problem, std::size_t iteration)
Definition NewtonSolver.cpp:332
dolfin::NewtonSolver::iteration
std::size_t iteration() const
Definition NewtonSolver.cpp:262
dolfin::NewtonSolver::linear_solver
GenericLinearSolver & linear_solver() const
Definition NewtonSolver.cpp:287
dolfin::NewtonSolver::update_solution
virtual void update_solution(GenericVector &x, const GenericVector &dx, double relaxation_parameter, const NonlinearProblem &nonlinear_problem, std::size_t iteration)
Definition NewtonSolver.cpp:349
dolfin::NewtonSolver::get_relaxation_parameter
double get_relaxation_parameter()
Definition NewtonSolver.h:149
dolfin::NewtonSolver::default_parameters
static Parameters default_parameters()
Definition NewtonSolver.cpp:48
dolfin::NonlinearProblem
Definition NonlinearProblem.h:37
dolfin::Parameters
Definition Parameters.h:95
dolfin::Variable::Variable
Variable()
Create unnamed variable.
Definition Variable.cpp:31
dolfin
Definition adapt.h:30