19 #include "pism/coupler/surface/StuffAsAnomaly.hh"
20 #include "pism/util/Grid.hh"
21 #include "pism/util/Time.hh"
22 #include "pism/util/pism_utilities.hh"
23 #include "pism/util/MaxTimestep.hh"
28 StuffAsAnomaly::StuffAsAnomaly(std::shared_ptr<const Grid>
g, std::shared_ptr<SurfaceModel> input)
29 : SurfaceModel(
g, input),
32 m_mass_flux_input(m_grid,
"climatic_mass_balance",
WITHOUT_GHOSTS),
37 m_mass_flux.set_attrs(
"climate_state",
38 "surface mass balance (accumulation/ablation) rate",
40 "land_ice_surface_specific_mass_balance_flux");
41 m_mass_flux.metadata()[
"output_units"] =
"kg m-2 year-1";
43 m_temp.set_attrs(
"climate_state",
"ice temperature at the ice surface",
47 m_mass_flux_0.set_attrs(
"internal",
"surface mass flux at the beginning of a run",
48 "kg m-2 s-1",
"land_ice_surface_specific_mass_balance_flux");
50 m_mass_flux_input.set_attrs(
"model_state",
"surface mass flux to apply anomalies to",
51 "kg m-2 s-1",
"land_ice_surface_specific_mass_balance_flux");
53 m_temp_0.set_attrs(
"internal",
"ice-surface temperature and the beginning of a run",
"K",
56 m_temp_input.set_attrs(
"model_state",
"ice-surface temperature to apply anomalies to",
60 void StuffAsAnomaly::init_impl(
const Geometry &geometry) {
61 if (m_input_model != NULL) {
62 m_input_model->init(geometry);
68 "* Initializing the 'turn_into_anomaly' modifier\n"
69 " (it applies climate data as anomalies relative to 'ice_surface_temp' and 'climatic_mass_balance'\n"
70 " read from '%s'.\n", opts.filename.c_str());
73 m_mass_flux_input.regrid(opts.filename, CRITICAL);
74 m_temp_input.regrid(opts.filename, CRITICAL);
76 m_mass_flux_input.read(opts.filename, opts.record);
77 m_temp_input.read(opts.filename, opts.record);
81 MaxTimestep StuffAsAnomaly::max_timestep_impl(
double t)
const {
83 return MaxTimestep(
"surface turn_into_anomaly");
86 void StuffAsAnomaly::update_impl(
const Geometry &geometry,
double t,
double dt) {
88 if (m_input_model != NULL) {
89 m_input_model->update(geometry, t, dt);
90 m_temp.copy_from(m_input_model->temperature());
91 m_mass_flux.copy_from(m_input_model->mass_flux());
94 if (t < time().start() + 1) {
96 m_temp_0.copy_from(m_temp);
97 m_mass_flux_0.copy_from(m_mass_flux);
101 array::AccessScope list{&m_mass_flux, &m_mass_flux_0, &m_mass_flux_input,
102 &m_temp, &m_temp_0, &m_temp_input};
104 for (
auto p = m_grid->points(); p; p.next()) {
105 const int i = p.i(), j = p.j();
107 m_mass_flux(i, j) = m_mass_flux(i, j) - m_mass_flux_0(i, j) + m_mass_flux_input(i, j);
108 m_temp(i, j) = m_temp(i, j) - m_temp_0(i, j) + m_temp_input(i, j);
112 const array::Scalar &StuffAsAnomaly::mass_flux_impl()
const {
116 const array::Scalar &StuffAsAnomaly::temperature_impl()
const {
InputOptions process_input_options(MPI_Comm com, Config::ConstPtr config)