Go to the documentation of this file.
21 #ifndef THUNDEREGG_PETSC_MATWRAPPER_H
22 #define THUNDEREGG_PETSC_MATWRAPPER_H
50 Vec getPetscVecWithoutGhost(
const Vector<D>& vec)
const
65 void copyToPetscVec(
const Vector<D>& vec, Vec petsc_vec)
const
67 double* petsc_vec_view;
68 size_t curr_index = 0;
69 VecGetArray(petsc_vec, &petsc_vec_view);
71 for (
int c = 0; c < vec.getNumComponents(); c++) {
73 Loop::Nested<D>(ld.
getStart(), ld.
getEnd(), [&](
const std::array<int, D>& coord) {
74 petsc_vec_view[curr_index] = ld[coord];
79 VecRestoreArray(petsc_vec, &petsc_vec_view);
87 void copyToVec(Vec petsc_vec,
Vector<D>& vec)
const
89 const double* petsc_vec_view;
90 size_t curr_index = 0;
91 VecGetArrayRead(petsc_vec, &petsc_vec_view);
93 for (
int c = 0; c < vec.getNumComponents(); c++) {
95 Loop::Nested<D>(ld.
getStart(), ld.
getEnd(), [&](
const std::array<int, D>& coord) {
96 ld[coord] = petsc_vec_view[curr_index];
101 VecRestoreArrayRead(petsc_vec, &petsc_vec_view);
109 void destroyPetscVec(
const Vector<D>& vec, Vec petsc_vec)
const { VecDestroy(&petsc_vec); }
131 Vec petsc_x = getPetscVecWithoutGhost(x);
132 copyToPetscVec(x, petsc_x);
134 Vec petsc_b = getPetscVecWithoutGhost(b);
136 MatMult(A, petsc_x, petsc_b);
138 copyToVec(petsc_b, b);
140 destroyPetscVec(x, petsc_x);
141 destroyPetscVec(b, petsc_b);
ComponentView< double, D > getComponentView(int component_index, int patch_local_index)
Get the ComponentView for the specified patch and component.
Definition: Vector.h:336
void apply(const Vector< D > &x, Vector< D > &b) const override
Virtual function that base classes have to implement.
Definition: MatWrapper.h:129
A collection of wrappers for operating with PETSc.
Definition: KSPSolver.h:35
const Communicator & getCommunicator() const
get the MPI Comm that this vector uses
Definition: Vector.h:311
Array for acessing data of a patch. It supports variable striding.
Definition: ComponentView.h:38
int getNumLocalCells() const
Get the number of local cells int he vector (excluding ghost cells)
Definition: Vector.h:322
const std::array< int, D > & getEnd() const
Get the coordinate of the last element.
Definition: View.h:211
Wraps a PETSc Mat object for use as an Operator.
Definition: MatWrapper.h:37
MatWrapper< D > * clone() const override
Clone this wrapper.
Definition: MatWrapper.h:128
MatWrapper(Mat A_in)
Construct a new MatWrapper object.
Definition: MatWrapper.h:119
Base class for operators.
Definition: Operator.h:37
Vector class for use in thunderegg.
Definition: Vector.h:42
int getNumLocalPatches() const
Get the number of local patches.
Definition: Vector.h:316
const std::array< int, D > & getStart() const
Get the coordinate of the first element.
Definition: View.h:207