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 when using SVector and SMatrix #144

Open
johhell opened this issue Apr 1, 2022 · 1 comment
Open

error when using SVector and SMatrix #144

johhell opened this issue Apr 1, 2022 · 1 comment

Comments

@johhell
Copy link
Contributor

johhell commented Apr 1, 2022

in my example I tried to simulate an induction machines in a 3~ system with position dependent coupling/inductance's.

part of the model for testing

    netz = Spannung | Map(U=:(U1v*sqrt(2.0/3.0))),
    equations = :[
        w = der(phi)
        wt = Omegarated*time
        Lsr  = Interpol1(phi)
        dLsr = Interpol2(phi)
        Lrs  = transpose(Lsr)
        dLrs = transpose(dLsr)
==>     netz.u =r1*i1 + Lss*der(i1)
        u2 = w*dLrs*i1 + Lrs*der(i1)
#         Moment = dot(i1, dLsr*i2)
        Moment = 0.0
        Imech*der(w) = Moment - LAST

        power = dot(netz.u, i1)

code "saveCodeOnFile"

...
        Lsr = Interpol1(phi)
        dLsr = Interpol2(phi)
        Lrs = transpose(Lsr)
        dLrs = transpose(dLsr)
==>     var"der(i1)" = -((var"netz.u" - _p[:r1]::SMatrix{3, 3, Float64, 9} * i1)) / -(_p[:Lss]::SMatrix{3, 3, Float64, 9})
        u2 = (w * dLrs) * i1 + Lrs * var"der(i1)"
        var"der(w)" = -((Float64)(_p[:LAST])::Float64) / (Float64)(_p[:Imech])::Float64
 ...

simplified: var"der(i1)" = SVector / SMatrix
the correct function should be: var"der(i1)" = SMatrix^-1 * SVector

errormessage

ERROR: LoadError: DimensionMismatch("Both inputs should have the same number of columns")
Stacktrace:
  [1] /(A::SVector{3, Float64}, B::SMatrix{3, 3, Float64, 9})
    @ LinearAlgebra ~/julia-1.7.1/share/julia/stdlib/v1.7/LinearAlgebra/src/generic.jl:1149
  [2] getDerivatives(_x::Vector{Float64}, _m::SimulationModel{Float64, Float64}, _time::Float64)
    @ Main ~/.julia/packages/Modia/2gNMw/src/A-CodeGeneration.jl:1685
  [3] #invokelatest#2
    @ ./essentials.jl:716 [inlined]

workaround

in my particular case an additional method was helping.

Base.:/(A::SVector, B::SMatrix) =  B^-1 * A
@johhell
Copy link
Contributor Author

johhell commented Apr 1, 2022

model for testing

testSMatrix.zip

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