{"action":"opened","number":721,"pull_request":{"url":"https://api.github.com/repos/mit-crpg/openmc/pulls/721","id":85504293,"html_url":"https://github.com/mit-crpg/openmc/pull/721","diff_url":"https://github.com/mit-crpg/openmc/pull/721.diff","patch_url":"https://github.com/mit-crpg/openmc/pull/721.patch","issue_url":"https://api.github.com/repos/mit-crpg/openmc/issues/721","number":721,"state":"open","locked":false,"title":"ENDF support in openmc.data and resonance reconstruction","user":{"login":"paulromano","id":743095,"avatar_url":"https://avatars.githubusercontent.com/u/743095?v=3","gravatar_id":"","url":"https://api.github.com/users/paulromano","html_url":"https://github.com/paulromano","followers_url":"https://api.github.com/users/paulromano/followers","following_url":"https://api.github.com/users/paulromano/following{/other_user}","gists_url":"https://api.github.com/users/paulromano/gists{/gist_id}","starred_url":"https://api.github.com/users/paulromano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulromano/subscriptions","organizations_url":"https://api.github.com/users/paulromano/orgs","repos_url":"https://api.github.com/users/paulromano/repos","events_url":"https://api.github.com/users/paulromano/events{/privacy}","received_events_url":"https://api.github.com/users/paulromano/received_events","type":"User","site_admin":false},"body":"This pull request extends the `openmc.data` module with `from_endf()` methods for many of the classes. They work the same as the `from_ace()` methods, so for example, you could do something like:\r\n```Python\r\nu235 = openmc.data.IncidentNeutron.from_endf('n-092_U_235.endf')\r\nelastic_xs = u235[2].xs['0K']\r\nnu_prompt = u235[18].products[0].yield_\r\n```\r\n\r\nIf you're familiar with the ACE machinery, the extensions should seem natural. Resonance data is stored in a new `resonances` attribute on `IncidentNeutron`, and there are a series of classes for dealing with the different resonance formalisms. Notably, the API is capable of reconstructing cross sections from the resonance parameters for SLBW, MLBW, and Reich-Moore formalisms. The most immediate use I can think of for this is generating 0 K elastic scattering cross sections for heavy-nuclide resonance scattering treatments (DBRC and the like). Since reconstructing resonances in Python would be dirt slow, I've implemented it in Cython to get closer to C performance. The use of Cython is optional -- when you setup the package, if Cython is not found, the only consequence is that resonance reconstruction is not available. All other features are still available.\r\n\r\nResonant cross sections are represented using a new `ResonancesWithBackground` class. This class has a `__call__()` method just like any other function, so you can evaluate it at one or many energies of your choosing.\r\n\r\nA few other notes:\r\n- The `FissionEnergyRelease` class has been reworked to use the new ENDF functionality.\r\n- TAB2 records in ENDF are not handled super cleanly right now. I'm kind of waiting for the GND folks to settle on how they plan to do low-level data containers for things like 1- and 2-D functions, and at that point, I'll try to move things to be more in line with GND.\r\n- Not all photon energy/angle distributions are handled yet. Not a big deal since we don't use photon production data yet anyway.\r\n- I haven't done anything with thermal scattering yet.\r\n\r\n## Notes on Resonance Reconstruction\r\n\r\nThe implementation is pretty slick if you ask me. Each formalism class (`SingleLevelBreitWigner`, `ReichMoore`, etc.) has a `parameters` attribute that is a Pandas dataframe of resonance parameters. The first time you go to reconstruct a cross section, the `_prepare_resonances()` method gets called which calculates shift and penetration factors and then stores them alongside the resonance parameters in a 2D array, one per (l,J) state. The actual reconstruction function in Cython can then efficiently use that 2D array.\r\n\r\nRegarding accuracy of the reconstructed cross sections -- in general, it is really good. As one example, here's the relative difference in cross sections between `openmc.data` and NJOY2012 for U235 from ENDF/B-VII.1:\r\n![u235](https://cloud.githubusercontent.com/assets/743095/18571880/3184c24a-7bb6-11e6-9599-e4ea33121cee.png)\r\nI've compared cross sections for all of ENDF/B-VII.1 (except for Cl35 and Pu239 for reasons I'll discuss) and almost everything is in very close agreement (errors < 1e-4) with NJOY2012. The cases where I saw relative differences larger than 1e-4 were:\r\n- Ar40, Nb93, U240, Gd152, Dy160: These nuclides actually have negative elastic scattering cross sections at 0 K. NJOY sets them to 1e-8 b, which of course results in huge relative differences. The following plot shows elastic scattering in Gd152:\r\n![gd152_negative](https://cloud.githubusercontent.com/assets/743095/18571374/33b4bdc6-7bb2-11e6-80d5-3a4af907b7b9.png)\r\n- Ce136, Sm150: The 1e-8 b minimum cross section also occurs even if the cross section is tiny but positive. This happens for these two nuclides. Here's a plot showing Ce136:\r\n![ce136_small](https://cloud.githubusercontent.com/assets/743095/18571391/4dc6ad96-7bb2-11e6-8ac4-93232e3c395c.png)\r\n- Fe54: There's a huge resonance interference dip in elastic scattering and\r\nwe miss the bottom by 0.1%.\r\n- Pb206, Pb208: These are the only two nuclides with differences that I can't yet explain. The differences are in capture at low energy, which is 1/v. However, our reconstructed cross sections are just slightly jagged if you zoom in closely enough. My guess is we're losing precision somewhere, but I haven't been able to figure out where exactly yet. Both of these use the Reich-Moore approximation. Here's the relative difference in Pb208 capture:\r\n![pb208](https://cloud.githubusercontent.com/assets/743095/18571429/924d7f44-7bb2-11e6-99f3-4cb1eae46fe8.png)\r\n\r\nFor the very curious: a [tarball](https://www.dropbox.com/s/ueliqho83adkhfx/plots.tar.xz?dl=0) with plots comparing all nuclides with resonances.\r\n\r\nI should mention that in order to get the extraordinary agreement on most nuclides, I did make sure I was using the same fundamental physics constants as NJOY (which feed into the calculation of the neutron wave number). If I use updated CODATA values, the comparisons are not quite as perfect, but still very good.\r\n\r\nThere were two cases I couldn't run:\r\n- Cl35: We can't handle LRF=7 (R-Matirx Limited) yet and this is the only guy in ENDF/B-VII.1 that uses that formalism.\r\n- Pu239: In VII.1, there are actually three resolved resonance ranges. I need to look into whether it's safe to just combine the parameters from all three. For what it's worth, I tested the new B/VIII.0 beta2 file and it compares perfectly with NJOY.\r\n\r\n**tl;dr** resonance reconstruction is not yet quite complete but is pretty damn good already.\r\n\r\n### Developer note\r\n\r\nIf, like me, you tend to add the OpenMC directory to your `PYTHONPATH`, you can still get the reconstruct Cython module built without having to install the entire API. To do this, just run:\r\n```sh\r\npython setup.py build_ext --inplace\r\n```","created_at":"2016-09-16T00:43:53Z","updated_at":"2016-09-16T00:43:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mit-crpg/openmc/pulls/721/commits","review_comments_url":"https://api.github.com/repos/mit-crpg/openmc/pulls/721/comments","review_comment_url":"https://api.github.com/repos/mit-crpg/openmc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mit-crpg/openmc/issues/721/comments","statuses_url":"https://api.github.com/repos/mit-crpg/openmc/statuses/cbcd3a7f573c1c5ead8a7d1ec5457d34fa034f87","head":{"label":"paulromano:pyapi-data-endf","ref":"pyapi-data-endf","sha":"cbcd3a7f573c1c5ead8a7d1ec5457d34fa034f87","user":{"login":"paulromano","id":743095,"avatar_url":"https://avatars.githubusercontent.com/u/743095?v=3","gravatar_id":"","url":"https://api.github.com/users/paulromano","html_url":"https://github.com/paulromano","followers_url":"https://api.github.com/users/paulromano/followers","following_url":"https://api.github.com/users/paulromano/following{/other_user}","gists_url":"https://api.github.com/users/paulromano/gists{/gist_id}","starred_url":"https://api.github.com/users/paulromano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulromano/subscriptions","organizations_url":"https://api.github.com/users/paulromano/orgs","repos_url":"https://api.github.com/users/paulromano/repos","events_url":"https://api.github.com/users/paulromano/events{/privacy}","received_events_url":"https://api.github.com/users/paulromano/received_events","type":"User","site_admin":false},"repo":{"id":6039026,"name":"openmc","full_name":"paulromano/openmc","owner":{"login":"paulromano","id":743095,"avatar_url":"https://avatars.githubusercontent.com/u/743095?v=3","gravatar_id":"","url":"https://api.github.com/users/paulromano","html_url":"https://github.com/paulromano","followers_url":"https://api.github.com/users/paulromano/followers","following_url":"https://api.github.com/users/paulromano/following{/other_user}","gists_url":"https://api.github.com/users/paulromano/gists{/gist_id}","starred_url":"https://api.github.com/users/paulromano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulromano/subscriptions","organizations_url":"https://api.github.com/users/paulromano/orgs","repos_url":"https://api.github.com/users/paulromano/repos","events_url":"https://api.github.com/users/paulromano/events{/privacy}","received_events_url":"https://api.github.com/users/paulromano/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/paulromano/openmc","description":"OpenMC Monte Carlo Code","fork":true,"url":"https://api.github.com/repos/paulromano/openmc","forks_url":"https://api.github.com/repos/paulromano/openmc/forks","keys_url":"https://api.github.com/repos/paulromano/openmc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paulromano/openmc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paulromano/openmc/teams","hooks_url":"https://api.github.com/repos/paulromano/openmc/hooks","issue_events_url":"https://api.github.com/repos/paulromano/openmc/issues/events{/number}","events_url":"https://api.github.com/repos/paulromano/openmc/events","assignees_url":"https://api.github.com/repos/paulromano/openmc/assignees{/user}","branches_url":"https://api.github.com/repos/paulromano/openmc/branches{/branch}","tags_url":"https://api.github.com/repos/paulromano/openmc/tags","blobs_url":"https://api.github.com/repos/paulromano/openmc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paulromano/openmc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paulromano/openmc/git/refs{/sha}","trees_url":"https://api.github.com/repos/paulromano/openmc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paulromano/openmc/statuses/{sha}","languages_url":"https://api.github.com/repos/paulromano/openmc/languages","stargazers_url":"https://api.github.com/repos/paulromano/openmc/stargazers","contributors_url":"https://api.github.com/repos/paulromano/openmc/contributors","subscribers_url":"https://api.github.com/repos/paulromano/openmc/subscribers","subscription_url":"https://api.github.com/repos/paulromano/openmc/subscription","commits_url":"https://api.github.com/repos/paulromano/openmc/commits{/sha}","git_commits_url":"https://api.github.com/repos/paulromano/openmc/git/commits{/sha}","comments_url":"https://api.github.com/repos/paulromano/openmc/comments{/number}","issue_comment_url":"https://api.github.com/repos/paulromano/openmc/issues/comments{/number}","contents_url":"https://api.github.com/repos/paulromano/openmc/contents/{+path}","compare_url":"https://api.github.com/repos/paulromano/openmc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paulromano/openmc/merges","archive_url":"https://api.github.com/repos/paulromano/openmc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paulromano/openmc/downloads","issues_url":"https://api.github.com/repos/paulromano/openmc/issues{/number}","pulls_url":"https://api.github.com/repos/paulromano/openmc/pulls{/number}","milestones_url":"https://api.github.com/repos/paulromano/openmc/milestones{/number}","notifications_url":"https://api.github.com/repos/paulromano/openmc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paulromano/openmc/labels{/name}","releases_url":"https://api.github.com/repos/paulromano/openmc/releases{/id}","deployments_url":"https://api.github.com/repos/paulromano/openmc/deployments","created_at":"2012-10-02T01:55:56Z","updated_at":"2016-01-18T18:36:18Z","pushed_at":"2016-09-15T23:55:40Z","git_url":"git://github.com/paulromano/openmc.git","ssh_url":"git@github.com:paulromano/openmc.git","clone_url":"https://github.com/paulromano/openmc.git","svn_url":"https://github.com/paulromano/openmc","homepage":"","size":28713,"stargazers_count":2,"watchers_count":2,"language":"FORTRAN","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":2,"default_branch":"develop"}},"base":{"label":"mit-crpg:develop","ref":"develop","sha":"4f95b4a7f664b7dd43276b386ce2306eb7526d78","user":{"login":"mit-crpg","id":1247634,"avatar_url":"https://avatars.githubusercontent.com/u/1247634?v=3","gravatar_id":"","url":"https://api.github.com/users/mit-crpg","html_url":"https://github.com/mit-crpg","followers_url":"https://api.github.com/users/mit-crpg/followers","following_url":"https://api.github.com/users/mit-crpg/following{/other_user}","gists_url":"https://api.github.com/users/mit-crpg/gists{/gist_id}","starred_url":"https://api.github.com/users/mit-crpg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mit-crpg/subscriptions","organizations_url":"https://api.github.com/users/mit-crpg/orgs","repos_url":"https://api.github.com/users/mit-crpg/repos","events_url":"https://api.github.com/users/mit-crpg/events{/privacy}","received_events_url":"https://api.github.com/users/mit-crpg/received_events","type":"Organization","site_admin":false},"repo":{"id":2081118,"name":"openmc","full_name":"mit-crpg/openmc","owner":{"login":"mit-crpg","id":1247634,"avatar_url":"https://avatars.githubusercontent.com/u/1247634?v=3","gravatar_id":"","url":"https://api.github.com/users/mit-crpg","html_url":"https://github.com/mit-crpg","followers_url":"https://api.github.com/users/mit-crpg/followers","following_url":"https://api.github.com/users/mit-crpg/following{/other_user}","gists_url":"https://api.github.com/users/mit-crpg/gists{/gist_id}","starred_url":"https://api.github.com/users/mit-crpg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mit-crpg/subscriptions","organizations_url":"https://api.github.com/users/mit-crpg/orgs","repos_url":"https://api.github.com/users/mit-crpg/repos","events_url":"https://api.github.com/users/mit-crpg/events{/privacy}","received_events_url":"https://api.github.com/users/mit-crpg/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mit-crpg/openmc","description":"OpenMC Monte Carlo Code","fork":false,"url":"https://api.github.com/repos/mit-crpg/openmc","forks_url":"https://api.github.com/repos/mit-crpg/openmc/forks","keys_url":"https://api.github.com/repos/mit-crpg/openmc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mit-crpg/openmc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mit-crpg/openmc/teams","hooks_url":"https://api.github.com/repos/mit-crpg/openmc/hooks","issue_events_url":"https://api.github.com/repos/mit-crpg/openmc/issues/events{/number}","events_url":"https://api.github.com/repos/mit-crpg/openmc/events","assignees_url":"https://api.github.com/repos/mit-crpg/openmc/assignees{/user}","branches_url":"https://api.github.com/repos/mit-crpg/openmc/branches{/branch}","tags_url":"https://api.github.com/repos/mit-crpg/openmc/tags","blobs_url":"https://api.github.com/repos/mit-crpg/openmc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mit-crpg/openmc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mit-crpg/openmc/git/refs{/sha}","trees_url":"https://api.github.com/repos/mit-crpg/openmc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mit-crpg/openmc/statuses/{sha}","languages_url":"https://api.github.com/repos/mit-crpg/openmc/languages","stargazers_url":"https://api.github.com/repos/mit-crpg/openmc/stargazers","contributors_url":"https://api.github.com/repos/mit-crpg/openmc/contributors","subscribers_url":"https://api.github.com/repos/mit-crpg/openmc/subscribers","subscription_url":"https://api.github.com/repos/mit-crpg/openmc/subscription","commits_url":"https://api.github.com/repos/mit-crpg/openmc/commits{/sha}","git_commits_url":"https://api.github.com/repos/mit-crpg/openmc/git/commits{/sha}","comments_url":"https://api.github.com/repos/mit-crpg/openmc/comments{/number}","issue_comment_url":"https://api.github.com/repos/mit-crpg/openmc/issues/comments{/number}","contents_url":"https://api.github.com/repos/mit-crpg/openmc/contents/{+path}","compare_url":"https://api.github.com/repos/mit-crpg/openmc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mit-crpg/openmc/merges","archive_url":"https://api.github.com/repos/mit-crpg/openmc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mit-crpg/openmc/downloads","issues_url":"https://api.github.com/repos/mit-crpg/openmc/issues{/number}","pulls_url":"https://api.github.com/repos/mit-crpg/openmc/pulls{/number}","milestones_url":"https://api.github.com/repos/mit-crpg/openmc/milestones{/number}","notifications_url":"https://api.github.com/repos/mit-crpg/openmc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mit-crpg/openmc/labels{/name}","releases_url":"https://api.github.com/repos/mit-crpg/openmc/releases{/id}","deployments_url":"https://api.github.com/repos/mit-crpg/openmc/deployments","created_at":"2011-07-21T00:33:27Z","updated_at":"2016-09-13T03:25:41Z","pushed_at":"2016-09-15T22:03:03Z","git_url":"git://github.com/mit-crpg/openmc.git","ssh_url":"git@github.com:mit-crpg/openmc.git","clone_url":"https://github.com/mit-crpg/openmc.git","svn_url":"https://github.com/mit-crpg/openmc","homepage":"http://mit-crpg.github.io/openmc/","size":48520,"stargazers_count":85,"watchers_count":85,"language":"FORTRAN","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":101,"mirror_url":null,"open_issues_count":52,"forks":101,"open_issues":52,"watchers":85,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/mit-crpg/openmc/pulls/721"},"html":{"href":"https://github.com/mit-crpg/openmc/pull/721"},"issue":{"href":"https://api.github.com/repos/mit-crpg/openmc/issues/721"},"comments":{"href":"https://api.github.com/repos/mit-crpg/openmc/issues/721/comments"},"review_comments":{"href":"https://api.github.com/repos/mit-crpg/openmc/pulls/721/comments"},"review_comment":{"href":"https://api.github.com/repos/mit-crpg/openmc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mit-crpg/openmc/pulls/721/commits"},"statuses":{"href":"https://api.github.com/repos/mit-crpg/openmc/statuses/cbcd3a7f573c1c5ead8a7d1ec5457d34fa034f87"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":3308,"deletions":171,"changed_files":21}}
{"actor":{"display_login":"paulromano"}}