21 #ifndef THUNDEREGG_PETSC_PCSHELLCREATOR_H
22 #define THUNDEREGG_PETSC_PCSHELLCREATOR_H
43 std::shared_ptr<const Operator<D>> op;
48 std::function<Vector<D>()> getNewVector;
59 , getNewVector(vector_allocator)
77 static int applyPC(PC A, Vec x, Vec b)
80 PCShellGetContext(A, (
void**)&psc);
87 VecGetArrayRead(x, &x_view);
90 for (
int c = 0; c < te_x.getNumComponents(); c++) {
92 Loop::Nested<D>(ld.
getStart(), ld.
getEnd(), [&](
const std::array<int, D>& coord) {
93 ld[coord] = x_view[index];
99 VecRestoreArrayRead(x, &x_view);
101 psc->op->apply(te_x, te_b);
104 VecGetArray(b, &b_view);
107 for (
int c = 0; c < te_x.getNumComponents(); c++) {
109 Loop::Nested<D>(ld.
getStart(), ld.
getEnd(), [&](
const std::array<int, D>& coord) {
110 b_view[index] = ld[coord];
115 VecRestoreArray(b, &b_view);
125 static int destroyPC(PC A)
128 PCShellGetContext(A, (
void**)&psc);
144 const std::function<
Vector<D>()>& vector_allocator)
149 PCCreate(MPI_COMM_WORLD, &P);
150 PCSetType(P, PCSHELL);
151 PCShellSetContext(P, psc);
152 PCShellSetApply(P, applyPC);
153 PCShellSetDestroy(P, destroyPC);
154 PCSetOperators(P, A, A);