17 #include "../config/config.hpp"
28 #include "petscconf.h"
29 #if !defined(PETSC_USE_REAL_DOUBLE)
30 #error "MFEM does not work with PETSc compiled without double precision"
32 #if defined(PETSC_USE_COMPLEX)
33 #error "MFEM does not work with PETSc compiled with complex numbers support"
35 #if defined(PETSC_USE_64BIT_INDICES) && !defined(HYPRE_BIGINT)
36 #error "Mismatch between HYPRE (32bit) and PETSc (64bit) integer types"
38 #if !defined(PETSC_USE_64BIT_INDICES) && defined(HYPRE_BIGINT)
39 #error "Mismatch between HYPRE (64bit) and PETSc (32bit) integer types"
42 #include "petscversion.h"
43 #if PETSC_VERSION_GE(3,12,0)
44 #include "petscsystypes.h"
54 typedef struct _p_Vec *
Vec;
55 typedef struct _p_Mat *
Mat;
56 typedef struct _p_KSP *
KSP;
57 typedef struct _p_PC *
PC;
58 typedef struct _p_SNES *
SNES;
59 typedef struct _p_TS *
TS;
71 class ParFiniteElementSpace;
119 bool transpose =
false,
bool allocate =
true);
125 bool allocate =
true);
145 operator Vec()
const {
return x; }
191 void Print(
const char *fname = NULL,
bool binary =
false)
const;
230 void BlockDiagonalConstructor(MPI_Comm comm,
PetscInt *row_starts,
232 bool assembled,
Mat *
A);
324 {
Mult(1.0, x, 0.0, y); }
333 operator Mat()
const {
return A; }
381 void Print(
const char *fname = NULL,
bool binary =
false)
const;
408 void Shift(
double s);
427 PetscParMatrix *
ParMult(
const PetscParMatrix *A,
const PetscParMatrix *B);
430 PetscParMatrix *
RAP(PetscParMatrix *Rt, PetscParMatrix *A, PetscParMatrix *P);
433 PetscParMatrix *
RAP(PetscParMatrix *A, PetscParMatrix *P);
436 PetscParMatrix *
RAP(HypreParMatrix *A, PetscParMatrix *P);
443 void EliminateBC(PetscParMatrix &A, PetscParMatrix &Ae,
444 const Array<int> &ess_dof_list,
const Vector &X, Vector &B);
458 bctype(_type), setup(false), eval_t(0.0),
459 eval_t_cached(std::numeric_limits<double>::min()) {}
474 {
mfem_error(
"PetscBCHandler::Eval method not overloaded"); }
502 double eval_t_cached;
516 const char*
GetName() {
return name.c_str(); }
522 class PetscSolverMonitor;
570 void Customize(
bool customize =
true)
const;
609 const std::string &prefix = std::string());
616 const std::string &prefix = std::string());
639 PetscPCGSolver(MPI_Comm comm,
const std::string &prefix = std::string());
642 const std::string &prefix = std::string());
651 const std::string &prefix = std::string());
653 const std::string &prefix = std::string());
655 const std::string &prefix = std::string());
718 const std::string &prefix = std::string());
721 const std::string &prefix = std::string());
729 const std::string &prefix = std::string());
738 const std::string &prefix = std::string());
740 const std::string &prefix = std::string());
761 Vector &W,
bool &changed_y,
bool &changed_w));
788 PetscODESolver(MPI_Comm comm,
const std::string &prefix = std::string());
803 virtual void Step(
Vector &x,
double &t,
double &dt);
804 virtual void Run(
Vector &x,
double &t,
double &dt,
double t_final);
824 MFEM_ABORT(
"MonitorSolution() is not implemented!")
830 MFEM_ABORT(
"MonitorResidual() is not implemented!")
840 #endif // MFEM_USE_MPI
841 #endif // MFEM_USE_PETSC
PetscPreconditionerFactory(const std::string &_name="MFEM Factory")
void SetPreconditioner(Solver &precond)
Sets the solver to perform preconditioning.
void SetPrintLevel(int plev)
PetscParVector * B
Right-hand side and solution vector.
void CreatePrivateContext()
void Print(const char *fname=NULL, bool binary=false) const
Prints the matrix (to stdout if fname is NULL)
virtual void SetOperator(const Operator &op)
Specification of the nonlinear operator.
Abstract class for PETSc's preconditioners.
PetscParMatrix & operator+=(const PetscParMatrix &B)
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
HypreParMatrix * RAP(const HypreParMatrix *A, const HypreParMatrix *P)
Returns the matrix P^t * A * P.
bool clcustom
Boolean to handle SetFromOptions calls.
void SetObjective(void(*obj)(Operator *op, const Vector &x, double *f))
Specification of an objective function to be used for line search.
void ConvertOperator(MPI_Comm comm, const Operator &op, Mat *B, Operator::Type tid)
Wrapper for PETSc's matrix class.
PetscParVector & operator+=(const PetscParVector &y)
const Array< int > * nat_dof
void ApplyBC(const Vector &x, Vector &y)
y = x on ess_tdof_list_c and y = g (internally evaluated) on ess_tdof_list
Abstract class for PETSc's linear solvers.
Vec x
The actual PETSc object.
Abstract class for PETSc's solvers.
PetscODESolver::Type GetType() const
virtual void Run(Vector &x, double &t, double &dt, double t_final)
Perform time integration from time t [in] to time tf [in].
void SetPostCheck(void(*post)(Operator *op, const Vector &X, Vector &Y, Vector &W, bool &changed_y, bool &changed_w))
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
ParFiniteElementSpace * fespace
Type GetType() const
Returns the type of boundary conditions.
Base abstract class for time dependent operators.
PetscInt GetNumCols() const
Returns the local number of columns.
void SetType(PetscODESolver::Type)
virtual void MonitorSolver(PetscSolver *solver)
Generic monitor to take access to the solver.
Pointer to an Operator of a specified type.
void Mult(double a, const Vector &x, double b, Vector &y) const
Matvec: y = a A x + b y.
PetscBDDCSolver(MPI_Comm comm, Operator &op, const PetscBDDCSolverParams &opts=PetscBDDCSolverParams(), const std::string &prefix=std::string())
PetscParVector & AddValues(const Array< PetscInt > &, const Array< PetscScalar > &)
Add values in a vector.
void SetMat(Mat newA)
Replace the inner Mat Object. The reference count of newA is increased.
virtual ~PetscSolver()
Destroy the PetscParVectors allocated (if any).
PetscNonlinearSolver(MPI_Comm comm, const std::string &prefix=std::string())
PetscInt GetGlobalNumRows() const
Returns the global number of rows.
virtual void Step(Vector &x, double &t, double &dt)
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in]...
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
void Init()
Initialize with defaults. Does not initialize inherited members.
PetscPreconditioner(MPI_Comm comm, const std::string &prefix=std::string())
PetscClassId cid
The class id of the actual PETSc object.
Abstract parallel finite element space.
void SetRelTol(double tol)
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an ...
void Randomize(PetscInt seed=0)
Set random values.
PetscPCGSolver(MPI_Comm comm, const std::string &prefix=std::string())
void Destroy()
Delete all owned data. Does not perform re-initialization with defaults.
void SetMonitor(PetscSolverMonitor *ctx)
Sets user-defined monitoring routine.
void SetMaxIter(int max_iter)
Abstract class for PETSc's ODE solvers.
PetscParVector & operator*=(PetscScalar d)
HypreParMatrix * ParMult(const HypreParMatrix *A, const HypreParMatrix *B)
Returns the matrix A * B.
void EliminateRowsCols(const Array< int > &rows_cols, const PetscParVector &X, PetscParVector &B, double diag=1.)
Eliminate rows and columns from the matrix, and rows from the vector B. Modify B with the BC values i...
Wrapper for PETSc's vector class.
void Customize(bool customize=true) const
Customize object with options set.
PetscInt M() const
Returns the global number of rows.
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
virtual ~PetscLinearSolver()
PetscInt GetNumRows() const
Returns the local number of rows.
void Print(const char *fname=NULL, bool binary=false) const
Prints the vector (to stdout if fname is NULL)
void EliminateBC(HypreParMatrix &A, HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B)
void ResetArray()
Reset the PETSc Vec object to use its default data. Call this method after the use of PlaceArray()...
PetscParVector & SetValues(const Array< PetscInt > &, const Array< PetscScalar > &)
Set values in a vector.
virtual void Init(TimeDependentOperator &f_, enum PetscODESolver::Type type)
Initialize the ODE solver.
PetscParMatrix * Transpose(bool action=false)
Returns the transpose of the PetscParMatrix.
PetscObject obj
The actual PETSc object (KSP, PC, SNES or TS).
Abstract class for monitoring PETSc's solvers.
void SetJacobianType(Operator::Type type)
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
Auxiliary class for BDDC customization.
virtual ~PetscPreconditioner()
MPI_Comm GetComm() const
Get the associated MPI communicator.
void FixResidualBC(const Vector &x, Vector &y)
y = x-g on ess_tdof_list, the rest of y is unchanged
PetscParMatrix & operator=(const PetscParMatrix &B)
PetscInt GetColStart() const
Returns the global index of the first local column.
virtual ~PetscParVector()
Calls PETSc's destroy function.
PetscFieldSplitSolver(MPI_Comm comm, Operator &op, const std::string &prefix=std::string())
PetscBCHandler * bchandler
Handler for boundary conditions.
PetscParMatrix & operator-=(const PetscParMatrix &B)
virtual Solver * NewPreconditioner(const OperatorHandle &oh)=0
void ScaleRows(const Vector &s)
Scale the local row i by s(i).
MPI_Comm GetComm() const
Get the associated MPI communicator.
void Shift(double s)
Shift diagonal by a constant.
void SetTime(double t)
Sets the current time.
ID for class PetscParMatrix, MATSHELL format.
PetscParMatrix()
Create an empty matrix to be used as a reference to an existing matrix.
void SetType(enum Type _type)
Sets the type of boundary conditions.
Abstract class for PETSc's nonlinear solvers.
void SetBCHandler(PetscBCHandler *bch)
Sets the object to handle essential boundary conditions.
Wrapper for hypre's parallel vector class.
virtual void Eval(double t, Vector &g)
Boundary conditions evaluation.
Type
Enumeration defining IDs for some classes derived from Operator.
PetscBCHandler(Type _type=ZERO)
PetscInt NNZ() const
Returns the number of nonzeros.
PetscLinearSolver(MPI_Comm comm, const std::string &prefix=std::string(), bool wrap=true)
virtual void Mult(const Vector &b, Vector &x) const
Application of the preconditioner.
Mat A
The actual PETSc object.
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
PetscInt N() const
Returns the global number of columns.
PetscParVector * GetY() const
Returns the inner vector in the range of A (it creates it if needed)
void SetJacobianType(Operator::Type type)
void MakeWrapper(MPI_Comm comm, const Operator *op, Mat *B)
Creates a wrapper around a mfem::Operator op using PETSc's MATSHELL object and returns the Mat in B...
void SetUpdate(void(*update)(Operator *op, int it, const mfem::Vector &F, const mfem::Vector &X, const mfem::Vector &D, const mfem::Vector &P))
bool operatorset
Boolean to handle SetOperator calls.
PetscParVector * X
Auxiliary vectors for typecasting.
void MultTranspose(double a, const Vector &x, double b, Vector &y) const
Matvec transpose: y = a A^T x + b y.
PetscParVector & operator-=(const PetscParVector &y)
virtual ~PetscPreconditionerFactory()
virtual ~PetscSolverMonitor()
virtual ~PetscNonlinearSolver()
void SetComputeNetFlux(bool net=true)
Setup BDDC with no-net-flux local solvers. Needs a ParFiniteElementSpace attached.
virtual ~PetscODESolver()
virtual ~PetscBCHandler()
PetscSolver()
Construct an empty PetscSolver. Initialize protected objects to NULL.
void SetPreconditionerFactory(PetscPreconditionerFactory *factory)
Sets the object for the creation of the preconditioner.
void MFEMInitializePetsc()
Convenience functions to initialize/finalize PETSc.
Mat ReleaseMat(bool dereference)
Release the PETSc Mat object. If dereference is true, decrement the refcount of the Mat object...
PetscParVector(MPI_Comm comm, PetscInt glob_size, PetscInt *col=NULL)
Creates vector with given global size and partitioning of the columns.
virtual void MonitorSolution(PetscInt it, PetscReal norm, const Vector &x)
Monitor the solution vector x.
ID for class PetscParMatrix, MATAIJ format.
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
void SetSpace(ParFiniteElementSpace *fe)
MPI_Comm GetComm() const
Get the associated MPI communicator.
PetscInt GlobalSize() const
Returns the global number of rows.
const Array< int > * ess_dof
PetscInt GetRowStart() const
Returns the global index of the first local row.
struct _p_PetscObject * PetscObject
void SetAbsTol(double tol)
Helper class for handling essential boundary conditions.
PetscParVector * GetX() const
Returns the inner vector in the domain of A (it creates it if needed)
Array< int > & GetTDofs()
Gets essential dofs (local, per-process numbering)
PetscParVector & operator=(PetscScalar d)
Set constant values.
PetscSolverMonitor(bool monitor_sol=false, bool monitor_res=true)
virtual void MonitorResidual(PetscInt it, PetscReal norm, const Vector &r)
Monitor the residual vector r.
void PlaceArray(PetscScalar *temp_data)
Temporarily replace the data of the PETSc Vec object. To return to the original data array...
void FreePrivateContext()
Vector * GlobalVector() const
Returns the global vector in each processor.
PetscODESolver(MPI_Comm comm, const std::string &prefix=std::string())
void EliminateRows(const Array< int > &rows)
Eliminate only the rows from the matrix.
PetscInt GetGlobalNumCols() const
Returns the global number of columns.
void SetNatBdrDofs(const Array< int > *natdofs, bool loc=false)
Specify dofs on the natural boundary.
Wrapper for hypre's ParCSR matrix class.
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
void operator*=(double s)
Scale all entries by s: A_scaled = s*A.
void SetEssBdrDofs(const Array< int > *essdofs, bool loc=false)
Specify dofs on the essential boundary.
void SetTDofs(Array< int > &list)
Sets essential dofs (local, per-process numbering)
void * private_ctx
Private context for solver.
void SetUp(PetscInt n)
SetUp the helper object, where n is the size of the solution vector.
void MakeRef(const PetscParMatrix &master)
Makes this object a reference to another PetscParMatrix.
void ScaleCols(const Vector &s)
Scale the local col i by s(i).
virtual ~PetscParMatrix()
Calls PETSc's destroy function.