From 9880684af9231533a8c5adcd17a8566ba5a38e7b Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 13:33:08 +0000 Subject: [PATCH 01/17] added video and corrected indentation --- docs/source/example_material.rst | 80 +++++++++++++++------------ docs/source/example_multimaterial.rst | 8 +-- docs/source/index.rst | 32 +++++++++-- 3 files changed, 77 insertions(+), 43 deletions(-) diff --git a/docs/source/example_material.rst b/docs/source/example_material.rst index 4069afd..14f5efb 100644 --- a/docs/source/example_material.rst +++ b/docs/source/example_material.rst @@ -8,7 +8,7 @@ Here is an example that accesses a material from the internal collection called :: - import neutronics-material-maker as nmm + import neutronics_material_maker as nmm my_mat = nmm.Material('eurofer') @@ -76,6 +76,7 @@ Lithium ceramics used in fusion breeder blankets often contain enriched lithium- my_mat2.openmc_material + The default enrichment target for 'Li4SiO4' is Li6 but this can be changed if required. :: @@ -94,61 +95,70 @@ Usage - make a your own materials Example making materials from elements :: + import neutronics_material_maker as nmm - my_mat = nmm.Material(material_name="li_with_si", - density= 3.0, - density_unit= "g/cm3", - percent_type= "ao", - elements={ - "Li":4, - "Si":2 - } - ) + my_mat = nmm.Material( + material_name="li_with_si", + density= 3.0, + density_unit= "g/cm3", + percent_type= "ao", + elements={ + "Li":4, + "Si":2 + } + ) + Example making materials from isotopes :: + import neutronics_material_maker as nmm - my_mat = nmm.Material(material_name="enriched_li", - density= 3.0, - density_unit= "g/cm3", - percent_type= "ao", - isotopes={ - "Li6":0.9, - "Li7":0.1 - } + my_mat = nmm.Material( + material_name="enriched_li", + density= 3.0, + density_unit= "g/cm3", + percent_type= "ao", + isotopes={ + "Li6":0.9, + "Li7":0.1 + } ) Example making materials from isotopes defined by zaid :: + import neutronics_material_maker as nmm - my_mat = nmm.Material(material_name="enriched_li", - density= 3.0, - density_unit= "g/cm3", - percent_type= "ao", - isotopes={ - "3006":0.9, - "3007":0.1 - } + my_mat = nmm.Material( + material_name="enriched_li", + density= 3.0, + density_unit= "g/cm3", + percent_type= "ao", + isotopes={ + "3006":0.9, + "3007":0.1 + } ) It is also possible to make your own materials directly from a dictionary by making use of the python syntax ** :: + import neutronics_material_maker as nmm - my_dict = { "material_name": "li_with_si", - "elements": { - "Li":4, - "Si":2 - }, - "density": 3.0, - "density_unit": "g/cm3", - "percent_type": "ao", - } + my_dict = { + "material_name": "li_with_si", + "elements": { + "Li":4, + "Si":2 + }, + "density": 3.0, + "density_unit": "g/cm3", + "percent_type": "ao", + } my_mat = nmm.Material(**my_dict) diff --git a/docs/source/example_multimaterial.rst b/docs/source/example_multimaterial.rst index 68dd6f0..2b90542 100644 --- a/docs/source/example_multimaterial.rst +++ b/docs/source/example_multimaterial.rst @@ -13,7 +13,7 @@ Making two materials and mixing them to create a MultiMaterial my_mat1 = nmm.Material('eurofer') my_mat2 = nmm.Material('tungsten') - my_mat3 = MultiMaterial(material_name='mixed_mat', - materials=[my_mat1, my_mat2], - fracs=[0.4, 0.6], - percent_type='vo') + my_mat3 = nmm.MultiMaterial(material_tag='mixed_mat', + materials=[my_mat1, my_mat2], + fracs=[0.4, 0.6], + percent_type='vo') diff --git a/docs/source/index.rst b/docs/source/index.rst index f576238..2d64a69 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -1,13 +1,22 @@ Neutronics Material Maker ========================= -The aim of this project is to facilitate the creation of materials for use in neutronics codes such as OpenMC, Serpent, MCNP and Fispact. +The aim of this project is to facilitate the creation of materials for use in +neutronics codes such as OpenMC, Serpent, MCNP and Fispact. -The hope is that by having this collection of materials it is easier to reuse materials across projects and use a common source with less room for user error. +The hope is that by having this collection of materials it is easier to reuse +materials across projects and use a common source with less room for user +error. -The package allows for materials to be made from either an internal library of materials or from your own material library. +The package allows for materials to be made from either an internal library of +materials or from your own material library. -Material densities can be made to account for temperature, pressure and isotopic enrichment. +Material densities can be made to account for temperature, pressure and +isotopic enrichment. + +.. raw:: html + + .. toctree:: @@ -21,6 +30,21 @@ Material densities can be made to account for temperature, pressure and isotopic example_library_usage +History +------- + +The package was originally created by Jonathan Shimwell as a method of +reducing the effort required to the same materials accross different neutronics +codes. The current version can be considered a materials library and translator +between material types. The original version contained methods of mixing +materials and building materials from chemical equations. These aspects of the +code were moved to OpenMC in code contributions (e.g +`1 `_ and +`2 `_ ) +which reduced the complexity and maintainance burden for the neutronics +material maker and brought on OpenMC as a major dependancy. + + Prerequisites ------------- From 8c3c2b302dce4a63f5099ac0a30ea5af6f66e123 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 13:43:37 +0000 Subject: [PATCH 02/17] added cython to help docs building --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 1421210..b58d58b 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,7 @@ }, tests_require=["pytest-cov", "pytest-runner"], install_requires=[ + "cython", "coolprop", "asteval", # 'openmc' when pip install is available From a47be62c182e975ebe9cc576cf94707d755bf688 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 13:51:02 +0000 Subject: [PATCH 03/17] specify python 3.8 on read the docs build --- docs/source/conf.py | 5 +++++ setup.py | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 5568546..3bc1213 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -28,6 +28,11 @@ # The full version, including alpha/beta/rc tags release = "1.0" +python: + # cool props doesn't support python 3.9 currently + # https://github.com/CoolProp/CoolProp/issues/1981 + version: 3.8 + # -- General configuration --------------------------------------------------- diff --git a/setup.py b/setup.py index b58d58b..1421210 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,6 @@ }, tests_require=["pytest-cov", "pytest-runner"], install_requires=[ - "cython", "coolprop", "asteval", # 'openmc' when pip install is available From cd9b0964e74bb90bad6194a437874ecfbb72a0f1 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Wed, 24 Feb 2021 13:51:35 +0000 Subject: [PATCH 04/17] Automated autopep8 fixes --- docs/source/conf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 3bc1213..de08eee 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -29,9 +29,9 @@ release = "1.0" python: - # cool props doesn't support python 3.9 currently - # https://github.com/CoolProp/CoolProp/issues/1981 - version: 3.8 + # cool props doesn't support python 3.9 currently + # https://github.com/CoolProp/CoolProp/issues/1981 + version: 3.8 # -- General configuration --------------------------------------------------- From ca2fa702aca9ad204ff5f8bbea140917421cdc6e Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 13:58:43 +0000 Subject: [PATCH 05/17] added requirments to read the docs --- docs/source/conf.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 3bc1213..d0ebc20 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -28,11 +28,12 @@ # The full version, including alpha/beta/rc tags release = "1.0" +# cool props doesn't support python 3.9 currently +# https://github.com/CoolProp/CoolProp/issues/1981 python: - # cool props doesn't support python 3.9 currently - # https://github.com/CoolProp/CoolProp/issues/1981 version: 3.8 - + install: + - requirements: requirements.txt # -- General configuration --------------------------------------------------- From d56c8eaafd12bb9b4461ccf851e0f16c1785a03a Mon Sep 17 00:00:00 2001 From: autopep8 Date: Wed, 24 Feb 2021 13:59:54 +0000 Subject: [PATCH 06/17] Automated autopep8 fixes --- docs/source/conf.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index d0ebc20..c840405 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -28,12 +28,12 @@ # The full version, including alpha/beta/rc tags release = "1.0" -# cool props doesn't support python 3.9 currently +# cool props doesn't support python 3.9 currently # https://github.com/CoolProp/CoolProp/issues/1981 python: - version: 3.8 - install: - - requirements: requirements.txt + version: 3.8 + install: + - requirements: requirements.txt # -- General configuration --------------------------------------------------- From 8954087b5f6064a17746c6718fd972729ecd3a25 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 14:04:58 +0000 Subject: [PATCH 07/17] trying python 3.7 --- docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index d0ebc20..dcb2d99 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -31,7 +31,7 @@ # cool props doesn't support python 3.9 currently # https://github.com/CoolProp/CoolProp/issues/1981 python: - version: 3.8 + version: 3.7 install: - requirements: requirements.txt From 4c6d54cec5f5eac417e5d93b713f6ca9a9644a8e Mon Sep 17 00:00:00 2001 From: autopep8 Date: Wed, 24 Feb 2021 14:05:51 +0000 Subject: [PATCH 08/17] Automated autopep8 fixes --- docs/source/conf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 12db4b6..d8c67d2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -31,9 +31,9 @@ # cool props doesn't support python 3.9 currently # https://github.com/CoolProp/CoolProp/issues/1981 python: - version: 3.7 - install: - - requirements: requirements.txt + version: 3.7 + install: + - requirements: requirements.txt # -- General configuration --------------------------------------------------- From aaeb3026a676966c1c9f74c1b9f910343372915c Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 14:12:04 +0000 Subject: [PATCH 09/17] moved python version to conda env --- docs/source/conf.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 12db4b6..91b6a98 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -28,13 +28,6 @@ # The full version, including alpha/beta/rc tags release = "1.0" -# cool props doesn't support python 3.9 currently -# https://github.com/CoolProp/CoolProp/issues/1981 -python: - version: 3.7 - install: - - requirements: requirements.txt - # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. From d411e12f2cedcd6f866f61575bb90715aa781ea9 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 14:19:25 +0000 Subject: [PATCH 10/17] specifying python 3.8; --- readthedocs.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readthedocs.yml b/readthedocs.yml index 9808f9f..26d4682 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -13,10 +13,10 @@ sphinx: # - pdf # this is not needed if using conda environment -# python: -# version: 3.7 -# install: -# - requirements: requirements.txt +python: + version: 3.8 + install: + - requirements: requirements.txt # specify conda environment needed for build conda: From 28df5a576139391960d7f8650aff69c94cb7d671 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 14:25:04 +0000 Subject: [PATCH 11/17] changed to version 2 yml --- readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs.yml b/readthedocs.yml index 26d4682..06daae2 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -2,7 +2,7 @@ # Read the Docs configuration file # Required -version: 1 +version: 2 # Build documentation in the docs/ directory with Sphinx sphinx: From c414a4718350fb19ada2b4968485bbc8d27b1586 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 14:29:02 +0000 Subject: [PATCH 12/17] changed file keyword to environment --- readthedocs.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readthedocs.yml b/readthedocs.yml index 06daae2..64ccba7 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -13,11 +13,11 @@ sphinx: # - pdf # this is not needed if using conda environment -python: - version: 3.8 - install: - - requirements: requirements.txt +# python: +# version: 3.8 +# install: +# - requirements: requirements.txt # specify conda environment needed for build conda: - file: environment.yml \ No newline at end of file + environment: environment.yml From 3f1fd102115c8770cc27b5867c8a8bc00655c43a Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 14:34:28 +0000 Subject: [PATCH 13/17] added python 3.8 to buld section of yml --- readthedocs.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readthedocs.yml b/readthedocs.yml index 64ccba7..1089c92 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -4,6 +4,12 @@ # Required version: 2 +build: + image: latest + +python: + version: 3.8 + # Build documentation in the docs/ directory with Sphinx sphinx: configuration: docs/source/conf.py From e4e08e09002504698f6f88f77dd686d9068f5016 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 14:42:44 +0000 Subject: [PATCH 14/17] added python 3.8 via python section --- readthedocs.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readthedocs.yml b/readthedocs.yml index 1089c92..f143d1d 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -19,10 +19,10 @@ sphinx: # - pdf # this is not needed if using conda environment -# python: -# version: 3.8 -# install: -# - requirements: requirements.txt +python: + version: 3.8 + install: + - requirements: requirements.txt # specify conda environment needed for build conda: From af7372d6ebc493fd897a96884479547921561454 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 14:46:42 +0000 Subject: [PATCH 15/17] removed cool props from conda enviroment --- docs/environment.yml | 7 +++++++ docs/source/index.rst | 22 ++++++++++++++-------- environment.yml | 1 + readthedocs.yml | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 docs/environment.yml diff --git a/docs/environment.yml b/docs/environment.yml new file mode 100644 index 0000000..9088990 --- /dev/null +++ b/docs/environment.yml @@ -0,0 +1,7 @@ +name: docs-environment + +channels: + - conda-forge + +dependencies: + - openmc diff --git a/docs/source/index.rst b/docs/source/index.rst index 2d64a69..71156ab 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -48,7 +48,8 @@ material maker and brought on OpenMC as a major dependancy. Prerequisites ------------- -To use the neutronics-material-maker tool you will need Python 3 and OpenMC installed. +To use the neutronics-material-maker tool you will need Python 3 and OpenMC +installed. * `Python 3 `_ * `OpenMC `_ @@ -58,19 +59,20 @@ To use the neutronics-material-maker tool you will need Python 3 and OpenMC inst Installation ------------ -The recommended method is to install from [Conda Forge](https://conda-forge.org) which also installs all the dependancies including OpenMC. +The recommended method is to install from [Conda Forge](https://conda-forge.org) +which also installs all the dependancies including OpenMC. ``` conda install neutronics_material_maker -c conda-forge ``` -Alternativly the code can be easily installed using pip (which doesn't currently include OpenMC) +Alternativly the code can be easily installed using pip (which doesn't +currently include OpenMC) -``` -pip install neutronics_material_maker -``` +`pip install neutronics_material_maker` -You can clone the repository, and install using the setup.py if you would like the development version. +You can clone the repository, and install using the setup.py if you would like +the development version. :: @@ -81,7 +83,11 @@ You can clone the repository, and install using the setup.py if you would like t Features -------- -There are two main user classes `Material() `_ and `MutliMaterial() `_ which are both fully documented. +There are two main user classes +`Material() `_ +and +`MutliMaterial() `_ +which are both fully documented. Example Scripts diff --git a/environment.yml b/environment.yml index 60d90f3..f8106bb 100644 --- a/environment.yml +++ b/environment.yml @@ -4,6 +4,7 @@ channels: - conda-forge dependencies: + - python=3.8 - openmc - pip: - coolprop diff --git a/readthedocs.yml b/readthedocs.yml index f143d1d..a74ea99 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -26,4 +26,4 @@ python: # specify conda environment needed for build conda: - environment: environment.yml + environment: docs/environment.yml From cad39c638b8d80798e391c0598da5e4ddddfb6fa Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 14:54:16 +0000 Subject: [PATCH 16/17] added code block to pip install; --- docs/source/index.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 71156ab..1571576 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -62,14 +62,17 @@ Installation The recommended method is to install from [Conda Forge](https://conda-forge.org) which also installs all the dependancies including OpenMC. -``` -conda install neutronics_material_maker -c conda-forge -``` +.. code-block:: bash + + conda install neutronics_material_maker -c conda-forge + Alternativly the code can be easily installed using pip (which doesn't currently include OpenMC) -`pip install neutronics_material_maker` +.. code-block:: bash + + pip install neutronics_material_maker You can clone the repository, and install using the setup.py if you would like the development version. From 6e9eee018c115831f115cc8e927747a70aa1c55c Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Wed, 24 Feb 2021 15:06:26 +0000 Subject: [PATCH 17/17] bump version and more type hinting --- neutronics_material_maker/mutlimaterial.py | 18 +++++++++--------- neutronics_material_maker/utils.py | 16 ++++++++-------- setup.py | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/neutronics_material_maker/mutlimaterial.py b/neutronics_material_maker/mutlimaterial.py index f980857..b561b19 100644 --- a/neutronics_material_maker/mutlimaterial.py +++ b/neutronics_material_maker/mutlimaterial.py @@ -4,7 +4,7 @@ import warnings from json import JSONEncoder -from typing import List, Optional +from typing import List, Optional, Union import neutronics_material_maker as nmm from neutronics_material_maker import (make_fispact_material, @@ -80,16 +80,16 @@ class MultiMaterial: def __init__( self, material_tag: Optional[str] = None, - materials: list = [], + materials: List[Union[nmm.Material, openmc.Material]] = [], fracs: List[float] = [], - percent_type: str = "vo", + percent_type: Optional[str] = "vo", packing_fraction: float = 1.0, - zaid_suffix: str = None, - material_id: int = None, - decimal_places: int = 8, - volume_in_cm3: float = None, - temperature_in_C: float = None, - temperature_in_K: float = None + zaid_suffix: Optional[str] = None, + material_id: Optional[int] = None, + decimal_places: Optional[int] = 8, + volume_in_cm3: Optional[float] = None, + temperature_in_C: Optional[float] = None, + temperature_in_K: Optional[float] = None ): self.material_tag = material_tag self.materials = materials diff --git a/neutronics_material_maker/utils.py b/neutronics_material_maker/utils.py index d55eb58..92903c3 100644 --- a/neutronics_material_maker/utils.py +++ b/neutronics_material_maker/utils.py @@ -14,7 +14,7 @@ .fispact_material not avaiable") -def make_fispact_material(mat): +def make_fispact_material(mat) -> str: """ Returns a Fispact material card for the material. This contains the required keywords (DENSITY and FUEL) and the number of atoms of each isotope in the @@ -43,7 +43,7 @@ def make_fispact_material(mat): return "\n".join(mat_card) -def make_serpent_material(mat): +def make_serpent_material(mat) -> str: """Returns the material in a string compatable with Serpent II""" if mat.material_tag is None: @@ -78,7 +78,7 @@ def make_serpent_material(mat): return "\n".join(mat_card) -def make_mcnp_material(mat): +def make_mcnp_material(mat) -> str: """Returns the material in a string compatable with MCNP6""" if mat.material_id is None: @@ -127,14 +127,14 @@ def make_mcnp_material(mat): return "\n".join(mat_card) -def isotope_to_zaid(isotope): +def isotope_to_zaid(isotope: str) -> str: """converts an isotope into a zaid e.g. Li6 -> 003006""" z, a, m = openmc.data.zam(isotope) zaid = str(z).zfill(3) + str(a).zfill(3) return zaid -def zaid_to_isotope(zaid): +def zaid_to_isotope(zaid: str) -> str: """converts an isotope into a zaid e.g. 003006 -> Li6""" a = str(zaid)[-3:] z = str(zaid)[:-3] @@ -142,7 +142,7 @@ def zaid_to_isotope(zaid): return symbol + str(int(a)) -def AddMaterialFromDir(directory, verbose=True): +def AddMaterialFromDir(directory: str, verbose: bool = True): """Add materials to the internal library from a directory of json files""" for filename in Path(directory).rglob("*.json"): with open(filename, "r") as f: @@ -153,7 +153,7 @@ def AddMaterialFromDir(directory, verbose=True): print(sorted(list(new_data.keys())), "\n") -def AddMaterialFromFile(filename, verbose=True): +def AddMaterialFromFile(filename, verbose=True) -> None: """Add materials to the internal library from a json file""" with open(filename, "r") as f: new_data = json.load(f) @@ -163,7 +163,7 @@ def AddMaterialFromFile(filename, verbose=True): print(sorted(list(material_dict.keys()))) -def AvailableMaterials(): +def AvailableMaterials() -> dict: """Returns a dictionary of available materials""" return material_dict diff --git a/setup.py b/setup.py index 1421210..34652c2 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="neutronics_material_maker", - version="0.1.12", + version="0.1.13", summary="Package for making material cards for neutronics codes", author="neutronics_material_maker development team", author_email="jonathan.shimwell@ukaea.uk",