6#include "pism/energy/BedThermalUnit.hh"
7#include "pism/util/EnthalpyConverter.hh"
8#include "pism/util/io/io_helpers.hh"
10#include "pism/icebin/IBIceModel.hh"
11#include "pism/icebin/IBSurfaceModel.hh"
12#include "pism/energy/EnergyModel.hh"
17static double const NaN = std::numeric_limits<double>::quiet_NaN();
29 ice_top_senth(grid,
"ice_top_senth"),
30 elevmask_ice(grid,
"elevmask_ice"),
31 elevmask_land(grid,
"elevmask_land") {
33 std::cout <<
"IBIceModel Conservation Formulas:" << std::endl;
58 m_log->message(2,
"# Allocating the icebin surface model...\n");
68 const double my_t0 =
m_grid.time->current();
69 const double my_dt = this->
dt;
79 const double my_t0 =
m_grid.time->current();
80 const double my_dt = this->
dt;
87 printf(
"BEGIN IBIceModel::energyStep(t=%f, dt=%f)\n", t,
dt);
92 const double my_dt =
dt;
121 const auto &strain_heating3 =
m_stress_balance->volumetric_strain_heating();
128 printf(
"BEGIN IBIceModel::MassContExplicitStep()\n");
157 for (
auto p :
m_grid->points()) {
158 const int i = p.i(), j = p.j();
173 double surface_mass_balance,
174 double basal_melt_rate,
177 double Href_to_H_flux,
178 double nonneg_rule_flux)
180 auto EC =
ctx()->enthalpy_converter();
187 double p_basal = EC->pressure(ice_thickness(i, j));
188 double T = EC->melting_temperature(p_basal);
189 double specific_enth_basal = EC->enthalpy_permissive(T, 1.0, p_basal);
199 const int ks =
m_grid->kBelowHeight(ice_thickness(i, j));
200 const double *Enth = ice_enthalpy.get_column(i, j);
201 double specific_enth_top = Enth[ks];
225 double by_dt = 1.0 /
dt;
226 printf(
"IBIceModel::set_rate(dt=%f)\n",
dt);
235 for (; base_ii !=
base.
all_vecs.end(); ++base_ii, ++cur_ii, ++rate_ii) {
242 for (
auto p :
m_grid->points()) {
243 const int i = p.i(), j = p.j();
247 vrate(i, j) = (vcur(i, j) - vbase(i, j)) * by_dt;
250 vrate(i, j) = vcur(i, j);
261 for (; base_ii !=
base.
all_vecs.end(); ++base_ii, ++cur_ii) {
268 for (
auto p :
m_grid->points()) {
269 const int i = p.i(), j = p.j();
271 vbase(i, j) = vcur(i, j);
279 auto EC =
ctx()->enthalpy_converter();
292 double const *Enth = ice_enthalpy.get_column(i, j);
295 auto ks =
m_grid->kBelowHeight(ice_thickness(i, j));
296 double senth = Enth[ks];
300 switch ((
int)cell_type(i, j)) {
348 for (; base_ii !=
base.
all_vecs.end(); ++base_ii, ++cur_ii) {
349 base_ii->vec.copy_from(cur_ii->vec);
365 double ice_density =
m_config->get_number(
"constants.ice.density",
"kg m-3");
373 for (
auto p :
m_grid->points()) {
374 const int i = p.i(), j = p.j();
381 if (ice_thickness(i, j) > 0) {
382 int ks = (
int)
m_grid->kBelowHeight(ice_thickness(i, j));
383 const auto *Enth = ice_enthalpy.get_column(i, j);
385 for (
int k = 0;
k < ks; ++
k) {
387 enth2(i, j) += Enth[
k] * dz;
391 double dz = (ice_thickness(i, j) -
m_grid->z(ks));
392 enth2(i, j) += Enth[ks] * dz;
395 enth2(i, j) *= ice_density;
396 mass2(i, j) = ice_thickness(i, j) * ice_density;
418 printf(
"BEGIN IBIceModel::merge_surface_temp default_val=%g\n", default_val);
419 auto EC =
ctx()->enthalpy_converter();
421 double ice_density =
m_config->get_number(
"constants.ice.density");
431 double &surface_temp_ij(surface_temp(i, j));
432 double const &deltah_ij(deltah(i, j));
434 const auto *Enth = ice_enthalpy.get_column(i, j);
437 const int ks =
m_grid->kBelowHeight(ice_thickness(i, j));
438 double spec_enth3 = Enth[ks];
440 if (deltah_ij != default_val) {
442 double toplayer_dz = ice_thickness(i, j) -
m_grid->z(ks);
446 spec_enth3 = spec_enth3 + deltah_ij / (toplayer_dz * ice_density) * timestep_s;
451 const double p = 0.0;
452 surface_temp_ij = EC->temperature(spec_enth3, p);
457 printf(
"END IBIceModel::merge_surface_temp\n");
array::Scalar2 ice_surface_elevation
array::CellType2 cell_type
array::Scalar2 ice_thickness
std::map< std::string, const Component * > m_submodels
the list of sub-models, for writing model states and obtaining diagnostics
std::shared_ptr< stressbalance::StressBalance > m_stress_balance
std::shared_ptr< surface::SurfaceModel > m_surface
void define_variables(const OutputFile &file, const std::set< VariableMetadata > &variables) const
std::shared_ptr< Config > m_config
Configuration flags and parameters.
void define_time(const OutputFile &file, bool with_bounds=false) const
void write_run_stats(const OutputFile &file) const
std::shared_ptr< Logger > m_log
Logger.
std::set< VariableMetadata > m_output_file_contents
Set of variables that will be written to the output file.
std::shared_ptr< Time > m_time
Time manager.
virtual void energy_step(double t, double dt)
Manage the solution of the energy equation, and related parallel communication.
void write_diagnostics(const OutputFile &file, const std::set< std::string > &variable_names) const
Writes variables listed in variable_names to file.
std::shared_ptr< energy::BedThermalUnit > m_btu
std::shared_ptr< OutputWriter > m_output_writer
std::shared_ptr< Context > ctx() const
Return the context this model is running in.
virtual void misc_setup(InputOptions input_options, DiagnosticReport report_type)
Miscellaneous initialization tasks plus tasks that need the fields that can come from regridding.
virtual void write_state(const OutputFile &file) const
virtual void allocate_couplers()
std::unique_ptr< hydrology::Hydrology > m_subglacial_hydrology
std::set< std::string > m_output_vars
std::shared_ptr< energy::EnergyModel > m_energy_model
const std::shared_ptr< Grid > m_grid
Computational grid.
void append_time(double time_seconds) const
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
void add(double alpha, const Array2D< T > &x)
pism::array::Scalar elevmask_ice
pism::array::Scalar ice_top_senth
void construct_surface_temp(pism::array::Scalar &deltah, double default_val, double timestep_s, pism::array::Scalar &surface_temp)
void dumpToFile(const std::string &filename) const
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)
pism::icebin::IBSurfaceModel * ib_surface_model()
virtual void allocate_couplers()
IBIceModel(std::shared_ptr< pism::Grid > grid, const std::shared_ptr< Context > &context, IBIceModel::Params const &_params)
void compute_enth2(pism::array::Scalar &enth2, pism::array::Scalar &mass2)
virtual void massContExplicitStep(double dt)
void prepare_outputs(double time_s)
void energy_step(double t, double dt)
Manage the solution of the energy equation, and related parallel communication.
virtual void allocate_subglacial_hydrology()
Decide which subglacial hydrology model to use.
pism::array::Scalar elevmask_land
virtual void misc_setup(InputOptions input_options, DiagnosticReport report_type)
Miscellaneous initialization tasks plus tasks that need the fields that can come from regridding.
double m_meter_per_s_to_kg_per_m2
pism::array::Scalar enthxfer
pism::array::Scalar massxfer
pism::array::Scalar deltah
pism::array::Scalar href_to_h
SMB as seen by PISM in iMgeometry.cc massContExplicitSte(). Used to check icebin_smb....
pism::array::Scalar nonneg_rule
std::ostream & print_formulas(std::ostream &out)
pism::array::Scalar geothermal_flux
Total amount of geothermal energy [J/m^2].
MassEnthVec2S internal_advection
MassEnthVec2S smb
accumulation / ablation, as provided by Icebin
pism::array::Scalar basal_frictional_heating
Total amount of basal friction heating [J/m^2].
std::vector< VecWithFlags > all_vecs
pism::array::Scalar strain_heating
Total amount of strain heating [J/m^2].
MassEnthVec2S melt_grounded
basal melt (grounded) (from summing meltrate_grounded)
pism::array::Scalar upward_geothermal_flux
Total amount of geothermal energy [J/m^2].
MassEnthVec2S melt_floating
sub-shelf melt (from summing meltrate_floating)
pism::array::Scalar deltah
Change in enthalpy of top layer.
#define PISM_ERROR_LOCATION
void sum_columns(const Array3D &data, double A, double B, Scalar &output)
void write_config(const Config &config, const std::string &variable_name, const OutputFile &file)
std::string printf(const char *format,...)