tPrecipitationScaling.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
---
tPrecipitationScaling.cc (2959B)
---
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 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 "PrecipitationScaling.hh"
20
21 #include "pism/coupler/util/ScalarForcing.hh"
22 #include "pism/util/ConfigInterface.hh"
23
24 namespace pism {
25 namespace atmosphere {
26
27 PrecipitationScaling::PrecipitationScaling(IceGrid::ConstPtr grid,
28 std::shared_ptr<AtmosphereModel> in)
29 : AtmosphereModel(grid, in) {
30
31 m_forcing.reset(new ScalarForcing(grid->ctx(),
32 "atmosphere.precip_scaling",
33 "delta_T",
34 "Kelvin",
35 "Kelvin",
36 "air temperature offsets"));
37
38 m_exp_factor = m_config->get_number("atmosphere.precip_exponential_factor_for_temperature");
39
40 m_precipitation = allocate_precipitation(grid);
41 }
42
43 PrecipitationScaling::~PrecipitationScaling() {
44 // empty
45 }
46
47 void PrecipitationScaling::init_impl(const Geometry &geometry) {
48 m_input_model->init(geometry);
49
50 m_log->message(2,
51 "* Initializing precipitation scaling"
52 " using temperature offsets...\n");
53
54 m_forcing->init();
55 }
56
57 void PrecipitationScaling::init_timeseries_impl(const std::vector<double> &ts) const {
58 AtmosphereModel::init_timeseries_impl(ts);
59
60 m_scaling_values.resize(ts.size());
61 for (unsigned int k = 0; k < ts.size(); ++k) {
62 m_scaling_values[k] = exp(m_exp_factor * m_forcing->value(ts[k]));
63 }
64 }
65
66 void PrecipitationScaling::update_impl(const Geometry &geometry, double t, double dt) {
67 m_input_model->update(geometry, t, dt);
68 m_forcing->update(t, dt);
69
70 m_precipitation->copy_from(m_input_model->mean_precipitation());
71 m_precipitation->scale(exp(m_exp_factor * m_forcing->value()));
72 }
73
74 const IceModelVec2S& PrecipitationScaling::mean_precipitation_impl() const {
75 return *m_precipitation;
76 }
77
78 void PrecipitationScaling::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
79 m_input_model->precip_time_series(i, j, result);
80
81 for (unsigned int k = 0; k < m_scaling_values.size(); ++k) {
82 result[k] *= m_scaling_values[k];
83 }
84 }
85
86 } // end of namespace atmosphere
87 } // end of namespace pism