38 #include "PetscVecTools.hpp"
39 #include "PCBlockDiagonal.hpp"
41 #include "Warnings.hpp"
60 PCBlockDiagonal::~PCBlockDiagonal()
65 std::cout <<
" -- Block diagonal preconditioner profile information: " << std::endl;
66 std::cout <<
"\t mScatterTime: " <<
mPCContext.mScatterTime << std::endl;
67 std::cout <<
"\t mA1PreconditionerTime: " <<
mPCContext.mA1PreconditionerTime << std::endl;
68 std::cout <<
"\t mA2PreconditionerTime: " <<
mPCContext.mA2PreconditionerTime << std::endl;
69 std::cout <<
"\t mGatherTime: " <<
mPCContext.mGatherTime << std::endl;
93 Mat system_matrix, dummy;
94 #if (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>=5)
95 KSPGetOperators(rKspObject, &system_matrix, &dummy);
98 KSPGetOperators(rKspObject, &system_matrix, &dummy, &flag);
102 MatGetSize(system_matrix, &num_rows, &num_columns);
103 assert(num_rows==num_columns);
105 PetscInt num_local_rows, num_local_columns;
106 MatGetLocalSize(system_matrix, &num_local_rows, &num_local_columns);
110 if ((num_rows%2 != 0) || (num_local_rows%2 != 0))
112 TERMINATE(
"Wrong matrix parallel layout detected in PCBlockDiagonal.");
116 unsigned subvector_num_rows = num_rows/2;
117 unsigned subvector_local_rows = num_local_rows/2;
139 assert(global_size == num_rows/2);
143 ISCreateStride(PETSC_COMM_WORLD, high-low, 2*low, 2, &A11_local_rows);
144 ISCreateStride(PETSC_COMM_WORLD, global_size, 0, 2, &A11_columns);
146 #if (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 8) //PETSc 3.8 or later
147 MatCreateSubMatrix(system_matrix, A11_local_rows, A11_local_rows,
150 MatGetSubMatrix(system_matrix, A11_local_rows, A11_local_rows,
165 assert(global_size == num_rows/2);
169 ISCreateStride(PETSC_COMM_WORLD, high-low, 2*low+1, 2, &A22_local_rows);
170 ISCreateStride(PETSC_COMM_WORLD, global_size, 1, 2, &A22_columns);
172 #if (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 8) //PETSc 3.8 or later
173 MatCreateSubMatrix(system_matrix, A22_local_rows, A22_local_rows,
176 MatGetSubMatrix(system_matrix, A22_local_rows, A22_local_rows,
186 #if (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 2) //PETSc 2.2
212 PetscPushErrorHandler(PetscIgnoreErrorHandler,
nullptr);
214 if (pc_set_error != 0)
216 WARNING(
"PETSc hypre preconditioning library is not installed");
219 PetscPopErrorHandler();
221 #if (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR<=5)
232 #if (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>=5)
246 PetscPushErrorHandler(PetscIgnoreErrorHandler,
nullptr);
249 PetscPopErrorHandler();
292 #if (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>=5)
303 #if (PETSC_VERSION_MAJOR == 3 && PETSC_VERSION_MINOR >= 1) //PETSc 3.1 or later
304 PetscErrorCode PCBlockDiagonalApply(PC pc_object,
Vec x,
Vec y)
308 PCShellGetContext(pc_object, &pc_context);
310 PetscErrorCode PCBlockDiagonalApply(
void* pc_context,
Vec x,
Vec y)
316 assert(block_diag_context!=
nullptr);
void PCBlockDiagonalCreate(KSP &rKspObject)
#define TERMINATE(message)
static double GetElapsedTime()
PCBlockDiagonalContext mPCContext
VecScatter A11_scatter_ctx
PCBlockDiagonal(KSP &rKspObject)
VecScatter A22_scatter_ctx
void PCBlockDiagonalSetUp()