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