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) 2018, 2019, 2020, 2021, 2023, 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/ocean/sea_level/Initialization.hh"
21
22#include "pism/coupler/util/init_step.hh"
23#include "pism/util/Logger.hh"
24#include "pism/util/io/IO_Flags.hh"
25
26namespace pism {
27namespace ocean {
28namespace sea_level {
29
30InitializationHelper::InitializationHelper(std::shared_ptr<const Grid> grid,
31 std::shared_ptr<SeaLevel> in)
32 : SeaLevel(grid, in) {
33
34 m_sea_level.metadata().set_name("effective_sea_level_elevation");
35}
36
37void InitializationHelper::update_impl(const Geometry &geometry, double t, double dt) {
38 SeaLevel::update_impl(geometry, t, dt);
39
41}
42
44 m_input_model->init(geometry);
45
47
48 if (opts.type == INIT_RESTART) {
49 m_log->message(2, "* Reading effective sea level forcing from '%s' for re-starting...\n",
50 opts.filename.c_str());
51
53 const unsigned int time_length = file.nrecords();
54 const unsigned int last_record = time_length > 0 ? time_length - 1 : 0;
55
56 m_sea_level.read(file, last_record);
57
58 file.close();
59 } else {
60 m_log->message(2, "* Performing a 'fake' sea level forcing time-step for bootstrapping...\n");
61
62 init_step(this, geometry, time());
63 }
64
65 // Support regridding. This is needed to ensure that initialization using "-i" is
66 // equivalent to "-i ... -bootstrap -regrid_file ..."
67 {
68 regrid("ocean model initialization helper", m_sea_level,
70 }
71}
72
73std::set<VariableMetadata> InitializationHelper::state_impl() const {
74 return pism::combine(m_input_model->state(), array::metadata({ &m_sea_level }));
75}
76
78 m_sea_level.write(output);
79
80 m_input_model->write_state(output);
81}
82
86
87} // end of namespace sea_level
88} // end of namespace ocean
89} // 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
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
void close()
Definition File.cc:237
High-level PISM I/O class.
Definition File.hh:57
VariableMetadata & set_name(const std::string &name)
void copy_from(const Array2D< T > &source)
Definition Array2D.hh:101
void read(const std::string &filename, unsigned int time)
Definition Array.cc:753
void write(const OutputFile &file) const
Definition Array.cc:859
VariableMetadata & metadata(unsigned int N=0)
Returns a reference to the VariableMetadata object containing metadata for the compoment N.
Definition Array.cc:467
const array::Scalar & sea_level_elevation_impl() const
InitializationHelper(std::shared_ptr< const Grid > g, std::shared_ptr< SeaLevel > in)
std::set< VariableMetadata > state_impl() const
void init_impl(const Geometry &geometry)
void update_impl(const Geometry &geometry, double t, double dt)
void write_state_impl(const OutputFile &output) const
The default (empty implementation).
std::shared_ptr< SeaLevel > m_input_model
Definition SeaLevel.hh:61
virtual void update_impl(const Geometry &geometry, double t, double dt)
Definition SeaLevel.cc:66
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
bool ocean(int M)
An ocean cell (floating ice or ice-free).
Definition Mask.hh:40
@ 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