20 #include "pism/stressbalance/blatter/util/grid_hierarchy.hh"
32 double grid_z(
double b,
double H,
int Mz,
int k) {
33 return b + H *
k / (Mz - 1.0);
59 DMDALocalInfo result = input;
73 result.gxs = input.gys;
74 result.gys = input.gzs;
75 result.gzs = input.gxs;
77 result.gxm = input.gym;
78 result.gym = input.gzm;
79 result.gzm = input.gxm;
100 #if PETSC_VERSION_LT(3,10,0)
101 ierr = DMDAGetReducedDMDA(dm, dof, &da); CHKERRQ(ierr);
103 ierr = DMDACreateCompatibleDMDA(dm, dof, &da); CHKERRQ(ierr);
106 ierr = DMSetUp(da); CHKERRQ(ierr);
108 ierr = DMCreateGlobalVector(da, ¶meters); CHKERRQ(ierr);
110 ierr = PetscObjectCompose((PetscObject)dm,
"3D_DM", (PetscObject)da); CHKERRQ(ierr);
111 ierr = PetscObjectCompose((PetscObject)dm,
"3D_DM_data", (PetscObject)parameters); CHKERRQ(ierr);
113 ierr = DMDestroy(&da); CHKERRQ(ierr);
115 ierr = VecDestroy(¶meters); CHKERRQ(ierr);
120 ierr = DMGetCoarsenLevel(dm, &level); CHKERRQ(ierr);
125 ierr = PetscObjectGetComm((PetscObject)dm, &comm); CHKERRQ(ierr);
128 ierr = DMDAGetLocalInfo(dm, &info); CHKERRQ(ierr);
135 ierr = PetscPrintf(comm,
136 "Blatter grid level %d: %3d x %3d x %3d (%8d) nodes\n",
137 (mg_levels - 1) -
static_cast<int>(level),
138 Mx, My, Mz, Mx * My * Mz); CHKERRQ(ierr);
154 DM da_fine, da_coarse;
160 mat_name = prefix +
"_restriction",
161 vec_name = prefix +
"_scaling";
164 ierr = PetscObjectQuery((PetscObject)fine, dm_name, (PetscObject *)&da_fine); CHKERRQ(ierr);
166 #if PETSC_VERSION_LT(3,17,0)
167 SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"No %s composed with given DMDA", dm_name);
169 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"No %s composed with given DMDA", dm_name);
174 ierr = PetscObjectQuery((PetscObject)coarse, dm_name, (PetscObject *)&da_coarse); CHKERRQ(ierr);
176 #if PETSC_VERSION_LT(3,17,0)
177 SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"No %s composed with given DMDA", dm_name);
179 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"No %s composed with given DMDA", dm_name);
184 ierr = DMCreateInterpolation(da_coarse, da_fine, &mat, &scale); CHKERRQ(ierr);
187 ierr = PetscObjectCompose((PetscObject)fine, vec_name.c_str(), (PetscObject)scale); CHKERRQ(ierr);
188 ierr = VecDestroy(&scale); CHKERRQ(ierr);
190 ierr = PetscObjectCompose((PetscObject)fine, mat_name.c_str(), (PetscObject)mat); CHKERRQ(ierr);
191 ierr = MatDestroy(&mat); CHKERRQ(ierr);
203 Vec X_fine, X_coarse, scaling;
204 DM da_fine, da_coarse;
209 mat_name = prefix +
"_restriction",
210 scaling_name = prefix +
"_scaling",
211 vec_name = prefix +
"_data";
214 ierr = PetscObjectQuery((PetscObject)fine, mat_name.c_str(), (PetscObject *)&mat); CHKERRQ(ierr);
216 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Failed to get the restriction matrix");
220 ierr = PetscObjectQuery((PetscObject)fine, scaling_name.c_str(), (PetscObject *)&scaling); CHKERRQ(ierr);
222 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Failed to get the scaling vector");
226 ierr = PetscObjectQuery((PetscObject)fine, dm_name, (PetscObject *)&da_fine); CHKERRQ(ierr);
228 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Failed to get the fine grid DM");
232 ierr = PetscObjectQuery((PetscObject)fine, vec_name.c_str(), (PetscObject *)&X_fine); CHKERRQ(ierr);
234 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Failed to get the fine grid Vec");
238 ierr = PetscObjectQuery((PetscObject)coarse, dm_name, (PetscObject *)&da_coarse); CHKERRQ(ierr);
240 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Failed to get the coarse grid DM");
244 ierr = PetscObjectQuery((PetscObject)coarse, vec_name.c_str(), (PetscObject *)&X_coarse); CHKERRQ(ierr);
246 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Failed to get the coarse grid Vec");
249 ierr = MatRestrict(mat, X_fine, X_coarse); CHKERRQ(ierr);
251 ierr = VecPointwiseMult(X_coarse, X_coarse, scaling); CHKERRQ(ierr);
double grid_z(double b, double H, int Mz, int k)
PetscErrorCode setup_level(DM dm, int mg_levels)
DMDALocalInfo grid_transpose(const DMDALocalInfo &input)
PetscErrorCode restrict_data(DM fine, DM coarse, const char *dm_name)
Restrict model parameters from the fine grid onto the coarse grid.
PetscErrorCode create_restriction(DM fine, DM coarse, const char *dm_name)
Create the restriction matrix.