PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
WeatherStation.cc
Go to the documentation of this file.
1/* Copyright (C) 2014, 2015, 2016, 2017, 2018, 2020, 2021, 2022, 2023, 2024, 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
20#include "pism/coupler/atmosphere/WeatherStation.hh"
21#include "pism/util/Config.hh"
22#include "pism/util/Grid.hh"
23#include "pism/util/error_handling.hh"
24#include "pism/util/MaxTimestep.hh"
25#include "pism/util/ScalarForcing.hh"
26#include "pism/util/Logger.hh"
27
28namespace pism {
29namespace atmosphere {
30
31WeatherStation::WeatherStation(std::shared_ptr<const Grid> grid)
32 : AtmosphereModel(grid) {
33
34 m_log->message(2,
35 "* Using the constant-in-space atmosphere model\n"
36 " for use with scalar data from one weather station\n"
37 " combined with lapse rate corrections...\n");
38
39 auto filename = m_config->get_string("atmosphere.one_station.file");
40
41 if (filename.empty()) {
43 "atmosphere.one_station.file cannot be empty");
44 }
45
46 m_log->message(2,
47 " - Reading air temperature and precipitation from '%s'...\n",
48 filename.c_str());
49
50 auto &ctx = *grid->ctx();
51
52 bool periodic = false;
53
54 m_precipitation_timeseries = std::make_shared<ScalarForcing>(ctx,
55 filename,
56 "precipitation",
57 "kg m-2 second-1",
58 "kg m-2 year-1",
59 "ice-equivalent precipitation rate",
60 periodic);
61
62 m_air_temp_timeseries = std::make_shared<ScalarForcing>(ctx,
63 filename,
64 "air_temp",
65 "kelvin",
66 "kelvin",
67 "near-surface air temperature",
68 periodic);
69
72}
73
74void WeatherStation::init_impl(const Geometry &geometry) {
75 (void) geometry;
76}
77
79 (void) t;
80 return MaxTimestep("atmosphere weather_station");
81}
82
83void WeatherStation::update_impl(const Geometry &geometry, double t, double dt) {
84 (void) geometry;
85
86 m_precipitation->set(m_precipitation_timeseries->average(t, dt));
87
88 m_temperature->set(m_air_temp_timeseries->average(t, dt));
89}
90
94
98
100 // empty
101}
102
104 // empty
105}
106
107void WeatherStation::init_timeseries_impl(const std::vector<double> &ts) const {
108 size_t N = ts.size();
109
110 m_precip_values.resize(N);
111 m_air_temp_values.resize(N);
112
113 for (unsigned int k = 0; k < N; ++k) {
116 }
117}
118
119void WeatherStation::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
120 (void)i;
121 (void)j;
122
123 result = m_precip_values;
124}
125
126void WeatherStation::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
127 (void)i;
128 (void)j;
129
130 result = m_air_temp_values;
131}
132
133} // end of namespace atmosphere
134} // 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
std::shared_ptr< const Logger > m_log
logger (for easy access)
Definition Component.hh:164
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
size_t size() const
Return the total number of elements in the owned part of an array.
Definition Array.cc:930
static std::shared_ptr< array::Scalar > allocate_temperature(std::shared_ptr< const Grid > grid)
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.
std::shared_ptr< ScalarForcing > m_precipitation_timeseries
std::shared_ptr< array::Scalar > m_temperature
void temp_time_series_impl(int i, int j, std::vector< double > &values) const
void update_impl(const Geometry &geometry, double t, double dt)
WeatherStation(std::shared_ptr< const Grid > g)
void init_impl(const Geometry &geometry)
std::vector< double > m_air_temp_values
void init_timeseries_impl(const std::vector< double > &ts) const
const array::Scalar & air_temperature_impl() const
const array::Scalar & precipitation_impl() const
MaxTimestep max_timestep_impl(double t) const
std::shared_ptr< ScalarForcing > m_air_temp_timeseries
std::vector< double > m_precip_values
std::shared_ptr< array::Scalar > m_precipitation
void precip_time_series_impl(int i, int j, std::vector< double > &values) const
#define PISM_ERROR_LOCATION
static const double k
Definition exactTestP.cc:42