PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
IP_SSATaucTikhonovGNSolver.hh
Go to the documentation of this file.
1 // Copyright (C) 2012, 2014, 2015, 2016, 2017, 2019, 2020, 2021, 2022, 2023 David Maxwell
2 //
3 // This file is part of PISM.
4 //
5 // PISM is free software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the Free Software
7 // Foundation; either version 3 of the License, or (at your option) any later
8 // version.
9 //
10 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with PISM; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef IP_SSATAUCTIKHONOVGN_HH_SIU7F33G
20 #define IP_SSATAUCTIKHONOVGN_HH_SIU7F33G
21 
22 #include "pism/inverse/IP_SSATaucForwardProblem.hh"
23 #include "pism/util/TerminationReason.hh"
24 #include "pism/util/error_handling.hh"
25 #include "pism/util/petscwrappers/KSP.hh"
26 #include "pism/inverse/functional/IPFunctional.hh"
27 
28 namespace pism {
29 namespace inverse {
30 
31 template<class C, void (C::*MultiplyCallback)(Vec,Vec) >
33 public:
34  static void connect(Mat A) {
35  PetscErrorCode ierr;
36  ierr = MatShellSetOperation(A, MATOP_MULT,
37  (void(*)(void))MatrixMultiplyCallback::callback);
38  PISM_CHK(ierr, "MatShellSetOperation");
39  }
40 protected:
41  static PetscErrorCode callback(Mat A, Vec x, Vec y) {
42  try {
43  C *ctx;
44  PetscErrorCode ierr = MatShellGetContext(A,&ctx);
45  PISM_CHK(ierr, "MatShellGetContext");
46  (ctx->*MultiplyCallback)(x,y);
47  } catch (...) {
48  MPI_Comm com = MPI_COMM_SELF;
49  PetscErrorCode ierr = PetscObjectGetComm((PetscObject)A, &com); CHKERRQ(ierr);
51  SETERRQ(com, 1, "A PISM callback failed");
52  }
53  return 0;
54  }
55 };
56 
58 public:
62 
64 
65  // typedef IP_SSATaucTikhonovGNSolverListener Listener;
66 
67  IP_SSATaucTikhonovGNSolver(IP_SSATaucForwardProblem &ssaforward, DesignVec &d0, StateVec &u_obs, double eta,
69 
71 
72  virtual std::shared_ptr<StateVec> stateSolution() {
73  return m_ssaforward.solution();
74  }
75 
76  virtual std::shared_ptr<DesignVec> designSolution() {
77  return m_d;
78  }
79 
80  virtual void setInitialGuess(DesignVec &d) {
81  m_d->copy_from(d);
82  }
83 
84  //! Sets the desired target misfit (in units of \f$\sqrt{J_{\rm misfit}}\f$).
85  virtual void setTargetMisfit(double misfit) {
86  m_target_misfit = misfit;
87  }
88 
89  virtual void evaluateGNFunctional(DesignVec &h, double *value);
90 
91  virtual void apply_GN(array::Scalar &h, array::Scalar &out);
92  virtual void apply_GN(Vec h, Vec out);
93 
94  virtual std::shared_ptr<TerminationReason> init();
95 
96  virtual std::shared_ptr<TerminationReason> check_convergence();
97 
98  virtual std::shared_ptr<TerminationReason> solve();
99 
100  virtual std::shared_ptr<TerminationReason> evaluate_objective_and_gradient();
101 
102 protected:
103 
104  virtual void assemble_GN_rhs(DesignVec &out);
105 
106  virtual std::shared_ptr<TerminationReason> solve_linearized();
107 
108  virtual std::shared_ptr<TerminationReason> compute_dlogalpha(double *dalpha);
109 
110  virtual std::shared_ptr<TerminationReason> linesearch();
111 
112  const unsigned int m_design_stencil_width;
113  const unsigned int m_state_stencil_width;
114 
116 
118 
127 
129 
130  std::shared_ptr<DesignVecGhosted> m_d; // ghosted
135 
139  DesignVec m_dh_dalpha; // ghosted
141 
145 
147 
149  StateVec1 m_u_diff; // ghosted
150 
153 
154  double m_eta;
157 
158  double m_alpha;
159  double m_logalpha;
161 
164  double m_vel_scale;
166 
167  MPI_Comm m_comm;
169 };
170 
171 } // end of namespace inverse
172 } // end of namespace pism
173 
174 #endif /* end of include guard: IP_SSATAUCTIKHONOVGN_HH_SIU7F33G */
std::shared_ptr< const Logger > ConstPtr
Definition: Logger.hh:46
Abstract base class for IPFunctionals arising from an inner product.
Definition: IPFunctional.hh:94
virtual std::shared_ptr< array::Vector > solution()
Returns the last solution of the SSA as computed by linearize_at.
Implements the forward problem of the map taking to the corresponding solution of the SSA.
virtual std::shared_ptr< TerminationReason > linesearch()
virtual void apply_GN(array::Scalar &h, array::Scalar &out)
virtual void evaluateGNFunctional(DesignVec &h, double *value)
virtual std::shared_ptr< TerminationReason > init()
virtual std::shared_ptr< TerminationReason > evaluate_objective_and_gradient()
IPInnerProductFunctional< StateVec > & m_stateFunctional
virtual std::shared_ptr< DesignVec > designSolution()
IPInnerProductFunctional< DesignVec > & m_designFunctional
virtual std::shared_ptr< TerminationReason > compute_dlogalpha(double *dalpha)
virtual std::shared_ptr< TerminationReason > solve()
virtual std::shared_ptr< TerminationReason > check_convergence()
virtual std::shared_ptr< TerminationReason > solve_linearized()
virtual void setTargetMisfit(double misfit)
Sets the desired target misfit (in units of ).
virtual std::shared_ptr< StateVec > stateSolution()
IP_SSATaucTikhonovGNSolver(IP_SSATaucForwardProblem &ssaforward, DesignVec &d0, StateVec &u_obs, double eta, IPInnerProductFunctional< DesignVec > &designFunctional, IPInnerProductFunctional< StateVec > &stateFunctional)
static PetscErrorCode callback(Mat A, Vec x, Vec y)
#define PISM_CHK(errcode, name)
void handle_fatal_errors(MPI_Comm com)
const int C[]
Definition: ssafd_code.cc:44