Chi-Tech
mgd_01aa_init_two_grid_params.cc
Go to the documentation of this file.
2#include "chi_runtime.h"
3#include "chi_log.h"
5
7{
8 // loop over all materials
9 for (const auto &mat_id_xs: matid_to_xs_map) {
10
11 // get the P0 transfer matrix and total XS
12 const auto &isotropic_transfer_matrix = mat_id_xs.second->TransferMatrix(0);
13 const auto &sigma_t = mat_id_xs.second->SigmaTotal();
14 const auto &diffusion_coeff = mat_id_xs.second->DiffusionCoefficient();
15
16 // put P0 transfer matrix in nicer form
18 for (unsigned int g = 0; g < num_groups_; ++g)
19 for (const auto &[row_g, gprime, sigma]: isotropic_transfer_matrix.Row(g))
20 S[g][gprime] = sigma;
21
22 // (L+D) e_new = -U e_old
23 // original matrix = diag(total) - scattering
24 // so L+D = diag(removal) - tril(scattering)
25 // and U = -triu(scattering)
28 for (unsigned int g = 0; g < num_groups_; ++g)
29 {
30 A[g][g] = sigma_t[g] - S[g][g];
31 for (unsigned int gp = 0; gp < g; ++gp)
32 A[g][gp] = -S[g][gp];
33 for (unsigned int gp = g + 1; gp < num_groups_; ++gp)
34 B[g][gp] = S[g][gp];
35 }
36 MatDbl Ainv = chi_math::Inverse(A);
37 // finally, obtain the iteration matrix
38 MatDbl C_ = chi_math::MatMul(Ainv, B);
39 // Perform power iteration
40 VecDbl E(num_groups_, 1.0);
41 double rho = chi_math::PowerIteration(C_, E, 10000, 1.0e-12);
42
43 // Compute two-grid diffusion quantities
44 // normalize spectrum
45 std::vector<double> spectrum(num_groups_, 1.0);
46 double sum = 0.0;
47 for (unsigned int g = 0; g < num_groups_; ++g)
48 sum += std::fabs(E[g]);
49 for (unsigned int g = 0; g < num_groups_; ++g)
50 spectrum[g] = std::fabs(E[g]) / sum;
51 // D ave and Sigma_a ave
52 double collapsed_D = 0.0;
53 double collapsed_sig_a = 0.0;
54 for (unsigned int g = last_fast_group_; g < num_groups_; ++g)
55 {
56 collapsed_D += diffusion_coeff[g] * spectrum[g];
57 collapsed_sig_a += sigma_t[g] * spectrum[g];
58 for (unsigned int gp = last_fast_group_; gp < num_groups_; ++gp)
59 collapsed_sig_a -= S[g][gp] * spectrum[gp];
60 }
61 // Verbose output the spectrum
62 Chi::log.Log0Verbose1() << "Fundamental eigen-value: " << rho;
63 std::stringstream outstr;
64 for (auto &xi: spectrum)
65 outstr << xi << '\n';
66 Chi::log.Log0Verbose1() << outstr.str(); // jcr verbose1
67
68// std::stringstream outstr2;
69// for (auto &xi: diffusion_coeff)
70// outstr2 << xi << '\n';
71// chi::log.Log0Verbose0() << outstr2.str(); // jcr verbose1
72//
73// std::cout << "collapsed = " << collapsed_sig_a
74// <<", "<< collapsed_D << std::endl;
75// chi::Exit(12345);
76
77 const auto mat_id = mat_id_xs.first;
79 std::make_pair(mat_id, TwoGridCollapsedInfo{collapsed_D,
80 collapsed_sig_a,
81 spectrum} ) );
82
83 }// end loop over materials
84
85}
std::vector< VecDbl > MatDbl
Definition: chi_math.h:13
std::vector< double > VecDbl
Definition: chi_math.h:12
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log0Verbose1()
Definition: chi_log.h:234
std::map< int, TwoGridCollapsedInfo > map_mat_id_2_tginfo
std::map< int, std::shared_ptr< chi_physics::MultiGroupXS > > matid_to_xs_map
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)