# Solving quasi-linear heat diffusion using DiffEqTools.jl and DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/solving-quasi-linear-heat-diffusion-using-diffeqtools-jl-and-differentialequations-jl/72954>\
**Category:** General Usage\
**Tags:** package, pde\
**Created:** [December 11, 2021, 10:14pm UTC](https://discourse.julialang.org/t/solving-quasi-linear-heat-diffusion-using-diffeqtools-jl-and-differentialequations-jl/72954 "2021-12-11T22:14:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iddingsite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iddingsite/32/31840_2.png) [@Iddingsite](https://discourse.julialang.org/u/Iddingsite)\
**Post date:** [December 11, 2021, 10:14pm UTC](https://discourse.julialang.org/t/solving-quasi-linear-heat-diffusion-using-diffeqtools-jl-and-differentialequations-jl/72954/1 "2021-12-11T22:14:52Z")

</div>

Hi everyone.

I am new to Julia and decided to give a try to the SciML framework.  
My goal is first to solve the quasi-linear heat equation using the method of Lines.

\partial\_t T = \partial\_x (\kappa(x) \,\, \partial\_x T(x,t))

In the future, I would like to use ModelingToolkit.jl, but I wanted to start by using only DiffEqTools.jl and DifferentialEquations.jl to better understand what’s going on inside the black box.  
I found a similar topic here with what I have in mind but for a constant diffusivity parameter: [Solving heat diffusion PDE using DiffEqTools.jl and DifferentialEquations.jl](https://discourse.julialang.org/t/solving-heat-diffusion-pde-using-diffeqtools-jl-and-differentialequations-jl/41630)

What I have so far is:

```julia
using DiffEqOperators, DifferentialEquations

#=
Solving heat equation with variable diffusity κT:
    ∂tT = ∂x(κT ∂x(T))
=#

const Lx = 1.0 # length of the rod in the x direction
const nx = 40 # number of points in the x direction
const Δx = Lx / (nx - 1) # grid spacing in the x direction
const x = range(0, length=nx, stop=Lx) # Define the locations along a gridline.
const u0 = sin.(pi*x/Lx) # initial condition

Q = Dirichlet0BC(eltype(u0)) # homogeneous dirichlet on the sides
u0_padded = Q * u0

κTx_padded = ones((length(u0_padded))) .* 1.22e-3 # has to be same length as T_padded

∂ut = similar(u0) # pre-allocate array
nonlinear_diffusion!(∂ut, 1, 1, 4,
κTx_padded, u0_padded, Δx, nx) # finite differences in space

tspan = (0.0, 10.0)

prob = ODEProblem(∂ut, u0, tspan)
solve(prob)

```

I got an error when using ODEProblem. What did I miss?

Thank you very much in advance 😃

---

<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 14, 2021, 11:12am UTC](https://discourse.julialang.org/t/solving-quasi-linear-heat-diffusion-using-diffeqtools-jl-and-differentialequations-jl/72954/2 "2021-12-14T11:12:27Z")

</div>

> [@Iddingsite](#):
>
> `prob = ODEProblem(∂ut, u0, tspan)`

`∂ut` isn’t a function. The `f` should be a function.

---

<div class="post-metadata">

**Author:** ![Iddingsite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iddingsite/32/31840_2.png) [@Iddingsite](https://discourse.julialang.org/u/Iddingsite)\
**Post date:** [December 14, 2021, 1:31pm UTC](https://discourse.julialang.org/t/solving-quasi-linear-heat-diffusion-using-diffeqtools-jl-and-differentialequations-jl/72954/3 "2021-12-14T13:31:52Z")

</div>

Thank you Chris, it was indeed the problem.

It seems that I didn’t quite understand this f parameter 😅

Everything is working now, and here is the solution for people coming across the same problem in the future:

```julia
using DiffEqOperators, DifferentialEquations

#=
Solving heat equation with variable diffusity κT:
    ∂tT = ∂x(κT ∂x(T))
=#

const Lx = 1.0 # length of the rod in the x direction
const nx = 40 # number of points in the x direction
const Δx = Lx / (nx - 1) # grid spacing in the x direction
const x = range(0, length=nx, stop=Lx) # Define the locations along a gridline.
const u0 = sin.(pi*x/Lx) # initial condition

Q = Dirichlet0BC(eltype(u0)) # homogeneous dirichlet on the sides
κTx_padded = ones((length(u0) + 2)) .* 1.22e-3 # has to be same length as T_padded

tspan = (0.0, 100.0)

function f(u,p,t)
    nonlinear_diffusion(1, 1, 4,
    κTx_padded, Q * u, Δx, nx)
end

prob = ODEProblem(f, u0, tspan)
sol = solve(prob)

```

Thanks again!
