PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
Initialization.cc
Go to the documentation of this file.
1 /* Copyright (C) 2016, 2017, 2018, 2019, 2020, 2023 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/Context.hh"
25 
26 namespace pism {
27 namespace surface {
28 
29 InitializationHelper::InitializationHelper(std::shared_ptr<const Grid> grid, std::shared_ptr<SurfaceModel> input)
30  : SurfaceModel(grid, input),
31  m_mass_flux(m_grid, "effective_climatic_mass_balance"),
32  m_temperature(m_grid, "effective_ice_surface_temp")
33 {
34 
35  if (not input) {
36  throw RuntimeError(PISM_ERROR_LOCATION, "pism::surface::InitializationHelper got a NULL input model");
37  }
38 
39  // allocate storage
40  {
42  .long_name(
43  "surface mass balance (accumulation/ablation) rate, as seen by the ice dynamics code (used for restarting)")
44  .units("kg m-2 s-1")
45  .set_time_independent(false);
46 
48  .long_name(
49  "temperature of the ice at the ice surface but below firn processes, as seen by the ice dynamics code (used for restarting)")
50  .units("Kelvin")
51  .set_time_independent(false);
52 
54  m_liquid_water_fraction->metadata().set_name("effective_ice_surface_liquid_water_fraction");
55  m_liquid_water_fraction->metadata(0)
56  .long_name(
57  "liquid water fraction of the ice at the top surface, as seen by the ice dynamics code (used for restarting)")
58  .units("1")
59  .set_time_independent(false);
60 
62  m_layer_mass->metadata().set_name("effective_surface_layer_mass");
63  m_layer_mass->metadata(0)
64  .long_name(
65  "mass held in the surface layer, as seen by the ice dynamics code (used for restarting)")
66  .units("kg")
67  .set_time_independent(false);
68 
70  m_layer_thickness->metadata().set_name("effective_surface_layer_thickness");
71  m_layer_thickness->metadata(0)
72  .long_name(
73  "thickness of the surface layer, as seen by the ice dynamics code (used for restarting)")
74  .units("meters")
75  .set_time_independent(false);
76  }
77 
79  m_accumulation->set_name("effective_" + m_accumulation->get_name());
80 
82  m_melt->set_name("effective_" + m_melt->get_name());
83 
85  m_runoff->set_name("effective_" + m_runoff->get_name());
86 
87  // collect pointers
91  m_layer_mass.get(),
92  m_layer_thickness.get(),
93  m_accumulation.get(),
94  m_melt.get(),
95  m_runoff.get()};
96 }
97 
99  m_input_model->init(geometry);
100 
102 
103  if (opts.type == INIT_RESTART) {
104  m_log->message(2, "* Reading effective surface model outputs from '%s' for re-starting...\n",
105  opts.filename.c_str());
106 
108  const unsigned int last_record = file.nrecords() - 1;
109  for (auto *v : m_variables) {
110  v->read(file, last_record);
111  }
112  } else {
113  m_log->message(2, "* Performing a 'fake' surface model time-step for bootstrapping...\n");
114 
115  init_step(this, geometry, time());
116  }
117 
118  // Support regridding. This is needed to ensure that initialization using "-i" is equivalent to
119  // "-i ... -bootstrap -regrid_file ..."
120  for (auto *v : m_variables) {
121  regrid("surface model initialization helper", *v, REGRID_WITHOUT_REGRID_VARS);
122  }
123 }
124 
125 void InitializationHelper::update_impl(const Geometry &geometry, double t, double dt) {
126  m_input_model->update(geometry, t, dt);
127 
128  // store outputs of the input model
129  m_mass_flux.copy_from(m_input_model->mass_flux());
130  m_temperature.copy_from(m_input_model->temperature());
131  m_liquid_water_fraction->copy_from(m_input_model->liquid_water_fraction());
132  m_layer_mass->copy_from(m_input_model->layer_mass());
133  m_layer_thickness->copy_from(m_input_model->layer_thickness());
134  m_accumulation->copy_from(m_input_model->accumulation());
135  m_melt->copy_from(m_input_model->melt());
136  m_runoff->copy_from(m_input_model->runoff());
137 }
138 
140  return *m_layer_thickness;
141 }
142 
144  return m_mass_flux;
145 }
146 
148  return m_temperature;
149 }
150 
152  return *m_liquid_water_fraction;
153 }
154 
156  return *m_layer_mass;
157 }
158 
160  return *m_accumulation;
161 }
162 
164  return *m_melt;
165 }
166 
168  return *m_runoff;
169 }
170 
172  for (auto *v : m_variables) {
173  v->define(output, io::PISM_DOUBLE);
174  }
175  m_input_model->define_model_state(output);
176 }
177 
179  for (auto *v : m_variables) {
180  v->write(output);
181  }
182  m_input_model->write_model_state(output);
183 }
184 
185 
186 
187 } // end of namespace surface
188 } // end of namespace pism
const Time & time() const
Definition: Component.cc:109
std::shared_ptr< const Grid > grid() const
Definition: Component.cc:105
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
@ REGRID_WITHOUT_REGRID_VARS
Definition: Component.hh:151
const std::shared_ptr< const Grid > m_grid
grid used by this component
Definition: Component.hh:156
void regrid(const std::string &module_name, array::Array &variable, RegriddingFlag flag=NO_REGRID_WITHOUT_REGRID_VARS)
Definition: Component.cc:159
unsigned int nrecords() const
Get the number of records. Uses the length of an unlimited dimension.
Definition: File.cc:313
High-level PISM I/O class.
Definition: File.hh:56
VariableMetadata & long_name(const std::string &input)
VariableMetadata & units(const std::string &input)
VariableMetadata & set_time_independent(bool flag)
void copy_from(const Array2D< T > &source)
Definition: Array2D.hh:73
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Definition: Array.cc:553
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
void write_model_state_impl(const File &output) const
The default (empty implementation).
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
void define_model_state_impl(const File &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)
Definition: SurfaceModel.cc:47
std::shared_ptr< SurfaceModel > m_input_model
static std::shared_ptr< array::Scalar > allocate_layer_mass(std::shared_ptr< const Grid > grid)
Definition: SurfaceModel.cc:35
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)
Definition: SurfaceModel.cc:60
The interface of PISM's surface models.
Definition: SurfaceModel.hh:42
#define PISM_ERROR_LOCATION
@ PISM_GUESS
Definition: IO_Flags.hh:56
@ PISM_READONLY
open an existing file for reading only
Definition: IO_Flags.hh:72
@ PISM_DOUBLE
Definition: IO_Flags.hh:52
InputOptions process_input_options(MPI_Comm com, Config::ConstPtr config)
Definition: Component.cc:43
@ INIT_RESTART
Definition: Component.hh:56
void init_step(M *model, const Geometry &geometry, const Time &time)
Definition: init_step.hh:32
InitializationType type
initialization type
Definition: Component.hh:61
std::string filename
name of the input file (if applicable)
Definition: Component.hh:63