PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
Anomaly.cc
Go to the documentation of this file.
1// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021, 2022, 2023, 2024, 2025 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/Anomaly.hh"
20
21#include "pism/util/Config.hh"
22#include "pism/util/Grid.hh"
23#include "pism/coupler/util/options.hh"
24#include "pism/util/array/Forcing.hh"
25#include "pism/util/Logger.hh"
26#include "pism/util/io/IO_Flags.hh"
27
28namespace pism {
29namespace atmosphere {
30
31Anomaly::Anomaly(std::shared_ptr<const Grid> g, std::shared_ptr<AtmosphereModel> in)
32 : AtmosphereModel(g, in) {
33
34 ForcingOptions opt(*m_grid->ctx(), "atmosphere.anomaly");
35
36 {
37 unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
38
40
41 m_air_temp_anomaly = std::make_shared<array::Forcing>(m_grid,
42 file,
43 "air_temp_anomaly",
44 "", // no standard name
45 buffer_size,
46 opt.periodic,
47 LINEAR);
48
49 m_precipitation_anomaly = std::make_shared<array::Forcing>(m_grid,
50 file,
51 "precipitation_anomaly",
52 "", // no standard name
53 buffer_size,
54 opt.periodic);
55 }
56
57 m_air_temp_anomaly->metadata(0)
58 .long_name("anomaly of the near-surface air temperature")
59 .units("kelvin");
60
61 m_precipitation_anomaly->metadata(0)
62 .long_name("anomaly of the ice-equivalent precipitation rate")
63 .units("kg m^-2 second^-1")
64 .output_units("kg m^-2 year^-1");
65
68}
69
70void Anomaly::init_impl(const Geometry &geometry) {
71 m_input_model->init(geometry);
72
73 ForcingOptions opt(*m_grid->ctx(), "atmosphere.anomaly");
74
75 m_log->message(2,
76 "* Initializing the -atmosphere ...,anomaly code...\n");
77
78 m_log->message(2,
79 " reading anomalies from %s ...\n",
80 opt.filename.c_str());
81
82 m_air_temp_anomaly->init(opt.filename, opt.periodic);
84}
85
86void Anomaly::update_impl(const Geometry &geometry, double t, double dt) {
87 m_input_model->update(geometry, t, dt);
88
89 m_precipitation_anomaly->update(t, dt);
90 m_air_temp_anomaly->update(t, dt);
91
92 m_precipitation_anomaly->average(t, dt);
93 m_air_temp_anomaly->average(t, dt);
94
95 // precipitation
96 {
97 m_precipitation->copy_from(m_input_model->precipitation());
99 }
100
101 // temperature
102 {
103 m_temperature->copy_from(m_input_model->air_temperature());
105 }
106}
107
111
115
117 m_input_model->begin_pointwise_access();
119 m_precipitation_anomaly->begin_access();
120}
121
123 m_input_model->end_pointwise_access();
124 m_precipitation_anomaly->end_access();
125 m_air_temp_anomaly->end_access();
126}
127
128void Anomaly::init_timeseries_impl(const std::vector<double> &ts) const {
130
131 m_air_temp_anomaly->init_interpolation(ts);
132
133 m_precipitation_anomaly->init_interpolation(ts);
134}
135
136void Anomaly::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
137 m_input_model->temp_time_series(i, j, result);
138
139 m_temp_anomaly.reserve(m_ts_times.size());
140 m_air_temp_anomaly->interp(i, j, m_temp_anomaly);
141
142 for (unsigned int k = 0; k < m_ts_times.size(); ++k) {
143 result[k] += m_temp_anomaly[k];
144 }
145}
146
147void Anomaly::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
148 m_input_model->precip_time_series(i, j, result);
149
150 m_mass_flux_anomaly.reserve(m_ts_times.size());
152
153 for (unsigned int k = 0; k < m_ts_times.size(); ++k) {
154 result[k] += m_mass_flux_anomaly[k];
155 }
156}
157
158} // end of namespace atmosphere
159} // end of namespace pism
std::shared_ptr< const Config > m_config
configuration database used by this component
Definition Component.hh:160
const std::shared_ptr< const Grid > m_grid
grid used by this component
Definition Component.hh:158
std::shared_ptr< const Logger > m_log
logger (for easy access)
Definition Component.hh:164
High-level PISM I/O class.
Definition File.hh:57
virtual void begin_access() const
Checks if an Array is allocated and calls DAVecGetArray.
Definition Array.cc:598
std::shared_ptr< array::Forcing > m_air_temp_anomaly
Definition Anomaly.hh:49
std::shared_ptr< array::Scalar > m_temperature
Definition Anomaly.hh:53
std::vector< double > m_mass_flux_anomaly
Definition Anomaly.hh:47
void init_timeseries_impl(const std::vector< double > &ts) const
Definition Anomaly.cc:128
const array::Scalar & precipitation_impl() const
Definition Anomaly.cc:108
std::shared_ptr< array::Forcing > m_precipitation_anomaly
Definition Anomaly.hh:50
void temp_time_series_impl(int i, int j, std::vector< double > &values) const
Definition Anomaly.cc:136
void end_pointwise_access_impl() const
Definition Anomaly.cc:122
void init_impl(const Geometry &geometry)
Definition Anomaly.cc:70
std::shared_ptr< array::Scalar > m_precipitation
Definition Anomaly.hh:52
void precip_time_series_impl(int i, int j, std::vector< double > &values) const
Definition Anomaly.cc:147
void begin_pointwise_access_impl() const
Definition Anomaly.cc:116
void update_impl(const Geometry &geometry, double t, double dt)
Definition Anomaly.cc:86
const array::Scalar & air_temperature_impl() const
Definition Anomaly.cc:112
std::vector< double > m_temp_anomaly
Definition Anomaly.hh:47
Anomaly(std::shared_ptr< const Grid > g, std::shared_ptr< AtmosphereModel > in)
Definition Anomaly.cc:31
virtual void init_timeseries_impl(const std::vector< double > &ts) const
static std::shared_ptr< array::Scalar > allocate_temperature(std::shared_ptr< const Grid > grid)
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.
@ PISM_NETCDF3
Definition IO_Flags.hh:58
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:69
static const double g
Definition exactTestP.cc:36
static const double k
Definition exactTestP.cc:42
std::string filename
Definition options.hh:33