# Locality rotation and translation

**URL:** <https://openmc.discourse.group/t/locality-rotation-and-translation/3672>\
**Category:** User Support\
**Created:** [November 24, 2023, 8:21am UTC](https://openmc.discourse.group/t/locality-rotation-and-translation/3672 "2023-11-24T08:21:01Z")\
**Posts on this page:** 2\
**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 24, 2023, 8:21am UTC](https://openmc.discourse.group/t/locality-rotation-and-translation/3672/1 "2023-11-24T08:21:01Z")

</div>

Hello, everyone！I use the **rotation and translation** functions to do partial rotate and translate of the model。Such as：

```auto
# Materials definitions
m1 = openmc.Material(material_id=1,name='AIR') #空气
m1.add_element('C',0.001205,'wo')
m1.add_nuclide('N14',0.7552927,'wo')
m1.add_nuclide('O16',0.231787,'wo')
m1.add_element('Ca',0.0128004,'wo')
m1.set_density('g/cm3', 0.001293)

m2 = openmc.Material(material_id=2, name='Pb')
m2.set_density('g/cc', 11.35)
m2.add_nuclide('Pb204', 0.0148 ,'wo') #1
m2.add_nuclide('Pb206',0.241,'wo')
m2.add_nuclide('Pb207', 0.226,'wo') #7
m2.add_nuclide('Pb208', 0.523,'wo') #8

m3 = openmc.Material(material_id=3, name='polyethylene')
m3.set_density('g/cc', 0.9843)
m3.add_nuclide('H1', 0.5262,'wo') #1
m3.add_element('C',0.2969,'wo')
m3.add_nuclide('O16', 0.1007,'wo') #7
m3.add_nuclide('Li6', 0.0724,'wo') #8
m3.add_nuclide('Li7', 0.0038,'wo') #11
m3.add_s_alpha_beta('c_H_in_H2O')

# Instantiate a Materials collection and export to xml
materials = openmc.Materials([m1,m2,m3])
materials.export_to_xml()

# surface
sphere100 = openmc.Sphere(x0=0,y0=0,z0=0,r=1000, boundary_type='vacuum')
ZCone6 = openmc.ZCone(x0=0,y0=0,z0=5.4, r2=(18/5.4)**2,boundary_type='transmission') 
zplane25 = openmc.ZPlane(z0=-10.8,boundary_type='vacuum')  
zplane4 = openmc.ZPlane(z0=0.0,boundary_type='transmission')
zplane8 = openmc.ZPlane(z0=3.0,boundary_type='transmission') 
xplane1 = openmc.XPlane(x0=-40,boundary_type='transmission')  
xplane2 = openmc.XPlane(x0=40,boundary_type='transmission')    
yplane1 = openmc.YPlane(y0=-40,boundary_type='transmission')  
yplane2 = openmc.YPlane(y0=40,boundary_type='transmission')

# Air preceeding Skin
cell3 = openmc.Cell(cell_id=3,fill =m3,region=+xplane1 & -xplane2 & +yplane1 & -yplane2 & -zplane4 & +zplane25) 
cell4 = openmc.Cell(cell_id=4,fill =m2,region= +zplane4 &-zplane8 & -ZCone6) 

rpp = openmc.model.RectangularParallelepiped(-5, 5, -5, 5, 23.5, 33.5)
rpp1 = openmc.model.RectangularParallelepiped(-3, 3, -3, 3, 25.5, 31.5)
cell23= openmc.Cell(cell_id=23,fill =m3,region= -rpp & +rpp1)
cell24= openmc.Cell(cell_id=24,fill =m2,region= -rpp1)
root1 = openmc.Universe(cells=[cell23,cell24])
cell21= openmc.Cell(cell_id=21,fill =root1,region= -rpp)
cell21.rotation=(0,45,45) #旋转参考x y z轴
cell21.translation=(0,20,20)

region1=cell21.region

cell30 = openmc.Cell(cell_id=30,fill =m1,region= ~((+xplane1 & -xplane2 & +yplane1 & -yplane2 & -zplane4 & +zplane25 )
                           | ( +zplane4 &-zplane8 & -ZCone6)| region1) 
                            & -sphere100)
root_universe = openmc.Universe(cells=( cell3, cell4, cell21, cell30 ))
geometry = openmc.Geometry(root_universe)
geometry.export_to_xml()

# 画图形
root_universe .plot(origin=(0, 0, 23.5),basis = 'yz',width=(100,100) ,color_by = 'material')
plt.show()
root_universe .plot(origin=(0, 0, 23.5),basis = 'xz',width=(100, 100),color_by = 'cell')
plt.show()
root_universe .plot(origin=(0, 0, 28.5),basis = 'xy',width=(100, 100),color_by = 'cell')
plt.show()

```

but，The result is that：There was a particle leak。  
Modeling model：  
 ![image](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/0/0bc7d13daf5942963b71243d224e765b26456956.png)  
 ![image](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/8/8d57fc512dcbd0ae288df2a997fc4d13a459d61f.png)

how do it？  
thanks very much！

---

<div class="post-metadata">

**Author:** ![pshriwise](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/pshriwise/32/3863_2.png) [@pshriwise](https://openmc.discourse.group/u/pshriwise)\
**Post date:** [January 24, 2024, 10:59pm UTC](https://openmc.discourse.group/t/locality-rotation-and-translation/3672/2 "2024-01-24T22:59:47Z")

</div>

Hi @ZENGJIE,

Thanks for your post. I think the problem is that you’re creating the cells in their final position _and_ rotating+translating them into place. It also helps to define universes with an infinite cell surrounding all other cells to avoid lost particle problems. I’ve created a notebook to demonstrate how some of these transformations work in more detail. I hope it’s helpful:

> <https://gist.github.com/pshriwise/5429f894b2ff3dc51107e492137f8f2f>
