PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
Initialization.cc
Go to the documentation of this file.
1/* Copyright (C) 2016, 2017, 2018, 2019, 2020, 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
20#include "pism/coupler/surface/Initialization.hh"
21#include "pism/util/error_handling.hh"
22#include "pism/util/io/File.hh"
23#include "pism/coupler/util/init_step.hh"
24#include "pism/util/Logger.hh"
25#include "pism/util/io/IO_Flags.hh"
26
27namespace pism {
28namespace surface {
29
30InitializationHelper::InitializationHelper(std::shared_ptr<const Grid> grid, std::shared_ptr<SurfaceModel> input)
31 : SurfaceModel(grid, input),
32 m_mass_flux(m_grid, "effective_climatic_mass_balance"),
33 m_temperature(m_grid, "effective_ice_surface_temp")
34{
35
36 if (not input) {
37 throw RuntimeError(PISM_ERROR_LOCATION, "pism::surface::InitializationHelper got a NULL input model");
38 }
39
40 // allocate storage
41 {
43 .long_name(
44 "surface mass balance (accumulation/ablation) rate, as seen by the ice dynamics code (used for restarting)")
45 .units("kg m^-2 s^-1")
46 .set_time_dependent(true);
47
49 .long_name(
50 "temperature of the ice at the ice surface but below firn processes, as seen by the ice dynamics code (used for restarting)")
51 .units("kelvin")
52 .set_time_dependent(true);
53
55 m_liquid_water_fraction->metadata().set_name("effective_ice_surface_liquid_water_fraction");
56 m_liquid_water_fraction->metadata(0)
57 .long_name(
58 "liquid water fraction of the ice at the top surface, as seen by the ice dynamics code (used for restarting)")
59 .units("1")
60 .set_time_dependent(true);
61
63 m_layer_mass->metadata().set_name("effective_surface_layer_mass");
64 m_layer_mass->metadata(0)
65 .long_name(
66 "mass held in the surface layer, as seen by the ice dynamics code (used for restarting)")
67 .units("kg")
68 .set_time_dependent(true);
69
71 m_layer_thickness->metadata().set_name("effective_surface_layer_thickness");
72 m_layer_thickness->metadata(0)
73 .long_name(
74 "thickness of the surface layer, as seen by the ice dynamics code (used for restarting)")
75 .units("meters")
76 .set_time_dependent(true);
77 }
78
80 m_accumulation->set_name("effective_" + m_accumulation->get_name());
81
83 m_melt->set_name("effective_" + m_melt->get_name());
84
86 m_runoff->set_name("effective_" + m_runoff->get_name());
87
88 // collect pointers
92 m_layer_mass.get(),
94 m_accumulation.get(),
95 m_melt.get(),
96 m_runoff.get()};
97}
98
100 m_input_model->init(geometry);
101
103
104 if (opts.type == INIT_RESTART) {
105 m_log->message(2, "* Reading effective surface model outputs from '%s' for re-starting...\n",
106 opts.filename.c_str());
107
109 const unsigned int last_record = file.nrecords() - 1;
110 for (auto *v : m_variables) {
111 v->read(file, last_record);
112 }
113 } else {
114 m_log->message(2, "* Performing a 'fake' surface model time-step for bootstrapping...\n");
115
116 init_step(this, geometry, time());
117 }
118
119 // Support regridding. This is needed to ensure that initialization using "-i" is equivalent to
120 // "-i ... -bootstrap -regrid_file ..."
121 for (auto *v : m_variables) {
122 regrid("surface model initialization helper", *v, REGRID_WITHOUT_REGRID_VARS);
123 }
124}
125
126void InitializationHelper::update_impl(const Geometry &geometry, double t, double dt) {
127 m_input_model->update(geometry, t, dt);
128
129 // store outputs of the input model
130 m_mass_flux.copy_from(m_input_model->mass_flux());
131 m_temperature.copy_from(m_input_model->temperature());
132 m_liquid_water_fraction->copy_from(m_input_model->liquid_water_fraction());
133 m_layer_mass->copy_from(m_input_model->layer_mass());
134 m_layer_thickness->copy_from(m_input_model->layer_thickness());
135 m_accumulation->copy_from(m_input_model->accumulation());
136 m_melt->copy_from(m_input_model->melt());
137 m_runoff->copy_from(m_input_model->runoff());
138}
139
143
147
151
155
159
163
165 return *m_melt;
166}
167
171
172std::set<VariableMetadata> InitializationHelper::state_impl() const {
173 std::set<VariableMetadata> variables{};
174 for (auto *v : m_variables) {
175 for (auto &nc_var : v->all_metadata()) {
176 variables.insert(nc_var);
177 }
178 }
179
180 return pism::combine(variables, m_input_model->state());
181}
182
184 for (auto *v : m_variables) {
185 v->write(output);
186 }
187 m_input_model->write_state(output);
188}
189
190
191
192} // end of namespace surface
193} // end of namespace pism
const Time & time() const
Definition Component.cc:111
std::shared_ptr< const Grid > grid() const
Definition Component.cc:107
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
void regrid(const std::string &module_name, array::Array &variable, RegriddingFlag flag=NO_REGRID_WITHOUT_REGRID_VARS)
Definition Component.cc:152
std::shared_ptr< const Logger > m_log
logger (for easy access)
Definition Component.hh:164
unsigned int nrecords() const
Get the number of records. Uses the length of an unlimited dimension.
Definition File.cc:280
High-level PISM I/O class.
Definition File.hh:57
VariableMetadata & long_name(const std::string &input)
VariableMetadata & units(const std::string &input)
VariableMetadata & set_time_dependent(bool flag)
void copy_from(const Array2D< T > &source)
Definition Array2D.hh:101
VariableMetadata & metadata(unsigned int N=0)
Returns a reference to the VariableMetadata object containing metadata for the compoment N.
Definition Array.cc:467
void init_impl(const Geometry &geometry)
const array::Scalar & accumulation_impl() const
void update_impl(const Geometry &geometry, double t, double dt)
std::vector< array::Array * > m_variables
const array::Scalar & temperature_impl() const
const array::Scalar & melt_impl() const
const array::Scalar & mass_flux_impl() const
InitializationHelper(std::shared_ptr< const Grid > g, std::shared_ptr< SurfaceModel > in)
const array::Scalar & runoff_impl() const
const array::Scalar & layer_mass_impl() const
std::set< VariableMetadata > state_impl() const
void write_state_impl(const OutputFile &output) const
The default (empty implementation).
const array::Scalar & layer_thickness_impl() const
const array::Scalar & liquid_water_fraction_impl() const
static std::shared_ptr< array::Scalar > allocate_runoff(std::shared_ptr< const Grid > grid)
std::shared_ptr< array::Scalar > m_melt
std::shared_ptr< array::Scalar > m_layer_thickness
static std::shared_ptr< array::Scalar > allocate_accumulation(std::shared_ptr< const Grid > grid)
static std::shared_ptr< array::Scalar > allocate_melt(std::shared_ptr< const Grid > grid)
std::shared_ptr< array::Scalar > m_runoff
static std::shared_ptr< array::Scalar > allocate_layer_thickness(std::shared_ptr< const Grid > grid)
std::shared_ptr< SurfaceModel > m_input_model
static std::shared_ptr< array::Scalar > allocate_layer_mass(std::shared_ptr< const Grid > grid)
std::shared_ptr< array::Scalar > m_layer_mass
std::shared_ptr< array::Scalar > m_accumulation
std::shared_ptr< array::Scalar > m_liquid_water_fraction
static std::shared_ptr< array::Scalar > allocate_liquid_water_fraction(std::shared_ptr< const Grid > grid)
The interface of PISM's surface models.
#define PISM_ERROR_LOCATION
@ PISM_GUESS
Definition IO_Flags.hh:57
@ PISM_READONLY
open an existing file for reading only
Definition IO_Flags.hh:69
@ INIT_RESTART
Definition Component.hh:56
void init_step(M *model, const In &inputs, const Time &time)
Definition init_step.hh:33
T combine(const T &a, const T &b)
InputOptions process_input_options(MPI_Comm com, std::shared_ptr< const Config > config)
Definition Component.cc:45
InitializationType type
initialization type
Definition Component.hh:61
std::string filename
name of the input file (if applicable)
Definition Component.hh:63