# Solving PDE with MethodOfLines

**URL:** <https://discourse.julialang.org/t/solving-pde-with-methodoflines/106936>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [November 30, 2023, 8:44am UTC](https://discourse.julialang.org/t/solving-pde-with-methodoflines/106936 "2023-11-30T08:44:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cwmeyer](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@Cwmeyer](https://discourse.julialang.org/u/Cwmeyer)\
**Post date:** [November 30, 2023, 8:44am UTC](https://discourse.julialang.org/t/solving-pde-with-methodoflines/106936/1 "2023-11-30T08:44:57Z")

</div>

Hi, I am new to Julia. I’m trying to solve a PDE using Method of lines but I am running into a unexpected error. `ERROR: type Term has no field lhs.` My code as follows:

```julia
using DifferentialEquations
using Plots
using MethodOfLines
using ModelingToolkit
using DomainSets

@parameters t,x
@variables u(..)

Dt = Differential(t)
Dx = Differential(x)
Dxx = Differential(x)^2

v = 5.0
Da = 5.0
pe = 100.0
L = 100.0
C0 = 1.0

eq = [Dt(u(t,x)) ~ -v * Dx(u(t,x)) + Da * Dxx(u(t,x))]

domain = [x ∈ Interval(0.0, 100.0), t ∈ Interval(0.0, 10.0)]

ibc = [C0 ~ -Da/v*Dx(u(t,0.0) + u(t,0.0)), Dx(u(t,L) ~ 0.0), u(0.0,x) ~ 0.0]

@named sys = PDESystem(eq, ibc, domain, [t,x], [u(t,x)] )

#sys = structural_simplify(sys)

dx = 1.0

discretization = MOLFiniteDifference([x => dx], t, approx_order = 2)
prob = discretize(sys, discretization)
sol = solve(prob, Tsit5(), saveat = 0.05)

```

Any help would be appreciated! Thanks!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 30, 2023, 9:35am UTC](https://discourse.julialang.org/t/solving-pde-with-methodoflines/106936/2 "2023-11-30T09:35:07Z")

</div>

> [@Cwmeyer](#):
>
> ```julia
> ibc = [C0 ~ -Da/v*Dx(u(t,0.0) + u(t,0.0)), Dx(u(t,L) ~ 0.0), u(0.0,x) ~ 0.0]
> 
> ```

Looks like you have a typo in there:

```julia
ibc = [C0 ~ -Da/v*Dx(u(t,0.0) + u(t,0.0)), Dx(u(t,L)) ~ 0.0, u(0.0,x) ~ 0.0]

```

---

<div class="post-metadata">

**Author:** ![Cwmeyer](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@Cwmeyer](https://discourse.julialang.org/u/Cwmeyer)\
**Post date:** [December 1, 2023, 6:24am UTC](https://discourse.julialang.org/t/solving-pde-with-methodoflines/106936/3 "2023-12-01T06:24:04Z")

</div>

Hi Chris, thanks for pointing out the typo. I managed to amend the boundary condition typos and still ran into the same error.

I did a bit of reading on the MethodOfLines package and found the following under the “Known Limitations”:

`That boundary conditions do not contain references to derivatives which are not in the direction of the boundary, except in time`

Since I am trying to solve the Danckwerts boundary conditions for PFR Axial Dispersion, I believe these conditions account for back mixing at the inlet layer which is obviously not in the direction of the boundary.

Once I assumed no back mixing at the inlet boundary condition, the code executed perfectly. Pretty cool!

So, if I were to improve the accuracy of the model by assuming back mixing at the inlet (therefore include a negative derivative not in the direction of the boundary) is there a way to still use the MOL and work around this issue? If not, what would you recommend?  
Thanks for the help!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 1, 2023, 9:17am UTC](https://discourse.julialang.org/t/solving-pde-with-methodoflines/106936/4 "2023-12-01T09:17:40Z")

</div>

> [@Cwmeyer](#):
>
> So, if I were to improve the accuracy of the model by assuming back mixing at the inlet (therefore include a negative derivative not in the direction of the boundary) is there a way to still use the MOL and work around this issue? If not, what would you recommend?

Open an issue. We’d need to setup the auto disxretizer to handle more cases
