mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Update build_xml to use serialization
File is largely based on the existing custom_source example. Uses the serialization attribute on the source to point to an XML file containing the serialized representation of the source. Also builds the serialized_source.xml file with some default values. Uses a new name for the library containing the serializable source.
This commit is contained in:
parent
61cf4f71a9
commit
1b60181ddb
1 changed files with 46 additions and 0 deletions
46
examples/serialized_custom_source/build_xml.py
Normal file
46
examples/serialized_custom_source/build_xml.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import openmc
|
||||
|
||||
# Define the serialised source
|
||||
serialized_source = """<Source>
|
||||
<Radius>1.5</Radius>
|
||||
<Energy>1e3</Energy>
|
||||
</Source>
|
||||
"""
|
||||
with open('serialized_source.xml', 'w') as f:
|
||||
f.write(serialized_source)
|
||||
|
||||
# Create a single material
|
||||
iron = openmc.Material()
|
||||
iron.set_density('g/cm3', 5.0)
|
||||
iron.add_element('Fe', 1.0)
|
||||
mats = openmc.Materials([iron])
|
||||
mats.export_to_xml()
|
||||
|
||||
# Create a 5 cm x 5 cm box filled with iron
|
||||
box = openmc.model.rectangular_prism(10.0, 10.0, boundary_type='vacuum')
|
||||
cell = openmc.Cell(fill=iron, region=box)
|
||||
geometry = openmc.Geometry([cell])
|
||||
geometry.export_to_xml()
|
||||
|
||||
# Tell OpenMC we're going to use our custom source
|
||||
settings = openmc.Settings()
|
||||
settings.run_mode = 'fixed source'
|
||||
settings.batches = 10
|
||||
settings.particles = 1000
|
||||
source = openmc.Source()
|
||||
source.library = 'build/libserialized_source.so'
|
||||
source.serialization = 'serialized_source.xml'
|
||||
settings.source = source
|
||||
settings.export_to_xml()
|
||||
|
||||
# Finally, define a mesh tally so that we can see the resulting flux
|
||||
mesh = openmc.RegularMesh()
|
||||
mesh.lower_left = (-5.0, -5.0)
|
||||
mesh.upper_right = (5.0, 5.0)
|
||||
mesh.dimension = (50, 50)
|
||||
|
||||
tally = openmc.Tally()
|
||||
tally.filters = [openmc.MeshFilter(mesh)]
|
||||
tally.scores = ['flux']
|
||||
tallies = openmc.Tallies([tally])
|
||||
tallies.export_to_xml()
|
||||
Loading…
Add table
Add a link
Reference in a new issue