20#include "pism/geometry/GeometryEvolution.hh"
22#include "pism/util/Grid.hh"
23#include "pism/util/Mask.hh"
24#include "pism/util/array/CellType.hh"
25#include "pism/util/array/Scalar.hh"
26#include "pism/util/array/Staggered.hh"
27#include "pism/util/array/Vector.hh"
29#include "pism/geometry/part_grid_threshold_thickness.hh"
30#include "pism/util/Context.hh"
31#include "pism/util/Logger.hh"
32#include "pism/util/Profiling.hh"
33#include "pism/util/Interpolation1D.hh"
34#include "pism/util/pism_utilities.hh"
36#include "pism/geometry/flux_limiter.hh"
48 Impl(std::shared_ptr<const Grid>
g);
97 : gc(*grid->ctx()->config()),
98 flux_divergence(grid,
"flux_divergence"),
99 conservation_error(grid,
"conservation_error"),
100 effective_SMB(grid,
"effective_SMB"),
101 effective_BMB(grid,
"effective_BMB"),
102 thickness_change(grid,
"thickness_change"),
103 ice_area_specific_volume_change(grid,
"ice_area_specific_volume_change"),
104 flux_staggered(grid,
"flux_staggered"),
105 flux_limited(grid,
"flux_limited"),
106 input_velocity(grid,
"input_velocity"),
107 bed_elevation(grid,
"bed_elevation"),
108 sea_level(grid,
"sea_level"),
109 ice_thickness(grid,
"ice_thickness"),
110 area_specific_volume(grid,
"area_specific_volume"),
111 surface_elevation(grid,
"surface_elevation"),
112 cell_type(grid,
"cell_type"),
113 residual(grid,
"residual"),
114 thickness(grid,
"thickness") {
116 auto config =
grid->ctx()->config();
122 ice_density = config->get_number(
"constants.ice.density");
123 use_bmr = config->get_flag(
"geometry.update.use_basal_melt_rate");
124 use_part_grid = config->get_flag(
"geometry.part_grid.enabled");
131 .
long_name(
"fluxes through cell interfaces (sides) on the staggered grid (x-offset)")
135 .
long_name(
"fluxes through cell interfaces (sides) on the staggered grid (y-offset)")
146 "conservation error due to enforcing non-negativity of ice thickness (over the last time step)")
150 .
long_name(
"effective surface mass balance over the last time step")
154 .
long_name(
"effective basal mass balance over the last time step")
160 .
long_name(
"change in area-specific volume due to flow")
161 .
units(
"meters^3 / meters^2");
167 .
long_name(
"ghosted copy of the input velocity")
168 .
units(
"meters / second");
175 .
long_name(
"working (ghosted) copy of the ice thickness")
179 .
long_name(
"working (ghosted) copy of the area specific volume")
180 .
units(
"meters^3 / meters^2");
183 .
long_name(
"working (ghosted) copy of the surface elevation")
292 if (limiter_count > 0) {
293 m_log->message(2,
"limited ice flux at %d locations\n", limiter_count);
359 surface_mass_balance_rate,
388 for (
auto p :
m_grid->points()) {
389 const int i = p.i(), j = p.j();
393 const double H_new = (H(i, j) + dH_SMB(i, j)) + dH_BMB(i, j);
420 if ((ice_free_ocean(current) and input > 0.0) or (ice_free_ocean(neighbor) and input < 0.0)) {
425 if ((ice_free_land(current) and input > 0.0) or (ice_free_land(neighbor) and input < 0.0)) {
430 if (grounded_ice(current) and grounded_ice(neighbor)) {
435 if ((grounded_ice(current) and floating_ice(neighbor)) or
436 (floating_ice(current) and grounded_ice(neighbor))) {
441 if ((grounded_ice(current) and ice_free_land(neighbor)) or
442 (ice_free_land(current) and grounded_ice(neighbor))) {
447 if ((grounded_ice(current) and ice_free_ocean(neighbor)) or
448 (ice_free_ocean(current) and grounded_ice(neighbor))) {
453 if (floating_ice(current) and floating_ice(neighbor)) {
458 if ((floating_ice(current) and ice_free_land(neighbor)) or
459 (ice_free_land(current) and floating_ice(neighbor))) {
465 if ((floating_ice(current) and ice_free_ocean(neighbor)) or
466 (ice_free_ocean(current) and floating_ice(neighbor))) {
471 if (ice_free_land(current) and ice_free_land(neighbor)) {
476 if ((ice_free_land(current) and ice_free_ocean(neighbor)) or
477 (ice_free_ocean(current) and ice_free_land(neighbor))) {
482 if (ice_free_ocean(current) and ice_free_ocean(neighbor)) {
498 if ((ice_free_ocean(current) and flux > 0.0) or (ice_free_ocean(neighbor) and flux < 0.0)) {
503 if ((ice_free_land(current) and flux > 0.0) or (ice_free_land(neighbor) and flux < 0.0)) {
508 if (grounded_ice(current) and grounded_ice(neighbor)) {
513 if ((grounded_ice(current) and floating_ice(neighbor)) or
514 (floating_ice(current) and grounded_ice(neighbor))) {
519 if ((grounded_ice(current) and ice_free_land(neighbor)) or
520 (ice_free_land(current) and grounded_ice(neighbor))) {
525 if ((grounded_ice(current) and ice_free_ocean(neighbor)) or
526 (ice_free_ocean(current) and grounded_ice(neighbor))) {
531 if (floating_ice(current) and floating_ice(neighbor)) {
537 if ((floating_ice(current) and ice_free_land(neighbor)) or
538 (ice_free_land(current) and floating_ice(neighbor))) {
544 if ((floating_ice(current) and ice_free_ocean(neighbor)) or
545 (ice_free_ocean(current) and floating_ice(neighbor))) {
550 if (ice_free_land(current) and ice_free_land(neighbor)) {
555 if ((ice_free_land(current) and ice_free_ocean(neighbor)) or
556 (ice_free_ocean(current) and ice_free_land(neighbor))) {
561 if (ice_free_ocean(current) and ice_free_ocean(neighbor)) {
583 array::AccessScope list{ &cell_type, &velocity, &ice_thickness, &diffusive_flux, &output };
588 for (
auto p :
m_grid->points()) {
589 const int i = p.i(), j = p.j(), M = cell_type.
as_int(i, j);
591 const double H = ice_thickness(i, j);
594 for (
int n = 0;
n < 2; ++
n) {
595 const int oi = 1 -
n,
600 const int M_n = cell_type.
as_int(i_n, j_n);
605 const Vector2d& V_n = velocity(i_n, j_n);
606 int W =
static_cast<int>(icy(M)), W_n =
static_cast<int>(icy(M_n));
608 auto v_staggered = (W * V + W_n * V_n) / std::max(W + W_n, 1);
609 v =
n == 0 ? v_staggered.u : v_staggered.v;
613 const double H_n = ice_thickness(i_n, j_n),
614 Q_advective = v * (v > 0.0 ? H : H_n);
616 output(i, j,
n) = Q_advective;
621 for (
auto p :
m_grid->points()) {
622 const int i = p.i(), j = p.j(), M = cell_type.
as_int(i, j);
624 for (
int n = 0;
n < 2; ++
n) {
625 const int oi = 1 -
n,
630 const int M_n = cell_type.
as_int(i_n, j_n);
636 output(i, j,
n) = Q_diffusive + Q_advective;
661 for (
auto p :
m_grid->points()) {
662 const int i = p.i(), j = p.j();
664 auto Q = flux.
star(i, j);
666 double divQ = (Q.e - Q.w) / dx + (Q.n - Q.s) / dy;
668 if (thickness_bc_mask(i, j) > 0.5) {
724 const double Lz =
m_grid->Lz();
728 for (
auto p :
m_grid->points()) {
729 const int i = p.i(), j = p.j();
737 area_specific_volume(i, j) += -divQ * dt;
745 if (threshold == 0.0) {
746 threshold = area_specific_volume(i, j);
749 if (area_specific_volume(i, j) >= threshold) {
750 ice_thickness(i, j) += threshold;
752 area_specific_volume(i, j) = 0.0;
761 ice_thickness(i, j) += -dt * divQ;
763 if (ice_thickness(i, j) > Lz) {
765 "ice thickness would exceed Lz at i=%d, j=%d (H=%f, Lz=%f)",
766 i, j, ice_thickness(i, j), Lz);
785 const int max_n_iterations = (
int)
m_config->get_number(
"geometry.part_grid.max_iterations");
788 for (
int i = 0; i < max_n_iterations and not done; ++i) {
789 m_log->message(4,
"redistribution iteration %d\n", i);
800 "WARNING: not done redistributing mass after %d iterations, remaining residual: %f m^3.\n",
809 if (max(ice_thickness) >
m_grid->Lz()) {
811 "after part_grid residual redistribution");
840 array::AccessScope list{ &cell_type, &ice_thickness, &area_specific_volume, &residual };
842 for (
auto p :
m_grid->points()) {
843 const int i = p.i(), j = p.j();
845 if (residual(i, j) <= 0.0) {
853 N += ice_free_ocean(m[d]) ? 1 : 0;
863 ice_thickness(i, j) += residual(i, j);
864 residual(i, j) = 0.0;
871 for (
auto p :
m_grid->points()) {
872 const int i = p.i(), j = p.j();
874 auto R = residual.
star(i, j);
877 area_specific_volume(i, j) += (R.e + R.w + R.n + R.s);
894 m_impl->
gc.
compute(sea_level, bed_topography, ice_thickness, cell_type, ice_surface_elevation);
896 double remaining_residual = 0.0;
903 &bed_topography, &cell_type };
905 for (
auto p :
m_grid->points()) {
906 const int i = p.i(), j = p.j();
908 if (area_specific_volume(i, j) <= 0.0) {
914 ice_surface_elevation.
star(i, j), bed_topography(i, j));
918 if (threshold == 0.0) {
919 threshold = area_specific_volume(i, j);
922 if (area_specific_volume(i, j) >= threshold) {
923 ice_thickness(i, j) += threshold;
924 residual(i, j) = area_specific_volume(i, j) - threshold;
925 area_specific_volume(i, j) = 0.0;
927 remaining_residual += residual(i, j);
935 done = remaining_residual <= 0.0;
965 for (
auto p :
m_grid->points()) {
966 const int i = p.i(), j = p.j();
968 const double H = ice_thickness(i, j), dH = thickness_change(i, j);
972 thickness_change(i, j) = -H;
976 const double V = area_specific_volume(i, j), dV = area_specific_volume_change(i, j);
979 area_specific_volume_change(i, j) = -V;
1023 array::AccessScope list{ &ice_thickness, &surface_mass_flux, &basal_melt_rate, &cell_type,
1024 &thickness_bc_mask, &effective_SMB, &effective_BMB };
1028 for (
auto p :
m_grid->points()) {
1029 const int i = p.i(), j = p.j();
1033 effective_SMB(i, j) = 0.0;
1034 effective_BMB(i, j) = 0.0;
1038 const double H = ice_thickness(i, j);
1052 effective_SMB(i, j) = dH_SMB;
1053 effective_BMB(i, j) = dH_BMB;
1061namespace diagnostics {
1072 auto result = allocate<array::Scalar>(
"flux_divergence");
1089 auto result = allocate<array::Staggered>(
"flux_staggered");
1100 using namespace diagnostics;
1103 std::map<std::string, Ptr> result;
1105 {
"flux_staggered", Ptr(
new FluxStaggered(
this)) },
1106 {
"flux_divergence", Ptr(
new FluxDivergence(
this)) },
1133 velocity, diffusive_flux,
1140 for (
auto p :
m_grid->points()) {
1141 const int i = p.i(), j = p.j();
1145 for (
int n : {0, 1}) {
1154 if (not (M == 0 and M_n == 0)) {
1155 output(i, j,
n) = 0.0;
1189 for (
auto p :
m_grid->points()) {
1190 const int i = p.i(), j = p.j();
1193 effective_SMB(i, j) = 0.0;
1194 effective_BMB(i, j) = 0.0;
1241 Q.
n *= (
int)grounded(cell_type.
n);
1242 Q.e *= (
int)grounded(cell_type.
e);
1243 Q.s *= (
int)grounded(cell_type.
s);
1244 Q.w *= (
int)grounded(cell_type.
w);
1246 return dy * (Q.w - Q.e) + dx * (Q.s - Q.n);
1268 auto grid = output.
grid();
1270 const double dx = grid->dx(),
1277 for (
auto p : grid->points()) {
1278 const int i = p.i(), j = p.j();
1280 double result = 0.0;
1282 if (cell_type.
ocean(i, j)) {
1284 auto Q = flux.
star(i, j);
1291 result *= unit_conversion_factor;
1294 output(i, j) += result;
1305 auto grid = cell_type.
grid();
1311 auto ice_density = grid->ctx()->config()->get_number(
"constants.ice.density");
1313 double conversion_factor = dt * ice_density;
1315 double total_flux = 0.0;
1321 for (
auto p : grid->points()) {
1322 const int i = p.i(), j = p.j();
1324 if (cell_type.
ocean(i, j)) {
1326 auto Q = flux.
star(i, j);
1332 total_flux += volume_flux * conversion_factor;
1340 return GlobalSum(grid->com, total_flux);
std::shared_ptr< const Grid > grid() const
std::shared_ptr< const Config > m_config
configuration database used by this component
const std::shared_ptr< const Grid > m_grid
grid used by this component
const Profiling & profiling() const
std::shared_ptr< const Logger > m_log
logger (for easy access)
A class defining a common interface for most PISM sub-models.
const GeometryEvolution * model
A template derived from Diagnostic, adding a "Model".
std::vector< VariableMetadata > m_vars
metadata corresponding to NetCDF variables
std::shared_ptr< Diagnostic > Ptr
void compute_mask(const array::Scalar &sea_level, const array::Scalar &bed, const array::Scalar &thickness, array::Scalar &result) const
void set_icefree_thickness(double threshold)
void compute(const array::Scalar &sea_level, const array::Scalar &bed, const array::Scalar &thickness, array::Scalar &out_mask, array::Scalar &out_surface) const
const array::Scalar & thickness_change_due_to_flow() const
virtual void set_no_model_mask(const array::Scalar &mask)
virtual void init_impl(const InputOptions &opts)
virtual void compute_surface_and_basal_mass_balance(double dt, const array::Scalar &thickness_bc_mask, const array::Scalar &ice_thickness, const array::CellType &cell_type, const array::Scalar &surface_mass_flux, const array::Scalar &basal_melt_rate, array::Scalar &effective_SMB, array::Scalar &effective_BMB)
const array::Scalar & bottom_surface_mass_balance() const
void apply_mass_fluxes(Geometry &geometry) const
virtual void set_no_model_mask_impl(const array::Scalar &mask)
void source_term_step(const Geometry &geometry, double dt, const array::Scalar &thickness_bc_mask, const array::Scalar &surface_mass_balance_rate, const array::Scalar &basal_melt_rate)
const array::Scalar & flux_divergence() const
void update_in_place(double dt, const array::Scalar &bed_topography, const array::Scalar &sea_level, const array::Scalar &flux_divergence, array::Scalar &ice_thickness, array::Scalar &area_specific_volume)
void residual_redistribution_iteration(const array::Scalar &bed_topography, const array::Scalar &sea_level, array::Scalar1 &ice_surface_elevation, array::Scalar &ice_thickness, array::CellType1 &cell_type, array::Scalar &area_specific_volume, array::Scalar1 &residual, bool &done)
Perform one iteration of the residual mass redistribution.
virtual void ensure_nonnegativity(const array::Scalar &ice_thickness, const array::Scalar &area_specific_volume, array::Scalar &thickness_change, array::Scalar &area_specific_volume_change, array::Scalar &conservation_error)
virtual void compute_interface_fluxes(const array::CellType1 &cell_type, const array::Scalar &ice_thickness, const array::Vector &velocity, const array::Staggered &diffusive_flux, array::Staggered &output)
GeometryEvolution(std::shared_ptr< const Grid > grid)
std::map< std::string, Diagnostic::Ptr > spatial_diagnostics_impl() const
void flow_step(const Geometry &ice_geometry, double dt, const array::Vector &advective_velocity, const array::Staggered &diffusive_flux, const array::Scalar &thickness_bc_mask)
const array::Scalar & top_surface_mass_balance() const
void apply_flux_divergence(Geometry &geometry) const
const array::Scalar & area_specific_volume_change_due_to_flow() const
virtual void compute_flux_divergence(double dt, const array::Staggered1 &flux, const array::Scalar &thickness_bc_mask, array::Scalar &conservation_error, array::Scalar &output)
const array::Scalar & conservation_error() const
const array::Staggered1 & flux_staggered() const
void init(const InputOptions &opts)
array::Scalar1 sea_level_elevation
array::Scalar1 ice_area_specific_volume
array::CellType2 cell_type
array::Scalar2 ice_thickness
array::Scalar2 bed_elevation
void failed()
Indicates a failure of a parallel section.
void begin(const char *name) const
void end(const char *name) const
array::Scalar1 m_no_model_mask
RegionalGeometryEvolution(std::shared_ptr< const Grid > grid)
void compute_surface_and_basal_mass_balance(double dt, const array::Scalar &thickness_bc_mask, const array::Scalar &ice_thickness, const array::CellType &cell_type, const array::Scalar &surface_mass_flux, const array::Scalar &basal_melt_rate, array::Scalar &effective_SMB, array::Scalar &effective_BMB)
void compute_interface_fluxes(const array::CellType1 &cell_type, const array::Scalar &ice_thickness, const array::Vector &velocity, const array::Staggered &diffusive_flux, array::Staggered &output)
void set_no_model_mask_impl(const array::Scalar &mask)
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
This class represents a 2D vector field (such as ice velocity) at a certain grid point.
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
void add(double alpha, const Array2D< T > &x)
void set_interpolation_type(InterpolationType type)
std::shared_ptr< const Grid > grid() const
void set(double c)
Result: v[j] <- c for all j.
void update_ghosts()
Updates ghost points.
VariableMetadata & metadata(unsigned int N=0)
Returns a reference to the VariableMetadata 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 ice_free_ocean(int i, int j) const
bool ocean(int i, int j) const
"Cell type" mask. Adds convenience methods to array::Scalar.
int as_int(int i, int j) const
stencils::Star< double > star(int i, int j) const
Returns the values at interfaces of the cell i,j using the staggered grid.
void copy_from(const array::Staggered &input)
A class for storing and accessing internal staggered-grid 2D fields. Uses dof=2 storage....
std::shared_ptr< array::Array > compute_impl() const
FluxDivergence(const GeometryEvolution *m)
Report the divergence of the ice flux.
std::shared_ptr< array::Array > compute_impl() const
FluxStaggered(const GeometryEvolution *m)
Report mass flux on the staggered grid.
#define PISM_ERROR_LOCATION
bool icy(int M)
Ice-filled cell (grounded or floating).
bool ice_free_land(int M)
bool ice_free_ocean(int M)
bool grounded(int M)
Grounded cell (grounded ice or ice-free).
bool ice_free(int M)
Ice-free cell (grounded or ocean).
int make_nonnegative_preserving(double dt, const array::Scalar1 &x, const array::Staggered1 &flux, array::Staggered &result)
static double effective_change(double H, double dH)
static double limit_advective_flux(int current, int neighbor, double input)
std::map< std::string, Diagnostic::Ptr > DiagnosticList
static double volume_flow_rate_from_land_to_water(const stencils::Star< int > &cell_type, const stencils::Star< double > &flux, double dx, double dy)
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'...
double total_grounding_line_flux(const array::CellType1 &cell_type, const array::Staggered1 &flux, double dt)
void ice_flow_rate_across_grounding_line(const array::CellType1 &cell_type, const array::Staggered1 &flux, double unit_conversion_factor, array::Scalar &output)
void GlobalSum(MPI_Comm comm, double *local, double *result, int count)
static double limit_diffusive_flux(int current, int neighbor, double flux)
array::Scalar flux_divergence
Flux divergence (used to track thickness changes due to flow).
array::Scalar thickness_change
Change in ice thickness due to flow during the last time step.
array::Vector1 input_velocity
array::CellType1 cell_type
array::Scalar conservation_error
bool use_bmr
True if the basal melt rate contributes to geometry evolution.
Impl(std::shared_ptr< const Grid > g)
array::Scalar ice_area_specific_volume_change
Change in the ice area-specific volume due to flow during the last time step.
array::Staggered flux_limited
Temporary storage for the flux limiter.
array::Scalar1 bed_elevation
array::Scalar effective_BMB
Effective basal mass balance.
array::Scalar1 area_specific_volume
bool use_part_grid
True if the part-grid scheme is enabled.
array::Scalar1 surface_elevation
array::Staggered1 flux_staggered
Flux through cell interfaces. Ghosted.
array::Scalar1 ice_thickness
array::Scalar effective_SMB
Effective surface mass balance.
Star stencil points (in the map-plane).