Hi all,
I’m trying to solve a simple 1D heat equation. As the future objective is to identify some parameters of this equation, I use ModellingToolkit
with MethodOfLines
as showcased in the example of the MethodOfLines
package.
The only difference is that I would like to solve the temperature profile in two materials, hence some parameters vary in space. I found in the examples a way to make a variable vary in time (Getting Started with ModelingToolkit.jl · ModelingToolkit.jl) but cannot make it work with space.
Here is my current take on the problem (adapted from the example Solving the Heat Equation · MethodOfLines.jl).
using ModelingToolkit, MethodOfLines, DomainSets, OrdinaryDiffEq
# Parameters, variables, and derivatives
@parameters t x
@variables α(x) # the space varying parameter
@variables u(..)
Dt = Differential(t)
Dx = Differential(x)
Dxx = Differential(x)^2
α_fun(x) = x >= 80 ? 10 : 20 # its value depends on x
@register_symbolic α_fun(x)
L = 100.
h = 10
Text = 10
tmax = 24*60*60
# 1D PDE and boundary conditions
eq = [ α ~ α_fun(x),
Dt(u(t, x)) ~ α*Dxx(u(t, x)) ] # Tried to reproduce the example with forcing function but not sure this is right...
bcs = [u(0,x) ~ 20.,
Dt(u(t, 0)) ~ 500,
Dt(u(t, L)) ~ -h*(u(t,L) - Text)] # Heat source on one side, convection on the other
# Space and time domains
domains = [t ∈ Interval(0.0, tmax),
x ∈ Interval(0., L)]
# PDE system
@named pdesys = PDESystem(eq, bcs, domains, [t, x], [u(t, x), α])
# Method of lines discretization
# Need a small dx here for accuracy
dx = 0.1
order = 2
discretization = MOLFiniteDifference([x => dx], t)
# Convert the PDE problem into an ODE problem
prob = discretize(pdesys, discretization) # This has now been running for 3 hours straight...
I’m quite sure I’m not on the right path but could not find similar examples. Has someone achieved this before?
Thanks!