# Rotating rectangular\_prism()

**URL:** <https://openmc.discourse.group/t/rotating-rectangular-prism/3335>\
**Category:** User Support\
**Created:** [August 19, 2023, 9:53am UTC](https://openmc.discourse.group/t/rotating-rectangular-prism/3335 "2023-08-19T09:53:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruri](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@Ruri](https://openmc.discourse.group/u/Ruri)\
**Post date:** [August 19, 2023, 9:53am UTC](https://openmc.discourse.group/t/rotating-rectangular-prism/3335/1 "2023-08-19T09:53:55Z")

</div>

I want to create a rectangular prism shape with circular corner sides. I am using **openmc.model.rectangular\_prism** to create it. I have successfully created it and positioned it in coordinates. I want to rotate the prism by 45 degrees, so I added the **“rotate()”** command to rotate it. However, the result I obtained changed the initial coordinates of the prism, and the prism did not rotate according to the desired inclination. How should I rotate it so that it has the correct inclination but still remains at the same (x, y) coordinates?

 ![no rotate](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/4/45450c87e263e7f6ad0876e1c676e93bd96316c3.png) ![with rotate](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/6/6a87e7e1f60054733caa6c1348ce96684bf03d19.png)

 ![core design](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/a/a02719143100dbcc21cc2402196096a2946203d3.jpeg)

```auto
r_ch = 98.6
r_cir = 3
s_rec	= 10
h_rec	= 2* r_cir

pipe = openmc.model.rectangular_prism(s_rec, h_rec, axis='z', origin=((sin(pi/4)*r_ch), (cos(pi/4)*r_ch)), corner_radius=r_cir, )

ppu	= (pipe).rotate((0,45,0))

pipe_cell = openmc.Cell(fill= helium , region=ppu & -t_act_core & +ct_dum_core)

```

---

<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:** [August 20, 2023, 3:58am UTC](https://openmc.discourse.group/t/rotating-rectangular-prism/3335/2 "2023-08-20T03:58:43Z")

</div>

@Ruri The `rotate` method has [a `pivot` argument](https://docs.openmc.org/en/stable/pythonapi/generated/openmc.Region.html#openmc.Region.rotate) that allows you to choose that point around which things are rotated. If it is not specified, the point (0, 0, 0) is used as the pivot, which is why your prism will get shifted. I believe you should use the origin of your prism as the pivot point too so that it is rotated about its center. Also, assuming based on the figres that the direction into/out of the page is the z direction, you probably want to rotate about the z axis (e.g., `(0, 0, 45)`)

---

<div class="post-metadata">

**Author:** ![Ruri](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@Ruri](https://openmc.discourse.group/u/Ruri)\
**Post date:** [August 20, 2023, 4:56am UTC](https://openmc.discourse.group/t/rotating-rectangular-prism/3335/3 "2023-08-20T04:56:09Z")

</div>

Thank you, Dr. @paulromano . I have completed the problem with your guidance.

```auto
r_ch = 98.6
r_cir = 3
s_rec	= 10
h_rec	= 2* r_cir

pipe = openmc.model.rectangular_prism(s_rec, h_rec, axis='z', origin=((sin(pi/4)*r_ch), (cos(pi/4)*r_ch)), corner_radius=r_cir, )

ppu	= (pipe).rotate((0,0,-45), pivot=((sin(pi/4)*r_ch), (cos(pi/4)*r_ch), 0.0), order='xyz', inplace=False, memo=None)

pipe_cell = openmc.Cell(fill= fuel, region=ppu & -t_act_core & +ct_dum_core)

```

 ![fix](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/b/ba9fbb4a7e3aa7ff0dcceb2548a1821f8f0e0b1c.png)

Currently, I would like to distribute 2-3 different types of pebbles (fuel pebble, moderator pebble) within a 3D core randomly. Is the approach for doing this the same as distributing TRISO particles within a spherical geometry ?, but this time using the boundaries of a cylindrical geometry type?

Is it possible to distribute the three pebbles randomly with a specific ratio? If possible, could you provide guidance for me to solve this problem?

---

<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:** [August 20, 2023, 5:11am UTC](https://openmc.discourse.group/t/rotating-rectangular-prism/3335/4 "2023-08-20T05:11:52Z")

</div>

You can use the `openmc.model.pack_spheres` function to get the coordinates of all pebbles (fuel + moderator + …). Then you can split them up as desired between the different pebble types, creating an `openmc.model.TRISO` object for each.

---

<div class="post-metadata">

**Author:** ![Ruri](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@Ruri](https://openmc.discourse.group/u/Ruri)\
**Post date:** [August 21, 2023, 3:55pm UTC](https://openmc.discourse.group/t/rotating-rectangular-prism/3335/5 "2023-08-21T15:55:11Z")

</div>

I’ve created a model as shown in " [Modeling TRISO Particles](https://nbviewer.org/github/openmc-dev/openmc-notebooks/blob/main/triso.ipynb)", and I’m trying to distribute fuel and moderator, but only one type of pebble is coming out in the geometry.

```auto
##fuel 1 distribution
fuel1_pebble = openmc.model.pack_spheres(radius=outer_radius, region= active_core , pf=0.3, num_spheres=0.57*tot_pebble)
fuel1_pack = [openmc.model.TRISO(outer_radius, fill = fuel_spheres_unv , center=c) for c in fuel1_pebble]

fuel_1_box = openmc.Cell(region = active_core )
lower_left_f1, upper_right_f1 = fuel_1_box.region.bounding_box
shape_f1 = (5, 5, 5)
pitch_f1 = (upper_right_f1 - lower_left_f1)/shape_f1
lattice_f1 = openmc.model.create_triso_lattice(fuel1_pack, lower_left_f1, pitch_f1, shape_f1, helium)
fuel_1_box.fill = lattice_f1

pebble_universe = openmc.Universe(cells = ([fuel_1_box,]))
fuel1_cell_distribution = openmc.Cell(region = active_core, fill = pebble_universe)

##moderator distribution
moderator_pebble = openmc.model.pack_spheres(radius=outer_radius, region= active_core , pf=0.3, num_spheres=0.43*tot_pebble)
moderator_pack = [openmc.model.TRISO(outer_radius, fill = moderator_spheres_unv , center=c) for c in moderator_pebble]

moderator_box = openmc.Cell(region = active_core )
lower_left_mod, upper_right_mod	= moderator_box.region.bounding_box
shape_mod = (4, 4, 4)
pitch_mod = (upper_right_mod - lower_left_mod)/shape_mod
lattice_mod = openmc.model.create_triso_lattice(moderator_pack, lower_left_mod, pitch_mod, shape_mod, helium)
moderator_box.fill = lattice_mod

mod_pebble_universe = openmc.Universe(cells = ([moderator_box,]))
mod_cell_distribution = openmc.Cell(region = active_core, fill = mod_pebble_universe)

```

 ![plot_1](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/3/3aabd4f7b6b6ac91e8ea270c559a42e11b5ffeaa.png)

---

<div class="post-metadata">

**Author:** ![Ruri](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@Ruri](https://openmc.discourse.group/u/Ruri)\
**Post date:** [August 26, 2023, 3:20am UTC](https://openmc.discourse.group/t/rotating-rectangular-prism/3335/6 "2023-08-26T03:20:33Z")

</div>

Sorry @paulromano , I’ve tried to adjust my code, but I still can’t distribute 2 pebbles at once, only 1 type of pebble appears when I plot the code. Can you point out the error in my code

---

<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:** [August 26, 2023, 5:39am UTC](https://openmc.discourse.group/t/rotating-rectangular-prism/3335/7 "2023-08-26T05:39:30Z")

</div>

Again, you should have only a single call to `pack_spheres` that generates the pebble locations for both fuel/moderator pebbles. Then your `pack` variable, which is a list, needs to include both `TRISO(..., fill=fuel_spheres_univ)` and `TRISO(..., fill=moderator_spheres_univ)` wherever you want fuel and moderator pebbles to show up. It is up to you how you want to split up the pebble locations that are returned by `pack_spheres`. For example if you wanted to randomly pick fuel/moderator with probability 0.5:

```auto
pebbles = openmc.model.pack_spheres(...)
pack = []
for c in pebbles:
    if random.random() < 0.5:
        pack.append(openmc.model.TRISO(fill=fuel_spheres_univ, ...))
    else:
        pack.append(openmc.model.TRISO(fill=moderator_spheres_univ, ...))

```

This is just one way you could go about it.

---

<div class="post-metadata">

**Author:** ![Ruri](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@Ruri](https://openmc.discourse.group/u/Ruri)\
**Post date:** [August 26, 2023, 8:08am UTC](https://openmc.discourse.group/t/rotating-rectangular-prism/3335/8 "2023-08-26T08:08:25Z")

</div>

Thanks @paulromano , it solved the problem
