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