MFEM  v3.3
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 #ifdef MFEM_USE_SUNDIALS
37 #include <nvector/nvector_parhyp.h>
38 #endif
39 
40 namespace mfem
41 {
42 
43 class ParFiniteElementSpace;
44 class HypreParMatrix;
45 
46 namespace internal
47 {
48 
49 template <typename int_type>
50 inline int to_int(int_type i)
51 {
52  MFEM_ASSERT(int_type(int(i)) == i, "overflow converting int_type to int");
53  return int(i);
54 }
55 
56 // Specialization for to_int(int)
57 template <> inline int to_int(int i) { return i; }
58 
59 // Convert a HYPRE_Int to int
60 #ifdef HYPRE_BIGINT
61 template <>
62 inline int to_int(HYPRE_Int i)
63 {
64  MFEM_ASSERT(HYPRE_Int(int(i)) == i, "overflow converting HYPRE_Int to int");
65  return int(i);
66 }
67 #endif
68 
69 }
70 
71 /// Wrapper for hypre's parallel vector class
72 class HypreParVector : public Vector
73 {
74 private:
75  int own_ParVector;
76 
77  /// The actual object
78  hypre_ParVector *x;
79 
80  friend class HypreParMatrix;
81 
82  // Set Vector::data and Vector::size from *x
83  inline void _SetDataAndSize_();
84 
85 public:
86  /** Creates vector with given global size and partitioning of the columns.
87  Processor P owns columns [col[P],col[P+1]) */
88  HypreParVector(MPI_Comm comm, HYPRE_Int glob_size, HYPRE_Int *col);
89  /** Creates vector with given global size, partitioning of the columns,
90  and data. The data must be allocated and destroyed outside.
91  If _data is NULL, a dummy vector without a valid data array will
92  be created. */
93  HypreParVector(MPI_Comm comm, HYPRE_Int glob_size, double *_data,
94  HYPRE_Int *col);
95  /// Creates vector compatible with y
97  /// Creates vector compatible with (i.e. in the domain of) A or A^T
98  explicit HypreParVector(const HypreParMatrix &A, int transpose = 0);
99  /// Creates vector wrapping y
100  explicit HypreParVector(HYPRE_ParVector y);
101  /// Create a true dof parallel vector on a given ParFiniteElementSpace
102  explicit HypreParVector(ParFiniteElementSpace *pfes);
103 
104  /// MPI communicator
105  MPI_Comm GetComm() { return x->comm; }
106 
107  /// Returns the row partitioning
108  inline HYPRE_Int *Partitioning() { return x->partitioning; }
109 
110  /// Returns the global number of rows
111  inline HYPRE_Int GlobalSize() { return x->global_size; }
112 
113  /// Typecasting to hypre's hypre_ParVector*
114  operator hypre_ParVector*() const { return x; }
115 #ifndef HYPRE_PAR_VECTOR_STRUCT
116  /// Typecasting to hypre's HYPRE_ParVector, a.k.a. void *
117  operator HYPRE_ParVector() const { return (HYPRE_ParVector) x; }
118 #endif
119  /// Changes the ownership of the the vector
120  hypre_ParVector *StealParVector() { own_ParVector = 0; return x; }
121 
122  /// Sets ownership of the internal hypre_ParVector
123  void SetOwnership(int own) { own_ParVector = own; }
124 
125  /// Gets ownership of the internal hypre_ParVector
126  int GetOwnership() const { return own_ParVector; }
127 
128  /// Returns the global vector in each processor
129  Vector* GlobalVector() const;
130 
131  /// Set constant values
132  HypreParVector& operator= (double d);
133  /// Define '=' for hypre vectors.
135 
136  /** Sets the data of the Vector and the hypre_ParVector to _data.
137  Must be used only for HypreParVectors that do not own the data,
138  e.g. created with the constructor:
139  HypreParVector(MPI_Comm comm, HYPRE_Int glob_size, double *_data,
140  HYPRE_Int *col). */
141  void SetData(double *_data);
142 
143  /// Set random values
144  HYPRE_Int Randomize(HYPRE_Int seed);
145 
146  /// Prints the locally owned rows in parallel
147  void Print(const char *fname) const;
148 
149  /// Calls hypre's destroy function
150  ~HypreParVector();
151 
152 #ifdef MFEM_USE_SUNDIALS
153  /// Return a new wrapper SUNDIALS N_Vector of type SUNDIALS_NVEC_PARHYP.
154  /** The returned N_Vector must be destroyed by the caller. */
155  virtual N_Vector ToNVector() { return N_VMake_ParHyp(x); }
156 
157  /** @brief Update an existing wrapper SUNDIALS N_Vector of type
158  SUNDIALS_NVEC_PARHYP to point to this Vector. */
159  virtual void ToNVector(N_Vector &nv);
160 #endif
161 };
162 
163 /// Returns the inner product of x and y
164 double InnerProduct(HypreParVector &x, HypreParVector &y);
165 double InnerProduct(HypreParVector *x, HypreParVector *y);
166 
167 
168 /** @brief Compute the l_p norm of the Vector which is split without overlap
169  across the given communicator. */
170 double ParNormlp(const Vector &vec, double p, MPI_Comm comm);
171 
172 
173 /// Wrapper for hypre's ParCSR matrix class
174 class HypreParMatrix : public Operator
175 {
176 private:
177  /// The actual object
178  hypre_ParCSRMatrix *A;
179 
180  /// Auxiliary vectors for typecasting
181  mutable HypreParVector *X, *Y;
182 
183  // Flags indicating ownership of A->diag->{i,j,data}, A->offd->{i,j,data},
184  // and A->col_map_offd.
185  // The possible values for diagOwner are:
186  // -1: no special treatment of A->diag (default)
187  // 0: prevent hypre from destroying A->diag->{i,j,data}
188  // 1: same as 0, plus take ownership of A->diag->{i,j}
189  // 2: same as 0, plus take ownership of A->diag->data
190  // 3: same as 0, plus take ownership of A->diag->{i,j,data}
191  // The same values and rules apply to offdOwner and A->offd.
192  // The possible values for colMapOwner are:
193  // -1: no special treatment of A->col_map_offd (default)
194  // 0: prevent hypre from destroying A->col_map_offd
195  // 1: same as 0, plus take ownership of A->col_map_offd
196  // All owned arrays are destroyed with 'delete []'.
197  signed char diagOwner, offdOwner, colMapOwner;
198 
199  // Does the object own the pointer A?
200  signed char ParCSROwner;
201 
202  // Initialize with defaults. Does not initialize inherited members.
203  void Init();
204 
205  // Delete all owned data. Does not perform re-initialization with defaults.
206  void Destroy();
207 
208  // Copy (shallow or deep, based on HYPRE_BIGINT) the I and J arrays from csr
209  // to hypre_csr. Shallow copy the data. Return the appropriate ownership
210  // flag.
211  static char CopyCSR(SparseMatrix *csr, hypre_CSRMatrix *hypre_csr);
212  // Copy (shallow or deep, based on HYPRE_BIGINT) the I and J arrays from
213  // bool_csr to hypre_csr. Allocate the data array and set it to all ones.
214  // Return the appropriate ownership flag.
215  static char CopyBoolCSR(Table *bool_csr, hypre_CSRMatrix *hypre_csr);
216 
217  // Copy the j array of a hypre_CSRMatrix to the given J array, converting
218  // the indices from HYPRE_Int to int.
219  static void CopyCSR_J(hypre_CSRMatrix *hypre_csr, int *J);
220 
221 public:
222  /// An empty matrix to be used as a reference to an existing matrix
223  HypreParMatrix();
224 
225  /// Converts hypre's format to HypreParMatrix
226  explicit HypreParMatrix(hypre_ParCSRMatrix *a)
227  {
228  Init();
229  A = a;
230  height = GetNumRows();
231  width = GetNumCols();
232  }
233 
234  /** Creates block-diagonal square parallel matrix. Diagonal is given by diag
235  which must be in CSR format (finalized). The new HypreParMatrix does not
236  take ownership of any of the input arrays.
237  @warning The ordering of the columns in each row in @a *diag may be
238  changed by this constructor to ensure that the first entry in each row is
239  the diagonal one. This is expected by most hypre functions. */
240  HypreParMatrix(MPI_Comm comm, HYPRE_Int glob_size, HYPRE_Int *row_starts,
241  SparseMatrix *diag);
242 
243  /** Creates block-diagonal rectangular parallel matrix. Diagonal is given by
244  diag which must be in CSR format (finalized). The new HypreParMatrix does
245  not take ownership of any of the input arrays. */
246  HypreParMatrix(MPI_Comm comm, HYPRE_Int global_num_rows,
247  HYPRE_Int global_num_cols, HYPRE_Int *row_starts,
248  HYPRE_Int *col_starts, SparseMatrix *diag);
249 
250  /** Creates general (rectangular) parallel matrix. The new HypreParMatrix
251  does not take ownership of any of the input arrays. */
252  HypreParMatrix(MPI_Comm comm, HYPRE_Int global_num_rows,
253  HYPRE_Int global_num_cols, HYPRE_Int *row_starts,
254  HYPRE_Int *col_starts, SparseMatrix *diag, SparseMatrix *offd,
255  HYPRE_Int *cmap);
256 
257  /** Creates general (rectangular) parallel matrix. The new HypreParMatrix
258  takes ownership of all input arrays, except col_starts and row_starts. */
259  HypreParMatrix(MPI_Comm comm,
260  HYPRE_Int global_num_rows, HYPRE_Int global_num_cols,
261  HYPRE_Int *row_starts, HYPRE_Int *col_starts,
262  HYPRE_Int *diag_i, HYPRE_Int *diag_j, double *diag_data,
263  HYPRE_Int *offd_i, HYPRE_Int *offd_j, double *offd_data,
264  HYPRE_Int offd_num_cols, HYPRE_Int *offd_col_map);
265 
266  /// Creates a parallel matrix from SparseMatrix on processor 0.
267  HypreParMatrix(MPI_Comm comm, HYPRE_Int *row_starts, HYPRE_Int *col_starts,
268  SparseMatrix *a);
269 
270  /** Creates boolean block-diagonal rectangular parallel matrix. The new
271  HypreParMatrix does not take ownership of any of the input arrays. */
272  HypreParMatrix(MPI_Comm comm, HYPRE_Int global_num_rows,
273  HYPRE_Int global_num_cols, HYPRE_Int *row_starts,
274  HYPRE_Int *col_starts, Table *diag);
275 
276  /** Creates boolean rectangular parallel matrix. The new HypreParMatrix takes
277  ownership of the arrays i_diag, j_diag, i_offd, j_offd, and cmap; does
278  not take ownership of the arrays row and col. */
279  HypreParMatrix(MPI_Comm comm, int id, int np, HYPRE_Int *row, HYPRE_Int *col,
280  HYPRE_Int *i_diag, HYPRE_Int *j_diag, HYPRE_Int *i_offd,
281  HYPRE_Int *j_offd, HYPRE_Int *cmap, HYPRE_Int cmap_size);
282 
283  /** Creates a general parallel matrix from a local CSR matrix on each
284  processor described by the I, J and data arrays. The local matrix should
285  be of size (local) nrows by (global) glob_ncols. The new parallel matrix
286  contains copies of all input arrays (so they can be deleted). */
287  HypreParMatrix(MPI_Comm comm, int nrows, HYPRE_Int glob_nrows,
288  HYPRE_Int glob_ncols, int *I, HYPRE_Int *J,
289  double *data, HYPRE_Int *rows, HYPRE_Int *cols);
290 
291  /// Make this HypreParMatrix a reference to 'master'
292  void MakeRef(const HypreParMatrix &master);
293 
294  /// MPI communicator
295  MPI_Comm GetComm() const { return A->comm; }
296 
297  /// Typecasting to hypre's hypre_ParCSRMatrix*
298  operator hypre_ParCSRMatrix*() const { return A; }
299 #ifndef HYPRE_PAR_CSR_MATRIX_STRUCT
300  /// Typecasting to hypre's HYPRE_ParCSRMatrix, a.k.a. void *
301  operator HYPRE_ParCSRMatrix() { return (HYPRE_ParCSRMatrix) A; }
302 #endif
303  /// Changes the ownership of the the matrix
304  hypre_ParCSRMatrix* StealData();
305 
306  /// Explicitly set the three ownership flags, see docs for diagOwner etc.
307  void SetOwnerFlags(signed char diag, signed char offd, signed char colmap)
308  { diagOwner = diag, offdOwner = offd, colMapOwner = colmap; }
309 
310  /// Get diag ownership flag
311  signed char OwnsDiag() const { return diagOwner; }
312  /// Get offd ownership flag
313  signed char OwnsOffd() const { return offdOwner; }
314  /// Get colmap ownership flag
315  signed char OwnsColMap() const { return colMapOwner; }
316 
317  /** If the HypreParMatrix does not own the row-starts array, make a copy of
318  it that the HypreParMatrix will own. If the col-starts array is the same
319  as the row-starts array, col-starts is also replaced. */
320  void CopyRowStarts();
321  /** If the HypreParMatrix does not own the col-starts array, make a copy of
322  it that the HypreParMatrix will own. If the row-starts array is the same
323  as the col-starts array, row-starts is also replaced. */
324  void CopyColStarts();
325 
326  /// Returns the global number of nonzeros
327  inline HYPRE_Int NNZ() const { return A->num_nonzeros; }
328  /// Returns the row partitioning
329  inline HYPRE_Int *RowPart() { return A->row_starts; }
330  /// Returns the column partitioning
331  inline HYPRE_Int *ColPart() { return A->col_starts; }
332  /// Returns the row partitioning (const version)
333  inline const HYPRE_Int *RowPart() const { return A->row_starts; }
334  /// Returns the column partitioning (const version)
335  inline const HYPRE_Int *ColPart() const { return A->col_starts; }
336  /// Returns the global number of rows
337  inline HYPRE_Int M() const { return A->global_num_rows; }
338  /// Returns the global number of columns
339  inline HYPRE_Int N() const { return A->global_num_cols; }
340 
341  /// Get the local diagonal of the matrix.
342  void GetDiag(Vector &diag) const;
343  /// Get the local diagonal block. NOTE: 'diag' will not own any data.
344  void GetDiag(SparseMatrix &diag) const;
345  /// Get the local off-diagonal block. NOTE: 'offd' will not own any data.
346  void GetOffd(SparseMatrix &offd, HYPRE_Int* &cmap) const;
347 
348  /** Split the matrix into M x N equally sized blocks of parallel matrices.
349  The size of 'blocks' must already be set to M x N. */
350  void GetBlocks(Array2D<HypreParMatrix*> &blocks,
351  bool interleaved_rows = false,
352  bool interleaved_cols = false) const;
353 
354  /// Returns the transpose of *this
356 
357  /// Returns the number of rows in the diagonal block of the ParCSRMatrix
358  int GetNumRows() const
359  {
360  return internal::to_int(
361  hypre_CSRMatrixNumRows(hypre_ParCSRMatrixDiag(A)));
362  }
363 
364  /// Returns the number of columns in the diagonal block of the ParCSRMatrix
365  int GetNumCols() const
366  {
367  return internal::to_int(
368  hypre_CSRMatrixNumCols(hypre_ParCSRMatrixDiag(A)));
369  }
370 
371  HYPRE_Int GetGlobalNumRows() const
372  { return hypre_ParCSRMatrixGlobalNumRows(A); }
373 
374  HYPRE_Int GetGlobalNumCols() const
375  { return hypre_ParCSRMatrixGlobalNumCols(A); }
376 
377  HYPRE_Int *GetRowStarts() const { return hypre_ParCSRMatrixRowStarts(A); }
378 
379  HYPRE_Int *GetColStarts() const { return hypre_ParCSRMatrixColStarts(A); }
380 
381  /// Computes y = alpha * A * x + beta * y
382  HYPRE_Int Mult(HypreParVector &x, HypreParVector &y,
383  double alpha = 1.0, double beta = 0.0);
384  /// Computes y = alpha * A * x + beta * y
385  HYPRE_Int Mult(HYPRE_ParVector x, HYPRE_ParVector y,
386  double alpha = 1.0, double beta = 0.0);
387  /// Computes y = alpha * A^t * x + beta * y
389  double alpha = 1.0, double beta = 0.0);
390 
391  void Mult(double a, const Vector &x, double b, Vector &y) const;
392  void MultTranspose(double a, const Vector &x, double b, Vector &y) const;
393 
394  virtual void Mult(const Vector &x, Vector &y) const
395  { Mult(1.0, x, 0.0, y); }
396  virtual void MultTranspose(const Vector &x, Vector &y) const
397  { MultTranspose(1.0, x, 0.0, y); }
398 
399  /** The "Boolean" analog of y = alpha * A * x + beta * y, where elements in
400  the sparsity pattern of the matrix are treated as "true". */
401  void BooleanMult(int alpha, int *x, int beta, int *y)
402  {
403  internal::hypre_ParCSRMatrixBooleanMatvec(A, alpha, x, beta, y);
404  }
405 
406  /// Initialize all entries with value.
407  HypreParMatrix &operator=(double value)
408  { internal::hypre_ParCSRMatrixSetConstantValues(A, value); return *this; }
409 
410  /** Perform the operation `*this += B`, assuming that both matrices use the
411  same row and column partitions and the same col_map_offd arrays. We also
412  assume that the sparsity pattern of `*this` contains that of `B`. */
413  HypreParMatrix &operator+=(const HypreParMatrix &B) { return Add(1.0, B); }
414 
415  /** Perform the operation `*this += beta*B`, assuming that both matrices use
416  the same row and column partitions and the same col_map_offd arrays. We
417  also assume that the sparsity pattern of `*this` contains that of `B`. */
418  HypreParMatrix &Add(const double beta, const HypreParMatrix &B)
419  {
420  MFEM_VERIFY(internal::hypre_ParCSRMatrixSum(A, beta, B.A) == 0,
421  "error in hypre_ParCSRMatrixSum");
422  return *this;
423  }
424 
425  /** Multiply A on the left by a block-diagonal parallel matrix D. Return
426  a new parallel matrix, D*A. If D has a different number of rows than A,
427  D's row starts array needs to be given (as returned by the methods
428  GetDofOffsets/GetTrueDofOffsets of ParFiniteElementSpace). The new matrix
429  D*A uses copies of the row-, column-starts arrays, so "this" matrix and
430  "row_starts" can be deleted.
431  NOTE: this operation is local and does not require communication. */
433  HYPRE_Int* row_starts = NULL) const;
434 
435  /// Scale the local row i by s(i).
436  void ScaleRows(const Vector & s);
437  /// Scale the local row i by 1./s(i)
438  void InvScaleRows(const Vector & s);
439  /// Scale all entries by s: A_scaled = s*A.
440  void operator*=(double s);
441 
442  /// Remove values smaller in absolute value than some threshold
443  void Threshold(double threshold = 0.0);
444 
445  /// If a row contains only zeros, set its diagonal to 1.
446  void EliminateZeroRows() { hypre_ParCSRMatrixFixZeroRows(A); }
447 
448  /** Eliminate rows and columns from the matrix, and rows from the vector B.
449  Modify B with the BC values in X. */
450  void EliminateRowsCols(const Array<int> &rows_cols, const HypreParVector &X,
451  HypreParVector &B);
452 
453  /** Eliminate rows and columns from the matrix and store the eliminated
454  elements in a new matrix Ae (returned), so that the modified matrix and
455  Ae sum to the original matrix. */
456  HypreParMatrix* EliminateRowsCols(const Array<int> &rows_cols);
457 
458  /// Prints the locally owned rows in parallel
459  void Print(const char *fname, HYPRE_Int offi = 0, HYPRE_Int offj = 0);
460  /// Reads the matrix from a file
461  void Read(MPI_Comm comm, const char *fname);
462 
463  /// Calls hypre's destroy function
464  virtual ~HypreParMatrix() { Destroy(); }
465 
466  Type GetType() const { return HYPRE_PARCSR; }
467 };
468 
469 /** @brief Return a new matrix `C = alpha*A + beta*B`, assuming that both `A`
470  and `B` use the same row and column partitions and the same `col_map_offd`
471  arrays. */
472 HypreParMatrix *Add(double alpha, const HypreParMatrix &A,
473  double beta, const HypreParMatrix &B);
474 
475 /// Returns the matrix A * B
476 HypreParMatrix * ParMult(HypreParMatrix *A, HypreParMatrix *B);
477 
478 /// Returns the matrix P^t * A * P
479 HypreParMatrix * RAP(HypreParMatrix *A, HypreParMatrix *P);
480 /// Returns the matrix Rt^t * A * P
481 HypreParMatrix * RAP(HypreParMatrix * Rt, HypreParMatrix *A, HypreParMatrix *P);
482 
483 /** Eliminate essential BC specified by 'ess_dof_list' from the solution X to
484  the r.h.s. B. Here A is a matrix with eliminated BC, while Ae is such that
485  (A+Ae) is the original (Neumann) matrix before elimination. */
486 void EliminateBC(HypreParMatrix &A, HypreParMatrix &Ae,
487  const Array<int> &ess_dof_list, const Vector &X, Vector &B);
488 
489 
490 /// Parallel smoothers in hypre
491 class HypreSmoother : public Solver
492 {
493 protected:
494  /// The linear system matrix
496  /// Right-hand side and solution vectors
497  mutable HypreParVector *B, *X;
498  /// Temporary vectors
499  mutable HypreParVector *V, *Z;
500  /// FIR Filter Temporary Vectors
501  mutable HypreParVector *X0, *X1;
502 
503  /** Smoother type from hypre_ParCSRRelax() in ams.c plus extensions, see the
504  enumeration Type below. */
505  int type;
506  /// Number of relaxation sweeps
508  /// Damping coefficient (usually <= 1)
509  double relax_weight;
510  /// SOR parameter (usually in (0,2))
511  double omega;
512  /// Order of the smoothing polynomial
514  /// Fraction of spectrum to smooth for polynomial relaxation
516  /// Apply the polynomial smoother to A or D^{-1/2} A D^{-1/2}
518 
519  /// Taubin's lambda-mu method parameters
520  double lambda;
521  double mu;
523 
524  /// l1 norms of the rows of A
525  double *l1_norms;
526  /// If set, take absolute values of the computed l1_norms
528  /// Maximal eigenvalue estimate for polynomial smoothing
529  double max_eig_est;
530  /// Minimal eigenvalue estimate for polynomial smoothing
531  double min_eig_est;
532  /// Parameters for windowing function of FIR filter
533  double window_params[3];
534 
535  /// Combined coefficients for windowing and Chebyshev polynomials.
536  double* fir_coeffs;
537 
538 public:
539  /** Hypre smoother types:
540  0 = Jacobi
541  1 = l1-scaled Jacobi
542  2 = l1-scaled block Gauss-Seidel/SSOR
543  4 = truncated l1-scaled block Gauss-Seidel/SSOR
544  5 = lumped Jacobi
545  6 = Gauss-Seidel
546  16 = Chebyshev
547  1001 = Taubin polynomial smoother
548  1002 = FIR polynomial smoother. */
549  enum Type { Jacobi = 0, l1Jacobi = 1, l1GS = 2, l1GStr = 4, lumpedJacobi = 5,
550  GS = 6, Chebyshev = 16, Taubin = 1001, FIR = 1002
551  };
552 
553  HypreSmoother();
554 
556  int relax_times = 1, double relax_weight = 1.0,
557  double omega = 1.0, int poly_order = 2,
558  double poly_fraction = .3);
559 
560  /// Set the relaxation type and number of sweeps
562  /// Set SOR-related parameters
563  void SetSOROptions(double relax_weight, double omega);
564  /// Set parameters for polynomial smoothing
565  void SetPolyOptions(int poly_order, double poly_fraction);
566  /// Set parameters for Taubin's lambda-mu method
567  void SetTaubinOptions(double lambda, double mu, int iter);
568 
569  /// Convenience function for setting canonical windowing parameters
570  void SetWindowByName(const char* window_name);
571  /// Set parameters for windowing function for FIR smoother.
572  void SetWindowParameters(double a, double b, double c);
573  /// Compute window and Chebyshev coefficients for given polynomial order.
574  void SetFIRCoefficients(double max_eig);
575 
576  /// After computing l1-norms, replace them with their absolute values.
577  /** By default, the l1-norms take their sign from the corresponding diagonal
578  entries in the associated matrix. */
579  void SetPositiveDiagonal(bool pos = true) { pos_l1_norms = pos; }
580 
581  /** Set/update the associated operator. Must be called after setting the
582  HypreSmoother type and options. */
583  virtual void SetOperator(const Operator &op);
584 
585  /// Relax the linear system Ax=b
586  virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
587  virtual void Mult(const Vector &b, Vector &x) const;
588 
589  virtual ~HypreSmoother();
590 };
591 
592 
593 /// Abstract class for hypre's solvers and preconditioners
594 class HypreSolver : public Solver
595 {
596 protected:
597  /// The linear system matrix
599 
600  /// Right-hand side and solution vector
601  mutable HypreParVector *B, *X;
602 
603  /// Was hypre's Setup function called already?
604  mutable int setup_called;
605 
606 public:
607  HypreSolver();
608 
610 
611  /// Typecast to HYPRE_Solver -- return the solver
612  virtual operator HYPRE_Solver() const = 0;
613 
614  /// hypre's internal Setup function
615  virtual HYPRE_PtrToParSolverFcn SetupFcn() const = 0;
616  /// hypre's internal Solve function
617  virtual HYPRE_PtrToParSolverFcn SolveFcn() const = 0;
618 
619  virtual void SetOperator(const Operator &op)
620  { mfem_error("HypreSolvers do not support SetOperator!"); }
621 
622  /// Solve the linear system Ax=b
623  virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
624  virtual void Mult(const Vector &b, Vector &x) const;
625 
626  virtual ~HypreSolver();
627 };
628 
629 /// PCG solver in hypre
630 class HyprePCG : public HypreSolver
631 {
632 private:
633  HYPRE_Solver pcg_solver;
634 
635 public:
637 
638  void SetTol(double tol);
639  void SetMaxIter(int max_iter);
640  void SetLogging(int logging);
641  void SetPrintLevel(int print_lvl);
642 
643  /// Set the hypre solver to be used as a preconditioner
644  void SetPreconditioner(HypreSolver &precond);
645 
646  /** Use the L2 norm of the residual for measuring PCG convergence, plus
647  (optionally) 1) periodically recompute true residuals from scratch; and
648  2) enable residual-based stopping criteria. */
649  void SetResidualConvergenceOptions(int res_frequency=-1, double rtol=0.0);
650 
651  /// non-hypre setting
653 
654  void GetNumIterations(int &num_iterations)
655  {
656  HYPRE_Int num_it;
657  HYPRE_ParCSRPCGGetNumIterations(pcg_solver, &num_it);
658  num_iterations = internal::to_int(num_it);
659  }
660 
661  /// The typecast to HYPRE_Solver returns the internal pcg_solver
662  virtual operator HYPRE_Solver() const { return pcg_solver; }
663 
664  /// PCG Setup function
665  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
666  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRPCGSetup; }
667  /// PCG Solve function
668  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
669  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRPCGSolve; }
670 
671  /// Solve Ax=b with hypre's PCG
672  virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
673  using HypreSolver::Mult;
674 
675  virtual ~HyprePCG();
676 };
677 
678 /// GMRES solver in hypre
679 class HypreGMRES : public HypreSolver
680 {
681 private:
682  HYPRE_Solver gmres_solver;
683 
684 public:
686 
687  void SetTol(double tol);
688  void SetMaxIter(int max_iter);
689  void SetKDim(int dim);
690  void SetLogging(int logging);
691  void SetPrintLevel(int print_lvl);
692 
693  /// Set the hypre solver to be used as a preconditioner
694  void SetPreconditioner(HypreSolver &precond);
695 
696  /// non-hypre setting
698 
699  /// The typecast to HYPRE_Solver returns the internal gmres_solver
700  virtual operator HYPRE_Solver() const { return gmres_solver; }
701 
702  /// GMRES Setup function
703  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
704  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRGMRESSetup; }
705  /// GMRES Solve function
706  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
707  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRGMRESSolve; }
708 
709  /// Solve Ax=b with hypre's GMRES
710  virtual void Mult (const HypreParVector &b, HypreParVector &x) const;
711  using HypreSolver::Mult;
712 
713  virtual ~HypreGMRES();
714 };
715 
716 /// The identity operator as a hypre solver
718 {
719 public:
720  virtual operator HYPRE_Solver() const { return NULL; }
721 
722  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
723  { return (HYPRE_PtrToParSolverFcn) hypre_ParKrylovIdentitySetup; }
724  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
725  { return (HYPRE_PtrToParSolverFcn) hypre_ParKrylovIdentity; }
726 
727  virtual ~HypreIdentity() { }
728 };
729 
730 /// Jacobi preconditioner in hypre
732 {
733 public:
736  virtual operator HYPRE_Solver() const { return NULL; }
737 
738  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
739  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRDiagScaleSetup; }
740  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
741  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRDiagScale; }
742 
743  HypreParMatrix* GetData() { return A; }
744  virtual ~HypreDiagScale() { }
745 };
746 
747 /// The ParaSails preconditioner in hypre
749 {
750 private:
751  HYPRE_Solver sai_precond;
752 
753 public:
755 
756  void SetSymmetry(int sym);
757 
758  /// The typecast to HYPRE_Solver returns the internal sai_precond
759  virtual operator HYPRE_Solver() const { return sai_precond; }
760 
761  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
762  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParaSailsSetup; }
763  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
764  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParaSailsSolve; }
765 
766  virtual ~HypreParaSails();
767 };
768 
769 /// The BoomerAMG solver in hypre
771 {
772 private:
773  HYPRE_Solver amg_precond;
774 
775  /// Rigid body modes
777 
778  /// Finite element space for elasticity problems, see SetElasticityOptions()
779  ParFiniteElementSpace *fespace;
780 
781  /// Recompute the rigid-body modes vectors (in the rbms array)
782  void RecomputeRBMs();
783 
784  /// Default, generally robust, BoomerAMG options
785  void SetDefaultOptions();
786 
787  // If amg_precond is NULL, allocates it and sets default options.
788  // Otherwise saves the options from amg_precond, destroys it, allocates a new
789  // one, and sets its options to the saved values.
790  void ResetAMGPrecond();
791 
792 public:
793  HypreBoomerAMG();
794 
796 
797  virtual void SetOperator(const Operator &op);
798 
799  /** More robust options for systems, such as elasticity. Note that BoomerAMG
800  assumes Ordering::byVDIM in the finite element space used to generate the
801  matrix A. */
802  void SetSystemsOptions(int dim);
803 
804  /** A special elasticity version of BoomerAMG that takes advantage of
805  geometric rigid body modes and could perform better on some problems, see
806  "Improving algebraic multigrid interpolation operators for linear
807  elasticity problems", Baker, Kolev, Yang, NLAA 2009, DOI:10.1002/nla.688.
808  As with SetSystemsOptions(), this solver assumes Ordering::byVDIM. */
810 
811  void SetPrintLevel(int print_level)
812  { HYPRE_BoomerAMGSetPrintLevel(amg_precond, print_level); }
813 
814  /// The typecast to HYPRE_Solver returns the internal amg_precond
815  virtual operator HYPRE_Solver() const { return amg_precond; }
816 
817  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
818  { return (HYPRE_PtrToParSolverFcn) HYPRE_BoomerAMGSetup; }
819  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
820  { return (HYPRE_PtrToParSolverFcn) HYPRE_BoomerAMGSolve; }
821 
822  virtual ~HypreBoomerAMG();
823 };
824 
825 /// Compute the discrete gradient matrix between the nodal linear and ND1 spaces
826 HypreParMatrix* DiscreteGrad(ParFiniteElementSpace *edge_fespace,
827  ParFiniteElementSpace *vert_fespace);
828 /// Compute the discrete curl matrix between the ND1 and RT0 spaces
829 HypreParMatrix* DiscreteCurl(ParFiniteElementSpace *face_fespace,
830  ParFiniteElementSpace *edge_fespace);
831 
832 /// The Auxiliary-space Maxwell Solver in hypre
833 class HypreAMS : public HypreSolver
834 {
835 private:
836  HYPRE_Solver ams;
837 
838  /// Vertex coordinates
839  HypreParVector *x, *y, *z;
840  /// Discrete gradient matrix
841  HypreParMatrix *G;
842  /// Nedelec interpolation matrix and its components
843  HypreParMatrix *Pi, *Pix, *Piy, *Piz;
844 
845 public:
847 
848  void SetPrintLevel(int print_lvl);
849 
850  /// Set this option when solving a curl-curl problem with zero mass term
851  void SetSingularProblem() { HYPRE_AMSSetBetaPoissonMatrix(ams, NULL); }
852 
853  /// The typecast to HYPRE_Solver returns the internal ams object
854  virtual operator HYPRE_Solver() const { return ams; }
855 
856  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
857  { return (HYPRE_PtrToParSolverFcn) HYPRE_AMSSetup; }
858  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
859  { return (HYPRE_PtrToParSolverFcn) HYPRE_AMSSolve; }
860 
861  virtual ~HypreAMS();
862 };
863 
864 /// The Auxiliary-space Divergence Solver in hypre
865 class HypreADS : public HypreSolver
866 {
867 private:
868  HYPRE_Solver ads;
869 
870  /// Vertex coordinates
871  HypreParVector *x, *y, *z;
872  /// Discrete gradient matrix
873  HypreParMatrix *G;
874  /// Discrete curl matrix
875  HypreParMatrix *C;
876  /// Nedelec interpolation matrix and its components
877  HypreParMatrix *ND_Pi, *ND_Pix, *ND_Piy, *ND_Piz;
878  /// Raviart-Thomas interpolation matrix and its components
879  HypreParMatrix *RT_Pi, *RT_Pix, *RT_Piy, *RT_Piz;
880 
881 public:
883 
884  void SetPrintLevel(int print_lvl);
885 
886  /// The typecast to HYPRE_Solver returns the internal ads object
887  virtual operator HYPRE_Solver() const { return ads; }
888 
889  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
890  { return (HYPRE_PtrToParSolverFcn) HYPRE_ADSSetup; }
891  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
892  { return (HYPRE_PtrToParSolverFcn) HYPRE_ADSSolve; }
893 
894  virtual ~HypreADS();
895 };
896 
897 /** LOBPCG eigenvalue solver in hypre
898 
899  The Locally Optimal Block Preconditioned Conjugate Gradient (LOBPCG)
900  eigenvalue solver is designed to find the lowest eigenmodes of the
901  generalized eigenvalue problem:
902  A x = lambda M x
903  where A is symmetric, potentially indefinite and M is symmetric positive
904  definite. The eigenvectors are M-orthonormal, meaning that
905  x^T M x = 1 and x^T M y = 0,
906  if x and y are distinct eigenvectors. The matrix M is optional and is
907  assumed to be the identity if left unset.
908 
909  The efficiency of LOBPCG relies on the availability of a suitable
910  preconditioner for the matrix A. The preconditioner is supplied through the
911  SetPreconditioner() method. It should be noted that the operator used with
912  the preconditioner need not be A itself.
913 
914  For more information regarding LOBPCG see "Block Locally Optimal
915  Preconditioned Eigenvalue Xolvers (BLOPEX) in Hypre and PETSc" by
916  A. Knyazev, M. Argentati, I. Lashuk, and E. Ovtchinnikov, SISC, 29(5),
917  2224-2239, 2007.
918 */
920 {
921 private:
922  MPI_Comm comm;
923  int myid;
924  int numProcs;
925  int nev; // Number of desired eigenmodes
926  int seed; // Random seed used for initial vectors
927 
928  HYPRE_Int glbSize; // Global number of DoFs in the linear system
929  HYPRE_Int * part; // Row partitioning of the linear system
930 
931  // Pointer to HYPRE's solver struct
932  HYPRE_Solver lobpcg_solver;
933 
934  // Interface for matrix storage type
935  mv_InterfaceInterpreter interpreter;
936 
937  // Interface for setting up and performing matrix-vector products
938  HYPRE_MatvecFunctions matvec_fn;
939 
940  // Eigenvalues
941  Array<double> eigenvalues;
942 
943  // Forward declaration
944  class HypreMultiVector;
945 
946  // MultiVector to store eigenvectors
947  HypreMultiVector * multi_vec;
948 
949  // Empty vectors used to setup the matrices and preconditioner
950  HypreParVector * x;
951 
952  /// Internal class to represent a set of eigenvectors
953  class HypreMultiVector
954  {
955  private:
956  // Pointer to hypre's multi-vector object
957  mv_MultiVectorPtr mv_ptr;
958 
959  // Wrappers for each member of the multivector
960  HypreParVector ** hpv;
961 
962  // Number of vectors in the multivector
963  int nv;
964 
965  public:
966  HypreMultiVector(int n, HypreParVector & v,
967  mv_InterfaceInterpreter & interpreter);
968  ~HypreMultiVector();
969 
970  /// Set random values
971  void Randomize(HYPRE_Int seed);
972 
973  /// Extract a single HypreParVector object
974  HypreParVector & GetVector(unsigned int i);
975 
976  /// Transfers ownership of data to returned array of vectors
977  HypreParVector ** StealVectors();
978 
979  operator mv_MultiVectorPtr() const { return mv_ptr; }
980 
981  mv_MultiVectorPtr & GetMultiVector() { return mv_ptr; }
982  };
983 
984  static void * OperatorMatvecCreate( void *A, void *x );
985  static HYPRE_Int OperatorMatvec( void *matvec_data,
986  HYPRE_Complex alpha,
987  void *A,
988  void *x,
989  HYPRE_Complex beta,
990  void *y );
991  static HYPRE_Int OperatorMatvecDestroy( void *matvec_data );
992 
993  static HYPRE_Int PrecondSolve(void *solver,
994  void *A,
995  void *b,
996  void *x);
997  static HYPRE_Int PrecondSetup(void *solver,
998  void *A,
999  void *b,
1000  void *x);
1001 
1002 public:
1003  HypreLOBPCG(MPI_Comm comm);
1004  ~HypreLOBPCG();
1005 
1006  void SetTol(double tol);
1007  void SetMaxIter(int max_iter);
1008  void SetPrintLevel(int logging);
1009  void SetNumModes(int num_eigs) { nev = num_eigs; }
1010  void SetPrecondUsageMode(int pcg_mode);
1011  void SetRandomSeed(int s) { seed = s; }
1012 
1013  // The following four methods support general operators
1014  void SetPreconditioner(Solver & precond);
1015  void SetOperator(Operator & A);
1016  void SetMassMatrix(Operator & M);
1017 
1018  /// Solve the eigenproblem
1019  void Solve();
1020 
1021  /// Collect the converged eigenvalues
1022  void GetEigenvalues(Array<double> & eigenvalues);
1023 
1024  /// Extract a single eigenvector
1025  HypreParVector & GetEigenvector(unsigned int i);
1026 
1027  /// Transfer ownership of the converged eigenvectors
1028  HypreParVector ** StealEigenvectors() { return multi_vec->StealVectors(); }
1029 };
1030 
1031 /** AME eigenvalue solver in hypre
1032 
1033  The Auxiliary space Maxwell Eigensolver (AME) is designed to find
1034  the lowest eigenmodes of the generalized eigenvalue problem:
1035  Curl Curl x = lambda M x
1036  where the Curl Curl operator is discretized using Nedelec finite element
1037  basis functions. Properties of this discretization are essential to
1038  eliminating the large null space of the Curl Curl operator.
1039 
1040  This eigensolver relies upon the LOBPCG eigensolver internally. It is also
1041  expected that the preconditioner supplied to this method will be the
1042  HypreAMS preconditioner defined above.
1043 
1044  As with LOBPCG, the operator set in the preconditioner need not be the same
1045  as A. This flexibility may be useful in solving eigenproblems which bare a
1046  strong resemblance to the Curl Curl problems for which AME is designed.
1047 
1048  Unlike LOBPCG, this eigensolver requires that the mass matrix be set.
1049  It is possible to circumvent this by passing an identity operator as the
1050  mass matrix but it seems unlikely that this would be useful so it is not the
1051  default behavior.
1052 */
1054 {
1055 private:
1056  int myid;
1057  int numProcs;
1058  int nev; // Number of desired eigenmodes
1059  bool setT;
1060 
1061  // Pointer to HYPRE's AME solver struct
1062  HYPRE_Solver ame_solver;
1063 
1064  // Pointer to HYPRE's AMS solver struct
1065  HypreSolver * ams_precond;
1066 
1067  // Eigenvalues
1068  HYPRE_Real * eigenvalues;
1069 
1070  // MultiVector to store eigenvectors
1071  HYPRE_ParVector * multi_vec;
1072 
1073  HypreParVector ** eigenvectors;
1074 
1075  void createDummyVectors();
1076 
1077 public:
1078  HypreAME(MPI_Comm comm);
1079  ~HypreAME();
1080 
1081  void SetTol(double tol);
1082  void SetMaxIter(int max_iter);
1083  void SetPrintLevel(int logging);
1084  void SetNumModes(int num_eigs);
1085 
1086  // The following four methods support operators of type HypreParMatrix.
1087  void SetPreconditioner(HypreSolver & precond);
1088  void SetOperator(HypreParMatrix & A);
1089  void SetMassMatrix(HypreParMatrix & M);
1090 
1091  /// Solve the eigenproblem
1092  void Solve();
1093 
1094  /// Collect the converged eigenvalues
1095  void GetEigenvalues(Array<double> & eigenvalues);
1096 
1097  /// Extract a single eigenvector
1098  HypreParVector & GetEigenvector(unsigned int i);
1099 
1100  /// Transfer ownership of the converged eigenvectors
1102 };
1103 
1104 }
1105 
1106 #endif // MFEM_USE_MPI
1107 
1108 #endif
Type GetType() const
Definition: hypre.hpp:466
virtual ~HypreBoomerAMG()
Definition: hypre.cpp:2525
const HYPRE_Int * ColPart() const
Returns the column partitioning (const version)
Definition: hypre.hpp:335
void SetTol(double tol)
Definition: hypre.cpp:1993
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition: hypre.cpp:2156
void EliminateRowsCols(const Array< int > &rows_cols, const HypreParVector &X, HypreParVector &B)
Definition: hypre.cpp:1263
MPI_Comm GetComm() const
MPI communicator.
Definition: hypre.hpp:295
Vector * GlobalVector() const
Returns the global vector in each processor.
Definition: hypre.cpp:127
The Auxiliary-space Maxwell Solver in hypre.
Definition: hypre.hpp:833
HypreParVector * X0
FIR Filter Temporary Vectors.
Definition: hypre.hpp:501
HypreParVector & GetEigenvector(unsigned int i)
Extract a single eigenvector.
Definition: hypre.cpp:3183
double min_eig_est
Minimal eigenvalue estimate for polynomial smoothing.
Definition: hypre.hpp:531
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:724
The Auxiliary-space Divergence Solver in hypre.
Definition: hypre.hpp:865
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:2975
void Print(const char *fname, HYPRE_Int offi=0, HYPRE_Int offj=0)
Prints the locally owned rows in parallel.
Definition: hypre.cpp:1286
MPI_Comm GetComm()
MPI communicator.
Definition: hypre.hpp:105
HYPRE_Int N() const
Returns the global number of columns.
Definition: hypre.hpp:339
int setup_called
Was hypre&#39;s Setup function called already?
Definition: hypre.hpp:604
HYPRE_Int * ColPart()
Returns the column partitioning.
Definition: hypre.hpp:331
void MakeRef(const HypreParMatrix &master)
Make this HypreParMatrix a reference to &#39;master&#39;.
Definition: hypre.cpp:766
HypreParMatrix * LeftDiagMult(const SparseMatrix &D, HYPRE_Int *row_starts=NULL) const
Definition: hypre.cpp:1019
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:1013
HypreParMatrix & Add(const double beta, const HypreParMatrix &B)
Definition: hypre.hpp:418
HypreParVector * B
Right-hand side and solution vector.
Definition: hypre.hpp:601
HypreDiagScale(HypreParMatrix &A)
Definition: hypre.hpp:735
double window_params[3]
Parameters for windowing function of FIR filter.
Definition: hypre.hpp:533
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: hypre.hpp:394
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:858
HypreADS(HypreParMatrix &A, ParFiniteElementSpace *face_fespace)
Definition: hypre.cpp:2735
void SetWindowByName(const char *window_name)
Convenience function for setting canonical windowing parameters.
Definition: hypre.cpp:1665
HypreParMatrix(hypre_ParCSRMatrix *a)
Converts hypre&#39;s format to HypreParMatrix.
Definition: hypre.hpp:226
void GetEigenvalues(Array< double > &eigenvalues)
Collect the converged eigenvalues.
Definition: hypre.cpp:3388
void SetPreconditioner(HypreSolver &precond)
Definition: hypre.cpp:3354
virtual N_Vector ToNVector()
Return a new wrapper SUNDIALS N_Vector of type SUNDIALS_NVEC_PARHYP.
Definition: hypre.hpp:155
void SetTol(double tol)
Definition: hypre.cpp:3333
virtual ~HypreGMRES()
Definition: hypre.cpp:2232
void SetPreconditioner(Solver &precond)
Definition: hypre.cpp:3106
void SetMassMatrix(Operator &M)
Definition: hypre.cpp:3161
Abstract parallel finite element space.
Definition: pfespace.hpp:28
void SetPrintLevel(int logging)
Definition: hypre.cpp:3091
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
Definition: operator.hpp:261
virtual ~HypreAMS()
Definition: hypre.cpp:2715
void SetTol(double tol)
Definition: hypre.cpp:2131
void SetOperator(HypreParMatrix &A)
Definition: hypre.cpp:3360
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
GMRES Solve function.
Definition: hypre.hpp:706
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
Definition: hypre.hpp:1028
HypreParMatrix & operator+=(const HypreParMatrix &B)
Definition: hypre.hpp:413
bool pos_l1_norms
If set, take absolute values of the computed l1_norms.
Definition: hypre.hpp:527
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:943
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:2151
void ScaleRows(const Vector &s)
Scale the local row i by s(i).
Definition: hypre.cpp:1096
double poly_fraction
Fraction of spectrum to smooth for polynomial relaxation.
Definition: hypre.hpp:515
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:2008
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:790
int poly_scale
Apply the polynomial smoother to A or D^{-1/2} A D^{-1/2}.
Definition: hypre.hpp:517
void SetTol(double tol)
Definition: hypre.cpp:3079
HypreParVector * X1
Definition: hypre.hpp:501
The identity operator as a hypre solver.
Definition: hypre.hpp:717
void SetWindowParameters(double a, double b, double c)
Set parameters for windowing function for FIR smoother.
Definition: hypre.cpp:1680
void EliminateZeroRows()
If a row contains only zeros, set its diagonal to 1.
Definition: hypre.hpp:446
HYPRE_Int NNZ() const
Returns the global number of nonzeros.
Definition: hypre.hpp:327
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre&#39;s GMRES.
Definition: hypre.cpp:2164
void SetPositiveDiagonal(bool pos=true)
After computing l1-norms, replace them with their absolute values.
Definition: hypre.hpp:579
void Print(const char *fname) const
Prints the locally owned rows in parallel.
Definition: hypre.cpp:169
void EliminateBC(HypreParMatrix &A, HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B)
Definition: hypre.cpp:1435
void SetSystemsOptions(int dim)
Definition: hypre.cpp:2407
HypreLOBPCG(MPI_Comm comm)
Definition: hypre.cpp:3050
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
Definition: densemat.cpp:2807
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Relax the linear system Ax=b.
Definition: hypre.cpp:1804
hypre_ParVector * StealParVector()
Changes the ownership of the the vector.
Definition: hypre.hpp:120
The BoomerAMG solver in hypre.
Definition: hypre.hpp:770
HYPRE_Int GetGlobalNumRows() const
Definition: hypre.hpp:371
void SetSymmetry(int sym)
Definition: hypre.cpp:2261
int dim
Definition: ex3.cpp:47
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 ...
Definition: hypre.hpp:396
virtual ~HypreParaSails()
Definition: hypre.cpp:2266
The ParaSails preconditioner in hypre.
Definition: hypre.hpp:748
HYPRE_Int GetGlobalNumCols() const
Definition: hypre.hpp:374
void SetMaxIter(int max_iter)
Definition: hypre.cpp:3085
double * l1_norms
l1 norms of the rows of A
Definition: hypre.hpp:525
Data type sparse matrix.
Definition: sparsemat.hpp:38
void SetOwnerFlags(signed char diag, signed char offd, signed char colmap)
Explicitly set the three ownership flags, see docs for diagOwner etc.
Definition: hypre.hpp:307
void SetLogging(int logging)
Definition: hypre.cpp:2003
void SetZeroInintialIterate()
non-hypre setting
Definition: hypre.hpp:652
Jacobi preconditioner in hypre.
Definition: hypre.hpp:731
virtual ~HypreSolver()
Definition: hypre.cpp:1975
HyprePCG(HypreParMatrix &_A)
Definition: hypre.cpp:1982
virtual HYPRE_PtrToParSolverFcn SolveFcn() const =0
hypre&#39;s internal Solve function
void SetKDim(int dim)
Definition: hypre.cpp:2141
void SetResidualConvergenceOptions(int res_frequency=-1, double rtol=0.0)
Definition: hypre.cpp:2021
int to_int(const std::string &str)
Definition: text.hpp:68
void SetPrintLevel(int print_level)
Definition: hypre.hpp:811
void GetBlocks(Array2D< HypreParMatrix * > &blocks, bool interleaved_rows=false, bool interleaved_cols=false) const
Definition: hypre.cpp:910
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve the linear system Ax=b.
Definition: hypre.cpp:1928
HypreParMatrix * RAP(HypreParMatrix *A, HypreParMatrix *P)
Returns the matrix P^t * A * P.
Definition: hypre.cpp:1385
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
PCG Solve function.
Definition: hypre.hpp:668
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
Definition: hypre.cpp:3435
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:164
double relax_weight
Damping coefficient (usually &lt;= 1)
Definition: hypre.hpp:509
Parallel smoothers in hypre.
Definition: hypre.hpp:491
void SetElasticityOptions(ParFiniteElementSpace *fespace)
Definition: hypre.cpp:2489
void GetDiag(Vector &diag) const
Get the local diagonal of the matrix.
Definition: hypre.cpp:868
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:817
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:722
void BooleanMult(int alpha, int *x, int beta, int *y)
Definition: hypre.hpp:401
HypreParMatrix * A
The linear system matrix.
Definition: hypre.hpp:495
HypreAMS(HypreParMatrix &A, ParFiniteElementSpace *edge_fespace)
Definition: hypre.cpp:2536
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:740
virtual void SetOperator(const Operator &op)
Definition: hypre.cpp:1687
virtual HYPRE_PtrToParSolverFcn SetupFcn() const =0
hypre&#39;s internal Setup function
void SetLogging(int logging)
Definition: hypre.cpp:2146
virtual ~HypreADS()
Definition: hypre.cpp:2953
HypreParMatrix()
An empty matrix to be used as a reference to an existing matrix.
Definition: hypre.cpp:251
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:738
void SetMaxIter(int max_iter)
Definition: hypre.cpp:1998
HypreParMatrix * GetData()
Definition: hypre.hpp:743
HYPRE_Int * RowPart()
Returns the row partitioning.
Definition: hypre.hpp:329
void SetSOROptions(double relax_weight, double omega)
Set SOR-related parameters.
Definition: hypre.cpp:1645
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:72
HypreParVector * X
Definition: hypre.hpp:601
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:889
Type
Enumeration defining IDs for some classes derived from Operator.
Definition: operator.hpp:123
void GetEigenvalues(Array< double > &eigenvalues)
Collect the converged eigenvalues.
Definition: hypre.cpp:3171
PCG solver in hypre.
Definition: hypre.hpp:630
GMRES solver in hypre.
Definition: hypre.hpp:679
signed char OwnsOffd() const
Get offd ownership flag.
Definition: hypre.hpp:313
const HYPRE_Int * RowPart() const
Returns the row partitioning (const version)
Definition: hypre.hpp:333
signed char OwnsColMap() const
Get colmap ownership flag.
Definition: hypre.hpp:315
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:2730
HypreParVector * X
Definition: hypre.hpp:497
void mfem_error(const char *msg)
Definition: error.cpp:106
void Solve()
Solve the eigenproblem.
Definition: hypre.cpp:3382
void SetNumModes(int num_eigs)
Definition: hypre.cpp:3325
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:763
virtual ~HypreDiagScale()
Definition: hypre.hpp:744
int GetNumRows() const
Returns the number of rows in the diagonal block of the ParCSRMatrix.
Definition: hypre.hpp:358
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.hpp:619
double max_eig_est
Maximal eigenvalue estimate for polynomial smoothing.
Definition: hypre.hpp:529
HypreAME(MPI_Comm comm)
Definition: hypre.cpp:3283
HypreParMatrix * Transpose()
Returns the transpose of *this.
Definition: hypre.cpp:932
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:761
virtual ~HypreIdentity()
Definition: hypre.hpp:727
int height
Dimension of the output / number of rows in the matrix.
Definition: operator.hpp:24
void SetMaxIter(int max_iter)
Definition: hypre.cpp:3339
void SetFIRCoefficients(double max_eig)
Compute window and Chebyshev coefficients for given polynomial order.
Definition: hypre.cpp:1764
void SetRandomSeed(int s)
Definition: hypre.hpp:1011
signed char OwnsDiag() const
Get diag ownership flag.
Definition: hypre.hpp:311
double * fir_coeffs
Combined coefficients for windowing and Chebyshev polynomials.
Definition: hypre.hpp:536
void Threshold(double threshold=0.0)
Remove values smaller in absolute value than some threshold.
Definition: hypre.cpp:1210
double InnerProduct(HypreParVector *x, HypreParVector *y)
Definition: hypre.cpp:199
HYPRE_Int GlobalSize()
Returns the global number of rows.
Definition: hypre.hpp:111
virtual ~HypreSmoother()
Definition: hypre.cpp:1894
HypreParVector(MPI_Comm comm, HYPRE_Int glob_size, HYPRE_Int *col)
Definition: hypre.cpp:49
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:2390
void SetData(double *_data)
Definition: hypre.cpp:159
void InvScaleRows(const Vector &s)
Scale the local row i by 1./s(i)
Definition: hypre.cpp:1131
void SetTaubinOptions(double lambda, double mu, int iter)
Set parameters for Taubin&#39;s lambda-mu method.
Definition: hypre.cpp:1657
HypreParVector * B
Right-hand side and solution vectors.
Definition: hypre.hpp:497
void SetMassMatrix(HypreParMatrix &M)
Definition: hypre.cpp:3375
HYPRE_Int M() const
Returns the global number of rows.
Definition: hypre.hpp:337
void SetZeroInintialIterate()
non-hypre setting
Definition: hypre.hpp:697
virtual ~HyprePCG()
Definition: hypre.cpp:2107
int GetNumCols() const
Returns the number of columns in the diagonal block of the ParCSRMatrix.
Definition: hypre.hpp:365
void SetOperator(Operator &A)
Definition: hypre.cpp:3115
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition: hypre.cpp:2013
void SetPolyOptions(int poly_order, double poly_fraction)
Set parameters for polynomial smoothing.
Definition: hypre.cpp:1651
void GetNumIterations(int &num_iterations)
Definition: hypre.hpp:654
void CopyColStarts()
Definition: hypre.cpp:827
int relax_times
Number of relaxation sweeps.
Definition: hypre.hpp:507
void operator*=(double s)
Scale all entries by s: A_scaled = s*A.
Definition: hypre.cpp:1172
void SetPrintLevel(int logging)
Definition: hypre.cpp:3345
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:210
void SetOwnership(int own)
Sets ownership of the internal hypre_ParVector.
Definition: hypre.hpp:123
Abstract class for hypre&#39;s solvers and preconditioners.
Definition: hypre.hpp:594
HypreParVector & operator=(double d)
Set constant values.
Definition: hypre.cpp:137
const double alpha
Definition: ex15.cpp:337
Vector data type.
Definition: vector.hpp:36
HypreParMatrix & operator=(double value)
Initialize all entries with value.
Definition: hypre.hpp:407
HypreGMRES(HypreParMatrix &_A)
Definition: hypre.cpp:2113
hypre_ParCSRMatrix * StealData()
Changes the ownership of the the matrix.
Definition: hypre.cpp:776
void SetPrecondUsageMode(int pcg_mode)
Definition: hypre.cpp:3100
virtual ~HypreParMatrix()
Calls hypre&#39;s destroy function.
Definition: hypre.hpp:464
HypreParMatrix * A
The linear system matrix.
Definition: hypre.hpp:598
void SetMaxIter(int max_iter)
Definition: hypre.cpp:2136
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:904
HYPRE_Int * GetColStarts() const
Definition: hypre.hpp:379
HypreParVector & GetEigenvector(unsigned int i)
Extract a single eigenvector.
Definition: hypre.cpp:3424
double omega
SOR parameter (usually in (0,2))
Definition: hypre.hpp:511
HYPRE_Int * GetRowStarts() const
Definition: hypre.hpp:377
Base class for solvers.
Definition: operator.hpp:257
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:856
int GetOwnership() const
Gets ownership of the internal hypre_ParVector.
Definition: hypre.hpp:126
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
PCG Setup function.
Definition: hypre.hpp:665
Abstract operator.
Definition: operator.hpp:21
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:174
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:819
~HypreParVector()
Calls hypre&#39;s destroy function.
Definition: hypre.cpp:174
void SetNumModes(int num_eigs)
Definition: hypre.hpp:1009
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre&#39;s PCG.
Definition: hypre.cpp:2034
HypreParVector * Z
Definition: hypre.hpp:499
void SetSingularProblem()
Set this option when solving a curl-curl problem with zero mass term.
Definition: hypre.hpp:851
void Solve()
Solve the eigenproblem.
Definition: hypre.cpp:3189
void Read(MPI_Comm comm, const char *fname)
Reads the matrix from a file.
Definition: hypre.cpp:1291
HypreParVector * V
Temporary vectors.
Definition: hypre.hpp:499
void SetType(HypreSmoother::Type type, int relax_times=1)
Set the relaxation type and number of sweeps.
Definition: hypre.cpp:1639
HypreParaSails(HypreParMatrix &A)
Definition: hypre.cpp:2238
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
GMRES Setup function.
Definition: hypre.hpp:703
int width
Dimension of the input / number of columns in the matrix.
Definition: operator.hpp:25
int poly_order
Order of the smoothing polynomial.
Definition: hypre.hpp:513
HYPRE_Int * Partitioning()
Returns the row partitioning.
Definition: hypre.hpp:108
double lambda
Taubin&#39;s lambda-mu method parameters.
Definition: hypre.hpp:520
HypreParMatrix * ParMult(HypreParMatrix *A, HypreParMatrix *B)
Returns the matrix A * B.
Definition: hypre.cpp:1375
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:891