Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WeatherStation.cc
Go to the documentation of this file.
1/* Copyright (C) 2014, 2015, 2016, 2017, 2018, 2020, 2021, 2022, 2023, 2024 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/ConfigInterface.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
27namespace pism {
28namespace atmosphere {
29
30WeatherStation::WeatherStation(std::shared_ptr<const Grid> grid)
31 : AtmosphereModel(grid) {
32
33 m_log->message(2,
34 "* Using the constant-in-space atmosphere model\n"
35 " for use with scalar data from one weather station\n"
36 " combined with lapse rate corrections...\n");
37
38 auto filename = m_config->get_string("atmosphere.one_station.file");
39
40 if (filename.empty()) {
42 "atmosphere.one_station.file cannot be empty");
43 }
44
45 m_log->message(2,
46 " - Reading air temperature and precipitation from '%s'...\n",
47 filename.c_str());
48
49 auto &ctx = *grid->ctx();
50
51 bool periodic = false;
52
53 m_precipitation_timeseries = std::make_shared<ScalarForcing>(ctx,
54 filename,
55 "precipitation",
56 "kg m-2 second-1",
57 "kg m-2 year-1",
58 "ice-equivalent precipitation rate",
59 periodic);
60
61 m_air_temp_timeseries = std::make_shared<ScalarForcing>(ctx,
62 filename,
63 "air_temp",
64 "kelvin",
65 "kelvin",
66 "near-surface air temperature",
67 periodic);
68
71}
72
73void WeatherStation::init_impl(const Geometry &geometry) {
74 (void) geometry;
75}
76
78 (void) t;
79 return MaxTimestep("atmosphere weather_station");
80}
81
82void WeatherStation::update_impl(const Geometry &geometry, double t, double dt) {
83 (void) geometry;
84
85 m_precipitation->set(m_precipitation_timeseries->average(t, dt));
86
87 m_temperature->set(m_air_temp_timeseries->average(t, dt));
88}
89
93
97
99 // empty
100}
101
103 // empty
104}
105
106void WeatherStation::init_timeseries_impl(const std::vector<double> &ts) const {
107 size_t N = ts.size();
108
109 m_precip_values.resize(N);
110 m_air_temp_values.resize(N);
111
112 for (unsigned int k = 0; k < N; ++k) {
115 }
116}
117
118void WeatherStation::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
119 (void)i;
120 (void)j;
121
122 result = m_precip_values;
123}
124
125void WeatherStation::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
126 (void)i;
127 (void)j;
128
129 result = m_air_temp_values;
130}
131
132} // end of namespace atmosphere
133} // end of namespace pism
std::shared_ptr< const Grid > grid() const
Definition Component.cc:105
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
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:909
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