| 297 | /////////////////////////////// PRIVATE ////////////////////////////////////// |
| 298 | |
| 299 | void |
| 300 | SCPoissonHypreLevelSolver::allocateHypreData() |
| 301 | { |
| 302 | // Get the MPI communicator. |
| 303 | MPI_Comm communicator = IBTK_MPI::getCommunicator(); |
| 304 | |
| 305 | // Setup the hypre grid and variables and assemble the grid. |
| 306 | Pointer<CartesianGridGeometry<NDIM>> grid_geometry = d_hierarchy->getGridGeometry(); |
| 307 | const IntVector<NDIM>& ratio = d_level->getRatio(); |
| 308 | const IntVector<NDIM>& periodic_shift = grid_geometry->getPeriodicShift(ratio); |
| 309 | |
| 310 | HYPRE_SStructGridCreate(communicator, NDIM, NPARTS, &d_grid); |
| 311 | for (PatchLevel<NDIM>::Iterator p(d_level); p; p++) |
| 312 | { |
| 313 | const Box<NDIM>& patch_box = d_level->getPatch(p())->getBox(); |
| 314 | auto lower = hypre_array(patch_box.lower()); |
| 315 | auto upper = hypre_array(patch_box.upper()); |
| 316 | HYPRE_SStructGridSetExtents(d_grid, PART, lower.data(), upper.data()); |
| 317 | } |
| 318 | |
| 319 | std::array<HYPRE_Int, 3> hypre_periodic_shift; |
| 320 | for (unsigned int d = 0; d < NDIM; ++d) |
| 321 | { |
| 322 | hypre_periodic_shift[d] = periodic_shift(d); |
| 323 | } |
| 324 | for (int d = NDIM; d < 3; ++d) |
| 325 | { |
| 326 | hypre_periodic_shift[d] = 0; |
| 327 | } |
| 328 | HYPRE_SStructGridSetPeriodic(d_grid, PART, hypre_periodic_shift.data()); |
| 329 | |
| 330 | #if (NDIM == 2) |
| 331 | HYPRE_SStructVariable vartypes[NVARS] = { HYPRE_SSTRUCT_VARIABLE_XFACE, HYPRE_SSTRUCT_VARIABLE_YFACE }; |
| 332 | #endif |
| 333 | #if (NDIM == 3) |
| 334 | HYPRE_SStructVariable vartypes[NVARS] = { HYPRE_SSTRUCT_VARIABLE_XFACE, |
| 335 | HYPRE_SSTRUCT_VARIABLE_YFACE, |
| 336 | HYPRE_SSTRUCT_VARIABLE_ZFACE }; |
| 337 | #endif |
| 338 | HYPRE_SStructGridSetVariables(d_grid, PART, NVARS, vartypes); |
| 339 | |
| 340 | HYPRE_SStructGridAssemble(d_grid); |
| 341 | |
| 342 | // Allocate stencil data and set stencil offsets. |
| 343 | static const int stencil_sz = 2 * NDIM + 1; |
| 344 | d_stencil_offsets.resize(stencil_sz); |
| 345 | std::fill(d_stencil_offsets.begin(), d_stencil_offsets.end(), hier::Index<NDIM>(0)); |
| 346 | for (unsigned int axis = 0, stencil_index = 1; axis < NDIM; ++axis) |
| 347 | { |
| 348 | for (int side = 0; side <= 1; ++side, ++stencil_index) |
| 349 | { |
| 350 | d_stencil_offsets[stencil_index](axis) = (side == 0 ? -1 : +1); |
| 351 | } |
| 352 | } |
| 353 | for (int var = 0; var < NVARS; ++var) |
| 354 | { |
| 355 | HYPRE_SStructStencilCreate(NDIM, stencil_sz, &d_stencil[var]); |
| 356 | for (int s = 0; s < stencil_sz; ++s) |