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
IBIceModel.hh
Go to the documentation of this file.
1#pragma once
2
3#include "pism/icebin/IBSurfaceModel.hh"
4#include "pism/icebin/MassEnergyBudget.hh"
5#include "pism/icebin/NullTransportHydrology.hh"
6#include "pism/icemodel/IceModel.hh"
7#include <memory>
8
9// Stuff defined in the icebin library
10// (NOT a dependency of ours)
11namespace icebin {
12namespace gpism {
13class IceCoupler_PISM;
14}
15} // namespace icebin
16
17namespace pism {
18namespace icebin {
19
20/** This is the IceBin customized version of PISM's pism::IceModel class.
21
22See https://github.com/pism/pism/issues/219
23
24Here's a short term solution, though: create a new class
25IBIceModel derived from IceModel and re-implement
26IceModel::allocate_couplers(). In it, set
27IceModel::external_surface_model and IceModel::external_ocean_model as
28you see fit (IceModel will not de-allocate a surface (ocean) model if
29it is set to true) and allocate PSConstantICEBIN. You might also want
30to add IBIceModel::get_surface_model() which returns
31IceModel::surface to get access to PSConstantICEBIN from outside of
32IBIceModel.
33*/
34
35class IBIceModel : public pism::IceModel {
36 // FIXME: this is a bad idea. It means that IBIceModel needs a better public API.
37 friend class ::icebin::gpism::IceCoupler_PISM;
38
39public:
41 struct Params {
43 std::string output_dir;
44 };
46
47protected:
48 MassEnergyBudget base; // Cumulative totals at start of this time step
49 MassEnergyBudget cur; // Cumulative totals now
50 MassEnergyBudget rate; // At end of coupling timestep, set to (cur - base) / dt
51
52 // Output variables prepared for return to GCM
53 // (relevant ice model state to be exported)
54
55 // Specific enthalpy at surface of the ice sheet [J kg-1]
57
58public:
59 // Elevation of ice grid cells, with NaN off the ice sheet [m]
61 // Elevation of ice+bare land grid cells, with NaN in the ocean [m]
63
64protected:
65
66public:
68 int i, int j,
69 double surface_mass_balance, // [m s-1] ice equivalent (from PISM)
70 double basal_melt_rate, // [m s-1] ice equivalent
71 double divQ_SIA, // [m s-1] ice equivalent
72 double divQ_SSA, // [m s-1] ice equivalent
73 double Href_to_H_flux, // [m s-1] ice equivalent
74 double nonneg_rule_flux); // [m s-1] ice equivalent
75 virtual void massContExplicitStep();
76
77private:
78 // Temporary variables inside massContExplicitStep()
79 double m_ice_density; // From config
80 double m_meter_per_s_to_kg_per_m2; // Conversion factor computed from m_ice_density
81
82public:
83 /** @param t0 Time of last time we coupled. */
84 void set_rate(double dt);
85
86 void reset_rate();
87
88 std::unique_ptr<pism::File> pre_mass_nc; //!< Write variables every time massContPostHook() is called.
89 std::unique_ptr<pism::File> post_mass_nc;
90 std::unique_ptr<pism::File> pre_energy_nc;
91 std::unique_ptr<pism::File> post_energy_nc;
92
93 // see iceModel.cc for implementation of constructor and destructor:
94 /** @param gcm_params Pointer to IceModel::gcm_params. Lives at least as long as this object. */
95 IBIceModel(std::shared_ptr<pism::Grid> grid, const std::shared_ptr<Context> &context,
96 IBIceModel::Params const &_params);
97 virtual ~IBIceModel(); // must be virtual merely because some members are virtual
98
99 virtual void allocate_subglacial_hydrology();
100 virtual void allocate_couplers();
101 virtual void time_setup();
102 virtual void misc_setup();
103
105
106 /** @return Our instance of IBSurfaceModel */
108 return std::dynamic_pointer_cast<IBSurfaceModel>(m_surface).get();
109 }
110
114
115
116 /** @return Current time for mass timestepping */
117 double mass_t() const {
118 return m_time->current();
119 }
120 /** @return Current time for enthalpy timestepping */
121 double enthalpy_t() const {
122 return t_TempAge;
123 }
124
125 // I added these...
126 void massContPreHook();
127 void massContPostHook();
128 // Pre and post for energy
129 void energy_step();
130
131 void prepare_outputs(double time_s);
132
133 void dumpToFile(const std::string &filename) const ;
134
135 /** Read things out of the ice model that will be sent back BEFORE
136 the first coupling timestep (eg, ice surface enthalpy) */
138
139 /** Merges surface temperature derived from m_ice_enthalpy into any NaN values
140 in the vector provided.
141 @param deltah IN: Input from Icebin (change in enthalpy of each grid
142 cell over the timestep) [W m-2].
143 @param default_val: The value that deltah(i,j) will have if no value
144 is listed for that grid cell
145 @param timestep_s: Length of the current coupling timestep [s]
146 @param surface_temp OUT: Resulting surface temperature to use as the Dirichlet B.C.
147 */
148 void construct_surface_temp(pism::array::Scalar &deltah, // IN: Input from Icebin
149 double default_val,
150 double timestep_s, // Length of this coupling interval [s]
151 pism::array::Scalar &surface_temp);
152};
153} // namespace icebin
154} // namespace pism
std::shared_ptr< surface::SurfaceModel > m_surface
Definition IceModel.hh:279
const Time::Ptr m_time
Time manager.
Definition IceModel.hh:246
std::shared_ptr< Grid > grid() const
Return the grid used by this model.
Definition utilities.cc:121
double dt() const
Definition IceModel.cc:126
double t_TempAge
time of last update for enthalpy/temperature
Definition IceModel.hh:313
std::unique_ptr< hydrology::Hydrology > m_subglacial_hydrology
Definition IceModel.hh:254
pism::array::Scalar elevmask_ice
Definition IBIceModel.hh:60
pism::array::Scalar ice_top_senth
Definition IBIceModel.hh:56
void construct_surface_temp(pism::array::Scalar &deltah, double default_val, double timestep_s, pism::array::Scalar &surface_temp)
std::unique_ptr< pism::File > post_mass_nc
Definition IBIceModel.hh:89
virtual void misc_setup()
Miscellaneous initialization tasks plus tasks that need the fields that can come from regridding.
MassEnergyBudget base
Definition IBIceModel.hh:48
void dumpToFile(const std::string &filename) const
pism::icebin::NullTransportHydrology * null_hydrology()
virtual void time_setup()
Initialize time from an input file or command-line options.
virtual void accumulateFluxes_massContExplicitStep(int i, int j, double surface_mass_balance, double basal_melt_rate, double divQ_SIA, double divQ_SSA, double Href_to_H_flux, double nonneg_rule_flux)
double enthalpy_t() const
pism::icebin::IBSurfaceModel * ib_surface_model()
virtual void allocate_couplers()
Definition IBIceModel.cc:54
std::unique_ptr< pism::File > post_energy_nc
Definition IBIceModel.hh:91
virtual void massContExplicitStep()
std::unique_ptr< pism::File > pre_mass_nc
Write variables every time massContPostHook() is called.
Definition IBIceModel.hh:88
void compute_enth2(pism::array::Scalar &enth2, pism::array::Scalar &mass2)
void prepare_outputs(double time_s)
MassEnergyBudget rate
Definition IBIceModel.hh:50
void energy_step()
Manage the solution of the energy equation, and related parallel communication.
Definition IBIceModel.cc:84
virtual void allocate_subglacial_hydrology()
Decide which subglacial hydrology model to use.
Definition IBIceModel.cc:44
MassEnergyBudget cur
Definition IBIceModel.hh:49
void set_rate(double dt)
pism::array::Scalar elevmask_land
Definition IBIceModel.hh:62
std::unique_ptr< pism::File > pre_energy_nc
Definition IBIceModel.hh:90