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

ERROR: type SCCNonlinearProblem has no field kwargs #3320

Open
bradcarman opened this issue Jan 14, 2025 · 2 comments
Open

ERROR: type SCCNonlinearProblem has no field kwargs #3320

bradcarman opened this issue Jan 14, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@bradcarman
Copy link
Contributor

The following produces the error: type SCCNonlinearProblem has no field kwargs

using ModelingToolkit
using ModelingToolkit: D_nounits as D, t_nounits as t
using OrdinaryDiffEq

reg_pow(x, a, delta = 0.1) = ifelse(abs(x/delta) >= 1, sign(x)*abs(x/delta)^a * delta^a, (delta^a*x)/delta)

function System(; name)
    pars = @parameters begin
        ρ₀ = 1000
        β = 2e9
        A = 0.1
        m = 100
        L = 1
    
        p_s = 100e5
        p_r = 10e5
        C1 = 1.35
        C2 = 1.35
        c = 1000
        A_p = 0.00094
    
        transition=0.1
    end   
    vars = @variables begin
        p_1(t) = p_s
        p_2(t) = p_r
        x(t)=0
        dx(t)=0
        ddx(t), [guess=0]
        rho_1(t), [guess=ρ₀]
        rho_2(t), [guess=ρ₀]
        drho_1(t), [guess=0]
        drho_2(t), [guess=0]
        m_1(t), [guess=0]
        m_2(t), [guess=0]
        u_1(t), [guess=0]
        u_2(t), [guess=0]
    end
    
    eqs = [
    
        D(x) ~ dx
        D(dx) ~ ddx
    
        D(m_1) ~ u_1*ρ₀*A_p
        D(m_2) ~ u_2*ρ₀*A_p
    
        # volume & mass
        m_1 ~ rho_1*(L+x)*A
        m_2 ~ rho_2*(L-x)*A
    
        # density
        rho_1 ~ ρ₀*(1 + p_1/β)
        rho_2 ~ ρ₀*(1 + p_2/β)
        
        # actuator force balance
        m*ddx ~ (p_1 - p_2)*A - c*dx
        
        # orifices
        (p_s - p_1) ~ C1*ρ₀*reg_pow(u_1, 2)  # orifice 1
        (p_r - p_2) ~ C2*ρ₀*reg_pow(u_2, 2)  # orifice 2
    
    ]
    
    return ODESystem(eqs, t, vars, pars; name)
end

@mtkbuild sys = System()

initprob = ModelingToolkit.InitializationProblem(sys, 0.0)
initsys = solve(initprob) 

The full stacktrace is...

julia> initsys = solve(initprob)
ERROR: type SCCNonlinearProblem has no field kwargs
Stacktrace:
 [1] getproperty(prob::SCCNonlinearProblem{…}, name::Symbol)
   @ SciMLBase C:\Users\bradl\.julia\packages\SciMLBase\XzPx0\src\problems\nonlinear_problems.jl:519
 [2] solve(::SCCNonlinearProblem{…}; sensealg::Nothing, u0::Nothing, p::Nothing, wrap::Val{…}, kwargs::@Kwargs{})
   @ DiffEqBase C:\Users\bradl\.julia\packages\DiffEqBase\R2Vjs\src\solve.jl:1030
 [3] solve(::SCCNonlinearProblem{Vector{…}, false, Vector{…}, Vector{…}, NonlinearFunction{…}, MTKParameters{…}})
   @ DiffEqBase C:\Users\bradl\.julia\packages\DiffEqBase\R2Vjs\src\solve.jl:1028
 [4] top-level scope
   @ c:\Work\Packages\Issue953\initialization.jl:75
Some type information was truncated. Use `show(err)` to see complete types.

Current versions are...

(Issue953) pkg> st
Status `C:\Work\Packages\Issue953\Project.toml`

  [961ee093] ModelingToolkit v9.60.0

  [1dea7af3] OrdinaryDiffEq v6.90.1
@bradcarman bradcarman added the bug Something isn't working label Jan 14, 2025
@AayushSabharwal
Copy link
Member

This is a missing dispatch in NonlinearSolve.jl. It doesn't use the default algorithm, so you need to explicitly provide it:

initsys = solve(initprob, FastShortcutNonlinearPolyalg())

@ChrisRackauckas
Copy link
Member

oh 😅 that's easy to fix at least.

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

3 participants