Chi-Tech
lbs_03e_tgdsa.cc
Go to the documentation of this file.
2
4
6
8
9// ###################################################################
10/**Initializes the Within-Group DSA solver. */
12{
13 if (groupset.apply_tgdsa_)
14 {
15 //=========================================== Make UnknownManager
16 const auto& uk_man = discretization_->UNITARY_UNKNOWN_MANAGER;
17
18 //=========================================== Make boundary conditions
20
21 //=========================================== Make TwoGridInfo
22 for (const auto& mat_id_xs_pair : matid_to_xs_map_)
23 {
24 const auto& mat_id = mat_id_xs_pair.first;
25 const auto& xs = mat_id_xs_pair.second;
26
30
32 std::make_pair(mat_id, std::move(tginfo)));
33 }
34
35 //=========================================== Make xs map
37 typedef std::map<int, MGXS> MatID2MGDXSMap;
38 MatID2MGDXSMap matid_2_mgxs_map;
39 for (const auto& matid_xs_pair : matid_to_xs_map_)
40 {
41 const auto& mat_id = matid_xs_pair.first;
42
43 const auto& tg_info =
45
46 matid_2_mgxs_map.insert(
47 std::make_pair(mat_id, MGXS{{tg_info.collapsed_D},
48 {tg_info.collapsed_sig_a}}));
49 }
50
51 //=========================================== Create solver
52 const auto& sdm = *discretization_;
53
54 auto solver = std::make_shared<acceleration::DiffusionMIPSolver>(
55 std::string(TextName() + "_TGDSA"),
56 sdm,
57 uk_man,
58 bcs,
59 matid_2_mgxs_map,
61 true); // verbosity
62
63 solver->options.residual_tolerance = groupset.tgdsa_tol_;
64 solver->options.max_iters = groupset.tgdsa_max_iters_;
65 solver->options.verbose = groupset.tgdsa_verbose_;
66 solver->options.additional_options_string = groupset.tgdsa_string_;
67
68 solver->Initialize();
69
70 std::vector<double> dummy_rhs(sdm.GetNumLocalDOFs(uk_man), 0.0);
71
72 solver->AssembleAand_b(dummy_rhs);
73
74 groupset.tgdsa_solver_ = solver;
75 }
76}
77
78// ###################################################################
79/**Cleans up memory consuming items. */
81{
82 if (groupset.apply_tgdsa_) groupset.tgdsa_solver_ = nullptr;
83}
84
85// ###################################################################
86/**Assembles a delta-phi vector on the first moment.*/
88 const LBSGroupset& groupset,
89 const std::vector<double>& phi_in,
90 std::vector<double>& delta_phi_local)
91{
92 const auto& sdm = *discretization_;
93 const auto& phi_uk_man = flux_moments_uk_man_;
94
95 const int gsi = groupset.groups_.front().id_;
96 const size_t gss = groupset.groups_.size();
97
98 delta_phi_local.clear();
99 delta_phi_local.assign(local_node_count_, 0.0);
100
101 for (const auto& cell : grid_ptr_->local_cells)
102 {
103 const auto& cell_mapping = sdm.GetCellMapping(cell);
104 const size_t num_nodes = cell_mapping.NumNodes();
105 const auto& S = matid_to_xs_map_[cell.material_id_]->TransferMatrix(0);
106
107 for (size_t i = 0; i < num_nodes; ++i)
108 {
109 const int64_t dphi_map = sdm.MapDOFLocal(cell, i);
110 const int64_t phi_map = sdm.MapDOFLocal(cell, i, phi_uk_man, 0, 0);
111
112 double& delta_phi_mapped = delta_phi_local[dphi_map];
113 const double* phi_in_mapped = &phi_in[phi_map];
114
115 for (size_t g = 0; g < gss; ++g)
116 {
117 double R_g = 0.0;
118 for (const auto& [row_g, gprime, sigma_sm] : S.Row(gsi + g))
119 if (gprime >= gsi and gprime != (gsi + g))
120 R_g += sigma_sm * phi_in_mapped[gprime];
121
122 delta_phi_mapped += R_g;
123 } // for g
124 } // for node
125 } // for cell
126}
127
128// ###################################################################
129/**DAssembles a delta-phi vector on the first moment.*/
131 const LBSGroupset& groupset,
132 const std::vector<double>& delta_phi_local,
133 std::vector<double>& ref_phi_new)
134{
135 const auto& sdm = *discretization_;
136 const auto& phi_uk_man = flux_moments_uk_man_;
137
138 const int gsi = groupset.groups_.front().id_;
139 const size_t gss = groupset.groups_.size();
140
141 const auto& map_mat_id_2_tginfo =
143
144 for (const auto& cell : grid_ptr_->local_cells)
145 {
146 const auto& cell_mapping = sdm.GetCellMapping(cell);
147 const size_t num_nodes = cell_mapping.NumNodes();
148
149 const auto& xi_g = map_mat_id_2_tginfo.at(cell.material_id_).spectrum;
150
151 for (size_t i = 0; i < num_nodes; ++i)
152 {
153 const int64_t dphi_map = sdm.MapDOFLocal(cell, i);
154 const int64_t phi_map = sdm.MapDOFLocal(cell, i, phi_uk_man, 0, gsi);
155
156 const double delta_phi_mapped = delta_phi_local[dphi_map];
157 double* phi_new_mapped = &ref_phi_new[phi_map];
158
159 for (int g = 0; g < gss; ++g)
160 phi_new_mapped[g] += delta_phi_mapped * xi_g[gsi + g];
161 } // for dof
162 } // for cell
163}
std::string TextName() const
Definition: chi_solver.cc:116
struct lbs::LBSGroupset::TwoGridAccelerationInfo tg_acceleration_info_
std::shared_ptr< lbs::acceleration::DiffusionMIPSolver > tgdsa_solver_
Definition: lbs_groupset.h:73
std::vector< LBSGroup > groups_
Definition: lbs_groupset.h:41
std::string tgdsa_string_
Definition: lbs_groupset.h:70
static void CleanUpTGDSA(LBSGroupset &groupset)
std::shared_ptr< chi_math::SpatialDiscretization > discretization_
Definition: lbs_solver.h:74
std::vector< UnitCellMatrices > unit_cell_matrices_
Definition: lbs_solver.h:81
void AssembleTGDSADeltaPhiVector(const LBSGroupset &groupset, const std::vector< double > &phi_in, std::vector< double > &delta_phi_local)
std::map< uint64_t, std::shared_ptr< SweepBndry > > sweep_boundaries_
Definition: lbs_solver.h:86
void DisAssembleTGDSADeltaPhiVector(const LBSGroupset &groupset, const std::vector< double > &delta_phi_local, std::vector< double > &ref_phi_new)
void InitTGDSA(LBSGroupset &groupset)
std::map< int, XSPtr > matid_to_xs_map_
Definition: lbs_solver.h:71
std::map< uint64_t, BoundaryCondition > TranslateBCs(const std::map< uint64_t, SwpBndryPtr > &sweep_boundaries, bool vaccum_bcs_are_dirichlet)
Definition: acceleration.cc:12
@ JFULL
Jacobi with full conv. of within-group scattering.
TwoGridCollapsedInfo MakeTwoGridCollapsedInfo(const chi_physics::MultiGroupXS &xs, EnergyCollapseScheme scheme)
std::map< int, acceleration::TwoGridCollapsedInfo > map_mat_id_2_tginfo
Definition: lbs_groupset.h:77