PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
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)
11 namespace icebin {
12 namespace gpism {
13 class IceCoupler_PISM;
14 }
15 } // namespace icebin
16 
17 namespace pism {
18 namespace icebin {
19 
20 /** This is the IceBin customized version of PISM's pism::IceModel class.
21 
22 See https://github.com/pism/pism/issues/219
23 
24 Here's a short term solution, though: create a new class
25 IBIceModel derived from IceModel and re-implement
26 IceModel::allocate_couplers(). In it, set
27 IceModel::external_surface_model and IceModel::external_ocean_model as
28 you see fit (IceModel will not de-allocate a surface (ocean) model if
29 it is set to true) and allocate PSConstantICEBIN. You might also want
30 to add IBIceModel::get_surface_model() which returns
31 IceModel::surface to get access to PSConstantICEBIN from outside of
32 IBIceModel.
33 */
34 
35 class 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 
39 public:
41  struct Params {
42  double time_start_s;
43  std::string output_dir;
44  };
45  Params const params;
46 
47 protected:
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 
58 public:
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 
64 protected:
65 
66 public:
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 
77 private:
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 
82 public:
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 
112  return dynamic_cast<pism::icebin::NullTransportHydrology *>(m_subglacial_hydrology.get());
113  }
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:286
const Time::Ptr m_time
Time manager.
Definition: IceModel.hh:251
std::shared_ptr< Grid > grid() const
Return the grid used by this model.
Definition: utilities.cc:122
double dt() const
Definition: IceModel.cc:140
double t_TempAge
time of last update for enthalpy/temperature
Definition: IceModel.hh:320
std::unique_ptr< hydrology::Hydrology > m_subglacial_hydrology
Definition: IceModel.hh:261
pism::array::Scalar elevmask_ice
Definition: IBIceModel.hh:60
pism::IceModel super
Definition: IBIceModel.hh:40
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)
Definition: IBIceModel.cc:420
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.
Definition: IBIceModel.cc:343
MassEnergyBudget base
Definition: IBIceModel.hh:48
void dumpToFile(const std::string &filename) const
Definition: IBIceModel.cc:321
virtual void time_setup()
Initialize time from an input file or command-line options.
Definition: IBIceModel.cc:333
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)
Definition: IBIceModel.cc:170
double enthalpy_t() const
Definition: IBIceModel.hh:121
virtual void allocate_couplers()
Definition: IBIceModel.cc:54
double mass_t() const
Definition: IBIceModel.hh:117
std::unique_ptr< pism::File > post_energy_nc
Definition: IBIceModel.hh:91
virtual void massContExplicitStep()
Definition: IBIceModel.cc:125
std::unique_ptr< pism::File > pre_mass_nc
Write variables every time massContPostHook() is called.
Definition: IBIceModel.hh:88
IBIceModel(std::shared_ptr< pism::Grid > grid, const std::shared_ptr< Context > &context, IBIceModel::Params const &_params)
Definition: IBIceModel.cc:23
void compute_enth2(pism::array::Scalar &enth2, pism::array::Scalar &mass2)
Definition: IBIceModel.cc:372
pism::icebin::NullTransportHydrology * null_hydrology()
Definition: IBIceModel.hh:111
void prepare_outputs(double time_s)
Definition: IBIceModel.cc:275
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)
Definition: IBIceModel.cc:219
pism::icebin::IBSurfaceModel * ib_surface_model()
Definition: IBIceModel.hh:107
pism::array::Scalar elevmask_land
Definition: IBIceModel.hh:62
std::unique_ptr< pism::File > pre_energy_nc
Definition: IBIceModel.hh:90