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

Add call to the OpenMC Depletion Solver #13

Merged
merged 36 commits into from
May 31, 2023
Merged

Conversation

abachma2
Copy link
Collaborator

This PR adds new functionality to the DepleteReactor archetype:

  • Call the OpenMC depletion sovler during the transmute method
  • Write the resulting composition to an xml file
  • Add state variables for the path to the directory with OpenMC model files and the name of the decay chain file

The CI fails because importing openmc into the archetype (i.e. import openmc) causes a segmentation fault. The seg fault is after the simulation runs and writes the results to the output file and is trying to close python imports (I think). So it all still mostly runs, and I have manually compared the results of the output database to the expected values in the test suite. An issue (#12) has been created to help resolve the seg fault.

Add state variable definition and default. Add mention to phase 1 of
DRE, but not sure it is any meaningful functionality. Tests all pass
New functions to get the index of a materials commodity name,
recipe name, or preference based on the material's object ID.
These functions exist in cycamore:Reactor, but were previously overlooked
add an if loop to only get the material if its commodity
name is in the spent materials dictionary. Call the get_commods
function instead of just looping of the commodity names list.
3 tests failing, two of which concern the resources
The loop for the recipes was creating a bid for each
possiblespent fuel recipe, which is unphysical. Each spent fuel
assembly will only have one composition. Instead, get the index of
the commodity name in fuel_outcommods and matches to the recipe
at the same index of fuel_outrecipes. Enforces the need for users to
have consistent ordering in their input file
Had to manually call each step of the Depletion.run_depletion
because it just would not work if I tried to call that method
directly
@abachma2 abachma2 requested a review from yardasol April 25, 2023 20:30
@abachma2 abachma2 self-assigned this Apr 25, 2023
@abachma2 abachma2 added Comp:Core This issue has to do with the main bulk of the code or document. (methods, main content) Difficulty:2-Challenging This issue may be complex or require specialized skills. Priority:2-Normal This work is important and should be completed ASAP. Status:5-In Review This issue has been handled, and the solution is being reviewed. (probably as a PR) Type:Feature New feature or feature request labels Apr 25, 2023
Comment on lines 11 to 47
- name: Setup Conda
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: openmcyclus-env
environment-file: environment.yml
use-mamba: true

- name: Conda config
run: |
conda config --env --set pip_interop_enabled True

- name: Update Environment
run: |
mamba env update -n openmcyclus-env -f environment.yml

- name: Install pytest
run: conda install -y pytest

- name: Build OpenMC
run: |
mamba install openmc
conda install -y python=3.7 cyclus cycamore
HDF5_DIR=$CONDA_PREFIX && pip install h5py

- name: OpenMC dependencies
run: |
sudo apt -y update
sudo apt install -y libhdf5-dev

- name: Download OpenMC
uses: actions/checkout@v3
with:
repository: openmc-dev/openmc
path: openmc
submodules: recursive

- name: Build OpenMC from source
run: |
run: build-openmc.sh


- name: Install OpenMC cross section library
run: echo "OPENMC_CROSS_SECTIONS=cross_sections.xml" >> $GITHUB_ENV
Copy link

Choose a reason for hiding this comment

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

Have you tested this workflow yet? If not, you could merge into your fork's main branch to test it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like right now there is a syntax error in the ci scripts, so I will fix that. But because of a seg fault when importing OpenMC into a cyclus script (See issue #12), there isn't much point in running the integration tests in a CI environment, because they will all fail due to the seg fault. I can make sure that the environment builds and the unit tests pass, but that's the best I can do until Issue #12 is resolved.

Copy link

Choose a reason for hiding this comment

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

Oh yes sorry for not reading your PR comments properly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All good. It's important to have the CI as functional as possible. I'll fix the syntax error int he CI on this branch, but do the bulk of the CI changes/maintenance on another branch to keep this PR from getting too big.

Copy link
Member

@nsryan2 nsryan2 left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, I saw Sun Myung's comment so I won't approve quite yet, I had some minor README comments, package comments, and some stuff on the tests.

pytest --ignore tests/unit_tests
pytest

FWAk8hnxPUNDeep!
Copy link
Member

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure how that ended up there. I must have accidentally copied whatever was in my clipboard into the file. It's been removed!

### Install OpenMCyclus
To install this archetype library run ``pip install .``.
To run tests: ``pytest`` from the main directory.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### Testing
In progress.

Should there be a testing subsubsection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All it would contain would be the sentence about running pytest.

assert all(quantities == [10]*6)
assert len(tbl) == 9
assert all(times == [0,0,0,2,2,5,5,8,8])
assert all(quantities == [10]*9)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert all(quantities == [10]*9)
assert all(quantities == [10]*len(tbl))

Would it reduce the chance for errors if you add times later if you changed it to this? For test_resources too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This part of the code is testing what's in the output database. So your code suggestion is just testing if all of the entries in the table are of value 10, not specifically if there are 9 occurrences of value 10 in the table. I suppose that by testing for [10]*9 that's also checking that there are 9 values in the table, same as l.124. but I'm okay with being redundant in my testing.

Copy link

@smpark7 smpark7 left a comment

Choose a reason for hiding this comment

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

I didn't run anything but I looked through your code. Here are my review comments.

Comment on lines +107 to +108
<model_path>/home/abachmann/openmcyclus/tests/</model_path>
<chain_file>chain_endfb71_pwr.xml</chain_file>
Copy link

Choose a reason for hiding this comment

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

Can this be a relative path? It won't work on other people's computers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe? I'll play around with it. Can we make this an issue so that this doesn't hold up the merging of this PR?

Copy link

Choose a reason for hiding this comment

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

Sure that's okay

Comment on lines +344 to +371
for commod_index, commod in enumerate(self.fuel_outcommods):
reqs = requests[commod]
print("time:", self.context.time, "reqs:", reqs)
if len(reqs) == 0:
continue
elif (got_mats == False):
all_mats = self.peek_spent()

if len(all_mats) == 0:
tot_qty = 0
continue
mats = [all_mats[commod]]
if commod in all_mats:
mats = [all_mats[commod]]

else:
mats = []
print("time:", self.context.time, "mats to trade matching request commod:", mats)
if len(mats) == 0:
continue
for ii in range(len(self.fuel_outrecipes)):
recipe_comp = self.context.get_recipe(self.fuel_outrecipes[ii])
for req in reqs:
tot_bid = 0
for jj in range(len(mats)):
tot_bid += mats[jj].quantity
qty = min(req.target.quantity, self.spent_fuel.quantity)
mat = ts.Material.create_untracked(qty, recipe_comp)
continue

recipe_comp = self.context.get_recipe(self.fuel_outrecipes[commod_index])

for req in reqs:
tot_bid = 0
for jj in range(len(mats)):
tot_bid += mats[jj].quantity
qty = min(req.target.quantity, self.assem_size)
mat = ts.Material.create_untracked(qty, recipe_comp)
for kk in range(self.spent_fuel.count):
Copy link

Choose a reason for hiding this comment

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

Nice refactoring. You may wanna update your for-loop index names.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In what way? How would you suggest updating the index names?

Copy link

Choose a reason for hiding this comment

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

Renaming jj and kk as ii and jj. But leaving it as is is fine too

@abachma2 abachma2 requested review from nsryan2 and smpark7 May 30, 2023 20:40
Copy link

@smpark7 smpark7 left a comment

Choose a reason for hiding this comment

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

LGTM! @nsryan2 go ahead and merge if you approve too.

@nsryan2 nsryan2 merged commit 8338002 into arfc:main May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Comp:Core This issue has to do with the main bulk of the code or document. (methods, main content) Difficulty:2-Challenging This issue may be complex or require specialized skills. Priority:2-Normal This work is important and should be completed ASAP. Status:5-In Review This issue has been handled, and the solution is being reviewed. (probably as a PR) Type:Feature New feature or feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants