File: deprecated-petsc-3.17.patch

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