ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

How to write parameters in FunctionalAffect in MTK9?

Open HKruenaegel opened this issue 11 months ago • 0 comments

Instead of writing:

function affect!(integ,u,p,ctx)
    integ.p[p.d_b1]=output[8]

in my old and working code, I think I have now to write:

function affect!(integ,u,p,ctx)
    setp(integ, p.d_b1)(integ,output[8])

But this gives the error:

ERROR: UndefVarError: `setp` not defined
Stacktrace:
  [1] affect!(integ::OrdinaryDiffEq.ODEIntegrator{…}, u::@NamedTuple{…}, p::@NamedTuple{…}, ctx::Nothing)
    @ Main d:\Julia\MTK_9\acausal_inverter.jl:91
  [2] #468
    @ C:\Users\Hannes_Kruenaegel\.julia\packages\ModelingToolkit\y7GM9\src\systems\callbacks.jl:522 [inlined]
  [3] PeriodicCallbackAffect
    @ C:\Users\Hannes_Kruenaegel\.julia\packages\DiffEqCallbacks\CcAxU\src\iterative_and_periodic.jl:89 [inlined]
  [4] apply_discrete_callback!
    @ C:\Users\Hannes_Kruenaegel\.julia\packages\DiffEqBase\8vI1R\src\callbacks.jl:613 [inlined]
  [5] handle_callbacks!(integrator::OrdinaryDiffEq.ODEIntegrator{…})
    @ OrdinaryDiffEq C:\Users\Hannes_Kruenaegel\.julia\packages\OrdinaryDiffEq\DmspS\src\integrators\integrator_utils.jl:349
  [6] _loopfooter!(integrator::OrdinaryDiffEq.ODEIntegrator{…})
    @ OrdinaryDiffEq C:\Users\Hannes_Kruenaegel\.julia\packages\OrdinaryDiffEq\DmspS\src\integrators\integrator_utils.jl:254
  [7] loopfooter!
    @ C:\Users\Hannes_Kruenaegel\.julia\packages\OrdinaryDiffEq\DmspS\src\integrators\integrator_utils.jl:207 [inlined]
  [8] solve!(integrator::OrdinaryDiffEq.ODEIntegrator{…})
    @ OrdinaryDiffEq C:\Users\Hannes_Kruenaegel\.julia\packages\OrdinaryDiffEq\DmspS\src\solve.jl:545
  [9] __solve(::ODEProblem{…}, ::Rodas4P2{…}; kwargs::@Kwargs{…})
    @ OrdinaryDiffEq C:\Users\Hannes_Kruenaegel\.julia\packages\OrdinaryDiffEq\DmspS\src\solve.jl:7
 [10] __solve
    @ C:\Users\Hannes_Kruenaegel\.julia\packages\OrdinaryDiffEq\DmspS\src\solve.jl:1 [inlined]
 [11] solve_call(_prob::ODEProblem{…}, args::Rodas4P2{…}; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::@Kwargs{…})
    @ DiffEqBase C:\Users\Hannes_Kruenaegel\.julia\packages\DiffEqBase\8vI1R\src\solve.jl:612
 [12] solve_up(prob::ODEProblem{…}, sensealg::Nothing, u0::Vector{…}, p::ModelingToolkit.MTKParameters{…}, args::Rodas4P2{…}; kwargs::@Kwargs{…})
    @ DiffEqBase C:\Users\Hannes_Kruenaegel\.julia\packages\DiffEqBase\8vI1R\src\solve.jl:1080
 [13] solve_up
    @ C:\Users\Hannes_Kruenaegel\.julia\packages\DiffEqBase\8vI1R\src\solve.jl:1066 [inlined]
 [14] solve(prob::ODEProblem{…}, args::Rodas4P2{…}; sensealg::Nothing, u0::Nothing, p::Nothing, wrap::Val{…}, kwargs::@Kwargs{…})
    @ DiffEqBase C:\Users\Hannes_Kruenaegel\.julia\packages\DiffEqBase\8vI1R\src\solve.jl:1003
 [15] top-level scope
    @ d:\Julia\MTK_9\acausal_inverter.jl:387
Some type information was truncated. Use `show(err)` to see complete types.

Also if I try this, I get an error:

julia> prob[booster.RL.R]
ERROR: Indexing with parameters is deprecated. Use `getp(prob, booster₊RL₊R)(prob)` for parameter indexing.
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:35
 [2] getindex(prob::ODEProblem{…}, sym::Num)
   @ SciMLBase C:\Users\Hannes_Kruenaegel\.julia\packages\SciMLBase\Dwomw\src\problems\problem_interface.jl:33
 [3] top-level scope
   @ REPL[5]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> getp(prob,booster.RL.R)(prob)
ERROR: UndefVarError: `getp` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

HKruenaegel avatar Mar 07 '24 10:03 HKruenaegel