mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 05:05:30 -04:00
Namespace mgxs-related global variables
This commit is contained in:
parent
5fae5ffa9e
commit
c301612ca2
9 changed files with 58 additions and 50 deletions
|
|
@ -15,6 +15,8 @@ namespace openmc {
|
|||
// Global variables
|
||||
//==============================================================================
|
||||
|
||||
namespace data {
|
||||
|
||||
extern std::vector<Mgxs> nuclides_MG;
|
||||
extern std::vector<Mgxs> macro_xs;
|
||||
extern "C" int num_energy_groups;
|
||||
|
|
@ -22,6 +24,8 @@ extern std::vector<double> energy_bins;
|
|||
extern std::vector<double> energy_bin_avg;
|
||||
extern std::vector<double> rev_energy_bins;
|
||||
|
||||
} // namespace data
|
||||
|
||||
//==============================================================================
|
||||
// Mgxs data loading interface methods
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -10,34 +10,29 @@
|
|||
|
||||
namespace openmc {
|
||||
|
||||
//TODO: Remove energy_bin_avg and material_xs parameters when they reside on
|
||||
//TODO: Remove material_xs parameters when they reside on
|
||||
// the C-side this should happen after materials, physics, input, and tallies
|
||||
// are brought over
|
||||
|
||||
//! \brief samples particle behavior after a collision event.
|
||||
//! \param p Particle to operate on
|
||||
//! \param energy_bin_avg Average energy within each energy bin
|
||||
//! \param material_xs The cross section cache for the current material
|
||||
extern "C" void
|
||||
collision_mg(Particle* p, const double* energy_bin_avg,
|
||||
const MaterialMacroXS* material_xs);
|
||||
collision_mg(Particle* p, const MaterialMacroXS* material_xs);
|
||||
|
||||
//! \brief samples a reaction type.
|
||||
//!
|
||||
//! Note that there is special logic when suvival biasing is turned on since
|
||||
//! fission and disappearance are treated implicitly.
|
||||
//! \param p Particle to operate on
|
||||
//! \param energy_bin_avg Average energy within each energy bin
|
||||
//! \param material_xs The cross section cache for the current material
|
||||
void
|
||||
sample_reaction(Particle* p, const double* energy_bin_avg,
|
||||
const MaterialMacroXS* material_xs);
|
||||
sample_reaction(Particle* p, const MaterialMacroXS* material_xs);
|
||||
|
||||
//! \brief Samples the scattering event
|
||||
//! \param p Particle to operate on
|
||||
//! \param energy_bin_avg Average energy within each energy bin
|
||||
void
|
||||
scatter(Particle* p, const double* energy_bin_avg);
|
||||
scatter(Particle* p);
|
||||
|
||||
//! \brief Determines the average total, prompt and delayed neutrons produced
|
||||
//! from fission and creates the appropriate bank sites.
|
||||
|
|
|
|||
|
|
@ -22,10 +22,18 @@
|
|||
|
||||
namespace openmc {
|
||||
|
||||
//==============================================================================
|
||||
// Global variables
|
||||
//==============================================================================
|
||||
|
||||
namespace data {
|
||||
|
||||
// Storage for the MGXS data
|
||||
std::vector<Mgxs> nuclides_MG;
|
||||
std::vector<Mgxs> macro_xs;
|
||||
|
||||
} // namespace data
|
||||
|
||||
//==============================================================================
|
||||
// Mgxs base-class methods
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -13,10 +13,14 @@ namespace openmc {
|
|||
// Global variable definitions
|
||||
//==============================================================================
|
||||
|
||||
namespace data {
|
||||
|
||||
std::vector<double> energy_bins;
|
||||
std::vector<double> energy_bin_avg;
|
||||
std::vector<double> rev_energy_bins;
|
||||
|
||||
} // namesapce data
|
||||
|
||||
//==============================================================================
|
||||
// Mgxs data loading interface methods
|
||||
//==============================================================================
|
||||
|
|
@ -44,7 +48,7 @@ add_mgxs_c(hid_t file_id, const char* name, int energy_groups,
|
|||
Mgxs mg(xs_grp, energy_groups, delayed_groups, temperature, tolerance,
|
||||
max_order, legendre_to_tabular, legendre_to_tabular_points, method);
|
||||
|
||||
nuclides_MG.push_back(mg);
|
||||
data::nuclides_MG.push_back(mg);
|
||||
close_group(xs_grp);
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +59,7 @@ query_fissionable_c(int n_nuclides, const int i_nuclides[])
|
|||
{
|
||||
bool result = false;
|
||||
for (int n = 0; n < n_nuclides; n++) {
|
||||
if (nuclides_MG[i_nuclides[n] - 1].fissionable) result = true;
|
||||
if (data::nuclides_MG[i_nuclides[n] - 1].fissionable) result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -79,16 +83,16 @@ create_macro_xs_c(const char* mat_name, int n_nuclides, const int i_nuclides[],
|
|||
// material
|
||||
std::vector<Mgxs*> mgxs_ptr(n_nuclides);
|
||||
for (int n = 0; n < n_nuclides; n++) {
|
||||
mgxs_ptr[n] = &nuclides_MG[i_nuclides[n] - 1];
|
||||
mgxs_ptr[n] = &data::nuclides_MG[i_nuclides[n] - 1];
|
||||
}
|
||||
|
||||
Mgxs macro(mat_name, temperature, mgxs_ptr, atom_densities_vec,
|
||||
tolerance, method);
|
||||
macro_xs.emplace_back(macro);
|
||||
data::macro_xs.emplace_back(macro);
|
||||
} else {
|
||||
// Preserve the ordering of materials by including a blank entry
|
||||
Mgxs macro;
|
||||
macro_xs.emplace_back(macro);
|
||||
data::macro_xs.emplace_back(macro);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,18 +101,18 @@ create_macro_xs_c(const char* mat_name, int n_nuclides, const int i_nuclides[],
|
|||
void read_mg_cross_sections_header_c(hid_t file_id)
|
||||
{
|
||||
ensure_exists(file_id, "energy_groups", true);
|
||||
read_attribute(file_id, "energy_groups", num_energy_groups);
|
||||
read_attribute(file_id, "energy_groups", data::num_energy_groups);
|
||||
|
||||
ensure_exists(file_id, "group structure", true);
|
||||
read_attribute(file_id, "group structure", rev_energy_bins);
|
||||
read_attribute(file_id, "group structure", data::rev_energy_bins);
|
||||
|
||||
// Reverse energy bins
|
||||
std::copy(rev_energy_bins.crbegin(), rev_energy_bins.crend(),
|
||||
std::back_inserter(energy_bins));
|
||||
std::copy(data::rev_energy_bins.crbegin(), data::rev_energy_bins.crend(),
|
||||
std::back_inserter(data::energy_bins));
|
||||
|
||||
// Create average energies
|
||||
for (int i = 0; i < energy_bins.size() - 1; ++i) {
|
||||
energy_bin_avg.push_back(0.5*(energy_bins[i] + energy_bins[i+1]));
|
||||
for (int i = 0; i < data::energy_bins.size() - 1; ++i) {
|
||||
data::energy_bin_avg.push_back(0.5*(data::energy_bins[i] + data::energy_bins[i+1]));
|
||||
}
|
||||
|
||||
// Add entries into libraries for MG data
|
||||
|
|
@ -134,7 +138,7 @@ void
|
|||
calculate_xs_c(int i_mat, int gin, double sqrtkT, const double uvw[3],
|
||||
double& total_xs, double& abs_xs, double& nu_fiss_xs)
|
||||
{
|
||||
macro_xs[i_mat - 1].calculate_xs(gin - 1, sqrtkT, uvw, total_xs, abs_xs,
|
||||
data::macro_xs[i_mat - 1].calculate_xs(gin - 1, sqrtkT, uvw, total_xs, abs_xs,
|
||||
nu_fiss_xs);
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +163,7 @@ get_nuclide_xs_c(int index, int xstype, int gin, int* gout, double* mu, int* dg)
|
|||
} else {
|
||||
dg_c_p = dg;
|
||||
}
|
||||
return nuclides_MG[index - 1].get_xs(xstype, gin - 1, gout_c_p, mu, dg_c_p);
|
||||
return data::nuclides_MG[index - 1].get_xs(xstype, gin - 1, gout_c_p, mu, dg_c_p);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -183,7 +187,7 @@ get_macro_xs_c(int index, int xstype, int gin, int* gout, double* mu, int* dg)
|
|||
} else {
|
||||
dg_c_p = dg;
|
||||
}
|
||||
return macro_xs[index - 1].get_xs(xstype, gin - 1, gout_c_p, mu, dg_c_p);
|
||||
return data::macro_xs[index - 1].get_xs(xstype, gin - 1, gout_c_p, mu, dg_c_p);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -192,7 +196,7 @@ void
|
|||
set_nuclide_angle_index_c(int index, const double uvw[3])
|
||||
{
|
||||
// Update the values
|
||||
nuclides_MG[index - 1].set_angle_index(uvw);
|
||||
data::nuclides_MG[index - 1].set_angle_index(uvw);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -201,7 +205,7 @@ void
|
|||
set_macro_angle_index_c(int index, const double uvw[3])
|
||||
{
|
||||
// Update the values
|
||||
macro_xs[index - 1].set_angle_index(uvw);
|
||||
data::macro_xs[index - 1].set_angle_index(uvw);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -210,7 +214,7 @@ void
|
|||
set_nuclide_temperature_index_c(int index, double sqrtkT)
|
||||
{
|
||||
// Update the values
|
||||
nuclides_MG[index - 1].set_temperature_index(sqrtkT);
|
||||
data::nuclides_MG[index - 1].set_temperature_index(sqrtkT);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -225,7 +229,7 @@ get_name_c(int index, int name_len, char* name)
|
|||
std::strcpy(name, str.c_str());
|
||||
|
||||
// Now get the data and copy to the C-string
|
||||
str = nuclides_MG[index - 1].name;
|
||||
str = data::nuclides_MG[index - 1].name;
|
||||
std::strcpy(name, str.c_str());
|
||||
|
||||
// Finally, remove the null terminator
|
||||
|
|
@ -237,7 +241,7 @@ get_name_c(int index, int name_len, char* name)
|
|||
double
|
||||
get_awr_c(int index)
|
||||
{
|
||||
return nuclides_MG[index - 1].awr;
|
||||
return data::nuclides_MG[index - 1].awr;
|
||||
}
|
||||
|
||||
} // namespace openmc
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ Particle::from_source(const Bank* src)
|
|||
} else {
|
||||
g = static_cast<int>(src->E);
|
||||
last_g = static_cast<int>(src->E);
|
||||
E = energy_bin_avg[g - 1];
|
||||
E = data::energy_bin_avg[g - 1];
|
||||
}
|
||||
last_E = E;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,14 +21,13 @@
|
|||
namespace openmc {
|
||||
|
||||
void
|
||||
collision_mg(Particle* p, const double* energy_bin_avg,
|
||||
const MaterialMacroXS* material_xs)
|
||||
collision_mg(Particle* p, const MaterialMacroXS* material_xs)
|
||||
{
|
||||
// Add to the collision counter for the particle
|
||||
p->n_collision++;
|
||||
|
||||
// Sample the reaction type
|
||||
sample_reaction(p, energy_bin_avg, material_xs);
|
||||
sample_reaction(p, material_xs);
|
||||
|
||||
// Display information about collision
|
||||
if ((settings::verbosity >= 10) || (simulation::trace)) {
|
||||
|
|
@ -39,8 +38,7 @@ collision_mg(Particle* p, const double* energy_bin_avg,
|
|||
}
|
||||
|
||||
void
|
||||
sample_reaction(Particle* p, const double* energy_bin_avg,
|
||||
const MaterialMacroXS* material_xs)
|
||||
sample_reaction(Particle* p, const MaterialMacroXS* material_xs)
|
||||
{
|
||||
// Create fission bank sites. Note that while a fission reaction is sampled,
|
||||
// it never actually "happens", i.e. the weight of the particle does not
|
||||
|
|
@ -72,7 +70,7 @@ sample_reaction(Particle* p, const double* energy_bin_avg,
|
|||
if (!p->alive) return;
|
||||
|
||||
// Sample a scattering event to determine the energy of the exiting neutron
|
||||
scatter(p, energy_bin_avg);
|
||||
scatter(p);
|
||||
|
||||
// Play Russian roulette if survival biasing is turned on
|
||||
if (settings::survival_biasing) {
|
||||
|
|
@ -82,14 +80,14 @@ sample_reaction(Particle* p, const double* energy_bin_avg,
|
|||
}
|
||||
|
||||
void
|
||||
scatter(Particle* p, const double* energy_bin_avg)
|
||||
scatter(Particle* p)
|
||||
{
|
||||
// Adjust indices for Fortran to C++ indexing
|
||||
// TODO: Remove when no longer needed
|
||||
int gin = p->last_g - 1;
|
||||
int gout = p->g - 1;
|
||||
int i_mat = p->material - 1;
|
||||
macro_xs[i_mat].sample_scatter(gin, gout, p->mu, p->wgt);
|
||||
data::macro_xs[i_mat].sample_scatter(gin, gout, p->mu, p->wgt);
|
||||
|
||||
// Adjust return value for fortran indexing
|
||||
// TODO: Remove when no longer needed
|
||||
|
|
@ -99,7 +97,7 @@ scatter(Particle* p, const double* energy_bin_avg)
|
|||
rotate_angle_c(p->coord[0].uvw, p->mu, nullptr);
|
||||
|
||||
// Update energy value for downstream compatability (in tallying)
|
||||
p->E = energy_bin_avg[gout];
|
||||
p->E = data::energy_bin_avg[gout];
|
||||
|
||||
// Set event component
|
||||
p->event = EVENT_SCATTER;
|
||||
|
|
@ -180,7 +178,7 @@ create_fission_sites(Particle* p, Bank* bank_array, int64_t* size_bank,
|
|||
// the energy in the fission bank
|
||||
int dg;
|
||||
int gout;
|
||||
macro_xs[p->material - 1].sample_fission_energy(p->g - 1, dg, gout);
|
||||
data::macro_xs[p->material - 1].sample_fission_energy(p->g - 1, dg, gout);
|
||||
bank_array[i].E = static_cast<double>(gout + 1);
|
||||
bank_array[i].delayed_group = dg + 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -318,9 +318,9 @@ Bank sample_external_source()
|
|||
|
||||
// If running in MG, convert site % E to group
|
||||
if (!settings::run_CE) {
|
||||
site.E = lower_bound_index(rev_energy_bins.begin(), rev_energy_bins.end(),
|
||||
site.E);
|
||||
site.E = num_energy_groups - site.E;
|
||||
site.E = lower_bound_index(data::rev_energy_bins.begin(),
|
||||
data::rev_energy_bins.end(), site.E);
|
||||
site.E = data::num_energy_groups - site.E;
|
||||
}
|
||||
|
||||
// Set the random number generator back to the tracking stream.
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ EnergyFilter::from_xml(pugi::xml_node node)
|
|||
// (after flipping for the different ordering of the library and tallying
|
||||
// systems).
|
||||
if (!settings::run_CE) {
|
||||
if (n_bins_ == num_energy_groups) {
|
||||
if (n_bins_ == data::num_energy_groups) {
|
||||
matches_transport_groups_ = true;
|
||||
for (auto i = 0; i < n_bins_ + 1; i++) {
|
||||
if (rev_energy_bins[i] != bins_[i]) {
|
||||
if (data::rev_energy_bins[i] != bins_[i]) {
|
||||
matches_transport_groups_ = false;
|
||||
break;
|
||||
}
|
||||
|
|
@ -44,10 +44,10 @@ const
|
|||
if (p->g != F90_NONE && matches_transport_groups_) {
|
||||
if (estimator == ESTIMATOR_TRACKLENGTH) {
|
||||
//TODO: off-by-one
|
||||
match.bins_.push_back(num_energy_groups - p->g + 1);
|
||||
match.bins_.push_back(data::num_energy_groups - p->g + 1);
|
||||
} else {
|
||||
//TODO: off-by-one
|
||||
match.bins_.push_back(num_energy_groups - p->last_g + 1);
|
||||
match.bins_.push_back(data::num_energy_groups - p->last_g + 1);
|
||||
}
|
||||
match.weights_.push_back(1.0);
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ EnergyoutFilter::get_all_bins(const Particle* p, int estimator,
|
|||
FilterMatch& match) const
|
||||
{
|
||||
if (p->g != F90_NONE && matches_transport_groups_) {
|
||||
match.bins_.push_back(num_energy_groups - p->g + 1);
|
||||
match.bins_.push_back(data::num_energy_groups - p->g + 1);
|
||||
match.weights_.push_back(1.0);
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -33,10 +33,9 @@ module tracking
|
|||
implicit none
|
||||
|
||||
interface
|
||||
subroutine collision_mg(p, energy_bin_avg, material_xs) bind(C)
|
||||
subroutine collision_mg(p, material_xs) bind(C)
|
||||
import Particle, C_DOUBLE, MaterialMacroXS
|
||||
type(Particle), intent(inout) :: p
|
||||
real(C_DOUBLE), intent(in) :: energy_bin_avg(*)
|
||||
type(MaterialMacroXS), intent(in) :: material_xs
|
||||
end subroutine collision_mg
|
||||
|
||||
|
|
@ -235,7 +234,7 @@ contains
|
|||
if (run_CE) then
|
||||
call collision(p)
|
||||
else
|
||||
call collision_mg(p, energy_bin_avg, material_xs)
|
||||
call collision_mg(p, material_xs)
|
||||
end if
|
||||
|
||||
! Score collision estimator tallies -- this is done after a collision
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue