Question for mesh tallys and cells, very different values

import openmc
import numpy as np
import pandas as pd

import os
os.environ[‘OPENMC_CROSS_SECTIONS’] = ‘’
openmc.config[‘cross_sections’] = ‘’

Materials

air=openmc.Material(name=‘air’)
air.add_element(‘N’,80)
air.add_element(‘O’,20)
air.set_density(‘g/cm3’,1.3e-3)

materials = openmc.Materials([air])
materials.export_to_xml()

Geometry

Limiting Planes

Xm = openmc.XPlane( x0=-300, name=‘X-’, boundary_type=‘vacuum’)
Xp = openmc.XPlane( x0=+300, name=‘X+’, boundary_type=‘vacuum’)
Ym = openmc.YPlane( y0=-300, name=‘Y-’, boundary_type=‘vacuum’)
Yp = openmc.YPlane( y0=+300, name=‘Y+’, boundary_type=‘vacuum’)
Bottom= openmc.ZPlane(z0= 0, boundary_type=‘vacuum’)
Top= openmc.ZPlane(z0= 300, boundary_type=‘vacuum’)

Create root Universe

root_universe = openmc.Universe(universe_id=0, name=‘root universe’)

Create a cell to be used as a spherical detector

detector_sphere = openmc.Sphere(r = 25, x0 = 100, y0 = 0, z0 = 150) #Uncomment to simulate the case in which the source is outside the sphere
#detector_sphere = openmc.Sphere(r = 25, x0 = 0, y0 = 0, z0 = 150) #Uncomment to simulate the case in which the source is inside the sphere
#detector_sphere = openmc.Sphere(r = 25, x0 = 0, y0 = 100, z0 = 150) #Uncomment to simulate the effect of superimposing MeshFilter and CellFilter
detector_cell = openmc.Cell(fill = air, region = -detector_sphere)

Create Main Region

main_cell = openmc.Cell(name=‘source et fill’)
main_cell.fill = air
main_cell.region = -Top & +Bottom & -Yp & +Xm & +Ym & -Xp & +detector_sphere

root_universe.add_cells([main_cell,detector_cell])

Create Geometry and set root Universe

geometry = openmc.Geometry(root_universe)

Export to “geometry.xml”

geometry.export_to_xml()

cubic_mesh = openmc.RegularMesh()
cubic_mesh.dimension = [1, 1, 1]
cubic_mesh.lower_left = [-20, 80, 130] #Uncomment to simulate the case in which the source is outside the sphere
cubic_mesh.upper_right = [+20, 120, 170] #Uncomment to simulate the case in which the source is outside the sphere
#cubic_mesh.lower_left = [-20, -20, 130] #Uncomment to simulate the case in which the source is inside the sphere
#cubic_mesh.upper_right = [+20, 20, 170] #Uncomment to simulate the case in which the source is inside the sphere#
cubic_mesh_filter = openmc.MeshFilter(cubic_mesh)

spherical_mesh = openmc.SphericalMesh()
spherical_mesh.origin = [0,100,150] #Uncomment to simulate the case in which the source is outside the sphere
#spherical_mesh.origin = [0,0,150] #Uncomment to simulate the case in which the source is inside the sphere
spherical_mesh.r_grid = [0,25.]
spherical_mesh_filter = openmc.MeshFilter(spherical_mesh)

cellfilter = openmc.CellFilter(detector_cell)

Instantiate an empty Tallies object

tallies = openmc.Tallies()

Flux tally - Cube Tracklength

cube_track = openmc.Tally(name=‘Cube Tracklength’)
cube_track.filters = [cubic_mesh_filter]
cube_track.scores = [‘flux’]
cube_track.estimator = ‘tracklength’
tallies.append(cube_track)

Flux tally - Sphere Tracklength

sphere_track = openmc.Tally(name=‘Sphere Tracklength’)
sphere_track.filters = [spherical_mesh_filter]
sphere_track.scores = [‘flux’]
sphere_track.estimator = ‘tracklength’
tallies.append(sphere_track)

Flux tally - Cube Collision

cube_coll = openmc.Tally(name=‘Cube Collision’)
cube_coll.filters = [cubic_mesh_filter]
cube_coll.scores = [‘flux’]
cube_coll.estimator = ‘collision’
tallies.append(cube_coll)

Flux tally - Sphere Collision

sphere_coll = openmc.Tally(name=‘Sphere Collision’)
sphere_coll.filters = [spherical_mesh_filter]
sphere_coll.scores = [“flux”]
sphere_coll.estimator = ‘collision’
tallies.append(sphere_coll)
tallies.export_to_xml()

Flux tally - Spherical Cell Tracklength

cell_track = openmc.Tally(name=‘Cell Tracklength’)
cell_track.filters = [cellfilter]
cell_track.scores = [‘flux’]
cell_track.estimator = ‘tracklength’
tallies.append(cell_track)

Flux tally - Spherical Cell Collision

cell_coll = openmc.Tally(name=‘Cell Collision’)
cell_coll.filters = [cellfilter]
cell_coll.scores = [“flux”]
cell_coll.estimator = ‘collision’
tallies.append(cell_coll)
tallies.export_to_xml()

Source

src = openmc.Source()
src.space=openmc.stats.Point((0.0000, 0.0000, 150.))
src.energy = openmc.stats.Discrete([1.3e6],1)
src.strength = 1e10
src.particle =‘photon’
src.angle = openmc.stats.Isotropic()

Settings

settings = openmc.Settings()
settings.source = src
settings.seed = 2
settings.run_mode=‘fixed source’
settings.batches = 1000
settings.inactive = 20
settings.particles = 4000
settings.export_to_xml()

Run the model

openmc.run()

post_processing

with openmc.StatePoint(“statepoint.1000.h5”) as sp:

cube_track = sp.get_tally(name='Cube Tracklength')
sphere_track = sp.get_tally(name='Sphere Tracklength')
cube_coll = sp.get_tally(name='Cube Collision')
sphere_coll = sp.get_tally(name='Sphere Collision')
cell_track = sp.get_tally(name='Cell Tracklength')
cell_coll = sp.get_tally(name='Cell Collision')

sp.close()

print(“Tracklength Estimator - Sphere: " + str(sphere_track.mean[0,0,0]))
print(“Collision Estimator - Sphere: " + str(sphere_coll.mean[0,0,0]))
print(”\n\n”)
print(“Tracklength Estimator - Cube: " + str(cube_track.mean[0,0,0]))
print(“Collision Estimator - Cube: " + str(cube_coll.mean[0,0,0]))
print(”\n\n”)
print("Tracklength Estimator - Spherical Cell: " + str(cell_track.mean[0,0,0]))
print("Collision Estimator - Spherical Cell: " + str(cell_coll.mean[0,0,0]))