PISM, A Parallel Ice Sheet Model  stable v2.0.4 committed by Constantine Khrulev on 2022-05-25 12:02:27 -0800
YearlyCycle.cc
Go to the documentation of this file.
1 // Copyright (C) 2008-2020 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 // Implementation of the atmosphere model using constant-in-time precipitation
21 // and a cosine yearly cycle for near-surface air temperatures.
22 
23 #include <gsl/gsl_math.h> // M_PI
24 
25 #include "YearlyCycle.hh"
26 #include "pism/util/Time.hh"
27 #include "pism/util/IceGrid.hh"
28 #include "pism/util/ConfigInterface.hh"
29 #include "pism/util/io/io_helpers.hh"
30 #include "pism/util/pism_utilities.hh"
31 #include "pism/util/Context.hh"
32 
33 namespace pism {
34 namespace atmosphere {
35 
37  : AtmosphereModel(g),
38  m_air_temp_mean_annual(m_grid, "air_temp_mean_annual", WITHOUT_GHOSTS),
39  m_air_temp_mean_summer(m_grid, "air_temp_mean_summer", WITHOUT_GHOSTS),
40  m_precipitation(m_grid, "precipitation", WITHOUT_GHOSTS) {
41 
42  m_snow_temp_summer_day = m_config->get_number("atmosphere.fausto_air_temp.summer_peak_day");
43 
44  m_air_temp_mean_annual.set_attrs("diagnostic",
45  "mean annual near-surface air temperature (without sub-year time-dependence or forcing)",
46  "K", "K",
47  "", 0); // no CF standard_name
49 
50  m_air_temp_mean_summer.set_attrs("diagnostic",
51  "mean summer (NH: July/ SH: January) near-surface air temperature (without sub-year time-dependence or forcing)",
52  "Kelvin", "Kelvin",
53  "", 0); // no CF standard_name
55 
56  m_precipitation.set_attrs("model_state", "precipitation rate",
57  "kg m-2 second-1", "kg m-2 year-1", "precipitation_flux", 0);
59 }
60 
61 //! Reads in the precipitation data from the input file.
62 void YearlyCycle::init_impl(const Geometry &geometry) {
63  (void) geometry;
64 
66  init_internal(opts.filename, opts.type == INIT_BOOTSTRAP, opts.record);
67 }
68 
69 //! Read precipitation data from a given file.
70 void YearlyCycle::init_internal(const std::string &input_filename, bool do_regrid,
71  unsigned int start) {
72  // read precipitation rate from file
73  m_log->message(2,
74  " reading mean annual ice-equivalent precipitation rate 'precipitation'\n"
75  " from %s ... \n",
76  input_filename.c_str());
77  if (do_regrid == true) {
78  m_precipitation.regrid(input_filename, CRITICAL); // fails if not found!
79  } else {
80  m_precipitation.read(input_filename, start); // fails if not found!
81  }
82 }
83 
84 void YearlyCycle::define_model_state_impl(const File &output) const {
85  m_precipitation.define(output);
86 }
87 
88 void YearlyCycle::write_model_state_impl(const File &output) const {
89  m_precipitation.write(output);
90 }
91 
92 //! Copies the stored precipitation field into result.
94  return m_precipitation;
95 }
96 
97 //! Copies the stored mean annual near-surface air temperature field into result.
100 }
101 
102 //! Copies the stored mean summer near-surface air temperature field into result.
104  return m_air_temp_mean_summer;
105 }
106 
107 void YearlyCycle::init_timeseries_impl(const std::vector<double> &ts) const {
108  // constants related to the standard yearly cycle
109  const double
110  summerday_fraction = m_grid->ctx()->time()->day_of_the_year_to_year_fraction(m_snow_temp_summer_day);
111 
112  size_t N = ts.size();
113 
114  m_ts_times.resize(N);
115  m_cosine_cycle.resize(N);
116  for (unsigned int k = 0; k < m_ts_times.size(); k++) {
117  double tk = m_grid->ctx()->time()->year_fraction(ts[k]) - summerday_fraction;
118 
119  m_ts_times[k] = ts[k];
120  m_cosine_cycle[k] = cos(2.0 * M_PI * tk);
121  }
122 }
123 
124 void YearlyCycle::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
125  result.resize(m_ts_times.size());
126  for (unsigned int k = 0; k < m_ts_times.size(); k++) {
127  result[k] = m_precipitation(i,j);
128  }
129 }
130 
131 void YearlyCycle::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
132  result.resize(m_ts_times.size());
133  for (unsigned int k = 0; k < m_ts_times.size(); ++k) {
135  }
136 }
137 
142 }
143 
148 }
149 
150 namespace diagnostics {
151 
152 /*! @brief Mean summer near-surface air temperature. */
153 class MeanSummerTemperature : public Diag<YearlyCycle>
154 {
155 public:
157  : Diag<YearlyCycle>(m) {
158 
159  /* set metadata: */
160  m_vars = {SpatialVariableMetadata(m_sys, "air_temp_mean_summer")};
161 
162  set_attrs("mean summer near-surface air temperature used in the cosine yearly cycle", "",
163  "Kelvin", "Kelvin", 0);
164  }
165 private:
167 
168  IceModelVec2S::Ptr result(new IceModelVec2S(m_grid, "air_temp_mean_summer", WITHOUT_GHOSTS));
169  result->metadata(0) = m_vars[0];
170 
171  result->copy_from(model->mean_summer_temp());
172 
173  return result;
174  }
175 };
176 } // end of namespace diagnostics
177 
180 
181  result["air_temp_mean_summer"] = Diagnostic::Ptr(new diagnostics::MeanSummerTemperature(this));
182 
183  return result;
184 }
185 
186 } // end of namespace atmosphere
187 } // end of namespace pism
const Config::ConstPtr m_config
configuration database used by this component
Definition: Component.hh:138
const Logger::ConstPtr m_log
logger (for easy access)
Definition: Component.hh:142
const IceGrid::ConstPtr m_grid
grid used by this component
Definition: Component.hh:136
const YearlyCycle * model
Definition: Diagnostic.hh:166
A template derived from Diagnostic, adding a "Model".
Definition: Diagnostic.hh:161
const units::System::Ptr m_sys
the unit system
Definition: Diagnostic.hh:108
std::vector< SpatialVariableMetadata > m_vars
metadata corresponding to NetCDF variables
Definition: Diagnostic.hh:112
std::shared_ptr< Diagnostic > Ptr
Definition: Diagnostic.hh:64
IceGrid::ConstPtr m_grid
the grid
Definition: Diagnostic.hh:106
void set_attrs(const std::string &long_name, const std::string &standard_name, const std::string &units, const std::string &glaciological_units, unsigned int N=0)
A method for setting common variable attributes.
Definition: Diagnostic.cc:132
High-level PISM I/O class.
Definition: File.hh:51
std::shared_ptr< const IceGrid > ConstPtr
Definition: IceGrid.hh:233
std::shared_ptr< IceModelVec2S > Ptr
Definition: iceModelVec.hh:341
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Definition: iceModelVec.cc:533
void set_attrs(const std::string &pism_intent, const std::string &long_name, const std::string &units, const std::string &glaciological_units, const std::string &standard_name, unsigned int component)
Sets NetCDF attributes of an IceModelVec object.
Definition: iceModelVec.cc:399
void regrid(const std::string &filename, RegriddingFlag flag, double default_value=0.0)
Definition: iceModelVec.cc:838
std::shared_ptr< IceModelVec > Ptr
Definition: iceModelVec.hh:206
virtual void begin_access() const
Checks if an IceModelVec is allocated and calls DAVecGetArray.
Definition: iceModelVec.cc:622
void read(const std::string &filename, unsigned int time)
Definition: iceModelVec.cc:833
void define(const File &file, IO_Type default_type=PISM_DOUBLE) const
Define variables corresponding to an IceModelVec in a file opened using file.
Definition: iceModelVec.cc:523
void write(const std::string &filename) const
Definition: iceModelVec.cc:822
virtual void end_access() const
Checks if an IceModelVec is allocated and calls DAVecRestoreArray.
Definition: iceModelVec.cc:643
void set_time_independent(bool flag)
Set the time independent flag for all variables corresponding to this IceModelVec instance.
Definition: iceModelVec.cc:175
Spatial NetCDF variable (corresponding to a 2D or 3D scalar field).
virtual DiagnosticList diagnostics_impl() const
std::vector< double > m_ts_times
A purely virtual class defining the interface of a PISM Atmosphere Model.
virtual void define_model_state_impl(const File &output) const
The default (empty implementation).
Definition: YearlyCycle.cc:84
virtual const IceModelVec2S & mean_precipitation_impl() const
Copies the stored precipitation field into result.
Definition: YearlyCycle.cc:93
void init_internal(const std::string &input_filename, bool regrid, unsigned int start)
Read precipitation data from a given file.
Definition: YearlyCycle.cc:70
YearlyCycle(IceGrid::ConstPtr g)
Definition: YearlyCycle.cc:36
virtual void init_impl(const Geometry &geometry)
Reads in the precipitation data from the input file.
Definition: YearlyCycle.cc:62
std::vector< double > m_cosine_cycle
Definition: YearlyCycle.hh:65
virtual void init_timeseries_impl(const std::vector< double > &ts) const
Definition: YearlyCycle.cc:107
IceModelVec2S m_air_temp_mean_annual
Definition: YearlyCycle.hh:64
virtual void end_pointwise_access_impl() const
Definition: YearlyCycle.cc:144
virtual void write_model_state_impl(const File &output) const
The default (empty implementation).
Definition: YearlyCycle.cc:88
virtual void begin_pointwise_access_impl() const
Definition: YearlyCycle.cc:138
IceModelVec2S m_air_temp_mean_summer
Definition: YearlyCycle.hh:64
virtual DiagnosticList diagnostics_impl() const
Definition: YearlyCycle.cc:178
virtual void temp_time_series_impl(int i, int j, std::vector< double > &result) const
Definition: YearlyCycle.cc:131
virtual const IceModelVec2S & mean_annual_temp_impl() const
Copies the stored mean annual near-surface air temperature field into result.
Definition: YearlyCycle.cc:98
virtual void precip_time_series_impl(int i, int j, std::vector< double > &result) const
Definition: YearlyCycle.cc:124
virtual const IceModelVec2S & mean_summer_temp() const
Copies the stored mean summer near-surface air temperature field into result.
Definition: YearlyCycle.cc:103
Mean summer near-surface air temperature.
Definition: YearlyCycle.cc:154
InputOptions process_input_options(MPI_Comm com, Config::ConstPtr config)
Definition: Component.cc:45
static const double g
Definition: exactTestP.cc:39
@ INIT_BOOTSTRAP
Definition: Component.hh:39
std::map< std::string, Diagnostic::Ptr > DiagnosticList
Definition: Diagnostic.hh:117
static const double k
Definition: exactTestP.cc:45
@ CRITICAL
Definition: IO_Flags.hh:70
@ WITHOUT_GHOSTS
Definition: iceModelVec.hh:49
InitializationType type
initialization type
Definition: Component.hh:44
std::string filename
name of the input file (if applicable)
Definition: Component.hh:46
unsigned int record
index of the record to re-start from
Definition: Component.hh:48