23 #include <gsl/gsl_interp.h>
25 #include "pism/util/pism_options.hh"
26 #include "pism/util/error_handling.hh"
27 #include "pism/util/Grid.hh"
28 #include "pism/util/io/File.hh"
29 #include "pism/util/Component.hh"
30 #include "pism/util/Context.hh"
35 const std::vector<double> &x,
36 double x_min,
double x_max) {
39 axis.c_str(), axis.c_str(), axis.c_str(),
43 if (x_min >= x.back()) {
45 axis.c_str(), axis.c_str(), axis.c_str(),
49 if (x_max <= x.front()) {
51 axis.c_str(), axis.c_str(), axis.c_str(),
57 const std::vector<double> &x,
58 double x_min,
double x_max,
59 double &x0,
double &Lx,
unsigned int &Mx) {
63 size_t x_start = gsl_interp_bsearch(x.data(), x_min, 0, x.size() - 1);
69 size_t x_end = gsl_interp_bsearch(x.data(), x_max, 0, x.size() - 1);
71 x_end =
std::min(x.size() - 1, x_end + 1);
74 Lx = (x[x_end] - x[x_start]) / 2.0;
76 x0 = (x[x_start] + x[x_end]) / 2.0;
78 assert(x_end + 1 >= x_start);
79 Mx = x_end + 1 - x_start;
90 "range of X coordinates in the selected subset", {});
92 "range of Y coordinates in the selected subset", {});
95 "Grid refinement factor (applies to the horizontal grid)", 1);
97 if (options.type ==
INIT_BOOTSTRAP and x_range.is_set() and y_range.is_set()) {
101 if (x_range->size() != 2) {
105 if (y_range->size() != 2) {
111 std::vector<std::string> names = {
"enthalpy",
"temp",
"land_ice_thickness",
112 "bedrock_altitude",
"thk",
"topg"};
113 bool grid_info_found =
false;
116 for (
const auto& name : names) {
119 if (not grid_info_found) {
125 if (grid_info_found) {
132 input_grid.
x0, input_grid.
Lx, input_grid.
Mx);
135 input_grid.
y0, input_grid.
Ly, input_grid.
My);
145 if (not grid_info_found) {
147 "no geometry information found in '%s'",
148 options.filename.c_str());
151 if (refinement_factor > 1) {
152 input_grid.
Mx = (input_grid.
Mx - 1) * refinement_factor + 1;
153 input_grid.
My = (input_grid.
My - 1) * refinement_factor + 1;
162 return std::make_shared<Grid>(ctx, input_grid);
165 if (x_range.is_set() ^ y_range.is_set()) {
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.
static std::shared_ptr< Grid > FromOptions(std::shared_ptr< const Context > ctx)
Create a grid using command-line options and (possibly) an input file.
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
void vertical_grid_from_options(std::shared_ptr< const Config > config)
Process -Mz and -Lz; set z;.
double y0
Domain center in the Y direction.
double x0
Domain center in the X direction.
void ownership_ranges_from_options(unsigned int size)
Re-compute ownership ranges. Uses current values of Mx and My.
Registration registration
Grid registration.
unsigned int Mx
Number of grid points in the X direction.
double Ly
Domain half-width in the Y direction.
double Lx
Domain half-width in the X direction.
unsigned int My
Number of grid points in the Y direction.
Grid parameters; used to collect defaults before an Grid is allocated.
#define PISM_ERROR_LOCATION
double min(const array::Scalar &input)
Finds minimum over all the values in an array::Scalar object. Ignores ghosts.
@ PISM_READONLY
open an existing file for reading only
std::shared_ptr< Grid > regional_grid_from_options(std::shared_ptr< Context > ctx)
Create a grid using command-line options and (possibly) an input file.
InputOptions process_input_options(MPI_Comm com, Config::ConstPtr config)
static void validate_range(const std::string &axis, const std::vector< double > &x, double x_min, double x_max)
static void subset_extent(const std::string &axis, const std::vector< double > &x, double x_min, double x_max, double &x0, double &Lx, unsigned int &Mx)