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

modified src/mcnp_library.cpp to properly read the directory entries #30

Merged
merged 6 commits into from
Feb 5, 2024

Conversation

furutaka
Copy link
Contributor

According to an MCNP document, the lines below "DIRECTORY" (case insensitive) in a "xsdir" file consist of "seven- to eleven-entry description of each table". The present implementation, however, seems to assume that eleven entries always exist, and therefore when it encounters a seven-entry line, it coredumps in e.g. trying to convert a string to double in mcnp_library.cpp:191

To properly read these variable-entry-number lines, a modification was made by utilizing std::getline(); the input stream is read line-by-line and then decomposed.

Tested with

  • MCNP_DATA/xsdir
  • MCNP_DATA/xsdir_mcnp5_endfb-7.0
  • MCNP_DATA/xsdir_mcnp5_endfb-7.1
  • MCNP_DATA/xsdir_mcnp6.1
  • MCNP_DATA/xsdir_mcnp6.1_endfb-7.0
  • MCNP_DATA/xsdir_mcnp6.1_endfb-7.1
    of MCNP6.1 and
  • PHITS331A/data/xsdir.jnd (JENDL-4)
    of PHITS.

According to an MCNP document,
https://mcnp.lanl.gov/pdf_files/TechReport_2022_LANL_LA-UR-22-30006Rev.1_KuleszaAdamsEtAl.pdf
the lines below "DIRECTORY" (case insensitive) consist of
"seven- to eleven-entry description of each table".
The present implementation, however, seems to assume eleven
entries, and therefore when it encounters a seven-entry line,
it coredumps in e.g. trying to convert a string to double
in mcnp_library.cpp:191

To properly read these variable-entry-number lines, a modification
was made by utilizing std::getline(); the input stream is read
line-by-line and then decomposed.
if (str!="+" && line_buffer.size()<=11) // each content if it's not
line_buffer.push_back(str); // the continuation mark
else
goto LINE_LOOP; // goto the continued line
Copy link
Owner

Choose a reason for hiding this comment

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

Would it be possible to remove this goto ? I think a good solution might be to put the 3 lines above into a lambda function, and we can then call that at the beginning of the outer while loop, and in this else statement.

@HunterBelanger
Copy link
Owner

Thank you for your contribution ! I left one comment about changing the goto, but in general it looks like your modifications and the use of that regex make the code simpler, which is great !

Currently, Papillon cannot handle multiple ACE tables being in the same file (as you can see, the address_str variable is read, but never used). I am not super familiar with these other libraries that you tested on, but do any of them have multiple ACE tables in a single file ? Currently, the MCNPLibrary class would not handle this correctly either. I think having multiple ACE tables in a file has fallen out of favor, but if this is something that is done in the libraries that you tested, I am thinking that this PR might be the right opportunity to fix this.

@furutaka
Copy link
Contributor Author

furutaka commented Jan 2, 2024

Hi. Happy new year!

Sorry for my late reply; I had to make a trip to a different part of Japan to attend a memorial service and then to do year-end clean-up of my house after coming back home...

I've further modified the code to eliminate the goto. I hope it's now cleaner and concise enough.

It's possible to extract the contents of a directry-entry line by using a regular expression (and I did write the regex e.g. const std::regex dirent("^ *([^[:space:]]+)( +([^[:space:]]+)){6,11}");) instead of using getline() and std::vector<std::string, but I don't think it's worth because it does NOT seem to contribute for further simplification.

As for the address_str and ACE format, I'm not familiar with them either! I'm sorry but I'm merely a user and I've just tried to use(plot) the data to get insight into some results of Monte Carlo simulations.

(Sorry for my broken language!)

@HunterBelanger
Copy link
Owner

Sorry for taking so long to get back to this ! Don't worry about the multiple ACE tables in a file; I will handle this in a separate PR at some point. I made a few small modifications to your branch, but otherwise I think it looks good. Please check to make sure that it still works on your other xsdirs, and if so, I will merge this PR.

@furutaka
Copy link
Contributor Author

It does NOT work at all; it seems that by doing temp_str.clear(); another old defect was revealed.
According to MCNP manual, 10th parameter is

Temperature. This is the temperature in MeV at which a neutron table is processed. This entry is used
only for neutron data.

and is not always given. Therefore, in case it's not given, the following line,
169 double temp = std::stod(temp_str) * MEV_TO_EV * EV_TO_K;
will cause an error (in trying to convert an empty string to double). My modification also did not take this into consideration, but it was hidden because temp_str was not clear()ed once it was set (which is a bug) and the lines without temperature are often given after the lines with it.
Apparently the line needs some kind of guard, and I think it may be done according to zaid_suffix. The xsdir files of MCNP and PHITS seem to have the temperature data in the lines with the following ZAID suffices:

  • c: Continuous-energy neutron data libraries
  • d: Discrete-energy neutron data libraries
  • e: Electron data libraries
  • h: Proton data libraries
  • o: Deuteron data libraries
  • p: Photoatomic data libraries with atomic relaxation data
  • t: S(α,β) data tables
  • u: Photonuclear data libraries

By the way, the MCNP manual says that the temperature parameter "is used only for neutron data", but temp is used only for suffices 'c' and 't'. Is it ok to leave the 'd' line untouched? (I'm not an XSDIR expert)

@HunterBelanger
Copy link
Owner

I modified it now to only read CE neutron data with a c or t suffix. Hopefully this is the last needed fix 🤞🏼.

@furutaka
Copy link
Contributor Author

furutaka commented Feb 5, 2024

I don't think you have tested the modified code by yourself...
It didn't work yet; we have to skip the empty string returned by getline() after reading all the lines.

@HunterBelanger
Copy link
Owner

My apologies: I did test it, but I think that there was an older version caught in my LD_LIBRARY_PATH that was being picked up, because I only saw this problem once I switched computers. I think this looks good now, and I will go ahead and merge it. Thank you again for your contribution, and please don't hesitate to make more in the future if you find something that can be improved !

@HunterBelanger HunterBelanger merged commit 50811ee into HunterBelanger:develop Feb 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants