PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
BedDef.cc
Go to the documentation of this file.
1 // Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 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/earth/BedDef.hh"
20 #include "pism/util/Grid.hh"
21 #include "pism/util/ConfigInterface.hh"
22 #include "pism/util/Context.hh"
23 
24 namespace pism {
25 namespace bed {
26 
27 BedDef::BedDef(std::shared_ptr<const Grid> grid)
28  : Component(grid),
29  m_wide_stencil(m_config->get_number("grid.max_stencil_width")),
30  m_topg(m_grid, "topg"),
31  m_topg_last(m_grid, "topg"),
32  m_uplift(m_grid, "dbdt")
33 {
34 
35  m_topg.metadata(0)
36  .long_name("bedrock surface elevation")
37  .units("m")
38  .standard_name("bedrock_altitude");
39 
41  .long_name("bedrock surface elevation")
42  .units("m")
43  .standard_name("bedrock_altitude");
44 
46  .long_name("bedrock uplift rate")
47  .units("m s-1")
48  .standard_name("tendency_of_bedrock_altitude");
49 }
50 
52  return m_topg;
53 }
54 
55 const array::Scalar &BedDef::uplift() const {
56  return m_uplift;
57 }
58 
59 void BedDef::define_model_state_impl(const File &output) const {
61  m_topg.define(output, io::PISM_DOUBLE);
62 }
63 
64 void BedDef::write_model_state_impl(const File &output) const {
65  m_uplift.write(output);
66  m_topg.write(output);
67 }
68 
70  DiagnosticList result;
71  result = { { "dbdt", Diagnostic::wrap(m_uplift) }, { "topg", Diagnostic::wrap(m_topg) } };
72 
73  return result;
74 }
75 
76 void BedDef::init(const InputOptions &opts, const array::Scalar &ice_thickness,
77  const array::Scalar &sea_level_elevation) {
78  this->init_impl(opts, ice_thickness, sea_level_elevation);
79 }
80 
81 //! Initialize using provided bed elevation and uplift.
82 void BedDef::bootstrap(const array::Scalar &bed_elevation, const array::Scalar &bed_uplift,
83  const array::Scalar &ice_thickness,
84  const array::Scalar &sea_level_elevation) {
85  this->bootstrap_impl(bed_elevation, bed_uplift, ice_thickness, sea_level_elevation);
86 }
87 
88 void BedDef::bootstrap_impl(const array::Scalar &bed_elevation, const array::Scalar &bed_uplift,
89  const array::Scalar &ice_thickness,
90  const array::Scalar &sea_level_elevation) {
92  m_uplift.copy_from(bed_uplift);
93 
94  // suppress a compiler warning:
95  (void)ice_thickness;
96  (void)sea_level_elevation;
97 }
98 
99 void BedDef::update(const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation,
100  double t, double dt) {
101  this->update_impl(ice_thickness, sea_level_elevation, t, dt);
102 }
103 
104 //! Initialize from the context (input file and the "variables" database).
105 void BedDef::init_impl(const InputOptions &opts, const array::Scalar &ice_thickness,
106  const array::Scalar &sea_level_elevation) {
107  (void)ice_thickness;
108  (void)sea_level_elevation;
109 
110  switch (opts.type) {
111  case INIT_RESTART:
112  // read bed elevation and uplift rate from file
113  m_log->message(2, " reading bed topography and uplift from %s ... \n",
114  opts.filename.c_str());
115  // re-starting
116  m_topg.read(opts.filename, opts.record); // fails if not found!
117  m_uplift.read(opts.filename, opts.record); // fails if not found!
118  break;
119  case INIT_BOOTSTRAP:
120  // bootstrapping
121  m_topg.regrid(opts.filename, io::Default(m_config->get_number("bootstrapping.defaults.bed")));
122  m_uplift.regrid(opts.filename,
123  io::Default(m_config->get_number("bootstrapping.defaults.uplift")));
124  break;
125  case INIT_OTHER:
126  default: {
127  // do nothing
128  }
129  }
130 
131  // process -regrid_file and -regrid_vars
132  regrid("bed deformation", m_topg);
133  // uplift is not a part of the model state, but the user may want to take it from a -regrid_file
134  // during bootstrapping
135  regrid("bed deformation", m_uplift);
136 
137  std::string uplift_file = m_config->get_string("bed_deformation.bed_uplift_file");
138  if (not uplift_file.empty()) {
139  m_log->message(2, " reading bed uplift from %s ... \n", uplift_file.c_str());
140  m_uplift.regrid(uplift_file, io::Default::Nil());
141  }
142 
143  std::string correction_file = m_config->get_string("bed_deformation.bed_topography_delta_file");
144  if (not correction_file.empty()) {
145  apply_topg_offset(correction_file);
146  }
147 
148  // this should be the last thing we do here
150 }
151 
152 /*!
153  * Apply a correction to the bed topography by reading topg_delta from filename.
154  */
155 void BedDef::apply_topg_offset(const std::string &filename) {
156  m_log->message(2, " Adding a bed topography correction read in from %s...\n", filename.c_str());
157 
158  array::Scalar topg_delta(m_grid, "topg_delta");
159  topg_delta.metadata(0).long_name("bed topography correction").units("meters");
160 
161  topg_delta.regrid(filename, io::Default::Nil());
162 
163  m_topg.add(1.0, topg_delta);
164 }
165 
166 //! Compute bed uplift (dt is in seconds).
167 void BedDef::compute_uplift(const array::Scalar &bed, const array::Scalar &bed_last,
168  double dt, array::Scalar &result) {
169  bed.add(-1, bed_last, result);
170  //! uplift = (topg - topg_last) / dt
171  result.scale(1.0 / dt);
172 }
173 
174 double compute_load(double bed, double ice_thickness, double sea_level,
175  double ice_density, double ocean_density) {
176 
177  double
178  ice_load = ice_thickness,
179  ocean_depth = std::max(sea_level - bed, 0.0),
180  ocean_load = (ocean_density / ice_density) * ocean_depth;
181 
182  // this excludes the load of ice shelves
183  return ice_load > ocean_load ? ice_load : 0.0;
184 }
185 
186 /*! Compute the load on the bedrock in units of ice-equivalent thickness.
187  *
188  */
189 void compute_load(const array::Scalar &bed_elevation,
190  const array::Scalar &ice_thickness,
191  const array::Scalar &sea_level_elevation,
192  array::Scalar &result) {
193 
194  Config::ConstPtr config = result.grid()->ctx()->config();
195 
196  const double
197  ice_density = config->get_number("constants.ice.density"),
198  ocean_density = config->get_number("constants.sea_water.density");
199 
200  array::AccessScope list{&bed_elevation, &ice_thickness, &sea_level_elevation, &result};
201 
202  for (auto p = result.grid()->points(); p; p.next()) {
203  const int i = p.i(), j = p.j();
204 
205  result(i, j) = compute_load(bed_elevation(i, j),
206  ice_thickness(i, j),
207  sea_level_elevation(i, j),
208  ice_density, ocean_density);
209  }
210 }
211 
212 } // end of namespace bed
213 } // 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
void regrid(const std::string &module_name, array::Array &variable, RegriddingFlag flag=NO_REGRID_WITHOUT_REGRID_VARS)
Definition: Component.cc:159
A class defining a common interface for most PISM sub-models.
Definition: Component.hh:118
std::shared_ptr< const Config > ConstPtr
static Ptr wrap(const T &input)
Definition: Diagnostic.hh:160
High-level PISM I/O class.
Definition: File.hh:56
VariableMetadata & standard_name(const std::string &input)
VariableMetadata & long_name(const std::string &input)
VariableMetadata & units(const std::string &input)
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 add(double alpha, const Array2D< T > &x)
Definition: Array2D.hh:65
void read(const std::string &filename, unsigned int time)
Definition: Array.cc:809
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:540
void write(const std::string &filename) const
Definition: Array.cc:800
void scale(double alpha)
Result: v <- v * alpha. Calls VecScale.
Definition: Array.cc:253
std::shared_ptr< const Grid > grid() const
Definition: Array.cc:132
void regrid(const std::string &filename, io::Default default_value)
Definition: Array.cc:814
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Definition: Array.cc:553
virtual void write_model_state_impl(const File &output) const
The default (empty implementation).
Definition: BedDef.cc:64
virtual DiagnosticList diagnostics_impl() const
Definition: BedDef.cc:69
virtual void define_model_state_impl(const File &output) const
The default (empty implementation).
Definition: BedDef.cc:59
virtual void bootstrap_impl(const array::Scalar &bed_elevation, const array::Scalar &bed_uplift, const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation)
Definition: BedDef.cc:88
virtual void update_impl(const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation, double t, double dt)=0
void init(const InputOptions &opts, const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation)
Definition: BedDef.cc:76
array::Scalar2 m_topg_last
bed elevation at the time of the last update
Definition: BedDef.hh:83
void update(const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation, double t, double dt)
Definition: BedDef.cc:99
void bootstrap(const array::Scalar &bed_elevation, const array::Scalar &bed_uplift, const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation)
Initialize using provided bed elevation and uplift.
Definition: BedDef.cc:82
array::Scalar2 m_topg
current bed elevation
Definition: BedDef.hh:80
virtual void init_impl(const InputOptions &opts, const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation)
Initialize from the context (input file and the "variables" database).
Definition: BedDef.cc:105
BedDef(std::shared_ptr< const Grid > g)
Definition: BedDef.cc:27
virtual void apply_topg_offset(const std::string &filename)
Definition: BedDef.cc:155
array::Scalar m_uplift
bed uplift rate
Definition: BedDef.hh:86
const array::Scalar & uplift() const
Definition: BedDef.cc:55
const array::Scalar & bed_elevation() const
Definition: BedDef.cc:51
void compute_uplift(const array::Scalar &bed, const array::Scalar &bed_last, double dt, array::Scalar &result)
Compute bed uplift (dt is in seconds).
Definition: BedDef.cc:167
static Default Nil()
Definition: IO_Flags.hh:97
double max(const array::Scalar &input)
Finds maximum over all the values in an array::Scalar object. Ignores ghosts.
Definition: Scalar.cc:165
double compute_load(double bed, double ice_thickness, double sea_level, double ice_density, double ocean_density)
Definition: BedDef.cc:174
@ PISM_DOUBLE
Definition: IO_Flags.hh:52
@ INIT_BOOTSTRAP
Definition: Component.hh:56
@ INIT_OTHER
Definition: Component.hh:56
@ INIT_RESTART
Definition: Component.hh:56
std::map< std::string, Diagnostic::Ptr > DiagnosticList
Definition: Diagnostic.hh:125
InitializationType type
initialization type
Definition: Component.hh:61
std::string filename
name of the input file (if applicable)
Definition: Component.hh:63
unsigned int record
index of the record to re-start from
Definition: Component.hh:65