SciML / MethodOfLines.jl

Automatic Finite Difference PDE solving with Julia SciML
https://docs.sciml.ai/MethodOfLines/stable/
MIT License
163 stars 31 forks source link

ERROR: TypeError: non-boolean (Num) used in boolean context - when passing interpolation function in eqs definition #223

Open peraponf opened 1 year ago

peraponf commented 1 year ago

Hi,

I try to simulate heat transfer along a wellbore in 1D. The outside temperatures along the wellbore vary with depth. I try to pass the temperature profile for heat loss calculation in the equation definition as an interpolation function using Interpolations.jl. I got the error "ERROR: TypeError: non-boolean (Num) used in boolean context". Appreciate any help.

using ModelingToolkit, MethodOfLines, OrdinaryDiffEq, DomainSets
using Interpolations
using Plots

@parameters t z
@parameters c, Uz 
@variables T(..)
Dt = Differential(t)
Dz = Differential(z) 

#' Geothermal profile
TTVD = [70.0, 34.0, 100.0, 120.0, 95.0, 190.0]
zTVD = [0.0, 3000.0, 3050.0,  7000.0, 8500.0, 18400.0]
GeoT=linear_interpolation(zTVD,TTVD)

tmp=0:10:18000; 

# plot temperature profiles in TVD
p1=scatter(TTVD, zTVD, color= :red, label="data", xlabel="Temperature [F]", ylabel="True Vertical Depth [ft]", yflip = true)
plot!(GeoT(tmp), tmp, color= :blue, label="Interpolation", legend=:outerright, title="Geothermal Temperature")

#' Initial condition
T0(z)=GeoT(z)
#T0(z,t)=100.0*z
#' Define equation based on PDE
eqs = [Dt(T(t,z)) ~ -Uz * Dz(T(t,z)) + c*(T0(z) - T(t,z))]
xtalax commented 1 year ago

I think you need to register the interpolation, try @register_symbolic T0(z)

PS: Don't you want Dz to be a second order derivative?