PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
CalvingAtThickness.cc
Go to the documentation of this file.
1/* Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021, 2022, 2023, 2024, 2025 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/coupler/util/options.hh"
25#include "pism/util/array/Forcing.hh"
26#include "pism/util/io/File.hh"
27#include "pism/util/Logger.hh"
28#include "pism/util/io/IO_Flags.hh"
29
30namespace pism {
31
32//! @brief Calving and iceberg removal code.
33namespace calving {
34
35CalvingAtThickness::CalvingAtThickness(std::shared_ptr<const Grid> g)
36 : Component(g),
37 m_old_mask(m_grid, "old_mask") {
38
39 ForcingOptions opt(*m_grid->ctx(), "calving.thickness_calving");
40 {
41 unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
42
44
45 m_calving_threshold = std::make_shared<array::Forcing>(m_grid,
46 file,
47 "thickness_calving_threshold",
48 "", // no standard name
49 buffer_size,
50 opt.periodic,
51 LINEAR);
52
53 m_calving_threshold->metadata(0)
54 .long_name("threshold used by the 'calving at threshold' calving method")
55 .units("m"); // no standard name
56 m_calving_threshold->metadata()["valid_min"] = {0.0};
57 }
58
59 if (not m_config->get_flag("geometry.part_grid.enabled")) {
60 m_log->message(
61 2, "PISM WARNING: Calving at certain terminal ice thickness (-calving thickness_calving)\n"
62 " without application of partially filled grid cell scheme (-part_grid)\n"
63 " may lead to (incorrect) non-moving ice shelf front.\n");
64 }
65}
66
68
69 m_log->message(2, "* Initializing the 'calving at a threshold thickness' mechanism...\n");
70
71 ForcingOptions opt(*m_grid->ctx(), "calving.thickness_calving");
72
74 auto variable_exists = file.variable_exists(m_calving_threshold->get_name());
75 if (variable_exists) {
76 m_log->message(2,
77 " Reading thickness calving threshold from file '%s'...\n",
78 opt.filename.c_str());
79
81 } else {
82 double calving_threshold = m_config->get_number("calving.thickness_calving.threshold");
83
84 auto attributes = m_calving_threshold->metadata();
85 // replace with a constant array::Forcing
87 "thickness_calving_threshold",
88 calving_threshold);
89 // restore metadata
90 m_calving_threshold->metadata() = attributes;
91
92 m_log->message(2,
93 " Thickness threshold: %3.3f meters.\n", calving_threshold);
94 }
95}
96
97/**
98 * Updates ice cover mask and the ice thickness according to the
99 * calving rule removing ice at the shelf front that is thinner than a
100 * given threshold.
101 *
102 * @param[in] t beginning of the time step
103 * @param[in] dt length of the time step
104 * @param[in,out] pism_mask ice cover mask
105 * @param[in,out] ice_thickness ice thickness
106 *
107 * @return 0 on success
108 */
110 double dt,
111 array::Scalar &cell_type,
112 array::Scalar &ice_thickness) {
113
114 m_calving_threshold->update(t, dt);
115 m_calving_threshold->average(t, dt);
116
117 // this call fills ghosts of m_old_mask
118 m_old_mask.copy_from(cell_type);
119
120 const auto &threshold = *m_calving_threshold;
121
122 array::AccessScope list{&cell_type, &ice_thickness, &m_old_mask, &threshold};
123 for (auto p : m_grid->points()) {
124 const int i = p.i(), j = p.j();
125
126 if (m_old_mask.floating_ice(i, j) &&
128 ice_thickness(i, j) < threshold(i, j)) {
129 ice_thickness(i, j) = 0.0;
130 cell_type(i, j) = MASK_ICE_FREE_OCEAN;
131 }
132 }
133
134 cell_type.update_ghosts();
135 ice_thickness.update_ghosts();
136}
137
141
143 return {{"thickness_calving_threshold", Diagnostic::wrap(*m_calving_threshold)}};
144}
145
146} // end of namespace calving
147} // end of namespace pism
std::shared_ptr< const Config > m_config
configuration database used by this component
Definition Component.hh:160
const std::shared_ptr< const Grid > m_grid
grid used by this component
Definition Component.hh:158
std::shared_ptr< const Logger > m_log
logger (for easy access)
Definition Component.hh:164
A class defining a common interface for most PISM sub-models.
Definition Component.hh:118
static Ptr wrap(const T &input)
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:57
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
Definition Array.hh:66
void copy_from(const Array2D< T > &source)
Definition Array2D.hh:101
void update_ghosts()
Updates ghost points.
Definition Array.cc:645
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:148
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)
const array::Scalar & threshold() const
DiagnosticList spatial_diagnostics_impl() const
@ PISM_GUESS
Definition IO_Flags.hh:57
@ PISM_NETCDF3
Definition IO_Flags.hh:58
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:69
static const double g
Definition exactTestP.cc:36
std::map< std::string, Diagnostic::Ptr > DiagnosticList
@ MASK_ICE_FREE_OCEAN
Definition Mask.hh:35
std::string filename
Definition options.hh:33