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

Bouncing ball IDA issues #33

Open
JKRT opened this issue Jul 7, 2021 · 0 comments
Open

Bouncing ball IDA issues #33

JKRT opened this issue Jul 7, 2021 · 0 comments

Comments

@JKRT
Copy link
Owner

JKRT commented Jul 7, 2021

   using DiffEqBase
    using DifferentialEquations
    using Plots
    using Sundials
    import OMBackend
    function BouncingBallRealsStartConditions(aux, t)
        local x = zeros(2)
        local dx = zeros(2)
        local p = aux[1]
        local reals = aux[2]
        begin
            begin end
            reals[1] = 1.0
            dx[1] = reals[2]
            dx[2] = -(p[2])
        end
        x[1] = reals[1]
        x[2] = reals[2]
        return (x, dx)
    end
    function BouncingBallRealsAuxVarsHandler(res, dx, x, aux, t)
        local p = aux[1]
        local reals = aux[2]
    end
    function BouncingBallRealsDifferentialVars()
        return Bool[1, 1]
    end
    function BouncingBallRealsDAE_equations(res, dx, x, aux, t)
        BouncingBallRealsAuxVarsHandler(res, dx, x, aux, t)
        local p = aux[1]
        local reals = aux[2]
        res[1] = dx[1] - reals[2]
        res[2] = dx[2] - -(p[2])
        reals[1] = x[1]
        reals[2] = x[2]
    end
    function BouncingBallRealsParameterVars()
        local aux = Array{Array{Float64}}(undef, 2)
        local p = Array{Float64}(undef, 2)
        local reals = Array{Float64}(undef, 2)
        aux[1] = p
        aux[2] = reals
        p[1] = 0.7
        p[2] = 9.81
        return aux
    end
    begin
        saved_values_BouncingBallReals = SavedValues(Float64, Tuple{Float64,Array})
        function BouncingBallRealsCallbackSet(aux)
            local p = aux[1]
            begin
                function condition1(x, t, integrator)
                    x[1] - 0.0
                end
                function affect1!(integrator)
                    integrator.u[2] = -(p[1] * integrator.u[2])
                end
                cb1 = ContinuousCallback(
                    condition1,
                    affect1!,
                    rootfind = true,
                    save_positions = (false, false),
                    affect_neg! = affect1!,
                )
            end
            begin
                savingFunction(u, t, integrator) =
                    let
                        (t, deepcopy(integrator.p[2]))
                    end
                cb2 = SavingCallback(savingFunction, saved_values_BouncingBallReals)
            end
            return CallbackSet(cb1)
        end
    end
    function BouncingBallRealsSimulate(tspan = (0.0, 1.0))
        local aux = BouncingBallRealsParameterVars()
        (x0, dx0) = BouncingBallRealsStartConditions(aux, tspan[1])
        local differential_vars = BouncingBallRealsDifferentialVars()
        local problem = DAEProblem(
            BouncingBallRealsDAE_equations,
            dx0,
            x0,
            tspan,
            aux,
            differential_vars = differential_vars,
            callback = BouncingBallRealsCallbackSet(aux),
        )
        local solution = solve(problem, IDA())
        return solution
    end

Removing save positions and the OM saving callback produces the correct result for every run.
However, if I add the saving callback:

begin
     saved_values_BouncingBallReals = SavedValues(Float64, Tuple{Float64,Array})
     function BouncingBallRealsCallbackSet(aux)
         local p = aux[1]
         begin
             function condition1(x, t, integrator)
                 x[1] - 0.0
             end
             function affect1!(integrator)
                 integrator.u[2] = -(p[1] * integrator.u[2])
             end
             cb1 = ContinuousCallback(
                 condition1,
                 affect1!,
                 rootfind = true,
                 save_positions = (true, true),
                 affect_neg! = affect1!,
             )
         end
         begin
             savingFunction(u, t, integrator) =
                 let
                     (t, deepcopy(integrator.p[2]))
                 end
             cb2 = SavingCallback(savingFunction, saved_values_BouncingBallReals)
         end
         return CallbackSet(cb1, cb)
     end

This results in the following error:


┌ Warning: IDAGetDky failed with error code =
│   flag = -25
└ @ Sundials C:\Users\John\.julia\packages\Sundials\cdlY7\src\simple.jl:20

[IDAS ERROR]  IDAGetDky
  Illegal value for k.

┌ Warning: IDAGetDky failed with error code =
│   flag = -25
└ @ Sundials C:\Users\John\.julia\packages\Sundials\cdlY7\src\simple.jl:20

[IDAS ERROR]  IDAGetDky
  Illegal value for k.

┌ Warning: IDAGetDky failed with error code =
│   flag = -25
└ @ Sundials C:\Users\John\.julia\packages\Sundials\cdlY7\src\simple.jl:20

[IDAS ERROR]  IDAGetDky
  Illegal value for k.

┌ Warning: IDAGetDky failed with error code =
│   flag = -25
└ @ Sundials C:\Users\John\.julia\packages\Sundials\cdlY7\src\simple.jl:20

image

The plot seems correct. SciML/Sundials.jl#292 and SciML/Sundials.jl#290 seems to have the same issues

Aether-create pushed a commit to Aether-create/OMBackend.jl that referenced this issue Sep 10, 2024
* Reworking array handling

* Flatten array equations in loops. Added Casc6 to testsuite

* Account for final declarations for real-valued parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant