PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
ElevationChange.cc
Go to the documentation of this file.
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 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 #include "pism/coupler/atmosphere/ElevationChange.hh"
20 
21 #include <cmath> // std::exp()
22 
23 #include "pism/coupler/util/options.hh"
24 #include "pism/coupler/util/lapse_rates.hh"
25 #include "pism/util/io/io_helpers.hh"
26 #include "pism/geometry/Geometry.hh"
27 #include "pism/util/array/Forcing.hh"
28 
29 namespace pism {
30 namespace atmosphere {
31 
32 ElevationChange::ElevationChange(std::shared_ptr<const Grid> grid, std::shared_ptr<AtmosphereModel> in)
33  : AtmosphereModel(grid, in),
34  m_surface(grid, "ice_surface_elevation") {
35 
36  m_precip_lapse_rate = m_config->get_number("atmosphere.elevation_change.precipitation.lapse_rate",
37  "(kg m-2 / s) / m");
38 
39  m_precip_temp_lapse_rate = m_config->get_number("atmosphere.elevation_change.precipitation.temp_lapse_rate",
40  "K / m");
41  m_precip_exp_factor = m_config->get_number("atmosphere.precip_exponential_factor_for_temperature");
42 
43  m_temp_lapse_rate = m_config->get_number("atmosphere.elevation_change.temperature_lapse_rate",
44  "K / m");
45 
46  {
47  auto method = m_config->get_string("atmosphere.elevation_change.precipitation.method");
48  m_precip_method = method == "scale" ? SCALE : SHIFT;
49  }
50 
51  {
52  ForcingOptions opt(*m_grid->ctx(), "atmosphere.elevation_change");
53 
54  unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
55 
57 
58  m_reference_surface = std::make_shared<array::Forcing>(m_grid,
59  file,
60  "usurf",
61  "", // no standard name
62  buffer_size,
63  opt.periodic,
64  LINEAR);
65  m_reference_surface->metadata()
66  .long_name("ice surface elevation")
67  .units("m")
68  .standard_name("surface_altitude");
69  }
70 
73 }
74 
75 void ElevationChange::init_impl(const Geometry &geometry) {
76  using units::convert;
77 
78  m_input_model->init(geometry);
79 
80  m_log->message(2,
81  " [using elevation-change-dependent adjustments of air temperature and precipitation]\n");
82 
83  m_log->message(2,
84  " air temperature lapse rate: %3.3f K per km\n",
85  convert(m_sys, m_temp_lapse_rate, "K / m", "K / km"));
86 
87  if (m_precip_method == SHIFT) {
88  m_log->message(2,
89  " precipitation lapse rate: %3.3f (kg m-2 year-1) per km\n",
90  convert(m_sys, m_precip_lapse_rate, "(kg m-2 / s) / m", "(kg m-2 / year) / km"));
91  } else {
92  m_log->message(2,
93  " precipitation scaling factor with temperature: %3.3f Kelvin-1\n"
94  " temperature lapse rate: %3.3f K per km\n",
96  convert(m_sys, m_precip_temp_lapse_rate, "K / m", "K / km"));
97  }
98 
99  ForcingOptions opt(*m_grid->ctx(), "atmosphere.elevation_change");
100 
101  m_reference_surface->init(opt.filename, opt.periodic);
102 }
103 
104 void ElevationChange::update_impl(const Geometry &geometry, double t, double dt) {
105 
106  m_input_model->update(geometry, t, dt);
107 
108  m_reference_surface->update(t, dt);
109  m_reference_surface->interp(t + 0.5*dt);
110 
111  // make a copy of the surface elevation so that it is available in methods computing
112  // temperature and precipitation time series
114 
115  const auto &reference_surface = *m_reference_surface;
116 
117  // temperature
118  {
119  m_temperature->copy_from(m_input_model->air_temperature());
120 
121  lapse_rate_correction(m_surface, reference_surface,
123  }
124 
125  // precipitation
126  {
127  m_precipitation->copy_from(m_input_model->precipitation());
128 
129  switch (m_precip_method) {
130  case SCALE:
131  {
132  array::AccessScope list{&m_surface, &reference_surface, m_precipitation.get()};
133 
134  for (auto p = m_grid->points(); p; p.next()) {
135  const int i = p.i(), j = p.j();
136 
137  double dT = -m_precip_temp_lapse_rate * (m_surface(i, j) - reference_surface(i, j));
138 
139  (*m_precipitation)(i, j) *= std::exp(m_precip_exp_factor * dT);
140  }
141 
142  }
143  break;
144  case SHIFT:
145  default:
146  {
149  }
150  break;
151  }
152  }
153 }
154 
156  return *m_temperature;
157 }
158 
160  return *m_precipitation;
161 }
162 
164  m_input_model->begin_pointwise_access();
165 
166  m_reference_surface->begin_access();
168 }
169 
171  m_input_model->end_pointwise_access();
172 
173  m_reference_surface->end_access();
175 }
176 
177 void ElevationChange::init_timeseries_impl(const std::vector<double> &ts) const {
179 
180  m_reference_surface->init_interpolation(ts);
181 }
182 
183 void ElevationChange::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
184  std::vector<double> reference_surface(m_ts_times.size());
185 
186  m_input_model->temp_time_series(i, j, result);
187 
188  m_reference_surface->interp(i, j, reference_surface);
189 
190  for (unsigned int m = 0; m < m_ts_times.size(); ++m) {
191  result[m] -= m_temp_lapse_rate * (m_surface(i, j) - reference_surface[m]);
192  }
193 }
194 
195 void ElevationChange::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
196  auto N = m_ts_times.size();
197  std::vector<double> reference_surface(N);
198 
199  m_input_model->precip_time_series(i, j, result);
200 
201  m_reference_surface->interp(i, j, reference_surface);
202 
203  switch (m_precip_method) {
204  case SCALE:
205  {
206  for (unsigned int m = 0; m < N; ++m) {
207  double dT = -m_precip_temp_lapse_rate * (m_surface(i, j) - reference_surface[m]);
208  result[m] *= std::exp(m_precip_exp_factor * dT);
209  }
210  }
211  break;
212  case SHIFT:
213  for (unsigned int m = 0; m < N; ++m) {
214  result[m] -= m_precip_lapse_rate * (m_surface(i, j) - reference_surface[m]);
215  }
216  break;
217  }
218 }
219 
220 } // end of namespace atmosphere
221 } // end of namespace pism
const units::System::Ptr m_sys
unit system used by this component
Definition: Component.hh:160
std::shared_ptr< const Grid > grid() const
Definition: Component.cc:105
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
High-level PISM I/O class.
Definition: File.hh:56
array::Scalar2 ice_surface_elevation
Definition: Geometry.hh:57
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
virtual void end_access() const
Checks if an Array is allocated and calls DAVecRestoreArray.
Definition: Array.cc:667
virtual void begin_access() const
Checks if an Array is allocated and calls DAVecGetArray.
Definition: Array.cc:646
virtual void init_timeseries_impl(const std::vector< double > &ts) const
static std::shared_ptr< array::Scalar > allocate_temperature(std::shared_ptr< const Grid > grid)
std::shared_ptr< AtmosphereModel > m_input_model
static std::shared_ptr< array::Scalar > allocate_precipitation(std::shared_ptr< const Grid > grid)
std::vector< double > m_ts_times
A purely virtual class defining the interface of a PISM Atmosphere Model.
void precip_time_series_impl(int i, int j, std::vector< double > &result) const
const array::Scalar & precipitation_impl() const
std::shared_ptr< array::Forcing > m_reference_surface
const array::Scalar & air_temperature_impl() const
std::shared_ptr< array::Scalar > m_precipitation
void init_impl(const Geometry &geometry)
ElevationChange(std::shared_ptr< const Grid > g, std::shared_ptr< AtmosphereModel > in)
std::shared_ptr< array::Scalar > m_temperature
void temp_time_series_impl(int i, int j, std::vector< double > &result) const
void init_timeseries_impl(const std::vector< double > &ts) const
void update_impl(const Geometry &geometry, double t, double dt)
@ PISM_NETCDF3
Definition: IO_Flags.hh:57
@ PISM_READONLY
open an existing file for reading only
Definition: IO_Flags.hh:72
double convert(System::Ptr system, double input, const std::string &spec1, const std::string &spec2)
Convert a quantity from unit1 to unit2.
Definition: Units.cc:70
void lapse_rate_correction(const array::Scalar &surface, const array::Scalar &reference_surface, double lapse_rate, array::Scalar &result)
Definition: lapse_rates.cc:26
std::string filename
Definition: options.hh:33