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/surface/GivenClimate.hh"
20
21#include "pism/util/Time.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 surface {
30
31Given::Given(std::shared_ptr<const Grid> grid, std::shared_ptr<atmosphere::AtmosphereModel> input)
32 : SurfaceModel(grid)
33{
34 (void) input;
35
36 ForcingOptions opt(*m_grid->ctx(), "surface.given");
37
38 {
39 unsigned int buffer_size = m_config->get_number("input.forcing.buffer_size");
40
42
43 m_temperature = std::make_shared<array::Forcing>(m_grid,
44 file,
45 "ice_surface_temp",
46 "", // no standard name
47 buffer_size,
48 opt.periodic,
49 LINEAR);
50
51 m_mass_flux = std::make_shared<array::Forcing>(m_grid,
52 file,
53 "climatic_mass_balance",
54 "land_ice_surface_specific_mass_balance_flux",
55 buffer_size,
56 opt.periodic);
57 }
58
59 m_temperature->metadata(0)
60 .long_name("temperature of the ice at the ice surface but below firn processes")
61 .units("kelvin");
62 m_temperature->metadata()["valid_range"] = { 0.0, 323.15 }; // [0C, 50C]
63
64 const double smb_max = m_config->get_number("surface.given.smb_max", "kg m-2 second-1");
65
66 m_mass_flux->metadata(0)
67 .long_name("surface mass balance (accumulation/ablation) rate")
68 .units("kg m^-2 s^-1")
69 .output_units("kg m^-2 year^-1")
70 .standard_name("land_ice_surface_specific_mass_balance_flux");
71
72 m_mass_flux->metadata()["valid_range"] = {-smb_max, smb_max};
73}
74
75void Given::init_impl(const Geometry &geometry) {
76
77 m_log->message(2,
78 "* Initializing the surface model reading temperature at the top of the ice\n"
79 " and ice surface mass flux from a file...\n");
80
81 ForcingOptions opt(*m_grid->ctx(), "surface.given");
82
83 m_temperature->init(opt.filename, opt.periodic);
84 m_mass_flux->init(opt.filename, opt.periodic);
85
86 // read time-independent data right away:
87 if (m_temperature->buffer_size() == 1 && m_mass_flux->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_mass_flux->update(t, dt);
96 m_temperature->update(t, dt);
97
98 m_mass_flux->average(t, dt);
99 m_temperature->average(t, dt);
100
104
105}
106
108 return *m_mass_flux;
109}
110
112 return *m_temperature;
113}
114
116 return *m_accumulation;
117}
118
120 return *m_melt;
121}
122
124 return *m_runoff;
125}
126
127std::set<VariableMetadata> Given::state_impl() const {
128 return array::metadata({ m_mass_flux.get(), m_temperature.get() });
129}
130
131void Given::write_state_impl(const OutputFile &output) const {
132 m_mass_flux->write(output);
133 m_temperature->write(output);
134}
135
136} // end of namespace surface
137} // 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
void write(const OutputFile &file) const
Definition Array.cc:859
void write_state_impl(const OutputFile &output) const
The default (empty implementation).
const array::Scalar & accumulation_impl() const
const array::Scalar & melt_impl() const
const array::Scalar & runoff_impl() const
const array::Scalar & mass_flux_impl() const
std::set< VariableMetadata > state_impl() const
Given(std::shared_ptr< const Grid > g, std::shared_ptr< atmosphere::AtmosphereModel > input)
std::shared_ptr< array::Forcing > m_temperature
void update_impl(const Geometry &geometry, double t, double dt)
void init_impl(const Geometry &geometry)
std::shared_ptr< array::Forcing > m_mass_flux
const array::Scalar & temperature_impl() const
void update(const Geometry &geometry, double t, double dt)
void dummy_accumulation(const array::Scalar &smb, array::Scalar &result)
std::shared_ptr< array::Scalar > m_melt
std::shared_ptr< array::Scalar > m_runoff
void dummy_melt(const array::Scalar &smb, array::Scalar &result)
std::shared_ptr< array::Scalar > m_accumulation
void dummy_runoff(const array::Scalar &smb, array::Scalar &result)
The interface of PISM's surface models.
std::set< VariableMetadata > metadata(std::initializer_list< const Array * > vecs)
Definition Array.cc:1244
@ PISM_GUESS
Definition IO_Flags.hh:57
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:69
std::string filename
Definition options.hh:33