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, 2021, 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/ocean/Initialization.hh"
21 #include "pism/util/io/io_helpers.hh"
22 #include "pism/util/io/File.hh"
23 #include "pism/coupler/util/init_step.hh"
24 
25 namespace pism {
26 namespace ocean {
27 
28 InitializationHelper::InitializationHelper(std::shared_ptr<const Grid> g, std::shared_ptr<OceanModel> in)
29  : OceanModel(g, in) {
30 
32  m_water_column_pressure->set_name("effective_water_column_pressure");
33 
35  m_shelf_base_temperature->set_name("effective_shelf_base_temperature");
36 
38  m_shelf_base_mass_flux->set_name("effective_shelf_base_mass_flux");
39  // use internal units when saving
40  auto units = m_shelf_base_mass_flux->metadata()["units"];
41  m_shelf_base_mass_flux->metadata().output_units(units);
42 }
43 
44 void InitializationHelper::update_impl(const Geometry &geometry, double t, double dt) {
45  OceanModel::update_impl(geometry, t, dt);
46 
47  m_water_column_pressure->copy_from(m_input_model->average_water_column_pressure());
48  m_shelf_base_temperature->copy_from(m_input_model->shelf_base_temperature());
49  m_shelf_base_mass_flux->copy_from(m_input_model->shelf_base_mass_flux());
50 }
51 
53  m_input_model->init(geometry);
54 
56 
57  if (opts.type == INIT_RESTART) {
58  m_log->message(2, "* Reading effective ocean model outputs from '%s' for re-starting...\n",
59  opts.filename.c_str());
60 
62  const unsigned int time_length = file.nrecords();
63  const unsigned int last_record = time_length > 0 ? time_length - 1 : 0;
64 
65  m_water_column_pressure->read(file, last_record);
66  m_shelf_base_mass_flux->read(file, last_record);
67  m_shelf_base_temperature->read(file, last_record);
68 
69  file.close();
70  } else {
71  m_log->message(2, "* Performing a 'fake' ocean model time-step for bootstrapping...\n");
72 
73  init_step(this, geometry, time());
74  }
75 
76  // Support regridding. This is needed to ensure that initialization using "-i" is equivalent to
77  // "-i ... -bootstrap -regrid_file ..."
78  {
79  regrid("ocean model initialization helper", *m_water_column_pressure,
81  regrid("ocean model initialization helper", *m_shelf_base_mass_flux,
83  regrid("ocean model initialization helper", *m_shelf_base_temperature,
85  }
86 }
87 
90  m_shelf_base_mass_flux->define(output, io::PISM_DOUBLE);
92 
93  m_input_model->define_model_state(output);
94 }
95 
97  m_water_column_pressure->write(output);
98  m_shelf_base_mass_flux->write(output);
99  m_shelf_base_temperature->write(output);
100 
101  m_input_model->write_model_state(output);
102 }
103 
105  return *m_shelf_base_temperature;
106 }
107 
109  return *m_shelf_base_mass_flux;
110 }
111 
113  return *m_water_column_pressure;
114 }
115 
116 } // end of namespace ocean
117 } // 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
@ 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
void close()
Definition: File.cc:270
High-level PISM I/O class.
Definition: File.hh:56
const array::Scalar & shelf_base_mass_flux_impl() const
const array::Scalar & average_water_column_pressure_impl() const
void update_impl(const Geometry &geometry, double t, double dt)
std::shared_ptr< array::Scalar > m_shelf_base_mass_flux
void write_model_state_impl(const File &output) const
The default (empty implementation).
void init_impl(const Geometry &geometry)
void define_model_state_impl(const File &output) const
The default (empty implementation).
InitializationHelper(std::shared_ptr< const Grid > g, std::shared_ptr< OceanModel > in)
const array::Scalar & shelf_base_temperature_impl() const
std::shared_ptr< array::Scalar > m_shelf_base_temperature
std::shared_ptr< OceanModel > m_input_model
Definition: OceanModel.hh:72
std::shared_ptr< array::Scalar > m_water_column_pressure
Definition: OceanModel.hh:73
static std::shared_ptr< array::Scalar > allocate_shelf_base_temperature(std::shared_ptr< const Grid > g)
Definition: OceanModel.cc:31
static std::shared_ptr< array::Scalar > allocate_shelf_base_mass_flux(std::shared_ptr< const Grid > g)
Definition: OceanModel.cc:39
static std::shared_ptr< array::Scalar > allocate_water_column_pressure(std::shared_ptr< const Grid > g)
Definition: OceanModel.cc:49
virtual void update_impl(const Geometry &geometry, double t, double dt)
Definition: OceanModel.cc:107
A very rudimentary PISM ocean model.
Definition: OceanModel.hh:33
@ 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
bool ocean(int M)
An ocean cell (floating ice or ice-free).
Definition: Mask.hh:40
InputOptions process_input_options(MPI_Comm com, Config::ConstPtr config)
Definition: Component.cc:43
static const double g
Definition: exactTestP.cc:36
@ 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