Chi-Tech
energy_collapse.cc
Go to the documentation of this file.
1#include "acceleration.h"
2
4
5#include "chi_runtime.h"
6#include "chi_log.h"
7
8namespace lbs::acceleration
9{
10// ###################################################################
11/***/
12TwoGridCollapsedInfo
15{
16 const std::string fname = "lbs::acceleration::MakeTwoGridCollapsedInfo";
17
18 const size_t num_groups = xs.NumGroups();
19 const auto& sigma_t = xs.SigmaTotal();
20 const auto& diffusion_coeff = xs.DiffusionCoefficient();
21
22 //============================================= Make a Dense matrix from
23 // sparse transfer matrix
24 if (xs.TransferMatrices().empty())
25 throw std::logic_error(fname + ": list of scattering matrices empty.");
26
27 const auto& isotropic_transfer_matrix = xs.TransferMatrix(0);
28
29 MatDbl S(num_groups, VecDbl(num_groups, 0.0));
30 for (int g = 0; g < num_groups; g++)
31 for (const auto& [row_g, gprime, sigma] : isotropic_transfer_matrix.Row(g))
32 S[g][gprime] = sigma;
33
34 //============================================= Compiling the A and B matrices
35 // for different methods
36 MatDbl A(num_groups, VecDbl(num_groups, 0.0));
37 MatDbl B(num_groups, VecDbl(num_groups, 0.0));
38 for (int g = 0; g < num_groups; g++)
39 {
40 if (scheme == EnergyCollapseScheme::JFULL)
41 {
42 A[g][g] = sigma_t[g] - S[g][g];
43 for (int gp = 0; gp < g; gp++)
44 B[g][gp] = S[g][gp];
45
46 for (int gp = g + 1; gp < num_groups; gp++)
47 B[g][gp] = S[g][gp];
48 }
49 else if (scheme == EnergyCollapseScheme::JPARTIAL)
50 {
51 A[g][g] = sigma_t[g];
52 for (int gp = 0; gp < num_groups; gp++)
53 B[g][gp] = S[g][gp];
54 }
55 } // for g
56
57 //============================================= Correction for zero xs groups
58 // Some cross-sections developed from monte-carlo
59 // methods can result in some of the groups
60 // having zero cross-sections. In that case
61 // it will screw up the power iteration
62 // initial guess of 1.0. Here we reset them
63 for (int g = 0; g < num_groups; g++)
64 if (sigma_t[g] < 1.0e-16) A[g][g] = 1.0;
65
66 MatDbl Ainv = chi_math::Inverse(A);
67 MatDbl C = chi_math::MatMul(Ainv, B);
68 VecDbl E(num_groups, 1.0);
69
70 double collapsed_D = 0.0;
71 double collapsed_sig_a = 0.0;
72 std::vector<double> spectrum(num_groups, 1.0);
73
74 //============================================= Perform power iteration
75 double rho = chi_math::PowerIteration(C, E, 1000, 1.0e-12);
76
77 //======================================== Compute two-grid diffusion
78 // quantities
79 double sum = 0.0;
80 for (int g = 0; g < num_groups; g++)
81 sum += std::fabs(E[g]);
82
83 for (int g = 0; g < num_groups; g++)
84 spectrum[g] = std::fabs(E[g]) / sum;
85
86 for (int g = 0; g < num_groups; ++g)
87 {
88 collapsed_D += diffusion_coeff[g] * spectrum[g];
89
90 collapsed_sig_a += sigma_t[g] * spectrum[g];
91
92 for (int gp = 0; gp < num_groups; ++gp)
93 collapsed_sig_a -= S[g][gp] * spectrum[gp];
94 }
95
96 //======================================== Verbose output the spectrum
97 Chi::log.Log0Verbose1() << "Fundamental eigen-value: " << rho;
98 std::stringstream outstr;
99 for (auto& xi : spectrum)
100 outstr << xi << '\n';
101 Chi::log.Log0Verbose1() << outstr.str();
102
103 return {collapsed_D, collapsed_sig_a, spectrum};
104}
105
106} // namespace lbs::acceleration
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log0Verbose1()
Definition: chi_log.h:234
virtual const unsigned int NumGroups() const =0
virtual const chi_math::SparseMatrix & TransferMatrix(unsigned int ell) const =0
virtual const std::vector< double > & SigmaTotal() const =0
virtual const std::vector< chi_math::SparseMatrix > & TransferMatrices() const =0
virtual const std::vector< double > & DiffusionCoefficient() const =0
double PowerIteration(const MatDbl &A, VecDbl &e_vec, int max_it=2000, double tol=1.0e-13)
MatDbl Inverse(const MatDbl &A)
MatDbl MatMul(const MatDbl &A, const double c)
@ JFULL
Jacobi with full conv. of within-group scattering.
@ JPARTIAL
Jacobi with partially conv. of within-group scattering.
TwoGridCollapsedInfo MakeTwoGridCollapsedInfo(const chi_physics::MultiGroupXS &xs, EnergyCollapseScheme scheme)
std::vector< VecDbl > MatDbl
Definition: lbs_structs.h:19
std::vector< double > VecDbl
Definition: lbs_structs.h:18