MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
hypre.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_HYPRE
13#define MFEM_HYPRE
14
15#include "../config/config.hpp"
16
17#ifdef MFEM_USE_MPI
18
20#include "sparsemat.hpp"
21#include "hypre_parcsr.hpp"
22#include <mpi.h>
23
24// Enable internal hypre timing routines
25#define HYPRE_TIMING
26
27// hypre header files
28#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 built with CUDA support, A->diag owns the "host"
436 // pointers (according to A->diag->owns_data)
437 // -2: used when hypre is built with CUDA support, A->diag owns the "hypre"
438 // pointers (according to A->diag->owns_data)
439 // 0: prevent hypre from destroying A->diag->{i,j,data}
440 // 1: same as 0, plus own the "host" A->diag->{i,j}
441 // 2: same as 0, plus own the "host" A->diag->data
442 // 3: same as 0, plus own the "host" A->diag->{i,j,data}
443 // The same values and rules apply to offdOwner and A->offd.
444 // The possible values for colMapOwner are:
445 // -1: no special treatment of A->col_map_offd (default)
446 // 0: prevent hypre from destroying A->col_map_offd
447 // 1: same as 0, plus take ownership of A->col_map_offd
448 // All owned arrays are destroyed with 'delete []'.
449 signed char diagOwner, offdOwner, colMapOwner;
450
451 // Does the object own the pointer A?
452 signed char ParCSROwner;
453
454 MemoryIJData mem_diag, mem_offd;
455
456 // Initialize with defaults. Does not initialize inherited members.
457 void Init();
458
459 // Delete all owned data. Does not perform re-initialization with defaults.
460 void Destroy();
461
462 void Read(MemoryClass mc) const;
463 void ReadWrite(MemoryClass mc);
464 // The Boolean flags are used in Destroy().
465 void Write(MemoryClass mc, bool set_diag = true, bool set_offd = true);
466
467 // Copy (shallow/deep, based on HYPRE_BIGINT) the I and J arrays from csr to
468 // hypre_csr. Shallow copy the data. Return the appropriate ownership flag.
469 // The CSR arrays are wrapped in the mem_csr struct which is used to move
470 // these arrays to device, if necessary.
471 static signed char CopyCSR(SparseMatrix *csr,
472 MemoryIJData &mem_csr,
473 hypre_CSRMatrix *hypre_csr,
474 bool mem_owner);
475 // Copy (shallow or deep, based on HYPRE_BIGINT) the I and J arrays from
476 // bool_csr to hypre_csr. Allocate the data array and set it to all ones.
477 // Return the appropriate ownership flag. The CSR arrays are wrapped in the
478 // mem_csr struct which is used to move these arrays to device, if necessary.
479 static signed char CopyBoolCSR(Table *bool_csr,
480 MemoryIJData &mem_csr,
481 hypre_CSRMatrix *hypre_csr);
482
483 // Wrap the data from h_mat into mem with the given ownership flag.
484 // If the new Memory arrays in mem are not suitable to be accessed via
485 // GetHypreMemoryClass(), then mem will be re-allocated using the memory type
486 // returned by GetHypreMemoryType(), the data will be deep copied, and h_mat
487 // will be updated with the new pointers.
488 static signed char HypreCsrToMem(hypre_CSRMatrix *h_mat, MemoryType h_mat_mt,
489 bool own_ija, MemoryIJData &mem);
490
491public:
492 /// An empty matrix to be used as a reference to an existing matrix
494
495 /// Converts hypre's format to HypreParMatrix
496 /** If @a owner is false, ownership of @a a is not transferred */
497 void WrapHypreParCSRMatrix(hypre_ParCSRMatrix *a, bool owner = true);
498
499 /// Converts hypre's format to HypreParMatrix
500 /** If @a owner is false, ownership of @a a is not transferred */
501 explicit HypreParMatrix(hypre_ParCSRMatrix *a, bool owner = true)
502 {
503 Init();
504 WrapHypreParCSRMatrix(a, owner);
505 }
506
507 /// Creates block-diagonal square parallel matrix.
508 /** Diagonal is given by @a diag which must be in CSR format (finalized). The
509 new HypreParMatrix does not take ownership of any of the input arrays.
510 See @ref hypre_partitioning_descr "here" for a description of the row
511 partitioning array @a row_starts.
512
513 @warning The ordering of the columns in each row in @a *diag may be
514 changed by this constructor to ensure that the first entry in each row is
515 the diagonal one. This is expected by most hypre functions. */
516 HypreParMatrix(MPI_Comm comm, HYPRE_BigInt glob_size,
517 HYPRE_BigInt *row_starts,
518 SparseMatrix *diag); // constructor with 4 arguments, v1
519
520 /// Creates block-diagonal rectangular parallel matrix.
521 /** Diagonal is given by @a diag which must be in CSR format (finalized). The
522 new HypreParMatrix does not take ownership of any of the input arrays.
523 See @ref hypre_partitioning_descr "here" for a description of the
524 partitioning arrays @a row_starts and @a col_starts. */
525 HypreParMatrix(MPI_Comm comm, HYPRE_BigInt global_num_rows,
526 HYPRE_BigInt global_num_cols, HYPRE_BigInt *row_starts,
527 HYPRE_BigInt *col_starts,
528 SparseMatrix *diag); // constructor with 6 arguments, v1
529
530 /// Creates general (rectangular) parallel matrix.
531 /** The new HypreParMatrix does not take ownership of any of the input
532 arrays, if @a own_diag_offd is false (default). If @a own_diag_offd is
533 true, ownership of @a diag and @a offd is transferred to the
534 HypreParMatrix.
535
536 See @ref hypre_partitioning_descr "here" for a description of the
537 partitioning arrays @a row_starts and @a col_starts. */
538 HypreParMatrix(MPI_Comm comm, HYPRE_BigInt global_num_rows,
539 HYPRE_BigInt global_num_cols, HYPRE_BigInt *row_starts,
540 HYPRE_BigInt *col_starts, SparseMatrix *diag,
541 SparseMatrix *offd, HYPRE_BigInt *cmap,
542 bool own_diag_offd = false); // constructor with 8+1 arguments
543
544 /// Creates general (rectangular) parallel matrix.
545 /** The new HypreParMatrix takes ownership of all input arrays, except
546 @a col_starts and @a row_starts. See @ref hypre_partitioning_descr "here"
547 for a description of the partitioning arrays @a row_starts and @a
548 col_starts.
549
550 If @a hypre_arrays is false, all arrays (except @a row_starts and
551 @a col_starts) are assumed to be allocated according to the MemoryType
552 returned by Device::GetHostMemoryType(). If @a hypre_arrays is true, then
553 the same arrays are assumed to be allocated by hypre as host arrays. */
554 HypreParMatrix(MPI_Comm comm,
555 HYPRE_BigInt global_num_rows, HYPRE_BigInt global_num_cols,
556 HYPRE_BigInt *row_starts, HYPRE_BigInt *col_starts,
557 HYPRE_Int *diag_i, HYPRE_Int *diag_j, real_t *diag_data,
558 HYPRE_Int *offd_i, HYPRE_Int *offd_j, real_t *offd_data,
559 HYPRE_Int offd_num_cols,
560 HYPRE_BigInt *offd_col_map,
561 bool hypre_arrays = false); // constructor with 13+1 arguments
562
563 /// Creates a parallel matrix from SparseMatrix on processor 0.
564 /** See @ref hypre_partitioning_descr "here" for a description of the
565 partitioning arrays @a row_starts and @a col_starts. */
566 HypreParMatrix(MPI_Comm comm, HYPRE_BigInt *row_starts,
567 HYPRE_BigInt *col_starts,
568 const SparseMatrix *a); // constructor with 4 arguments, v2
569
570 /// Creates boolean block-diagonal rectangular parallel matrix.
571 /** The new HypreParMatrix does not take ownership of any of the input
572 arrays. See @ref hypre_partitioning_descr "here" for a description of the
573 partitioning arrays @a row_starts and @a col_starts. */
574 HypreParMatrix(MPI_Comm comm, HYPRE_BigInt global_num_rows,
575 HYPRE_BigInt global_num_cols, HYPRE_BigInt *row_starts,
576 HYPRE_BigInt *col_starts,
577 Table *diag); // constructor with 6 arguments, v2
578
579 /// Creates boolean rectangular parallel matrix.
580 /** The new HypreParMatrix takes ownership of the arrays @a i_diag,
581 @a j_diag, @a i_offd, @a j_offd, and @a cmap; does not take ownership of
582 the arrays @a row and @a col. See @ref hypre_partitioning_descr "here"
583 for a description of the partitioning arrays @a row and @a col. */
584 HypreParMatrix(MPI_Comm comm, int id, int np, HYPRE_BigInt *row,
585 HYPRE_BigInt *col,
586 HYPRE_Int *i_diag, HYPRE_Int *j_diag, HYPRE_Int *i_offd,
587 HYPRE_Int *j_offd, HYPRE_BigInt *cmap,
588 HYPRE_Int cmap_size); // constructor with 11 arguments
589
590 /** @brief Creates a general parallel matrix from a local CSR matrix on each
591 processor described by the @a I, @a J and @a data arrays. */
592 /** The local matrix should be of size (local) @a nrows by (global)
593 @a glob_ncols. The new parallel matrix contains copies of all input
594 arrays (so they can be deleted). See @ref hypre_partitioning_descr "here"
595 for a description of the partitioning arrays @a rows and @a cols. */
596 HypreParMatrix(MPI_Comm comm, int nrows, HYPRE_BigInt glob_nrows,
597 HYPRE_BigInt glob_ncols, const int *I, const HYPRE_BigInt *J,
598 const real_t *data, const HYPRE_BigInt *rows,
599 const HYPRE_BigInt *cols); // constructor with 9 arguments
600
601 /** @brief Copy constructor for a ParCSR matrix which creates a deep copy of
602 structure and data from @a P. */
604
605 /// Make this HypreParMatrix a reference to 'master'
606 void MakeRef(const HypreParMatrix &master);
607
608 /// MPI communicator
609 MPI_Comm GetComm() const { return A->comm; }
610
611 /// Typecasting to hypre's hypre_ParCSRMatrix*
612 operator hypre_ParCSRMatrix*() const { return A; }
613#ifndef HYPRE_PAR_CSR_MATRIX_STRUCT
614 /// Typecasting to hypre's HYPRE_ParCSRMatrix, a.k.a. void *
615 operator HYPRE_ParCSRMatrix() { return (HYPRE_ParCSRMatrix) A; }
616#endif
617 /// Changes the ownership of the matrix
618 hypre_ParCSRMatrix* StealData();
619
620 /// Explicitly set the three ownership flags, see docs for diagOwner etc.
621 void SetOwnerFlags(signed char diag, signed char offd, signed char colmap);
622
623 /// Get diag ownership flag
624 signed char OwnsDiag() const { return diagOwner; }
625 /// Get offd ownership flag
626 signed char OwnsOffd() const { return offdOwner; }
627 /// Get colmap ownership flag
628 signed char OwnsColMap() const { return colMapOwner; }
629
630 /** If the HypreParMatrix does not own the row-starts array, make a copy of
631 it that the HypreParMatrix will own. If the col-starts array is the same
632 as the row-starts array, col-starts is also replaced. */
633 void CopyRowStarts();
634 /** If the HypreParMatrix does not own the col-starts array, make a copy of
635 it that the HypreParMatrix will own. If the row-starts array is the same
636 as the col-starts array, row-starts is also replaced. */
637 void CopyColStarts();
638
639 /// Returns the global number of nonzeros
640 inline HYPRE_BigInt NNZ() const { return A->num_nonzeros; }
641 /// Returns the row partitioning
642 /** See @ref hypre_partitioning_descr "here" for a description of the
643 partitioning array. */
644 inline HYPRE_BigInt *RowPart() { return A->row_starts; }
645 /// Returns the column partitioning
646 /** See @ref hypre_partitioning_descr "here" for a description of the
647 partitioning array. */
648 inline HYPRE_BigInt *ColPart() { return A->col_starts; }
649 /// Returns the row partitioning (const version)
650 /** See @ref hypre_partitioning_descr "here" for a description of the
651 partitioning array. */
652 inline const HYPRE_BigInt *RowPart() const { return A->row_starts; }
653 /// Returns the column partitioning (const version)
654 /** See @ref hypre_partitioning_descr "here" for a description of the
655 partitioning array. */
656 inline const HYPRE_BigInt *ColPart() const { return A->col_starts; }
657 /// Returns the global number of rows
658 inline HYPRE_BigInt M() const { return A->global_num_rows; }
659 /// Returns the global number of columns
660 inline HYPRE_BigInt N() const { return A->global_num_cols; }
661
662 /// Get the local diagonal of the matrix.
663 void GetDiag(Vector &diag) const;
664 /// Get the local diagonal block. NOTE: 'diag' will not own any data.
665 void GetDiag(SparseMatrix &diag) const;
666 /// Get the local off-diagonal block. NOTE: 'offd' will not own any data.
667 void GetOffd(SparseMatrix &offd, HYPRE_BigInt* &cmap) const;
668 /** @brief Get a single SparseMatrix containing all rows from this processor,
669 merged from the diagonal and off-diagonal blocks stored by the
670 HypreParMatrix. */
671 /** @note The number of columns in the SparseMatrix will be the global number
672 of columns in the parallel matrix, so using this method may result in an
673 integer overflow in the column indices. */
674 void MergeDiagAndOffd(SparseMatrix &merged);
675
676 /// Return the diagonal of the matrix (Operator interface).
677 void AssembleDiagonal(Vector &diag) const override { GetDiag(diag); }
678
679 /** Split the matrix into M x N equally sized blocks of parallel matrices.
680 The size of 'blocks' must already be set to M x N. */
682 bool interleaved_rows = false,
683 bool interleaved_cols = false) const;
684
685 /// Returns the transpose of *this
686 HypreParMatrix * Transpose() const;
687
688 /** Returns principle submatrix given by array of indices of connections
689 with relative size > @a threshold in *this. */
690#if MFEM_HYPRE_VERSION >= 21800
692 real_t threshold=0.0) const;
693#endif
694
695 /// Returns the number of rows in the diagonal block of the ParCSRMatrix
696 int GetNumRows() const
697 {
698 return internal::to_int(
699 hypre_CSRMatrixNumRows(hypre_ParCSRMatrixDiag(A)));
700 }
701
702 /// Returns the number of columns in the diagonal block of the ParCSRMatrix
703 int GetNumCols() const
704 {
705 return internal::to_int(
706 hypre_CSRMatrixNumCols(hypre_ParCSRMatrixDiag(A)));
707 }
708
709 /// Return the global number of rows
711 { return hypre_ParCSRMatrixGlobalNumRows(A); }
712
713 /// Return the global number of columns
715 { return hypre_ParCSRMatrixGlobalNumCols(A); }
716
717 /// Return the parallel row partitioning array.
718 /** See @ref hypre_partitioning_descr "here" for a description of the
719 partitioning array. */
720 HYPRE_BigInt *GetRowStarts() const { return hypre_ParCSRMatrixRowStarts(A); }
721
722 /// Return the parallel column partitioning array.
723 /** See @ref hypre_partitioning_descr "here" for a description of the
724 partitioning array. */
725 HYPRE_BigInt *GetColStarts() const { return hypre_ParCSRMatrixColStarts(A); }
726
727 MemoryClass GetMemoryClass() const override { return GetHypreMemoryClass(); }
728
729 /// Ensure the action of the transpose is performed fast.
730 /** When HYPRE is built for GPUs, this method will construct and store the
731 transposes of the 'diag' and 'offd' CSR matrices. When HYPRE is not built
732 for GPUs, this method is a no-op.
733
734 This method is automatically called by MultTranspose().
735
736 If the matrix is modified the old transpose blocks can be deleted by
737 calling ResetTranspose(). */
738 void EnsureMultTranspose() const;
739
740 /** @brief Reset (destroy) the internal transpose matrix that is created by
741 EnsureMultTranspose() and MultTranspose().
742
743 If the matrix is modified, this method should be called to delete the
744 out-of-date transpose that is stored internally. */
745 void ResetTranspose() const;
746
747 /// Computes y = alpha * A * x + beta * y
748 HYPRE_Int Mult(HypreParVector &x, HypreParVector &y,
749 real_t alpha = 1.0, real_t beta = 0.0) const;
750 /// Computes y = alpha * A * x + beta * y
751 HYPRE_Int Mult(HYPRE_ParVector x, HYPRE_ParVector y,
752 real_t alpha = 1.0, real_t beta = 0.0) const;
753
754 /// Computes y = alpha * A^t * x + beta * y
755 /** If the matrix is modified, call ResetTranspose() and optionally
756 EnsureMultTranspose() to make sure this method uses the correct updated
757 transpose. */
759 real_t alpha = 1.0, real_t beta = 0.0) const;
760
761 void Mult(real_t a, const Vector &x, real_t b, Vector &y) const;
762
763 /// Computes y = alpha * A^t * x + beta * y
764 /** If the matrix is modified, call ResetTranspose() and optionally
765 EnsureMultTranspose() to make sure this method uses the correct updated
766 transpose. */
767 void MultTranspose(real_t a, const Vector &x, real_t b, Vector &y) const;
768
769 void Mult(const Vector &x, Vector &y) const override
770 { Mult(1.0, x, 0.0, y); }
771
772 /// Computes y = A^t * x
773 /** If the matrix is modified, call ResetTranspose() and optionally
774 EnsureMultTranspose() to make sure this method uses the correct updated
775 transpose. */
776 void MultTranspose(const Vector &x, Vector &y) const override
777 { MultTranspose(1.0, x, 0.0, y); }
778
779 void AddMult(const Vector &x, Vector &y, const real_t a = 1.0) const override
780 { Mult(a, x, 1.0, y); }
781 void AddMultTranspose(const Vector &x, Vector &y,
782 const real_t a = 1.0) const override
783 { MultTranspose(a, x, 1.0, y); }
784
785 using Operator::Mult;
787
788 /** @brief Computes y = a * |A| * x + b * y, using entry-wise absolute values
789 of the matrix A. */
790 void AbsMult(real_t a, const Vector &x, real_t b, Vector &y) const;
791
792 /// @brief Computes y = |A| * x, using entry-wise absolute values of the matrix A.
793 void AbsMult(const Vector &x, Vector &y) const override
794 { AbsMult(1.0, x, 0.0, y); }
795
796 /** @brief Computes y = a * |At| * x + b * y, using entry-wise absolute
797 values of the transpose of the matrix A. */
798 void AbsMultTranspose(real_t a, const Vector &x, real_t b, Vector &y) const;
799
800 /** @brief Computes y = |At| * x, using entry-wise absolute values of the
801 matrix A. */
802 void AbsMultTranspose(const Vector &x, Vector &y) const override
803 { AbsMultTranspose(1.0, x, 0.0, y); }
804
805 /** @brief The "Boolean" analog of y = alpha * A * x + beta * y, where
806 elements in the sparsity pattern of the matrix are treated as "true". */
807 void BooleanMult(int alpha, const int *x, int beta, int *y)
808 {
809 HostRead();
810 internal::hypre_ParCSRMatrixBooleanMatvec(A, alpha, const_cast<int*>(x),
811 beta, y);
812 HypreRead();
813 }
814
815 /** @brief The "Boolean" analog of y = alpha * A^T * x + beta * y, where
816 elements in the sparsity pattern of the matrix are treated as "true". */
817 void BooleanMultTranspose(int alpha, const int *x, int beta, int *y)
818 {
819 HostRead();
820 internal::hypre_ParCSRMatrixBooleanMatvecT(A, alpha, const_cast<int*>(x),
821 beta, y);
822 HypreRead();
823 }
824
825 /// Initialize all entries with value.
827 {
828#if MFEM_HYPRE_VERSION < 22200
829 internal::hypre_ParCSRMatrixSetConstantValues(A, value);
830#else
831 hypre_ParCSRMatrixSetConstantValues(A, value);
832#endif
833 return *this;
834 }
835
836 /** Perform the operation `*this += B`, assuming that both matrices use the
837 same row and column partitions and the same col_map_offd arrays, or B has
838 an empty off-diagonal block. We also assume that the sparsity pattern of
839 `*this` contains that of `B`. */
840 HypreParMatrix &operator+=(const HypreParMatrix &B) { return Add(1.0, B); }
841
842 /** Perform the operation `*this += beta*B`, assuming that both matrices use
843 the same row and column partitions and the same col_map_offd arrays, or
844 B has an empty off-diagonal block. We also assume that the sparsity
845 pattern of `*this` contains that of `B`. For a more general case consider
846 the stand-alone function ParAdd described below. */
848 {
849 MFEM_VERIFY(internal::hypre_ParCSRMatrixSum(A, beta, B.A) == 0,
850 "error in hypre_ParCSRMatrixSum");
851 return *this;
852 }
853
854 /** @brief Multiply the HypreParMatrix on the left by a block-diagonal
855 parallel matrix @a D and return the result as a new HypreParMatrix. */
856 /** If @a D has a different number of rows than @a A (this matrix), @a D's
857 row starts array needs to be given (as returned by the methods
858 GetDofOffsets/GetTrueDofOffsets of ParFiniteElementSpace). The new
859 matrix @a D*A uses copies of the row- and column-starts arrays, so "this"
860 matrix and @a row_starts can be deleted.
861 @note This operation is local and does not require communication. */
863 HYPRE_BigInt* row_starts = NULL) const;
864
865 /// Scale the local row i by s(i).
866 void ScaleRows(const Vector & s);
867 /// Scale the local row i by 1./s(i)
868 void InvScaleRows(const Vector & s);
869 /// Scale all entries by s: A_scaled = s*A.
870 void operator*=(real_t s);
871
872 /// Remove values smaller in absolute value than some threshold
873 void Threshold(real_t threshold = 0.0);
874
875 /** @brief Wrapper for hypre_ParCSRMatrixDropSmallEntries in different
876 versions of hypre. Drop off-diagonal entries that are smaller than
877 tol * l2 norm of its row */
878 /** For HYPRE versions < 2.14, this method just calls Threshold() with
879 threshold = tol * max(l2 row norm). */
880 void DropSmallEntries(real_t tol);
881
882 /// If a row contains only zeros, set its diagonal to 1.
883 void EliminateZeroRows() { hypre_ParCSRMatrixFixZeroRows(A); }
884
885 /** Eliminate rows and columns from the matrix, and rows from the vector B.
886 Modify B with the BC values in X. */
887 void EliminateRowsCols(const Array<int> &rows_cols, const HypreParVector &X,
888 HypreParVector &B);
889
890 /** Eliminate rows and columns from the matrix and store the eliminated
891 elements in a new matrix Ae (returned), so that the modified matrix and
892 Ae sum to the original matrix. */
894
895 /** Eliminate columns from the matrix and store the eliminated elements in a
896 new matrix Ae (returned) so that the modified matrix and Ae sum to the
897 original matrix. */
899
900 /// Eliminate rows from the diagonal and off-diagonal blocks of the matrix.
901 void EliminateRows(const Array<int> &rows);
902
903 /** @brief Eliminate essential BC specified by @a ess_dof_list from the
904 solution @a X to the r.h.s. @a B. */
905 /** This matrix is the matrix with eliminated BC, while @a Ae is such that
906 (A+Ae) is the original (Neumann) matrix before elimination. */
907 void EliminateBC(const HypreParMatrix &Ae, const Array<int> &ess_dof_list,
908 const Vector &X, Vector &B) const;
909
910 /** @brief Eliminate essential (Dirichlet) boundary conditions.
911
912 @param[in] ess_dofs indices of the degrees of freedom belonging to the
913 essential boundary conditions.
914 @param[in] diag_policy policy for diagonal entries. */
915 void EliminateBC(const Array<int> &ess_dofs,
916 DiagonalPolicy diag_policy);
917
918 /// Update the internal hypre_ParCSRMatrix object, A, to be on host.
919 /** After this call A's diagonal and off-diagonal should not be modified
920 until after a suitable call to {Host,Hypre}{Write,ReadWrite}. */
922
923 /// Update the internal hypre_ParCSRMatrix object, A, to be on host.
924 /** After this call A's diagonal and off-diagonal can be modified on host
925 and subsequent calls to Hypre{Read,Write,ReadWrite} will require a deep
926 copy of the data if hypre is built with device support. */
928
929 /// Update the internal hypre_ParCSRMatrix object, A, to be on host.
930 /** Similar to HostReadWrite(), except that the data will never be copied
931 from device to host to ensure host contains the correct current data. */
933
934 /** @brief Update the internal hypre_ParCSRMatrix object, A, to be in hypre
935 memory space. */
936 /** After this call A's diagonal and off-diagonal should not be modified
937 until after a suitable call to {Host,Hypre}{Write,ReadWrite}. */
938 void HypreRead() const { Read(GetHypreMemoryClass()); }
939
940 /** @brief Update the internal hypre_ParCSRMatrix object, A, to be in hypre
941 memory space. */
942 /** After this call A's diagonal and off-diagonal can be modified in hypre
943 memory space and subsequent calls to Host{Read,Write,ReadWrite} will
944 require a deep copy of the data if hypre is built with device support. */
946
947 /** @brief Update the internal hypre_ParCSRMatrix object, A, to be in hypre
948 memory space. */
949 /** Similar to HostReadWrite(), except that the data will never be copied
950 from host to hypre memory space to ensure the latter contains the correct
951 current data. */
953
954 Memory<HYPRE_Int> &GetDiagMemoryI() { return mem_diag.I; }
955 Memory<HYPRE_Int> &GetDiagMemoryJ() { return mem_diag.J; }
956 Memory<real_t> &GetDiagMemoryData() { return mem_diag.data; }
957
958 const Memory<HYPRE_Int> &GetDiagMemoryI() const { return mem_diag.I; }
959 const Memory<HYPRE_Int> &GetDiagMemoryJ() const { return mem_diag.J; }
960 const Memory<real_t> &GetDiagMemoryData() const { return mem_diag.data; }
961
962 /// @brief Prints the locally owned rows in parallel. The resulting files can
963 /// be read with Read_IJMatrix().
964 void Print(const std::string &fname, HYPRE_Int offi = 0,
965 HYPRE_Int offj = 0) const;
966 /// Reads the matrix from a file
967 void Read(MPI_Comm comm, const std::string &fname);
968 /// Read a matrix saved as a HYPRE_IJMatrix
969 void Read_IJMatrix(MPI_Comm comm, const std::string &fname);
970
971 /// Print information about the hypre_ParCSRCommPkg of the HypreParMatrix.
972 void PrintCommPkg(std::ostream &out = mfem::out) const;
973
974 /** @brief Print sizes and hashes for all data arrays of the HypreParMatrix
975 from the local MPI rank. */
976 /** This is a compact text representation of the local data of the
977 HypreParMatrix that can be used to compare matrices from different runs
978 without the need to save the whole matrix. */
979 void PrintHash(std::ostream &out) const;
980
981 /// @brief Return the Frobenius norm of the matrix (or 0 if the underlying
982 /// hypre matrix is NULL)
983 real_t FNorm() const;
984
985 /// Calls hypre's destroy function
986 virtual ~HypreParMatrix() { Destroy(); }
987
988 Type GetType() const { return Hypre_ParCSR; }
989};
990
991/// @brief Make @a A_hyp steal ownership of its diagonal part @a A_diag.
992///
993/// If @a A_hyp does not own I and J, then they are aliases pointing to the I
994/// and J arrays in @a A_diag. In that case, this function swaps the memory
995/// objects. Similarly for the data array.
996///
997/// After this function is called, @a A_hyp will own all of the arrays of its
998/// diagonal part.
999///
1000/// @note I and J can only be aliases when HYPRE_BIGINT is disabled.
1001void HypreStealOwnership(HypreParMatrix &A_hyp, SparseMatrix &A_diag);
1002
1003#if MFEM_HYPRE_VERSION >= 21800
1004
1006{
1008 RHS_ONLY,
1010};
1011
1012/** Constructs and applies block diagonal inverse of HypreParMatrix.
1013 The enum @a job specifies whether the matrix or the RHS should be
1014 scaled (or both). */
1015void BlockInverseScale(const HypreParMatrix *A, HypreParMatrix *C,
1016 const Vector *b, HypreParVector *d,
1017 int blocksize, BlockInverseScaleJob job);
1018#endif
1019
1020/** @brief Return a new matrix `C = alpha*A + beta*B`, assuming that both `A`
1021 and `B` use the same row and column partitions and the same `col_map_offd`
1022 arrays. */
1023HypreParMatrix *Add(real_t alpha, const HypreParMatrix &A,
1024 real_t beta, const HypreParMatrix &B);
1025
1026/** Returns the matrix @a A * @a B. Returned matrix does not necessarily own
1027 row or column starts unless the bool @a own_matrix is set to true. */
1028HypreParMatrix * ParMult(const HypreParMatrix *A, const HypreParMatrix *B,
1029 bool own_matrix = false);
1030/// Returns the matrix A + B
1031/** It is assumed that both matrices use the same row and column partitions and
1032 the same col_map_offd arrays. */
1033HypreParMatrix * ParAdd(const HypreParMatrix *A, const HypreParMatrix *B);
1034
1035/// Returns the matrix P^t * A * P
1036HypreParMatrix * RAP(const HypreParMatrix *A, const HypreParMatrix *P);
1037/// Returns the matrix Rt^t * A * P
1038HypreParMatrix * RAP(const HypreParMatrix * Rt, const HypreParMatrix *A,
1039 const HypreParMatrix *P);
1040
1041/// Returns a merged hypre matrix constructed from hypre matrix blocks.
1042/** It is assumed that all block matrices use the same communicator, and the
1043 block sizes are consistent in rows and columns. Rows and columns are
1044 renumbered but not redistributed in parallel, e.g. the block rows owned by
1045 each process remain on that process in the resulting matrix. Some blocks can
1046 be NULL. Each block and the entire system can be rectangular. Scalability to
1047 extremely large processor counts is limited by global MPI communication, see
1048 GatherBlockOffsetData() in hypre.cpp. */
1049HypreParMatrix *HypreParMatrixFromBlocks(Array2D<const HypreParMatrix*> &blocks,
1050 Array2D<real_t> *blockCoeff=NULL);
1051/// @overload
1052MFEM_DEPRECATED HypreParMatrix *HypreParMatrixFromBlocks(
1053 Array2D<HypreParMatrix*> &blocks,
1054 Array2D<real_t> *blockCoeff=NULL);
1055
1056/** @brief Eliminate essential BC specified by @a ess_dof_list from the solution
1057 @a X to the r.h.s. @a B. */
1058/** Here @a A is a matrix with eliminated BC, while @a Ae is such that (A+Ae) is
1059 the original (Neumann) matrix before elimination. */
1060void EliminateBC(const HypreParMatrix &A, const HypreParMatrix &Ae,
1061 const Array<int> &ess_dof_list, const Vector &X, Vector &B);
1062
1063
1064/// Parallel smoothers in hypre
1065class HypreSmoother : public Solver
1066{
1067protected:
1068 /// The linear system matrix
1070 /// Right-hand side and solution vectors
1071 mutable HypreParVector *B, *X;
1072 /** @brief Auxiliary buffers for the case when the input or output arrays in
1073 methods like Mult(const Vector &, Vector &) need to be deep copied in
1074 order to be used by hypre. */
1076 /// Temporary vectors
1077 mutable HypreParVector *V, *Z;
1078 /// FIR Filter Temporary Vectors
1080
1081 /** Smoother type from hypre_ParCSRRelax() in ams.c plus extensions, see the
1082 enumeration Type below. */
1083 int type;
1084 /// Number of relaxation sweeps
1086 /// Damping coefficient (usually <= 1)
1088 /// SOR parameter (usually in (0,2))
1090 /// Order of the smoothing polynomial
1092 /// Fraction of spectrum to smooth for polynomial relaxation
1094 /// Apply the polynomial smoother to A or D^{-1/2} A D^{-1/2}
1096
1097 /// Taubin's lambda-mu method parameters
1101
1102 /// l1 norms of the rows of A
1104 /// If set, take absolute values of the computed l1_norms
1106 /// Number of CG iterations to determine eigenvalue estimates
1108 /// Maximal eigenvalue estimate for polynomial smoothing
1110 /// Minimal eigenvalue estimate for polynomial smoothing
1112 /// Parameters for windowing function of FIR filter
1114
1115 /// Combined coefficients for windowing and Chebyshev polynomials.
1117
1118 /// A flag that indicates whether the linear system matrix A is symmetric
1120
1121public:
1122 /// HYPRE smoother types
1123 enum Type
1124 {
1125 Jacobi = 0, ///< Jacobi
1126 l1Jacobi = 1, ///< l1-scaled Jacobi
1127 l1GS = 2, ///< l1-scaled block Gauss-Seidel/SSOR
1128 l1GStr = 4, ///< truncated l1-scaled block Gauss-Seidel/SSOR
1129 lumpedJacobi = 5, ///< lumped Jacobi
1130 GS = 6, ///< Gauss-Seidel
1131 OPFS = 10, /**< On-processor forward solve for matrix w/ triangular
1132 structure */
1133 Chebyshev = 16, ///< Chebyshev
1134 Taubin = 1001, ///< Taubin polynomial smoother
1135 FIR = 1002 ///< FIR polynomial smoother
1137
1138 /// @deprecated Use DefaultType() instead
1139#if !defined(HYPRE_USING_GPU)
1140 MFEM_DEPRECATED static constexpr Type default_type = l1GS;
1141#else
1142 MFEM_DEPRECATED static constexpr Type default_type = l1Jacobi;
1143#endif
1144
1145 /** @brief Default value for the smoother type used by the constructors:
1146 Type::l1GS when HYPRE is running on CPU and Type::l1Jacobi when HYPRE is
1147 running on GPU. */
1149 {
1150 return HypreUsingGPU() ? l1Jacobi : l1GS;
1151 }
1152
1153 HypreSmoother();
1154
1155 HypreSmoother(const HypreParMatrix &A_, int type = DefaultType(),
1156 int relax_times = 1, real_t relax_weight = 1.0,
1157 real_t omega = 1.0, int poly_order = 2,
1158 real_t poly_fraction = .3, int eig_est_cg_iter = 10);
1159
1160 /// Set the relaxation type and number of sweeps
1162 /// Set SOR-related parameters
1164 /// Set parameters for polynomial smoothing
1165 /** By default, 10 iterations of CG are used to estimate the eigenvalues.
1166 Setting eig_est_cg_iter = 0 uses hypre's hypre_ParCSRMaxEigEstimate() instead. */
1168 int eig_est_cg_iter = 10);
1169 /// Set parameters for Taubin's lambda-mu method
1170 void SetTaubinOptions(real_t lambda, real_t mu, int iter);
1171
1172 /// Convenience function for setting canonical windowing parameters
1173 void SetWindowByName(const char* window_name);
1174 /// Set parameters for windowing function for FIR smoother.
1176 /// Compute window and Chebyshev coefficients for given polynomial order.
1177 void SetFIRCoefficients(real_t max_eig);
1178
1179 /// After computing l1-norms, replace them with their absolute values.
1180 /** By default, the l1-norms take their sign from the corresponding diagonal
1181 entries in the associated matrix. */
1182 void SetPositiveDiagonal(bool pos = true) { pos_l1_norms = pos; }
1183
1184 /** Explicitly indicate whether the linear system matrix A is symmetric. If A
1185 is symmetric, the smoother will also be symmetric. In this case, calling
1186 MultTranspose will be redirected to Mult. (This is also done if the
1187 smoother is diagonal.) By default, A is assumed to be nonsymmetric. */
1188 void SetOperatorSymmetry(bool is_sym) { A_is_symmetric = is_sym; }
1189
1190 /** Set/update the associated operator. Must be called after setting the
1191 HypreSmoother type and options. */
1192 void SetOperator(const Operator &op) override;
1193
1194 /// Relax the linear system Ax=b
1195 virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
1196 void Mult(const Vector &b, Vector &x) const override;
1197 using Operator::Mult;
1198
1199 /// Apply transpose of the smoother to relax the linear system Ax=b
1200 void MultTranspose(const Vector &b, Vector &x) const override;
1201
1202 virtual ~HypreSmoother();
1203};
1204
1205
1206/// Abstract class for hypre's solvers and preconditioners
1207class HypreSolver : public Solver
1208{
1209public:
1210 /// How to treat errors returned by hypre function calls.
1212 {
1213 IGNORE_HYPRE_ERRORS, ///< Ignore hypre errors (see e.g. HypreADS)
1214 WARN_HYPRE_ERRORS, ///< Issue warnings on hypre errors
1215 ABORT_HYPRE_ERRORS ///< Abort on hypre errors (default in base class)
1217
1218protected:
1219 /// The linear system matrix
1221
1222 /// Right-hand side and solution vector
1223 mutable HypreParVector *B, *X;
1224
1226
1227 /// Was hypre's Setup function called already?
1228 mutable int setup_called;
1229
1230 /// How to treat hypre errors.
1232
1233 /// @brief Makes the internal HypreParVector%s @a B and @a X wrap the input
1234 /// vectors @a b and @a x.
1235 ///
1236 /// Returns true if @a x can be shallow-copied, false otherwise.
1237 bool WrapVectors(const Vector &b, Vector &x) const;
1238
1239public:
1240 HypreSolver();
1241
1242 HypreSolver(const HypreParMatrix *A_);
1243
1244 /// Typecast to HYPRE_Solver -- return the solver
1245 virtual operator HYPRE_Solver() const = 0;
1246
1247 /// hypre's internal Setup function
1248 virtual HYPRE_PtrToParSolverFcn SetupFcn() const = 0;
1249 /// hypre's internal Solve function
1250 virtual HYPRE_PtrToParSolverFcn SolveFcn() const = 0;
1251
1252 ///@{
1253
1254 /// @brief Set up the solver (if not set up already, also called
1255 /// automatically by HypreSolver::Mult).
1256 virtual void Setup(const HypreParVector &b, HypreParVector &x) const;
1257 /// @brief Set up the solver (if not set up already, also called
1258 /// automatically by HypreSolver::Mult).
1259 virtual void Setup(const Vector &b, Vector &x) const;
1260
1261 ///@}
1262
1263 void SetOperator(const Operator &op) override
1264 { mfem_error("HypreSolvers do not support SetOperator!"); }
1265
1266 MemoryClass GetMemoryClass() const override { return GetHypreMemoryClass(); }
1267
1268 ///@{
1269
1270 /// Solve the linear system Ax=b
1271 virtual void Mult(const HypreParVector &b, HypreParVector &x) const;
1272 /// Solve the linear system Ax=b
1273 void Mult(const Vector &b, Vector &x) const override;
1274 using Operator::Mult;
1275
1276 ///@}
1277
1278 /** @brief Set the behavior for treating hypre errors, see the ErrorMode
1279 enum. The default mode in the base class is ABORT_HYPRE_ERRORS. */
1280 /** Currently, there are three cases in derived classes where the error flag
1281 is set to IGNORE_HYPRE_ERRORS:
1282 * in the method HypreBoomerAMG::SetElasticityOptions(), and
1283 * in the constructor of classes HypreAMS and HypreADS.
1284 The reason for this is that a nonzero hypre error is returned) when
1285 hypre_ParCSRComputeL1Norms() encounters zero row in a matrix, which is
1286 expected in some cases with the above solvers. */
1287 void SetErrorMode(ErrorMode err_mode) const { error_mode = err_mode; }
1288
1289 virtual ~HypreSolver();
1290};
1291
1292
1293#if MFEM_HYPRE_VERSION >= 21800
1294/** Preconditioner for HypreParMatrices that are triangular in some ordering.
1295 Finds correct ordering and performs forward substitution on processor
1296 as approximate inverse. Exact on one processor. */
1298{
1299public:
1301 explicit HypreTriSolve(const HypreParMatrix &A) : HypreSolver(&A) { }
1302 operator HYPRE_Solver() const override { return NULL; }
1303
1304 HYPRE_PtrToParSolverFcn SetupFcn() const override
1305 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSROnProcTriSetup; }
1306 HYPRE_PtrToParSolverFcn SolveFcn() const override
1307 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSROnProcTriSolve; }
1308
1309 const HypreParMatrix* GetData() const { return A; }
1310
1311 /// Deprecated. Use HypreTriSolve::GetData() const instead.
1312 MFEM_DEPRECATED HypreParMatrix* GetData()
1313 { return const_cast<HypreParMatrix*>(A); }
1314
1315 virtual ~HypreTriSolve() { }
1316};
1317#endif
1318
1319/// PCG solver in hypre
1320class HyprePCG : public HypreSolver
1321{
1322private:
1323 HYPRE_Solver pcg_solver;
1324
1325 HypreSolver * precond;
1326
1327public:
1328 HyprePCG(MPI_Comm comm);
1329
1330 HyprePCG(const HypreParMatrix &A_);
1331
1332 void SetOperator(const Operator &op) override;
1333
1334 void SetTol(real_t tol);
1335 void SetAbsTol(real_t atol);
1336 void SetMaxIter(int max_iter);
1337 void SetLogging(int logging);
1338 void SetPrintLevel(int print_lvl);
1339
1340 /// Set the hypre solver to be used as a preconditioner
1341 void SetPreconditioner(HypreSolver &precond);
1342
1343 /** Use the L2 norm of the residual for measuring PCG convergence, plus
1344 (optionally) 1) periodically recompute true residuals from scratch; and
1345 2) enable residual-based stopping criteria. */
1346 void SetResidualConvergenceOptions(int res_frequency=-1, real_t rtol=0.0);
1347
1348 /// deprecated: use SetZeroInitialIterate()
1349 MFEM_DEPRECATED void SetZeroInintialIterate() { iterative_mode = false; }
1350
1351 /// non-hypre setting
1353
1354 void GetNumIterations(int &num_iterations) const
1355 {
1356 HYPRE_Int num_it;
1357 HYPRE_ParCSRPCGGetNumIterations(pcg_solver, &num_it);
1358 num_iterations = internal::to_int(num_it);
1359 }
1360
1361 void GetFinalResidualNorm(real_t &final_res_norm) const
1362 {
1363 HYPRE_ParCSRPCGGetFinalRelativeResidualNorm(pcg_solver,
1364 &final_res_norm);
1365 }
1366
1367 /// The typecast to HYPRE_Solver returns the internal pcg_solver
1368 operator HYPRE_Solver() const override { return pcg_solver; }
1369
1370 /// PCG Setup function
1371 HYPRE_PtrToParSolverFcn SetupFcn() const override
1372 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRPCGSetup; }
1373 /// PCG Solve function
1374 HYPRE_PtrToParSolverFcn SolveFcn() const override
1375 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRPCGSolve; }
1376
1377 /// Solve Ax=b with hypre's PCG
1378 void Mult(const HypreParVector &b, HypreParVector &x) const override;
1379 using HypreSolver::Mult;
1380
1381 virtual ~HyprePCG();
1382};
1383
1384/// GMRES solver in hypre
1386{
1387private:
1388 HYPRE_Solver gmres_solver;
1389
1390 HypreSolver * precond;
1391
1392 /// Default, generally robust, GMRES options
1393 void SetDefaultOptions();
1394
1395public:
1396 HypreGMRES(MPI_Comm comm);
1397
1398 HypreGMRES(const HypreParMatrix &A_);
1399
1400 void SetOperator(const Operator &op) override;
1401
1402 void SetTol(real_t tol);
1403 void SetAbsTol(real_t tol);
1404 void SetMaxIter(int max_iter);
1405 void SetKDim(int dim);
1406 void SetLogging(int logging);
1407 void SetPrintLevel(int print_lvl);
1408
1409 /// Set the hypre solver to be used as a preconditioner
1410 void SetPreconditioner(HypreSolver &precond);
1411
1412 /// deprecated: use SetZeroInitialIterate()
1413 MFEM_DEPRECATED void SetZeroInintialIterate() { iterative_mode = false; }
1414
1415 /// non-hypre setting
1417
1418 void GetNumIterations(int &num_iterations) const
1419 {
1420 HYPRE_Int num_it;
1421 HYPRE_ParCSRGMRESGetNumIterations(gmres_solver, &num_it);
1422 num_iterations = internal::to_int(num_it);
1423 }
1424
1425 void GetFinalResidualNorm(real_t &final_res_norm) const
1426 {
1427 HYPRE_ParCSRGMRESGetFinalRelativeResidualNorm(gmres_solver,
1428 &final_res_norm);
1429 }
1430
1431 /// The typecast to HYPRE_Solver returns the internal gmres_solver
1432 operator HYPRE_Solver() const override { return gmres_solver; }
1433
1434 /// GMRES Setup function
1435 HYPRE_PtrToParSolverFcn SetupFcn() const override
1436 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRGMRESSetup; }
1437 /// GMRES Solve function
1438 HYPRE_PtrToParSolverFcn SolveFcn() const override
1439 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRGMRESSolve; }
1440
1441 /// Solve Ax=b with hypre's GMRES
1442 void Mult(const HypreParVector &b, HypreParVector &x) const override;
1443 using HypreSolver::Mult;
1444
1445 virtual ~HypreGMRES();
1446};
1447
1448/// Flexible GMRES solver in hypre
1450{
1451private:
1452 HYPRE_Solver fgmres_solver;
1453
1454 HypreSolver * precond;
1455
1456 /// Default, generally robust, FGMRES options
1457 void SetDefaultOptions();
1458
1459public:
1460 HypreFGMRES(MPI_Comm comm);
1461
1462 HypreFGMRES(const HypreParMatrix &A_);
1463
1464 void SetOperator(const Operator &op) override;
1465
1466 void SetTol(real_t tol);
1467 void SetMaxIter(int max_iter);
1468 void SetKDim(int dim);
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_ParCSRFlexGMRESGetNumIterations(fgmres_solver, &num_it);
1485 num_iterations = internal::to_int(num_it);
1486 }
1487
1488 void GetFinalResidualNorm(real_t &final_res_norm) const
1489 {
1490 HYPRE_ParCSRFlexGMRESGetFinalRelativeResidualNorm(fgmres_solver,
1491 &final_res_norm);
1492 }
1493
1494 /// The typecast to HYPRE_Solver returns the internal fgmres_solver
1495 operator HYPRE_Solver() const override { return fgmres_solver; }
1496
1497 /// FGMRES Setup function
1498 HYPRE_PtrToParSolverFcn SetupFcn() const override
1499 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRFlexGMRESSetup; }
1500 /// FGMRES Solve function
1501 HYPRE_PtrToParSolverFcn SolveFcn() const override
1502 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRFlexGMRESSolve; }
1503
1504 /// Solve Ax=b with hypre's FGMRES
1505 void Mult(const HypreParVector &b, HypreParVector &x) const override;
1506 using HypreSolver::Mult;
1507
1508 virtual ~HypreFGMRES();
1509};
1510
1511/// The identity operator as a hypre solver
1513{
1514public:
1515 operator HYPRE_Solver() const override { return NULL; }
1516
1517 HYPRE_PtrToParSolverFcn SetupFcn() const override
1518 { return (HYPRE_PtrToParSolverFcn) hypre_ParKrylovIdentitySetup; }
1519 HYPRE_PtrToParSolverFcn SolveFcn() const override
1520 { return (HYPRE_PtrToParSolverFcn) hypre_ParKrylovIdentity; }
1521
1522 virtual ~HypreIdentity() { }
1523};
1524
1525/// Jacobi preconditioner in hypre
1527{
1528public:
1531 operator HYPRE_Solver() const override { return NULL; }
1532
1533 void SetOperator(const Operator &op) override;
1534
1535 HYPRE_PtrToParSolverFcn SetupFcn() const override
1536 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRDiagScaleSetup; }
1537 HYPRE_PtrToParSolverFcn SolveFcn() const override
1538 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParCSRDiagScale; }
1539
1540 const HypreParMatrix* GetData() const { return A; }
1541
1542 /// Deprecated. Use HypreDiagScale::GetData() const instead.
1543 MFEM_DEPRECATED HypreParMatrix* GetData()
1544 { return const_cast<HypreParMatrix*>(A); }
1545
1546 virtual ~HypreDiagScale() { }
1547};
1548
1549/// The ParaSails preconditioner in hypre
1551{
1552private:
1553 HYPRE_Solver sai_precond;
1554
1555 /// Default, generally robust, ParaSails options
1556 void SetDefaultOptions();
1557
1558 // If sai_precond is NULL, this method allocates it and sets default options.
1559 // Otherwise the method saves the options from sai_precond, destroys it,
1560 // allocates a new object, and sets its options to the saved values.
1561 void ResetSAIPrecond(MPI_Comm comm);
1562
1563public:
1564 HypreParaSails(MPI_Comm comm);
1565
1567
1568 void SetOperator(const Operator &op) override;
1569
1570 /// Set the threshold and levels parameters
1571 /** The accuracy and cost of ParaSails are parametrized by the real
1572 * @a thresh and integer @a nlevels parameters (0<=thresh<=1, 0<=nlevels).
1573 * Lower values of @a thresh and higher values of @a nlevels lead to
1574 * more accurate, but more expensive preconditioners. More accurate
1575 * preconditioners are also more expensive per iteration. The default
1576 * values are @a thresh = 0.1 and @a nlevels = 1.
1577 */
1578 void SetParams(real_t thresh, int nlevels);
1579
1580 /// Set the filter parameter
1581 /** The filter parameter is used to drop small nonzeros in the preconditioner,
1582 * to reduce the cost of applying the preconditioner. Values from 0.055
1583 * to 0.1 are recommended. The default value is 0.1.
1584 */
1585 void SetFilter(real_t filter);
1586
1587 /// Set symmetry parameter
1588 /** The recognized options are:
1589 * 0 = nonsymmetric and/or indefinite problem, and nonsymmetric preconditioner
1590 * 1 = SPD problem, and SPD (factored) preconditioner
1591 * 2 = nonsymmetric, definite problem, and SPD (factored) preconditioner
1592 */
1593 void SetSymmetry(int sym);
1594
1595 /// Set the load balance parameter
1596 /** A zero value indicates that no load balance is attempted; a value
1597 * of unity indicates that perfect load balance will be attempted. The
1598 * recommended value is 0.9 to balance the overhead of data exchanges
1599 * for load balancing. No load balancing is needed if the preconditioner
1600 * is very sparse and fast to construct. The default value is 0.
1601 */
1602 void SetLoadBal(real_t loadbal);
1603
1604 /// Set the pattern reuse parameter
1605 /** A nonzero value indicates that the pattern of the preconditioner
1606 * should be reused for subsequent constructions of the proconditioner.
1607 * A zero value inicates that the peconditioner should be constructed
1608 * from scratch. The default value is 0.
1609 */
1610 void SetReuse(int reuse);
1611
1612 /// Set the logging parameter
1613 /** A nonzero value prints statistics of the setup procedure to stdout.
1614 * The default value of this parameter is 1.
1615 */
1616 void SetLogging(int logging);
1617
1618 /// The typecast to HYPRE_Solver returns the internal sai_precond
1619 operator HYPRE_Solver() const override { return sai_precond; }
1620
1621 HYPRE_PtrToParSolverFcn SetupFcn() const override
1622 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParaSailsSetup; }
1623 HYPRE_PtrToParSolverFcn SolveFcn() const override
1624 { return (HYPRE_PtrToParSolverFcn) HYPRE_ParaSailsSolve; }
1625
1626 virtual ~HypreParaSails();
1627};
1628
1629/** The Euclid preconditioner in Hypre
1630
1631 Euclid implements the Parallel Incomplete LU factorization technique. For
1632 more information see:
1633
1634 "A Scalable Parallel Algorithm for Incomplete Factor Preconditioning" by
1635 David Hysom and Alex Pothen, https://doi.org/10.1137/S1064827500376193
1636*/
1638{
1639private:
1640 HYPRE_Solver euc_precond;
1641
1642 /// Default, generally robust, Euclid options
1643 void SetDefaultOptions();
1644
1645 // If euc_precond is NULL, this method allocates it and sets default options.
1646 // Otherwise the method saves the options from euc_precond, destroys it,
1647 // allocates a new object, and sets its options to the saved values.
1648 void ResetEuclidPrecond(MPI_Comm comm);
1649
1650public:
1651 HypreEuclid(MPI_Comm comm);
1652
1654
1655 void SetLevel(int level);
1656 void SetStats(int stats);
1657 void SetMemory(int mem);
1658 void SetBJ(int bj);
1659 void SetRowScale(int row_scale);
1660
1661 void SetOperator(const Operator &op) override;
1662
1663 /// The typecast to HYPRE_Solver returns the internal euc_precond
1664 operator HYPRE_Solver() const override { return euc_precond; }
1665
1666 HYPRE_PtrToParSolverFcn SetupFcn() const override
1667 { return (HYPRE_PtrToParSolverFcn) HYPRE_EuclidSetup; }
1668 HYPRE_PtrToParSolverFcn SolveFcn() const override
1669 { return (HYPRE_PtrToParSolverFcn) HYPRE_EuclidSolve; }
1670
1671 virtual ~HypreEuclid();
1672};
1673
1674#if MFEM_HYPRE_VERSION >= 21900
1675/**
1676@brief Wrapper for Hypre's native parallel ILU preconditioner.
1677
1678The default ILU factorization type is ILU(k). If you need to change this, or
1679any other option, you can use the HYPRE_Solver method to cast the object for use
1680with Hypre's native functions. For example, if want to use natural ordering
1681rather than RCM reordering, you can use the following approach:
1682
1683@code
1684mfem::HypreILU ilu();
1685int reorder_type = 0;
1686HYPRE_ILUSetLocalReordering(ilu, reorder_type);
1687@endcode
1688*/
1689class HypreILU : public HypreSolver
1690{
1691private:
1692 HYPRE_Solver ilu_precond;
1693
1694 /// Set the ILU default options
1695 void SetDefaultOptions();
1696
1697 /** Reset the ILU preconditioner.
1698 @note If ilu_precond is NULL, this method allocates; otherwise it destroys
1699 ilu_precond and allocates a new object. In both cases the default options
1700 are set. */
1701 void ResetILUPrecond();
1702
1703public:
1704 /// Constructor; sets the default options
1705 HypreILU();
1706
1707 virtual ~HypreILU();
1708
1709 /// Set the fill level for ILU(k); the default is k=1.
1710 void SetLevelOfFill(HYPRE_Int lev_fill);
1711
1712 void SetType(HYPRE_Int ilu_type);
1713 void SetMaxIter(HYPRE_Int max_iter);
1714 void SetTol(HYPRE_Real tol);
1715 void SetLocalReordering(HYPRE_Int reorder_type);
1716
1717 /// Set the print level: 0 = none, 1 = setup, 2 = solve, 3 = setup+solve
1718 void SetPrintLevel(HYPRE_Int print_level);
1719
1720 /// The typecast to HYPRE_Solver returns the internal ilu_precond
1721 operator HYPRE_Solver() const override { return ilu_precond; }
1722
1723 void SetOperator(const Operator &op) override;
1724
1725 /// ILU Setup function
1726 HYPRE_PtrToParSolverFcn SetupFcn() const override
1727 { return (HYPRE_PtrToParSolverFcn) HYPRE_ILUSetup; }
1728
1729 /// ILU Solve function
1730 HYPRE_PtrToParSolverFcn SolveFcn() const override
1731 { return (HYPRE_PtrToParSolverFcn) HYPRE_ILUSolve; }
1732};
1733#endif
1734
1735/// The BoomerAMG solver in hypre
1737{
1738private:
1739 HYPRE_Solver amg_precond;
1740
1741 /// Rigid body modes
1743
1744 /// Finite element space for elasticity problems, see SetElasticityOptions()
1745 ParFiniteElementSpace *fespace;
1746
1747 /// Recompute the rigid-body modes vectors (in the rbms array)
1748 void RecomputeRBMs();
1749
1750 /// Default, generally robust, BoomerAMG options
1751 void SetDefaultOptions();
1752
1753 // If amg_precond is NULL, allocates it and sets default options.
1754 // Otherwise saves the options from amg_precond, destroys it, allocates a new
1755 // one, and sets its options to the saved values.
1756 void ResetAMGPrecond();
1757
1758public:
1760
1762
1763 void SetOperator(const Operator &op) override;
1764
1765 /** More robust options for systems, such as elasticity. */
1766 void SetSystemsOptions(int dim, bool order_bynodes=false);
1767
1768 /** A special elasticity version of BoomerAMG that takes advantage of
1769 geometric rigid body modes and could perform better on some problems, see
1770 "Improving algebraic multigrid interpolation operators for linear
1771 elasticity problems", Baker, Kolev, Yang, NLAA 2009, DOI:10.1002/nla.688.
1772 The optional argument @ interp_refine is used to enable/disable pre-processing
1773 of the interpolation matrix through iterative weight refinement */
1775 bool interp_refine = true);
1776
1777#if MFEM_HYPRE_VERSION >= 21800
1778 /** Hypre parameters to use AIR AMG solve for advection-dominated problems.
1779 See "Nonsymmetric Algebraic Multigrid Based on Local Approximate Ideal
1780 Restriction (AIR)," Manteuffel, Ruge, Southworth, SISC (2018),
1781 DOI:/10.1137/17M1144350. Options: "distanceR" -> distance of neighbor
1782 DOFs for the restriction operator; options include 1, 2, and 15 (1.5).
1783 Strings "prerelax" and "postrelax" indicate points to relax on:
1784 F = F-points, C = C-points, A = all points. E.g., FFC -> relax on
1785 F-points, relax again on F-points, then relax on C-points. */
1786 void SetAdvectiveOptions(int distance=15, const std::string &prerelax="",
1787 const std::string &postrelax="FFC");
1788
1789 /// Expert option - consult hypre documentation/team
1791 { HYPRE_BoomerAMGSetStrongThresholdR(amg_precond, strengthR); }
1792
1793 /// Expert option - consult hypre documentation/team
1795 { HYPRE_BoomerAMGSetFilterThresholdR(amg_precond, filterR); }
1796
1797 /// Expert option - consult hypre documentation/team
1798 void SetRestriction(int restrict_type)
1799 { HYPRE_BoomerAMGSetRestriction(amg_precond, restrict_type); }
1800
1801 /// Expert option - consult hypre documentation/team
1803 { HYPRE_BoomerAMGSetIsTriangular(amg_precond, 1); }
1804
1805 /// Expert option - consult hypre documentation/team
1806 void SetGMRESSwitchR(int gmres_switch)
1807 { HYPRE_BoomerAMGSetGMRESSwitchR(amg_precond, gmres_switch); }
1808
1809 /// Expert option - consult hypre documentation/team
1810 void SetCycleNumSweeps(int prerelax, int postrelax)
1811 {
1812 HYPRE_BoomerAMGSetCycleNumSweeps(amg_precond, prerelax, 1);
1813 HYPRE_BoomerAMGSetCycleNumSweeps(amg_precond, postrelax, 2);
1814 }
1815#endif
1816
1817 void SetPrintLevel(int print_level)
1818 { HYPRE_BoomerAMGSetPrintLevel(amg_precond, print_level); }
1819
1820 void SetMaxIter(int max_iter)
1821 { HYPRE_BoomerAMGSetMaxIter(amg_precond, max_iter); }
1822
1823 /// Expert option - consult hypre documentation/team
1824 void SetMaxLevels(int max_levels)
1825 { HYPRE_BoomerAMGSetMaxLevels(amg_precond, max_levels); }
1826
1827 /// Expert option - consult hypre documentation/team
1828 void SetTol(real_t tol)
1829 { HYPRE_BoomerAMGSetTol(amg_precond, tol); }
1830
1831 /// Expert option - consult hypre documentation/team
1833 { HYPRE_BoomerAMGSetStrongThreshold(amg_precond, strength); }
1834
1835 /// Expert option - consult hypre documentation/team
1836 void SetInterpolation(int interp_type)
1837 { HYPRE_BoomerAMGSetInterpType(amg_precond, interp_type); }
1838
1839 /// Expert option - consult hypre documentation/team
1840 void SetCoarsening(int coarsen_type)
1841 { HYPRE_BoomerAMGSetCoarsenType(amg_precond, coarsen_type); }
1842
1843 /// Expert option - consult hypre documentation/team
1844 void SetRelaxType(int relax_type)
1845 { HYPRE_BoomerAMGSetRelaxType(amg_precond, relax_type); }
1846
1847 /// Expert option - consult hypre documentation/team
1848 void SetCycleType(int cycle_type)
1849 { HYPRE_BoomerAMGSetCycleType(amg_precond, cycle_type); }
1850
1851 void GetNumIterations(int &num_iterations) const
1852 {
1853 HYPRE_Int num_it;
1854 HYPRE_BoomerAMGGetNumIterations(amg_precond, &num_it);
1855 num_iterations = internal::to_int(num_it);
1856 }
1857
1858 /// Expert option - consult hypre documentation/team
1859 void SetNodal(int blocksize)
1860 {
1861 HYPRE_BoomerAMGSetNumFunctions(amg_precond, blocksize);
1862 HYPRE_BoomerAMGSetNodal(amg_precond, 1);
1863 }
1864
1865 /// Expert option - consult hypre documentation/team
1866 void SetAggressiveCoarsening(int num_levels)
1867 { HYPRE_BoomerAMGSetAggNumLevels(amg_precond, num_levels); }
1868
1869 /// The typecast to HYPRE_Solver returns the internal amg_precond
1870 operator HYPRE_Solver() const override { return amg_precond; }
1871
1872 HYPRE_PtrToParSolverFcn SetupFcn() const override
1873 { return (HYPRE_PtrToParSolverFcn) HYPRE_BoomerAMGSetup; }
1874 HYPRE_PtrToParSolverFcn SolveFcn() const override
1875 { return (HYPRE_PtrToParSolverFcn) HYPRE_BoomerAMGSolve; }
1876
1877 using HypreSolver::Mult;
1878
1879 virtual ~HypreBoomerAMG();
1880};
1881
1882/// Compute the discrete gradient matrix between the nodal linear and ND1 spaces
1884 ParFiniteElementSpace *vert_fespace);
1885/// Compute the discrete curl matrix between the ND1 and RT0 spaces
1887 ParFiniteElementSpace *edge_fespace);
1888
1889/// The Auxiliary-space Maxwell Solver in hypre
1890class HypreAMS : public HypreSolver
1891{
1892private:
1893 /// Construct AMS solver from finite element space
1894 void Init(ParFiniteElementSpace *edge_space);
1895
1896 /// Create the hypre solver object and set the default options, given the
1897 /// space dimension @a sdim and cycle type @a cycle_type.
1898 void MakeSolver(int sdim, int cycle_type);
1899
1900 /// Construct the gradient and interpolation matrices associated with
1901 /// @a edge_fespace, and add them to the solver.
1902 void MakeGradientAndInterpolation(ParFiniteElementSpace *edge_fespace,
1903 int cycle_type);
1904
1905 // Recreates another AMS solver with the same options when SetOperator is
1906 // called multiple times.
1907 void ResetAMSPrecond();
1908
1909 /// The underlying hypre solver object
1910 HYPRE_Solver ams;
1911 /// Vertex coordinates
1912 HypreParVector *x, *y, *z;
1913 /// Discrete gradient matrix
1914 HypreParMatrix *G;
1915 /// Nedelec interpolation matrix and its components
1916 HypreParMatrix *Pi, *Pix, *Piy, *Piz;
1917
1918 /// AMS cycle type
1919 int ams_cycle_type = 0;
1920 /// Spatial dimension of the underlying mesh
1921 int space_dim = 0;
1922 /// Flag set if `SetSingularProblem` is called, needed in `ResetAMSPrecond`
1923 bool singular = false;
1924 /// Flag set if `SetPrintLevel` is called, needed in `ResetAMSPrecond`
1925 int print_level = 1;
1926
1927public:
1928 /// @brief Construct the AMS solver on the given edge finite element space.
1929 ///
1930 /// HypreAMS::SetOperator must be called to set the system matrix.
1931 HypreAMS(ParFiniteElementSpace *edge_fespace);
1932
1933 /// Construct the AMS solver using the given matrix and finite element space.
1934 HypreAMS(const HypreParMatrix &A, ParFiniteElementSpace *edge_fespace);
1935
1936 /// @brief Construct the AMS solver using the provided discrete gradient
1937 /// matrix @a G_ and the vertex coordinate vectors @a x_, @a y_, and @a z_.
1938 ///
1939 /// For 2D problems, @a z_ may be NULL. All other parameters must be
1940 /// non-NULL. The solver assumes ownership of G_, x_, y_, and z_.
1942 HypreParVector *y_, HypreParVector *z_=NULL);
1943
1944 void SetOperator(const Operator &op) override;
1945
1946 void SetPrintLevel(int print_lvl);
1947
1948 /// Set this option when solving a curl-curl problem with zero mass term
1950 {
1951 HYPRE_AMSSetBetaPoissonMatrix(ams, NULL);
1952 singular = true;
1953 }
1954
1955 /// The typecast to HYPRE_Solver returns the internal ams object
1956 operator HYPRE_Solver() const override { return ams; }
1957
1958 HYPRE_PtrToParSolverFcn SetupFcn() const override
1959 { return (HYPRE_PtrToParSolverFcn) HYPRE_AMSSetup; }
1960 HYPRE_PtrToParSolverFcn SolveFcn() const override
1961 { return (HYPRE_PtrToParSolverFcn) HYPRE_AMSSolve; }
1962
1963 virtual ~HypreAMS();
1964};
1965
1966/// The Auxiliary-space Divergence Solver in hypre
1967class HypreADS : public HypreSolver
1968{
1969private:
1970 /// Construct ADS solver from finite element space
1971 void Init(ParFiniteElementSpace *face_fespace);
1972
1973 /// Create the hypre solver object and set the default options, using the
1974 /// cycle type cycle_type and AMS cycle type ams_cycle_type data members.
1975 void MakeSolver();
1976
1977 /// Construct the discrete curl, gradient and interpolation matrices
1978 /// associated with @a face_fespace, and add them to the solver.
1979 void MakeDiscreteMatrices(ParFiniteElementSpace *face_fespace);
1980
1981 HYPRE_Solver ads;
1982
1983 /// Vertex coordinates
1984 HypreParVector *x, *y, *z;
1985 /// Discrete gradient matrix
1986 HypreParMatrix *G;
1987 /// Discrete curl matrix
1988 HypreParMatrix *C;
1989 /// Nedelec interpolation matrix and its components
1990 HypreParMatrix *ND_Pi, *ND_Pix, *ND_Piy, *ND_Piz;
1991 /// Raviart-Thomas interpolation matrix and its components
1992 HypreParMatrix *RT_Pi, *RT_Pix, *RT_Piy, *RT_Piz;
1993
1994 /// ADS cycle type
1995 const int cycle_type = 11;
1996 /// AMS cycle type
1997 const int ams_cycle_type = 14;
1998 /// ADS print level
1999 int print_level = 1;
2000
2001 // Recreates another ADS solver with the same options when SetOperator is
2002 // called multiple times.
2003 void ResetADSPrecond();
2004public:
2005 HypreADS(ParFiniteElementSpace *face_fespace);
2006
2007 HypreADS(const HypreParMatrix &A, ParFiniteElementSpace *face_fespace);
2008
2009 /// @brief Construct the ADS solver using the provided discrete curl matrix
2010 /// @a C, discrete gradient matrix @a G_ and vertex coordinate vectors @a x_,
2011 /// @a y_, and @a z_.
2012 ///
2013 /// None of the inputs may be NULL. The solver assumes ownership of C_, G_,
2014 /// x_, y_, and z_.
2017
2018 void SetOperator(const Operator &op) override;
2019
2020 void SetPrintLevel(int print_lvl);
2021
2022 /// The typecast to HYPRE_Solver returns the internal ads object
2023 operator HYPRE_Solver() const override { return ads; }
2024
2025 HYPRE_PtrToParSolverFcn SetupFcn() const override
2026 { return (HYPRE_PtrToParSolverFcn) HYPRE_ADSSetup; }
2027 HYPRE_PtrToParSolverFcn SolveFcn() const override
2028 { return (HYPRE_PtrToParSolverFcn) HYPRE_ADSSolve; }
2029
2030 virtual ~HypreADS();
2031};
2032
2033/** LOBPCG eigenvalue solver in hypre
2034
2035 The Locally Optimal Block Preconditioned Conjugate Gradient (LOBPCG)
2036 eigenvalue solver is designed to find the lowest eigenmodes of the
2037 generalized eigenvalue problem:
2038 A x = lambda M x
2039 where A is symmetric, potentially indefinite and M is symmetric positive
2040 definite. The eigenvectors are M-orthonormal, meaning that
2041 x^T M x = 1 and x^T M y = 0,
2042 if x and y are distinct eigenvectors. The matrix M is optional and is
2043 assumed to be the identity if left unset.
2044
2045 The efficiency of LOBPCG relies on the availability of a suitable
2046 preconditioner for the matrix A. The preconditioner is supplied through the
2047 SetPreconditioner() method. It should be noted that the operator used with
2048 the preconditioner need not be A itself.
2049
2050 For more information regarding LOBPCG see "Block Locally Optimal
2051 Preconditioned Eigenvalue Xolvers (BLOPEX) in Hypre and PETSc" by
2052 A. Knyazev, M. Argentati, I. Lashuk, and E. Ovtchinnikov, SISC, 29(5),
2053 2224-2239, 2007.
2054*/
2056{
2057private:
2058 MPI_Comm comm;
2059 int myid;
2060 int numProcs;
2061 int nev; // Number of desired eigenmodes
2062 int seed; // Random seed used for initial vectors
2063
2064 HYPRE_BigInt glbSize; // Global number of DoFs in the linear system
2065 HYPRE_BigInt * part; // Row partitioning of the linear system
2066
2067 // Pointer to HYPRE's solver struct
2068 HYPRE_Solver lobpcg_solver;
2069
2070 // Interface for matrix storage type
2071 mv_InterfaceInterpreter interpreter;
2072
2073 // Interface for setting up and performing matrix-vector products
2074 HYPRE_MatvecFunctions matvec_fn;
2075
2076 // Eigenvalues
2077 Array<real_t> eigenvalues;
2078
2079 // Forward declaration
2080 class HypreMultiVector;
2081
2082 // MultiVector to store eigenvectors
2083 HypreMultiVector * multi_vec;
2084
2085 // Empty vectors used to setup the matrices and preconditioner
2086 HypreParVector * x;
2087
2088 // An optional operator which projects vectors into a desired subspace
2089 Operator * subSpaceProj;
2090
2091 /// Internal class to represent a set of eigenvectors
2092 class HypreMultiVector
2093 {
2094 private:
2095 // Pointer to hypre's multi-vector object
2096 mv_MultiVectorPtr mv_ptr;
2097
2098 // Wrappers for each member of the multivector
2099 HypreParVector ** hpv;
2100
2101 // Number of vectors in the multivector
2102 int nv;
2103
2104 public:
2105 HypreMultiVector(int n, HypreParVector & v,
2106 mv_InterfaceInterpreter & interpreter);
2107 ~HypreMultiVector();
2108
2109 /// Set random values
2110 void Randomize(HYPRE_Int seed);
2111
2112 /// Extract a single HypreParVector object
2113 HypreParVector & GetVector(unsigned int i);
2114
2115 /// Transfers ownership of data to returned array of vectors
2116 HypreParVector ** StealVectors();
2117
2118 operator mv_MultiVectorPtr() const { return mv_ptr; }
2119
2120 mv_MultiVectorPtr & GetMultiVector() { return mv_ptr; }
2121 };
2122
2123 static void * OperatorMatvecCreate( void *A, void *x );
2124 static HYPRE_Int OperatorMatvec( void *matvec_data,
2125 HYPRE_Complex alpha,
2126 void *A,
2127 void *x,
2128 HYPRE_Complex beta,
2129 void *y );
2130 static HYPRE_Int OperatorMatvecDestroy( void *matvec_data );
2131
2132 static HYPRE_Int PrecondSolve(void *solver,
2133 void *A,
2134 void *b,
2135 void *x);
2136 static HYPRE_Int PrecondSetup(void *solver,
2137 void *A,
2138 void *b,
2139 void *x);
2140
2141public:
2142 HypreLOBPCG(MPI_Comm comm);
2143 ~HypreLOBPCG();
2144
2145 void SetTol(real_t tol);
2146 void SetRelTol(real_t rel_tol);
2147 void SetMaxIter(int max_iter);
2148 void SetPrintLevel(int logging);
2149 void SetNumModes(int num_eigs) { nev = num_eigs; }
2150 void SetPrecondUsageMode(int pcg_mode);
2151 void SetRandomSeed(int s) { seed = s; }
2152 void SetInitialVectors(int num_vecs, HypreParVector ** vecs);
2153
2154 // The following four methods support general operators
2155 void SetPreconditioner(Solver & precond);
2156 void SetOperator(Operator & A);
2157 void SetMassMatrix(Operator & M);
2158 void SetSubSpaceProjector(Operator & proj) { subSpaceProj = &proj; }
2159
2160 /// Solve the eigenproblem
2161 void Solve();
2162
2163 /// Collect the converged eigenvalues
2164 void GetEigenvalues(Array<real_t> & eigenvalues) const;
2165
2166 /// Extract a single eigenvector
2167 const HypreParVector & GetEigenvector(unsigned int i) const;
2168
2169 /// Transfer ownership of the converged eigenvectors
2170 HypreParVector ** StealEigenvectors() { return multi_vec->StealVectors(); }
2171};
2172
2173/** AME eigenvalue solver in hypre
2174
2175 The Auxiliary space Maxwell Eigensolver (AME) is designed to find
2176 the lowest eigenmodes of the generalized eigenvalue problem:
2177 Curl Curl x = lambda M x
2178 where the Curl Curl operator is discretized using Nedelec finite element
2179 basis functions. Properties of this discretization are essential to
2180 eliminating the large null space of the Curl Curl operator.
2181
2182 This eigensolver relies upon the LOBPCG eigensolver internally. It is also
2183 expected that the preconditioner supplied to this method will be the
2184 HypreAMS preconditioner defined above.
2185
2186 As with LOBPCG, the operator set in the preconditioner need not be the same
2187 as A. This flexibility may be useful in solving eigenproblems which bare a
2188 strong resemblance to the Curl Curl problems for which AME is designed.
2189
2190 Unlike LOBPCG, this eigensolver requires that the mass matrix be set.
2191 It is possible to circumvent this by passing an identity operator as the
2192 mass matrix but it seems unlikely that this would be useful so it is not the
2193 default behavior.
2194*/
2196{
2197private:
2198 int myid;
2199 int numProcs;
2200 int nev; // Number of desired eigenmodes
2201 bool setT;
2202
2203 // Pointer to HYPRE's AME solver struct
2204 HYPRE_Solver ame_solver;
2205
2206 // Pointer to HYPRE's AMS solver struct
2207 HypreSolver * ams_precond;
2208
2209 // Eigenvalues
2210 HYPRE_Real * eigenvalues;
2211
2212 // MultiVector to store eigenvectors
2213 HYPRE_ParVector * multi_vec;
2214
2215 // HypreParVector wrappers to contain eigenvectors
2216 mutable HypreParVector ** eigenvectors;
2217
2218 void createDummyVectors() const;
2219
2220public:
2221 HypreAME(MPI_Comm comm);
2222 ~HypreAME();
2223
2224 void SetTol(real_t tol);
2225 void SetRelTol(real_t rel_tol);
2226 void SetMaxIter(int max_iter);
2227 void SetPrintLevel(int logging);
2228 void SetNumModes(int num_eigs);
2229
2230 // The following four methods support operators of type HypreParMatrix.
2231 void SetPreconditioner(HypreSolver & precond);
2232 void SetOperator(const HypreParMatrix & A);
2233 void SetMassMatrix(const HypreParMatrix & M);
2234
2235 /// Solve the eigenproblem
2236 void Solve();
2237
2238 /// Collect the converged eigenvalues
2239 void GetEigenvalues(Array<real_t> & eigenvalues) const;
2240
2241 /// Extract a single eigenvector
2242 const HypreParVector & GetEigenvector(unsigned int i) const;
2243
2244 /// Transfer ownership of the converged eigenvectors
2246};
2247
2248}
2249
2250#endif // MFEM_USE_MPI
2251
2252#endif
Dynamic 2D array using row-major layout.
Definition array.hpp:430
static MemoryType GetHostMemoryType()
Get the current Host MemoryType. This is the MemoryType used by most MFEM classes when allocating mem...
Definition device.hpp:268
static MemoryClass GetHostMemoryClass()
Get the current Host MemoryClass. This is the MemoryClass used by most MFEM host Memory objects.
Definition device.hpp:272
The Auxiliary-space Divergence Solver in hypre.
Definition hypre.hpp:1968
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:6176
HypreADS(ParFiniteElementSpace *face_fespace)
Definition hypre.cpp:5885
HYPRE_PtrToParSolverFcn SetupFcn() const override
hypre's internal Setup function
Definition hypre.hpp:2025
HYPRE_PtrToParSolverFcn SolveFcn() const override
hypre's internal Solve function
Definition hypre.hpp:2027
void SetPrintLevel(int print_lvl)
Definition hypre.cpp:6218
virtual ~HypreADS()
Definition hypre.cpp:6196
void SetTol(real_t tol)
Definition hypre.cpp:6644
void SetNumModes(int num_eigs)
Definition hypre.cpp:6636
HypreAME(MPI_Comm comm)
Definition hypre.cpp:6594
void SetPreconditioner(HypreSolver &precond)
Definition hypre.cpp:6675
void SetPrintLevel(int logging)
Definition hypre.cpp:6666
void SetMassMatrix(const HypreParMatrix &M)
Definition hypre.cpp:6696
const HypreParVector & GetEigenvector(unsigned int i) const
Extract a single eigenvector.
Definition hypre.cpp:6739
void GetEigenvalues(Array< real_t > &eigenvalues) const
Collect the converged eigenvalues.
Definition hypre.cpp:6715
void SetOperator(const HypreParMatrix &A)
Definition hypre.cpp:6681
void Solve()
Solve the eigenproblem.
Definition hypre.cpp:6703
void SetMaxIter(int max_iter)
Definition hypre.cpp:6660
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
Definition hypre.cpp:6750
void SetRelTol(real_t rel_tol)
Definition hypre.cpp:6650
The Auxiliary-space Maxwell Solver in hypre.
Definition hypre.hpp:1891
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:5844
HypreAMS(ParFiniteElementSpace *edge_fespace)
Construct the AMS solver on the given edge finite element space.
Definition hypre.cpp:5482
virtual ~HypreAMS()
Definition hypre.cpp:5864
void SetPrintLevel(int print_lvl)
Definition hypre.cpp:5879
HYPRE_PtrToParSolverFcn SolveFcn() const override
hypre's internal Solve function
Definition hypre.hpp:1960
void SetSingularProblem()
Set this option when solving a curl-curl problem with zero mass term.
Definition hypre.hpp:1949
HYPRE_PtrToParSolverFcn SetupFcn() const override
hypre's internal Setup function
Definition hypre.hpp:1958
The BoomerAMG solver in hypre.
Definition hypre.hpp:1737
void SetAggressiveCoarsening(int num_levels)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1866
void GetNumIterations(int &num_iterations) const
Definition hypre.hpp:1851
void SetInterpolation(int interp_type)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1836
void SetCycleNumSweeps(int prerelax, int postrelax)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1810
HYPRE_PtrToParSolverFcn SolveFcn() const override
hypre's internal Solve function
Definition hypre.hpp:1874
void SetIsTriangular()
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1802
void SetSystemsOptions(int dim, bool order_bynodes=false)
Definition hypre.cpp:5185
void SetCoarsening(int coarsen_type)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1840
void SetElasticityOptions(ParFiniteElementSpace *fespace, bool interp_refine=true)
Definition hypre.cpp:5312
void SetPrintLevel(int print_level)
Definition hypre.hpp:1817
void SetRestriction(int restrict_type)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1798
void SetStrongThresholdR(real_t strengthR)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1790
void SetMaxLevels(int max_levels)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1824
void SetCycleType(int cycle_type)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1848
void SetAdvectiveOptions(int distance=15, const std::string &prerelax="", const std::string &postrelax="FFC")
Definition hypre.cpp:5364
void SetGMRESSwitchR(int gmres_switch)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1806
void SetFilterThresholdR(real_t filterR)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1794
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:5166
virtual ~HypreBoomerAMG()
Definition hypre.cpp:5472
void SetRelaxType(int relax_type)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1844
void SetNodal(int blocksize)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1859
void SetStrengthThresh(real_t strength)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1832
void SetTol(real_t tol)
Expert option - consult hypre documentation/team.
Definition hypre.hpp:1828
void SetMaxIter(int max_iter)
Definition hypre.hpp:1820
HYPRE_PtrToParSolverFcn SetupFcn() const override
hypre's internal Setup function
Definition hypre.hpp:1872
Jacobi preconditioner in hypre.
Definition hypre.hpp:1527
HypreDiagScale(const HypreParMatrix &A)
Definition hypre.hpp:1530
const HypreParMatrix * GetData() const
Definition hypre.hpp:1540
MFEM_DEPRECATED HypreParMatrix * GetData()
Deprecated. Use HypreDiagScale::GetData() const instead.
Definition hypre.hpp:1543
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:4679
HYPRE_PtrToParSolverFcn SolveFcn() const override
hypre's internal Solve function
Definition hypre.hpp:1537
HYPRE_PtrToParSolverFcn SetupFcn() const override
hypre's internal Setup function
Definition hypre.hpp:1535
virtual ~HypreDiagScale()
Definition hypre.hpp:1546
void SetStats(int stats)
Definition hypre.cpp:4857
virtual ~HypreEuclid()
Definition hypre.cpp:4911
HYPRE_PtrToParSolverFcn SetupFcn() const override
hypre's internal Setup function
Definition hypre.hpp:1666
void SetMemory(int mem)
Definition hypre.cpp:4862
void SetLevel(int level)
Definition hypre.cpp:4852
HYPRE_PtrToParSolverFcn SolveFcn() const override
hypre's internal Solve function
Definition hypre.hpp:1668
HypreEuclid(MPI_Comm comm)
Definition hypre.cpp:4821
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:4887
void SetRowScale(int row_scale)
Definition hypre.cpp:4872
void SetBJ(int bj)
Definition hypre.cpp:4867
Flexible GMRES solver in hypre.
Definition hypre.hpp:1450
void SetTol(real_t tol)
Definition hypre.cpp:4567
void SetMaxIter(int max_iter)
Definition hypre.cpp:4572
HYPRE_PtrToParSolverFcn SetupFcn() const override
FGMRES Setup function.
Definition hypre.hpp:1498
MFEM_DEPRECATED void SetZeroInintialIterate()
deprecated: use SetZeroInitialIterate()
Definition hypre.hpp:1476
HypreFGMRES(MPI_Comm comm)
Definition hypre.cpp:4513
virtual ~HypreFGMRES()
Definition hypre.cpp:4673
HYPRE_PtrToParSolverFcn SolveFcn() const override
FGMRES Solve function.
Definition hypre.hpp:1501
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:4545
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition hypre.cpp:4592
void SetZeroInitialIterate()
non-hypre setting
Definition hypre.hpp:1479
void SetPrintLevel(int print_lvl)
Definition hypre.cpp:4587
void Mult(const HypreParVector &b, HypreParVector &x) const override
Solve Ax=b with hypre's FGMRES.
Definition hypre.cpp:4601
void GetFinalResidualNorm(real_t &final_res_norm) const
Definition hypre.hpp:1488
void SetLogging(int logging)
Definition hypre.cpp:4582
void GetNumIterations(int &num_iterations) const
Definition hypre.hpp:1481
void SetKDim(int dim)
Definition hypre.cpp:4577
GMRES solver in hypre.
Definition hypre.hpp:1386
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:4373
HYPRE_PtrToParSolverFcn SolveFcn() const override
GMRES Solve function.
Definition hypre.hpp:1438
void GetFinalResidualNorm(real_t &final_res_norm) const
Definition hypre.hpp:1425
void SetLogging(int logging)
Definition hypre.cpp:4415
virtual ~HypreGMRES()
Definition hypre.cpp:4507
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition hypre.cpp:4425
void SetMaxIter(int max_iter)
Definition hypre.cpp:4405
void GetNumIterations(int &num_iterations) const
Definition hypre.hpp:1418
void SetTol(real_t tol)
Definition hypre.cpp:4395
void SetPrintLevel(int print_lvl)
Definition hypre.cpp:4420
void Mult(const HypreParVector &b, HypreParVector &x) const override
Solve Ax=b with hypre's GMRES.
Definition hypre.cpp:4435
HypreGMRES(MPI_Comm comm)
Definition hypre.cpp:4341
void SetAbsTol(real_t tol)
Definition hypre.cpp:4400
void SetKDim(int dim)
Definition hypre.cpp:4410
HYPRE_PtrToParSolverFcn SetupFcn() const override
GMRES Setup function.
Definition hypre.hpp:1435
void SetZeroInitialIterate()
non-hypre setting
Definition hypre.hpp:1416
MFEM_DEPRECATED void SetZeroInintialIterate()
deprecated: use SetZeroInitialIterate()
Definition hypre.hpp:1413
Wrapper for Hypre's native parallel ILU preconditioner.
Definition hypre.hpp:1690
HypreILU()
Constructor; sets the default options.
Definition hypre.cpp:4918
HYPRE_PtrToParSolverFcn SolveFcn() const override
ILU Solve function.
Definition hypre.hpp:1730
void SetType(HYPRE_Int ilu_type)
Definition hypre.cpp:4966
void SetLocalReordering(HYPRE_Int reorder_type)
Definition hypre.cpp:4981
virtual ~HypreILU()
Definition hypre.cpp:5010
void SetMaxIter(HYPRE_Int max_iter)
Definition hypre.cpp:4971
void SetLevelOfFill(HYPRE_Int lev_fill)
Set the fill level for ILU(k); the default is k=1.
Definition hypre.cpp:4961
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:4991
void SetTol(HYPRE_Real tol)
Definition hypre.cpp:4976
HYPRE_PtrToParSolverFcn SetupFcn() const override
ILU Setup function.
Definition hypre.hpp:1726
void SetPrintLevel(HYPRE_Int print_level)
Set the print level: 0 = none, 1 = setup, 2 = solve, 3 = setup+solve.
Definition hypre.cpp:4986
The identity operator as a hypre solver.
Definition hypre.hpp:1513
HYPRE_PtrToParSolverFcn SolveFcn() const override
hypre's internal Solve function
Definition hypre.hpp:1519
HYPRE_PtrToParSolverFcn SetupFcn() const override
hypre's internal Setup function
Definition hypre.hpp:1517
virtual ~HypreIdentity()
Definition hypre.hpp:1522
void SetMassMatrix(Operator &M)
Definition hypre.cpp:6417
HypreLOBPCG(MPI_Comm comm)
Definition hypre.cpp:6294
void SetPrintLevel(int logging)
Definition hypre.cpp:6346
void SetPreconditioner(Solver &precond)
Definition hypre.cpp:6361
void GetEigenvalues(Array< real_t > &eigenvalues) const
Collect the converged eigenvalues.
Definition hypre.cpp:6427
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
Definition hypre.hpp:2170
void SetTol(real_t tol)
Definition hypre.cpp:6324
void SetOperator(Operator &A)
Definition hypre.cpp:6370
void SetNumModes(int num_eigs)
Definition hypre.hpp:2149
void Solve()
Solve the eigenproblem.
Definition hypre.cpp:6484
void SetPrecondUsageMode(int pcg_mode)
Definition hypre.cpp:6355
void SetRandomSeed(int s)
Definition hypre.hpp:2151
void SetInitialVectors(int num_vecs, HypreParVector **vecs)
Definition hypre.cpp:6445
void SetSubSpaceProjector(Operator &proj)
Definition hypre.hpp:2158
void SetMaxIter(int max_iter)
Definition hypre.cpp:6340
void SetRelTol(real_t rel_tol)
Definition hypre.cpp:6330
const HypreParVector & GetEigenvector(unsigned int i) const
Extract a single eigenvector.
Definition hypre.cpp:6439
PCG solver in hypre.
Definition hypre.hpp:1321
void Mult(const HypreParVector &b, HypreParVector &x) const override
Solve Ax=b with hypre's PCG.
Definition hypre.cpp:4258
HyprePCG(MPI_Comm comm)
Definition hypre.cpp:4170
HYPRE_PtrToParSolverFcn SolveFcn() const override
PCG Solve function.
Definition hypre.hpp:1374
MFEM_DEPRECATED void SetZeroInintialIterate()
deprecated: use SetZeroInitialIterate()
Definition hypre.hpp:1349
void GetNumIterations(int &num_iterations) const
Definition hypre.hpp:1354
void SetResidualConvergenceOptions(int res_frequency=-1, real_t rtol=0.0)
Definition hypre.cpp:4245
void SetZeroInitialIterate()
non-hypre setting
Definition hypre.hpp:1352
void SetPrintLevel(int print_lvl)
Definition hypre.cpp:4230
HYPRE_PtrToParSolverFcn SetupFcn() const override
PCG Setup function.
Definition hypre.hpp:1371
void SetLogging(int logging)
Definition hypre.cpp:4225
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
Definition hypre.cpp:4235
void SetMaxIter(int max_iter)
Definition hypre.cpp:4220
void GetFinalResidualNorm(real_t &final_res_norm) const
Definition hypre.hpp:1361
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:4188
void SetAbsTol(real_t atol)
Definition hypre.cpp:4215
void SetTol(real_t tol)
Definition hypre.cpp:4210
virtual ~HyprePCG()
Definition hypre.cpp:4335
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:419
Type GetType() const
Definition hypre.hpp:988
const Memory< real_t > & GetDiagMemoryData() const
Definition hypre.hpp:960
void HypreReadWrite()
Update the internal hypre_ParCSRMatrix object, A, to be in hypre memory space.
Definition hypre.hpp:945
signed char OwnsDiag() const
Get diag ownership flag.
Definition hypre.hpp:624
void operator*=(real_t s)
Scale all entries by s: A_scaled = s*A.
Definition hypre.cpp:2229
signed char OwnsColMap() const
Get colmap ownership flag.
Definition hypre.hpp:628
virtual ~HypreParMatrix()
Calls hypre's destroy function.
Definition hypre.hpp:986
HYPRE_BigInt N() const
Returns the global number of columns.
Definition hypre.hpp:660
void ScaleRows(const Vector &s)
Scale the local row i by s(i).
Definition hypre.cpp:2144
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:2025
HYPRE_BigInt * ColPart()
Returns the column partitioning.
Definition hypre.hpp:648
void HostReadWrite()
Update the internal hypre_ParCSRMatrix object, A, to be on host.
Definition hypre.hpp:927
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:2681
void DropSmallEntries(real_t tol)
Wrapper for hypre_ParCSRMatrixDropSmallEntries in different versions of hypre. Drop off-diagonal entr...
Definition hypre.cpp:2352
const Memory< HYPRE_Int > & GetDiagMemoryI() const
Definition hypre.hpp:958
const Memory< HYPRE_Int > & GetDiagMemoryJ() const
Definition hypre.hpp:959
void PrintCommPkg(std::ostream &out=mfem::out) const
Print information about the hypre_ParCSRCommPkg of the HypreParMatrix.
Definition hypre.cpp:2715
void GetDiag(Vector &diag) const
Get the local diagonal of the matrix.
Definition hypre.cpp:1607
const HYPRE_BigInt * RowPart() const
Returns the row partitioning (const version)
Definition hypre.hpp:652
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:1999
MemoryClass GetMemoryClass() const override
Return the MemoryClass preferred by the Operator.
Definition hypre.hpp:727
void Threshold(real_t threshold=0.0)
Remove values smaller in absolute value than some threshold.
Definition hypre.cpp:2272
Memory< HYPRE_Int > & GetDiagMemoryI()
Definition hypre.hpp:954
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:2042
void EliminateRows(const Array< int > &rows)
Eliminate rows from the diagonal and off-diagonal blocks of the matrix.
Definition hypre.cpp:2438
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:2008
int GetNumCols() const
Returns the number of columns in the diagonal block of the ParCSRMatrix.
Definition hypre.hpp:703
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:1516
void InvScaleRows(const Vector &s)
Scale the local row i by 1./s(i)
Definition hypre.cpp:2183
void ResetTranspose() const
Reset (destroy) the internal transpose matrix that is created by EnsureMultTranspose() and MultTransp...
Definition hypre.cpp:1841
void WrapHypreParCSRMatrix(hypre_ParCSRMatrix *a, bool owner=true)
Converts hypre's format to HypreParMatrix.
Definition hypre.cpp:688
int GetNumRows() const
Returns the number of rows in the diagonal block of the ParCSRMatrix.
Definition hypre.hpp:696
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:779
Memory< HYPRE_Int > & GetDiagMemoryJ()
Definition hypre.hpp:955
HYPRE_BigInt * GetRowStarts() const
Return the parallel row partitioning array.
Definition hypre.hpp:720
HypreParMatrix(hypre_ParCSRMatrix *a, bool owner=true)
Converts hypre's format to HypreParMatrix.
Definition hypre.hpp:501
void HypreRead() const
Update the internal hypre_ParCSRMatrix object, A, to be in hypre memory space.
Definition hypre.hpp:938
HYPRE_BigInt NNZ() const
Returns the global number of nonzeros.
Definition hypre.hpp:640
const HYPRE_BigInt * ColPart() const
Returns the column partitioning (const version)
Definition hypre.hpp:656
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:817
HypreParMatrix & operator+=(const HypreParMatrix &B)
Definition hypre.hpp:840
HypreParMatrix()
An empty matrix to be used as a reference to an existing matrix.
Definition hypre.cpp:682
signed char OwnsOffd() const
Get offd ownership flag.
Definition hypre.hpp:626
HYPRE_BigInt GetGlobalNumRows() const
Return the global number of rows.
Definition hypre.hpp:710
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:2752
void HostWrite()
Update the internal hypre_ParCSRMatrix object, A, to be on host.
Definition hypre.hpp:932
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:793
HYPRE_BigInt GetGlobalNumCols() const
Return the global number of columns.
Definition hypre.hpp:714
void HostRead() const
Update the internal hypre_ParCSRMatrix object, A, to be on host.
Definition hypre.hpp:921
void EliminateRowsCols(const Array< int > &rows_cols, const HypreParVector &X, HypreParVector &B)
Definition hypre.cpp:2399
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:1863
void MultTranspose(const Vector &x, Vector &y) const override
Computes y = A^t * x.
Definition hypre.hpp:776
HypreParMatrix * ExtractSubmatrix(const Array< int > &indices, real_t threshold=0.0) const
Definition hypre.cpp:1751
void EnsureMultTranspose() const
Ensure the action of the transpose is performed fast.
Definition hypre.cpp:1828
void Mult(const Vector &x, Vector &y) const override
Operator application: y=A(x).
Definition hypre.hpp:769
MPI_Comm GetComm() const
MPI communicator.
Definition hypre.hpp:609
Memory< real_t > & GetDiagMemoryData()
Definition hypre.hpp:956
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:802
HYPRE_BigInt * GetColStarts() const
Return the parallel column partitioning array.
Definition hypre.hpp:725
void EliminateZeroRows()
If a row contains only zeros, set its diagonal to 1.
Definition hypre.hpp:883
void Read_IJMatrix(MPI_Comm comm, const std::string &fname)
Read a matrix saved as a HYPRE_IJMatrix.
Definition hypre.cpp:2701
HypreParMatrix & Add(const real_t beta, const HypreParMatrix &B)
Definition hypre.hpp:847
void GetBlocks(Array2D< HypreParMatrix * > &blocks, bool interleaved_rows=false, bool interleaved_cols=false) const
Definition hypre.cpp:1708
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:2451
void MakeRef(const HypreParMatrix &master)
Make this HypreParMatrix a reference to 'master'.
Definition hypre.cpp:1476
real_t FNorm() const
Return the Frobenius norm of the matrix (or 0 if the underlying hypre matrix is NULL)
Definition hypre.cpp:2818
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:781
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:807
void GetOffd(SparseMatrix &offd, HYPRE_BigInt *&cmap) const
Get the local off-diagonal block. NOTE: 'offd' will not own any data.
Definition hypre.cpp:1678
HYPRE_BigInt * RowPart()
Returns the row partitioning.
Definition hypre.hpp:644
void AssembleDiagonal(Vector &diag) const override
Return the diagonal of the matrix (Operator interface).
Definition hypre.hpp:677
void HypreWrite()
Update the internal hypre_ParCSRMatrix object, A, to be in hypre memory space.
Definition hypre.hpp:952
HYPRE_BigInt M() const
Returns the global number of rows.
Definition hypre.hpp:658
HypreParMatrix & operator=(real_t value)
Initialize all entries with value.
Definition hypre.hpp:826
hypre_ParCSRMatrix * StealData()
Changes the ownership of the matrix.
Definition hypre.cpp:1494
HypreParMatrix * Transpose() const
Returns the transpose of *this.
Definition hypre.cpp:1732
void MergeDiagAndOffd(SparseMatrix &merged)
Get a single SparseMatrix containing all rows from this processor, merged from the diagonal and off-d...
Definition hypre.cpp:1684
HypreParMatrix * EliminateCols(const Array< int > &cols)
Definition hypre.cpp:2424
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:423
void HypreRead() const
Prepare the HypreParVector for read access in hypre's device memory space, HYPRE_MEMORY_DEVICE.
Definition hypre.cpp:366
void Read(MPI_Comm comm, const std::string &fname)
Reads a HypreParVector from files saved with HypreParVector::Print.
Definition hypre.cpp:447
HypreParVector CreateCompatibleVector() const
Constructs a HypreParVector compatible with the calling vector.
Definition hypre.cpp:292
void Print(const std::string &fname) const
Prints the locally owned rows in parallel.
Definition hypre.cpp:442
hypre_ParVector * StealParVector()
Changes the ownership of the vector.
Definition hypre.hpp: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:409
~HypreParVector()
Calls hypre's destroy function.
Definition hypre.cpp:459
void WrapHypreParVector(hypre_ParVector *y, bool owner=true)
Converts hypre's format to HypreParVector.
Definition hypre.cpp:309
HYPRE_Int Randomize(HYPRE_Int seed)
Set random values.
Definition hypre.cpp:437
const HYPRE_BigInt * Partitioning() const
Returns the parallel row/column partitioning.
Definition hypre.hpp:304
void HypreReadWrite()
Prepare the HypreParVector for read and write access in hypre's device memory space,...
Definition hypre.cpp:376
MPI_Comm GetComm() const
MPI communicator.
Definition hypre.hpp: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:385
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:394
MFEM_DEPRECATED HYPRE_BigInt * Partitioning()
Returns a non-const pointer to the parallel row/column partitioning. Deprecated in favor of HypreParV...
Definition hypre.hpp:310
HypreParVector & operator=(real_t d)
Set constant values.
Definition hypre.cpp:328
void SetData(real_t *data_)
Sets the data of the Vector and the hypre_ParVector to data_.
Definition hypre.cpp:360
int GetOwnership() const
Gets ownership of the internal hypre_ParVector.
Definition hypre.hpp: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
The ParaSails preconditioner in hypre.
Definition hypre.hpp:1551
void SetReuse(int reuse)
Set the pattern reuse parameter.
Definition hypre.cpp:4805
HYPRE_PtrToParSolverFcn SetupFcn() const override
hypre's internal Setup function
Definition hypre.hpp:1621
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.cpp:4761
void SetSymmetry(int sym)
Set symmetry parameter.
Definition hypre.cpp:4795
HYPRE_PtrToParSolverFcn SolveFcn() const override
hypre's internal Solve function
Definition hypre.hpp:1623
void SetParams(real_t thresh, int nlevels)
Set the threshold and levels parameters.
Definition hypre.cpp:4785
void SetLoadBal(real_t loadbal)
Set the load balance parameter.
Definition hypre.cpp:4800
HypreParaSails(MPI_Comm comm)
Definition hypre.cpp:4697
void SetFilter(real_t filter)
Set the filter parameter.
Definition hypre.cpp:4790
void SetLogging(int logging)
Set the logging parameter.
Definition hypre.cpp:4810
virtual ~HypreParaSails()
Definition hypre.cpp:4815
Parallel smoothers in hypre.
Definition hypre.hpp:1066
int eig_est_cg_iter
Number of CG iterations to determine eigenvalue estimates.
Definition hypre.hpp:1107
int poly_order
Order of the smoothing polynomial.
Definition hypre.hpp:1091
void SetPolyOptions(int poly_order, real_t poly_fraction, int eig_est_cg_iter=10)
Set parameters for polynomial smoothing.
Definition hypre.cpp:3636
void SetOperatorSymmetry(bool is_sym)
Definition hypre.hpp:1188
void SetFIRCoefficients(real_t max_eig)
Compute window and Chebyshev coefficients for given polynomial order.
Definition hypre.cpp:3811
HypreParVector * X
Definition hypre.hpp:1071
void SetWindowParameters(real_t a, real_t b, real_t c)
Set parameters for windowing function for FIR smoother.
Definition hypre.cpp:3667
real_t poly_fraction
Fraction of spectrum to smooth for polynomial relaxation.
Definition hypre.hpp:1093
void MultTranspose(const Vector &b, Vector &x) const override
Apply transpose of the smoother to relax the linear system Ax=b.
Definition hypre.cpp:3992
HypreParVector * V
Temporary vectors.
Definition hypre.hpp:1077
HypreParMatrix * A
The linear system matrix.
Definition hypre.hpp:1069
real_t * fir_coeffs
Combined coefficients for windowing and Chebyshev polynomials.
Definition hypre.hpp:1116
int relax_times
Number of relaxation sweeps.
Definition hypre.hpp:1085
void SetWindowByName(const char *window_name)
Convenience function for setting canonical windowing parameters.
Definition hypre.cpp:3652
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Relax the linear system Ax=b.
Definition hypre.cpp:3851
real_t * l1_norms
l1 norms of the rows of A
Definition hypre.hpp:1103
void SetOperator(const Operator &op) override
Definition hypre.cpp:3674
void SetPositiveDiagonal(bool pos=true)
After computing l1-norms, replace them with their absolute values.
Definition hypre.hpp:1182
real_t max_eig_est
Maximal eigenvalue estimate for polynomial smoothing.
Definition hypre.hpp:1109
void SetTaubinOptions(real_t lambda, real_t mu, int iter)
Set parameters for Taubin's lambda-mu method.
Definition hypre.cpp:3644
bool pos_l1_norms
If set, take absolute values of the computed l1_norms.
Definition hypre.hpp:1105
real_t window_params[3]
Parameters for windowing function of FIR filter.
Definition hypre.hpp:1113
static MFEM_DEPRECATED constexpr Type default_type
Definition hypre.hpp:1140
real_t omega
SOR parameter (usually in (0,2))
Definition hypre.hpp:1089
int poly_scale
Apply the polynomial smoother to A or D^{-1/2} A D^{-1/2}.
Definition hypre.hpp:1095
HypreParVector * B
Right-hand side and solution vectors.
Definition hypre.hpp:1071
real_t relax_weight
Damping coefficient (usually <= 1)
Definition hypre.hpp:1087
HypreParVector * Z
Definition hypre.hpp:1077
real_t min_eig_est
Minimal eigenvalue estimate for polynomial smoothing.
Definition hypre.hpp:1111
void SetSOROptions(real_t relax_weight, real_t omega)
Set SOR-related parameters.
Definition hypre.cpp:3630
Memory< real_t > auxX
Definition hypre.hpp:1075
void SetType(HypreSmoother::Type type, int relax_times=1)
Set the relaxation type and number of sweeps.
Definition hypre.cpp:3624
Type
HYPRE smoother types.
Definition hypre.hpp:1124
@ lumpedJacobi
lumped Jacobi
Definition hypre.hpp:1129
@ Chebyshev
Chebyshev.
Definition hypre.hpp:1133
@ l1GS
l1-scaled block Gauss-Seidel/SSOR
Definition hypre.hpp:1127
@ FIR
FIR polynomial smoother.
Definition hypre.hpp:1135
@ GS
Gauss-Seidel.
Definition hypre.hpp:1130
@ l1GStr
truncated l1-scaled block Gauss-Seidel/SSOR
Definition hypre.hpp:1128
@ Taubin
Taubin polynomial smoother.
Definition hypre.hpp:1134
@ l1Jacobi
l1-scaled Jacobi
Definition hypre.hpp:1126
real_t lambda
Taubin's lambda-mu method parameters.
Definition hypre.hpp:1098
Memory< real_t > auxB
Auxiliary buffers for the case when the input or output arrays in methods like Mult(const Vector &,...
Definition hypre.hpp:1075
HypreParVector * X1
Definition hypre.hpp:1079
bool A_is_symmetric
A flag that indicates whether the linear system matrix A is symmetric.
Definition hypre.hpp:1119
HypreParVector * X0
FIR Filter Temporary Vectors.
Definition hypre.hpp:1079
virtual ~HypreSmoother()
Definition hypre.cpp:4002
static Type DefaultType()
Default value for the smoother type used by the constructors: Type::l1GS when HYPRE is running on CPU...
Definition hypre.hpp:1148
Abstract class for hypre's solvers and preconditioners.
Definition hypre.hpp:1208
MemoryClass GetMemoryClass() const override
Return the MemoryClass preferred by the Operator.
Definition hypre.hpp:1266
const HypreParMatrix * A
The linear system matrix.
Definition hypre.hpp:1220
int setup_called
Was hypre's Setup function called already?
Definition hypre.hpp:1228
HypreParVector * X
Definition hypre.hpp:1223
ErrorMode
How to treat errors returned by hypre function calls.
Definition hypre.hpp:1212
@ WARN_HYPRE_ERRORS
Issue warnings on hypre errors.
Definition hypre.hpp:1214
@ IGNORE_HYPRE_ERRORS
Ignore hypre errors (see e.g. HypreADS)
Definition hypre.hpp:1213
@ ABORT_HYPRE_ERRORS
Abort on hypre errors (default in base class)
Definition hypre.hpp:1215
virtual HYPRE_PtrToParSolverFcn SolveFcn() const =0
hypre's internal Solve function
HypreParVector * B
Right-hand side and solution vector.
Definition hypre.hpp:1223
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:4043
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:1287
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve the linear system Ax=b.
Definition hypre.cpp:4121
Memory< real_t > auxB
Definition hypre.hpp:1225
ErrorMode error_mode
How to treat hypre errors.
Definition hypre.hpp:1231
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
Definition hypre.hpp:1263
virtual ~HypreSolver()
Definition hypre.cpp:4161
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:4094
virtual HYPRE_PtrToParSolverFcn SetupFcn() const =0
hypre's internal Setup function
Memory< real_t > auxX
Definition hypre.hpp:1225
virtual ~HypreTriSolve()
Definition hypre.hpp:1315
const HypreParMatrix * GetData() const
Definition hypre.hpp:1309
HYPRE_PtrToParSolverFcn SolveFcn() const override
hypre's internal Solve function
Definition hypre.hpp:1306
MFEM_DEPRECATED HypreParMatrix * GetData()
Deprecated. Use HypreTriSolve::GetData() const instead.
Definition hypre.hpp:1312
HypreTriSolve(const HypreParMatrix &A)
Definition hypre.hpp:1301
HYPRE_PtrToParSolverFcn SetupFcn() const override
hypre's internal Setup function
Definition hypre.hpp:1304
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:25
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
Definition operator.hpp:48
Type
Enumeration defining IDs for some classes derived from Operator.
Definition operator.hpp:296
@ Hypre_ParCSR
ID for class HypreParMatrix.
Definition operator.hpp:299
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:100
Abstract parallel finite element space.
Definition pfespace.hpp:31
Base class for solvers.
Definition operator.hpp:792
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
Definition operator.hpp:795
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
const real_t alpha
Definition ex15.cpp:369
int dim
Definition ex24.cpp:53
real_t proj(GridFunction &psi, real_t target_volume, real_t tol=1e-12, int max_its=10)
Bregman projection of ρ = sigmoid(ψ) onto the subspace ∫_Ω ρ dx = θ vol(Ω) as follows:
Definition ex37.cpp:72
HYPRE_Int HYPRE_BigInt
real_t b
Definition lissajous.cpp:42
real_t a
Definition lissajous.cpp:41
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:348
real_t ParNormlp(const Vector &vec, real_t p, MPI_Comm comm)
Compute the l_p norm of the Vector which is split without overlap across the given communicator.
Definition hypre.cpp:479
void mfem_error(const char *msg)
Definition error.cpp:154
T * Write(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for write access to mem with the mfem::Device's DeviceMemoryClass, if on_dev = true,...
Definition device.hpp:365
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition globals.hpp:66
HypreParMatrix * DiscreteGrad(ParFiniteElementSpace *edge_fespace, ParFiniteElementSpace *vert_fespace)
Compute the discrete gradient matrix between the nodal linear and ND1 spaces.
real_t InnerProduct(HypreParVector *x, HypreParVector *y)
Definition hypre.cpp:468
MemoryClass
Memory classes identify sets of memory types.
@ MANAGED
Memory types: { MANAGED }.
MemoryClass GetHypreMemoryClass()
The MemoryClass used by Hypre objects.
Definition hypre.hpp: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:382
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:3201
HypreParMatrix * ParAdd(const HypreParMatrix *A, const HypreParMatrix *B)
Returns the matrix A + B.
Definition hypre.cpp:2981
BlockInverseScaleJob
Definition hypre.hpp:1006
void HypreStealOwnership(HypreParMatrix &A_hyp, SparseMatrix &A_diag)
Make A_hyp steal ownership of its diagonal part A_diag.
Definition hypre.cpp:2912
HypreParMatrix * ParMult(const HypreParMatrix *A, const HypreParMatrix *B, bool own_matrix)
Definition hypre.cpp:3021
int to_int(const std::string &str)
Convert a string to an int.
Definition text.hpp:62
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:2934
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:3453
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