29 #include "pism/util/IceModelVec_impl.hh"
38 #include "pism/util/io/File.hh"
39 #include "pism/util/Logger.hh"
40 #include "pism/util/Context.hh"
41 #include "pism/util/VariableMetadata.hh"
51 :
IceModelVec(grid, name, ghostedp, 1, width, {0.0}) {
52 set_begin_access_use_dof(
false);
56 auto result = std::make_shared<IceModelVec2S>(source.
grid(),
60 result->metadata() = source.
metadata();
66 return static_cast<double**
>(
m_array);
70 return static_cast<double const* const*
>(
m_array);
86 const int i = p.i(), j = p.j();
98 const int i = p.i(), j = p.j();
100 result(i, j) = input(i, j).magnitude();
111 const int i = p.i(), j = p.j();
113 if (M(i, j) <= 0.0) {
124 return (array(i + 1,j) - array(i - 1,j)) / (2 * array.
grid()->dx());
130 return (array(i,j + 1) - array(i,j - 1)) / (2 * array.
grid()->dy());
137 const auto &grid = *array.
grid();
140 return diff_x(array, i,j);
144 return (array(i + 1,j) - array(i,j)) / (grid.dx());
145 }
else if (i == (
int)grid.Mx() - 1) {
146 return (array(i,j) - array(i - 1,j)) / (grid.dx());
148 return diff_x(array, i,j);
156 const auto &grid = *array.
grid();
159 return diff_y(array, i,j);
163 return (array(i,j + 1) - array(i,j)) / (grid.dy());
166 if (j == (
int)grid.My() - 1) {
167 return (array(i,j) - array(i,j - 1)) / (grid.dy());
170 return diff_y(array, i,j);
183 result += input(p.i(), p.j());
194 auto grid = input.
grid();
196 double result = input(grid->xs(), grid->ys());
198 result =
std::max(result, input(p.i(), p.j()));
211 result =
std::max(result, std::abs(input(p.i(), p.j())));
222 auto grid = input.
grid();
224 double result = input(grid->xs(), grid->ys());
226 result =
std::min(result, input(p.i(), p.j()));
248 unsigned int stencil_width)
249 :
IceModelVec3(grid, name, ghostedp, 2, stencil_width) {
255 double z[2] = {0.0, 0.0};
259 const int i = p.i(), j = p.j();
261 z[0] =
std::max(z[0], std::abs(input(i, j, 0)));
262 z[1] =
std::max(z[1], std::abs(input(i, j, 1)));
268 return {result[0], result[1]};
Makes sure that we call begin_access() and end_access() for all accessed IceModelVecs.
std::shared_ptr< const IceGrid > ConstPtr
IceModelVec2Int(IceGrid::ConstPtr grid, const std::string &name, IceModelVecKind ghostedp, int width=1)
void add(double alpha, const IceModelVec2S &x)
IceModelVec2S(IceGrid::ConstPtr grid, const std::string &name, IceModelVecKind ghostedp, int width=1)
void copy_from(const IceModelVec2S &source)
IceModelVec2Stag(IceGrid::ConstPtr grid, const std::string &name, IceModelVecKind ghostedp, unsigned int stencil_width=1)
A class for storing and accessing internal staggered-grid 2D fields. Uses dof=2 storage....
A virtual class collecting methods common to ice and bedrock 3D fields.
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
IceGrid::ConstPtr grid() const
void set_begin_access_use_dof(bool flag)
const std::string & get_name() const
Get the name of an IceModelVec object.
void inc_state_counter()
Increment the object state counter.
Abstract class for reading, writing, allocating, and accessing a DA-based PETSc Vec (2D and 3D fields...
double magnitude() const
Magnitude.
This class represents a 2D vector field (such as ice velocity) at a certain grid point.
void add(const V &x, double alpha, const V &y, V &result, bool scatter=true)
Computes result = x + alpha * y, where x, y, and z are 2D IceModelVecs (scalar or vector).
void copy(const V &source, V &destination, bool scatter=true)
void apply_mask(const IceModelVec2S &M, double fill, IceModelVec2S &result)
Masks out all the areas where by setting them to fill.
double diff_x(const IceModelVec2S &array, int i, int j)
Returns the x-derivative at i,j approximated using centered finite differences.
double max(const IceModelVec2S &input)
Finds maximum over all the values in an IceModelVec2S object. Ignores ghosts.
void compute_magnitude(const IceModelVec2S &v_x, const IceModelVec2S &v_y, IceModelVec2S &result)
Sets an IceModelVec2 to the magnitude of a 2D vector field with components v_x and v_y.
double diff_x_p(const IceModelVec2S &array, int i, int j)
Returns the x-derivative at i,j approximated using centered finite differences. Respects grid periodi...
void GlobalMax(MPI_Comm comm, double *local, double *result, int count)
double absmax(const IceModelVec2S &input)
Finds maximum over all the absolute values in an IceModelVec2S object. Ignores ghosts.
std::shared_ptr< IceModelVec2S > duplicate(const IceModelVec2S &source)
double min(const IceModelVec2S &input)
Finds minimum over all the values in an IceModelVec2S object. Ignores ghosts.
void GlobalMin(MPI_Comm comm, double *local, double *result, int count)
double diff_y_p(const IceModelVec2S &array, int i, int j)
Returns the y-derivative at i,j approximated using centered finite differences. Respects grid periodi...
void GlobalSum(MPI_Comm comm, double *local, double *result, int count)
double diff_y(const IceModelVec2S &array, int i, int j)
Returns the y-derivative at i,j approximated using centered finite differences.
IceModelVecKind
What "kind" of a vector to create: with or without ghosts.
double sum(const IceModelVec2S &input)
Sums up all the values in an IceModelVec2S object. Ignores ghosts.
InterpolationType interpolation_type