Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix generating 0K data from NJOY #905

Merged
merged 6 commits into from Aug 2, 2017
Merged

Conversation

liangjg
Copy link
Contributor

@liangjg liangjg commented Jul 28, 2017

  1. A tiny bug in generating 0K data from NJOY
import urllib.request
import openmc.data

url = 'https://t2.lanl.gov/nis/data/data/ENDFB-VII.1-neutron/Fe/56'
filename, headers = urllib.request.urlretrieve(url, 'fe56.endf')
fe56_njoy = openmc.data.IncidentNeutron.from_njoy('fe56.endf', temperatures=[0.])
fe56_njoy.export_to_hdf5('fe56.h5')
fe56_hdf5 = openmc.data.IncidentNeutron.from_hdf5('fe56.h5')
fe56_hdf5[1].xs['0K']([1e6])
IndexError: index 3334 is out of bounds for axis 1 with size 2869

It is caused by the action to add 0K elastic scattering cross section from PENDF after running njoy, which overwrites the existing '0K' energy grid. This can be fixed by adding a line above the block

# Add 0K elastic scattering cross section
if '0K' not in data.energy:
  ...
  1. [Not implemented] The error tolerance in reconstruction is currently fixed as 0.001. The users may want a different error in some cases. Should we add a parameter in the APIs to make it possible? I mean to set the err card in input file. For the tempr and errmax, we may remove them to use the default values in njoy. The same changes can be made on broadr. The thnmax (upper limit for broadening) 1.0e6 in the template is recommended to be removed too as the default upper limit for broadening has been changed since NJOY2012.75. But I'm not sure why the values like thnmax and errmax are different in sab case so the changes are not made yet. I'll push the new commit after @paulromano gives more suggestions.

@liangjg
Copy link
Contributor Author

liangjg commented Jul 28, 2017

Well, I pushed the changes to make error tolerance a parameter for generating data from njoy. Let me know if there is any problem. @paulromano

@paulromano
Copy link
Contributor

Thanks @liangjg, I'll take a look soon!

@liangjg
Copy link
Contributor Author

liangjg commented Jul 30, 2017

I found another issue on generating 0K data from NJOY:

nuc = openmc.data.IncidentNeutron.from_njoy('n-018_Ar_036.endf', temperatures=[0.], stdout=True)
"""
 njoy 2016.15  08May17                                       07/30/17 10:45:53
 *****************************************************************************

 reconr...                                                                0.0s

 broadr...                                                                0.1s

 heatr...                                                                 0.1s

 purr...                                                                  0.2s

 mat = 1825                                                               0.2s
      1 of    22 loops done for all temps & sig0s.                       25.6s
      2 of    22 loops done for all temps & sig0s.                       50.2s
      3 of    22 loops done for all temps & sig0s.                       74.6s
      4 of    22 loops done for all temps & sig0s.                       99.0s
      5 of    22 loops done for all temps & sig0s.                      123.3s
      6 of    22 loops done for all temps & sig0s.                      147.7s
      7 of    22 loops done for all temps & sig0s.                      172.1s
      8 of    22 loops done for all temps & sig0s.                      196.5s
      9 of    22 loops done for all temps & sig0s.                      220.9s
     10 of    22 loops done for all temps & sig0s.                      245.4s
     11 of    22 loops done for all temps & sig0s.                      269.8s
     12 of    22 loops done for all temps & sig0s.                      294.3s
     13 of    22 loops done for all temps & sig0s.                      318.7s
     14 of    22 loops done for all temps & sig0s.                      343.2s
     15 of    22 loops done for all temps & sig0s.                      367.6s
     16 of    22 loops done for all temps & sig0s.                      392.1s
     17 of    22 loops done for all temps & sig0s.                      416.5s
     18 of    22 loops done for all temps & sig0s.                      441.0s
     19 of    22 loops done for all temps & sig0s.                      465.4s
     20 of    22 loops done for all temps & sig0s.                      489.8s
     21 of    22 loops done for all temps & sig0s.                      514.3s
     22 of    22 loops done for all temps & sig0s.                      538.8s

 acer...                                                                538.8s
At line 852 of file /home/liangjg/codes/NJOY2016/src/endf.f90 (unit = 24, file = 'tape24')
Fortran runtime error: Bad value during floating point read
"""

The error appears for nuclides with unresolved resonance range. There are a lot of 'NaN' in the output of purr module. I've no idea why NJOY fails on treating probability table at 0K. Any thoughts?

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @liangjg. I also had in mind that it would be useful to specify the error tolerance but then forgot to implement that -- glad you did!

@@ -824,7 +824,7 @@ def from_endf(cls, ev_or_filename):
return data

@classmethod
def from_njoy(cls, filename, temperatures=None, **kwargs):
def from_njoy(cls, filename, temperatures=None, error=0.001, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's put this argument on njoy.make_ace instead of here. It will still be possible for a user to specify it as a keyword argument since **kwargs gets passed to make_ace.

@@ -588,7 +588,8 @@ def from_ace(cls, ace_or_filename, name=None):
return table

@classmethod
def from_njoy(cls, filename, filename_thermal, temperatures=None, **kwargs):
def from_njoy(cls, filename, filename_thermal, temperatures=None,
error=0.001, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here -- move this argument to njoy.make_ace_thermal and let **kwargs pass it if needed.

@liangjg
Copy link
Contributor Author

liangjg commented Aug 1, 2017

@paulromano The argument error has been removed from the upper-level function from_njoy.
Additionally, I tried to add several other arguments to allow omitting certain modules when running NJOY, like:

openmc.data.IncidentNeutron.from_njoy("n-092-U-235.endf", [0.], heatr=False, purr=False)

will skip calling heatr and purr modules. I found this is useful for me to parse pure 0K ce xs for vector fitting.

@@ -50,84 +50,66 @@
75: ThermalTuple('ouo2', [8016, 8017, 8018], 1),
}


_PENDF_TEMPLATE = """
_ACE_TEMPLATE_RECONR = """
Copy link
Contributor

Choose a reason for hiding this comment

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

We might as well rename all these to just _TEMPLATE_* since they are not specific to ACE now.

@@ -147,6 +130,8 @@ def run(commands, tapein, tapeout, stdout=False, njoy_exec='njoy'):
Dictionary mapping tape numbers to paths for any input files
tapeout : dict
Dictionary mapping tape numbers to paths for any output files
print_commands : bool, optional
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 it would be more useful to have the inputs saved to a file. Why don't we have an argument run(..., input_filename=None, ...) that if it's set to a string will save the inputs to a file with that name. So below, you'd have something like:

if input_filename is not None:
    with open(input_filename, 'w') as input:
        input.write(commands)

@paulromano
Copy link
Contributor

Really nice set of additions @liangjg. These would have been useful to me as I was debugging this module actually! Should be ready to merge after those last two comments of mine are addressed.

By the way, if you just need 0 K cross sections, you could do something like:

import openmc.data

openmc.data.njoy.make_pendf(endf_filename)
data = openmc.data.IncidentNeutron.from_endf('pendf')
elastic_scatter = data[2].xs['0K'] 

write NJOY input into file rather than printing on screen
_ACE_TEMPLATE -> _TEMPLATE
@liangjg
Copy link
Contributor Author

liangjg commented Aug 2, 2017

@paulromano Thanks for the suggestion to use make_pendf() and from_endf() .

@paulromano paulromano merged commit f124bec into openmc-dev:develop Aug 2, 2017
@liangjg liangjg deleted the njoy_0K branch February 28, 2019 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants