20 #ifndef PISM_DATAACCESS_H
21 #define PISM_DATAACCESS_H
24 #include <petscdmda.h>
26 #include "pism/util/error_handling.hh"
47 assert(dim == 2 or dim == 3);
50 ierr =
setup(da,
"2D_DM",
"2D_DM_data");
52 ierr =
setup(da,
"3D_DM",
"3D_DM_data");
57 "Failed to create an DataAccess instance");
61 int setup(DM da,
const char *dm_name,
const char *vec_name) {
64 m_com = MPI_COMM_SELF;
65 ierr = PetscObjectGetComm((PetscObject)da, &
m_com); CHKERRQ(ierr);
67 ierr = PetscObjectQuery((PetscObject)da, dm_name, (PetscObject*)&
m_da); CHKERRQ(ierr);
70 SETERRQ(
m_com, 1,
"Failed to get the inner DM");
74 ierr = PetscObjectQuery((PetscObject)da, vec_name, (PetscObject*)&X); CHKERRQ(ierr);
77 SETERRQ(
m_com, 1,
"Failed to get the inner Vec");
81 ierr = DMGetLocalVector(
m_da, &
m_x); CHKERRQ(ierr);
83 ierr = DMGlobalToLocalBegin(
m_da, X, INSERT_VALUES,
m_x); CHKERRQ(ierr);
85 ierr = DMGlobalToLocalEnd(
m_da, X, INSERT_VALUES,
m_x); CHKERRQ(ierr);
90 ierr = DMDAVecGetArray(
m_da,
m_x, &
m_a); CHKERRQ(ierr);
97 PetscErrorCode ierr = DMDAVecRestoreArray(
m_da,
m_x, &
m_a);
98 PISM_CHK(ierr,
"DMDAVecRestoreArray");
101 ierr = DMRestoreLocalVector(
m_da, &
m_x);
102 PISM_CHK(ierr,
"DMRestoreLocalVector");
int setup(DM da, const char *dm_name, const char *vec_name)
DataAccess(DM da, int dim, AccessType type)
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
#define PISM_CHK(errcode, name)
#define PISM_ERROR_LOCATION
void handle_fatal_errors(MPI_Comm com)