From 3385c8b0a20e0aa27ca2f138ba98813c08babc69 Mon Sep 17 00:00:00 2001 From: Adam G Nelson Date: Mon, 3 Sep 2018 14:15:25 -0400 Subject: [PATCH] some small potential bug fixes and code cleanup --- src/scattdata.cpp | 10 ++-------- src/xsdata.cpp | 19 +++++-------------- tests/regression_tests/mg_basic/test.py | 2 +- .../regression_tests/mg_basic_delayed/test.py | 2 +- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/scattdata.cpp b/src/scattdata.cpp index 0ff7969d1..1069ef6e9 100644 --- a/src/scattdata.cpp +++ b/src/scattdata.cpp @@ -109,13 +109,7 @@ ScattData::base_combine(size_t max_order, // Combine mult_numer and mult_denom into the combined multiplicity matrix xt::xtensor this_mult({groups, groups}, 1.); - for (int gin = 0; gin < groups; gin++) { - for (int gout = 0; gout < groups; gout++) { - if (mult_denom(gin, gout) > 0.) { - this_mult(gin, gout) = mult_numer(gin, gout) / mult_denom(gin, gout); - } - } - } + this_mult = xt::nan_to_num(mult_numer / mult_denom); // We have the data, now we need to convert to a jagged array and then use // the initialize function to store it on the object. @@ -531,7 +525,7 @@ ScattDataHistogram::calc_f(int gin, int gout, double mu) int imu; if (mu == 1.) { // use size -2 to have the index one before the end - imu = this->mu.size() - 2; + imu = this->mu.shape()[0] - 2; } else { imu = std::floor((mu + 1.) / dmu + 1.) - 1; } diff --git a/src/xsdata.cpp b/src/xsdata.cpp index fd849b1c7..cd53b826e 100644 --- a/src/xsdata.cpp +++ b/src/xsdata.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "xtensor/xview.hpp" #include "xtensor/xindex_view.hpp" @@ -204,13 +205,7 @@ XsData::fission_vector_no_delayed_from_hdf5(hid_t xsdata_grp, size_t n_ang, temp_chi = temp_chi / xt::view(xt::sum(temp_chi, {1}), xt::all(), xt::newaxis()); // Now every incoming group in self.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); - } - } - } + chi_prompt = xt::view(temp_chi, xt::all(), xt::newaxis(), xt::all()); // Get nu-fission directly if (object_exists(xsdata_grp, "prompt-nu-fission")) { @@ -317,7 +312,8 @@ XsData::fission_matrix_no_delayed_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 / prompt_nu_fission; + chi_prompt = temp_matrix / xt::view(prompt_nu_fission, xt::all(), xt::all(), + xt::newaxis()); } //============================================================================== @@ -391,12 +387,7 @@ XsData::scatter_from_hdf5(hid_t xsdata_grp, size_t n_ang, size_t energy_groups, // Now use this info to find the length of a vector to hold the flattened // data. - size_t length = 0; - for (size_t a = 0; a < n_ang; a++) { - for (size_t gin = 0; gin < energy_groups; gin++) { - length += order_data * (gmax(a, gin) - gmin(a, gin) + 1); - } - } + size_t length = order_data * xt::sum(gmax - gmin + 1)(); double_4dvec input_scatt(n_ang, double_3dvec(energy_groups)); xt::xtensor temp_arr({length}, 0.); diff --git a/tests/regression_tests/mg_basic/test.py b/tests/regression_tests/mg_basic/test.py index c29c7ca1f..7b456bb9d 100644 --- a/tests/regression_tests/mg_basic/test.py +++ b/tests/regression_tests/mg_basic/test.py @@ -82,7 +82,7 @@ class MGXSTestHarness(PyAPITestHarness): os.remove(f) -def test_mg_benchmark(): +def test_mg_basic(): create_library() mat_names = ['base leg', 'base tab', 'base hist', 'base matrix', 'base ang', 'micro'] diff --git a/tests/regression_tests/mg_basic_delayed/test.py b/tests/regression_tests/mg_basic_delayed/test.py index 6c527bbe3..8fbcaca49 100644 --- a/tests/regression_tests/mg_basic_delayed/test.py +++ b/tests/regression_tests/mg_basic_delayed/test.py @@ -97,7 +97,7 @@ class MGXSTestHarness(PyAPITestHarness): os.remove(f) -def test_mg_benchmark(): +def test_mg_basic_delayed(): create_library() model = slab_mg(num_regions=4, mat_names=['vec beta', 'vec no beta', 'matrix beta', 'matrix no beta'])