SciML / ModelingToolkit.jl

An acausal modeling framework for automatically parallelized scientific machine learning (SciML) in Julia. A computer algebra system for integrated symbolics for physics-informed machine learning and automated transformations of differential equations
https://mtk.sciml.ai/dev/
Other
1.43k stars 209 forks source link

Boundary Value Problem #924

Open kkakosim opened 3 years ago

kkakosim commented 3 years ago

Hello all, is there any example or test implementing a "BVPsystem"? I tried to implement like ODE but with no luck

@parameters r
@variables T(..)
D = Differential(r)

kc = 25.
ks = 385.
Tf = 350.
Rc = 0.005
Rs = 1.5 * Rc
h = 100.
Sc = 0.
Tinit = 298.

# 1D ODE and boundary conditions
eq = [0 ~ (1/r^2) * D( (1/r^2) * kc * D( T(r) ) ) + Sc,
      0~ D(T(0)),
      0~ D(T(Rs)) - h * (T(Rs) - Tf)]  

# ODE system
sys = ODESystem(eq, T)
p=[]
T0 = [T => Tinit]
rspan=(0.0 , Rs)
prob = ODEProblem(sys, T0, rspan, p)

# Solve ODE problem
sol = solve(prob)
ChrisRackauckas commented 3 years ago

There is no example of one right now. The closest is to use PDESystem to describe such a BVP. It's a future feature.

kkakosim commented 3 years ago

I used the PDE System in MTk but I get this strange error with the Robin BC. I checked the tests, but still trying to figure out what should be the correct format.

using ModelingToolkit,DiffEqOperators,DiffEqBase,LinearAlgebra,Test,OrdinaryDiffEq
using ModelingToolkit: Differential
using Plots
gr()

@inline function if_else(condition::Bool, @nospecialize(trueval), @nospecialize(falseval))
    return ifelse(condition, trueval, falseval)
end

ModelingToolkit.@register if_else(x, trueval, falseval)
# This is needed to bring if_else into MTK's scope.
@eval ModelingToolkit using ..Main: if_else

@parameters t x
@variables T(..)
Dt = Differential(t)
Dx = Differential(x)

kc = 25.
ks = 385.
Tf = 350.
Rc = 0.005
Rs = 1.5 * Rc
h = 100.
Sc = 1.E8
Tinit = 298.

# 1D PDE and boundary conditions
eq = Dt(T(t,x)) ~  kc * (1/x^2) * Dx( (1/x^2) * Dx( T(t, x) ) ) + Sc * (1 - x/Rs)

bcs=[T(0, x) ~ Tinit,
    Dx(T(t, 0)) ~ 0.,
    Dx(T(t, Rs)) ~ h/kc * (T(t, Rs) - Tf)]  

# Space and time domains
domains = [t ∈ IntervalDomain(0.0, 1.),
           x ∈ IntervalDomain(0.0 , Rs)]

# PDE system
pdesys = PDESystem(eq, bcs, domains, [t,x], [T])

# Method of lines discretization
dx =Rc/10
order = 2
discretization = MOLFiniteDifference(dx,order)

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

# Solve ODE problem
sol = solve(prob, Tsit5(), saveat=0.1)   

The error is

lhs = T(0, x) lhs = Differential(x)(T(t, 0)) lhs = Differential(x)(T(t, 0.0075)) ERROR: LoadError: UndefVarError: T not defined

when I set the T(t, Rs) to a fixed it works. I tried changing the format of this BC with no success.

ChrisRackauckas commented 3 years ago

MOLFiniteDifference won't support BVPs right now.

BambOoxX commented 3 months ago

@ChrisRackauckas Would you have a new status about BVProblem with MTK ? I'm trying to apply this to a simple 1D model but it fails at the moment.

ChrisRackauckas commented 3 months ago

I talked with someone at JuliaCon about it, I think @AayushSabharwal ? So after he's done with vacation he has a long list but it's scheduled.