PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
SIAFD_diagnostics.cc
Go to the documentation of this file.
1 // Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020, 2021, 2022, 2023 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 #include "pism/stressbalance/sia/SIAFD_diagnostics.hh"
20 #include "pism/stressbalance/sia/BedSmoother.hh"
21 #include "pism/util/Vars.hh"
22 #include "pism/util/array/CellType.hh"
23 
24 namespace pism {
25 namespace stressbalance {
26 
28  DiagnosticList result = {
29  {"diffusivity", Diagnostic::Ptr(new SIAFD_diffusivity(this))},
30  {"diffusivity_staggered", Diagnostic::Ptr(new SIAFD_diffusivity_staggered(this))},
31  {"schoofs_theta", Diagnostic::Ptr(new SIAFD_schoofs_theta(this))},
32  {"thksmooth", Diagnostic::Ptr(new SIAFD_thksmooth(this))},
33  {"topgsmooth", Diagnostic::Ptr(new SIAFD_topgsmooth(this))},
34  {"h_x", Diagnostic::Ptr(new SIAFD_h_x(this))},
35  {"h_y", Diagnostic::Ptr(new SIAFD_h_y(this))}
36  };
37  return result;
38 }
39 
41  m_vars = { { m_sys, "schoofs_theta" } };
42 
43  m_vars[0]
44  .long_name("multiplier 'theta' in Schoof's (2003) theory of bed roughness in SIA")
45  .units("1");
46  m_vars[0]["valid_range"] = { 0.0, 1.0 };
47 }
48 
49 std::shared_ptr<array::Array> SIAFD_schoofs_theta::compute_impl() const {
50  const array::Scalar *surface = m_grid->variables().get_2d_scalar("surface_altitude");
51  auto result = allocate<array::Scalar>("schoofs_theta");
52 
53  model->bed_smoother().theta(*surface, *result);
54 
55  return result;
56 }
57 
58 
60  m_vars = { { m_sys, "topgsmooth" } };
61  m_vars[0]
62  .long_name("smoothed bed elevation in Schoof's (2003) theory of bed roughness in SIA")
63  .units("m");
64 }
65 
66 std::shared_ptr<array::Array> SIAFD_topgsmooth::compute_impl() const {
67  auto result = allocate<array::Scalar>("topgsmooth");
68 
69  result->copy_from(model->bed_smoother().smoothed_bed());
70 
71  return result;
72 }
73 
75  : Diag<SIAFD>(m) {
76 
77  m_vars = { { m_sys, "thksmooth" } };
78  m_vars[0]
79  .long_name(
80  "thickness relative to smoothed bed elevation in Schoof's (2003) theory of bed roughness in SIA")
81  .units("m");
82 }
83 
84 std::shared_ptr<array::Array> SIAFD_thksmooth::compute_impl() const {
85 
86  const auto &surface = *m_grid->variables().get_2d_scalar("surface_altitude");
87  const auto &thickness = *m_grid->variables().get_2d_scalar("land_ice_thickness");
88 
89  array::CellType2 cell_type(m_grid, "cell_type");
90  {
91  const auto &mask = *m_grid->variables().get_2d_cell_type("mask");
92  cell_type.copy_from(mask);
93  }
94 
95  auto result = allocate<array::Scalar>("thksmooth");
96 
97  model->bed_smoother().smoothed_thk(surface, thickness, cell_type,
98  *result);
99  return result;
100 }
101 
102 
103 
105  : Diag<SIAFD>(m) {
106 
107  m_vars = { { m_sys, "diffusivity" } };
108  m_vars[0].long_name("diffusivity of SIA mass continuity equation").units("m2 s-1");
109 }
110 
111 std::shared_ptr<array::Array> SIAFD_diffusivity::compute_impl() const {
112  auto result = allocate<array::Scalar>("diffusivity");
113 
114  array::CellType1 cell_type(m_grid, "cell_type");
115  {
116  const auto &mask = *m_grid->variables().get_2d_cell_type("mask");
117  cell_type.copy_from(mask);
118  }
119  bool include_floating_ice = true;
120  staggered_to_regular(cell_type, model->diffusivity(), include_floating_ice, *result);
121 
122  return result;
123 }
124 
126  : Diag<SIAFD>(m) {
127 
128  m_vars = { { m_sys, "diffusivity_i" }, { m_sys, "diffusivity_j" } };
129  m_vars[0]
130  .long_name("diffusivity of SIA mass continuity equation on the staggered grid (i-offset)")
131  .units("m2 s-1");
132  m_vars[1]
133  .long_name("diffusivity of SIA mass continuity equation on the staggered grid (j-offset)")
134  .units("m2 s-1");
135 }
136 
137 static void copy_staggered_vec(const array::Staggered &input, array::Staggered &output) {
138  auto grid = output.grid();
139 
140  array::AccessScope list{ &input, &output };
141 
142  for (auto p = grid->points(); p; p.next()) {
143  const int i = p.i(), j = p.j();
144 
145  output(i, j, 0) = input(i, j, 0);
146  output(i, j, 1) = input(i, j, 1);
147  }
148 }
149 
150 std::shared_ptr<array::Array> SIAFD_diffusivity_staggered::compute_impl() const {
151  auto result = allocate<array::Staggered>("diffusivity");
152 
153  copy_staggered_vec(model->diffusivity(), *result);
154 
155  return result;
156 }
157 
159  : Diag<SIAFD>(m) {
160 
161  m_vars = { { m_sys, "h_x_i" }, { m_sys, "h_x_j" } };
162  m_vars[0].long_name("the x-component of the surface gradient, i-offset").units("1");
163  m_vars[1].long_name("the x-component of the surface gradient, j-offset").units("1");
164 }
165 
166 std::shared_ptr<array::Array> SIAFD_h_x::compute_impl() const {
167  auto result = allocate<array::Staggered>("h_x");
168 
169  copy_staggered_vec(model->surface_gradient_x(), *result);
170 
171  return result;
172 }
173 
175  : Diag<SIAFD>(m) {
176 
177  m_vars = { { m_sys, "h_y_i" }, { m_sys, "h_y_j" } };
178  m_vars[0].long_name("the y-component of the surface gradient, i-offset").units("1");
179  m_vars[1].long_name("the y-component of the surface gradient, j-offset").units("1");
180 }
181 
182 std::shared_ptr<array::Array> SIAFD_h_y::compute_impl() const {
183 
184  auto result = allocate<array::Staggered>("h_y");
185 
186  copy_staggered_vec(model->surface_gradient_y(), *result);
187 
188  return result;
189 }
190 
191 } // end of namespace stressbalance
192 } // end of namespace pism
const SIAFD * model
Definition: Diagnostic.hh:172
A template derived from Diagnostic, adding a "Model".
Definition: Diagnostic.hh:166
const units::System::Ptr m_sys
the unit system
Definition: Diagnostic.hh:116
std::vector< SpatialVariableMetadata > m_vars
metadata corresponding to NetCDF variables
Definition: Diagnostic.hh:120
std::shared_ptr< Diagnostic > Ptr
Definition: Diagnostic.hh:65
std::shared_ptr< const Grid > m_grid
the grid
Definition: Diagnostic.hh:114
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
Definition: Array.hh:65
void copy_from(const Array2D< T > &source)
Definition: Array2D.hh:73
std::shared_ptr< const Grid > grid() const
Definition: Array.cc:132
A class for storing and accessing internal staggered-grid 2D fields. Uses dof=2 storage....
Definition: Staggered.hh:35
virtual std::shared_ptr< array::Array > compute_impl() const
Compute diffusivity of the SIA flow (on the staggered grid).
virtual std::shared_ptr< array::Array > compute_impl() const
Compute diffusivity of the SIA flow.
virtual std::shared_ptr< array::Array > compute_impl() const
Reports the x-component of the ice surface gradient on the staggered grid as computed by SIAFD.
virtual std::shared_ptr< array::Array > compute_impl() const
Reports the y-component of the ice surface gradient on the staggered grid as computed by SIAFD.
virtual std::shared_ptr< array::Array > compute_impl() const
Computes the multiplier in Schoof's (2003) theory of the effect of bed roughness on the diffusivity ...
virtual std::shared_ptr< array::Array > compute_impl() const
Computes the thickness relative to the smoothed bed elevation in Schoof's (2003) theory of the effect...
virtual std::shared_ptr< array::Array > compute_impl() const
Computes the smoothed bed elevation from Schoof's (2003) theory of the effect of bed roughness on the...
virtual DiagnosticList diagnostics_impl() const
void staggered_to_regular(const array::CellType1 &cell_type, const array::Staggered1 &input, bool include_floating_ice, array::Scalar &result)
Definition: Staggered.cc:87
static void copy_staggered_vec(const array::Staggered &input, array::Staggered &output)
std::map< std::string, Diagnostic::Ptr > DiagnosticList
Definition: Diagnostic.hh:125