DOLFIN
DOLFIN C++ interface
Loading...
Searching...
No Matches
MixedNonlinearVariationalSolver.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 Cecile Daversin-Catty, 2018.
19//
20// First added: 2017-10-03
21// Last changed: 2017-10-03
22
23#ifndef __MIXED_NONLINEAR_VARIATIONAL_SOLVER_H
24#define __MIXED_NONLINEAR_VARIATIONAL_SOLVER_H
25
26#include <dolfin/nls/NonlinearProblem.h>
27#include <dolfin/nls/NewtonSolver.h>
28#include <dolfin/nls/PETScSNESSolver.h>
29#include "MixedNonlinearVariationalProblem.h"
30#include "SystemAssembler.h"
31
32namespace dolfin
33{
34
35 // Forward declarations
36 class MixedNonlinearVariationalProblem;
37 class PETScNestMatrix;
38
40
42 {
43 public:
44 /* typedef std::tuple<std::vector<std::shared_ptr<GenericVector>>, */
45 /* std::vector<std::shared_ptr<GenericMatrix>> > assembled_system_type; */
46
49 explicit MixedNonlinearVariationalSolver(std::shared_ptr<MixedNonlinearVariationalProblem> problem);
51 std::pair<std::size_t, bool> solve();
52
55 {
56 Parameters p("nonlinear_variational_solver");
57
58 p.add("symmetric", false);
59 p.add("print_rhs", false);
60 p.add("print_matrix", false);
61
62 std::set<std::string> nonlinear_solvers = {"newton"};
63 std::string default_nonlinear_solver = "newton";
65
66 #ifdef HAS_PETSC
68 nonlinear_solvers.insert("snes");
69 #endif
70
71 p.add("nonlinear_solver", default_nonlinear_solver, nonlinear_solvers);
72
73 return p;
74 }
75
76 private:
77
78 // Nonlinear (algebraic) problem
79 class MixedNonlinearDiscreteProblem : public NonlinearProblem
80 {
81 public:
82
83 // Constructor
84 MixedNonlinearDiscreteProblem(
85 std::shared_ptr<const MixedNonlinearVariationalProblem> problem,
86 std::shared_ptr<const MixedNonlinearVariationalSolver> solver);
87
88 // Destructor
89 ~MixedNonlinearDiscreteProblem();
90
91 // Compute F at current point x
92 virtual void F(GenericVector& b, const GenericVector& x);
93
94 // Compute J = F' at current point x
95 virtual void J(GenericMatrix& A, const GenericVector& x);
96
97 private:
99
100 // Problem and solver objects
101 std::shared_ptr<const MixedNonlinearVariationalProblem> _problem;
102 std::shared_ptr<const MixedNonlinearVariationalSolver> _solver;
103
104 // Store J(i,j) and F(i) for each block (i,j)
105 std::vector<std::shared_ptr<GenericMatrix>> _Js;
106 std::vector<std::shared_ptr<GenericVector>> _bs;
107 };
108
109 // The nonlinear problem
110 std::shared_ptr<MixedNonlinearVariationalProblem> _problem;
111
112 // The nonlinear discrete problem
113 std::shared_ptr<MixedNonlinearDiscreteProblem> nonlinear_problem;
114
115 // The Newton solver
116 std::shared_ptr<NewtonSolver> newton_solver;
117
118 #ifdef HAS_PETSC
119 // Or, alternatively, the SNES solver
120 std::shared_ptr<PETScSNESSolver> snes_solver;
121 #endif
122
123 };
124}
125
126#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
This class implements a solver for mixed nonlinear variational problems.
Definition MixedNonlinearVariationalSolver.h:42
static Parameters default_parameters()
Default parameter values.
Definition MixedNonlinearVariationalSolver.h:54
MixedNonlinearVariationalSolver()
Create linear variational solver for given problem.
Definition MixedNonlinearVariationalSolver.cpp:46
std::pair< std::size_t, bool > solve()
Solve variational problem.
Definition MixedNonlinearVariationalSolver.cpp:60
static Parameters default_parameters()
Definition NewtonSolver.cpp:48
Definition NonlinearProblem.h:37
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