Chi-Tech
multigroup_xs_export.cc
Go to the documentation of this file.
1#include "multigroup_xs.h"
2
3#include "chi_runtime.h"
4#include "chi_log.h"
5#include "utils/chi_timer.h"
6
7#include <iostream>
8
9//###################################################################
10/**
11 * Exports the cross section information to ChiTech format.
12 *
13 * \param file_name The name of the file to save the cross sections to.
14 * \param fission_scaling A factor to scale fission data to. This is
15 * generally equal to \f$ 1/k_{eff} \f$. Generally, this is done to
16 * create exactly critical cross sections for a transient initial
17 * condition.
18 */
20ExportToChiXSFile(const std::string &file_name,
21 const double fission_scaling /* = 1.0 */) const
22{
23 Chi::log.Log() << "Exporting transport cross section to file: " << file_name;
24
25 //============================================================
26 // Define utility functions
27 //============================================================
28
29 /**Lambda to print a 1D-xs*/
30 auto Print1DXS = [](std::ofstream& ofile,
31 const std::string& prefix,
32 const std::vector<double>& xs,
33 double min_value=-1.0)
34 {
35 bool proceed = false;
36 if (min_value >= 0.0)
37 {
38 for (auto val : xs)
39 if (val > min_value)
40 {
41 proceed = true;
42 break;
43 }
44
45 if (not proceed)
46 return;
47 }
48
49 ofile << "\n";
50 ofile << prefix << "_BEGIN\n";
51 {
52 unsigned int g = 0;
53 for (auto val : xs)
54 ofile << g++ << " "
55 << val << "\n";
56 }
57 ofile << prefix << "_END\n";
58 };
59
60 //============================================================
61 // Open the output file
62 //============================================================
63
64 std::ofstream ofile(file_name);
65
66 //============================================================
67 // Write the header info
68 //============================================================
69
70 std::vector<double> nu, nu_prompt, nu_delayed;
71 const auto& sigma_f = SigmaFission();
72 const auto& nu_sigma_f = NuSigmaF();
73 const auto& nu_prompt_sigma_f = NuPromptSigmaF();
74 const auto& nu_delayed_sigma_f = NuDelayedSigmaF();
75 for (unsigned int g = 0; g < NumGroups(); ++g)
76 {
77 if (NumPrecursors() > 0)
78 {
79 nu_prompt.push_back(nu_prompt_sigma_f[g] / sigma_f[g]);
80 nu_delayed.push_back(nu_delayed_sigma_f[g] / sigma_f[g]);
81 }
82 nu.push_back(nu_sigma_f[g] / sigma_f[g]);
83 }
84
85 std::vector<double> decay_constants, fractional_yields;
86 for (const auto& precursor : Precursors())
87 {
88 decay_constants.push_back(precursor.decay_constant);
89 fractional_yields.push_back(precursor.fractional_yield);
90 }
91
92
93
94 ofile << "# Exported cross section from ChiTech\n";
95 ofile << "# Date: " << chi::Timer::GetLocalDateTimeString() << "\n";
96 ofile << "NUM_GROUPS " << NumGroups() << "\n";
97 ofile << "NUM_MOMENTS " << ScatteringOrder() + 1 << "\n";
98 if (NumPrecursors() > 0)
99 ofile << "NUM_PRECURSORS " << NumPrecursors() << "\n";
100
101 //basic cross section data
102 Print1DXS(ofile, "SIGMA_T", SigmaTotal(), 1.0e-20);
103 Print1DXS(ofile, "SIGMA_A", SigmaAbsorption(), 1.0e-20);
104
105 //fission data
106 if (not SigmaFission().empty())
107 {
108 std::vector<double> scaled_sigma_f = SigmaFission();
109 if (fission_scaling != 1.0)
110 {
111 for (auto& val: scaled_sigma_f)
112 val *= fission_scaling;
113 }
114
115 Print1DXS(ofile, "SIGMA_F", scaled_sigma_f, 1.0e-20);
116 if (NumPrecursors() > 0)
117 {
118 Print1DXS(ofile, "NU_PROMPT", nu_prompt, 1.0e-20);
119 Print1DXS(ofile, "NU_DELAYED", nu_delayed, 1.0e-20);
120// Print1DXS(ofile, "CHI_PROMPT", chi_prompt, 1.0e-20);
121
122 ofile << "\nCHI_DELAYED_BEGIN\n";
123 const auto& precursors = Precursors();
124 for (unsigned int j = 0; j < NumPrecursors(); ++j)
125 for (unsigned int g = 0; g < NumGroups(); ++g)
126 ofile << "G_PRECURSOR_VAL"
127 << " " << g
128 << " " << j
129 << " " << precursors[j].emission_spectrum[g]
130 << "\n";
131 ofile << "CHI_DELAYED_END\n";
132
133 Print1DXS(ofile, "PRECURSOR_DECAY_CONSTANTS",
134 decay_constants, 1.0e-20);
135 Print1DXS(ofile, "PRECURSOR_FRACTIONAL_YIELDS",
136 fractional_yields, 1.0e-20);
137
138 }
139 else
140 {
141 Print1DXS(ofile, "NU", nu, 1.0e-20);
142// Print1DXS(ofile, "CHI", chi, 1.0e-20);
143 }
144 }
145
146 //inverse speed data
147 if (not InverseVelocity().empty())
148 Print1DXS(ofile, "INV_VELOCITY", InverseVelocity(), 1.0e-20);
149
150 //transfer matrices
151 if (not TransferMatrices().empty())
152 {
153 ofile << "\n";
154 ofile << "TRANSFER_MOMENTS_BEGIN\n";
155 for (size_t ell = 0; ell < TransferMatrices().size(); ++ell)
156 {
157 if (ell ==0 ) ofile << "#Zeroth moment (l=0)\n";
158 else ofile << "#(l=" << ell << ")\n";
159
160 const auto& matrix = TransferMatrix(ell);
161
162 for (size_t g = 0; g < matrix.rowI_values_.size(); ++g)
163 {
164 const auto& col_indices = matrix.rowI_indices_[g];
165 const auto& col_values = matrix.rowI_values_[g];
166
167 for (size_t k=0; k<col_indices.size(); ++k)
168 ofile << "M_GPRIME_G_VAL "
169 << ell << " "
170 << col_indices[k] << " "
171 << g << " "
172 << col_values[k] << "\n";
173 }//for g
174
175 ofile << "\n";
176 }//for ell
177 ofile << "TRANSFER_MOMENTS_END\n";
178 }//if has transfer matrices
179
180 if (not ProductionMatrix().empty())
181 {
182 const auto& F = ProductionMatrix();
183
184 ofile << "\n";
185 ofile << "PRODUCTION_MATRIX_BEGIN\n";
186 for (unsigned int g = 0; g < NumGroups(); ++g)
187 {
188 const auto& prod = F[g];
189 for (unsigned int gp = 0; gp < NumGroups(); ++gp)
190 {
191 const double value =
192 fission_scaling != 1.0 ?
193 prod[gp] * fission_scaling : prod[gp];
194
195 ofile << "G_GPRIME_VAL "
196 << g << " "
197 << gp << " "
198 << value << "\n";
199 }
200 }
201 }
202
203 ofile.close();
204
205 Chi::log.Log0Verbose1() << "Done exporting transport "
206 "cross section to file: " << file_name;
207}
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
LogStream Log0Verbose1()
Definition: chi_log.h:234
static std::string GetLocalDateTimeString()
Definition: chi_timer.cc:55
virtual const unsigned int NumGroups() const =0
virtual const std::vector< Precursor > & Precursors() const =0
virtual const unsigned int NumPrecursors() const =0
virtual const chi_math::SparseMatrix & TransferMatrix(unsigned int ell) const =0
virtual const std::vector< double > & InverseVelocity() const =0
virtual const std::vector< double > & NuDelayedSigmaF() const =0
virtual const std::vector< std::vector< double > > ProductionMatrix() const =0
virtual const std::vector< double > & SigmaTotal() const =0
virtual const std::vector< double > & SigmaAbsorption() const =0
void ExportToChiXSFile(const std::string &file_name, const double fission_scaling=1.0) const
virtual const std::vector< double > & SigmaFission() const =0
virtual const unsigned int ScatteringOrder() const =0
virtual const std::vector< double > & NuSigmaF() const =0
virtual const std::vector< double > & NuPromptSigmaF() const =0
virtual const std::vector< chi_math::SparseMatrix > & TransferMatrices() const =0