30#if defined(MFEM_USE_DOUBLE) && !defined(PETSC_USE_REAL_DOUBLE)
31#error "Mismatch between MFEM and PETSc real types"
33#if defined(MFEM_USE_SINGLE) && !defined(PETSC_USE_REAL_SINGLE)
34#error "Mismatch between MFEM and PETSc real types"
36#if defined(PETSC_USE_COMPLEX)
37#error "MFEM does not work with PETSc compiled with complex numbers support"
39#if defined(PETSC_USE_64BIT_INDICES) && !defined(HYPRE_BIGINT)
40#error "Mismatch between HYPRE (32bit) and PETSc (64bit) integer types"
42#if !defined(PETSC_USE_64BIT_INDICES) && defined(HYPRE_BIGINT)
43#error "Mismatch between HYPRE (64bit) and PETSc (32bit) integer types"
46#include "petscversion.h"
47#if PETSC_VERSION_GE(3,12,0)
48#include "petscsystypes.h"
72typedef struct ::_p_Vec *
Vec;
73typedef struct ::_p_Mat *
Mat;
74typedef struct ::_p_KSP *
KSP;
75typedef struct ::_p_PC *
PC;
76typedef struct ::_p_SNES *
SNES;
77typedef struct ::_p_TS *
TS;
103 int size_,
bool usedev_)
113 bool read_,
bool write_,
bool usedev_)
153class ParFiniteElementSpace;
208 bool transpose =
false,
bool allocate =
true);
214 bool allocate =
true);
304 void Print(
const char *fname = NULL,
bool binary =
false)
const;
352 void BlockDiagonalConstructor(MPI_Comm comm,
PetscInt *row_starts,
356 void SetUpForDevice();
448 {
Mult(1.0, x, 0.0, y); }
454 const real_t a = 1.0)
const override
455 {
Mult(
a, x, 1.0, y); }
458 const real_t a = 1.0)
const override
513 void Print(
const char *fname = NULL,
bool binary =
false)
const;
567PetscParMatrix *
ParMult(
const PetscParMatrix *A,
const PetscParMatrix *B);
570PetscParMatrix *
RAP(PetscParMatrix *Rt, PetscParMatrix *A, PetscParMatrix *P);
577PetscParMatrix *
RAP(PetscParMatrix *A, PetscParMatrix *P);
580PetscParMatrix *
RAP(HypreParMatrix *A, PetscParMatrix *P);
587void EliminateBC(PetscParMatrix &A, PetscParMatrix &Ae,
588 const Array<int> &ess_dof_list,
const Vector &X, Vector &B);
602 bctype(type_), setup(false), eval_t(0.0),
603 eval_t_cached(std::numeric_limits<
real_t>::min()) {}
618 {
mfem_error(
"PetscBCHandler::Eval method not overloaded"); }
666 const char*
GetName() {
return name.c_str(); }
672class PetscSolverMonitor;
720 void Customize(
bool customize =
true)
const;
758 bool wrap =
true,
bool iter_mode =
false);
760 const std::string &prefix = std::string(),
bool iter_mode =
false);
767 const std::string &prefix = std::string(),
bool iter_mode =
false);
794 PetscPCGSolver(MPI_Comm comm,
const std::string &prefix = std::string(),
795 bool iter_mode =
false);
797 bool iter_mode =
false);
799 const std::string &prefix = std::string(),
bool iter_mode =
false);
811 const std::string &prefix = std::string());
813 const std::string &prefix = std::string());
815 const std::string &prefix = std::string());
879 const std::string &prefix = std::string());
882 const std::string &prefix = std::string());
890 const std::string &prefix = std::string());
901 const std::string &prefix = std::string());
910 const std::string &prefix = std::string());
912 const std::string &prefix = std::string());
933 Vector &W,
bool &changed_y,
bool &changed_w));
960 PetscODESolver(MPI_Comm comm,
const std::string &prefix = std::string());
996 MFEM_ABORT(
"MonitorSolution() is not implemented!")
1002 MFEM_ABORT(
"MonitorResidual() is not implemented!")
Wrapper for hypre's ParCSR matrix class.
Wrapper for hypre's parallel vector class.
Class used by MFEM to store pointers to host and/or device memory.
void MakeAlias(const Memory &base, int offset, int size)
void Sync(const Memory &other) const
Copy the host/device pointer validity flags from other to *this.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
Pointer to an Operator of a specified type.
Type
Enumeration defining IDs for some classes derived from Operator.
@ PETSC_MATAIJ
ID for class PetscParMatrix, MATAIJ format.
@ PETSC_MATSHELL
ID for class PetscParMatrix, MATSHELL format.
Abstract parallel finite element space.
Helper class for handling essential boundary conditions.
PetscBCHandler(Type type_=ZERO)
@ CONSTANT
Constant in time b.c.
void SetTDofs(Array< int > &list)
Sets essential dofs (local, per-process numbering)
Type GetType() const
Returns the type of boundary conditions.
virtual ~PetscBCHandler()
virtual void Eval(real_t t, Vector &g)
Boundary conditions evaluation.
void SetTime(real_t t)
Sets the current time.
void SetUp(PetscInt n)
SetUp the helper object, where n is the size of the solution vector.
void ZeroBC(const Vector &x, Vector &y)
y = x on ess_tdof_list_c and y = 0 on ess_tdof_list
Array< int > & GetTDofs()
Gets essential dofs (local, per-process numbering)
void FixResidualBC(const Vector &x, Vector &y)
y = x-g on ess_tdof_list, the rest of y is unchanged
void ApplyBC(const Vector &x, Vector &y)
y = x on ess_tdof_list_c and y = g (internally evaluated) on ess_tdof_list
void SetType(enum Type type_)
Sets the type of boundary conditions.
void Zero(Vector &x)
Replace boundary dofs with 0.
Auxiliary class for BDDC customization.
const Array< int > * nat_dof
void SetEssBdrDofs(const Array< int > *essdofs, bool loc=false)
Specify dofs on the essential boundary.
void SetSpace(ParFiniteElementSpace *fe)
void SetComputeNetFlux(bool net=true)
Setup BDDC with no-net-flux local solvers. Needs a ParFiniteElementSpace attached.
ParFiniteElementSpace * fespace
void SetNatBdrDofs(const Array< int > *natdofs, bool loc=false)
Specify dofs on the natural boundary.
const Array< int > * ess_dof
PetscBDDCSolver(MPI_Comm comm, Operator &op, const PetscBDDCSolverParams &opts=PetscBDDCSolverParams(), const std::string &prefix=std::string())
PetscFieldSplitSolver(MPI_Comm comm, Operator &op, const std::string &prefix=std::string())
PetscH2Solver(Operator &op, ParFiniteElementSpace *fes, const std::string &prefix=std::string())
Abstract class for PETSc's linear solvers.
virtual void MultTranspose(const Vector &b, Vector &x) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
virtual ~PetscLinearSolver()
virtual void SetOperator(const Operator &op)
PetscLinearSolver(MPI_Comm comm, const std::string &prefix=std::string(), bool wrap=true, bool iter_mode=false)
void SetPreconditioner(Solver &precond)
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Wrapper for syncing PETSc's vector memory.
bool DeviceRequested() const
void SetHostInvalid() const
void SetHostValid() const
bool WriteRequested() const
const real_t * GetDevicePointer() const
const real_t * GetHostPointer() const
void MakeAliasForSync(Memory< real_t > &base_, int offset_, int size_, bool read_, bool write_, bool usedev_)
bool IsAliasForSync() const
void MakeAliasForSync(const Memory< real_t > &base_, int offset_, int size_, bool usedev_)
void SetDeviceInvalid() const
bool ReadRequested() const
void SetDeviceValid() const
Abstract class for PETSc's nonlinear solvers.
void SetPostCheck(void(*post)(Operator *op, const Vector &X, Vector &Y, Vector &W, bool &changed_y, bool &changed_w))
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
void SetObjective(void(*obj)(Operator *op, const Vector &x, real_t *f))
Specification of an objective function to be used for line search.
virtual ~PetscNonlinearSolver()
void SetJacobianType(Operator::Type type)
void SetUpdate(void(*update)(Operator *op, int it, const Vector &F, const Vector &X, const Vector &D, const Vector &P))
virtual void SetOperator(const Operator &op)
Specification of the nonlinear operator.
PetscNonlinearSolver(MPI_Comm comm, const std::string &prefix=std::string())
Abstract class for PETSc's ODE solvers.
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
virtual void Init(TimeDependentOperator &f_, enum PetscODESolver::Type type)
Initialize the ODE solver.
virtual void Run(Vector &x, real_t &t, real_t &dt, real_t t_final)
Perform time integration from time t [in] to time tf [in].
virtual void Step(Vector &x, real_t &t, real_t &dt)
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in].
void SetType(PetscODESolver::Type)
PetscODESolver::Type GetType() const
PetscODESolver(MPI_Comm comm, const std::string &prefix=std::string())
void SetJacobianType(Operator::Type type)
virtual ~PetscODESolver()
PetscPCGSolver(MPI_Comm comm, const std::string &prefix=std::string(), bool iter_mode=false)
Wrapper for PETSc's matrix class.
void Print(const char *fname=NULL, bool binary=false) const
Prints the matrix (to stdout if fname is NULL)
PetscInt GetNumRows() const
Returns the local number of rows.
void ScaleCols(const Vector &s)
Scale the local col i by s(i).
void MakeRef(const PetscParMatrix &master)
Makes this object a reference to another PetscParMatrix.
void EliminateRows(const Array< int > &rows)
Eliminate only the rows from the matrix.
void ConvertOperator(MPI_Comm comm, const Operator &op, petsc::Mat *B, Operator::Type tid)
PetscInt GetGlobalNumCols() const
Returns the global number of columns.
PetscParMatrix & operator-=(const PetscParMatrix &B)
void Mult(real_t a, const Vector &x, real_t b, Vector &y) const
Matvec: y = a A x + b y.
PetscInt GetColStart() const
Returns the global index of the first local column.
PetscInt M() const
Returns the global number of rows.
virtual ~PetscParMatrix()
Calls PETSc's destroy function.
void EliminateRowsCols(const Array< int > &rows_cols, const PetscParVector &X, PetscParVector &B, real_t diag=1.)
Eliminate rows and columns from the matrix, and rows from the vector B. Modify B with the BC values i...
PetscParVector * GetY() const
Returns the inner vector in the range of A (it creates it if needed)
MPI_Comm GetComm() const
Get the associated MPI communicator.
PetscInt GetGlobalNumRows() const
Returns the global number of rows.
PetscParMatrix & operator=(const PetscParMatrix &B)
void MultTranspose(const Vector &x, Vector &y) const override
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
petsc::Mat ReleaseMat(bool dereference)
Release the PETSc Mat object. If dereference is true, decrement the refcount of the Mat object.
void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
void MakeWrapper(MPI_Comm comm, const Operator *op, petsc::Mat *B)
Creates a wrapper around a mfem::Operator op using PETSc's MATSHELL object and returns the Mat in B.
PetscInt GetNumCols() const
Returns the local number of columns.
PetscInt NNZ() const
Returns the number of nonzeros.
petsc::Mat A
The actual PETSc object.
PetscParVector * GetX() const
Returns the inner vector in the domain of A (it creates it if needed)
void Shift(real_t s)
Shift diagonal by a constant.
PetscParVector * X
Auxiliary vectors for typecasting.
PetscParMatrix()
Create an empty matrix to be used as a reference to an existing matrix.
void SetMat(petsc::Mat newA)
Replace the inner Mat Object. The reference count of newA is increased.
void operator*=(real_t s)
Scale all entries by s: A_scaled = s*A.
void SetBlockSize(PetscInt rbs, PetscInt cbs=-1)
Set row and column block sizes of a matrix.
PetscInt N() const
Returns the global number of columns.
PetscParMatrix * Transpose(bool action=false)
Returns the transpose of the PetscParMatrix.
void Init()
Initialize with defaults. Does not initialize inherited members.
void Destroy()
Delete all owned data. Does not perform re-initialization with defaults.
PetscInt GetRowStart() const
Returns the global index of the first local row.
void MultTranspose(real_t a, const Vector &x, real_t b, Vector &y) const
Matvec transpose: y = a A^T x + b y.
PetscParMatrix & operator+=(const PetscParMatrix &B)
void AddMult(const Vector &x, Vector &y, const real_t a=1.0) const override
Operator application: y+=A(x) (default) or y+=a*A(x).
void ScaleRows(const Vector &s)
Scale the local row i by s(i).
void AddMultTranspose(const Vector &x, Vector &y, const real_t a=1.0) const override
Operator transpose application: y+=A^t(x) (default) or y+=a*A^t(x).
void ResetMemory()
Completes the operation started with PlaceMemory.
void SetFlagsFromMask_() const
void PlaceMemory(Memory< real_t > &, bool=false)
This requests write access from where the memory is valid and temporarily replaces the corresponding ...
void Randomize(PetscInt seed=0)
Set random values.
void SetBlockSize(PetscInt bs)
Set block size of a vector.
bool UseDevice() const override
Return the device flag of the Memory object used by the Vector.
real_t * HostReadWrite() override
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
void PlaceArray(PetscScalar *temp_data)
Temporarily replace the data of the PETSc Vec object. To return to the original data array,...
PetscInt GlobalSize() const
Returns the global number of rows.
PetscParVector & operator-=(const PetscParVector &y)
real_t * Write(bool=true) override
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
void UpdateVecFromFlags()
Update PETSc's Vec after having accessed its data via GetMemory()
void Print(const char *fname=NULL, bool binary=false) const
Prints the vector (to stdout if fname is NULL)
real_t * ReadWrite(bool=true) override
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
const real_t * HostRead() const override
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
const real_t * Read(bool=true) const override
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
real_t * HostWrite() override
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), false).
PetscParVector & operator+=(const PetscParVector &y)
petsc::Vec x
The actual PETSc object.
MPI_Comm GetComm() const
Get the associated MPI communicator.
virtual ~PetscParVector()
Calls PETSc's destroy function.
void ResetArray()
Reset the PETSc Vec object to use its default data. Call this method after the use of PlaceArray().
Vector * GlobalVector() const
Returns the global vector in each processor.
PetscParVector & AddValues(const Array< PetscInt > &, const Array< PetscScalar > &)
Add values in a vector.
PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscInt *col=NULL)
Creates vector with given global size and partitioning of the columns.
PetscParVector & SetValues(const Array< PetscInt > &, const Array< PetscScalar > &)
Set values in a vector.
PetscParVector & operator*=(PetscScalar d)
PetscParVector & operator=(PetscScalar d)
Set constant values.
virtual ~PetscPreconditionerFactory()
PetscPreconditionerFactory(const std::string &name_="MFEM Factory")
virtual Solver * NewPreconditioner(const OperatorHandle &oh)=0
Abstract class for PETSc's preconditioners.
virtual void MultTranspose(const Vector &b, Vector &x) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
virtual void Mult(const Vector &b, Vector &x) const
Application of the preconditioner.
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
virtual ~PetscPreconditioner()
PetscPreconditioner(MPI_Comm comm, const std::string &prefix=std::string())
Abstract class for monitoring PETSc's solvers.
virtual ~PetscSolverMonitor()
virtual void MonitorResidual(PetscInt it, PetscReal norm, const Vector &r)
Monitor the residual vector r.
virtual void MonitorSolution(PetscInt it, PetscReal norm, const Vector &x)
Monitor the solution vector x.
virtual void MonitorSolver(PetscSolver *solver)
Generic monitor to take access to the solver.
PetscSolverMonitor(bool monitor_sol=false, bool monitor_res=true)
Abstract class for PETSc's solvers.
PetscClassId cid
The class id of the actual PETSc object.
void SetAbsTol(real_t tol)
void * private_ctx
Private context for solver.
void SetPrintLevel(int plev)
void SetBCHandler(PetscBCHandler *bch)
Sets the object to handle essential boundary conditions.
void SetMaxIter(int max_iter)
void SetRelTol(real_t tol)
void CreatePrivateContext()
virtual ~PetscSolver()
Destroy the PetscParVectors allocated (if any).
MPI_Comm GetComm() const
Get the associated MPI communicator.
PetscSolver()
Construct an empty PetscSolver. Initialize protected objects to NULL.
PetscObject obj
The actual PETSc object (KSP, PC, SNES or TS).
bool clcustom
Boolean to handle SetFromOptions calls.
bool operatorset
Boolean to handle SetOperator calls.
void Customize(bool customize=true) const
Customize object with options set.
void SetMonitor(PetscSolverMonitor *ctx)
Sets user-defined monitoring routine.
void FreePrivateContext()
PetscBCHandler * bchandler
Handler for boundary conditions.
void SetPreconditionerFactory(PetscPreconditionerFactory *factory)
Sets the object for the creation of the preconditioner.
PetscParVector * B
Right-hand side and solution vector.
Base abstract class for first order time dependent operators.
void trans(const Vector &u, Vector &x)
void write(std::ostream &os, T value)
Write 'value' to stream.
T read(std::istream &is)
Read a value from the stream and return it.
void mfem_error(const char *msg)
PetscParMatrix * TripleMatrixProduct(PetscParMatrix *R, PetscParMatrix *A, PetscParMatrix *P)
Returns the matrix R * A * P.
void RAP(const DenseMatrix &A, const DenseMatrix &P, DenseMatrix &RAP)
void MFEMInitializePetsc()
Convenience functions to initialize/finalize PETSc.
HypreParMatrix * ParMult(const HypreParMatrix *A, const HypreParMatrix *B, bool own_matrix)
void EliminateBC(const HypreParMatrix &A, const HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B)
Eliminate essential BC specified by ess_dof_list from the solution X to the r.h.s....
std::function< real_t(const Vector &)> f(real_t mass_coeff)
struct s_NavierContext ctx
struct _p_PetscObject * PetscObject