PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
SeaLevel.cc
Go to the documentation of this file.
1 /* Copyright (C) 2018, 2019, 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/SeaLevel.hh"
21 
22 #include "pism/util/MaxTimestep.hh"
23 
24 #include "pism/util/pism_utilities.hh" // combine
25 
26 namespace pism {
27 namespace ocean {
28 namespace sea_level {
29 
30 // "Modifier" constructor.
31 SeaLevel::SeaLevel(std::shared_ptr<const Grid> grid, std::shared_ptr<SeaLevel> input)
32  : Component(grid),
33  m_input_model(input),
34  m_sea_level(grid, "sea_level") {
35 
37  .long_name("sea level elevation, relative to the geoid")
38  .units("meter");
39 }
40 
41 // "Model" constructor (returns sea level is zero).
42 SeaLevel::SeaLevel(std::shared_ptr<const Grid> g)
43  : SeaLevel(g, std::shared_ptr<SeaLevel>()) {
44  // empty
45 }
46 
47 void SeaLevel::init(const Geometry &geometry) {
48  init_impl(geometry);
49 }
50 
51 void SeaLevel::init_impl(const Geometry &geometry) {
52  if (m_input_model) {
53  m_input_model->init(geometry);
54  } else {
55  double z_s = m_config->get_number("sea_level.constant.value");
56  m_sea_level.set(z_s);
57  m_log->message(2, "* Using constant sea level at %f meters...\n", z_s);
58  }
59 }
60 
61 void SeaLevel::update(const Geometry &geometry, double t, double dt) {
62  update_impl(geometry, t, dt);
63 }
64 
65 void SeaLevel::update_impl(const Geometry &geometry, double t, double dt) {
66  if (m_input_model) {
67  m_input_model->update(geometry, t, dt);
68  } else {
69  double z_s = m_config->get_number("sea_level.constant.value");
70  m_sea_level.set(z_s);
71  }
72 }
73 
75  return m_sea_level;
76 }
77 
79  if (m_input_model) {
80  return m_input_model->max_timestep(t);
81  }
82  return MaxTimestep("sea level forcing");
83 }
84 
85 void SeaLevel::define_model_state_impl(const File &output) const {
86  if (m_input_model) {
87  m_input_model->define_model_state(output);
88  }
89 }
90 
91 void SeaLevel::write_model_state_impl(const File &output) const {
92  if (m_input_model) {
93  m_input_model->write_model_state(output);
94  }
95 }
96 
97 namespace diagnostics {
98 
99 /*! @brief Sea level elevation. */
100 class SL : public Diag<SeaLevel> {
101 public:
102  SL(const SeaLevel *m) : Diag<SeaLevel>(m) {
103  m_vars = { { m_sys, "sea_level" } };
104  m_vars[0].long_name("sea level elevation, relative to the geoid").units("meters");
105  }
106 
107 protected:
108  std::shared_ptr<array::Array> compute_impl() const {
109  auto result = allocate<array::Scalar>("sea_level");
110 
111  result->copy_from(model->elevation());
112 
113  return result;
114  }
115 };
116 
117 } // end of namespace diagnostics
118 
120  DiagnosticList result = {
121  {"sea_level", Diagnostic::Ptr(new diagnostics::SL(this))},
122  };
123 
124  if (m_input_model) {
125  return combine(result, m_input_model->diagnostics());
126  } else {
127  return result;
128  }
129 }
130 
132  if (m_input_model) {
133  return m_input_model->ts_diagnostics();
134  } else {
135  return {};
136  }
137 }
138 
139 } // end of namespace sea_level
140 } // end of namespace ocean
141 } // end of namespace pism
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
A class defining a common interface for most PISM sub-models.
Definition: Component.hh:118
const SeaLevel * model
Definition: Diagnostic.hh:172
A template derived from Diagnostic, adding a "Model".
Definition: Diagnostic.hh:166
const units::System::Ptr m_sys
the unit system
Definition: Diagnostic.hh:116
std::vector< SpatialVariableMetadata > m_vars
metadata corresponding to NetCDF variables
Definition: Diagnostic.hh:120
std::shared_ptr< Diagnostic > Ptr
Definition: Diagnostic.hh:65
High-level PISM I/O class.
Definition: File.hh:56
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
Definition: MaxTimestep.hh:31
VariableMetadata & long_name(const std::string &input)
VariableMetadata & units(const std::string &input)
void set(double c)
Result: v[j] <- c for all j.
Definition: Array.cc:707
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Definition: Array.cc:553
void update(const Geometry &geometry, double t, double dt)
Definition: SeaLevel.cc:61
virtual void define_model_state_impl(const File &output) const
The default (empty implementation).
Definition: SeaLevel.cc:85
std::shared_ptr< SeaLevel > m_input_model
Definition: SeaLevel.hh:61
virtual void write_model_state_impl(const File &output) const
The default (empty implementation).
Definition: SeaLevel.cc:91
virtual void update_impl(const Geometry &geometry, double t, double dt)
Definition: SeaLevel.cc:65
virtual TSDiagnosticList ts_diagnostics_impl() const
Definition: SeaLevel.cc:131
SeaLevel(std::shared_ptr< const Grid > g, std::shared_ptr< SeaLevel > input)
Definition: SeaLevel.cc:31
virtual void init_impl(const Geometry &geometry)
Definition: SeaLevel.cc:51
virtual DiagnosticList diagnostics_impl() const
Definition: SeaLevel.cc:119
virtual MaxTimestep max_timestep_impl(double t) const
Definition: SeaLevel.cc:78
void init(const Geometry &geometry)
Definition: SeaLevel.cc:47
const array::Scalar & elevation() const
Definition: SeaLevel.cc:74
std::shared_ptr< array::Array > compute_impl() const
Definition: SeaLevel.cc:108
bool ocean(int M)
An ocean cell (floating ice or ice-free).
Definition: Mask.hh:40
static const double g
Definition: exactTestP.cc:36
std::map< std::string, TSDiagnostic::Ptr > TSDiagnosticList
Definition: Diagnostic.hh:343
std::map< std::string, Diagnostic::Ptr > DiagnosticList
Definition: Diagnostic.hh:125
T combine(const T &a, const T &b)