-
-
Notifications
You must be signed in to change notification settings - Fork 74
Getting an error when running discretize on a PDESystem with MOLFiniteDifference #421
Comments
Possibly related to #415. But you should make sure your operation |
@bgroenks96 thanks! Unfortunately, I ran it again with the proper broadcasting and still ran into the same issue |
I'm not sure what the issues is... but I know I have seen the exact same error before when trying to set up a PDE problem. |
Haven't tried this locally yet but the order of your independent variables (currently |
@tinosulzer nice catch! That in fact changed the error message. Now I get
Which I guess is promising because I can try to debug again. Will update here if I manage to fix it. Re: better error messages – is there anything I can do to help? I'm still a bit of a Julia noob but can gladly try to participate. An error/warning like "you inverted your independent variables, are you sure about that?" would be super helpful. |
Another thing is I don't think you can specify 2nd order (in time) systems yet, so you might need to explicitly rewrite it as a first-order system for now, but this is definitely functionality we should add |
@tinosulzer Oh! Thanks for heads up. Beginner question: what's the best way to rewrite the system as a first order system? |
|
Quick update: I just rewrote it into a first-order system and tried to debug for a bit. Sadly, no change. It seems like the compiler throws an error before it reads For convenience here is an update version of the code.
The error is the same |
Looks like the problem could be broadcasting the |
That's a good guess but unfortunately it didn't do anything. the compiler threw an error instantly (which I took it as a cache-hint that the problem is not with I rewrote the boundary into Dirichlet boundary conditions (just like in this example https://diffeqoperators.sciml.ai/stable/symbolic_tutorials/mol_heat/#Dirichlet-boundary-conditions). The compiler had to evaluate for a bit, and then I got the most interesting of errors:
See the boundary array below for reference. I think
|
Have identified the problem but don't fully understand it or know how to fix it. It's a bug in DiffEqOperators.jl/src/MOLFiniteDifference/MOL_discretization.jl Lines 208 to 211 in 40aa4b9
2D example> depvarbcmaps[i]
u(t, 0.0, y) => Num[u₁ˏ₁(t), u₁ˏ₂(t), u₁ˏ₃(t), u₁ˏ₄(t), u₁ˏ₅(t), u₁ˏ₆(t), u₁ˏ₇(t), u₁ˏ₈(t), u₁ˏ₉(t), u₁ˏ₁₀(t), u₁ˏ₁₁(t)]
> lhs
Num[u₁ˏ₁(t), u₁ˏ₂(t), u₁ˏ₃(t), u₁ˏ₄(t), u₁ˏ₅(t), u₁ˏ₆(t), u₁ˏ₇(t), u₁ˏ₈(t), u₁ˏ₉(t), u₁ˏ₁₀(t), u₁ˏ₁₁(t)]
> rhs
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 3D example> depvarbcmaps[i]
V(t, 0.0, y, z) => Num[V₁ˏ₁ˏ₁(t) V₁ˏ₁ˏ₂(t) V₁ˏ₁ˏ₃(t) V₁ˏ₁ˏ₄(t) V₁ˏ₁ˏ₅(t) V₁ˏ₁ˏ₆(t) V₁ˏ₁ˏ₇(t) V₁ˏ₁ˏ₈(t) V₁ˏ₁ˏ₉(t) V₁ˏ₁ˏ₁₀(t) V₁ˏ₁ˏ₁₁(t); V₁ˏ₂ˏ₁(t) V₁ˏ₂ˏ₂(t) V₁ˏ₂ˏ₃(t) V₁ˏ₂ˏ₄(t) V₁ˏ₂ˏ₅(t) V₁ˏ₂ˏ₆(t) V₁ˏ₂ˏ₇(t) V₁ˏ₂ˏ₈(t) V₁ˏ₂ˏ₉(t) V₁ˏ₂ˏ₁₀(t) V₁ˏ₂ˏ₁₁(t); V₁ˏ₃ˏ₁(t) V₁ˏ₃ˏ₂(t) V₁ˏ₃ˏ₃(t) V₁ˏ₃ˏ₄(t) V₁ˏ₃ˏ₅(t) V₁ˏ₃ˏ₆(t) V₁ˏ₃ˏ₇(t) V₁ˏ₃ˏ₈(t) V₁ˏ₃ˏ₉(t) V₁ˏ₃ˏ₁₀(t) V₁ˏ₃ˏ₁₁(t); V₁ˏ₄ˏ₁(t) V₁ˏ₄ˏ₂(t) V₁ˏ₄ˏ₃(t) V₁ˏ₄ˏ₄(t) V₁ˏ₄ˏ₅(t) V₁ˏ₄ˏ₆(t) V₁ˏ₄ˏ₇(t) V₁ˏ₄ˏ₈(t) V₁ˏ₄ˏ₉(t) V₁ˏ₄ˏ₁₀(t) V₁ˏ₄ˏ₁₁(t); V₁ˏ₅ˏ₁(t) V₁ˏ₅ˏ₂(t) V₁ˏ₅ˏ₃(t) V₁ˏ₅ˏ₄(t) V₁ˏ₅ˏ₅(t) V₁ˏ₅ˏ₆(t) V₁ˏ₅ˏ₇(t) V₁ˏ₅ˏ₈(t) V₁ˏ₅ˏ₉(t) V₁ˏ₅ˏ₁₀(t) V₁ˏ₅ˏ₁₁(t); V₁ˏ₆ˏ₁(t) V₁ˏ₆ˏ₂(t) V₁ˏ₆ˏ₃(t) V₁ˏ₆ˏ₄(t) V₁ˏ₆ˏ₅(t) V₁ˏ₆ˏ₆(t) V₁ˏ₆ˏ₇(t) V₁ˏ₆ˏ₈(t) V₁ˏ₆ˏ₉(t) V₁ˏ₆ˏ₁₀(t) V₁ˏ₆ˏ₁₁(t); V₁ˏ₇ˏ₁(t) V₁ˏ₇ˏ₂(t) V₁ˏ₇ˏ₃(t) V₁ˏ₇ˏ₄(t) V₁ˏ₇ˏ₅(t) V₁ˏ₇ˏ₆(t) V₁ˏ₇ˏ₇(t) V₁ˏ₇ˏ₈(t) V₁ˏ₇ˏ₉(t) V₁ˏ₇ˏ₁₀(t) V₁ˏ₇ˏ₁₁(t); V₁ˏ₈ˏ₁(t) V₁ˏ₈ˏ₂(t) V₁ˏ₈ˏ₃(t) V₁ˏ₈ˏ₄(t) V₁ˏ₈ˏ₅(t) V₁ˏ₈ˏ₆(t) V₁ˏ₈ˏ₇(t) V₁ˏ₈ˏ₈(t) V₁ˏ₈ˏ₉(t) V₁ˏ₈ˏ₁₀(t) V₁ˏ₈ˏ₁₁(t); V₁ˏ₉ˏ₁(t) V₁ˏ₉ˏ₂(t) V₁ˏ₉ˏ₃(t) V₁ˏ₉ˏ₄(t) V₁ˏ₉ˏ₅(t) V₁ˏ₉ˏ₆(t) V₁ˏ₉ˏ₇(t) V₁ˏ₉ˏ₈(t) V₁ˏ₉ˏ₉(t) V₁ˏ₉ˏ₁₀(t) V₁ˏ₉ˏ₁₁(t); V₁ˏ₁₀ˏ₁(t) V₁ˏ₁₀ˏ₂(t) V₁ˏ₁₀ˏ₃(t) V₁ˏ₁₀ˏ₄(t) V₁ˏ₁₀ˏ₅(t) V₁ˏ₁₀ˏ₆(t) V₁ˏ₁₀ˏ₇(t) V₁ˏ₁₀ˏ₈(t) V₁ˏ₁₀ˏ₉(t) V₁ˏ₁₀ˏ₁₀(t) V₁ˏ₁₀ˏ₁₁(t); V₁ˏ₁₁ˏ₁(t) V₁ˏ₁₁ˏ₂(t) V₁ˏ₁₁ˏ₃(t) V₁ˏ₁₁ˏ₄(t) V₁ˏ₁₁ˏ₅(t) V₁ˏ₁₁ˏ₆(t) V₁ˏ₁₁ˏ₇(t) V₁ˏ₁₁ˏ₈(t) V₁ˏ₁₁ˏ₉(t) V₁ˏ₁₁ˏ₁₀(t) V₁ˏ₁₁ˏ₁₁(t)]
> lhs
Matrix{Num}[[V₁ˏ₁ˏ₁(t) V₁ˏ₁ˏ₂(t) V₁ˏ₁ˏ₃(t) V₁ˏ₁ˏ₄(t) V₁ˏ₁ˏ₅(t) V₁ˏ₁ˏ₆(t) V₁ˏ₁ˏ₇(t) V₁ˏ₁ˏ₈(t) V₁ˏ₁ˏ₉(t) V₁ˏ₁ˏ₁₀(t) V₁ˏ₁ˏ₁₁(t); V₁ˏ₂ˏ₁(t) V₁ˏ₂ˏ₂(t) V₁ˏ₂ˏ₃(t) V₁ˏ₂ˏ₄(t) V₁ˏ₂ˏ₅(t) V₁ˏ₂ˏ₆(t) V₁ˏ₂ˏ₇(t) V₁ˏ₂ˏ₈(t) V₁ˏ₂ˏ₉(t) V₁ˏ₂ˏ₁₀(t) V₁ˏ₂ˏ₁₁(t); V₁ˏ₃ˏ₁(t) V₁ˏ₃ˏ₂(t) V₁ˏ₃ˏ₃(t) V₁ˏ₃ˏ₄(t) V₁ˏ₃ˏ₅(t) V₁ˏ₃ˏ₆(t) V₁ˏ₃ˏ₇(t) V₁ˏ₃ˏ₈(t) V₁ˏ₃ˏ₉(t) V₁ˏ₃ˏ₁₀(t) V₁ˏ₃ˏ₁₁(t); V₁ˏ₄ˏ₁(t) V₁ˏ₄ˏ₂(t) V₁ˏ₄ˏ₃(t) V₁ˏ₄ˏ₄(t) V₁ˏ₄ˏ₅(t) V₁ˏ₄ˏ₆(t) V₁ˏ₄ˏ₇(t) V₁ˏ₄ˏ₈(t) V₁ˏ₄ˏ₉(t) V₁ˏ₄ˏ₁₀(t) V₁ˏ₄ˏ₁₁(t); V₁ˏ₅ˏ₁(t) V₁ˏ₅ˏ₂(t) V₁ˏ₅ˏ₃(t) V₁ˏ₅ˏ₄(t) V₁ˏ₅ˏ₅(t) V₁ˏ₅ˏ₆(t) V₁ˏ₅ˏ₇(t) V₁ˏ₅ˏ₈(t) V₁ˏ₅ˏ₉(t) V₁ˏ₅ˏ₁₀(t) V₁ˏ₅ˏ₁₁(t); V₁ˏ₆ˏ₁(t) V₁ˏ₆ˏ₂(t) V₁ˏ₆ˏ₃(t) V₁ˏ₆ˏ₄(t) V₁ˏ₆ˏ₅(t) V₁ˏ₆ˏ₆(t) V₁ˏ₆ˏ₇(t) V₁ˏ₆ˏ₈(t) V₁ˏ₆ˏ₉(t) V₁ˏ₆ˏ₁₀(t) V₁ˏ₆ˏ₁₁(t); V₁ˏ₇ˏ₁(t) V₁ˏ₇ˏ₂(t) V₁ˏ₇ˏ₃(t) V₁ˏ₇ˏ₄(t) V₁ˏ₇ˏ₅(t) V₁ˏ₇ˏ₆(t) V₁ˏ₇ˏ₇(t) V₁ˏ₇ˏ₈(t) V₁ˏ₇ˏ₉(t) V₁ˏ₇ˏ₁₀(t) V₁ˏ₇ˏ₁₁(t); V₁ˏ₈ˏ₁(t) V₁ˏ₈ˏ₂(t) V₁ˏ₈ˏ₃(t) V₁ˏ₈ˏ₄(t) V₁ˏ₈ˏ₅(t) V₁ˏ₈ˏ₆(t) V₁ˏ₈ˏ₇(t) V₁ˏ₈ˏ₈(t) V₁ˏ₈ˏ₉(t) V₁ˏ₈ˏ₁₀(t) V₁ˏ₈ˏ₁₁(t); V₁ˏ₉ˏ₁(t) V₁ˏ₉ˏ₂(t) V₁ˏ₉ˏ₃(t) V₁ˏ₉ˏ₄(t) V₁ˏ₉ˏ₅(t) V₁ˏ₉ˏ₆(t) V₁ˏ₉ˏ₇(t) V₁ˏ₉ˏ₈(t) V₁ˏ₉ˏ₉(t) V₁ˏ₉ˏ₁₀(t) V₁ˏ₉ˏ₁₁(t); V₁ˏ₁₀ˏ₁(t) V₁ˏ₁₀ˏ₂(t) V₁ˏ₁₀ˏ₃(t) V₁ˏ₁₀ˏ₄(t) V₁ˏ₁₀ˏ₅(t) V₁ˏ₁₀ˏ₆(t) V₁ˏ₁₀ˏ₇(t) V₁ˏ₁₀ˏ₈(t) V₁ˏ₁₀ˏ₉(t) V₁ˏ₁₀ˏ₁₀(t) V₁ˏ₁₀ˏ₁₁(t); V₁ˏ₁₁ˏ₁(t) V₁ˏ₁₁ˏ₂(t) V₁ˏ₁₁ˏ₃(t) V₁ˏ₁₁ˏ₄(t) V₁ˏ₁₁ˏ₅(t) V₁ˏ₁₁ˏ₆(t) V₁ˏ₁₁ˏ₇(t) V₁ˏ₁₁ˏ₈(t) V₁ˏ₁₁ˏ₉(t) V₁ˏ₁₁ˏ₁₀(t) V₁ˏ₁₁ˏ₁₁(t)]]
> rhs
[0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0] So the problem is that in 3D |
Actually I'm not sure if I'm going to be more helpful than pointing out what you already know haha:
Will only work if lhs is a single thing. Otherwise it treats whatever you give it as a literal and returns it without modification. This is by design. You may want to check to see if Also:
You may get a better performance if you did: |
Oh actually the problem is in
because in 3D lhs is a matrix so it triggers the else condition. Don't know how I missed this yesterday. What's the best way to test whether an object is a Vector/Matrix or not?
|
gives
|
Remember to use |
What's a clean way to convert a |
|
What's the more efficient way to do this @shashi ? @parameters t x y
rhs = exp(y) * t
maps = [[x => 0.0, y=>0.0], [x=>0.0, y=> 0.2], [x=>0.0, y=> 0.4]]
substitute.(rhs,maps) |
I think |
Well I don't think that's right... What you're doing is probably the most efficient. Sorry I misunderstood what you're trying to do in my comment about using |
Another thing you can do is compile a function.
|
I also get the 'ArgumentError: reducing over an empty collection is not allowed' error on the simpler example below, where the boundary conditions are specified in the same order as the equations, and it's first order. using ModelingToolkit
using DomainSets
using DiffEqOperators
using OrdinaryDiffEq
@parameters t a
@variables S(..) I(..) R(..)
Dt = Differential(t)
Da = Differential(a)
Ia = Symbolics.Integral(a in DomainSets.ClosedInterval(0,40))
β = 0.0005
γ = 0.25
t_end = 40.0
a_end = 40.0
eqs = [Dt(S(t,a)) + Da(S(t,a)) ~ -β*S(t,a)*Ia(I(t,a)),
Dt(I(t,a)) + Da(I(t,a)) ~ β*S(t,a)*Ia(I(t,a)) - γ*I(t,a)];
bcs = [
S(0,a) ~ 990.0/a_end,
I(0,a) ~ 10.0/a_end,
]
domains = [t ∈ Interval(0,t_end), a ∈ Interval(0,a_end)];
@named pde_system = PDESystem(eqs, bcs, domains, [t, a], [S(t,a), I(t,a)]);
# Method of lines discretization
da = 0.1
order = 2
mol_discretization = MOLFiniteDifference([a=>da],t;centered_order=order)
# Convert the PDE problem into an ODE problem
mol_prob = discretize(pde_system,mol_discretization)
# Solve ODE problem
mol_sol = solve(mol_prob,Tsit5(),saveat=0.1) The discretization step fails as below: julia> mol_prob = discretize(pde_system,mol_discretization)
ERROR: ArgumentError: reducing over an empty collection is not allowed
Stacktrace:
[1] _empty_reduce_error()
@ Base ./reduce.jl:299
[2] reduce_empty(op::Function, #unused#::Type{Any})
@ Base ./reduce.jl:309
[3] mapreduce_empty(#unused#::typeof(identity), op::Function, T::Type)
@ Base ./reduce.jl:343
[4] reduce_empty(op::Base.MappingRF{typeof(identity), typeof(vcat)}, #unused#::Type{Any})
@ Base ./reduce.jl:329
[5] reduce_empty_iter
@ ./reduce.jl:355 [inlined]
[6] mapreduce_empty_iter(f::Function, op::Function, itr::Vector{Any}, ItrEltype::Base.HasEltype)
@ Base ./reduce.jl:351
[7] _mapreduce(f::typeof(identity), op::typeof(vcat), #unused#::IndexLinear, A::Vector{Any})
@ Base ./reduce.jl:400
[8] _mapreduce_dim
@ ./reducedim.jl:318 [inlined]
[9] #mapreduce#672
@ ./reducedim.jl:310 [inlined]
[10] mapreduce
@ ./reducedim.jl:310 [inlined]
[11] #reduce#674
@ ./reducedim.jl:359 [inlined]
[12] reduce
@ ./reducedim.jl:359 [inlined]
[13] symbolic_discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{Vector{Pair{Num, Float64}}, Num})
@ DiffEqOperators ~/.julia/packages/DiffEqOperators/G3svj/src/MOLFiniteDifference/MOL_discretization.jl:369
[14] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{Vector{Pair{Num, Float64}}, Num})
@ DiffEqOperators ~/.julia/packages/DiffEqOperators/G3svj/src/MOLFiniteDifference/MOL_discretization.jl:391
[15] top-level scope
@ none:1 |
This library doesn't support Integro-Differential Equations. We should just throw a better error for that. |
Is it worth putting in an issue for a feature request to support integro-differential equations? Or is automated MOL too tricky? |
It's worth opening an issue, but I don't think it would get implemented any time soon. |
Hi everyone,
I am getting an
ArgumentError: reducing over an empty collection is not allowed
when runningdiscretize
on a PDESystem withMOLFiniteDifference
. Though I spent some time combing through the code before asking, I am not sure what I am doing wrong at this point.Here is the code for reference. I am a beginner, so there might be some silly mistake. But the model works when I discretize it with
PhysicsInformedNN
The text was updated successfully, but these errors were encountered: