PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
CosineYearlyCycle.cc
Go to the documentation of this file.
1 // Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2021, 2023 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 #include "pism/coupler/atmosphere/CosineYearlyCycle.hh"
20 #include "pism/util/Time.hh"
21 #include "pism/util/pism_options.hh"
22 #include "pism/util/ConfigInterface.hh"
23 #include "pism/util/Grid.hh"
24 #include "pism/util/io/File.hh"
25 
26 #include "pism/util/error_handling.hh"
27 #include "pism/util/MaxTimestep.hh"
28 
29 #include "pism/util/ScalarForcing.hh"
30 
31 namespace pism {
32 namespace atmosphere {
33 
34 CosineYearlyCycle::CosineYearlyCycle(std::shared_ptr<const Grid> grid)
35  : YearlyCycle(grid) {
36 
37  auto scaling_file = m_config->get_string("atmosphere.yearly_cycle.scaling.file");
38 
39  if (not scaling_file.empty()) {
40  m_A.reset(new ScalarForcing(*grid->ctx(),
41  "atmosphere.yearly_cycle.scaling",
42  "amplitude_scaling",
43  "1", "1",
44  "temperature amplitude scaling"));
45  }
46 }
47 
48 void CosineYearlyCycle::init_impl(const Geometry &geometry) {
49  (void) geometry;
50 
51  m_log->message(2,
52  "* Initializing the 'cosine yearly cycle' atmosphere model...\n");
53 
54  auto input_file = m_config->get_string("atmosphere.yearly_cycle.file");
55 
56  if (input_file.empty()) {
58  "Please specify an '-atmosphere yearly_cycle' input file\n"
59  "using atmosphere.yearly_cycle.file or a command-line option.");
60  }
61 
62  m_log->message(2,
63  " Reading mean annual air temperature, mean July air temperature, and\n"
64  " precipitation fields from '%s'...\n", input_file.c_str());
65 
69 }
70 
72  (void) t;
73  return MaxTimestep("atmosphere cosine_yearly_cycle");
74 }
75 
76 void CosineYearlyCycle::update_impl(const Geometry &geometry, double t, double dt) {
77  (void) geometry;
78  (void) t;
79  (void) dt;
80  // an implementation is necessary because the base class does not define this
81 }
82 
83 void CosineYearlyCycle::init_timeseries_impl(const std::vector<double> &ts) const {
84 
86 
87  if (m_A) {
88  for (unsigned int k = 0; k < ts.size(); ++k) {
89  m_cosine_cycle[k] *= m_A->value(ts[k]);
90  }
91  }
92 }
93 
94 } // end of namespace atmosphere
95 } // 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...
Definition: MaxTimestep.hh:31
void regrid(const std::string &filename, io::Default default_value)
Definition: Array.cc:814
std::shared_ptr< ScalarForcing > m_A
virtual void init_impl(const Geometry &geometry)
Reads in the precipitation data from the input file.
virtual MaxTimestep max_timestep_impl(double t) const
virtual void init_timeseries_impl(const std::vector< double > &ts) const
CosineYearlyCycle(std::shared_ptr< const Grid > g)
virtual void update_impl(const Geometry &geometry, double t, double dt)
array::Scalar m_air_temp_mean_summer
Definition: YearlyCycle.hh:63
std::vector< double > m_cosine_cycle
Definition: YearlyCycle.hh:64
virtual void init_timeseries_impl(const std::vector< double > &ts) const
Definition: YearlyCycle.cc:110
array::Scalar m_air_temp_mean_annual
Definition: YearlyCycle.hh:63
static Default Nil()
Definition: IO_Flags.hh:97
#define PISM_ERROR_LOCATION
static const double k
Definition: exactTestP.cc:42