PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
SeaLevel.cc
Go to the documentation of this file.
1/* Copyright (C) 2018, 2019, 2021, 2023, 2025, 2026 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#include "pism/util/Logger.hh"
26
27namespace pism {
28namespace ocean {
29namespace sea_level {
30
31// "Modifier" constructor.
32SeaLevel::SeaLevel(std::shared_ptr<const Grid> grid, std::shared_ptr<SeaLevel> input)
33 : Component(grid),
34 m_input_model(input),
35 m_sea_level(grid, "sea_level") {
36
38 .long_name("sea level elevation, relative to the geoid")
39 .units("meter");
40}
41
42// "Model" constructor (returns sea level is zero).
43SeaLevel::SeaLevel(std::shared_ptr<const Grid> g)
44 : SeaLevel(g, std::shared_ptr<SeaLevel>()) {
45 // empty
46}
47
48void SeaLevel::init(const Geometry &geometry) {
49 init_impl(geometry);
50}
51
52void SeaLevel::init_impl(const Geometry &geometry) {
53 if (m_input_model) {
54 m_input_model->init(geometry);
55 } else {
56 double z_s = m_config->get_number("sea_level.constant.value");
57 m_sea_level.set(z_s);
58 m_log->message(2, "* Using constant sea level at %f meters...\n", z_s);
59 }
60}
61
62void SeaLevel::update(const Geometry &geometry, double t, double dt) {
63 update_impl(geometry, t, dt);
64}
65
66void SeaLevel::update_impl(const Geometry &geometry, double t, double dt) {
67 if (m_input_model) {
68 m_input_model->update(geometry, t, dt);
69 } else {
70 double z_s = m_config->get_number("sea_level.constant.value");
71 m_sea_level.set(z_s);
72 }
73}
74
76 return m_sea_level;
77}
78
80 if (m_input_model) {
81 return m_input_model->max_timestep(t);
82 }
83 return MaxTimestep("sea level forcing");
84}
85
86std::set<VariableMetadata> SeaLevel::state_impl() const {
87 if (m_input_model) {
88 return m_input_model->state();
89 }
90 return {};
91}
92
93void SeaLevel::write_state_impl(const OutputFile &output) const {
94 if (m_input_model) {
95 m_input_model->write_state(output);
96 }
97}
98
99namespace diagnostics {
100
101/*! @brief Sea level elevation. */
102class SL : public Diag<SeaLevel> {
103public:
104 SL(const SeaLevel *m) : Diag<SeaLevel>(m) {
105 m_vars = { { m_sys, "sea_level", *m_grid } };
106 m_vars[0].long_name("sea level elevation, relative to the geoid").units("meters");
107 }
108
109protected:
110 std::shared_ptr<array::Array> compute_impl() const {
111 auto result = allocate<array::Scalar>("sea_level");
112
113 result->copy_from(model->elevation());
114
115 return result;
116 }
117};
118
119} // end of namespace diagnostics
120
122 DiagnosticList result = {
123 {"sea_level", Diagnostic::Ptr(new diagnostics::SL(this))},
124 };
125
126 if (m_input_model) {
127 return combine(result, m_input_model->spatial_diagnostics());
128 } else {
129 return result;
130 }
131}
132
134 if (m_input_model) {
135 return m_input_model->scalar_diagnostics();
136 } else {
137 return {};
138 }
139}
140
141} // end of namespace sea_level
142} // end of namespace ocean
143} // end of namespace pism
std::shared_ptr< const Config > m_config
configuration database used by this component
Definition Component.hh:160
std::shared_ptr< const Logger > m_log
logger (for easy access)
Definition Component.hh:164
A class defining a common interface for most PISM sub-models.
Definition Component.hh:118
const SeaLevel * model
A template derived from Diagnostic, adding a "Model".
std::vector< VariableMetadata > m_vars
metadata corresponding to NetCDF variables
const units::System::Ptr m_sys
the unit system
std::shared_ptr< Diagnostic > Ptr
Definition Diagnostic.hh:67
std::shared_ptr< const Grid > m_grid
the grid
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
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:659
VariableMetadata & metadata(unsigned int N=0)
Returns a reference to the VariableMetadata object containing metadata for the compoment N.
Definition Array.cc:467
void update(const Geometry &geometry, double t, double dt)
Definition SeaLevel.cc:62
virtual std::set< VariableMetadata > state_impl() const
Definition SeaLevel.cc:86
virtual TSDiagnosticList scalar_diagnostics_impl() const
Definition SeaLevel.cc:133
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
SeaLevel(std::shared_ptr< const Grid > g, std::shared_ptr< SeaLevel > input)
Definition SeaLevel.cc:32
virtual void init_impl(const Geometry &geometry)
Definition SeaLevel.cc:52
virtual DiagnosticList spatial_diagnostics_impl() const
Definition SeaLevel.cc:121
virtual MaxTimestep max_timestep_impl(double t) const
Definition SeaLevel.cc:79
virtual void write_state_impl(const OutputFile &output) const
The default (empty implementation).
Definition SeaLevel.cc:93
void init(const Geometry &geometry)
Definition SeaLevel.cc:48
const array::Scalar & elevation() const
Definition SeaLevel.cc:75
std::shared_ptr< array::Array > compute_impl() const
Definition SeaLevel.cc:110
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
std::map< std::string, Diagnostic::Ptr > DiagnosticList
T combine(const T &a, const T &b)