tGivenClimate.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
---
tGivenClimate.cc (4589B)
---
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 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 "GivenClimate.hh"
20
21 #include "pism/coupler/util/options.hh"
22 #include "pism/util/IceGrid.hh"
23 #include "pism/util/ConfigInterface.hh"
24 #include "pism/util/Time.hh"
25
26 namespace pism {
27 namespace atmosphere {
28
29 Given::Given(IceGrid::ConstPtr g)
30 : AtmosphereModel(g, std::shared_ptr<AtmosphereModel>()) {
31 ForcingOptions opt(*m_grid->ctx(), "atmosphere.given");
32
33 {
34 unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
35 unsigned int evaluations_per_year = m_config->get_number("input.forcing.evaluations_per_year");
36 bool periodic = opt.period > 0;
37
38 File file(m_grid->com, opt.filename, PISM_NETCDF3, PISM_READONLY);
39
40 m_air_temp = IceModelVec2T::ForcingField(m_grid,
41 file,
42 "air_temp",
43 "", // no standard name
44 buffer_size,
45 evaluations_per_year,
46 periodic,
47 LINEAR);
48
49 m_precipitation = IceModelVec2T::ForcingField(m_grid,
50 file,
51 "precipitation",
52 "", // no standard name
53 buffer_size,
54 evaluations_per_year,
55 periodic);
56 }
57
58 {
59 m_air_temp->set_attrs("diagnostic", "mean annual near-surface air temperature",
60 "Kelvin", "Kelvin", "", 0);
61 m_air_temp->metadata(0).set_numbers("valid_range", {0.0, 323.15}); // (0 C, 50 C)
62 }
63 {
64 m_precipitation->set_attrs("model_state", "precipitation rate",
65 "kg m-2 second-1", "kg m-2 year-1", "precipitation_flux", 0);
66 }
67 }
68
69 Given::~Given() {
70 // empty
71 }
72
73 void Given::init_impl(const Geometry &geometry) {
74 m_log->message(2,
75 "* Initializing the atmosphere model reading near-surface air temperature\n"
76 " and ice-equivalent precipitation from a file...\n");
77
78 ForcingOptions opt(*m_grid->ctx(), "atmosphere.given");
79
80 m_air_temp->init(opt.filename, opt.period, opt.reference_time);
81 m_precipitation->init(opt.filename, opt.period, opt.reference_time);
82
83 // read time-independent data right away:
84 if (m_air_temp->n_records() == 1 && m_precipitation->n_records() == 1) {
85 update(geometry, m_grid->ctx()->time()->current(), 0); // dt is irrelevant
86 }
87 }
88
89 void Given::update_impl(const Geometry &geometry, double t, double dt) {
90 (void) geometry;
91
92 m_precipitation->update(t, dt);
93 m_air_temp->update(t, dt);
94
95 m_precipitation->average(t, dt);
96 m_air_temp->average(t, dt);
97 }
98
99 const IceModelVec2S& Given::mean_precipitation_impl() const {
100 return *m_precipitation;
101 }
102
103 const IceModelVec2S& Given::mean_annual_temp_impl() const {
104 return *m_air_temp;
105 }
106
107 void Given::begin_pointwise_access_impl() const {
108
109 m_air_temp->begin_access();
110 m_precipitation->begin_access();
111 }
112
113 void Given::end_pointwise_access_impl() const {
114
115 m_air_temp->end_access();
116 m_precipitation->end_access();
117 }
118
119 void Given::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
120
121 m_air_temp->interp(i, j, result);
122 }
123
124 void Given::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
125
126 m_precipitation->interp(i, j, result);
127 }
128
129 void Given::init_timeseries_impl(const std::vector<double> &ts) const {
130
131 m_air_temp->init_interpolation(ts);
132
133 m_precipitation->init_interpolation(ts);
134
135 m_ts_times = ts;
136 }
137
138
139 } // end of namespace atmosphere
140 } // end of namespace pism