Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.1-cd005eec8 committed by Constantine Khrulev on 2025-03-07
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SSA.cc
Go to the documentation of this file.
1// Copyright (C) 2004--2019, 2021, 2022, 2023, 2024 Constantine Khroulev, Ed Bueler, Jed Brown, Torsten Albrecht
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#include "pism/stressbalance/ssa/SSA.hh"
20#include "pism/util/EnthalpyConverter.hh"
21#include "pism/rheology/FlowLawFactory.hh"
22#include "pism/util/Mask.hh"
23#include "pism/util/error_handling.hh"
24#include "pism/util/io/File.hh"
25#include "pism/util/array/CellType.hh"
26#include "pism/stressbalance/StressBalance.hh"
27#include "pism/geometry/Geometry.hh"
28
29namespace pism {
30namespace stressbalance {
31
33 m_min_thickness = config.get_number("stress_balance.ssa.strength_extension.min_thickness");
34 m_constant_nu = config.get_number("stress_balance.ssa.strength_extension.constant_nu");
35}
36
37//! Set strength = (viscosity times thickness).
38/*! Determines nu by input strength and current min_thickness. */
40 if (my_nuH <= 0.0) {
41 throw RuntimeError::formatted(PISM_ERROR_LOCATION, "nuH must be positive, got %f", my_nuH);
42 }
44}
45
46//! Set minimum thickness to trigger use of extension.
47/*! Preserves strength (nuH) by also updating using current nu. */
48void SSAStrengthExtension::set_min_thickness(double my_min_thickness) {
49 if (my_min_thickness <= 0.0) {
50 throw RuntimeError::formatted(PISM_ERROR_LOCATION, "min_thickness must be positive, got %f",
51 my_min_thickness);
52 }
53 double nuH = m_constant_nu * m_min_thickness;
54 m_min_thickness = my_min_thickness;
56}
57
58//! Returns strength = (viscosity times thickness).
62
63//! Returns minimum thickness to trigger use of extension.
67
68
69SSA::SSA(std::shared_ptr<const Grid> g)
71 m_velocity_global(m_grid, "bar")
72{
73
74 m_e_factor = m_config->get_number("stress_balance.ssa.enhancement_factor");
75
77
78 // override velocity metadata
79 m_velocity.metadata(0).set_name("u_ssa");
80 m_velocity.metadata(0).long_name("SSA model ice velocity in the X direction");
81
82 m_velocity.metadata(1).set_name("v_ssa");
83 m_velocity.metadata(1).long_name("SSA model ice velocity in the Y direction");
84
85 {
86 rheology::FlowLawFactory ice_factory("stress_balance.ssa.", m_config, m_EC);
87 ice_factory.remove(ICE_GOLDSBY_KOHLSTEDT);
88 m_flow_law = ice_factory.create();
89 }
90}
91
93 if (strength_extension != NULL) {
94 delete strength_extension;
95 strength_extension = NULL;
96 }
97}
98
99
100//! \brief Initialize a generic regular-grid SSA solver.
102
104
105 m_log->message(2, "* Initializing the SSA stress balance...\n");
106 m_log->message(2,
107 " [using the %s flow law]\n", m_flow_law->name().c_str());
108
110
111 // Check if PISM is being initialized from an output file from a previous run
112 // and read the initial guess (unless asked not to).
113 if (opts.type == INIT_RESTART) {
114 if (m_config->get_flag("stress_balance.ssa.read_initial_guess")) {
115 File input_file(m_grid->com, opts.filename, io::PISM_GUESS, io::PISM_READONLY);
116 bool u_ssa_found = input_file.variable_exists("u_ssa");
117 bool v_ssa_found = input_file.variable_exists("v_ssa");
118 unsigned int start = input_file.nrecords() - 1;
119
120 if (u_ssa_found and v_ssa_found) {
121 m_log->message(3, "Reading u_ssa and v_ssa...\n");
122
123 m_velocity.read(input_file, start);
124 }
125 }
126 } else {
127 m_velocity.set(0.0); // default initial guess
128 }
129}
130
131//! \brief Update the SSA solution.
132void SSA::update(const Inputs &inputs, bool full_update) {
133
134 if (full_update) {
135 solve(inputs);
137 *inputs.basal_yield_stress,
138 inputs.geometry->cell_type,
140 }
141}
142
143
144/*!
145 * Estimate velocity at ice-free cells near the ice margin using interpolation from
146 * immediate neighbors that are icy.
147 *
148 * This is used to improve the initial guess of ice viscosity at marginal locations when
149 * ice advances: otherwise we would use the *zero* velocity (if CFBC is "on"), and that is
150 * a poor estimate at best.
151 *
152 * Note: icy cells of `velocity` are treated as read-only, and ice-free marginal cells are
153 * write-only. This means that it's okay for `velocity` to be a input-output argument: we
154 * don't use of the values modified by this method.
155 */
157 array::Vector1 &velocity) const {
158 array::AccessScope list{&cell_type, &velocity};
159
160 for (auto p = m_grid->points(); p; p.next()) {
161 const int i = p.i(), j = p.j();
162
163 if (cell_type.ice_free(i, j) and cell_type.next_to_ice(i, j)) {
164
165 auto M = cell_type.star_int(i, j);
166 auto vel = velocity.star(i, j);
167
168 Vector2d sum{0.0, 0.0};
169 int N = 0;
170 for (auto d : {North, East, South, West}) {
171 if (mask::icy(M[d])) {
172 sum += vel[d];
173 ++N;
174 }
175 }
176 velocity(i, j) = sum / std::max(N, 1);
177 }
178 }
180}
181
182
183std::string SSA::stdout_report() const {
184 return m_stdout_ssa;
185}
186
187void SSA::define_model_state_impl(const File &output) const {
189}
190
191void SSA::write_model_state_impl(const File &output) const {
192 m_velocity.write(output);
193}
194
195} // end of namespace stressbalance
196} // end of namespace pism
#define ICE_GOLDSBY_KOHLSTEDT
const Config::ConstPtr m_config
configuration database used by this component
Definition Component.hh:158
const Logger::ConstPtr m_log
logger (for easy access)
Definition Component.hh:162
const std::shared_ptr< const Grid > m_grid
grid used by this component
Definition Component.hh:156
double get_number(const std::string &name, UseFlag flag=REMEMBER_THIS_USE) const
A class for storing and accessing PISM configuration flags and parameters.
unsigned int nrecords() const
Get the number of records. Uses the length of an unlimited dimension.
Definition File.cc:280
bool variable_exists(const std::string &short_name) const
Checks if a variable exists.
Definition File.cc:378
High-level PISM I/O class.
Definition File.hh:55
array::CellType2 cell_type
Definition Geometry.hh:55
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
VariableMetadata & long_name(const std::string &input)
VariableMetadata & set_name(const std::string &name)
This class represents a 2D vector field (such as ice velocity) at a certain grid point.
Definition Vector2d.hh:29
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
Definition Array.hh:64
stencils::Star< T > star(int i, int j) const
Definition Array2D.hh:79
void read(const std::string &filename, unsigned int time)
Definition Array.cc:731
void define(const File &file, io::Type default_type) const
Define variables corresponding to an Array in a file opened using file.
Definition Array.cc:463
void write(const std::string &filename) const
Definition Array.cc:722
void set(double c)
Result: v[j] <- c for all j.
Definition Array.cc:629
void update_ghosts()
Updates ghost points.
Definition Array.cc:615
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Definition Array.cc:476
bool next_to_ice(int i, int j) const
Ice-free margin (at least one of four neighbors has ice).
Definition CellType.hh:87
stencils::Star< int > star_int(int i, int j) const
Definition Scalar.hh:72
bool ice_free(int i, int j) const
Definition CellType.hh:54
std::shared_ptr< FlowLaw > create()
void remove(const std::string &name)
const array::Scalar * basal_yield_stress
double get_notional_strength() const
Returns strength = (viscosity times thickness).
Definition SSA.cc:59
void set_min_thickness(double my_min_thickness)
Set minimum thickness to trigger use of extension.
Definition SSA.cc:48
SSAStrengthExtension(const Config &c)
Definition SSA.cc:32
double get_min_thickness() const
Returns minimum thickness to trigger use of extension.
Definition SSA.cc:64
void set_notional_strength(double my_nuH)
Set strength = (viscosity times thickness).
Definition SSA.cc:39
Gives an extension coefficient to maintain ellipticity of SSA where ice is thin.
Definition SSA.hh:57
virtual void update(const Inputs &inputs, bool full_update)
Update the SSA solution.
Definition SSA.cc:132
virtual void solve(const Inputs &inputs)=0
SSA(std::shared_ptr< const Grid > g)
Definition SSA.cc:69
void extrapolate_velocity(const array::CellType1 &cell_type, array::Vector1 &velocity) const
Definition SSA.cc:156
virtual void define_model_state_impl(const File &output) const
The default (empty implementation).
Definition SSA.cc:187
SSAStrengthExtension * strength_extension
Definition SSA.hh:115
virtual std::string stdout_report() const
Produce a report string for the standard output.
Definition SSA.cc:183
std::string m_stdout_ssa
Definition SSA.hh:131
virtual void write_model_state_impl(const File &output) const
The default (empty implementation).
Definition SSA.cc:191
virtual void init_impl()
Initialize a generic regular-grid SSA solver.
Definition SSA.cc:101
const array::Vector1 & velocity() const
Get the thickness-advective 2D velocity.
void compute_basal_frictional_heating(const array::Vector &velocity, const array::Scalar &tauc, const array::CellType &mask, array::Scalar &result) const
Compute the basal frictional heating.
std::shared_ptr< rheology::FlowLaw > m_flow_law
Shallow stress balance (such as the SSA).
#define PISM_ERROR_LOCATION
@ PISM_GUESS
Definition IO_Flags.hh:56
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:68
@ PISM_DOUBLE
Definition IO_Flags.hh:52
bool icy(int M)
Ice-filled cell (grounded or floating).
Definition Mask.hh:48
InputOptions process_input_options(MPI_Comm com, Config::ConstPtr config)
Definition Component.cc:43
static const double g
Definition exactTestP.cc:36
@ INIT_RESTART
Definition Component.hh:56
@ North
Definition stencils.hh:24
@ East
Definition stencils.hh:24
@ South
Definition stencils.hh:24
@ West
Definition stencils.hh:24
InitializationType type
initialization type
Definition Component.hh:61
std::string filename
name of the input file (if applicable)
Definition Component.hh:63