PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
pism::Grid Class Reference

Describes the PISM grid and the distribution of data across processors. More...

#include <Grid.hh>

Classes

struct  Impl
 Internal structures of Grid. More...
 

Public Member Functions

 ~Grid ()
 
 Grid (std::shared_ptr< const Context > context, const grid::Parameters &p)
 Create a PISM distributed computational grid. More...
 
std::shared_ptr< petsc::DMget_dm (unsigned int dm_dof, unsigned int stencil_width) const
 Get a PETSc DM ("distributed array manager") object for given dof (number of degrees of freedom per grid point) and stencil width. More...
 
void report_parameters () const
 Report grid parameters. More...
 
void compute_point_neighbors (double X, double Y, int &i_left, int &i_right, int &j_bottom, int &j_top) const
 Computes indices of grid points to the lower left and upper right from (X,Y). More...
 
std::vector< int > point_neighbors (double X, double Y) const
 
std::vector< double > interpolation_weights (double x, double y) const
 Compute 4 interpolation weights necessary for linear interpolation from the current grid. See compute_point_neighbors for the ordering of neighbors. More...
 
unsigned int kBelowHeight (double height) const
 Return the index k into zlevels[] so that zlevels[k] <= height < zlevels[k+1] and k < Mz. More...
 
int max_patch_size () const
 
std::shared_ptr< const Contextctx () const
 Return execution context this grid corresponds to. More...
 
int xs () const
 Global starting index of this processor's subset. More...
 
int xm () const
 Width of this processor's sub-domain. More...
 
int ys () const
 Global starting index of this processor's subset. More...
 
int ym () const
 Width of this processor's sub-domain. More...
 
const std::vector< double > & x () const
 X-coordinates. More...
 
double x (size_t i) const
 Get a particular x coordinate. More...
 
const std::vector< double > & y () const
 Y-coordinates. More...
 
double y (size_t i) const
 Get a particular y coordinate. More...
 
const std::vector< double > & z () const
 Z-coordinates within the ice. More...
 
double z (size_t i) const
 Get a particular z coordinate. More...
 
double dx () const
 Horizontal grid spacing. More...
 
double dy () const
 Horizontal grid spacing. More...
 
double cell_area () const
 
unsigned int Mx () const
 Total grid size in the X direction. More...
 
unsigned int My () const
 Total grid size in the Y direction. More...
 
unsigned int Mz () const
 Number of vertical levels. More...
 
double Lx () const
 Half-width of the computational domain. More...
 
double Ly () const
 Half-width of the computational domain. More...
 
double Lz () const
 Height of the computational domain. More...
 
double x0 () const
 X-coordinate of the center of the domain. More...
 
double y0 () const
 Y-coordinate of the center of the domain. More...
 
const MappingInfoget_mapping_info () const
 
void set_mapping_info (const MappingInfo &info)
 
double dz_min () const
 Minimum vertical spacing. More...
 
double dz_max () const
 Maximum vertical spacing. More...
 
grid::Periodicity periodicity () const
 Return grid periodicity. More...
 
grid::Registration registration () const
 
unsigned int size () const
 MPI communicator size. More...
 
int rank () const
 MPI rank. More...
 
Varsvariables ()
 Dictionary of variables (2D and 3D fields) associated with this grid. More...
 
const Varsvariables () const
 Dictionary of variables (2D and 3D fields) associated with this grid. More...
 
int pio_io_decomposition (int dof, int output_datatype) const
 
PointsWithGhosts points (unsigned int stencil_width=0) const
 

Static Public Member Functions

static std::shared_ptr< GridShallow (std::shared_ptr< const Context > ctx, double Lx, double Ly, double x0, double y0, unsigned int Mx, unsigned int My, grid::Registration r, grid::Periodicity p)
 Initialize a uniform, shallow (3 z-levels) grid with half-widths (Lx,Ly) and Mx by My nodes. More...
 
static std::shared_ptr< GridFromFile (std::shared_ptr< const Context > ctx, const std::string &filename, const std::vector< std::string > &var_names, grid::Registration r)
 Create a grid using one of variables in var_names in file. More...
 
static std::shared_ptr< GridFromOptions (std::shared_ptr< const Context > ctx)
 Create a grid using command-line options and (possibly) an input file. More...
 

Public Attributes

const MPI_Comm com
 

Private Member Functions

 Grid (const Grid &)
 
Gridoperator= (const Grid &)
 

Private Attributes

Implm_impl
 

Detailed Description

Describes the PISM grid and the distribution of data across processors.

This class holds parameters describing the grid, including the vertical spacing and which part of the horizontal grid is owned by the processor. It contains the dimensions of the PISM (4-dimensional, x*y*z*time) computational box. The vertical spacing can be quite arbitrary.

It creates and destroys a two dimensional PETSc DA (distributed array). The creation of this DA is the point at which PISM gets distributed across multiple processors.

Organization of PISM's computational grid

PISM uses the class Grid to manage computational grids and their parameters.

Computational grids PISM can use are

Each processor "owns" a rectangular patch of xm times ym grid points with indices starting at xs and ys in the X and Y directions respectively.

The typical code performing a point-wise computation will look like

for (Points p(grid); p; p.next()) {
const int i = p.i(), j = p.j();
field(i,j) = value;
}

For finite difference (and some other) computations we often need to know values at map-plane neighbors of a grid point.

We say that a patch owned by a processor is surrounded by a strip of "ghost" grid points belonging to patches next to the one in question. This lets us to access (read) values at all the eight neighbors of a grid point for all the grid points, including ones at an edge of a processor patch and at an edge of a computational domain.

All the values written to ghost points will be lost next time ghost values are updated.

Sometimes it is beneficial to update ghost values locally (for instance when a computation A uses finite differences to compute derivatives of a quantity produced using a purely local (point-wise) computation B). In this case the loop above can be modified to look like

for (PointsWithGhosts p(grid, ghost_width); p; p.next()) {
const int i = p.i(), j = p.j();
field(i,j) = value;
}

Definition at line 282 of file Grid.hh.


The documentation for this class was generated from the following files: