PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
IP_SSATaucTaoTikhonovProblemLCL.hh
Go to the documentation of this file.
1 // Copyright (C) 2012, 2014, 2015, 2016, 2017, 2021, 2022, 2023 David Maxwell and Constantine Khroulev
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_SSATAUCTIKHONOVLCL_HH_39UGM4S2
20 #define IP_SSATAUCTIKHONOVLCL_HH_39UGM4S2
21 
22 #include <memory>
23 
24 #include <petscsys.h>
25 
26 #include "pism/inverse/TaoUtil.hh"
27 #include "pism/inverse/IPTwoBlockVec.hh"
28 #include "pism/inverse/IP_SSATaucForwardProblem.hh"
29 #include "pism/inverse/functional/IPFunctional.hh"
30 
31 namespace pism {
32 namespace inverse {
33 
34 class IP_SSATaucTaoTikhonovProblemLCL;
35 
36 //! Iteration callback class for IP_SSATaucTaoTikhonovProblemLCL
37 /*! A class for objects receiving iteration callbacks from a
38  IP_SSATaucTaoTikhonovProblemLCL. These callbacks can be used to
39  monitor the solution, plot iterations, print diagnostic messages,
40  etc. IP_SSATaucTaoTikhonovProblemLCLListeners are ususally used via
41  a reference counted pointer
42  IP_SSATaucTaoTikhonovProblemLCLListeners::Ptr to allow for good
43  memory management when Listeners are created as subclasses of Python
44  classes.*/
46 public:
47 
48  typedef std::shared_ptr<IP_SSATaucTaoTikhonovProblemLCLListener> Ptr;
49 
52 
55 
56  //! Callback called after each iteration.
57  //
58  // @param problem, The class calling the callback.
59  // @param eta Tikhonov penalty parameter.
60  // @param iter Current iteration count.
61  // @param objectiveValue Value of the state functional.
62  // @param designValue Value of the design functional.
63  // @param &d Value of the design variable.
64  // @param &diff_d Diference between design variable and a priori estimate.
65  // @param &grad_d Gradient of design functional
66  // @param &u Value of state variable
67  // @param &diff_u Difference between state variable and desired value.
68  // @param &grad_u Gradient of state functional
69  // @param constraints Residual for state variable being a solution of the %SSA
71  double eta,
72  int iter,
73  double objectiveValue,
74  double designValue,
75  const std::shared_ptr<DesignVec> &d,
76  const std::shared_ptr<DesignVec> &diff_d,
77  const std::shared_ptr<DesignVec> &grad_d,
78  const std::shared_ptr<StateVec> &u,
79  const std::shared_ptr<StateVec> &diff_u,
80  const std::shared_ptr<StateVec> &grad_u,
81  const std::shared_ptr<StateVec> &constraints) = 0;
82 };
83 
84 //! \brief Defines a Tikhonov minimization problem of determining \f$\tau_c\f$ from %SSA velocities to be solved with a TaoBasicSolver using the tao_lcl algorithm.
85 /*! Experimental and not particularly functional. */
87 public:
90 
93 
95 
97  IPFunctional<DesignVec> &designFunctional, IPFunctional<StateVec> &stateFunctional);
98 
99  virtual ~IP_SSATaucTaoTikhonovProblemLCL() = default;
100 
101  virtual void addListener(Listener::Ptr listener) {
102  m_listeners.push_back(listener);
103  }
104 
105  virtual std::shared_ptr<StateVec> stateSolution();
106  virtual std::shared_ptr<DesignVec> designSolution();
107 
108  virtual void setInitialGuess(DesignVec &d0);
109 
110  void connect(Tao tao);
111 
112  void monitorTao(Tao tao);
113 
114  virtual void evaluateObjectiveAndGradient(Tao tao, Vec x, double *value, Vec gradient);
115 
116  virtual std::shared_ptr<TerminationReason> formInitialGuess(Vec *x);
117 
118  virtual void evaluateConstraints(Tao tao, Vec x, Vec r);
119 
120  virtual void evaluateConstraintsJacobianState(Tao tao, Vec x, Mat Jstate, Mat Jpc, Mat Jinv,
121  MatStructure *s);
122 
123  virtual void evaluateConstraintsJacobianDesign(Tao tao, Vec x, Mat Jdesign);
124 
125  virtual void applyConstraintsJacobianDesign(Vec x, Vec y);
126  virtual void applyConstraintsJacobianDesignTranspose(Vec x, Vec y);
127 
128 protected:
129 
131 
132  std::unique_ptr<IPTwoBlockVec> m_x;
133 
135  std::shared_ptr<DesignVecGhosted> m_d;
137  std::shared_ptr<DesignVecGhosted> m_d_diff;
139 
140  std::shared_ptr<StateVec> m_uGlobal;
141  StateVec1 m_u; // ghosted
142  StateVec1 m_du; // ghosted
144  std::shared_ptr<StateVec> m_u_diff;
145 
146  std::shared_ptr<DesignVec> m_grad_design;
147  std::shared_ptr<StateVec> m_grad_state;
148 
149  double m_eta;
150 
151  double m_val_design;
152  double m_val_state;
153 
154  std::shared_ptr<StateVec> m_constraints;
157 
160 
163 
166 
167  std::vector<Listener::Ptr> m_listeners;
168 
169  static PetscErrorCode jacobian_design_callback(Mat A, Vec x, Vec y);
170  static PetscErrorCode jacobian_design_transpose_callback(Mat A, Vec x, Vec y);
171 };
172 
173 } // end of namespace inverse
174 } // end of namespace pism
175 
176 #endif /* end of include guard: IP_SSATAUCTIKHONOVLCL_HH_39UGM4S2 */
Abstract base class for functions from ice model vectors to .
Definition: IPFunctional.hh:41
Implements the forward problem of the map taking to the corresponding solution of the SSA.
std::shared_ptr< IP_SSATaucTaoTikhonovProblemLCLListener > Ptr
virtual void iteration(IP_SSATaucTaoTikhonovProblemLCL &problem, double eta, int iter, double objectiveValue, double designValue, const std::shared_ptr< DesignVec > &d, const std::shared_ptr< DesignVec > &diff_d, const std::shared_ptr< DesignVec > &grad_d, const std::shared_ptr< StateVec > &u, const std::shared_ptr< StateVec > &diff_u, const std::shared_ptr< StateVec > &grad_u, const std::shared_ptr< StateVec > &constraints)=0
Callback called after each iteration.
Iteration callback class for IP_SSATaucTaoTikhonovProblemLCL.
virtual void evaluateObjectiveAndGradient(Tao tao, Vec x, double *value, Vec gradient)
static PetscErrorCode jacobian_design_transpose_callback(Mat A, Vec x, Vec y)
virtual void evaluateConstraintsJacobianState(Tao tao, Vec x, Mat Jstate, Mat Jpc, Mat Jinv, MatStructure *s)
virtual std::shared_ptr< TerminationReason > formInitialGuess(Vec *x)
IP_SSATaucTaoTikhonovProblemLCL(IP_SSATaucForwardProblem &ssaforward, DesignVec &d0, StateVec &u_obs, double eta, IPFunctional< DesignVec > &designFunctional, IPFunctional< StateVec > &stateFunctional)
virtual void evaluateConstraintsJacobianDesign(Tao tao, Vec x, Mat Jdesign)
static PetscErrorCode jacobian_design_callback(Mat A, Vec x, Vec y)
Defines a Tikhonov minimization problem of determining from SSA velocities to be solved with a TaoBa...