PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
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, 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#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/geometry/Geometry.hh"
26#include "pism/util/array/Forcing.hh"
27#include "pism/util/Logger.hh"
28#include "pism/util/io/IO_Flags.hh"
29
30namespace pism {
31namespace atmosphere {
32
33ElevationChange::ElevationChange(std::shared_ptr<const Grid> grid, std::shared_ptr<AtmosphereModel> in)
34 : AtmosphereModel(grid, in),
35 m_surface(grid, "ice_surface_elevation") {
36
37 m_precip_lapse_rate = m_config->get_number("atmosphere.elevation_change.precipitation.lapse_rate",
38 "(kg m-2 / s) / m");
39
40 m_precip_temp_lapse_rate = m_config->get_number("atmosphere.elevation_change.precipitation.temp_lapse_rate",
41 "K / m");
42 m_precip_exp_factor = m_config->get_number("atmosphere.precip_exponential_factor_for_temperature");
43
44 m_temp_lapse_rate = m_config->get_number("atmosphere.elevation_change.temperature_lapse_rate",
45 "K / m");
46
47 {
48 auto method = m_config->get_string("atmosphere.elevation_change.precipitation.method");
49 m_precip_method = method == "scale" ? SCALE : SHIFT;
50 }
51
52 {
53 ForcingOptions opt(*m_grid->ctx(), "atmosphere.elevation_change");
54
55 unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
56
58
59 m_reference_surface = std::make_shared<array::Forcing>(m_grid,
60 file,
61 "usurf",
62 "", // no standard name
63 buffer_size,
64 opt.periodic,
65 LINEAR);
66 m_reference_surface->metadata()
67 .long_name("ice surface elevation")
68 .units("m")
69 .standard_name("surface_altitude");
70 }
71
74}
75
76void ElevationChange::init_impl(const Geometry &geometry) {
77 using units::convert;
78
79 m_input_model->init(geometry);
80
81 m_log->message(2,
82 " [using elevation-change-dependent adjustments of air temperature and precipitation]\n");
83
84 m_log->message(2,
85 " air temperature lapse rate: %3.3f K per km\n",
86 convert(m_sys, m_temp_lapse_rate, "K / m", "K / km"));
87
88 if (m_precip_method == SHIFT) {
89 m_log->message(2,
90 " precipitation lapse rate: %3.3f (kg m-2 year-1) per km\n",
91 convert(m_sys, m_precip_lapse_rate, "(kg m-2 / s) / m", "(kg m-2 / year) / km"));
92 } else {
93 m_log->message(2,
94 " precipitation scaling factor with temperature: %3.3f kelvin^-1\n"
95 " temperature lapse rate: %3.3f K per km\n",
97 convert(m_sys, m_precip_temp_lapse_rate, "K / m", "K / km"));
98 }
99
100 ForcingOptions opt(*m_grid->ctx(), "atmosphere.elevation_change");
101
102 m_reference_surface->init(opt.filename, opt.periodic);
103}
104
105void ElevationChange::update_impl(const Geometry &geometry, double t, double dt) {
106
107 m_input_model->update(geometry, t, dt);
108
109 m_reference_surface->update(t, dt);
110 m_reference_surface->interp(t + 0.5*dt);
111
112 // make a copy of the surface elevation so that it is available in methods computing
113 // temperature and precipitation time series
115
116 const auto &reference_surface = *m_reference_surface;
117
118 // temperature
119 {
120 m_temperature->copy_from(m_input_model->air_temperature());
121
122 lapse_rate_correction(m_surface, reference_surface,
124 }
125
126 // precipitation
127 {
128 m_precipitation->copy_from(m_input_model->precipitation());
129
130 switch (m_precip_method) {
131 case SCALE:
132 {
133 array::AccessScope list{&m_surface, &reference_surface, m_precipitation.get()};
134
135 for (auto p : m_grid->points()) {
136 const int i = p.i(), j = p.j();
137
138 double dT = -m_precip_temp_lapse_rate * (m_surface(i, j) - reference_surface(i, j));
139
140 (*m_precipitation)(i, j) *= std::exp(m_precip_exp_factor * dT);
141 }
142
143 }
144 break;
145 case SHIFT:
146 default:
147 {
150 }
151 break;
152 }
153 }
154}
155
159
163
165 m_input_model->begin_pointwise_access();
166
169}
170
172 m_input_model->end_pointwise_access();
173
174 m_reference_surface->end_access();
176}
177
178void ElevationChange::init_timeseries_impl(const std::vector<double> &ts) const {
180
181 m_reference_surface->init_interpolation(ts);
182}
183
184void ElevationChange::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
185 std::vector<double> reference_surface(m_ts_times.size());
186
187 m_input_model->temp_time_series(i, j, result);
188
189 m_reference_surface->interp(i, j, reference_surface);
190
191 for (unsigned int m = 0; m < m_ts_times.size(); ++m) {
192 result[m] -= m_temp_lapse_rate * (m_surface(i, j) - reference_surface[m]);
193 }
194}
195
196void ElevationChange::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
197 auto N = m_ts_times.size();
198 std::vector<double> reference_surface(N);
199
200 m_input_model->precip_time_series(i, j, result);
201
202 m_reference_surface->interp(i, j, reference_surface);
203
204 switch (m_precip_method) {
205 case SCALE:
206 {
207 for (unsigned int m = 0; m < N; ++m) {
208 double dT = -m_precip_temp_lapse_rate * (m_surface(i, j) - reference_surface[m]);
209 result[m] *= std::exp(m_precip_exp_factor * dT);
210 }
211 }
212 break;
213 case SHIFT:
214 for (unsigned int m = 0; m < N; ++m) {
215 result[m] -= m_precip_lapse_rate * (m_surface(i, j) - reference_surface[m]);
216 }
217 break;
218 }
219}
220
221} // end of namespace atmosphere
222} // end of namespace pism
const units::System::Ptr m_sys
unit system used by this component
Definition Component.hh:162
std::shared_ptr< const Grid > grid() const
Definition Component.cc:107
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
High-level PISM I/O class.
Definition File.hh:57
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:66
void copy_from(const Array2D< T > &source)
Definition Array2D.hh:101
virtual void end_access() const
Checks if an Array is allocated and calls DAVecRestoreArray.
Definition Array.cc:619
virtual void begin_access() const
Checks if an Array is allocated and calls DAVecGetArray.
Definition Array.cc:598
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)
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:58
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:69
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)
std::string filename
Definition options.hh:33