-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from fusion-energy/develop
added requested_units to functions
- Loading branch information
Showing
12 changed files
with
527 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cff-version: 1.2.0 | ||
message: "If you use this software, please cite it as below." | ||
authors: | ||
- family-names: "Shimwell" | ||
given-names: "Jonathan" | ||
orcid: "https://orcid.org/0000-0001-6909-0946" | ||
title: "A Python package for plotting regular mesh tally results from neutronics simulations." | ||
version: 0.1.0 | ||
date-released: 2021-10-30 | ||
url: "https://github.com/fusion-energy/regular_mesh_plotter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# This minimal example makes a 3D volume and exports the shape to a stp file | ||
# A surrounding volume called a graveyard is needed for neutronics simulations | ||
|
||
import openmc | ||
import openmc_dagmc_wrapper as odw | ||
import openmc_plasma_source as ops | ||
import openmc_data_downloader as odd | ||
|
||
|
||
# MATERIALS | ||
breeder_material = openmc.Material(1, "PbLi") # Pb84.2Li15.8 | ||
# breeder_material.add_element("Pb", 84.2, percent_type="ao") | ||
breeder_material.add_element( | ||
"Li", | ||
15.8, | ||
percent_type="ao", | ||
enrichment=50.0, | ||
enrichment_target="Li6", | ||
enrichment_type="ao", | ||
) # 50% enriched | ||
breeder_material.set_density("atom/b-cm", 3.2720171e-2) # around 11 g/cm3 | ||
|
||
iron = openmc.Material(name="iron") | ||
iron.set_density("g/cm3", 7.75) | ||
iron.add_element("Li", 0.95, percent_type="wo") | ||
|
||
materials = openmc.Materials([breeder_material, iron]) | ||
|
||
odd.just_in_time_library_generator(libraries="TENDL-2019", materials=materials) | ||
|
||
# GEOMETRY | ||
|
||
# surfaces | ||
vessel_inner = openmc.Sphere(r=500) | ||
first_wall_outer_surface = openmc.Sphere(r=510) | ||
breeder_blanket_outer_surface = openmc.Sphere(r=610, boundary_type="vacuum") | ||
|
||
# cells | ||
inner_vessel_region = -vessel_inner | ||
inner_vessel_cell = openmc.Cell(region=inner_vessel_region) | ||
|
||
first_wall_region = -first_wall_outer_surface & +vessel_inner | ||
first_wall_cell = openmc.Cell(region=first_wall_region) | ||
first_wall_cell.fill = iron | ||
|
||
breeder_blanket_region = +first_wall_outer_surface & -breeder_blanket_outer_surface | ||
breeder_blanket_cell = openmc.Cell(region=breeder_blanket_region) | ||
breeder_blanket_cell.fill = breeder_material | ||
|
||
universe = openmc.Universe( | ||
cells=[inner_vessel_cell, first_wall_cell, breeder_blanket_cell] | ||
) | ||
geometry = openmc.Geometry(universe) | ||
|
||
tally1 = odw.MeshTally2D( | ||
tally_type="neutron_effective_dose", | ||
plane="xy", | ||
mesh_resolution=(10, 5), | ||
bounding_box=[(-100, -100, 0), (100, 100, 1)], | ||
) | ||
|
||
tally2 = odw.MeshTally3D( | ||
mesh_resolution=(100, 100, 100), | ||
bounding_box=[(-100, -100, 0), (100, 100, 1)], | ||
tally_type="neutron_effective_dose", | ||
) | ||
|
||
tally3 = odw.MeshTally2D( | ||
tally_type="neutron_flux", | ||
plane="xy", | ||
mesh_resolution=(10, 5), | ||
bounding_box=[(-100, -100, 0), (100, 100, 1)], | ||
) | ||
|
||
tallies = openmc.Tallies( | ||
[ | ||
tally1, | ||
tally2, | ||
tally3, | ||
] | ||
) | ||
|
||
settings = odw.FusionSettings() | ||
settings.batches = 2 | ||
settings.particles = 1000000 | ||
# assigns a ring source of DT energy neutrons to the source using the | ||
# openmc_plasma_source package | ||
settings.source = ops.FusionPointSource() | ||
|
||
|
||
my_model = openmc.model.Model( | ||
materials=materials, geometry=geometry, settings=settings, tallies=tallies | ||
) | ||
statepoint_file = my_model.run() |
104 changes: 104 additions & 0 deletions
104
examples/create_statepoint_file_with_meshes_openmc_dagmc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# This minimal example makes a 3D volume and exports the shape to a stp file | ||
# A surrounding volume called a graveyard is needed for neutronics simulations | ||
|
||
import openmc | ||
import openmc_dagmc_wrapper as odw | ||
import openmc_plasma_source as ops | ||
import paramak | ||
from stl_to_h5m import stl_to_h5m | ||
|
||
my_shape = paramak.ExtrudeStraightShape( | ||
points=[(1, 1), (1, 200), (600, 200), (600, 1)], | ||
distance=180, | ||
) | ||
|
||
my_shape.export_stl("example.stl") | ||
|
||
# This script converts the CAD stl files generated into h5m files that can be | ||
# used in DAGMC enabled codes. h5m files created in this way are imprinted, | ||
# merged, faceted and ready for use in OpenMC. One of the key aspects of this | ||
# is the assignment of materials to the volumes present in the CAD files. | ||
|
||
stl_to_h5m( | ||
files_with_tags=[("example.stl", "mat1")], | ||
h5m_filename="dagmc.h5m", | ||
) | ||
|
||
# makes use of the previously created neutronics geometry (h5m file) and assigns | ||
# actual materials to the material tags. Sets simulation intensity and specifies | ||
# the neutronics results to record (know as tallies). | ||
|
||
geometry = odw.Geometry( | ||
h5m_filename="dagmc.h5m", | ||
) | ||
|
||
materials = odw.Materials( | ||
h5m_filename="dagmc.h5m", correspondence_dict={"mat1": "eurofer"} | ||
) | ||
|
||
tally1 = odw.MeshTally2D( | ||
tally_type="neutron_effective_dose", | ||
plane="xy", | ||
mesh_resolution=(10, ), | ||
bounding_box="dagmc.h5m", | ||
) | ||
tally2 = odw.MeshTally2D( | ||
tally_type="neutron_effective_dose", | ||
plane="yz", | ||
mesh_resolution=(10, 5), | ||
bounding_box="dagmc.h5m", | ||
) | ||
tally3 = odw.MeshTally2D( | ||
tally_type="neutron_effective_dose", | ||
plane="xz", | ||
mesh_resolution=(10, 5), | ||
bounding_box="dagmc.h5m", | ||
) | ||
tally4 = odw.MeshTally2D( | ||
tally_type="neutron_effective_dose", | ||
plane="xy", | ||
mesh_resolution=(10, ), | ||
bounding_box="dagmc.h5m", | ||
) | ||
tally5 = odw.MeshTally2D( | ||
tally_type="neutron_effective_dose", | ||
plane="yz", | ||
mesh_resolution=(10, 5), | ||
bounding_box="dagmc.h5m", | ||
) | ||
tally6 = odw.MeshTally2D( | ||
tally_type="neutron_effective_dose", | ||
plane="xz", | ||
mesh_resolution=(10, 5), | ||
bounding_box="dagmc.h5m", | ||
) | ||
|
||
# tally2 = odw.MeshTally3D( | ||
# mesh_resolution=(100, 100, 100), | ||
# bounding_box="dagmc.h5m", | ||
# tally_type="neutron_effective_dose", | ||
# ) | ||
|
||
tallies = openmc.Tallies( | ||
[ | ||
tally1, | ||
tally2, | ||
tally3, | ||
tally4, | ||
tally5, | ||
tally6, | ||
] | ||
) | ||
|
||
settings = odw.FusionSettings() | ||
settings.batches = 2 | ||
settings.particles = 1000 | ||
# assigns a ring source of DT energy neutrons to the source using the | ||
# openmc_plasma_source package | ||
settings.source = ops.FusionPointSource() | ||
|
||
|
||
my_model = openmc.Model( | ||
materials=materials, geometry=geometry, settings=settings, tallies=tallies | ||
) | ||
statepoint_file = my_model.run() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import regular_mesh_plotter as rmp | ||
import openmc | ||
|
||
# loads in the statepoint file containing tallies | ||
statepoint = openmc.StatePoint(filepath="statepoint.2.h5") | ||
|
||
# gets one tally from the available tallies | ||
my_tally = statepoint.get_tally(name="2_neutron_effective_dose") | ||
|
||
# creates a plot of the mesh tally | ||
my_plot = rmp.plot_regular_mesh_dose_tally( | ||
tally=my_tally, # the openmc tally object to plot, must be a 2d mesh tally | ||
filename='plot_regular_mesh_dose_tally.png', # the filename of the picture file saved | ||
scale=None, # LogNorm(), | ||
vmin=None, | ||
label="", | ||
x_label="X [cm]", | ||
y_label="Y [cm]", | ||
rotate_plot = 0, | ||
required_units='picosievert cm **2 / simulated_particle', | ||
source_strength = None, | ||
) | ||
|
||
# displays the plot | ||
my_plot.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import regular_mesh_plotter as rmp | ||
import openmc | ||
|
||
# loads in the statepoint file containing tallies | ||
statepoint = openmc.StatePoint(filepath="statepoint.2.h5") | ||
|
||
# gets one tally from the available tallies | ||
my_tally = statepoint.get_tally(name="2_neutron_effective_dose") | ||
|
||
# creates a plot of the mesh | ||
my_plot = rmp.plot_regular_mesh_dose_tally_with_geometry( | ||
tally=my_tally, | ||
dagmc_file_or_trimesh_object="dagmc.h5m", | ||
filename = 'plot_regular_mesh_dose_tally_with_geometry.png', | ||
scale=None, # LogNorm(), | ||
vmin=None, | ||
label="", | ||
x_label="X [cm]", | ||
y_label="Y [cm]", | ||
plane_origin = None, # this could be skipped as it defaults to None, which uses the center of the mesh | ||
plane_normal = [0, 0, 1], | ||
rotate_mesh = 0, | ||
rotate_geometry = 0, | ||
required_units='picosievert cm **2 / simulated_particle', | ||
source_strength = None, | ||
): | ||
|
||
my_plot.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
import regular_mesh_plotter as rmp | ||
import openmc | ||
|
||
# loads in the statepoint file containing tallies | ||
statepoint = openmc.StatePoint(filepath="statepoint.2.h5") | ||
|
||
# gets one tally from the available tallies | ||
my_tally = statepoint.get_tally(name="2_neutron_effective_dose") | ||
|
||
# creates a plot of the mesh | ||
plot_regular_mesh_tally( | ||
tally, | ||
filename: Optional[str] = None, | ||
scale=None, # LogNorm(), | ||
vmin=None, | ||
label="", | ||
base_plt=None, | ||
x_label="X [cm]", | ||
y_label="Y [cm]", | ||
rotate_plot: float = 0, | ||
required_units: str = None, | ||
source_strength: float = None, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
import regular_mesh_plotter as rmp | ||
import openmc | ||
|
||
# loads in the statepoint file containing tallies | ||
statepoint = openmc.StatePoint(filepath="statepoint.2.h5") | ||
|
||
# gets one tally from the available tallies | ||
my_tally = statepoint.get_tally(name="2_neutron_effective_dose") | ||
|
||
# creates a plot of the mesh | ||
my_plot = rmp.plot_regular_mesh_tally_with_geometry( | ||
tally=my_tally, | ||
dagmc_file_or_trimesh_object='dagmc.h5m', | ||
std_dev_or_tally_value='tally_value', | ||
filename='plot_regular_mesh_tally_with_geometry.png', | ||
scale=None, # LogNorm(), | ||
vmin=None, | ||
label="", | ||
x_label="X [cm]", | ||
y_label="Y [cm]", | ||
plane_origin = [0,0,0], | ||
plane_normal = [0, 0, 1], | ||
rotate_mesh = 0, | ||
rotate_geometry = 0, | ||
required_units=None, | ||
source_strength = None | ||
) | ||
|
||
my_plot.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
import regular_mesh_plotter as rmp | ||
import openmc | ||
|
||
# loads in the statepoint file containing tallies | ||
statepoint = openmc.StatePoint(filepath="statepoint.2.h5") | ||
|
||
# gets one tally from the available tallies | ||
my_tally = statepoint.get_tally(name="2_neutron_effective_dose") | ||
|
||
# creates a plot of the mesh | ||
plot_regular_mesh_values( | ||
values: np.ndarray, | ||
filename: Optional[str] = None, | ||
scale=None, # LogNorm(), | ||
vmin=None, | ||
label="", | ||
base_plt=None, | ||
extent=None, | ||
x_label="X [cm]", | ||
y_label="Y [cm]", | ||
rotate_plot: float = 0, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import regular_mesh_plotter as rmp | ||
import openmc | ||
|
||
# loads in the statepoint file containing tallies | ||
statepoint = openmc.StatePoint(filepath="statepoint.2.h5") | ||
|
||
# gets one tally from the available tallies | ||
my_tally = statepoint.get_tally(name="2_neutron_effective_dose") | ||
|
||
|
||
|
||
def plot_regular_mesh_values_with_geometry( | ||
values: np.ndarray, | ||
dagmc_file_or_trimesh_object, | ||
filename: Optional[str] = None, | ||
scale=None, # LogNorm(), | ||
vmin=None, | ||
label="", | ||
extent=None, | ||
x_label="X [cm]", | ||
y_label="Y [cm]", | ||
plane_origin: List[float] = None, | ||
plane_normal: List[float] = [0, 0, 1], | ||
rotate_mesh: float = 0, | ||
rotate_geometry: float = 0, | ||
): |
Oops, something went wrong.