DOLFIN
DOLFIN C++ interface
Loading...
Searching...
No Matches
NonlinearVariationalSolver.h
1// Copyright (C) 2008-2011 Anders Logg and 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 Marie E. Rognes, 2011.
19// Modified by Corrado Maurini, 2013.
20//
21// First added: 2011-01-14 (2008-12-26 as VariationalProblem.h)
22// Last changed: 2013-11-20
23
24#ifndef __NONLINEAR_VARIATIONAL_SOLVER_H
25#define __NONLINEAR_VARIATIONAL_SOLVER_H
26
27#include <dolfin/nls/NonlinearProblem.h>
28#include <dolfin/nls/NewtonSolver.h>
29#include <dolfin/nls/PETScSNESSolver.h>
30#include "NonlinearVariationalProblem.h"
31#include "SystemAssembler.h"
32
33namespace dolfin
34{
35
38
40 {
41 public:
42
44 explicit NonlinearVariationalSolver(std::shared_ptr<NonlinearVariationalProblem> problem);
45
52 std::pair<std::size_t, bool> solve();
53
56 {
57 Parameters p("nonlinear_variational_solver");
58
59 p.add("symmetric", false);
60 p.add("print_rhs", false);
61 p.add("print_matrix", false);
62
63 std::set<std::string> nonlinear_solvers = {"newton"};
64 std::string default_nonlinear_solver = "newton";
66
67 #ifdef HAS_PETSC
69 nonlinear_solvers.insert("snes");
70 #endif
71
72 p.add("nonlinear_solver", default_nonlinear_solver, nonlinear_solvers);
73
74 return p;
75 }
76
77 private:
78
79 // Nonlinear (algebraic) problem
80 class NonlinearDiscreteProblem : public NonlinearProblem
81 {
82 public:
83
84 // Constructor
85 NonlinearDiscreteProblem(
86 std::shared_ptr<const NonlinearVariationalProblem> problem,
87 std::shared_ptr<const NonlinearVariationalSolver> solver);
88
89 // Destructor
90 ~NonlinearDiscreteProblem();
91
92 // Compute F at current point x
93 virtual void F(GenericVector& b, const GenericVector& x);
94
95 // Compute J = F' at current point x
96 virtual void J(GenericMatrix& A, const GenericVector& x);
97
98 private:
99
100 // Problem and solver objects
101 std::shared_ptr<const NonlinearVariationalProblem> _problem;
102 std::shared_ptr<const NonlinearVariationalSolver> _solver;
103
104 };
105
106 // The nonlinear problem
107 std::shared_ptr<NonlinearVariationalProblem> _problem;
108
109 // The nonlinear discrete problem
110 std::shared_ptr<NonlinearDiscreteProblem> nonlinear_problem;
111
112 // The Newton solver
113 std::shared_ptr<NewtonSolver> newton_solver;
114
115 #ifdef HAS_PETSC
116 // Or, alternatively, the SNES solver
117 std::shared_ptr<PETScSNESSolver> snes_solver;
118 #endif
119
120 };
121
122}
123
124#endif
This class defines a common interface for matrices.
Definition GenericMatrix.h:47
This class defines a common interface for vectors.
Definition GenericVector.h:48
static Parameters default_parameters()
Definition NewtonSolver.cpp:48
Definition NonlinearProblem.h:37
Definition NonlinearVariationalSolver.h:40
std::pair< std::size_t, bool > solve()
Definition NonlinearVariationalSolver.cpp:46
static Parameters default_parameters()
Default parameter values.
Definition NonlinearVariationalSolver.h:55
static Parameters default_parameters()
Default parameter values.
Definition PETScSNESSolver.cpp:83
Definition Parameters.h:95
void add(std::string key)
Definition Parameters.h:128
Common base class for DOLFIN variables.
Definition Variable.h:36
Definition adapt.h:30