Debian Codegraph @

debian/patches/deprecated-petsc-3.17.patch

raw
1 diff --git a/dolfin/nls/PETScTAOSolver.cpp b/dolfin/nls/PETScTAOSolver.cpp
2 index 96ecf55..55318bb 100644
3 --- a/dolfin/nls/PETScTAOSolver.cpp
4 +++ b/dolfin/nls/PETScTAOSolver.cpp
5 @@ -96,8 +96,13 @@ PETScTAOSolver::PETScTAOSolver(MPI_Comm comm,
6 if (ierr != 0) petsc_error(ierr, __FILE__, "TaoCreate");
7
8 // Set Hessian and preconditioner only once
9 + #if PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 17
10 + ierr = TaoSetHessian(_tao, _matH.mat(), _matP.mat(), nullptr, nullptr);
11 + if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetHessian");
12 + #else
13 ierr = TaoSetHessianRoutine(_tao, _matH.mat(), _matP.mat(), nullptr, nullptr);
14 if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetHessianRoutine");
15 + #endif
16
17 // Set parameter values
18 parameters = default_parameters();
19 @@ -223,8 +228,13 @@ void PETScTAOSolver::init(OptimisationProblem& optimisation_problem,
20 set_ksp_options();
21
22 // Set initial vector
23 + #if PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 17
24 + ierr = TaoSetSolution(_tao, x.vec());
25 + if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetSolution");
26 + #else
27 ierr = TaoSetInitialVector(_tao, x.vec());
28 if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetInitialVector");
29 + #endif
30
31 // Set the bounds in case of a bound-constrained minimisation problem
32 if (_has_bounds)
33 @@ -234,10 +244,17 @@ void PETScTAOSolver::init(OptimisationProblem& optimisation_problem,
34 }
35
36 // Set the objective function, gradient and Hessian evaluation routines
37 + #if PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 17
38 + ierr = TaoSetObjectiveAndGradient(_tao, nullptr, FormFunctionGradient, &_tao_ctx);
39 + if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetObjectiveAndGradient");
40 + ierr = TaoSetHessian(_tao, nullptr, nullptr, FormHessian, &_tao_ctx);
41 + if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetHessian");
42 + #else
43 ierr = TaoSetObjectiveAndGradientRoutine(_tao, FormFunctionGradient, &_tao_ctx);
44 if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetObjectiveAndGradientRoutine");
45 ierr = TaoSetHessianRoutine(_tao, nullptr, nullptr, FormHessian, &_tao_ctx);
46 if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetHessianRoutine");
47 + #endif
48
49 // Clear previous monitors
50 ierr = TaoCancelMonitors(_tao);
51 @@ -388,9 +405,15 @@ PetscErrorCode PETScTAOSolver::FormHessian(Tao tao, Vec x, Mat H, Mat P,
52 if (P_wrap.empty())
53 {
54 log(TRACE, "TAO FormHessian: using Hessian as preconditioner matrix");
55 + #if PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 17
56 + PetscErrorCode ierr = TaoSetHessian(tao, nullptr, H,
57 + nullptr, nullptr);
58 + if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetHessian");
59 + #else
60 PetscErrorCode ierr = TaoSetHessianRoutine(tao, nullptr, H,
61 nullptr, nullptr);
62 if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetHessianRoutine");
63 + #endif
64 }
65
66 return 0;
67 diff --git a/dolfin/nls/TAOLinearBoundSolver.cpp b/dolfin/nls/TAOLinearBoundSolver.cpp
68 index 78fa1e7..bc2c384 100644
69 --- a/dolfin/nls/TAOLinearBoundSolver.cpp
70 +++ b/dolfin/nls/TAOLinearBoundSolver.cpp
71 @@ -172,8 +172,13 @@ std::size_t TAOLinearBoundSolver::solve(const PETScMatrix& A1,
72
73 // Set initial vector
74 dolfin_assert(_tao);
75 + #if PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 17
76 + ierr = TaoSetSolution(_tao, x.vec());
77 + if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetSolution");
78 + #else
79 ierr = TaoSetInitialVector(_tao, x.vec());
80 if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetInitialVector");
81 + #endif
82
83 // Set the bound on the variables
84 ierr = TaoSetVariableBounds(_tao, xl.vec(), xu.vec());
85 @@ -181,6 +186,15 @@ std::size_t TAOLinearBoundSolver::solve(const PETScMatrix& A1,
86
87 // Set the user function, gradient, hessian evaluation routines and
88 // data structures
89 + #if PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 17
90 + ierr = TaoSetObjectiveAndGradient(_tao, nullptr,
91 + __TAOFormFunctionGradientQuadraticProblem, this);
92 + if (ierr != 0) petsc_error(ierr, __FILE__,
93 + "TaoSetObjectiveAndGradient");
94 + ierr = TaoSetHessian(_tao, A->mat(), A->mat(),
95 + __TAOFormHessianQuadraticProblem, this);
96 + if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetHessian");
97 + #else
98 ierr = TaoSetObjectiveAndGradientRoutine(_tao,
99 __TAOFormFunctionGradientQuadraticProblem, this);
100 if (ierr != 0) petsc_error(ierr, __FILE__,
101 @@ -188,6 +202,7 @@ std::size_t TAOLinearBoundSolver::solve(const PETScMatrix& A1,
102 ierr = TaoSetHessianRoutine(_tao, A->mat(), A->mat(),
103 __TAOFormHessianQuadraticProblem, this);
104 if (ierr != 0) petsc_error(ierr, __FILE__, "TaoSetHessianRoutine");
105 + #endif
106
107 // Set parameters from local parameters, including ksp parameters
108 read_parameters();