tCosineYearlyCycle.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tCosineYearlyCycle.cc (3202B)
---
1 // Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018 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 "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/IceGrid.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/coupler/util/ScalarForcing.hh"
30
31 namespace pism {
32 namespace atmosphere {
33
34 CosineYearlyCycle::CosineYearlyCycle(IceGrid::ConstPtr 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 CosineYearlyCycle::~CosineYearlyCycle() {
49 // empty
50 }
51
52 void CosineYearlyCycle::init_impl(const Geometry &geometry) {
53 (void) geometry;
54
55 m_log->message(2,
56 "* Initializing the 'cosine yearly cycle' atmosphere model...\n");
57
58 auto input_file = m_config->get_string("atmosphere.yearly_cycle.file");
59
60 if (input_file.empty()) {
61 throw RuntimeError(PISM_ERROR_LOCATION,
62 "Please specify an '-atmosphere yearly_cycle' input file\n"
63 "using atmosphere.yearly_cycle.file or a command-line option.");
64 }
65
66 m_log->message(2,
67 " Reading mean annual air temperature, mean July air temperature, and\n"
68 " precipitation fields from '%s'...\n", input_file.c_str());
69
70 m_air_temp_mean_annual.regrid(input_file, CRITICAL);
71 m_air_temp_mean_summer.regrid(input_file, CRITICAL);
72 m_precipitation.regrid(input_file, CRITICAL);
73
74 if (m_A) {
75 m_A->init();
76 }
77 }
78
79 MaxTimestep CosineYearlyCycle::max_timestep_impl(double t) const {
80 (void) t;
81 return MaxTimestep("atmosphere cosine_yearly_cycle");
82 }
83
84 void CosineYearlyCycle::update_impl(const Geometry &geometry, double t, double dt) {
85 (void) geometry;
86 if (m_A) {
87 m_A->update(t, dt);
88 }
89 }
90
91 void CosineYearlyCycle::init_timeseries_impl(const std::vector<double> &ts) const {
92
93 YearlyCycle::init_timeseries_impl(ts);
94
95 if (m_A) {
96 for (unsigned int k = 0; k < ts.size(); ++k) {
97 m_cosine_cycle[k] *= m_A->value(ts[k]);
98 }
99 }
100 }
101
102 } // end of namespace atmosphere
103 } // end of namespace pism