12 #include "../config/config.hpp"
17 #include "../fem/fem.hpp"
30 template<
typename TargetT,
typename SourceT>
31 static TargetT *DuplicateAs(
const SourceT *array,
int size,
32 bool cplusplus =
true)
34 TargetT *target_array = cplusplus ?
new TargetT[size]
35 : hypre_TAlloc(TargetT, size);
36 for (
int i = 0; i < size; i++)
38 target_array[i] = array[i];
43 inline void HypreParVector::_SetDataAndSize_()
45 SetDataAndSize(hypre_VectorData(hypre_ParVectorLocalVector(x)),
47 hypre_VectorSize(hypre_ParVectorLocalVector(x))));
50 HypreParVector::HypreParVector(MPI_Comm comm, HYPRE_Int glob_size,
53 x = hypre_ParVectorCreate(comm,glob_size,col);
54 hypre_ParVectorInitialize(x);
55 hypre_ParVectorSetPartitioningOwner(x,0);
57 hypre_ParVectorSetDataOwner(x,1);
58 hypre_SeqVectorSetDataOwner(hypre_ParVectorLocalVector(x),1);
64 double *_data, HYPRE_Int *col) :
Vector()
66 x = hypre_ParVectorCreate(comm,glob_size,col);
67 hypre_ParVectorSetDataOwner(x,1);
68 hypre_SeqVectorSetDataOwner(hypre_ParVectorLocalVector(x),0);
69 hypre_ParVectorSetPartitioningOwner(x,0);
70 hypre_VectorData(hypre_ParVectorLocalVector(x)) = _data;
73 hypre_ParVectorInitialize(x);
80 x = hypre_ParVectorCreate(y.x -> comm, y.x -> global_size,
82 hypre_ParVectorInitialize(x);
83 hypre_ParVectorSetPartitioningOwner(x,0);
84 hypre_ParVectorSetDataOwner(x,1);
85 hypre_SeqVectorSetDataOwner(hypre_ParVectorLocalVector(x),1);
94 x = hypre_ParVectorInDomainOf(A);
98 x = hypre_ParVectorInRangeOf(A);
106 x = (hypre_ParVector *) y;
115 hypre_ParVectorInitialize(x);
116 hypre_ParVectorSetPartitioningOwner(x,0);
118 hypre_ParVectorSetDataOwner(x,1);
119 hypre_SeqVectorSetDataOwner(hypre_ParVectorLocalVector(x),1);
124 HypreParVector::operator hypre_ParVector*()
const
129 #ifndef HYPRE_PAR_VECTOR_STRUCT
130 HypreParVector::operator HYPRE_ParVector()
const
132 return (HYPRE_ParVector) x;
138 hypre_Vector *hv = hypre_ParVectorToVectorAll(*
this);
139 Vector *v =
new Vector(hv->data, internal::to_int(hv->size));
141 hypre_SeqVectorSetDataOwner(hv,0);
142 hypre_SeqVectorDestroy(hv);
148 hypre_ParVectorSetConstantValues(x,d);
155 if (size != y.
Size())
161 for (
int i = 0; i <
size; i++)
170 Vector::data = hypre_VectorData(hypre_ParVectorLocalVector(x)) = _data;
175 return hypre_ParVectorSetRandomValues(x,seed);
180 hypre_ParVectorPrint(x,fname);
187 hypre_ParVectorDestroy(x);
194 return hypre_ParVectorInnerProd(*x, *y);
199 return hypre_ParVectorInnerProd(x, y);
203 void HypreParMatrix::Init()
207 diagOwner = offdOwner = colMapOwner = -1;
217 char HypreParMatrix::CopyCSR(
SparseMatrix *csr, hypre_CSRMatrix *hypre_csr)
219 hypre_CSRMatrixData(hypre_csr) = csr->
GetData();
221 hypre_CSRMatrixI(hypre_csr) = csr->
GetI();
222 hypre_CSRMatrixJ(hypre_csr) = csr->
GetJ();
226 hypre_CSRMatrixI(hypre_csr) =
227 DuplicateAs<HYPRE_Int>(csr->
GetI(), csr->
Height()+1);
228 hypre_CSRMatrixJ(hypre_csr) =
235 char HypreParMatrix::CopyBoolCSR(Table *bool_csr, hypre_CSRMatrix *hypre_csr)
237 int nnz = bool_csr->Size_of_connections();
238 double *data =
new double[nnz];
239 for (
int i = 0; i < nnz; i++)
243 hypre_CSRMatrixData(hypre_csr) = data;
245 hypre_CSRMatrixI(hypre_csr) = bool_csr->GetI();
246 hypre_CSRMatrixJ(hypre_csr) = bool_csr->GetJ();
250 hypre_CSRMatrixI(hypre_csr) =
251 DuplicateAs<HYPRE_Int>(bool_csr->GetI(), bool_csr->Size()+1);
252 hypre_CSRMatrixJ(hypre_csr) =
253 DuplicateAs<HYPRE_Int>(bool_csr->GetJ(), nnz);
259 void HypreParMatrix::CopyCSR_J(hypre_CSRMatrix *hypre_csr,
int *J)
261 HYPRE_Int nnz = hypre_CSRMatrixNumNonzeros(hypre_csr);
262 for (HYPRE_Int j = 0; j < nnz; j++)
264 J[j] = int(hypre_CSRMatrixJ(hypre_csr)[j]);
271 :
Operator(diag->Height(), diag->Width())
274 A = hypre_ParCSRMatrixCreate(comm, glob_size, glob_size, row_starts,
276 hypre_ParCSRMatrixSetDataOwner(A,1);
277 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
278 hypre_ParCSRMatrixSetColStartsOwner(A,0);
280 hypre_CSRMatrixSetDataOwner(A->diag,0);
281 diagOwner = CopyCSR(diag, A->diag);
282 hypre_CSRMatrixSetRownnz(A->diag);
284 hypre_CSRMatrixSetDataOwner(A->offd,1);
285 hypre_CSRMatrixI(A->offd) = hypre_CTAlloc(HYPRE_Int, diag->
Height()+1);
292 hypre_ParCSRMatrixSetNumNonzeros(A);
295 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
297 CopyCSR_J(A->diag, diag->
GetJ());
300 hypre_MatvecCommPkgCreate(A);
305 HYPRE_Int global_num_rows,
306 HYPRE_Int global_num_cols,
307 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
309 :
Operator(diag->Height(), diag->Width())
312 A = hypre_ParCSRMatrixCreate(comm, global_num_rows, global_num_cols,
313 row_starts, col_starts,
315 hypre_ParCSRMatrixSetDataOwner(A,1);
316 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
317 hypre_ParCSRMatrixSetColStartsOwner(A,0);
319 hypre_CSRMatrixSetDataOwner(A->diag,0);
320 diagOwner = CopyCSR(diag, A->diag);
321 hypre_CSRMatrixSetRownnz(A->diag);
323 hypre_CSRMatrixSetDataOwner(A->offd,1);
324 hypre_CSRMatrixI(A->offd) = hypre_CTAlloc(HYPRE_Int, diag->
Height()+1);
326 hypre_ParCSRMatrixSetNumNonzeros(A);
329 if (row_starts == col_starts)
331 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
333 CopyCSR_J(A->diag, diag->
GetJ());
337 hypre_MatvecCommPkgCreate(A);
342 HYPRE_Int global_num_rows,
343 HYPRE_Int global_num_cols,
344 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
347 :
Operator(diag->Height(), diag->Width())
350 A = hypre_ParCSRMatrixCreate(comm, global_num_rows, global_num_cols,
351 row_starts, col_starts,
354 hypre_ParCSRMatrixSetDataOwner(A,1);
355 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
356 hypre_ParCSRMatrixSetColStartsOwner(A,0);
358 hypre_CSRMatrixSetDataOwner(A->diag,0);
359 diagOwner = CopyCSR(diag, A->diag);
360 hypre_CSRMatrixSetRownnz(A->diag);
362 hypre_CSRMatrixSetDataOwner(A->offd,0);
363 offdOwner = CopyCSR(offd, A->offd);
364 hypre_CSRMatrixSetRownnz(A->offd);
366 hypre_ParCSRMatrixColMapOffd(A) = cmap;
370 hypre_ParCSRMatrixSetNumNonzeros(A);
373 if (row_starts == col_starts)
375 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
377 CopyCSR_J(A->diag, diag->
GetJ());
381 hypre_MatvecCommPkgCreate(A);
387 HYPRE_Int global_num_rows, HYPRE_Int global_num_cols,
388 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
389 HYPRE_Int *diag_i, HYPRE_Int *diag_j,
double *diag_data,
390 HYPRE_Int *offd_i, HYPRE_Int *offd_j,
double *offd_data,
391 HYPRE_Int offd_num_cols, HYPRE_Int *offd_col_map)
394 A = hypre_ParCSRMatrixCreate(comm, global_num_rows, global_num_cols,
395 row_starts, col_starts, offd_num_cols, 0, 0);
396 hypre_ParCSRMatrixSetDataOwner(A,1);
397 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
398 hypre_ParCSRMatrixSetColStartsOwner(A,0);
400 HYPRE_Int local_num_rows = hypre_CSRMatrixNumRows(A->diag);
402 hypre_CSRMatrixSetDataOwner(A->diag,0);
403 hypre_CSRMatrixI(A->diag) = diag_i;
404 hypre_CSRMatrixJ(A->diag) = diag_j;
405 hypre_CSRMatrixData(A->diag) = diag_data;
406 hypre_CSRMatrixNumNonzeros(A->diag) = diag_i[local_num_rows];
407 hypre_CSRMatrixSetRownnz(A->diag);
411 hypre_CSRMatrixSetDataOwner(A->offd,0);
412 hypre_CSRMatrixI(A->offd) = offd_i;
413 hypre_CSRMatrixJ(A->offd) = offd_j;
414 hypre_CSRMatrixData(A->offd) = offd_data;
415 hypre_CSRMatrixNumNonzeros(A->offd) = offd_i[local_num_rows];
416 hypre_CSRMatrixSetRownnz(A->offd);
420 hypre_ParCSRMatrixColMapOffd(A) = offd_col_map;
424 hypre_ParCSRMatrixSetNumNonzeros(A);
427 if (row_starts == col_starts)
429 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
432 hypre_MatvecCommPkgCreate(A);
440 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
443 MFEM_ASSERT(sm_a != NULL,
"invalid input");
444 MFEM_VERIFY(!HYPRE_AssumedPartitionCheck(),
445 "this method can not be used with assumed partition");
449 hypre_CSRMatrix *csr_a;
450 csr_a = hypre_CSRMatrixCreate(sm_a ->
Height(), sm_a ->
Width(),
451 sm_a -> NumNonZeroElems());
453 hypre_CSRMatrixSetDataOwner(csr_a,0);
454 CopyCSR(sm_a, csr_a);
455 hypre_CSRMatrixSetRownnz(csr_a);
457 A = hypre_CSRMatrixToParCSRMatrix(comm, csr_a, row_starts, col_starts);
460 delete [] hypre_CSRMatrixI(csr_a);
461 delete [] hypre_CSRMatrixJ(csr_a);
463 hypre_CSRMatrixI(csr_a) = NULL;
464 hypre_CSRMatrixDestroy(csr_a);
470 if (row_starts == col_starts)
472 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
475 hypre_MatvecCommPkgCreate(A);
480 HYPRE_Int global_num_rows,
481 HYPRE_Int global_num_cols,
482 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
487 A = hypre_ParCSRMatrixCreate(comm, global_num_rows, global_num_cols,
488 row_starts, col_starts, 0, nnz, 0);
489 hypre_ParCSRMatrixSetDataOwner(A,1);
490 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
491 hypre_ParCSRMatrixSetColStartsOwner(A,0);
493 hypre_CSRMatrixSetDataOwner(A->diag,0);
494 diagOwner = CopyBoolCSR(diag, A->diag);
495 hypre_CSRMatrixSetRownnz(A->diag);
497 hypre_CSRMatrixSetDataOwner(A->offd,1);
498 hypre_CSRMatrixI(A->offd) = hypre_CTAlloc(HYPRE_Int, diag->
Size()+1);
500 hypre_ParCSRMatrixSetNumNonzeros(A);
503 if (row_starts == col_starts)
505 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
507 CopyCSR_J(A->diag, diag->
GetJ());
511 hypre_MatvecCommPkgCreate(A);
519 HYPRE_Int *row, HYPRE_Int *col,
520 HYPRE_Int *i_diag, HYPRE_Int *j_diag,
521 HYPRE_Int *i_offd, HYPRE_Int *j_offd,
522 HYPRE_Int *cmap, HYPRE_Int cmap_size)
524 HYPRE_Int diag_nnz, offd_nnz;
527 if (HYPRE_AssumedPartitionCheck())
529 diag_nnz = i_diag[row[1]-row[0]];
530 offd_nnz = i_offd[row[1]-row[0]];
532 A = hypre_ParCSRMatrixCreate(comm, row[2], col[2], row, col,
533 cmap_size, diag_nnz, offd_nnz);
537 diag_nnz = i_diag[row[
id+1]-row[id]];
538 offd_nnz = i_offd[row[
id+1]-row[id]];
540 A = hypre_ParCSRMatrixCreate(comm, row[np], col[np], row, col,
541 cmap_size, diag_nnz, offd_nnz);
544 hypre_ParCSRMatrixSetDataOwner(A,1);
545 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
546 hypre_ParCSRMatrixSetColStartsOwner(A,0);
550 double *a_diag =
new double[diag_nnz];
551 for (i = 0; i < diag_nnz; i++)
556 double *a_offd =
new double[offd_nnz];
557 for (i = 0; i < offd_nnz; i++)
562 hypre_CSRMatrixSetDataOwner(A->diag,0);
563 hypre_CSRMatrixI(A->diag) = i_diag;
564 hypre_CSRMatrixJ(A->diag) = j_diag;
565 hypre_CSRMatrixData(A->diag) = a_diag;
566 hypre_CSRMatrixSetRownnz(A->diag);
570 hypre_CSRMatrixSetDataOwner(A->offd,0);
571 hypre_CSRMatrixI(A->offd) = i_offd;
572 hypre_CSRMatrixJ(A->offd) = j_offd;
573 hypre_CSRMatrixData(A->offd) = a_offd;
574 hypre_CSRMatrixSetRownnz(A->offd);
578 hypre_ParCSRMatrixColMapOffd(A) = cmap;
582 hypre_ParCSRMatrixSetNumNonzeros(A);
587 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
590 hypre_MatvecCommPkgCreate(A);
599 HYPRE_Int glob_ncols,
int *I, HYPRE_Int *J,
600 double *data, HYPRE_Int *rows, HYPRE_Int *cols)
606 HYPRE_Int my_col_start, my_col_end;
607 if (HYPRE_AssumedPartitionCheck())
610 my_col_start = cols[0];
611 my_col_end = cols[1];
616 MPI_Comm_rank(comm, &myid);
617 MPI_Comm_size(comm, &part_size);
619 my_col_start = cols[myid];
620 my_col_end = cols[myid+1];
624 HYPRE_Int *row_starts, *col_starts;
627 row_starts = col_starts = hypre_TAlloc(HYPRE_Int, part_size);
628 for (
int i = 0; i < part_size; i++)
630 row_starts[i] = rows[i];
635 row_starts = hypre_TAlloc(HYPRE_Int, part_size);
636 col_starts = hypre_TAlloc(HYPRE_Int, part_size);
637 for (
int i = 0; i < part_size; i++)
639 row_starts[i] = rows[i];
640 col_starts[i] = cols[i];
646 HYPRE_Int diag_nnz = 0, offd_nnz = 0, offd_num_cols = 0;
647 map<HYPRE_Int, HYPRE_Int> offd_map;
648 for (HYPRE_Int j = 0, loc_nnz = I[nrows]; j < loc_nnz; j++)
650 HYPRE_Int glob_col = J[j];
651 if (my_col_start <= glob_col && glob_col < my_col_end)
657 offd_map.insert(pair<const HYPRE_Int, HYPRE_Int>(glob_col, -1));
662 for (map<HYPRE_Int, HYPRE_Int>::iterator it = offd_map.begin();
663 it != offd_map.end(); ++it)
665 it->second = offd_num_cols++;
669 A = hypre_ParCSRMatrixCreate(comm, glob_nrows, glob_ncols,
670 row_starts, col_starts, offd_num_cols,
672 hypre_ParCSRMatrixInitialize(A);
674 HYPRE_Int *diag_i, *diag_j, *offd_i, *offd_j, *offd_col_map;
675 double *diag_data, *offd_data;
678 diag_data = A->diag->data;
681 offd_data = A->offd->data;
682 offd_col_map = A->col_map_offd;
684 diag_nnz = offd_nnz = 0;
685 for (HYPRE_Int i = 0, j = 0; i < nrows; i++)
687 diag_i[i] = diag_nnz;
688 offd_i[i] = offd_nnz;
689 for (HYPRE_Int j_end = I[i+1]; j < j_end; j++)
691 HYPRE_Int glob_col = J[j];
692 if (my_col_start <= glob_col && glob_col < my_col_end)
694 diag_j[diag_nnz] = glob_col - my_col_start;
695 diag_data[diag_nnz] = data[j];
700 offd_j[offd_nnz] = offd_map[glob_col];
701 offd_data[offd_nnz] = data[j];
706 diag_i[nrows] = diag_nnz;
707 offd_i[nrows] = offd_nnz;
708 for (map<HYPRE_Int, HYPRE_Int>::iterator it = offd_map.begin();
709 it != offd_map.end(); ++it)
711 offd_col_map[it->second] = it->first;
714 hypre_ParCSRMatrixSetNumNonzeros(A);
716 if (row_starts == col_starts)
718 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
720 hypre_MatvecCommPkgCreate(A);
741 MFEM_ASSERT(diagOwner == -1 && offdOwner == -1 && colMapOwner == -1,
"");
742 MFEM_ASSERT(ParCSROwner,
"");
743 hypre_ParCSRMatrix *R = A;
752 if (!A || hypre_ParCSRMatrixOwnsRowStarts(A) ||
753 (hypre_ParCSRMatrixRowStarts(A) == hypre_ParCSRMatrixColStarts(A) &&
754 hypre_ParCSRMatrixOwnsColStarts(A)))
760 if (HYPRE_AssumedPartitionCheck())
766 MPI_Comm_size(hypre_ParCSRMatrixComm(A), &row_starts_size);
770 HYPRE_Int *old_row_starts = hypre_ParCSRMatrixRowStarts(A);
771 HYPRE_Int *new_row_starts = hypre_CTAlloc(HYPRE_Int, row_starts_size);
772 for (
int i = 0; i < row_starts_size; i++)
774 new_row_starts[i] = old_row_starts[i];
777 hypre_ParCSRMatrixRowStarts(A) = new_row_starts;
778 hypre_ParCSRMatrixOwnsRowStarts(A) = 1;
780 if (hypre_ParCSRMatrixColStarts(A) == old_row_starts)
782 hypre_ParCSRMatrixColStarts(A) = new_row_starts;
783 hypre_ParCSRMatrixOwnsColStarts(A) = 0;
789 if (!A || hypre_ParCSRMatrixOwnsColStarts(A) ||
790 (hypre_ParCSRMatrixRowStarts(A) == hypre_ParCSRMatrixColStarts(A) &&
791 hypre_ParCSRMatrixOwnsRowStarts(A)))
797 if (HYPRE_AssumedPartitionCheck())
803 MPI_Comm_size(hypre_ParCSRMatrixComm(A), &col_starts_size);
807 HYPRE_Int *old_col_starts = hypre_ParCSRMatrixColStarts(A);
808 HYPRE_Int *new_col_starts = hypre_CTAlloc(HYPRE_Int, col_starts_size);
809 for (
int i = 0; i < col_starts_size; i++)
811 new_col_starts[i] = old_col_starts[i];
814 hypre_ParCSRMatrixColStarts(A) = new_col_starts;
816 if (hypre_ParCSRMatrixRowStarts(A) == old_col_starts)
818 hypre_ParCSRMatrixRowStarts(A) = new_col_starts;
819 hypre_ParCSRMatrixOwnsRowStarts(A) = 1;
820 hypre_ParCSRMatrixOwnsColStarts(A) = 0;
824 hypre_ParCSRMatrixOwnsColStarts(A) = 1;
832 for (
int j = 0; j < size; j++)
834 diag(j) = A->diag->data[A->diag->i[j]];
835 MFEM_ASSERT(A->diag->j[A->diag->i[j]] == j,
836 "the first entry in each row must be the diagonal one");
840 static void MakeWrapper(
const hypre_CSRMatrix *mat,
SparseMatrix &wrapper)
842 HYPRE_Int nr = hypre_CSRMatrixNumRows(mat);
843 HYPRE_Int nc = hypre_CSRMatrixNumCols(mat);
846 hypre_CSRMatrixJ(mat),
847 hypre_CSRMatrixData(mat),
848 nr, nc,
false,
false,
false);
850 HYPRE_Int nnz = hypre_CSRMatrixNumNonzeros(mat);
851 SparseMatrix tmp(DuplicateAs<int>(hypre_CSRMatrixI(mat), nr+1),
852 DuplicateAs<int>(hypre_CSRMatrixJ(mat), nnz),
853 hypre_CSRMatrixData(mat),
854 nr, nc,
true,
false,
false);
861 MakeWrapper(A->diag, diag);
866 MakeWrapper(A->offd, offd);
867 cmap = A->col_map_offd;
871 bool interleaved_rows,
872 bool interleaved_cols)
const
877 hypre_ParCSRMatrix **hypre_blocks =
new hypre_ParCSRMatrix*[nr * nc];
878 internal::hypre_ParCSRMatrixSplit(A, nr, nc, hypre_blocks,
879 interleaved_rows, interleaved_cols);
881 for (
int i = 0; i < nr; i++)
883 for (
int j = 0; j < nc; j++)
889 delete [] hypre_blocks;
894 hypre_ParCSRMatrix * At;
895 hypre_ParCSRMatrixTranspose(A, &At, 1);
896 hypre_ParCSRMatrixSetNumNonzeros(At);
898 hypre_MatvecCommPkgCreate(At);
906 return hypre_ParCSRMatrixMatvec(a, A, x, b, y);
928 hypre_ParCSRMatrixMatvec(a, A, *X, b, *Y);
932 double b,
Vector &y)
const
953 hypre_ParCSRMatrixMatvecT(a, A, *Y, b, *X);
959 return hypre_ParCSRMatrixMatvec(a, A, (hypre_ParVector *) x, b,
960 (hypre_ParVector *) y);
966 return hypre_ParCSRMatrixMatvecT(a, A, x, b, y);
970 HYPRE_Int* row_starts)
const
972 const bool assumed_partition = HYPRE_AssumedPartitionCheck();
973 const bool same_rows = (D.
Height() == hypre_CSRMatrixNumRows(A->diag));
976 if (assumed_partition)
982 MPI_Comm_size(
GetComm(), &part_size);
986 HYPRE_Int global_num_rows;
989 row_starts = hypre_ParCSRMatrixRowStarts(A);
990 global_num_rows = hypre_ParCSRMatrixGlobalNumRows(A);
994 MFEM_VERIFY(row_starts != NULL,
"the number of rows in D and A is not "
995 "the same; row_starts must be given (not NULL)");
1000 assumed_partition ? row_starts[2] : row_starts[part_size-1];
1003 HYPRE_Int *col_starts = hypre_ParCSRMatrixColStarts(A);
1004 HYPRE_Int *col_map_offd;
1009 GetOffd(A_offd, col_map_offd);
1017 global_num_rows, hypre_ParCSRMatrixGlobalNumCols(A),
1018 DuplicateAs<HYPRE_Int>(row_starts, part_size,
false),
1019 DuplicateAs<HYPRE_Int>(col_starts, part_size,
false),
1021 DuplicateAs<HYPRE_Int>(col_map_offd, A_offd.
Width()));
1026 #ifndef HYPRE_BIGINT
1037 hypre_ParCSRMatrixSetRowStartsOwner(DA->A, 1);
1038 hypre_ParCSRMatrixSetColStartsOwner(DA->A, 1);
1040 DA->diagOwner = DA->offdOwner = 3;
1041 DA->colMapOwner = 1;
1048 if (hypre_CSRMatrixNumRows(A->diag) != hypre_CSRMatrixNumRows(A->offd))
1053 if (hypre_CSRMatrixNumRows(A->diag) != diag.
Size())
1055 mfem_error(
"Note the Vector diag is not of compatible dimensions with A\n");
1059 double *Adiag_data = hypre_CSRMatrixData(A->diag);
1060 HYPRE_Int *Adiag_i = hypre_CSRMatrixI(A->diag);
1063 double *Aoffd_data = hypre_CSRMatrixData(A->offd);
1064 HYPRE_Int *Aoffd_i = hypre_CSRMatrixI(A->offd);
1067 for (
int i(0); i < size; ++i)
1070 for (jj = Adiag_i[i]; jj < Adiag_i[i+1]; ++jj)
1072 Adiag_data[jj] *= val;
1074 for (jj = Aoffd_i[i]; jj < Aoffd_i[i+1]; ++jj)
1076 Aoffd_data[jj] *= val;
1083 if (hypre_CSRMatrixNumRows(A->diag) != hypre_CSRMatrixNumRows(A->offd))
1088 if (hypre_CSRMatrixNumRows(A->diag) != diag.
Size())
1090 mfem_error(
"Note the Vector diag is not of compatible dimensions with A\n");
1094 double *Adiag_data = hypre_CSRMatrixData(A->diag);
1095 HYPRE_Int *Adiag_i = hypre_CSRMatrixI(A->diag);
1098 double *Aoffd_data = hypre_CSRMatrixData(A->offd);
1099 HYPRE_Int *Aoffd_i = hypre_CSRMatrixI(A->offd);
1102 for (
int i(0); i < size; ++i)
1107 mfem_error(
"HypreParMatrix::InvDiagScale : Division by 0");
1111 for (jj = Adiag_i[i]; jj < Adiag_i[i+1]; ++jj)
1113 Adiag_data[jj] *= val;
1115 for (jj = Aoffd_i[i]; jj < Aoffd_i[i+1]; ++jj)
1117 Aoffd_data[jj] *= val;
1124 if (hypre_CSRMatrixNumRows(A->diag) != hypre_CSRMatrixNumRows(A->offd))
1129 HYPRE_Int size=hypre_CSRMatrixNumRows(A->diag);
1132 double *Adiag_data = hypre_CSRMatrixData(A->diag);
1133 HYPRE_Int *Adiag_i = hypre_CSRMatrixI(A->diag);
1134 for (jj = 0; jj < Adiag_i[size]; ++jj)
1136 Adiag_data[jj] *= s;
1139 double *Aoffd_data = hypre_CSRMatrixData(A->offd);
1140 HYPRE_Int *Aoffd_i = hypre_CSRMatrixI(A->offd);
1141 for (jj = 0; jj < Aoffd_i[size]; ++jj)
1143 Aoffd_data[jj] *= s;
1147 static void get_sorted_rows_cols(
const Array<int> &rows_cols,
1152 for (
int i = 0; i < rows_cols.
Size(); i++)
1154 hypre_sorted[i] = rows_cols[i];
1155 if (i && rows_cols[i-1] > rows_cols[i]) { sorted =
false; }
1157 if (!sorted) { hypre_sorted.
Sort(); }
1166 hypre_CSRMatrix * csr_A;
1167 hypre_CSRMatrix * csr_A_wo_z;
1168 hypre_ParCSRMatrix * parcsr_A_ptr;
1169 int * row_starts = NULL;
int * col_starts = NULL;
1170 int row_start = -1;
int row_end = -1;
1171 int col_start = -1;
int col_end = -1;
1173 comm = hypre_ParCSRMatrixComm(A);
1175 MPI_Comm_size(comm, &num_procs);
1177 ierr += hypre_ParCSRMatrixGetLocalRange(A,
1178 &row_start,&row_end,
1179 &col_start,&col_end );
1181 row_starts = hypre_ParCSRMatrixRowStarts(A);
1182 col_starts = hypre_ParCSRMatrixColStarts(A);
1184 parcsr_A_ptr = hypre_ParCSRMatrixCreate(comm,row_starts[num_procs],
1185 col_starts[num_procs],row_starts,
1188 csr_A = hypre_MergeDiagAndOffd(A);
1190 csr_A_wo_z = hypre_CSRMatrixDeleteZeros(csr_A,threshold);
1194 if (csr_A_wo_z == NULL)
1200 ierr += hypre_CSRMatrixDestroy(csr_A);
1203 ierr += GenerateDiagAndOffd(csr_A_wo_z,parcsr_A_ptr,
1206 ierr += hypre_CSRMatrixDestroy(csr_A_wo_z);
1208 ierr += hypre_ParCSRMatrixDestroy(A);
1218 get_sorted_rows_cols(rows_cols, rc_sorted);
1220 internal::hypre_ParCSRMatrixEliminateAXB(
1227 get_sorted_rows_cols(rows_cols, rc_sorted);
1229 hypre_ParCSRMatrix* Ae;
1230 internal::hypre_ParCSRMatrixEliminateAAe(
1238 hypre_ParCSRMatrixPrintIJ(A,offi,offj,fname);
1246 HYPRE_Int base_i, base_j;
1247 hypre_ParCSRMatrixReadIJ(comm, fname, &base_i, &base_j, &A);
1248 hypre_ParCSRMatrixSetNumNonzeros(A);
1250 hypre_MatvecCommPkgCreate(A);
1256 void HypreParMatrix::Destroy()
1258 if ( X != NULL ) {
delete X; }
1259 if ( Y != NULL ) {
delete Y; }
1261 if (A == NULL) {
return; }
1267 delete [] hypre_CSRMatrixI(A->diag);
1268 delete [] hypre_CSRMatrixJ(A->diag);
1270 hypre_CSRMatrixI(A->diag) = NULL;
1271 hypre_CSRMatrixJ(A->diag) = NULL;
1274 delete [] hypre_CSRMatrixData(A->diag);
1276 hypre_CSRMatrixData(A->diag) = NULL;
1282 delete [] hypre_CSRMatrixI(A->offd);
1283 delete [] hypre_CSRMatrixJ(A->offd);
1285 hypre_CSRMatrixI(A->offd) = NULL;
1286 hypre_CSRMatrixJ(A->offd) = NULL;
1289 delete [] hypre_CSRMatrixData(A->offd);
1291 hypre_CSRMatrixData(A->offd) = NULL;
1293 if (colMapOwner >= 0)
1295 if (colMapOwner & 1)
1297 delete [] hypre_ParCSRMatrixColMapOffd(A);
1299 hypre_ParCSRMatrixColMapOffd(A) = NULL;
1304 hypre_ParCSRMatrixDestroy(A);
1310 hypre_ParCSRMatrix * ab;
1311 ab = hypre_ParMatmul(*A,*B);
1313 hypre_MatvecCommPkgCreate(ab);
1320 HYPRE_Int P_owns_its_col_starts =
1321 hypre_ParCSRMatrixOwnsColStarts((hypre_ParCSRMatrix*)(*P));
1323 hypre_ParCSRMatrix * rap;
1324 hypre_BoomerAMGBuildCoarseOperator(*P,*A,*P,&rap);
1325 hypre_ParCSRMatrixSetNumNonzeros(rap);
1330 hypre_ParCSRMatrixSetRowStartsOwner(rap,0);
1331 hypre_ParCSRMatrixSetColStartsOwner(rap,0);
1333 if (P_owns_its_col_starts)
1335 hypre_ParCSRMatrixSetColStartsOwner(*P, 1);
1343 HYPRE_Int P_owns_its_col_starts =
1344 hypre_ParCSRMatrixOwnsColStarts((hypre_ParCSRMatrix*)(*P));
1345 HYPRE_Int Rt_owns_its_col_starts =
1346 hypre_ParCSRMatrixOwnsColStarts((hypre_ParCSRMatrix*)(*Rt));
1348 hypre_ParCSRMatrix * rap;
1349 hypre_BoomerAMGBuildCoarseOperator(*Rt,*A,*P,&rap);
1351 hypre_ParCSRMatrixSetNumNonzeros(rap);
1353 if (!P_owns_its_col_starts)
1357 hypre_ParCSRMatrixSetColStartsOwner(rap,0);
1359 if (!Rt_owns_its_col_starts)
1363 hypre_ParCSRMatrixSetRowStartsOwner(rap,0);
1373 Ae.
Mult(-1.0, X, 1.0, B);
1375 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag((hypre_ParCSRMatrix *)A);
1376 double *data = hypre_CSRMatrixData(A_diag);
1377 HYPRE_Int *I = hypre_CSRMatrixI(A_diag);
1379 HYPRE_Int *J = hypre_CSRMatrixJ(A_diag);
1380 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd((hypre_ParCSRMatrix *)A);
1381 HYPRE_Int *I_offd = hypre_CSRMatrixI(A_offd);
1382 double *data_offd = hypre_CSRMatrixData(A_offd);
1385 for (
int i = 0; i < ess_dof_list.
Size(); i++)
1387 int r = ess_dof_list[i];
1388 B(r) = data[I[r]] * X(r);
1395 MFEM_ABORT(
"the diagonal entry must be the first entry in the row!");
1397 for (
int j = I[r]+1; j < I[r+1]; j++)
1401 MFEM_ABORT(
"all off-diagonal entries must be zero!");
1404 for (
int j = I_offd[r]; j < I_offd[r+1]; j++)
1406 if (data_offd[j] != 0.0)
1408 MFEM_ABORT(
"all off-diagonal entries must be zero!");
1428 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1429 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A_diag);
1431 double *u_data = hypre_VectorData(hypre_ParVectorLocalVector(u));
1432 double *r_data = hypre_VectorData(hypre_ParVectorLocalVector(r));
1434 for (
int i = 0; i < N; i++)
1437 hypre_ParVectorCopy(f, r);
1438 hypre_ParCSRMatrixMatvec(-1.0, A, u, 1.0, r);
1441 (0 == (i % 2)) ? coef = lambda : coef = mu;
1443 for (HYPRE_Int j = 0; j < num_rows; j++)
1445 u_data[j] += coef*r_data[j] / max_eig;
1461 hypre_ParVector *x0,
1462 hypre_ParVector *x1,
1463 hypre_ParVector *x2,
1464 hypre_ParVector *x3)
1467 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1468 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A_diag);
1470 double *u_data = hypre_VectorData(hypre_ParVectorLocalVector(u));
1472 double *x0_data = hypre_VectorData(hypre_ParVectorLocalVector(x0));
1473 double *x1_data = hypre_VectorData(hypre_ParVectorLocalVector(x1));
1474 double *x2_data = hypre_VectorData(hypre_ParVectorLocalVector(x2));
1475 double *x3_data = hypre_VectorData(hypre_ParVectorLocalVector(x3));
1477 hypre_ParVectorCopy(u, x0);
1480 hypre_ParVectorCopy(f, x1);
1481 hypre_ParCSRMatrixMatvec(-1.0, A, x0, 1.0, x1);
1483 for (HYPRE_Int i = 0; i < num_rows; i++)
1485 x1_data[i] /= -max_eig;
1489 for (HYPRE_Int i = 0; i < num_rows; i++)
1491 x1_data[i] = x0_data[i] -x1_data[i];
1495 for (HYPRE_Int i = 0; i < num_rows; i++)
1497 x3_data[i] = fir_coeffs[0]*x0_data[i] +fir_coeffs[1]*x1_data[i];
1500 for (
int n = 2; n <= poly_order; n++)
1503 hypre_ParVectorCopy(f, x2);
1504 hypre_ParCSRMatrixMatvec(-1.0, A, x1, 1.0, x2);
1506 for (HYPRE_Int i = 0; i < num_rows; i++)
1508 x2_data[i] /= -max_eig;
1516 for (HYPRE_Int i = 0; i < num_rows; i++)
1518 x2_data[i] = (x1_data[i]-x0_data[i]) +(x1_data[i]-2*x2_data[i]);
1519 x3_data[i] += fir_coeffs[n]*x2_data[i];
1520 x0_data[i] = x1_data[i];
1521 x1_data[i] = x2_data[i];
1525 for (HYPRE_Int i = 0; i < num_rows; i++)
1527 u_data[i] = x3_data[i];
1546 B =
X =
V =
Z = NULL;
1552 int _relax_times,
double _relax_weight,
double _omega,
1553 int _poly_order,
double _poly_fraction)
1563 B =
X =
V =
Z = NULL;
1572 type =
static_cast<int>(_type);
1598 double a = -1, b, c;
1599 if (!strcmp(name,
"Rectangular")) { a = 1.0, b = 0.0, c = 0.0; }
1600 if (!strcmp(name,
"Hanning")) { a = 0.5, b = 0.5, c = 0.0; }
1601 if (!strcmp(name,
"Hamming")) { a = 0.54, b = 0.46, c = 0.0; }
1602 if (!strcmp(name,
"Blackman")) { a = 0.42, b = 0.50, c = 0.08; }
1605 mfem_error(
"HypreSmoother::SetWindowByName : name not recognized!");
1623 mfem_error(
"HypreSmoother::SetOperator : not HypreParMatrix!");
1629 if (
B) {
delete B; }
1630 if (
X) {
delete X; }
1631 if (
V) {
delete V; }
1632 if (
Z) {
delete Z; }
1651 A->
Mult(ones, diag);
1666 else if (
type == 1001 ||
type == 1002)
1697 double* window_coeffs =
new double[
poly_order+1];
1698 double* cheby_coeffs =
new double[
poly_order+1];
1706 window_coeffs[i] = a + b*cos(t) +c*cos(2*t);
1710 double theta_pb = acos(1.0 -0.5*k_pb);
1712 cheby_coeffs[0] = (theta_pb +sigma)/M_PI;
1715 double t = i*(theta_pb+sigma);
1716 cheby_coeffs[i] = 2.0*sin(t)/(i*M_PI);
1721 fir_coeffs[i] = window_coeffs[i]*cheby_coeffs[i];
1724 delete[] window_coeffs;
1725 delete[] cheby_coeffs;
1732 mfem_error(
"HypreSmoother::Mult (...) : HypreParMatrix A is missing");
1740 HYPRE_ParCSRDiagScale(NULL, *
A, b, x);
1764 else if (
type == 1002)
1779 hypre_ParCSRRelax(*
A, b,
type,
1784 hypre_ParCSRRelax(*
A, b,
type,
1795 mfem_error(
"HypreSmoother::Mult (...) : HypreParMatrix A is missing");
1801 A -> GetGlobalNumRows(),
1803 A -> GetRowStarts());
1805 A -> GetGlobalNumCols(),
1807 A -> GetColStarts());
1820 if (
B) {
delete B; }
1821 if (
X) {
delete X; }
1822 if (
V) {
delete V; }
1823 if (
Z) {
delete Z; }
1832 if (
X0) {
delete X0; }
1833 if (
X1) {
delete X1; }
1845 :
Solver(_A->Height(), _A->Width())
1856 mfem_error(
"HypreSolver::Mult (...) : HypreParMatrix A is missing");
1876 mfem_error(
"HypreSolver::Mult (...) : HypreParMatrix A is missing");
1882 A -> GetGlobalNumRows(),
1884 A -> GetRowStarts());
1886 A -> GetGlobalNumCols(),
1888 A -> GetColStarts());
1901 if (
B) {
delete B; }
1902 if (
X) {
delete X; }
1912 HYPRE_ParCSRMatrixGetComm(*
A, &comm);
1914 HYPRE_ParCSRPCGCreate(comm, &pcg_solver);
1919 HYPRE_PCGSetTol(pcg_solver, tol);
1924 HYPRE_PCGSetMaxIter(pcg_solver, max_iter);
1929 HYPRE_PCGSetLogging(pcg_solver, logging);
1934 HYPRE_ParCSRPCGSetPrintLevel(pcg_solver, print_lvl);
1939 HYPRE_ParCSRPCGSetPrecond(pcg_solver,
1947 HYPRE_PCGSetTwoNorm(pcg_solver, 1);
1948 if (res_frequency > 0)
1950 HYPRE_PCGSetRecomputeResidualP(pcg_solver, res_frequency);
1954 HYPRE_PCGSetResidualTol(pcg_solver, rtol);
1961 HYPRE_Int time_index = 0;
1962 HYPRE_Int num_iterations;
1963 double final_res_norm;
1965 HYPRE_Int print_level;
1967 HYPRE_PCGGetPrintLevel(pcg_solver, &print_level);
1969 HYPRE_ParCSRMatrixGetComm(*
A, &comm);
1973 if (print_level > 0)
1975 time_index = hypre_InitializeTiming(
"PCG Setup");
1976 hypre_BeginTiming(time_index);
1979 HYPRE_ParCSRPCGSetup(pcg_solver, *
A, b, x);
1982 if (print_level > 0)
1984 hypre_EndTiming(time_index);
1985 hypre_PrintTiming(
"Setup phase times", comm);
1986 hypre_FinalizeTiming(time_index);
1987 hypre_ClearTiming();
1991 if (print_level > 0)
1993 time_index = hypre_InitializeTiming(
"PCG Solve");
1994 hypre_BeginTiming(time_index);
2002 HYPRE_ParCSRPCGSolve(pcg_solver, *
A, b, x);
2004 if (print_level > 0)
2006 hypre_EndTiming(time_index);
2007 hypre_PrintTiming(
"Solve phase times", comm);
2008 hypre_FinalizeTiming(time_index);
2009 hypre_ClearTiming();
2011 HYPRE_ParCSRPCGGetNumIterations(pcg_solver, &num_iterations);
2012 HYPRE_ParCSRPCGGetFinalRelativeResidualNorm(pcg_solver,
2015 MPI_Comm_rank(comm, &myid);
2019 cout <<
"PCG Iterations = " << num_iterations << endl
2020 <<
"Final PCG Relative Residual Norm = " << final_res_norm
2028 HYPRE_ParCSRPCGDestroy(pcg_solver);
2042 HYPRE_ParCSRMatrixGetComm(*
A, &comm);
2044 HYPRE_ParCSRGMRESCreate(comm, &gmres_solver);
2045 HYPRE_ParCSRGMRESSetKDim(gmres_solver, k_dim);
2046 HYPRE_ParCSRGMRESSetMaxIter(gmres_solver, max_iter);
2047 HYPRE_ParCSRGMRESSetTol(gmres_solver, tol);
2052 HYPRE_GMRESSetTol(gmres_solver, tol);
2057 HYPRE_GMRESSetMaxIter(gmres_solver, max_iter);
2062 HYPRE_GMRESSetKDim(gmres_solver, k_dim);
2067 HYPRE_GMRESSetLogging(gmres_solver, logging);
2072 HYPRE_GMRESSetPrintLevel(gmres_solver, print_lvl);
2077 HYPRE_ParCSRGMRESSetPrecond(gmres_solver,
2086 HYPRE_Int time_index = 0;
2087 HYPRE_Int num_iterations;
2088 double final_res_norm;
2090 HYPRE_Int print_level;
2092 HYPRE_GMRESGetPrintLevel(gmres_solver, &print_level);
2094 HYPRE_ParCSRMatrixGetComm(*
A, &comm);
2098 if (print_level > 0)
2100 time_index = hypre_InitializeTiming(
"GMRES Setup");
2101 hypre_BeginTiming(time_index);
2104 HYPRE_ParCSRGMRESSetup(gmres_solver, *
A, b, x);
2107 if (print_level > 0)
2109 hypre_EndTiming(time_index);
2110 hypre_PrintTiming(
"Setup phase times", comm);
2111 hypre_FinalizeTiming(time_index);
2112 hypre_ClearTiming();
2116 if (print_level > 0)
2118 time_index = hypre_InitializeTiming(
"GMRES Solve");
2119 hypre_BeginTiming(time_index);
2127 HYPRE_ParCSRGMRESSolve(gmres_solver, *
A, b, x);
2129 if (print_level > 0)
2131 hypre_EndTiming(time_index);
2132 hypre_PrintTiming(
"Solve phase times", comm);
2133 hypre_FinalizeTiming(time_index);
2134 hypre_ClearTiming();
2136 HYPRE_ParCSRGMRESGetNumIterations(gmres_solver, &num_iterations);
2137 HYPRE_ParCSRGMRESGetFinalRelativeResidualNorm(gmres_solver,
2140 MPI_Comm_rank(comm, &myid);
2144 cout <<
"GMRES Iterations = " << num_iterations << endl
2145 <<
"Final GMRES Relative Residual Norm = " << final_res_norm
2153 HYPRE_ParCSRGMRESDestroy(gmres_solver);
2161 int sai_max_levels = 1;
2162 double sai_threshold = 0.1;
2163 double sai_filter = 0.1;
2165 double sai_loadbal = 0.0;
2167 int sai_logging = 1;
2169 HYPRE_ParCSRMatrixGetComm(A, &comm);
2171 HYPRE_ParaSailsCreate(comm, &sai_precond);
2172 HYPRE_ParaSailsSetParams(sai_precond, sai_threshold, sai_max_levels);
2173 HYPRE_ParaSailsSetFilter(sai_precond, sai_filter);
2174 HYPRE_ParaSailsSetSym(sai_precond, sai_sym);
2175 HYPRE_ParaSailsSetLoadbal(sai_precond, sai_loadbal);
2176 HYPRE_ParaSailsSetReuse(sai_precond, sai_reuse);
2177 HYPRE_ParaSailsSetLogging(sai_precond, sai_logging);
2182 HYPRE_ParaSailsSetSym(sai_precond, sym);
2187 HYPRE_ParaSailsDestroy(sai_precond);
2193 HYPRE_BoomerAMGCreate(&amg_precond);
2194 SetDefaultOptions();
2199 HYPRE_BoomerAMGCreate(&amg_precond);
2200 SetDefaultOptions();
2203 void HypreBoomerAMG::SetDefaultOptions()
2206 int coarsen_type = 10;
2208 double theta = 0.25;
2211 int interp_type = 6;
2216 int relax_sweeps = 1;
2219 int print_level = 1;
2220 int max_levels = 25;
2222 HYPRE_BoomerAMGSetCoarsenType(amg_precond, coarsen_type);
2223 HYPRE_BoomerAMGSetAggNumLevels(amg_precond, agg_levels);
2224 HYPRE_BoomerAMGSetRelaxType(amg_precond, relax_type);
2225 HYPRE_BoomerAMGSetNumSweeps(amg_precond, relax_sweeps);
2226 HYPRE_BoomerAMGSetStrongThreshold(amg_precond, theta);
2227 HYPRE_BoomerAMGSetInterpType(amg_precond, interp_type);
2228 HYPRE_BoomerAMGSetPMaxElmts(amg_precond, Pmax);
2229 HYPRE_BoomerAMGSetPrintLevel(amg_precond, print_level);
2230 HYPRE_BoomerAMGSetMaxLevels(amg_precond, max_levels);
2233 HYPRE_BoomerAMGSetMaxIter(amg_precond, 1);
2234 HYPRE_BoomerAMGSetTol(amg_precond, 0.0);
2237 void HypreBoomerAMG::ResetAMGPrecond()
2239 HYPRE_Int coarsen_type;
2240 HYPRE_Int agg_levels;
2241 HYPRE_Int relax_type;
2242 HYPRE_Int relax_sweeps;
2244 HYPRE_Int interp_type;
2246 HYPRE_Int print_level;
2248 HYPRE_Int nrbms = rbms.
Size();
2250 HYPRE_Int nodal_diag;
2251 HYPRE_Int relax_coarse;
2252 HYPRE_Int interp_vec_variant;
2254 HYPRE_Int smooth_interp_vectors;
2255 HYPRE_Int interp_refine;
2257 hypre_ParAMGData *amg_data = (hypre_ParAMGData *)amg_precond;
2260 HYPRE_BoomerAMGGetCoarsenType(amg_precond, &coarsen_type);
2261 agg_levels = hypre_ParAMGDataAggNumLevels(amg_data);
2262 relax_type = hypre_ParAMGDataUserRelaxType(amg_data);
2263 relax_sweeps = hypre_ParAMGDataUserNumSweeps(amg_data);
2264 HYPRE_BoomerAMGGetStrongThreshold(amg_precond, &theta);
2265 hypre_BoomerAMGGetInterpType(amg_precond, &interp_type);
2266 HYPRE_BoomerAMGGetPMaxElmts(amg_precond, &Pmax);
2267 HYPRE_BoomerAMGGetPrintLevel(amg_precond, &print_level);
2268 HYPRE_BoomerAMGGetNumFunctions(amg_precond, &dim);
2271 nodal = hypre_ParAMGDataNodal(amg_data);
2272 nodal_diag = hypre_ParAMGDataNodalDiag(amg_data);
2273 HYPRE_BoomerAMGGetCycleRelaxType(amg_precond, &relax_coarse, 3);
2274 interp_vec_variant = hypre_ParAMGInterpVecVariant(amg_data);
2275 q_max = hypre_ParAMGInterpVecQMax(amg_data);
2276 smooth_interp_vectors = hypre_ParAMGSmoothInterpVectors(amg_data);
2277 interp_refine = hypre_ParAMGInterpRefine(amg_data);
2280 HYPRE_BoomerAMGDestroy(amg_precond);
2281 HYPRE_BoomerAMGCreate(&amg_precond);
2283 HYPRE_BoomerAMGSetCoarsenType(amg_precond, coarsen_type);
2284 HYPRE_BoomerAMGSetAggNumLevels(amg_precond, agg_levels);
2285 HYPRE_BoomerAMGSetRelaxType(amg_precond, relax_type);
2286 HYPRE_BoomerAMGSetNumSweeps(amg_precond, relax_sweeps);
2287 HYPRE_BoomerAMGSetMaxLevels(amg_precond, 25);
2288 HYPRE_BoomerAMGSetTol(amg_precond, 0.0);
2289 HYPRE_BoomerAMGSetMaxIter(amg_precond, 1);
2290 HYPRE_BoomerAMGSetStrongThreshold(amg_precond, theta);
2291 HYPRE_BoomerAMGSetInterpType(amg_precond, interp_type);
2292 HYPRE_BoomerAMGSetPMaxElmts(amg_precond, Pmax);
2293 HYPRE_BoomerAMGSetPrintLevel(amg_precond, print_level);
2294 HYPRE_BoomerAMGSetNumFunctions(amg_precond, dim);
2297 HYPRE_BoomerAMGSetNodal(amg_precond, nodal);
2298 HYPRE_BoomerAMGSetNodalDiag(amg_precond, nodal_diag);
2299 HYPRE_BoomerAMGSetCycleRelaxType(amg_precond, relax_coarse, 3);
2300 HYPRE_BoomerAMGSetInterpVecVariant(amg_precond, interp_vec_variant);
2301 HYPRE_BoomerAMGSetInterpVecQMax(amg_precond, q_max);
2302 HYPRE_BoomerAMGSetSmoothInterpVectors(amg_precond, smooth_interp_vectors);
2303 HYPRE_BoomerAMGSetInterpRefine(amg_precond, interp_refine);
2305 HYPRE_BoomerAMGSetInterpVectors(amg_precond, rbms.
Size(), rbms.
GetData());
2312 MFEM_VERIFY(new_A,
"new Operator must be a HypreParMatrix!");
2314 if (
A) { ResetAMGPrecond(); }
2328 HYPRE_BoomerAMGSetNumFunctions(amg_precond, dim);
2331 HYPRE_BoomerAMGSetAggNumLevels(amg_precond, 0);
2332 HYPRE_BoomerAMGSetStrongThreshold(amg_precond, 0.5);
2338 y = 0.0; y(0) = x(1); y(1) = -x(0);
2340 static void func_ryz(
const Vector &x, Vector &y)
2342 y = 0.0; y(1) = x(2); y(2) = -x(1);
2344 static void func_rzx(
const Vector &x, Vector &y)
2346 y = 0.0; y(2) = x(0); y(0) = -x(2);
2349 void HypreBoomerAMG::RecomputeRBMs()
2352 Array<HypreParVector*> gf_rbms;
2355 for (
int i = 0; i < rbms.
Size(); i++)
2357 HYPRE_ParVectorDestroy(rbms[i]);
2364 VectorFunctionCoefficient coeff_rxy(2, func_rxy);
2366 ParGridFunction rbms_rxy(fespace);
2367 rbms_rxy.ProjectCoefficient(coeff_rxy);
2370 gf_rbms.SetSize(nrbms);
2371 gf_rbms[0] = rbms_rxy.ParallelAverage();
2377 VectorFunctionCoefficient coeff_rxy(3, func_rxy);
2378 VectorFunctionCoefficient coeff_ryz(3, func_ryz);
2379 VectorFunctionCoefficient coeff_rzx(3, func_rzx);
2381 ParGridFunction rbms_rxy(fespace);
2382 ParGridFunction rbms_ryz(fespace);
2383 ParGridFunction rbms_rzx(fespace);
2384 rbms_rxy.ProjectCoefficient(coeff_rxy);
2385 rbms_ryz.ProjectCoefficient(coeff_ryz);
2386 rbms_rzx.ProjectCoefficient(coeff_rzx);
2389 gf_rbms.SetSize(nrbms);
2390 gf_rbms[0] = rbms_rxy.ParallelAverage();
2391 gf_rbms[1] = rbms_ryz.ParallelAverage();
2392 gf_rbms[2] = rbms_rzx.ParallelAverage();
2401 for (
int i = 0; i < nrbms; i++)
2403 rbms[i] = gf_rbms[i]->StealParVector();
2411 this->fespace = fespace;
2421 int relax_coarse = 8;
2424 int interp_vec_variant = 2;
2426 int smooth_interp_vectors = 1;
2430 int interp_refine = 1;
2432 HYPRE_BoomerAMGSetNodal(amg_precond, nodal);
2433 HYPRE_BoomerAMGSetNodalDiag(amg_precond, nodal_diag);
2434 HYPRE_BoomerAMGSetCycleRelaxType(amg_precond, relax_coarse, 3);
2435 HYPRE_BoomerAMGSetInterpVecVariant(amg_precond, interp_vec_variant);
2436 HYPRE_BoomerAMGSetInterpVecQMax(amg_precond, q_max);
2437 HYPRE_BoomerAMGSetSmoothInterpVectors(amg_precond, smooth_interp_vectors);
2438 HYPRE_BoomerAMGSetInterpRefine(amg_precond, interp_refine);
2441 HYPRE_BoomerAMGSetInterpVectors(amg_precond, rbms.
Size(), rbms.
GetData());
2446 for (
int i = 0; i < rbms.
Size(); i++)
2448 HYPRE_ParVectorDestroy(rbms[i]);
2451 HYPRE_BoomerAMGDestroy(amg_precond);
2458 int cycle_type = 13;
2461 double rlx_weight = 1.0;
2462 double rlx_omega = 1.0;
2463 int amg_coarsen_type = 10;
2464 int amg_agg_levels = 1;
2465 int amg_rlx_type = 8;
2466 double theta = 0.25;
2467 int amg_interp_type = 6;
2474 bool trace_space, rt_trace_space;
2478 trace_space = trace_space || rt_trace_space;
2481 if (edge_fespace->
GetNE() > 0)
2486 if (dim == 2) { p++; }
2501 HYPRE_AMSCreate(&ams);
2503 HYPRE_AMSSetDimension(ams, sdim);
2504 HYPRE_AMSSetTol(ams, 0.0);
2505 HYPRE_AMSSetMaxIter(ams, 1);
2506 HYPRE_AMSSetCycleType(ams, cycle_type);
2507 HYPRE_AMSSetPrintLevel(ams, 1);
2529 for (
int i = 0; i < pmesh->
GetNV(); i++)
2531 coord = pmesh -> GetVertex(i);
2532 x_coord(i) = coord[0];
2533 y_coord(i) = coord[1];
2534 if (sdim == 3) { z_coord(i) = coord[2]; }
2541 HYPRE_AMSSetCoordinateVectors(ams, *x, *y, NULL);
2546 HYPRE_AMSSetCoordinateVectors(ams, *x, *y, *z);
2570 HYPRE_AMSSetDiscreteGradient(ams, *G);
2574 Pi = Pix = Piy = Piz = NULL;
2593 if (cycle_type < 10)
2601 Pix = Pi_blocks(0,0);
2602 Piy = Pi_blocks(0,1);
2603 if (sdim == 3) { Piz = Pi_blocks(0,2); }
2608 HYPRE_ParCSRMatrix HY_Pi = (Pi) ? (HYPRE_ParCSRMatrix) *Pi : NULL;
2609 HYPRE_ParCSRMatrix HY_Pix = (Pix) ? (HYPRE_ParCSRMatrix) *Pix : NULL;
2610 HYPRE_ParCSRMatrix HY_Piy = (Piy) ? (HYPRE_ParCSRMatrix) *Piy : NULL;
2611 HYPRE_ParCSRMatrix HY_Piz = (Piz) ? (HYPRE_ParCSRMatrix) *Piz : NULL;
2612 HYPRE_AMSSetInterpolations(ams, HY_Pi, HY_Pix, HY_Piy, HY_Piz);
2614 delete vert_fespace_d;
2617 delete vert_fespace;
2622 delete edge_fespace;
2627 HYPRE_AMSSetSmoothingOptions(ams, rlx_type, rlx_sweeps, rlx_weight, rlx_omega);
2628 HYPRE_AMSSetAlphaAMGOptions(ams, amg_coarsen_type, amg_agg_levels, amg_rlx_type,
2629 theta, amg_interp_type, amg_Pmax);
2630 HYPRE_AMSSetBetaAMGOptions(ams, amg_coarsen_type, amg_agg_levels, amg_rlx_type,
2631 theta, amg_interp_type, amg_Pmax);
2636 HYPRE_AMSDestroy(ams);
2651 HYPRE_AMSSetPrintLevel(ams, print_lvl);
2657 int cycle_type = 11;
2660 double rlx_weight = 1.0;
2661 double rlx_omega = 1.0;
2662 int amg_coarsen_type = 10;
2663 int amg_agg_levels = 1;
2664 int amg_rlx_type = 8;
2665 double theta = 0.25;
2666 int amg_interp_type = 6;
2668 int ams_cycle_type = 14;
2674 if (face_fespace->
GetNE() > 0)
2686 HYPRE_ADSCreate(&ads);
2688 HYPRE_ADSSetTol(ads, 0.0);
2689 HYPRE_ADSSetMaxIter(ads, 1);
2690 HYPRE_ADSSetCycleType(ads, cycle_type);
2691 HYPRE_ADSSetPrintLevel(ads, 1);
2719 for (
int i = 0; i < pmesh->
GetNV(); i++)
2721 coord = pmesh -> GetVertex(i);
2722 x_coord(i) = coord[0];
2723 y_coord(i) = coord[1];
2724 z_coord(i) = coord[2];
2729 HYPRE_ADSSetCoordinateVectors(ads, *x, *y, *z);
2753 HYPRE_ADSSetDiscreteCurl(ads, *C);
2772 HYPRE_ADSSetDiscreteGradient(ads, *G);
2776 RT_Pi = RT_Pix = RT_Piy = RT_Piz = NULL;
2777 ND_Pi = ND_Pix = ND_Piy = ND_Piz = NULL;
2796 if (ams_cycle_type < 10)
2806 ND_Pix = ND_Pi_blocks(0,0);
2807 ND_Piy = ND_Pi_blocks(0,1);
2808 ND_Piz = ND_Pi_blocks(0,2);
2826 if (cycle_type < 10)
2835 RT_Pix = RT_Pi_blocks(0,0);
2836 RT_Piy = RT_Pi_blocks(0,1);
2837 RT_Piz = RT_Pi_blocks(0,2);
2842 HYPRE_ParCSRMatrix HY_RT_Pi, HY_RT_Pix, HY_RT_Piy, HY_RT_Piz;
2843 HY_RT_Pi = (RT_Pi) ? (HYPRE_ParCSRMatrix) *RT_Pi : NULL;
2844 HY_RT_Pix = (RT_Pix) ? (HYPRE_ParCSRMatrix) *RT_Pix : NULL;
2845 HY_RT_Piy = (RT_Piy) ? (HYPRE_ParCSRMatrix) *RT_Piy : NULL;
2846 HY_RT_Piz = (RT_Piz) ? (HYPRE_ParCSRMatrix) *RT_Piz : NULL;
2847 HYPRE_ParCSRMatrix HY_ND_Pi, HY_ND_Pix, HY_ND_Piy, HY_ND_Piz;
2848 HY_ND_Pi = (ND_Pi) ? (HYPRE_ParCSRMatrix) *ND_Pi : NULL;
2849 HY_ND_Pix = (ND_Pix) ? (HYPRE_ParCSRMatrix) *ND_Pix : NULL;
2850 HY_ND_Piy = (ND_Piy) ? (HYPRE_ParCSRMatrix) *ND_Piy : NULL;
2851 HY_ND_Piz = (ND_Piz) ? (HYPRE_ParCSRMatrix) *ND_Piz : NULL;
2852 HYPRE_ADSSetInterpolations(ads,
2853 HY_RT_Pi, HY_RT_Pix, HY_RT_Piy, HY_RT_Piz,
2854 HY_ND_Pi, HY_ND_Pix, HY_ND_Piy, HY_ND_Piz);
2856 delete vert_fespace_d;
2860 delete vert_fespace;
2862 delete edge_fespace;
2865 HYPRE_ADSSetSmoothingOptions(ads, rlx_type, rlx_sweeps, rlx_weight, rlx_omega);
2866 HYPRE_ADSSetAMGOptions(ads, amg_coarsen_type, amg_agg_levels, amg_rlx_type,
2867 theta, amg_interp_type, amg_Pmax);
2868 HYPRE_ADSSetAMSOptions(ads, ams_cycle_type, amg_coarsen_type, amg_agg_levels,
2869 amg_rlx_type, theta, amg_interp_type, amg_Pmax);
2874 HYPRE_ADSDestroy(ads);
2896 HYPRE_ADSSetPrintLevel(ads, print_lvl);
2899 HypreLOBPCG::HypreMultiVector::HypreMultiVector(
int n,
HypreParVector & v,
2900 mv_InterfaceInterpreter & interpreter)
2904 mv_ptr = mv_MultiVectorCreateFromSampleVector(&interpreter, nv,
2905 (HYPRE_ParVector)v);
2907 HYPRE_ParVector* vecs = NULL;
2909 mv_TempMultiVector* tmp =
2910 (mv_TempMultiVector*)mv_MultiVectorGetData(mv_ptr);
2911 vecs = (HYPRE_ParVector*)(tmp -> vector);
2914 hpv =
new HypreParVector*[nv];
2915 for (
int i=0; i<nv; i++)
2917 hpv[i] =
new HypreParVector(vecs[i]);
2921 HypreLOBPCG::HypreMultiVector::~HypreMultiVector()
2925 for (
int i=0; i<nv; i++)
2932 mv_MultiVectorDestroy(mv_ptr);
2936 HypreLOBPCG::HypreMultiVector::Randomize(HYPRE_Int seed)
2938 mv_MultiVectorSetRandom(mv_ptr, seed);
2942 HypreLOBPCG::HypreMultiVector::GetVector(
unsigned int i)
2944 MFEM_ASSERT((
int)i < nv,
"index out of range");
2950 HypreLOBPCG::HypreMultiVector::StealVectors()
2952 HypreParVector ** hpv_ret = hpv;
2956 mv_TempMultiVector * mv_tmp =
2957 (mv_TempMultiVector*)mv_MultiVectorGetData(mv_ptr);
2959 mv_tmp->ownsVectors = 0;
2961 for (
int i=0; i<nv; i++)
2963 hpv_ret[i]->SetOwnership(1);
2980 MPI_Comm_size(comm,&numProcs);
2981 MPI_Comm_rank(comm,&myid);
2983 HYPRE_ParCSRSetupInterpreter(&interpreter);
2984 HYPRE_ParCSRSetupMatvec(&matvec_fn);
2985 HYPRE_LOBPCGCreate(&interpreter, &matvec_fn, &lobpcg_solver);
2994 HYPRE_LOBPCGDestroy(lobpcg_solver);
3000 HYPRE_LOBPCGSetTol(lobpcg_solver, tol);
3006 HYPRE_LOBPCGSetMaxIter(lobpcg_solver, max_iter);
3014 HYPRE_LOBPCGSetPrintLevel(lobpcg_solver, logging);
3021 HYPRE_LOBPCGSetPrecondUsageMode(lobpcg_solver, pcg_mode);
3027 HYPRE_LOBPCGSetPrecond(lobpcg_solver,
3028 (HYPRE_PtrToSolverFcn)this->PrecondSolve,
3029 (HYPRE_PtrToSolverFcn)this->PrecondSetup,
3030 (HYPRE_Solver)&precond);
3036 int locSize = A.
Width();
3038 if (HYPRE_AssumedPartitionCheck())
3040 part =
new HYPRE_Int[2];
3042 MPI_Scan(&locSize, &part[1], 1, HYPRE_MPI_INT, MPI_SUM, comm);
3044 part[0] = part[1] - locSize;
3047 MPI_Allreduce(&locSize, &glbSize, 1, HYPRE_MPI_INT, MPI_SUM, comm);
3051 part =
new HYPRE_Int[numProcs+1];
3053 MPI_Allgather(&locSize, 1, MPI_INT,
3054 &part[1], 1, HYPRE_MPI_INT, comm);
3057 for (
int i=0; i<numProcs; i++)
3059 part[i+1] += part[i];
3062 glbSize = part[numProcs];
3072 matvec_fn.MatvecCreate = this->OperatorMatvecCreate;
3073 matvec_fn.Matvec = this->OperatorMatvec;
3074 matvec_fn.MatvecDestroy = this->OperatorMatvecDestroy;
3076 HYPRE_LOBPCGSetup(lobpcg_solver,(HYPRE_Matrix)&A,NULL,NULL);
3082 matvec_fn.MatvecCreate = this->OperatorMatvecCreate;
3083 matvec_fn.Matvec = this->OperatorMatvec;
3084 matvec_fn.MatvecDestroy = this->OperatorMatvecDestroy;
3086 HYPRE_LOBPCGSetupB(lobpcg_solver,(HYPRE_Matrix)&M,NULL);
3095 for (
int i=0; i<nev; i++)
3097 eigs[i] = eigenvalues[i];
3104 return multi_vec->GetVector(i);
3111 if ( multi_vec == NULL )
3113 MFEM_ASSERT(x != NULL,
"In HypreLOBPCG::Solve()");
3115 multi_vec =
new HypreMultiVector(nev, *x, interpreter);
3116 multi_vec->Randomize(seed);
3126 HYPRE_LOBPCGSolve(lobpcg_solver, NULL, *multi_vec, eigenvalues);
3130 HypreLOBPCG::OperatorMatvecCreate(
void *A,
3137 return ( matvec_data );
3141 HypreLOBPCG::OperatorMatvec(
void *matvec_data,
3142 HYPRE_Complex alpha,
3148 MFEM_VERIFY(alpha == 1.0 && beta == 0.0,
"values not supported");
3150 Operator *Aop = (Operator*)A;
3152 int width = Aop->Width();
3154 hypre_ParVector * xPar = (hypre_ParVector *)x;
3155 hypre_ParVector * yPar = (hypre_ParVector *)y;
3157 Vector xVec(xPar->local_vector->data, width);
3158 Vector yVec(yPar->local_vector->data, width);
3160 Aop->Mult( xVec, yVec );
3166 HypreLOBPCG::OperatorMatvecDestroy(
void *matvec_data )
3172 HypreLOBPCG::PrecondSolve(
void *solver,
3177 Solver *PC = (Solver*)solver;
3178 Operator *OP = (Operator*)A;
3180 int width = OP->Width();
3182 hypre_ParVector * bPar = (hypre_ParVector *)b;
3183 hypre_ParVector * xPar = (hypre_ParVector *)x;
3185 Vector bVec(bPar->local_vector->data, width);
3186 Vector xVec(xPar->local_vector->data, width);
3188 PC->Mult( bVec, xVec );
3194 HypreLOBPCG::PrecondSetup(
void *solver,
3212 MPI_Comm_size(comm,&numProcs);
3213 MPI_Comm_rank(comm,&myid);
3215 HYPRE_AMECreate(&ame_solver);
3216 HYPRE_AMESetPrintLevel(ame_solver, 0);
3223 hypre_TFree(multi_vec);
3228 for (
int i=0; i<nev; i++)
3230 delete eigenvectors[i];
3233 delete [] eigenvectors;
3237 hypre_TFree(eigenvalues);
3240 HYPRE_AMEDestroy(ame_solver);
3248 HYPRE_AMESetBlockSize(ame_solver, nev);
3254 HYPRE_AMESetTol(ame_solver, tol);
3260 HYPRE_AMESetMaxIter(ame_solver, max_iter);
3268 HYPRE_AMESetPrintLevel(ame_solver, logging);
3275 ams_precond = &precond;
3283 HYPRE_Solver ams_precond_ptr = (HYPRE_Solver)*ams_precond;
3285 ams_precond->
SetupFcn()(*ams_precond,A,NULL,NULL);
3287 HYPRE_AMESetAMSSolver(ame_solver, ams_precond_ptr);
3290 HYPRE_AMESetup(ame_solver);
3296 HYPRE_ParCSRMatrix parcsr_M = M;
3297 HYPRE_AMESetMassMatrix(ame_solver,(HYPRE_ParCSRMatrix)parcsr_M);
3303 HYPRE_AMESolve(ame_solver);
3310 eigs.
SetSize(nev); eigs = -1.0;
3312 if ( eigenvalues == NULL )
3315 HYPRE_AMEGetEigenvalues(ame_solver,&eigenvalues);
3319 for (
int i=0; i<nev; i++)
3321 eigs[i] = eigenvalues[i];
3326 HypreAME::createDummyVectors()
3328 if ( multi_vec == NULL )
3330 HYPRE_AMEGetEigenvectors(ame_solver,&multi_vec);
3333 eigenvectors =
new HypreParVector*[nev];
3334 for (
int i=0; i<nev; i++)
3336 eigenvectors[i] =
new HypreParVector(multi_vec[i]);
3345 if ( eigenvectors == NULL )
3347 this->createDummyVectors();
3350 return *eigenvectors[i];
3356 if ( eigenvectors == NULL )
3358 this->createDummyVectors();
3363 eigenvectors = NULL;
virtual ~HypreBoomerAMG()
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
int Size() const
Logical size of the array.
void EliminateRowsCols(const Array< int > &rows_cols, const HypreParVector &X, HypreParVector &B)
virtual int NumNonZeroElems() const
Returns the number of the nonzero elements in the matrix.
Vector()
Default constructor for Vector. Sets size = 0 and data = NULL.
MPI_Comm GetComm() const
MPI communicator.
Vector * GlobalVector() const
Returns the global vector in each processor.
HypreParVector * X0
FIR Filter Temporary Vectors.
HypreParVector & GetEigenvector(unsigned int i)
Extract a single eigenvector.
double min_eig_est
Minimal eigenvalue estimate for polynomial smoothing.
void SetPrintLevel(int print_lvl)
void Print(const char *fname, HYPRE_Int offi=0, HYPRE_Int offj=0)
Prints the locally owned rows in parallel.
int setup_called
Was hypre's Setup function called already?
void MakeRef(const HypreParMatrix &master)
Make this HypreParMatrix a reference to 'master'.
HypreParMatrix * LeftDiagMult(const SparseMatrix &D, HYPRE_Int *row_starts=NULL) const
HYPRE_Int MultTranspose(HypreParVector &x, HypreParVector &y, double alpha=1.0, double beta=0.0)
Computes y = alpha * A^t * x + beta * y.
void SetSize(int s)
Resizes the vector if the new size is different.
HypreParVector * B
Right-hand side and solution vector.
double window_params[3]
Parameters for windowing function of FIR filter.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols.
HypreADS(HypreParMatrix &A, ParFiniteElementSpace *face_fespace)
void SetWindowByName(const char *window_name)
Convenience function for setting canonical windowing parameters.
int GetFaceOrder(int i) const
Returns the order of the i'th face finite element.
T * GetData()
Returns the data.
void GetEigenvalues(Array< double > &eigenvalues)
Collect the converged eigenvalues.
HYPRE_Int GlobalTrueVSize()
void SetPreconditioner(HypreSolver &precond)
int Size() const
Returns the size of the vector.
void SetPreconditioner(Solver &precond)
void SetMassMatrix(Operator &M)
Abstract parallel finite element space.
void SetPrintLevel(int logging)
bool iterative_mode
If true, use the second argument of Mult as an initial guess.
void SetOperator(HypreParMatrix &A)
void LoseData()
Lose the ownership of the graph (I, J) and data (A) arrays.
HYPRE_Int Mult(HypreParVector &x, HypreParVector &y, double alpha=1.0, double beta=0.0)
Computes y = alpha * A * x + beta * y.
void SetPrintLevel(int print_lvl)
void ScaleRows(const Vector &s)
Scale the local row i by s(i).
int Size_of_connections() const
double poly_fraction
Fraction of spectrum to smooth for polynomial relaxation.
void SetPrintLevel(int print_lvl)
int poly_scale
Apply the polynomial smoother to A or D^{-1/2} A D^{-1/2}.
void AddDomainInterpolator(DiscreteInterpolator *di)
HYPRE_Int * GetTrueDofOffsets()
void SetWindowParameters(double a, double b, double c)
Set parameters for windowing function for FIR smoother.
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre's GMRES.
void Print(const char *fname) const
Prints the locally owned rows in parallel.
void EliminateBC(HypreParMatrix &A, HypreParMatrix &Ae, const Array< int > &ess_dof_list, const Vector &X, Vector &B)
void SetSystemsOptions(int dim)
HypreLOBPCG(MPI_Comm comm)
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Relax the linear system Ax=b.
int GetNE() const
Returns number of elements in the mesh.
HYPRE_Int GetGlobalNumRows() const
void SetSymmetry(int sym)
virtual ~HypreParaSails()
HYPRE_Int GetGlobalNumCols() const
void SetMaxIter(int max_iter)
double * l1_norms
l1 norms of the rows of A
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows.
void SetLogging(int logging)
Mesh * GetMesh() const
Returns the mesh.
HyprePCG(HypreParMatrix &_A)
virtual HYPRE_PtrToParSolverFcn SolveFcn() const =0
hypre's internal Solve function
void SetResidualConvergenceOptions(int res_frequency=-1, double rtol=0.0)
void GetBlocks(Array2D< HypreParMatrix * > &blocks, bool interleaved_rows=false, bool interleaved_cols=false) const
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve the linear system Ax=b.
HypreParMatrix * RAP(HypreParMatrix *A, HypreParMatrix *P)
Returns the matrix P^t * A * P.
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
HYPRE_Int Randomize(HYPRE_Int seed)
Set random values.
double relax_weight
Damping coefficient (usually <= 1)
void SetElasticityOptions(ParFiniteElementSpace *fespace)
void GetDiag(Vector &diag) const
Get the local diagonal of the matrix.
void Sort()
Sorts the array. This requires operator< to be defined for T.
int Size() const
Returns the number of TYPE I elements.
HypreParMatrix * A
The linear system matrix.
double * GetData() const
Return element data.
HypreAMS(HypreParMatrix &A, ParFiniteElementSpace *edge_fespace)
int * GetI() const
Return the array I.
virtual void SetOperator(const Operator &op)
virtual HYPRE_PtrToParSolverFcn SetupFcn() const =0
hypre's internal Setup function
void SetLogging(int logging)
HypreParMatrix()
An empty matrix to be used as a reference to an existing matrix.
void SetMaxIter(int max_iter)
int ParCSRRelax_FIR(hypre_ParCSRMatrix *A, hypre_ParVector *f, double max_eig, int poly_order, double *fir_coeffs, hypre_ParVector *u, hypre_ParVector *x0, hypre_ParVector *x1, hypre_ParVector *x2, hypre_ParVector *x3)
HypreParMatrix * ParallelAssemble() const
Returns the matrix "assembled" on the true dofs.
void SetSOROptions(double relax_weight, double omega)
Set SOR-related parameters.
int SpaceDimension() const
Wrapper for hypre's parallel vector class.
int ParCSRRelax_Taubin(hypre_ParCSRMatrix *A, hypre_ParVector *f, double lambda, double mu, int N, double max_eig, hypre_ParVector *u, hypre_ParVector *r)
void GetEigenvalues(Array< double > &eigenvalues)
Collect the converged eigenvalues.
void SetPrintLevel(int print_lvl)
void mfem_error(const char *msg)
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
void Solve()
Solve the eigenproblem.
void AddTraceFaceInterpolator(DiscreteInterpolator *di)
int GetOrder(int i) const
Returns the order of the i'th finite element.
void SetNumModes(int num_eigs)
int GetNumRows() const
Returns the number of rows in the diagonal block of the ParCSRMatrix.
double max_eig_est
Maximal eigenvalue estimate for polynomial smoothing.
HypreParMatrix * Transpose()
Returns the transpose of *this.
void SetMaxIter(int max_iter)
void SetFIRCoefficients(double max_eig)
Compute window and Chebyshev coefficients for given polynomial order.
double * fir_coeffs
Combined coefficients for windowing and Chebyshev polynomials.
void Threshold(double threshold=0.0)
Remove values smaller in absolute value than some threshold.
double InnerProduct(HypreParVector *x, HypreParVector *y)
HypreParVector(MPI_Comm comm, HYPRE_Int glob_size, HYPRE_Int *col)
virtual void SetOperator(const Operator &op)
Set/update the solver for the given operator.
void SetData(double *_data)
void InvScaleRows(const Vector &s)
Scale the local row i by 1./s(i)
void SetTaubinOptions(double lambda, double mu, int iter)
Set parameters for Taubin's lambda-mu method.
HypreParVector * B
Right-hand side and solution vectors.
void SetMassMatrix(HypreParMatrix &M)
int GetNumCols() const
Returns the number of columns in the diagonal block of the ParCSRMatrix.
void SetOperator(Operator &A)
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
void SetPolyOptions(int poly_order, double poly_fraction)
Set parameters for polynomial smoothing.
int relax_times
Number of relaxation sweeps.
void operator*=(double s)
Scale all entries by s: A_scaled = s*A.
void SetPrintLevel(int logging)
void SetOwnership(int own)
Sets ownership of the internal hypre_ParVector.
void SetDataOwner(bool owna)
Set the data ownership flag (A array).
Abstract class for hypre's solvers and preconditioners.
HypreParVector & operator=(double d)
Set constant values.
Arbitrary order H(curl)-conforming Nedelec finite elements.
const FiniteElementCollection * FEColl() const
HypreGMRES(HypreParMatrix &_A)
void GetParBlocks(Array2D< HypreParMatrix * > &blocks) const
hypre_ParCSRMatrix * StealData()
Changes the ownership of the the matrix.
void SetPrecondUsageMode(int pcg_mode)
HypreParMatrix * A
The linear system matrix.
Arbitrary order H1-conforming (continuous) finite elements.
void SetMaxIter(int max_iter)
void GetOffd(SparseMatrix &offd, HYPRE_Int *&cmap) const
Get the local off-diagonal block. NOTE: 'offd' will not own any data.
HYPRE_Int * GetColStarts() const
HypreParVector & GetEigenvector(unsigned int i)
Extract a single eigenvector.
double omega
SOR parameter (usually in (0,2))
HYPRE_Int * GetRowStarts() const
Class for parallel grid function.
Wrapper for hypre's ParCSR matrix class.
void Swap(SparseMatrix &other)
~HypreParVector()
Calls hypre's destroy function.
virtual void Assemble(int skip_zeros=1)
int * GetJ() const
Return the array J.
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre's PCG.
Class for parallel meshes.
void Solve()
Solve the eigenproblem.
void Read(MPI_Comm comm, const char *fname)
Reads the matrix from a file.
HypreParVector * V
Temporary vectors.
void SetType(HypreSmoother::Type type, int relax_times=1)
Set the relaxation type and number of sweeps.
HypreParaSails(HypreParMatrix &A)
int poly_order
Order of the smoothing polynomial.
double lambda
Taubin's lambda-mu method parameters.
HypreParMatrix * ParMult(HypreParMatrix *A, HypreParMatrix *B)
Returns the matrix A * B.
void ParallelProject(Vector &tv) const
Returns the vector restricted to the true dofs.