PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
AtmosphereModel.hh
Go to the documentation of this file.
1 // Copyright (C) 2008-2018, 2021, 2022 Ed Bueler, Constantine Khroulev, Ricarda Winkelmann,
2 // Gudfinna Adalgeirsdottir and Andy Aschwanden
3 //
4 // This file is part of PISM.
5 //
6 // PISM is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3 of the License, or (at your option) any later
9 // version.
10 //
11 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with PISM; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #ifndef __AtmosphereModel
21 #define __AtmosphereModel
22 
23 #include <vector>
24 
25 #include "pism/util/Component.hh"
26 
27 namespace pism {
28 
29 //! @brief Atmosphere models and modifiers: provide precipitation and
30 //! temperature to a surface::SurfaceModel below
31 namespace atmosphere {
32 //! A purely virtual class defining the interface of a PISM Atmosphere Model.
33 class AtmosphereModel : public Component {
34 public:
35  AtmosphereModel(std::shared_ptr<const Grid> g);
36  AtmosphereModel(std::shared_ptr<const Grid> g, std::shared_ptr<AtmosphereModel> input);
37  virtual ~AtmosphereModel() = default;
38 
39  void init(const Geometry &geometry);
40 
41  void update(const Geometry &geometry, double t, double dt);
42 
43  //! @brief Sets result to the mean precipitation, in "kg m-2 second-1".
44  const array::Scalar& precipitation() const;
45 
46  //! @brief Sets result to the mean near-surface air temperature, in degrees Kelvin.
47  const array::Scalar& air_temperature() const;
48 
49  void begin_pointwise_access() const;
50  void end_pointwise_access() const;
51  void init_timeseries(const std::vector<double> &ts) const;
52  //! \brief Sets a pre-allocated N-element array "result" to the time-series of
53  //! ice-equivalent precipitation (m/s) at the point i,j on the grid.
54  //!
55  //! See temp_time_series() for more.
56  void precip_time_series(int i, int j, std::vector<double> &result) const;
57 
58  //! \brief Sets a pre-allocated N-element array "result" to the time-series
59  //! of near-surface air temperature (degrees Kelvin) at the point i,j on the
60  //! grid. Times (in years) are specified in ts. NB! Has to be surrounded by
61  //! begin_pointwise_access() and end_pointwise_access()
62  void temp_time_series(int i, int j, std::vector<double> &result) const;
63 protected:
64  virtual void init_impl(const Geometry &geometry) = 0;
65  virtual void update_impl(const Geometry &geometry, double t, double dt) = 0;
66  virtual void define_model_state_impl(const File &output) const;
67  virtual void write_model_state_impl(const File &output) const;
68 
69  virtual MaxTimestep max_timestep_impl(double my_t) const;
70 
71  virtual const array::Scalar& precipitation_impl() const;
72  virtual const array::Scalar& air_temperature_impl() const;
73 
74  virtual void begin_pointwise_access_impl() const;
75  virtual void end_pointwise_access_impl() const;
76  virtual void init_timeseries_impl(const std::vector<double> &ts) const;
77  virtual void precip_time_series_impl(int i, int j, std::vector<double> &result) const;
78  virtual void temp_time_series_impl(int i, int j, std::vector<double> &result) const;
79 
80  virtual DiagnosticList diagnostics_impl() const;
81  virtual TSDiagnosticList ts_diagnostics_impl() const;
82 protected:
83  mutable std::vector<double> m_ts_times;
84 
85  std::shared_ptr<AtmosphereModel> m_input_model;
86 
87  static std::shared_ptr<array::Scalar> allocate_temperature(std::shared_ptr<const Grid> grid);
88  static std::shared_ptr<array::Scalar> allocate_precipitation(std::shared_ptr<const Grid> grid);
89 };
90 
91 } // end of namespace atmosphere
92 } // end of namespace pism
93 
94 #endif // __AtmosphereModel
std::shared_ptr< const Grid > grid() const
Definition: Component.cc:105
A class defining a common interface for most PISM sub-models.
Definition: Component.hh:118
High-level PISM I/O class.
Definition: File.hh:56
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
Definition: MaxTimestep.hh:31
virtual DiagnosticList diagnostics_impl() const
void update(const Geometry &geometry, double t, double dt)
virtual ~AtmosphereModel()=default
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 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 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.
static const double g
Definition: exactTestP.cc:36
std::map< std::string, TSDiagnostic::Ptr > TSDiagnosticList
Definition: Diagnostic.hh:343
std::map< std::string, Diagnostic::Ptr > DiagnosticList
Definition: Diagnostic.hh:125