PISM, A Parallel Ice Sheet Model  stable v2.0.4 committed by Constantine Khrulev on 2022-05-25 12:02:27 -0800
Initialization.cc
Go to the documentation of this file.
1 /* Copyright (C) 2016, 2017, 2018, 2019, 2020 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 "Initialization.hh"
21 #include "pism/util/error_handling.hh"
22 #include "pism/util/pism_utilities.hh"
23 #include "pism/util/io/File.hh"
24 #include "pism/coupler/util/init_step.hh"
25 #include "pism/util/Context.hh"
26 
27 namespace pism {
28 namespace surface {
29 
30 InitializationHelper::InitializationHelper(IceGrid::ConstPtr grid, std::shared_ptr<SurfaceModel> input)
31  : SurfaceModel(grid, input),
32  m_mass_flux(m_grid, "effective_climatic_mass_balance", WITHOUT_GHOSTS),
33  m_temperature(m_grid, "effective_ice_surface_temp", WITHOUT_GHOSTS)
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  {
42  m_mass_flux.set_attrs("model_state",
43  "surface mass balance (accumulation/ablation) rate, as seen by the ice dynamics code (used for restarting)",
44  "kg m-2 s-1", "kg m-2 year-1", "", 0);
46 
47  m_temperature.set_attrs("model_state",
48  "temperature of the ice at the ice surface but below firn processes, as seen by the ice dynamics code (used for restarting)",
49  "Kelvin", "Kelvin", "", 0);
51 
53  m_liquid_water_fraction->metadata().set_name("effective_ice_surface_liquid_water_fraction");
54  m_liquid_water_fraction->set_attrs("model_state",
55  "liquid water fraction of the ice at the top surface, as seen by the ice dynamics code (used for restarting)",
56  "1", "1", "", 0);
57  m_liquid_water_fraction->set_time_independent(false);
58 
60  m_layer_mass->metadata().set_name("effective_surface_layer_mass");
61  m_layer_mass->set_attrs("model_state",
62  "mass held in the surface layer, as seen by the ice dynamics code (used for restarting)",
63  "kg", "kg",
64  "", 0);
65  m_layer_mass->set_time_independent(false);
66 
68  m_layer_thickness->metadata().set_name("effective_surface_layer_thickness");
69  m_layer_thickness->set_attrs("model_state",
70  "thickness of the surface layer, as seen by the ice dynamics code (used for restarting)",
71  "meters", "meters", "", 0);
72  m_layer_thickness->set_time_independent(false);
73  }
74 
76  m_accumulation->set_name("effective_" + m_accumulation->get_name());
77 
79  m_melt->set_name("effective_" + m_melt->get_name());
80 
82  m_runoff->set_name("effective_" + m_runoff->get_name());
83 
84  // collect pointers
88  m_layer_mass.get(),
89  m_layer_thickness.get(),
90  m_accumulation.get(),
91  m_melt.get(),
92  m_runoff.get()};
93 }
94 
96  m_input_model->init(geometry);
97 
99 
100  if (opts.type == INIT_RESTART) {
101  m_log->message(2, "* Reading effective surface model outputs from '%s' for re-starting...\n",
102  opts.filename.c_str());
103 
104  File file(m_grid->com, opts.filename, PISM_GUESS, PISM_READONLY);
105  const unsigned int last_record = file.nrecords() - 1;
106  for (auto v : m_variables) {
107  v->read(file, last_record);
108  }
109  } else {
110  m_log->message(2, "* Performing a 'fake' surface model time-step for bootstrapping...\n");
111 
112  init_step(this, geometry, *m_grid->ctx()->time());
113  }
114 
115  // Support regridding. This is needed to ensure that initialization using "-i" is equivalent to
116  // "-i ... -bootstrap -regrid_file ..."
117  for (auto v : m_variables) {
118  regrid("surface model initialization helper", *v, REGRID_WITHOUT_REGRID_VARS);
119  }
120 }
121 
122 void InitializationHelper::update_impl(const Geometry &geometry, double t, double dt) {
123  m_input_model->update(geometry, t, dt);
124 
125  // store outputs of the input model
126  m_mass_flux.copy_from(m_input_model->mass_flux());
127  m_temperature.copy_from(m_input_model->temperature());
128  m_liquid_water_fraction->copy_from(m_input_model->liquid_water_fraction());
129  m_layer_mass->copy_from(m_input_model->layer_mass());
130  m_layer_thickness->copy_from(m_input_model->layer_thickness());
131  m_accumulation->copy_from(m_input_model->accumulation());
132  m_melt->copy_from(m_input_model->melt());
133  m_runoff->copy_from(m_input_model->runoff());
134 }
135 
137  return *m_layer_thickness;
138 }
139 
141  return m_mass_flux;
142 }
143 
145  return m_temperature;
146 }
147 
149  return *m_liquid_water_fraction;
150 }
151 
153  return *m_layer_mass;
154 }
155 
157  return *m_accumulation;
158 }
159 
161  return *m_melt;
162 }
163 
165  return *m_runoff;
166 }
167 
169  for (auto v : m_variables) {
170  v->define(output);
171  }
172  m_input_model->define_model_state(output);
173 }
174 
176  for (auto v : m_variables) {
177  v->write(output);
178  }
179  m_input_model->write_model_state(output);
180 }
181 
182 
183 
184 } // end of namespace surface
185 } // end of namespace pism
IceGrid::ConstPtr grid() const
Definition: Component.cc:105
const Config::ConstPtr m_config
configuration database used by this component
Definition: Component.hh:138
const Logger::ConstPtr m_log
logger (for easy access)
Definition: Component.hh:142
@ REGRID_WITHOUT_REGRID_VARS
Definition: Component.hh:131
virtual void regrid(const std::string &module_name, IceModelVec &variable, RegriddingFlag flag=NO_REGRID_WITHOUT_REGRID_VARS)
Definition: Component.cc:151
const IceGrid::ConstPtr m_grid
grid used by this component
Definition: Component.hh:136
unsigned int nrecords() const
Get the number of records. Uses the length of an unlimited dimension.
Definition: File.cc:316
High-level PISM I/O class.
Definition: File.hh:51
std::shared_ptr< const IceGrid > ConstPtr
Definition: IceGrid.hh:233
void copy_from(const IceModelVec2S &source)
void set_attrs(const std::string &pism_intent, const std::string &long_name, const std::string &units, const std::string &glaciological_units, const std::string &standard_name, unsigned int component)
Sets NetCDF attributes of an IceModelVec object.
Definition: iceModelVec.cc:399
void set_time_independent(bool flag)
Set the time independent flag for all variables corresponding to this IceModelVec instance.
Definition: iceModelVec.cc:175
const IceModelVec2S & runoff_impl() const
void init_impl(const Geometry &geometry)
InitializationHelper(IceGrid::ConstPtr g, std::shared_ptr< SurfaceModel > in)
void update_impl(const Geometry &geometry, double t, double dt)
const IceModelVec2S & accumulation_impl() const
const IceModelVec2S & melt_impl() const
const IceModelVec2S & temperature_impl() const
const IceModelVec2S & liquid_water_fraction_impl() const
const IceModelVec2S & layer_mass_impl() const
std::vector< IceModelVec * > m_variables
void write_model_state_impl(const File &output) const
The default (empty implementation).
const IceModelVec2S & mass_flux_impl() const
const IceModelVec2S & layer_thickness_impl() const
void define_model_state_impl(const File &output) const
The default (empty implementation).
IceModelVec2S::Ptr m_liquid_water_fraction
static IceModelVec2S::Ptr allocate_liquid_water_fraction(IceGrid::ConstPtr grid)
Definition: SurfaceModel.cc:62
IceModelVec2S::Ptr m_melt
static IceModelVec2S::Ptr allocate_melt(IceGrid::ConstPtr grid)
IceModelVec2S::Ptr m_layer_mass
IceModelVec2S::Ptr m_accumulation
std::shared_ptr< SurfaceModel > m_input_model
static IceModelVec2S::Ptr allocate_accumulation(IceGrid::ConstPtr grid)
static IceModelVec2S::Ptr allocate_layer_mass(IceGrid::ConstPtr grid)
Definition: SurfaceModel.cc:38
static IceModelVec2S::Ptr allocate_runoff(IceGrid::ConstPtr grid)
IceModelVec2S::Ptr m_runoff
IceModelVec2S::Ptr m_layer_thickness
static IceModelVec2S::Ptr allocate_layer_thickness(IceGrid::ConstPtr grid)
Definition: SurfaceModel.cc:49
The interface of PISM's surface models.
Definition: SurfaceModel.hh:45
#define PISM_ERROR_LOCATION
InputOptions process_input_options(MPI_Comm com, Config::ConstPtr config)
Definition: Component.cc:45
@ INIT_RESTART
Definition: Component.hh:39
@ PISM_GUESS
Definition: IO_Flags.hh:41
@ PISM_READONLY
open an existing file for reading only
Definition: IO_Flags.hh:49
void init_step(M *model, const Geometry &geometry, const Time &time)
Definition: init_step.hh:32
@ WITHOUT_GHOSTS
Definition: iceModelVec.hh:49
InitializationType type
initialization type
Definition: Component.hh:44
std::string filename
name of the input file (if applicable)
Definition: Component.hh:46