From fb4510d25e5e4ff0a63e15085b15b1ae2b5e4b1e Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 23 Mar 2022 22:41:46 +0000 Subject: [PATCH 01/13] added nuclear data download --- .github/workflows/ci_with_install.yml | 48 +++++++++++++++++++++++++++ .gitignore | 8 +++++ 2_run_openmc_dagmc_simulation.py | 21 ++++++++---- README.md | 12 +++---- environment_cad.yml | 13 ++++++++ environment_neutronics.yml | 11 ++++++ 6 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/ci_with_install.yml create mode 100644 environment_cad.yml create mode 100644 environment_neutronics.yml diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml new file mode 100644 index 0000000..5b2b2a7 --- /dev/null +++ b/.github/workflows/ci_with_install.yml @@ -0,0 +1,48 @@ + +# This CI will launch a Docker image that contains all the dependencies required +# within that image the pytest test suite is run + + +name: CI with install + +on: + pull_request: + branches: + - develop + - main + +jobs: + testing: + runs-on: ubuntu-latest + container: + image: continuumio/miniconda3 + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: install dependencies package + run: | + apt update -y + apt-get install ffmpeg libsm6 libxext6 -y + + - name: create environment 1 + run: | + conda env create -f environment_cad.yml + conda activate env_cad + + - name: run script 1 of 3 + run: | + python 1_creation_of_dagmc_geometry.py + + - name: create environment 1 + run: | + conda env create -f environment_neutronics.yml + conda activate env_neutronics + + - name: run script 2 of 3 + run: | + 2_run_openmc_dagmc_simulation.py + + - name: run script 3 of 3 + run: | + 3_extract_results.py diff --git a/.gitignore b/.gitignore index b6e4761..e354119 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,11 @@ dmypy.json # Pyre type checker .pyre/ + +# output files +*.h5m +*.html +*.xml +*.h5 +*.out +*.xml diff --git a/2_run_openmc_dagmc_simulation.py b/2_run_openmc_dagmc_simulation.py index 580ce4d..ae22154 100644 --- a/2_run_openmc_dagmc_simulation.py +++ b/2_run_openmc_dagmc_simulation.py @@ -1,30 +1,31 @@ import openmc +import openmc_data_downloader as odd + # Names of material tags can be found with the command line tool # mbsize -ll dagmc.h5m | grep 'NAME = mat:' - -mat_vacuum_vessel = openmc.Material(name="mat_vacuum_vessel") +mat_vacuum_vessel = openmc.Material(name="vacuum_vessel") mat_vacuum_vessel.add_element("Fe", 1, "ao") mat_vacuum_vessel.set_density("g/cm3", 7.7) -mat_upper_blanket = openmc.Material(name="mat_upper_blanket") +mat_upper_blanket = openmc.Material(name="upper_blanket") mat_upper_blanket.add_element("Li", 1, "ao") mat_upper_blanket.set_density("g/cm3", 0.5) -mat_lower_blanket = openmc.Material(name="mat_lower_blanket") +mat_lower_blanket = openmc.Material(name="lower_blanket") mat_lower_blanket.add_element("Li", 1, "ao") mat_lower_blanket.set_density("g/cm3", 0.5) -mat_lower_vacuum_vessel = openmc.Material(name="mat_lower_vacuum_vessel") +mat_lower_vacuum_vessel = openmc.Material(name="lower_vacuum_vessel") mat_lower_vacuum_vessel.add_element("Fe", 1, "ao") mat_lower_vacuum_vessel.set_density("g/cm3", 7.7) -mat_upper_vacuum_vessel = openmc.Material(name="mat_upper_vacuum_vessel") +mat_upper_vacuum_vessel = openmc.Material(name="upper_vacuum_vessel") mat_upper_vacuum_vessel.add_element("Fe", 1, "ao") mat_upper_vacuum_vessel.set_density("g/cm3", 7.7) -mat_blanket = openmc.Material(name="mat_blanket") +mat_blanket = openmc.Material(name="blanket") mat_blanket.add_element("Li", 1, "ao") mat_blanket.set_density("g/cm3", 0.5) @@ -39,6 +40,12 @@ ] ) +#downloads the nuclear data and sets the openmc_cross_sections environmental variable +odd.just_in_time_library_generator( + libraries='ENDFB-7.1-NNDC', + materials=materials +) + # makes use of the dagmc geometry dag_univ = openmc.DAGMCUniverse("dagmc.h5m") diff --git a/README.md b/README.md index ba7852c..75f3342 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,8 @@ cd cad-to-dagmc-to-openmc-example Make an environment for the model preparation ``` -conda create --name paramak_env python=3.9 -conda activate paramak_env -conda install -c fusion-energy -c cadquery -c conda-forge paramak -pip install jupyter_cadquery +conda env create -f environment_cad.yml +conda activate env_cad ``` Then run the script for making the DAGMC model. @@ -44,10 +42,8 @@ paraview dagmc.vtk First make an environment for simulation. ``` -conda create --name openmc_dagmc_env python=3.9 -conda activate openmc_dagmc_env -conda install -c conda-forge openmc -pip install openmc_mesh_tally_to_vtk +conda env create -f environment_neutronics.yml +conda activate env_neutronics ``` Then run the simulation which will produce a statepoint.10.h5 file that contains the simulation outputs diff --git a/environment_cad.yml b/environment_cad.yml new file mode 100644 index 0000000..25f1216 --- /dev/null +++ b/environment_cad.yml @@ -0,0 +1,13 @@ + + +name: env_cad +channels: + - fusion-energy + - cadquery + - conda-forge +dependencies: + - python=3.9 + - paramak=0.7.2 + - pip + - pip: + - jupyter-cadquery diff --git a/environment_neutronics.yml b/environment_neutronics.yml new file mode 100644 index 0000000..4c1cbd6 --- /dev/null +++ b/environment_neutronics.yml @@ -0,0 +1,11 @@ + + +name: env_neutronics +channels: + - conda-forge +dependencies: + - python=3.9 + - openmc=0.13.0 + - pip + - pip: + - openmc_data_downloader From fc487c55f6c4a37545d8202a97756834914708b3 Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 23 Mar 2022 22:44:58 +0000 Subject: [PATCH 02/13] fixed typos --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 75f3342..d0f4660 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -This example simulates a simplfied model of an inertial confinement fusion reactor. +[![CI with install](https://github.com/shimwell/cad-to-dagmc-to-openmc-example/actions/workflows/ci_with_install.yml/badge.svg)](https://github.com/shimwell/cad-to-dagmc-to-openmc-example/actions/workflows/ci_with_install.yml) + +This example simulates a simplified model of an inertial confinement fusion reactor. - A CAD model is made and automatically converted to a DAGMC geometry that is then used in OpenMC for a neutronics simulation. - The neutronics simulation obtains the tritium breeding ratio and a 3D map of tritium production. From d46a0e20c7248dc7166346b4d88af82a2ad2e877 Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 23 Mar 2022 22:45:12 +0000 Subject: [PATCH 03/13] added missing package --- environment_neutronics.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment_neutronics.yml b/environment_neutronics.yml index 4c1cbd6..c3562ca 100644 --- a/environment_neutronics.yml +++ b/environment_neutronics.yml @@ -9,3 +9,4 @@ dependencies: - pip - pip: - openmc_data_downloader + - openmc_mesh_tally_to_vtk From 80a80c509f9275e812c39097e4f69752639f49c6 Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 23 Mar 2022 22:47:00 +0000 Subject: [PATCH 04/13] reduced number of particles --- 2_run_openmc_dagmc_simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2_run_openmc_dagmc_simulation.py b/2_run_openmc_dagmc_simulation.py index ae22154..6d2d6bf 100644 --- a/2_run_openmc_dagmc_simulation.py +++ b/2_run_openmc_dagmc_simulation.py @@ -69,7 +69,7 @@ # specifies the simulation computational intensity settings = openmc.Settings() settings.batches = 10 -settings.particles = 100000 +settings.particles = 10000 settings.inactive = 0 settings.run_mode = "fixed source" settings.source = my_source From e79c6a8acc4390f5ea6f875b886f70bbf495959e Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 23 Mar 2022 22:52:34 +0000 Subject: [PATCH 05/13] added conda init --- .github/workflows/ci_with_install.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 5b2b2a7..3b2cfb2 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -20,6 +20,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 + - name: conda init + run: | + conda init bash + - name: install dependencies package run: | apt update -y From 57b3772fd169772e28895a41d306e132a81f8cf3 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 24 Mar 2022 09:38:04 +0000 Subject: [PATCH 06/13] init code with .sh script --- .github/workflows/ci_with_install.yml | 2 +- conda_init_for_ci.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 conda_init_for_ci.sh diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 3b2cfb2..01f79e1 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -22,7 +22,7 @@ jobs: - name: conda init run: | - conda init bash + bash -i conda_init_for_ci.sh - name: install dependencies package run: | diff --git a/conda_init_for_ci.sh b/conda_init_for_ci.sh new file mode 100644 index 0000000..0704985 --- /dev/null +++ b/conda_init_for_ci.sh @@ -0,0 +1 @@ +conda init \ No newline at end of file From 04291be0f68cb0b0121d8f1694c89da04a7fbb91 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 24 Mar 2022 10:09:13 +0000 Subject: [PATCH 07/13] added vtk --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e354119..485366d 100644 --- a/.gitignore +++ b/.gitignore @@ -135,3 +135,4 @@ dmypy.json *.h5 *.out *.xml +*.vtk From f14a3a3dccd7618a32eabe3a66738eae8a61bb43 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 24 Mar 2022 10:09:26 +0000 Subject: [PATCH 08/13] added conda requirement --- README.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d0f4660..e0ba418 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,27 @@ This example simulates a simplified model of an inertial confinement fusion reac - The neutronics simulation obtains the tritium breeding ratio and a 3D map of tritium production. - The simulation outputs are post processed to display the results and produce a VTK file for visualization. +# Prerequisites + +This minimal example makes use of Conda to manage and install the packages. + +You will need one of these conda distributions to be installed or work within a [Docker image](https://hub.docker.com/r/continuumio/miniconda3) + +- [Miniconda](https://docs.conda.io/en/latest/miniconda.html) + +- [Anaconda](https://www.anaconda.com/) + +- [Miniforge](https://github.com/conda-forge/miniforge) + +- [Miniconda](https://docs.conda.io/en/latest/miniconda.html) + # First clone the repository ```bash git clone https://github.com/shimwell/cad-to-dagmc-to-openmc-example.git cd cad-to-dagmc-to-openmc-example ``` -# Making the DAGMC model. +# Making the DAGMC model Make an environment for the model preparation ``` @@ -29,7 +43,6 @@ Then open the ```dagmc.html``` file in an internet browser to view the CAD creat ![CAD geometry image](https://user-images.githubusercontent.com/8583900/159698975-d82544c7-635b-4117-b4bc-4d61a8cf9ecc.png) - Optionally you can inspect the DAGMC file at this stage by converting the h5m file to a vtk file and opening this with [Paraview](https://www.paraview.org/) ``` mbconvert dagmc.h5m dagmc.vtk @@ -37,9 +50,7 @@ paraview dagmc.vtk ``` ![DAGMC model image](https://user-images.githubusercontent.com/8583900/159698979-3665e14b-ca42-4df2-8a1e-deee6597efc0.png) - - -# Simulating the model in OpenMC. +# Simulating the model in OpenMC First make an environment for simulation. @@ -58,7 +69,7 @@ Then run the post processing script that should output the Tritium Breeding Rati python 3_extract_results.py ``` -Open up the VTK file with paraview +Open up the VTK file with Paraview and slice the data to see the high tritium breeding region ```bash paraview tritium_production_map.vtk ``` From 7db66f0478c6d34c82f8aadad98417f75faa1d56 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 24 Mar 2022 10:09:46 +0000 Subject: [PATCH 09/13] moved init after env creation --- .github/workflows/ci_with_install.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index 01f79e1..a27f874 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -20,9 +20,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: conda init - run: | - bash -i conda_init_for_ci.sh - name: install dependencies package run: | @@ -34,6 +31,10 @@ jobs: conda env create -f environment_cad.yml conda activate env_cad + - name: conda init + run: | + bash -i conda_init_for_ci.sh + - name: run script 1 of 3 run: | python 1_creation_of_dagmc_geometry.py From 1ab92005ffc2218bc59fe462aaa70f7a403a1aa7 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 24 Mar 2022 10:29:25 +0000 Subject: [PATCH 10/13] removed activate part --- .github/workflows/ci_with_install.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index a27f874..d339524 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -29,7 +29,6 @@ jobs: - name: create environment 1 run: | conda env create -f environment_cad.yml - conda activate env_cad - name: conda init run: | @@ -42,7 +41,6 @@ jobs: - name: create environment 1 run: | conda env create -f environment_neutronics.yml - conda activate env_neutronics - name: run script 2 of 3 run: | From 032b1b509c2f0b32e2717789c6b7b4ba0e5b22a0 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 24 Mar 2022 10:30:15 +0000 Subject: [PATCH 11/13] added source bashrc --- .github/workflows/ci_with_install.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index d339524..bcfacb2 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -29,6 +29,9 @@ jobs: - name: create environment 1 run: | conda env create -f environment_cad.yml + conda init bash + source ~/.bashrc + conda activate env_cad - name: conda init run: | @@ -41,6 +44,9 @@ jobs: - name: create environment 1 run: | conda env create -f environment_neutronics.yml + conda init bash + source ~/.bashrc + conda activate env_neutronics - name: run script 2 of 3 run: | From 5338c314662f0a3a446d1d277dfdddd39afb196e Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 24 Mar 2022 12:04:12 +0000 Subject: [PATCH 12/13] trying .source instead of source --- .github/workflows/ci_with_install.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index bcfacb2..baeacd6 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -19,7 +19,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v2 - - name: install dependencies package run: | @@ -30,7 +29,7 @@ jobs: run: | conda env create -f environment_cad.yml conda init bash - source ~/.bashrc + .source ~/.bashrc conda activate env_cad - name: conda init @@ -45,7 +44,7 @@ jobs: run: | conda env create -f environment_neutronics.yml conda init bash - source ~/.bashrc + .source ~/.bashrc conda activate env_neutronics - name: run script 2 of 3 From facadd2a071fb08f81deb41f15cd284f5e851447 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 24 Mar 2022 12:28:38 +0000 Subject: [PATCH 13/13] [skip ci] removed ci badge while conda activate is fixed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e0ba418..a7504be 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![CI with install](https://github.com/shimwell/cad-to-dagmc-to-openmc-example/actions/workflows/ci_with_install.yml/badge.svg)](https://github.com/shimwell/cad-to-dagmc-to-openmc-example/actions/workflows/ci_with_install.yml) + This example simulates a simplified model of an inertial confinement fusion reactor.