PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
SSAFEM.hh
Go to the documentation of this file.
1 // Copyright (C) 2009--2017, 2020, 2021, 2022, 2023 Jed Brown and Ed Bueler and Constantine Khroulev and 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 _SSAFEM_H_
20 #define _SSAFEM_H_
21 
22 #include "pism/stressbalance/ssa/SSA.hh"
23 #include "pism/util/fem/FEM.hh"
24 #include "pism/util/petscwrappers/SNES.hh"
25 #include "pism/util/TerminationReason.hh"
26 #include "pism/util/Mask.hh"
27 
28 namespace pism {
29 
30 namespace stressbalance {
31 
32 //! Factory function for constructing a new SSAFEM.
33 SSA * SSAFEMFactory(std::shared_ptr<const Grid> grid);
34 
35 //! PISM's SSA solver: the finite element method implementation written by Jed and David
36 /*!
37  Jed's original code is in rev 831: src/base/ssaJed/...
38  The SSAFEM duplicates most of the functionality of SSAFD, using the finite element method.
39 */
40 class SSAFEM : public SSA {
41 public:
42  SSAFEM(std::shared_ptr<const Grid> g);
43 
44  virtual ~SSAFEM() = default;
45 
46 protected:
47  virtual void init_impl();
48  void cache_inputs(const Inputs &inputs);
49 
50  //! Storage for SSA coefficients at element nodes.
51  //!
52  //! All fields must be "double" or structures containing "double"
53  //! for array::Array2D<T> to work correctly.
54  struct Coefficients {
55  //! ice thickness
56  double thickness;
57  //! bed elevation
58  double bed;
59  //! sea level
60  double sea_level;
61  //! basal yield stress
62  double tauc;
63  //! ice hardness
64  double hardness;
65  //! prescribed gravitational driving stress
67  };
68 
71 
73  double m_alpha;
74  double m_rho_g;
75 
77 
78  void quad_point_values(const fem::Element &Q,
79  const Coefficients *x,
80  int *mask,
81  double *thickness,
82  double *tauc,
83  double *hardness) const;
84 
86  const Coefficients *x,
87  Vector2d *driving_stress) const;
88 
89  void driving_stress(const fem::Element &E,
90  const Coefficients *x,
91  Vector2d *driving_stress) const;
92 
93  void PointwiseNuHAndBeta(double thickness,
94  double hardness,
95  int mask,
96  double tauc,
97  const Vector2d &U,
98  const Vector2d &U_x,
99  const Vector2d &U_y,
100  double *nuH, double *dnuH,
101  double *beta, double *dbeta);
102 
103  void compute_local_function(Vector2d const *const *const velocity,
104  Vector2d **residual);
105 
106  void compute_local_jacobian(Vector2d const *const *const velocity, Mat J);
107 
108  virtual void solve(const Inputs &inputs);
109 
110  std::shared_ptr<TerminationReason> solve_with_reason(const Inputs &inputs);
111 
112  std::shared_ptr<TerminationReason> solve_nocache();
113 
114  //! Adaptor for gluing SNESDAFormFunction callbacks to an SSAFEM.
115  /* The callbacks from SNES are mediated via SNESDAFormFunction, which has the
116  convention that its context argument is a pointer to a struct
117  having a DA as its first entry. The CallbackData fulfills
118  this requirement, and allows for passing the callback on to an honest
119  SSAFEM object. */
120  struct CallbackData {
121  DM da;
123  };
124 
125  // objects used internally
127 
129 
130  //! Storage for node types (interior, boundary, exterior).
132  //! Boundary integral (CFBC contribution to the residual).
134 
138 
141  // fem::P1Element m_p1_element;
142 
143  // Support for direct specification of driving stress to the FEM SSA solver. This helps
144  // with certain test cases where the grid is periodic but the driving stress cannot be the
145  // gradient of a periodic function. (See commit ffb4be16.)
148 private:
149  void cache_residual_cfbc(const Inputs &inputs);
150  void monitor_jacobian(Mat Jac);
151  void monitor_function(Vector2d const *const *const velocity_global,
152  Vector2d const *const *const residual_global);
153 
154  //! SNES callbacks.
155  /*! These simply forward the call on to the SSAFEM member of the CallbackData */
156  static PetscErrorCode function_callback(DMDALocalInfo *info,
157  Vector2d const *const *const velocity,
158  Vector2d **residual,
159  CallbackData *fe);
160  static PetscErrorCode jacobian_callback(DMDALocalInfo *info,
161  Vector2d const *const *const xg,
162  Mat A, Mat J, CallbackData *fe);
163 };
164 
165 
166 } // end of namespace stressbalance
167 } // end of namespace pism
168 
169 #endif /* _SSAFEM_H_ */
This class represents a 2D vector field (such as ice velocity) at a certain grid point.
Definition: Vector2d.hh:29
A storage vector combining related fields in a struct.
Definition: Array2D.hh:32
Manages iterating over element indices.
The mapping from global to local degrees of freedom.
Definition: Element.hh:61
Q1 element with sides parallel to X and Y axes.
Definition: Element.hh:257
void compute_local_function(Vector2d const *const *const velocity, Vector2d **residual)
Implements the callback for computing the residual.
Definition: SSAFEM.cc:726
std::shared_ptr< TerminationReason > solve_with_reason(const Inputs &inputs)
Definition: SSAFEM.cc:174
void PointwiseNuHAndBeta(double thickness, double hardness, int mask, double tauc, const Vector2d &U, const Vector2d &U_x, const Vector2d &U_y, double *nuH, double *dnuH, double *beta, double *dbeta)
Compute the "(regularized effective viscosity) x (ice thickness)" and effective viscous bed strength ...
Definition: SSAFEM.cc:494
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.
Definition: SSAFEM.cc:336
const array::Scalar * m_driving_stress_x
Definition: SSAFEM.hh:146
static PetscErrorCode function_callback(DMDALocalInfo *info, Vector2d const *const *const velocity, Vector2d **residual, CallbackData *fe)
SNES callbacks.
Definition: SSAFEM.cc:1202
void cache_inputs(const Inputs &inputs)
Initialize stored data from the coefficients in the SSA. Called by SSAFEM::solve.
Definition: SSAFEM.cc:258
void compute_local_jacobian(Vector2d const *const *const velocity, Mat J)
Implements the callback for computing the Jacobian.
Definition: SSAFEM.cc:948
SSAFEM(std::shared_ptr< const Grid > g)
Definition: SSAFEM.cc:46
CallbackData m_callback_data
Definition: SSAFEM.hh:126
virtual ~SSAFEM()=default
array::Vector1 m_boundary_integral
Boundary integral (CFBC contribution to the residual).
Definition: SSAFEM.hh:133
void monitor_jacobian(Mat Jac)
Definition: SSAFEM.cc:1160
void explicit_driving_stress(const fem::Element &E, const Coefficients *x, Vector2d *driving_stress) const
Definition: SSAFEM.cc:370
static PetscErrorCode jacobian_callback(DMDALocalInfo *info, Vector2d const *const *const xg, Mat A, Mat J, CallbackData *fe)
Definition: SSAFEM.cc:1218
array::Scalar1 m_bc_mask
Definition: SSAFEM.hh:69
virtual void solve(const Inputs &inputs)
Definition: SSAFEM.cc:160
fem::Q1Element2 m_q1_element
Definition: SSAFEM.hh:140
GeometryCalculator m_gc
Definition: SSAFEM.hh:72
virtual void init_impl()
Initialize a generic regular-grid SSA solver.
Definition: SSAFEM.cc:117
std::shared_ptr< TerminationReason > solve_nocache()
Definition: SSAFEM.cc:184
void cache_residual_cfbc(const Inputs &inputs)
Compute and cache residual contributions from the integral over the lateral boundary.
Definition: SSAFEM.cc:542
fem::ElementIterator m_element_index
Definition: SSAFEM.hh:139
const array::Scalar * m_driving_stress_y
Definition: SSAFEM.hh:147
void monitor_function(Vector2d const *const *const velocity_global, Vector2d const *const *const residual_global)
Definition: SSAFEM.cc:904
array::Scalar1 m_node_type
Storage for node types (interior, boundary, exterior).
Definition: SSAFEM.hh:131
array::Vector1 m_bc_values
Definition: SSAFEM.hh:70
array::Array2D< Coefficients > m_coefficients
Definition: SSAFEM.hh:76
PISM's SSA solver: the finite element method implementation written by Jed and David.
Definition: SSAFEM.hh:40
const array::Vector & driving_stress() const
Definition: SSA.cc:389
PISM's SSA solver.
Definition: SSA.hh:110
const array::Vector1 & velocity() const
Get the thickness-advective 2D velocity.
SSA * SSAFEMFactory(std::shared_ptr< const Grid > g)
Factory function for constructing a new SSAFEM.
Definition: SSAFEM.cc:112
static const double g
Definition: exactTestP.cc:36
const int J[]
Definition: ssafd_code.cc:34
Adaptor for gluing SNESDAFormFunction callbacks to an SSAFEM.
Definition: SSAFEM.hh:120
double tauc
basal yield stress
Definition: SSAFEM.hh:62
Vector2d driving_stress
prescribed gravitational driving stress
Definition: SSAFEM.hh:66