# Lattice Cell as Tally CellFilter

**URL:** <https://openmc.discourse.group/t/lattice-cell-as-tally-cellfilter/1071>\
**Category:** User Support\
**Created:** [March 17, 2021, 9:58am UTC](https://openmc.discourse.group/t/lattice-cell-as-tally-cellfilter/1071 "2021-03-17T09:58:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicola](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/nicola/32/1163_2.png) [@nicola](https://openmc.discourse.group/u/nicola)\
**Post date:** [March 17, 2021, 9:58am UTC](https://openmc.discourse.group/t/lattice-cell-as-tally-cellfilter/1071/1 "2021-03-17T09:58:52Z")

</div>

Dears,

I apologize in advance if my question comes as naive.

Consider the attached [figure](https://github.com/nicolacavallini/openmc-ex/blob/master/model.pdf).

I want to use the three copies of Cell0 as volumes to define a CellFilter tally.

When I try to retrieve them from CellW, I basically get three copies of the same cell. On the other hand, when I plot the geometry, I correctly get them in the intended position in the world reference.

I attach the [code too](https://github.com/nicolacavallini/openmc-ex/blob/master/question.py), that is a little simpler than the picture, it only includes the three copies of Cell0 and its surroundings.

I will help with the coding if necessary.

thanks a lot,  
Nicola

---

<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:** [March 19, 2021, 12:32pm UTC](https://openmc.discourse.group/t/lattice-cell-as-tally-cellfilter/1071/2 "2021-03-19T12:32:53Z")

</div>

Hi @nicola and welcome to the forum! The normal `CellFilter` is not capable of distinguishing between multiple instances of the same underlying cell (as used in multiple universes/lattices). If you want a separate tally for that cell in each of the different lattice positions, you would need to use `CellInstanceFilter`. If those are the only three instances of that cell, the following should work:

```auto
tally.filters = [CellInstanceFilter([(d_cell, 0), (d_cell, 1), (d_cell, 2)])]

```

---

<div class="post-metadata">

**Author:** ![nicola](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/nicola/32/1163_2.png) [@nicola](https://openmc.discourse.group/u/nicola)\
**Post date:** [March 22, 2021, 10:38am UTC](https://openmc.discourse.group/t/lattice-cell-as-tally-cellfilter/1071/4 "2021-03-22T10:38:08Z")

</div>

Hi @paulromano thanks a lot, I will refer to [this test](https://github.com/openmc-dev/openmc/blob/develop/tests/regression_tests/filter_cellinstance/test.py) for usage.

I have still one question. How to I link the instance number, to the actual instance coordinates?  
thanks a lot 🙂

---

<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:** [March 23, 2021, 11:29am UTC](https://openmc.discourse.group/t/lattice-cell-as-tally-cellfilter/1071/5 "2021-03-23T11:29:20Z")

</div>

That’s a very good question. Right now, it’s not super easy to figure out how the instance number relates to coordinates. In your particular case, the instances will be numbered from bottom to top in the lattice starting at 0. In the general case, the only way you can get at this right now is if you know the coordinate of a point contained in the cell you are interested in. If this coordinate is (x,y,z), you can use the following code to determine it:

```auto
import openmc.lib

openmc.lib.init()
cell, instance = openmc.lib.find_cell((x, y, z))
print(f'Cell {cell.id}, Instance {instance}')
openmc.lib.finalize()

```

We’re planning on adding support to our [plotting application](https://github.com/openmc-dev/plotter/) for showing instance numbers, which would make this a lot easier.

---

<div class="post-metadata">

**Author:** ![nicola](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/nicola/32/1163_2.png) [@nicola](https://openmc.discourse.group/u/nicola)\
**Post date:** [March 24, 2021, 8:35am UTC](https://openmc.discourse.group/t/lattice-cell-as-tally-cellfilter/1071/6 "2021-03-24T08:35:06Z")

</div>

Thanks a lot Paul, that’s a good starting point.

Cannot promise much, but I would like to study the code and see if I can contribute.
