20 #ifdef LIBMESH_HAVE_PETSC 47 #if PETSC_RELEASE_LESS_THAN(3,0,1) 50 Preconditioner<Number> * preconditioner =
static_cast<Preconditioner<Number> *
>(ctx);
52 if (!preconditioner->initialized())
53 libmesh_error_msg(
"Preconditioner not initialized! Make sure you call init() before solve!");
55 preconditioner->setup();
63 Preconditioner<Number> * preconditioner =
static_cast<Preconditioner<Number> *
>(ctx);
65 PetscVector<Number> x_vec(x, preconditioner->comm());
66 PetscVector<Number> y_vec(y, preconditioner->comm());
68 preconditioner->apply(x_vec,y_vec);
77 Preconditioner<Number> * preconditioner =
static_cast<Preconditioner<Number> *
>(ctx);
79 if (!preconditioner->initialized())
80 libmesh_error_msg(
"Preconditioner not initialized! Make sure you call init() before solve!");
82 preconditioner->setup();
91 Preconditioner<Number> * preconditioner =
static_cast<Preconditioner<Number> *
>(ctx);
93 PetscVector<Number> x_vec(x, preconditioner->comm());
94 PetscVector<Number> y_vec(y, preconditioner->comm());
96 preconditioner->apply(x_vec,y_vec);
102 #ifdef LIBMESH_ENABLE_DEPRECATED 103 #if PETSC_RELEASE_LESS_THAN(3,0,1) 106 libmesh_deprecated();
112 libmesh_deprecated();
119 libmesh_deprecated();
125 libmesh_deprecated();
133 template <
typename T>
136 _restrict_solve_to_is(nullptr),
137 _restrict_solve_to_is_complement(nullptr),
148 template <
typename T>
155 if (_restrict_solve_to_is !=
nullptr)
157 PetscErrorCode
ierr = LibMeshISDestroy(&_restrict_solve_to_is);
158 LIBMESH_CHKERR(
ierr);
159 _restrict_solve_to_is =
nullptr;
162 if (_restrict_solve_to_is_complement !=
nullptr)
164 PetscErrorCode
ierr = LibMeshISDestroy(&_restrict_solve_to_is_complement);
165 LIBMESH_CHKERR(
ierr);
166 _restrict_solve_to_is_complement =
nullptr;
171 PetscErrorCode
ierr=0;
173 ierr = LibMeshKSPDestroy(&_ksp);
174 LIBMESH_CHKERR(
ierr);
177 this->_solver_type =
GMRES;
179 if (!this->_preconditioner)
181 if (this->n_processors() == 1)
191 template <
typename T>
199 PetscErrorCode
ierr=0;
202 ierr = KSPCreate (this->comm().
get(), &_ksp);
203 LIBMESH_CHKERR(
ierr);
207 ierr = KSPSetOptionsPrefix(_ksp,
name);
208 LIBMESH_CHKERR(
ierr);
212 ierr = KSPGetPC (_ksp, &_pc);
213 LIBMESH_CHKERR(
ierr);
216 this->set_petsc_solver_type();
220 if (this->_solver_configuration)
222 this->_solver_configuration->set_options_during_init();
232 ierr = KSPSetFromOptions (_ksp);
233 LIBMESH_CHKERR(
ierr);
243 #if PETSC_VERSION_LESS_THAN(3,0,0) || !PETSC_RELEASE_LESS_THAN(3,4,0) 247 const KSPType ksp_type;
250 ierr = KSPGetType (_ksp, &ksp_type);
251 LIBMESH_CHKERR(
ierr);
253 if (strcmp(ksp_type,
"preonly"))
255 ierr = KSPSetInitialGuessNonzero (_ksp, PETSC_TRUE);
256 LIBMESH_CHKERR(
ierr);
264 ierr = KSPSetResidualHistory(_ksp,
268 LIBMESH_CHKERR(
ierr);
273 if (this->_preconditioner)
275 this->_preconditioner->init();
276 PCShellSetContext(_pc,(
void *)this->_preconditioner);
284 template <
typename T>
293 PetscErrorCode
ierr=0;
296 ierr = KSPCreate (this->comm().
get(), &_ksp);
297 LIBMESH_CHKERR(
ierr);
301 ierr = KSPSetOptionsPrefix(_ksp,
name);
302 LIBMESH_CHKERR(
ierr);
309 ierr = KSPGetPC (_ksp, &_pc);
310 LIBMESH_CHKERR(
ierr);
313 #if PETSC_RELEASE_LESS_THAN(3,5,0) 314 ierr = KSPSetOperators(_ksp, matrix->
mat(), matrix->
mat(),DIFFERENT_NONZERO_PATTERN);
316 ierr = KSPSetOperators(_ksp, matrix->
mat(), matrix->
mat());
318 LIBMESH_CHKERR(
ierr);
321 this->set_petsc_solver_type();
325 if (this->_solver_configuration)
327 this->_solver_configuration->set_options_during_init();
337 ierr = KSPSetFromOptions (_ksp);
338 LIBMESH_CHKERR(
ierr);
348 #if PETSC_VERSION_LESS_THAN(3,0,0) || !PETSC_RELEASE_LESS_THAN(3,4,0) 351 const KSPType ksp_type;
354 ierr = KSPGetType (_ksp, &ksp_type);
355 LIBMESH_CHKERR(
ierr);
357 if (strcmp(ksp_type,
"preonly"))
359 ierr = KSPSetInitialGuessNonzero (_ksp, PETSC_TRUE);
360 LIBMESH_CHKERR(
ierr);
368 ierr = KSPSetResidualHistory(_ksp,
372 LIBMESH_CHKERR(
ierr);
375 if (this->_preconditioner)
377 this->_preconditioner->set_matrix(*matrix);
378 this->_preconditioner->init();
379 PCShellSetContext(_pc,(
void *)this->_preconditioner);
388 template <
typename T>
397 template <
typename T>
402 PetscErrorCode
ierr=0;
410 _subset_solve_mode = subset_solve_mode;
414 PetscInt * petsc_dofs =
nullptr;
415 ierr = PetscMalloc(dofs->size()*
sizeof(PetscInt), &petsc_dofs);
416 LIBMESH_CHKERR(
ierr);
418 for (std::size_t i=0; i<dofs->size(); i++)
419 petsc_dofs[i] = (*dofs)[i];
421 ierr = ISCreateLibMesh(this->comm().
get(),
422 cast_int<PetscInt>(dofs->size()),
424 &_restrict_solve_to_is);
425 LIBMESH_CHKERR(
ierr);
431 template <
typename T>
432 std::pair<unsigned int, Real>
438 const unsigned int m_its)
440 LOG_SCOPE(
"solve()",
"PetscLinearSolver");
444 PetscMatrix<T> * precond = cast_ptr<PetscMatrix<T> *>(&precond_in);
445 PetscVector<T> * solution = cast_ptr<PetscVector<T> *>(&solution_in);
450 PetscErrorCode
ierr=0;
451 PetscInt its=0, max_its =
static_cast<PetscInt
>(m_its);
452 PetscReal final_resid=0.;
468 Mat submat =
nullptr;
469 Mat subprecond =
nullptr;
470 Vec subrhs =
nullptr;
471 Vec subsolution =
nullptr;
472 VecScatter scatter =
nullptr;
473 std::unique_ptr<PetscMatrix<Number>> subprecond_matrix;
477 if (_restrict_solve_to_is !=
nullptr)
479 PetscInt is_local_size = this->_restrict_solve_to_is_local_size();
481 ierr = VecCreate(this->comm().
get(),&subrhs);
482 LIBMESH_CHKERR(
ierr);
483 ierr = VecSetSizes(subrhs,is_local_size,PETSC_DECIDE);
484 LIBMESH_CHKERR(
ierr);
485 ierr = VecSetFromOptions(subrhs);
486 LIBMESH_CHKERR(
ierr);
488 ierr = VecCreate(this->comm().
get(),&subsolution);
489 LIBMESH_CHKERR(
ierr);
490 ierr = VecSetSizes(subsolution,is_local_size,PETSC_DECIDE);
491 LIBMESH_CHKERR(
ierr);
492 ierr = VecSetFromOptions(subsolution);
493 LIBMESH_CHKERR(
ierr);
495 ierr = LibMeshVecScatterCreate(rhs->vec(), _restrict_solve_to_is, subrhs,
nullptr, &scatter);
496 LIBMESH_CHKERR(
ierr);
498 ierr = VecScatterBegin(scatter,rhs->vec(),subrhs,INSERT_VALUES,SCATTER_FORWARD);
499 LIBMESH_CHKERR(
ierr);
500 ierr = VecScatterEnd(scatter,rhs->vec(),subrhs,INSERT_VALUES,SCATTER_FORWARD);
501 LIBMESH_CHKERR(
ierr);
503 ierr = VecScatterBegin(scatter,solution->vec(),subsolution,INSERT_VALUES,SCATTER_FORWARD);
504 LIBMESH_CHKERR(
ierr);
505 ierr = VecScatterEnd(scatter,solution->vec(),subsolution,INSERT_VALUES,SCATTER_FORWARD);
506 LIBMESH_CHKERR(
ierr);
508 ierr = LibMeshCreateSubMatrix(matrix->
mat(),
509 _restrict_solve_to_is,
510 _restrict_solve_to_is,
511 #if PETSC_VERSION_LESS_THAN(3,1,0) 516 LIBMESH_CHKERR(
ierr);
518 ierr = LibMeshCreateSubMatrix(precond->mat(),
519 _restrict_solve_to_is,
520 _restrict_solve_to_is,
521 #if PETSC_VERSION_LESS_THAN(3,1,0) 526 LIBMESH_CHKERR(
ierr);
534 _create_complement_is(rhs_in);
535 PetscInt is_complement_local_size =
536 cast_int<PetscInt>(rhs_in.
local_size()-is_local_size);
538 Vec subvec1 =
nullptr;
539 Mat submat1 =
nullptr;
540 VecScatter scatter1 =
nullptr;
542 ierr = VecCreate(this->comm().
get(),&subvec1);
543 LIBMESH_CHKERR(
ierr);
544 ierr = VecSetSizes(subvec1,is_complement_local_size,PETSC_DECIDE);
545 LIBMESH_CHKERR(
ierr);
546 ierr = VecSetFromOptions(subvec1);
547 LIBMESH_CHKERR(
ierr);
549 ierr = LibMeshVecScatterCreate(rhs->vec(),_restrict_solve_to_is_complement, subvec1,
nullptr, &scatter1);
550 LIBMESH_CHKERR(
ierr);
552 ierr = VecScatterBegin(scatter1,_subset_solve_mode==
SUBSET_COPY_RHS ? rhs->vec() : solution->vec(),subvec1,INSERT_VALUES,SCATTER_FORWARD);
553 LIBMESH_CHKERR(
ierr);
554 ierr = VecScatterEnd(scatter1,_subset_solve_mode==
SUBSET_COPY_RHS ? rhs->vec() : solution->vec(),subvec1,INSERT_VALUES,SCATTER_FORWARD);
555 LIBMESH_CHKERR(
ierr);
557 ierr = VecScale(subvec1,-1.0);
558 LIBMESH_CHKERR(
ierr);
560 ierr = LibMeshCreateSubMatrix(matrix->
mat(),
561 _restrict_solve_to_is,
562 _restrict_solve_to_is_complement,
563 #if PETSC_VERSION_LESS_THAN(3,1,0) 568 LIBMESH_CHKERR(
ierr);
570 ierr = MatMultAdd(submat1,subvec1,subrhs,subrhs);
571 LIBMESH_CHKERR(
ierr);
573 ierr = LibMeshVecScatterDestroy(&scatter1);
574 LIBMESH_CHKERR(
ierr);
575 ierr = LibMeshVecDestroy(&subvec1);
576 LIBMESH_CHKERR(
ierr);
577 ierr = LibMeshMatDestroy(&submat1);
578 LIBMESH_CHKERR(
ierr);
580 #if PETSC_RELEASE_LESS_THAN(3,5,0) 581 ierr = KSPSetOperators(_ksp, submat, subprecond,
582 this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
584 ierr = KSPSetOperators(_ksp, submat, subprecond);
586 PetscBool ksp_reuse_preconditioner = this->same_preconditioner ? PETSC_TRUE : PETSC_FALSE;
587 ierr = KSPSetReusePreconditioner(_ksp, ksp_reuse_preconditioner);
589 LIBMESH_CHKERR(
ierr);
591 if (this->_preconditioner)
594 this->_preconditioner->set_matrix(*subprecond_matrix);
595 this->_preconditioner->init();
600 #if PETSC_RELEASE_LESS_THAN(3,5,0) 601 ierr = KSPSetOperators(_ksp, matrix->
mat(), precond->mat(),
602 this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
604 ierr = KSPSetOperators(_ksp, matrix->
mat(), precond->mat());
606 PetscBool ksp_reuse_preconditioner = this->same_preconditioner ? PETSC_TRUE : PETSC_FALSE;
607 ierr = KSPSetReusePreconditioner(_ksp, ksp_reuse_preconditioner);
609 LIBMESH_CHKERR(
ierr);
611 if (this->_preconditioner)
613 this->_preconditioner->set_matrix(matrix_in);
614 this->_preconditioner->init();
620 ierr = KSPSetTolerances (_ksp, tol, PETSC_DEFAULT,
621 PETSC_DEFAULT, max_its);
622 LIBMESH_CHKERR(
ierr);
625 ierr = KSPSetFromOptions(_ksp);
626 LIBMESH_CHKERR(
ierr);
630 if (this->_solver_configuration)
632 this->_solver_configuration->configure_solver();
636 if (_restrict_solve_to_is !=
nullptr)
638 ierr = KSPSolve (_ksp, subrhs, subsolution);
639 LIBMESH_CHKERR(
ierr);
643 ierr = KSPSolve (_ksp, rhs->vec(), solution->vec());
644 LIBMESH_CHKERR(
ierr);
648 ierr = KSPGetIterationNumber (_ksp, &its);
649 LIBMESH_CHKERR(
ierr);
652 ierr = KSPGetResidualNorm (_ksp, &final_resid);
653 LIBMESH_CHKERR(
ierr);
655 if (_restrict_solve_to_is !=
nullptr)
657 switch(_subset_solve_mode)
660 ierr = VecZeroEntries(solution->vec());
661 LIBMESH_CHKERR(
ierr);
665 ierr = VecCopy(rhs->vec(),solution->vec());
666 LIBMESH_CHKERR(
ierr);
674 libmesh_error_msg(
"Invalid subset solve mode = " << _subset_solve_mode);
676 ierr = VecScatterBegin(scatter,subsolution,solution->vec(),INSERT_VALUES,SCATTER_REVERSE);
677 LIBMESH_CHKERR(
ierr);
678 ierr = VecScatterEnd(scatter,subsolution,solution->vec(),INSERT_VALUES,SCATTER_REVERSE);
679 LIBMESH_CHKERR(
ierr);
681 ierr = LibMeshVecScatterDestroy(&scatter);
682 LIBMESH_CHKERR(
ierr);
684 if (this->_preconditioner)
688 this->_preconditioner->set_matrix(matrix_in);
689 this->_preconditioner->init();
692 ierr = LibMeshVecDestroy(&subsolution);
693 LIBMESH_CHKERR(
ierr);
694 ierr = LibMeshVecDestroy(&subrhs);
695 LIBMESH_CHKERR(
ierr);
696 ierr = LibMeshMatDestroy(&submat);
697 LIBMESH_CHKERR(
ierr);
698 ierr = LibMeshMatDestroy(&subprecond);
699 LIBMESH_CHKERR(
ierr);
703 return std::make_pair(its, final_resid);
706 template <
typename T>
707 std::pair<unsigned int, Real>
712 const unsigned int m_its)
714 LOG_SCOPE(
"solve()",
"PetscLinearSolver");
719 PetscMatrix<T> * precond = cast_ptr<PetscMatrix<T> *>(&matrix_in);
720 PetscVector<T> * solution = cast_ptr<PetscVector<T> *>(&solution_in);
725 PetscErrorCode
ierr=0;
726 PetscInt its=0, max_its =
static_cast<PetscInt
>(m_its);
727 PetscReal final_resid=0.;
735 Mat submat =
nullptr;
736 Mat subprecond =
nullptr;
737 Vec subrhs =
nullptr;
738 Vec subsolution =
nullptr;
739 VecScatter scatter =
nullptr;
740 std::unique_ptr<PetscMatrix<Number>> subprecond_matrix;
744 if (_restrict_solve_to_is !=
nullptr)
746 PetscInt is_local_size = this->_restrict_solve_to_is_local_size();
748 ierr = VecCreate(this->comm().
get(),&subrhs);
749 LIBMESH_CHKERR(
ierr);
750 ierr = VecSetSizes(subrhs,is_local_size,PETSC_DECIDE);
751 LIBMESH_CHKERR(
ierr);
752 ierr = VecSetFromOptions(subrhs);
753 LIBMESH_CHKERR(
ierr);
755 ierr = VecCreate(this->comm().
get(),&subsolution);
756 LIBMESH_CHKERR(
ierr);
757 ierr = VecSetSizes(subsolution,is_local_size,PETSC_DECIDE);
758 LIBMESH_CHKERR(
ierr);
759 ierr = VecSetFromOptions(subsolution);
760 LIBMESH_CHKERR(
ierr);
762 ierr = LibMeshVecScatterCreate(rhs->vec(),_restrict_solve_to_is, subrhs,
nullptr, &scatter);
763 LIBMESH_CHKERR(
ierr);
765 ierr = VecScatterBegin(scatter,rhs->vec(),subrhs,INSERT_VALUES,SCATTER_FORWARD);
766 LIBMESH_CHKERR(
ierr);
767 ierr = VecScatterEnd(scatter,rhs->vec(),subrhs,INSERT_VALUES,SCATTER_FORWARD);
768 LIBMESH_CHKERR(
ierr);
770 ierr = VecScatterBegin(scatter,solution->vec(),subsolution,INSERT_VALUES,SCATTER_FORWARD);
771 LIBMESH_CHKERR(
ierr);
772 ierr = VecScatterEnd(scatter,solution->vec(),subsolution,INSERT_VALUES,SCATTER_FORWARD);
773 LIBMESH_CHKERR(
ierr);
775 ierr = LibMeshCreateSubMatrix(matrix->
mat(),
776 _restrict_solve_to_is,
777 _restrict_solve_to_is,
778 #if PETSC_VERSION_LESS_THAN(3,1,0) 783 LIBMESH_CHKERR(
ierr);
785 ierr = LibMeshCreateSubMatrix(precond->mat(),
786 _restrict_solve_to_is,
787 _restrict_solve_to_is,
788 #if PETSC_VERSION_LESS_THAN(3,1,0) 793 LIBMESH_CHKERR(
ierr);
801 _create_complement_is(rhs_in);
802 PetscInt is_complement_local_size =
803 cast_int<PetscInt>(rhs_in.
local_size()-is_local_size);
805 Vec subvec1 =
nullptr;
806 Mat submat1 =
nullptr;
807 VecScatter scatter1 =
nullptr;
809 ierr = VecCreate(this->comm().
get(),&subvec1);
810 LIBMESH_CHKERR(
ierr);
811 ierr = VecSetSizes(subvec1,is_complement_local_size,PETSC_DECIDE);
812 LIBMESH_CHKERR(
ierr);
813 ierr = VecSetFromOptions(subvec1);
814 LIBMESH_CHKERR(
ierr);
816 ierr = LibMeshVecScatterCreate(rhs->vec(),_restrict_solve_to_is_complement, subvec1,
nullptr, &scatter1);
817 LIBMESH_CHKERR(
ierr);
819 ierr = VecScatterBegin(scatter1,_subset_solve_mode==
SUBSET_COPY_RHS ? rhs->vec() : solution->vec(),subvec1,INSERT_VALUES,SCATTER_FORWARD);
820 LIBMESH_CHKERR(
ierr);
821 ierr = VecScatterEnd(scatter1,_subset_solve_mode==
SUBSET_COPY_RHS ? rhs->vec() : solution->vec(),subvec1,INSERT_VALUES,SCATTER_FORWARD);
822 LIBMESH_CHKERR(
ierr);
824 ierr = VecScale(subvec1,-1.0);
825 LIBMESH_CHKERR(
ierr);
827 ierr = LibMeshCreateSubMatrix(matrix->
mat(),
828 _restrict_solve_to_is,
829 _restrict_solve_to_is_complement,
830 #if PETSC_VERSION_LESS_THAN(3,1,0) 835 LIBMESH_CHKERR(
ierr);
837 ierr = MatMultAdd(submat1,subvec1,subrhs,subrhs);
838 LIBMESH_CHKERR(
ierr);
840 ierr = LibMeshVecScatterDestroy(&scatter1);
841 LIBMESH_CHKERR(
ierr);
842 ierr = LibMeshVecDestroy(&subvec1);
843 LIBMESH_CHKERR(
ierr);
844 ierr = LibMeshMatDestroy(&submat1);
845 LIBMESH_CHKERR(
ierr);
847 #if PETSC_RELEASE_LESS_THAN(3,5,0) 848 ierr = KSPSetOperators(_ksp, submat, subprecond,
849 this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
851 ierr = KSPSetOperators(_ksp, submat, subprecond);
853 PetscBool ksp_reuse_preconditioner = this->same_preconditioner ? PETSC_TRUE : PETSC_FALSE;
854 ierr = KSPSetReusePreconditioner(_ksp, ksp_reuse_preconditioner);
856 LIBMESH_CHKERR(
ierr);
858 if (this->_preconditioner)
861 this->_preconditioner->set_matrix(*subprecond_matrix);
862 this->_preconditioner->init();
867 #if PETSC_RELEASE_LESS_THAN(3,5,0) 868 ierr = KSPSetOperators(_ksp, matrix->
mat(), precond->mat(),
869 this->same_preconditioner ? SAME_PRECONDITIONER : DIFFERENT_NONZERO_PATTERN);
871 ierr = KSPSetOperators(_ksp, matrix->
mat(), precond->mat());
873 PetscBool ksp_reuse_preconditioner = this->same_preconditioner ? PETSC_TRUE : PETSC_FALSE;
874 ierr = KSPSetReusePreconditioner(_ksp, ksp_reuse_preconditioner);
876 LIBMESH_CHKERR(
ierr);
878 if (this->_preconditioner)
880 this->_preconditioner->set_matrix(matrix_in);
881 this->_preconditioner->init();
887 ierr = KSPSetTolerances (_ksp, tol, PETSC_DEFAULT,
888 PETSC_DEFAULT, max_its);
889 LIBMESH_CHKERR(
ierr);
892 ierr = KSPSetFromOptions(_ksp);
893 LIBMESH_CHKERR(
ierr);
896 if (_restrict_solve_to_is !=
nullptr)
898 ierr = KSPSolveTranspose (_ksp, subrhs, subsolution);
899 LIBMESH_CHKERR(
ierr);
903 ierr = KSPSolveTranspose (_ksp, rhs->vec(), solution->vec());
904 LIBMESH_CHKERR(
ierr);
908 ierr = KSPGetIterationNumber (_ksp, &its);
909 LIBMESH_CHKERR(
ierr);
912 ierr = KSPGetResidualNorm (_ksp, &final_resid);
913 LIBMESH_CHKERR(
ierr);
915 if (_restrict_solve_to_is !=
nullptr)
917 switch(_subset_solve_mode)
920 ierr = VecZeroEntries(solution->vec());
921 LIBMESH_CHKERR(
ierr);
925 ierr = VecCopy(rhs->vec(),solution->vec());
926 LIBMESH_CHKERR(
ierr);
934 libmesh_error_msg(
"Invalid subset solve mode = " << _subset_solve_mode);
936 ierr = VecScatterBegin(scatter,subsolution,solution->vec(),INSERT_VALUES,SCATTER_REVERSE);
937 LIBMESH_CHKERR(
ierr);
938 ierr = VecScatterEnd(scatter,subsolution,solution->vec(),INSERT_VALUES,SCATTER_REVERSE);
939 LIBMESH_CHKERR(
ierr);
941 ierr = LibMeshVecScatterDestroy(&scatter);
942 LIBMESH_CHKERR(
ierr);
944 if (this->_preconditioner)
948 this->_preconditioner->set_matrix(matrix_in);
949 this->_preconditioner->init();
952 ierr = LibMeshVecDestroy(&subsolution);
953 LIBMESH_CHKERR(
ierr);
954 ierr = LibMeshVecDestroy(&subrhs);
955 LIBMESH_CHKERR(
ierr);
956 ierr = LibMeshMatDestroy(&submat);
957 LIBMESH_CHKERR(
ierr);
958 ierr = LibMeshMatDestroy(&subprecond);
959 LIBMESH_CHKERR(
ierr);
963 return std::make_pair(its, final_resid);
967 template <
typename T>
968 std::pair<unsigned int, Real>
973 const unsigned int m_its)
976 #if PETSC_VERSION_LESS_THAN(3,1,0) 977 if (_restrict_solve_to_is !=
nullptr)
978 libmesh_error_msg(
"The current implementation of subset solves with " \
979 <<
"shell matrices requires PETSc version 3.1 or above. " \
980 <<
"Older PETSc version do not support automatic " \
981 <<
"submatrix generation of shell matrices.");
984 LOG_SCOPE(
"solve()",
"PetscLinearSolver");
987 PetscVector<T> * solution = cast_ptr<PetscVector<T> *>(&solution_in);
992 PetscErrorCode
ierr=0;
993 PetscInt its=0, max_its =
static_cast<PetscInt
>(m_its);
994 PetscReal final_resid=0.;
996 Mat submat =
nullptr;
997 Vec subrhs =
nullptr;
998 Vec subsolution =
nullptr;
999 VecScatter scatter =
nullptr;
1007 ierr = MatCreateShell(this->comm().
get(),
1012 const_cast<void *
>(
static_cast<const void *
>(&shell_matrix)),
1019 LIBMESH_CHKERR(
ierr);
1020 ierr = MatShellSetOperation(mat,MATOP_MULT,
reinterpret_cast<void(*)(
void)
>(_petsc_shell_matrix_mult));
1021 LIBMESH_CHKERR(
ierr);
1022 ierr = MatShellSetOperation(mat,MATOP_MULT_ADD,
reinterpret_cast<void(*)(
void)
>(_petsc_shell_matrix_mult_add));
1023 LIBMESH_CHKERR(
ierr);
1024 ierr = MatShellSetOperation(mat,MATOP_GET_DIAGONAL,
reinterpret_cast<void(*)(
void)
>(_petsc_shell_matrix_get_diagonal));
1025 LIBMESH_CHKERR(
ierr);
1029 if (_restrict_solve_to_is !=
nullptr)
1031 PetscInt is_local_size = this->_restrict_solve_to_is_local_size();
1033 ierr = VecCreate(this->comm().
get(),&subrhs);
1034 LIBMESH_CHKERR(
ierr);
1035 ierr = VecSetSizes(subrhs,is_local_size,PETSC_DECIDE);
1036 LIBMESH_CHKERR(
ierr);
1037 ierr = VecSetFromOptions(subrhs);
1038 LIBMESH_CHKERR(
ierr);
1040 ierr = VecCreate(this->comm().
get(),&subsolution);
1041 LIBMESH_CHKERR(
ierr);
1042 ierr = VecSetSizes(subsolution,is_local_size,PETSC_DECIDE);
1043 LIBMESH_CHKERR(
ierr);
1044 ierr = VecSetFromOptions(subsolution);
1045 LIBMESH_CHKERR(
ierr);
1047 ierr = LibMeshVecScatterCreate(rhs->vec(),_restrict_solve_to_is, subrhs,
nullptr, &scatter);
1048 LIBMESH_CHKERR(
ierr);
1050 ierr = VecScatterBegin(scatter,rhs->vec(),subrhs,INSERT_VALUES,SCATTER_FORWARD);
1051 LIBMESH_CHKERR(
ierr);
1052 ierr = VecScatterEnd(scatter,rhs->vec(),subrhs,INSERT_VALUES,SCATTER_FORWARD);
1053 LIBMESH_CHKERR(
ierr);
1055 ierr = VecScatterBegin(scatter,solution->
vec(),subsolution,INSERT_VALUES,SCATTER_FORWARD);
1056 LIBMESH_CHKERR(
ierr);
1057 ierr = VecScatterEnd(scatter,solution->
vec(),subsolution,INSERT_VALUES,SCATTER_FORWARD);
1058 LIBMESH_CHKERR(
ierr);
1060 #if !PETSC_VERSION_LESS_THAN(3,1,0) 1061 ierr = LibMeshCreateSubMatrix(mat,
1062 _restrict_solve_to_is,
1063 _restrict_solve_to_is,
1066 LIBMESH_CHKERR(
ierr);
1075 _create_complement_is(rhs_in);
1076 PetscInt is_complement_local_size =
1077 cast_int<PetscInt>(rhs_in.
local_size()-is_local_size);
1079 Vec subvec1 =
nullptr;
1080 Mat submat1 =
nullptr;
1081 VecScatter scatter1 =
nullptr;
1083 ierr = VecCreate(this->comm().
get(),&subvec1);
1084 LIBMESH_CHKERR(
ierr);
1085 ierr = VecSetSizes(subvec1,is_complement_local_size,PETSC_DECIDE);
1086 LIBMESH_CHKERR(
ierr);
1087 ierr = VecSetFromOptions(subvec1);
1088 LIBMESH_CHKERR(
ierr);
1090 ierr = LibMeshVecScatterCreate(rhs->vec(),_restrict_solve_to_is_complement, subvec1,
nullptr, &scatter1);
1091 LIBMESH_CHKERR(
ierr);
1093 ierr = VecScatterBegin(scatter1,_subset_solve_mode==
SUBSET_COPY_RHS ? rhs->vec() : solution->
vec(),subvec1,INSERT_VALUES,SCATTER_FORWARD);
1094 LIBMESH_CHKERR(
ierr);
1095 ierr = VecScatterEnd(scatter1,_subset_solve_mode==
SUBSET_COPY_RHS ? rhs->vec() : solution->
vec(),subvec1,INSERT_VALUES,SCATTER_FORWARD);
1096 LIBMESH_CHKERR(
ierr);
1098 ierr = VecScale(subvec1,-1.0);
1099 LIBMESH_CHKERR(
ierr);
1101 #if !PETSC_VERSION_LESS_THAN(3,1,0) 1102 ierr = LibMeshCreateSubMatrix(mat,
1103 _restrict_solve_to_is,
1104 _restrict_solve_to_is_complement,
1107 LIBMESH_CHKERR(
ierr);
1120 Vec subvec2 =
nullptr;
1121 ierr = VecCreate(this->comm().
get(),&subvec2);
1122 LIBMESH_CHKERR(
ierr);
1123 ierr = VecSetSizes(subvec2,is_local_size,PETSC_DECIDE);
1124 LIBMESH_CHKERR(
ierr);
1125 ierr = VecSetFromOptions(subvec2);
1126 LIBMESH_CHKERR(
ierr);
1127 ierr = MatMult(submat1,subvec1,subvec2);
1128 LIBMESH_CHKERR(
ierr);
1129 ierr = VecAXPY(subrhs,1.0,subvec2);
1131 ierr = LibMeshVecScatterDestroy(&scatter1);
1132 LIBMESH_CHKERR(
ierr);
1133 ierr = LibMeshVecDestroy(&subvec1);
1134 LIBMESH_CHKERR(
ierr);
1135 ierr = LibMeshMatDestroy(&submat1);
1136 LIBMESH_CHKERR(
ierr);
1138 #if PETSC_RELEASE_LESS_THAN(3,5,0) 1139 ierr = KSPSetOperators(_ksp, submat, submat,
1140 DIFFERENT_NONZERO_PATTERN);
1142 ierr = KSPSetOperators(_ksp, submat, submat);
1144 LIBMESH_CHKERR(
ierr);
1148 #if PETSC_RELEASE_LESS_THAN(3,5,0) 1149 ierr = KSPSetOperators(_ksp, mat, mat,
1150 DIFFERENT_NONZERO_PATTERN);
1152 ierr = KSPSetOperators(_ksp, mat, mat);
1154 LIBMESH_CHKERR(
ierr);
1159 ierr = KSPSetTolerances (_ksp, tol, PETSC_DEFAULT,
1160 PETSC_DEFAULT, max_its);
1161 LIBMESH_CHKERR(
ierr);
1164 ierr = KSPSetFromOptions(_ksp);
1165 LIBMESH_CHKERR(
ierr);
1168 if (_restrict_solve_to_is !=
nullptr)
1170 ierr = KSPSolve (_ksp, subrhs, subsolution);
1171 LIBMESH_CHKERR(
ierr);
1175 ierr = KSPSolve (_ksp, rhs->vec(), solution->
vec());
1176 LIBMESH_CHKERR(
ierr);
1180 ierr = KSPGetIterationNumber (_ksp, &its);
1181 LIBMESH_CHKERR(
ierr);
1184 ierr = KSPGetResidualNorm (_ksp, &final_resid);
1185 LIBMESH_CHKERR(
ierr);
1187 if (_restrict_solve_to_is !=
nullptr)
1189 switch(_subset_solve_mode)
1192 ierr = VecZeroEntries(solution->
vec());
1193 LIBMESH_CHKERR(
ierr);
1197 ierr = VecCopy(rhs->vec(),solution->
vec());
1198 LIBMESH_CHKERR(
ierr);
1206 libmesh_error_msg(
"Invalid subset solve mode = " << _subset_solve_mode);
1208 ierr = VecScatterBegin(scatter,subsolution,solution->
vec(),INSERT_VALUES,SCATTER_REVERSE);
1209 LIBMESH_CHKERR(
ierr);
1210 ierr = VecScatterEnd(scatter,subsolution,solution->
vec(),INSERT_VALUES,SCATTER_REVERSE);
1211 LIBMESH_CHKERR(
ierr);
1213 ierr = LibMeshVecScatterDestroy(&scatter);
1214 LIBMESH_CHKERR(
ierr);
1216 ierr = LibMeshVecDestroy(&subsolution);
1217 LIBMESH_CHKERR(
ierr);
1218 ierr = LibMeshVecDestroy(&subrhs);
1219 LIBMESH_CHKERR(
ierr);
1220 ierr = LibMeshMatDestroy(&submat);
1221 LIBMESH_CHKERR(
ierr);
1225 ierr = LibMeshMatDestroy(&mat);
1226 LIBMESH_CHKERR(
ierr);
1229 return std::make_pair(its, final_resid);
1234 template <
typename T>
1235 std::pair<unsigned int, Real>
1241 const unsigned int m_its)
1244 #if PETSC_VERSION_LESS_THAN(3,1,0) 1245 if (_restrict_solve_to_is !=
nullptr)
1246 libmesh_error_msg(
"The current implementation of subset solves with " \
1247 <<
"shell matrices requires PETSc version 3.1 or above. " \
1248 <<
"Older PETSc version do not support automatic " \
1249 <<
"submatrix generation of shell matrices.");
1252 LOG_SCOPE(
"solve()",
"PetscLinearSolver");
1255 const PetscMatrix<T> * precond = cast_ptr<const PetscMatrix<T> *>(&precond_matrix);
1256 PetscVector<T> * solution = cast_ptr<PetscVector<T> *>(&solution_in);
1261 PetscErrorCode
ierr=0;
1262 PetscInt its=0, max_its =
static_cast<PetscInt
>(m_its);
1263 PetscReal final_resid=0.;
1265 Mat submat =
nullptr;
1266 Mat subprecond =
nullptr;
1267 Vec subrhs =
nullptr;
1268 Vec subsolution =
nullptr;
1269 VecScatter scatter =
nullptr;
1270 std::unique_ptr<PetscMatrix<Number>> subprecond_matrix;
1278 ierr = MatCreateShell(this->comm().
get(),
1283 const_cast<void *
>(
static_cast<const void *
>(&shell_matrix)),
1290 LIBMESH_CHKERR(
ierr);
1291 ierr = MatShellSetOperation(mat,MATOP_MULT,
reinterpret_cast<void(*)(
void)
>(_petsc_shell_matrix_mult));
1292 LIBMESH_CHKERR(
ierr);
1293 ierr = MatShellSetOperation(mat,MATOP_MULT_ADD,
reinterpret_cast<void(*)(
void)
>(_petsc_shell_matrix_mult_add));
1294 LIBMESH_CHKERR(
ierr);
1295 ierr = MatShellSetOperation(mat,MATOP_GET_DIAGONAL,
reinterpret_cast<void(*)(
void)
>(_petsc_shell_matrix_get_diagonal));
1296 LIBMESH_CHKERR(
ierr);
1300 if (_restrict_solve_to_is !=
nullptr)
1302 PetscInt is_local_size = this->_restrict_solve_to_is_local_size();
1304 ierr = VecCreate(this->comm().
get(),&subrhs);
1305 LIBMESH_CHKERR(
ierr);
1306 ierr = VecSetSizes(subrhs,is_local_size,PETSC_DECIDE);
1307 LIBMESH_CHKERR(
ierr);
1308 ierr = VecSetFromOptions(subrhs);
1309 LIBMESH_CHKERR(
ierr);
1311 ierr = VecCreate(this->comm().
get(),&subsolution);
1312 LIBMESH_CHKERR(
ierr);
1313 ierr = VecSetSizes(subsolution,is_local_size,PETSC_DECIDE);
1314 LIBMESH_CHKERR(
ierr);
1315 ierr = VecSetFromOptions(subsolution);
1316 LIBMESH_CHKERR(
ierr);
1318 ierr = LibMeshVecScatterCreate(rhs->vec(),_restrict_solve_to_is, subrhs,
nullptr, &scatter);
1319 LIBMESH_CHKERR(
ierr);
1321 ierr = VecScatterBegin(scatter,rhs->vec(),subrhs,INSERT_VALUES,SCATTER_FORWARD);
1322 LIBMESH_CHKERR(
ierr);
1323 ierr = VecScatterEnd(scatter,rhs->vec(),subrhs,INSERT_VALUES,SCATTER_FORWARD);
1324 LIBMESH_CHKERR(
ierr);
1326 ierr = VecScatterBegin(scatter,solution->vec(),subsolution,INSERT_VALUES,SCATTER_FORWARD);
1327 LIBMESH_CHKERR(
ierr);
1328 ierr = VecScatterEnd(scatter,solution->vec(),subsolution,INSERT_VALUES,SCATTER_FORWARD);
1329 LIBMESH_CHKERR(
ierr);
1331 #if !PETSC_VERSION_LESS_THAN(3,1,0) 1332 ierr = LibMeshCreateSubMatrix(mat,
1333 _restrict_solve_to_is,
1334 _restrict_solve_to_is,
1337 LIBMESH_CHKERR(
ierr);
1340 _restrict_solve_to_is,
1341 _restrict_solve_to_is,
1344 LIBMESH_CHKERR(
ierr);
1353 _create_complement_is(rhs_in);
1354 PetscInt is_complement_local_size = rhs_in.
local_size()-is_local_size;
1356 Vec subvec1 =
nullptr;
1357 Mat submat1 =
nullptr;
1358 VecScatter scatter1 =
nullptr;
1360 ierr = VecCreate(this->comm().
get(),&subvec1);
1361 LIBMESH_CHKERR(
ierr);
1362 ierr = VecSetSizes(subvec1,is_complement_local_size,PETSC_DECIDE);
1363 LIBMESH_CHKERR(
ierr);
1364 ierr = VecSetFromOptions(subvec1);
1365 LIBMESH_CHKERR(
ierr);
1367 ierr = LibMeshVecScatterCreate(rhs->vec(),_restrict_solve_to_is_complement, subvec1,
nullptr, &scatter1);
1368 LIBMESH_CHKERR(
ierr);
1370 ierr = VecScatterBegin(scatter1,_subset_solve_mode==
SUBSET_COPY_RHS ? rhs->vec() : solution->vec(),subvec1,INSERT_VALUES,SCATTER_FORWARD);
1371 LIBMESH_CHKERR(
ierr);
1372 ierr = VecScatterEnd(scatter1,_subset_solve_mode==
SUBSET_COPY_RHS ? rhs->vec() : solution->vec(),subvec1,INSERT_VALUES,SCATTER_FORWARD);
1373 LIBMESH_CHKERR(
ierr);
1375 ierr = VecScale(subvec1,-1.0);
1376 LIBMESH_CHKERR(
ierr);
1378 #if !PETSC_VERSION_LESS_THAN(3,1,0) 1379 ierr = LibMeshCreateSubMatrix(mat,
1380 _restrict_solve_to_is,
1381 _restrict_solve_to_is_complement,
1384 LIBMESH_CHKERR(
ierr);
1397 Vec subvec2 =
nullptr;
1398 ierr = VecCreate(this->comm().
get(),&subvec2);
1399 LIBMESH_CHKERR(
ierr);
1400 ierr = VecSetSizes(subvec2,is_local_size,PETSC_DECIDE);
1401 LIBMESH_CHKERR(
ierr);
1402 ierr = VecSetFromOptions(subvec2);
1403 LIBMESH_CHKERR(
ierr);
1404 ierr = MatMult(submat1,subvec1,subvec2);
1405 LIBMESH_CHKERR(
ierr);
1406 ierr = VecAXPY(subrhs,1.0,subvec2);
1407 LIBMESH_CHKERR(
ierr);
1409 ierr = LibMeshVecScatterDestroy(&scatter1);
1410 LIBMESH_CHKERR(
ierr);
1411 ierr = LibMeshVecDestroy(&subvec1);
1412 LIBMESH_CHKERR(
ierr);
1413 ierr = LibMeshMatDestroy(&submat1);
1414 LIBMESH_CHKERR(
ierr);
1417 #if PETSC_RELEASE_LESS_THAN(3,5,0) 1418 ierr = KSPSetOperators(_ksp, submat, subprecond,
1419 DIFFERENT_NONZERO_PATTERN);
1421 ierr = KSPSetOperators(_ksp, submat, subprecond);
1423 LIBMESH_CHKERR(
ierr);
1425 if (this->_preconditioner)
1428 this->_preconditioner->set_matrix(*subprecond_matrix);
1429 this->_preconditioner->init();
1434 #if PETSC_RELEASE_LESS_THAN(3,5,0) 1436 DIFFERENT_NONZERO_PATTERN);
1440 LIBMESH_CHKERR(
ierr);
1442 if (this->_preconditioner)
1445 this->_preconditioner->init();
1451 ierr = KSPSetTolerances (_ksp, tol, PETSC_DEFAULT,
1452 PETSC_DEFAULT, max_its);
1453 LIBMESH_CHKERR(
ierr);
1456 ierr = KSPSetFromOptions(_ksp);
1457 LIBMESH_CHKERR(
ierr);
1460 if (_restrict_solve_to_is !=
nullptr)
1462 ierr = KSPSolve (_ksp, subrhs, subsolution);
1463 LIBMESH_CHKERR(
ierr);
1467 ierr = KSPSolve (_ksp, rhs->vec(), solution->vec());
1468 LIBMESH_CHKERR(
ierr);
1472 ierr = KSPGetIterationNumber (_ksp, &its);
1473 LIBMESH_CHKERR(
ierr);
1476 ierr = KSPGetResidualNorm (_ksp, &final_resid);
1477 LIBMESH_CHKERR(
ierr);
1479 if (_restrict_solve_to_is !=
nullptr)
1481 switch(_subset_solve_mode)
1484 ierr = VecZeroEntries(solution->vec());
1485 LIBMESH_CHKERR(
ierr);
1489 ierr = VecCopy(rhs->vec(),solution->vec());
1490 LIBMESH_CHKERR(
ierr);
1498 libmesh_error_msg(
"Invalid subset solve mode = " << _subset_solve_mode);
1500 ierr = VecScatterBegin(scatter,subsolution,solution->vec(),INSERT_VALUES,SCATTER_REVERSE);
1501 LIBMESH_CHKERR(
ierr);
1502 ierr = VecScatterEnd(scatter,subsolution,solution->vec(),INSERT_VALUES,SCATTER_REVERSE);
1503 LIBMESH_CHKERR(
ierr);
1505 ierr = LibMeshVecScatterDestroy(&scatter);
1506 LIBMESH_CHKERR(
ierr);
1508 if (this->_preconditioner)
1513 this->_preconditioner->init();
1516 ierr = LibMeshVecDestroy(&subsolution);
1517 LIBMESH_CHKERR(
ierr);
1518 ierr = LibMeshVecDestroy(&subrhs);
1519 LIBMESH_CHKERR(
ierr);
1520 ierr = LibMeshMatDestroy(&submat);
1521 LIBMESH_CHKERR(
ierr);
1522 ierr = LibMeshMatDestroy(&subprecond);
1523 LIBMESH_CHKERR(
ierr);
1527 ierr = LibMeshMatDestroy(&mat);
1528 LIBMESH_CHKERR(
ierr);
1531 return std::make_pair(its, final_resid);
1536 template <
typename T>
1539 PetscErrorCode
ierr = 0;
1549 ierr = KSPGetResidualHistory(_ksp, &p, &its);
1550 LIBMESH_CHKERR(
ierr);
1553 if (its == 0)
return;
1559 for (PetscInt i=0; i<its; ++i)
1569 template <
typename T>
1572 PetscErrorCode
ierr = 0;
1582 ierr = KSPGetResidualHistory(_ksp, &p, &its);
1583 LIBMESH_CHKERR(
ierr);
1588 libMesh::err <<
"No iterations have been performed, returning 0." << std::endl;
1599 template <
typename T>
1602 PetscErrorCode
ierr = 0;
1604 switch (this->_solver_type)
1608 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPCG));
1609 LIBMESH_CHKERR(
ierr);
1613 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPCR));
1614 LIBMESH_CHKERR(
ierr);
1618 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPCGS));
1619 LIBMESH_CHKERR(
ierr);
1623 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPBICG));
1624 LIBMESH_CHKERR(
ierr);
1628 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPTCQMR));
1629 LIBMESH_CHKERR(
ierr);
1633 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPTFQMR));
1634 LIBMESH_CHKERR(
ierr);
1638 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPLSQR));
1639 LIBMESH_CHKERR(
ierr);
1643 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPBCGS));
1644 LIBMESH_CHKERR(
ierr);
1648 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPMINRES));
1649 LIBMESH_CHKERR(
ierr);
1653 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPGMRES));
1654 LIBMESH_CHKERR(
ierr);
1658 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPRICHARDSON));
1659 LIBMESH_CHKERR(
ierr);
1663 #if defined(LIBMESH_HAVE_PETSC) && PETSC_VERSION_LESS_THAN(3,3,0) 1664 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPCHEBYCHEV));
1665 LIBMESH_CHKERR(
ierr);
1668 ierr = KSPSetType (_ksp, const_cast<KSPType>(KSPCHEBYSHEV));
1669 LIBMESH_CHKERR(
ierr);
1677 <<
"Continuing with PETSC defaults" << std::endl;
1683 template <
typename T>
1686 KSPConvergedReason reason;
1687 KSPGetConvergedReason(_ksp, &reason);
1691 #if !PETSC_VERSION_LESS_THAN(3,2,0) 1709 #if PETSC_VERSION_LESS_THAN(3,4,0) 1716 #if !PETSC_VERSION_LESS_THAN(3,7,0) 1720 libMesh::err <<
"Unknown convergence flag!" << std::endl;
1726 template <
typename T>
1730 PetscErrorCode
ierr=0;
1732 ierr = MatShellGetContext(mat,&ctx);
1750 template <
typename T>
1754 PetscErrorCode
ierr=0;
1756 ierr = MatShellGetContext(mat,&ctx);
1769 arg_global = add_global;
1780 template <
typename T>
1784 PetscErrorCode
ierr=0;
1786 ierr = MatShellGetContext(mat,&ctx);
1811 #endif // #ifdef LIBMESH_HAVE_PETSC std::string name(const ElemQuality q)
void petsc_auto_fieldsplit(PC my_pc, const System &sys)
NumericVector interface to PETSc Vec.
void get_residual_history(std::vector< double > &hist)
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &matrix_in, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its) override
virtual numeric_index_type size() const =0
virtual void init(const char *name=nullptr) override
static PetscErrorCode _petsc_shell_matrix_mult_add(Mat mat, Vec arg, Vec add, Vec dest)
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
const Parallel::Communicator & comm() const
virtual void vector_mult_add(NumericVector< T > &dest, const NumericVector< T > &arg) const =0
processor_id_type n_processors() const
PetscLinearSolver(const libMesh::Parallel::Communicator &comm_in)
PetscErrorCode libmesh_petsc_preconditioner_setup(void *ctx)
Manages consistently variables, degrees of freedom, and coefficient vectors.
void set_petsc_solver_type()
void init(triangulateio &t)
virtual void restrict_solve_to(const std::vector< unsigned int > *const dofs, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO) override
OStreamProxy err(std::cerr)
virtual std::pair< unsigned int, Real > adjoint_solve(SparseMatrix< T > &matrix_in, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const double tol, const unsigned int m_its) override
PetscErrorCode __libmesh_petsc_preconditioner_setup(void *ctx)
virtual void init_names(const System &) override
static void set_petsc_preconditioner_type(const PreconditionerType &preconditioner_type, PC &pc)
std::string enum_to_string(const T e)
virtual void get_diagonal(NumericVector< T > &dest) const =0
static PetscErrorCode _petsc_shell_matrix_mult(Mat mat, Vec arg, Vec dest)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real get_initial_residual()
PetscErrorCode libmesh_petsc_preconditioner_apply(void *ctx, Vec x, Vec y)
virtual numeric_index_type local_size() const =0
PreconditionerType _preconditioner_type
SparseMatrix interface to PETSc Mat.
virtual LinearConvergenceReason get_converged_reason() const override
PetscErrorCode __libmesh_petsc_preconditioner_apply(void *ctx, Vec x, Vec y)
virtual void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const =0
virtual void close() override
static PetscErrorCode _petsc_shell_matrix_get_diagonal(Mat mat, Vec dest)
virtual void clear() override
virtual void close() override