MFEM  v3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
hypre.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_HYPRE
13 #define MFEM_HYPRE
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_MPI
18 
19 #include <mpi.h>
20 
21 // Enable internal hypre timing routines
22 #define HYPRE_TIMING
23 
24 // hypre header files
25 #include "seq_mv.h"
26 #include "_hypre_parcsr_mv.h"
27 #include "_hypre_parcsr_ls.h"
28 #include "temp_multivector.h"
29 
30 #ifdef HYPRE_COMPLEX
31 #error "MFEM does not work with HYPRE's complex numbers support"
32 #endif
33 
34 #include "sparsemat.hpp"
35 #include "hypre_parcsr.hpp"
36 
37 namespace mfem
38 {
39 
40 class ParFiniteElementSpace;
41 class HypreParMatrix;
42 
43 namespace internal
44 {
45 
46 // Convert a HYPRE_Int to int
47 inline int to_int(HYPRE_Int i)
48 {
49 #ifdef HYPRE_BIGINT
50  MFEM_ASSERT(HYPRE_Int(int(i)) == i, "overflow converting HYPRE_Int to int");
51 #endif
52  return int(i);
53 }
54 
55 }
56 
58 class HypreParVector : public Vector
59 {
60 private:
61  int own_ParVector;
62 
64  hypre_ParVector *x;
65 
66  friend class HypreParMatrix;
67 
68  // Set Vector::data and Vector::size from *x
69  inline void _SetDataAndSize_();
70 
71 public:
74  HypreParVector(MPI_Comm comm, HYPRE_Int glob_size, HYPRE_Int *col);
79  HypreParVector(MPI_Comm comm, HYPRE_Int glob_size, double *_data,
80  HYPRE_Int *col);
84  explicit HypreParVector(const HypreParMatrix &A, int transpose = 0);
86  explicit HypreParVector(HYPRE_ParVector y);
88  explicit HypreParVector(ParFiniteElementSpace *pfes);
89 
91  MPI_Comm GetComm() { return x->comm; }
92 
94  inline HYPRE_Int *Partitioning() { return x->partitioning; }
95 
97  inline HYPRE_Int GlobalSize() { return x->global_size; }
98 
100  operator hypre_ParVector*() const;
101 #ifndef HYPRE_PAR_VECTOR_STRUCT
102  operator HYPRE_ParVector() const;
104 #endif
105  hypre_ParVector *StealParVector() { own_ParVector = 0; return x; }
107 
109  void SetOwnership(int own) { own_ParVector = own; }
110 
112  int GetOwnership() const { return own_ParVector; }
113 
115  Vector* GlobalVector() const;
116 
118  HypreParVector& operator= (double d);
121 
127  void SetData(double *_data);
128 
130  HYPRE_Int Randomize(HYPRE_Int seed);
131 
133  void Print(const char *fname) const;
134 
136  ~HypreParVector();
137 };
138 
140 double InnerProduct(HypreParVector &x, HypreParVector &y);
141 double InnerProduct(HypreParVector *x, HypreParVector *y);
142 
143 
146 double ParNormlp(const Vector &vec, double p, MPI_Comm comm);
147 
148 
150 class HypreParMatrix : public Operator
151 {
152 private:
154  hypre_ParCSRMatrix *A;
155 
157  mutable HypreParVector *X, *Y;
158 
159  // Flags indicating ownership of A->diag->{i,j,data}, A->offd->{i,j,data},
160  // and A->col_map_offd.
161  // The possible values for diagOwner are:
162  // -1: no special treatment of A->diag (default)
163  // 0: prevent hypre from destroying A->diag->{i,j,data}
164  // 1: same as 0, plus take ownership of A->diag->{i,j}
165  // 2: same as 0, plus take ownership of A->diag->data
166  // 3: same as 0, plus take ownership of A->diag->{i,j,data}
167  // The same values and rules apply to offdOwner and A->offd.
168  // The possible values for colMapOwner are:
169  // -1: no special treatment of A->col_map_offd (default)
170  // 0: prevent hypre from destroying A->col_map_offd
171  // 1: same as 0, plus take ownership of A->col_map_offd
172  // All owned arrays are destroyed with 'delete []'.
173  char diagOwner, offdOwner, colMapOwner;
174 
175  // Does the object own the pointer A?
176  char ParCSROwner;
177 
178  // Initialize with defaults. Does not initialize inherited members.
179  void Init();
180 
181  // Delete all owned data. Does not perform re-initialization with defaults.
182  void Destroy();
183 
184  // Copy (shallow or deep, based on HYPRE_BIGINT) the I and J arrays from csr
185  // to hypre_csr. Shallow copy the data. Return the appropriate ownership
186  // flag.
187  static char CopyCSR(SparseMatrix *csr, hypre_CSRMatrix *hypre_csr);
188  // Copy (shallow or deep, based on HYPRE_BIGINT) the I and J arrays from
189  // bool_csr to hypre_csr. Allocate the data array and set it to all ones.
190  // Return the appropriate ownership flag.
191  static char CopyBoolCSR(Table *bool_csr, hypre_CSRMatrix *hypre_csr);
192 
193  // Copy the j array of a hypre_CSRMatrix to the given J array, converting
194  // the indices from HYPRE_Int to int.
195  static void CopyCSR_J(hypre_CSRMatrix *hypre_csr, int *J);
196 
197 public:
199  HypreParMatrix();
200 
202  explicit HypreParMatrix(hypre_ParCSRMatrix *a)
203  {
204  Init();
205  A = a;
206  height = GetNumRows();
207  width = GetNumCols();
208  }
209 
213  HypreParMatrix(MPI_Comm comm, HYPRE_Int glob_size, HYPRE_Int *row_starts,
214  SparseMatrix *diag);
215 
219  HypreParMatrix(MPI_Comm comm, HYPRE_Int global_num_rows,
220  HYPRE_Int global_num_cols, HYPRE_Int *row_starts,
221  HYPRE_Int *col_starts, SparseMatrix *diag);
222 
225  HypreParMatrix(MPI_Comm comm, HYPRE_Int global_num_rows,
226  HYPRE_Int global_num_cols, HYPRE_Int *row_starts,
227  HYPRE_Int *col_starts, SparseMatrix *diag, SparseMatrix *offd,
228  HYPRE_Int *cmap);
229 
232  HypreParMatrix(MPI_Comm comm,
233  HYPRE_Int global_num_rows, HYPRE_Int global_num_cols,
234  HYPRE_Int *row_starts, HYPRE_Int *col_starts,
235  HYPRE_Int *diag_i, HYPRE_Int *diag_j, double *diag_data,
236  HYPRE_Int *offd_i, HYPRE_Int *offd_j, double *offd_data,
237  HYPRE_Int offd_num_cols, HYPRE_Int *offd_col_map);
238 
240  HypreParMatrix(MPI_Comm comm, HYPRE_Int *row_starts, HYPRE_Int *col_starts,
241  SparseMatrix *a);
242 
245  HypreParMatrix(MPI_Comm comm, HYPRE_Int global_num_rows,
246  HYPRE_Int global_num_cols, HYPRE_Int *row_starts,
247  HYPRE_Int *col_starts, Table *diag);
248 
252  HypreParMatrix(MPI_Comm comm, int id, int np, HYPRE_Int *row, HYPRE_Int *col,
253  HYPRE_Int *i_diag, HYPRE_Int *j_diag, HYPRE_Int *i_offd,
254  HYPRE_Int *j_offd, HYPRE_Int *cmap, HYPRE_Int cmap_size);
255 
260  HypreParMatrix(MPI_Comm comm, int nrows, HYPRE_Int glob_nrows,
261  HYPRE_Int glob_ncols, int *I, HYPRE_Int *J,
262  double *data, HYPRE_Int *rows, HYPRE_Int *cols);
263 
265  void MakeRef(const HypreParMatrix &master);
266 
268  MPI_Comm GetComm() const { return A->comm; }
269 
271  operator hypre_ParCSRMatrix*() { return A; }
272 #ifndef HYPRE_PAR_CSR_MATRIX_STRUCT
273  operator HYPRE_ParCSRMatrix() { return (HYPRE_ParCSRMatrix) A; }
275 #endif
276  hypre_ParCSRMatrix* StealData();
278 
280  void SetOwnerFlags(char diag, char offd, char colmap)
281  { diagOwner = diag, offdOwner = offd, colMapOwner = colmap; }
282 
284  char OwnsDiag() const { return diagOwner; }
286  char OwnsOffd() const { return offdOwner; }
288  char OwnsColMap() const { return colMapOwner; }
289 
293  void CopyRowStarts();
297  void CopyColStarts();
298 
300  inline HYPRE_Int NNZ() { return A->num_nonzeros; }
302  inline HYPRE_Int *RowPart() { return A->row_starts; }
304  inline HYPRE_Int *ColPart() { return A->col_starts; }
306  inline HYPRE_Int M() { return A->global_num_rows; }
308  inline HYPRE_Int N() { return A->global_num_cols; }
309 
311  void GetDiag(Vector &diag) const;
313  void GetDiag(SparseMatrix &diag) const;
315  void GetOffd(SparseMatrix &offd, HYPRE_Int* &cmap) const;
316 
319  void GetBlocks(Array2D<HypreParMatrix*> &blocks,
320  bool interleaved_rows = false,
321  bool interleaved_cols = false) const;
322 
325 
327  int GetNumRows() const
328  {
329  return internal::to_int(
330  hypre_CSRMatrixNumRows(hypre_ParCSRMatrixDiag(A)));
331  }
332 
334  int GetNumCols() const
335  {
336  return internal::to_int(
337  hypre_CSRMatrixNumCols(hypre_ParCSRMatrixDiag(A)));
338  }
339 
340  HYPRE_Int GetGlobalNumRows() const
341  { return hypre_ParCSRMatrixGlobalNumRows(A); }
342 
343  HYPRE_Int GetGlobalNumCols() const
344  { return hypre_ParCSRMatrixGlobalNumCols(A); }
345 
346  HYPRE_Int *GetRowStarts() const { return hypre_ParCSRMatrixRowStarts(A); }
347 
348  HYPRE_Int *GetColStarts() const { return hypre_ParCSRMatrixColStarts(A); }
349 
351  HYPRE_Int Mult(HypreParVector &x, HypreParVector &y,
352  double alpha = 1.0, double beta = 0.0);
354  HYPRE_Int Mult(HYPRE_ParVector x, HYPRE_ParVector y,
355  double alpha = 1.0, double beta = 0.0);
358  double alpha = 1.0, double beta = 0.0);
359 
360  void Mult(double a, const Vector &x, double b, Vector &y) const;
361  void MultTranspose(double a, const Vector &x, double b, Vector &y) const;
362 
363  virtual void Mult(const Vector &x, Vector &y) const
364  { Mult(1.0, x, 0.0, y); }
365  virtual void MultTranspose(const Vector &x, Vector &y) const
366  { MultTranspose(1.0, x, 0.0, y); }
367 
370  void BooleanMult(int alpha, int *x, int beta, int *y)
371  {
372  internal::hypre_ParCSRMatrixBooleanMatvec(A, alpha, x, beta, y);
373  }
374 
383  HYPRE_Int* row_starts = NULL) const;
384 
386  void ScaleRows(const Vector & s);
388  void InvScaleRows(const Vector & s);
390  void operator*=(double s);
391 
393  void Threshold(double threshold = 0.0);
394 
396  void EliminateZeroRows() { hypre_ParCSRMatrixFixZeroRows(A); }
397 
400  void EliminateRowsCols(const Array<int> &rows_cols, const HypreParVector &X,
401  HypreParVector &B);
402 
406  HypreParMatrix* EliminateRowsCols(const Array<int> &rows_cols);
407 
409  void Print(const char *fname, HYPRE_Int offi = 0, HYPRE_Int offj = 0);
411  void Read(MPI_Comm comm, const char *fname);
412 
414  virtual ~HypreParMatrix() { Destroy(); }
415 };
416 
418 HypreParMatrix * ParMult(HypreParMatrix *A, HypreParMatrix *B);
419 
421 HypreParMatrix * RAP(HypreParMatrix *A, HypreParMatrix *P);
423 HypreParMatrix * RAP(HypreParMatrix * Rt, HypreParMatrix *A, HypreParMatrix *P);
424 
428 void EliminateBC(HypreParMatrix &A, HypreParMatrix &Ae,
429  const Array<int> &ess_dof_list, const Vector &X, Vector &B);
430 
431 
433 class HypreSmoother : public Solver
434 {
435 protected:
439  mutable HypreParVector *B, *X;
441  mutable HypreParVector *V, *Z;
443  mutable HypreParVector *X0, *X1;
444 
447  int type;
451  double relax_weight;
453  double omega;
460 
462  double lambda;
463  double mu;
465 
467  double *l1_norms;
469  double max_eig_est;
471  double min_eig_est;
473  double window_params[3];
474 
476  double* fir_coeffs;
477 
478 public:
489  enum Type { Jacobi = 0, l1Jacobi = 1, l1GS = 2, l1GStr = 4, lumpedJacobi = 5,
490  GS = 6, Chebyshev = 16, Taubin = 1001, FIR = 1002
491  };
492 
493  HypreSmoother();
494 
496  int relax_times = 1, double relax_weight = 1.0,
497  double omega = 1.0, int poly_order = 2,
498  double poly_fraction = .3);
499 
503  void SetSOROptions(double relax_weight, double omega);
505  void SetPolyOptions(int poly_order, double poly_fraction);
507  void SetTaubinOptions(double lambda, double mu, int iter);
508 
510  void SetWindowByName(const char* window_name);
512  void SetWindowParameters(double a, double b, double c);
514  void SetFIRCoefficients(double max_eig);
515 
518  virtual void SetOperator(const Operator &op);
519 
521  virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
522  virtual void Mult(const Vector &b, Vector &x) const;
523 
524  virtual ~HypreSmoother();
525 };
526 
527 
529 class HypreSolver : public Solver
530 {
531 protected:
534 
536  mutable HypreParVector *B, *X;
537 
539  mutable int setup_called;
540 
541 public:
542  HypreSolver();
543 
545 
547  virtual operator HYPRE_Solver() const = 0;
548 
550  virtual HYPRE_PtrToParSolverFcn SetupFcn() const = 0;
552  virtual HYPRE_PtrToParSolverFcn SolveFcn() const = 0;
553 
554  virtual void SetOperator(const Operator &op)
555  { mfem_error("HypreSolvers do not support SetOperator!"); }
556 
558  virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
559  virtual void Mult(const Vector &b, Vector &x) const;
560 
561  virtual ~HypreSolver();
562 };
563 
565 class HyprePCG : public HypreSolver
566 {
567 private:
568  HYPRE_Solver pcg_solver;
569 
570 public:
572 
573  void SetTol(double tol);
574  void SetMaxIter(int max_iter);
575  void SetLogging(int logging);
576  void SetPrintLevel(int print_lvl);
577 
579  void SetPreconditioner(HypreSolver &precond);
580 
584  void SetResidualConvergenceOptions(int res_frequency=-1, double rtol=0.0);
585 
588 
589  void GetNumIterations(int &num_iterations)
590  {
591  HYPRE_Int num_it;
592  HYPRE_ParCSRPCGGetNumIterations(pcg_solver, &num_it);
593  num_iterations = internal::to_int(num_it);
594  }
595 
597  virtual operator HYPRE_Solver() const { return pcg_solver; }
598 
600  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
601  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRPCGSetup; }
603  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
604  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRPCGSolve; }
605 
607  virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
608  using HypreSolver::Mult;
609 
610  virtual ~HyprePCG();
611 };
612 
614 class HypreGMRES : public HypreSolver
615 {
616 private:
617  HYPRE_Solver gmres_solver;
618 
619 public:
621 
622  void SetTol(double tol);
623  void SetMaxIter(int max_iter);
624  void SetKDim(int dim);
625  void SetLogging(int logging);
626  void SetPrintLevel(int print_lvl);
627 
629  void SetPreconditioner(HypreSolver &precond);
630 
633 
635  virtual operator HYPRE_Solver() const { return gmres_solver; }
636 
638  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
639  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRGMRESSetup; }
641  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
642  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRGMRESSolve; }
643 
645  virtual void Mult (const HypreParVector &b, HypreParVector &x) const;
646  using HypreSolver::Mult;
647 
648  virtual ~HypreGMRES();
649 };
650 
653 {
654 public:
655  virtual operator HYPRE_Solver() const { return NULL; }
656 
657  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
658  { return (HYPRE_PtrToParSolverFcn) hypre_ParKrylovIdentitySetup; }
659  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
660  { return (HYPRE_PtrToParSolverFcn) hypre_ParKrylovIdentity; }
661 
662  virtual ~HypreIdentity() { }
663 };
664 
667 {
668 public:
671  virtual operator HYPRE_Solver() const { return NULL; }
672 
673  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
674  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRDiagScaleSetup; }
675  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
676  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRDiagScale; }
677 
678  HypreParMatrix* GetData() { return A; }
679  virtual ~HypreDiagScale() { }
680 };
681 
684 {
685 private:
686  HYPRE_Solver sai_precond;
687 
688 public:
690 
691  void SetSymmetry(int sym);
692 
694  virtual operator HYPRE_Solver() const { return sai_precond; }
695 
696  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
697  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParaSailsSetup; }
698  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
699  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParaSailsSolve; }
700 
701  virtual ~HypreParaSails();
702 };
703 
706 {
707 private:
708  HYPRE_Solver amg_precond;
709 
712 
714  ParFiniteElementSpace *fespace;
715 
717  void RecomputeRBMs();
718 
720  void SetDefaultOptions();
721 
722  // If amg_precond is NULL, allocates it and sets default options.
723  // Otherwise saves the options from amg_precond, destroys it, allocates a new
724  // one, and sets its options to the saved values.
725  void ResetAMGPrecond();
726 
727 public:
728  HypreBoomerAMG();
729 
731 
732  virtual void SetOperator(const Operator &op);
733 
737  void SetSystemsOptions(int dim);
738 
745 
746  void SetPrintLevel(int print_level)
747  { HYPRE_BoomerAMGSetPrintLevel(amg_precond, print_level); }
748 
750  virtual operator HYPRE_Solver() const { return amg_precond; }
751 
752  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
753  { return (HYPRE_PtrToParSolverFcn) HYPRE_BoomerAMGSetup; }
754  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
755  { return (HYPRE_PtrToParSolverFcn) HYPRE_BoomerAMGSolve; }
756 
757  virtual ~HypreBoomerAMG();
758 };
759 
761 HypreParMatrix* DiscreteGrad(ParFiniteElementSpace *edge_fespace,
762  ParFiniteElementSpace *vert_fespace);
764 HypreParMatrix* DiscreteCurl(ParFiniteElementSpace *face_fespace,
765  ParFiniteElementSpace *edge_fespace);
766 
768 class HypreAMS : public HypreSolver
769 {
770 private:
771  HYPRE_Solver ams;
772 
774  HypreParVector *x, *y, *z;
776  HypreParMatrix *G;
778  HypreParMatrix *Pi, *Pix, *Piy, *Piz;
779 
780 public:
782 
783  void SetPrintLevel(int print_lvl);
784 
786  void SetSingularProblem() { HYPRE_AMSSetBetaPoissonMatrix(ams, NULL); }
787 
789  virtual operator HYPRE_Solver() const { return ams; }
790 
791  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
792  { return (HYPRE_PtrToParSolverFcn) HYPRE_AMSSetup; }
793  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
794  { return (HYPRE_PtrToParSolverFcn) HYPRE_AMSSolve; }
795 
796  virtual ~HypreAMS();
797 };
798 
800 class HypreADS : public HypreSolver
801 {
802 private:
803  HYPRE_Solver ads;
804 
806  HypreParVector *x, *y, *z;
808  HypreParMatrix *G;
810  HypreParMatrix *C;
812  HypreParMatrix *ND_Pi, *ND_Pix, *ND_Piy, *ND_Piz;
814  HypreParMatrix *RT_Pi, *RT_Pix, *RT_Piy, *RT_Piz;
815 
816 public:
818 
819  void SetPrintLevel(int print_lvl);
820 
822  virtual operator HYPRE_Solver() const { return ads; }
823 
824  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
825  { return (HYPRE_PtrToParSolverFcn) HYPRE_ADSSetup; }
826  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
827  { return (HYPRE_PtrToParSolverFcn) HYPRE_ADSSolve; }
828 
829  virtual ~HypreADS();
830 };
831 
855 {
856 private:
857  MPI_Comm comm;
858  int myid;
859  int numProcs;
860  int nev; // Number of desired eigenmodes
861  int seed; // Random seed used for initial vectors
862 
863  HYPRE_Int glbSize; // Global number of DoFs in the linear system
864  HYPRE_Int * part; // Row partitioning of the linear system
865 
866  // Pointer to HYPRE's solver struct
867  HYPRE_Solver lobpcg_solver;
868 
869  // Interface for matrix storage type
870  mv_InterfaceInterpreter interpreter;
871 
872  // Interface for setting up and performing matrix-vector products
873  HYPRE_MatvecFunctions matvec_fn;
874 
875  // Eigenvalues
876  Array<double> eigenvalues;
877 
878  // Forward declaration
879  class HypreMultiVector;
880 
881  // MultiVector to store eigenvectors
882  HypreMultiVector * multi_vec;
883 
884  // Empty vectors used to setup the matrices and preconditioner
885  HypreParVector * x;
886 
888  class HypreMultiVector
889  {
890  private:
891  // Pointer to hypre's multi-vector object
892  mv_MultiVectorPtr mv_ptr;
893 
894  // Wrappers for each member of the multivector
895  HypreParVector ** hpv;
896 
897  // Number of vectors in the multivector
898  int nv;
899 
900  public:
901  HypreMultiVector(int n, HypreParVector & v,
902  mv_InterfaceInterpreter & interpreter);
903  ~HypreMultiVector();
904 
906  void Randomize(HYPRE_Int seed);
907 
909  HypreParVector & GetVector(unsigned int i);
910 
912  HypreParVector ** StealVectors();
913 
914  operator mv_MultiVectorPtr() const { return mv_ptr; }
915 
916  mv_MultiVectorPtr & GetMultiVector() { return mv_ptr; }
917  };
918 
919  static void * OperatorMatvecCreate( void *A, void *x );
920  static HYPRE_Int OperatorMatvec( void *matvec_data,
921  HYPRE_Complex alpha,
922  void *A,
923  void *x,
924  HYPRE_Complex beta,
925  void *y );
926  static HYPRE_Int OperatorMatvecDestroy( void *matvec_data );
927 
928  static HYPRE_Int PrecondSolve(void *solver,
929  void *A,
930  void *b,
931  void *x);
932  static HYPRE_Int PrecondSetup(void *solver,
933  void *A,
934  void *b,
935  void *x);
936 
937 public:
938  HypreLOBPCG(MPI_Comm comm);
939  ~HypreLOBPCG();
940 
941  void SetTol(double tol);
942  void SetMaxIter(int max_iter);
943  void SetPrintLevel(int logging);
944  void SetNumModes(int num_eigs) { nev = num_eigs; }
945  void SetPrecondUsageMode(int pcg_mode);
946  void SetRandomSeed(int s) { seed = s; }
947 
948  // The following four methods support general operators
949  void SetPreconditioner(Solver & precond);
950  void SetOperator(Operator & A);
951  void SetMassMatrix(Operator & M);
952 
954  void Solve();
955 
957  void GetEigenvalues(Array<double> & eigenvalues);
958 
960  HypreParVector & GetEigenvector(unsigned int i);
961 
963  HypreParVector ** StealEigenvectors() { return multi_vec->StealVectors(); }
964 };
965 
988 class HypreAME
989 {
990 private:
991  int myid;
992  int numProcs;
993  int nev; // Number of desired eigenmodes
994  bool setT;
995 
996  // Pointer to HYPRE's AME solver struct
997  HYPRE_Solver ame_solver;
998 
999  // Pointer to HYPRE's AMS solver struct
1000  HypreSolver * ams_precond;
1001 
1002  // Eigenvalues
1003  HYPRE_Real * eigenvalues;
1004 
1005  // MultiVector to store eigenvectors
1006  HYPRE_ParVector * multi_vec;
1007 
1008  HypreParVector ** eigenvectors;
1009 
1010  void createDummyVectors();
1011 
1012 public:
1013  HypreAME(MPI_Comm comm);
1014  ~HypreAME();
1015 
1016  void SetTol(double tol);
1017  void SetMaxIter(int max_iter);
1018  void SetPrintLevel(int logging);
1019  void SetNumModes(int num_eigs);
1020 
1021  // The following four methods support operators of type HypreParMatrix.
1022  void SetPreconditioner(HypreSolver & precond);
1023  void SetOperator(HypreParMatrix & A);
1024  void SetMassMatrix(HypreParMatrix & M);
1025 
1027  void Solve();
1028 
1030  void GetEigenvalues(Array<double> & eigenvalues);
1031 
1033  HypreParVector & GetEigenvector(unsigned int i);
1034 
1037 };
1038 
1039 }
1040 
1041 #endif // MFEM_USE_MPI
1042 
1043 #endif
virtual ~HypreBoomerAMG()
Definition: hypre.cpp:2496
int to_int(string str)
void SetTol(double tol)
Definition: hypre.cpp:1964
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition: hypre.cpp:2127
HYPRE_Int NNZ()
Returns the global number of nonzeros.
Definition: hypre.hpp:300
void EliminateRowsCols(const Array< int > &rows_cols, const HypreParVector &X, HypreParVector &B)
Definition: hypre.cpp:1260
MPI_Comm GetComm() const
MPI communicator.
Definition: hypre.hpp:268
Vector * GlobalVector() const
Returns the global vector in each processor.
Definition: hypre.cpp:140
The Auxiliary-space Maxwell Solver in hypre.
Definition: hypre.hpp:768
HypreParVector * X0
FIR Filter Temporary Vectors.
Definition: hypre.hpp:443
HypreParVector & GetEigenvector(unsigned int i)
Extract a single eigenvector.
Definition: hypre.cpp:3154
double min_eig_est
Minimal eigenvalue estimate for polynomial smoothing.
Definition: hypre.hpp:471
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:659
void SetOwnerFlags(char diag, char offd, char colmap)
Explicitly set the three ownership flags, see docs for diagOwner etc.
Definition: hypre.hpp:280
The Auxiliary-space Divergence Solver in hypre.
Definition: hypre.hpp:800
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:2946
void Print(const char *fname, HYPRE_Int offi=0, HYPRE_Int offj=0)
Prints the locally owned rows in parallel.
Definition: hypre.cpp:1283
MPI_Comm GetComm()
MPI communicator.
Definition: hypre.hpp:91
HYPRE_Int M()
Returns the global number of rows.
Definition: hypre.hpp:306
int setup_called
Was hypre&#39;s Setup function called already?
Definition: hypre.hpp:539
HYPRE_Int * ColPart()
Returns the column partitioning.
Definition: hypre.hpp:304
void MakeRef(const HypreParMatrix &master)
Make this HypreParMatrix a reference to &#39;master&#39;.
Definition: hypre.cpp:763
HypreParMatrix * LeftDiagMult(const SparseMatrix &D, HYPRE_Int *row_starts=NULL) const
Definition: hypre.cpp:1016
HYPRE_Int MultTranspose(HypreParVector &x, HypreParVector &y, double alpha=1.0, double beta=0.0)
Computes y = alpha * A^t * x + beta * y.
Definition: hypre.cpp:1010
HypreParVector * B
Right-hand side and solution vector.
Definition: hypre.hpp:536
HypreDiagScale(HypreParMatrix &A)
Definition: hypre.hpp:670
double window_params[3]
Parameters for windowing function of FIR filter.
Definition: hypre.hpp:473
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
Definition: hypre.hpp:363
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:793
HypreADS(HypreParMatrix &A, ParFiniteElementSpace *face_fespace)
Definition: hypre.cpp:2706
void SetWindowByName(const char *window_name)
Convenience function for setting canonical windowing parameters.
Definition: hypre.cpp:1643
HypreParMatrix(hypre_ParCSRMatrix *a)
Converts hypre&#39;s format to HypreParMatrix.
Definition: hypre.hpp:202
void GetEigenvalues(Array< double > &eigenvalues)
Collect the converged eigenvalues.
Definition: hypre.cpp:3359
void SetPreconditioner(HypreSolver &precond)
Definition: hypre.cpp:3325
void SetTol(double tol)
Definition: hypre.cpp:3304
virtual ~HypreGMRES()
Definition: hypre.cpp:2203
void SetPreconditioner(Solver &precond)
Definition: hypre.cpp:3077
void SetMassMatrix(Operator &M)
Definition: hypre.cpp:3132
Abstract parallel finite element space.
Definition: pfespace.hpp:28
void SetPrintLevel(int logging)
Definition: hypre.cpp:3062
bool iterative_mode
If true, use the second argument of Mult as an initial guess.
Definition: operator.hpp:106
virtual ~HypreAMS()
Definition: hypre.cpp:2686
void SetTol(double tol)
Definition: hypre.cpp:2102
void SetOperator(HypreParMatrix &A)
Definition: hypre.cpp:3331
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
GMRES Solve function.
Definition: hypre.hpp:641
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
Definition: hypre.hpp:963
HYPRE_Int Mult(HypreParVector &x, HypreParVector &y, double alpha=1.0, double beta=0.0)
Computes y = alpha * A * x + beta * y.
Definition: hypre.cpp:940
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:2122
void ScaleRows(const Vector &s)
Scale the local row i by s(i).
Definition: hypre.cpp:1093
double poly_fraction
Fraction of spectrum to smooth for polynomial relaxation.
Definition: hypre.hpp:457
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:1979
HypreParMatrix * DiscreteGrad(ParFiniteElementSpace *edge_fespace, ParFiniteElementSpace *vert_fespace)
Compute the discrete gradient matrix between the nodal linear and ND1 spaces.
void CopyRowStarts()
Definition: hypre.cpp:787
int poly_scale
Apply the polynomial smoother to A or D^{-1/2} A D^{-1/2}.
Definition: hypre.hpp:459
void SetTol(double tol)
Definition: hypre.cpp:3050
HypreParVector * X1
Definition: hypre.hpp:443
The identity operator as a hypre solver.
Definition: hypre.hpp:652
void SetWindowParameters(double a, double b, double c)
Set parameters for windowing function for FIR smoother.
Definition: hypre.cpp:1658
void EliminateZeroRows()
If a row contains only zeros, set its diagonal to 1.
Definition: hypre.hpp:396
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre&#39;s GMRES.
Definition: hypre.cpp:2135
void Print(const char *fname) const
Prints the locally owned rows in parallel.
Definition: hypre.cpp:182
void EliminateBC(HypreParMatrix &A, HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B)
Definition: hypre.cpp:1415
void SetSystemsOptions(int dim)
Definition: hypre.cpp:2378
HypreLOBPCG(MPI_Comm comm)
Definition: hypre.cpp:3021
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Relax the linear system Ax=b.
Definition: hypre.cpp:1775
hypre_ParVector * StealParVector()
Changes the ownership of the the vector.
Definition: hypre.hpp:106
The BoomerAMG solver in hypre.
Definition: hypre.hpp:705
HYPRE_Int GetGlobalNumRows() const
Definition: hypre.hpp:340
void SetSymmetry(int sym)
Definition: hypre.cpp:2232
int dim
Definition: ex3.cpp:47
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
Definition: hypre.hpp:365
virtual ~HypreParaSails()
Definition: hypre.cpp:2237
The ParaSails preconditioner in hypre.
Definition: hypre.hpp:683
HYPRE_Int GetGlobalNumCols() const
Definition: hypre.hpp:343
void SetMaxIter(int max_iter)
Definition: hypre.cpp:3056
double * l1_norms
l1 norms of the rows of A
Definition: hypre.hpp:467
Data type sparse matrix.
Definition: sparsemat.hpp:38
void SetLogging(int logging)
Definition: hypre.cpp:1974
void SetZeroInintialIterate()
non-hypre setting
Definition: hypre.hpp:587
Jacobi preconditioner in hypre.
Definition: hypre.hpp:666
virtual ~HypreSolver()
Definition: hypre.cpp:1946
HyprePCG(HypreParMatrix &_A)
Definition: hypre.cpp:1953
virtual HYPRE_PtrToParSolverFcn SolveFcn() const =0
hypre&#39;s internal Solve function
void SetKDim(int dim)
Definition: hypre.cpp:2112
void SetResidualConvergenceOptions(int res_frequency=-1, double rtol=0.0)
Definition: hypre.cpp:1992
void SetPrintLevel(int print_level)
Definition: hypre.hpp:746
void GetBlocks(Array2D< HypreParMatrix * > &blocks, bool interleaved_rows=false, bool interleaved_cols=false) const
Definition: hypre.cpp:907
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve the linear system Ax=b.
Definition: hypre.cpp:1899
HypreParMatrix * RAP(HypreParMatrix *A, HypreParMatrix *P)
Returns the matrix P^t * A * P.
Definition: hypre.cpp:1365
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
PCG Solve function.
Definition: hypre.hpp:603
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
Definition: hypre.cpp:3406
HypreParMatrix * DiscreteCurl(ParFiniteElementSpace *face_fespace, ParFiniteElementSpace *edge_fespace)
Compute the discrete curl matrix between the ND1 and RT0 spaces.
HYPRE_Int Randomize(HYPRE_Int seed)
Set random values.
Definition: hypre.cpp:177
double relax_weight
Damping coefficient (usually &lt;= 1)
Definition: hypre.hpp:451
Parallel smoothers in hypre.
Definition: hypre.hpp:433
void SetElasticityOptions(ParFiniteElementSpace *fespace)
Definition: hypre.cpp:2460
void GetDiag(Vector &diag) const
Get the local diagonal of the matrix.
Definition: hypre.cpp:865
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:752
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:657
void BooleanMult(int alpha, int *x, int beta, int *y)
Definition: hypre.hpp:370
HypreParMatrix * A
The linear system matrix.
Definition: hypre.hpp:437
HypreAMS(HypreParMatrix &A, ParFiniteElementSpace *edge_fespace)
Definition: hypre.cpp:2507
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:675
virtual void SetOperator(const Operator &op)
Definition: hypre.cpp:1665
virtual HYPRE_PtrToParSolverFcn SetupFcn() const =0
hypre&#39;s internal Setup function
void SetLogging(int logging)
Definition: hypre.cpp:2117
char OwnsColMap() const
Get colmap ownership flag.
Definition: hypre.hpp:288
virtual ~HypreADS()
Definition: hypre.cpp:2924
HypreParMatrix()
An empty matrix to be used as a reference to an existing matrix.
Definition: hypre.cpp:248
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:673
void SetMaxIter(int max_iter)
Definition: hypre.cpp:1969
HypreParMatrix * GetData()
Definition: hypre.hpp:678
HYPRE_Int * RowPart()
Returns the row partitioning.
Definition: hypre.hpp:302
void SetSOROptions(double relax_weight, double omega)
Set SOR-related parameters.
Definition: hypre.cpp:1623
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:58
HypreParVector * X
Definition: hypre.hpp:536
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:824
void GetEigenvalues(Array< double > &eigenvalues)
Collect the converged eigenvalues.
Definition: hypre.cpp:3142
PCG solver in hypre.
Definition: hypre.hpp:565
GMRES solver in hypre.
Definition: hypre.hpp:614
char OwnsOffd() const
Get offd ownership flag.
Definition: hypre.hpp:286
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:2701
HypreParVector * X
Definition: hypre.hpp:439
void mfem_error(const char *msg)
Definition: error.cpp:23
void Solve()
Solve the eigenproblem.
Definition: hypre.cpp:3353
void SetNumModes(int num_eigs)
Definition: hypre.cpp:3296
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:698
virtual ~HypreDiagScale()
Definition: hypre.hpp:679
int GetNumRows() const
Returns the number of rows in the diagonal block of the ParCSRMatrix.
Definition: hypre.hpp:327
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.hpp:554
double max_eig_est
Maximal eigenvalue estimate for polynomial smoothing.
Definition: hypre.hpp:469
HypreAME(MPI_Comm comm)
Definition: hypre.cpp:3254
HypreParMatrix * Transpose()
Returns the transpose of *this.
Definition: hypre.cpp:929
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:696
virtual ~HypreIdentity()
Definition: hypre.hpp:662
void SetMaxIter(int max_iter)
Definition: hypre.cpp:3310
void SetFIRCoefficients(double max_eig)
Compute window and Chebyshev coefficients for given polynomial order.
Definition: hypre.cpp:1735
void SetRandomSeed(int s)
Definition: hypre.hpp:946
double * fir_coeffs
Combined coefficients for windowing and Chebyshev polynomials.
Definition: hypre.hpp:476
void Threshold(double threshold=0.0)
Remove values smaller in absolute value than some threshold.
Definition: hypre.cpp:1207
double InnerProduct(HypreParVector *x, HypreParVector *y)
Definition: hypre.cpp:196
HYPRE_Int GlobalSize()
Returns the global number of rows.
Definition: hypre.hpp:97
virtual ~HypreSmoother()
Definition: hypre.cpp:1865
HypreParVector(MPI_Comm comm, HYPRE_Int glob_size, HYPRE_Int *col)
Definition: hypre.cpp:50
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:2361
void SetData(double *_data)
Definition: hypre.cpp:172
void InvScaleRows(const Vector &s)
Scale the local row i by 1./s(i)
Definition: hypre.cpp:1128
HYPRE_Int N()
Returns the global number of columns.
Definition: hypre.hpp:308
void SetTaubinOptions(double lambda, double mu, int iter)
Set parameters for Taubin&#39;s lambda-mu method.
Definition: hypre.cpp:1635
HypreParVector * B
Right-hand side and solution vectors.
Definition: hypre.hpp:439
void SetMassMatrix(HypreParMatrix &M)
Definition: hypre.cpp:3346
void SetZeroInintialIterate()
non-hypre setting
Definition: hypre.hpp:632
virtual ~HyprePCG()
Definition: hypre.cpp:2078
int GetNumCols() const
Returns the number of columns in the diagonal block of the ParCSRMatrix.
Definition: hypre.hpp:334
void SetOperator(Operator &A)
Definition: hypre.cpp:3086
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition: hypre.cpp:1984
void SetPolyOptions(int poly_order, double poly_fraction)
Set parameters for polynomial smoothing.
Definition: hypre.cpp:1629
void GetNumIterations(int &num_iterations)
Definition: hypre.hpp:589
void CopyColStarts()
Definition: hypre.cpp:824
int relax_times
Number of relaxation sweeps.
Definition: hypre.hpp:449
void operator*=(double s)
Scale all entries by s: A_scaled = s*A.
Definition: hypre.cpp:1169
void SetPrintLevel(int logging)
Definition: hypre.cpp:3316
double ParNormlp(const Vector &vec, double p, MPI_Comm comm)
Compute the l_p norm of the Vector which is split without overlap across the given communicator...
Definition: hypre.cpp:207
void SetOwnership(int own)
Sets ownership of the internal hypre_ParVector.
Definition: hypre.hpp:109
Abstract class for hypre&#39;s solvers and preconditioners.
Definition: hypre.hpp:529
char OwnsDiag() const
Get diag ownership flag.
Definition: hypre.hpp:284
HypreParVector & operator=(double d)
Set constant values.
Definition: hypre.cpp:150
const double alpha
Definition: ex15.cpp:337
Vector data type.
Definition: vector.hpp:33
HypreGMRES(HypreParMatrix &_A)
Definition: hypre.cpp:2084
hypre_ParCSRMatrix * StealData()
Changes the ownership of the the matrix.
Definition: hypre.cpp:773
void SetPrecondUsageMode(int pcg_mode)
Definition: hypre.cpp:3071
virtual ~HypreParMatrix()
Calls hypre&#39;s destroy function.
Definition: hypre.hpp:414
HypreParMatrix * A
The linear system matrix.
Definition: hypre.hpp:533
void SetMaxIter(int max_iter)
Definition: hypre.cpp:2107
void GetOffd(SparseMatrix &offd, HYPRE_Int *&cmap) const
Get the local off-diagonal block. NOTE: &#39;offd&#39; will not own any data.
Definition: hypre.cpp:901
HYPRE_Int * GetColStarts() const
Definition: hypre.hpp:348
HypreParVector & GetEigenvector(unsigned int i)
Extract a single eigenvector.
Definition: hypre.cpp:3395
double omega
SOR parameter (usually in (0,2))
Definition: hypre.hpp:453
HYPRE_Int * GetRowStarts() const
Definition: hypre.hpp:346
Base class for solvers.
Definition: operator.hpp:102
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:791
int GetOwnership() const
Gets ownership of the internal hypre_ParVector.
Definition: hypre.hpp:112
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
PCG Setup function.
Definition: hypre.hpp:600
Abstract operator.
Definition: operator.hpp:21
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:150
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:754
~HypreParVector()
Calls hypre&#39;s destroy function.
Definition: hypre.cpp:187
void SetNumModes(int num_eigs)
Definition: hypre.hpp:944
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre&#39;s PCG.
Definition: hypre.cpp:2005
HypreParVector * Z
Definition: hypre.hpp:441
void SetSingularProblem()
Set this option when solving a curl-curl problem with zero mass term.
Definition: hypre.hpp:786
void Solve()
Solve the eigenproblem.
Definition: hypre.cpp:3160
void Read(MPI_Comm comm, const char *fname)
Reads the matrix from a file.
Definition: hypre.cpp:1288
HypreParVector * V
Temporary vectors.
Definition: hypre.hpp:441
void SetType(HypreSmoother::Type type, int relax_times=1)
Set the relaxation type and number of sweeps.
Definition: hypre.cpp:1617
HypreParaSails(HypreParMatrix &A)
Definition: hypre.cpp:2209
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
GMRES Setup function.
Definition: hypre.hpp:638
int poly_order
Order of the smoothing polynomial.
Definition: hypre.hpp:455
HYPRE_Int * Partitioning()
Returns the row partitioning.
Definition: hypre.hpp:94
double lambda
Taubin&#39;s lambda-mu method parameters.
Definition: hypre.hpp:462
HypreParMatrix * ParMult(HypreParMatrix *A, HypreParMatrix *B)
Returns the matrix A * B.
Definition: hypre.cpp:1355
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:826