PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
Delta_T.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 "pism/coupler/atmosphere/Delta_T.hh"
20
21#include "pism/util/Config.hh"
22#include "pism/util/ScalarForcing.hh"
23#include "pism/coupler/util/options.hh"
24#include "pism/util/array/Forcing.hh"
25#include "pism/util/Logger.hh"
26#include "pism/util/io/IO_Flags.hh"
27
28namespace pism {
29namespace atmosphere {
30
31Delta_T::Delta_T(std::shared_ptr<const Grid> grid, std::shared_ptr<AtmosphereModel> in)
32 : AtmosphereModel(grid, in) {
33
34 std::string
35 prefix = "atmosphere.delta_T",
36 variable_name = "delta_T",
37 long_name = "near-surface air temperature offsets",
38 units = "kelvin",
39 external_units = "kelvin";
40
41 ForcingOptions opt(*m_grid->ctx(), prefix);
42
43 // will be closed at the end of scope
45
46 // Assume that we are expected to use 1D scaling if the input file contains a scalar
47 // time-series.
48 bool scalar = input.dimensions(variable_name).size() == 1;
49
50 if (scalar) {
51 m_1d_offsets.reset(new ScalarForcing(*grid->ctx(),
52 prefix,
53 variable_name,
54 units, external_units,
55 long_name));
56 } else {
57 unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
58
59 m_2d_offsets = std::make_shared<array::Forcing>(m_grid,
60 input,
61 variable_name,
62 "", // no standard name
63 buffer_size,
64 opt.periodic);
65 m_2d_offsets->metadata()
66 .long_name(long_name)
67 .units(units)
68 .output_units(external_units);
69 }
70
72}
73
74void Delta_T::init_impl(const Geometry &geometry) {
75 m_input_model->init(geometry);
76
77 m_log->message(2,
78 "* Initializing near-surface air temperature offsets...\n");
79
80 if (m_2d_offsets) {
81 ForcingOptions opt(*m_grid->ctx(), "atmosphere.delta_T");
82 m_2d_offsets->init(opt.filename, opt.periodic);
83 }
84}
85
86void Delta_T::init_timeseries_impl(const std::vector<double> &ts) const {
88
89 m_offset_values.resize(ts.size());
90
91 if (m_1d_offsets) {
92 for (unsigned int k = 0; k < ts.size(); ++k) {
93 m_offset_values[k] = m_1d_offsets->value(ts[k]);
94 }
95 }
96
97 if (m_2d_offsets) {
98 m_2d_offsets->init_interpolation(ts);
99 }
100}
101
103 m_input_model->begin_pointwise_access();
104
105 if (m_2d_offsets) {
106 m_2d_offsets->begin_access();
107 }
108}
109
111 m_input_model->end_pointwise_access();
112
113 if (m_2d_offsets) {
114 m_2d_offsets->end_access();
115 }
116}
117
118void Delta_T::update_impl(const Geometry &geometry, double t, double dt) {
119 m_input_model->update(geometry, t, dt);
120 m_temperature->copy_from(m_input_model->air_temperature());
121
122 if (m_1d_offsets) {
123 m_temperature->shift(m_1d_offsets->value(t + 0.5 * dt));
124 }
125
126 if (m_2d_offsets) {
127 m_2d_offsets->update(t, dt);
128 m_2d_offsets->average(t, dt);
129
130 auto &T = *m_temperature;
131 const auto &delta = *m_2d_offsets;
132
133 array::AccessScope list{&T, &delta};
134
135 for (auto p : m_grid->points()) {
136 const int i = p.i(), j = p.j();
137
138 T(i, j) += delta(i, j);
139 }
140 }
141}
142
146
147void Delta_T::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
148 m_input_model->temp_time_series(i, j, result);
149
150 if (m_2d_offsets) {
151 // m_offset_values was resized in init_interpolation and so it should have enough
152 // elements
153 m_2d_offsets->interp(i, j, m_offset_values);
154 } else if (m_1d_offsets) {
155 // empty: m_offset_values were set in init_timeseries_impl()
156 }
157
158 for (size_t k = 0; k < result.size(); ++k) {
159 result[k] += m_offset_values[k];
160 }
161}
162
163} // end of namespace atmosphere
164} // end of namespace pism
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
std::vector< std::string > dimensions(const std::string &variable_name) const
Definition File.cc:390
High-level PISM I/O class.
Definition File.hh:57
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
Definition Array.hh:66
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
A purely virtual class defining the interface of a PISM Atmosphere Model.
const array::Scalar & air_temperature_impl() const
Definition Delta_T.cc:143
std::shared_ptr< array::Scalar > m_temperature
Definition Delta_T.hh:53
void temp_time_series_impl(int i, int j, std::vector< double > &values) const
Definition Delta_T.cc:147
std::shared_ptr< ScalarForcing > m_1d_offsets
Definition Delta_T.hh:49
void init_impl(const Geometry &geometry)
Definition Delta_T.cc:74
void end_pointwise_access_impl() const
Definition Delta_T.cc:110
void begin_pointwise_access_impl() const
Definition Delta_T.cc:102
std::shared_ptr< array::Forcing > m_2d_offsets
Definition Delta_T.hh:51
void update_impl(const Geometry &geometry, double t, double dt)
Definition Delta_T.cc:118
std::vector< double > m_offset_values
Definition Delta_T.hh:47
void init_timeseries_impl(const std::vector< double > &ts) const
Definition Delta_T.cc:86
Delta_T(std::shared_ptr< const Grid > g, std::shared_ptr< AtmosphereModel > in)
Definition Delta_T.cc:31
@ PISM_GUESS
Definition IO_Flags.hh:57
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:69
static const double k
Definition exactTestP.cc:42
std::string filename
Definition options.hh:33