From adc935b99dbebc70d7896849c14b1475ea768165 Mon Sep 17 00:00:00 2001 From: agnelson Date: Tue, 5 Oct 2021 11:59:47 -0500 Subject: [PATCH 1/4] Added a MG version of regression_tests/volume_calc --- .../volume_calc/inputs_true_mg.dat | 76 +++++++++++++++++++ tests/regression_tests/volume_calc/test.py | 60 +++++++++++++-- 2 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 tests/regression_tests/volume_calc/inputs_true_mg.dat diff --git a/tests/regression_tests/volume_calc/inputs_true_mg.dat b/tests/regression_tests/volume_calc/inputs_true_mg.dat new file mode 100644 index 0000000000..21c2a9834a --- /dev/null +++ b/tests/regression_tests/volume_calc/inputs_true_mg.dat @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + mg_lib.h5 + + + + + + + + + + + + + + + volume + multi-group + + cell + 1 2 3 + 100000 + -1.0 -1.0 -6.0 + 1.0 1.0 6.0 + + + material + 1 2 + 100000 + -1.0 -1.0 -6.0 + 1.0 1.0 6.0 + + + universe + 0 + 100000 + -1.0 -1.0 -6.0 + 1.0 1.0 6.0 + + + cell + 1 2 3 + 100 + -1.0 -1.0 -6.0 + 1.0 1.0 6.0 + + + + material + 1 2 + 100 + -1.0 -1.0 -6.0 + 1.0 1.0 6.0 + + + + cell + 1 2 3 + 100 + -1.0 -1.0 -6.0 + 1.0 1.0 6.0 + + + diff --git a/tests/regression_tests/volume_calc/test.py b/tests/regression_tests/volume_calc/test.py index 1f1a2c7c95..fc96e4a551 100644 --- a/tests/regression_tests/volume_calc/test.py +++ b/tests/regression_tests/volume_calc/test.py @@ -1,6 +1,7 @@ import os import glob -import sys + +import numpy as np import openmc @@ -9,12 +10,15 @@ from tests.testing_harness import PyAPITestHarness class VolumeTest(PyAPITestHarness): - def __init__(self, *args, **kwargs): + def __init__(self, is_ce, *args, **kwargs): super().__init__(*args, **kwargs) self.exp_std_dev = 1e-01 self.exp_rel_err = 1e-01 self.exp_variance = 5e-02 + self.is_ce = is_ce + if not is_ce: + self.inputs_true = 'inputs_true_mg.dat' def _build_inputs(self): # Define materials @@ -22,7 +26,8 @@ class VolumeTest(PyAPITestHarness): water.add_nuclide('H1', 2.0) water.add_nuclide('O16', 1.0) water.add_nuclide('B10', 0.0001) - water.add_s_alpha_beta('c_H_in_H2O') + if self.is_ce: + water.add_s_alpha_beta('c_H_in_H2O') water.set_density('g/cc', 1.0) fuel = openmc.Material(2) @@ -31,6 +36,8 @@ class VolumeTest(PyAPITestHarness): fuel.set_density('g/cc', 4.5) materials = openmc.Materials((water, fuel)) + if not self.is_ce: + materials.cross_sections = 'mg_lib.h5' materials.export_to_xml() cyl = openmc.ZCylinder(surface_id=1, r=1.0, boundary_type='vacuum') @@ -68,9 +75,50 @@ class VolumeTest(PyAPITestHarness): # Define settings settings = openmc.Settings() settings.run_mode = 'volume' + if not self.is_ce: + settings.energy_mode = 'multi-group' settings.volume_calculations = vol_calcs settings.export_to_xml() + # Create the MGXS file is necessary + if not self.is_ce: + groups = openmc.mgxs.EnergyGroups(group_edges=[0., 20.e6]) + mg_xs_file = openmc.MGXSLibrary(groups) + + nu = [2.] + fiss = [1.] + capture = [1.] + absorption_fissile = np.add(fiss, capture) + absorption_other = capture + scatter = np.array([[[1.]]]) + total_fissile = np.add(absorption_fissile, + np.sum(scatter[:, :, 0], axis=1)) + total_other = np.add(absorption_other, + np.sum(scatter[:, :, 0], axis=1)) + chi = [1.] + + for iso in ['H1', 'O16', 'B10', 'Mo99', 'U235']: + mat = openmc.XSdata(iso, groups) + mat.order = 0 + mat.set_scatter_matrix(scatter) + if iso == 'U235': + mat.set_nu_fission(np.multiply(nu, fiss)) + mat.set_absorption(absorption_fissile) + mat.set_total(total_fissile) + mat.set_chi(chi) + else: + mat.set_absorption(absorption_other) + mat.set_total(total_other) + mg_xs_file.add_xsdata(mat) + mg_xs_file.export_to_hdf5('mg_lib.h5') + + def _cleanup(self): + super()._cleanup() + output = ['mg_lib.h5'] + for f in output: + if os.path.exists(f): + os.remove(f) + def _get_results(self): outstr = '' for i, filename in enumerate(sorted(glob.glob('volume_*.h5'))): @@ -116,6 +164,8 @@ class VolumeTest(PyAPITestHarness): def _test_output_created(self): pass + def test_volume_calc(): - harness = VolumeTest('') - harness.main() + for is_ce in [True, False]: + harness = VolumeTest(is_ce, '') + harness.main() From 75fd0a7f78116681ccc9126f71fea9b27d95360f Mon Sep 17 00:00:00 2001 From: agnelson Date: Tue, 5 Oct 2021 14:12:31 -0500 Subject: [PATCH 2/4] Added test of volume calc from MG mode, then corrected 2 issues: the first led to #1698, the second led to the test failing as volume calcs need atom densities but they existed in a different location in MG mode. To fix the former, if blocks were placed to point to the MG nuclide data as necessary, and the latter by calling Material.finalize() at the appropriate spot in the MG code --- src/material.cpp | 32 ++++++++++++---------- src/mgxs_interface.cpp | 6 +++- src/volume_calc.cpp | 7 +++-- tests/regression_tests/volume_calc/test.py | 2 ++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/material.cpp b/src/material.cpp index ca29ce7404..30dfa5ed50 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -349,24 +349,26 @@ Material::~Material() void Material::finalize() { // Set fissionable if any nuclide is fissionable - for (const auto& i_nuc : nuclide_) { - if (data::nuclides[i_nuc]->fissionable_) { - fissionable_ = true; - break; + if (settings::run_CE) { + for (const auto& i_nuc : nuclide_) { + if (data::nuclides[i_nuc]->fissionable_) { + fissionable_ = true; + break; + } } + + // Generate material bremsstrahlung data for electrons and positrons + if (settings::photon_transport && + settings::electron_treatment == ElectronTreatment::TTB) { + this->init_bremsstrahlung(); + } + + // Assign thermal scattering tables + this->init_thermal(); } - // Generate material bremsstrahlung data for electrons and positrons - if (settings::photon_transport && - settings::electron_treatment == ElectronTreatment::TTB) { - this->init_bremsstrahlung(); - } - - // Assign thermal scattering tables - this->init_thermal(); - - // Normalize density - this->normalize_density(); +// Normalize density +this->normalize_density(); } void Material::normalize_density() diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 1a6dab5c6a..77085d57c8 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -123,10 +123,14 @@ void MgxsInterface::create_macro_xs() // Therefore type(nuclides[mat->nuclide_[0]]) dictates type(macroxs). // At the same time, we will find the scattering type, as that will dictate // how we allocate the scatter object within macroxs. + for (int i = 0; i < model::materials.size(); ++i) { + // First we have to normalize the densities as it has not been called yet + // for MG mode + auto& mat {model::materials[i]}; + mat->finalize(); if (kTs[i].size() > 0) { // Convert atom_densities to a vector - auto& mat {model::materials[i]}; vector atom_densities( mat->atom_density_.begin(), mat->atom_density_.end()); diff --git a/src/volume_calc.cpp b/src/volume_calc.cpp index ae738d6bb1..3ae98fdc38 100644 --- a/src/volume_calc.cpp +++ b/src/volume_calc.cpp @@ -8,6 +8,7 @@ #include "openmc/hdf5_interface.h" #include "openmc/material.h" #include "openmc/message_passing.h" +#include "openmc/mgxs_interface.h" #include "openmc/nuclide.h" #include "openmc/output.h" #include "openmc/random_lcg.h" @@ -237,7 +238,8 @@ vector VolumeCalculation::execute() const // Create 2D array to store atoms/uncertainty for each nuclide. Later this // is compressed into vectors storing only those nuclides that are // non-zero - auto n_nuc = data::nuclides.size(); + auto n_nuc = settings::run_CE ? data::nuclides.size() + : data::mg.nuclides_.size(); xt::xtensor atoms({n_nuc, 2}, 0.0); #ifdef OPENMC_MPI @@ -442,7 +444,8 @@ void VolumeCalculation::to_hdf5( vector nucnames; for (int i_nuc : result.nuclides) { - nucnames.push_back(data::nuclides[i_nuc]->name_); + nucnames.push_back(settings::run_CE ? data::nuclides[i_nuc]->name_ + : data::mg.nuclides_[i_nuc].name); } // Create array of total # of atoms with uncertainty for each nuclide diff --git a/tests/regression_tests/volume_calc/test.py b/tests/regression_tests/volume_calc/test.py index fc96e4a551..ddca3ceaa7 100644 --- a/tests/regression_tests/volume_calc/test.py +++ b/tests/regression_tests/volume_calc/test.py @@ -100,6 +100,8 @@ class VolumeTest(PyAPITestHarness): for iso in ['H1', 'O16', 'B10', 'Mo99', 'U235']: mat = openmc.XSdata(iso, groups) mat.order = 0 + mat.atomic_weight_ratio = \ + openmc.data.atomic_mass(iso) / openmc.data.NEUTRON_MASS mat.set_scatter_matrix(scatter) if iso == 'U235': mat.set_nu_fission(np.multiply(nu, fiss)) From f86410a6d83666fc1be1d892b355e9d57dbfb178 Mon Sep 17 00:00:00 2001 From: Adam Nelson <1037107+nelsonag@users.noreply.github.com> Date: Wed, 6 Oct 2021 13:26:29 -0500 Subject: [PATCH 3/4] Updated volume_calc test per comments from @paulromano --- tests/regression_tests/volume_calc/test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/regression_tests/volume_calc/test.py b/tests/regression_tests/volume_calc/test.py index ddca3ceaa7..189312a2f6 100644 --- a/tests/regression_tests/volume_calc/test.py +++ b/tests/regression_tests/volume_calc/test.py @@ -80,7 +80,7 @@ class VolumeTest(PyAPITestHarness): settings.volume_calculations = vol_calcs settings.export_to_xml() - # Create the MGXS file is necessary + # Create the MGXS file if necessary if not self.is_ce: groups = openmc.mgxs.EnergyGroups(group_edges=[0., 20.e6]) mg_xs_file = openmc.MGXSLibrary(groups) @@ -167,7 +167,7 @@ class VolumeTest(PyAPITestHarness): pass -def test_volume_calc(): - for is_ce in [True, False]: - harness = VolumeTest(is_ce, '') - harness.main() +@pytest.mark.parametrize('is_ce', [True, False]) +def test_volume_calc(is_ce): + harness = VolumeTest(is_ce, '') + harness.main() From 8c6502436141f0114149ae1b2d00dde3b3688a9e Mon Sep 17 00:00:00 2001 From: agnelson Date: Wed, 6 Oct 2021 13:49:33 -0500 Subject: [PATCH 4/4] importing pytest in vol_calc test --- tests/regression_tests/volume_calc/test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/regression_tests/volume_calc/test.py b/tests/regression_tests/volume_calc/test.py index 189312a2f6..e04eac7ff7 100644 --- a/tests/regression_tests/volume_calc/test.py +++ b/tests/regression_tests/volume_calc/test.py @@ -2,6 +2,7 @@ import os import glob import numpy as np +import pytest import openmc