diff --git a/examples/serialized_custom_source/build_xml.py b/examples/serialized_custom_source/build_xml.py new file mode 100644 index 0000000000..fba5459598 --- /dev/null +++ b/examples/serialized_custom_source/build_xml.py @@ -0,0 +1,46 @@ +import openmc + +# Define the serialised source +serialized_source = """ + 1.5 + 1e3 + +""" +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()