PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
Anomaly.cc
Go to the documentation of this file.
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 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/Anomaly.hh"
20 
21 #include "pism/util/ConfigInterface.hh"
22 #include "pism/util/Grid.hh"
23 #include "pism/coupler/util/options.hh"
24 #include "pism/util/array/Forcing.hh"
25 
26 namespace pism {
27 namespace atmosphere {
28 
29 Anomaly::Anomaly(std::shared_ptr<const Grid> g, std::shared_ptr<AtmosphereModel> in)
30  : AtmosphereModel(g, in) {
31 
32  ForcingOptions opt(*m_grid->ctx(), "atmosphere.anomaly");
33 
34  {
35  unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
36 
38 
39  m_air_temp_anomaly = std::make_shared<array::Forcing>(m_grid,
40  file,
41  "air_temp_anomaly",
42  "", // no standard name
43  buffer_size,
44  opt.periodic,
45  LINEAR);
46 
47  m_precipitation_anomaly = std::make_shared<array::Forcing>(m_grid,
48  file,
49  "precipitation_anomaly",
50  "", // no standard name
51  buffer_size,
52  opt.periodic);
53  }
54 
55  m_air_temp_anomaly->metadata(0)
56  .long_name("anomaly of the near-surface air temperature")
57  .units("Kelvin");
58 
59  m_precipitation_anomaly->metadata(0)
60  .long_name("anomaly of the ice-equivalent precipitation rate")
61  .units("kg m-2 second-1")
62  .output_units("kg m-2 year-1");
63 
66 }
67 
68 void Anomaly::init_impl(const Geometry &geometry) {
69  m_input_model->init(geometry);
70 
71  ForcingOptions opt(*m_grid->ctx(), "atmosphere.anomaly");
72 
73  m_log->message(2,
74  "* Initializing the -atmosphere ...,anomaly code...\n");
75 
76  m_log->message(2,
77  " reading anomalies from %s ...\n",
78  opt.filename.c_str());
79 
80  m_air_temp_anomaly->init(opt.filename, opt.periodic);
82 }
83 
84 void Anomaly::update_impl(const Geometry &geometry, double t, double dt) {
85  m_input_model->update(geometry, t, dt);
86 
87  m_precipitation_anomaly->update(t, dt);
88  m_air_temp_anomaly->update(t, dt);
89 
90  m_precipitation_anomaly->average(t, dt);
91  m_air_temp_anomaly->average(t, dt);
92 
93  // precipitation
94  {
95  m_precipitation->copy_from(m_input_model->precipitation());
97  }
98 
99  // temperature
100  {
101  m_temperature->copy_from(m_input_model->air_temperature());
102  m_temperature->add(1.0, *m_air_temp_anomaly);
103  }
104 }
105 
107  return *m_precipitation;
108 }
109 
111  return *m_temperature;
112 }
113 
115  m_input_model->begin_pointwise_access();
116  m_air_temp_anomaly->begin_access();
117  m_precipitation_anomaly->begin_access();
118 }
119 
121  m_input_model->end_pointwise_access();
122  m_precipitation_anomaly->end_access();
123  m_air_temp_anomaly->end_access();
124 }
125 
126 void Anomaly::init_timeseries_impl(const std::vector<double> &ts) const {
128 
129  m_air_temp_anomaly->init_interpolation(ts);
130 
131  m_precipitation_anomaly->init_interpolation(ts);
132 }
133 
134 void Anomaly::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
135  m_input_model->temp_time_series(i, j, result);
136 
137  m_temp_anomaly.reserve(m_ts_times.size());
138  m_air_temp_anomaly->interp(i, j, m_temp_anomaly);
139 
140  for (unsigned int k = 0; k < m_ts_times.size(); ++k) {
141  result[k] += m_temp_anomaly[k];
142  }
143 }
144 
145 void Anomaly::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
146  m_input_model->precip_time_series(i, j, result);
147 
148  m_mass_flux_anomaly.reserve(m_ts_times.size());
150 
151  for (unsigned int k = 0; k < m_ts_times.size(); ++k) {
152  result[k] += m_mass_flux_anomaly[k];
153  }
154 }
155 
156 } // end of namespace atmosphere
157 } // 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
High-level PISM I/O class.
Definition: File.hh:56
std::shared_ptr< array::Forcing > m_air_temp_anomaly
Definition: Anomaly.hh:49
std::shared_ptr< array::Scalar > m_temperature
Definition: Anomaly.hh:53
std::vector< double > m_mass_flux_anomaly
Definition: Anomaly.hh:47
void init_timeseries_impl(const std::vector< double > &ts) const
Definition: Anomaly.cc:126
const array::Scalar & precipitation_impl() const
Definition: Anomaly.cc:106
std::shared_ptr< array::Forcing > m_precipitation_anomaly
Definition: Anomaly.hh:50
void temp_time_series_impl(int i, int j, std::vector< double > &values) const
Definition: Anomaly.cc:134
void end_pointwise_access_impl() const
Definition: Anomaly.cc:120
void init_impl(const Geometry &geometry)
Definition: Anomaly.cc:68
std::shared_ptr< array::Scalar > m_precipitation
Definition: Anomaly.hh:52
void precip_time_series_impl(int i, int j, std::vector< double > &values) const
Definition: Anomaly.cc:145
void begin_pointwise_access_impl() const
Definition: Anomaly.cc:114
void update_impl(const Geometry &geometry, double t, double dt)
Definition: Anomaly.cc:84
const array::Scalar & air_temperature_impl() const
Definition: Anomaly.cc:110
std::vector< double > m_temp_anomaly
Definition: Anomaly.hh:47
Anomaly(std::shared_ptr< const Grid > g, std::shared_ptr< AtmosphereModel > in)
Definition: Anomaly.cc:29
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.
@ PISM_NETCDF3
Definition: IO_Flags.hh:57
@ PISM_READONLY
open an existing file for reading only
Definition: IO_Flags.hh:72
static const double g
Definition: exactTestP.cc:36
static const double k
Definition: exactTestP.cc:42
std::string filename
Definition: options.hh:33