Skip to content

Commit

Permalink
Merge branch 'gpr_implementation'
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschalz committed Jun 14, 2021
2 parents 739a11b + 518183f commit 14d4d73
Show file tree
Hide file tree
Showing 20 changed files with 2,822 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ build
misc
commit_msg
__pycache__

*.egg-info
*.swp
*.json
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,20 @@ FIND_PACKAGE(COIN REQUIRED)
SET(STUB_INCLUDE_DIRS ${STUB_INCLUDE_DIRS} ${COIN_INCLUDE_DIR})
set(LIBS ${LIBS} ${COIN_LIBRARIES})

# Find Python and python.h
FIND_PACKAGE(PythonLibs REQUIRED)
SET(STUB_INCLUDE_DIRS ${STUB_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})

# Find Niels Lohmann's 'JSON for Modern C++' package
FIND_PACKAGE(nlohmann_json REQUIRED)
# The line below does not work!
# For unknown reasons, CMake does not find the include directories
# and nlohmann_json_INCLUDE_DIRS is an unset variable.
SET(STUB_INCLUDE_DIRS ${STUB_INCLUDE_DIRS} ${nlohmann_json_INCLUDE_DIRS})

# include all the directories we just found
INCLUDE_DIRECTORIES(${STUB_INCLUDE_DIRS})


# add the agents
ADD_SUBDIRECTORY(src)

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2020, RWTH Aachen University Nuclear Verification and Disarmament Group
Copyright (c) 2020-2021, RWTH Aachen University Nuclear Verification and Disarmament Group
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
52 changes: 46 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
# misoenrichment: a Cyclus multi component isotope enrichment module

`misoenrichment` is a module developed at the [Nuclear Verification and Disarmament Group](https://www.nvd.rwth-aachen.de/) at RWTH Aachen University for the nuclear fuel cycle simulator
[Cyclus](http://fuelcycle.org). It provides a Cyclus facility that enriches
uranium streams composed of two or more isotopes taking into account the
[Cyclus](http://fuelcycle.org). It currently provides two Cyclus facilities.

`MIsoEnrich` is an enrichment facility that enriches
streams composed of two or more uranium isotopes taking into account the
different enrichment behaviour of minor isotopes such as <sup>234</sup>U (present in
natural as well as in reprocessed uranium) or <sup>236</sup>U (present in
reprocessed uranium from spent nuclear fuel). The tracking of minor
isotopes makes this module suitable for nuclear archaeology, see, e.g., Ref 3.

`GprReactor` is a Cyclus reactor facility that uses Gaussian Process
Regression (GPR) to calculate the composition of the irradiated fuel depending
on various input parameters. Generally, this implementation works for any
reactor type and any input parameters. However, one needs the appropriate
GPR model (which needs to be generated using training data) and depending
on which input parameters are chosen, the source code of `GprReactor` may
need minor tweaking. Additional information on this issue will be given
in future commits.

Table of Contents
- [Getting Started](#getting-started)
- [Theoretical background](#theoretical-background)
- [MIsoEnrich](#misoenrich)
- [Getting Started](#getting-started)
- [Theoretical background](#theoretical-background)
- [GprReactor](#gprreactor)
- [Requirements](#requirements)
- [References](#references)

## Getting started
## MIsoEnrich
### Getting started
An example input file is found in `input/main.py` featuring a
`cycamore::Source` source agent, a `MIsoEnrich` enrichment facility and two
`cycamore::Sink` agents, one for enriched and one for depleted uranium.
Expand All @@ -34,7 +49,7 @@ level, as explained above) and then blending the product with uranium from
the feed. This procedure is only performed if the `use_downblending`
variable is set to `True` in the input file.

## Theoretical background
### Theoretical background
The implementation of the facility itself and the interaction with Cyclus'
Dynamic Resource Exchange is based on the binary enrichment facility from
the [Cycamore](https://github.com/cyclus/cycamore) package.
Expand All @@ -44,6 +59,31 @@ Ref 1 derives the mathematical formalism of a matched abundance ratio cascade
using constant overall stage separation factors while Ref 2 gives a new
physically founded approach to calculating said separation factors.

## GprReactor
### Requirements
This facility needs Niels Lohmann's [JSON for Modern C++](https://json.nlohmann.me/)
library. It can be downloaded from his [GitHub repository](https://github.com/nlohmann/json)
or using one of the many package managers, see [here](https://github.com/nlohmann/json#package-managers).
Successfully tested using `conda install -c conda-forge nlohmann_json` and using `CMake`.
When using `CMake`, then the package needs to be installed globally
(i.e., under `/usr/local`), as shown in the following:
```
$ git clone https://github.com/nlohmann/json
$ cd json
$ mkdir build
$cd build
$ cmake ..
$ make
$ sudo make install
```
While it _should_ be possible to install `JSON for Modern C++` locally,
i.e. in `~/.local`, this results in `CMake` not finding `nlohmann/json.hpp`
during the `misoenrichment` installation. I will hopefully manage to
fix this in future versions.

Additionally, one needs `Python3` in combination with the `NumPy` and
`SciPy` packages.

## References

1. E. von Halle, _Multicomponent Isotope Separation in Matched Abundance
Expand Down
4 changes: 3 additions & 1 deletion input/archetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ def archetypes():
{"lib": "agents", "name": "NullRegion"},
{"lib": "cycamore", "name": "Sink"},
{"lib": "cycamore", "name": "Source"},
{"lib": "misoenrichment", "name":"MIsoEnrich"}
{"lib": "cycamore", "name": "Storage"},
{"lib": "misoenrichment", "name": "GprReactor"},
{"lib": "misoenrichment", "name": "MIsoEnrich"}
]
}}

Expand Down
4 changes: 2 additions & 2 deletions input/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ def control():
d = {"control": {
"startyear": 2020,
"startmonth": 1,
"duration": 12,
"dt": 2629846, # duration of a time step in seconds, here: 1 month
"duration": 365,
"dt": 86400, # duration of a time step in seconds, here: 1 day
"simhandle": "misoenrichment tutorial file",
}
}
Expand Down
35 changes: 29 additions & 6 deletions input/facility.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ def facility():
"config": {"Source": {
"outcommod": "NaturalU",
"outrecipe": "NaturalURecipe",
"throughput": 2000
"throughput": 10000
}}
},
{
"name": "EnrichedUSink",
"name": "SpentFuelSink",
"config": {"Sink": {
"in_commods": {"val": ["EnrichedU"]},
"recipe_name": "EnrichedURecipe"
"in_commods": {"val": ["SpentFuel"]}
}}
},
{
Expand All @@ -22,6 +21,15 @@ def facility():
"recipe_name": "DepletedURecipe"
}}
},
{
"name": "FreshFuelStorage",
"config": {"Storage": {
"in_commods": {"val": ["EnrichedU"]},
"out_commods": {"val": ["FreshFuel"]},
"in_recipe": ["EnrichedURecipe"],
"residence_time": 0
}}
},
{
"name": "EnrichmentFacility",
"config": {"MIsoEnrich": {
Expand All @@ -31,13 +39,28 @@ def facility():
"tails_commod": "DepletedU",
"tails_assay": 0.003,
"initial_feed": 0,
"max_feed_inventory": 10000,
"max_feed_inventory": 1e299,
"gamma_235": 1.35,
"swu_capacity": 1e299,
"swu_capacity_vals": {"val": [1e5, 1000, 2000]},
"swu_capacity_vals": {"val": [1e5, 5e4, 5e5]},
"swu_capacity_times": {"val": [0, 5, 6]},
"use_downblending": True
}}
},
{
"name": "SavannahRiverReactor",
"config": {"GprReactor": {
"in_commods": {"val": ["FreshFuel"]},
"out_commods": {"val": ["SpentFuel"]},
"in_recipes": {"val": ["EnrichedURecipe"]},
"n_assem_core": 1,
"n_assem_batch": 1,
"assem_size": 110820,
"cycle_time": 88,
"refuel_time": 6,
"power_output": 2400,
"temperature": 350
}}
}
]}
return d
10 changes: 6 additions & 4 deletions input/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ def recipe():
"name": "NaturalURecipe",
"basis": "mass",
"nuclide": [
{"id": "U234", "comp": 5.5e-3},
# At the moment (May 2021), U234 is not taken into
# account by the Gpr model.
#{"id": "U234", "comp": 5.5e-3},
{"id": "U235", "comp": 0.711},
{"id": "U238", "comp": 100 - 0.711 - 5.5e-3}
{"id": "U238", "comp": 100 - 0.711}
]
},
{
"name": "EnrichedURecipe",
"basis": "mass",
"nuclide": [
{"id": "U235", "comp": 90},
{"id": "U238", "comp": 10}
{"id": "U235", "comp": 1.1},
{"id": "U238", "comp": 98.9}
]
},
{
Expand Down
5 changes: 5 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def install(args):
root_dir = os.path.split(__file__)[0]
makefile = os.path.join(args.build_dir, 'Makefile')

print("Installing Python (sub)module 'spentfuelgpr'...")
spent_fuel_gpr_dir = os.path.join(root_dir, "spentfuelgpr")
subprocess.check_call(["pip3", "install", "-e", spent_fuel_gpr_dir])
print()

if not os.path.exists(makefile):
rtn = subprocess.call(['which', 'cmake'], shell=(os.name == 'nt'))
if rtn != 0:
Expand Down
Binary file added spentfuelgpr/data/x_trainingset.npy
Binary file not shown.
Binary file added spentfuelgpr/data/y_trainingset_reduced.npy
Binary file not shown.
22 changes: 22 additions & 0 deletions spentfuelgpr/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup

def main():
setup(
name="spentfuelgpr",
version="0.1",
description="Python part of the MIsoEnrichment module",
author="Nuclear Verification and Disarmament Group, RWTH Aachen University",
url="https://github.com/maxschalz/miso_enrichment/",
license="BSD-3-Clause",
packages=["spentfuelgpr"],
classifiers=["License :: OSI Approved :: BSD-3-Clause License",
"Programming Language :: Python :: 3"],
install_requires=["numpy", "scipy"]
)
return

if __name__=="__main__":
main()
24 changes: 24 additions & 0 deletions spentfuelgpr/spentfuelgpr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Calculate the composition of spent fuel based on a set of trained GPRs.
This module is part of the misoenrichment module for Cyclus, see
https://github.com/maxschalz/miso_enrichment/ .
The module is strongly based on Antonio Figueroa's work, who kindly
provided the original code. For more information, please see
https://doi.org/10.1016/j.anucene.2020.108085
or https://arxiv.org/abs/2006.12921
or https://github.com/FigueroaAC/GPs-for-SpentFuel
"""

__author__ = "Nuclear Verification and Disarmament Group, RWTH Aachen University"
__copyright__ = "Copyright 2020-2021, Nuclear Verification and Disarmament Group, RWTH Aachen University"
__credits__ = ["Antonio Figueroa", "Max Schalz"]
__license__ = "BSD-3-Clause"
__version__ = "2.0"
__maintainer__ = "Max Schalz"

from .kernel import *
from .predict_posterior import *
Loading

0 comments on commit 14d4d73

Please sign in to comment.