# Periodic Boundary Conditions

**URL:** <https://openmc.discourse.group/t/periodic-boundary-conditions/1141>\
**Category:** User Support\
**Created:** [April 16, 2021, 5:03pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141 "2021-04-16T17:03:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gwenchee](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gwenchee](https://openmc.discourse.group/u/gwenchee)\
**Post date:** [April 16, 2021, 5:03pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141/1 "2021-04-16T17:03:13Z")

</div>

Hi all,

I recently updated OpenMC to v0.12.1 and my input file that previously worked is now throwing an error for periodic boundary conditions. The error is:

```
libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: Rotational periodic BCs are only supported for rotations about the origin, but surface 4 does not intersect the origin.

```

I have attached a minimal working example.  
[test.py](https://openmc.discourse.group/uploads/short-url/AiJMj46oW5v2J599o7fkY5Z0LZJ.py) (2.0 KB)  
My geometry is a hexagonal fuel assembly with periodic boundary conditions.

 ![173766357_757152594850457_2485671841439369730_n](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/7/77b4b3c37ae6ca49cc3467b15530510fc41fd730.jpeg)  
I read in the documentation that "If both planes have the same normal vector, a translational  
periodicity is assumed; rotational periodicity is assumed otherwise. " I’m not sure why OpenMC does not recognize the paired surfaces as having the same normal vector. Any ideas to why this is happening?

Best,  
Gwen

---

<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:** [April 19, 2021, 12:28pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141/2 "2021-04-19T12:28:22Z")

</div>

Thanks for reporting this @gwenchee. It looks like when we expanded boundary conditions in our latest release, we messed up this particular case. Right now it only works for general planes (Ax + By + Cy = D) if you have √(A² + B² + C²) = 1. A workaround for your particular case then is as follows:

```auto
def plane(m, x, y, bc="transmission"):
    norm = np.sqrt(1 + m*m)
    return openmc.Plane(a=-m/norm, b=1/norm, d=(-m * x + y)/norm, boundary_type=bc)

```

I’ll get a proper fix submitted today so that this is not an issue in the future.

By the way, you may be interested in the [openmc.model.hexagonal\_prism](https://docs.openmc.org/en/latest/pythonapi/generated/openmc.model.hexagonal_prism.html#openmc.model.hexagonal_prism) function that makes it much easier to create geometries with hexagonal prisms in them!

---

<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:** [April 19, 2021, 12:49pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141/3 "2021-04-19T12:49:55Z")

</div>

Fix has been [submitted](https://github.com/openmc-dev/openmc/pull/1820) for review.

---

<div class="post-metadata">

**Author:** ![gwenchee](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gwenchee](https://openmc.discourse.group/u/gwenchee)\
**Post date:** [April 19, 2021, 1:05pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141/5 "2021-04-19T13:05:41Z")

</div>

Thank you for the fix!

---

<div class="post-metadata">

**Author:** ![gwenchee](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gwenchee](https://openmc.discourse.group/u/gwenchee)\
**Post date:** [October 14, 2021, 5:01pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141/6 "2021-10-14T17:01:03Z")

</div>

Hey Paul,

I might have found another issue with the periodic boundary conditions for translational planes. I set up a cube with x-y periodicity and the simulation runs for v0.12.0 but throws this error for v0.12.1 and v0.12.2:

` ERROR: Found at least three periodic surfaces without a specified partner. Please specify the partner for each periodic surface.`

This occurs when I define the translational periodic planes with openmc.XPlane and openmc.YPlane, and then with openmc.Plane. I have attached the simple minimal working examples.  
[test.py](https://openmc.discourse.group/uploads/short-url/pved1BXC1bBDCsIFIZGhluCuFGK.py) (1.2 KB)  
[test3.py](https://openmc.discourse.group/uploads/short-url/uDK2bocmoNeaC06PfkqKfxShvVf.py) (1.2 KB)

Best,  
Gwen

---

<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:** [October 18, 2021, 12:33pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141/7 "2021-10-18T12:33:22Z")

</div>

@gwenchee I would say this is actually by design. Now that OpenMC has the ability to do both translational and rotationally periodic boundary conditions, If you have two x-planes and y-planes that are specified as periodic, it’s not clear which pairs of planes should be periodic with respect to one another. To explicitly set pairs of planes as being periodic, you can add the following to your code:

```auto
x_right.periodic_surface = x_left
y_bot.periodic_surface = y_top

```

---

<div class="post-metadata">

**Author:** ![gwenchee](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gwenchee](https://openmc.discourse.group/u/gwenchee)\
**Post date:** [October 19, 2021, 5:18pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141/8 "2021-10-19T17:18:17Z")

</div>

@paulromano I explicitly defined the pairs of planes, yet still, get the error. This is how I defined the surfaces in test.py:

```auto
x_left = +openmc.XPlane(x0=0, boundary_type="periodic")

x_right = -openmc.XPlane(x0=5, boundary_type="periodic")

y_top = -openmc.YPlane(y0=5, boundary_type="periodic")

y_bot = +openmc.YPlane(y0=0, boundary_type="periodic")

x_left.periodic_surface = x_right

y_top.periodic_surface = y_bot

z_top = -openmc.ZPlane(z0=5, boundary_type="reflective")

z_bot = +openmc.ZPlane(z0=0, boundary_type="reflective")

```

The error only occurs from v0.12.1 onwards.

---

<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:** [October 19, 2021, 10:01pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141/9 "2021-10-19T22:01:31Z")

</div>

The `periodic_surface` attribute has to be set on a `Surface` object, whereas you are trying to apply it to a region (the result of taking the unary `+` or `-` operator on a surface). So you should have:

```auto
x_left = openmc.XPlane(...)
x_right = openmc.XPlane(...)
y_top = openmc.YPlane(...)
y_bot = openmc.YPlane(...)
x_left.periodic_surface = x_right
y_top.periodic_surface = y_top

...
region = +x_left & -x_right & ...

```

---

<div class="post-metadata">

**Author:** ![gwenchee](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gwenchee](https://openmc.discourse.group/u/gwenchee)\
**Post date:** [October 22, 2021, 8:17pm UTC](https://openmc.discourse.group/t/periodic-boundary-conditions/1141/10 "2021-10-22T20:17:53Z")

</div>

Ah I see, I totally missed that. Thanks, Paul!

Gwen
