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

Adding atomic mass management in C++ API #2819

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from

Conversation

bam241
Copy link
Contributor

@bam241 bam241 commented Dec 31, 2023

Description

This adds a simple API to read store and access, atomic masses.
This is merrily a transposition of the existing version in the Python API.
see data.py

This should be a step toward resolving of #2756.

I still have few questions:

  • shall we bind this to the Python solution (to avoid duplicates) ?
  • I have added reading and storing of the binding energy and mass excess. As there is no use now for those, shall we skip reading them and storing them ?
  • Where else could this be useful and leveraged ? For the plotter when no cross section are provided ?
  • do you have any advice on formatting and naming ?
  • any obvious place where this should be documented ?
  • any things I may have forgotten ?

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

This work is sponsored by First Light Fusion.

@bam241
Copy link
Contributor Author

bam241 commented Dec 31, 2023

I understand this is not yet ready.
I am looking for feedback to make this mergeable.

@bam241
Copy link
Contributor Author

bam241 commented Jan 1, 2024

I have tested this locally, it seems to be working.
The only thing I didn't figure out is how to point to mass_1.mas20.txt proper path.
right now it is located in openmc/data/ because it is used in the Python API. Not sure how to get that path from the cpp API, and/or if I should...

Copy link
Contributor

@gridley gridley left a comment

Choose a reason for hiding this comment

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

Nice simple code! Here are a few minor suggestions.

return s;
}

// Read a line from atomic mass data and pull usesull content
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Read a line from atomic mass data and pull usesull content
// Read a line from atomic mass data and pull useful content

src/atomic_mass_data.cpp Outdated Show resolved Hide resolved
src/atomic_mass_data.cpp Outdated Show resolved Hide resolved
auto pos = atomic_mass_data.find(nuclide);

if (pos == atomic_mass_data.end()) {
throw std::out_of_range(
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC the general paradigm in OpenMC now is to call fatal_error rather than throw exceptions but I'll let someone else weigh in.

src/atomic_mass_data.cpp Outdated Show resolved Hide resolved
auto pos = atomic_mass_data.find(nuclide);

if (pos == atomic_mass_data.end()) {
throw std::out_of_range(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
throw std::out_of_range(
fatal_error(

Not sure what is preferred, but this way it is an easy switch.

@bam241
Copy link
Contributor Author

bam241 commented Jan 6, 2024

thx for the review @gridley, much appreciated.

I think I have addressed most/all you comments :)

@bam241
Copy link
Contributor Author

bam241 commented Jan 11, 2024

now it is failing where I expect it to,

I need access to the mass_1.mas20.txt, and I don't know where to put it to guaranty it, to where to access it from

@shimwell
Copy link
Member

mass_1.mas20.txt

Not sure either but perhaps the values from the txt file can just be in the same cpp file that needs the data?

@bam241
Copy link
Contributor Author

bam241 commented Jan 11, 2024

the file exist in the Python API, I am wondering if there is a place where it can live and both API could access it

@bam241
Copy link
Contributor Author

bam241 commented Jan 13, 2024

The problem is mass_1.mas20.txt is already present in the Python source, and installed in the Python package.

I don't know what is best:

  • include all the mass data in a include file as done in constant.h
  • find a way to link to the file somehow.

if we decide to do an include file, shall we add a script to generate it ? generate it on build ?

@paulromano @pshriwise do you have any opinion about this ?

@yrrepy
Copy link
Contributor

yrrepy commented Apr 9, 2024

Hi Baptiste,
I was having some issues with with Abundances (different values in the Python API compared to what is used in MCNP)
#2423
#2586
#2585

I think it would be ideal for both of these files, atomic masses and atomic abundances to be in external files that are linked in. So there are defaults, but the user can select to read-in a user selected database.
It would be best if the Python API and C++ API could do this.

@shimwell
Copy link
Member

The need for this PR and following PR #2105 appear again in my new job. It would be great to have a materials collection like PNNL in openmc as it appears to be a common need across a few different organisation that I've seen using using openmc

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.

4 participants