-
Notifications
You must be signed in to change notification settings - Fork 609
Add reactivity control to coupled transport-depletion analyses #2693
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
Open
church89
wants to merge
86
commits into
openmc-dev:develop
Choose a base branch
from
openmsr:batchwise_pr
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+572
−1
Open
Changes from all commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
41653f0
first commit to new branch
church89 1d3f0ca
batchwise first commits
church89 f561da1
update unit test
church89 652df2b
add test unit
church89 c08b762
unit test update
church89 7b27002
further improvements to the module
church89 0910bf2
add unit and regression tests
church89 2cd774e
Merge pull request #10 from openmc-dev/develop
church89 562baad
add missing docstrings
church89 7643aaf
remove unused import
church89 1777cee
add missing returns
church89 6eb6651
fix typo
church89 42b8e3d
Merge pull request #11 from openmc-dev/develop
church89 2d48f17
prevent to openmc batchwise_root when to there
church89 d56fb98
Apply suggestions from code review
church89 5e2023a
address comments by @drewejohnson
church89 4a2788e
fix some docstrings
church89 3110e45
reformatted with black
church89 a4f1f16
refactoring of _search_for_keff method
church89 0c804dd
fix some spelling typos
church89 38ed171
first commit to new branch
church89 cea8801
resolve conflicts
church89 7138d2d
update unit test
church89 872fa81
add test unit
church89 c16bece
unit test update
church89 643a75f
further improvements to the module
church89 94abad5
add unit and regression tests
church89 688631c
add missing docstrings
church89 325969f
remove unused import
church89 5d6e991
add missing returns
church89 85a1f35
fix typo
church89 d69a8a8
prevent to openmc batchwise_root when to there
church89 13ee2e3
Apply suggestions from code review
church89 1731fda
address comments by @drewejohnson
church89 e8c36f6
fix some docstrings
church89 e4c0ad2
reformatted with black
church89 f1213a4
refactoring of _search_for_keff method
church89 12a988d
fix some spelling typos
church89 ad8c7ed
fix conflicts
church89 ef4fe68
missing underscore
church89 1aad455
add batchwise get method and update unit test
church89 f3dfdf8
Apply suggestions from code review
church89 9d6c5be
address comments by @drewejohnson
church89 a4b44ed
address more comments by @drewejohnson
church89 0a2933c
replaced batchwise nomenclature with reactivity_control one
church89 0ccc75a
update regression reference result files
church89 da184bb
few fixes
church89 64543ff
fix unit test failing
church89 9328e5b
explicit path argument in SIIntegrator step result save method, since…
church89 a4731ab
add reactivity control restarting condition to integrator class
church89 49191d4
Merge branch 'develop' into batchwise_pr
church89 ee13d16
remove unused index argumnet in restart method to comply with latest …
church89 12a1e70
make sure cell attribute vector maintain initial coordinates
church89 f67b231
make sure bracket type is an array and apply black code style
church89 06366b5
fix failing regression test
church89 fbf91c4
update reference result files
church89 21e1ac6
change warning message
church89 6ad6ea0
restore check conditions in adaptive search_for_keff routine
church89 efc1f61
made ReactivityControllers settable through the integrator
church89 75ca1f2
Merge pull request #31 from openmsr/reactivity_control
church89 d2fa7a0
extend use of paramteric geometry to lattice and not only universe
church89 7583f78
implement suggested changes to reactivity control classes
church89 fa13a81
update tests
church89 c3a6705
Merge pull request #32 from openmsr/reactivity_control_abstrac
church89 e7c15cf
add forgotten argument to StepResult save method
church89 4f988cf
Merge remote-tracking branch 'openmsr/add_path_to_step_res' into batc…
church89 f576e87
Merge branch 'develop' into batchwise_pr
church89 3ed3071
Merge pull request #44 from openmc-dev/develop
church89 8d7ac63
Merge branch 'develop' of https://github.com/openmc-dev/openmc into o…
church89 47f7a12
Merge branch 'openmc-dev-develop' into batchwise_pr
church89 dc40d18
add lost docstring
church89 3e9733b
refactoring of reactivity control
church89 17f10c4
remove obsolete bits and update unit test
church89 5737c39
minor fix
church89 22b1fe2
minor fix
church89 1258e26
Merge pull request #54 from openmsr/batchwise_pr_keff_search_update
church89 4c512ad
addressing Paul's comments
church89 76b5ab4
add renamed files
church89 c2c0a6e
add updated result files
church89 e5188d2
add forgotten docstring
church89 e9ea747
fix update vec logic
church89 1fd1ad7
make keff_search control class private
church89 48dc319
update unit test
church89 fcb0d3d
update test results
church89 eb9dcac
update regression tests
church89 0a10fe3
fix bug
church89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| import openmc.lib | ||
| from openmc.mpi import comm | ||
| from typing import Callable | ||
| from warnings import warn | ||
|
|
||
| class _KeffSearchControl: | ||
| """Controller for keff search during depletion calculations. | ||
|
|
||
| This class performs keff searches to maintain a target keff by adjusting | ||
| a model parameter through a provided function. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| operator : openmc.deplete.Operator | ||
| Depletion operator instance | ||
| function : Callable | ||
| Function that modifies the model based on a parameter value | ||
| x0 : float | ||
| Initial lower bound for the keff search | ||
| x1 : float | ||
| Initial upper bound for the keff search | ||
| bracket : list[float] | ||
| Absolute bracketing interval lower and upper | ||
| if keff search solution lies off these limits the closest | ||
| limit will be set as new result. | ||
| search_kwargs : dict, optional | ||
| Additional keyword arguments to pass to `model.keff_search` | ||
| """ | ||
| def __init__(self, operator, function: Callable, x0: float, x1: float, bracket: list[float], **search_kwargs): | ||
| if len(bracket) != 2: | ||
| raise ValueError(f"bracket must have exactly 2 elements, got {len(bracket)}") | ||
| if bracket[0] >= bracket[1]: | ||
| raise ValueError(f"bracket[0] must be < bracket[1], got {bracket}") | ||
| self.x0 = x0 | ||
| self.x1 = x1 | ||
| self.operator = operator | ||
| self.function = function | ||
| self.search_kwargs = search_kwargs | ||
| self.search_kwargs['x_min'] = bracket[0] | ||
| self.search_kwargs['x_max'] = bracket[1] | ||
|
|
||
| def search_for_keff(self, x, step_index): | ||
| """Perform keff search and update the atom density vector. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| x : list of numpy.ndarray | ||
| Current atom density vector (atoms per material) | ||
| step_index : int | ||
| Current depletion step index | ||
|
|
||
| Returns | ||
| ------- | ||
| x : list of numpy.ndarray | ||
| Updated atom density vector | ||
| root : float | ||
| Parameter value that achieves target keff | ||
| """ | ||
| root = self._search_for_keff() | ||
| x = self._update_vec(x) | ||
| return x, root | ||
|
|
||
| def _search_for_keff(self) -> float: | ||
| """Perform the keff search using the model's keff_search method. | ||
|
|
||
| Returns | ||
| ------- | ||
| float | ||
| Parameter value that achieves target keff | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError | ||
| If the keff search fails to converge | ||
| """ | ||
| with openmc.lib.TemporarySession(model=self.operator.model) as session: | ||
| # Only pass the first 3 required args plus explicitly provided kwargs | ||
| result = self.operator.model.keff_search( | ||
| self.function, | ||
| self.x0, | ||
| self.x1, | ||
| **self.search_kwargs | ||
| ) | ||
| if not result.converged: | ||
| raise ValueError( | ||
| f"Search for keff failed to converge. " | ||
| f"Termination reason: {result.flag}" | ||
| ) | ||
|
|
||
| root = result.root | ||
|
|
||
| # Check if root is outside the bracket bounds and give a warning | ||
| if root < self.search_kwargs['x_min']: | ||
| warn( | ||
| f"keff search result ({root:.6f}) is below the lower bracket bound " | ||
| f"({self.search_kwargs['x_min']:.6f}). Clamping to bracket lower bound.", | ||
| UserWarning | ||
| ) | ||
|
|
||
| elif root > self.search_kwargs['x_max']: | ||
| warn( | ||
| f"keff search result ({root:.6f}) is above the upper bracket bound " | ||
| f"({self.search_kwargs['x_max']:.6f}). Clamping to bracket upper bound.", | ||
| UserWarning | ||
| ) | ||
|
|
||
| #restore the number of initial batches | ||
| openmc.lib.settings.set_batches(self.operator.model.settings.batches) | ||
|
|
||
| return root | ||
|
|
||
| def _update_vec(self, x): | ||
| """Update the atom density vector from openmc.lib.materials and AtomNumber object. | ||
|
|
||
| This method synchronizes the atom densities across all MPI ranks by | ||
| broadcasting the number object from each rank and updating the x vector | ||
| with the current atom densities from openmc.lib.materials or AtomNumber object | ||
| if the nuclide is not in openmc.lib.materials. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| x : list of numpy.ndarray | ||
| Atom density vector to update (atoms per material) | ||
|
|
||
| Returns | ||
| ------- | ||
| list of numpy.ndarray | ||
| Updated atom density vector synchronized across all ranks | ||
| """ | ||
| for rank in range(comm.size): | ||
| number_i = comm.bcast(self.operator.number, root=rank) | ||
|
|
||
| for mat_idx, mat in enumerate(number_i.materials): | ||
| for nuc in number_i.nuclides: | ||
| if nuc in number_i.burnable_nuclides: | ||
| nuc_idx = number_i.burnable_nuclides.index(nuc) | ||
| volume = number_i.get_mat_volume(mat) # cm^3 | ||
| if nuc in openmc.lib.materials[int(mat)].nuclides: | ||
| _nuc_idx = openmc.lib.materials[int(mat)].nuclides.index(nuc) | ||
| val = 1.0e24 * openmc.lib.materials[int(mat)].densities[_nuc_idx] # atom/cm^3 | ||
| else: | ||
| val = number_i.get_atom_density(mat, nuc) # atom/cm^3 | ||
| x[mat_idx][nuc_idx] = val * volume | ||
|
|
||
| x = comm.bcast(x, root=rank) | ||
| return x | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the density change is being made through
openmc.lib, wouldn't this end up resetting the densities to what they were before sinceoperator.numberdoesn't get updated?