Chi-Tech
mip_wgs_context2.cc
Go to the documentation of this file.
1#include "mip_wgs_context2.h"
2
3#include <petscksp.h>
4
9
10#include "chi_runtime.h"
11#include "chi_log.h"
12
13#include <iomanip>
14
15#define sc_double static_cast<double>
16#define PCShellPtr PetscErrorCode (*)(PC, Vec, Vec)
17
18namespace lbs
19{
20
21template<>
23{
24 if (log_info_)
25 {
26 std::string method_name;
27 switch (groupset_.iterative_method_)
28 {
30 method_name = "KRYLOV_RICHARDSON"; break;
32 method_name = "KRYLOV_GMRES"; break;
34 method_name = "KRYLOV_BICGSTAB"; break;
35 default: method_name = "KRYLOV_GMRES";
36 }
38 << "\n\n"
39 << "********** Solving groupset " << groupset_.id_
40 << " with " << method_name << ".\n\n";
41 }
42}
43
44template<>
46{
47 auto& ksp = solver;
48
49 PC pc;
50 KSPGetPC(ksp, &pc);
51
52 if (groupset_.apply_tgdsa_)
53 {
54 PCSetType(pc, PCSHELL);
55 PCShellSetApply(pc, (PCShellPtr) MIP_TGDSA_PreConditionerMult);
56 PCShellSetContext(pc, &(*this));
57 }
58
59 KSPSetPCSide(ksp,PC_LEFT);
60 KSPSetUp(ksp);
61}
62
63template<>
64std::pair<int64_t, int64_t> MIPWGSContext2<Mat, Vec, KSP>::SystemSize()
65{
66 const size_t local_node_count = lbs_solver_.LocalNodeCount();
67 const size_t globl_node_count = lbs_solver_.GlobalNodeCount();
68
69 const size_t groupset_numgrps = groupset_.groups_.size();
70 const size_t local_size = local_node_count * groupset_numgrps;
71 const size_t globl_size = globl_node_count * groupset_numgrps;
72
73 return {static_cast<int64_t>(local_size),
74 static_cast<int64_t>(globl_size)};
75}
76
77template<>
79{
80 ++counter_applications_of_inv_op_;
81 auto& mip_solver = *lbs_mip_ss_solver_.gs_mip_solvers_[groupset_.id_];
82
83 lbs_solver_.PhiNewLocal() = lbs_solver_.QMomentsLocal();
84
85 Vec work_vector;
86 VecDuplicate(mip_solver.RHS(), &work_vector);
87
88 lbs_solver_.SetGSPETScVecFromPrimarySTLvector(groupset_,
89 work_vector,
91
92 mip_solver.Assemble_b(work_vector);
93 mip_solver.Solve(work_vector);
94
95 lbs_solver_.SetPrimarySTLvectorFromGSPETScVec(groupset_,
96 work_vector,
98
99 VecDestroy(&work_vector);
100}
101
102template<>
104{
105 lbs_solver_.GSScopedCopyPrimarySTLvectors(groupset_,
108}
109
110}//namespace lbs
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
#define PCShellPtr
@ KRYLOV_BICGSTAB
BiCGStab iterative algorithm.
@ KRYLOV_RICHARDSON
Richardson iteration.
@ KRYLOV_GMRES
GMRES iterative algorithm.
int MIP_TGDSA_PreConditionerMult(PC pc, Vec phi_input, Vec pc_output)
struct _p_Vec * Vec
void SetPreconditioner(SolverType &solver) override
void ApplyInverseTransportOperator(int scope) override
void PostSolveCallback() override
void PreSetupCallback() override
std::pair< int64_t, int64_t > SystemSize() override