# Periodic boundary conditions for PDE system using MethodOfLines.jl

**URL:** <https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761>\
**Category:** Numerics\
**Created:** [March 30, 2022, 6:11pm UTC](https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761 "2022-03-30T18:11:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wayne\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wayne_wang/32/35056_2.png) [@Wayne\_Wang](https://discourse.julialang.org/u/Wayne_Wang)\
**Post date:** [March 30, 2022, 6:11pm UTC](https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761/1 "2022-03-30T18:11:51Z")

</div>

Hi all! I’m working with ModellingToolkit and DiffEqOperators to solve a set of PDEs. In particular, I wanted to test out a 1D Kuramoto-Sivashinsky type of equation with periodic boundary conditions, but I’m having some issues with the boundary conditions:

```julia
@parameters x t
@variables u(..)
Dt = Differential(t)
Dx = Differential(x)
Dxx = Differential(x)^2
Dxxxx = Differential(x)^4

∇(u) = Dx(u) 
∇²(u) = Dxx(u) 
∇⁴(u) = Dxxxx(u) 

# 2D PDE and boundary conditions
eqs = Dt(u(x,t)) ~ - u(x,t) * ∇(u(x,t)) - ∇²(u(x,t)) - ∇⁴(u(x,t))

T = 1.0
xmin = 0.0
xmax = 1.0

μ0 = 0.3; σ0 = 0.05
f0 = x -> 0.6*exp(-(x - μ0)^2 / (2 * σ0^2))

bcs = [u(x,0.0) ~ f0(x),
       u(xmin,t) ~ u(xmax,t)]

# Space and time domains
domains = [t ∈ IntervalDomain(0.0, T),
           x ∈ IntervalDomain(xmin, xmax)]

# PDE system
pdesys = PDESystem(eqs, bcs, domains, [x,t], [u(x,t)])

# Method of lines discretization
N = 32
Δx = 1.0/(N+1)
discretization = MOLFiniteDifference([x => Δx], t; centered_order = 4)

# Convert the PDE problem into an ODE problem
prob = discretize(pdesys, discretization)

# Solving the problem
sol = solve(prob, Rodas4(autodiff=false); abstol=1e-6, reltol=1e-6)

```

But I got the error `ERROR: InvalidSystemException: The system is unbalanced. There are 34 highest order derivative variables and 33 equations.` after running the `discretize` function.

A different set of BCs, such as:

```julia
bcs = [u(x,0.0) ~ f0(x),
       u(xmin,t) ~ 0,
       u(xmax,t) ~ 0]

```

seems to be working fine. I wonder whether it’s the way I specified the periodic BCs was wrong. Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![xtalax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xtalax/32/35293_2.png) [@xtalax](https://discourse.julialang.org/u/xtalax)\
**Post date:** [March 30, 2022, 6:41pm UTC](https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761/2 "2022-03-30T18:41:43Z")

</div>

Are you using MethodOfLines.jl, or an older version of DiffEqOperators? I recommend retrying with the latest version of MethodOfLines

---

<div class="post-metadata">

**Author:** ![Wayne\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wayne_wang/32/35056_2.png) [@Wayne\_Wang](https://discourse.julialang.org/u/Wayne_Wang)\
**Post date:** [March 30, 2022, 6:42pm UTC](https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761/3 "2022-03-30T18:42:27Z")

</div>

No I’m actually using the DiffEqOperators.

---

<div class="post-metadata">

**Author:** ![xtalax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xtalax/32/35293_2.png) [@xtalax](https://discourse.julialang.org/u/xtalax)\
**Post date:** [March 30, 2022, 6:44pm UTC](https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761/4 "2022-03-30T18:44:08Z")

</div>

Please retry with MethodOfLines, the DiffEqOperators version has been moved out and expanded upon there, with better periodic condition handling.

---

<div class="post-metadata">

**Author:** ![Wayne\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wayne_wang/32/35056_2.png) [@Wayne\_Wang](https://discourse.julialang.org/u/Wayne_Wang)\
**Post date:** [March 30, 2022, 6:44pm UTC](https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761/5 "2022-03-30T18:44:57Z")

</div>

I see I’ll try it out and see what happens. Thanks!

---

<div class="post-metadata">

**Author:** ![xtalax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xtalax/32/35293_2.png) [@xtalax](https://discourse.julialang.org/u/xtalax)\
**Post date:** [March 30, 2022, 6:45pm UTC](https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761/6 "2022-03-30T18:45:38Z")

</div>

Let me know how it goes!

---

<div class="post-metadata">

**Author:** ![Wayne\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wayne_wang/32/35056_2.png) [@Wayne\_Wang](https://discourse.julialang.org/u/Wayne_Wang)\
**Post date:** [March 30, 2022, 7:16pm UTC](https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761/7 "2022-03-30T19:16:37Z")

</div>

MethodOfLines worked! Thanks again!

---

<div class="post-metadata">

**Author:** ![xtalax](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xtalax/32/35293_2.png) [@xtalax](https://discourse.julialang.org/u/xtalax)\
**Post date:** [March 30, 2022, 7:19pm UTC](https://discourse.julialang.org/t/periodic-boundary-conditions-for-pde-system-using-methodoflines-jl/78761/8 "2022-03-30T19:19:23Z")

</div>

Glad to hear! Please give us a star on [github](https://github.com/SciML/MethodOfLines.jl) if you’ve got time
