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