Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PrecipitationScaling.cc
Go to the documentation of this file.
1// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020, 2021, 2022, 2023, 2024 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#include <cmath> // exp()
19
20#include "pism/coupler/atmosphere/PrecipitationScaling.hh"
21
22#include "pism/util/ScalarForcing.hh"
23#include "pism/util/ConfigInterface.hh"
24
25namespace pism {
26namespace atmosphere {
27
28PrecipitationScaling::PrecipitationScaling(std::shared_ptr<const Grid> grid,
29 std::shared_ptr<AtmosphereModel> in)
30 : AtmosphereModel(grid, in) {
31
32 m_forcing.reset(new ScalarForcing(*grid->ctx(),
33 "atmosphere.precip_scaling",
34 "delta_T",
35 "kelvin",
36 "kelvin",
37 "air temperature offsets"));
38
39 m_exp_factor = m_config->get_number("atmosphere.precip_exponential_factor_for_temperature");
40
42}
43
45 m_input_model->init(geometry);
46
47 m_log->message(2,
48 "* Initializing precipitation scaling"
49 " using temperature offsets...\n");
50}
51
52void PrecipitationScaling::init_timeseries_impl(const std::vector<double> &ts) const {
54
55 m_scaling_values.resize(ts.size());
56 for (unsigned int k = 0; k < ts.size(); ++k) {
57 m_scaling_values[k] = exp(m_exp_factor * m_forcing->value(ts[k]));
58 }
59}
60
61void PrecipitationScaling::update_impl(const Geometry &geometry, double t, double dt) {
62 m_input_model->update(geometry, t, dt);
63
64 m_precipitation->copy_from(m_input_model->precipitation());
65 m_precipitation->scale(exp(m_exp_factor * m_forcing->value(t + 0.5 * dt)));
66}
67
71
72void PrecipitationScaling::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
73 m_input_model->precip_time_series(i, j, result);
74
75 for (unsigned int k = 0; k < m_scaling_values.size(); ++k) {
76 result[k] *= m_scaling_values[k];
77 }
78}
79
80} // end of namespace atmosphere
81} // 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
virtual void init_timeseries_impl(const std::vector< double > &ts) const
std::shared_ptr< AtmosphereModel > m_input_model
static std::shared_ptr< array::Scalar > allocate_precipitation(std::shared_ptr< const Grid > grid)
A purely virtual class defining the interface of a PISM Atmosphere Model.
std::shared_ptr< ScalarForcing > m_forcing
void init_timeseries_impl(const std::vector< double > &ts) const
void update_impl(const Geometry &geometry, double t, double dt)
void precip_time_series_impl(int i, int j, std::vector< double > &values) const
PrecipitationScaling(std::shared_ptr< const Grid > g, std::shared_ptr< AtmosphereModel > in)
const array::Scalar & precipitation_impl() const
std::shared_ptr< array::Scalar > m_precipitation
void init_impl(const Geometry &geometry)
static const double k
Definition exactTestP.cc:42