19 #include "pism/inverse/IP_SSATaucForwardProblem.hh"
20 #include "pism/basalstrength/basal_resistance.hh"
21 #include "pism/util/Grid.hh"
22 #include "pism/util/Mask.hh"
23 #include "pism/util/Vars.hh"
24 #include "pism/util/error_handling.hh"
25 #include "pism/util/pism_utilities.hh"
26 #include "pism/geometry/Geometry.hh"
27 #include "pism/stressbalance/StressBalance.hh"
28 #include "pism/util/petscwrappers/DM.hh"
29 #include "pism/util/petscwrappers/Vec.hh"
38 m_dzeta_local(m_grid,
"d_zeta_local"),
39 m_tauc_copy(m_grid,
"tauc"),
40 m_fixed_tauc_locations(NULL),
42 m_du_global(m_grid,
"linearization work vector (sans ghosts)"),
43 m_du_local(m_grid,
"linearization work vector (with ghosts)"),
44 m_element_index(*m_grid),
45 m_element(*m_grid, fem::Q1Quadrature4()),
46 m_rebuild_J_state(true)
56 .
long_name(
"yield stress for basal till (plastic or pseudo-plastic model)")
59 ierr = DMSetMatType(*
m_da, MATBAIJ);
67 double ksp_rtol = 1e-12;
68 ierr = KSPSetTolerances(
m_ksp, ksp_rtol, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT);
72 ierr = KSPGetPC(
m_ksp, &pc);
75 ierr = PCSetType(pc, PCBJACOBI);
78 ierr = KSPSetFromOptions(
m_ksp);
107 inputs.
bc_mask =
m_grid->variables().get_2d_mask(
"vel_bc_mask");
137 for (
auto p =
m_grid->points(1); p; p.next()) {
138 const int i = p.i(), j = p.j();
231 dzeta_local = &dzeta;
236 list.
add(*dzeta_local);
239 for (
auto p =
m_grid->points(); p; p.next()) {
240 const int i = p.i(), j = p.j();
261 double dtauc_q[Nq_max];
276 for (
int j = ys; j < ys + ym; j++) {
277 for (
int i = xs; i < xs + xm; i++) {
280 for (
unsigned int k = 0;
k < Nk;
k++) {
305 for (
unsigned int k = 0;
k < Nk;
k++) {
307 dtauc_e[
k] *= dzeta_e[
k];
314 double thickness[Nq_max];
316 double hardness[Nq_max];
321 mask, thickness, tauc, hardness);
324 for (
unsigned int q = 0; q < Nq; q++) {
335 for (
unsigned int k = 0;
k < Nk;
k++) {
423 for (
auto p =
m_grid->points(); p; p.next()) {
424 const int i = p.i(), j = p.j();
437 for (
int j=ys; j<ys+ym; j++) {
438 for (
int i=xs; i<xs+xm; i++) {
457 for (
unsigned int k=0;
k<Nk;
k++) {
464 double thickness[Nq_max];
466 double hardness[Nq_max];
471 mask, thickness, tauc, hardness);
474 for (
unsigned int q=0; q<Nq; q++) {
479 double dbeta_dtauc = 0;
486 for (
unsigned int k=0;
k<Nk;
k++) {
499 for (
auto p =
m_grid->points(); p; p.next()) {
500 const int i = p.i(), j = p.j();
504 dzeta_a[j][i] *= dtauc_dzeta;
545 KSPConvergedReason reason;
546 ierr = KSPGetConvergedReason(
m_ksp, &reason);
547 PISM_CHK(ierr,
"KSPGetConvergedReason");
550 "IP_SSATaucForwardProblem::apply_linearization solve"
551 " failed to converge (KSP reason %s)",
552 KSPConvergedReasons[reason]);
555 "IP_SSATaucForwardProblem::apply_linearization converged"
556 " (KSP reason %s)\n",
557 KSPConvergedReasons[reason]);
611 KSPConvergedReason reason;
612 ierr = KSPGetConvergedReason(
m_ksp, &reason);
613 PISM_CHK(ierr,
"KSPGetConvergedReason");
617 "IP_SSATaucForwardProblem::apply_linearization solve"
618 " failed to converge (KSP reason %s)",
619 KSPConvergedReasons[reason]);
622 "IP_SSATaucForwardProblem::apply_linearization converged"
623 " (KSP reason %s)\n",
624 KSPConvergedReasons[reason]);
const Config::ConstPtr m_config
configuration database used by this component
const Logger::ConstPtr m_log
logger (for easy access)
const std::shared_ptr< const Grid > m_grid
grid used by this component
array::Scalar1 sea_level_elevation
void ensure_consistency(double ice_free_thickness_threshold)
array::Scalar1 ice_area_specific_volume
array::Scalar2 ice_thickness
array::Scalar2 bed_elevation
virtual double drag(double tauc, double vx, double vy) const
Compute the drag coefficient for the basal shear stress.
void failed()
Indicates a failure of a parallel section.
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
This class represents a 2D vector field (such as ice velocity) at a certain grid point.
std::shared_ptr< Wrapper > Ptr
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
void copy_from(const Array2D< T > &source)
void add(double alpha, const Array2D< T > &x)
void scale(double alpha)
Result: v <- v * alpha. Calls VecScale.
void set(double c)
Result: v[j] <- c for all j.
void update_ghosts()
Updates ghost points.
unsigned int stencil_width() const
Get the stencil width of the current Array. Returns 0 if ghosts are not available.
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
void enforce_homogeneous(const Element2 &element, double *x_e)
void fix_residual_homogeneous(double **r_global)
void enforce(const Element2 &element, Vector2d *x_e)
void fix_residual_homogeneous(Vector2d **r)
void enforce_homogeneous(const Element2 &element, Vector2d *x_e)
void constrain(Element2 &element)
Constrain element, i.e. ensure that quadratures do not contribute to Dirichlet nodes by marking corre...
void evaluate(const T *x, T *vals, T *dx, T *dy)
Given nodal values, compute the values and partial derivatives at the quadrature points.
void reset(int i, int j)
Initialize the Element to element (i, j) for the purposes of inserting into global residual and Jacob...
void add_contribution(const T *local, T **y_global) const
Add the values of element-local contributions y to the global vector y_global.
void nodal_values(const array::Scalar &x_global, int *result) const
Get nodal values of an integer mask.
int xm
total number of elements to loop over in the x-direction.
int ym
total number of elements to loop over in the y-direction.
int ys
y-coordinate of the first element to loop over.
int xs
x-coordinate of the first element to loop over.
const Germ & chi(unsigned int q, unsigned int k) const
int n_pts() const
Number of quadrature points.
double weight(unsigned int q) const
Weight of the quadrature point q
virtual void convertToDesignVariable(array::Scalar &zeta, array::Scalar &d, bool communicate=true)
Transforms a vector of values to a vector of values.
virtual void toDesignVariable(double zeta, double *value, double *derivative)=0
Converts from parameterization value 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.
array::Scalar * m_fixed_tauc_locations
Locations where should not be adjusted.
IPDesignVariableParameterization & m_tauc_param
The function taking to .
bool m_rebuild_J_state
Flag indicating that the state jacobian matrix needs rebuilding.
fem::Q1Element2 m_element
array::Scalar * m_zeta
Current value of zeta, provided from caller.
petsc::KSP m_ksp
KSP used in apply_linearization and apply_linearization_transpose.
virtual void apply_linearization(array::Scalar &dzeta, array::Vector &du)
Applies the linearization of the forward map (i.e. the reduced gradient described in the class-level...
petsc::Mat m_J_state
Mat used in apply_linearization and apply_linearization_transpose.
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 .
std::shared_ptr< array::Vector > m_velocity_shared
Copy of the velocity field managed using a shared pointer.
virtual void apply_linearization_transpose(array::Vector &du, array::Scalar &dzeta)
Applies the transpose of the linearization of the forward map (i.e. the transpose of the reduced grad...
array::Vector1 m_du_local
Temporary storage when state vectors need to be used with ghosts.
fem::ElementIterator m_element_index
array::Vector m_du_global
Temporary storage when state vectors need to be used without ghosts.
IP_SSATaucForwardProblem(std::shared_ptr< const Grid > g, IPDesignVariableParameterization &tp)
virtual void set_design(array::Scalar &zeta)
Sets the current value of of the design paramter .
array::Scalar1 m_dzeta_local
Storage for d_zeta with ghosts, if needed when an argument d_zeta is ghost-less.
virtual void assemble_jacobian_state(array::Vector &u, Mat J)
Assembles the state Jacobian matrix.
array::Scalar2 m_tauc_copy
Storage for tauc (avoids modifying fields obtained via pism::Vars)
void compute_local_function(Vector2d const *const *const velocity, Vector2d **residual)
Implements the callback for computing the residual.
void quad_point_values(const fem::Element &Q, const Coefficients *x, int *mask, double *thickness, double *tauc, double *hardness) const
Compute quadrature point values of various coefficients given a quadrature Q and nodal values.
void cache_inputs(const Inputs &inputs)
Initialize stored data from the coefficients in the SSA. Called by SSAFEM::solve.
void compute_local_jacobian(Vector2d const *const *const velocity, Mat J)
Implements the callback for computing the Jacobian.
std::shared_ptr< TerminationReason > solve_nocache()
array::Vector1 m_bc_values
array::Array2D< Coefficients > m_coefficients
std::shared_ptr< petsc::DM > m_da
IceBasalResistancePlasticLaw * m_basal_sliding_law
array::Vector2 m_velocity
#define PISM_CHK(errcode, name)
#define PISM_ERROR_LOCATION
const unsigned int MAX_QUADRATURE_SIZE
double val
Function value.