PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
GivenClimate.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/GivenClimate.hh"
20
21#include "pism/coupler/util/options.hh"
22#include "pism/util/Grid.hh"
23#include "pism/util/Config.hh"
24#include "pism/util/Time.hh"
25#include "pism/util/array/Forcing.hh"
26#include "pism/util/Logger.hh"
27#include "pism/util/io/IO_Flags.hh"
28
29namespace pism {
30namespace atmosphere {
31
32Given::Given(std::shared_ptr<const Grid> g)
33 : AtmosphereModel(g, std::shared_ptr<AtmosphereModel>()) {
34 ForcingOptions opt(*m_grid->ctx(), "atmosphere.given");
35
36 {
37 unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
38
40
41 auto interp_type = m_config->get_string("atmosphere.given.air_temperature_interpolation");
42
43 InterpolationType interpolation = interp_type == "piecewise_linear" ? LINEAR : PIECEWISE_CONSTANT;
44
45 m_air_temp = std::make_shared<array::Forcing>(m_grid,
46 file,
47 "air_temp",
48 "", // no standard name
49 buffer_size,
50 opt.periodic,
51 interpolation);
52
53 m_precipitation = std::make_shared<array::Forcing>(m_grid,
54 file,
55 "precipitation",
56 "", // no standard name
57 buffer_size,
58 opt.periodic);
59 }
60
61 {
62 m_air_temp->metadata(0)
63 .long_name("mean annual near-surface air temperature")
64 .units("kelvin");
65 m_air_temp->metadata(0)["valid_range"] = { 0.0, 323.15 }; // (0 C, 50 C)
66 }
67 {
68 m_precipitation->metadata(0)
69 .long_name("precipitation rate")
70 .units("kg m^-2 second^-1")
71 .output_units("kg m^-2 year^-1")
72 .standard_name("precipitation_flux");
73 }
74}
75
76void Given::init_impl(const Geometry &geometry) {
77 m_log->message(2,
78 "* Initializing the atmosphere model reading near-surface air temperature\n"
79 " and ice-equivalent precipitation from a file...\n");
80
81 ForcingOptions opt(*m_grid->ctx(), "atmosphere.given");
82
83 m_air_temp->init(opt.filename, opt.periodic);
84 m_precipitation->init(opt.filename, opt.periodic);
85
86 // read time-independent data right away:
87 if (m_air_temp->buffer_size() == 1 && m_precipitation->buffer_size() == 1) {
88 update(geometry, time().current(), 0); // dt is irrelevant
89 }
90}
91
92void Given::update_impl(const Geometry &geometry, double t, double dt) {
93 (void) geometry;
94
95 m_precipitation->update(t, dt);
96 m_air_temp->update(t, dt);
97
98 m_precipitation->average(t, dt);
99 m_air_temp->average(t, dt);
100}
101
103 return *m_precipitation;
104}
105
107 return *m_air_temp;
108}
109
111
113 m_precipitation->begin_access();
114}
115
117
118 m_air_temp->end_access();
119 m_precipitation->end_access();
120}
121
122void Given::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
123
124 m_air_temp->interp(i, j, result);
125}
126
127void Given::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
128
129 m_precipitation->interp(i, j, result);
130}
131
132void Given::init_timeseries_impl(const std::vector<double> &ts) const {
133
134 m_air_temp->init_interpolation(ts);
135
136 m_precipitation->init_interpolation(ts);
137
138 m_ts_times = ts;
139}
140
141
142} // end of namespace atmosphere
143} // end of namespace pism
const Time & time() const
Definition Component.cc:111
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
void update(const Geometry &geometry, double t, double dt)
A purely virtual class defining the interface of a PISM Atmosphere Model.
void end_pointwise_access_impl() const
void update_impl(const Geometry &geometry, double t, double dt)
std::shared_ptr< array::Forcing > m_air_temp
void init_impl(const Geometry &geometry)
void precip_time_series_impl(int i, int j, std::vector< double > &values) const
std::shared_ptr< array::Forcing > m_precipitation
void init_timeseries_impl(const std::vector< double > &ts) const
const array::Scalar & precipitation_impl() const
void temp_time_series_impl(int i, int j, std::vector< double > &values) const
const array::Scalar & air_temperature_impl() const
void begin_pointwise_access_impl() const
Given(std::shared_ptr< const Grid > g)
@ PISM_NETCDF3
Definition IO_Flags.hh:58
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:69
@ PIECEWISE_CONSTANT
static const double g
Definition exactTestP.cc:36
std::string filename
Definition options.hh:33