DOLFIN
DOLFIN C++ interface
Loading...
Searching...
No Matches
NewtonSolver.h
1// Copyright (C) 2005-2008 Garth N. Wells
2//
3// This file is part of DOLFIN.
4//
5// DOLFIN is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// DOLFIN is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17//
18// Modified by Anders Logg 2006-2011
19// Modified by Anders E. Johansen 2011
20//
21// First added: 2005-10-23
22// Last changed: 2013-11-20
23
24#ifndef __NEWTON_SOLVER_H
25#define __NEWTON_SOLVER_H
26
27#include <utility>
28#include <memory>
29#include <dolfin/common/MPI.h>
30#include <dolfin/common/Variable.h>
31
32namespace dolfin
33{
34
35 // Forward declarations
36 class GenericLinearSolver;
37 class GenericLinearAlgebraFactory;
38 class GenericMatrix;
39 class GenericVector;
40 class NonlinearProblem;
41 class MixedNonlinearProblem;
42
45
46 class NewtonSolver : public Variable
47 {
48 public:
49
51 explicit NewtonSolver(MPI_Comm comm=MPI_COMM_WORLD);
52
62 NewtonSolver(MPI_Comm comm, std::shared_ptr<GenericLinearSolver> solver,
64
66 virtual ~NewtonSolver();
67
81 std::pair<std::size_t, bool> solve(NonlinearProblem& nonlinear_function,
82 GenericVector& x);
83
89 std::size_t iteration() const;
90
97 std::size_t krylov_iterations() const;
98
104 double residual() const;
105
111 double residual0() const;
112
118 double relative_residual() const;
119
126
133
141 void set_relaxation_parameter(double relaxation_parameter)
142 { _relaxation_parameter = relaxation_parameter; }
143
150 { return _relaxation_parameter; }
151
152 protected:
153
168 virtual bool converged(const GenericVector& r,
169 const NonlinearProblem& nonlinear_problem,
170 std::size_t iteration);
171
187 virtual void solver_setup(std::shared_ptr<const GenericMatrix> A,
188 std::shared_ptr<const GenericMatrix> P,
189 const NonlinearProblem& nonlinear_problem,
190 std::size_t iteration);
191
208 virtual void update_solution(GenericVector& x,
209 const GenericVector& dx,
210 double relaxation_parameter,
211 const NonlinearProblem& nonlinear_problem,
212 std::size_t iteration);
213
214 private:
215
216 // Current number of Newton iterations
217 std::size_t _newton_iteration;
218
219 // Accumulated number of Krylov iterations since solve began
220 std::size_t _krylov_iterations;
221
222 // Relaxation parameter
223 double _relaxation_parameter;
224
225 // Most recent residual and initial residual
226 double _residual, _residual0;
227
228 // Solver
229 std::shared_ptr<GenericLinearSolver> _solver;
230
231 // Jacobian matrix
232 std::shared_ptr<GenericMatrix> _matA;
233
234 // Preconditioner matrix
235 std::shared_ptr<GenericMatrix> _matP;
236
237 // Solution vector
238 std::shared_ptr<GenericVector> _dx;
239
240 // Residual vector
241 std::shared_ptr<GenericVector> _b;
242
243 // MPI communicator
244 dolfin::MPI::Comm _mpi_comm;
245
246 };
247
248}
249
250#endif
Base class for LinearAlgebra factories.
Definition GenericLinearAlgebraFactory.h:47
This class provides a general solver for linear systems Ax = b.
Definition GenericLinearSolver.h:38
This class defines a common interface for vectors.
Definition GenericVector.h:48
Definition MPI.h:77
Definition NewtonSolver.h:47
double residual0() const
Definition NewtonSolver.cpp:271
double residual() const
Definition NewtonSolver.cpp:266
std::pair< std::size_t, bool > solve(NonlinearProblem &nonlinear_function, GenericVector &x)
Definition NewtonSolver.cpp:102
virtual bool converged(const GenericVector &r, const NonlinearProblem &nonlinear_problem, std::size_t iteration)
Definition NewtonSolver.cpp:295
double relative_residual() const
Definition NewtonSolver.cpp:276
virtual ~NewtonSolver()
Destructor.
Definition NewtonSolver.cpp:96
void set_relaxation_parameter(double relaxation_parameter)
Definition NewtonSolver.h:141
std::size_t krylov_iterations() const
Definition NewtonSolver.cpp:261
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:326
std::size_t iteration() const
Definition NewtonSolver.cpp:256
GenericLinearSolver & linear_solver() const
Definition NewtonSolver.cpp:281
virtual void update_solution(GenericVector &x, const GenericVector &dx, double relaxation_parameter, const NonlinearProblem &nonlinear_problem, std::size_t iteration)
Definition NewtonSolver.cpp:343
double get_relaxation_parameter()
Definition NewtonSolver.h:149
static Parameters default_parameters()
Definition NewtonSolver.cpp:48
Definition NonlinearProblem.h:37
Definition Parameters.h:95
Common base class for DOLFIN variables.
Definition Variable.h:36
Definition adapt.h:30