Added delayed test and made code changes so that we pass the tests

This commit is contained in:
Adam G Nelson 2018-09-02 21:10:01 -04:00
parent d8ba9feae6
commit c7fa8c05ce
8 changed files with 154 additions and 106 deletions

View file

@ -463,11 +463,11 @@ Mgxs::get_xs(const int xstype, const int gin, int* gout, double* mu, int* dg)
case MG_GET_XS_DELAYED_NU_FISSION:
if (fissionable) {
if (dg != nullptr) {
val = xs_t->delayed_nu_fission(a, gin, *dg);
val = xs_t->delayed_nu_fission(a, *dg, gin);
} else {
val = 0.;
for (int d = 0; d < xs_t->delayed_nu_fission.shape()[2]; d++) {
val += xs_t->delayed_nu_fission(a, gin, d);
val += xs_t->delayed_nu_fission(a, d, gin);
}
}
} else {
@ -493,21 +493,21 @@ Mgxs::get_xs(const int xstype, const int gin, int* gout, double* mu, int* dg)
if (fissionable) {
if (gout != nullptr) {
if (dg != nullptr) {
val = xs_t->chi_delayed(a, gin, *gout, *dg);
val = xs_t->chi_delayed(a, *dg, gin, *gout);
} else {
val = xs_t->chi_delayed(a, gin, *gout, 0);
val = xs_t->chi_delayed(a, 0, gin, *gout);
}
} else {
if (dg != nullptr) {
val = 0.;
for (int g = 0; g < xs_t->delayed_nu_fission.shape()[2]; g++) {
val += xs_t->delayed_nu_fission(a, gin, g, *dg);
val += xs_t->delayed_nu_fission(a, *dg, gin, g);
}
} else {
val = 0.;
for (int g = 0; g < xs_t->delayed_nu_fission.shape()[2]; g++) {
for (int d = 0; d < xs_t->delayed_nu_fission.shape()[3]; d++) {
val += xs_t->delayed_nu_fission(a, gin, g, d);
val += xs_t->delayed_nu_fission(a, d, gin, g);
}
}
}
@ -578,7 +578,7 @@ Mgxs::sample_fission_energy(const int gin, int& dg, int& gout)
while (xi_pd >= prob_prompt) {
dg++;
prob_prompt +=
xs_t->delayed_nu_fission(cache[tid].a, gin, dg);
xs_t->delayed_nu_fission(cache[tid].a, dg, gin);
}
// adjust dg in case of round-off error
@ -587,11 +587,11 @@ Mgxs::sample_fission_energy(const int gin, int& dg, int& gout)
// sample the outgoing energy group
gout = 0;
double prob_gout =
xs_t->chi_delayed(cache[tid].a, gin, gout, dg);
xs_t->chi_delayed(cache[tid].a, dg, gin, gout);
while (prob_gout < xi_gout) {
gout++;
prob_gout +=
xs_t->chi_delayed(cache[tid].a, gin, gout, dg);
xs_t->chi_delayed(cache[tid].a, dg, gin, gout);
}
}
}

View file

@ -32,7 +32,7 @@ XsData::XsData(size_t energy_groups, size_t num_delayed_groups, bool fissionable
scatter_format != ANGLE_LEGENDRE) {
fatal_error("Invalid scatter_format!");
}
// allocate all [temperature][phi][theta][in group] quantities
// allocate all [temperature][angle][in group] quantities
std::vector<size_t> shape = {n_ang, energy_groups};
total = xt::zeros<double>(shape);
absorption = xt::zeros<double>(shape);
@ -44,21 +44,21 @@ XsData::XsData(size_t energy_groups, size_t num_delayed_groups, bool fissionable
kappa_fission = xt::zeros<double>(shape);
}
// allocate decay_rate; [temperature][phi][theta][delayed group]
// allocate decay_rate; [temperature][angle][delayed group]
shape[1] = num_delayed_groups;
decay_rate = xt::zeros<double>(shape);
if (fissionable) {
shape = {n_ang, energy_groups, num_delayed_groups};
// allocate delayed_nu_fission; [temperature][phi][theta][in group][delay group]
shape = {n_ang, num_delayed_groups, energy_groups};
// allocate delayed_nu_fission; [temperature][angle][delay group][in group]
delayed_nu_fission = xt::zeros<double>(shape);
// chi_prompt; [temperature][phi][theta][in group][out group]
// chi_prompt; [temperature][angle][in group][out group]
shape = {n_ang, energy_groups, energy_groups};
chi_prompt = xt::zeros<double>(shape);
// chi_delayed; [temperature][phi][theta][in group][out group][delay group]
shape = {n_ang, energy_groups, energy_groups, num_delayed_groups};
// chi_delayed; [temperature][angle][delay group][in group][out group]
shape = {n_ang, num_delayed_groups, energy_groups, energy_groups};
chi_delayed = xt::zeros<double>(shape);
}
@ -136,16 +136,9 @@ XsData::fission_vector_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang,
// Now every incoming group in prompt_chi and delayed_chi is the normalized
// chi we just made
for (size_t a = 0; a < n_ang; a++) {
for (size_t gin = 0; gin < energy_groups; gin++) {
for (size_t gout = 0; gout < energy_groups; gout++) {
chi_prompt(a, gin, gout) = temp_chi(a, gout);
for (size_t dg = 0; dg < delayed_groups; dg++) {
chi_delayed(a, gin, gout, dg) = temp_chi(a, gout);
}
}
}
}
chi_prompt = xt::view(temp_chi, xt::all(), xt::newaxis(), xt::all());
chi_delayed = xt::view(temp_chi, xt::all(), xt::newaxis(), xt::newaxis(),
xt::all());
// Get nu-fission
xt::xtensor<double, 2> temp_nufiss({n_ang, energy_groups}, 0.);
@ -159,13 +152,9 @@ XsData::fission_vector_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang,
prompt_nu_fission = temp_nufiss * (1. - xt::sum(temp_beta, {1}));
// Set delayed_nu_fission as beta * nu_fission
for (size_t a = 0; a < n_ang; a++) {
for (size_t gin = 0; gin < energy_groups; gin++) {
for (size_t dg = 0; dg < delayed_groups; dg++) {
delayed_nu_fission(a, gin, dg) = temp_beta(a, dg) * temp_nufiss(a, gin);
}
}
}
delayed_nu_fission =
xt::view(temp_beta, xt::all(), xt::all(), xt::newaxis()) *
xt::view(temp_nufiss, xt::all(), xt::newaxis(), xt::all());
}
void
@ -179,27 +168,21 @@ XsData::fission_vector_no_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang,
read_nd_vector(xsdata_grp, "chi-prompt", temp_chi_p, true);
// Normalize chi by summing over the outgoing groups for each incoming angle
temp_chi_p = temp_chi_p / xt::view(xt::sum(temp_chi_p, {1}), xt::all(), xt::newaxis());
temp_chi_p = temp_chi_p / xt::view(xt::sum(temp_chi_p, {1}), xt::all(),
xt::newaxis());
// Get chi-delayed
xt::xtensor<double, 3> temp_chi_d({n_ang, energy_groups, delayed_groups}, 0.);
xt::xtensor<double, 3> temp_chi_d({n_ang, delayed_groups, energy_groups}, 0.);
read_nd_vector(xsdata_grp, "chi-delayed", temp_chi_d, true);
// Normalize chi by summing over the outgoing groups for each incoming angle
temp_chi_d = temp_chi_d / xt::view(xt::sum(temp_chi_d, {1}), xt::all(),
xt::newaxis(), xt::all());
temp_chi_d = temp_chi_d / xt::view(xt::sum(temp_chi_d, {2}), xt::all(),
xt::all(), xt::newaxis());
// Now assign the prompt and delayed chis by replicating for each incoming group
for (size_t a = 0; a < n_ang; a++) {
for (size_t gin = 0; gin < energy_groups; gin++) {
for (size_t gout = 0; gout < energy_groups; gout++) {
chi_prompt(a, gin, gout) = temp_chi_p(a, gout);
for (size_t dg = 0; dg < delayed_groups; dg++) {
chi_delayed(a, gin, gout, dg) = temp_chi_d(a, gout, dg);
}
}
}
}
chi_prompt = xt::view(temp_chi_p, xt::all(), xt::newaxis(), xt::all());
chi_delayed = xt::view(temp_chi_d, xt::all(), xt::all(), xt::newaxis(),
xt::all());
// Get prompt and delayed nu-fission directly
read_nd_vector(xsdata_grp, "prompt-nu-fission", prompt_nu_fission, true);
@ -246,59 +229,40 @@ XsData::fission_matrix_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang,
// Data is provided as nu-fission and chi with a beta for delayed info
// Get nu-fission matrix
xt::xtensor<double, 3> temp_matrix({n_ang, energy_groups, energy_groups});
xt::xtensor<double, 3> temp_matrix({n_ang, energy_groups, energy_groups}, 0.);
read_nd_vector(xsdata_grp, "nu-fission", temp_matrix, true);
// Get beta
xt::xtensor<double, 3> temp_beta({n_ang, energy_groups, delayed_groups}, 0.);
xt::xtensor<double, 2> temp_beta({n_ang, delayed_groups}, 0.);
read_nd_vector(xsdata_grp, "beta", temp_beta, true);
xt::xtensor<double, 1> temp_beta_sum({n_ang}, 0.);
temp_beta_sum = xt::sum(temp_beta, {1});
// prompt_nu_fission is the sum of this matrix over outgoing groups and
// multiplied by (1 - beta_tot)
prompt_nu_fission = xt::sum(temp_matrix, {2}) * (1. - xt::sum(temp_beta, {2}));
// multiplied by (1 - beta_sum)
prompt_nu_fission = xt::sum(temp_matrix, {2}) * (1. - temp_beta_sum);
// delayed_nu_fission is the sum of this matrix over outgoing groups and
// multiplied by beta
for (size_t a = 0; a < n_ang; a++) {
for (size_t gin = 0; gin < energy_groups; gin++) {
double out_sum = 0.;
for (size_t gout = 0; gout < energy_groups; gout++) {
out_sum += temp_matrix(a, gin, gout);
}
for (size_t dg = 0; dg < delayed_groups; dg++) {
delayed_nu_fission(a, gin, dg) = temp_beta(a, dg) * out_sum;
}
}
}
delayed_nu_fission =
xt::view(temp_beta, xt::all(), xt::all(), xt::newaxis()) *
xt::view(xt::sum(temp_matrix, {2}), xt::all(), xt::newaxis(), xt::all());
// Store chi-prompt
for (size_t a = 0; a < n_ang; a++) {
for (size_t gin = 0; gin < energy_groups; gin++) {
for (size_t gout = 0; gout < energy_groups; gout++) {
double beta = 0.;
for (size_t dg = 0; dg < delayed_groups; dg++) {
beta += temp_beta(a, gin, dg);
}
chi_prompt(a, gin, gout) = (1.0 - beta) * temp_matrix(a, gin, gout);
}
}
}
chi_prompt = xt::view(1.0 - temp_beta_sum, xt::all(), xt::newaxis(), xt::newaxis()) * temp_matrix;
// Store chi-delayed
for (size_t a = 0; a < n_ang; a++) {
for (size_t gin = 0; gin < energy_groups; gin++) {
for (size_t gout = 0; gout < energy_groups; gout++) {
for (size_t dg = 0; dg < delayed_groups; dg++) {
chi_delayed(a, gin, gout, dg) = temp_beta(a, gin, dg) * temp_matrix(a, gin, gout);
}
}
}
}
chi_delayed =
xt::view(temp_beta, xt::all(), xt::all(), xt::newaxis(), xt::newaxis()) *
xt::view(temp_matrix, xt::all(), xt::newaxis(), xt::all(), xt::all());
//Normalize both
chi_prompt = chi_prompt / xt::view(xt::sum(chi_prompt, {2}), xt::all(), xt::newaxis());
chi_delayed = chi_delayed / xt::view(xt::sum(chi_delayed, {2}), xt::all(),
xt::newaxis(), xt::all());
chi_prompt = chi_prompt / xt::view(xt::sum(chi_prompt, {2}), xt::all(),
xt::all(), xt::newaxis());
chi_delayed = chi_delayed / xt::view(xt::sum(chi_delayed, {3}), xt::all(),
xt::all(), xt::all(), xt::newaxis());
}
void
@ -308,7 +272,7 @@ XsData::fission_matrix_no_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang,
// Data is provided separately as prompt + delayed nu-fission and chi
// Get the prompt nu-fission matrix
xt::xtensor<double, 3> temp_matrix_p({n_ang, energy_groups, energy_groups});
xt::xtensor<double, 3> temp_matrix_p({n_ang, energy_groups, energy_groups}, 0.);
read_nd_vector(xsdata_grp, "prompt-nu-fission", temp_matrix_p, true);
// prompt_nu_fission is the sum over outgoing groups
@ -316,19 +280,21 @@ XsData::fission_matrix_no_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang,
// chi_prompt is this matrix but normalized over outgoing groups, which we
// have already stored in prompt_nu_fission
chi_prompt = temp_matrix_p / prompt_nu_fission;
chi_prompt = temp_matrix_p /
xt::view(prompt_nu_fission, xt::all(), xt::all(), xt::newaxis());
// Get the delayed nu-fission matrix
xt::xtensor<double, 4> temp_matrix_d({n_ang, energy_groups, energy_groups,
delayed_groups});
xt::xtensor<double, 4> temp_matrix_d({n_ang, delayed_groups, energy_groups,
energy_groups}, 0.);
read_nd_vector(xsdata_grp, "delayed-nu-fission", temp_matrix_d, true);
// delayed_nu_fission is the sum over outgoing groups
delayed_nu_fission = xt::sum(temp_matrix_d, {2});
delayed_nu_fission = xt::sum(temp_matrix_d, {3});
// chi_prompt is this matrix but normalized over outgoing groups, which we
// have already stored in prompt_nu_fission
chi_delayed = temp_matrix_d / delayed_nu_fission;
chi_delayed = temp_matrix_d /
xt::view(delayed_nu_fission, xt::all(), xt::all(), xt::all(), xt::newaxis());
}
void
@ -339,7 +305,7 @@ XsData::fission_matrix_no_delayed_from_hdf5(hid_t xsdata_grp, size_t n_ang,
// Therefore, the code only considers the data as prompt.
// Get nu-fission matrix
xt::xtensor<double, 3> temp_matrix({n_ang, energy_groups, energy_groups});
xt::xtensor<double, 3> temp_matrix({n_ang, energy_groups, energy_groups}, 0.);
if (object_exists(xsdata_grp, "prompt-nu-fission")) {
read_nd_vector(xsdata_grp, "prompt-nu-fission", temp_matrix, true);
} else {
@ -366,7 +332,8 @@ XsData::fission_from_hdf5(hid_t xsdata_grp, size_t n_ang, size_t energy_groups,
// Get the data; the strategy for doing so depends on if the data is provided
// as a nu-fission matrix or a set of chi and nu-fission vectors
if (object_exists(xsdata_grp, "chi")) {
if (object_exists(xsdata_grp, "chi") ||
object_exists(xsdata_grp, "chi-prompt")) {
if (delayed_groups == 0) {
fission_vector_no_delayed_from_hdf5(xsdata_grp, n_ang, energy_groups);
} else {
@ -393,13 +360,10 @@ XsData::fission_from_hdf5(hid_t xsdata_grp, size_t n_ang, size_t energy_groups,
}
// Combine prompt_nu_fission and delayed_nu_fission into nu_fission
for (size_t a = 0; a < n_ang; a++) {
for (size_t gin = 0; gin < energy_groups; gin++) {
nu_fission(a, gin) = prompt_nu_fission(a, gin);
for (size_t dg = 0; dg < delayed_groups; dg++) {
nu_fission(a, gin) += delayed_nu_fission(a, gin, dg);
}
}
if (delayed_groups == 0) {
nu_fission = prompt_nu_fission;
} else {
nu_fission = prompt_nu_fission + xt::sum(delayed_nu_fission, {1});
}
}

View file

@ -1,16 +1,47 @@
<?xml version='1.0' encoding='utf-8'?>
<geometry>
<cell id="1" material="1" region="1 -2" universe="0" />
<cell id="2" material="2" region="2 -3" universe="0" />
<cell id="3" material="3" region="3 -4" universe="0" />
<cell id="4" material="4" region="4 -5" universe="0" />
<cell id="5" material="5" region="5 -6" universe="0" />
<cell id="6" material="6" region="6 -7" universe="0" />
<surface boundary="reflective" coeffs="0.0" id="1" type="x-plane" />
<surface boundary="vacuum" coeffs="929.45" id="2" type="x-plane" />
<surface coeffs="154.90833333333333" id="2" type="x-plane" />
<surface coeffs="309.81666666666666" id="3" type="x-plane" />
<surface coeffs="464.725" id="4" type="x-plane" />
<surface coeffs="619.6333333333333" id="5" type="x-plane" />
<surface coeffs="774.5416666666666" id="6" type="x-plane" />
<surface boundary="vacuum" coeffs="929.45" id="7" type="x-plane" />
</geometry>
<?xml version='1.0' encoding='utf-8'?>
<materials>
<cross_sections>2g.h5</cross_sections>
<material id="1" name="mat_1">
<material id="1" name="base leg">
<density units="macro" value="1.0" />
<macroscopic name="mat_1" />
</material>
<material id="2" name="base tab">
<density units="macro" value="1.0" />
<macroscopic name="mat_2" />
</material>
<material id="3" name="base hist">
<density units="macro" value="1.0" />
<macroscopic name="mat_3" />
</material>
<material id="4" name="base matrix">
<density units="macro" value="1.0" />
<macroscopic name="mat_4" />
</material>
<material id="5" name="base ang">
<density units="macro" value="1.0" />
<macroscopic name="mat_5" />
</material>
<material id="6" name="micro">
<density units="sum" />
<nuclide ao="0.5" name="mat_1" />
<nuclide ao="0.5" name="mat_6" />
</material>
</materials>
<?xml version='1.0' encoding='utf-8'?>
<settings>
@ -20,7 +51,7 @@
<inactive>5</inactive>
<source strength="1.0">
<space type="box">
<parameters>-929.45 -1e+50 -1e+50 929.45 1e+50 1e+50</parameters>
<parameters>0.0 -1000.0 -1000.0 154.90833333333333 1000.0 1000.0</parameters>
</space>
</source>
<output>

View file

@ -1,2 +1,2 @@
k-combined:
9.949396E-01 2.047218E-02
1.005345E+00 1.109180E-02

View file

@ -156,7 +156,7 @@ def create_model():
class MGXSTestHarness(PyAPITestHarness):
def _cleanup(self):
super()._cleanup()
f = '2g .h5'
f = '2g.h5'
if os.path.exists(f):
os.remove(f)

View file

@ -0,0 +1,51 @@
<?xml version='1.0' encoding='utf-8'?>
<geometry>
<cell id="1" material="1" region="1 -2" universe="0" />
<cell id="2" material="2" region="2 -3" universe="0" />
<cell id="3" material="3" region="3 -4" universe="0" />
<cell id="4" material="4" region="4 -5" universe="0" />
<surface boundary="reflective" coeffs="0.0" id="1" type="x-plane" />
<surface coeffs="232.3625" id="2" type="x-plane" />
<surface coeffs="464.725" id="3" type="x-plane" />
<surface coeffs="697.0875000000001" id="4" type="x-plane" />
<surface boundary="vacuum" coeffs="929.45" id="5" type="x-plane" />
</geometry>
<?xml version='1.0' encoding='utf-8'?>
<materials>
<cross_sections>2g.h5</cross_sections>
<material id="1" name="vec beta">
<density units="macro" value="1.0" />
<macroscopic name="mat_1" />
</material>
<material id="2" name="vec no beta">
<density units="macro" value="1.0" />
<macroscopic name="mat_2" />
</material>
<material id="3" name="matrix beta">
<density units="macro" value="1.0" />
<macroscopic name="mat_3" />
</material>
<material id="4" name="matrix no beta">
<density units="macro" value="1.0" />
<macroscopic name="mat_4" />
</material>
</materials>
<?xml version='1.0' encoding='utf-8'?>
<settings>
<run_mode>eigenvalue</run_mode>
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<space type="box">
<parameters>0.0 -1000.0 -1000.0 232.3625 1000.0 1000.0</parameters>
</space>
</source>
<output>
<summary>false</summary>
</output>
<energy_mode>multi-group</energy_mode>
<tabular_legendre>
<enable>false</enable>
</tabular_legendre>
</settings>

View file

@ -0,0 +1,2 @@
k-combined:
9.928704E-01 2.679667E-02

View file

@ -164,7 +164,7 @@ def create_model():
class MGXSTestHarness(PyAPITestHarness):
def _cleanup(self):
super()._cleanup()
f = '2g .h5'
f = '2g.h5'
if os.path.exists(f):
os.remove(f)