ModiaSim / Modia.jl

Modeling and simulation of multidomain engineering systems
MIT License
321 stars 38 forks source link

issue with "m.x_init" #135

Closed johhell closed 2 years ago

johhell commented 2 years ago

description

after upgrading to Julia 1.7 and using the latest version of ModiaLang, I have some problems with init-values in the simulationmodel. In a previous version of ModiaLang I used (before mid Dec 2021) everything was fine. I can find the defined init-value in the table, but the position is not correct.

used versions

git clone from 2022-02-21

Julia: Version 1.7.1 (2021-12-22)
name = "ModiaLang"  version = "0.11.1"
name = "ModiaBase"  version = "0.9.1"

definition of init-values in model

...
    xfd = 0.2181,
    xf1d = 0.0011,
    Psifd = Var(init=1.234),        <<<<=====
...
    xaq = parameter | Map(value=:(xq - xl)),
    PsiRe = Var(init=1.001),        <<<<=====
    Psi1Re = Var(init=1.002),        <<<<=====
    equations = :[
...
    J = Inertia | Map(
        J=3.0,
        w=Var(init=1.0),        <<<<=====
        phi=Var(init=0.0),
        ),
...

@instantiateModel --> correct

println(ModiaBase.get_x_table(instModel.equationInfo.x_info))

16×6 DataFrame
 Row │ name                           unit    startOrInit  fixed  nominal  unbounded 
     │ String                         String  Any          Bool   Float64  Bool      
─────┼───────────────────────────────────────────────────────────────────────────────
   1 │ GridVolts.rad                          0.0          false      NaN      false
   2 │ T1.X.ixRe                                           false      NaN      false
   3 │ T1.X.ixIm                                           false      NaN      false
   4 │ synUnit.SM.phiKR                                    false      NaN      false
   5 │ synUnit.SM.PsiRe                       1.001         true      NaN      false
   6 │ synUnit.SM.PsiIm                                    false      NaN      false
   7 │ synUnit.SM.Psi1Re                      1.002         true      NaN      false
   8 │ synUnit.SM.Psi1Im                                   false      NaN      false
   9 │ synUnit.SM.Psifd                       1.234         true      NaN      false
  10 │ synUnit.exciter.transducer.x           1.0           true      NaN      false
  11 │ synUnit.exciter.PI1.Integr.x           0.0           true      NaN      false
  12 │ synUnit.exciter.PIa.Integr.x           0.0           true      NaN      false
  13 │ synUnit.exciter.PI1f.x                 0.0           true      NaN      false
  14 │ synUnit.exciter.PT1a.Integr.x          0.0           true      NaN      false
  15 │ J.phi                                  0.0           true      NaN      false
  16 │ J.w                                    1.0           true      NaN      false

states in simulation --> error

  # │ state                          init   unit  nominal 
────┼─────────────────────────────────────────────────────
  1 │ GridVolts.rad                  0.0              NaN
  2 │ T1.X.ixRe                      1.001            NaN    <<<<=== WRONG
  3 │ T1.X.ixIm                      1.002            NaN    <<<<=== WRONG
  4 │ synUnit.SM.phiKR               1.234            NaN    <<<<=== WRONG
  5 │ synUnit.SM.PsiRe               1.0              NaN    <<<<=== MISSING
  6 │ synUnit.SM.PsiIm               0.0              NaN
  7 │ synUnit.SM.Psi1Re              0.0              NaN    <<<<=== MISSING
  8 │ synUnit.SM.Psi1Im              0.0              NaN
  9 │ synUnit.SM.Psifd               0.0              NaN    <<<<=== MISSING
 10 │ synUnit.exciter.transducer.x   0.0              NaN
 11 │ synUnit.exciter.PI1.Integr.x   1.0              NaN    <<<<=== WRONG
 12 │ synUnit.exciter.PIa.Integr.x   0.0              NaN
 13 │ synUnit.exciter.PI1f.x         0.0              NaN
 14 │ synUnit.exciter.PT1a.Integr.x  0.0              NaN
 15 │ J.phi                          0.0              NaN
 16 │ J.w                            0.0              NaN    <<<<=== MISSING
MartinOtter commented 2 years ago

I am sorry, this should not have happened.

All the test models in ModiaBase, ModiaLang, next Modia3D version run and from the information above, I have no idea, where the error could be.

Can you send a complete model that runs under the previous version and does not longer run in the newest versions?

johhell commented 2 years ago

The first time I observed the problem was ~ Dec 20 2021. I tried a new ModiaLang, but switched back to the old version. Maybe a modification you did short before is the reason.

I think the problem has to do with variables without init/start values. See below: Unbenannt 1 In the past a missing start-value was automatically set to 0.0 . Due to the missing value now, the values are ordered not correct in the m.x_init This warning now results in an error.

Warning message from getSortedAndSolvedAST for model SMtest:
Init/start values missing in the model for some ODE states.
Involved variables:
    T1.X.ixRe
    T1.X.ixIm
    synUnit.SM.phiKR
    synUnit.SM.PsiIm
    synUnit.SM.Psi1Im

workaround

define start/init for all variables At the moment I'm using variables without explicit definition.

MartinOtter commented 2 years ago

In the new Modia version (0.9.0), the start/init implementation has changed. In particular missing start/init values should now be correctly handled. There is some chance that your reported error is fixed.