PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
CalvingAtThickness.cc
Go to the documentation of this file.
1 /* Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021, 2022, 2023 PISM Authors
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 
20 #include "pism/frontretreat/calving/CalvingAtThickness.hh"
21 
22 #include "pism/util/Mask.hh"
23 #include "pism/util/Grid.hh"
24 #include "pism/util/pism_utilities.hh"
25 #include "pism/coupler/util/options.hh"
26 #include "pism/util/array/Forcing.hh"
27 #include "pism/util/io/File.hh"
28 
29 namespace pism {
30 
31 //! @brief Calving and iceberg removal code.
32 namespace calving {
33 
34 CalvingAtThickness::CalvingAtThickness(std::shared_ptr<const Grid> g)
35  : Component(g),
36  m_old_mask(m_grid, "old_mask") {
37 
38  ForcingOptions opt(*m_grid->ctx(), "calving.thickness_calving");
39  {
40  unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
41 
43 
44  m_calving_threshold = std::make_shared<array::Forcing>(m_grid,
45  file,
46  "thickness_calving_threshold",
47  "", // no standard name
48  buffer_size,
49  opt.periodic,
50  LINEAR);
51 
52  m_calving_threshold->metadata(0)
53  .long_name("threshold used by the 'calving at threshold' calving method")
54  .units("m"); // no standard name
55  m_calving_threshold->metadata()["valid_min"] = {0.0};
56  }
57 }
58 
60 
61  m_log->message(2, "* Initializing the 'calving at a threshold thickness' mechanism...\n");
62 
63  ForcingOptions opt(*m_grid->ctx(), "calving.thickness_calving");
64 
66  auto variable_exists = file.find_variable(m_calving_threshold->get_name());
67  if (variable_exists) {
68  m_log->message(2,
69  " Reading thickness calving threshold from file '%s'...\n",
70  opt.filename.c_str());
71 
72  m_calving_threshold->init(opt.filename, opt.periodic);
73  } else {
74  double calving_threshold = m_config->get_number("calving.thickness_calving.threshold");
75 
76  SpatialVariableMetadata attributes = m_calving_threshold->metadata();
77  // replace with a constant array::Forcing
79  "thickness_calving_threshold",
80  calving_threshold);
81  // restore metadata
82  m_calving_threshold->metadata() = attributes;
83 
84  m_log->message(2,
85  " Thickness threshold: %3.3f meters.\n", calving_threshold);
86  }
87 }
88 
89 /**
90  * Updates ice cover mask and the ice thickness according to the
91  * calving rule removing ice at the shelf front that is thinner than a
92  * given threshold.
93  *
94  * @param[in] t beginning of the time step
95  * @param[in] dt length of the time step
96  * @param[in,out] pism_mask ice cover mask
97  * @param[in,out] ice_thickness ice thickness
98  *
99  * @return 0 on success
100  */
102  double dt,
103  array::Scalar &cell_type,
104  array::Scalar &ice_thickness) {
105 
106  m_calving_threshold->update(t, dt);
107  m_calving_threshold->average(t, dt);
108 
109  // this call fills ghosts of m_old_mask
110  m_old_mask.copy_from(cell_type);
111 
112  const auto &threshold = *m_calving_threshold;
113 
114  array::AccessScope list{&cell_type, &ice_thickness, &m_old_mask, &threshold};
115  for (auto p = m_grid->points(); p; p.next()) {
116  const int i = p.i(), j = p.j();
117 
118  if (m_old_mask.floating_ice(i, j) &&
120  ice_thickness(i, j) < threshold(i, j)) {
121  ice_thickness(i, j) = 0.0;
122  cell_type(i, j) = MASK_ICE_FREE_OCEAN;
123  }
124  }
125 
126  cell_type.update_ghosts();
127  ice_thickness.update_ghosts();
128 }
129 
131  return *m_calving_threshold;
132 }
133 
135  return {{"thickness_calving_threshold", Diagnostic::wrap(*m_calving_threshold)}};
136 }
137 
138 } // end of namespace calving
139 } // end of namespace pism
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
A class defining a common interface for most PISM sub-models.
Definition: Component.hh:118
static Ptr wrap(const T &input)
Definition: Diagnostic.hh:160
VariableLookupData find_variable(const std::string &short_name, const std::string &std_name) const
Find a variable using its standard name and/or short name.
Definition: File.cc:361
High-level PISM I/O class.
Definition: File.hh:56
Spatial NetCDF variable (corresponding to a 2D or 3D scalar field).
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
void update_ghosts()
Updates ghost points.
Definition: Array.cc:693
bool next_to_ice_free_ocean(int i, int j) const
Definition: CellType.hh:106
bool floating_ice(int i, int j) const
Definition: CellType.hh:50
static std::shared_ptr< Forcing > Constant(std::shared_ptr< const Grid > grid, const std::string &short_name, double value)
Definition: Forcing.cc:147
std::shared_ptr< array::Forcing > m_calving_threshold
void update(double t, double dt, array::Scalar &cell_type, array::Scalar &ice_thickness)
CalvingAtThickness(std::shared_ptr< const Grid > g)
DiagnosticList diagnostics_impl() const
const array::Scalar & threshold() const
@ PISM_GUESS
Definition: IO_Flags.hh:56
@ PISM_NETCDF3
Definition: IO_Flags.hh:57
@ PISM_READONLY
open an existing file for reading only
Definition: IO_Flags.hh:72
static const double g
Definition: exactTestP.cc:36
std::map< std::string, Diagnostic::Ptr > DiagnosticList
Definition: Diagnostic.hh:125
@ MASK_ICE_FREE_OCEAN
Definition: Mask.hh:35
std::string filename
Definition: options.hh:33