Cleaning up code, resolving @paulromano comments

This commit is contained in:
Adam G Nelson 2018-09-05 20:46:33 -04:00
parent cd1dfc0d19
commit 4b56c86c50
7 changed files with 27 additions and 59 deletions

View file

@ -11,9 +11,9 @@
namespace openmc {
typedef std::vector<std::vector<double> > double_2dvec;
typedef std::vector<std::vector<std::vector<double> > > double_3dvec;
typedef std::vector<std::vector<std::vector<std::vector<double> > > > double_4dvec;
using double_2dvec = std::vector<std::vector<double>>;
using double_3dvec = std::vector<std::vector<std::vector<double>>>;
using double_4dvec = std::vector<std::vector<std::vector<std::vector<double>>>>;
// ============================================================================
// VERSIONING NUMBERS

View file

@ -70,9 +70,6 @@ void
read_nd_vector(hid_t obj_id, const char* name, xt::xtensor<double, 4>& result,
bool must_have = false);
void
read_nd_vector(hid_t obj_id, const char* name, xt::xtensor<double, 5>& result,
bool must_have = false);
std::vector<hsize_t> attribute_shape(hid_t obj_id, const char* name);
std::vector<std::string> dataset_names(hid_t group_id);

View file

@ -159,7 +159,7 @@ class Mgxs {
//! @param dg delayed group index; use nullptr if irrelevant.
//! @return Requested cross section value.
double
get_xs(const int xstype, const int gin, int* gout, double* mu, int* dg);
get_xs(int xstype, int gin, int* gout, double* mu, int* dg);
//! \brief Samples the fission neutron energy and if prompt or delayed.
//!
@ -167,7 +167,7 @@ class Mgxs {
//! @param dg Sampled delayed group index.
//! @param gout Sampled outgoing energy group.
void
sample_fission_energy(const int gin, int& dg, int& gout);
sample_fission_energy(int gin, int& dg, int& gout);
//! \brief Samples the outgoing energy and angle from a scatter event.
//!
@ -176,7 +176,7 @@ class Mgxs {
//! @param mu Sampled cosine of the change-in-angle.
//! @param wgt Weight of the particle to be adjusted.
void
sample_scatter(const int gin, int& gout, double& mu, double& wgt);
sample_scatter(int gin, int& gout, double& mu, double& wgt);
//! \brief Calculates cross section quantities needed for tracking.
//!
@ -187,14 +187,14 @@ class Mgxs {
//! @param abs_xs Resultant absorption cross section.
//! @param nu_fiss_xs Resultant nu-fission cross section.
void
calculate_xs(const int gin, const double sqrtkT, const double uvw[3],
calculate_xs(int gin, double sqrtkT, const double uvw[3],
double& total_xs, double& abs_xs, double& nu_fiss_xs);
//! \brief Sets the temperature index in cache given a temperature
//!
//! @param sqrtkT Temperature of the material.
void
set_temperature_index(const double sqrtkT);
set_temperature_index(double sqrtkT);
//! \brief Sets the angle index in cache given a direction
//!

View file

@ -94,7 +94,7 @@ class XsData {
// [angle][incoming group][outgoing group][delayed group]
xt::xtensor<double, 4> chi_delayed;
// scatter has the following dimensions: [angle]
std::vector<std::shared_ptr<ScattData> > scatter;
std::vector<std::shared_ptr<ScattData>> scatter;
XsData() = default;

View file

@ -673,36 +673,6 @@ read_nd_vector(hid_t obj_id, const char* name, xt::xtensor<double, 4>& result,
}
}
void
read_nd_vector(hid_t obj_id, const char* name, xt::xtensor<double, 5>& result,
bool must_have)
{
if (object_exists(obj_id, name)) {
int dim1 = result.shape()[0];
int dim2 = result.shape()[1];
int dim3 = result.shape()[2];
int dim4 = result.shape()[3];
int dim5 = result.shape()[4];
double temp_arr[dim1 * dim2 * dim3 * dim4 * dim5];
read_double(obj_id, name, temp_arr, true);
int temp_idx = 0;
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) {
for (int k = 0; k < dim3; k++) {
for (int l = 0; l < dim4; l++) {
for (int m = 0; m < dim5; m++) {
result(i, j, k, l, m) = temp_arr[temp_idx++];
}
}
}
}
}
} else if (must_have) {
fatal_error(std::string("Must provide " + std::string(name) + "!"));
}
}
void
read_tally_results(hid_t group_id, hsize_t n_filter, hsize_t n_score, double* results)

View file

@ -423,7 +423,7 @@ Mgxs::combine(const std::vector<Mgxs*>& micros, const std::vector<double>& scala
//==============================================================================
double
Mgxs::get_xs(const int xstype, const int gin, int* gout, double* mu, int* dg)
Mgxs::get_xs(int xstype, int gin, int* gout, double* mu, int* dg)
{
// This method assumes that the temperature and angle indices are set
#ifdef _OPENMP
@ -535,7 +535,7 @@ Mgxs::get_xs(const int xstype, const int gin, int* gout, double* mu, int* dg)
//==============================================================================
void
Mgxs::sample_fission_energy(const int gin, int& dg, int& gout)
Mgxs::sample_fission_energy(int gin, int& dg, int& gout)
{
// This method assumes that the temperature and angle indices are set
#ifdef _OPENMP
@ -599,7 +599,7 @@ Mgxs::sample_fission_energy(const int gin, int& dg, int& gout)
//==============================================================================
void
Mgxs::sample_scatter(const int gin, int& gout, double& mu, double& wgt)
Mgxs::sample_scatter(int gin, int& gout, double& mu, double& wgt)
{
// This method assumes that the temperature and angle indices are set
// Sample the data
@ -614,7 +614,7 @@ Mgxs::sample_scatter(const int gin, int& gout, double& mu, double& wgt)
//==============================================================================
void
Mgxs::calculate_xs(const int gin, const double sqrtkT, const double uvw[3],
Mgxs::calculate_xs(int gin, double sqrtkT, const double uvw[3],
double& total_xs, double& abs_xs, double& nu_fiss_xs)
{
// Set our indices
@ -649,7 +649,7 @@ Mgxs::equiv(const Mgxs& that)
//==============================================================================
void
Mgxs::set_temperature_index(const double sqrtkT)
Mgxs::set_temperature_index(double sqrtkT)
{
// See if we need to find the new index
#ifdef _OPENMP

View file

@ -132,7 +132,7 @@ XsData::fission_vector_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang,
read_nd_vector(xsdata_grp, "chi", temp_chi, true);
// Normalize chi by summing over the outgoing groups for each incoming angle
temp_chi = temp_chi / xt::view(xt::sum(temp_chi, {1}), xt::all(), xt::newaxis());
temp_chi /= xt::view(xt::sum(temp_chi, {1}), xt::all(), xt::newaxis());
// Now every incoming group in prompt_chi and delayed_chi is the normalized
// chi we just made
@ -186,16 +186,15 @@ 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 /= xt::view(xt::sum(temp_chi_p, {1}), xt::all(), xt::newaxis());
// Get chi-delayed
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, {2}), xt::all(),
xt::all(), xt::newaxis());
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
chi_prompt = xt::view(temp_chi_p, xt::all(), xt::newaxis(), xt::all());
@ -203,8 +202,10 @@ XsData::fission_vector_no_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang,
xt::all());
// Get prompt and delayed nu-fission directly
read_nd_vector(xsdata_grp, "prompt-nu-fission", prompt_nu_fission, true);
read_nd_vector(xsdata_grp, "delayed-nu-fission", delayed_nu_fission, true);
read_nd_vector(xsdata_grp, "prompt-nu-fission", prompt_nu_fission,
true);
read_nd_vector(xsdata_grp, "delayed-nu-fission",
delayed_nu_fission, true);
}
void
@ -219,7 +220,7 @@ XsData::fission_vector_no_delayed_from_hdf5(hid_t xsdata_grp, size_t n_ang,
read_nd_vector(xsdata_grp, "chi", temp_chi, true);
// Normalize chi by summing over the outgoing groups for each incoming angle
temp_chi = temp_chi / xt::view(xt::sum(temp_chi, {1}), xt::all(), xt::newaxis());
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
chi_prompt = xt::view(temp_chi, xt::all(), xt::newaxis(), xt::all());
@ -299,11 +300,11 @@ XsData::fission_matrix_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang,
}
//Normalize both chis
chi_prompt = chi_prompt / xt::view(xt::sum(chi_prompt, {2}), xt::all(),
xt::all(), xt::newaxis());
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());
chi_delayed /= xt::view(xt::sum(chi_delayed, {3}),
xt::all(), xt::all(), xt::all(), xt::newaxis());
}
void