18 std::vector<double>& solution,
bool use_initial_guess )
20 const std::string fname =
"lbs::acceleration::DiffusionMIPSolver::Solve";
22 VecDuplicate(
rhs_, &x);
25 if (not use_initial_guess) KSPSetInitialGuessNonzero(
ksp_, PETSC_FALSE);
27 KSPSetInitialGuessNonzero(
ksp_, PETSC_TRUE);
29 KSPSetTolerances(
ksp_,
37 PetscBool symmetry = PETSC_FALSE;
38 MatIsSymmetric(
A_, 1.0e-6, &symmetry);
39 if (symmetry == PETSC_FALSE)
40 throw std::logic_error(fname +
":Symmetry check failed");
46 KSPSetConvergenceTest(
52 VecNorm(
rhs_, NORM_2, &rhs_norm);
56 if (use_initial_guess)
59 VecGetArray(x, &x_raw);
61 for (
const auto& value : solution)
63 VecRestoreArray(x, &x_raw);
73 VecNorm(x, NORM_2, &sol_norm);
77 KSPConvergedReason reason;
78 KSPGetConvergedReason(
ksp_, &reason);
105 Vec petsc_solution,
bool use_initial_guess )
107 const std::string fname =
"lbs::acceleration::DiffusionMIPSolver::Solve";
109 VecDuplicate(rhs_, &x);
112 if (not use_initial_guess) KSPSetInitialGuessNonzero(ksp_, PETSC_FALSE);
114 KSPSetInitialGuessNonzero(ksp_, PETSC_TRUE);
116 KSPSetTolerances(ksp_,
117 options.residual_tolerance,
118 options.residual_tolerance,
122 if (options.perform_symmetry_check)
124 PetscBool symmetry = PETSC_FALSE;
125 MatIsSymmetric(A_, 1.0e-6, &symmetry);
126 if (symmetry == PETSC_FALSE)
127 throw std::logic_error(fname +
":Symmetry check failed");
133 KSPSetConvergenceTest(
139 VecNorm(rhs_, NORM_2, &rhs_norm);
143 if (use_initial_guess) { VecCopy(petsc_solution, x); }
146 KSPSolve(ksp_, rhs_, x);
152 VecNorm(x, NORM_2, &sol_norm);
156 KSPConvergedReason reason;
157 KSPGetConvergedReason(ksp_, &reason);
165 VecCopy(x, petsc_solution);
LogStream Log(LOG_LVL level=LOG_0)
virtual void LocalizePETScVectorWithGhosts(Vec petsc_vector, std::vector< double > &local_vector, const UnknownManager &unknown_manager) const
virtual void LocalizePETScVector(Vec petsc_vector, std::vector< double > &local_vector, const UnknownManager &unknown_manager) const
struct lbs::acceleration::DiffusionSolver::Options options
const bool requires_ghosts_
const chi_math::SpatialDiscretization & sdm_
void Solve(std::vector< double > &solution, bool use_initial_guess=false)
const chi_math::UnknownManager uk_man_
PetscErrorCode RelativeResidualConvergenceTest(KSP ksp, PetscInt n, PetscReal rnorm, KSPConvergedReason *convergedReason, void *monitordestroy)
PetscErrorCode KSPMonitorRelativeToRHS(KSP ksp, PetscInt n, PetscReal rnorm, void *)
void CommunicateGhostEntries(Vec x)
std::string GetPETScConvergedReasonstring(KSPConvergedReason reason)
int max_iters
Maximum iterations.
double residual_tolerance
Residual tol. relative to rhs.
bool verbose
Verbosity flag.
bool perform_symmetry_check
For debugging only (very expensive)