PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
YearlyCycle.cc
Go to the documentation of this file.
1// Copyright (C) 2008-2020, 2023, 2024, 2025 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 "pism/coupler/atmosphere/YearlyCycle.hh"
26#include "pism/util/Time.hh"
27#include "pism/util/Grid.hh"
28#include "pism/util/Config.hh"
29#include "pism/util/Logger.hh"
30#include "pism/util/io/IO_Flags.hh"
31
32namespace pism {
33namespace atmosphere {
34
35YearlyCycle::YearlyCycle(std::shared_ptr<const Grid> g)
37 m_air_temp_mean_annual(m_grid, "air_temp_mean_annual"),
38 m_air_temp_mean_summer(m_grid, "air_temp_mean_summer"),
39 m_precipitation(m_grid, "precipitation") {
40
41 m_snow_temp_summer_day = m_config->get_number("atmosphere.fausto_air_temp.summer_peak_day");
42
44 .long_name(
45 "mean annual near-surface air temperature (without sub-year time-dependence or forcing)")
46 .units("kelvin");
48
50 .long_name(
51 "mean summer (NH: July/ SH: January) near-surface air temperature (without sub-year time-dependence or forcing)")
52 .units("kelvin");
54
56 .long_name("precipitation rate")
57 .units("kg m^-2 second^-1")
58 .output_units("kg m^-2 year^-1")
59 .standard_name("precipitation_flux")
60 .set_time_dependent(false);
61}
62
63//! Reads in the precipitation data from the input file.
64void YearlyCycle::init_impl(const Geometry &geometry) {
65 (void) geometry;
66
68 init_internal(opts.filename, opts.type == INIT_BOOTSTRAP, opts.record);
69}
70
71//! Read precipitation data from a given file.
72void YearlyCycle::init_internal(const std::string &input_filename, bool do_regrid,
73 unsigned int start) {
74 // read precipitation rate from file
75 m_log->message(2,
76 " reading mean annual ice-equivalent precipitation rate 'precipitation'\n"
77 " from %s ... \n",
78 input_filename.c_str());
79 if (do_regrid == true) {
80 m_precipitation.regrid(input_filename, io::Default::Nil()); // fails if not found!
81 } else {
82 m_precipitation.read(input_filename, start); // fails if not found!
83 }
84}
85
86std::set<VariableMetadata> YearlyCycle::state_impl() const {
88}
89
90void YearlyCycle::write_state_impl(const OutputFile &output) const {
91 m_precipitation.write(output);
92}
93
94//! Copies the stored precipitation field into result.
98
99//! Copies the stored mean annual near-surface air temperature field into result.
103
104//! Copies the stored mean summer near-surface air temperature field into result.
108
109void YearlyCycle::init_timeseries_impl(const std::vector<double> &ts) const {
110 // constants related to the standard yearly cycle
111 const double
113
114 size_t N = ts.size();
115
116 m_ts_times.resize(N);
117 m_cosine_cycle.resize(N);
118 for (unsigned int k = 0; k < m_ts_times.size(); k++) {
119 double tk = time().year_fraction(ts[k]) - summerday_fraction;
120
121 m_ts_times[k] = ts[k];
122 m_cosine_cycle[k] = cos(2.0 * M_PI * tk);
123 }
124}
125
126void YearlyCycle::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
127 result.resize(m_ts_times.size());
128 for (unsigned int k = 0; k < m_ts_times.size(); k++) {
129 result[k] = m_precipitation(i,j);
130 }
131}
132
133void YearlyCycle::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
134 result.resize(m_ts_times.size());
135 for (unsigned int k = 0; k < m_ts_times.size(); ++k) {
137 }
138}
139
145
151
152namespace diagnostics {
153
154/*! @brief Mean summer near-surface air temperature. */
155class MeanSummerTemperature : public Diag<YearlyCycle>
156{
157public:
159 m_vars = { { m_sys, "air_temp_mean_summer", *m_grid } };
160 m_vars[0]
161 .long_name("mean summer near-surface air temperature used in the cosine yearly cycle")
162 .units("kelvin");
163 }
164
165private:
166 std::shared_ptr<array::Array> compute_impl() const {
167 auto result = allocate<array::Scalar>("air_temp_mean_summer");
168
169 result->copy_from(model->mean_summer_temp());
170
171 return result;
172 }
173};
174} // end of namespace diagnostics
175
178
179 result["air_temp_mean_summer"] = Diagnostic::Ptr(new diagnostics::MeanSummerTemperature(this));
180
181 return result;
182}
183
184} // end of namespace atmosphere
185} // end of namespace pism
const Time & time() const
Definition Component.cc:111
std::shared_ptr< const Config > m_config
configuration database used by this component
Definition Component.hh:160
const std::shared_ptr< const Grid > m_grid
grid used by this component
Definition Component.hh:158
std::shared_ptr< const Logger > m_log
logger (for easy access)
Definition Component.hh:164
const YearlyCycle * model
A template derived from Diagnostic, adding a "Model".
std::vector< VariableMetadata > m_vars
metadata corresponding to NetCDF variables
const units::System::Ptr m_sys
the unit system
std::shared_ptr< Diagnostic > Ptr
Definition Diagnostic.hh:67
std::shared_ptr< const Grid > m_grid
the grid
double year_fraction(double T) const
Returns the fraction of a year that passed since the last beginning of a year. Only useful in codes w...
Definition Time.cc:835
double day_of_the_year_to_year_fraction(unsigned int day) const
Convert the day number to the year fraction.
Definition Time.cc:525
VariableMetadata & long_name(const std::string &input)
VariableMetadata & units(const std::string &input)
VariableMetadata & standard_name(const std::string &input)
VariableMetadata & output_units(const std::string &input)
VariableMetadata & set_time_dependent(bool flag)
void read(const std::string &filename, unsigned int time)
Definition Array.cc:753
virtual void end_access() const
Checks if an Array is allocated and calls DAVecRestoreArray.
Definition Array.cc:619
void write(const OutputFile &file) const
Definition Array.cc:859
virtual void begin_access() const
Checks if an Array is allocated and calls DAVecGetArray.
Definition Array.cc:598
void regrid(const std::string &filename, io::Default default_value)
Definition Array.cc:758
VariableMetadata & metadata(unsigned int N=0)
Returns a reference to the VariableMetadata object containing metadata for the compoment N.
Definition Array.cc:467
virtual DiagnosticList spatial_diagnostics_impl() const
A purely virtual class defining the interface of a PISM Atmosphere Model.
array::Scalar m_air_temp_mean_summer
void init_internal(const std::string &input_filename, bool regrid, unsigned int start)
Read precipitation data from a given file.
YearlyCycle(std::shared_ptr< const Grid > g)
virtual const array::Scalar & mean_summer_temp() const
Copies the stored mean summer near-surface air temperature field into result.
virtual std::set< VariableMetadata > state_impl() const
virtual void init_impl(const Geometry &geometry)
Reads in the precipitation data from the input file.
virtual DiagnosticList spatial_diagnostics_impl() const
std::vector< double > m_cosine_cycle
virtual void init_timeseries_impl(const std::vector< double > &ts) const
virtual void end_pointwise_access_impl() const
virtual void begin_pointwise_access_impl() const
array::Scalar m_air_temp_mean_annual
virtual void temp_time_series_impl(int i, int j, std::vector< double > &result) const
virtual void write_state_impl(const OutputFile &output) const
The default (empty implementation).
virtual const array::Scalar & air_temperature_impl() const
Copies the stored mean annual near-surface air temperature field into result.
virtual void precip_time_series_impl(int i, int j, std::vector< double > &result) const
virtual const array::Scalar & precipitation_impl() const
Copies the stored precipitation field into result.
std::shared_ptr< array::Array > compute_impl() const
Mean summer near-surface air temperature.
static Default Nil()
Definition IO_Flags.hh:94
std::set< VariableMetadata > metadata(std::initializer_list< const Array * > vecs)
Definition Array.cc:1244
static const double g
Definition exactTestP.cc:36
@ INIT_BOOTSTRAP
Definition Component.hh:56
std::map< std::string, Diagnostic::Ptr > DiagnosticList
static const double k
Definition exactTestP.cc:42
InputOptions process_input_options(MPI_Comm com, std::shared_ptr< const Config > config)
Definition Component.cc:45
InitializationType type
initialization type
Definition Component.hh:61
std::string filename
name of the input file (if applicable)
Definition Component.hh:63
unsigned int record
index of the record to re-start from
Definition Component.hh:65