Skip to content

Commit

Permalink
Update use of Python API in C5G7 scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed May 26, 2016
1 parent 0ed38d8 commit 468e49c
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 165 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ comou?

# Compiled python files
*.pyc

# Python API-generated XML files
c5g7/openmc/**/*.xml
37 changes: 12 additions & 25 deletions c5g7/openmc/2d/build-xml-2d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import openmc
from openmc.source import Source
from openmc.stats import Box
import sys
sys.path.append('../')
from lattices import lattices, universes, cells, surfaces
Expand All @@ -22,10 +20,9 @@

from materials import materials

# Instantiate a MaterialsFile, register all Materials, and export to XML
materials_file = openmc.MaterialsFile()
# Instantiate a Materials collection, register all Materials, and export to XML
materials_file = openmc.Materials(materials.values())
materials_file.default_xs = '300k'
materials_file.add_materials(materials.values())
materials_file.export_to_xml()


Expand All @@ -47,30 +44,26 @@
lattices['Core'].universes = [[u, m, w], [m, u, w], [w, w, w]]
cells['Core'].fill = lattices['Core']

# Instantiate a Geometry and register the root Universe
# Instantiate a Geometry, register the root Universe, and export to XML
geometry = openmc.Geometry()
geometry.root_universe = universes['Root']

# Instantiate a GeometryFile, register Geometry, and export to XML
geometry_file = openmc.GeometryFile()
geometry_file.geometry = geometry
geometry_file.export_to_xml()
geometry.export_to_xml()


###############################################################################
# Exporting to OpenMC settings.xml File
###############################################################################

# Instantiate a SettingsFile, set all runtime parameters, and export to XML
settings_file = openmc.SettingsFile()
# Instantiate a Settings, set all runtime parameters, and export to XML
settings_file = openmc.Settings()
settings_file.energy_mode = "multi-group"
settings_file.cross_sections = "./mg_cross_sections.xml"
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.output = {'tallies': True, 'summary': True}
settings_file.source = Source(space=Box([-32.13, -10.71, -1.0],
[10.71, 32.13, 1.0]))
settings_file.source = openmc.Source(space=openmc.stats.Box(
[-32.13, -10.71, -1.0], [10.71, 32.13, 1.0]))
settings_file.entropy_lower_left = [-32.13, -32.13, -1.E50]
settings_file.entropy_upper_right = [32.13, 32.13, 1.E50]
settings_file.entropy_dimension = [51, 51, 1]
Expand All @@ -89,20 +82,14 @@
plot_1.color = 'mat'
plot_1.basis = 'xy'

# Instantiate a PlotsFile, add Plot, and export to XML
plot_file = openmc.PlotsFile()
plot_file.add_plot(plot_1)
# Instantiate a Plots collection and export to XML
plot_file = openmc.Plots([plot_1])
plot_file.export_to_xml()

###############################################################################
# Exporting to OpenMC tallies.xml File
###############################################################################

# Instantiate a TalliesFile, register Tally/Mesh, and export to XML
tallies_file = openmc.TalliesFile()
tallies_file.add_mesh(mesh)

for tally in tallies.values():
tallies_file.add_tally(tally)

# Instantiate a Tallies, register Tally/Mesh, and export to XML
tallies_file = openmc.Tallies(tallies.values())
tallies_file.export_to_xml()
37 changes: 12 additions & 25 deletions c5g7/openmc/3d/build-xml-3d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import openmc
from openmc.source import Source
from openmc.stats import Box
import sys
sys.path.append('../')
from lattices import lattices, universes, cells, surfaces
Expand All @@ -22,10 +20,9 @@

from materials import materials

# Instantiate a MaterialsFile, register all Materials, and export to XML
materials_file = openmc.MaterialsFile()
# Instantiate a Materials collection, register all Materials, and export to XML
materials_file = openmc.Materials(materials.values())
materials_file.default_xs = '300k'
materials_file.add_materials(materials.values())
materials_file.export_to_xml()


Expand All @@ -51,29 +48,26 @@
# Add Core lattice to Core cell
cells['Core'].fill = lattices['Core']

# Instantiate a Geometry and register the root Universe
# Instantiate a Geometry, register the root Universe, and export to XML
geometry = openmc.Geometry()
geometry.root_universe = universes['Root']

# Instantiate a GeometryFile, register Geometry, and export to XML
geometry_file = openmc.GeometryFile()
geometry_file.geometry = geometry
geometry_file.export_to_xml()
geometry.export_to_xml()


###############################################################################
# Exporting to OpenMC settings.xml File
###############################################################################

# Instantiate a SettingsFile, set all runtime parameters, and export to XML
settings_file = openmc.SettingsFile()
# Instantiate a Settings, set all runtime parameters, and export to XML
settings_file = openmc.Settings()
settings_file.energy_mode = "multi-group"
settings_file.cross_sections = "./mg_cross_sections.xml"
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.output = {'tallies': True, 'summary': True}
settings_file.source = Source(space=Box([-32.13, -10.71, -107.1], [10.71, 32.13, 85.68]))
settings_file.source = openmc.Source(space=openmc.stats.Box(
[-32.13, -10.71, -107.1], [10.71, 32.13, 85.68]))
settings_file.entropy_lower_left = [-32.13, -32.13, -107.1]
settings_file.entropy_upper_right = [32.13, 32.13, 107.1]
settings_file.entropy_dimension = [51, 51, 30]
Expand All @@ -100,21 +94,14 @@
plot_2.color = 'mat'
plot_2.basis = 'xz'

# Instantiate a PlotsFile, add Plot, and export to XML
plot_file = openmc.PlotsFile()
plot_file.add_plot(plot_1)
plot_file.add_plot(plot_2)
# Instantiate a Plots collection and export to XML
plot_file = openmc.Plots([plot_1, plot_2])
plot_file.export_to_xml()

###############################################################################
# Exporting to OpenMC tallies.xml File
###############################################################################

# Instantiate a TalliesFile, register Tally/Mesh, and export to XML
tallies_file = openmc.TalliesFile()
tallies_file.add_mesh(mesh)

for tally in tallies.values():
tallies_file.add_tally(tally)

# Instantiate a Tallies collection and export to XML
tallies_file = openmc.Tallies(tallies.values())
tallies_file.export_to_xml()
2 changes: 1 addition & 1 deletion c5g7/openmc/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
control_rod_xsdata.nu_fission = np.zeros(7)
control_rod_xsdata.chi = np.zeros(7)

mg_cross_sections_file = openmc.MGXSLibraryFile(groups)
mg_cross_sections_file = openmc.MGXSLibrary(groups)
mg_cross_sections_file.add_xsdatas([uo2_xsdata, mox43_xsdata, mox7_xsdata, mox87_xsdata,
fiss_chamber_xsdata, guide_tube_xsdata, water_xsdata,
control_rod_xsdata])
Expand Down
48 changes: 15 additions & 33 deletions c5g7/openmc/pin/build-xml-pin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import openmc
from openmc.source import Source
from openmc.stats import Box
import sys
sys.path.append('../')
import cells
Expand All @@ -21,10 +19,9 @@

from materials import materials

# Instantiate a MaterialsFile, register all Materials, and export to XML
materials_file = openmc.MaterialsFile()
# Instantiate a Materials, register all Materials, and export to XML
materials_file = openmc.Materials(materials.values())
materials_file.default_xs = '300k'
materials_file.add_materials(materials.values())
materials_file.export_to_xml()


Expand All @@ -37,31 +34,26 @@
universes['Root'] = openmc.Universe(universe_id=0, name='Root')
universes['Root'].add_cells([cells.cells['UO2'], cells.cells['UO2 Pin']])

# Instantiate a Geometry and register the root Universe
# Instantiate a Geometry, register the root Universe, and export to XML
geometry = openmc.Geometry()
geometry.root_universe = universes['Root']

# Instantiate a GeometryFile, register Geometry, and export to XML
geometry_file = openmc.GeometryFile()
geometry_file.geometry = geometry
geometry_file.export_to_xml()
geometry.export_to_xml()


###############################################################################
# Exporting to OpenMC settings.xml File
###############################################################################

# Instantiate a SettingsFile, set all runtime parameters, and export to XML
settings_file = openmc.SettingsFile()
# Instantiate a Settings, set all runtime parameters, and export to XML
settings_file = openmc.Settings()
settings_file.energy_mode = "multi-group"
settings_file.cross_sections = "./mg_cross_sections.xml"
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.output = {'tallies': True, 'summary': True}
settings_file.source = Source(space=Box([-0.63,-0.63,-1.E50],
[ 0.63, 0.63, 1.E50],
only_fissionable=True))
settings_file.source = openmc.Source(space=openmc.stats.Box(
[-0.63, -0.63, -1.e50], [0.63, 0.63, 1.e50], only_fissionable=True))
settings_file.entropy_lower_left = [-0.63,-0.63,-1.E50]
settings_file.entropy_upper_right = [ 0.63, 0.63, 1.E50]
settings_file.entropy_dimension = [10,10,1]
Expand All @@ -80,9 +72,8 @@
plot_1.color = 'mat'
plot_1.basis = 'xy'

# Instantiate a PlotsFile, add Plot, and export to XML
plot_file = openmc.PlotsFile()
plot_file.add_plot(plot_1)
# Instantiate a Plots collection and export to XML
plot_file = openmc.PlotsFile([plot_1])
plot_file.export_to_xml()

###############################################################################
Expand All @@ -105,21 +96,12 @@

# Instantiate the Tally
tallies['Mesh Rates'] = openmc.Tally(tally_id=1, name='tally 1')
tallies['Mesh Rates'].add_filter(mesh_filter)
tallies['Mesh Rates'].add_score('flux')
tallies['Mesh Rates'].add_score('fission')
tallies['Mesh Rates'].add_score('nu-fission')
tallies['Mesh Rates'].filters = [mesh_filter]
tallies['Mesh Rates'].scores = ['flux', 'fission', 'nu-fission']

tallies['Global Rates'] = openmc.Tally(tally_id=2, name='tally 2')
tallies['Global Rates'].add_score('flux')
tallies['Global Rates'].add_score('fission')
tallies['Global Rates'].add_score('nu-fission')

# Instantiate a TalliesFile, register Tally/Mesh, and export to XML
tallies_file = openmc.TalliesFile()
tallies_file.add_mesh(mesh)

for tally in tallies.values():
tallies_file.add_tally(tally)
tallies['Global Rates'].scores = ['flux', 'fission', 'nu-fission']

# Instantiate a Tallies collection and export to XML
tallies_file = openmc.Tallies(tallies.values())
tallies_file.export_to_xml()
37 changes: 12 additions & 25 deletions c5g7/openmc/rodded-A/build-xml-rodded-A.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import openmc
from openmc.source import Source
from openmc.stats import Box
import sys
sys.path.append('../')
from lattices import lattices, universes, cells, surfaces
Expand All @@ -22,10 +20,9 @@

from materials import materials

# Instantiate a MaterialsFile, register all Materials, and export to XML
materials_file = openmc.MaterialsFile()
# Instantiate a Materials collection and export to XML
materials_file = openmc.Materials(materials.values())
materials_file.default_xs = '300k'
materials_file.add_materials(materials.values())
materials_file.export_to_xml()


Expand Down Expand Up @@ -55,29 +52,26 @@
# Add Core lattice to Core cell
cells['Core'].fill = lattices['Core']

# Instantiate a Geometry and register the root Universe
# Instantiate a Geometry, register the root Universe, and export to XML
geometry = openmc.Geometry()
geometry.root_universe = universes['Root']

# Instantiate a GeometryFile, register Geometry, and export to XML
geometry_file = openmc.GeometryFile()
geometry_file.geometry = geometry
geometry_file.export_to_xml()
geometry.export_to_xml()


###############################################################################
# Exporting to OpenMC settings.xml File
###############################################################################

# Instantiate a SettingsFile, set all runtime parameters, and export to XML
settings_file = openmc.SettingsFile()
# Instantiate a Settings, set all runtime parameters, and export to XML
settings_file = openmc.Settings()
settings_file.energy_mode = "multi-group"
settings_file.cross_sections = "./mg_cross_sections.xml"
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
settings_file.output = {'tallies': True, 'summary': True}
settings_file.source = Source(space=Box([-32.13, -10.71, -107.1], [10.71, 32.13, 85.68]))
settings_file.source = openmc.Source(space=openmc.stats.Box(
[-32.13, -10.71, -107.1], [10.71, 32.13, 85.68]))
settings_file.entropy_lower_left = [-32.13, -32.13, -107.1]
settings_file.entropy_upper_right = [32.13, 32.13, 107.1]
settings_file.entropy_dimension = [51, 51, 30]
Expand All @@ -104,21 +98,14 @@
plot_2.color = 'mat'
plot_2.basis = 'xz'

# Instantiate a PlotsFile, add Plot, and export to XML
plot_file = openmc.PlotsFile()
plot_file.add_plot(plot_1)
plot_file.add_plot(plot_2)
# Instantiate a Plots collection and export to XML
plot_file = openmc.Plots([plot_1, plot_2])
plot_file.export_to_xml()

###############################################################################
# Exporting to OpenMC tallies.xml File
###############################################################################

# Instantiate a TalliesFile, register Tally/Mesh, and export to XML
tallies_file = openmc.TalliesFile()
tallies_file.add_mesh(mesh)

for tally in tallies.values():
tallies_file.add_tally(tally)

# Instantiate a Tallies and export to XML
tallies_file = openmc.Tallies(tallies.values())
tallies_file.export_to_xml()
Loading

0 comments on commit 468e49c

Please sign in to comment.