20 #include <gsl/gsl_math.h>
23 #include "pism/coupler/AtmosphereModel.hh"
24 #include "pism/util/Time.hh"
25 #include "pism/util/error_handling.hh"
26 #include "pism/util/MaxTimestep.hh"
27 #include "pism/util/Context.hh"
30 namespace atmosphere {
33 auto result = std::make_shared<array::Scalar>(
grid,
"air_temp");
36 .long_name(
"mean annual near-surface air temperature")
43 auto result = std::make_shared<array::Scalar>(
grid,
"precipitation");
46 .long_name(
"precipitation rate")
47 .units(
"kg m-2 second-1")
48 .output_units(
"kg m-2 year-1")
49 .standard_name(
"precipitation_flux");
60 std::shared_ptr<AtmosphereModel> input)
103 namespace diagnostics {
110 m_vars[0].long_name(
"instantaneous value of the near-surface air temperature").units(
"Kelvin");
116 auto result = allocate<array::Scalar>(
"air_temp_snapshot");
118 std::vector<double> current_time = {
m_grid->ctx()->time()->current() };
119 std::vector<double> temperature = { 0.0 };
121 model->init_timeseries(current_time);
123 model->begin_pointwise_access();
128 for (
auto p =
m_grid->points(); p; p.next()) {
129 const int i = p.i(), j = p.j();
131 model->temp_time_series(i, j, temperature);
133 (*result)(i, j) = temperature[0];
140 model->end_pointwise_access();
151 m_vars[0].long_name(
"effective mean-annual near-surface air temperature").units(
"Kelvin");
156 auto result = allocate<array::Scalar>(
"effective_air_temp");
158 result->copy_from(
model->air_temperature());
170 .long_name(
"effective precipitation rate")
171 .standard_name(
"precipitation_flux")
172 .units(
"kg m-2 second-1")
173 .output_units(
"kg m-2 year-1");
178 auto result = allocate<array::Scalar>(
"effective_precipitation");
180 result->copy_from(
model->precipitation());
205 {
"air_temp_snapshot",
Diagnostic::Ptr(
new AirTemperatureSnapshot(
this))},
std::shared_ptr< const Grid > grid() const
DiagnosticList diagnostics() const
A class defining a common interface for most PISM sub-models.
const AtmosphereModel * model
A template derived from Diagnostic, adding a "Model".
const units::System::Ptr m_sys
the unit system
std::vector< SpatialVariableMetadata > m_vars
metadata corresponding to NetCDF variables
std::shared_ptr< Diagnostic > Ptr
std::shared_ptr< const Grid > m_grid
the grid
High-level PISM I/O class.
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
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
virtual DiagnosticList diagnostics_impl() const
void update(const Geometry &geometry, double t, double dt)
virtual TSDiagnosticList ts_diagnostics_impl() const
virtual void update_impl(const Geometry &geometry, double t, double dt)=0
virtual void write_model_state_impl(const File &output) const
The default (empty implementation).
virtual void define_model_state_impl(const File &output) const
The default (empty implementation).
virtual void init_timeseries_impl(const std::vector< double > &ts) const
const array::Scalar & air_temperature() const
Sets result to the mean near-surface air temperature, in degrees Kelvin.
static std::shared_ptr< array::Scalar > allocate_temperature(std::shared_ptr< const Grid > grid)
void init_timeseries(const std::vector< double > &ts) const
const array::Scalar & precipitation() const
Sets result to the mean precipitation, in "kg m-2 second-1".
virtual void init_impl(const Geometry &geometry)=0
virtual const array::Scalar & precipitation_impl() const
void begin_pointwise_access() const
void init(const Geometry &geometry)
virtual void precip_time_series_impl(int i, int j, std::vector< double > &result) const
virtual void begin_pointwise_access_impl() const
std::shared_ptr< AtmosphereModel > m_input_model
void end_pointwise_access() const
void temp_time_series(int i, int j, std::vector< double > &result) const
Sets a pre-allocated N-element array "result" to the time-series of near-surface air temperature (deg...
virtual const array::Scalar & air_temperature_impl() const
virtual void end_pointwise_access_impl() const
AtmosphereModel(std::shared_ptr< const Grid > g)
virtual void temp_time_series_impl(int i, int j, std::vector< double > &result) const
static std::shared_ptr< array::Scalar > allocate_precipitation(std::shared_ptr< const Grid > grid)
virtual MaxTimestep max_timestep_impl(double my_t) const
std::vector< double > m_ts_times
void precip_time_series(int i, int j, std::vector< double > &result) const
Sets a pre-allocated N-element array "result" to the time-series of ice-equivalent precipitation (m/s...
A purely virtual class defining the interface of a PISM Atmosphere Model.
AirTemperatureSnapshot(const AtmosphereModel *m)
std::shared_ptr< array::Array > compute_impl() const
Instantaneous near-surface air temperature.
std::shared_ptr< array::Array > compute_impl() const
AirTemperature(const AtmosphereModel *m)
Effective near-surface mean-annual air temperature.
Precipitation(const AtmosphereModel *m)
std::shared_ptr< array::Array > compute_impl() const
Effective precipitation rate (average over time step).
#define PISM_ERROR_LOCATION
std::map< std::string, TSDiagnostic::Ptr > TSDiagnosticList
std::map< std::string, Diagnostic::Ptr > DiagnosticList
T combine(const T &a, const T &b)