36#ifndef PRECICE_NO_PETSC
122 void init(PetscInt rows);
128 void setValue(PetscInt row, PetscScalar value);
130 void arange(
double start,
double stop);
186 void assemble(MatAssemblyType type = MAT_FINAL_ASSEMBLY);
194 void init(PetscInt localRows, PetscInt localCols, PetscInt globalRows, PetscInt globalCols,
195 MatType type =
nullptr,
bool doSetup =
true);
202 MatInfo
getInfo(MatInfoType flag)
const;
204 void setValue(PetscInt row, PetscInt col, PetscScalar value);
295void destroy(ISLocalToGlobalMapping *IS);
This class provides a lightweight logger.
A C++ 11 implementation of the non-owning C++20 std::span type.
Utility class for managing PETSc operations.
static bool weInitialized
Whether we have initialized Petsc or if it was initialized by an application calling us.
static void finalize()
Finalizes Petsc environment.
static void initialize(utils::Parallel::Communicator comm)
Initializes the Petsc environment.
static logging::Logger _log
SolverResult getSolverResult()
Returns the current convergence reason as a SolverRestult.
PetscReal getRealtiveTolerance()
Returns the relavtive tolerance of the KSP.
KSPSolver(KSPSolver &&other)=default
Move constructor, use the implicitly declared.
std::string summaryFor(Vector &b)
Returns a summary the KSP solving for b.
SolverResult solveTranspose(Vector &b, Vector &x)
Solves the transposed linear system, returns false it not converged.
void reset()
Destroys and recreates the ksp on the same communicator.
KSPSolver(const KSPSolver &)=delete
Delete copy and assignment constructor.
PetscReal getResidualNorm()
Returns the last residual norm of the KSP.
KSPSolver & operator=(const KSPSolver &)=delete
PetscInt getIterationNumber()
Returns the iteration number of solver, either during or after the solve call.
SolverResult solve(Vector &b, Vector &x)
Solves the linear system, returns false it not converged.
SolverResult
The state of the KSP after returning from solve()
@ Diverged
The solver diverged.
@ Stopped
The solver reached the maximum iterations.
@ Converged
The solver converged.
void setColumn(Vector &v, PetscInt col)
void read(const std::string &filename)
Reads the matrix from file, stored in PETSc binary format.
void write(const std::string &filename, VIEWERFORMAT format=ASCII) const
Writes the matrix to file.
void assemble(MatAssemblyType type=MAT_FINAL_ASSEMBLY)
void view() const
Prints the matrix.
std::pair< PetscInt, PetscInt > getSize() const
Returns (rows, cols) global size.
void setValue(PetscInt row, PetscInt col, PetscScalar value)
void viewDraw() const
Graphically draws the matrix structure.
void init(PetscInt localRows, PetscInt localCols, PetscInt globalRows, PetscInt globalCols, MatType type=nullptr, bool doSetup=true)
Initializes matrix of given size and type.
std::pair< PetscInt, PetscInt > ownerRange() const
Returns a pair that mark the beginning and end of the matrix' ownership range.
PetscInt blockSize() const
Returns the block size of the matrix.
void reset()
Destroys and recreates the matrix on the same communicator.
Matrix & operator=(const Matrix &)=delete
Matrix(const Matrix &)=delete
Delete copy and assignment constructor.
Matrix(Matrix &&)=default
Move constructor, use the implicitly declared.
Matrix & operator=(Matrix &&)=default
std::pair< PetscInt, PetscInt > getLocalSize() const
Returns (rows, cols) local size.
MatInfo getInfo(MatInfoType flag) const
Get the MatInfo struct for the matrix.
std::pair< PetscInt, PetscInt > ownerRangeColumn() const
Returns a pair that mark the beginning and end of the matrix' column ownership range.
Vector & copyTo(precice::span< double > destination)
double l2norm() const
returns the l2-norm of the vector
PetscInt getLocalSize() const
void arange(double start, double stop)
void read(const std::string &filename, VIEWERFORMAT format=ASCII)
Reads the vector from file.
void setValue(PetscInt row, PetscScalar value)
void sort()
Sorts the LOCAL partition of the vector.
static Vector allocate(const std::string &name="")
Allocates a new vector on the given MPI communicator.
Vector & copyFrom(precice::span< const double > source)
void view() const
Prints the vector.
std::pair< PetscInt, PetscInt > ownerRange() const
Returns a pair that mark the beginning and end of the vectors ownership range. Use first and second t...
void write(const std::string &filename, VIEWERFORMAT format=ASCII) const
Writes the vector to file.
static logging::Logger _log
void swap(Vector &other) noexcept
Swaps the ownership of two vectors.
Vector & operator=(const Vector &other)
Vector(const std::string &name="")
Creates a new vector on the given MPI communicator.
void init(PetscInt rows)
Sets the size and calls VecSetFromOptions.
void destroy(ISLocalToGlobalMapping *IS)
Destroys an ISLocalToGlobalMapping, if IS is not null and PetscIsInitialized.
void swap(Vector &lhs, Vector &rhs) noexcept
Main namespace of the precice library.