Chi-Tech
single_state_mgxs_02_diffparams.cc
Go to the documentation of this file.
1#include "single_state_mgxs.h"
2#include "chi_runtime.h"
3#include "chi_log.h"
4
5
6//######################################################################
8{
9 sigma_a_.assign(num_groups_, 0.0);
10
11 // compute for a pure absorber
12 if (transfer_matrices_.empty())
13 for (size_t g = 0; g < num_groups_; ++g)
14 sigma_a_[g] = sigma_t_[g];
15
16 // estimate from a transfer matrix
17 else
18 {
20 << "Estimating absorption from the transfer matrices.";
21
22 const auto& S0 = transfer_matrices_[0];
23 for (size_t g = 0; g < num_groups_; ++g)
24 {
25 // estimate the scattering cross section
26 double sig_s = 0.0;
27 for (size_t row = 0; row < S0.NumRows(); ++row)
28 {
29 const auto& cols = S0.rowI_indices_[row];
30 const auto& vals = S0.rowI_values_[row];
31 for (size_t t = 0; t < cols.size(); ++t)
32 if (cols[t] == g)
33 {
34 sig_s += vals[t];
35 break;
36 }
37 }
38
39 sigma_a_[g] = sigma_t_[g] - sig_s;
40
41 // TODO: Should negative absorption be allowed?
42 if (sigma_a_[g] < 0.0)
44 << "Negative absorption cross section encountered "
45 << "in group " << g << " when estimating from the "
46 << "transfer matrices";
47 }//for g
48 }//if scattering present
49}
50
51
52//######################################################################
54{
55 if (diffusion_initialized_)
56 return;
57
58 //initialize diffusion data
59 diffusion_coeff_.resize(num_groups_, 1.0);
60 sigma_s_gtog_.resize(num_groups_, 0.0);
61 sigma_removal_.resize(num_groups_, 0.1);
62
63 //perfom computations group-wise
64 const auto& S = transfer_matrices_;
65 for (unsigned int g = 0; g < num_groups_; ++g)
66 {
67 //============================================================
68 // Determine transport correction
69 //============================================================
70
71 double sig_1 = 0.0;
72 if (S.size() > 1)
73 {
74 for (unsigned int gp = 0; gp < num_groups_; ++gp)
75 {
76 const auto& cols = S[1].rowI_indices_[gp];
77 const auto& vals = S[1].rowI_values_[gp];
78 for (size_t t = 0; t < cols.size(); ++t)
79 if (cols[t] == g)
80 {
81 sig_1 += vals[t];
82 break;
83 }
84 }//for gp
85 }//if moment 1 available
86
87 //============================================================
88 // Compute diffusion coefficient
89 //============================================================
90
91 if (sig_1 >= sigma_t_[g])
92 {
93 sig_1 = 0.0;
95 << "Transport corrected diffusion coefficient failed for group "
96 << g << " in call to " << __FUNCTION__ << ". "
97 << "sigma_t=" << sigma_t_[g] << " sigs_g_(m=1)=" << sig_1
98 << ". Setting sigs_g_(m=1) to zero for this group.";
99 }
100
101 //compute the diffusion coefficient
102 //cap the value for when sig_t - sig_1 is near zero
103 diffusion_coeff_[g] = std::fmin(1.0e12,
104 1.0 / 3.0 / (sigma_t_[g] - sig_1));
105
106 //============================================================
107 // Determine within group scattering
108 //============================================================
109
110 if (!S.empty())
111 {
112 const auto& cols = S[0].rowI_indices_[g];
113 const auto& vals = S[0].rowI_values_[g];
114 for (size_t t = 0; t < cols.size(); ++t)
115 if (cols[t] == g)
116 {
117 sigma_s_gtog_[g] = vals[t];
118 break;
119 }
120 }
121
122 //============================================================
123 // Compute removal cross section
124 //============================================================
125
126 sigma_removal_[g] = std::max(0.0, sigma_t_[g] - sigma_s_gtog_[g]);
127 }//for g
128
129 diffusion_initialized_ = true;
130}
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log0Warning()
Definition: chi_log.h:231
unsigned int num_groups_
Total number of groups.
std::vector< double > sigma_t_
Total cross section.
std::vector< chi_math::SparseMatrix > transfer_matrices_
std::vector< double > sigma_a_
Absorption cross section.