MethodOfLines.jl
MethodOfLines.jl copied to clipboard
Variables in separate but overlapping domains
An important piece of the P2D battery model is to be able to simulate variables with separate but overlapping domains, corresponding to the different components of the battery. More specifically, one variable's domain is a subset of another's.
[EDIT: slightly more complex MWE requiring offsets]
For example, with domains 0<x<3 and 0<y<1 and 2<z<3 where y and z are subsets of x:
using ModelingToolkit
import IfElse
@parameters t x y z
@variables u(..) v(..) w(..)
Dt = Differential(t)
Dx = Differential(x)
Dxx = Differential(x)^2
Dy = Differential(y)
Dyy = Differential(y)^2
Dz = Differential(z)
Dzz = Differential(z)^2
sy = u(t,y) + v(t,y)
sz = u(t,z) + w(t,z)
sx = IfElse.ifelse(x<1,sy,IfElse.ifelse(x>2,sz,0))
eqs = [Dt(u(t,x)) ~ Dxx(u(t,x)) + sx,
Dt(v(t,y)) ~ Dyy(v(t,y)) + sy,
Dt(w(t,z)) ~ Dzz(w(t,z)) + sz,]
bcs = [u(0,x) ~ 1,
v(0,y) ~ 1,
w(0,z) ~ 1,
u(t,0) ~ 0.0, u(t,3) ~ 0.0,
v(t,0) ~ 0.0, v(t,1) ~ 0.0,
w(t,2) ~ 0.0, w(t,3) ~ 0.0]
domains = [t ∈ Interval(0.0,1.0),
x ∈ Interval(0.0,3.0),
y ∈ Interval(0.0,1.0),
z ∈ Interval(2.0,3.0)]
@named pdesys = PDESystem(eqs,bcs,domains,[t,x,y,z],[u(t,x),v(t,y),w(t,z)])
I believe there may have been a previous issue or PR somewhere in SciML for this, but can't find it
@xtalax 's suggestions were:
- Discretize space before discretizing equations
- Use offset arrays for
wso that the indexing lines up withu
I guess we would either need to explicitly specify somewhere that y and z domains are subsets of x domain, or the discretization can infer it from the fact that they are all provided as the second argument of u
Would the regions ever need non orthoganal/perpendicular boundaries?
Not in my use case (which is just 1D)