PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
PrescribedRetreat.cc
Go to the documentation of this file.
1 /* Copyright (C) 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/PrescribedRetreat.hh"
21 #include "pism/coupler/util/options.hh"
22 #include "pism/util/array/Forcing.hh"
23 
24 namespace pism {
25 
26 PrescribedRetreat::PrescribedRetreat(std::shared_ptr<const Grid> grid)
27  : Component(grid) {
28  ForcingOptions opt(*m_grid->ctx(), "geometry.front_retreat.prescribed");
29  {
30  unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
31 
33 
35  std::make_shared<array::Forcing>(m_grid, file, "land_ice_area_fraction_retreat",
36  "", // no standard name
37  buffer_size, opt.periodic);
38  m_retreat_mask->metadata(0)
39  .long_name("maximum ice extent mask")
40  .units("1");
41  }
42 }
43 
45 
46  ForcingOptions opt(*m_grid->ctx(), "geometry.front_retreat.prescribed");
47 
48  m_log->message(2,
49  "* Initializing the prescribed front retreat mechanism\n"
50  " using a time-dependent ice extent mask '%s' in '%s'...\n",
51  m_retreat_mask->get_name().c_str(), opt.filename.c_str());
52 
53  m_retreat_mask->init(opt.filename, opt.periodic);
54 }
55 
56 void PrescribedRetreat::update(double t, double dt, array::Scalar &ice_thickness,
57  array::Scalar &ice_area_specific_volume) {
58  m_retreat_mask->update(t, dt);
59  m_retreat_mask->average(t, dt);
60 
61  array::AccessScope list{ m_retreat_mask.get(), &ice_thickness, &ice_area_specific_volume };
62 
63  for (auto p = m_grid->points(); p; p.next()) {
64  const int i = p.i(), j = p.j();
65 
66  double f = (*m_retreat_mask)(i, j);
67 
68  if (f <= 0.0) {
69  ice_area_specific_volume(i, j) = 0.0;
70  ice_thickness(i, j) = 0.0;
71  } else if (f < 1.0) {
72  ice_area_specific_volume(i, j) = ice_thickness(i, j) * f;
73  ice_thickness(i, j) = 0.0;
74  } else {
75  // M == 1.0: do nothing
76  }
77  }
78 }
79 
81  auto dt = m_retreat_mask->max_timestep(t);
82 
83  if (dt.finite()) {
84  return MaxTimestep(dt.value(), "prescribed ice retreat");
85  }
86  return MaxTimestep("prescribed ice retreat");
87 }
88 
89 } // 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
High-level PISM I/O class.
Definition: File.hh:56
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
Definition: MaxTimestep.hh:31
std::shared_ptr< array::Forcing > m_retreat_mask
PrescribedRetreat(std::shared_ptr< const Grid > grid)
void update(double t, double dt, array::Scalar &ice_thickness, array::Scalar &ice_area_specific_volume)
MaxTimestep max_timestep_impl(double t) const
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
Definition: Array.hh:65
@ PISM_NETCDF3
Definition: IO_Flags.hh:57
@ PISM_READONLY
open an existing file for reading only
Definition: IO_Flags.hh:72
std::string filename
Definition: options.hh:33