Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector of parameters in PDE system @parameters DU[1:2] fail to discretize #434

Open
dmetivie opened this issue Nov 27, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@dmetivie
Copy link

Describe the bug 🐞
When using a vector of parameters @parameters DU[1:2]::Float64, the discretize function of a PDE problem fails with a mysterious error message. The same problem with 2 distinct parameters @parameters D, U works.
Is the syntax wrong? I did not find documentation for this case except in this FAQ . Maybe it is a problem from ModelingToolkit (I suspect other issues with remake and @parameters).

Expected behavior

The same problem with 2 distinct parameters @parameters D, U works. The syntax with vector should work.

Minimal Reproducible Example 👇

using ModelingToolkit: Interval
using ModelingToolkit
using DifferentialEquations
using MethodOfLines
# Variables
@independent_variables x,t
@variables c(..)
∂t = Differential(t)
∂²x = Differential(x)^2
∂x = Differential(x)
# Space and time domains
L = 3.0
T = 3.0
dom = [x  Interval(0, L), t  Interval(0, T)]
# Initial and boundary conditions
bcs = [
    c(0, t) ~ 1.0,
    c(x, 0) ~ 0.0,
]
# Parameters
@parameters DU[1:2]::Float64
# PDE
eqn = ∂t(c(x, t)) ~ DU[1] * ∂²x(c(x, t)) - DU[2] * ∂x(c(x, t))
# Define PDE system
@named sys = PDESystem(eqn,
    bcs,
    dom,
    [x, t],
    [c(x, t)],
    DU;
    defaults=Dict(DU => [0.1, 1.2])
)

# Define ODE problem
prob = discretize(sys,
    MOLFiniteDifference([x => 0.05],
        t,
        advection_scheme=scheme = UpwindScheme(2)
    )
)

Error & Stacktrace ⚠️

ERROR: MethodError: Cannot `convert` an object of type 
  Vector{Int64} to an object of type
  AbstractRange
The function `convert` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:126
  convert(::Type{SL}, ::FillArrays.AbstractFill{T, 1} where T) where SL<:AbstractRange
   @ FillArrays C:\Users\metivier\.julia\packages\FillArrays\lVl4c\src\FillArrays.jl:567
  convert(::Type{T}, ::AbstractRange) where T<:AbstractRange
   @ Base range.jl:269
  ...

Stacktrace:
 [1] setindex!(h::Dict{…}, v0::Vector{…}, key::SymbolicUtils.BasicSymbolic{…})
   @ Base .\dict.jl:355
 [2] getindex(x::Symbolics.ArrayOp{Vector{Real}}, idx::Vector{Int64})
   @ Symbolics C:\Users\metivier\.julia\packages\Symbolics\YbNrd\src\array-lib.jl:67
 [3] getindex(x::Symbolics.Arr{Num, 1}, idx::Vector{Int64})
   @ Symbolics C:\Users\metivier\.julia\packages\Symbolics\YbNrd\src\array-lib.jl:94
 [4] ODESystem(deqs::Vector{…}, iv::Num, dvs::Vector{…}, ps::Symbolics.Arr{…}; controls::Vector{…}, observed::Vector{…}, systems::Vector{…}, tspan::Nothing, name::Symbol, description::String, default_u0::Dict{…}, default_p::Dict{…}, defaults::Dict{…}, guesses::Dict{…}, initializesystem::Nothing, initialization_eqs::Vector{…}, schedule::Nothing, connector_type::Nothing, preface::Nothing, continuous_events::Nothing, discrete_events::Nothing, parameter_dependencies::Vector{…}, checks::Bool, metadata::MethodOfLines.MOLMetadata{…}, gui_metadata::Nothing, is_dde::Nothing, tstops::Vector{…})
   @ ModelingToolkit C:\Users\metivier\.julia\packages\ModelingToolkit\ompZE\src\systems\diffeqs\odesystem.jl:273
 [5] generate_system(disc_state::PDEBase.EquationState, s::MethodOfLines.DiscreteSpace{…}, u0::Vector{…}, tspan::Tuple{…}, metadata::MethodOfLines.MOLMetadata{…}, disc::MOLFiniteDifference{…})
   @ PDEBase C:\Users\metivier\.julia\packages\PDEBase\VVGPP\src\discretization_state.jl:40
 [6] symbolic_discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{…})
   @ PDEBase C:\Users\metivier\.julia\packages\PDEBase\VVGPP\src\symbolic_discretize.jl:89
 [7] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{…}; analytic::Nothing, kwargs::@Kwargs{})
   @ PDEBase C:\Users\metivier\.julia\packages\PDEBase\VVGPP\src\discretization_state.jl:57
 [8] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{…})
   @ PDEBase C:\Users\metivier\.julia\packages\PDEBase\VVGPP\src\discretization_state.jl:54
 [9] top-level scope
   @ c:\Users\metivier\Dropbox\PC (2)\Documents\GitLab\thesis_yoann_cartier\Code\inverse\mwe_yoann_diffeqestim_heat_eqt_mtk.jl:36
Some type information was truncated. Use `show(err)` to see complete types.

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
  [0c46a032] DifferentialEquations v7.15.0
  [94925ecb] MethodOfLines v0.11.7
  [961ee093] ModelingToolkit v9.53.0
@dmetivie dmetivie added the bug Something isn't working label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant