19#include "pism/frontretreat/FrontRetreat.hh"
21#include "pism/util/array/CellType.hh"
22#include "pism/util/MaxTimestep.hh"
23#include "pism/util/pism_utilities.hh"
24#include "pism/geometry/part_grid_threshold_thickness.hh"
25#include "pism/geometry/Geometry.hh"
26#include "pism/util/Context.hh"
32 m_cell_type(m_grid,
"cell_type"),
33 m_tmp(m_grid,
"temporary_storage") {
48 const int Mx =
m_grid->Mx();
49 const int My =
m_grid->My();
53 for (
auto p =
m_grid->points(1); p; p.next()) {
54 const int i = p.i(), j = p.j();
56 if (i < 0 or i >= Mx or j < 0 or j >= My) {
59 output(i, j) = input(i, j);
76 auto sys =
grid->ctx()->unit_system();
80 double dt_min =
m_config->get_number(
"geometry.front_retreat.minimum_time_step",
"seconds");
83 retreat_rate_max = 0.0,
84 retreat_rate_mean = 0.0;
89 for (
auto pt =
grid->points(); pt; pt.next()) {
90 const int i = pt.i(), j = pt.j();
94 bc_mask(i, j) < 0.5) {
97 const double C = retreat_rate(i, j);
100 retreat_rate_mean += C;
101 retreat_rate_max = std::max(C, retreat_rate_max);
110 retreat_rate_mean /= N_cells;
112 retreat_rate_mean = 0.0;
115 double denom = retreat_rate_max /
grid->dx();
116 const double epsilon = convert(sys, 0.001 / (
grid->dx() +
grid->dy()),
"seconds",
"years");
118 double dt = 1.0 / (denom + epsilon);
121 " frontal retreat: maximum rate = %.2f m/year gives dt=%.5f years\n"
122 " mean rate = %.2f m/year over %d cells\n",
123 convert(
m_sys, retreat_rate_max,
"m second-1",
"m year-1"),
124 convert(
m_sys, dt,
"seconds",
"years"),
125 convert(
m_sys, retreat_rate_mean,
"m second-1",
"m year-1"),
128 return MaxTimestep(std::max(dt, dt_min),
"front_retreat");
153 if (
m_config->get_flag(
"geometry.front_retreat.wrap_around")) {
161 const double dx =
m_grid->dx();
170 for (
auto pt =
m_grid->points(); pt; pt.next()) {
171 const int i = pt.i(), j = pt.j();
176 bc_mask(i, j) < 0.5) {
180 rate = retreat_rate(i, j),
181 Href_old = Href(i, j);
185 ice_thickness.
star(i, j),
186 surface_elevation.
star(i, j),
190 const double Href_change = -dt * rate * H_threshold / dx;
192 if (Href_old + Href_change >= 0.0) {
194 Href(i, j) = Href_old + Href_change;
211 sl = sea_level.
star(i, j);
228 m_tmp(i, j) = (Href_old + Href_change) / (
double)N;
241 for (
auto p =
m_grid->points(); p; p.next()) {
242 const int i = p.i(), j = p.j();
245 if (bc_mask.
as_int(i, j) == 0 and
249 const double delta_H = (
m_tmp(i + 1, j) +
m_tmp(i - 1, j) +
253 Href(i, j) = ice_thickness(i, j) + delta_H;
254 ice_thickness(i, j) = 0.0;
258 if (Href(i, j) < 0.0) {
const units::System::Ptr m_sys
unit system used by this component
std::shared_ptr< const Grid > grid() const
const Config::ConstPtr m_config
configuration database used by this component
const Logger::ConstPtr m_log
logger (for easy access)
const std::shared_ptr< const Grid > m_grid
grid used by this component
A class defining a common interface for most PISM sub-models.
void update_geometry(double dt, const Geometry &geometry, const array::Scalar1 &bc_mask, const array::Scalar &retreat_rate, array::Scalar &Href, array::Scalar1 &ice_thickness)
array::CellType1 m_cell_type
MaxTimestep max_timestep(const array::CellType1 &cell_type, const array::Scalar &bc_mask, const array::Scalar &retreat_rate) const
FrontRetreat(std::shared_ptr< const Grid > g)
void compute_modified_mask(const array::CellType1 &input, array::CellType1 &output) const
array::Scalar1 sea_level_elevation
array::Scalar2 ice_surface_elevation
array::CellType2 cell_type
array::Scalar2 bed_elevation
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
void failed()
Indicates a failure of a parallel section.
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
void copy_from(const Array2D< T > &source)
stencils::Star< T > star(int i, int j) const
std::shared_ptr< const Grid > grid() const
void set(double c)
Result: v[j] <- c for all j.
void update_ghosts()
Updates ghost points.
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
bool next_to_ice(int i, int j) const
Ice-free margin (at least one of four neighbors has ice).
stencils::Star< int > star_int(int i, int j) const
bool floating_ice(int i, int j) const
bool ice_free_ocean(int i, int j) const
bool grounded_ice(int i, int j) const
stencils::Star< int > star_int(int i, int j) const
int as_int(int i, int j) const
double convert(System::Ptr system, double input, const std::string &spec1, const std::string &spec2)
Convert a quantity from unit1 to unit2.
void GlobalMax(MPI_Comm comm, double *local, double *result, int count)
double part_grid_threshold_thickness(stencils::Star< int > cell_type, stencils::Star< double > ice_thickness, stencils::Star< double > surface_elevation, double bed_elevation)
Compute threshold thickness used when deciding if a partially-filled cell should be considered 'full'...
void GlobalSum(MPI_Comm comm, double *local, double *result, int count)