Commit graph

25 commits

Author SHA1 Message Date
Paul Romano
c4a75f7062
Ensure that Model.run() works when specifying a custom XML path (#2889) 2024-03-11 22:35:32 -05:00
Paul Romano
85c963e223
Move 'import lxml' to third-party block of imports (#2803) 2023-12-13 14:11:32 +00:00
Patrick Myers
1cb22075ef
Changed xml to lxml (#2489) 2023-05-09 10:41:04 -05:00
josh
3c7483becb Add a simple unittest for the FissionYield deepcopy 2022-09-08 02:08:18 +00:00
Paul Romano
5e8c7a55fe Provide better error message if missing FPY parent is not in chain 2020-06-17 07:08:49 -05:00
Paul Romano
ff58c199b1 Add test for borrowing FPY, update documentation 2020-06-16 22:32:40 -05:00
Andrew Johnson
3669709061
Apply suggestions from code review
* Use set operations (|=) rather than in-place methods (update)
* Remove second arguments to some asserts in Chain.reduce testing

Co-Authored-By: Paul Romano <paul.k.romano@gmail.com>
2020-03-25 07:01:42 -04:00
Andrew Johnson
2c2d9d7f31
Provide FissionYieldDistribution.restrict_products 2020-03-21 09:00:42 -04:00
Andrew Johnson
2854b3a3a0
Disallow numpy ufuncs being applied directly to FissionYields
Set ``__array_ufunc__`` to ``None`` to ensure that numpy floats respect
__rmul__ and __radd__ for fission yields. Allows weights to be left
or right multiplied as numpy floats, which can be computed during
fission yield weighting. A unit test has been added to ensure this
behavior is preserved

Closes #1492
2020-02-25 10:00:13 -05:00
Andrew Johnson
91c08ef323
Improve/expand special methods for FissionYield
Remove copy method.

__contains__ and __getitem__ now take advantage of the
ordering of products. This can improve time searching
for fission products and retrieving yields.

radd and rmul methods defer to their left counterparts, e.g.
x * fy => fy * x. Return NotImplemented types if addition is
not done with another set of fission yields and multiplication
is not done with a scalar.

Improve/expand special methods for FissionYield

Remove copy method.

__contains__ and __getitem__ now take advantage of the
ordering of products. This can improve time searching
for fission products and retrieving yields.

radd and rmul methods defer to their left counterparts, e.g.
x * fy => fy * x. Return NotImplemented types if addition is
not done with another set of fission yields and multiplication
is not done with a scalar.
2019-08-23 08:32:32 -05:00
Andrew Johnson
4f46aa895c
Teach deplete.Nuclide.validate about new fission yields
Reconfigure tests/unit_tests/test_deplete_chain.py and
tests/unit_tests/test_deplete_nuclide.py to use the new
dictionary-like representation of fission yields.
2019-08-21 17:46:51 -05:00
Andrew Johnson
93d68a24df
Merge branch 'develop' into chain-fission-yields 2019-08-21 17:32:14 -05:00
Andrew Johnson
60f89794f6
Use dictionary to create FissionYieldDistribution
Removes the FissionYieldDistribution.from_dict method as the
most natural way to create such a distribution is with a dictionary.
2019-08-21 10:58:25 -05:00
Andrew Johnson
f977962113
Support passing nuclide name to Nuclide objects
Allow the creation of a Nuclide with
>>> n = Nuclide("U235")
2019-08-21 10:44:28 -05:00
Andrew Johnson
b19a2db0ee
Respond to reviewer comments on FY helpers
- Change Operator attribute name for fission yield helper
- Use copy.deepcopy for constant_yields, fast_yields, and thermal_yields
- Change import location of openmc in tests
- Use bisect.bisect_left to find replacement fission yields on
  FissionYieldCutoffHelper if thermal or fast energies not found
2019-08-21 10:24:09 -05:00
Andrew Johnson
2aa1849eda
Apply suggestions from code review
Co-Authored-By: Paul Romano <paul.k.romano@gmail.com>
2019-08-21 08:46:55 -05:00
Andrew Johnson
32f3c27cf6
Add minor changes from code review to deplete.Nuclide.validate 2019-08-19 10:07:20 -05:00
Andrew Johnson
f2fa86fd52
Delegate Nuclide yield properties to FissionYieldDistribution
For consistency across the various fission yield helpers, the
Nuclide object now sets the yield data to always be a
FissionYieldDistribution or an empty dictionary.
Nuclide.yield_energies is now a property that returns the
energies from the FissionYieldDistribution.

When setting the yield_data, the Nuclide enforces the object
to be a Mapping instance. If the incoming yield_data is a
FissionYieldDistribution, no conversions are made. Otherwise,
a new distribution is created with the from_dict method.

The Chain.from_xml method now creates the yield_data for
nuclides using FissionYieldDistribution.from_dict

Changes were made to some unit tests that attempted to set
the yield_energies, which do not have a setter.
2019-08-14 16:10:05 -05:00
Andrew Johnson
ec7af8f376
Add validation for deplete.Nuclide branching ratios, fission yields
Method Nuclide.validate traverses over decay mode and reaction lists,
as well as all fission yield data to check for inconsistencies.
The following checks are performed:

1) For all non-fission reactions and decay modes, do the sum of
   branching ratios equal about 1?
2) For fission reactions, do the sum of fission yield
   fractions equal about 2?

Users are allowed to supply three control arguments:
- strict: bool that controls if errors are raised [True] or
warnings [False]
- quiet: bool that controls if warnings are printed [False] or
supressed [True]
- tolerance: float that provides some wiggle room on the comparisons
``y - tol <= x <= y + tol``

The method returns a boolean if 1) no inconsistencies were found and
strict evaluates to True, 2) strict evaluates to False regardless of
quiet. If ``strict`` evaluates to False and ``quiet``
evaluates to True, the method will return at the first inconsistency.

No type checking is done because this will potentially be called
by ``openmc.deplete.Chain`` for many nuclides as the primary
entry point. Type and value checking will be done there.

A unit test was added that creates a valid nuclide, and then
strategically invalidates it to check for the various exceptions
and error messages.
2019-08-08 16:06:43 -05:00
Andrew Johnson
27f2c6b15f
Guard against divide by zero in fission yield helper
Create an empty matrix to fit energy-dependent fission
rates for [materials, energies, nuclides].
Use the nonzero method on total fission rate to find
indicies along the first and last axis for non-zero total
fission rate. Populate corresponding fractional fission
rates by dividing group fission rates by total fission rate,
using the indices for materials and nuclides with non-zero
total fission rate.

Use numpy.where to find where total fission rate is zero,
and directly set these locations to zero in the final
result matrix.

Also clean up some lint in openmc.deplete.nuclide related to
old variable names and unused imports.
2019-08-08 08:14:27 -05:00
Andrew Johnson
8cd71be864
Store depletion fission yields with common yield matrix
Add two new classes for working with fission yield data
on the Chain. The primary class is FissionYieldDistribution.
This class stores distributions for one nuclide with
potentially many energies, with the assumption that the
products don't change __too__ much across energy.
Looking at the CASL chain and one generated by ENDF data,
this appears to be the case. Most distributions are
"full" in the sense that energies produce the same products.
There are some cases where one or two products may not
exist for a given energy.

The FissionYieldDistribution retains a dictionary-like behavior,
e.g. d[0.0253]["Xe135"] is a valid command and returns the
yield for Xe-135 at a "thermal" spectrum, due to yields provided
at 0.0253 eV. This is done with a helper class, _FissionYield,
implemented first to support this behavior, but also to
allow vector-operations in combining fission yields.

These _FissionYield objects store the same product vector and
a view into the underlying yield_matrix for a single energy.
To support simple weighting of yields, the __mull__ and
__iadd__ methods are implemented. A copy method is provided
to remove the chance of modifying the original yield data.

test_deplete_chain and test_deplete_nuclide have been modified
in order to utilize these classes, without ruining the validity
of the tests. Tests for the view / copy methods and vector
operations on _FissionYield objects are included.
2019-08-07 19:54:49 -05:00
Paul Romano
236e7f8b9e Add format spec for depletion chain XML file 2018-02-20 00:05:53 -06:00
Paul Romano
dba919c610 Convert deplete unit tests to use pytest 2018-02-14 11:24:24 -06:00
Paul Romano
43147b70eb Change xml_write -> export_to_xml, xml_read -> from_xml for consistency 2018-02-14 10:17:30 -06:00
Paul Romano
8549f22e14 Move depletion tests into normal regression/unit test directories 2018-02-13 15:08:05 -06:00
Renamed from tests/deplete_tests/test_nuclide.py (Browse further)