Skip to content

Material refactor plus integration tests#17

Merged
shawest merged 8 commits intoshawest:masterfrom
mpiercy827:material-refactor-plus-integration-tests
Feb 12, 2026
Merged

Material refactor plus integration tests#17
shawest merged 8 commits intoshawest:masterfrom
mpiercy827:material-refactor-plus-integration-tests

Conversation

@mpiercy827
Copy link
Contributor

@mpiercy827 mpiercy827 commented Feb 2, 2026

This pull request factors material-related code (including the calculation of stopping powers) into its own neucbot/material.py file, and also adds integration tests to ensure that any change in functionality does not impact the expected output of neucBOT.

More details can be found in the commit messages.

This pull request moves functionality for creating materials and
calculating stopping power into neucbot/material.py. As part of this
refactoring, the stopping power calculations now use binary search
(using bisect.bisect) rather than sequential search for faster
computations on average (logarithmic time rather than linear time).
As some of the implementation details for neucBOT change under the hood
(e.g. the use of binary search rather than sequential searching), there
needs to be a comprehensive way beyond unit tests to ensure that no
regressions are introduced.

To do this, outputs files were generated for the following three
commands on the current master branch:

$ python3 ./neucbot.py -m Materials/Acrylic.dat -c Chains/Th232Chain.dat
$ python3 ./neucbot.py -m Materials/Acrylic.dat -l AlphaLists/Rn220Alphas.dat
$ python3 ./neucbot.py -m Materials/Acrylic.dat -l AlphaLists/Bi212Alphas.dat

These output files will serve as integration tests. As more neucBOT
refactoring and enhancements occur, they should not change the expected
outputs of these commands. In a subsequent commit, these tests will be
required to pass in all Github PRs before merging.
@mpiercy827 mpiercy827 force-pushed the material-refactor-plus-integration-tests branch from 88869a4 to 8cc6c75 Compare February 2, 2026 17:12
The stopping power calculation for a material at a given alpha energy
level was incorrectly copied/modified when being moved from neucbot.py
to neucbot/material.py, and this was caught by the integration tests
added in an earlier commit.

The unit tests have been modified accordingly and the integration tests
are almost passing, they are off by ~1e-16.
The commit populates stopping power lists when a MaterialComposition is
created so that they don't have to be recreated/recalculated for every
alpha energy step (which is the current implementation).
This commit normalizes the abundance of an isotope between 0 and 1 in the
element.abundance() function, and ensures that isotope fractions in a
MaterialComposition object are also between 0 and 1.

The only diffs present in the integration tests at this point are due to
floating point precision limitations and can likely be ignored.
@mpiercy827 mpiercy827 marked this pull request as ready for review February 4, 2026 19:06
@shawest shawest merged commit 8955f68 into shawest:master Feb 12, 2026
1 check passed
@mpiercy827 mpiercy827 deleted the material-refactor-plus-integration-tests branch February 13, 2026 00:01
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.

2 participants