PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
TemperatureIndex.cc
Go to the documentation of this file.
1// Copyright (C) 2011--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 <algorithm> // std::min
20
21#include "pism/coupler/surface/TemperatureIndex.hh"
22#include "pism/coupler/surface/localMassBalance.hh"
23#include "pism/util/Grid.hh"
24#include "pism/util/Time.hh"
25#include "pism/coupler/AtmosphereModel.hh"
26#include "pism/util/io/File.hh"
27
28#include "pism/util/error_handling.hh"
29#include "pism/util/pism_utilities.hh"
30#include "pism/util/array/CellType.hh"
31#include "pism/geometry/Geometry.hh"
32#include "pism/util/array/Forcing.hh"
33#include "pism/util/Logger.hh"
34#include "pism/util/io/IO_Flags.hh"
35
36namespace pism {
37namespace surface {
38
39///// PISM surface model implementing a PDD scheme.
40
41TemperatureIndex::TemperatureIndex(std::shared_ptr<const Grid> g,
42 std::shared_ptr<atmosphere::AtmosphereModel> input)
43 : SurfaceModel(g, input),
44 m_mass_flux(m_grid, "climatic_mass_balance"),
45 m_firn_depth(m_grid, "firn_depth"),
46 m_snow_depth(m_grid, "snow_depth") {
47
48 m_base_ddf.snow = m_config->get_number("surface.pdd.factor_snow");
49 m_base_ddf.ice = m_config->get_number("surface.pdd.factor_ice");
50 m_base_ddf.refreeze_fraction = m_config->get_number("surface.pdd.refreeze");
51 m_base_pddStdDev = m_config->get_number("surface.pdd.std_dev.value");
52 m_sd_use_param = m_config->get_flag("surface.pdd.std_dev.use_param");
53 m_sd_param_a = m_config->get_number("surface.pdd.std_dev.param_a");
54 m_sd_param_b = m_config->get_number("surface.pdd.std_dev.param_b");
55
56 bool use_fausto_params = m_config->get_flag("surface.pdd.fausto.enabled");
57
58 auto method = m_config->get_string("surface.pdd.method");
59
60 if (method == "repeatable_random_process") {
62 } else if (method == "random_process") {
64 } else {
66 }
67
68 if (use_fausto_params) {
70 m_base_pddStdDev = 2.53;
71 }
72
73 auto sd_file = m_config->get_string("surface.pdd.std_dev.file");
74
75 if (not sd_file.empty()) {
76 bool sd_periodic = m_config->get_flag("surface.pdd.std_dev.periodic");
77 int max_buffer_size = (int) m_config->get_number("input.forcing.buffer_size");
78
79 File file(m_grid->com, sd_file, io::PISM_NETCDF3, io::PISM_READONLY);
80 m_air_temp_sd = std::make_shared<array::Forcing>(m_grid, file,
81 "air_temp_sd", "",
82 max_buffer_size,
83 sd_periodic,
84 LINEAR);
85 m_sd_file_set = true;
86 } else {
87 m_air_temp_sd = array::Forcing::Constant(m_grid, "air_temp_sd", 0.0);
88 m_sd_file_set = false;
89 }
90
91 m_air_temp_sd->metadata(0)
92 .long_name("standard deviation of near-surface air temperature")
93 .units("kelvin");
94
96 .long_name("instantaneous surface mass balance (accumulation/ablation) rate")
97 .units("kg m^-2 s^-1")
98 .standard_name("land_ice_surface_specific_mass_balance_flux");
99
100 m_mass_flux.metadata()["comment"] = "positive values correspond to ice gain";
101
103 .long_name("snow cover depth (set to zero once a year)")
104 .units("m");
105 m_snow_depth.set(0.0);
106
108 .long_name("firn cover depth")
109 .units("m");
110 m_firn_depth.metadata()["valid_min"] = {0.0};
111 m_firn_depth.set(0.0);
112
114
118}
119
121
122 // call the default implementation (not the interface method init())
123 SurfaceModel::init_impl(geometry);
124
125 // report user's modeling choices
126 {
127 m_log->message(2,
128 "* Initializing the default temperature-index, PDD-based surface processes scheme.\n"
129 " Precipitation and 2m air temperature provided by atmosphere are inputs.\n"
130 " Surface mass balance and ice upper surface temperature are outputs.\n"
131 " See PISM User's Manual for control of degree-day factors.\n");
132
133 m_log->message(2,
134 " Computing number of positive degree-days by: %s.\n",
135 m_mbscheme->method().c_str());
136
137 if (m_faustogreve) {
138 m_log->message(2,
139 " Setting PDD parameters from [Faustoetal2009].\n");
140 } else {
141 m_log->message(2,
142 " Using default PDD parameters.\n");
143 }
144 }
145
146 // initialize the spatially-variable air temperature standard deviation
147 {
148 auto sd_file = m_config->get_string("surface.pdd.std_dev.file");
149 if (sd_file.empty()) {
150 m_log->message(2,
151 " Using constant standard deviation of near-surface temperature.\n");
152
153 auto attributes = m_air_temp_sd->metadata();
154 // replace with a constant array::Forcing:
156 // restore metadata:
157 m_air_temp_sd->metadata() = attributes;
158 } else {
159 m_log->message(2,
160 " Reading standard deviation of near-surface temperature from '%s'...\n",
161 sd_file.c_str());
162
163 bool sd_periodic = m_config->get_flag("surface.pdd.std_dev.periodic");
164 m_air_temp_sd->init(sd_file, sd_periodic);
165 }
166 }
167
168 // initializing the model state
169 auto input = process_input_options(m_grid->com, m_config);
170
171 auto firn_file = m_config->get_string("surface.pdd.firn_depth_file");
172
173 if (input.type == INIT_RESTART) {
174 if (not firn_file.empty()) {
176 "surface.pdd.firn_depth_file is not allowed when"
177 " re-starting from a PISM output file.");
178 }
179
180 m_firn_depth.read(input.filename, input.record);
181 m_snow_depth.read(input.filename, input.record);
182 } else if (input.type == INIT_BOOTSTRAP) {
183
184 m_snow_depth.regrid(input.filename, io::Default(0.0));
185
186 if (firn_file.empty()) {
187 m_firn_depth.regrid(input.filename, io::Default(0.0));
188 } else {
190 }
191 } else {
192
193 m_snow_depth.set(0.0);
194
195 if (firn_file.empty()) {
196 m_firn_depth.set(0.0);
197 } else {
199 }
200 }
201
202 {
203 regrid("PDD surface model", m_snow_depth);
204 regrid("PDD surface model", m_firn_depth);
205 }
206
207 // finish up
208 {
210
211 m_accumulation->set(0.0);
212 m_melt->set(0.0);
213 m_runoff->set(0.0);
214 }
215}
216
218 return m_atmosphere->max_timestep(my_t);
219}
220
222 // compute the time corresponding to the beginning of the next balance year
223 double
224 balance_year_start_day = m_config->get_number("surface.mass_balance_year_start_day"),
225 one_day = units::convert(m_sys, 1.0, "days", "seconds"),
226 year_start = this->time().calendar_year_start(time),
227 balance_year_start = year_start + (balance_year_start_day - 1.0) * one_day;
228
229 if (balance_year_start > time) {
230 return balance_year_start;
231 }
232 return this->time().increment_date(balance_year_start, 1);
233}
234
235void TemperatureIndex::update_impl(const Geometry &geometry, double t, double dt) {
236
237 // make a copy of the pointer to convince clang static analyzer that its value does not
238 // change during the call
239 FaustoGrevePDDObject *fausto_greve = m_faustogreve.get();
240
241 // update to ensure that temperature and precipitation time series are correct:
242 m_atmosphere->update(geometry, t, dt);
243
244 m_temperature->copy_from(m_atmosphere->air_temperature());
245
246 // set up air temperature and precipitation time series
247 auto N = static_cast<int>(m_mbscheme->get_timeseries_length(dt));
248
249 const double dtseries = dt / N;
250 std::vector<double> ts(N), T(N), S(N), P(N), PDDs(N);
251 for (int k = 0; k < N; ++k) {
252 ts[k] = t + k * dtseries;
253 }
254
255 // update standard deviation time series
256 if (m_sd_file_set) {
257 m_air_temp_sd->update(t, dt);
258 m_air_temp_sd->init_interpolation(ts);
259 }
260
261 const auto &mask = geometry.cell_type;
262 const auto &H = geometry.ice_thickness;
263
264 array::AccessScope list{&mask, &H, m_air_temp_sd.get(), &m_mass_flux,
266 m_accumulation.get(), m_melt.get(), m_runoff.get()};
267
268 const double
269 sigmalapserate = m_config->get_number("surface.pdd.std_dev.lapse_lat_rate"),
270 sigmabaselat = m_config->get_number("surface.pdd.std_dev.lapse_lat_base");
271
272 const array::Scalar *latitude = &geometry.latitude;
273 if ((fausto_greve != nullptr) or sigmalapserate != 0.0) {
274 list.add(*latitude);
275 }
276
277 if (fausto_greve != nullptr) {
278 const array::Scalar
279 *longitude = &geometry.latitude,
280 *surface_altitude = &geometry.ice_surface_elevation;
281
282 fausto_greve->update_temp_mj(*surface_altitude, *latitude, *longitude);
283 }
284
286
287 m_atmosphere->init_timeseries(ts);
288
289 m_atmosphere->begin_pointwise_access();
290
291 const double ice_density = m_config->get_number("constants.ice.density");
292
293 ParallelSection loop(m_grid->com);
294 try {
295 for (auto p : m_grid->points()) {
296 const int i = p.i(), j = p.j();
297
298 // the temperature time series from the AtmosphereModel and its modifiers
299 m_atmosphere->temp_time_series(i, j, T);
300
301 if (mask.ice_free_ocean(i, j)) {
302 // ignore precipitation over ice-free ocean
303 for (int k = 0; k < N; ++k) {
304 P[k] = 0.0;
305 }
306 } else {
307 // elsewhere, get precipitation from the atmosphere model
308 m_atmosphere->precip_time_series(i, j, P);
309 }
310
311 // convert precipitation from "kg m-2 second-1" to "m second-1" (PDDMassBalance expects
312 // accumulation in m/second ice equivalent)
313 for (int k = 0; k < N; ++k) {
314 P[k] = P[k] / ice_density;
315 // kg / (m^2 * second) / (kg / m^3) = m / second
316 }
317
318 // interpolate temperature standard deviation time series
319 if (m_sd_file_set) {
320 m_air_temp_sd->interp(i, j, S);
321 } else {
322 double tmp = (*m_air_temp_sd)(i, j);
323 for (int k = 0; k < N; ++k) {
324 S[k] = tmp;
325 }
326 }
327
328 if (fausto_greve != nullptr) {
329 // we have been asked to set mass balance parameters according to
330 // formula (6) in [\ref Faustoetal2009]; they overwrite ddf set above
331 ddf = fausto_greve->degree_day_factors(i, j, (*latitude)(i, j));
332 }
333
334 // apply standard deviation lapse rate on top of prescribed values
335 if (sigmalapserate != 0.0) {
336 double lat = (*latitude)(i, j);
337 for (int k = 0; k < N; ++k) {
338 S[k] += sigmalapserate * (lat - sigmabaselat);
339 }
340 (*m_air_temp_sd)(i, j) = S[0]; // ensure correct SD reporting
341 }
342
343 // apply standard deviation param over ice if in use
344 if (m_sd_use_param and mask.icy(i, j)) {
345 for (int k = 0; k < N; ++k) {
346 S[k] = m_sd_param_a * (T[k] - 273.15) + m_sd_param_b;
347 if (S[k] < 0.0) {
348 S[k] = 0.0 ;
349 }
350 }
351 (*m_air_temp_sd)(i, j) = S[0]; // ensure correct SD reporting
352 }
353
354 // Use temperature time series, the "positive" threshhold, and
355 // the standard deviation of the daily variability to get the
356 // number of positive degree days (PDDs)
357 if (mask.ice_free_ocean(i, j)) {
358 for (int k = 0; k < N; ++k) {
359 PDDs[k] = 0.0;
360 }
361 } else {
362 m_mbscheme->get_PDDs(dtseries, S, T, // inputs
363 PDDs); // output
364 }
365
366 // Use temperature time series to remove rainfall from precipitation
367 m_mbscheme->get_snow_accumulation(T, // air temperature (input)
368 P); // precipitation rate (input-output)
369
370 // Use degree-day factors, the number of PDDs, and the snow precipitation to get surface mass
371 // balance (and diagnostics: accumulation, melt, runoff)
372 {
373 double next_snow_depth_reset = m_next_balance_year_start;
374
375 // make copies of firn and snow depth values at this point to avoid accessing 2D
376 // fields in the inner loop
377 double
378 ice = H(i, j),
379 firn = m_firn_depth(i, j),
380 snow = m_snow_depth(i, j);
381
382 // accumulation, melt, runoff over this time-step
383 double
384 A = 0.0,
385 M = 0.0,
386 R = 0.0,
387 SMB = 0.0;
388
389 for (int k = 0; k < N; ++k) {
390 if (ts[k] >= next_snow_depth_reset) {
391 snow = 0.0;
392 while (next_snow_depth_reset <= ts[k]) {
393 next_snow_depth_reset = time().increment_date(next_snow_depth_reset, 1);
394 }
395 }
396
397 const double accumulation = P[k] * dtseries;
398
400 changes = m_mbscheme->step(ddf, PDDs[k],
401 ice, firn, snow, accumulation);
402
403 // update ice thickness
404 ice += changes.smb;
405 assert(ice >= 0);
406
407 // update firn depth
408 firn += changes.firn_depth;
409 assert(firn >= 0);
410
411 // update snow depth
412 snow += changes.snow_depth;
413 assert(snow >= 0);
414
415 // update total accumulation, melt, and runoff
416 {
417 A += accumulation;
418 M += changes.melt;
419 R += changes.runoff;
420 SMB += changes.smb;
421 }
422 } // end of the time-stepping loop
423
424 // set firn and snow depths
425 m_firn_depth(i, j) = firn;
426 m_snow_depth(i, j) = snow;
427
428 // set total accumulation, melt, and runoff, and SMB at this point, converting
429 // from "meters, ice equivalent" to "kg / m^2"
430 {
431 (*m_accumulation)(i, j) = A * ice_density;
432 (*m_melt)(i, j) = M * ice_density;
433 (*m_runoff)(i, j) = R * ice_density;
434 // m_mass_flux (unlike m_accumulation, m_melt, and m_runoff), is a
435 // rate. m * (kg / m^3) / second = kg / m^2 / second
436 m_mass_flux(i, j) = SMB * ice_density / dt;
437 }
438 }
439
440 if (mask.ice_free_ocean(i, j)) {
441 m_firn_depth(i, j) = 0.0; // no firn in the ocean
442 m_snow_depth(i, j) = 0.0; // snow over the ocean does not stick
443 }
444 }
445 } catch (...) {
446 loop.failed();
447 }
448 loop.check();
449
450 m_atmosphere->end_pointwise_access();
451
453}
454
458
462
466
468 return *m_melt;
469}
470
472 return *m_runoff;
473}
474
478
482
486
487std::set<VariableMetadata> TemperatureIndex::state_impl() const {
488 auto variables = array::metadata({ &m_firn_depth, &m_snow_depth });
489
490 return pism::combine(variables, SurfaceModel::state_impl());
491}
492
495 m_firn_depth.write(output);
496 m_snow_depth.write(output);
497}
498
500 DiagnosticList result = {
501 {"air_temp_sd", Diagnostic::wrap(*m_air_temp_sd)},
502 {"snow_depth", Diagnostic::wrap(m_snow_depth)},
503 {"firn_depth", Diagnostic::wrap(m_firn_depth)},
504 };
505
507
508 return result;
509}
510
511} // end of namespace surface
512} // end of namespace pism
const units::System::Ptr m_sys
unit system used by this component
Definition Component.hh:162
const Time & time() const
Definition Component.cc:111
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
void regrid(const std::string &module_name, array::Array &variable, RegriddingFlag flag=NO_REGRID_WITHOUT_REGRID_VARS)
Definition Component.cc:152
std::shared_ptr< const Logger > m_log
logger (for easy access)
Definition Component.hh:164
static Ptr wrap(const T &input)
High-level PISM I/O class.
Definition File.hh:57
array::Scalar2 ice_surface_elevation
Definition Geometry.hh:57
array::CellType2 cell_type
Definition Geometry.hh:55
array::Scalar2 ice_thickness
Definition Geometry.hh:51
array::Scalar latitude
Definition Geometry.hh:41
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
void failed()
Indicates a failure of a parallel section.
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
double increment_date(double T, double years) const
Definition Time.cc:867
double calendar_year_start(double T) const
Returns the model time in seconds corresponding to the beginning of the year T falls into.
Definition Time.cc:858
VariableMetadata & long_name(const std::string &input)
VariableMetadata & units(const std::string &input)
VariableMetadata & standard_name(const std::string &input)
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
Definition Array.hh:66
void add(double alpha, const Array2D< T > &x)
Definition Array2D.hh:93
void read(const std::string &filename, unsigned int time)
Definition Array.cc:753
void write(const OutputFile &file) const
Definition Array.cc:859
void set(double c)
Result: v[j] <- c for all j.
Definition Array.cc:659
void regrid(const std::string &filename, io::Default default_value)
Definition Array.cc:758
VariableMetadata & metadata(unsigned int N=0)
Returns a reference to the VariableMetadata object containing metadata for the compoment N.
Definition Array.cc:467
static std::shared_ptr< Forcing > Constant(std::shared_ptr< const Grid > grid, const std::string &short_name, double value)
Definition Forcing.cc:148
static Default Nil()
Definition IO_Flags.hh:94
LocalMassBalance::DegreeDayFactors degree_day_factors(int i, int j, double latitude)
void update_temp_mj(const array::Scalar &surfelev, const array::Scalar &lat, const array::Scalar &lon)
Updates mean July near-surface air temperature.
A PDD implementation which computes the local mass balance based on an expectation integral.
An alternative PDD implementation which simulates a random process to get the number of PDDs.
static std::shared_ptr< array::Scalar > allocate_runoff(std::shared_ptr< const Grid > grid)
std::shared_ptr< atmosphere::AtmosphereModel > m_atmosphere
static std::shared_ptr< array::Scalar > allocate_temperature(std::shared_ptr< const Grid > grid)
const array::Scalar & accumulation() const
Returns accumulation.
static std::shared_ptr< array::Scalar > allocate_accumulation(std::shared_ptr< const Grid > grid)
static std::shared_ptr< array::Scalar > allocate_melt(std::shared_ptr< const Grid > grid)
virtual void write_state_impl(const OutputFile &output) const
The default (empty implementation).
virtual std::set< VariableMetadata > state_impl() const
virtual DiagnosticList spatial_diagnostics_impl() const
virtual void init_impl(const Geometry &geometry)
The interface of PISM's surface models.
std::shared_ptr< array::Scalar > m_accumulation
total accumulation during the last time step
virtual const array::Scalar & accumulation_impl() const
virtual void init_impl(const Geometry &geometry)
virtual const array::Scalar & runoff_impl() const
virtual void update_impl(const Geometry &geometry, double t, double dt)
virtual const array::Scalar & melt_impl() const
virtual const array::Scalar & mass_flux_impl() const
const array::Scalar & snow_depth() const
array::Scalar m_snow_depth
snow depth (reset once a year)
virtual const array::Scalar & temperature_impl() const
std::shared_ptr< array::Forcing > m_air_temp_sd
standard deviation of the daily variability of the air temperature
std::unique_ptr< FaustoGrevePDDObject > m_faustogreve
if not NULL then user wanted fausto PDD stuff
virtual DiagnosticList spatial_diagnostics_impl() const
const array::Scalar & air_temp_sd() const
double compute_next_balance_year_start(double time)
virtual void write_state_impl(const OutputFile &output) const
The default (empty implementation).
virtual MaxTimestep max_timestep_impl(double t) const
double m_base_pddStdDev
K; daily amount of randomness.
array::Scalar m_mass_flux
cached surface mass balance rate
std::shared_ptr< array::Scalar > m_runoff
total runoff during the last time step
virtual std::set< VariableMetadata > state_impl() const
array::Scalar m_firn_depth
firn depth
std::shared_ptr< array::Scalar > m_melt
total melt during the last time step
std::shared_ptr< array::Scalar > m_temperature
TemperatureIndex(std::shared_ptr< const Grid > g, std::shared_ptr< atmosphere::AtmosphereModel > input)
std::unique_ptr< LocalMassBalance > m_mbscheme
mass balance scheme to use
const array::Scalar & firn_depth() const
LocalMassBalance::DegreeDayFactors m_base_ddf
holds degree-day factors in location-independent case
#define PISM_ERROR_LOCATION
std::set< VariableMetadata > metadata(std::initializer_list< const Array * > vecs)
Definition Array.cc:1244
@ 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
static const double g
Definition exactTestP.cc:36
@ INIT_BOOTSTRAP
Definition Component.hh:56
@ INIT_RESTART
Definition Component.hh:56
std::map< std::string, Diagnostic::Ptr > DiagnosticList
static const double k
Definition exactTestP.cc:42
T combine(const T &a, const T &b)
InputOptions process_input_options(MPI_Comm com, std::shared_ptr< const Config > config)
Definition Component.cc:45
double ice
m day^-1 K^-1; ice-equivalent amount of ice melted, per PDD
double refreeze_fraction
fraction of melted snow which refreezes as ice
double snow
m day^-1 K^-1; ice-equivalent amount of snow melted, per PDD
A struct which holds degree day factors.
static double S(unsigned n)
Definition test_cube.c:58