#!/usr/bin/env python

from argparse import ArgumentParser

import numpy as np
import openmc

parser = ArgumentParser()
parser.add_argument('-s', '--size', action='store', default='small',
                    help='Size of nuclide inventory (small or large)')
args = parser.parse_args()

# Define materials
fuel = openmc.Material(name='Fuel', material_id=1)
fuel.set_density('g/cm3', 10.062)
fuel.add_nuclide("U234", 4.9476e-6)
fuel.add_nuclide("U235", 4.8218e-4)
fuel.add_nuclide("U236", 9.0402e-5)
fuel.add_nuclide("U238", 2.1504e-2)
fuel.add_nuclide("Np237", 7.3733e-6)
fuel.add_nuclide("Pu238", 1.5148e-6)
fuel.add_nuclide("Pu239", 1.3955e-4)
fuel.add_nuclide("Pu240", 3.4405e-5)
fuel.add_nuclide("Pu241", 2.1439e-5)
fuel.add_nuclide("Pu242", 3.7422e-6)
fuel.add_nuclide("Am241", 4.5041e-7)
fuel.add_nuclide("Am242_m1", 9.2301e-9)
fuel.add_nuclide("Am243", 4.7878e-7)
fuel.add_nuclide("Cm242", 1.0485e-7)
fuel.add_nuclide("Cm243", 1.4268e-9)
fuel.add_nuclide("Cm244", 8.8756e-8)
fuel.add_nuclide("Cm245", 3.5285e-9)
fuel.add_nuclide("Mo95", 2.6497e-5)
fuel.add_nuclide("Tc99", 3.2772e-5)
fuel.add_nuclide("Ru101", 3.0742e-5)
fuel.add_nuclide("Ru103", 2.3505e-6)
fuel.add_nuclide("Ag109", 2.0009e-6)
fuel.add_nuclide("Xe135", 1.0801e-8)
fuel.add_nuclide("Cs133", 3.4612e-5)
fuel.add_nuclide("Nd143", 2.6078e-5)
fuel.add_nuclide("Nd145", 1.9898e-5)
fuel.add_nuclide("Sm147", 1.6128e-6)
fuel.add_nuclide("Sm149", 1.1627e-7)
fuel.add_nuclide("Sm150", 7.1727e-6)
fuel.add_nuclide("Sm151", 5.4947e-7)
fuel.add_nuclide("Sm152", 3.0221e-6)
fuel.add_nuclide("Eu153", 2.6209e-6)
fuel.add_nuclide("Gd155", 1.5369e-9)
fuel.add_nuclide("O16", 4.5737e-2)

# For H-M large, add all minor actinides and fission products
if args.size == 'large':
    # fission products from all actinides
    fuel.add_nuclide('Cu65', 1.0e-12)
    fuel.add_nuclide('Zn66', 1.0e-12)
    fuel.add_nuclide('Zn67', 1.0e-12)
    fuel.add_nuclide('Zn68', 1.0e-12)
    fuel.add_nuclide('Zn70', 1.0e-12)
    fuel.add_nuclide('Ga69', 1.0e-12)
    fuel.add_nuclide('Ga71', 1.0e-12)
    fuel.add_nuclide('Ge70', 1.0e-12)
    fuel.add_nuclide('Ge72', 1.0e-12)
    fuel.add_nuclide('Ge73', 1.0e-12)
    fuel.add_nuclide('Ge74', 1.0e-12)
    fuel.add_nuclide('Ge76', 1.0e-12)
    fuel.add_nuclide('As74', 1.0e-12)
    fuel.add_nuclide('As75', 1.0e-12)
    fuel.add_nuclide('Se74', 1.0e-12)
    fuel.add_nuclide('Se76', 1.0e-12)
    fuel.add_nuclide('Se77', 1.0e-12)
    fuel.add_nuclide('Se78', 1.0e-12)
    fuel.add_nuclide('Se79', 1.0e-12)
    fuel.add_nuclide('Se80', 1.0e-12)
    fuel.add_nuclide('Se82', 1.0e-12)
    fuel.add_nuclide('Br79', 1.0e-12)
    fuel.add_nuclide('Br81', 1.0e-12)
    fuel.add_nuclide('Kr78', 1.0e-12)
    fuel.add_nuclide('Kr80', 1.0e-12)
    fuel.add_nuclide('Kr82', 1.0e-12)
    fuel.add_nuclide('Kr83', 1.0e-12)
    fuel.add_nuclide('Kr84', 1.0e-12)
    fuel.add_nuclide('Kr85', 1.0e-12)
    fuel.add_nuclide('Kr86', 1.0e-12)
    fuel.add_nuclide('Rb85', 1.0e-12)
    fuel.add_nuclide('Rb86', 1.0e-12)
    fuel.add_nuclide('Rb87', 1.0e-12)
    fuel.add_nuclide('Sr84', 1.0e-12)
    fuel.add_nuclide('Sr86', 1.0e-12)
    fuel.add_nuclide('Sr87', 1.0e-12)
    fuel.add_nuclide('Sr88', 1.0e-12)
    fuel.add_nuclide('Sr89', 1.0e-12)
    fuel.add_nuclide('Sr90', 1.0e-12)
    fuel.add_nuclide('Y89', 1.0e-12)
    fuel.add_nuclide('Y90', 1.0e-12)
    fuel.add_nuclide('Y91', 1.0e-12)
    fuel.add_nuclide('Zr90', 1.0e-12)
    fuel.add_nuclide('Zr91', 1.0e-12)
    fuel.add_nuclide('Zr92', 1.0e-12)
    fuel.add_nuclide('Zr93', 1.0e-12)
    fuel.add_nuclide('Zr94', 1.0e-12)
    fuel.add_nuclide('Zr95', 1.0e-12)
    fuel.add_nuclide('Zr96', 1.0e-12)
    fuel.add_nuclide('Nb93', 1.0e-12)
    fuel.add_nuclide('Nb94', 1.0e-12)
    fuel.add_nuclide('Nb95', 1.0e-12)
    fuel.add_nuclide('Mo92', 1.0e-12)
    fuel.add_nuclide('Mo94', 1.0e-12)
    fuel.add_nuclide('Mo96', 1.0e-12)
    fuel.add_nuclide('Mo97', 1.0e-12)
    fuel.add_nuclide('Mo98', 1.0e-12)
    fuel.add_nuclide('Mo99', 1.0e-12)
    fuel.add_nuclide('Mo100', 1.0e-12)
    fuel.add_nuclide('Ru96', 1.0e-12)
    fuel.add_nuclide('Ru98', 1.0e-12)
    fuel.add_nuclide('Ru99', 1.0e-12)
    fuel.add_nuclide('Ru100', 1.0e-12)
    fuel.add_nuclide('Ru102', 1.0e-12)
    fuel.add_nuclide('Ru104', 1.0e-12)
    fuel.add_nuclide('Ru105', 1.0e-12)
    fuel.add_nuclide('Ru106', 1.0e-12)
    fuel.add_nuclide('Rh103', 1.0e-12)
    fuel.add_nuclide('Rh105', 1.0e-12)
    fuel.add_nuclide('Pd102', 1.0e-12)
    fuel.add_nuclide('Pd104', 1.0e-12)
    fuel.add_nuclide('Pd105', 1.0e-12)
    fuel.add_nuclide('Pd106', 1.0e-12)
    fuel.add_nuclide('Pd107', 1.0e-12)
    fuel.add_nuclide('Pd108', 1.0e-12)
    fuel.add_nuclide('Pd110', 1.0e-12)
    fuel.add_nuclide('Ag107', 1.0e-12)
    fuel.add_nuclide('Ag110_m1', 1.0e-12)
    fuel.add_nuclide('Ag111', 1.0e-12)
    fuel.add_nuclide('Cd106', 1.0e-12)
    fuel.add_nuclide('Cd108', 1.0e-12)
    fuel.add_nuclide('Cd110', 1.0e-12)
    fuel.add_nuclide('Cd111', 1.0e-12)
    fuel.add_nuclide('Cd112', 1.0e-12)
    fuel.add_nuclide('Cd113', 1.0e-12)
    fuel.add_nuclide('Cd114', 1.0e-12)
    fuel.add_nuclide('Cd115_m1', 1.0e-12)
    fuel.add_nuclide('Cd116', 1.0e-12)
    fuel.add_nuclide('In113', 1.0e-12)
    fuel.add_nuclide('In115', 1.0e-12)
    fuel.add_nuclide('Sn112', 1.0e-12)
    fuel.add_nuclide('Sn113', 1.0e-12)
    fuel.add_nuclide('Sn114', 1.0e-12)
    fuel.add_nuclide('Sn115', 1.0e-12)
    fuel.add_nuclide('Sn116', 1.0e-12)
    fuel.add_nuclide('Sn117', 1.0e-12)
    fuel.add_nuclide('Sn118', 1.0e-12)
    fuel.add_nuclide('Sn119', 1.0e-12)
    fuel.add_nuclide('Sn120', 1.0e-12)
    fuel.add_nuclide('Sn122', 1.0e-12)
    fuel.add_nuclide('Sn123', 1.0e-12)
    fuel.add_nuclide('Sn124', 1.0e-12)
    fuel.add_nuclide('Sn125', 1.0e-12)
    fuel.add_nuclide('Sn126', 1.0e-12)
    fuel.add_nuclide('Sb121', 1.0e-12)
    fuel.add_nuclide('Sb123', 1.0e-12)
    fuel.add_nuclide('Sb124', 1.0e-12)
    fuel.add_nuclide('Sb125', 1.0e-12)
    fuel.add_nuclide('Sb126', 1.0e-12)
    fuel.add_nuclide('Te120', 1.0e-12)
    fuel.add_nuclide('Te122', 1.0e-12)
    fuel.add_nuclide('Te123', 1.0e-12)
    fuel.add_nuclide('Te124', 1.0e-12)
    fuel.add_nuclide('Te125', 1.0e-12)
    fuel.add_nuclide('Te126', 1.0e-12)
    fuel.add_nuclide('Te127_m1', 1.0e-12)
    fuel.add_nuclide('Te128', 1.0e-12)
    fuel.add_nuclide('Te129_m1', 1.0e-12)
    fuel.add_nuclide('Te130', 1.0e-12)
    fuel.add_nuclide('Te132', 1.0e-12)
    fuel.add_nuclide('I127', 1.0e-12)
    fuel.add_nuclide('I129', 1.0e-12)
    fuel.add_nuclide('I130', 1.0e-12)
    fuel.add_nuclide('I131', 1.0e-12)
    fuel.add_nuclide('I135', 1.0e-12)
    fuel.add_nuclide('Xe124', 1.0e-12)
    fuel.add_nuclide('Xe126', 1.0e-12)
    fuel.add_nuclide('Xe128', 1.0e-12)
    fuel.add_nuclide('Xe129', 1.0e-12)
    fuel.add_nuclide('Xe130', 1.0e-12)
    fuel.add_nuclide('Xe131', 1.0e-12)
    fuel.add_nuclide('Xe132', 1.0e-12)
    fuel.add_nuclide('Xe133', 1.0e-12)
    fuel.add_nuclide('Xe134', 1.0e-12)
    fuel.add_nuclide('Xe136', 1.0e-12)
    fuel.add_nuclide('Cs134', 1.0e-12)
    fuel.add_nuclide('Cs135', 1.0e-12)
    fuel.add_nuclide('Cs136', 1.0e-12)
    fuel.add_nuclide('Cs137', 1.0e-12)
    fuel.add_nuclide('Ba132', 1.0e-12)
    fuel.add_nuclide('Ba133', 1.0e-12)
    fuel.add_nuclide('Ba134', 1.0e-12)
    fuel.add_nuclide('Ba135', 1.0e-12)
    fuel.add_nuclide('Ba136', 1.0e-12)
    fuel.add_nuclide('Ba137', 1.0e-12)
    fuel.add_nuclide('Ba138', 1.0e-12)
    fuel.add_nuclide('Ba140', 1.0e-12)
    fuel.add_nuclide('La138', 1.0e-12)
    fuel.add_nuclide('La139', 1.0e-12)
    fuel.add_nuclide('La140', 1.0e-12)
    fuel.add_nuclide('Ce138', 1.0e-12)
    fuel.add_nuclide('Ce139', 1.0e-12)
    fuel.add_nuclide('Ce140', 1.0e-12)
    fuel.add_nuclide('Ce141', 1.0e-12)
    fuel.add_nuclide('Ce142', 1.0e-12)
    fuel.add_nuclide('Ce143', 1.0e-12)
    fuel.add_nuclide('Ce144', 1.0e-12)
    fuel.add_nuclide('Pr141', 1.0e-12)
    fuel.add_nuclide('Pr142', 1.0e-12)
    fuel.add_nuclide('Pr143', 1.0e-12)
    fuel.add_nuclide('Nd142', 1.0e-12)
    fuel.add_nuclide('Nd144', 1.0e-12)
    fuel.add_nuclide('Nd146', 1.0e-12)
    fuel.add_nuclide('Nd147', 1.0e-12)
    fuel.add_nuclide('Nd148', 1.0e-12)
    fuel.add_nuclide('Nd150', 1.0e-12)
    fuel.add_nuclide('Pm147', 1.0e-12)
    fuel.add_nuclide('Pm148', 1.0e-12)
    fuel.add_nuclide('Pm148_m1', 1.0e-12)
    fuel.add_nuclide('Pm149', 1.0e-12)
    fuel.add_nuclide('Pm151', 1.0e-12)
    fuel.add_nuclide('Sm144', 1.0e-12)
    fuel.add_nuclide('Sm148', 1.0e-12)
    fuel.add_nuclide('Sm153', 1.0e-12)
    fuel.add_nuclide('Sm154', 1.0e-12)
    fuel.add_nuclide('Eu151', 1.0e-12)
    fuel.add_nuclide('Eu152', 1.0e-12)
    fuel.add_nuclide('Eu154', 1.0e-12)
    fuel.add_nuclide('Eu155', 1.0e-12)
    fuel.add_nuclide('Eu156', 1.0e-12)
    fuel.add_nuclide('Eu157', 1.0e-12)
    fuel.add_nuclide('Gd152', 1.0e-12)
    fuel.add_nuclide('Gd153', 1.0e-12)
    fuel.add_nuclide('Gd154', 1.0e-12)
    fuel.add_nuclide('Gd156', 1.0e-12)
    fuel.add_nuclide('Gd157', 1.0e-12)
    fuel.add_nuclide('Gd158', 1.0e-12)
    fuel.add_nuclide('Gd160', 1.0e-12)
    fuel.add_nuclide('Tb159', 1.0e-12)
    fuel.add_nuclide('Tb160', 1.0e-12)
    fuel.add_nuclide('Dy156', 1.0e-12)
    fuel.add_nuclide('Dy158', 1.0e-12)
    fuel.add_nuclide('Dy160', 1.0e-12)
    fuel.add_nuclide('Dy161', 1.0e-12)
    fuel.add_nuclide('Dy162', 1.0e-12)
    fuel.add_nuclide('Dy163', 1.0e-12)
    fuel.add_nuclide('Dy164', 1.0e-12)
    fuel.add_nuclide('Ho165', 1.0e-12)
    fuel.add_nuclide('Ho166_m1', 1.0e-12)
    fuel.add_nuclide('Er162', 1.0e-12)
    fuel.add_nuclide('Er164', 1.0e-12)
    fuel.add_nuclide('Er166', 1.0e-12)
    fuel.add_nuclide('Er167', 1.0e-12)
    fuel.add_nuclide('Er168', 1.0e-12)
    fuel.add_nuclide('Er170', 1.0e-12)
    fuel.add_nuclide('Tm168', 1.0e-12)
    fuel.add_nuclide('Tm169', 1.0e-12)
    fuel.add_nuclide('Tm170', 1.0e-12)
    # minor actinides
    fuel.add_nuclide('U233', 1.0e-12)
    fuel.add_nuclide('U237', 1.0e-12)
    fuel.add_nuclide('Np238', 1.0e-12)
    fuel.add_nuclide('Cm246', 1.0e-12)
    # other reaction products from (n,p), (n,a), etc.
    fuel.add_nuclide('H1', 1.0e-12)
    fuel.add_nuclide('H2', 1.0e-12)
    fuel.add_nuclide('H3', 1.0e-12)
    fuel.add_nuclide('He3', 1.0e-12)
    fuel.add_nuclide('He4', 1.0e-12)

clad = openmc.Material(name='Cladding', material_id=2)
clad.set_density('g/cm3', 5.77)
clad.add_element("Zr", 1.0)

cold_water = openmc.Material(name='Cold borated water', material_id=3)
cold_water.set_density('atom/b-cm', 0.07416)
cold_water.add_nuclide("H1", 2.0)
cold_water.add_nuclide("O16", 1.0)
cold_water.add_nuclide("B10", 6.490e-4)
cold_water.add_nuclide("B11", 2.689e-3)
cold_water.add_s_alpha_beta('c_H_in_H2O')

hot_water = openmc.Material(name='Hot borated water', material_id=4)
hot_water.set_density('atom/b-cm', 0.06614)
hot_water.add_nuclide("H1", 2.0)
hot_water.add_nuclide("O16", 1.0)
hot_water.add_nuclide("B10", 6.490e-4)
hot_water.add_nuclide("B11", 2.689e-3)
hot_water.add_s_alpha_beta('c_H_in_H2O')

rpv_steel = openmc.Material(name='Reactor pressure vessel steel',
                            material_id=5)
rpv_steel.set_density('g/cm3', 7.9)
rpv_steel.add_nuclide("Fe54", 0.05437098, 'wo')
rpv_steel.add_nuclide("Fe56", 0.88500663, 'wo')
rpv_steel.add_nuclide("Fe57", 0.0208008, 'wo')
rpv_steel.add_nuclide("Fe58", 0.00282159, 'wo')
rpv_steel.add_nuclide("Ni58", 0.0067198, 'wo')
rpv_steel.add_nuclide("Ni60", 0.0026776, 'wo')
rpv_steel.add_nuclide("Ni61", 0.0001183, 'wo')
rpv_steel.add_nuclide("Ni62", 0.0003835, 'wo')
rpv_steel.add_nuclide("Ni64", 0.0001008, 'wo')
rpv_steel.add_nuclide("Mn55", 0.01, 'wo')
rpv_steel.add_nuclide("Mo92", 0.000849, 'wo')
rpv_steel.add_nuclide("Mo94", 0.0005418, 'wo')
rpv_steel.add_nuclide("Mo95", 0.0009438, 'wo')
rpv_steel.add_nuclide("Mo96", 0.0010002, 'wo')
rpv_steel.add_nuclide("Mo97", 0.0005796, 'wo')
rpv_steel.add_nuclide("Mo98", 0.0014814, 'wo')
rpv_steel.add_nuclide("Mo100", 0.0006042, 'wo')
rpv_steel.add_nuclide("Si28", 0.00367464, 'wo')
rpv_steel.add_nuclide("Si29", 0.00019336, 'wo')
rpv_steel.add_nuclide("Si30", 0.000132, 'wo')
rpv_steel.add_nuclide("Cr50", 0.00010435, 'wo')
rpv_steel.add_nuclide("Cr52", 0.002092475, 'wo')
rpv_steel.add_nuclide("Cr53", 0.00024185, 'wo')
rpv_steel.add_nuclide("Cr54", 6.1325e-05, 'wo')
rpv_steel.add_nuclide("C0", 0.0025, 'wo')
rpv_steel.add_nuclide("Cu63", 0.0013696, 'wo')
rpv_steel.add_nuclide("Cu65", 0.0006304, 'wo')

lower_rad_ref = openmc.Material(name='Lower radial reflector',
                                material_id=6)
lower_rad_ref.set_density('g/cm3', 4.32)
lower_rad_ref.add_nuclide("H1", 0.0095661, 'wo')
lower_rad_ref.add_nuclide("O16", 0.0759107, 'wo')
lower_rad_ref.add_nuclide("B10", 3.08409e-5, 'wo')
lower_rad_ref.add_nuclide("B11", 1.40499e-4, 'wo')
lower_rad_ref.add_nuclide("Fe54", 0.035620772088, 'wo')
lower_rad_ref.add_nuclide("Fe56", 0.579805982228, 'wo')
lower_rad_ref.add_nuclide("Fe57", 0.01362750048, 'wo')
lower_rad_ref.add_nuclide("Fe58", 0.001848545204, 'wo')
lower_rad_ref.add_nuclide("Ni58", 0.055298376566, 'wo')
lower_rad_ref.add_nuclide("Ni60", 0.022034425592, 'wo')
lower_rad_ref.add_nuclide("Ni61", 0.000973510811, 'wo')
lower_rad_ref.add_nuclide("Ni62", 0.003155886695, 'wo')
lower_rad_ref.add_nuclide("Ni64", 0.000829500336, 'wo')
lower_rad_ref.add_nuclide("Mn55", 0.0182870, 'wo')
lower_rad_ref.add_nuclide("Si28", 0.00839976771, 'wo')
lower_rad_ref.add_nuclide("Si29", 0.00044199679, 'wo')
lower_rad_ref.add_nuclide("Si30", 0.0003017355, 'wo')
lower_rad_ref.add_nuclide("Cr50", 0.007251360806, 'wo')
lower_rad_ref.add_nuclide("Cr52", 0.145407678031, 'wo')
lower_rad_ref.add_nuclide("Cr53", 0.016806340306, 'wo')
lower_rad_ref.add_nuclide("Cr54", 0.004261520857, 'wo')
lower_rad_ref.add_s_alpha_beta('c_H_in_H2O')

upper_rad_ref = openmc.Material(name='Upper radial reflector /'
                                'Top plate region', material_id=7)
upper_rad_ref.set_density('g/cm3', 4.28)
upper_rad_ref.add_nuclide("H1", 0.0086117, 'wo')
upper_rad_ref.add_nuclide("O16", 0.0683369, 'wo')
upper_rad_ref.add_nuclide("B10", 2.77638e-5, 'wo')
upper_rad_ref.add_nuclide("B11", 1.26481e-4, 'wo')
upper_rad_ref.add_nuclide("Fe54", 0.035953677186, 'wo')
upper_rad_ref.add_nuclide("Fe56", 0.585224740891, 'wo')
upper_rad_ref.add_nuclide("Fe57", 0.01375486056, 'wo')
upper_rad_ref.add_nuclide("Fe58", 0.001865821363, 'wo')
upper_rad_ref.add_nuclide("Ni58", 0.055815129186, 'wo')
upper_rad_ref.add_nuclide("Ni60", 0.022240333032, 'wo')
upper_rad_ref.add_nuclide("Ni61", 0.000982608081, 'wo')
upper_rad_ref.add_nuclide("Ni62", 0.003185377845, 'wo')
upper_rad_ref.add_nuclide("Ni64", 0.000837251856, 'wo')
upper_rad_ref.add_nuclide("Mn55", 0.0184579, 'wo')
upper_rad_ref.add_nuclide("Si28", 0.00847831314, 'wo')
upper_rad_ref.add_nuclide("Si29", 0.00044612986, 'wo')
upper_rad_ref.add_nuclide("Si30", 0.000304557, 'wo')
upper_rad_ref.add_nuclide("Cr50", 0.00731912987, 'wo')
upper_rad_ref.add_nuclide("Cr52", 0.146766614995, 'wo')
upper_rad_ref.add_nuclide("Cr53", 0.01696340737, 'wo')
upper_rad_ref.add_nuclide("Cr54", 0.004301347765, 'wo')
upper_rad_ref.add_s_alpha_beta('c_H_in_H2O')

bot_plate = openmc.Material(name='Bottom plate region', material_id=8)
bot_plate.set_density('g/cm3', 7.184)
bot_plate.add_nuclide("H1", 0.0011505, 'wo')
bot_plate.add_nuclide("O16", 0.0091296, 'wo')
bot_plate.add_nuclide("B10", 3.70915e-6, 'wo')
bot_plate.add_nuclide("B11", 1.68974e-5, 'wo')
bot_plate.add_nuclide("Fe54", 0.03855611055, 'wo')
bot_plate.add_nuclide("Fe56", 0.627585036425, 'wo')
bot_plate.add_nuclide("Fe57", 0.014750478, 'wo')
bot_plate.add_nuclide("Fe58", 0.002000875025, 'wo')
bot_plate.add_nuclide("Ni58", 0.059855207342, 'wo')
bot_plate.add_nuclide("Ni60", 0.023850159704, 'wo')
bot_plate.add_nuclide("Ni61", 0.001053732407, 'wo')
bot_plate.add_nuclide("Ni62", 0.003415945715, 'wo')
bot_plate.add_nuclide("Ni64", 0.000897854832, 'wo')
bot_plate.add_nuclide("Mn55", 0.0197940, 'wo')
bot_plate.add_nuclide("Si28", 0.00909197802, 'wo')
bot_plate.add_nuclide("Si29", 0.00047842098, 'wo')
bot_plate.add_nuclide("Si30", 0.000326601, 'wo')
bot_plate.add_nuclide("Cr50", 0.007848910646, 'wo')
bot_plate.add_nuclide("Cr52", 0.157390026871, 'wo')
bot_plate.add_nuclide("Cr53", 0.018191270146, 'wo')
bot_plate.add_nuclide("Cr54", 0.004612692337, 'wo')
bot_plate.add_s_alpha_beta('c_H_in_H2O')

bot_nozzle = openmc.Material(name='Bottom nozzle region', material_id=9)
bot_nozzle.set_density('g/cm3', 2.53)
bot_nozzle.add_nuclide("H1", 0.0245014, 'wo')
bot_nozzle.add_nuclide("O16", 0.1944274, 'wo')
bot_nozzle.add_nuclide("B10", 7.89917e-5, 'wo')
bot_nozzle.add_nuclide("B11", 3.59854e-4, 'wo')
bot_nozzle.add_nuclide("Fe54", 0.030411411144, 'wo')
bot_nozzle.add_nuclide("Fe56", 0.495012237964, 'wo')
bot_nozzle.add_nuclide("Fe57", 0.01163454624, 'wo')
bot_nozzle.add_nuclide("Fe58", 0.001578204652, 'wo')
bot_nozzle.add_nuclide("Ni58", 0.047211231662, 'wo')
bot_nozzle.add_nuclide("Ni60", 0.018811987544, 'wo')
bot_nozzle.add_nuclide("Ni61", 0.000831139127, 'wo')
bot_nozzle.add_nuclide("Ni62", 0.002694352115, 'wo')
bot_nozzle.add_nuclide("Ni64", 0.000708189552, 'wo')
bot_nozzle.add_nuclide("Mn55", 0.0156126, 'wo')
bot_nozzle.add_nuclide("Si28", 0.007171335558, 'wo')
bot_nozzle.add_nuclide("Si29", 0.000377356542, 'wo')
bot_nozzle.add_nuclide("Si30", 0.0002576079, 'wo')
bot_nozzle.add_nuclide("Cr50", 0.006190885148, 'wo')
bot_nozzle.add_nuclide("Cr52", 0.124142524198, 'wo')
bot_nozzle.add_nuclide("Cr53", 0.014348496148, 'wo')
bot_nozzle.add_nuclide("Cr54", 0.003638294506, 'wo')
bot_nozzle.add_s_alpha_beta('c_H_in_H2O')

top_nozzle = openmc.Material(name='Top nozzle region', material_id=10)
top_nozzle.set_density('g/cm3', 1.746)
top_nozzle.add_nuclide("H1", 0.0358870, 'wo')
top_nozzle.add_nuclide("O16", 0.2847761, 'wo')
top_nozzle.add_nuclide("B10", 1.15699e-4, 'wo')
top_nozzle.add_nuclide("B11", 5.27075e-4, 'wo')
top_nozzle.add_nuclide("Fe54", 0.02644016154, 'wo')
top_nozzle.add_nuclide("Fe56", 0.43037146399, 'wo')
top_nozzle.add_nuclide("Fe57", 0.0101152584, 'wo')
top_nozzle.add_nuclide("Fe58", 0.00137211607, 'wo')
top_nozzle.add_nuclide("Ni58", 0.04104621835, 'wo')
top_nozzle.add_nuclide("Ni60", 0.0163554502, 'wo')
top_nozzle.add_nuclide("Ni61", 0.000722605975, 'wo')
top_nozzle.add_nuclide("Ni62", 0.002342513875, 'wo')
top_nozzle.add_nuclide("Ni64", 0.0006157116, 'wo')
top_nozzle.add_nuclide("Mn55", 0.0135739, 'wo')
top_nozzle.add_nuclide("Si28", 0.006234853554, 'wo')
top_nozzle.add_nuclide("Si29", 0.000328078746, 'wo')
top_nozzle.add_nuclide("Si30", 0.0002239677, 'wo')
top_nozzle.add_nuclide("Cr50", 0.005382452306, 'wo')
top_nozzle.add_nuclide("Cr52", 0.107931450781, 'wo')
top_nozzle.add_nuclide("Cr53", 0.012474806806, 'wo')
top_nozzle.add_nuclide("Cr54", 0.003163190107, 'wo')
top_nozzle.add_s_alpha_beta('c_H_in_H2O')

top_fa = openmc.Material(name='Top of fuel assemblies', material_id=11)
top_fa.set_density('g/cm3', 3.044)
top_fa.add_nuclide("H1", 0.0162913, 'wo')
top_fa.add_nuclide("O16", 0.1292776, 'wo')
top_fa.add_nuclide("B10", 5.25228e-5, 'wo')
top_fa.add_nuclide("B11", 2.39272e-4, 'wo')
top_fa.add_nuclide("Zr90", 0.43313403903, 'wo')
top_fa.add_nuclide("Zr91", 0.09549277374, 'wo')
top_fa.add_nuclide("Zr92", 0.14759527104, 'wo')
top_fa.add_nuclide("Zr94", 0.15280552077, 'wo')
top_fa.add_nuclide("Zr96", 0.02511169542, 'wo')
top_fa.add_s_alpha_beta('c_H_in_H2O')

bot_fa = openmc.Material(name='Bottom of fuel assemblies', material_id=12)
bot_fa.set_density('g/cm3', 1.762)
bot_fa.add_nuclide("H1", 0.0292856, 'wo')
bot_fa.add_nuclide("O16", 0.2323919, 'wo')
bot_fa.add_nuclide("B10", 9.44159e-5, 'wo')
bot_fa.add_nuclide("B11", 4.30120e-4, 'wo')
bot_fa.add_nuclide("Zr90", 0.3741373658, 'wo')
bot_fa.add_nuclide("Zr91", 0.0824858164, 'wo')
bot_fa.add_nuclide("Zr92", 0.1274914944, 'wo')
bot_fa.add_nuclide("Zr94", 0.1319920622, 'wo')
bot_fa.add_nuclide("Zr96", 0.0216912612, 'wo')
bot_fa.add_s_alpha_beta('c_H_in_H2O')

# Define the materials file.
materials = openmc.Materials()
materials.default_xs = '71c'
materials += [fuel, clad, cold_water, hot_water, rpv_steel,
              lower_rad_ref, upper_rad_ref, bot_plate,
              bot_nozzle, top_nozzle, top_fa, bot_fa]
materials.export_to_xml()

# Define surfaces.
s1 = openmc.ZCylinder(R=0.41, surface_id=1)
s2 = openmc.ZCylinder(R=0.475, surface_id=2)
s3 = openmc.ZCylinder(R=0.56, surface_id=3)
s4 = openmc.ZCylinder(R=0.62, surface_id=4)
s5 = openmc.ZCylinder(R=187.6, surface_id=5)
s6 = openmc.ZCylinder(R=209.0, surface_id=6)
s7 = openmc.ZCylinder(R=229.0, surface_id=7)
s8 = openmc.ZCylinder(R=249.0, surface_id=8)
s8.boundary_type = 'vacuum'

s31 = openmc.ZPlane(z0=-229.0, surface_id=31)
s31.boundary_type = 'vacuum'
s32 = openmc.ZPlane(z0=-199.0, surface_id=32)
s33 = openmc.ZPlane(z0=-193.0, surface_id=33)
s34 = openmc.ZPlane(z0=-183.0, surface_id=34)
s35 = openmc.ZPlane(z0=0.0, surface_id=35)
s36 = openmc.ZPlane(z0=183.0, surface_id=36)
s37 = openmc.ZPlane(z0=203.0, surface_id=37)
s38 = openmc.ZPlane(z0=215.0, surface_id=38)
s39 = openmc.ZPlane(z0=223.0, surface_id=39)
s39.boundary_type = 'vacuum'

# Define pin cells.
c21 = openmc.Cell(cell_id=21, fill=fuel, region=-s1)
c22 = openmc.Cell(cell_id=22, fill=clad, region=+s1 & -s2)
c23 = openmc.Cell(cell_id=23, fill=cold_water, region=+s2)
fuel_cold = openmc.Universe(name='Fuel pin, cladding, cold water',
                            universe_id=1, cells=(c21, c22, c23))

c24 = openmc.Cell(cell_id=24, fill=cold_water, region=-s3)
c25 = openmc.Cell(cell_id=25, fill=clad, region=+s3 & -s4)
c26 = openmc.Cell(cell_id=26, fill=cold_water, region=+s4)
tube_cold = openmc.Universe(name='Instrumentation guide tube, cold water',
                            universe_id=2, cells=(c24, c25, c26))

c27 = openmc.Cell(cell_id=27, fill=fuel, region=-s1)
c28 = openmc.Cell(cell_id=28, fill=clad, region=+s1 & -s2)
c29 = openmc.Cell(cell_id=29, fill=hot_water, region=+s2)
fuel_hot = openmc.Universe(name='Fuel pin, cladding, hot water',
                           universe_id=3, cells=(c27, c28, c29))

c30 = openmc.Cell(cell_id=30, fill=hot_water, region=-s3)
c31 = openmc.Cell(cell_id=31, fill=clad, region=+s3 & -s4)
c32 = openmc.Cell(cell_id=32, fill=hot_water, region=+s4)
tube_hot = openmc.Universe(name='Instrumentation guide tube, hot water',
                           universe_id=4, cells=(c30, c31, c32))

guide_tubes = [(2, 5), (2, 8), (2, 11), (3, 3), (3, 13),
               (5, 2), (5, 5), (5, 8), (5, 11), (5, 14),
               (8, 2), (8, 5), (8, 8), (8, 11), (8, 14),
               (11, 2), (11, 5), (11, 8), (11, 11), (11, 14),
               (13, 3), (13, 13), (14, 5), (14, 8), (14, 11)]

# Define fuel lattices.
l100 = openmc.RectLattice(name='Fuel assembly (lower half)', lattice_id=100)
l100.lower_left = (-10.71, -10.71)
l100.pitch = (1.26, 1.26)
l100.universes = np.tile(fuel_cold, (17, 17))
for position in guide_tubes:
    l100.universes[position] = tube_cold

l101 = openmc.RectLattice(name='Fuel assembly (upper half)', lattice_id=101)
l101.lower_left = (-10.71, -10.71)
l101.pitch = (1.26, 1.26)
l101.universes = np.tile(fuel_hot, (17, 17))
for position in guide_tubes:
    l101.universes[position] = tube_hot

# Define assemblies.
c50 = openmc.Cell(cell_id=50, fill=cold_water, region=+s34 & -s35)
fa_cw = openmc.Universe(name='Water assembly (cold)', universe_id=5, cells=[c50])

c70 = openmc.Cell(cell_id=70, fill=hot_water, region=+s35 & -s36)
fa_hw = openmc.Universe(name='Water assembly (hot)', universe_id=7, cells=[c70])

c60 = openmc.Cell(cell_id=60, fill=l100, region=+s34 & -s35)
fa_cold = openmc.Universe(name='Fuel assembly (cold)', universe_id=6, cells=[c60])

c80 = openmc.Cell(cell_id=80, fill=l101, region=+s35 & -s36)
fa_hot = openmc.Universe(name='Fuel assembly (hot)', universe_id=8, cells=[c80])

# Define core lattices
l200 = openmc.RectLattice(name='Core lattice (lower half)', lattice_id=200)
l200.lower_left = (-224.91, -224.91)
l200.pitch = (21.42, 21.42)
l200.universes = [
    [fa_cw]*21,
    [fa_cw]*21,
    [fa_cw]*7 + [fa_cold]*7 + [fa_cw]*7,
    [fa_cw]*5 + [fa_cold]*11 + [fa_cw]*5,
    [fa_cw]*4 + [fa_cold]*13 + [fa_cw]*4,
    [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3,
    [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3,
    [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
    [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
    [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
    [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
    [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
    [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
    [fa_cw]*2 + [fa_cold]*17 + [fa_cw]*2,
    [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3,
    [fa_cw]*3 + [fa_cold]*15 + [fa_cw]*3,
    [fa_cw]*4 + [fa_cold]*13 + [fa_cw]*4,
    [fa_cw]*5 + [fa_cold]*11 + [fa_cw]*5,
    [fa_cw]*7 + [fa_cold]*7 + [fa_cw]*7,
    [fa_cw]*21,
    [fa_cw]*21]

l201 = openmc.RectLattice(name='Core lattice (lower half)', lattice_id=201)
l201.lower_left = (-224.91, -224.91)
l201.pitch = (21.42, 21.42)
l201.universes = [
    [fa_hw]*21,
    [fa_hw]*21,
    [fa_hw]*7 + [fa_hot]*7 + [fa_hw]*7,
    [fa_hw]*5 + [fa_hot]*11 + [fa_hw]*5,
    [fa_hw]*4 + [fa_hot]*13 + [fa_hw]*4,
    [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3,
    [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3,
    [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
    [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
    [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
    [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
    [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
    [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
    [fa_hw]*2 + [fa_hot]*17 + [fa_hw]*2,
    [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3,
    [fa_hw]*3 + [fa_hot]*15 + [fa_hw]*3,
    [fa_hw]*4 + [fa_hot]*13 + [fa_hw]*4,
    [fa_hw]*5 + [fa_hot]*11 + [fa_hw]*5,
    [fa_hw]*7 + [fa_hot]*7 + [fa_hw]*7,
    [fa_hw]*21,
    [fa_hw]*21]

# Define root universe
c1 = openmc.Cell(cell_id=1, fill=l200, region=-s6 & +s34 & -s35)
c2 = openmc.Cell(cell_id=2, fill=l201, region=-s6 & +s35 & -s36)
c3 = openmc.Cell(cell_id=3, fill=bot_plate, region=-s7 & +s31 & -s32)
c4 = openmc.Cell(cell_id=4, fill=bot_nozzle, region=-s5 & +s32 & -s33)
c5 = openmc.Cell(cell_id=5, fill=bot_fa, region=-s5 & +s33 & -s34)
c6 = openmc.Cell(cell_id=6, fill=top_fa, region=-s5 & +s36 & -s37)
c7 = openmc.Cell(cell_id=7, fill=top_nozzle, region=-s5 & +s37 & -s38)
c8 = openmc.Cell(cell_id=8, fill=upper_rad_ref, region=-s7 & +s38 & -s39)
c9 = openmc.Cell(cell_id=9, fill=bot_nozzle, region=+s6 & -s7 & +s32 & -s38)
c10 = openmc.Cell(cell_id=10, fill=rpv_steel, region=+s7 & -s8 & +s31 & -s39)
c11 = openmc.Cell(cell_id=11, fill=lower_rad_ref, region=+s5 & -s6 & +s32 & -s34)
c12 = openmc.Cell(cell_id=12, fill=upper_rad_ref, region=+s5 & -s6 & +s36 & -s38)
root = openmc.Universe(universe_id=0, name='root universe',
                       cells=(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12))

# Create and export geometry
geometry = openmc.Geometry(root)
geometry.export_to_xml()

settings = openmc.Settings()
settings.batches = 10
settings.inactive = 5
settings.particles = 1000
settings.source = openmc.Source(space=openmc.stats.Box(
    [-160, -160, -183], [160, 160, 183]))
settings.export_to_xml()

plot = openmc.Plot()
plot.filename = 'mat'
plot.origin = (125, 125, 0)
plot.width = (250, 250)
plot.pixels = (3000, 3000)
plot.color = 'mat'
plots = openmc.Plots([plot])
plots.export_to_xml()
