20 #include "pism/util/array/Scalar.hh"
22 #include "pism/util/array/Vector.hh"
23 #include "pism/util/VariableMetadata.hh"
24 #include "pism/util/pism_utilities.hh"
45 auto result = std::make_shared<Scalar>(this->
grid(), this->
get_name());
46 result->metadata() = this->
metadata();
57 :
Scalar(grid, name, width) {
69 for (
auto p = result.
grid()->points(); p; p.next()) {
70 const int i = p.i(), j = p.j();
72 result(i, j) = input(i, j).magnitude();
82 for (
auto p = result.
grid()->points(); p; p.next()) {
83 const int i = p.i(), j = p.j();
96 return (array(i + 1,j) - array(i - 1,j)) / (2 * array.
grid()->dx());
102 return (array(i,j + 1) - array(i,j - 1)) / (2 * array.
grid()->dy());
109 const auto &grid = *array.
grid();
112 return diff_x(array, i,j);
116 return (array(i + 1,j) - array(i,j)) / (grid.dx());
119 if (i == (
int)grid.Mx() - 1) {
120 return (array(i,j) - array(i - 1,j)) / (grid.dx());
123 return diff_x(array, i,j);
130 const auto &grid = *array.
grid();
133 return diff_y(array, i,j);
137 return (array(i,j + 1) - array(i,j)) / (grid.dy());
140 if (j == (
int)grid.My() - 1) {
141 return (array(i,j) - array(i,j - 1)) / (grid.dy());
144 return diff_y(array, i,j);
156 for (
auto p = input.
grid()->points(); p; p.next()) {
157 result += input(p.i(), p.j());
168 auto grid = input.
grid();
170 double result = input(grid->xs(), grid->ys());
171 for (
auto p = grid->points(); p; p.next()) {
172 result =
std::max(result, input(p.i(), p.j()));
184 for (
auto p = input.
grid()->points(); p; p.next()) {
185 result =
std::max(result, std::abs(input(p.i(), p.j())));
196 auto grid = input.
grid();
198 double result = input(grid->xs(), grid->ys());
199 for (
auto p = grid->points(); p; p.next()) {
200 result =
std::min(result, input(p.i(), p.j()));
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
A storage vector combining related fields in a struct.
const std::string & get_name() const
Get the name of an Array object.
std::shared_ptr< const Grid > grid() const
void inc_state_counter()
Increment the object state counter.
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Scalar1(std::shared_ptr< const Grid > grid, const std::string &name)
Scalar2(std::shared_ptr< const Grid > grid, const std::string &name)
Scalar(std::shared_ptr< const Grid > grid, const std::string &name)
std::shared_ptr< Scalar > duplicate() const
void apply_mask(const array::Scalar &M, double fill, array::Scalar &result)
Masks out all the areas where by setting them to fill.
double diff_y(const array::Scalar &array, int i, int j)
Returns the y-derivative at i,j approximated using centered finite differences.
double max(const array::Scalar &input)
Finds maximum over all the values in an array::Scalar object. Ignores ghosts.
double diff_x(const array::Scalar &array, int i, int j)
Returns the x-derivative at i,j approximated using centered finite differences.
double sum(const array::Scalar &input)
Sums up all the values in an array::Scalar object. Ignores ghosts.
double diff_x_p(const array::Scalar &array, int i, int j)
Returns the x-derivative at i,j approximated using centered finite differences. Respects grid periodi...
double min(const array::Scalar &input)
Finds minimum 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.
void compute_magnitude(const array::Vector &input, array::Scalar &result)
double diff_y_p(const array::Scalar &array, int i, int j)
Returns the y-derivative at i,j approximated using centered finite differences. Respects grid periodi...
void GlobalMax(MPI_Comm comm, double *local, double *result, int count)
void GlobalMin(MPI_Comm comm, double *local, double *result, int count)
void GlobalSum(MPI_Comm comm, double *local, double *result, int count)