<jupyter_start><jupyter_text>Modeling a Pin-CellThis notebook is intended to demonstrate the basic features of the Python API for constructing input files and running OpenMC. In it, we will show how to create a basic reflective pin-cell model that is equivalent to modeling an infinite array of fuel pins. If you have never used OpenMC, this can serve as a good starting point to learn the Python API. We highly recommend having a copy of the [Python API reference documentation](https://docs.openmc.org/en/stable/pythonapi/index.html) open in another browser tab that you can refer to.<jupyter_code>%matplotlib inline
import openmc<jupyter_output><empty_output><jupyter_text>Defining MaterialsMaterials in OpenMC are defined as a set of nuclides with specified atom/weight fractions. To begin, we will create a material by making an instance of the `Material` class. In OpenMC, many objects, including materials, are identified by a "unique ID" that is simply just a positive integer. These IDs are used when exporting XML files that the solver reads in. They also appear in the output and can be used for identification. Since an integer ID is not very useful by itself, you can also give a material a `name` as well.<jupyter_code>uo2 = openmc.Material(1, "uo2")
print(uo2)<jupyter_output>Material
	ID             =	1
	Name           =	uo2
	Temperature    =	None
	Density        =	None [sum]
	S(a,b) Tables  
	Nuclides<jupyter_text>On the XML side, you have no choice but to supply an ID. However, in the Python API, if you don't give an ID, one will be automatically generated for you:<jupyter_code>mat = openmc.Material()
print(mat)<jupyter_output>Material
	ID             =	2
	Name           =	
	Temperature    =	None
	Density        =	None [sum]
	S(a,b) Tables  
	Nuclides<jupyter_text>We see that an ID of 2 was automatically assigned. Let's now move on to adding nuclides to our `uo2` material. The `Material` object has a method `add_nuclide()` whose first argument is the name of the nuclide and second argument is the atom or weight fraction.<jupyter_code>help(uo2.add_nuclide)<jupyter_output>Help on method add_nuclide in module openmc.material:

add_nuclide(nuclide, percent, percent_type='ao') method of openmc.material.Material instance
    Add a nuclide to the material
    
    Parameters
    ----------
    nuclide : str
        Nuclide to add, e.g., 'Mo95'
    percent : float
        Atom or weight percent
    percent_type : {'ao', 'wo'}
        'ao' for atom percent and 'wo' for weight percent<jupyter_text>We see that by default it assumes we want an atom fraction.<jupyter_code># Add nuclides to uo2
uo2.add_nuclide('U235', 0.03)
uo2.add_nuclide('U238', 0.97)
uo2.add_nuclide('O16', 2.0)<jupyter_output><empty_output><jupyter_text>Now we need to assign a total density to the material. We'll use the `set_density` for this.<jupyter_code>uo2.set_density('g/cm3', 10.0)<jupyter_output><empty_output><jupyter_text>You may sometimes be given a material specification where all the nuclide densities are in units of atom/b-cm. In this case, you just want the density to be the sum of the constituents. In that case, you can simply run `mat.set_density('sum')`.With UO2 finished, let's now create materials for the clad and coolant. Note the use of `add_element()` for zirconium.<jupyter_code>zirconium = openmc.Material(name="zirconium")
zirconium.add_element('Zr', 1.0)
zirconium.set_density('g/cm3', 6.6)

water = openmc.Material(name="h2o")
water.add_nuclide('H1', 2.0)
water.add_nuclide('O16', 1.0)
water.set_density('g/cm3', 1.0)<jupyter_output><empty_output><jupyter_text>An astute observer might now point out that this water material we just created will only use free-atom cross sections. We need to tell it to use an $S(\alpha,\beta)$ table so that the bound atom cross section is used at thermal energies. To do this, there's an `add_s_alpha_beta()` method. Note the use of the GND-style name "c_H_in_H2O".<jupyter_code>water.add_s_alpha_beta('c_H_in_H2O')<jupyter_output><empty_output><jupyter_text>When we go to run the transport solver in OpenMC, it is going to look for a `materials.xml` file. Thus far, we have only created objects in memory. To actually create a `materials.xml` file, we need to instantiate a `Materials` collection and export it to XML.<jupyter_code>materials = openmc.Materials([uo2, zirconium, water])<jupyter_output><empty_output><jupyter_text>Note that `Materials` is actually a subclass of Python's built-in `list`, so we can use methods like `append()`, `insert()`, `pop()`, etc.<jupyter_code>materials = openmc.Materials()
materials.append(uo2)
materials += [zirconium, water]
isinstance(materials, list)<jupyter_output><empty_output><jupyter_text>Finally, we can create the XML file with the `export_to_xml()` method. In a Jupyter notebook, we can run a shell command by putting `!` before it, so in this case we are going to display the `materials.xml` file that we created.<jupyter_code>materials.export_to_xml()
!cat materials.xml<jupyter_output><?xml version='1.0' encoding='utf-8'?>
<materials>
  <material depletable="true" id="1" name="uo2">
    <density units="g/cm3" value="10.0" />
    <nuclide ao="0.03" name="U235" />
    <nuclide ao="0.97" name="U238" />
    <nuclide ao="2.0" name="O16" />
  </material>
  <material id="3" name="zirconium">
    <density units="g/cm3" value="6.6" />
    <nuclide ao="0.5145" name="Zr90" />
    <nuclide ao="0.1122" name="Zr91" />
    <nuclide ao="0.1715" name="Zr92" />
    <nuclide ao="0.1738" name="Zr94" />
    <nuclide ao="0.028" name="Zr96" />
  </material>
  <material id="4" name="h2o">
    <density units="g/cm3" value="1.0" />
    <nuclide ao="2.0" name="H1" />
    <nuclide ao="1.0" name="O16" />
    <sab name="c_H_in_H2O" />
  </material>
</materials><jupyter_text>Element ExpansionDid you notice something really cool that happened to our Zr element? OpenMC automatically turned it into a list of nuclides when it exported it! The way this feature works is as follows:- First, it checks whether `Materials.cross_sections` has been set, indicating the path to a `cross_sections.xml` file.- If `Materials.cross_sections` isn't set, it looks for the `OPENMC_CROSS_SECTIONS` environment variable.- If either of these are found, it scans the file to see what nuclides are actually available and will expand elements accordingly.Let's see what happens if we change O16 in water to elemental O.<jupyter_code>water.remove_nuclide('O16')
water.add_element('O', 1.0)

materials.export_to_xml()
!cat materials.xml<jupyter_output><?xml version='1.0' encoding='utf-8'?>
<materials>
  <material depletable="true" id="1" name="uo2">
    <density units="g/cm3" value="10.0" />
    <nuclide ao="0.03" name="U235" />
    <nuclide ao="0.97" name="U238" />
    <nuclide ao="2.0" name="O16" />
  </material>
  <material id="3" name="zirconium">
    <density units="g/cm3" value="6.6" />
    <nuclide ao="0.5145" name="Zr90" />
    <nuclide ao="0.1122" name="Zr91" />
    <nuclide ao="0.1715" name="Zr92" />
    <nuclide ao="0.1738" name="Zr94" />
    <nuclide ao="0.028" name="Zr96" />
  </material>
  <material id="4" name="h2o">
    <density units="g/cm3" value="1.0" />
    <nuclide ao="2.0" name="H1" />
    <nuclide ao="0.999621" name="O16" />
    <nuclide ao="0.000379" name="O17" />
    <sab name="c_H_in_H2O" />
  </material>
</materials><jupyter_text>We see that now O16 and O17 were automatically added. O18 is missing because our cross sections file (which is based on ENDF/B-VII.1) doesn't have O18. If OpenMC didn't know about the cross sections file, it would have assumed that all isotopes exist.  The `cross_sections.xml` fileThe `cross_sections.xml` tells OpenMC where it can find nuclide cross sections and $S(\alpha,\beta)$ tables. It serves the same purpose as MCNP's `xsdir` file and Serpent's `xsdata` file. As we mentioned, this can be set either by the `OPENMC_CROSS_SECTIONS` environment variable or the `Materials.cross_sections` attribute.Let's have a look at what's inside this file:<jupyter_code>!cat $OPENMC_CROSS_SECTIONS | head -n 10
print('    ...')
!cat $OPENMC_CROSS_SECTIONS | tail -n 10<jupyter_output><?xml version='1.0' encoding='utf-8'?>
<cross_sections>
  <library materials="H1" path="H1.h5" type="neutron" />
  <library materials="H2" path="H2.h5" type="neutron" />
  <library materials="H3" path="H3.h5" type="neutron" />
  <library materials="He3" path="He3.h5" type="neutron" />
  <library materials="He4" path="He4.h5" type="neutron" />
  <library materials="Li6" path="Li6.h5" type="neutron" />
  <library materials="Li7" path="Li7.h5" type="neutron" />
  <library materials="Be7" path="Be7.h5" type="neutron" />
    ...
  <library materials="Cf253" path="wmp/098253.h5" type="wmp" />
  <library materials="Cf254" path="wmp/098254.h5" type="wmp" />
  <library materials="Es251" path="wmp/099251.h5" type="wmp" />
  <library materials="Es252" path="wmp/099252.h5" type="wmp" />
  <library materials="Es253" path="wmp/099253.h5" type="wmp" />
  <library materials="Es254" path="wmp/099254.h5" type="wmp" />
  <library materials="Es254_m1" path="wmp/099254m1.h5" type="wmp" />
  <library materi[...]<jupyter_text>EnrichmentNote that the `add_element()` method has a special argument `enrichment` that can be used for Uranium. For example, if we know that we want to create 3% enriched UO2, the following would work:<jupyter_code>uo2_three = openmc.Material()
uo2_three.add_element('U', 1.0, enrichment=3.0)
uo2_three.add_element('O', 2.0)
uo2_three.set_density('g/cc', 10.0)<jupyter_output><empty_output><jupyter_text>MixturesIn OpenMC it is also possible to define materials by mixing existing materials. For example, if we wanted to create MOX fuel out of a mixture of UO2 (97 wt%) and PuO2 (3 wt%) we could do the following:<jupyter_code># Create PuO2 material
puo2 = openmc.Material()
puo2.add_nuclide('Pu239', 0.94)
puo2.add_nuclide('Pu240', 0.06)
puo2.add_nuclide('O16', 2.0)
puo2.set_density('g/cm3', 11.5)

# Create the mixture
mox = openmc.Material.mix_materials([uo2, puo2], [0.97, 0.03], 'wo')<jupyter_output><empty_output><jupyter_text>The 'wo' argument in the `mix_materials()` method specifies that the fractions are weight fractions. Materials can also be mixed by atomic and volume fractions with 'ao' and 'vo', respectively. For 'ao' and 'wo' the fractions must sum to one. For 'vo', if fractions do not sum to one, the remaining fraction is set as void.  Defining GeometryAt this point, we have three materials defined, exported to XML, and ready to be used in our model. To finish our model, we need to define the geometric arrangement of materials. OpenMC represents physical volumes using constructive solid geometry (CSG), also known as combinatorial geometry. The object that allows us to assign a material to a region of space is called a `Cell` (same concept in MCNP, for those familiar). In order to define a region that we can assign to a cell, we must first define surfaces which bound the region. A *surface* is a locus of zeros of a function of Cartesian coordinates $x$, $y$, and $z$, e.g.- A plane perpendicular to the x axis: $x - x_0 = 0$- A cylinder parallel to the z axis: $(x - x_0)^2 + (y - y_0)^2 - R^2 = 0$- A sphere: $(x - x_0)^2 + (y - y_0)^2 + (z - z_0)^2 - R^2 = 0$Between those three classes of surfaces (planes, cylinders, spheres), one can construct a wide variety of models. It is also possible to define cones and general second-order surfaces (tori are not currently supported).Note that defining a surface is not sufficient to specify a volume -- in order to define an actual volume, one must reference the half-space of a surface. A surface *half-space* is the region whose points satisfy a positive or negative inequality of the surface equation. For example, for a sphere of radius one centered at the origin, the surface equation is $f(x,y,z) = x^2 + y^2 + z^2 - 1 = 0$. Thus, we say that the negative half-space of the sphere, is defined as the collection of points satisfying $f(x,y,z) < 0$, which one can reason is the inside of the sphere. Conversely, the positive half-space of the sphere would correspond to all points outside of the sphere.Let's go ahead and create a sphere and confirm that what we've told you is true.<jupyter_code>sphere = openmc.Sphere(r=1.0)<jupyter_output><empty_output><jupyter_text>Note that by default the sphere is centered at the origin so we didn't have to supply `x0`, `y0`, or `z0` arguments. Strictly speaking, we could have omitted `R` as well since it defaults to one. To get the negative or positive half-space, we simply need to apply the `-` or `+` unary operators, respectively.(NOTE: Those unary operators are defined by special methods: `__pos__` and `__neg__` in this case).<jupyter_code>inside_sphere = -sphere
outside_sphere = +sphere<jupyter_output><empty_output><jupyter_text>Now let's see if `inside_sphere` actually contains points inside the sphere:<jupyter_code>print((0,0,0) in inside_sphere, (0,0,2) in inside_sphere)
print((0,0,0) in outside_sphere, (0,0,2) in outside_sphere)<jupyter_output>True False
False True<jupyter_text>Everything works as expected! Now that we understand how to create half-spaces, we can create more complex volumes by combining half-spaces using Boolean operators: `&` (intersection), `|` (union), and `~` (complement). For example, let's say we want to define a region that is the top part of the sphere (all points inside the sphere that have $z > 0$.<jupyter_code>z_plane = openmc.ZPlane(z0=0)
northern_hemisphere = -sphere & +z_plane<jupyter_output><empty_output><jupyter_text>For many regions, OpenMC can automatically determine a bounding box. To get the bounding box, we use the `bounding_box` property of a region, which returns a tuple of the lower-left and upper-right Cartesian coordinates for the bounding box:<jupyter_code>northern_hemisphere.bounding_box<jupyter_output><empty_output><jupyter_text>Now that we see how to create volumes, we can use them to create a cell.<jupyter_code>cell = openmc.Cell()
cell.region = northern_hemisphere

# or...
cell = openmc.Cell(region=northern_hemisphere)<jupyter_output><empty_output><jupyter_text>By default, the cell is not filled by any material (void). In order to assign a material, we set the `fill` property of a `Cell`.<jupyter_code>cell.fill = water<jupyter_output><empty_output><jupyter_text>Universes and in-line plotting A collection of cells is known as a universe (again, this will be familiar to MCNP/Serpent users) and can be used as a repeatable unit when creating a model. Although we don't need it yet, the benefit of creating a universe is that we can visualize our geometry while we're creating it.<jupyter_code>universe = openmc.Universe()
universe.add_cell(cell)

# this also works
universe = openmc.Universe(cells=[cell])<jupyter_output><empty_output><jupyter_text>The `Universe` object has a `plot` method that will display our the universe as current constructed:<jupyter_code>universe.plot(width=(2.0, 2.0))<jupyter_output><empty_output><jupyter_text>By default, the plot will appear in the $x$-$y$ plane. We can change that with the `basis` argument.<jupyter_code>universe.plot(width=(2.0, 2.0), basis='xz')<jupyter_output><empty_output><jupyter_text>If we have particular fondness for, say, fuchsia, we can tell the `plot()` method to make our cell that color.<jupyter_code>universe.plot(width=(2.0, 2.0), basis='xz',
              colors={cell: 'fuchsia'})<jupyter_output><empty_output><jupyter_text>Pin cell geometryWe now have enough knowledge to create our pin-cell. We need three surfaces to define the fuel and clad:1. The outer surface of the fuel -- a cylinder parallel to the z axis2. The inner surface of the clad -- same as above3. The outer surface of the clad -- same as aboveThese three surfaces will all be instances of `openmc.ZCylinder`, each with a different radius according to the specification.<jupyter_code>fuel_outer_radius = openmc.ZCylinder(r=0.39)
clad_inner_radius = openmc.ZCylinder(r=0.40)
clad_outer_radius = openmc.ZCylinder(r=0.46)<jupyter_output><empty_output><jupyter_text>With the surfaces created, we can now take advantage of the built-in operators on surfaces to create regions for the fuel, the gap, and the clad:<jupyter_code>fuel_region = -fuel_outer_radius
gap_region = +fuel_outer_radius & -clad_inner_radius
clad_region = +clad_inner_radius & -clad_outer_radius<jupyter_output><empty_output><jupyter_text>Now we can create corresponding cells that assign materials to these regions. As with materials, cells have unique IDs that are assigned either manually or automatically. Note that the gap cell doesn't have any material assigned (it is void by default).<jupyter_code>fuel = openmc.Cell(name='fuel')
fuel.fill = uo2
fuel.region = fuel_region

gap = openmc.Cell(name='air gap')
gap.region = gap_region

clad = openmc.Cell(name='clad')
clad.fill = zirconium
clad.region = clad_region<jupyter_output><empty_output><jupyter_text>Finally, we need to handle the coolant outside of our fuel pin. To do this, we create x- and y-planes that bound the geometry.<jupyter_code>pitch = 1.26
left = openmc.XPlane(x0=-pitch/2, boundary_type='reflective')
right = openmc.XPlane(x0=pitch/2, boundary_type='reflective')
bottom = openmc.YPlane(y0=-pitch/2, boundary_type='reflective')
top = openmc.YPlane(y0=pitch/2, boundary_type='reflective')<jupyter_output><empty_output><jupyter_text>The water region is going to be everything outside of the clad outer radius and within the box formed as the intersection of four half-spaces.<jupyter_code>water_region = +left & -right & +bottom & -top & +clad_outer_radius

moderator = openmc.Cell(name='moderator')
moderator.fill = water
moderator.region = water_region<jupyter_output><empty_output><jupyter_text>OpenMC also includes a factory function that generates a rectangular prism that could have made our lives easier.<jupyter_code>box = openmc.rectangular_prism(width=pitch, height=pitch,
                               boundary_type='reflective')
type(box)<jupyter_output><empty_output><jupyter_text>Pay attention here -- the object that was returned is NOT a surface. It is actually the intersection of four surface half-spaces, just like we created manually before. Thus, we don't need to apply the unary operator (`-box`). Instead, we can directly combine it with `+clad_or`.<jupyter_code>water_region = box & +clad_outer_radius<jupyter_output><empty_output><jupyter_text>The final step is to assign the cells we created to a universe and tell OpenMC that this universe is the "root" universe in our geometry. The `Geometry` is the final object that is actually exported to XML.<jupyter_code>root_universe = openmc.Universe(cells=(fuel, gap, clad, moderator))

geometry = openmc.Geometry()
geometry.root_universe = root_universe

# or...
geometry = openmc.Geometry(root_universe)
geometry.export_to_xml()
!cat geometry.xml<jupyter_output><?xml version='1.0' encoding='utf-8'?>
<geometry>
  <cell id="3" material="1" name="fuel" region="-3" universe="3" />
  <cell id="4" material="void" name="air gap" region="3 -4" universe="3" />
  <cell id="5" material="3" name="clad" region="4 -5" universe="3" />
  <cell id="6" material="4" name="moderator" region="6 -7 8 -9 5" universe="3" />
  <surface coeffs="0.0 0.0 0.39" id="3" type="z-cylinder" />
  <surface coeffs="0.0 0.0 0.4" id="4" type="z-cylinder" />
  <surface coeffs="0.0 0.0 0.46" id="5" type="z-cylinder" />
  <surface boundary="reflective" coeffs="-0.63" id="6" type="x-plane" />
  <surface boundary="reflective" coeffs="0.63" id="7" type="x-plane" />
  <surface boundary="reflective" coeffs="-0.63" id="8" type="y-plane" />
  <surface boundary="reflective" coeffs="0.63" id="9" type="y-plane" />
</geometry><jupyter_text>Starting source and settingsThe Python API has a module ``openmc.stats`` with various univariate and multivariate probability distributions. We can use these distributions to create a starting source using the ``openmc.Source`` object.<jupyter_code># Create a point source
point = openmc.stats.Point((0, 0, 0))
source = openmc.Source(space=point)<jupyter_output><empty_output><jupyter_text>Now let's create a `Settings` object and give it the source we created along with specifying how many batches and particles we want to run.<jupyter_code>settings = openmc.Settings()
settings.source = source
settings.batches = 100
settings.inactive = 10
settings.particles = 1000
settings.export_to_xml()
!cat settings.xml<jupyter_output><?xml version='1.0' encoding='utf-8'?>
<settings>
  <run_mode>eigenvalue</run_mode>
  <particles>1000</particles>
  <batches>100</batches>
  <inactive>10</inactive>
  <source strength="1.0">
    <space type="point">
      <parameters>0 0 0</parameters>
    </space>
  </source>
</settings><jupyter_text>User-defined talliesWe actually have all the *required* files needed to run a simulation. Before we do that though, let's give a quick example of how to create tallies. We will show how one would tally the total, fission, absorption, and (n,$\gamma$) reaction rates for $^{235}$U in the cell containing fuel. Recall that filters allow us to specify *where* in phase-space we want events to be tallied and scores tell us *what* we want to tally:$$X = \underbrace{\int d\mathbf{r} \int d\mathbf{\Omega} \int dE}_{\text{filters}} \; \underbrace{f(\mathbf{r},\mathbf{\Omega},E)}_{\text{scores}} \psi (\mathbf{r},\mathbf{\Omega},E)$$In this case, the *where* is "the fuel cell". So, we will create a cell filter specifying the fuel cell.<jupyter_code>cell_filter = openmc.CellFilter(fuel)

tally = openmc.Tally(1)
tally.filters = [cell_filter]<jupyter_output><empty_output><jupyter_text>The *what* is the total, fission, absorption, and (n,$\gamma$) reaction rates in $^{235}$U. By default, if we only specify what reactions, it will gives us tallies over all nuclides. We can use the `nuclides` attribute to name specific nuclides we're interested in.<jupyter_code>tally.nuclides = ['U235']
tally.scores = ['total', 'fission', 'absorption', '(n,gamma)']<jupyter_output><empty_output><jupyter_text>Similar to the other files, we need to create a `Tallies` collection and export it to XML.<jupyter_code>tallies = openmc.Tallies([tally])
tallies.export_to_xml()
!cat tallies.xml<jupyter_output><?xml version='1.0' encoding='utf-8'?>
<tallies>
  <filter id="1" type="cell">
    <bins>3</bins>
  </filter>
  <tally id="1">
    <filters>1</filters>
    <nuclides>U235</nuclides>
    <scores>total fission absorption (n,gamma)</scores>
  </tally>
</tallies><jupyter_text>Running OpenMCRunning OpenMC from Python can be done using the `openmc.run()` function. This function allows you to set the number of MPI processes and OpenMP threads, if need be.<jupyter_code>openmc.run()<jupyter_output>%%%%%%%%%%%%%%%
                           %%%%%%%%%%%%%%%%%%%%%%%%
                        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                                    %%%%%%%%%%%%%%%%%%%%%%%%
                                     %%%%%%%%%%%%%%%%%%%%%%%%
                 ###############      %%%%%%%%%%%%%%%%%%%%%%%%
                ##################     %%%%%%%%%%%%%%%%%%%%%%%
                ###################     %%%%%%%%%%%%%%%%%%%%%%%
                ####################     %%%%%%%%%%%%%%%%%%%%%%
                #####################     %%%%%%%%%%%%%%%%%%%%%
                ######################     %%%%%%%%%%%%%%%%%%%%
                #######################     %%%%%%%%%%%%%%%%%%
                 #######################     %%%%%%%%%%%%%%%%%
                 #####################[...]<jupyter_text>Great! OpenMC already told us our k-effective. It also spit out a file called `tallies.out` that shows our tallies. This is a very basic method to look at tally data; for more sophisticated methods, see other example notebooks.<jupyter_code>!cat tallies.out<jupyter_output>============================>     TALLY 1     <============================

 Cell 3
   U235
     Total Reaction Rate                  0.726151 +/- 0.00251702
     Fission Rate                         0.543836 +/- 0.00205084
     Absorption Rate                      0.652874 +/- 0.002424
     (n,gamma)                            0.10904 +/- 0.000385793<jupyter_text>Geometry plottingWe saw before that we could call the `Universe.plot()` method to show a universe while we were creating our geometry. There is also a built-in plotter in the codebase that is much faster than the Python plotter and has more options. The interface looks somewhat similar to the `Universe.plot()` method. Instead though, we create `Plot` instances, assign them to a `Plots` collection, export it to XML, and then run OpenMC in geometry plotting mode. As an example, let's specify that we want the plot to be colored by material (rather than by cell) and we assign yellow to fuel and blue to water.<jupyter_code>plot = openmc.Plot()
plot.filename = 'pinplot'
plot.width = (pitch, pitch)
plot.pixels = (200, 200)
plot.color_by = 'material'
plot.colors = {uo2: 'yellow', water: 'blue'}<jupyter_output><empty_output><jupyter_text>With our plot created, we need to add it to a `Plots` collection which can be exported to XML.<jupyter_code>plots = openmc.Plots([plot])
plots.export_to_xml()
!cat plots.xml<jupyter_output><?xml version='1.0' encoding='utf-8'?>
<plots>
  <plot basis="xy" color_by="material" filename="pinplot" id="1" type="slice">
    <origin>0.0 0.0 0.0</origin>
    <width>1.26 1.26</width>
    <pixels>200 200</pixels>
    <color id="1" rgb="255 255 0" />
    <color id="4" rgb="0 0 255" />
  </plot>
</plots><jupyter_text>Now we can run OpenMC in plotting mode by calling the `plot_geometry()` function. Under the hood this is calling `openmc --plot`.<jupyter_code>openmc.plot_geometry()<jupyter_output>%%%%%%%%%%%%%%%
                           %%%%%%%%%%%%%%%%%%%%%%%%
                        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                                    %%%%%%%%%%%%%%%%%%%%%%%%
                                     %%%%%%%%%%%%%%%%%%%%%%%%
                 ###############      %%%%%%%%%%%%%%%%%%%%%%%%
                ##################     %%%%%%%%%%%%%%%%%%%%%%%
                ###################     %%%%%%%%%%%%%%%%%%%%%%%
                ####################     %%%%%%%%%%%%%%%%%%%%%%
                #####################     %%%%%%%%%%%%%%%%%%%%%
                ######################     %%%%%%%%%%%%%%%%%%%%
                #######################     %%%%%%%%%%%%%%%%%%
                 #######################     %%%%%%%%%%%%%%%%%
                 #####################[...]<jupyter_text>OpenMC writes out a peculiar image with a `.ppm` extension. If you have ImageMagick installed, this can be converted into a more normal `.png` file.<jupyter_code>!convert pinplot.ppm pinplot.png<jupyter_output><empty_output><jupyter_text>We can use functionality from IPython to display the image inline in our notebook:<jupyter_code>from IPython.display import Image
Image("pinplot.png")<jupyter_output><empty_output><jupyter_text>That was a little bit cumbersome. Thankfully, OpenMC provides us with a method on the `Plot` class that does all that "boilerplate" work.<jupyter_code>plot.to_ipython_image()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15034572638743077, 'fraction_numerical': 0.02519639430909025, 'mean_word_length': 4.355564172159752, 'pattern_counts': {'":': 0, '<': 301, '<?xml version=': 7, '>': 300, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '47', 'dir': 'jupyter-structured-clean-dedup', 'id': '204773', 'license': 'MIT', 'n_tokens_mistral': 9174, 'n_tokens_neox': 8460, 'n_words': 2864, 'path': 'docs/source/examples/pincell.ipynb', 'repo_name': 'gridley/openmc', 'size': '27623'}