Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/openmc/particle_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ struct NuclideMicroXS {

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

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion openmc/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def _calculate_cexs_nuclide(this, types, temperature=294., sab_name=None,
elif ncrystal_cfg:
import NCrystal
nc_scatter = NCrystal.createScatter(ncrystal_cfg)
nc_func = nc_scatter.crossSectionNonOriented
nc_func = nc_scatter.xsect
nc_emax = 5 # eV # this should be obtained from NCRYSTAL_MAX_ENERGY
energy_grid = np.union1d(np.geomspace(min(energy_grid),
1.1*nc_emax,
Expand Down
4 changes: 3 additions & 1 deletion src/particle.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the update of the NCrystal XS could be taken out of the if condition. Then the ACE XS is not recalculated if only the NCrystal XS changes, but the XS is updated anyway:

void Particle::update_neutron_xs(
  int i_nuclide, int i_grid, int i_sab, double sab_frac, double ncrystal_xs)
{
  // Get microscopic cross section cache
  auto& micro = this->neutron_xs(i_nuclide);

  // If the cache doesn't match, recalculate micro xs
  bool recalculate_xs = ( this->E() != micro.last_E || 
                          this->sqrtkT() != micro.last_sqrtkT ||
                          i_sab != micro.index_sab || 
                          sab_frac != micro.sab_frac );
  if ( recalculate_xs ) {
    data::nuclides[i_nuclide]->calculate_xs(i_sab, i_grid, sab_frac, *this);
  }
  // If NCrystal is being used, update micro cross section cache
  if ((recalculate_xs || ncrystal_xs != micro.last_ncrystal_xs ) 
       && (ncrystal_xs >= 0.0) ) {
    ncrystal_update_micro(ncrystal_xs, micro);
    micro.last_ncrystal_xs = ncrystal_xs;
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is getting a bit too complicated for my liking, I can't really wrap my head around whether or not that will always end up correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's keep it your way.

Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,12 @@ void Particle::update_neutron_xs(

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

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