<jupyter_start><jupyter_text>Neutronics simulation with CAD geometryThis example creates a CAD geometry and then carries out a neutronics simulation with a heating cell tally. This section makes a few components and places them in a reactor object. These will form the CAD model with which we will perform a neutronics simulation.<jupyter_code>import paramak

plasma = paramak.Plasma(
    minor_radius=150.,
    major_radius=450.,
    triangularity=0.55,
    elongation=2.,
    rotation_angle=270
)

blanket = paramak.BlanketFP(
    plasma=plasma,
    thickness=50,
    stop_angle=90,
    start_angle=-90,
    offset_from_plasma=40,
    rotation_angle=270,
)
!rm blanket.stl
my_reactor = paramak.Reactor([plasma, blanket])
my_reactor.export_stl(['plasma.stl', 'blanket.stl'])
my_reactor.show()<jupyter_output><empty_output><jupyter_text>This section forms the neutronics model by combining the 3D model, the plasma source and some assigned materials. Additionally, the tallies to record the heating are specified. There are a few different methods of converting a CAD model into a neutronics model. Each method has pros and cons.The rector can also be converted from stl or stp to h5m format which is the 3D geometry format used by DAGMC to represent neutronics geometry.stl-to-h5m can convert stl files to a h5m geometryhttps://github.com/fusion-energy/stl_to_h5mcad-to-h5m can convert stp files to h5m geometryhttps://github.com/fusion-energy/cad_to_h5m<jupyter_code>from stl_to_h5m import stl_to_h5m
!rm dagmc.h5m
stl_to_h5m(
    files_with_tags=[
        ('blanket.stl', 'blanket'),
    ],
    h5m_filename='dagmc.h5m',
)<jupyter_output><empty_output><jupyter_text>The model can now be simulated in OpenMC. OpenMC is imported along with some convenience packages<jupyter_code>import openmc
import openmc_dagmc_wrapper as odw
import openmc_plasma_source as ops<jupyter_output><empty_output><jupyter_text>The following code 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).<jupyter_code># this links the material tags in the dagmc h5m file with materials.
# these materials are input as strings so they will be looked up in the
# neutronics material maker package
material_tag_to_material_dict = {
    'blanket':'Li4SiO4',
}

geometry = odw.Geometry(h5m_filename='dagmc.h5m')

materials = odw.Materials(
    h5m_filename='dagmc.h5m',
    correspondence_dict=material_tag_to_material_dict
)

tally1 = odw.CellTally(
    tally_type="heating",
    target="blanket",
    materials=materials
)

tallies = openmc.Tallies([tally1])

# odw.FusionSettings is the same as openmc.settings but it just sets the mode to fixed source and inactive batches to zero
settings = odw.FusionSettings()
settings.batches = 1
settings.particles = 100

# assigns a ring source of DT energy neutrons to the source using the
# openmc_plasma_source package
settings.source = ops.FusionRingSource(fuel="DT", radius=350)

my_model = openmc.Model(
    materials=materials, geometry=geometry, settings=settings, tallies=tallies
)

# delete old files just in case they are there
!rm summary.h5
!rm statepoint*.h5

# starts the simulation and gets the filename of the output file produced
statepoint_file = my_model.run()<jupyter_output><empty_output><jupyter_text>Extracting the resulting tally value from the statepoint file<jupyter_code>sp = openmc.StatePoint(statepoint_file)

heating_tally = sp.get_tally(name='blanket_heating')

# this returns the tally in unknown base units
heating_tally.get_values().sum()<jupyter_output><empty_output><jupyter_text>This next cell just imports a post processing package and uses that package to find the units of the tally<jupyter_code>import openmc_tally_unit_converter as otuc

tally = otuc.process_tally(
    heating_tally,
)
# this prints the tally with base units identified
print(tally)<jupyter_output><empty_output><jupyter_text>Converts the units from the base units (eV/simulated particle) to MeV/simulated particle<jupyter_code>otuc.process_tally(
    heating_tally,
    required_units="MeV/source_particle"
)<jupyter_output><empty_output><jupyter_text>Converts units by normalising by the source strength (number of nuetrons per second)<jupyter_code>otuc.process_tally(
    heating_tally,
    required_units="gigawatts",
    source_strength=1e21
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07290264692687304, 'fraction_numerical': 0.013683266038582324, 'mean_word_length': 5.655223880597015, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '166272', 'license': 'MIT', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1404, 'n_words': 434, 'path': 'tasks/task_11_CAD_cell_tally_heat/1_simulate_CAD_neutronics_geometry_with_cell_tally_heat.ipynb', 'repo_name': 'fusion-energy/neutronics-workshop', 'size': '4458'}