Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PyOceanModel.hh
Go to the documentation of this file.
1// Copyright (C) 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#ifndef PISM_PYOCEANMODEL_H
20#define PISM_PYOCEANMODEL_H
21
22#include "pism/coupler/ocean/CompleteOceanModel.hh"
23#include <memory>
24
25namespace pism {
26namespace ocean {
27
28/*!
29 * The base class for ocean models that are implemented in Python
30 */
32public:
33 virtual ~PyOceanModel() = default;
34
35 std::shared_ptr<pism::array::Scalar> shelf_base_temperature;
36 std::shared_ptr<array::Scalar> shelf_base_mass_flux;
37 std::shared_ptr<array::Scalar> water_column_pressure;
38
39 /*!
40 * Allocate data members. We need this to be able to test a Python implementation of an
41 * ocean model *without* the rest of PISM.
42 */
43 void allocate(std::shared_ptr<const Grid> grid);
44
45 /*!
46 * Maximum time step the model can take at time `t` (in seconds)
47 */
48 virtual MaxTimestep max_timestep(double t) const;
49
50 /*!
51 * Initialize the model state from formulas, by reading from an input file, etc.
52 */
53 virtual void init(const Geometry &geometry);
54
55 /*!
56 * Update the state of the model by taking a time step from `t` to `t + dt` (in seconds).
57 *
58 * Assumes that the time step length `dt` is allowed at the time `t`.
59 */
60 virtual void update(const Geometry &geometry, double t, double dt);
61
62 /*!
63 * Define model state variables and set their attributes
64 */
65 virtual void define_model_state(const File &output) const;
66
67 /*!
68 * Write model state variables and set their attributes
69 */
70 virtual void write_model_state(const File &output) const;
71};
72
73//! The adapter class for Python ocean models
74/*!
75 * We need this class because SWIG cannot create a wrapper for the OceanModel class that
76 * can be used as a base class for Python classes. (Specifically: it does not support
77 * methods that return a reference, e.g. `const array::Scalar& shelf_base_mass_flux_impl()`.)
78 */
80public:
81 PyOceanModelAdapter(std::shared_ptr<const Grid> grid, std::shared_ptr<PyOceanModel> implementation);
82 virtual ~PyOceanModelAdapter() = default;
83
84private:
85 MaxTimestep max_timestep_impl(double t) const;
86 void update_impl(const Geometry &geometry, double my_t, double my_dt);
87 void init_impl(const Geometry &geometry);
88
89 void define_model_state_impl(const File &output) const;
90 void write_model_state_impl(const File &output) const;
91
92 std::shared_ptr<PyOceanModel> m_impl;
93};
94
95} // end of namespace ocean
96} // end of namespace pism
97#endif /* PISM_PYOCEANMODEL_H */
std::shared_ptr< const Grid > grid() const
Definition Component.cc:105
High-level PISM I/O class.
Definition File.hh:55
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
virtual ~PyOceanModelAdapter()=default
void update_impl(const Geometry &geometry, double my_t, double my_dt)
void init_impl(const Geometry &geometry)
MaxTimestep max_timestep_impl(double t) const
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).
std::shared_ptr< PyOceanModel > m_impl
The adapter class for Python ocean models.
virtual ~PyOceanModel()=default
virtual void init(const Geometry &geometry)
virtual void write_model_state(const File &output) const
virtual void update(const Geometry &geometry, double t, double dt)
virtual MaxTimestep max_timestep(double t) const
std::shared_ptr< pism::array::Scalar > shelf_base_temperature
virtual void define_model_state(const File &output) const
std::shared_ptr< array::Scalar > water_column_pressure
std::shared_ptr< array::Scalar > shelf_base_mass_flux
void allocate(std::shared_ptr< const Grid > grid)
bool ocean(int M)
An ocean cell (floating ice or ice-free).
Definition Mask.hh:40