Skip to content

Commit 8a62e7e

Browse files
tkittelmarquezjpaulromano
authored
Fix caching issue when using NCrystal materials (#3538)
Co-authored-by: Jose Ignacio Marquez Damian <22483345+marquezj@users.noreply.github.com> Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent 7806703 commit 8a62e7e

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

include/openmc/particle_data.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ struct NuclideMicroXS {
154154

155155
// Energy and temperature last used to evaluate these cross sections. If
156156
// these values have changed, then the cross sections must be re-evaluated.
157-
double last_E {0.0}; //!< Last evaluated energy
158-
double last_sqrtkT {0.0}; //!< Last temperature in sqrt(Boltzmann constant
159-
//!< * temperature (eV))
157+
double last_E {0.0}; //!< Last evaluated energy
158+
double last_sqrtkT {0.0}; //!< Last temperature in sqrt(Boltzmann constant
159+
//!< * temperature (eV))
160+
double ncrystal_xs {-1.0}; //!< NCrystal cross section
160161
};
161162

162163
//==============================================================================

openmc/plotter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def _calculate_cexs_nuclide(this, types, temperature=294., sab_name=None,
501501
elif ncrystal_cfg:
502502
import NCrystal
503503
nc_scatter = NCrystal.createScatter(ncrystal_cfg)
504-
nc_func = nc_scatter.crossSectionNonOriented
504+
nc_func = nc_scatter.xsect
505505
nc_emax = 5 # eV # this should be obtained from NCRYSTAL_MAX_ENERGY
506506
energy_grid = np.union1d(np.geomspace(min(energy_grid),
507507
1.1*nc_emax,

src/particle.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,12 @@ void Particle::update_neutron_xs(
855855

856856
// If the cache doesn't match, recalculate micro xs
857857
if (this->E() != micro.last_E || this->sqrtkT() != micro.last_sqrtkT ||
858-
i_sab != micro.index_sab || sab_frac != micro.sab_frac) {
858+
i_sab != micro.index_sab || sab_frac != micro.sab_frac ||
859+
ncrystal_xs != micro.ncrystal_xs) {
859860
data::nuclides[i_nuclide]->calculate_xs(i_sab, i_grid, sab_frac, *this);
860861

861862
// If NCrystal is being used, update micro cross section cache
863+
micro.ncrystal_xs = ncrystal_xs;
862864
if (ncrystal_xs >= 0.0) {
863865
data::nuclides[i_nuclide]->calculate_elastic_xs(*this);
864866
ncrystal_update_micro(ncrystal_xs, micro);

0 commit comments

Comments
 (0)