15#define sc_int64_t static_cast<int64_t>
17#define GetAGSContextPtr(x) \
18 std::dynamic_pointer_cast<AGSContext<Mat,Vec,KSP>>(x)
27 const auto sizes = ags_context_ptr->SystemSize();
29 num_local_dofs_ = sizes.first;
30 num_globl_dofs_ = sizes.second;
43 MatCreateShell(PETSC_COMM_WORLD,
sc_int64_t(num_local_dofs_),
47 &(*context_ptr_),&A_);
50 MatShellSetOperation(A_, MATOP_MULT,
51 (
void (*)()) chi_math::LinearSolverMatrixAction<Mat, Vec>);
54 KSPSetOperators(solver_, A_, A_);
63 ags_context_ptr->SetPreconditioner(solver_);
80 auto& lbs_solver = ags_context_ptr->lbs_solver_;
82 const int gid_i = GroupSpanFirstID();
83 const int gid_f = GroupSpanLastID();
84 const auto& phi = lbs_solver.PhiOldLocal();
87 VecDuplicate(x_, &x_old);
92 const auto saved_qmoms = lbs_solver.QMomentsLocal();
94 for (
int iter = 0; iter < tolerance_options_.maximum_iterations; ++iter)
97 lbs_solver.SetGroupScopedPETScVecFromPrimarySTLvector(gid_i,gid_f,x_old,phi);
99 for (
auto& solver : ags_context_ptr->sub_solvers_list_)
105 lbs_solver.SetGroupScopedPETScVecFromPrimarySTLvector(gid_i,gid_f,x_,phi);
107 VecAXPY(x_old, -1.0, x_);
108 PetscReal error_norm; VecNorm(x_old, NORM_2, &error_norm);
109 PetscReal sol_norm;VecNorm(x_, NORM_2, &sol_norm);
114 <<
"********** AGS solver iteration " << std::setw(3) << iter <<
" "
115 <<
" Relative change " << std::setw(10) << std::setprecision(4)
116 << error_norm/sol_norm;
118 lbs_solver.QMomentsLocal() = saved_qmoms;
120 if (error_norm < tolerance_options_.residual_absolute)
#define GetAGSContextPtr(x)
LogStream Log(LOG_LVL level=LOG_0)
void SetInitialGuess() override
void SetPreconditioner() override
virtual void SetSystemSize() override
virtual void SetSystem() override
virtual ~AGSLinearSolver() override
Vec CreateVector(int64_t local_size, int64_t global_size)