25#include "pism/util/array/Array3D.hh"
27#include "pism/util/Config.hh"
28#include "pism/util/Context.hh"
29#include "pism/util/Grid.hh"
30#include "pism/util/VariableMetadata.hh"
31#include "pism/util/array/Array_impl.hh"
32#include "pism/util/array/Scalar.hh"
33#include "pism/util/error_handling.hh"
34#include "pism/util/io/IO_Flags.hh"
35#include "pism/util/io/io_helpers.hh"
36#include "pism/util/InputInterpolation.hh"
44 const std::vector<double> &levels,
unsigned int stencil_width)
45 :
Array(grid, name, ghostedp, 1, stencil_width, levels) {
51 "pism::array::Array3D '%s' has to have at least one \"vertical\" level", name.c_str());
63 double ***arr = (
double ***)
m_array;
66 ierr = PetscMemzero(arr[j][i],
levels().
size() *
sizeof(
double));
69 unsigned int nlevels =
levels().size();
70 for (
unsigned int k = 0;
k < nlevels;
k++) {
80 double ***arr = (
double ***)
m_array;
81 PetscErrorCode ierr = PetscMemcpy(arr[j][i], input,
levels().
size() *
sizeof(
double));
86static bool legal_level(
const std::vector<double> &levels,
double z) {
87 double z_min = levels.front();
88 double z_max = levels.back();
89 const double eps = 1.0e-6;
90 return not(z < z_min - eps || z > z_max + eps);
103 if (not legal_level(zs, z)) {
105 "Array3D interpolate(): level %f is not legal; name = %s", z,
112 if (z >= zs[N - 1]) {
113 return column[N - 1];
122 const double incr = (z - zs[mcurr]) / (zs[mcurr + 1] - zs[mcurr]);
123 const double valm = column[mcurr];
124 return valm + incr * (column[mcurr + 1] - valm);
131 return ((
double ***)
m_array)[j][i];
138 return ((
double ***)
m_array)[j][i];
147 for (
auto p : output.
grid()->points()) {
148 const int i = p.i(), j = p.j();
165 for (
auto p : output.
grid()->points()) {
166 const int i = p.i(), j = p.j();
198 const unsigned int Mz = data.
grid()->Mz();
202 for (
auto p : data.
grid()->points()) {
203 const int i = p.i(), j = p.j();
207 double scalar_sum = 0.0;
208 for (
unsigned int k = 0;
k < Mz; ++
k) {
209 scalar_sum += column[
k];
211 output(i, j) = A * output(i, j) + B * scalar_sum;
228 const int i = p.i(), j = p.j();
230#if PETSC_VERSION_LT(3, 12, 0)
252 result->metadata() = this->
metadata();
259 auto log =
grid()->ctx()->log();
263 auto V = file.
find_variable(variable.get_name(), variable[
"standard_name"]);
270 int last_record = -1;
271 interp->regrid(variable, file, last_record, *
grid(), tmp);
279 PetscErrorCode ierr = VecCopy(tmp,
vec());
VariableLookupData find_variable(const std::string &short_name, const std::string &std_name) const
Find a variable using its standard name and/or short name.
High-level PISM I/O class.
void failed()
Indicates a failure of a parallel section.
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
void copy_from(const Array3D &input)
double interpolate(int i, int j, double z) const
Return value of scalar quantity at level z (m) above base of ice (by linear interpolation).
void set_column(int i, int j, double c)
Set all values of scalar quantity to given a single value in a particular column.
void regrid_impl(const File &file, io::Default default_value)
Gets an Array from a file file, interpolating onto the current grid.
Array3D(std::shared_ptr< const Grid > grid, const std::string &name, Kind ghostedp, const std::vector< double > &levels, unsigned int stencil_width=1)
std::shared_ptr< Array3D > duplicate(Kind ghostedp=WITHOUT_GHOSTS) const
double * get_column(int i, int j)
A virtual class collecting methods common to ice and bedrock 3D fields.
unsigned int ndof() const
Returns the number of degrees of freedom per grid point.
const std::vector< double > & levels() const
size_t size() const
Return the total number of elements in the owned part of an array.
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.
std::shared_ptr< petsc::DM > dm() const
void set_begin_access_use_dof(bool flag)
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.
void check_array_indices(int i, int j, unsigned int k) const
Check array indices and warn if they are out of range.
Abstract class for reading, writing, allocating, and accessing a DA-based PETSc Vec (2D and 3D fields...
#define PISM_CHK(errcode, name)
#define PISM_ERROR_LOCATION
void extract_surface(const Array3D &data, double z, Scalar &output)
Copies a horizontal slice at level z of an Array3D into output.
void sum_columns(const Array3D &data, double A, double B, Scalar &output)
void global_to_local(petsc::DM &dm, Vec source, Vec destination)
void set_default_value_or_stop(const VariableMetadata &variable, io::Default default_value, const Logger &log, Vec output)
Kind
What "kind" of a vector to create: with or without ghosts.
bool ghosted
true if this Array is ghosted
std::shared_ptr< const Grid > grid
The computational grid.
InterpolationType interpolation_type
gsl_interp_accel * bsearch_accel