Periodic Boundary Conditions
Periodic boundary conditions arise in any situation where the end point must be equal to the beginning point. This type of boundary condition is typical where something is repeating many times but the optimization or simulation only needs to take place over one cycle of that sequence. An examples of a repeating process is the body's natural Circadian rhythm or a power plant that produces power to follow daily demand cycles. Examples of periodic boundary conditions in natural cycles or in manufacturing processes give importance to these conditions in numerical simulation.
Boundary conditions are added for select variables with the use of a periodic object declaration.
APMonitor Model
q = periodic
End Objects
In Python Gekko, there is a periodic function to add the APMonitor periodic condition.
Python Gekko
Linking this periodic object to a variable in the model enforces the periodic condition by adding an additional equation that the end point must be equal to the beginning point in the horizon.
An example illustrates the use of periodic boundary conditions.
minu(x−3)2
dxdt+x=cos(t)+u
x(0)=x(8)=1
u(0)=u(8)=1
0≤u≤5

Scripts in MATLAB and Python are available below to recreate this solution along with the model equations in APMonitor. Both MATLAB and Python scripts produce equivalent results.
Periodic Energy Storage
A further example demonstrates a more complicated model for energy storage and retrieval. In this case, energy is stored during the first hours of the day when demand is lower. The power generation runs at a constant level while the energy storage is able to follow the cyclical demand. Energy storage is set to a periodic boundary condition to ensure that the beginning and end of the day have at least 100 units of stored energy. Scripts are available in both MATLAB and Python.

Reference
- Safdarnejad, S.M., Hedengren, J.D., Baxter, L.L., Plant-level dynamic optimization of Cryogenic Carbon Capture with conventional and renewable power sources, Applied Energy, Volume 149, 2015, Pages 354-366, ISSN 0306-2619, DOI: 10.1016/j.apenergy.2015.03.100. Article