# How to calculate the neutron flux of each lattiece universe (corresponding cell)

**URL:** <https://openmc.discourse.group/t/how-to-calculate-the-neutron-flux-of-each-lattiece-universe-corresponding-cell/3671>\
**Category:** User Support\
**Created:** [November 23, 2023, 7:12am UTC](https://openmc.discourse.group/t/how-to-calculate-the-neutron-flux-of-each-lattiece-universe-corresponding-cell/3671 "2023-11-23T07:12:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZENGJIE](https://avatars.discourse-cdn.com/v4/letter/z/898d66/32.png) [@ZENGJIE](https://openmc.discourse.group/u/ZENGJIE)\
**Post date:** [November 23, 2023, 7:12am UTC](https://openmc.discourse.group/t/how-to-calculate-the-neutron-flux-of-each-lattiece-universe-corresponding-cell/3671/1 "2023-11-23T07:12:38Z")

</div>

Hello! I’m a new openmc scholar.  
I use lattiece to build 3D models, but I need to calculate the neutron flux of each lattiece universe (corresponding cell)  
Like mcnp’s input card:  
99999 0 -52 51 -62 61 -72 71 u=99999 lat=1 fill=0:35 0:35 0:35  
…  
100000 0 -53 51 -63 61 -73 71 fill=99999  
…  
F14:n (99999 \< 99999[0:35 0:35 0:35] \< 100000)

Such as:  
I use lattiece to build 3D models:

```auto
# 
cell1001 = openmc.Cell(cell_id=1001,fill =m6,region= -sphere100) 
cell2001 = openmc.Cell(cell_id=2001,fill =m4,region= -sphere100) 
cell3001 = openmc.Cell(cell_id=3001,fill =m5,region= -sphere100) 

# universe 
u1001 = openmc.Universe()
u1001.add_cell(cell1001)
u2001 = openmc.Universe()
u2001.add_cell(cell2001)
u3001 = openmc.Universe()
u3001.add_cell(cell3001)

# 36*36*36
target_shape=(36,36,36)
array_water = np.zeros(target_shape, dtype=object)
array_water = np.transpose(array_water , (2, 1, 0))
array_water[:] = u2001
array_water[0,:,:] = u1001
array_water[:,0,:] = u2001
array_water[...,0] = u3001

lat3d = openmc.RectLattice(name='Head univ') #
lat3d.pitch = (space_x, space_y, space_z) 
lat3d.lower_left = (-5, -5, 3.5)
lat3d.universes=array_water

```

thanks very much !

I use CellInstanceFilter to do that:

```auto
cell_instances = ([lat3d])
cell_instances = [(lat3d, i) for i in range(0, 36*36*36, 1)]
cellinst_filter = openmc.CellInstanceFilter(cell_instances,filter_id =1)

particle_filter = openmc.ParticleFilter(['neutron']) 
energy_filter = openmc.EnergyFilter([0, 0.5,10E+03,10E+06])

# Instantiate flux tally Filter
flux_cell_tally = openmc.Tally(name="neutron_flux_on_mesh")
multiplier = openmc.EnergyFunctionFilter([0.0, 2e7], [1/C100, 1/C100])
flux_cell_tally.filters = [cellinst_filter, particle_filter,energy_filter,multiplier]
f
![image|690x278](upload://buTecpFhH9jvaTlEiDHoM9fAOIx.png)
lux_cell_tally.scores = ['flux']

```

But

 ![image](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/5/5095d71f0e969a4884e9ac0bb09b78d28c513541.png)  
What am I supposed to do?

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [November 27, 2023, 7:52pm UTC](https://openmc.discourse.group/t/how-to-calculate-the-neutron-flux-of-each-lattiece-universe-corresponding-cell/3671/2 "2023-11-27T19:52:17Z")

</div>

For `CellInstanceFilter`, you need to give it tuples of (cell, index). So for example, you could use `cell1001` or `cell2001`, but not `lat3d` which is a `RectLattice` object. If you are not looking for a specific cell within each lattice element but rather a score for the entirety of each lattice element, you could use a `MeshFilter` with a mesh that lines up with the rectangular lattice.

---

<div class="post-metadata">

**Author:** ![ZENGJIE](https://avatars.discourse-cdn.com/v4/letter/z/898d66/32.png) [@ZENGJIE](https://openmc.discourse.group/u/ZENGJIE)\
**Post date:** [November 28, 2023, 6:16am UTC](https://openmc.discourse.group/t/how-to-calculate-the-neutron-flux-of-each-lattiece-universe-corresponding-cell/3671/3 "2023-11-28T06:16:15Z")

</div>

@ paulromano thank you very much! Because the cell needs to be rotated at a certain Angle, if the MeshFilter is used, part of the cell is not tally。May I ask, is there a good way to tally each Universe of lattiece（cell of lattiece）？Can the mesh be rotated?

---

<div class="post-metadata">

**Author:** ![yrrepy](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/yrrepy/32/2365_2.png) [@yrrepy](https://openmc.discourse.group/u/yrrepy)\
**Post date:** [November 28, 2023, 7:07am UTC](https://openmc.discourse.group/t/how-to-calculate-the-neutron-flux-of-each-lattiece-universe-corresponding-cell/3671/4 "2023-11-28T07:07:36Z")

</div>

I recommend using the _distribcell_ filter to score each individual lattice element

[https://docs.openmc.org/en/stable/pythonapi/generated/openmc.DistribcellFilter.html](https://docs.openmc.org/en/stable/pythonapi/generated/openmc.DistribcellFilter.html)

[https://docs.openmc.org/en/latest/io\_formats/tallies.html#filter-element](https://docs.openmc.org/en/latest/io_formats/tallies.html#filter-element)

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [November 28, 2023, 12:42pm UTC](https://openmc.discourse.group/t/how-to-calculate-the-neutron-flux-of-each-lattiece-universe-corresponding-cell/3671/5 "2023-11-28T12:42:48Z")

</div>

> [@ZENGJIE](#):
>
> is there a good way to tally each Universe of lattiece（cell of lattiece）？Can the mesh be rotated?

Unfortunately the answer to both of these at present is no.

---

<div class="post-metadata">

**Author:** ![ZENGJIE](https://avatars.discourse-cdn.com/v4/letter/z/898d66/32.png) [@ZENGJIE](https://openmc.discourse.group/u/ZENGJIE)\
**Post date:** [November 30, 2023, 1:19am UTC](https://openmc.discourse.group/t/how-to-calculate-the-neutron-flux-of-each-lattiece-universe-corresponding-cell/3671/6 "2023-11-30T01:19:35Z")

</div>

thank you very much！ I’ll try it your way。

---

<div class="post-metadata">

**Author:** ![ZENGJIE](https://avatars.discourse-cdn.com/v4/letter/z/898d66/32.png) [@ZENGJIE](https://openmc.discourse.group/u/ZENGJIE)\
**Post date:** [November 30, 2023, 1:22am UTC](https://openmc.discourse.group/t/how-to-calculate-the-neutron-flux-of-each-lattiece-universe-corresponding-cell/3671/7 "2023-11-30T01:22:33Z")

</div>

😅 thank you very much！Can I ask you something about the rotation，About lattiece rotation?
