Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #52 from fusion-energy/develop
Browse files Browse the repository at this point in the history
addding fast flux and refactor to use  dagmc-h5m-file-inspector
  • Loading branch information
shimwell authored Sep 10, 2021
2 parents b56e2b3 + 525d4a8 commit 689a242
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 295 deletions.
18 changes: 9 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@ jobs:
- run:
name: run test_NeutronicModel
command:
pytest tests/test_neutronics_model.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

- run:
name: run test_shape_neutronics
command:
pytest tests/test_shape_neutronics.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

- run:
name: run test_reactor_neutronics
command:
pytest tests/test_reactor_neutronics.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

- run:
name: run test_neutronics_utils
command:
pytest tests/test_neutronics_utils.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml
# - run:
# name: run test_neutronics_utils
# command:
# pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

- run:
name: run test_example_neutronics_simulations
command:
pytest tests/test_example_neutronics_simulations.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml

# TODO add example notebooks
# - run:
# name: run notebook_testing
# command:
# pytest tests/notebook_testing.py -v --cov=openmc-dagmc_wrapper --cov-append --cov-report term --cov-report xml --junitxml=test-reports/junit.xml
# pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml --junitxml=test-reports/junit.xml


- store_test_results:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ jobs:
- name: install package
run: |
python setup.py install
- name: run tests
run: |
bash run_tests.sh
pytest tests/test_neutronics_model.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_reactor_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_shape_neutronics.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/test_example_neutronics_simulations.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
# pytest tests/test_neutronics_utils.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
pytest tests/notebook_testing.py -v --cov=openmc_dagmc_wrapper --cov-append --cov-report term --cov-report xml
curl -s https://codecov.io/bash
2 changes: 0 additions & 2 deletions openmc_dagmc_wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .utils import get_neutronics_results_from_statepoint_file
from .utils import find_material_groups_in_h5m
from .utils import find_volume_ids_in_h5m
from .utils import create_initial_particles
from .utils import extract_points_from_initial_source
from .utils import silently_remove_file
Expand Down
105 changes: 72 additions & 33 deletions openmc_dagmc_wrapper/neutronics_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
from pathlib import Path
from typing import List, Optional, Tuple, Union

import dagmc_h5m_file_inspector as di
import neutronics_material_maker as nmm
import openmc
import openmc.lib # needed to find bounding box of h5m file
import plotly.graph_objects as go
from openmc.data import REACTION_MT, REACTION_NAME

from .utils import (
create_initial_particles,
extract_points_from_initial_source,
get_neutronics_results_from_statepoint_file,
silently_remove_file,
plotly_trace,
)
from .utils import (create_initial_particles,
extract_points_from_initial_source,
get_neutronics_results_from_statepoint_file, plotly_trace,
silently_remove_file)


class NeutronicsModel:
Expand All @@ -31,8 +29,8 @@ class NeutronicsModel:
neutronics-material-maker.Material or
neutronics-material-maker.MultiMaterial. All components within the
geometry object must be accounted for. Material tags required
for a Reactor or Shape can be obtained with .material_tags() and
material_tag respectively.
for a Reactor or Shape can be obtained using the python package
dagmc_h5m_file_inspector
cell_tallies: the cell based tallies to calculate, options include
spectra, TBR, heating, flux, MT numbers and OpenMC standard scores
such as (n,Xa) which is helium production are also supported
Expand Down Expand Up @@ -123,6 +121,9 @@ def h5m_filename(self):
@h5m_filename.setter
def h5m_filename(self, value):
if isinstance(value, str):
if not Path(value).is_file():
msg = f"h5m_filename provided ({value}) does not exist"
raise FileNotFoundError(msg)
self._h5m_filename = value
else:
msg = "NeutronicsModelFromReactor.h5m_filename should be a string"
Expand All @@ -134,7 +135,12 @@ def tet_mesh_filename(self):

@tet_mesh_filename.setter
def tet_mesh_filename(self, value):
if isinstance(value, (str, type(None))):
if isinstance(value, str):
if not Path(value).is_file():
msg = f"tet_mesh_filename provided ({value}) does not exist"
raise FileNotFoundError(msg)
self._tet_mesh_filename = value
if isinstance(value, type(None)):
self._tet_mesh_filename = value
else:
msg = "NeutronicsModelFromReactor.tet_mesh_filename should be a string"
Expand Down Expand Up @@ -171,7 +177,8 @@ def cell_tallies(self, value):
"flux",
"spectra",
"absorption",
"effective_dose"] +
"effective_dose",
"fast_flux"] +
list(
REACTION_MT.keys()) +
list(
Expand Down Expand Up @@ -273,19 +280,27 @@ def create_material(self, material_tag: str, material_entry):
return openmc_material

def create_openmc_materials(self):

materials_in_h5m = di.get_materials_from_h5m(self.h5m_filename)
# # checks all the required materials are present
# for reactor_material in self.geometry.material_tags:
# if reactor_material not in self.materials.keys():
# raise ValueError(
# "material included by the reactor model has not \
# been added", reactor_material)

# # checks that no extra materials we added
# for reactor_material in self.materials.keys():
# if reactor_material not in self.geometry.material_tags:
# raise ValueError(
# "material has been added that is not needed for this \
# reactor model", reactor_material)
for reactor_material in self.materials.keys():
if reactor_material not in materials_in_h5m:
msg = (
f"material with tag {reactor_material} was not found in "
"the dagmc h5m file")
raise ValueError(msg)

if 'graveyard' in materials_in_h5m:
required_number_of_materials = len(materials_in_h5m) - 1
else:
required_number_of_materials = len(materials_in_h5m)

if required_number_of_materials != len(self.materials.keys()):
msg = (
f"the NeutronicsModel.materials does not match the material "
"tags in the dagmc h5m file. Materials in h5m file "
f"{materials_in_h5m}. Materials provided {self.materials.keys()}")
raise ValueError(msg)

silently_remove_file("materials.xml")

Expand Down Expand Up @@ -394,9 +409,9 @@ def export_xml(
Defaults to None which uses the NeutronicsModel.mesh_tally_2d
attribute.
cell_tallies: the cell based tallies to calculate, options include
TBR, heating, flux, MT numbers, effective_dose and OpenMC
standard scores such as (n,Xa) which is helium production are
also supported
TBR, heating, flux, MT numbers, effective_dose, fast_flux and
OpenMC standard scores such as (n,Xa) which is helium production
are also supported
https://docs.openmc.org/en/latest/usersguide/tallies.html#scores.
Defaults to None which uses the NeutronicsModel.cell_tallies
attribute.
Expand Down Expand Up @@ -505,6 +520,7 @@ def export_xml(
mesh_xyz.upper_right = self.mesh_3d_corners[1]

for standard_tally in self.mesh_tally_3d:

if standard_tally == "effective_dose":
energy_bins_n, dose_coeffs_n = openmc.data.dose_coefficients(
particle="neutron",
Expand Down Expand Up @@ -665,6 +681,27 @@ def export_xml(
self.tallies.append(tally)
self._add_tally_for_every_material(suffix, score)

elif standard_tally == "fast_flux":

energy_bins = [1e6, 1000e6]
energy_filter = openmc.EnergyFilter(energy_bins)

neutron_particle_filter = openmc.ParticleFilter([
"neutron"])
self._add_tally_for_every_material(
"neutron_fast_flux",
"flux",
[neutron_particle_filter, energy_filter],
)
if self.photon_transport is True:
photon_particle_filter = openmc.ParticleFilter([
"photon"])
self._add_tally_for_every_material(
"photon_fast_flux",
"flux",
[photon_particle_filter, energy_filter],
)

elif standard_tally == "spectra":

energy_bins = openmc.mgxs.GROUP_STRUCTURES["CCFE-709"]
Expand Down Expand Up @@ -699,7 +736,6 @@ def export_xml(
energy_function_filter_n = openmc.EnergyFunctionFilter(
energy_bins_n, dose_coeffs_n
)
# energy_function_filter_p = openmc.EnergyFunctionFilter(energy_bins_p, dose_coeffs_p)

self._add_tally_for_every_material(
"neutron_effective_dose",
Expand Down Expand Up @@ -731,6 +767,9 @@ def export_xml(
suffix = standard_tally
self._add_tally_for_every_material(suffix, score)

# todo add photon tallys for standard tallies
# if self.photon_transport:

# make the model from geometry, materials, settings and tallies
model = openmc.model.Model(geom, self.mats, settings, self.tallies)

Expand Down Expand Up @@ -813,6 +852,12 @@ def simulate(
)
raise TypeError(msg)

if not Path(self.h5m_filename).is_file():
msg = f"""{self.h5m_filename} file was not found. Please set
export_h5m to True or use the export_h5m() methods to create
the dagmc.h5m file"""
raise FileNotFoundError(msg)

if export_xml is True:
self.export_xml(
simulation_batches=simulation_batches,
Expand All @@ -835,12 +880,6 @@ def simulate(
)
raise FileNotFoundError(msg)

if not Path(self.h5m_filename).is_file():
msg = f"""{self.h5m_filename} file was not found. Please set
export_h5m to True or use the export_h5m() methods to create
the dagmc.h5m file"""
raise FileNotFoundError(msg)

# Deletes summary.h5m if it already exists.
# This avoids permission problems when trying to overwrite the file
silently_remove_file("summary.h5")
Expand Down
Loading

0 comments on commit 689a242

Please sign in to comment.