20 #include "pism/util/array/Staggered.hh"
22 #include "pism/util/Mask.hh"
24 #include "pism/util/pism_utilities.hh"
25 #include "pism/util/array/CellType.hh"
26 #include "pism/util/array/Vector.hh"
33 set_begin_access_use_dof(
true);
37 unsigned int stencil_width)
39 set_begin_access_use_dof(
true);
48 for (
auto p =
grid()->points(); p; p.next()) {
49 const int i = p.i(), j = p.j();
51 (*this)(i, j, 0) = input(i, j, 0);
52 (*this)(i, j, 1) = input(i, j, 1);
71 double z[2] = {0.0, 0.0};
74 for (
auto p = input.
grid()->points(); p; p.next()) {
75 const int i = p.i(), j = p.j();
77 z[0] =
std::max(z[0], std::abs(input(i, j, 0)));
78 z[1] =
std::max(z[1], std::abs(input(i, j, 1)));
84 return {result[0], result[1]};
89 bool include_floating_ice,
95 auto grid = result.
grid();
99 for (
auto p = grid->points(); p; p.next()) {
100 const int i = p.i(), j = p.j();
103 (include_floating_ice and cell_type.
icy(i, j))) {
104 auto M = cell_type.
star(i, j);
105 auto F = input.
star(i, j);
107 int n = 0, e = 0, s = 0, w = 0;
108 if (include_floating_ice) {
109 n =
static_cast<int>(
icy(M.n));
110 e =
static_cast<int>(
icy(M.e));
111 s =
static_cast<int>(
icy(M.s));
112 w =
static_cast<int>(
icy(M.w));
120 if (
n + e + s + w > 0) {
121 result(i, j) = (
n *
F.n + e *
F.e + s *
F.s + w *
F.w) / (
n + e + s + w);
133 bool include_floating_ice,
142 auto grid = result.
grid();
146 for (
auto p = grid->points(); p; p.next()) {
147 const int i = p.i(), j = p.j();
149 auto M = cell_type.
star(i, j);
150 auto F = input.
star(i, j);
152 int n = 0, e = 0, s = 0, w = 0;
153 if (include_floating_ice) {
154 n =
static_cast<int>(
icy(M.n));
155 e =
static_cast<int>(
icy(M.e));
156 s =
static_cast<int>(
icy(M.s));
157 w =
static_cast<int>(
icy(M.w));
166 result(i, j).u = (e *
F.e + w *
F.w) / (e + w);
168 result(i, j).u = 0.0;
172 result(i, j).v = (
n *
F.n + s *
F.s) / (
n + s);
174 result(i, j).v = 0.0;
void failed()
Indicates a failure of a parallel section.
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
stencils::Star< T > star(int i, int j) const
std::shared_ptr< const Grid > grid() const
void inc_state_counter()
Increment the object state counter.
void update_ghosts()
Updates ghost points.
unsigned int stencil_width() const
Get the stencil width of the current Array. Returns 0 if ghosts are not available.
Abstract class for reading, writing, allocating, and accessing a DA-based PETSc Vec (2D and 3D fields...
bool grounded_ice(int i, int j) const
bool icy(int i, int j) const
Staggered1(std::shared_ptr< const Grid > grid, const std::string &name)
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)
Staggered(std::shared_ptr< const Grid > grid, const std::string &name)
A class for storing and accessing internal staggered-grid 2D fields. Uses dof=2 storage....
void staggered_to_regular(const array::CellType1 &cell_type, const array::Staggered1 &input, bool include_floating_ice, array::Scalar &result)
double max(const array::Scalar &input)
Finds maximum over all the values in an array::Scalar object. Ignores ghosts.
double absmax(const array::Scalar &input)
Finds maximum over all the absolute values in an array::Scalar object. Ignores ghosts.
bool icy(int M)
Ice-filled cell (grounded or floating).
static double F(double SL, double B, double H, double alpha)
void GlobalMax(MPI_Comm comm, double *local, double *result, int count)