diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml new file mode 100644 index 0000000..baeacd6 --- /dev/null +++ b/.github/workflows/ci_with_install.yml @@ -0,0 +1,56 @@ + +# 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 init bash + .source ~/.bashrc + 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 + + - 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: | + 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..485366d 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,12 @@ dmypy.json # Pyre type checker .pyre/ + +# output files +*.h5m +*.html +*.xml +*.h5 +*.out +*.xml +*.vtk diff --git a/2_run_openmc_dagmc_simulation.py b/2_run_openmc_dagmc_simulation.py index 580ce4d..6d2d6bf 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") @@ -62,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 diff --git a/README.md b/README.md index ba7852c..a7504be 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,37 @@ -This example simulates a simplfied model of an inertial confinement fusion reactor. + + +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. - 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 ``` -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. @@ -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,17 +50,13 @@ 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. ``` -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 @@ -60,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 ``` 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 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..c3562ca --- /dev/null +++ b/environment_neutronics.yml @@ -0,0 +1,12 @@ + + +name: env_neutronics +channels: + - conda-forge +dependencies: + - python=3.9 + - openmc=0.13.0 + - pip + - pip: + - openmc_data_downloader + - openmc_mesh_tally_to_vtk