Refactored examples into xml and python subdirectories. Implemented basic using Python API

This commit is contained in:
Will Boyd 2014-10-13 09:11:28 -04:00
parent 6f4131ded4
commit b0e5c88b57
40 changed files with 541 additions and 2 deletions

View file

@ -0,0 +1,141 @@
import openmc
###############################################################################
# Simulation Input File Parameters
###############################################################################
# OpenMC simulation parameters
batches = 15
inactive = 5
particles = 10000
###############################################################################
# Exporting to OpenMC materials.xml File
###############################################################################
# Instantiate some Nuclides
h1 = openmc.Nuclide('H-1')
o16 = openmc.Nuclide('O-16')
u235 = openmc.Nuclide('U-235')
# Instantiate some Materials and register the appropriate Nuclides
moderator = openmc.Material(material_id=41, name='moderator')
moderator.setDensity('g/cc', 1.0)
moderator.addNuclide(h1, 2.)
moderator.addNuclide(o16, 1.)
moderator.addSAlphaBeta('HH2O', '71t')
fuel = openmc.Material(material_id=40, name='fuel')
fuel.setDensity('g/cc', 4.5)
fuel.addNuclide(u235, 1.)
# Instantiate a MaterialsFile, register all Materials, and export to XML
materials_file = openmc.MaterialsFile()
materials_file.setDefaultXS('71c')
materials_file.addMaterials([moderator, fuel])
materials_file.exportToXML()
###############################################################################
# Exporting to OpenMC geometry.xml File
###############################################################################
# Instantiate ZCylinder surfaces
surf1 = openmc.ZCylinder(surface_id=1, x0=0, y0=0, R=7, name='surf 1')
surf2 = openmc.ZCylinder(surface_id=2, x0=0, y0=0, R=9, name='surf 2')
surf3 = openmc.ZCylinder(surface_id=3, x0=0, y0=0, R=11, name='surf 3')
surf3.setBoundaryType('vacuum')
# Instantiate Cells
cell1 = openmc.Cell(cell_id=1, name='cell 1')
cell2 = openmc.Cell(cell_id=100, name='cell 2')
cell3 = openmc.Cell(cell_id=101, name='cell 3')
cell4 = openmc.Cell(cell_id=2, name='cell 4')
# Register Surfaces with Cells
cell1.addSurface(surface=surf2, halfspace=-1)
cell2.addSurface(surface=surf1, halfspace=-1)
cell3.addSurface(surface=surf1, halfspace=+1)
cell4.addSurface(surface=surf2, halfspace=+1)
cell4.addSurface(surface=surf3, halfspace=-1)
# Register Materials with Cells
cell2.setFill(fuel)
cell3.setFill(moderator)
cell4.setFill(moderator)
# Instantiate Universes
universe1 = openmc.Universe(universe_id=37)
root = openmc.Universe(universe_id=0, name='root universe')
cell1.setFill(universe1)
# Register Cells with Universes
universe1.addCells([cell2, cell3])
root.addCells([cell1, cell4])
# Instantiate a Geometry and register the root Universe
geometry = openmc.Geometry()
geometry.setRootUniverse(root)
# Instantiate a GeometryFile, register Geometry, and export to XML
geometry_file = openmc.GeometryFile()
geometry_file.setGeometry(geometry)
geometry_file.exportToXML()
###############################################################################
# Exporting to OpenMC settings.xml File
###############################################################################
# Instantiate a SettingsFile, set all runtime parameters, and export to XML
settings_file = openmc.SettingsFile()
settings_file.setBatches(batches)
settings_file.setInactive(inactive)
settings_file.setParticles(particles)
settings_file.setSourceSpace('box', [-4, -4, -4, 4, 4, 4])
settings_file.exportToXML()
###############################################################################
# Exporting to OpenMC tallies.xml File
###############################################################################
# Instantiate some tally Filters
cell_filter = openmc.Filter(type='cell', bins=100)
energy_filter = openmc.Filter(type='energy', bins=[0., 20.])
energyout_filter = openmc.Filter(type='energyout', bins=[0., 20.])
# Instantiate the first Tally
first_tally = openmc.Tally(tally_id=1, label='first tally')
first_tally.addFilter(cell_filter)
scores = ['total', 'scatter', 'nu-scatter', \
'absorption', 'fission', 'nu-fission']
for score in scores:
first_tally.addScore(score)
# Instantiate the second Tally
second_tally = openmc.Tally(tally_id=2, label='second tally')
second_tally.addFilter(cell_filter)
second_tally.addFilter(energy_filter)
scores = ['total', 'scatter', 'nu-scatter', \
'absorption', 'fission', 'nu-fission']
for score in scores:
second_tally.addScore(score)
# Instantiate the third Tally
third_tally = openmc.Tally(tally_id=3, label='third tally')
third_tally.addFilter(cell_filter)
third_tally.addFilter(energy_filter)
third_tally.addFilter(energyout_filter)
scores = ['scatter', 'nu-scatter', 'nu-fission']
for score in scores:
third_tally.addScore(score)
# Instantiate a TalliesFile, register all Tallies, and export to XML
tallies_file = openmc.TalliesFile()
tallies_file.addTally(first_tally)
tallies_file.addTally(second_tally)
tallies_file.addTally(third_tally)
tallies_file.exportToXML()

View file

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<geometry>
<cell id="1" fill="6" surfaces="1 -2 3 -4" />
<cell id="2" universe="5" fill="4" surfaces="1 -2 3 -4" />
<cell id="101" universe="1" material="1" surfaces="-5" />
<cell id="102" universe="1" material="2" surfaces="5" />
<cell id="201" universe="2" material="1" surfaces="-6" />
<cell id="202" universe="2" material="2" surfaces="6" />
<cell id="301" universe="3" material="1" surfaces="-7" />
<cell id="302" universe="3" material="2" surfaces="7" />
<!-- 4 x 4 assembly -->
<lattice id="4">
<type>rectangular</type>
<dimension>2 2</dimension>
<lower_left>-1.0 -1.0</lower_left>
<width>1.0 1.0</width>
<universes>
1 2
2 3
</universes>
</lattice>
<!-- 4 x 4 core -->
<lattice id="6">
<type>rectangular</type>
<dimension>2 2</dimension>
<lower_left>-2.0 -2.0</lower_left>
<width>2.0 2.0</width>
<universes>
5 5
5 5
</universes>
</lattice>
<surface id="1" type="x-plane" coeffs="-2.0" boundary="vacuum" />
<surface id="2" type="x-plane" coeffs="2.0" boundary="vacuum" />
<surface id="3" type="y-plane" coeffs="-2.0" boundary="vacuum" />
<surface id="4" type="y-plane" coeffs="2.0" boundary="vacuum" />
<surface id="5" type="z-cylinder" coeffs="0.0 0.0 0.4" />
<surface id="6" type="z-cylinder" coeffs="0.0 0.0 0.3" />
<surface id="7" type="z-cylinder" coeffs="0.0 0.0 0.2" />
</geometry>

View file

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<materials>
<default_xs>71c</default_xs>
<!-- Definition of materials -->
<material id="1">
<density value="4.5" units="g/cc" />
<nuclide name="U-235" ao="1.0" />
</material>
<material id="2">
<density value="1.0" units="g/cc" />
<nuclide name="H-1" ao="2.0" />
<nuclide name="O-16" ao="1.0" />
<sab name="HH2O" xs="71t" />
</material>
</materials>

View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<plots>
<plot id="1" color="mat">
<origin>0. 0. 0.</origin>
<width>4.0 4.0</width>
<pixels>400 400</pixels>
</plot>
</plots>

View file

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<settings>
<!-- Parameters for k-eigenvalue calculation -->
<eigenvalue>
<batches>20</batches>
<inactive>10</inactive>
<particles>10000</particles>
</eigenvalue>
<!-- Starting source -->
<source>
<space type="box">
<parameters>-1 -1 -1 1 1 1</parameters>
</space>
</source>
</settings>

View file

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<tallies>
<mesh id="1">
<type>rectangular</type>
<dimension>4 4</dimension>
<lower_left>-2.0 -2.0</lower_left>
<width>1.0 1.0</width>
</mesh>
<tally id="1">
<filter type="mesh" bins="1" />
<scores>total</scores>
</tally>
</tallies>

View file

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<geometry>
<cell id="1" fill="5" surfaces="1 -2 3 -4" />
<cell id="101" universe="1" material="1" surfaces="-5" />
<cell id="102" universe="1" material="2" surfaces="5" />
<cell id="201" universe="2" material="1" surfaces="-6" />
<cell id="202" universe="2" material="2" surfaces="6" />
<cell id="301" universe="3" material="1" surfaces="-7" />
<cell id="302" universe="3" material="2" surfaces="7" />
<lattice id="5">
<type>rectangular</type>
<dimension>4 4</dimension>
<lower_left>-2.0 -2.0</lower_left>
<width>1.0 1.0</width>
<universes>
1 2 1 2
2 3 2 3
1 2 1 2
2 3 2 3
</universes>
</lattice>
<surface id="1" type="x-plane" coeffs="-2.0" boundary="vacuum" />
<surface id="2" type="x-plane" coeffs="2.0" boundary="vacuum" />
<surface id="3" type="y-plane" coeffs="-2.0" boundary="vacuum" />
<surface id="4" type="y-plane" coeffs="2.0" boundary="vacuum" />
<surface id="5" type="z-cylinder" coeffs="0.0 0.0 0.4" />
<surface id="6" type="z-cylinder" coeffs="0.0 0.0 0.3" />
<surface id="7" type="z-cylinder" coeffs="0.0 0.0 0.2" />
</geometry>

View file

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<materials>
<default_xs>71c</default_xs>
<!-- Definition of materials -->
<material id="1">
<density value="4.5" units="g/cc" />
<nuclide name="U-235" ao="1.0" />
</material>
<material id="2">
<density value="1.0" units="g/cc" />
<nuclide name="H-1" ao="2.0" />
<nuclide name="O-16" ao="1.0" />
<sab name="HH2O" xs="71t" />
</material>
</materials>

View file

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<plots>
<plot id="1" color="mat">
<origin>0. 0. 0.</origin>
<width>4.0 4.0</width>
<pixels>400 400</pixels>
<!-- <meshlines mesh="1" linewidth="2" color="0 255 0"/> -->
</plot>
</plots>

View file

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<settings>
<!-- Parameters for k-eigenvalue calculation -->
<eigenvalue>
<batches>20</batches>
<inactive>10</inactive>
<particles>10000</particles>
</eigenvalue>
<!-- Starting source -->
<source>
<space type="box">
<parameters>-1 -1 -1 1 1 1</parameters>
</space>
</source>
</settings>

View file

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<tallies>
<mesh id="1">
<type>rectangular</type>
<dimension>4 4</dimension>
<lower_left>-2.0 -2.0</lower_left>
<width>1.0 1.0</width>
</mesh>
<tally id="1">
<filter type="mesh" bins="1" />
<scores>total</scores>
</tally>
</tallies>

View file

@ -0,0 +1,27 @@
<?xml version="1.0"?>
<geometry>
<!--
This is a simple pin cell model based on dimensions from the MIT BEAVRS
(Benchmarking for Evaluation and Validation of Reactor Simulations)
benchmark.
-->
<!-- Surfaces for fuel, gap, cladding. Dimensions from Figure 2 in BEAVRS -->
<surface id="1" type="z-cylinder" coeffs="0. 0. 0.39218" /> <!-- Fuel OR -->
<surface id="2" type="z-cylinder" coeffs="0. 0. 0.40005" /> <!-- Clad IR -->
<surface id="3" type="z-cylinder" coeffs="0. 0. 0.45720" /> <!-- Clad OR -->
<!-- Reflective surfaces on outside of pin-cell. The lattice pitch is 1.25984
cm (taken from Table 2 in BEAVRS). -->
<surface id="4" type="x-plane" coeffs="-0.62992" boundary="reflective" />
<surface id="5" type="x-plane" coeffs=" 0.62992" boundary="reflective" />
<surface id="6" type="y-plane" coeffs="-0.62992" boundary="reflective" />
<surface id="7" type="y-plane" coeffs=" 0.62992" boundary="reflective" />
<cell id="1" material="1" surfaces=" -1" /> <!-- UO2 Fuel -->
<cell id="2" material="2" surfaces="1 -2" /> <!-- Helium gap -->
<cell id="3" material="3" surfaces="2 -3" /> <!-- Zircaloy cladding -->
<cell id="4" material="4" surfaces="3 4 -5 6 -7" /> <!-- Borated water -->
</geometry>

View file

@ -0,0 +1,70 @@
<?xml version="1.0"?>
<materials>
<!-- By default, use 300K cross sections -->
<default_xs>71c</default_xs>
<!--
Since O-18 is not present in ENDF/B-VII, it was necessary to combine the
atom densities for O-17 and O-18 in any materials containing Oxygen.
-->
<!-- UO2 fuel at 2.4 wt% enrichment -->
<material id="1">
<density value="10.29769" units="g/cm3" />
<nuclide name="U-234" ao="4.4843e-06" />
<nuclide name="U-235" ao="5.5815e-04" />
<nuclide name="U-238" ao="2.2408e-02" />
<nuclide name="O-16" ao="4.5829e-02" />
<nuclide name="O-17" ao="1.1164e-04" />
</material>
<!-- Helium for gap -->
<material id="2">
<density value="0.001598" units="g/cm3" />
<nuclide name="He-4" ao="2.4044e-04" />
</material>
<!-- Zircaloy 4 -->
<material id="3">
<density value="6.55" units="g/cm3" />
<nuclide name="O-16" ao="3.0743e-04" />
<nuclide name="O-17" ao="7.4887e-07" />
<nuclide name="Cr-50" ao="3.2962e-06" />
<nuclide name="Cr-52" ao="6.3564e-05" />
<nuclide name="Cr-53" ao="7.2076e-06" />
<nuclide name="Cr-54" ao="1.7941e-06" />
<nuclide name="Fe-54" ao="8.6699e-06" />
<nuclide name="Fe-56" ao="1.3610e-04" />
<nuclide name="Fe-57" ao="3.1431e-06" />
<nuclide name="Fe-58" ao="4.1829e-07" />
<nuclide name="Zr-90" ao="2.1827e-02" />
<nuclide name="Zr-91" ao="4.7600e-03" />
<nuclide name="Zr-92" ao="7.2758e-03" />
<nuclide name="Zr-94" ao="7.3734e-03" />
<nuclide name="Zr-96" ao="1.1879e-03" />
<nuclide name="Sn-112" ao="4.6735e-06" />
<nuclide name="Sn-114" ao="3.1799e-06" />
<nuclide name="Sn-115" ao="1.6381e-06" />
<nuclide name="Sn-116" ao="7.0055e-05" />
<nuclide name="Sn-117" ao="3.7003e-05" />
<nuclide name="Sn-118" ao="1.1669e-04" />
<nuclide name="Sn-119" ao="4.1387e-05" />
<nuclide name="Sn-120" ao="1.5697e-04" />
<nuclide name="Sn-122" ao="2.2308e-05" />
<nuclide name="Sn-124" ao="2.7897e-05" />
</material>
<!-- Borated water at 975 ppm -->
<material id="4">
<density value="0.740582" units="g/cm3" />
<nuclide name="B-10" ao="8.0042e-06" />
<nuclide name="B-11" ao="3.2218e-05" />
<nuclide name="H-1" ao="4.9457e-02" />
<nuclide name="H-2" ao="7.4196e-06" />
<nuclide name="O-16" ao="2.4672e-02" />
<nuclide name="O-17" ao="6.0099e-05" />
<sab name="HH2O" xs="71t" />
</material>
</materials>

View file

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<settings>
<!-- Define how many particles to run and for how many batches -->
<eigenvalue>
<batches>100</batches>
<inactive>10</inactive>
<particles>1000</particles>
</eigenvalue>
<!-- The starting source is a uniform distribution over the entire pin
cell. Note that since this is effectively a 2D model, the z coordinates
are inconsequential -->
<source>
<space type="box">
<parameters>
-0.62992 -0.62992 -1.
0.62992 0.62992 1.
</parameters>
</space>
</source>
<!-- To assess convergence of the source distribution, we need to define the
bounds for a mesh over which the Shannon entropy should be
calculated. The extent in the z direction is made arbitrarily large. -->
<entropy>
<lower_left>-0.39218 -0.39218 -1.e50</lower_left>
<upper_right>0.39218 0.39218 1.e50</upper_right>
<dimension>10 10 1</dimension>
</entropy>
</settings>

View file

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<tallies>
<mesh id="1" type="rectangular">
<dimension>100 100 1</dimension>
<lower_left>-0.62992 -0.62992 -1.e50</lower_left>
<upper_right>0.62992 0.62992 1.e50</upper_right>
</mesh>
<tally id="1">
<filter type="mesh" bins="1" />
<filter type="energy" bins="0. 4.e-6 20.0" />
<scores>flux fission nu-fission</scores>
</tally>
</tallies>

View file

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<geometry>
<!-- Definition of Cells -->
<cell id="1">
<universe>0</universe>
<material>1</material>
<surfaces>1 -2 3 -4 5 -6</surfaces>
</cell>
<!-- Defition of Surfaces -->
<surface id="1" type="x-plane" coeffs="-1" boundary="vacuum" />
<surface id="2" type="x-plane" coeffs="1" boundary="vacuum" />
<surface id="3" type="y-plane" coeffs="-1" boundary="reflective" />
<surface id="4" type="y-plane" coeffs="1" boundary="reflective" />
<surface id="5" type="z-plane" coeffs="-1" boundary="reflective" />
<surface id="6" type="z-plane" coeffs="1" boundary="reflective" />
</geometry>

View file

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<materials>
<default_xs>71c</default_xs>
<material id="1">
<density value="4.5" units="g/cc" />
<nuclide name="U-235" ao="1.0" />
</material>
</materials>

View file

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<settings>
<!-- Parameters for k-eigenvalue calculation -->
<eigenvalue>
<batches>500</batches>
<inactive>10</inactive>
<particles>10000</particles>
</eigenvalue>
<!-- Starting source -->
<source>
<space type="box">
<parameters>-1 -1 -1 1 1 1</parameters>
</space>
</source>
</settings>