PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
Initialization.cc
Go to the documentation of this file.
1 /* Copyright (C) 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/sea_level/Initialization.hh"
21 
22 #include "pism/coupler/util/init_step.hh"
23 
24 namespace pism {
25 namespace ocean {
26 namespace sea_level {
27 
28 InitializationHelper::InitializationHelper(std::shared_ptr<const Grid> grid,
29  std::shared_ptr<SeaLevel> in)
30  : SeaLevel(grid, in) {
31 
32  m_sea_level.metadata().set_name("effective_sea_level_elevation");
33 }
34 
35 void InitializationHelper::update_impl(const Geometry &geometry, double t, double dt) {
36  SeaLevel::update_impl(geometry, t, dt);
37 
38  m_sea_level.copy_from(m_input_model->elevation());
39 }
40 
42  m_input_model->init(geometry);
43 
45 
46  if (opts.type == INIT_RESTART) {
47  m_log->message(2, "* Reading effective sea level forcing from '%s' for re-starting...\n",
48  opts.filename.c_str());
49 
51  const unsigned int time_length = file.nrecords();
52  const unsigned int last_record = time_length > 0 ? time_length - 1 : 0;
53 
54  m_sea_level.read(file, last_record);
55 
56  file.close();
57  } else {
58  m_log->message(2, "* Performing a 'fake' sea level forcing time-step for bootstrapping...\n");
59 
60  init_step(this, geometry, time());
61  }
62 
63  // Support regridding. This is needed to ensure that initialization using "-i" is
64  // equivalent to "-i ... -bootstrap -regrid_file ..."
65  {
66  regrid("ocean model initialization helper", m_sea_level,
68  }
69 }
70 
73 
74  m_input_model->define_model_state(output);
75 }
76 
78  m_sea_level.write(output);
79 
80  m_input_model->write_model_state(output);
81 }
82 
84  return m_sea_level;
85 }
86 
87 } // end of namespace sea_level
88 } // end of namespace ocean
89 } // 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
VariableMetadata & set_name(const std::string &name)
void copy_from(const Array2D< T > &source)
Definition: Array2D.hh:73
void read(const std::string &filename, unsigned int time)
Definition: Array.cc:809
void define(const File &file, io::Type default_type) const
Define variables corresponding to an Array in a file opened using file.
Definition: Array.cc:540
void write(const std::string &filename) const
Definition: Array.cc:800
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Definition: Array.cc:553
const array::Scalar & sea_level_elevation_impl() const
InitializationHelper(std::shared_ptr< const Grid > g, std::shared_ptr< SeaLevel > in)
void write_model_state_impl(const File &output) const
The default (empty implementation).
void define_model_state_impl(const File &output) const
The default (empty implementation).
void init_impl(const Geometry &geometry)
void update_impl(const Geometry &geometry, double t, double dt)
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:65
@ 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
@ 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