19 #include "pism/inverse/IP_SSATaucTaoTikhonovProblemLCL.hh"
20 #include "pism/util/Grid.hh"
21 #include "pism/util/ConfigInterface.hh"
22 #include "pism/util/Context.hh"
40 : m_ssaforward(ssaforward),
41 m_dGlobal(d0.grid(),
"design variable (global)"),
43 m_dzeta(d0.grid(),
"dzeta"),
44 m_u(d0.grid(),
"state variable"),
45 m_du(d0.grid(),
"du"),
48 m_d_Jdesign(d0.grid(),
"Jdesign design variable"),
49 m_u_Jdesign(d0.grid(),
"Jdesign state variable"),
50 m_designFunctional(designFunctional),
51 m_stateFunctional(stateFunctional)
55 std::shared_ptr<const Grid> grid =
m_d0.
grid();
57 double stressScale = grid->ctx()->config()->get_number(
"inverse.design.param_tauc_scale");
60 m_velocityScale = grid->ctx()->config()->get_number(
"inverse.ssa.velocity_scale",
"m second-1");
80 ierr = DMSetMatType(da, MATBAIJ);
86 int nLocalNodes = grid->xm()*grid->ym();
87 int nGlobalNodes = grid->Mx()*grid->My();
88 ierr = MatCreateShell(grid->com, 2*nLocalNodes, nLocalNodes, 2*nGlobalNodes, nGlobalNodes,
92 ierr = MatShellSetOperation(
m_Jdesign, MATOP_MULT,
94 PISM_CHK(ierr,
"MatShellSetOperation");
96 ierr = MatShellSetOperation(
m_Jdesign, MATOP_MULT_TRANSPOSE,
98 PISM_CHK(ierr,
"MatShellSetOperation");
107 std::shared_ptr<IP_SSATaucTaoTikhonovProblemLCL::StateVec>
116 std::shared_ptr<IP_SSATaucTaoTikhonovProblemLCL::DesignVec>
118 m_x->scatterToA(
m_d->vec());
124 ierr = TaoSetStateDesignIS(tao,
125 m_x->blockBIndexSet() ,
126 m_x->blockAIndexSet() );
127 PISM_CHK(ierr,
"TaoSetStateDesignIS");
144 ierr = TaoGetSolutionStatus(tao, &its, NULL, NULL, NULL, NULL, NULL);
145 PISM_CHK(ierr,
"TaoGetSolutionStatus");
148 for (
int k = 0;
k < nListeners;
k++) {
160 double *value, Vec gradient) {
189 if (reason->failed()) {
239 *s = SAME_NONZERO_PATTERN;
260 PISM_CHK(ierr,
"DMGlobalToLocalBegin");
263 PISM_CHK(ierr,
"DMGlobalToLocalEnd");
277 ierr = DMGlobalToLocalBegin(*
m_du.
dm(), x, INSERT_VALUES,
m_du.
vec());
278 PISM_CHK(ierr,
"DMGlobalToLocalBegin");
280 ierr = DMGlobalToLocalEnd(*
m_du.
dm(), x, INSERT_VALUES,
m_du.
vec());
281 PISM_CHK(ierr,
"DMGlobalToLocalEnd");
294 PetscErrorCode ierr = MatShellGetContext(A,&ctx);
295 PISM_CHK(ierr,
"MatShellGetContext");
299 MPI_Comm com = MPI_COMM_SELF;
300 PetscErrorCode ierr = PetscObjectGetComm((PetscObject)A, &com); CHKERRQ(ierr);
302 SETERRQ(com, 1,
"A PISM callback failed");
311 PetscErrorCode ierr = MatShellGetContext(A,&ctx);
312 PISM_CHK(ierr,
"MatShellGetContext");
316 MPI_Comm com = MPI_COMM_SELF;
317 PetscErrorCode ierr = PetscObjectGetComm((PetscObject)A, &com); CHKERRQ(ierr);
319 SETERRQ(com, 1,
"A PISM callback failed");
static std::shared_ptr< TerminationReason > success()
void copy_from(const Array2D< T > &source)
std::shared_ptr< const Grid > grid() const
std::shared_ptr< petsc::DM > dm() const
virtual void valueAt(IMVecType &x, double *OUTPUT)=0
Computes the value of the functional at the vector x.
virtual void gradientAt(IMVecType &x, IMVecType &gradient)=0
Computes the gradient of the functional at the vector x.
Abstract base class for functions from ice model vectors to .
virtual void apply_jacobian_design(array::Vector &u, array::Scalar &dzeta, array::Vector &du)
Applies the design Jacobian matrix to a perturbation of the design variable.
virtual void apply_jacobian_design_transpose(array::Vector &u, array::Vector &du, array::Scalar &dzeta)
Applies the transpose of the design Jacobian matrix to a perturbation of the state variable.
virtual std::shared_ptr< array::Vector > solution()
Returns the last solution of the SSA as computed by linearize_at.
petsc::DM & get_da() const
Exposes the DMDA of the underlying grid for the benefit of TAO.
virtual void assemble_residual(array::Vector &u, array::Vector &R)
Computes the residual function as defined in the class-level documentation.
virtual std::shared_ptr< TerminationReason > linearize_at(array::Scalar &zeta)
Sets the current value of the design variable and solves the SSA to find the associated .
virtual void set_design(array::Scalar &zeta)
Sets the current value of of the design paramter .
virtual void assemble_jacobian_state(array::Vector &u, Mat J)
Assembles the state Jacobian matrix.
Implements the forward problem of the map taking to the corresponding solution of the SSA.
std::shared_ptr< DesignVecGhosted > m_d
IPFunctional< array::Scalar > & m_designFunctional
array::Scalar1 m_d_Jdesign
virtual std::shared_ptr< StateVec > stateSolution()
array::Vector1 m_u_Jdesign
virtual void applyConstraintsJacobianDesignTranspose(Vec x, Vec y)
virtual std::shared_ptr< DesignVec > designSolution()
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 evaluateConstraints(Tao tao, Vec x, Vec r)
std::shared_ptr< DesignVec > m_grad_design
virtual void setInitialGuess(DesignVec &d0)
std::vector< Listener::Ptr > m_listeners
IPFunctional< array::Vector > & m_stateFunctional
std::shared_ptr< StateVec > m_grad_state
std::shared_ptr< StateVec > m_constraints
std::shared_ptr< DesignVecGhosted > m_d_diff
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)
std::unique_ptr< IPTwoBlockVec > m_x
array::Scalar1 DesignVecGhosted
std::shared_ptr< StateVec > m_u_diff
IP_SSATaucForwardProblem & m_ssaforward
virtual void applyConstraintsJacobianDesign(Vec x, Vec y)
virtual void evaluateConstraintsJacobianDesign(Tao tao, Vec x, Mat Jdesign)
static PetscErrorCode jacobian_design_callback(Mat A, Vec x, Vec y)
double m_constraintsScale
std::shared_ptr< StateVec > m_uGlobal
Defines a Tikhonov minimization problem of determining from SSA velocities to be solved with a TaoBa...
static void connect(Tao tao, Problem &p, Vec c, Mat Jc, Mat Jd, Mat Jcpc=NULL, Mat Jcinv=NULL)
static void connect(Tao tao, Problem &p)
Adaptor to connect a TAO objective and gradient function callback to a C++ object method.
#define PISM_CHK(errcode, name)
void handle_fatal_errors(MPI_Comm com)