MFEM  v4.5.1
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-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
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 #include "../general/globals.hpp"
30 
31 #ifdef HYPRE_COMPLEX
32 #error "MFEM does not work with HYPRE's complex numbers support"
33 #endif
34 
35 #if defined(HYPRE_USING_GPU) && \
36  !(defined(HYPRE_USING_CUDA) || defined(HYPRE_USING_HIP))
37 #error "Unsupported GPU build of HYPRE! Only CUDA and HIP builds are supported."
38 #endif
39 #if defined(HYPRE_USING_CUDA) && !defined(MFEM_USE_CUDA)
40 #error "MFEM_USE_CUDA=YES is required when HYPRE is built with CUDA!"
41 #endif
42 #if defined(HYPRE_USING_HIP) && !defined(MFEM_USE_HIP)
43 #error "MFEM_USE_HIP=YES is required when HYPRE is built with HIP!"
44 #endif
45 
46 // MFEM_HYPRE_FORALL is a macro similar to MFEM_FORALL, but it executes on the
47 // device that hypre was configured with (no matter what device was selected
48 // in MFEM's runtime configuration).
49 #if defined(HYPRE_USING_CUDA)
50 #define MFEM_HYPRE_FORALL(i, N,...) CuWrap1D(N, [=] MFEM_DEVICE \
51  (int i) {__VA_ARGS__})
52 #elif defined(HYPRE_USING_HIP)
53 #define MFEM_HYPRE_FORALL(i, N,...) HipWrap1D(N, [=] MFEM_DEVICE \
54  (int i) {__VA_ARGS__})
55 #else
56 #define MFEM_HYPRE_FORALL(i, N,...) for (int i = 0; i < N; i++) { __VA_ARGS__ }
57 #endif
58 
59 #include "sparsemat.hpp"
60 #include "hypre_parcsr.hpp"
61 
62 namespace mfem
63 {
64 
65 class ParFiniteElementSpace;
66 class HypreParMatrix;
67 
68 
69 /// @brief A simple singleton class for hypre's global settings, that 1) calls
70 /// HYPRE_Init() and sets some GPU-relevant options at construction and 2) calls
71 /// HYPRE_Finalize() at destruction.
72 class Hypre
73 {
74 public:
75  /// @brief Initialize hypre by calling HYPRE_Init() and set default options.
76  /// After calling Hypre::Init(), hypre will be finalized automatically at
77  /// program exit.
78  ///
79  /// Calling HYPRE_Finalize() manually is not compatible with this class.
80  static void Init() { Instance(); }
81 
82  /// @brief Finalize hypre (called automatically at program exit if
83  /// Hypre::Init() has been called).
84  ///
85  /// Multiple calls to Hypre::Finalize() have no effect. This function can be
86  /// called manually to more precisely control when hypre is finalized.
87  static void Finalize();
88 
89 private:
90  /// Calls HYPRE_Init() when the singleton is constructed.
91  Hypre();
92 
93  /// The singleton destructor (called at program exit) finalizes hypre.
94  ~Hypre() { Finalize(); }
95 
96  /// Set the default hypre global options (mostly GPU-relevant).
97  void SetDefaultOptions();
98 
99  /// Create and return the Hypre singleton object.
100  static Hypre &Instance()
101  {
102  static Hypre hypre;
103  return hypre;
104  }
105 
106  bool finalized = false; ///< Has Hypre::Finalize() been called already?
107 };
108 
109 
110 namespace internal
111 {
112 
113 template <typename int_type>
114 inline int to_int(int_type i)
115 {
116  MFEM_ASSERT(int_type(int(i)) == i, "overflow converting int_type to int");
117  return int(i);
118 }
119 
120 // Specialization for to_int(int)
121 template <> inline int to_int(int i) { return i; }
122 
123 // Convert a HYPRE_Int to int
124 #ifdef HYPRE_BIGINT
125 template <>
126 inline int to_int(HYPRE_Int i)
127 {
128  MFEM_ASSERT(HYPRE_Int(int(i)) == i, "overflow converting HYPRE_Int to int");
129  return int(i);
130 }
131 #endif
132 
133 } // namespace internal
134 
135 
136 /// The MemoryClass used by Hypre objects.
138 {
139 #if !defined(HYPRE_USING_GPU)
140  return MemoryClass::HOST;
141 #elif defined(HYPRE_USING_UNIFIED_MEMORY)
142  return MemoryClass::MANAGED;
143 #else
144  return MemoryClass::DEVICE;
145 #endif
146 }
147 
148 /// The MemoryType used by MFEM when allocating arrays for Hypre objects.
150 {
151 #if !defined(HYPRE_USING_GPU)
152  return Device::GetHostMemoryType();
153 #elif defined(HYPRE_USING_UNIFIED_MEMORY)
154  return MemoryType::MANAGED;
155 #else
156  return MemoryType::DEVICE;
157 #endif
158 }
159 
160 /// Wrapper for hypre's parallel vector class
161 class HypreParVector : public Vector
162 {
163 private:
164  int own_ParVector;
165 
166  /// The actual object
167  hypre_ParVector *x;
168 
169  friend class HypreParMatrix;
170 
171  // Set Vector::data and Vector::size from *x
172  inline void _SetDataAndSize_();
173 
174 public:
175 
176  /// Default constructor, no underlying @a hypre_ParVector is created.
178  {
179  own_ParVector = false;
180  x = NULL;
181  }
182 
183  /** @brief Creates vector with given global size and parallel partitioning of
184  the rows/columns given by @a col. */
185  /** @anchor hypre_partitioning_descr
186  The partitioning is defined in one of two ways depending on the
187  configuration of HYPRE:
188  1. If HYPRE_AssumedPartitionCheck() returns true (the default),
189  then col is of length 2 and the local processor owns columns
190  [col[0],col[1]).
191  2. If HYPRE_AssumedPartitionCheck() returns false, then col is of
192  length (number of processors + 1) and processor P owns columns
193  [col[P],col[P+1]) i.e. each processor has a copy of the same col
194  array. */
195  HypreParVector(MPI_Comm comm, HYPRE_BigInt glob_size, HYPRE_BigInt *col);
196  /** @brief Creates vector with given global size, partitioning of the
197  columns, and data. */
198  /** The data must be allocated and destroyed outside. If @a data_ is NULL, a
199  dummy vector without a valid data array will be created. See @ref
200  hypre_partitioning_descr "here" for a description of the @a col array.
201 
202  If @a is_device_ptr is true, the pointer @a data_ is assumed to be
203  allocated in the memory location HYPRE_MEMORY_DEVICE. */
204  HypreParVector(MPI_Comm comm, HYPRE_BigInt glob_size, double *data_,
205  HYPRE_BigInt *col, bool is_device_ptr = false);
206  /// Creates a deep copy of @a y
207  HypreParVector(const HypreParVector &y);
208  /// Move constructor for HypreParVector. "Steals" data from its argument.
210  /// Creates vector compatible with (i.e. in the domain of) A or A^T
211  explicit HypreParVector(const HypreParMatrix &A, int transpose = 0);
212  /// Creates vector wrapping y
213  explicit HypreParVector(HYPRE_ParVector y);
214  /// Create a true dof parallel vector on a given ParFiniteElementSpace
215  explicit HypreParVector(ParFiniteElementSpace *pfes);
216 
217  /// \brief Constructs a @p HypreParVector *compatible* with the calling vector
218  /// - meaning that it will be the same size and have the same partitioning.
220 
221  /// MPI communicator
222  MPI_Comm GetComm() const { return x->comm; }
223 
224  /// Converts hypre's format to HypreParVector
225  void WrapHypreParVector(hypre_ParVector *y, bool owner=true);
226 
227  /// Returns the parallel row/column partitioning
228  /** See @ref hypre_partitioning_descr "here" for a description of the
229  partitioning array. */
230  inline const HYPRE_BigInt *Partitioning() const { return x->partitioning; }
231 
232  /// @brief Returns a non-const pointer to the parallel row/column
233  /// partitioning.
234  /// Deprecated in favor of HypreParVector::Partitioning() const.
235  MFEM_DEPRECATED
236  inline HYPRE_BigInt *Partitioning() { return x->partitioning; }
237 
238  /// Returns the global number of rows
239  inline HYPRE_BigInt GlobalSize() const { return x->global_size; }
240 
241  /// Typecasting to hypre's hypre_ParVector*
242  operator hypre_ParVector*() const { return x; }
243 #ifndef HYPRE_PAR_VECTOR_STRUCT
244  /// Typecasting to hypre's HYPRE_ParVector, a.k.a. void *
245  operator HYPRE_ParVector() const { return (HYPRE_ParVector) x; }
246 #endif
247  /// Changes the ownership of the vector
248  hypre_ParVector *StealParVector() { own_ParVector = 0; return x; }
249 
250  /// Sets ownership of the internal hypre_ParVector
251  void SetOwnership(int own) { own_ParVector = own; }
252 
253  /// Gets ownership of the internal hypre_ParVector
254  int GetOwnership() const { return own_ParVector; }
255 
256  /// Returns the global vector in each processor
257  Vector* GlobalVector() const;
258 
259  /// Set constant values
260  HypreParVector& operator= (double d);
261  /// Define '=' for hypre vectors.
263  /// Move assignment
265 
266  using Vector::Read;
267 
268  /// Sets the data of the Vector and the hypre_ParVector to @a data_.
269  /** Must be used only for HypreParVector%s that do not own the data,
270  e.g. created with the constructor:
271  HypreParVector(MPI_Comm, HYPRE_BigInt, double *, HYPRE_BigInt *). */
272  void SetData(double *data_);
273 
274  /** @brief Prepare the HypreParVector for read access in hypre's device
275  memory space, HYPRE_MEMORY_DEVICE. */
276  void HypreRead() const;
277 
278  /** @brief Prepare the HypreParVector for read and write access in hypre's
279  device memory space, HYPRE_MEMORY_DEVICE. */
280  void HypreReadWrite();
281 
282  /** @brief Prepare the HypreParVector for write access in hypre's device
283  memory space, HYPRE_MEMORY_DEVICE. */
284  void HypreWrite();
285 
286  /** @brief Replace the HypreParVector's data with the given Memory, @a mem,
287  and prepare the vector for read access in hypre's device memory space,
288  HYPRE_MEMORY_DEVICE. */
289  /** This method must be used with HypreParVector%s that do not own the data,
290  e.g. created with the constructor:
291  HypreParVector(MPI_Comm, HYPRE_BigInt, double *, HYPRE_BigInt *).
292 
293  The Memory @a mem must be accessible with the hypre MemoryClass defined
294  by GetHypreMemoryClass(). */
295  void WrapMemoryRead(const Memory<double> &mem);
296 
297  /** @brief Replace the HypreParVector's data with the given Memory, @a mem,
298  and prepare the vector for read and write access in hypre's device memory
299  space, HYPRE_MEMORY_DEVICE. */
300  /** This method must be used with HypreParVector%s that do not own the data,
301  e.g. created with the constructor:
302  HypreParVector(MPI_Comm, HYPRE_BigInt, double *, HYPRE_BigInt *).
303 
304  The Memory @a mem must be accessible with the hypre MemoryClass defined
305  by GetHypreMemoryClass(). */
307 
308  /** @brief Replace the HypreParVector's data with the given Memory, @a mem,
309  and prepare the vector for write access in hypre's device memory space,
310  HYPRE_MEMORY_DEVICE. */
311  /** This method must be used with HypreParVector%s that do not own the data,
312  e.g. created with the constructor:
313  HypreParVector(MPI_Comm, HYPRE_BigInt, double *, HYPRE_BigInt *).
314 
315  The Memory @a mem must be accessible with the hypre MemoryClass defined
316  by GetHypreMemoryClass(). */
317  void WrapMemoryWrite(Memory<double> &mem);
318 
319  /// Set random values
320  HYPRE_Int Randomize(HYPRE_Int seed);
321 
322  /// Prints the locally owned rows in parallel
323  void Print(const char *fname) const;
324 
325  /// Reads a HypreParVector from files saved with HypreParVector::Print
326  void Read(MPI_Comm comm, const char *fname);
327 
328  /// Calls hypre's destroy function
329  ~HypreParVector();
330 };
331 
332 /// Returns the inner product of x and y
333 double InnerProduct(HypreParVector &x, HypreParVector &y);
334 double InnerProduct(HypreParVector *x, HypreParVector *y);
335 
336 
337 /** @brief Compute the l_p norm of the Vector which is split without overlap
338  across the given communicator. */
339 double ParNormlp(const Vector &vec, double p, MPI_Comm comm);
340 
341 
342 /// Wrapper for hypre's ParCSR matrix class
343 class HypreParMatrix : public Operator
344 {
345 private:
346  /// The actual object
347  hypre_ParCSRMatrix *A;
348 
349  /// Auxiliary vectors for typecasting
350  mutable HypreParVector *X, *Y;
351  /** @brief Auxiliary buffers for the case when the input or output arrays in
352  methods like Mult(double, const Vector &, double, Vector &) need to be
353  deep copied in order to be used by hypre. */
354  mutable Memory<double> auxX, auxY;
355 
356  // Flags indicating ownership of A->diag->{i,j,data}, A->offd->{i,j,data},
357  // and A->col_map_offd.
358  // The possible values for diagOwner are:
359  // -1: no special treatment of A->diag (default)
360  // when hypre is built with CUDA support, A->diag owns the "host"
361  // pointers (according to A->diag->owns_data)
362  // -2: used when hypre is built with CUDA support, A->diag owns the "hypre"
363  // pointers (according to A->diag->owns_data)
364  // 0: prevent hypre from destroying A->diag->{i,j,data}
365  // 1: same as 0, plus own the "host" A->diag->{i,j}
366  // 2: same as 0, plus own the "host" A->diag->data
367  // 3: same as 0, plus own the "host" A->diag->{i,j,data}
368  // The same values and rules apply to offdOwner and A->offd.
369  // The possible values for colMapOwner are:
370  // -1: no special treatment of A->col_map_offd (default)
371  // 0: prevent hypre from destroying A->col_map_offd
372  // 1: same as 0, plus take ownership of A->col_map_offd
373  // All owned arrays are destroyed with 'delete []'.
374  signed char diagOwner, offdOwner, colMapOwner;
375 
376  // Does the object own the pointer A?
377  signed char ParCSROwner;
378 
379  MemoryIJData mem_diag, mem_offd;
380 
381  // Initialize with defaults. Does not initialize inherited members.
382  void Init();
383 
384  // Delete all owned data. Does not perform re-initialization with defaults.
385  void Destroy();
386 
387  void Read(MemoryClass mc) const;
388  void ReadWrite(MemoryClass mc);
389  // The Boolean flags are used in Destroy().
390  void Write(MemoryClass mc, bool set_diag = true, bool set_offd = true);
391 
392  // Copy (shallow/deep, based on HYPRE_BIGINT) the I and J arrays from csr to
393  // hypre_csr. Shallow copy the data. Return the appropriate ownership flag.
394  // The CSR arrays are wrapped in the mem_csr struct which is used to move
395  // these arrays to device, if necessary.
396  static signed char CopyCSR(SparseMatrix *csr,
397  MemoryIJData &mem_csr,
398  hypre_CSRMatrix *hypre_csr,
399  bool mem_owner);
400  // Copy (shallow or deep, based on HYPRE_BIGINT) the I and J arrays from
401  // bool_csr to hypre_csr. Allocate the data array and set it to all ones.
402  // Return the appropriate ownership flag. The CSR arrays are wrapped in the
403  // mem_csr struct which is used to move these arrays to device, if necessary.
404  static signed char CopyBoolCSR(Table *bool_csr,
405  MemoryIJData &mem_csr,
406  hypre_CSRMatrix *hypre_csr);
407 
408  // Wrap the data from h_mat into mem with the given ownership flag.
409  // If the new Memory arrays in mem are not suitable to be accessed via
410  // GetHypreMemoryClass(), then mem will be re-allocated using the memory type
411  // returned by GetHypreMemoryType(), the data will be deep copied, and h_mat
412  // will be updated with the new pointers.
413  static signed char HypreCsrToMem(hypre_CSRMatrix *h_mat, MemoryType h_mat_mt,
414  bool own_ija, MemoryIJData &mem);
415 
416 public:
417  /// An empty matrix to be used as a reference to an existing matrix
418  HypreParMatrix();
419 
420  /// Converts hypre's format to HypreParMatrix
421  /** If @a owner is false, ownership of @a a is not transferred */
422  void WrapHypreParCSRMatrix(hypre_ParCSRMatrix *a, bool owner = true);
423 
424  /// Converts hypre's format to HypreParMatrix
425  /** If @a owner is false, ownership of @a a is not transferred */
426  explicit HypreParMatrix(hypre_ParCSRMatrix *a, bool owner = true)
427  {
428  Init();
429  WrapHypreParCSRMatrix(a, owner);
430  }
431 
432  /// Creates block-diagonal square parallel matrix.
433  /** Diagonal is given by @a diag which must be in CSR format (finalized). The
434  new HypreParMatrix does not take ownership of any of the input arrays.
435  See @ref hypre_partitioning_descr "here" for a description of the row
436  partitioning array @a row_starts.
437 
438  @warning The ordering of the columns in each row in @a *diag may be
439  changed by this constructor to ensure that the first entry in each row is
440  the diagonal one. This is expected by most hypre functions. */
441  HypreParMatrix(MPI_Comm comm, HYPRE_BigInt glob_size,
442  HYPRE_BigInt *row_starts,
443  SparseMatrix *diag); // constructor with 4 arguments, v1
444 
445  /// Creates block-diagonal rectangular parallel matrix.
446  /** Diagonal is given by @a diag which must be in CSR format (finalized). The
447  new HypreParMatrix does not take ownership of any of the input arrays.
448  See @ref hypre_partitioning_descr "here" for a description of the
449  partitioning arrays @a row_starts and @a col_starts. */
450  HypreParMatrix(MPI_Comm comm, HYPRE_BigInt global_num_rows,
451  HYPRE_BigInt global_num_cols, HYPRE_BigInt *row_starts,
452  HYPRE_BigInt *col_starts,
453  SparseMatrix *diag); // constructor with 6 arguments, v1
454 
455  /// Creates general (rectangular) parallel matrix.
456  /** The new HypreParMatrix does not take ownership of any of the input
457  arrays, if @a own_diag_offd is false (default). If @a own_diag_offd is
458  true, ownership of @a diag and @a offd is transferred to the
459  HypreParMatrix.
460 
461  See @ref hypre_partitioning_descr "here" for a description of the
462  partitioning arrays @a row_starts and @a col_starts. */
463  HypreParMatrix(MPI_Comm comm, HYPRE_BigInt global_num_rows,
464  HYPRE_BigInt global_num_cols, HYPRE_BigInt *row_starts,
465  HYPRE_BigInt *col_starts, SparseMatrix *diag,
466  SparseMatrix *offd, HYPRE_BigInt *cmap,
467  bool own_diag_offd = false); // constructor with 8+1 arguments
468 
469  /// Creates general (rectangular) parallel matrix.
470  /** The new HypreParMatrix takes ownership of all input arrays, except
471  @a col_starts and @a row_starts. See @ref hypre_partitioning_descr "here"
472  for a description of the partitioning arrays @a row_starts and @a
473  col_starts.
474 
475  If @a hypre_arrays is false, all arrays (except @a row_starts and
476  @a col_starts) are assumed to be allocated according to the MemoryType
477  returned by Device::GetHostMemoryType(). If @a hypre_arrays is true, then
478  the same arrays are assumed to be allocated by hypre as host arrays. */
479  HypreParMatrix(MPI_Comm comm,
480  HYPRE_BigInt global_num_rows, HYPRE_BigInt global_num_cols,
481  HYPRE_BigInt *row_starts, HYPRE_BigInt *col_starts,
482  HYPRE_Int *diag_i, HYPRE_Int *diag_j, double *diag_data,
483  HYPRE_Int *offd_i, HYPRE_Int *offd_j, double *offd_data,
484  HYPRE_Int offd_num_cols,
485  HYPRE_BigInt *offd_col_map,
486  bool hypre_arrays = false); // constructor with 13+1 arguments
487 
488  /// Creates a parallel matrix from SparseMatrix on processor 0.
489  /** See @ref hypre_partitioning_descr "here" for a description of the
490  partitioning arrays @a row_starts and @a col_starts. */
491  HypreParMatrix(MPI_Comm comm, HYPRE_BigInt *row_starts,
492  HYPRE_BigInt *col_starts,
493  SparseMatrix *a); // constructor with 4 arguments, v2
494 
495  /// Creates boolean block-diagonal rectangular parallel matrix.
496  /** The new HypreParMatrix does not take ownership of any of the input
497  arrays. See @ref hypre_partitioning_descr "here" for a description of the
498  partitioning arrays @a row_starts and @a col_starts. */
499  HypreParMatrix(MPI_Comm comm, HYPRE_BigInt global_num_rows,
500  HYPRE_BigInt global_num_cols, HYPRE_BigInt *row_starts,
501  HYPRE_BigInt *col_starts,
502  Table *diag); // constructor with 6 arguments, v2
503 
504  /// Creates boolean rectangular parallel matrix.
505  /** The new HypreParMatrix takes ownership of the arrays @a i_diag,
506  @a j_diag, @a i_offd, @a j_offd, and @a cmap; does not take ownership of
507  the arrays @a row and @a col. See @ref hypre_partitioning_descr "here"
508  for a description of the partitioning arrays @a row and @a col. */
509  HypreParMatrix(MPI_Comm comm, int id, int np, HYPRE_BigInt *row,
510  HYPRE_BigInt *col,
511  HYPRE_Int *i_diag, HYPRE_Int *j_diag, HYPRE_Int *i_offd,
512  HYPRE_Int *j_offd, HYPRE_BigInt *cmap,
513  HYPRE_Int cmap_size); // constructor with 11 arguments
514 
515  /** @brief Creates a general parallel matrix from a local CSR matrix on each
516  processor described by the @a I, @a J and @a data arrays. */
517  /** The local matrix should be of size (local) @a nrows by (global)
518  @a glob_ncols. The new parallel matrix contains copies of all input
519  arrays (so they can be deleted). See @ref hypre_partitioning_descr "here"
520  for a description of the partitioning arrays @a rows and @a cols. */
521  HypreParMatrix(MPI_Comm comm, int nrows, HYPRE_BigInt glob_nrows,
522  HYPRE_BigInt glob_ncols, int *I, HYPRE_BigInt *J,
523  double *data, HYPRE_BigInt *rows,
524  HYPRE_BigInt *cols); // constructor with 9 arguments
525 
526  /** @brief Copy constructor for a ParCSR matrix which creates a deep copy of
527  structure and data from @a P. */
528  HypreParMatrix(const HypreParMatrix &P);
529 
530  /// Make this HypreParMatrix a reference to 'master'
531  void MakeRef(const HypreParMatrix &master);
532 
533  /// MPI communicator
534  MPI_Comm GetComm() const { return A->comm; }
535 
536  /// Typecasting to hypre's hypre_ParCSRMatrix*
537  operator hypre_ParCSRMatrix*() const { return A; }
538 #ifndef HYPRE_PAR_CSR_MATRIX_STRUCT
539  /// Typecasting to hypre's HYPRE_ParCSRMatrix, a.k.a. void *
540  operator HYPRE_ParCSRMatrix() { return (HYPRE_ParCSRMatrix) A; }
541 #endif
542  /// Changes the ownership of the matrix
543  hypre_ParCSRMatrix* StealData();
544 
545  /// Explicitly set the three ownership flags, see docs for diagOwner etc.
546  void SetOwnerFlags(signed char diag, signed char offd, signed char colmap);
547 
548  /// Get diag ownership flag
549  signed char OwnsDiag() const { return diagOwner; }
550  /// Get offd ownership flag
551  signed char OwnsOffd() const { return offdOwner; }
552  /// Get colmap ownership flag
553  signed char OwnsColMap() const { return colMapOwner; }
554 
555  /** If the HypreParMatrix does not own the row-starts array, make a copy of
556  it that the HypreParMatrix will own. If the col-starts array is the same
557  as the row-starts array, col-starts is also replaced. */
558  void CopyRowStarts();
559  /** If the HypreParMatrix does not own the col-starts array, make a copy of
560  it that the HypreParMatrix will own. If the row-starts array is the same
561  as the col-starts array, row-starts is also replaced. */
562  void CopyColStarts();
563 
564  /// Returns the global number of nonzeros
565  inline HYPRE_BigInt NNZ() const { return A->num_nonzeros; }
566  /// Returns the row partitioning
567  /** See @ref hypre_partitioning_descr "here" for a description of the
568  partitioning array. */
569  inline HYPRE_BigInt *RowPart() { return A->row_starts; }
570  /// Returns the column partitioning
571  /** See @ref hypre_partitioning_descr "here" for a description of the
572  partitioning array. */
573  inline HYPRE_BigInt *ColPart() { return A->col_starts; }
574  /// Returns the row partitioning (const version)
575  /** See @ref hypre_partitioning_descr "here" for a description of the
576  partitioning array. */
577  inline const HYPRE_BigInt *RowPart() const { return A->row_starts; }
578  /// Returns the column partitioning (const version)
579  /** See @ref hypre_partitioning_descr "here" for a description of the
580  partitioning array. */
581  inline const HYPRE_BigInt *ColPart() const { return A->col_starts; }
582  /// Returns the global number of rows
583  inline HYPRE_BigInt M() const { return A->global_num_rows; }
584  /// Returns the global number of columns
585  inline HYPRE_BigInt N() const { return A->global_num_cols; }
586 
587  /// Get the local diagonal of the matrix.
588  void GetDiag(Vector &diag) const;
589  /// Get the local diagonal block. NOTE: 'diag' will not own any data.
590  void GetDiag(SparseMatrix &diag) const;
591  /// Get the local off-diagonal block. NOTE: 'offd' will not own any data.
592  void GetOffd(SparseMatrix &offd, HYPRE_BigInt* &cmap) const;
593  /** @brief Get a single SparseMatrix containing all rows from this processor,
594  merged from the diagonal and off-diagonal blocks stored by the
595  HypreParMatrix. */
596  /** @note The number of columns in the SparseMatrix will be the global number
597  of columns in the parallel matrix, so using this method may result in an
598  integer overflow in the column indices. */
599  void MergeDiagAndOffd(SparseMatrix &merged);
600 
601  /// Return the diagonal of the matrix (Operator interface).
602  virtual void AssembleDiagonal(Vector &diag) const { GetDiag(diag); }
603 
604  /** Split the matrix into M x N equally sized blocks of parallel matrices.
605  The size of 'blocks' must already be set to M x N. */
606  void GetBlocks(Array2D<HypreParMatrix*> &blocks,
607  bool interleaved_rows = false,
608  bool interleaved_cols = false) const;
609 
610  /// Returns the transpose of *this
611  HypreParMatrix * Transpose() const;
612 
613  /** Returns principle submatrix given by array of indices of connections
614  with relative size > @a threshold in *this. */
615 #if MFEM_HYPRE_VERSION >= 21800
617  double threshold=0.0) const;
618 #endif
619 
620  /// Returns the number of rows in the diagonal block of the ParCSRMatrix
621  int GetNumRows() const
622  {
623  return internal::to_int(
624  hypre_CSRMatrixNumRows(hypre_ParCSRMatrixDiag(A)));
625  }
626 
627  /// Returns the number of columns in the diagonal block of the ParCSRMatrix
628  int GetNumCols() const
629  {
630  return internal::to_int(
631  hypre_CSRMatrixNumCols(hypre_ParCSRMatrixDiag(A)));
632  }
633 
634  /// Return the global number of rows
636  { return hypre_ParCSRMatrixGlobalNumRows(A); }
637 
638  /// Return the global number of columns
640  { return hypre_ParCSRMatrixGlobalNumCols(A); }
641 
642  /// Return the parallel row partitioning array.
643  /** See @ref hypre_partitioning_descr "here" for a description of the
644  partitioning array. */
645  HYPRE_BigInt *GetRowStarts() const { return hypre_ParCSRMatrixRowStarts(A); }
646 
647  /// Return the parallel column partitioning array.
648  /** See @ref hypre_partitioning_descr "here" for a description of the
649  partitioning array. */
650  HYPRE_BigInt *GetColStarts() const { return hypre_ParCSRMatrixColStarts(A); }
651 
652  virtual MemoryClass GetMemoryClass() const { return GetHypreMemoryClass(); }
653 
654  /// Ensure the action of the transpose is performed fast.
655  /** When HYPRE is built for GPUs, this method will construct and store the
656  transposes of the 'diag' and 'offd' CSR matrices. When HYPRE is not built
657  for GPUs, this method is a no-op.
658 
659  This method is automatically called by MultTranspose().
660 
661  If the matrix is modified the old transpose blocks can be deleted by
662  calling ResetTranspose(). */
663  void EnsureMultTranspose() const;
664 
665  /** @brief Reset (destroy) the internal transpose matrix that is created by
666  EnsureMultTranspose() and MultTranspose().
667 
668  If the matrix is modified, this method should be called to delete the
669  out-of-date transpose that is stored internally. */
670  void ResetTranspose() const;
671 
672  /// Computes y = alpha * A * x + beta * y
673  HYPRE_Int Mult(HypreParVector &x, HypreParVector &y,
674  double alpha = 1.0, double beta = 0.0) const;
675  /// Computes y = alpha * A * x + beta * y
676  HYPRE_Int Mult(HYPRE_ParVector x, HYPRE_ParVector y,
677  double alpha = 1.0, double beta = 0.0) const;
678 
679  /// Computes y = alpha * A^t * x + beta * y
680  /** If the matrix is modified, call ResetTranspose() and optionally
681  EnsureMultTranspose() to make sure this method uses the correct updated
682  transpose. */
684  double alpha = 1.0, double beta = 0.0) const;
685 
686  void Mult(double a, const Vector &x, double b, Vector &y) const;
687 
688  /// Computes y = alpha * A^t * x + beta * y
689  /** If the matrix is modified, call ResetTranspose() and optionally
690  EnsureMultTranspose() to make sure this method uses the correct updated
691  transpose. */
692  void MultTranspose(double a, const Vector &x, double b, Vector &y) const;
693 
694  virtual void Mult(const Vector &x, Vector &y) const
695  { Mult(1.0, x, 0.0, y); }
696 
697  /// Computes y = A^t * x
698  /** If the matrix is modified, call ResetTranspose() and optionally
699  EnsureMultTranspose() to make sure this method uses the correct updated
700  transpose. */
701  virtual void MultTranspose(const Vector &x, Vector &y) const
702  { MultTranspose(1.0, x, 0.0, y); }
703 
704  /** @brief Computes y = a * |A| * x + b * y, using entry-wise absolute values
705  of the matrix A. */
706  void AbsMult(double a, const Vector &x, double b, Vector &y) const;
707 
708  /** @brief Computes y = a * |At| * x + b * y, using entry-wise absolute
709  values of the transpose of the matrix A. */
710  void AbsMultTranspose(double a, const Vector &x, double b, Vector &y) const;
711 
712  /** @brief The "Boolean" analog of y = alpha * A * x + beta * y, where
713  elements in the sparsity pattern of the matrix are treated as "true". */
714  void BooleanMult(int alpha, const int *x, int beta, int *y)
715  {
716  HostRead();
717  internal::hypre_ParCSRMatrixBooleanMatvec(A, alpha, const_cast<int*>(x),
718  beta, y);
719  HypreRead();
720  }
721 
722  /** @brief The "Boolean" analog of y = alpha * A^T * x + beta * y, where
723  elements in the sparsity pattern of the matrix are treated as "true". */
724  void BooleanMultTranspose(int alpha, const int *x, int beta, int *y)
725  {
726  HostRead();
727  internal::hypre_ParCSRMatrixBooleanMatvecT(A, alpha, const_cast<int*>(x),
728  beta, y);
729  HypreRead();
730  }
731 
732  /// Initialize all entries with value.
733  HypreParMatrix &operator=(double value)
734  {
735 #if MFEM_HYPRE_VERSION < 22200
736  internal::hypre_ParCSRMatrixSetConstantValues(A, value);
737 #else
738  hypre_ParCSRMatrixSetConstantValues(A, value);
739 #endif
740  return *this;
741  }
742 
743  /** Perform the operation `*this += B`, assuming that both matrices use the
744  same row and column partitions and the same col_map_offd arrays, or B has
745  an empty off-diagonal block. We also assume that the sparsity pattern of
746  `*this` contains that of `B`. */
747  HypreParMatrix &operator+=(const HypreParMatrix &B) { return Add(1.0, B); }
748 
749  /** Perform the operation `*this += beta*B`, assuming that both matrices use
750  the same row and column partitions and the same col_map_offd arrays, or
751  B has an empty off-diagonal block. We also assume that the sparsity
752  pattern of `*this` contains that of `B`. For a more general case consider
753  the stand-alone function ParAdd described below. */
754  HypreParMatrix &Add(const double beta, const HypreParMatrix &B)
755  {
756  MFEM_VERIFY(internal::hypre_ParCSRMatrixSum(A, beta, B.A) == 0,
757  "error in hypre_ParCSRMatrixSum");
758  return *this;
759  }
760 
761  /** @brief Multiply the HypreParMatrix on the left by a block-diagonal
762  parallel matrix @a D and return the result as a new HypreParMatrix. */
763  /** If @a D has a different number of rows than @a A (this matrix), @a D's
764  row starts array needs to be given (as returned by the methods
765  GetDofOffsets/GetTrueDofOffsets of ParFiniteElementSpace). The new
766  matrix @a D*A uses copies of the row- and column-starts arrays, so "this"
767  matrix and @a row_starts can be deleted.
768  @note This operation is local and does not require communication. */
770  HYPRE_BigInt* row_starts = NULL) const;
771 
772  /// Scale the local row i by s(i).
773  void ScaleRows(const Vector & s);
774  /// Scale the local row i by 1./s(i)
775  void InvScaleRows(const Vector & s);
776  /// Scale all entries by s: A_scaled = s*A.
777  void operator*=(double s);
778 
779  /// Remove values smaller in absolute value than some threshold
780  void Threshold(double threshold = 0.0);
781 
782  /** @brief Wrapper for hypre_ParCSRMatrixDropSmallEntries in different
783  versions of hypre. Drop off-diagonal entries that are smaller than
784  tol * l2 norm of its row */
785  /** For HYPRE versions < 2.14, this method just calls Threshold() with
786  threshold = tol * max(l2 row norm). */
787  void DropSmallEntries(double tol);
788 
789  /// If a row contains only zeros, set its diagonal to 1.
790  void EliminateZeroRows() { hypre_ParCSRMatrixFixZeroRows(A); }
791 
792  /** Eliminate rows and columns from the matrix, and rows from the vector B.
793  Modify B with the BC values in X. */
794  void EliminateRowsCols(const Array<int> &rows_cols, const HypreParVector &X,
795  HypreParVector &B);
796 
797  /** Eliminate rows and columns from the matrix and store the eliminated
798  elements in a new matrix Ae (returned), so that the modified matrix and
799  Ae sum to the original matrix. */
800  HypreParMatrix* EliminateRowsCols(const Array<int> &rows_cols);
801 
802  /** Eliminate columns from the matrix and store the eliminated elements in a
803  new matrix Ae (returned) so that the modified matrix and Ae sum to the
804  original matrix. */
806 
807  /// Eliminate rows from the diagonal and off-diagonal blocks of the matrix.
808  void EliminateRows(const Array<int> &rows);
809 
810  /** @brief Eliminate essential BC specified by @a ess_dof_list from the
811  solution @a X to the r.h.s. @a B. */
812  /** This matrix is the matrix with eliminated BC, while @a Ae is such that
813  (A+Ae) is the original (Neumann) matrix before elimination. */
814  void EliminateBC(const HypreParMatrix &Ae, const Array<int> &ess_dof_list,
815  const Vector &X, Vector &B) const;
816 
817  /** @brief Eliminate essential (Dirichlet) boundary conditions.
818 
819  @param[in] ess_dofs indices of the degrees of freedom belonging to the
820  essential boundary conditions.
821  @param[in] diag_policy policy for diagonal entries. */
822  void EliminateBC(const Array<int> &ess_dofs,
823  DiagonalPolicy diag_policy);
824 
825  /// Update the internal hypre_ParCSRMatrix object, A, to be on host.
826  /** After this call A's diagonal and off-diagonal should not be modified
827  until after a suitable call to {Host,Hypre}{Write,ReadWrite}. */
828  void HostRead() const { Read(Device::GetHostMemoryClass()); }
829 
830  /// Update the internal hypre_ParCSRMatrix object, A, to be on host.
831  /** After this call A's diagonal and off-diagonal can be modified on host
832  and subsequent calls to Hypre{Read,Write,ReadWrite} will require a deep
833  copy of the data if hypre is built with device support. */
834  void HostReadWrite() { ReadWrite(Device::GetHostMemoryClass()); }
835 
836  /// Update the internal hypre_ParCSRMatrix object, A, to be on host.
837  /** Similar to HostReadWrite(), except that the data will never be copied
838  from device to host to ensure host contains the correct current data. */
840 
841  /** @brief Update the internal hypre_ParCSRMatrix object, A, to be in hypre
842  memory space. */
843  /** After this call A's diagonal and off-diagonal should not be modified
844  until after a suitable call to {Host,Hypre}{Write,ReadWrite}. */
845  void HypreRead() const { Read(GetHypreMemoryClass()); }
846 
847  /** @brief Update the internal hypre_ParCSRMatrix object, A, to be in hypre
848  memory space. */
849  /** After this call A's diagonal and off-diagonal can be modified in hypre
850  memory space and subsequent calls to Host{Read,Write,ReadWrite} will
851  require a deep copy of the data if hypre is built with device support. */
852  void HypreReadWrite() { ReadWrite(GetHypreMemoryClass()); }
853 
854  /** @brief Update the internal hypre_ParCSRMatrix object, A, to be in hypre
855  memory space. */
856  /** Similar to HostReadWrite(), except that the data will never be copied
857  from host to hypre memory space to ensure the latter contains the correct
858  current data. */
859  void HypreWrite() { Write(GetHypreMemoryClass()); }
860 
861  Memory<HYPRE_Int> &GetDiagMemoryI() { return mem_diag.I; }
862  Memory<HYPRE_Int> &GetDiagMemoryJ() { return mem_diag.J; }
863  Memory<double> &GetDiagMemoryData() { return mem_diag.data; }
864 
865  const Memory<HYPRE_Int> &GetDiagMemoryI() const { return mem_diag.I; }
866  const Memory<HYPRE_Int> &GetDiagMemoryJ() const { return mem_diag.J; }
867  const Memory<double> &GetDiagMemoryData() const { return mem_diag.data; }
868 
869  /// Prints the locally owned rows in parallel
870  void Print(const char *fname, HYPRE_Int offi = 0, HYPRE_Int offj = 0) const;
871  /// Reads the matrix from a file
872  void Read(MPI_Comm comm, const char *fname);
873  /// Read a matrix saved as a HYPRE_IJMatrix
874  void Read_IJMatrix(MPI_Comm comm, const char *fname);
875 
876  /// Print information about the hypre_ParCSRCommPkg of the HypreParMatrix.
877  void PrintCommPkg(std::ostream &out = mfem::out) const;
878 
879  /** @brief Print sizes and hashes for all data arrays of the HypreParMatrix
880  from the local MPI rank. */
881  /** This is a compact text representation of the local data of the
882  HypreParMatrix that can be used to compare matrices from different runs
883  without the need to save the whole matrix. */
884  void PrintHash(std::ostream &out) const;
885 
886  /// Calls hypre's destroy function
887  virtual ~HypreParMatrix() { Destroy(); }
888 
889  Type GetType() const { return Hypre_ParCSR; }
890 };
891 
892 /// @brief Make @a A_hyp steal ownership of its diagonal part @a A_diag.
893 ///
894 /// If @a A_hyp does not own I and J, then they are aliases pointing to the I
895 /// and J arrays in @a A_diag. In that case, this function swaps the memory
896 /// objects. Similarly for the data array.
897 ///
898 /// After this function is called, @a A_hyp will own all of the arrays of its
899 /// diagonal part.
900 ///
901 /// @note I and J can only be aliases when HYPRE_BIGINT is disabled.
902 void HypreStealOwnership(HypreParMatrix &A_hyp, SparseMatrix &A_diag);
903 
904 #if MFEM_HYPRE_VERSION >= 21800
905 
907 {
908  MATRIX_ONLY,
909  RHS_ONLY,
911 };
912 
913 /** Constructs and applies block diagonal inverse of HypreParMatrix.
914  The enum @a job specifies whether the matrix or the RHS should be
915  scaled (or both). */
916 void BlockInverseScale(const HypreParMatrix *A, HypreParMatrix *C,
917  const Vector *b, HypreParVector *d,
918  int blocksize, BlockInverseScaleJob job);
919 #endif
920 
921 /** @brief Return a new matrix `C = alpha*A + beta*B`, assuming that both `A`
922  and `B` use the same row and column partitions and the same `col_map_offd`
923  arrays. */
924 HypreParMatrix *Add(double alpha, const HypreParMatrix &A,
925  double beta, const HypreParMatrix &B);
926 
927 /** Returns the matrix @a A * @a B. Returned matrix does not necessarily own
928  row or column starts unless the bool @a own_matrix is set to true. */
929 HypreParMatrix * ParMult(const HypreParMatrix *A, const HypreParMatrix *B,
930  bool own_matrix = false);
931 /// Returns the matrix A + B
932 /** It is assumed that both matrices use the same row and column partitions and
933  the same col_map_offd arrays. */
934 HypreParMatrix * ParAdd(const HypreParMatrix *A, const HypreParMatrix *B);
935 
936 /// Returns the matrix P^t * A * P
937 HypreParMatrix * RAP(const HypreParMatrix *A, const HypreParMatrix *P);
938 /// Returns the matrix Rt^t * A * P
939 HypreParMatrix * RAP(const HypreParMatrix * Rt, const HypreParMatrix *A,
940  const HypreParMatrix *P);
941 
942 /// Returns a merged hypre matrix constructed from hypre matrix blocks.
943 /** It is assumed that all block matrices use the same communicator, and the
944  block sizes are consistent in rows and columns. Rows and columns are
945  renumbered but not redistributed in parallel, e.g. the block rows owned by
946  each process remain on that process in the resulting matrix. Some blocks can
947  be NULL. Each block and the entire system can be rectangular. Scalability to
948  extremely large processor counts is limited by global MPI communication, see
949  GatherBlockOffsetData() in hypre.cpp. */
950 HypreParMatrix * HypreParMatrixFromBlocks(Array2D<HypreParMatrix*> &blocks,
951  Array2D<double> *blockCoeff=NULL);
952 
953 /** @brief Eliminate essential BC specified by @a ess_dof_list from the solution
954  @a X to the r.h.s. @a B. */
955 /** Here @a A is a matrix with eliminated BC, while @a Ae is such that (A+Ae) is
956  the original (Neumann) matrix before elimination. */
957 void EliminateBC(const HypreParMatrix &A, const HypreParMatrix &Ae,
958  const Array<int> &ess_dof_list, const Vector &X, Vector &B);
959 
960 
961 /// Parallel smoothers in hypre
962 class HypreSmoother : public Solver
963 {
964 protected:
965  /// The linear system matrix
967  /// Right-hand side and solution vectors
968  mutable HypreParVector *B, *X;
969  /** @brief Auxiliary buffers for the case when the input or output arrays in
970  methods like Mult(const Vector &, Vector &) need to be deep copied in
971  order to be used by hypre. */
973  /// Temporary vectors
974  mutable HypreParVector *V, *Z;
975  /// FIR Filter Temporary Vectors
976  mutable HypreParVector *X0, *X1;
977 
978  /** Smoother type from hypre_ParCSRRelax() in ams.c plus extensions, see the
979  enumeration Type below. */
980  int type;
981  /// Number of relaxation sweeps
983  /// Damping coefficient (usually <= 1)
984  double relax_weight;
985  /// SOR parameter (usually in (0,2))
986  double omega;
987  /// Order of the smoothing polynomial
989  /// Fraction of spectrum to smooth for polynomial relaxation
991  /// Apply the polynomial smoother to A or D^{-1/2} A D^{-1/2}
993 
994  /// Taubin's lambda-mu method parameters
995  double lambda;
996  double mu;
998 
999  /// l1 norms of the rows of A
1000  double *l1_norms;
1001  /// If set, take absolute values of the computed l1_norms
1003  /// Number of CG iterations to determine eigenvalue estimates
1005  /// Maximal eigenvalue estimate for polynomial smoothing
1006  double max_eig_est;
1007  /// Minimal eigenvalue estimate for polynomial smoothing
1008  double min_eig_est;
1009  /// Parameters for windowing function of FIR filter
1010  double window_params[3];
1011 
1012  /// Combined coefficients for windowing and Chebyshev polynomials.
1013  double* fir_coeffs;
1014 
1015  /// A flag that indicates whether the linear system matrix A is symmetric
1017 
1018 public:
1019  /** Hypre smoother types:
1020  0 = Jacobi
1021  1 = l1-scaled Jacobi
1022  2 = l1-scaled block Gauss-Seidel/SSOR
1023  4 = truncated l1-scaled block Gauss-Seidel/SSOR
1024  5 = lumped Jacobi
1025  6 = Gauss-Seidel
1026  10 = On-processor forward solve for matrix w/ triangular structure
1027  16 = Chebyshev
1028  1001 = Taubin polynomial smoother
1029  1002 = FIR polynomial smoother. */
1030  enum Type { Jacobi = 0, l1Jacobi = 1, l1GS = 2, l1GStr = 4, lumpedJacobi = 5,
1031  GS = 6, OPFS = 10, Chebyshev = 16, Taubin = 1001, FIR = 1002
1032  };
1033 #if !defined(HYPRE_USING_GPU)
1034  static constexpr Type default_type = l1GS;
1035 #else
1036  static constexpr Type default_type = l1Jacobi;
1037 #endif
1038 
1039  HypreSmoother();
1040 
1041  HypreSmoother(const HypreParMatrix &A_, int type = default_type,
1042  int relax_times = 1, double relax_weight = 1.0,
1043  double omega = 1.0, int poly_order = 2,
1044  double poly_fraction = .3, int eig_est_cg_iter = 10);
1045 
1046  /// Set the relaxation type and number of sweeps
1048  /// Set SOR-related parameters
1049  void SetSOROptions(double relax_weight, double omega);
1050  /// Set parameters for polynomial smoothing
1051  /** By default, 10 iterations of CG are used to estimate the eigenvalues.
1052  Setting eig_est_cg_iter = 0 uses hypre's hypre_ParCSRMaxEigEstimate() instead. */
1053  void SetPolyOptions(int poly_order, double poly_fraction,
1054  int eig_est_cg_iter = 10);
1055  /// Set parameters for Taubin's lambda-mu method
1056  void SetTaubinOptions(double lambda, double mu, int iter);
1057 
1058  /// Convenience function for setting canonical windowing parameters
1059  void SetWindowByName(const char* window_name);
1060  /// Set parameters for windowing function for FIR smoother.
1061  void SetWindowParameters(double a, double b, double c);
1062  /// Compute window and Chebyshev coefficients for given polynomial order.
1063  void SetFIRCoefficients(double max_eig);
1064 
1065  /// After computing l1-norms, replace them with their absolute values.
1066  /** By default, the l1-norms take their sign from the corresponding diagonal
1067  entries in the associated matrix. */
1068  void SetPositiveDiagonal(bool pos = true) { pos_l1_norms = pos; }
1069 
1070  /** Explicitly indicate whether the linear system matrix A is symmetric. If A
1071  is symmetric, the smoother will also be symmetric. In this case, calling
1072  MultTranspose will be redirected to Mult. (This is also done if the
1073  smoother is diagonal.) By default, A is assumed to be nonsymmetric. */
1074  void SetOperatorSymmetry(bool is_sym) { A_is_symmetric = is_sym; }
1075 
1076  /** Set/update the associated operator. Must be called after setting the
1077  HypreSmoother type and options. */
1078  virtual void SetOperator(const Operator &op);
1079 
1080  /// Relax the linear system Ax=b
1081  virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
1082  virtual void Mult(const Vector &b, Vector &x) const;
1083 
1084  /// Apply transpose of the smoother to relax the linear system Ax=b
1085  virtual void MultTranspose(const Vector &b, Vector &x) const;
1086 
1087  virtual ~HypreSmoother();
1088 };
1089 
1090 
1091 /// Abstract class for hypre's solvers and preconditioners
1092 class HypreSolver : public Solver
1093 {
1094 public:
1095  /// How to treat errors returned by hypre function calls.
1097  {
1098  IGNORE_HYPRE_ERRORS, ///< Ignore hypre errors (see e.g. HypreADS)
1099  WARN_HYPRE_ERRORS, ///< Issue warnings on hypre errors
1100  ABORT_HYPRE_ERRORS ///< Abort on hypre errors (default in base class)
1101  };
1102 
1103 protected:
1104  /// The linear system matrix
1106 
1107  /// Right-hand side and solution vector
1108  mutable HypreParVector *B, *X;
1109 
1111 
1112  /// Was hypre's Setup function called already?
1113  mutable int setup_called;
1114 
1115  /// How to treat hypre errors.
1117 
1118  /// @brief Makes the internal HypreParVector%s @a B and @a X wrap the input
1119  /// vectors @a b and @a x.
1120  ///
1121  /// Returns true if @a x can be shallow-copied, false otherwise.
1122  bool WrapVectors(const Vector &b, Vector &x) const;
1123 
1124 public:
1125  HypreSolver();
1126 
1127  HypreSolver(const HypreParMatrix *A_);
1128 
1129  /// Typecast to HYPRE_Solver -- return the solver
1130  virtual operator HYPRE_Solver() const = 0;
1131 
1132  /// hypre's internal Setup function
1133  virtual HYPRE_PtrToParSolverFcn SetupFcn() const = 0;
1134  /// hypre's internal Solve function
1135  virtual HYPRE_PtrToParSolverFcn SolveFcn() const = 0;
1136 
1137  ///@{
1138 
1139  /// @brief Set up the solver (if not set up already, also called
1140  /// automatically by HypreSolver::Mult).
1141  virtual void Setup(const HypreParVector &b, HypreParVector &x) const;
1142  /// @brief Set up the solver (if not set up already, also called
1143  /// automatically by HypreSolver::Mult).
1144  virtual void Setup(const Vector &b, Vector &x) const;
1145 
1146  ///@}
1147 
1148  virtual void SetOperator(const Operator &op)
1149  { mfem_error("HypreSolvers do not support SetOperator!"); }
1150 
1151  virtual MemoryClass GetMemoryClass() const { return GetHypreMemoryClass(); }
1152 
1153  ///@{
1154 
1155  /// Solve the linear system Ax=b
1156  virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
1157  /// Solve the linear system Ax=b
1158  virtual void Mult(const Vector &b, Vector &x) const;
1159 
1160  ///@}
1161 
1162  /** @brief Set the behavior for treating hypre errors, see the ErrorMode
1163  enum. The default mode in the base class is ABORT_HYPRE_ERRORS. */
1164  /** Currently, there are three cases in derived classes where the error flag
1165  is set to IGNORE_HYPRE_ERRORS:
1166  * in the method HypreBoomerAMG::SetElasticityOptions(), and
1167  * in the constructor of classes HypreAMS and HypreADS.
1168  The reason for this is that a nonzero hypre error is returned) when
1169  hypre_ParCSRComputeL1Norms() encounters zero row in a matrix, which is
1170  expected in some cases with the above solvers. */
1171  void SetErrorMode(ErrorMode err_mode) const { error_mode = err_mode; }
1172 
1173  virtual ~HypreSolver();
1174 };
1175 
1176 
1177 #if MFEM_HYPRE_VERSION >= 21800
1178 /** Preconditioner for HypreParMatrices that are triangular in some ordering.
1179  Finds correct ordering and performs forward substitution on processor
1180  as approximate inverse. Exact on one processor. */
1182 {
1183 public:
1185  explicit HypreTriSolve(const HypreParMatrix &A) : HypreSolver(&A) { }
1186  virtual operator HYPRE_Solver() const { return NULL; }
1187 
1188  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1189  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSROnProcTriSetup; }
1190  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1191  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSROnProcTriSolve; }
1192 
1193  const HypreParMatrix* GetData() const { return A; }
1194 
1195  /// Deprecated. Use HypreTriSolve::GetData() const instead.
1196  MFEM_DEPRECATED HypreParMatrix* GetData()
1197  { return const_cast<HypreParMatrix*>(A); }
1198 
1199  virtual ~HypreTriSolve() { }
1200 };
1201 #endif
1202 
1203 /// PCG solver in hypre
1204 class HyprePCG : public HypreSolver
1205 {
1206 private:
1207  HYPRE_Solver pcg_solver;
1208 
1209  HypreSolver * precond;
1210 
1211 public:
1212  HyprePCG(MPI_Comm comm);
1213 
1214  HyprePCG(const HypreParMatrix &A_);
1215 
1216  virtual void SetOperator(const Operator &op);
1217 
1218  void SetTol(double tol);
1219  void SetAbsTol(double atol);
1220  void SetMaxIter(int max_iter);
1221  void SetLogging(int logging);
1222  void SetPrintLevel(int print_lvl);
1223 
1224  /// Set the hypre solver to be used as a preconditioner
1225  void SetPreconditioner(HypreSolver &precond);
1226 
1227  /** Use the L2 norm of the residual for measuring PCG convergence, plus
1228  (optionally) 1) periodically recompute true residuals from scratch; and
1229  2) enable residual-based stopping criteria. */
1230  void SetResidualConvergenceOptions(int res_frequency=-1, double rtol=0.0);
1231 
1232  /// deprecated: use SetZeroInitialIterate()
1233  MFEM_DEPRECATED void SetZeroInintialIterate() { iterative_mode = false; }
1234 
1235  /// non-hypre setting
1237 
1238  void GetNumIterations(int &num_iterations) const
1239  {
1240  HYPRE_Int num_it;
1241  HYPRE_ParCSRPCGGetNumIterations(pcg_solver, &num_it);
1242  num_iterations = internal::to_int(num_it);
1243  }
1244 
1245  void GetFinalResidualNorm(double &final_res_norm) const
1246  {
1247  HYPRE_ParCSRPCGGetFinalRelativeResidualNorm(pcg_solver,
1248  &final_res_norm);
1249  }
1250 
1251  /// The typecast to HYPRE_Solver returns the internal pcg_solver
1252  virtual operator HYPRE_Solver() const { return pcg_solver; }
1253 
1254  /// PCG Setup function
1255  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1256  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRPCGSetup; }
1257  /// PCG Solve function
1258  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1259  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRPCGSolve; }
1260 
1261  /// Solve Ax=b with hypre's PCG
1262  virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
1263  using HypreSolver::Mult;
1264 
1265  virtual ~HyprePCG();
1266 };
1267 
1268 /// GMRES solver in hypre
1269 class HypreGMRES : public HypreSolver
1270 {
1271 private:
1272  HYPRE_Solver gmres_solver;
1273 
1274  HypreSolver * precond;
1275 
1276  /// Default, generally robust, GMRES options
1277  void SetDefaultOptions();
1278 
1279 public:
1280  HypreGMRES(MPI_Comm comm);
1281 
1282  HypreGMRES(const HypreParMatrix &A_);
1283 
1284  virtual void SetOperator(const Operator &op);
1285 
1286  void SetTol(double tol);
1287  void SetAbsTol(double tol);
1288  void SetMaxIter(int max_iter);
1289  void SetKDim(int dim);
1290  void SetLogging(int logging);
1291  void SetPrintLevel(int print_lvl);
1292 
1293  /// Set the hypre solver to be used as a preconditioner
1294  void SetPreconditioner(HypreSolver &precond);
1295 
1296  /// deprecated: use SetZeroInitialIterate()
1297  MFEM_DEPRECATED void SetZeroInintialIterate() { iterative_mode = false; }
1298 
1299  /// non-hypre setting
1301 
1302  void GetNumIterations(int &num_iterations) const
1303  {
1304  HYPRE_Int num_it;
1305  HYPRE_ParCSRGMRESGetNumIterations(gmres_solver, &num_it);
1306  num_iterations = internal::to_int(num_it);
1307  }
1308 
1309  void GetFinalResidualNorm(double &final_res_norm) const
1310  {
1311  HYPRE_ParCSRGMRESGetFinalRelativeResidualNorm(gmres_solver,
1312  &final_res_norm);
1313  }
1314 
1315  /// The typecast to HYPRE_Solver returns the internal gmres_solver
1316  virtual operator HYPRE_Solver() const { return gmres_solver; }
1317 
1318  /// GMRES Setup function
1319  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1320  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRGMRESSetup; }
1321  /// GMRES Solve function
1322  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1323  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRGMRESSolve; }
1324 
1325  /// Solve Ax=b with hypre's GMRES
1326  virtual void Mult (const HypreParVector &b, HypreParVector &x) const;
1327  using HypreSolver::Mult;
1328 
1329  virtual ~HypreGMRES();
1330 };
1331 
1332 /// Flexible GMRES solver in hypre
1333 class HypreFGMRES : public HypreSolver
1334 {
1335 private:
1336  HYPRE_Solver fgmres_solver;
1337 
1338  HypreSolver * precond;
1339 
1340  /// Default, generally robust, FGMRES options
1341  void SetDefaultOptions();
1342 
1343 public:
1344  HypreFGMRES(MPI_Comm comm);
1345 
1346  HypreFGMRES(const HypreParMatrix &A_);
1347 
1348  virtual void SetOperator(const Operator &op);
1349 
1350  void SetTol(double tol);
1351  void SetMaxIter(int max_iter);
1352  void SetKDim(int dim);
1353  void SetLogging(int logging);
1354  void SetPrintLevel(int print_lvl);
1355 
1356  /// Set the hypre solver to be used as a preconditioner
1357  void SetPreconditioner(HypreSolver &precond);
1358 
1359  /// deprecated: use SetZeroInitialIterate()
1360  MFEM_DEPRECATED void SetZeroInintialIterate() { iterative_mode = false; }
1361 
1362  /// non-hypre setting
1364 
1365  void GetNumIterations(int &num_iterations) const
1366  {
1367  HYPRE_Int num_it;
1368  HYPRE_ParCSRFlexGMRESGetNumIterations(fgmres_solver, &num_it);
1369  num_iterations = internal::to_int(num_it);
1370  }
1371 
1372  void GetFinalResidualNorm(double &final_res_norm) const
1373  {
1374  HYPRE_ParCSRFlexGMRESGetFinalRelativeResidualNorm(fgmres_solver,
1375  &final_res_norm);
1376  }
1377 
1378  /// The typecast to HYPRE_Solver returns the internal fgmres_solver
1379  virtual operator HYPRE_Solver() const { return fgmres_solver; }
1380 
1381  /// FGMRES Setup function
1382  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1383  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRFlexGMRESSetup; }
1384  /// FGMRES Solve function
1385  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1386  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRFlexGMRESSolve; }
1387 
1388  /// Solve Ax=b with hypre's FGMRES
1389  virtual void Mult (const HypreParVector &b, HypreParVector &x) const;
1390  using HypreSolver::Mult;
1391 
1392  virtual ~HypreFGMRES();
1393 };
1394 
1395 /// The identity operator as a hypre solver
1397 {
1398 public:
1399  virtual operator HYPRE_Solver() const { return NULL; }
1400 
1401  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1402  { return (HYPRE_PtrToParSolverFcn) hypre_ParKrylovIdentitySetup; }
1403  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1404  { return (HYPRE_PtrToParSolverFcn) hypre_ParKrylovIdentity; }
1405 
1406  virtual ~HypreIdentity() { }
1407 };
1408 
1409 /// Jacobi preconditioner in hypre
1411 {
1412 public:
1414  explicit HypreDiagScale(const HypreParMatrix &A) : HypreSolver(&A) { }
1415  virtual operator HYPRE_Solver() const { return NULL; }
1416 
1417  virtual void SetOperator(const Operator &op);
1418 
1419  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1420  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRDiagScaleSetup; }
1421  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1422  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRDiagScale; }
1423 
1424  const HypreParMatrix* GetData() const { return A; }
1425 
1426  /// Deprecated. Use HypreDiagScale::GetData() const instead.
1427  MFEM_DEPRECATED HypreParMatrix* GetData()
1428  { return const_cast<HypreParMatrix*>(A); }
1429 
1430  virtual ~HypreDiagScale() { }
1431 };
1432 
1433 /// The ParaSails preconditioner in hypre
1435 {
1436 private:
1437  HYPRE_Solver sai_precond;
1438 
1439  /// Default, generally robust, ParaSails options
1440  void SetDefaultOptions();
1441 
1442  // If sai_precond is NULL, this method allocates it and sets default options.
1443  // Otherwise the method saves the options from sai_precond, destroys it,
1444  // allocates a new object, and sets its options to the saved values.
1445  void ResetSAIPrecond(MPI_Comm comm);
1446 
1447 public:
1448  HypreParaSails(MPI_Comm comm);
1449 
1451 
1452  virtual void SetOperator(const Operator &op);
1453 
1454  void SetParams(double threshold, int max_levels);
1455  void SetFilter(double filter);
1456  void SetLoadBal(double loadbal);
1457  void SetReuse(int reuse);
1458  void SetLogging(int logging);
1459  void SetSymmetry(int sym);
1460 
1461  /// The typecast to HYPRE_Solver returns the internal sai_precond
1462  virtual operator HYPRE_Solver() const { return sai_precond; }
1463 
1464  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1465  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParaSailsSetup; }
1466  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1467  { return (HYPRE_PtrToParSolverFcn) HYPRE_ParaSailsSolve; }
1468 
1469  virtual ~HypreParaSails();
1470 };
1471 
1472 /** The Euclid preconditioner in Hypre
1473 
1474  Euclid implements the Parallel Incomplete LU factorization technique. For
1475  more information see:
1476 
1477  "A Scalable Parallel Algorithm for Incomplete Factor Preconditioning" by
1478  David Hysom and Alex Pothen, https://doi.org/10.1137/S1064827500376193
1479 */
1480 class HypreEuclid : public HypreSolver
1481 {
1482 private:
1483  HYPRE_Solver euc_precond;
1484 
1485  /// Default, generally robust, Euclid options
1486  void SetDefaultOptions();
1487 
1488  // If euc_precond is NULL, this method allocates it and sets default options.
1489  // Otherwise the method saves the options from euc_precond, destroys it,
1490  // allocates a new object, and sets its options to the saved values.
1491  void ResetEuclidPrecond(MPI_Comm comm);
1492 
1493 public:
1494  HypreEuclid(MPI_Comm comm);
1495 
1496  HypreEuclid(const HypreParMatrix &A);
1497 
1498  void SetLevel(int level);
1499  void SetStats(int stats);
1500  void SetMemory(int mem);
1501  void SetBJ(int bj);
1502  void SetRowScale(int row_scale);
1503 
1504  virtual void SetOperator(const Operator &op);
1505 
1506  /// The typecast to HYPRE_Solver returns the internal euc_precond
1507  virtual operator HYPRE_Solver() const { return euc_precond; }
1508 
1509  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1510  { return (HYPRE_PtrToParSolverFcn) HYPRE_EuclidSetup; }
1511  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1512  { return (HYPRE_PtrToParSolverFcn) HYPRE_EuclidSolve; }
1513 
1514  virtual ~HypreEuclid();
1515 };
1516 
1517 #if MFEM_HYPRE_VERSION >= 21900
1518 /**
1519 @brief Wrapper for Hypre's native parallel ILU preconditioner.
1520 
1521 The default ILU factorization type is ILU(k). If you need to change this, or
1522 any other option, you can use the HYPRE_Solver method to cast the object for use
1523 with Hypre's native functions. For example, if want to use natural ordering
1524 rather than RCM reordering, you can use the following approach:
1525 
1526 @code
1527 mfem::HypreILU ilu();
1528 int reorder_type = 0;
1529 HYPRE_ILUSetLocalReordering(ilu, reorder_type);
1530 @endcode
1531 */
1532 class HypreILU : public HypreSolver
1533 {
1534 private:
1535  HYPRE_Solver ilu_precond;
1536 
1537  /// Set the ILU default options
1538  void SetDefaultOptions();
1539 
1540  /** Reset the ILU preconditioner.
1541  @note If ilu_precond is NULL, this method allocates; otherwise it destroys
1542  ilu_precond and allocates a new object. In both cases the default options
1543  are set. */
1544  void ResetILUPrecond();
1545 
1546 public:
1547  /// Constructor; sets the default options
1548  HypreILU();
1549 
1550  virtual ~HypreILU();
1551 
1552  /// Set the fill level for ILU(k); the default is k=1.
1553  void SetLevelOfFill(HYPRE_Int lev_fill);
1554 
1555  void SetType(HYPRE_Int ilu_type);
1556  void SetMaxIter(HYPRE_Int max_iter);
1557  void SetTol(HYPRE_Real tol);
1558  void SetLocalReordering(HYPRE_Int reorder_type);
1559 
1560  /// Set the print level: 0 = none, 1 = setup, 2 = solve, 3 = setup+solve
1561  void SetPrintLevel(HYPRE_Int print_level);
1562 
1563  /// The typecast to HYPRE_Solver returns the internal ilu_precond
1564  virtual operator HYPRE_Solver() const { return ilu_precond; }
1565 
1566  virtual void SetOperator(const Operator &op);
1567 
1568  /// ILU Setup function
1569  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1570  { return (HYPRE_PtrToParSolverFcn) HYPRE_ILUSetup; }
1571 
1572  /// ILU Solve function
1573  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1574  { return (HYPRE_PtrToParSolverFcn) HYPRE_ILUSolve; }
1575 };
1576 #endif
1577 
1578 /// The BoomerAMG solver in hypre
1580 {
1581 private:
1582  HYPRE_Solver amg_precond;
1583 
1584  /// Rigid body modes
1586 
1587  /// Finite element space for elasticity problems, see SetElasticityOptions()
1588  ParFiniteElementSpace *fespace;
1589 
1590  /// Recompute the rigid-body modes vectors (in the rbms array)
1591  void RecomputeRBMs();
1592 
1593  /// Default, generally robust, BoomerAMG options
1594  void SetDefaultOptions();
1595 
1596  // If amg_precond is NULL, allocates it and sets default options.
1597  // Otherwise saves the options from amg_precond, destroys it, allocates a new
1598  // one, and sets its options to the saved values.
1599  void ResetAMGPrecond();
1600 
1601 public:
1602  HypreBoomerAMG();
1603 
1605 
1606  virtual void SetOperator(const Operator &op);
1607 
1608  /** More robust options for systems, such as elasticity. */
1609  void SetSystemsOptions(int dim, bool order_bynodes=false);
1610 
1611  /** A special elasticity version of BoomerAMG that takes advantage of
1612  geometric rigid body modes and could perform better on some problems, see
1613  "Improving algebraic multigrid interpolation operators for linear
1614  elasticity problems", Baker, Kolev, Yang, NLAA 2009, DOI:10.1002/nla.688.
1615  This solver assumes Ordering::byVDIM in the FiniteElementSpace used to
1616  construct A. */
1618 
1619 #if MFEM_HYPRE_VERSION >= 21800
1620  /** Hypre parameters to use AIR AMG solve for advection-dominated problems.
1621  See "Nonsymmetric Algebraic Multigrid Based on Local Approximate Ideal
1622  Restriction (AIR)," Manteuffel, Ruge, Southworth, SISC (2018),
1623  DOI:/10.1137/17M1144350. Options: "distanceR" -> distance of neighbor
1624  DOFs for the restriction operator; options include 1, 2, and 15 (1.5).
1625  Strings "prerelax" and "postrelax" indicate points to relax on:
1626  F = F-points, C = C-points, A = all points. E.g., FFC -> relax on
1627  F-points, relax again on F-points, then relax on C-points. */
1628  void SetAdvectiveOptions(int distance=15, const std::string &prerelax="",
1629  const std::string &postrelax="FFC");
1630 
1631  /// Expert option - consult hypre documentation/team
1632  void SetStrongThresholdR(double strengthR)
1633  { HYPRE_BoomerAMGSetStrongThresholdR(amg_precond, strengthR); }
1634 
1635  /// Expert option - consult hypre documentation/team
1636  void SetFilterThresholdR(double filterR)
1637  { HYPRE_BoomerAMGSetFilterThresholdR(amg_precond, filterR); }
1638 
1639  /// Expert option - consult hypre documentation/team
1640  void SetRestriction(int restrict_type)
1641  { HYPRE_BoomerAMGSetRestriction(amg_precond, restrict_type); }
1642 
1643  /// Expert option - consult hypre documentation/team
1645  { HYPRE_BoomerAMGSetIsTriangular(amg_precond, 1); }
1646 
1647  /// Expert option - consult hypre documentation/team
1648  void SetGMRESSwitchR(int gmres_switch)
1649  { HYPRE_BoomerAMGSetGMRESSwitchR(amg_precond, gmres_switch); }
1650 
1651  /// Expert option - consult hypre documentation/team
1652  void SetCycleNumSweeps(int prerelax, int postrelax)
1653  {
1654  HYPRE_BoomerAMGSetCycleNumSweeps(amg_precond, prerelax, 1);
1655  HYPRE_BoomerAMGSetCycleNumSweeps(amg_precond, postrelax, 2);
1656  }
1657 #endif
1658 
1659  void SetPrintLevel(int print_level)
1660  { HYPRE_BoomerAMGSetPrintLevel(amg_precond, print_level); }
1661 
1662  void SetMaxIter(int max_iter)
1663  { HYPRE_BoomerAMGSetMaxIter(amg_precond, max_iter); }
1664 
1665  /// Expert option - consult hypre documentation/team
1666  void SetMaxLevels(int max_levels)
1667  { HYPRE_BoomerAMGSetMaxLevels(amg_precond, max_levels); }
1668 
1669  /// Expert option - consult hypre documentation/team
1670  void SetTol(double tol)
1671  { HYPRE_BoomerAMGSetTol(amg_precond, tol); }
1672 
1673  /// Expert option - consult hypre documentation/team
1674  void SetStrengthThresh(double strength)
1675  { HYPRE_BoomerAMGSetStrongThreshold(amg_precond, strength); }
1676 
1677  /// Expert option - consult hypre documentation/team
1678  void SetInterpolation(int interp_type)
1679  { HYPRE_BoomerAMGSetInterpType(amg_precond, interp_type); }
1680 
1681  /// Expert option - consult hypre documentation/team
1682  void SetCoarsening(int coarsen_type)
1683  { HYPRE_BoomerAMGSetCoarsenType(amg_precond, coarsen_type); }
1684 
1685  /// Expert option - consult hypre documentation/team
1686  void SetRelaxType(int relax_type)
1687  { HYPRE_BoomerAMGSetRelaxType(amg_precond, relax_type); }
1688 
1689  /// Expert option - consult hypre documentation/team
1690  void SetCycleType(int cycle_type)
1691  { HYPRE_BoomerAMGSetCycleType(amg_precond, cycle_type); }
1692 
1693  void GetNumIterations(int &num_iterations) const
1694  {
1695  HYPRE_Int num_it;
1696  HYPRE_BoomerAMGGetNumIterations(amg_precond, &num_it);
1697  num_iterations = internal::to_int(num_it);
1698  }
1699 
1700  /// Expert option - consult hypre documentation/team
1701  void SetNodal(int blocksize)
1702  {
1703  HYPRE_BoomerAMGSetNumFunctions(amg_precond, blocksize);
1704  HYPRE_BoomerAMGSetNodal(amg_precond, 1);
1705  }
1706 
1707  /// Expert option - consult hypre documentation/team
1708  void SetAggressiveCoarsening(int num_levels)
1709  { HYPRE_BoomerAMGSetAggNumLevels(amg_precond, num_levels); }
1710 
1711  /// The typecast to HYPRE_Solver returns the internal amg_precond
1712  virtual operator HYPRE_Solver() const { return amg_precond; }
1713 
1714  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1715  { return (HYPRE_PtrToParSolverFcn) HYPRE_BoomerAMGSetup; }
1716  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1717  { return (HYPRE_PtrToParSolverFcn) HYPRE_BoomerAMGSolve; }
1718 
1719  using HypreSolver::Mult;
1720 
1721  virtual ~HypreBoomerAMG();
1722 };
1723 
1724 /// Compute the discrete gradient matrix between the nodal linear and ND1 spaces
1725 HypreParMatrix* DiscreteGrad(ParFiniteElementSpace *edge_fespace,
1726  ParFiniteElementSpace *vert_fespace);
1727 /// Compute the discrete curl matrix between the ND1 and RT0 spaces
1728 HypreParMatrix* DiscreteCurl(ParFiniteElementSpace *face_fespace,
1729  ParFiniteElementSpace *edge_fespace);
1730 
1731 /// The Auxiliary-space Maxwell Solver in hypre
1732 class HypreAMS : public HypreSolver
1733 {
1734 private:
1735  /// Construct AMS solver from finite element space
1736  void Init(ParFiniteElementSpace *edge_space);
1737 
1738  /// Create the hypre solver object and set the default options, given the
1739  /// space dimension @a sdim and cycle type @a cycle_type.
1740  void MakeSolver(int sdim, int cycle_type);
1741 
1742  /// Construct the gradient and interpolation matrices associated with
1743  /// @a edge_fespace, and add them to the solver.
1744  void MakeGradientAndInterpolation(ParFiniteElementSpace *edge_fespace,
1745  int cycle_type);
1746 
1747  /// The underlying hypre solver object
1748  HYPRE_Solver ams;
1749  /// Vertex coordinates
1750  HypreParVector *x, *y, *z;
1751  /// Discrete gradient matrix
1752  HypreParMatrix *G;
1753  /// Nedelec interpolation matrix and its components
1754  HypreParMatrix *Pi, *Pix, *Piy, *Piz;
1755 
1756  /// AMS cycle type
1757  int ams_cycle_type = 0;
1758  /// Spatial dimension of the underlying mesh
1759  int space_dim = 0;
1760  /// Flag set if `SetSingularProblem` is called, needed in `ResetAMSPrecond`
1761  bool singular = false;
1762  /// Flag set if `SetPrintLevel` is called, needed in `ResetAMSPrecond`
1763  int print_level = 1;
1764 
1765  // Recreates another AMS solver with the same options when SetOperator is
1766  // called multiple times.
1767  void ResetAMSPrecond();
1768 
1769 public:
1770  /// @brief Construct the AMS solver on the given edge finite element space.
1771  ///
1772  /// HypreAMS::SetOperator must be called to set the system matrix.
1773  HypreAMS(ParFiniteElementSpace *edge_fespace);
1774 
1775  /// Construct the AMS solver using the given matrix and finite element space.
1776  HypreAMS(const HypreParMatrix &A, ParFiniteElementSpace *edge_fespace);
1777 
1778  /// @brief Construct the AMS solver using the provided discrete gradient
1779  /// matrix @a G_ and the vertex coordinate vectors @a x_, @a y_, and @a z_.
1780  ///
1781  /// For 2D problems, @a z_ may be NULL. All other parameters must be
1782  /// non-NULL. The solver assumes ownership of G_, x_, y_, and z_.
1784  HypreParVector *y_, HypreParVector *z_=NULL);
1785 
1786  virtual void SetOperator(const Operator &op);
1787 
1788  void SetPrintLevel(int print_lvl);
1789 
1790  /// Set this option when solving a curl-curl problem with zero mass term
1792  {
1793  HYPRE_AMSSetBetaPoissonMatrix(ams, NULL);
1794  singular = true;
1795  }
1796 
1797  /// The typecast to HYPRE_Solver returns the internal ams object
1798  virtual operator HYPRE_Solver() const { return ams; }
1799 
1800  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1801  { return (HYPRE_PtrToParSolverFcn) HYPRE_AMSSetup; }
1802  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1803  { return (HYPRE_PtrToParSolverFcn) HYPRE_AMSSolve; }
1804 
1805  virtual ~HypreAMS();
1806 };
1807 
1808 /// The Auxiliary-space Divergence Solver in hypre
1809 class HypreADS : public HypreSolver
1810 {
1811 private:
1812  /// Construct ADS solver from finite element space
1813  void Init(ParFiniteElementSpace *face_fespace);
1814 
1815  /// Create the hypre solver object and set the default options, using the
1816  /// cycle type cycle_type and AMS cycle type ams_cycle_type data members.
1817  void MakeSolver();
1818 
1819  /// Construct the discrete curl, gradient and interpolation matrices
1820  /// associated with @a face_fespace, and add them to the solver.
1821  void MakeDiscreteMatrices(ParFiniteElementSpace *face_fespace);
1822 
1823  HYPRE_Solver ads;
1824 
1825  /// Vertex coordinates
1826  HypreParVector *x, *y, *z;
1827  /// Discrete gradient matrix
1828  HypreParMatrix *G;
1829  /// Discrete curl matrix
1830  HypreParMatrix *C;
1831  /// Nedelec interpolation matrix and its components
1832  HypreParMatrix *ND_Pi, *ND_Pix, *ND_Piy, *ND_Piz;
1833  /// Raviart-Thomas interpolation matrix and its components
1834  HypreParMatrix *RT_Pi, *RT_Pix, *RT_Piy, *RT_Piz;
1835 
1836  /// ADS cycle type
1837  const int cycle_type = 11;
1838  /// AMS cycle type
1839  const int ams_cycle_type = 14;
1840  /// ADS print level
1841  int print_level = 1;
1842 
1843  // Recreates another ADS solver with the same options when SetOperator is
1844  // called multiple times.
1845  void ResetADSPrecond();
1846 public:
1847  HypreADS(ParFiniteElementSpace *face_fespace);
1848 
1849  HypreADS(const HypreParMatrix &A, ParFiniteElementSpace *face_fespace);
1850 
1851  /// @brief Construct the ADS solver using the provided discrete curl matrix
1852  /// @a C, discrete gradient matrix @a G_ and vertex coordinate vectors @a x_,
1853  /// @a y_, and @a z_.
1854  ///
1855  /// None of the inputs may be NULL. The solver assumes ownership of C_, G_,
1856  /// x_, y_, and z_.
1859 
1860  virtual void SetOperator(const Operator &op);
1861 
1862  void SetPrintLevel(int print_lvl);
1863 
1864  /// The typecast to HYPRE_Solver returns the internal ads object
1865  virtual operator HYPRE_Solver() const { return ads; }
1866 
1867  virtual HYPRE_PtrToParSolverFcn SetupFcn() const
1868  { return (HYPRE_PtrToParSolverFcn) HYPRE_ADSSetup; }
1869  virtual HYPRE_PtrToParSolverFcn SolveFcn() const
1870  { return (HYPRE_PtrToParSolverFcn) HYPRE_ADSSolve; }
1871 
1872  virtual ~HypreADS();
1873 };
1874 
1875 /** LOBPCG eigenvalue solver in hypre
1876 
1877  The Locally Optimal Block Preconditioned Conjugate Gradient (LOBPCG)
1878  eigenvalue solver is designed to find the lowest eigenmodes of the
1879  generalized eigenvalue problem:
1880  A x = lambda M x
1881  where A is symmetric, potentially indefinite and M is symmetric positive
1882  definite. The eigenvectors are M-orthonormal, meaning that
1883  x^T M x = 1 and x^T M y = 0,
1884  if x and y are distinct eigenvectors. The matrix M is optional and is
1885  assumed to be the identity if left unset.
1886 
1887  The efficiency of LOBPCG relies on the availability of a suitable
1888  preconditioner for the matrix A. The preconditioner is supplied through the
1889  SetPreconditioner() method. It should be noted that the operator used with
1890  the preconditioner need not be A itself.
1891 
1892  For more information regarding LOBPCG see "Block Locally Optimal
1893  Preconditioned Eigenvalue Xolvers (BLOPEX) in Hypre and PETSc" by
1894  A. Knyazev, M. Argentati, I. Lashuk, and E. Ovtchinnikov, SISC, 29(5),
1895  2224-2239, 2007.
1896 */
1898 {
1899 private:
1900  MPI_Comm comm;
1901  int myid;
1902  int numProcs;
1903  int nev; // Number of desired eigenmodes
1904  int seed; // Random seed used for initial vectors
1905 
1906  HYPRE_BigInt glbSize; // Global number of DoFs in the linear system
1907  HYPRE_BigInt * part; // Row partitioning of the linear system
1908 
1909  // Pointer to HYPRE's solver struct
1910  HYPRE_Solver lobpcg_solver;
1911 
1912  // Interface for matrix storage type
1913  mv_InterfaceInterpreter interpreter;
1914 
1915  // Interface for setting up and performing matrix-vector products
1916  HYPRE_MatvecFunctions matvec_fn;
1917 
1918  // Eigenvalues
1919  Array<double> eigenvalues;
1920 
1921  // Forward declaration
1922  class HypreMultiVector;
1923 
1924  // MultiVector to store eigenvectors
1925  HypreMultiVector * multi_vec;
1926 
1927  // Empty vectors used to setup the matrices and preconditioner
1928  HypreParVector * x;
1929 
1930  // An optional operator which projects vectors into a desired subspace
1931  Operator * subSpaceProj;
1932 
1933  /// Internal class to represent a set of eigenvectors
1934  class HypreMultiVector
1935  {
1936  private:
1937  // Pointer to hypre's multi-vector object
1938  mv_MultiVectorPtr mv_ptr;
1939 
1940  // Wrappers for each member of the multivector
1941  HypreParVector ** hpv;
1942 
1943  // Number of vectors in the multivector
1944  int nv;
1945 
1946  public:
1947  HypreMultiVector(int n, HypreParVector & v,
1948  mv_InterfaceInterpreter & interpreter);
1949  ~HypreMultiVector();
1950 
1951  /// Set random values
1952  void Randomize(HYPRE_Int seed);
1953 
1954  /// Extract a single HypreParVector object
1955  HypreParVector & GetVector(unsigned int i);
1956 
1957  /// Transfers ownership of data to returned array of vectors
1958  HypreParVector ** StealVectors();
1959 
1960  operator mv_MultiVectorPtr() const { return mv_ptr; }
1961 
1962  mv_MultiVectorPtr & GetMultiVector() { return mv_ptr; }
1963  };
1964 
1965  static void * OperatorMatvecCreate( void *A, void *x );
1966  static HYPRE_Int OperatorMatvec( void *matvec_data,
1967  HYPRE_Complex alpha,
1968  void *A,
1969  void *x,
1970  HYPRE_Complex beta,
1971  void *y );
1972  static HYPRE_Int OperatorMatvecDestroy( void *matvec_data );
1973 
1974  static HYPRE_Int PrecondSolve(void *solver,
1975  void *A,
1976  void *b,
1977  void *x);
1978  static HYPRE_Int PrecondSetup(void *solver,
1979  void *A,
1980  void *b,
1981  void *x);
1982 
1983 public:
1984  HypreLOBPCG(MPI_Comm comm);
1985  ~HypreLOBPCG();
1986 
1987  void SetTol(double tol);
1988  void SetRelTol(double rel_tol);
1989  void SetMaxIter(int max_iter);
1990  void SetPrintLevel(int logging);
1991  void SetNumModes(int num_eigs) { nev = num_eigs; }
1992  void SetPrecondUsageMode(int pcg_mode);
1993  void SetRandomSeed(int s) { seed = s; }
1994  void SetInitialVectors(int num_vecs, HypreParVector ** vecs);
1995 
1996  // The following four methods support general operators
1997  void SetPreconditioner(Solver & precond);
1998  void SetOperator(Operator & A);
1999  void SetMassMatrix(Operator & M);
2000  void SetSubSpaceProjector(Operator & proj) { subSpaceProj = &proj; }
2001 
2002  /// Solve the eigenproblem
2003  void Solve();
2004 
2005  /// Collect the converged eigenvalues
2006  void GetEigenvalues(Array<double> & eigenvalues) const;
2007 
2008  /// Extract a single eigenvector
2009  const HypreParVector & GetEigenvector(unsigned int i) const;
2010 
2011  /// Transfer ownership of the converged eigenvectors
2012  HypreParVector ** StealEigenvectors() { return multi_vec->StealVectors(); }
2013 };
2014 
2015 /** AME eigenvalue solver in hypre
2016 
2017  The Auxiliary space Maxwell Eigensolver (AME) is designed to find
2018  the lowest eigenmodes of the generalized eigenvalue problem:
2019  Curl Curl x = lambda M x
2020  where the Curl Curl operator is discretized using Nedelec finite element
2021  basis functions. Properties of this discretization are essential to
2022  eliminating the large null space of the Curl Curl operator.
2023 
2024  This eigensolver relies upon the LOBPCG eigensolver internally. It is also
2025  expected that the preconditioner supplied to this method will be the
2026  HypreAMS preconditioner defined above.
2027 
2028  As with LOBPCG, the operator set in the preconditioner need not be the same
2029  as A. This flexibility may be useful in solving eigenproblems which bare a
2030  strong resemblance to the Curl Curl problems for which AME is designed.
2031 
2032  Unlike LOBPCG, this eigensolver requires that the mass matrix be set.
2033  It is possible to circumvent this by passing an identity operator as the
2034  mass matrix but it seems unlikely that this would be useful so it is not the
2035  default behavior.
2036 */
2038 {
2039 private:
2040  int myid;
2041  int numProcs;
2042  int nev; // Number of desired eigenmodes
2043  bool setT;
2044 
2045  // Pointer to HYPRE's AME solver struct
2046  HYPRE_Solver ame_solver;
2047 
2048  // Pointer to HYPRE's AMS solver struct
2049  HypreSolver * ams_precond;
2050 
2051  // Eigenvalues
2052  HYPRE_Real * eigenvalues;
2053 
2054  // MultiVector to store eigenvectors
2055  HYPRE_ParVector * multi_vec;
2056 
2057  // HypreParVector wrappers to contain eigenvectors
2058  mutable HypreParVector ** eigenvectors;
2059 
2060  void createDummyVectors() const;
2061 
2062 public:
2063  HypreAME(MPI_Comm comm);
2064  ~HypreAME();
2065 
2066  void SetTol(double tol);
2067  void SetRelTol(double rel_tol);
2068  void SetMaxIter(int max_iter);
2069  void SetPrintLevel(int logging);
2070  void SetNumModes(int num_eigs);
2071 
2072  // The following four methods support operators of type HypreParMatrix.
2073  void SetPreconditioner(HypreSolver & precond);
2074  void SetOperator(const HypreParMatrix & A);
2075  void SetMassMatrix(const HypreParMatrix & M);
2076 
2077  /// Solve the eigenproblem
2078  void Solve();
2079 
2080  /// Collect the converged eigenvalues
2081  void GetEigenvalues(Array<double> & eigenvalues) const;
2082 
2083  /// Extract a single eigenvector
2084  const HypreParVector & GetEigenvector(unsigned int i) const;
2085 
2086  /// Transfer ownership of the converged eigenvectors
2088 };
2089 
2090 }
2091 
2092 #endif // MFEM_USE_MPI
2093 
2094 #endif
Type GetType() const
Definition: hypre.hpp:889
MemoryType GetHypreMemoryType()
The MemoryType used by MFEM when allocating arrays for Hypre objects.
Definition: hypre.hpp:149
virtual ~HypreBoomerAMG()
Definition: hypre.cpp:5239
void SetAbsTol(double atol)
Definition: hypre.cpp:4000
Memory< double > auxX
Definition: hypre.hpp:972
void SetTol(double tol)
Definition: hypre.cpp:3995
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition: hypre.cpp:4210
void SetType(HYPRE_Int ilu_type)
Definition: hypre.cpp:4751
void EliminateRowsCols(const Array< int > &rows_cols, const HypreParVector &X, HypreParVector &B)
Definition: hypre.cpp:2272
HypreADS(ParFiniteElementSpace *face_fespace)
Definition: hypre.cpp:5668
const HypreParMatrix * GetData() const
Definition: hypre.hpp:1193
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(), hypre will be finalized automatically at program exit.
Definition: hypre.hpp:80
static constexpr Type default_type
Definition: hypre.hpp:1034
MPI_Comm GetComm() const
MPI communicator.
Definition: hypre.hpp:534
HypreEuclid(MPI_Comm comm)
Definition: hypre.cpp:4606
void SetErrorMode(ErrorMode err_mode) const
Set the behavior for treating hypre errors, see the ErrorMode enum. The default mode in the base clas...
Definition: hypre.hpp:1171
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:4330
Vector * GlobalVector() const
Returns the global vector in each processor.
Definition: hypre.cpp:264
void EliminateBC(const HypreParMatrix &A, const HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B)
Eliminate essential BC specified by ess_dof_list from the solution X to the r.h.s. B.
Definition: hypre.cpp:3263
The Auxiliary-space Maxwell Solver in hypre.
Definition: hypre.hpp:1732
HypreParVector * X0
FIR Filter Temporary Vectors.
Definition: hypre.hpp:976
void SetStrengthThresh(double strength)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1674
double min_eig_est
Minimal eigenvalue estimate for polynomial smoothing.
Definition: hypre.hpp:1008
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:1403
static MemoryClass GetHostMemoryClass()
Get the current Host MemoryClass. This is the MemoryClass used by most MFEM host Memory objects...
Definition: device.hpp:268
ErrorMode
How to treat errors returned by hypre function calls.
Definition: hypre.hpp:1096
The Auxiliary-space Divergence Solver in hypre.
Definition: hypre.hpp:1809
Memory< HYPRE_Int > I
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
FGMRES Solve function.
Definition: hypre.hpp:1385
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:6020
MFEM_DEPRECATED HypreParMatrix * GetData()
Deprecated. Use HypreTriSolve::GetData() const instead.
Definition: hypre.hpp:1196
void SetRowScale(int row_scale)
Definition: hypre.cpp:4657
void SetMassMatrix(const HypreParMatrix &M)
Definition: hypre.cpp:6498
virtual ~HypreEuclid()
Definition: hypre.cpp:4696
void WrapMemoryWrite(Memory< double > &mem)
Replace the HypreParVector&#39;s data with the given Memory, mem, and prepare the vector for write access...
Definition: hypre.cpp:368
int setup_called
Was hypre&#39;s Setup function called already?
Definition: hypre.hpp:1113
Device memory; using CUDA or HIP *Malloc and *Free.
void HypreRead() const
Prepare the HypreParVector for read access in hypre&#39;s device memory space, HYPRE_MEMORY_DEVICE.
Definition: hypre.cpp:311
void EliminateBC(const HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B) const
Eliminate essential BC specified by ess_dof_list from the solution X to the r.h.s. B.
Definition: hypre.cpp:2324
Memory< double > data
const Memory< HYPRE_Int > & GetDiagMemoryJ() const
Definition: hypre.hpp:866
void HypreRead() const
Update the internal hypre_ParCSRMatrix object, A, to be in hypre memory space.
Definition: hypre.hpp:845
void SetLogging(int logging)
Definition: hypre.cpp:4590
HYPRE_BigInt GlobalSize() const
Returns the global number of rows.
Definition: hypre.hpp:239
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:3973
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition: hypre.cpp:4377
void MakeRef(const HypreParMatrix &master)
Make this HypreParMatrix a reference to &#39;master&#39;.
Definition: hypre.cpp:1334
void Read_IJMatrix(MPI_Comm comm, const char *fname)
Read a matrix saved as a HYPRE_IJMatrix.
Definition: hypre.cpp:2549
static void Finalize()
Finalize hypre (called automatically at program exit if Hypre::Init() has been called).
Definition: hypre.cpp:41
HypreParMatrix & Add(const double beta, const HypreParMatrix &B)
Definition: hypre.hpp:754
HypreParVector CreateCompatibleVector() const
Constructs a HypreParVector compatible with the calling vector.
Definition: hypre.cpp:238
HypreParVector * B
Right-hand side and solution vector.
Definition: hypre.hpp:1108
Wrapper for Hypre&#39;s native parallel ILU preconditioner.
Definition: hypre.hpp:1532
void GetNumIterations(int &num_iterations) const
Definition: hypre.hpp:1238
const HypreParMatrix * GetData() const
Definition: hypre.hpp:1424
double window_params[3]
Parameters for windowing function of FIR filter.
Definition: hypre.hpp:1010
virtual void Mult(const Vector &x, Vector &y) const
Operator application: y=A(x).
Definition: hypre.hpp:694
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:1802
void SetInitialVectors(int num_vecs, HypreParVector **vecs)
Definition: hypre.cpp:6247
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:4158
void SetWindowByName(const char *window_name)
Convenience function for setting canonical windowing parameters.
Definition: hypre.cpp:3462
bool WrapVectors(const Vector &b, Vector &x) const
Makes the internal HypreParVectors B and X wrap the input vectors b and x.
Definition: hypre.cpp:3828
HypreTriSolve(const HypreParMatrix &A)
Definition: hypre.hpp:1185
Issue warnings on hypre errors.
Definition: hypre.hpp:1099
void SetPreconditioner(HypreSolver &precond)
Definition: hypre.cpp:6477
HyprePCG(MPI_Comm comm)
Definition: hypre.cpp:3955
void SetTol(double tol)
Definition: hypre.cpp:6446
HypreILU()
Constructor; sets the default options.
Definition: hypre.cpp:4703
void SetRestriction(int restrict_type)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1640
HypreAMS(ParFiniteElementSpace *edge_fespace)
Construct the AMS solver on the given edge finite element space.
Definition: hypre.cpp:5249
void SetKDim(int dim)
Definition: hypre.cpp:4362
virtual ~HypreGMRES()
Definition: hypre.cpp:4292
void SetCycleNumSweeps(int prerelax, int postrelax)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1652
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:4372
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:5978
void SetPreconditioner(Solver &precond)
Definition: hypre.cpp:6163
MFEM_DEPRECATED void SetZeroInintialIterate()
deprecated: use SetZeroInitialIterate()
Definition: hypre.hpp:1297
Memory< HYPRE_Int > & GetDiagMemoryJ()
Definition: hypre.hpp:862
void SetMassMatrix(Operator &M)
Definition: hypre.cpp:6219
Abstract parallel finite element space.
Definition: pfespace.hpp:28
HypreParVector()
Default constructor, no underlying hypre_ParVector is created.
Definition: hypre.hpp:177
void SetPrintLevel(int logging)
Definition: hypre.cpp:6148
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
Definition: operator.hpp:659
virtual ~HypreAMS()
Definition: hypre.cpp:5647
void SetTol(double tol)
Definition: hypre.cpp:4180
virtual ~HypreILU()
Definition: hypre.cpp:4795
void SetAdvectiveOptions(int distance=15, const std::string &prerelax="", const std::string &postrelax="FFC")
Definition: hypre.cpp:5131
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
GMRES Solve function.
Definition: hypre.hpp:1322
void BlockInverseScale(const HypreParMatrix *A, HypreParMatrix *C, const Vector *b, HypreParVector *d, int blocksize, BlockInverseScaleJob job)
Definition: hypre.cpp:2762
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
Definition: hypre.hpp:2012
void HostWrite()
Update the internal hypre_ParCSRMatrix object, A, to be on host.
Definition: hypre.hpp:839
HypreParMatrix & operator+=(const HypreParMatrix &B)
Definition: hypre.hpp:747
bool pos_l1_norms
If set, take absolute values of the computed l1_norms.
Definition: hypre.hpp:1002
HypreParMatrix * ParMult(const HypreParMatrix *A, const HypreParMatrix *B, bool own_matrix)
Definition: hypre.cpp:2849
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:4205
void SetZeroInitialIterate()
non-hypre setting
Definition: hypre.hpp:1363
void SetStrongThresholdR(double strengthR)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1632
MPI_Comm GetComm() const
MPI communicator.
Definition: hypre.hpp:222
void ScaleRows(const Vector &s)
Scale the local row i by s(i).
Definition: hypre.cpp:2013
void SetParams(double threshold, int max_levels)
Definition: hypre.cpp:4570
double poly_fraction
Fraction of spectrum to smooth for polynomial relaxation.
Definition: hypre.hpp:990
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:4015
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:4776
HypreParMatrix * DiscreteGrad(ParFiniteElementSpace *edge_fespace, ParFiniteElementSpace *vert_fespace)
Compute the discrete gradient matrix between the nodal linear and ND1 spaces.
int poly_scale
Apply the polynomial smoother to A or D^{-1/2} A D^{-1/2}.
Definition: hypre.hpp:992
void MergeDiagAndOffd(SparseMatrix &merged)
Get a single SparseMatrix containing all rows from this processor, merged from the diagonal and off-d...
Definition: hypre.cpp:1559
void GetEigenvalues(Array< double > &eigenvalues) const
Collect the converged eigenvalues.
Definition: hypre.cpp:6229
void BooleanMultTranspose(int alpha, const int *x, int beta, int *y)
The &quot;Boolean&quot; analog of y = alpha * A^T * x + beta * y, where elements in the sparsity pattern of the...
Definition: hypre.hpp:724
void SetTol(double tol)
Definition: hypre.cpp:6126
HypreParVector * X1
Definition: hypre.hpp:976
void SetMaxIter(HYPRE_Int max_iter)
Definition: hypre.cpp:4756
HypreFGMRES(MPI_Comm comm)
Definition: hypre.cpp:4298
HYPRE_BigInt N() const
Returns the global number of columns.
Definition: hypre.hpp:585
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre&#39;s FGMRES.
Definition: hypre.cpp:4386
HYPRE_BigInt M() const
Returns the global number of rows.
Definition: hypre.hpp:583
The identity operator as a hypre solver.
Definition: hypre.hpp:1396
void SetWindowParameters(double a, double b, double c)
Set parameters for windowing function for FIR smoother.
Definition: hypre.cpp:3477
void EliminateZeroRows()
If a row contains only zeros, set its diagonal to 1.
Definition: hypre.hpp:790
void GetFinalResidualNorm(double &final_res_norm) const
Definition: hypre.hpp:1245
virtual ~HypreTriSolve()
Definition: hypre.hpp:1199
void SetLoadBal(double loadbal)
Definition: hypre.cpp:4580
HypreGMRES(MPI_Comm comm)
Definition: hypre.cpp:4126
void GetOffd(SparseMatrix &offd, HYPRE_BigInt *&cmap) const
Get the local off-diagonal block. NOTE: &#39;offd&#39; will not own any data.
Definition: hypre.cpp:1553
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:4546
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre&#39;s GMRES.
Definition: hypre.cpp:4220
virtual void AssembleDiagonal(Vector &diag) const
Return the diagonal of the matrix (Operator interface).
Definition: hypre.hpp:602
void SetPositiveDiagonal(bool pos=true)
After computing l1-norms, replace them with their absolute values.
Definition: hypre.hpp:1068
void SetReuse(int reuse)
Definition: hypre.cpp:4585
void Print(const char *fname) const
Prints the locally owned rows in parallel.
Definition: hypre.cpp:387
void HypreWrite()
Update the internal hypre_ParCSRMatrix object, A, to be in hypre memory space.
Definition: hypre.hpp:859
void AbsMultTranspose(double a, const Vector &x, double b, Vector &y) const
Computes y = a * |At| * x + b * y, using entry-wise absolute values of the transpose of the matrix A...
Definition: hypre.cpp:1894
HypreLOBPCG(MPI_Comm comm)
Definition: hypre.cpp:6096
HYPRE_BigInt * GetRowStarts() const
Return the parallel row partitioning array.
Definition: hypre.hpp:645
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
Definition: densemat.cpp:2282
MFEM_DEPRECATED HYPRE_BigInt * Partitioning()
Returns a non-const pointer to the parallel row/column partitioning. Deprecated in favor of HypreParV...
Definition: hypre.hpp:236
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Relax the linear system Ax=b.
Definition: hypre.cpp:3636
hypre_ParVector * StealParVector()
Changes the ownership of the vector.
Definition: hypre.hpp:248
The BoomerAMG solver in hypre.
Definition: hypre.hpp:1579
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:4464
void SetRelaxType(int relax_type)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1686
void SetSymmetry(int sym)
Definition: hypre.cpp:4595
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
Definition: hypre.hpp:652
virtual void MultTranspose(const Vector &x, Vector &y) const
Computes y = A^t * x.
Definition: hypre.hpp:701
void HypreStealOwnership(HypreParMatrix &A_hyp, SparseMatrix &A_diag)
Make A_hyp steal ownership of its diagonal part A_diag.
Definition: hypre.cpp:2740
virtual ~HypreParaSails()
Definition: hypre.cpp:4600
The ParaSails preconditioner in hypre.
Definition: hypre.hpp:1434
void SetMaxIter(int max_iter)
Definition: hypre.cpp:6142
double * l1_norms
l1 norms of the rows of A
Definition: hypre.hpp:1000
Data type sparse matrix.
Definition: sparsemat.hpp:50
BlockInverseScaleJob
Definition: hypre.hpp:906
void SetOwnerFlags(signed char diag, signed char offd, signed char colmap)
Explicitly set the three ownership flags, see docs for diagOwner etc.
Definition: hypre.cpp:1371
void PrintHash(std::ostream &out) const
Print sizes and hashes for all data arrays of the HypreParMatrix from the local MPI rank...
Definition: hypre.cpp:2607
void SetLogging(int logging)
Definition: hypre.cpp:4010
Jacobi preconditioner in hypre.
Definition: hypre.hpp:1410
virtual ~HypreSolver()
Definition: hypre.cpp:3946
virtual HYPRE_PtrToParSolverFcn SolveFcn() const =0
hypre&#39;s internal Solve function
void SetRelTol(double rel_tol)
Definition: hypre.cpp:6452
void SetKDim(int dim)
Definition: hypre.cpp:4195
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
Definition: error.cpp:154
void SetResidualConvergenceOptions(int res_frequency=-1, double rtol=0.0)
Definition: hypre.cpp:4030
double b
Definition: lissajous.cpp:42
int to_int(const std::string &str)
Convert a string to an int.
Definition: text.hpp:62
Abort on hypre errors (default in base class)
Definition: hypre.hpp:1100
void SetLogging(int logging)
Definition: hypre.cpp:4367
void SetPrintLevel(int print_level)
Definition: hypre.hpp:1659
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
FGMRES Setup function.
Definition: hypre.hpp:1382
void SetOperatorSymmetry(bool is_sym)
Definition: hypre.hpp:1074
void ResetTranspose() const
Reset (destroy) the internal transpose matrix that is created by EnsureMultTranspose() and MultTransp...
Definition: hypre.cpp:1713
void GetBlocks(Array2D< HypreParMatrix * > &blocks, bool interleaved_rows=false, bool interleaved_cols=false) const
Definition: hypre.cpp:1583
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve the linear system Ax=b.
Definition: hypre.cpp:3906
HypreParaSails(MPI_Comm comm)
Definition: hypre.cpp:4482
void HypreWrite()
Prepare the HypreParVector for write access in hypre&#39;s device memory space, HYPRE_MEMORY_DEVICE.
Definition: hypre.cpp:330
void SetTol(double tol)
Definition: hypre.cpp:4352
void WrapHypreParVector(hypre_ParVector *y, bool owner=true)
Converts hypre&#39;s format to HypreParVector.
Definition: hypre.cpp:255
void SetTol(double tol)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1670
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
PCG Solve function.
Definition: hypre.hpp:1258
void Read(MPI_Comm comm, const char *fname)
Reads a HypreParVector from files saved with HypreParVector::Print.
Definition: hypre.cpp:392
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:5627
virtual MemoryClass GetMemoryClass() const
Return the MemoryClass preferred by the Operator.
Definition: hypre.hpp:1151
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
Definition: hypre.cpp:6552
const HypreParMatrix * A
The linear system matrix.
Definition: hypre.hpp:1105
HypreParMatrix * DiscreteCurl(ParFiniteElementSpace *face_fespace, ParFiniteElementSpace *edge_fespace)
Compute the discrete curl matrix between the ND1 and RT0 spaces.
HypreParMatrix * Transpose() const
Returns the transpose of *this.
Definition: hypre.cpp:1607
HYPRE_Int Randomize(HYPRE_Int seed)
Set random values.
Definition: hypre.cpp:382
void SetFilterThresholdR(double filterR)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1636
Ignore hypre errors (see e.g. HypreADS)
Definition: hypre.hpp:1098
double relax_weight
Damping coefficient (usually &lt;= 1)
Definition: hypre.hpp:984
Parallel smoothers in hypre.
Definition: hypre.hpp:962
Memory< HYPRE_Int > J
void SetElasticityOptions(ParFiniteElementSpace *fespace)
Definition: hypre.cpp:5083
Memory< double > auxB
Definition: hypre.hpp:1110
void GetDiag(Vector &diag) const
Get the local diagonal of the matrix.
Definition: hypre.cpp:1480
void GetFinalResidualNorm(double &final_res_norm) const
Definition: hypre.hpp:1309
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:1714
void SetBJ(int bj)
Definition: hypre.cpp:4652
void RAP(const DenseMatrix &A, const DenseMatrix &P, DenseMatrix &RAP)
Definition: densemat.cpp:3213
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
ILU Solve function.
Definition: hypre.hpp:1573
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:1401
void SetZeroInitialIterate()
non-hypre setting
Definition: hypre.hpp:1300
void SetLevelOfFill(HYPRE_Int lev_fill)
Set the fill level for ILU(k); the default is k=1.
Definition: hypre.cpp:4746
HypreParMatrix * A
The linear system matrix.
Definition: hypre.hpp:966
void SetCoarsening(int coarsen_type)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1682
void SetGMRESSwitchR(int gmres_switch)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1648
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:1421
Dynamic 2D array using row-major layout.
Definition: array.hpp:351
virtual void SetOperator(const Operator &op)
Definition: hypre.cpp:3484
virtual HYPRE_PtrToParSolverFcn SetupFcn() const =0
hypre&#39;s internal Setup function
void SetLogging(int logging)
Definition: hypre.cpp:4200
virtual ~HypreADS()
Definition: hypre.cpp:5998
HYPRE_BigInt GetGlobalNumCols() const
Return the global number of columns.
Definition: hypre.hpp:639
HypreParMatrix()
An empty matrix to be used as a reference to an existing matrix.
Definition: hypre.cpp:601
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:1419
bool A_is_symmetric
A flag that indicates whether the linear system matrix A is symmetric.
Definition: hypre.hpp:1016
void SetMaxIter(int max_iter)
Definition: hypre.cpp:4005
void SetMaxIter(int max_iter)
Definition: hypre.hpp:1662
void SetMaxIter(int max_iter)
Definition: hypre.cpp:4357
void SetPolyOptions(int poly_order, double poly_fraction, int eig_est_cg_iter=10)
Set parameters for polynomial smoothing.
Definition: hypre.cpp:3446
HypreDiagScale(const HypreParMatrix &A)
Definition: hypre.hpp:1414
void SetSOROptions(double relax_weight, double omega)
Set SOR-related parameters.
Definition: hypre.cpp:3440
void BooleanMult(int alpha, const int *x, int beta, int *y)
The &quot;Boolean&quot; analog of y = alpha * A * x + beta * y, where elements in the sparsity pattern of the m...
Definition: hypre.hpp:714
void SetInterpolation(int interp_type)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1678
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:161
HypreParMatrix * EliminateCols(const Array< int > &cols)
Definition: hypre.cpp:2297
HypreParVector * X
Definition: hypre.hpp:1108
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:1867
Type
Enumeration defining IDs for some classes derived from Operator.
Definition: operator.hpp:256
static MemoryType GetHostMemoryType()
Get the current Host MemoryType. This is the MemoryType used by most MFEM classes when allocating mem...
Definition: device.hpp:264
const Memory< HYPRE_Int > & GetDiagMemoryI() const
Definition: hypre.hpp:865
PCG solver in hypre.
Definition: hypre.hpp:1204
GMRES solver in hypre.
Definition: hypre.hpp:1269
signed char OwnsOffd() const
Get offd ownership flag.
Definition: hypre.hpp:551
void HostRead() const
Update the internal hypre_ParCSRMatrix object, A, to be on host.
Definition: hypre.hpp:828
MemoryType
Memory types supported by MFEM.
Definition: mem_manager.hpp:31
signed char OwnsColMap() const
Get colmap ownership flag.
Definition: hypre.hpp:553
void SetPrintLevel(int print_lvl)
Definition: hypre.cpp:5662
Memory< double > auxX
Definition: hypre.hpp:1110
HypreParVector * X
Definition: hypre.hpp:968
void Solve()
Solve the eigenproblem.
Definition: hypre.cpp:6505
HYPRE_Int HYPRE_BigInt
void SetData(double *data_)
Sets the data of the Vector and the hypre_ParVector to data_.
Definition: hypre.cpp:305
void SetNumModes(int num_eigs)
Definition: hypre.cpp:6438
void SetStats(int stats)
Definition: hypre.cpp:4642
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:1466
HypreParMatrix(hypre_ParCSRMatrix *a, bool owner=true)
Converts hypre&#39;s format to HypreParMatrix.
Definition: hypre.hpp:426
virtual ~HypreDiagScale()
Definition: hypre.hpp:1430
const HypreParVector & GetEigenvector(unsigned int i) const
Extract a single eigenvector.
Definition: hypre.cpp:6541
int GetNumRows() const
Returns the number of rows in the diagonal block of the ParCSRMatrix.
Definition: hypre.hpp:621
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:1190
const HYPRE_BigInt * ColPart() const
Returns the column partitioning (const version)
Definition: hypre.hpp:581
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.hpp:1148
HypreParMatrix * ParAdd(const HypreParMatrix *A, const HypreParMatrix *B)
Returns the matrix A + B.
Definition: hypre.cpp:2809
double max_eig_est
Maximal eigenvalue estimate for polynomial smoothing.
Definition: hypre.hpp:1006
A class to initialize the size of a Tensor.
Definition: dtensor.hpp:54
void SetRelTol(double rel_tol)
Definition: hypre.cpp:6132
HypreAME(MPI_Comm comm)
Definition: hypre.cpp:6396
HYPRE_Int MultTranspose(HypreParVector &x, HypreParVector &y, double alpha=1.0, double beta=0.0) const
Computes y = alpha * A^t * x + beta * y.
Definition: hypre.cpp:1868
void GetNumIterations(int &num_iterations) const
Definition: hypre.hpp:1693
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:1464
virtual ~HypreIdentity()
Definition: hypre.hpp:1406
void SetMaxLevels(int max_levels)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1666
void SetMaxIter(int max_iter)
Definition: hypre.cpp:6462
void SetFIRCoefficients(double max_eig)
Compute window and Chebyshev coefficients for given polynomial order.
Definition: hypre.cpp:3596
void SetRandomSeed(int s)
Definition: hypre.hpp:1993
double a
Definition: lissajous.cpp:41
void EliminateRows(const Array< int > &rows)
Eliminate rows from the diagonal and off-diagonal blocks of the matrix.
Definition: hypre.cpp:2311
signed char OwnsDiag() const
Get diag ownership flag.
Definition: hypre.hpp:549
double * fir_coeffs
Combined coefficients for windowing and Chebyshev polynomials.
Definition: hypre.hpp:1013
void SetIsTriangular()
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1644
void SetLevel(int level)
Definition: hypre.cpp:4637
void Threshold(double threshold=0.0)
Remove values smaller in absolute value than some threshold.
Definition: hypre.cpp:2141
double InnerProduct(HypreParVector *x, HypreParVector *y)
Definition: hypre.cpp:413
void GetNumIterations(int &num_iterations) const
Definition: hypre.hpp:1365
void Print(const char *fname, HYPRE_Int offi=0, HYPRE_Int offj=0) const
Prints the locally owned rows in parallel.
Definition: hypre.cpp:2526
virtual ~HypreSmoother()
Definition: hypre.cpp:3787
void SetPrintLevel(HYPRE_Int print_level)
Set the print level: 0 = none, 1 = setup, 2 = solve, 3 = setup+solve.
Definition: hypre.cpp:4771
Host memory; using new[] and delete[].
void SetSubSpaceProjector(Operator &proj)
Definition: hypre.hpp:2000
constexpr MemoryClass GetHypreMemoryClass()
The MemoryClass used by Hypre objects.
Definition: hypre.hpp:137
HYPRE_BigInt GetGlobalNumRows() const
Return the global number of rows.
Definition: hypre.hpp:635
void EnsureMultTranspose() const
Ensure the action of the transpose is performed fast.
Definition: hypre.cpp:1703
HYPRE_BigInt * ColPart()
Returns the column partitioning.
Definition: hypre.hpp:573
void HypreReadWrite()
Prepare the HypreParVector for read and write access in hypre&#39;s device memory space, HYPRE_MEMORY_DEVICE.
Definition: hypre.cpp:321
void GetFinalResidualNorm(double &final_res_norm) const
Definition: hypre.hpp:1372
Memory< HYPRE_Int > & GetDiagMemoryI()
Definition: hypre.hpp:861
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:4943
void InvScaleRows(const Vector &s)
Scale the local row i by 1./s(i)
Definition: hypre.cpp:2052
MFEM_DEPRECATED void SetZeroInintialIterate()
deprecated: use SetZeroInitialIterate()
Definition: hypre.hpp:1233
virtual void Setup(const HypreParVector &b, HypreParVector &x) const
Set up the solver (if not set up already, also called automatically by HypreSolver::Mult).
Definition: hypre.cpp:3879
void SetTaubinOptions(double lambda, double mu, int iter)
Set parameters for Taubin&#39;s lambda-mu method.
Definition: hypre.cpp:3454
HypreParVector * B
Right-hand side and solution vectors.
Definition: hypre.hpp:968
HYPRE_BigInt * RowPart()
Returns the row partitioning.
Definition: hypre.hpp:569
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
Definition: hypre.cpp:4672
virtual void MultTranspose(const Vector &b, Vector &x) const
Apply transpose of the smoother to relax the linear system Ax=b.
Definition: hypre.cpp:3777
A simple singleton class for hypre&#39;s global settings, that 1) calls HYPRE_Init() and sets some GPU-re...
Definition: hypre.hpp:72
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
Definition: operator.hpp:47
int dim
Definition: ex24.cpp:53
virtual ~HyprePCG()
Definition: hypre.cpp:4120
int GetNumCols() const
Returns the number of columns in the diagonal block of the ParCSRMatrix.
Definition: hypre.hpp:628
void SetZeroInitialIterate()
non-hypre setting
Definition: hypre.hpp:1236
void SetOperator(Operator &A)
Definition: hypre.cpp:6172
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition: hypre.cpp:4020
void SetLocalReordering(HYPRE_Int reorder_type)
Definition: hypre.cpp:4766
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:1188
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:1511
int relax_times
Number of relaxation sweeps.
Definition: hypre.hpp:982
void GetEigenvalues(Array< double > &eigenvalues) const
Collect the converged eigenvalues.
Definition: hypre.cpp:6517
void SetCycleType(int cycle_type)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1690
void operator*=(double s)
Scale all entries by s: A_scaled = s*A.
Definition: hypre.cpp:2098
void SetPrintLevel(int logging)
Definition: hypre.cpp:6468
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:424
int eig_est_cg_iter
Number of CG iterations to determine eigenvalue estimates.
Definition: hypre.hpp:1004
void SetOwnership(int own)
Sets ownership of the internal hypre_ParVector.
Definition: hypre.hpp:251
Abstract class for hypre&#39;s solvers and preconditioners.
Definition: hypre.hpp:1092
Flexible GMRES solver in hypre.
Definition: hypre.hpp:1333
ErrorMode error_mode
How to treat hypre errors.
Definition: hypre.hpp:1116
HYPRE_BigInt NNZ() const
Returns the global number of nonzeros.
Definition: hypre.hpp:565
const HypreParVector & GetEigenvector(unsigned int i) const
Extract a single eigenvector.
Definition: hypre.cpp:6241
HYPRE_BigInt * GetColStarts() const
Return the parallel column partitioning array.
Definition: hypre.hpp:650
void SetMemory(int mem)
Definition: hypre.cpp:4647
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
ILU Setup function.
Definition: hypre.hpp:1569
const HYPRE_BigInt * Partitioning() const
Returns the parallel row/column partitioning.
Definition: hypre.hpp:230
HypreParVector & operator=(double d)
Set constant values.
Definition: hypre.cpp:274
const double alpha
Definition: ex15.cpp:369
Vector data type.
Definition: vector.hpp:60
void SetAbsTol(double tol)
Definition: hypre.cpp:4185
void PrintCommPkg(std::ostream &out=mfem::out) const
Print information about the hypre_ParCSRCommPkg of the HypreParMatrix.
Definition: hypre.cpp:2570
HypreParMatrix & operator=(double value)
Initialize all entries with value.
Definition: hypre.hpp:733
void GetNumIterations(int &num_iterations) const
Definition: hypre.hpp:1302
HypreParMatrix * ExtractSubmatrix(const Array< int > &indices, double threshold=0.0) const
Definition: hypre.cpp:1626
hypre_ParCSRMatrix * StealData()
Changes the ownership of the matrix.
Definition: hypre.cpp:1352
void SetPrecondUsageMode(int pcg_mode)
Definition: hypre.cpp:6157
void SetOperator(const HypreParMatrix &A)
Definition: hypre.cpp:6483
void SetSystemsOptions(int dim, bool order_bynodes=false)
Definition: hypre.cpp:4962
virtual ~HypreParMatrix()
Calls hypre&#39;s destroy function.
Definition: hypre.hpp:887
ID for class HypreParMatrix.
Definition: operator.hpp:260
HYPRE_Int Mult(HypreParVector &x, HypreParVector &y, double alpha=1.0, double beta=0.0) const
Computes y = alpha * A * x + beta * y.
Definition: hypre.cpp:1732
void SetFilter(double filter)
Definition: hypre.cpp:4575
void DropSmallEntries(double tol)
Wrapper for hypre_ParCSRMatrixDropSmallEntries in different versions of hypre. Drop off-diagonal entr...
Definition: hypre.cpp:2226
void SetAggressiveCoarsening(int num_levels)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1708
void SetMaxIter(int max_iter)
Definition: hypre.cpp:4190
RefCoord s[3]
const HYPRE_BigInt * RowPart() const
Returns the row partitioning (const version)
Definition: hypre.hpp:577
double omega
SOR parameter (usually in (0,2))
Definition: hypre.hpp:986
HypreParMatrix * LeftDiagMult(const SparseMatrix &D, HYPRE_BigInt *row_starts=NULL) const
Multiply the HypreParMatrix on the left by a block-diagonal parallel matrix D and return the result a...
Definition: hypre.cpp:1911
Base class for solvers.
Definition: operator.hpp:655
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:1800
void SetNodal(int blocksize)
Expert option - consult hypre documentation/team.
Definition: hypre.hpp:1701
int GetOwnership() const
Gets ownership of the internal hypre_ParVector.
Definition: hypre.hpp:254
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
PCG Setup function.
Definition: hypre.hpp:1255
void WrapHypreParCSRMatrix(hypre_ParCSRMatrix *a, bool owner=true)
Converts hypre&#39;s format to HypreParMatrix.
Definition: hypre.cpp:607
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition: globals.hpp:66
Abstract operator.
Definition: operator.hpp:24
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:343
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
hypre&#39;s internal Setup function
Definition: hypre.hpp:1509
void HostReadWrite()
Update the internal hypre_ParCSRMatrix object, A, to be on host.
Definition: hypre.hpp:834
void AbsMult(double a, const Vector &x, double b, Vector &y) const
Computes y = a * |A| * x + b * y, using entry-wise absolute values of the matrix A.
Definition: hypre.cpp:1877
Memory< double > auxB
Auxiliary buffers for the case when the input or output arrays in methods like Mult(const Vector &amp;...
Definition: hypre.hpp:972
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:1716
~HypreParVector()
Calls hypre&#39;s destroy function.
Definition: hypre.cpp:404
void SetNumModes(int num_eigs)
Definition: hypre.hpp:1991
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre&#39;s PCG.
Definition: hypre.cpp:4043
HypreParMatrix * HypreParMatrixFromBlocks(Array2D< HypreParMatrix * > &blocks, Array2D< double > *blockCoeff)
Returns a merged hypre matrix constructed from hypre matrix blocks.
Definition: hypre.cpp:3019
Memory< double > & GetDiagMemoryData()
Definition: hypre.hpp:863
HypreParVector * Z
Definition: hypre.hpp:974
void SetSingularProblem()
Set this option when solving a curl-curl problem with zero mass term.
Definition: hypre.hpp:1791
void Solve()
Solve the eigenproblem.
Definition: hypre.cpp:6286
virtual ~HypreFGMRES()
Definition: hypre.cpp:4458
HypreParVector * V
Temporary vectors.
Definition: hypre.hpp:974
void SetType(HypreSmoother::Type type, int relax_times=1)
Set the relaxation type and number of sweeps.
Definition: hypre.cpp:3434
virtual const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition: vector.hpp:449
const Memory< double > & GetDiagMemoryData() const
Definition: hypre.hpp:867
MemoryClass
Memory classes identify sets of memory types.
Definition: mem_manager.hpp:73
void WrapMemoryReadWrite(Memory< double > &mem)
Replace the HypreParVector&#39;s data with the given Memory, mem, and prepare the vector for read and wri...
Definition: hypre.cpp:354
virtual HYPRE_PtrToParSolverFcn SetupFcn() const
GMRES Setup function.
Definition: hypre.hpp:1319
int poly_order
Order of the smoothing polynomial.
Definition: hypre.hpp:988
void SetTol(HYPRE_Real tol)
Definition: hypre.cpp:4761
double lambda
Taubin&#39;s lambda-mu method parameters.
Definition: hypre.hpp:995
void WrapMemoryRead(const Memory< double > &mem)
Replace the HypreParVector&#39;s data with the given Memory, mem, and prepare the vector for read access ...
Definition: hypre.cpp:339
MFEM_DEPRECATED void SetZeroInintialIterate()
deprecated: use SetZeroInitialIterate()
Definition: hypre.hpp:1360
MFEM_DEPRECATED HypreParMatrix * GetData()
Deprecated. Use HypreDiagScale::GetData() const instead.
Definition: hypre.hpp:1427
virtual HYPRE_PtrToParSolverFcn SolveFcn() const
hypre&#39;s internal Solve function
Definition: hypre.hpp:1869
void HypreReadWrite()
Update the internal hypre_ParCSRMatrix object, A, to be in hypre memory space.
Definition: hypre.hpp:852