PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
SSAFD.hh
Go to the documentation of this file.
1 // Copyright (C) 2004--2023 Jed Brown, Ed Bueler 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 _SSAFD_H_
20 #define _SSAFD_H_
21 
22 #include "pism/stressbalance/ssa/SSA.hh"
23 
24 #include "pism/util/error_handling.hh"
25 #include "pism/util/petscwrappers/Viewer.hh"
26 #include "pism/util/petscwrappers/KSP.hh"
27 #include "pism/util/petscwrappers/Mat.hh"
28 #include "pism/util/array/Staggered.hh"
29 
30 namespace pism {
31 namespace stressbalance {
32 
33 //! PISM's SSA solver: the finite difference implementation.
34 class SSAFD : public SSA
35 {
36 public:
37  SSAFD(std::shared_ptr<const Grid> g);
38  virtual ~SSAFD() = default;
39 
40  const array::Staggered & integrated_viscosity() const;
41 protected:
42  virtual void init_impl();
43 
44  virtual DiagnosticList diagnostics_impl() const;
45 
46  virtual void pc_setup_bjacobi();
47 
48  virtual void pc_setup_asm();
49 
50  virtual void solve(const Inputs &inputs);
51 
52  virtual void picard_iteration(const Inputs &inputs,
53  double nuH_regularization,
54  double nuH_iter_failure_underrelax);
55 
56  virtual void picard_manager(const Inputs &inputs,
57  double nuH_regularization,
58  double nuH_iter_failure_underrelax);
59 
60  virtual void picard_strategy_regularization(const Inputs &inputs);
61 
62  virtual void compute_hardav_staggered(const Inputs &inputs);
63 
64  virtual void compute_nuH_staggered(const array::Scalar1 &ice_thickness,
65  const array::Vector1 &velocity,
66  const array::Staggered &hardness,
67  double nuH_regularization,
68  array::Staggered &result);
69 
70  virtual void compute_nuH_staggered_cfbc(const array::Scalar1 &ice_thickness,
71  const array::CellType2 &mask,
72  const array::Vector1 &velocity,
73  const array::Staggered &hardness,
74  double nuH_regularization,
75  array::Staggered &result);
76 
77  virtual void compute_nuH_norm(double &norm,
78  double &norm_change);
79 
80  virtual void assemble_matrix(const Inputs &inputs,
81  bool include_basal_shear, Mat A);
82 
83  virtual void assemble_rhs(const Inputs &inputs);
84 
85  virtual void write_system_petsc(const std::string &namepart);
86 
87  virtual void update_nuH_viewers();
88 
89  virtual bool is_marginal(int i, int j, bool ssa_dirichlet_bc);
90 
91  virtual void fracture_induced_softening(const array::Scalar *fracture_density);
92 
93  // objects used internally
96 
97  struct Work {
98  // u_x on the i offset
99  double u_x;
100  // v_x on the i offset
101  double v_x;
102  // weight for the i offset
103  double w_i;
104  // u_y on the j offset
105  double u_y;
106  // v_y on the j offset
107  double v_y;
108  // weight for the j offset
109  double w_j;
110  };
112 
115  array::Vector m_b; // right hand side
116 
118  const double m_scaling;
119 
122 
124  std::shared_ptr<petsc::Viewer> m_nuh_viewer;
126 
127  class KSPFailure : public RuntimeError {
128  public:
129  KSPFailure(const char* reason);
130  };
131 
132  class PicardFailure : public RuntimeError {
133  public:
134  PicardFailure(const std::string &message);
135  };
136 };
137 
138 //! Constructs a new SSAFD
139 SSA * SSAFDFactory(std::shared_ptr<const Grid> grid);
140 
141 } // end of namespace stressbalance
142 } // end of namespace pism
143 
144 #endif /* _SSAFD_H_ */
A storage vector combining related fields in a struct.
Definition: Array2D.hh:32
A class for storing and accessing internal staggered-grid 2D fields. Uses dof=2 storage....
Definition: Staggered.hh:35
KSPFailure(const char *reason)
Definition: SSAFD.cc:39
PicardFailure(const std::string &message)
Definition: SSAFD.cc:44
virtual void compute_nuH_norm(double &norm, double &norm_change)
Compute the norm of nu H and the change in nu H.
Definition: SSAFD.cc:1256
SSAFD(std::shared_ptr< const Grid > g)
Definition: SSAFD.cc:61
const array::Staggered & integrated_viscosity() const
Definition: SSAFD.cc:1767
virtual void init_impl()
Initialize a generic regular-grid SSA solver.
Definition: SSAFD.cc:199
virtual void picard_strategy_regularization(const Inputs &inputs)
Old SSAFD recovery strategy: increase the SSA regularization parameter.
Definition: SSAFD.cc:1210
array::Array2D< Work > m_work
Definition: SSAFD.hh:111
virtual void fracture_induced_softening(const array::Scalar *fracture_density)
Correct vertically-averaged hardness using a parameterization of the fracture-induced softening.
Definition: SSAFD.cc:1363
std::shared_ptr< petsc::Viewer > m_nuh_viewer
Definition: SSAFD.hh:124
virtual ~SSAFD()=default
array::Staggered m_hardness
Definition: SSAFD.hh:94
array::Vector1 m_velocity_old
Definition: SSAFD.hh:117
virtual void update_nuH_viewers()
Update the nuH viewer, which shows log10(nu H).
Definition: SSAFD.cc:1652
array::Staggered1 m_nuH
Definition: SSAFD.hh:95
virtual void compute_nuH_staggered_cfbc(const array::Scalar1 &ice_thickness, const array::CellType2 &mask, const array::Vector1 &velocity, const array::Staggered &hardness, double nuH_regularization, array::Staggered &result)
Compute the product of ice viscosity and thickness on the staggered grid. Used when CFBC is enabled.
Definition: SSAFD.cc:1509
virtual void compute_nuH_staggered(const array::Scalar1 &ice_thickness, const array::Vector1 &velocity, const array::Staggered &hardness, double nuH_regularization, array::Staggered &result)
Compute the product of ice thickness and effective viscosity (on the staggered grid).
Definition: SSAFD.cc:1437
virtual void solve(const Inputs &inputs)
Compute the vertically-averaged horizontal velocity from the shallow shelf approximation.
Definition: SSAFD.cc:940
virtual void write_system_petsc(const std::string &namepart)
Definition: SSAFD.cc:1719
const double m_scaling
Definition: SSAFD.hh:118
virtual DiagnosticList diagnostics_impl() const
Definition: SSAFD.cc:1759
unsigned int m_default_pc_failure_max_count
Definition: SSAFD.hh:121
virtual void assemble_matrix(const Inputs &inputs, bool include_basal_shear, Mat A)
Assemble the left-hand side matrix for the KSP-based, Picard iteration, and finite difference impleme...
Definition: SSAFD.cc:491
virtual void pc_setup_asm()
Definition: SSAFD.cc:146
array::Vector m_b
Definition: SSAFD.hh:115
virtual bool is_marginal(int i, int j, bool ssa_dirichlet_bc)
Checks if a cell is near or at the ice front.
Definition: SSAFD.cc:1698
virtual void compute_hardav_staggered(const Inputs &inputs)
Computes vertically-averaged ice hardness on the staggered grid.
Definition: SSAFD.cc:1276
virtual void picard_iteration(const Inputs &inputs, double nuH_regularization, double nuH_iter_failure_underrelax)
Definition: SSAFD.cc:1001
virtual void picard_manager(const Inputs &inputs, double nuH_regularization, double nuH_iter_failure_underrelax)
Manages the Picard iteration loop.
Definition: SSAFD.cc:1033
virtual void pc_setup_bjacobi()
Definition: SSAFD.cc:122
unsigned int m_default_pc_failure_count
Definition: SSAFD.hh:120
array::Staggered1 m_nuH_old
Definition: SSAFD.hh:95
virtual void assemble_rhs(const Inputs &inputs)
Computes the right-hand side ("rhs") of the linear problem for the Picard iteration and finite-differ...
Definition: SSAFD.cc:233
PISM's SSA solver: the finite difference implementation.
Definition: SSAFD.hh:35
PISM's SSA solver.
Definition: SSA.hh:110
const array::Vector1 & velocity() const
Get the thickness-advective 2D velocity.
SSA * SSAFDFactory(std::shared_ptr< const Grid > g)
Constructs a new SSAFD.
Definition: SSAFD.cc:49
static const double g
Definition: exactTestP.cc:36
std::map< std::string, Diagnostic::Ptr > DiagnosticList
Definition: Diagnostic.hh:125