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

TransferRates (old msr continuous capabilities) #2358

Merged
merged 178 commits into from Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
4fa3ea2
first commit to v13.1 of msr_continuous
church89 Sep 15, 2022
338bc81
improved readability
church89 Sep 15, 2022
261f411
made msr optional in form_matrix function
church89 Sep 15, 2022
2381f7f
improved msr structure for readability
church89 Sep 15, 2022
d6fa940
improved msr structure for readability
church89 Sep 15, 2022
7b4b2e2
improved msr structure for readability
church89 Sep 15, 2022
5ecc88a
first commit
church89 Sep 15, 2022
dd25257
improve readablity
church89 Sep 16, 2022
c7feba9
small fix
church89 Sep 19, 2022
1c7d1be
wrapping msr_continuous implementation for testing in the new realease
church89 Sep 19, 2022
481d344
.
church89 Sep 20, 2022
994bba1
.
church89 Sep 20, 2022
72de96b
fix order of msr arguments in funcs
church89 Sep 22, 2022
c351c6f
introduce make_transfer_matrix function to create transfer matrices t…
church89 Sep 22, 2022
81f5b05
fix attributes
church89 Sep 22, 2022
b81ab55
made new call to chain.py form_transfer_matrix
church89 Sep 22, 2022
555635f
removed diag_matrix in form_matrix function
church89 Sep 22, 2022
ee0651a
small fixes
church89 Sep 23, 2022
0797d50
add internal functions and add descriptions
church89 Sep 27, 2022
645b1d2
change structure of the code for readability
church89 Sep 27, 2022
2a1c3ab
simplified transform_matrix function and add method description
church89 Sep 27, 2022
0f37a72
add doc
church89 Sep 27, 2022
64ab0f5
better ordering of class functions
church89 Sep 28, 2022
f467e37
.
church89 Oct 3, 2022
5a6b998
first commits to new msr_batchwise branch
church89 Oct 3, 2022
2df1538
split msr_batchwise into 2 classes
church89 Oct 4, 2022
c7ae824
still building new structure
church89 Oct 4, 2022
c21c751
remove inheritance to openmc.operator due to circularity import issues
church89 Oct 4, 2022
8aec93f
add msr.py import
church89 Oct 5, 2022
f61f514
include abc into msr_batchwise parent class
church89 Oct 5, 2022
cc552ec
add initialize geometry in memory function
church89 Oct 5, 2022
5fc5540
add try except to the root_finder algorithm
church89 Oct 5, 2022
a143aff
add void function openmc_initialize_geometry()
church89 Oct 5, 2022
726c081
add openmc_initialize_geometry()
church89 Oct 5, 2022
24a4708
change msr_bw function name
church89 Oct 5, 2022
7148d90
update nomenclature
church89 Oct 5, 2022
f33a31c
fix msr_bw_geom
church89 Oct 5, 2022
7b743e5
remove output
church89 Oct 6, 2022
02bc8e9
fixed search method
church89 Oct 6, 2022
8f4f7f7
print debug
church89 Oct 7, 2022
a76b1f0
uncomment _set_geom_coeff() at the end of the searchforkeff
church89 Oct 7, 2022
2e92ae5
fix _material_critical_update
church89 Oct 10, 2022
90ae929
fix geometry re-initialization after geom critical control step
church89 Oct 10, 2022
77cfa91
fix print output argment with new run_args
church89 Oct 10, 2022
a41f919
fix paramters
church89 Oct 10, 2022
ae55211
added function descriptions and fix some namings
church89 Oct 13, 2022
1c38486
added msr arguments and attributes description and remove isinstance …
church89 Oct 13, 2022
5d0a1c5
Merge pull request #3 from openmsr/msr_batchwise_internal
church89 Oct 13, 2022
6c8a41f
fixed msr arguments description and add proper msr call function to t…
church89 Oct 13, 2022
a3d6ba4
fixed some arguments and attributes description
church89 Oct 13, 2022
6529297
replaced model.run with openmc.run for reading xml files (waiting to …
church89 Oct 13, 2022
d1471cf
keep modifying methods description
church89 Oct 14, 2022
3976f25
batchwise geom fully in memory
church89 Oct 18, 2022
495d46a
restoring
church89 Oct 18, 2022
5d6ef97
batchwise geom fully in memory
church89 Oct 18, 2022
6baadcb
change some namings and minor fixes
church89 Oct 20, 2022
3a2db25
moved _msr_search_for_keff to base class, implement adaptive bracket …
church89 Oct 20, 2022
a332da9
restore to develop branch
church89 Oct 21, 2022
df92f84
add some @properties and openmc.checkvalue checks
church89 Oct 21, 2022
cbccbde
take only positive nuclide values in msrBatchWiseMat _model_builder
church89 Oct 24, 2022
c5bec11
restoring to main:branch
church89 Oct 24, 2022
a79258d
implement erik comment on msr cont
church89 Oct 24, 2022
59f8416
implement Erik's comment on removal rates subtraction from bateman ma…
church89 Oct 25, 2022
3d83166
Merge pull request #4 from openmsr/msr_cont_trans_matrix_sub
church89 Oct 25, 2022
9a76e2d
update doc and mod res calculation in _msr_search_for_keff func
church89 Oct 27, 2022
be419b5
removed msr arguments, not needed anymore
church89 Oct 27, 2022
1a933e5
removed msr import, not needed anymore
church89 Oct 27, 2022
ff2011a
add doc description and some checks
church89 Oct 27, 2022
9d09a26
fixed some docs and inverted argument order in _timed_deplete fun
church89 Oct 28, 2022
8d88048
fixed some docs
church89 Oct 28, 2022
28a2a09
fixed some docs
church89 Oct 28, 2022
a72a750
removed not needed import
church89 Oct 28, 2022
46cbb20
removed unused argument from MsrCont
church89 Oct 28, 2022
0697455
yet other changes to the nuclides update function: _conc_dict is remo…
church89 Oct 31, 2022
78557e7
fixed a python warning and removed unused printing
church89 Nov 1, 2022
90a0d6b
moved step_index check in __msr_critical_update function to msr clas …
church89 Nov 1, 2022
36dbe85
moved step_index check in __msr_critical_update function to msr clas …
church89 Nov 1, 2022
558eb2d
Merge pull request #5 from openmsr/msr_internal
church89 Nov 1, 2022
938c339
add docstring to _save_res
church89 Nov 1, 2022
2eb2736
restore to main: removed printing line
church89 Nov 1, 2022
ad6dff7
removed volume renormalization, not needed here
church89 Nov 1, 2022
bda9441
fixed get_id dest_mat order on set_removal_rate func and fixed a check
church89 Nov 2, 2022
eb4a254
removed forgotten printing
church89 Nov 2, 2022
4bc7a38
add missing docstring
church89 Nov 2, 2022
df50386
Merge branch 'openmc-dev:develop' into msr_13.2
church89 Nov 4, 2022
644d407
fix error in MsrBatchwiseMat _model_builder func
church89 Nov 8, 2022
028dec3
Removed msr batchwise class
church89 Nov 23, 2022
4f49891
Removed msr batchwise capabilities
church89 Nov 23, 2022
0de058d
restored
church89 Nov 23, 2022
9d706b0
removed reference to msr batchwise
church89 Nov 23, 2022
283201f
added missing NUM_PROCESSES variable
church89 Nov 23, 2022
fb67aca
Update openmc/deplete/chain.py
church89 Jan 24, 2023
3fd22cb
Update openmc/deplete/chain.py
church89 Jan 24, 2023
75525ed
Update openmc/deplete/msr.py
church89 Jan 24, 2023
3d015e9
Update openmc/deplete/msr.py
church89 Jan 24, 2023
fa81909
Update openmc/deplete/msr.py
church89 Jan 24, 2023
f3c4126
Update openmc/deplete/msr.py
church89 Jan 24, 2023
df2b636
Update openmc/deplete/msr.py
church89 Jan 24, 2023
8808307
Update openmc/deplete/msr.py
church89 Jan 24, 2023
82eba4a
Update openmc/deplete/msr.py
church89 Jan 24, 2023
de76a55
Update openmc/deplete/msr.py
church89 Jan 24, 2023
99d68db
Update openmc/deplete/msr.py
church89 Jan 24, 2023
47e8ca1
Update openmc/deplete/msr.py
church89 Jan 24, 2023
5692ef3
Update openmc/deplete/msr.py
church89 Jan 24, 2023
d4573da
addressing comments from @gridley
church89 Jan 25, 2023
3f86ac0
addressing comments from @gridley
church89 Jan 25, 2023
30e3324
add regression test for deplete msr continuous
church89 Feb 1, 2023
178abe3
add unit test for deplete msr continuous
church89 Feb 1, 2023
e2c7d1e
add missing depletion result reference file
church89 Feb 1, 2023
89b2703
fixed docstrings
church89 Feb 2, 2023
dcdbfe0
Add msr to depletion documentation
church89 Feb 2, 2023
ed1b4ca
Update docs/source/methods/depletion.rst
church89 Feb 17, 2023
9476e08
Update docs/source/methods/depletion.rst
church89 Feb 17, 2023
077b996
Update docs/source/methods/depletion.rst
church89 Feb 17, 2023
9037c9e
Update docs/source/usersguide/depletion.rst
church89 Feb 17, 2023
b3ff200
Update docs/source/usersguide/depletion.rst
church89 Feb 17, 2023
b6afaf3
Update docs/source/usersguide/depletion.rst
church89 Feb 17, 2023
a8b91db
Update docs/source/usersguide/depletion.rst
church89 Feb 17, 2023
46dafde
Update docs/source/pythonapi/deplete.rst
church89 Feb 17, 2023
97d12fd
address @yardasol comments
church89 Feb 17, 2023
4f03e71
Apply suggestions from code review
church89 Feb 20, 2023
2d3b692
Apply suggestions from code review
church89 Feb 20, 2023
d674143
reformulate epsilon and lambda definitions
church89 Feb 20, 2023
350314e
address @gridley fix typoscomments
church89 Feb 22, 2023
2109212
Apply suggestions from code review
church89 Feb 24, 2023
02c1bcf
Apply suggestions from code review
church89 Feb 24, 2023
150cb14
Update openmc/deplete/pool.py
church89 Feb 24, 2023
3977299
add feeding rate example in theory section
church89 Feb 24, 2023
e33f0d5
Apply suggestions from code review
church89 Feb 24, 2023
fbf3abe
fix typo
church89 Feb 25, 2023
76a8d11
Apply suggestions from code review
church89 Feb 25, 2023
47c635f
fix indentation
church89 Feb 25, 2023
25b0f16
something wrong with some indentation
church89 Feb 27, 2023
62d7ab3
missing import
church89 Mar 1, 2023
50d3d1a
address @yardasol suggestion of adding more regression tests
church89 Mar 1, 2023
9b56648
remove double loop; adjust comments
yardasol Mar 2, 2023
e853e57
variable name, docstring, and formatting adjustments
yardasol Mar 2, 2023
9bcfec2
remove double for loop; variable name adjustments
yardasol Mar 2, 2023
88dfb08
theory page adjustments
yardasol Mar 2, 2023
9353533
tweak tests
yardasol Mar 2, 2023
dd98f08
update docstring for
yardasol Mar 2, 2023
c3c2982
add version tag
yardasol Mar 2, 2023
c4dd0f2
add units testing
church89 Mar 6, 2023
970c960
address @yardasol comments and add more regressions
church89 Mar 6, 2023
4d0dd8c
removed unused
church89 Mar 6, 2023
992f571
consistency changes in pool.py
yardasol Mar 6, 2023
dec322c
Merge branch 'msr_13.2_cont' into msr_13.2_cont_yardasol
yardasol Mar 6, 2023
4c0a33c
remove trailing colons
yardasol Mar 7, 2023
f61650c
Merge pull request #6 from yardasol/msr_13.2_cont_yardasol
church89 Mar 8, 2023
7662907
fix yardasol tweaks
yardasol Mar 8, 2023
a48751a
Merge pull request #9 from yardasol/msr_13.2_cont_yardasol
church89 Mar 9, 2023
2ee747e
Apply suggestions from code review
church89 Mar 20, 2023
5ff148d
add missing 'self'
church89 Mar 20, 2023
1e2c0cf
switched back to double loop
church89 Mar 20, 2023
85404af
rename variable
church89 Mar 20, 2023
4691571
Apply suggestions from code review
church89 Mar 20, 2023
d1459cb
switched back to double loop
church89 Mar 20, 2023
b0250fc
fix docstrings
church89 Mar 20, 2023
0c9d85e
reduce number of batches during regression tests
church89 Mar 20, 2023
7930cd2
rename MsrContinuous to TransferRates and made consistent everywhere;…
church89 Mar 21, 2023
c343815
add docstring
church89 Mar 22, 2023
20a8c7e
Apply suggestions from code review
church89 Apr 14, 2023
69c7df2
add public method to class
church89 Apr 15, 2023
950a328
make class private
church89 Apr 15, 2023
6d8f1f7
modified tests to comply with private class
church89 Apr 15, 2023
b4d0a6f
prevent transfer_rates to be reinitialized when making more calls and…
church89 Apr 19, 2023
34b9c1c
fix method names
church89 Apr 19, 2023
c6837c3
update docs
church89 Apr 19, 2023
d36836e
resolve conflict with new argument
church89 Apr 22, 2023
98a96b3
Merge branch 'develop' into msr_13.2_cont
church89 Apr 22, 2023
d30a0d1
Apply suggestions from code review
church89 Apr 25, 2023
0f4787c
address comments from @gridley review
church89 Apr 25, 2023
bf80c03
Apply suggestions from code review
church89 Apr 25, 2023
d06bed4
Apply suggestions from code review
church89 Apr 26, 2023
18fa051
Update tests/regression_tests/deplete_with_transfer_rates/test.py
church89 Apr 26, 2023
ebd2166
Apply suggestions from code review
church89 Apr 27, 2023
0c51d72
Update docs/source/methods/depletion.rst
church89 Apr 27, 2023
d748eec
address @yardasol comment
church89 Apr 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 82 additions & 0 deletions docs/source/methods/depletion.rst
Expand Up @@ -257,3 +257,85 @@ choose one of two methods for estimating the heating rate, including:

The method for normalization can be chosen through the ``normalization_mode``
argument to the :class:`openmc.deplete.CoupledOperator` class.

--------------
Transfer Rates
--------------

OpenMC allows continuous removal or feed of nuclides by adding an
extra transfer rate term to the depletion matrix. An application of this feature
is the chemical processing of Molten Salt Reactors (MSRs), where one can
model the removal of fission products or feeding fresh fuel into the system.

A transfer rate as defined here is the rate at which nuclides are
continuously removed/fed from/to a material.

.. note::

A transfer rate can be positive or negative, indicating removal or feed
respectively.

Mathematically, it can be thought of as an additional term :math:`\mathbf{T}`
in the depletion equation that is proportional to the nuclide density, which can be written as:

.. math::

\begin{aligned}\frac{dN_i(t)}{dt} = &\underbrace{\sum\limits_j f_{j\rightarrow i}
\int_0^\infty dE \; \sigma_j (E,t) \phi(E,t) N_j(t) - \int_0^\infty dE \; \sigma_i(E,t)
\phi(E,t) N_i(t)}_\textbf{R} \\
&+ \underbrace{\sum_j \left [ \lambda_{j\rightarrow i} N_j(t) - \lambda_{i\rightarrow j} N_i(t) \right ]}_\textbf{D} \\
&- \underbrace{t_i N_i(t)}_\textbf{T} \end{aligned}

where the reaction term :math:`\mathbf{R}`, the decay term :math:`\mathbf{D}`
and the new transfer term :math:`\mathbf{T}` have been grouped together so that
:math:`\mathbf{A} = \mathbf{R}+\mathbf{D}-\mathbf{T}`.
The transfer rate coefficient :math:`t_i` defines the continuous transfer of the
nuclide :math:`i`, which behaves similar to radioactive decay.
:math:`t_i` can also be defined as the reciprocal of a cycle time
:math:`T_{cyc}`, intended as the time needed to process the whole inventory.
church89 marked this conversation as resolved.
Show resolved Hide resolved

Note that this formulation assumes homogeneous distribution of nuclide
:math:`i` throughout the material.

A more rigorous description of removal rate and its implementation can be found
in the paper by `Hombourger
<https://doi.org/10.1016/j.anucene.2020.107504>`_.

The resulting burnup matrix can be solved with the same integration algorithms
that are used in the absence of the transfer term.

.. note::

If no ``destination_material`` is specified, nuclides that are removed
or fed will not be tracked afterwards.

Coupling materials
------------------

To keep track of removed nuclides or to feed nuclides from one depletable material
to another, the respective depletion equations have to be coupled. This can be
achieved by defining one block matrix, with diagonal blocks corresponding to
depletion matrices :math:`\mathbf{A_{ii}}`, where the index :math:`i` indicates
the depletable material id, and off-diagonal blocks corresponding to inter-material
coupling matrices :math:`\mathbf{T_{ij}}`, positioned so that that the indices :math:`i` and
:math:`j` indicate the nuclides receiving and losing materials, respectively.
The nuclide vectors are assembled together in one single vector and the resulting
system is solved with the same integration algorithms seen before.

As an example, consider the case of two depletable materials and one
transfer defined from material 1 to material 2. The final system will look like:

.. math::

\begin{aligned}\frac{d}{dt}\begin{pmatrix}\vec{N_1}\\ \vec{N_2}\end{pmatrix} &=
\begin{pmatrix}\mathbf{A_{11}} & \mathbf{0}\\ \mathbf{T_{21}} & \mathbf{A_{22 }}
\end{pmatrix} \begin{pmatrix}\vec{N_1}\\ \vec{N_2}\end{pmatrix} \end{aligned}
gridley marked this conversation as resolved.
Show resolved Hide resolved

where:

:math:`\mathbf{A_{11}} = \mathbf{R_{11}}+\mathbf{D_{11}}-\mathbf{T_{21}}`, and

:math:`\mathbf{A_{22}} = \mathbf{R_{22}}+\mathbf{D_{22}}`.

Note that mass conservation is guaranteed by transferring the number
of atoms directly.
16 changes: 13 additions & 3 deletions docs/source/pythonapi/deplete.rst
Expand Up @@ -54,7 +54,7 @@ provides the following transport operator classes:
IndependentOperator

The :class:`CoupledOperator` and :class:`IndependentOperator` classes must also
have some knowledge of how nuclides transmute and decay. This is handled by the
have some knowledge of how nuclides transmute and decay. This is handled by the
:class:`Chain` class.

Minimal Example
Expand Down Expand Up @@ -195,14 +195,24 @@ total system energy.
helpers.FissionYieldCutoffHelper
helpers.FluxCollapseHelper

The :class:`openmc.deplete.IndependentOperator` uses inner classes subclassed
The :class:`openmc.deplete.IndependentOperator` uses inner classes subclassed
from those listed above to perform similar calculations.

The following classes are used to define transfer rates to model continuous
removal or feed of nuclides during depletion.

.. autosummary::
:toctree: generated
:nosignatures:
:template: myclass.rst

transfer_rates.TransferRates

Intermediate Classes
--------------------

Specific implementations of abstract base classes may utilize some of
the same methods and data structures. These methods and data are stored
the same methods and data structures. These methods and data are stored
in intermediate classes.

Methods common to tally-based implementation of :class:`FissionYieldHelper`
Expand Down
70 changes: 67 additions & 3 deletions docs/source/usersguide/depletion.rst
Expand Up @@ -262,7 +262,7 @@ Loading and Generating Microscopic Cross Sections
-------------------------------------------------

As mentioned earlier, any transport code could be used to calculate one-group
microscopic cross sections. The :mod:`openmc.deplete` module provides the
microscopic cross sections. The :mod:`openmc.deplete` module provides the
:class:`~openmc.deplete.MicroXS` class, which contains methods to read in
pre-calculated cross sections from a ``.csv`` file or from data arrays::

Expand Down Expand Up @@ -355,9 +355,9 @@ Multiple Materials

A transport-independent depletion simulation using ``source-rate`` normalization
will calculate reaction rates for each material independently. This can be
useful for running many different cases of a particular scenario. A
useful for running many different cases of a particular scenario. A
transport-independent depletion simulation using ``fission-q`` normalization
will sum the fission energy values across all materials into :math:`Q_i` in
will sum the fission energy values across all materials into :math:`Q_i` in
Equation :math:numref:`fission-q`, and Equation :math:numref:`fission-q`
provides the flux we use to calculate the reaction rates in each material.
This can be useful for running a scenario with multiple depletable materials
Expand All @@ -370,3 +370,67 @@ The values of the one-group microscopic cross sections passed to
:class:`openmc.deplete.IndependentOperator` are fixed for the entire depletion
simulation. This implicit assumption may produce inaccurate results for certain
scenarios.

Transfer Rates
==============

Transfer rates define removal or feed of nuclides to or from one or more
depletable materials. This can be useful to model continuous fuel reprocessing,
online fission products separation, etc.

Transfer rates are defined by calling the
:meth:`~openmc.deplete.abc.Integrator.add_transfer_rate()` method directly from
one of the Integrator classes::

...
integrator = openmc.deplete.PredictorIntegrator(op, time_steps, power)
integrator.add_transfer_rate(...)

Defining transfer rates
-----------------------

The :meth:`~openmc.deplete.abc.Integrator.add_transfer_rate()` method requires a
:class:`~openmc.Material` instance (alternatively, a material id or
the name) as the depletable material from which nuclides are processed,
a list of elements that share the same transfer rate, and a transfer rate itself.

.. caution::

Make sure you set the transfer rate value with the right sign.
A positive transfer rate assumes removal, while a negative one assumes feed.
church89 marked this conversation as resolved.
Show resolved Hide resolved

The ``transfer_rate_units`` argument specifies the units for the transfer rate.
The default is `1/s`, but '1/min', '1/h', '1/d' and '1/a' are also valid
options.

For example, to define continuous removal of xenon from one material with a
removal rate value of 0.1 s\ :sup:`-1` (or a cycle time of 10 s), you'd use::

mat1 = openmc.Material(material_id=1, name='fuel')

...

integrator = openmc.deplete.PredictorIntegrator(op, time_steps, power)
# by openmc.Material object
integrator.add_transfer_rate(mat1, ['Xe'], 0.1)
# or by material id
integrator.add_transfer_rate(1, ['Xe'], 0.1)
# or by material name
integrator.add_transfer_rate('fuel', ['Xe'], 0.1)

Note that in this case the xenon isotopes that are removed will not be tracked.

Defining a destination material
-------------------------------

To transfer elements from one depletable material to another, the
``destination_material`` parameter needs to be passed to the
:meth:`~openmc.deplete.abc.Integrator.add_transfer_rate()` method. For example,
to transfer xenon from one material to another, you'd use::

...
mat2 = openmc.Material(name='storage')

...

integrator.add_transfer_rate(mat1, ['Xe'], 0.1, destination_material=mat2)
1 change: 1 addition & 0 deletions openmc/deplete/__init__.py
Expand Up @@ -16,6 +16,7 @@
from .stepresult import *
from .results import *
from .integrators import *
from .transfer_rates import *
from . import abc
from . import cram
from . import helpers
37 changes: 34 additions & 3 deletions openmc/deplete/abc.py
Expand Up @@ -24,6 +24,7 @@
from .chain import Chain
from .results import Results
from .pool import deplete
from .transfer_rates import TransferRates


__all__ = [
Expand Down Expand Up @@ -547,7 +548,6 @@ class Integrator(ABC):
:attr:`solver`.

.. versionadded:: 0.12

Attributes
----------
operator : openmc.deplete.abc.TransportOperator
Expand All @@ -574,7 +574,10 @@ class Integrator(ABC):
* ``n1`` is a :class:`numpy.ndarray` of compositions at the
next time step. Expected to be of the same shape as ``n0``

.. versionadded:: 0.12
transfer_rates : openmc.deplete.TransferRates
Instance of TransferRates class to perform continuous transfer during depletion

.. versionadded:: 0.13.4

"""

Expand Down Expand Up @@ -654,6 +657,8 @@ def __init__(self, operator, timesteps, power=None, power_density=None,
self.timesteps = asarray(seconds)
self.source_rates = asarray(source_rates)

self.transfer_rates = None

if isinstance(solver, str):
# Delay importing of cram module, which requires this file
if solver == "cram48":
Expand Down Expand Up @@ -704,7 +709,8 @@ def solver(self, func):
def _timed_deplete(self, concs, rates, dt, matrix_func=None):
start = time.time()
results = deplete(
self._solver, self.chain, concs, rates, dt, matrix_func)
self._solver, self.chain, concs, rates, dt, matrix_func,
self.transfer_rates)
return time.time() - start, results

@abstractmethod
Expand Down Expand Up @@ -835,6 +841,31 @@ def integrate(self, final_step=True, output=True):

self.operator.finalize()

def add_transfer_rate(self, material, elements, transfer_rate,
transfer_rate_units='1/s', destination_material=None):
"""Add transfer rates to depletable material.

Parameters
----------
material : openmc.Material or str or int
Depletable material
elements : list of str
List of strings of elements that share transfer rate
transfer_rate : float
Rate at which elements are transferred. A positive or negative values
set removal of feed rates, respectively.
destination_material : openmc.Material or str or int, Optional
Destination material to where nuclides get fed.
transfer_rate_units : {'1/s', '1/min', '1/h', '1/d', '1/a'}
Units for values specified in the transfer_rate argument. 's' means
seconds, 'min' means minutes, 'h' means hours, 'a' means Julian years.

"""
if self.transfer_rates is None:
self.transfer_rates = TransferRates(self.operator, self.operator.model)

self.transfer_rates.set_transfer_rate(material, elements, transfer_rate,
transfer_rate_units, destination_material)

@add_params
class SIIntegrator(Integrator):
Expand Down
58 changes: 58 additions & 0 deletions openmc/deplete/chain.py
Expand Up @@ -698,6 +698,64 @@ def form_matrix(self, rates, fission_yields=None):
dict.update(matrix_dok, matrix)
return matrix_dok.tocsr()

def form_rr_term(self, transfer_rates, materials):
"""Function to form the transfer rate term matrices.

.. versionadded:: 0.13.4

Parameters
----------
transfer_rates : openmc.deplete.TransferRates
Instance of openmc.deplete.TransferRates
materials : string or two-tuple of strings
Two cases are possible:

1) Material ID as string:
Nuclide transfer only. In this case the transfer rate terms will be
subtracted from the respective depletion matrix

2) Two-tuple of material IDs as strings:
Nuclide transfer from one material into another.
The pair is assumed to be
``(destination_material, source_material)``, where
``destination_material`` and ``source_material`` are the nuclide
receiving and losing materials, respectively.
The transfer rate terms get placed in the final matrix with indexing
position corresponding to the ID of the materials set.

Returns
church89 marked this conversation as resolved.
Show resolved Hide resolved
-------
scipy.sparse.csr_matrix
Sparse matrix representing transfer term.

"""
matrix = defaultdict(float)

for i, nuclide in enumerate(self.nuclides):
element = re.split(r'\d+', nuclide.name)[0]
# Build transfer terms matrices
if isinstance(materials, str):
material = materials
if element in transfer_rates.get_elements(material):
matrix[i, i] = transfer_rates.get_transfer_rate(material, element)
else:
matrix[i, i] = 0.0
paulromano marked this conversation as resolved.
Show resolved Hide resolved
#Build transfer terms matrices
elif isinstance(materials, tuple):
destination_material, material = materials
if transfer_rates.get_destination_material(material, element) == destination_material:
matrix[i, i] = transfer_rates.get_transfer_rate(material, element)
else:
warn(f'Material {destination_material} is not defined '
f'as a destination material for Material {material}. '
'Setting transfer rate to 0.0')
matrix[i, i] = 0.0
paulromano marked this conversation as resolved.
Show resolved Hide resolved
#Nothing else is allowed
n = len(self)
matrix_dok = sp.dok_matrix((n, n))
dict.update(matrix_dok, matrix)
return matrix_dok.tocsr()

def get_branch_ratios(self, reaction="(n,gamma)"):
"""Return a dictionary with reaction branching ratios

Expand Down