12 #include "../config/config.hpp"
17 #include "../fem/fem.hpp"
29 template<
typename TargetT,
typename SourceT>
30 static TargetT *DuplicateAs(
const SourceT *array,
int size,
31 bool cplusplus =
true)
33 TargetT *target_array = cplusplus ?
new TargetT[size]
34 : hypre_TAlloc(TargetT, size);
35 for (
int i = 0; i < size; i++)
37 target_array[i] = array[i];
42 inline void HypreParVector::_SetDataAndSize_()
44 SetDataAndSize(hypre_VectorData(hypre_ParVectorLocalVector(x)),
46 hypre_VectorSize(hypre_ParVectorLocalVector(x))));
49 HypreParVector::HypreParVector(MPI_Comm comm, HYPRE_Int glob_size,
52 x = hypre_ParVectorCreate(comm,glob_size,col);
53 hypre_ParVectorInitialize(x);
54 hypre_ParVectorSetPartitioningOwner(x,0);
56 hypre_ParVectorSetDataOwner(x,1);
57 hypre_SeqVectorSetDataOwner(hypre_ParVectorLocalVector(x),1);
63 double *_data, HYPRE_Int *col) :
Vector()
65 x = hypre_ParVectorCreate(comm,glob_size,col);
66 hypre_ParVectorSetDataOwner(x,1);
67 hypre_SeqVectorSetDataOwner(hypre_ParVectorLocalVector(x),0);
68 hypre_ParVectorSetPartitioningOwner(x,0);
70 hypre_VectorData(hypre_ParVectorLocalVector(x)) = &tmp;
73 hypre_ParVectorInitialize(x);
75 hypre_VectorData(hypre_ParVectorLocalVector(x)) = _data;
82 x = hypre_ParVectorCreate(y.x -> comm, y.x -> global_size,
84 hypre_ParVectorInitialize(x);
85 hypre_ParVectorSetPartitioningOwner(x,0);
86 hypre_ParVectorSetDataOwner(x,1);
87 hypre_SeqVectorSetDataOwner(hypre_ParVectorLocalVector(x),1);
97 x = hypre_ParVectorInDomainOf(const_cast<HypreParMatrix&>(A));
101 x = hypre_ParVectorInRangeOf(const_cast<HypreParMatrix&>(A));
109 x = (hypre_ParVector *) y;
118 hypre_ParVectorInitialize(x);
119 hypre_ParVectorSetPartitioningOwner(x,0);
121 hypre_ParVectorSetDataOwner(x,1);
122 hypre_SeqVectorSetDataOwner(hypre_ParVectorLocalVector(x),1);
129 hypre_Vector *hv = hypre_ParVectorToVectorAll(*
this);
132 hypre_SeqVectorSetDataOwner(hv,0);
133 hypre_SeqVectorDestroy(hv);
139 hypre_ParVectorSetConstantValues(x,d);
146 if (size != y.
Size())
152 for (
int i = 0; i <
size; i++)
161 Vector::data = hypre_VectorData(hypre_ParVectorLocalVector(x)) = _data;
166 return hypre_ParVectorSetRandomValues(x,seed);
171 hypre_ParVectorPrint(x,fname);
178 hypre_ParVectorDestroy(x);
182 #ifdef MFEM_USE_SUNDIALS
185 #define SUNFALSE FALSE
190 MFEM_ASSERT(nv && N_VGetVectorID(nv) == SUNDIALS_NVEC_PARHYP,
192 N_VectorContent_ParHyp nv_c = (N_VectorContent_ParHyp)(nv->content);
193 MFEM_ASSERT(nv_c->own_parvector == SUNFALSE,
"invalid N_Vector");
194 nv_c->local_length = x->local_vector->size;
195 nv_c->global_length = x->global_size;
196 nv_c->comm = x->comm;
200 #endif // MFEM_USE_SUNDIALS
205 return hypre_ParVectorInnerProd(*x, *y);
210 return hypre_ParVectorInnerProd(x, y);
219 double loc_norm = vec.
Norml1();
220 MPI_Allreduce(&loc_norm, &norm, 1, MPI_DOUBLE, MPI_SUM, comm);
224 double loc_norm = vec*vec;
225 MPI_Allreduce(&loc_norm, &norm, 1, MPI_DOUBLE, MPI_SUM, comm);
228 if (p < std::numeric_limits<double>::infinity())
231 for (
int i = 0; i < vec.
Size(); i++)
233 sum += pow(fabs(vec(i)), p);
235 MPI_Allreduce(&sum, &norm, 1, MPI_DOUBLE, MPI_SUM, comm);
236 norm = pow(norm, 1.0/p);
241 MPI_Allreduce(&loc_norm, &norm, 1, MPI_DOUBLE, MPI_MAX, comm);
247 void HypreParMatrix::Init()
251 diagOwner = offdOwner = colMapOwner = -1;
261 char HypreParMatrix::CopyCSR(
SparseMatrix *csr, hypre_CSRMatrix *hypre_csr)
263 hypre_CSRMatrixData(hypre_csr) = csr->
GetData();
265 hypre_CSRMatrixI(hypre_csr) = csr->
GetI();
266 hypre_CSRMatrixJ(hypre_csr) = csr->
GetJ();
270 hypre_CSRMatrixI(hypre_csr) =
271 DuplicateAs<HYPRE_Int>(csr->
GetI(), csr->
Height()+1);
272 hypre_CSRMatrixJ(hypre_csr) =
279 char HypreParMatrix::CopyBoolCSR(Table *bool_csr, hypre_CSRMatrix *hypre_csr)
281 int nnz = bool_csr->Size_of_connections();
282 double *data =
new double[nnz];
283 for (
int i = 0; i < nnz; i++)
287 hypre_CSRMatrixData(hypre_csr) = data;
289 hypre_CSRMatrixI(hypre_csr) = bool_csr->GetI();
290 hypre_CSRMatrixJ(hypre_csr) = bool_csr->GetJ();
294 hypre_CSRMatrixI(hypre_csr) =
295 DuplicateAs<HYPRE_Int>(bool_csr->GetI(), bool_csr->Size()+1);
296 hypre_CSRMatrixJ(hypre_csr) =
297 DuplicateAs<HYPRE_Int>(bool_csr->GetJ(), nnz);
303 void HypreParMatrix::CopyCSR_J(hypre_CSRMatrix *hypre_csr,
int *J)
305 HYPRE_Int nnz = hypre_CSRMatrixNumNonzeros(hypre_csr);
306 for (HYPRE_Int j = 0; j < nnz; j++)
308 J[j] = int(hypre_CSRMatrixJ(hypre_csr)[j]);
315 :
Operator(diag->Height(), diag->Width())
318 A = hypre_ParCSRMatrixCreate(comm, glob_size, glob_size, row_starts,
320 hypre_ParCSRMatrixSetDataOwner(A,1);
321 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
322 hypre_ParCSRMatrixSetColStartsOwner(A,0);
324 hypre_CSRMatrixSetDataOwner(A->diag,0);
325 diagOwner = CopyCSR(diag, A->diag);
326 hypre_CSRMatrixSetRownnz(A->diag);
328 hypre_CSRMatrixSetDataOwner(A->offd,1);
329 hypre_CSRMatrixI(A->offd) = hypre_CTAlloc(HYPRE_Int, diag->
Height()+1);
336 hypre_ParCSRMatrixSetNumNonzeros(A);
339 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
341 CopyCSR_J(A->diag, diag->
GetJ());
344 hypre_MatvecCommPkgCreate(A);
349 HYPRE_Int global_num_rows,
350 HYPRE_Int global_num_cols,
351 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
353 :
Operator(diag->Height(), diag->Width())
356 A = hypre_ParCSRMatrixCreate(comm, global_num_rows, global_num_cols,
357 row_starts, col_starts,
359 hypre_ParCSRMatrixSetDataOwner(A,1);
360 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
361 hypre_ParCSRMatrixSetColStartsOwner(A,0);
363 hypre_CSRMatrixSetDataOwner(A->diag,0);
364 diagOwner = CopyCSR(diag, A->diag);
365 hypre_CSRMatrixSetRownnz(A->diag);
367 hypre_CSRMatrixSetDataOwner(A->offd,1);
368 hypre_CSRMatrixI(A->offd) = hypre_CTAlloc(HYPRE_Int, diag->
Height()+1);
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);
386 HYPRE_Int global_num_rows,
387 HYPRE_Int global_num_cols,
388 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
391 :
Operator(diag->Height(), diag->Width())
394 A = hypre_ParCSRMatrixCreate(comm, global_num_rows, global_num_cols,
395 row_starts, col_starts,
398 hypre_ParCSRMatrixSetDataOwner(A,1);
399 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
400 hypre_ParCSRMatrixSetColStartsOwner(A,0);
402 hypre_CSRMatrixSetDataOwner(A->diag,0);
403 diagOwner = CopyCSR(diag, A->diag);
404 hypre_CSRMatrixSetRownnz(A->diag);
406 hypre_CSRMatrixSetDataOwner(A->offd,0);
407 offdOwner = CopyCSR(offd, A->offd);
408 hypre_CSRMatrixSetRownnz(A->offd);
410 hypre_ParCSRMatrixColMapOffd(A) = cmap;
414 hypre_ParCSRMatrixSetNumNonzeros(A);
417 if (row_starts == col_starts)
419 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
421 CopyCSR_J(A->diag, diag->
GetJ());
425 hypre_MatvecCommPkgCreate(A);
431 HYPRE_Int global_num_rows, HYPRE_Int global_num_cols,
432 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
433 HYPRE_Int *diag_i, HYPRE_Int *diag_j,
double *diag_data,
434 HYPRE_Int *offd_i, HYPRE_Int *offd_j,
double *offd_data,
435 HYPRE_Int offd_num_cols, HYPRE_Int *offd_col_map)
438 A = hypre_ParCSRMatrixCreate(comm, global_num_rows, global_num_cols,
439 row_starts, col_starts, offd_num_cols, 0, 0);
440 hypre_ParCSRMatrixSetDataOwner(A,1);
441 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
442 hypre_ParCSRMatrixSetColStartsOwner(A,0);
444 HYPRE_Int local_num_rows = hypre_CSRMatrixNumRows(A->diag);
446 hypre_CSRMatrixSetDataOwner(A->diag,0);
447 hypre_CSRMatrixI(A->diag) = diag_i;
448 hypre_CSRMatrixJ(A->diag) = diag_j;
449 hypre_CSRMatrixData(A->diag) = diag_data;
450 hypre_CSRMatrixNumNonzeros(A->diag) = diag_i[local_num_rows];
451 hypre_CSRMatrixSetRownnz(A->diag);
455 hypre_CSRMatrixSetDataOwner(A->offd,0);
456 hypre_CSRMatrixI(A->offd) = offd_i;
457 hypre_CSRMatrixJ(A->offd) = offd_j;
458 hypre_CSRMatrixData(A->offd) = offd_data;
459 hypre_CSRMatrixNumNonzeros(A->offd) = offd_i[local_num_rows];
460 hypre_CSRMatrixSetRownnz(A->offd);
464 hypre_ParCSRMatrixColMapOffd(A) = offd_col_map;
468 hypre_ParCSRMatrixSetNumNonzeros(A);
471 if (row_starts == col_starts)
473 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
476 hypre_MatvecCommPkgCreate(A);
484 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
487 MFEM_ASSERT(sm_a != NULL,
"invalid input");
488 MFEM_VERIFY(!HYPRE_AssumedPartitionCheck(),
489 "this method can not be used with assumed partition");
493 hypre_CSRMatrix *csr_a;
494 csr_a = hypre_CSRMatrixCreate(sm_a ->
Height(), sm_a ->
Width(),
495 sm_a -> NumNonZeroElems());
497 hypre_CSRMatrixSetDataOwner(csr_a,0);
498 CopyCSR(sm_a, csr_a);
499 hypre_CSRMatrixSetRownnz(csr_a);
501 A = hypre_CSRMatrixToParCSRMatrix(comm, csr_a, row_starts, col_starts);
504 delete [] hypre_CSRMatrixI(csr_a);
505 delete [] hypre_CSRMatrixJ(csr_a);
507 hypre_CSRMatrixI(csr_a) = NULL;
508 hypre_CSRMatrixDestroy(csr_a);
514 if (row_starts == col_starts)
516 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
519 hypre_MatvecCommPkgCreate(A);
524 HYPRE_Int global_num_rows,
525 HYPRE_Int global_num_cols,
526 HYPRE_Int *row_starts, HYPRE_Int *col_starts,
531 A = hypre_ParCSRMatrixCreate(comm, global_num_rows, global_num_cols,
532 row_starts, col_starts, 0, nnz, 0);
533 hypre_ParCSRMatrixSetDataOwner(A,1);
534 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
535 hypre_ParCSRMatrixSetColStartsOwner(A,0);
537 hypre_CSRMatrixSetDataOwner(A->diag,0);
538 diagOwner = CopyBoolCSR(diag, A->diag);
539 hypre_CSRMatrixSetRownnz(A->diag);
541 hypre_CSRMatrixSetDataOwner(A->offd,1);
542 hypre_CSRMatrixI(A->offd) = hypre_CTAlloc(HYPRE_Int, diag->
Size()+1);
544 hypre_ParCSRMatrixSetNumNonzeros(A);
547 if (row_starts == col_starts)
549 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
551 CopyCSR_J(A->diag, diag->
GetJ());
555 hypre_MatvecCommPkgCreate(A);
563 HYPRE_Int *row, HYPRE_Int *col,
564 HYPRE_Int *i_diag, HYPRE_Int *j_diag,
565 HYPRE_Int *i_offd, HYPRE_Int *j_offd,
566 HYPRE_Int *cmap, HYPRE_Int cmap_size)
568 HYPRE_Int diag_nnz, offd_nnz;
571 if (HYPRE_AssumedPartitionCheck())
573 diag_nnz = i_diag[row[1]-row[0]];
574 offd_nnz = i_offd[row[1]-row[0]];
576 A = hypre_ParCSRMatrixCreate(comm, row[2], col[2], row, col,
577 cmap_size, diag_nnz, offd_nnz);
581 diag_nnz = i_diag[row[
id+1]-row[id]];
582 offd_nnz = i_offd[row[
id+1]-row[id]];
584 A = hypre_ParCSRMatrixCreate(comm, row[np], col[np], row, col,
585 cmap_size, diag_nnz, offd_nnz);
588 hypre_ParCSRMatrixSetDataOwner(A,1);
589 hypre_ParCSRMatrixSetRowStartsOwner(A,0);
590 hypre_ParCSRMatrixSetColStartsOwner(A,0);
594 double *a_diag =
new double[diag_nnz];
595 for (i = 0; i < diag_nnz; i++)
600 double *a_offd =
new double[offd_nnz];
601 for (i = 0; i < offd_nnz; i++)
606 hypre_CSRMatrixSetDataOwner(A->diag,0);
607 hypre_CSRMatrixI(A->diag) = i_diag;
608 hypre_CSRMatrixJ(A->diag) = j_diag;
609 hypre_CSRMatrixData(A->diag) = a_diag;
610 hypre_CSRMatrixSetRownnz(A->diag);
614 hypre_CSRMatrixSetDataOwner(A->offd,0);
615 hypre_CSRMatrixI(A->offd) = i_offd;
616 hypre_CSRMatrixJ(A->offd) = j_offd;
617 hypre_CSRMatrixData(A->offd) = a_offd;
618 hypre_CSRMatrixSetRownnz(A->offd);
622 hypre_ParCSRMatrixColMapOffd(A) = cmap;
626 hypre_ParCSRMatrixSetNumNonzeros(A);
631 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
634 hypre_MatvecCommPkgCreate(A);
643 HYPRE_Int glob_ncols,
int *I, HYPRE_Int *J,
644 double *data, HYPRE_Int *rows, HYPRE_Int *cols)
650 HYPRE_Int my_col_start, my_col_end;
651 if (HYPRE_AssumedPartitionCheck())
654 my_col_start = cols[0];
655 my_col_end = cols[1];
660 MPI_Comm_rank(comm, &myid);
661 MPI_Comm_size(comm, &part_size);
663 my_col_start = cols[myid];
664 my_col_end = cols[myid+1];
668 HYPRE_Int *row_starts, *col_starts;
671 row_starts = col_starts = hypre_TAlloc(HYPRE_Int, part_size);
672 for (
int i = 0; i < part_size; i++)
674 row_starts[i] = rows[i];
679 row_starts = hypre_TAlloc(HYPRE_Int, part_size);
680 col_starts = hypre_TAlloc(HYPRE_Int, part_size);
681 for (
int i = 0; i < part_size; i++)
683 row_starts[i] = rows[i];
684 col_starts[i] = cols[i];
690 HYPRE_Int diag_nnz = 0, offd_nnz = 0, offd_num_cols = 0;
691 map<HYPRE_Int, HYPRE_Int> offd_map;
692 for (HYPRE_Int j = 0, loc_nnz = I[nrows]; j < loc_nnz; j++)
694 HYPRE_Int glob_col = J[j];
695 if (my_col_start <= glob_col && glob_col < my_col_end)
701 offd_map.insert(pair<const HYPRE_Int, HYPRE_Int>(glob_col, -1));
706 for (map<HYPRE_Int, HYPRE_Int>::iterator it = offd_map.begin();
707 it != offd_map.end(); ++it)
709 it->second = offd_num_cols++;
713 A = hypre_ParCSRMatrixCreate(comm, glob_nrows, glob_ncols,
714 row_starts, col_starts, offd_num_cols,
716 hypre_ParCSRMatrixInitialize(A);
718 HYPRE_Int *diag_i, *diag_j, *offd_i, *offd_j, *offd_col_map;
719 double *diag_data, *offd_data;
722 diag_data = A->diag->data;
725 offd_data = A->offd->data;
726 offd_col_map = A->col_map_offd;
728 diag_nnz = offd_nnz = 0;
729 for (HYPRE_Int i = 0, j = 0; i < nrows; i++)
731 diag_i[i] = diag_nnz;
732 offd_i[i] = offd_nnz;
733 for (HYPRE_Int j_end = I[i+1]; j < j_end; j++)
735 HYPRE_Int glob_col = J[j];
736 if (my_col_start <= glob_col && glob_col < my_col_end)
738 diag_j[diag_nnz] = glob_col - my_col_start;
739 diag_data[diag_nnz] = data[j];
744 offd_j[offd_nnz] = offd_map[glob_col];
745 offd_data[offd_nnz] = data[j];
750 diag_i[nrows] = diag_nnz;
751 offd_i[nrows] = offd_nnz;
752 for (map<HYPRE_Int, HYPRE_Int>::iterator it = offd_map.begin();
753 it != offd_map.end(); ++it)
755 offd_col_map[it->second] = it->first;
758 hypre_ParCSRMatrixSetNumNonzeros(A);
760 if (row_starts == col_starts)
762 hypre_CSRMatrixReorder(hypre_ParCSRMatrixDiag(A));
764 hypre_MatvecCommPkgCreate(A);
785 MFEM_ASSERT(diagOwner == -1 && offdOwner == -1 && colMapOwner == -1,
"");
786 MFEM_ASSERT(ParCSROwner,
"");
787 hypre_ParCSRMatrix *R = A;
796 if (!A || hypre_ParCSRMatrixOwnsRowStarts(A) ||
797 (hypre_ParCSRMatrixRowStarts(A) == hypre_ParCSRMatrixColStarts(A) &&
798 hypre_ParCSRMatrixOwnsColStarts(A)))
804 if (HYPRE_AssumedPartitionCheck())
810 MPI_Comm_size(hypre_ParCSRMatrixComm(A), &row_starts_size);
814 HYPRE_Int *old_row_starts = hypre_ParCSRMatrixRowStarts(A);
815 HYPRE_Int *new_row_starts = hypre_CTAlloc(HYPRE_Int, row_starts_size);
816 for (
int i = 0; i < row_starts_size; i++)
818 new_row_starts[i] = old_row_starts[i];
821 hypre_ParCSRMatrixRowStarts(A) = new_row_starts;
822 hypre_ParCSRMatrixOwnsRowStarts(A) = 1;
824 if (hypre_ParCSRMatrixColStarts(A) == old_row_starts)
826 hypre_ParCSRMatrixColStarts(A) = new_row_starts;
827 hypre_ParCSRMatrixOwnsColStarts(A) = 0;
833 if (!A || hypre_ParCSRMatrixOwnsColStarts(A) ||
834 (hypre_ParCSRMatrixRowStarts(A) == hypre_ParCSRMatrixColStarts(A) &&
835 hypre_ParCSRMatrixOwnsRowStarts(A)))
841 if (HYPRE_AssumedPartitionCheck())
847 MPI_Comm_size(hypre_ParCSRMatrixComm(A), &col_starts_size);
851 HYPRE_Int *old_col_starts = hypre_ParCSRMatrixColStarts(A);
852 HYPRE_Int *new_col_starts = hypre_CTAlloc(HYPRE_Int, col_starts_size);
853 for (
int i = 0; i < col_starts_size; i++)
855 new_col_starts[i] = old_col_starts[i];
858 hypre_ParCSRMatrixColStarts(A) = new_col_starts;
860 if (hypre_ParCSRMatrixRowStarts(A) == old_col_starts)
862 hypre_ParCSRMatrixRowStarts(A) = new_col_starts;
863 hypre_ParCSRMatrixOwnsRowStarts(A) = 1;
864 hypre_ParCSRMatrixOwnsColStarts(A) = 0;
868 hypre_ParCSRMatrixOwnsColStarts(A) = 1;
876 for (
int j = 0; j < size; j++)
878 diag(j) = A->diag->data[A->diag->i[j]];
879 MFEM_ASSERT(A->diag->j[A->diag->i[j]] == j,
880 "the first entry in each row must be the diagonal one");
884 static void MakeWrapper(
const hypre_CSRMatrix *mat,
SparseMatrix &wrapper)
886 HYPRE_Int nr = hypre_CSRMatrixNumRows(mat);
887 HYPRE_Int nc = hypre_CSRMatrixNumCols(mat);
890 hypre_CSRMatrixJ(mat),
891 hypre_CSRMatrixData(mat),
892 nr, nc,
false,
false,
false);
894 HYPRE_Int nnz = hypre_CSRMatrixNumNonzeros(mat);
895 SparseMatrix tmp(DuplicateAs<int>(hypre_CSRMatrixI(mat), nr+1),
896 DuplicateAs<int>(hypre_CSRMatrixJ(mat), nnz),
897 hypre_CSRMatrixData(mat),
898 nr, nc,
true,
false,
false);
905 MakeWrapper(A->diag, diag);
910 MakeWrapper(A->offd, offd);
911 cmap = A->col_map_offd;
915 bool interleaved_rows,
916 bool interleaved_cols)
const
921 hypre_ParCSRMatrix **hypre_blocks =
new hypre_ParCSRMatrix*[nr * nc];
922 internal::hypre_ParCSRMatrixSplit(A, nr, nc, hypre_blocks,
923 interleaved_rows, interleaved_cols);
925 for (
int i = 0; i < nr; i++)
927 for (
int j = 0; j < nc; j++)
933 delete [] hypre_blocks;
938 hypre_ParCSRMatrix * At;
939 hypre_ParCSRMatrixTranspose(A, &At, 1);
940 hypre_ParCSRMatrixSetNumNonzeros(At);
942 hypre_MatvecCommPkgCreate(At);
950 return hypre_ParCSRMatrixMatvec(a, A, x, b, y);
955 MFEM_ASSERT(x.
Size() ==
Width(),
"invalid x.Size() = " << x.
Size()
956 <<
", expected size = " <<
Width());
957 MFEM_ASSERT(y.
Size() ==
Height(),
"invalid y.Size() = " << y.
Size()
958 <<
", expected size = " <<
Height());
977 hypre_ParCSRMatrixMatvec(a, A, *X, b, *Y);
981 double b,
Vector &y)
const
983 MFEM_ASSERT(x.
Size() ==
Height(),
"invalid x.Size() = " << x.
Size()
984 <<
", expected size = " <<
Height());
985 MFEM_ASSERT(y.
Size() ==
Width(),
"invalid y.Size() = " << y.
Size()
986 <<
", expected size = " <<
Width());
1007 hypre_ParCSRMatrixMatvecT(a, A, *Y, b, *X);
1013 return hypre_ParCSRMatrixMatvec(a, A, (hypre_ParVector *) x, b,
1014 (hypre_ParVector *) y);
1020 return hypre_ParCSRMatrixMatvecT(a, A, x, b, y);
1024 HYPRE_Int* row_starts)
const
1026 const bool assumed_partition = HYPRE_AssumedPartitionCheck();
1027 if (row_starts == NULL)
1029 row_starts = hypre_ParCSRMatrixRowStarts(A);
1030 MFEM_VERIFY(D.
Height() == hypre_CSRMatrixNumRows(A->diag),
1031 "the matrix D is NOT compatible with the row starts of"
1032 " this HypreParMatrix, row_starts must be given.");
1037 if (assumed_partition)
1043 MPI_Comm_rank(
GetComm(), &offset);
1045 int local_num_rows = row_starts[offset+1]-row_starts[offset];
1046 MFEM_VERIFY(local_num_rows == D.
Height(),
"the number of rows in D is "
1047 " not compatible with the given row_starts");
1053 HYPRE_Int global_num_rows;
1054 if (assumed_partition)
1057 global_num_rows = row_starts[2];
1064 MPI_Comm_size(
GetComm(), &part_size);
1065 global_num_rows = row_starts[part_size];
1069 HYPRE_Int *col_starts = hypre_ParCSRMatrixColStarts(A);
1070 HYPRE_Int *col_map_offd;
1075 GetOffd(A_offd, col_map_offd);
1083 global_num_rows, hypre_ParCSRMatrixGlobalNumCols(A),
1084 DuplicateAs<HYPRE_Int>(row_starts, part_size,
false),
1085 DuplicateAs<HYPRE_Int>(col_starts, part_size,
false),
1087 DuplicateAs<HYPRE_Int>(col_map_offd, A_offd.
Width()));
1092 #ifndef HYPRE_BIGINT
1103 hypre_ParCSRMatrixSetRowStartsOwner(DA->A, 1);
1104 hypre_ParCSRMatrixSetColStartsOwner(DA->A, 1);
1106 DA->diagOwner = DA->offdOwner = 3;
1107 DA->colMapOwner = 1;
1114 if (hypre_CSRMatrixNumRows(A->diag) != hypre_CSRMatrixNumRows(A->offd))
1119 if (hypre_CSRMatrixNumRows(A->diag) != diag.
Size())
1121 mfem_error(
"Note the Vector diag is not of compatible dimensions with A\n");
1125 double *Adiag_data = hypre_CSRMatrixData(A->diag);
1126 HYPRE_Int *Adiag_i = hypre_CSRMatrixI(A->diag);
1129 double *Aoffd_data = hypre_CSRMatrixData(A->offd);
1130 HYPRE_Int *Aoffd_i = hypre_CSRMatrixI(A->offd);
1133 for (
int i(0); i < size; ++i)
1136 for (jj = Adiag_i[i]; jj < Adiag_i[i+1]; ++jj)
1138 Adiag_data[jj] *= val;
1140 for (jj = Aoffd_i[i]; jj < Aoffd_i[i+1]; ++jj)
1142 Aoffd_data[jj] *= val;
1149 if (hypre_CSRMatrixNumRows(A->diag) != hypre_CSRMatrixNumRows(A->offd))
1154 if (hypre_CSRMatrixNumRows(A->diag) != diag.
Size())
1156 mfem_error(
"Note the Vector diag is not of compatible dimensions with A\n");
1160 double *Adiag_data = hypre_CSRMatrixData(A->diag);
1161 HYPRE_Int *Adiag_i = hypre_CSRMatrixI(A->diag);
1164 double *Aoffd_data = hypre_CSRMatrixData(A->offd);
1165 HYPRE_Int *Aoffd_i = hypre_CSRMatrixI(A->offd);
1168 for (
int i(0); i < size; ++i)
1173 mfem_error(
"HypreParMatrix::InvDiagScale : Division by 0");
1177 for (jj = Adiag_i[i]; jj < Adiag_i[i+1]; ++jj)
1179 Adiag_data[jj] *= val;
1181 for (jj = Aoffd_i[i]; jj < Aoffd_i[i+1]; ++jj)
1183 Aoffd_data[jj] *= val;
1190 if (hypre_CSRMatrixNumRows(A->diag) != hypre_CSRMatrixNumRows(A->offd))
1195 HYPRE_Int size=hypre_CSRMatrixNumRows(A->diag);
1198 double *Adiag_data = hypre_CSRMatrixData(A->diag);
1199 HYPRE_Int *Adiag_i = hypre_CSRMatrixI(A->diag);
1200 for (jj = 0; jj < Adiag_i[size]; ++jj)
1202 Adiag_data[jj] *= s;
1205 double *Aoffd_data = hypre_CSRMatrixData(A->offd);
1206 HYPRE_Int *Aoffd_i = hypre_CSRMatrixI(A->offd);
1207 for (jj = 0; jj < Aoffd_i[size]; ++jj)
1209 Aoffd_data[jj] *= s;
1213 static void get_sorted_rows_cols(
const Array<int> &rows_cols,
1218 for (
int i = 0; i < rows_cols.
Size(); i++)
1220 hypre_sorted[i] = rows_cols[i];
1221 if (i && rows_cols[i-1] > rows_cols[i]) { sorted =
false; }
1223 if (!sorted) { hypre_sorted.
Sort(); }
1231 hypre_CSRMatrix * csr_A;
1232 hypre_CSRMatrix * csr_A_wo_z;
1233 hypre_ParCSRMatrix * parcsr_A_ptr;
1234 HYPRE_Int * row_starts = NULL; HYPRE_Int * col_starts = NULL;
1235 HYPRE_Int row_start = -1; HYPRE_Int row_end = -1;
1236 HYPRE_Int col_start = -1; HYPRE_Int col_end = -1;
1238 comm = hypre_ParCSRMatrixComm(A);
1240 ierr += hypre_ParCSRMatrixGetLocalRange(A,
1241 &row_start,&row_end,
1242 &col_start,&col_end );
1244 row_starts = hypre_ParCSRMatrixRowStarts(A);
1245 col_starts = hypre_ParCSRMatrixColStarts(A);
1247 bool old_owns_row = hypre_ParCSRMatrixOwnsRowStarts(A);
1248 bool old_owns_col = hypre_ParCSRMatrixOwnsColStarts(A);
1249 HYPRE_Int global_num_rows = hypre_ParCSRMatrixGlobalNumRows(A);
1250 HYPRE_Int global_num_cols = hypre_ParCSRMatrixGlobalNumCols(A);
1251 parcsr_A_ptr = hypre_ParCSRMatrixCreate(comm, global_num_rows,
1253 row_starts, col_starts,
1255 hypre_ParCSRMatrixOwnsRowStarts(parcsr_A_ptr) = old_owns_row;
1256 hypre_ParCSRMatrixOwnsColStarts(parcsr_A_ptr) = old_owns_col;
1258 csr_A = hypre_MergeDiagAndOffd(A);
1260 csr_A_wo_z = hypre_CSRMatrixDeleteZeros(csr_A,threshold);
1264 if (csr_A_wo_z == NULL)
1270 ierr += hypre_CSRMatrixDestroy(csr_A);
1276 ierr += GenerateDiagAndOffd(csr_A_wo_z,parcsr_A_ptr,
1279 ierr += hypre_CSRMatrixDestroy(csr_A_wo_z);
1281 ierr += hypre_ParCSRMatrixDestroy(A);
1291 get_sorted_rows_cols(rows_cols, rc_sorted);
1293 internal::hypre_ParCSRMatrixEliminateAXB(
1300 get_sorted_rows_cols(rows_cols, rc_sorted);
1302 hypre_ParCSRMatrix* Ae;
1303 internal::hypre_ParCSRMatrixEliminateAAe(
1311 hypre_ParCSRMatrixPrintIJ(A,offi,offj,fname);
1319 HYPRE_Int base_i, base_j;
1320 hypre_ParCSRMatrixReadIJ(comm, fname, &base_i, &base_j, &A);
1321 hypre_ParCSRMatrixSetNumNonzeros(A);
1323 hypre_MatvecCommPkgCreate(A);
1334 HYPRE_IJMatrix A_ij;
1335 HYPRE_IJMatrixRead(fname, comm, 5555, &A_ij);
1337 HYPRE_ParCSRMatrix A_parcsr;
1338 HYPRE_IJMatrixGetObject(A_ij, (
void**) &A_parcsr);
1340 A = (hypre_ParCSRMatrix*)A_parcsr;
1342 hypre_ParCSRMatrixSetNumNonzeros(A);
1344 hypre_MatvecCommPkgCreate(A);
1352 hypre_ParCSRCommPkg *comm_pkg = A->comm_pkg;
1353 MPI_Comm comm = A->comm;
1355 const int tag = 46801;
1357 MPI_Comm_rank(comm, &myid);
1358 MPI_Comm_size(comm, &nproc);
1362 MPI_Recv(&c, 1, MPI_CHAR, myid-1, tag, comm, MPI_STATUS_IGNORE);
1366 out <<
"\nHypreParMatrix: hypre_ParCSRCommPkg:\n";
1368 out <<
"Rank " << myid <<
":\n"
1369 " number of sends = " << comm_pkg->num_sends <<
1370 " (" <<
sizeof(double)*comm_pkg->send_map_starts[comm_pkg->num_sends] <<
1372 " number of recvs = " << comm_pkg->num_recvs <<
1373 " (" <<
sizeof(
double)*comm_pkg->recv_vec_starts[comm_pkg->num_recvs] <<
1375 if (myid != nproc-1)
1378 MPI_Send(&c, 1, MPI_CHAR, myid+1, tag, comm);
1387 void HypreParMatrix::Destroy()
1389 if ( X != NULL ) {
delete X; }
1390 if ( Y != NULL ) {
delete Y; }
1392 if (A == NULL) {
return; }
1398 delete [] hypre_CSRMatrixI(A->diag);
1399 delete [] hypre_CSRMatrixJ(A->diag);
1401 hypre_CSRMatrixI(A->diag) = NULL;
1402 hypre_CSRMatrixJ(A->diag) = NULL;
1405 delete [] hypre_CSRMatrixData(A->diag);
1407 hypre_CSRMatrixData(A->diag) = NULL;
1413 delete [] hypre_CSRMatrixI(A->offd);
1414 delete [] hypre_CSRMatrixJ(A->offd);
1416 hypre_CSRMatrixI(A->offd) = NULL;
1417 hypre_CSRMatrixJ(A->offd) = NULL;
1420 delete [] hypre_CSRMatrixData(A->offd);
1422 hypre_CSRMatrixData(A->offd) = NULL;
1424 if (colMapOwner >= 0)
1426 if (colMapOwner & 1)
1428 delete [] hypre_ParCSRMatrixColMapOffd(A);
1430 hypre_ParCSRMatrixColMapOffd(A) = NULL;
1435 hypre_ParCSRMatrixDestroy(A);
1442 hypre_ParCSRMatrix *C_hypre =
1443 internal::hypre_ParCSRMatrixAdd(const_cast<HypreParMatrix &>(A),
1444 const_cast<HypreParMatrix &>(B));
1445 MFEM_VERIFY(C_hypre,
"error in hypre_ParCSRMatrixAdd");
1447 hypre_MatvecCommPkgCreate(C_hypre);
1458 hypre_ParCSRMatrix * ab;
1459 ab = hypre_ParMatmul(*A,*B);
1460 hypre_ParCSRMatrixSetNumNonzeros(ab);
1462 hypre_MatvecCommPkgCreate(ab);
1469 hypre_ParCSRMatrix * C = internal::hypre_ParCSRMatrixAdd(*A,*B);
1471 hypre_MatvecCommPkgCreate(C);
1478 HYPRE_Int P_owns_its_col_starts =
1479 hypre_ParCSRMatrixOwnsColStarts((hypre_ParCSRMatrix*)(*P));
1481 hypre_ParCSRMatrix * rap;
1482 hypre_BoomerAMGBuildCoarseOperator(*P,*A,*P,&rap);
1483 hypre_ParCSRMatrixSetNumNonzeros(rap);
1488 hypre_ParCSRMatrixSetRowStartsOwner(rap,0);
1489 hypre_ParCSRMatrixSetColStartsOwner(rap,0);
1491 if (P_owns_its_col_starts)
1493 hypre_ParCSRMatrixSetColStartsOwner(*P, 1);
1502 HYPRE_Int P_owns_its_col_starts =
1503 hypre_ParCSRMatrixOwnsColStarts((hypre_ParCSRMatrix*)(*P));
1504 HYPRE_Int Rt_owns_its_col_starts =
1505 hypre_ParCSRMatrixOwnsColStarts((hypre_ParCSRMatrix*)(*Rt));
1507 hypre_ParCSRMatrix * rap;
1508 hypre_BoomerAMGBuildCoarseOperator(*Rt,*A,*P,&rap);
1510 hypre_ParCSRMatrixSetNumNonzeros(rap);
1515 hypre_ParCSRMatrixSetRowStartsOwner(rap,0);
1516 hypre_ParCSRMatrixSetColStartsOwner(rap,0);
1518 if (P_owns_its_col_starts)
1520 hypre_ParCSRMatrixSetColStartsOwner(*P, 1);
1522 if (Rt_owns_its_col_starts)
1524 hypre_ParCSRMatrixSetColStartsOwner(*Rt, 1);
1535 Ae.
Mult(-1.0, X, 1.0, B);
1537 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag((hypre_ParCSRMatrix *)A);
1538 double *data = hypre_CSRMatrixData(A_diag);
1539 HYPRE_Int *I = hypre_CSRMatrixI(A_diag);
1541 HYPRE_Int *J = hypre_CSRMatrixJ(A_diag);
1542 hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd((hypre_ParCSRMatrix *)A);
1543 HYPRE_Int *I_offd = hypre_CSRMatrixI(A_offd);
1544 double *data_offd = hypre_CSRMatrixData(A_offd);
1547 for (
int i = 0; i < ess_dof_list.
Size(); i++)
1549 int r = ess_dof_list[i];
1550 B(r) = data[I[r]] * X(r);
1557 MFEM_ABORT(
"the diagonal entry must be the first entry in the row!");
1559 for (
int j = I[r]+1; j < I[r+1]; j++)
1563 MFEM_ABORT(
"all off-diagonal entries must be zero!");
1566 for (
int j = I_offd[r]; j < I_offd[r+1]; j++)
1568 if (data_offd[j] != 0.0)
1570 MFEM_ABORT(
"all off-diagonal entries must be zero!");
1590 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1591 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A_diag);
1593 double *u_data = hypre_VectorData(hypre_ParVectorLocalVector(u));
1594 double *r_data = hypre_VectorData(hypre_ParVectorLocalVector(r));
1596 for (
int i = 0; i < N; i++)
1599 hypre_ParVectorCopy(f, r);
1600 hypre_ParCSRMatrixMatvec(-1.0, A, u, 1.0, r);
1603 (0 == (i % 2)) ? coef = lambda : coef = mu;
1605 for (HYPRE_Int j = 0; j < num_rows; j++)
1607 u_data[j] += coef*r_data[j] / max_eig;
1623 hypre_ParVector *x0,
1624 hypre_ParVector *x1,
1625 hypre_ParVector *x2,
1626 hypre_ParVector *x3)
1629 hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A);
1630 HYPRE_Int num_rows = hypre_CSRMatrixNumRows(A_diag);
1632 double *u_data = hypre_VectorData(hypre_ParVectorLocalVector(u));
1634 double *x0_data = hypre_VectorData(hypre_ParVectorLocalVector(x0));
1635 double *x1_data = hypre_VectorData(hypre_ParVectorLocalVector(x1));
1636 double *x2_data = hypre_VectorData(hypre_ParVectorLocalVector(x2));
1637 double *x3_data = hypre_VectorData(hypre_ParVectorLocalVector(x3));
1639 hypre_ParVectorCopy(u, x0);
1642 hypre_ParVectorCopy(f, x1);
1643 hypre_ParCSRMatrixMatvec(-1.0, A, x0, 1.0, x1);
1645 for (HYPRE_Int i = 0; i < num_rows; i++)
1647 x1_data[i] /= -max_eig;
1651 for (HYPRE_Int i = 0; i < num_rows; i++)
1653 x1_data[i] = x0_data[i] -x1_data[i];
1657 for (HYPRE_Int i = 0; i < num_rows; i++)
1659 x3_data[i] = fir_coeffs[0]*x0_data[i] +fir_coeffs[1]*x1_data[i];
1662 for (
int n = 2; n <= poly_order; n++)
1665 hypre_ParVectorCopy(f, x2);
1666 hypre_ParCSRMatrixMatvec(-1.0, A, x1, 1.0, x2);
1668 for (HYPRE_Int i = 0; i < num_rows; i++)
1670 x2_data[i] /= -max_eig;
1678 for (HYPRE_Int i = 0; i < num_rows; i++)
1680 x2_data[i] = (x1_data[i]-x0_data[i]) +(x1_data[i]-2*x2_data[i]);
1681 x3_data[i] += fir_coeffs[n]*x2_data[i];
1682 x0_data[i] = x1_data[i];
1683 x1_data[i] = x2_data[i];
1687 for (HYPRE_Int i = 0; i < num_rows; i++)
1689 u_data[i] = x3_data[i];
1709 B =
X =
V =
Z = NULL;
1715 int _relax_times,
double _relax_weight,
double _omega,
1716 int _poly_order,
double _poly_fraction)
1727 B =
X =
V =
Z = NULL;
1736 type =
static_cast<int>(_type);
1762 double a = -1, b, c;
1763 if (!strcmp(name,
"Rectangular")) { a = 1.0, b = 0.0, c = 0.0; }
1764 if (!strcmp(name,
"Hanning")) { a = 0.5, b = 0.5, c = 0.0; }
1765 if (!strcmp(name,
"Hamming")) { a = 0.54, b = 0.46, c = 0.0; }
1766 if (!strcmp(name,
"Blackman")) { a = 0.42, b = 0.50, c = 0.08; }
1769 mfem_error(
"HypreSmoother::SetWindowByName : name not recognized!");
1787 mfem_error(
"HypreSmoother::SetOperator : not HypreParMatrix!");
1793 if (
B) {
delete B; }
1794 if (
X) {
delete X; }
1795 if (
V) {
delete V; }
1796 if (
Z) {
delete Z; }
1815 A->
Mult(ones, diag);
1824 for (
int i = 0; i <
height; i++)
1837 else if (
type == 1001 ||
type == 1002)
1868 double* window_coeffs =
new double[
poly_order+1];
1869 double* cheby_coeffs =
new double[
poly_order+1];
1877 window_coeffs[i] = a + b*cos(t) +c*cos(2*t);
1881 double theta_pb = acos(1.0 -0.5*k_pb);
1883 cheby_coeffs[0] = (theta_pb +sigma)/M_PI;
1886 double t = i*(theta_pb+sigma);
1887 cheby_coeffs[i] = 2.0*sin(t)/(i*M_PI);
1892 fir_coeffs[i] = window_coeffs[i]*cheby_coeffs[i];
1895 delete[] window_coeffs;
1896 delete[] cheby_coeffs;
1903 mfem_error(
"HypreSmoother::Mult (...) : HypreParMatrix A is missing");
1911 HYPRE_ParCSRDiagScale(NULL, *
A, b, x);
1935 else if (
type == 1002)
1950 hypre_ParCSRRelax(*
A, b,
type,
1955 hypre_ParCSRRelax(*
A, b,
type,
1966 mfem_error(
"HypreSmoother::Mult (...) : HypreParMatrix A is missing");
1972 A -> GetGlobalNumRows(),
1974 A -> GetRowStarts());
1976 A -> GetGlobalNumCols(),
1978 A -> GetColStarts());
1991 if (
B) {
delete B; }
1992 if (
X) {
delete X; }
1993 if (
V) {
delete V; }
1994 if (
Z) {
delete Z; }
2003 if (
X0) {
delete X0; }
2004 if (
X1) {
delete X1; }
2016 :
Solver(_A->Height(), _A->Width())
2027 mfem_error(
"HypreSolver::Mult (...) : HypreParMatrix A is missing");
2047 mfem_error(
"HypreSolver::Mult (...) : HypreParMatrix A is missing");
2053 A -> GetGlobalNumRows(),
2055 A -> GetRowStarts());
2057 A -> GetGlobalNumCols(),
2059 A -> GetColStarts());
2072 if (
B) {
delete B; }
2073 if (
X) {
delete X; }
2083 HYPRE_ParCSRMatrixGetComm(*
A, &comm);
2085 HYPRE_ParCSRPCGCreate(comm, &pcg_solver);
2090 HYPRE_PCGSetTol(pcg_solver, tol);
2095 HYPRE_PCGSetMaxIter(pcg_solver, max_iter);
2100 HYPRE_PCGSetLogging(pcg_solver, logging);
2105 HYPRE_ParCSRPCGSetPrintLevel(pcg_solver, print_lvl);
2110 HYPRE_ParCSRPCGSetPrecond(pcg_solver,
2118 HYPRE_PCGSetTwoNorm(pcg_solver, 1);
2119 if (res_frequency > 0)
2121 HYPRE_PCGSetRecomputeResidualP(pcg_solver, res_frequency);
2125 HYPRE_PCGSetResidualTol(pcg_solver, rtol);
2132 HYPRE_Int time_index = 0;
2133 HYPRE_Int num_iterations;
2134 double final_res_norm;
2136 HYPRE_Int print_level;
2138 HYPRE_PCGGetPrintLevel(pcg_solver, &print_level);
2139 HYPRE_ParCSRPCGSetPrintLevel(pcg_solver, print_level%3);
2141 HYPRE_ParCSRMatrixGetComm(*
A, &comm);
2145 if (print_level > 0 && print_level < 3)
2147 time_index = hypre_InitializeTiming(
"PCG Setup");
2148 hypre_BeginTiming(time_index);
2151 HYPRE_ParCSRPCGSetup(pcg_solver, *
A, b, x);
2154 if (print_level > 0 && print_level < 3)
2156 hypre_EndTiming(time_index);
2157 hypre_PrintTiming(
"Setup phase times", comm);
2158 hypre_FinalizeTiming(time_index);
2159 hypre_ClearTiming();
2163 if (print_level > 0 && print_level < 3)
2165 time_index = hypre_InitializeTiming(
"PCG Solve");
2166 hypre_BeginTiming(time_index);
2174 HYPRE_ParCSRPCGSolve(pcg_solver, *
A, b, x);
2176 if (print_level > 0)
2178 if (print_level < 3)
2180 hypre_EndTiming(time_index);
2181 hypre_PrintTiming(
"Solve phase times", comm);
2182 hypre_FinalizeTiming(time_index);
2183 hypre_ClearTiming();
2186 HYPRE_ParCSRPCGGetNumIterations(pcg_solver, &num_iterations);
2187 HYPRE_ParCSRPCGGetFinalRelativeResidualNorm(pcg_solver,
2190 MPI_Comm_rank(comm, &myid);
2194 mfem::out <<
"PCG Iterations = " << num_iterations << endl
2195 <<
"Final PCG Relative Residual Norm = " << final_res_norm
2199 HYPRE_ParCSRPCGSetPrintLevel(pcg_solver, print_level);
2204 HYPRE_ParCSRPCGDestroy(pcg_solver);
2218 HYPRE_ParCSRMatrixGetComm(*
A, &comm);
2220 HYPRE_ParCSRGMRESCreate(comm, &gmres_solver);
2221 HYPRE_ParCSRGMRESSetKDim(gmres_solver, k_dim);
2222 HYPRE_ParCSRGMRESSetMaxIter(gmres_solver, max_iter);
2223 HYPRE_ParCSRGMRESSetTol(gmres_solver, tol);
2228 HYPRE_GMRESSetTol(gmres_solver, tol);
2233 HYPRE_GMRESSetMaxIter(gmres_solver, max_iter);
2238 HYPRE_GMRESSetKDim(gmres_solver, k_dim);
2243 HYPRE_GMRESSetLogging(gmres_solver, logging);
2248 HYPRE_GMRESSetPrintLevel(gmres_solver, print_lvl);
2253 HYPRE_ParCSRGMRESSetPrecond(gmres_solver,
2262 HYPRE_Int time_index = 0;
2263 HYPRE_Int num_iterations;
2264 double final_res_norm;
2266 HYPRE_Int print_level;
2268 HYPRE_GMRESGetPrintLevel(gmres_solver, &print_level);
2270 HYPRE_ParCSRMatrixGetComm(*
A, &comm);
2274 if (print_level > 0)
2276 time_index = hypre_InitializeTiming(
"GMRES Setup");
2277 hypre_BeginTiming(time_index);
2280 HYPRE_ParCSRGMRESSetup(gmres_solver, *
A, b, x);
2283 if (print_level > 0)
2285 hypre_EndTiming(time_index);
2286 hypre_PrintTiming(
"Setup phase times", comm);
2287 hypre_FinalizeTiming(time_index);
2288 hypre_ClearTiming();
2292 if (print_level > 0)
2294 time_index = hypre_InitializeTiming(
"GMRES Solve");
2295 hypre_BeginTiming(time_index);
2303 HYPRE_ParCSRGMRESSolve(gmres_solver, *
A, b, x);
2305 if (print_level > 0)
2307 hypre_EndTiming(time_index);
2308 hypre_PrintTiming(
"Solve phase times", comm);
2309 hypre_FinalizeTiming(time_index);
2310 hypre_ClearTiming();
2312 HYPRE_ParCSRGMRESGetNumIterations(gmres_solver, &num_iterations);
2313 HYPRE_ParCSRGMRESGetFinalRelativeResidualNorm(gmres_solver,
2316 MPI_Comm_rank(comm, &myid);
2320 mfem::out <<
"GMRES Iterations = " << num_iterations << endl
2321 <<
"Final GMRES Relative Residual Norm = " << final_res_norm
2329 HYPRE_ParCSRGMRESDestroy(gmres_solver);
2337 int sai_max_levels = 1;
2338 double sai_threshold = 0.1;
2339 double sai_filter = 0.1;
2341 double sai_loadbal = 0.0;
2343 int sai_logging = 1;
2345 HYPRE_ParCSRMatrixGetComm(A, &comm);
2347 HYPRE_ParaSailsCreate(comm, &sai_precond);
2348 HYPRE_ParaSailsSetParams(sai_precond, sai_threshold, sai_max_levels);
2349 HYPRE_ParaSailsSetFilter(sai_precond, sai_filter);
2350 HYPRE_ParaSailsSetSym(sai_precond, sai_sym);
2351 HYPRE_ParaSailsSetLoadbal(sai_precond, sai_loadbal);
2352 HYPRE_ParaSailsSetReuse(sai_precond, sai_reuse);
2353 HYPRE_ParaSailsSetLogging(sai_precond, sai_logging);
2358 HYPRE_ParaSailsSetSym(sai_precond, sym);
2363 HYPRE_ParaSailsDestroy(sai_precond);
2369 HYPRE_BoomerAMGCreate(&amg_precond);
2370 SetDefaultOptions();
2375 HYPRE_BoomerAMGCreate(&amg_precond);
2376 SetDefaultOptions();
2379 void HypreBoomerAMG::SetDefaultOptions()
2382 int coarsen_type = 10;
2384 double theta = 0.25;
2387 int interp_type = 6;
2392 int relax_sweeps = 1;
2395 int print_level = 1;
2396 int max_levels = 25;
2398 HYPRE_BoomerAMGSetCoarsenType(amg_precond, coarsen_type);
2399 HYPRE_BoomerAMGSetAggNumLevels(amg_precond, agg_levels);
2400 HYPRE_BoomerAMGSetRelaxType(amg_precond, relax_type);
2401 HYPRE_BoomerAMGSetNumSweeps(amg_precond, relax_sweeps);
2402 HYPRE_BoomerAMGSetStrongThreshold(amg_precond, theta);
2403 HYPRE_BoomerAMGSetInterpType(amg_precond, interp_type);
2404 HYPRE_BoomerAMGSetPMaxElmts(amg_precond, Pmax);
2405 HYPRE_BoomerAMGSetPrintLevel(amg_precond, print_level);
2406 HYPRE_BoomerAMGSetMaxLevels(amg_precond, max_levels);
2409 HYPRE_BoomerAMGSetMaxIter(amg_precond, 1);
2410 HYPRE_BoomerAMGSetTol(amg_precond, 0.0);
2413 void HypreBoomerAMG::ResetAMGPrecond()
2415 HYPRE_Int coarsen_type;
2416 HYPRE_Int agg_levels;
2417 HYPRE_Int relax_type;
2418 HYPRE_Int relax_sweeps;
2420 HYPRE_Int interp_type;
2422 HYPRE_Int print_level;
2424 HYPRE_Int nrbms = rbms.
Size();
2426 HYPRE_Int nodal_diag;
2427 HYPRE_Int relax_coarse;
2428 HYPRE_Int interp_vec_variant;
2430 HYPRE_Int smooth_interp_vectors;
2431 HYPRE_Int interp_refine;
2433 hypre_ParAMGData *amg_data = (hypre_ParAMGData *)amg_precond;
2436 HYPRE_BoomerAMGGetCoarsenType(amg_precond, &coarsen_type);
2437 agg_levels = hypre_ParAMGDataAggNumLevels(amg_data);
2438 relax_type = hypre_ParAMGDataUserRelaxType(amg_data);
2439 relax_sweeps = hypre_ParAMGDataUserNumSweeps(amg_data);
2440 HYPRE_BoomerAMGGetStrongThreshold(amg_precond, &theta);
2441 hypre_BoomerAMGGetInterpType(amg_precond, &interp_type);
2442 HYPRE_BoomerAMGGetPMaxElmts(amg_precond, &Pmax);
2443 HYPRE_BoomerAMGGetPrintLevel(amg_precond, &print_level);
2444 HYPRE_BoomerAMGGetNumFunctions(amg_precond, &dim);
2447 nodal = hypre_ParAMGDataNodal(amg_data);
2448 nodal_diag = hypre_ParAMGDataNodalDiag(amg_data);
2449 HYPRE_BoomerAMGGetCycleRelaxType(amg_precond, &relax_coarse, 3);
2450 interp_vec_variant = hypre_ParAMGInterpVecVariant(amg_data);
2451 q_max = hypre_ParAMGInterpVecQMax(amg_data);
2452 smooth_interp_vectors = hypre_ParAMGSmoothInterpVectors(amg_data);
2453 interp_refine = hypre_ParAMGInterpRefine(amg_data);
2456 HYPRE_BoomerAMGDestroy(amg_precond);
2457 HYPRE_BoomerAMGCreate(&amg_precond);
2459 HYPRE_BoomerAMGSetCoarsenType(amg_precond, coarsen_type);
2460 HYPRE_BoomerAMGSetAggNumLevels(amg_precond, agg_levels);
2461 HYPRE_BoomerAMGSetRelaxType(amg_precond, relax_type);
2462 HYPRE_BoomerAMGSetNumSweeps(amg_precond, relax_sweeps);
2463 HYPRE_BoomerAMGSetMaxLevels(amg_precond, 25);
2464 HYPRE_BoomerAMGSetTol(amg_precond, 0.0);
2465 HYPRE_BoomerAMGSetMaxIter(amg_precond, 1);
2466 HYPRE_BoomerAMGSetStrongThreshold(amg_precond, theta);
2467 HYPRE_BoomerAMGSetInterpType(amg_precond, interp_type);
2468 HYPRE_BoomerAMGSetPMaxElmts(amg_precond, Pmax);
2469 HYPRE_BoomerAMGSetPrintLevel(amg_precond, print_level);
2470 HYPRE_BoomerAMGSetNumFunctions(amg_precond, dim);
2473 HYPRE_BoomerAMGSetNodal(amg_precond, nodal);
2474 HYPRE_BoomerAMGSetNodalDiag(amg_precond, nodal_diag);
2475 HYPRE_BoomerAMGSetCycleRelaxType(amg_precond, relax_coarse, 3);
2476 HYPRE_BoomerAMGSetInterpVecVariant(amg_precond, interp_vec_variant);
2477 HYPRE_BoomerAMGSetInterpVecQMax(amg_precond, q_max);
2478 HYPRE_BoomerAMGSetSmoothInterpVectors(amg_precond, smooth_interp_vectors);
2479 HYPRE_BoomerAMGSetInterpRefine(amg_precond, interp_refine);
2481 HYPRE_BoomerAMGSetInterpVectors(amg_precond, rbms.
Size(), rbms.
GetData());
2488 MFEM_VERIFY(new_A,
"new Operator must be a HypreParMatrix!");
2490 if (
A) { ResetAMGPrecond(); }
2504 HYPRE_BoomerAMGSetNumFunctions(amg_precond, dim);
2507 HYPRE_BoomerAMGSetAggNumLevels(amg_precond, 0);
2508 HYPRE_BoomerAMGSetStrongThreshold(amg_precond, 0.5);
2514 y = 0.0; y(0) = x(1); y(1) = -x(0);
2516 static void func_ryz(
const Vector &x, Vector &y)
2518 y = 0.0; y(1) = x(2); y(2) = -x(1);
2520 static void func_rzx(
const Vector &x, Vector &y)
2522 y = 0.0; y(2) = x(0); y(0) = -x(2);
2525 void HypreBoomerAMG::RecomputeRBMs()
2528 Array<HypreParVector*> gf_rbms;
2531 for (
int i = 0; i < rbms.
Size(); i++)
2533 HYPRE_ParVectorDestroy(rbms[i]);
2540 VectorFunctionCoefficient coeff_rxy(2, func_rxy);
2542 ParGridFunction rbms_rxy(fespace);
2543 rbms_rxy.ProjectCoefficient(coeff_rxy);
2546 gf_rbms.SetSize(nrbms);
2547 gf_rbms[0] = rbms_rxy.ParallelAverage();
2553 VectorFunctionCoefficient coeff_rxy(3, func_rxy);
2554 VectorFunctionCoefficient coeff_ryz(3, func_ryz);
2555 VectorFunctionCoefficient coeff_rzx(3, func_rzx);
2557 ParGridFunction rbms_rxy(fespace);
2558 ParGridFunction rbms_ryz(fespace);
2559 ParGridFunction rbms_rzx(fespace);
2560 rbms_rxy.ProjectCoefficient(coeff_rxy);
2561 rbms_ryz.ProjectCoefficient(coeff_ryz);
2562 rbms_rzx.ProjectCoefficient(coeff_rzx);
2565 gf_rbms.SetSize(nrbms);
2566 gf_rbms[0] = rbms_rxy.ParallelAverage();
2567 gf_rbms[1] = rbms_ryz.ParallelAverage();
2568 gf_rbms[2] = rbms_rzx.ParallelAverage();
2577 for (
int i = 0; i < nrbms; i++)
2579 rbms[i] = gf_rbms[i]->StealParVector();
2587 this->fespace = fespace;
2597 int relax_coarse = 8;
2600 int interp_vec_variant = 2;
2602 int smooth_interp_vectors = 1;
2606 int interp_refine = 1;
2608 HYPRE_BoomerAMGSetNodal(amg_precond, nodal);
2609 HYPRE_BoomerAMGSetNodalDiag(amg_precond, nodal_diag);
2610 HYPRE_BoomerAMGSetCycleRelaxType(amg_precond, relax_coarse, 3);
2611 HYPRE_BoomerAMGSetInterpVecVariant(amg_precond, interp_vec_variant);
2612 HYPRE_BoomerAMGSetInterpVecQMax(amg_precond, q_max);
2613 HYPRE_BoomerAMGSetSmoothInterpVectors(amg_precond, smooth_interp_vectors);
2614 HYPRE_BoomerAMGSetInterpRefine(amg_precond, interp_refine);
2617 HYPRE_BoomerAMGSetInterpVectors(amg_precond, rbms.
Size(), rbms.
GetData());
2622 for (
int i = 0; i < rbms.
Size(); i++)
2624 HYPRE_ParVectorDestroy(rbms[i]);
2627 HYPRE_BoomerAMGDestroy(amg_precond);
2634 int cycle_type = 13;
2637 double rlx_weight = 1.0;
2638 double rlx_omega = 1.0;
2639 int amg_coarsen_type = 10;
2640 int amg_agg_levels = 1;
2641 int amg_rlx_type = 8;
2642 double theta = 0.25;
2643 int amg_interp_type = 6;
2650 bool trace_space, rt_trace_space;
2654 trace_space = trace_space || rt_trace_space;
2657 if (edge_fespace->
GetNE() > 0)
2662 if (dim == 2) { p++; }
2677 HYPRE_AMSCreate(&ams);
2679 HYPRE_AMSSetDimension(ams, sdim);
2680 HYPRE_AMSSetTol(ams, 0.0);
2681 HYPRE_AMSSetMaxIter(ams, 1);
2682 HYPRE_AMSSetCycleType(ams, cycle_type);
2683 HYPRE_AMSSetPrintLevel(ams, 1);
2705 for (
int i = 0; i < pmesh->
GetNV(); i++)
2707 coord = pmesh -> GetVertex(i);
2708 x_coord(i) = coord[0];
2709 y_coord(i) = coord[1];
2710 if (sdim == 3) { z_coord(i) = coord[2]; }
2717 HYPRE_AMSSetCoordinateVectors(ams, *x, *y, NULL);
2722 HYPRE_AMSSetCoordinateVectors(ams, *x, *y, *z);
2746 HYPRE_AMSSetDiscreteGradient(ams, *G);
2750 Pi = Pix = Piy = Piz = NULL;
2769 if (cycle_type < 10)
2777 Pix = Pi_blocks(0,0);
2778 Piy = Pi_blocks(0,1);
2779 if (sdim == 3) { Piz = Pi_blocks(0,2); }
2784 HYPRE_ParCSRMatrix HY_Pi = (Pi) ? (HYPRE_ParCSRMatrix) *Pi : NULL;
2785 HYPRE_ParCSRMatrix HY_Pix = (Pix) ? (HYPRE_ParCSRMatrix) *Pix : NULL;
2786 HYPRE_ParCSRMatrix HY_Piy = (Piy) ? (HYPRE_ParCSRMatrix) *Piy : NULL;
2787 HYPRE_ParCSRMatrix HY_Piz = (Piz) ? (HYPRE_ParCSRMatrix) *Piz : NULL;
2788 HYPRE_AMSSetInterpolations(ams, HY_Pi, HY_Pix, HY_Piy, HY_Piz);
2790 delete vert_fespace_d;
2793 delete vert_fespace;
2798 delete edge_fespace;
2803 HYPRE_AMSSetSmoothingOptions(ams, rlx_type, rlx_sweeps, rlx_weight, rlx_omega);
2804 HYPRE_AMSSetAlphaAMGOptions(ams, amg_coarsen_type, amg_agg_levels, amg_rlx_type,
2805 theta, amg_interp_type, amg_Pmax);
2806 HYPRE_AMSSetBetaAMGOptions(ams, amg_coarsen_type, amg_agg_levels, amg_rlx_type,
2807 theta, amg_interp_type, amg_Pmax);
2812 HYPRE_AMSDestroy(ams);
2827 HYPRE_AMSSetPrintLevel(ams, print_lvl);
2833 int cycle_type = 11;
2836 double rlx_weight = 1.0;
2837 double rlx_omega = 1.0;
2838 int amg_coarsen_type = 10;
2839 int amg_agg_levels = 1;
2840 int amg_rlx_type = 8;
2841 double theta = 0.25;
2842 int amg_interp_type = 6;
2844 int ams_cycle_type = 14;
2850 if (face_fespace->
GetNE() > 0)
2862 HYPRE_ADSCreate(&ads);
2864 HYPRE_ADSSetTol(ads, 0.0);
2865 HYPRE_ADSSetMaxIter(ads, 1);
2866 HYPRE_ADSSetCycleType(ads, cycle_type);
2867 HYPRE_ADSSetPrintLevel(ads, 1);
2895 for (
int i = 0; i < pmesh->
GetNV(); i++)
2897 coord = pmesh -> GetVertex(i);
2898 x_coord(i) = coord[0];
2899 y_coord(i) = coord[1];
2900 z_coord(i) = coord[2];
2905 HYPRE_ADSSetCoordinateVectors(ads, *x, *y, *z);
2929 HYPRE_ADSSetDiscreteCurl(ads, *C);
2948 HYPRE_ADSSetDiscreteGradient(ads, *G);
2952 RT_Pi = RT_Pix = RT_Piy = RT_Piz = NULL;
2953 ND_Pi = ND_Pix = ND_Piy = ND_Piz = NULL;
2972 if (ams_cycle_type < 10)
2982 ND_Pix = ND_Pi_blocks(0,0);
2983 ND_Piy = ND_Pi_blocks(0,1);
2984 ND_Piz = ND_Pi_blocks(0,2);
3002 if (cycle_type < 10)
3011 RT_Pix = RT_Pi_blocks(0,0);
3012 RT_Piy = RT_Pi_blocks(0,1);
3013 RT_Piz = RT_Pi_blocks(0,2);
3018 HYPRE_ParCSRMatrix HY_RT_Pi, HY_RT_Pix, HY_RT_Piy, HY_RT_Piz;
3019 HY_RT_Pi = (RT_Pi) ? (HYPRE_ParCSRMatrix) *RT_Pi : NULL;
3020 HY_RT_Pix = (RT_Pix) ? (HYPRE_ParCSRMatrix) *RT_Pix : NULL;
3021 HY_RT_Piy = (RT_Piy) ? (HYPRE_ParCSRMatrix) *RT_Piy : NULL;
3022 HY_RT_Piz = (RT_Piz) ? (HYPRE_ParCSRMatrix) *RT_Piz : NULL;
3023 HYPRE_ParCSRMatrix HY_ND_Pi, HY_ND_Pix, HY_ND_Piy, HY_ND_Piz;
3024 HY_ND_Pi = (ND_Pi) ? (HYPRE_ParCSRMatrix) *ND_Pi : NULL;
3025 HY_ND_Pix = (ND_Pix) ? (HYPRE_ParCSRMatrix) *ND_Pix : NULL;
3026 HY_ND_Piy = (ND_Piy) ? (HYPRE_ParCSRMatrix) *ND_Piy : NULL;
3027 HY_ND_Piz = (ND_Piz) ? (HYPRE_ParCSRMatrix) *ND_Piz : NULL;
3028 HYPRE_ADSSetInterpolations(ads,
3029 HY_RT_Pi, HY_RT_Pix, HY_RT_Piy, HY_RT_Piz,
3030 HY_ND_Pi, HY_ND_Pix, HY_ND_Piy, HY_ND_Piz);
3032 delete vert_fespace_d;
3036 delete vert_fespace;
3038 delete edge_fespace;
3041 HYPRE_ADSSetSmoothingOptions(ads, rlx_type, rlx_sweeps, rlx_weight, rlx_omega);
3042 HYPRE_ADSSetAMGOptions(ads, amg_coarsen_type, amg_agg_levels, amg_rlx_type,
3043 theta, amg_interp_type, amg_Pmax);
3044 HYPRE_ADSSetAMSOptions(ads, ams_cycle_type, amg_coarsen_type, amg_agg_levels,
3045 amg_rlx_type, theta, amg_interp_type, amg_Pmax);
3050 HYPRE_ADSDestroy(ads);
3072 HYPRE_ADSSetPrintLevel(ads, print_lvl);
3075 HypreLOBPCG::HypreMultiVector::HypreMultiVector(
int n,
HypreParVector & v,
3076 mv_InterfaceInterpreter & interpreter)
3080 mv_ptr = mv_MultiVectorCreateFromSampleVector(&interpreter, nv,
3081 (HYPRE_ParVector)v);
3083 HYPRE_ParVector* vecs = NULL;
3085 mv_TempMultiVector* tmp =
3086 (mv_TempMultiVector*)mv_MultiVectorGetData(mv_ptr);
3087 vecs = (HYPRE_ParVector*)(tmp -> vector);
3090 hpv =
new HypreParVector*[nv];
3091 for (
int i=0; i<nv; i++)
3093 hpv[i] =
new HypreParVector(vecs[i]);
3097 HypreLOBPCG::HypreMultiVector::~HypreMultiVector()
3101 for (
int i=0; i<nv; i++)
3108 mv_MultiVectorDestroy(mv_ptr);
3112 HypreLOBPCG::HypreMultiVector::Randomize(HYPRE_Int seed)
3114 mv_MultiVectorSetRandom(mv_ptr, seed);
3118 HypreLOBPCG::HypreMultiVector::GetVector(
unsigned int i)
3120 MFEM_ASSERT((
int)i < nv,
"index out of range");
3126 HypreLOBPCG::HypreMultiVector::StealVectors()
3128 HypreParVector ** hpv_ret = hpv;
3132 mv_TempMultiVector * mv_tmp =
3133 (mv_TempMultiVector*)mv_MultiVectorGetData(mv_ptr);
3135 mv_tmp->ownsVectors = 0;
3137 for (
int i=0; i<nv; i++)
3139 hpv_ret[i]->SetOwnership(1);
3157 MPI_Comm_size(comm,&numProcs);
3158 MPI_Comm_rank(comm,&myid);
3160 HYPRE_ParCSRSetupInterpreter(&interpreter);
3161 HYPRE_ParCSRSetupMatvec(&matvec_fn);
3162 HYPRE_LOBPCGCreate(&interpreter, &matvec_fn, &lobpcg_solver);
3171 HYPRE_LOBPCGDestroy(lobpcg_solver);
3177 HYPRE_LOBPCGSetTol(lobpcg_solver, tol);
3183 #if MFEM_HYPRE_VERSION >= 21101
3184 HYPRE_LOBPCGSetRTol(lobpcg_solver, rel_tol);
3186 MFEM_ABORT(
"This method requires HYPRE version >= 2.11.1");
3193 HYPRE_LOBPCGSetMaxIter(lobpcg_solver, max_iter);
3201 HYPRE_LOBPCGSetPrintLevel(lobpcg_solver, logging);
3208 HYPRE_LOBPCGSetPrecondUsageMode(lobpcg_solver, pcg_mode);
3214 HYPRE_LOBPCGSetPrecond(lobpcg_solver,
3215 (HYPRE_PtrToSolverFcn)this->PrecondSolve,
3216 (HYPRE_PtrToSolverFcn)this->PrecondSetup,
3217 (HYPRE_Solver)&precond);
3223 int locSize = A.
Width();
3225 if (HYPRE_AssumedPartitionCheck())
3227 part =
new HYPRE_Int[2];
3229 MPI_Scan(&locSize, &part[1], 1, HYPRE_MPI_INT, MPI_SUM, comm);
3231 part[0] = part[1] - locSize;
3233 MPI_Allreduce(&locSize, &glbSize, 1, HYPRE_MPI_INT, MPI_SUM, comm);
3237 part =
new HYPRE_Int[numProcs+1];
3239 MPI_Allgather(&locSize, 1, MPI_INT,
3240 &part[1], 1, HYPRE_MPI_INT, comm);
3243 for (
int i=0; i<numProcs; i++)
3245 part[i+1] += part[i];
3248 glbSize = part[numProcs];
3259 matvec_fn.MatvecCreate = this->OperatorMatvecCreate;
3260 matvec_fn.Matvec = this->OperatorMatvec;
3261 matvec_fn.MatvecDestroy = this->OperatorMatvecDestroy;
3263 HYPRE_LOBPCGSetup(lobpcg_solver,(HYPRE_Matrix)&A,NULL,NULL);
3269 matvec_fn.MatvecCreate = this->OperatorMatvecCreate;
3270 matvec_fn.Matvec = this->OperatorMatvec;
3271 matvec_fn.MatvecDestroy = this->OperatorMatvecDestroy;
3273 HYPRE_LOBPCGSetupB(lobpcg_solver,(HYPRE_Matrix)&M,NULL);
3282 for (
int i=0; i<nev; i++)
3284 eigs[i] = eigenvalues[i];
3291 return multi_vec->GetVector(i);
3298 if ( multi_vec == NULL )
3300 MFEM_ASSERT(x != NULL,
"In HypreLOBPCG::SetInitialVectors()");
3302 multi_vec =
new HypreMultiVector(nev, *x, interpreter);
3306 for (
int i=0; i < min(num_vecs,nev); i++)
3308 multi_vec->GetVector(i) = *vecs[i];
3312 for (
int i=min(num_vecs,nev); i < nev; i++)
3314 multi_vec->GetVector(i).Randomize(seed);
3318 if ( subSpaceProj != NULL )
3321 y = multi_vec->GetVector(0);
3323 for (
int i=1; i<nev; i++)
3325 subSpaceProj->
Mult(multi_vec->GetVector(i),
3326 multi_vec->GetVector(i-1));
3328 subSpaceProj->
Mult(y,
3329 multi_vec->GetVector(nev-1));
3337 if ( multi_vec == NULL )
3339 MFEM_ASSERT(x != NULL,
"In HypreLOBPCG::Solve()");
3341 multi_vec =
new HypreMultiVector(nev, *x, interpreter);
3342 multi_vec->Randomize(seed);
3344 if ( subSpaceProj != NULL )
3347 y = multi_vec->GetVector(0);
3349 for (
int i=1; i<nev; i++)
3351 subSpaceProj->
Mult(multi_vec->GetVector(i),
3352 multi_vec->GetVector(i-1));
3354 subSpaceProj->
Mult(y, multi_vec->GetVector(nev-1));
3365 HYPRE_LOBPCGSolve(lobpcg_solver, NULL, *multi_vec, eigenvalues);
3369 HypreLOBPCG::OperatorMatvecCreate(
void *A,
3376 return ( matvec_data );
3380 HypreLOBPCG::OperatorMatvec(
void *matvec_data,
3381 HYPRE_Complex
alpha,
3387 MFEM_VERIFY(alpha == 1.0 && beta == 0.0,
"values not supported");
3389 Operator *Aop = (Operator*)A;
3391 int width = Aop->Width();
3393 hypre_ParVector * xPar = (hypre_ParVector *)x;
3394 hypre_ParVector * yPar = (hypre_ParVector *)y;
3396 Vector xVec(xPar->local_vector->data, width);
3397 Vector yVec(yPar->local_vector->data, width);
3399 Aop->Mult( xVec, yVec );
3405 HypreLOBPCG::OperatorMatvecDestroy(
void *matvec_data )
3411 HypreLOBPCG::PrecondSolve(
void *solver,
3416 Solver *PC = (Solver*)solver;
3417 Operator *OP = (Operator*)A;
3419 int width = OP->Width();
3421 hypre_ParVector * bPar = (hypre_ParVector *)b;
3422 hypre_ParVector * xPar = (hypre_ParVector *)x;
3424 Vector bVec(bPar->local_vector->data, width);
3425 Vector xVec(xPar->local_vector->data, width);
3427 PC->Mult( bVec, xVec );
3433 HypreLOBPCG::PrecondSetup(
void *solver,
3451 MPI_Comm_size(comm,&numProcs);
3452 MPI_Comm_rank(comm,&myid);
3454 HYPRE_AMECreate(&ame_solver);
3455 HYPRE_AMESetPrintLevel(ame_solver, 0);
3462 hypre_TFree(multi_vec);
3467 for (
int i=0; i<nev; i++)
3469 delete eigenvectors[i];
3472 delete [] eigenvectors;
3476 hypre_TFree(eigenvalues);
3479 HYPRE_AMEDestroy(ame_solver);
3487 HYPRE_AMESetBlockSize(ame_solver, nev);
3493 HYPRE_AMESetTol(ame_solver, tol);
3499 #if MFEM_HYPRE_VERSION >= 21101
3500 HYPRE_AMESetRTol(ame_solver, rel_tol);
3502 MFEM_ABORT(
"This method requires HYPRE version >= 2.11.1");
3509 HYPRE_AMESetMaxIter(ame_solver, max_iter);
3517 HYPRE_AMESetPrintLevel(ame_solver, logging);
3524 ams_precond = &precond;
3532 HYPRE_Solver ams_precond_ptr = (HYPRE_Solver)*ams_precond;
3534 ams_precond->
SetupFcn()(*ams_precond,A,NULL,NULL);
3536 HYPRE_AMESetAMSSolver(ame_solver, ams_precond_ptr);
3539 HYPRE_AMESetup(ame_solver);
3545 HYPRE_ParCSRMatrix parcsr_M = M;
3546 HYPRE_AMESetMassMatrix(ame_solver,(HYPRE_ParCSRMatrix)parcsr_M);
3552 HYPRE_AMESolve(ame_solver);
3559 eigs.
SetSize(nev); eigs = -1.0;
3561 if ( eigenvalues == NULL )
3564 HYPRE_AMEGetEigenvalues(ame_solver,&eigenvalues);
3568 for (
int i=0; i<nev; i++)
3570 eigs[i] = eigenvalues[i];
3575 HypreAME::createDummyVectors()
3577 if ( multi_vec == NULL )
3579 HYPRE_AMEGetEigenvectors(ame_solver,&multi_vec);
3582 eigenvectors =
new HypreParVector*[nev];
3583 for (
int i=0; i<nev; i++)
3585 eigenvectors[i] =
new HypreParVector(multi_vec[i]);
3594 if ( eigenvectors == NULL )
3596 this->createDummyVectors();
3599 return *eigenvectors[i];
3605 if ( eigenvectors == NULL )
3607 this->createDummyVectors();
3612 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.
HypreParMatrix * RAP(const HypreParMatrix *A, const HypreParMatrix *P)
Returns the matrix P^t * A * P.
int setup_called
Was hypre's Setup function called already?
void MakeRef(const HypreParMatrix &master)
Make this HypreParMatrix a reference to 'master'.
void Read_IJMatrix(MPI_Comm comm, const char *fname)
Read a matrix saved as a HYPRE_IJMatrix.
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)
Resize the vector to size s.
HypreParMatrix & Add(const double beta, const HypreParMatrix &B)
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().
void SetInitialVectors(int num_vecs, HypreParVector **vecs)
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.
void SetPreconditioner(HypreSolver &precond)
int Size() const
Returns the size of the vector.
virtual N_Vector ToNVector()
Return a new wrapper SUNDIALS N_Vector of type SUNDIALS_NVEC_PARHYP.
void SetPreconditioner(Solver &precond)
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
void SetMassMatrix(Operator &M)
Abstract parallel finite element space.
double Normlinf() const
Returns the l_infinity norm of the vector.
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.
bool pos_l1_norms
If set, take absolute values of the computed l1_norms.
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.
HypreParMatrix * ParMult(const HypreParMatrix *A, const HypreParMatrix *B)
Returns the matrix A * B.
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)
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)
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
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 SetRelTol(double rel_tol)
void SetResidualConvergenceOptions(int res_frequency=-1, double rtol=0.0)
int to_int(const std::string &str)
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.
HYPRE_Int GlobalTrueVSize() const
HypreParVector ** StealEigenvectors()
Transfer ownership of the converged eigenvectors.
HypreParMatrix * Transpose() const
Returns the transpose of *this.
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, i.e. array A.
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.
double Norml1() const
Returns the l_1 norm of the vector.
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.
HypreParMatrix * ParAdd(const HypreParMatrix *A, const HypreParMatrix *B)
Returns the matrix A + B.
double max_eig_est
Maximal eigenvalue estimate for polynomial smoothing.
void SetRelTol(double rel_tol)
int height
Dimension of the output / number of rows in the matrix.
void SetMaxIter(int max_iter)
void SetFIRCoefficients(double max_eig)
Compute window and Chebyshev coefficients for given polynomial order.
int GetNV() const
Returns number of vertices. Vertices are only at the corners of elements, where you would expect them...
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)
double ParNormlp(const Vector &vec, double p, MPI_Comm comm)
Compute the l_p norm of the Vector which is split without overlap across the given communicator...
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.
HYPRE_Int * GetTrueDofOffsets() const
Arbitrary order H(curl)-conforming Nedelec finite elements.
const FiniteElementCollection * FEColl() const
void PrintCommPkg(std::ostream &out=mfem::out) const
Print information about the hypre_ParCSRCommPkg of the HypreParMatrix.
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.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
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 width
Dimension of the input / number of columns in the matrix.
int poly_order
Order of the smoothing polynomial.
double lambda
Taubin's lambda-mu method parameters.
void ParallelProject(Vector &tv) const
Returns the vector restricted to the true dofs.