Advertisement
Guest User

OpenMC_photon_flux_comparison

a guest
Jan 5th, 2023
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.99 KB | Source Code | 0 0
  1. ###############
  2. ### Imports ###
  3. ###############
  4.  
  5. import os
  6. import openmc
  7. import numpy as np
  8.  
  9.  
  10. #################
  11. ### Functions ###
  12. #################
  13.  
  14. # General function for creating a cuboid region.
  15. def create_cuboid(d, c=[0, 0, 0], r=[0, 0, 0], boundary = "transmission"):
  16.     x_coord, y_coord, z_coord = c # shifting the region
  17.     x_thick, y_thick, z_thick = d # region thicknesses
  18.    
  19.     # Object rotation
  20.     phi, theta, psi = np.array(r) * np.pi/180
  21.     rotation_transformation = np.round(np.array([
  22.                                 [np.cos(theta) * np.cos(psi),
  23.                                 -np.cos(phi) * np.sin(psi) + np.sin(phi) * np.sin(theta) * np.cos(psi),
  24.                                  np.sin(phi) * np.sin(psi) + np.cos(phi) * np.sin(theta) * np.cos(psi)],
  25.                                        
  26.                                 [np.cos(theta) * np.sin(psi),
  27.                                  np.cos(phi) * np.cos(psi) + np.sin(phi) * np.sin(theta) * np.sin(psi),
  28.                                 -np.sin(phi) * np.cos(psi) + np.cos(phi) * np.sin(theta) * np.sin(psi)],
  29.                                        
  30.                                [-np.sin(theta),
  31.                                  np.sin(phi) * np.cos(theta),
  32.                                  np.cos(phi) * np.cos(theta)]]), 8)
  33.    
  34.     x_plane_vector = np.array([1, 0, 0])
  35.     x_plane_vector = np.matmul(rotation_transformation, x_plane_vector)
  36.    
  37.     y_plane_vector = np.array([0, 1, 0])
  38.     y_plane_vector = np.matmul(rotation_transformation, y_plane_vector)
  39.    
  40.     z_plane_vector = np.array([0, 0, 1])
  41.     z_plane_vector = np.matmul(rotation_transformation, z_plane_vector)
  42.    
  43.     # Construction of Surface!
  44.     xplus_rect_surface  = openmc.Plane(a=x_plane_vector[0], b=x_plane_vector[1], c=x_plane_vector[2], d=x_thick/2+x_coord, boundary_type=boundary)
  45.     xminus_rect_surface = openmc.Plane(a=x_plane_vector[0], b=x_plane_vector[1], c=x_plane_vector[2], d=-x_thick/2+x_coord, boundary_type=boundary)
  46.  
  47.     yplus_rect_surface  = openmc.Plane(a=y_plane_vector[0], b=y_plane_vector[1], c=y_plane_vector[2], d=y_thick/2+y_coord, boundary_type=boundary)
  48.     yminus_rect_surface = openmc.Plane(a=y_plane_vector[0], b=y_plane_vector[1], c=y_plane_vector[2], d=-y_thick/2+y_coord, boundary_type=boundary)
  49.  
  50.     zplus_rect_surface  = openmc.Plane(a=z_plane_vector[0], b=z_plane_vector[1], c=z_plane_vector[2], d=z_thick/2+z_coord, boundary_type=boundary)
  51.     zminus_rect_surface = openmc.Plane(a=z_plane_vector[0], b=z_plane_vector[1], c=z_plane_vector[2], d=-z_thick/2+z_coord, boundary_type=boundary)
  52.    
  53.     # Sum region
  54.     region = (+xminus_rect_surface & -xplus_rect_surface &
  55.               +yminus_rect_surface & -yplus_rect_surface &
  56.               +zminus_rect_surface & -zplus_rect_surface)
  57.    
  58.     return region
  59.  
  60. # User-defined material library
  61. def Material_Library(element_name):
  62.     if element_name == "air":
  63.         mat = openmc.Material(name='air')
  64.         mat.add_element('C', 0.0124, percent_type='wo')
  65.         mat.add_element('N', 75.5267, percent_type='wo')
  66.         mat.add_element('O', 23.1781, percent_type='wo')
  67.         mat.add_element('Ar', 1.2827, percent_type='wo')
  68.         mat.set_density('g/cm3', 1.20479e-3)
  69.  
  70.     if element_name == "concrete_ordinary":
  71.         mat = openmc.Material(name='concrete_ordinary')
  72.         mat.add_element('H', 1, percent_type='wo')
  73.         mat.add_element('C', 0.1, percent_type='wo')
  74.         mat.add_element('O', 52.9107, percent_type='wo')
  75.         mat.add_element('Na', 1.6, percent_type='wo')
  76.         mat.add_element('Mg', 0.2, percent_type='wo')
  77.         mat.add_element('Al', 3.3872, percent_type='wo')
  78.         mat.add_element('Si', 33.7021, percent_type='wo')
  79.         mat.add_element('K', 1.3, percent_type='wo')
  80.         mat.add_element('Ca', 4.4, percent_type='wo')
  81.         mat.add_element('Fe', 1.4, percent_type='wo')
  82.         mat.set_density('g/cm3', 2.3)
  83.        
  84.     return mat
  85.  
  86.  
  87. #################
  88. ### Materials ###
  89. #################
  90.  
  91. air_mat = Material_Library("air")
  92. concrete_mat = Material_Library("concrete_ordinary")
  93. materials = openmc.Materials([air_mat, concrete_mat])
  94.  
  95. materials.export_to_xml()
  96.  
  97.  
  98. ################
  99. ### Settings ###
  100. ################
  101.  
  102. # Run Settings
  103. settings = openmc.Settings()
  104. settings.batches = 10
  105. settings.inactive = 0
  106. settings.particles = 50000000
  107. settings.run_mode = "fixed source"
  108.  
  109. # Transport Settings
  110. settings.max_tracks = 1000
  111. settings.electron_treatment = 'ttb' # led ttb
  112.  
  113. # initialises a new source object.
  114. my_source = openmc.Source()
  115.  
  116. # the distribution of source z values is just a single value.
  117. x_values = openmc.stats.Uniform(a=-50, b=50)
  118. y_values = openmc.stats.Uniform(a=-50, b=50)
  119. z_values = openmc.stats.Uniform(a=0, b=0)
  120.  
  121. my_source.space = openmc.stats.CartesianIndependent(x=x_values, y=y_values, z=z_values)
  122.  
  123. # sets the direction normal to concrete surface.
  124. my_source.angle = openmc.stats.Monodirectional([0, 0, 1])
  125.  
  126. # sets the energy distribution.
  127. my_source.energy = openmc.stats.Discrete([0.6616e6, 1.1732e6, 1.3325e6], [0.8605, 0.0697, 0.0698])
  128. my_source.particle = 'photon'
  129.  
  130. # Select Source for OpenMC run.
  131. settings.source = my_source
  132.  
  133. settings.cutoff = {'energy_electron': 0.521e6,
  134.                    'energy_photon'  : 1e4}
  135.  
  136. # Export to xml.
  137. settings.export_to_xml()
  138.  
  139.  
  140. ################
  141. ### Geometry ###
  142. ################
  143.  
  144. left_layer_value = 0       # For shifting layers to the correct positions.
  145. concrete_thickness = 10    # thickness of concrete layers in cm.
  146.  
  147. # Initial air layer of 150 cm.
  148. left_layer_value += 75
  149. ini_air_region = create_cuboid([300, 300, 150], c=[0, 0, left_layer_value])
  150. ini_air_cell = openmc.Cell(region=ini_air_region)
  151. ini_air_cell.fill = air_mat
  152. left_layer_value += 75
  153.  
  154. # Concrete layers.
  155. left_layer_value += concrete_thickness/2
  156. concrete_region_1 = create_cuboid(d=[300, 300, concrete_thickness], c=[0, 0, left_layer_value])
  157. concrete_cell_1 = openmc.Cell(region=concrete_region_1)
  158. concrete_cell_1.fill = concrete_mat
  159. left_layer_value += concrete_thickness/2
  160.  
  161. left_layer_value += concrete_thickness/2
  162. concrete_region_2 = create_cuboid(d=[300, 300, concrete_thickness], c=[0, 0, left_layer_value])
  163. concrete_cell_2 = openmc.Cell(region=concrete_region_2)
  164. concrete_cell_2.fill = concrete_mat
  165. left_layer_value += concrete_thickness/2
  166.  
  167. left_layer_value += concrete_thickness/2
  168. concrete_region_3 = create_cuboid(d=[300, 300, concrete_thickness], c=[0, 0, left_layer_value])
  169. concrete_cell_3 = openmc.Cell(region=concrete_region_3)
  170. concrete_cell_3.fill = concrete_mat
  171. left_layer_value += concrete_thickness/2
  172.  
  173. left_layer_value += concrete_thickness/2
  174. concrete_region_4 = create_cuboid(d=[300, 300, concrete_thickness], c=[0, 0, left_layer_value])
  175. concrete_cell_4 = openmc.Cell(region=concrete_region_4)
  176. concrete_cell_4.fill = concrete_mat
  177. left_layer_value += concrete_thickness/2
  178.  
  179. left_layer_value += concrete_thickness/2
  180. concrete_region_5 = create_cuboid(d=[300, 300, concrete_thickness], c=[0, 0, left_layer_value])
  181. concrete_cell_5 = openmc.Cell(region=concrete_region_5)
  182. concrete_cell_5.fill = concrete_mat
  183. left_layer_value += concrete_thickness/2
  184.  
  185. # Final air layers of 10 cm and 140 cm.
  186. left_layer_value += 5
  187. fin_air_region_1 = create_cuboid([300, 300, 10], c=[0, 0, left_layer_value])
  188. fin_air_cell_1 = openmc.Cell(region=fin_air_region_1)
  189. fin_air_cell_1.fill = air_mat
  190. left_layer_value += 5
  191.  
  192. left_layer_value += 70
  193. fin_air_region_2 = create_cuboid([300, 300, 140], c=[0, 0, left_layer_value])
  194. fin_air_cell_2 = openmc.Cell(region=fin_air_region_2)
  195. fin_air_cell_2.fill = air_mat
  196. left_layer_value += 70
  197.  
  198. # Vacuum
  199. outer_region = create_cuboid([300.001, 300.001, left_layer_value+0.001], c=[0, 0, left_layer_value/2], boundary="vacuum")
  200. outer_cell = openmc.Cell(region=outer_region)
  201.  
  202. # makes a universe to contain all the cells
  203. universe = openmc.Universe(cells=[ini_air_cell,
  204.                                   concrete_cell_1, concrete_cell_2, concrete_cell_3, concrete_cell_4, concrete_cell_5,
  205.                                   fin_air_cell_1, fin_air_cell_2,
  206.                                   outer_cell])
  207. geometry = openmc.Geometry(universe)
  208.  
  209. geometry.export_to_xml()
  210.  
  211.  
  212. ###############
  213. ### Tallies ###
  214. ###############
  215.  
  216. tallies = openmc.Tallies()
  217.  
  218. particle_filter = openmc.ParticleFilter("photon")
  219. cell_filter = openmc.CellFilter([concrete_cell_1, concrete_cell_2, concrete_cell_3, concrete_cell_4, concrete_cell_5,fin_air_cell_1])
  220. energy_array = np.array([0.01, 0.0249, 0.0398, 0.0547, 0.0696, 0.0845, 0.0994, 0.1143, 0.1292, 0.1441, 0.159, 0.1739, 0.1888,
  221.                          0.2037, 0.2186, 0.2335, 0.2484, 0.2633, 0.2782, 0.2931, 0.308, 0.3229, 0.3378, 0.3527, 0.3676, 0.3825,
  222.                          0.3974, 0.4123, 0.4272, 0.4421, 0.457, 0.4719, 0.4868, 0.5017, 0.5166, 0.5315, 0.5464, 0.5613, 0.5762,
  223.                          0.5911, 0.606, 0.6209, 0.6358, 0.6507, 0.6656, 0.6805, 0.6954, 0.7103, 0.7252, 0.7401, 0.755, 0.7699,
  224.                          0.7848, 0.7997, 0.8146, 0.8295, 0.8444, 0.8593, 0.8742, 0.8891, 0.904, 0.9189, 0.9338, 0.9487, 0.9636,
  225.                          0.9785, 0.9934, 1.0083, 1.0232, 1.0381, 1.053, 1.0679, 1.0828, 1.0977, 1.1126, 1.1275, 1.1424, 1.1573,
  226.                          1.1722, 1.1871, 1.202, 1.2169, 1.2318, 1.2467, 1.2616, 1.2765, 1.2914, 1.3063, 1.3212, 1.3361, 1.351,
  227.                          1.3659, 1.3808, 1.3957, 1.4106, 1.4255, 1.4404, 1.4553, 1.4702, 1.4851, 1.5])
  228. energy_array *= 1e6
  229. energy_filter = openmc.EnergyFilter(energy_array)
  230.  
  231. flux_tally = openmc.Tally(name='Photon Flux')
  232. flux_tally.filters = [cell_filter, energy_filter, particle_filter]
  233.  
  234. flux_tally.scores = ['flux']
  235. tallies.append(flux_tally)
  236.  
  237.  
  238. ###################
  239. ### Calculation ###
  240. ###################
  241.  
  242. model = openmc.model.Model(geometry, materials, settings, tallies)
  243. sp_filename = model.run(tracks=True)
  244.  
  245.  
  246. ###############
  247. ### Results ###
  248. ###############
  249.  
  250. # calculate mean flux per volume
  251. tally = openmc.StatePoint('statepoint.10.h5').get_tally(name="Photon Flux")
  252. photon_flux = tally.mean
  253. photon_flux = photon_flux / (300*300*10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement