Debian Codegraph @

debian/patches/mixed_solvers_without_petsc.patch

raw
1 --- a/dolfin/fem/MixedLinearVariationalSolver.cpp
2 +++ b/dolfin/fem/MixedLinearVariationalSolver.cpp
3 @@ -228,6 +228,7 @@
4 {
5 begin("Solving mixed linear variational problem.");
6
7 +#ifdef HAS_PETSC
8 // Get parameters
9 std::string solver_type = parameters["linear_solver"];
10 const std::string pc_type = parameters["preconditioner"];
11 @@ -301,6 +302,9 @@
12 // Ghost values have to be updated in parallel since they are not updated by solve
13 for(auto &u : us)
14 as_type<PETScVector>(u)->update_ghost_values();
15 +#else
16 + dolfin_error("MixedLinearVariationalSolver.cpp", "solve problem", "MixedLinearVariationalSolver::solve requires PETSc");
17 +#endif
18
19 #if 0 // Configure PCFieldSplit (Not working yet)
20 PETScOptions::set("pc_type", "fieldsplit");
21 --- a/dolfin/fem/MixedNonlinearVariationalSolver.cpp
22 +++ b/dolfin/fem/MixedNonlinearVariationalSolver.cpp
23 @@ -61,6 +61,7 @@
24 {
25 begin("Solving mixed nonlinear variational problem.");
26
27 +#ifdef HAS_PETSC
28 // Check that the Jacobian has been defined
29 dolfin_assert(_problem);
30 if (!_problem->has_jacobian())
31 @@ -70,14 +71,12 @@
32 "The Jacobian form has not been defined");
33 }
34 // Check that the dolfin is configured with petsc is bounds are set
35 -#ifndef HAS_PETSC
36 if (_problem->has_lower_bound() || _problem->has_upper_bound())
37 {
38 dolfin_error("NonlinearVariationalSolver.cpp",
39 "solve nonlinear variational problem",
40 "Needs PETSc to solve bound constrained problems");
41 }
42 -#endif
43
44 // Get problem data
45 dolfin_assert(_problem);
46 @@ -156,7 +155,6 @@
47 dolfin_assert(nonlinear_problem);
48 ret = newton_solver->solve(*nonlinear_problem, *x);
49 }
50 -#ifdef HAS_PETSC
51 // FIXME : SNES Solver need to be setup (SNES norm is zero at 1st iteration)
52 else if (std::string(parameters["nonlinear_solver"]) == "snes")
53 {
54 @@ -185,16 +183,20 @@
55 ret = snes_solver->solve(*nonlinear_problem, *x);
56 }
57 }
58 -#endif
59 else
60 {
61 dolfin_error("MixedNonlinearVariationalSolver.cpp",
62 "solve nonlinear variational problem",
63 "Unknown nonlinear solver type");
64 }
65 +#else
66 + dolfin_error("MixedNonlinearVariationalSolver.cpp", "solve problem", "MixedNonlinearVariationalSolver::solve requires PETSc");
67 +#endif
68
69 end();
70 +#ifdef HAS_PETSC
71 return ret;
72 +#endif
73 }
74 //-----------------------------------------------------------------------------
75 // Implementation of NonlinearDiscreteProblem
76 @@ -215,6 +217,7 @@
77 void MixedNonlinearVariationalSolver::
78 MixedNonlinearDiscreteProblem::F(GenericVector& b, const GenericVector& x)
79 {
80 +#ifdef HAS_PETSC
81 const auto bform = _problem->residual_form();
82 auto u = _problem->solution();
83 auto bcs = _problem->bcs();
84 @@ -262,11 +265,15 @@
85
86 // Update b from _bs[]
87 J.init_vectors(b, _bs);
88 +#else
89 + dolfin_error("MixedNonlinearVariationalSolver.cpp", "assemble residual", "MixedNonlinearVariationalSolver::F requires PETSc");
90 +#endif
91 }
92 //-----------------------------------------------------------------------------
93 void MixedNonlinearVariationalSolver::
94 MixedNonlinearDiscreteProblem::J(GenericMatrix& A, const GenericVector& x)
95 {
96 +#ifdef HAS_PETSC
97 const auto jform = _problem->jacobian_form();
98 auto u = _problem->solution();
99 auto bcs = _problem->bcs();
100 @@ -321,4 +328,7 @@
101 petsc_mats[i*u.size() + j] = as_type<PETScMatrix>(_Js[i*u.size() + j])->mat();
102 as_type<PETScMatrix>(A).set_nest(petsc_mats);
103 as_type<PETScMatrix>(A).apply("insert");
104 +#else
105 + dolfin_error("MixedNonlinearVariationalSolver.cpp", "assemble jacobian", "MixedNonlinearVariationalSolver::J requires PETSc");
106 +#endif
107 }
108 --- a/dolfin/nls/NewtonSolver.cpp
109 +++ b/dolfin/nls/NewtonSolver.cpp
110 @@ -156,11 +156,13 @@
111 }
112
113 // Might need a copy of _matA (nest -> aij)
114 +#ifdef HAS_PETSC
115 std::shared_ptr<GenericMatrix> _matAc;
116
117 bool need_mataij_conversion = (solver_type == "lu" or solver_type == "direct" or solver_type == "default" or solver_type == "mumps");
118 if (as_type<PETScMatrix>(_matA)->is_nest() and need_mataij_conversion)
119 log(WARNING, "Converting PETScNestMatrix into AIJ (due to direct solver)");
120 +#endif
121
122 // Start iterations
123 while (!newton_converged && _newton_iteration < maxiter)
124 @@ -170,6 +172,7 @@
125 nonlinear_problem.J_pc(*_matP, x);
126
127 // Setup (linear) solver (including set operators)
128 +#ifdef HAS_PETSC
129 if (as_type<PETScMatrix>(_matA)->is_nest() and need_mataij_conversion)
130 {
131 log(TRACE, "NewtonSolver: setup matrix with MATAIJ type in direct solver");
132 @@ -179,6 +182,9 @@
133 }
134 else
135 solver_setup(_matA, _matP, nonlinear_problem, _newton_iteration);
136 +#else
137 + solver_setup(_matA, _matP, nonlinear_problem, _newton_iteration);
138 +#endif
139
140 // Perform linear solve and update total number of Krylov
141 // iterations