Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

import headaches

import headaches

Hello everyone:

I started recently learning modelica, but there is a problem I avoided and I really need to solve.

I can import and simulate succesfully, both in OMEdit and through OMPython, models without units such as this:

Code:


model FirstOrder
  Real x;
equation
  der(x) = 1-x;
end FirstOrder;

But all of the following fail:

Code:


model FirstOrder
  import Modelica.Units.SI;
  SI.Position x;
equation
  der(x) = 1-x;
end FirstOrder;

Code:


model FirstOrder
  Modelica.Units.SI.Position x;
equation
  der(x) = 1-x;
end FirstOrder;

Code:

model FirstOrder

  import SI = Modelica.SIunits;
  SI.Position x;
equation
  der(x) = 1-x;
end FirstOrder;

I include both examples because of the recent change in notation in Modelica 4, since I'm not really sure if my system uses v4 or v3.2.3, since it says "Notification: Automatically loaded package Modelica 3.2.3 due to uses annotation."

I can import other libraries:

Code:

model exer

  import Modelica.Electrical.Analog.Basic;
  Basic.Resistor r(R = 10);
  Basic.Capacitor c(C = 1e-4, v(start = 0));
  Basic.Ground g;
  Modelica.Blocks.Sources.Sine sine(amplitude = 10, freqHz = 10);
  Modelica.Electrical.Analog.Sources.SignalVoltage signalVoltage1;
equation
  connect(sine.y, signalVoltage1.v);
  connect(signalVoltage1.p, r.p);
  connect(r.n, c.p);
  connect(c.n, g.p);
  connect(signalVoltage1.n, g.p);
  annotation(uses(Modelica(version="3.2.3")));
end exer;

Any idea?

Regards

Re: import headaches

Change line:

Code:


annotation(uses(Modelica(version="3.2.3")));

To:

Code:


annotation(uses(Modelica(version="4.0.0")));

If you want to use Modelica 4.0.0.

Re: import headaches

I forgot to ask, what OpenModelica version do you have?

Re: import headaches

I got a warning recently that I could upgrade to Modelica 4.0.0, but it turns out I didn't upgrade:

> dpkg -l | grep modelica
ii  drmodelica                                    1.17.0-1                                         all          An OMNotebook course in the Modelica language
ii  omlib-modelica-3.2.3                          3.2.3~20201118~124214~git~OM~maint~3.2.3-1       all          Modelica 3.2.3 is a Modelica library
ii  omlib-modelicabyexample-0.5.0                 0.5.0~154~g6044b75-1                             all          ModelicaByExample 0.5.0 is a Modelica library
ii  omlib-modelicareference                       20201118~124214~git~OM~maint~3.2.3-1             all          ModelicaReference is a Modelica library
ii  omlib-modelicaservices-3.2.3                  3.2.3~20201118~124214~git~OM~maint~3.2.3-1       all          ModelicaServices 3.2.3 is a Modelica library
ii  openmodelica                                  1.17.0-1                                         amd64        A complete Modelica environment

Re: import headaches

There you go, thanks a lot!

Code:


model FirstOrder annotation(uses(Modelica(version="3.2.3")));
  Modelica.SIunits.Position x;
equation
  der(x) = 1-x;
end FirstOrder;

Re: import headaches

I would put the annotation at the end of the class. Other places in a class were removed in the Modelica 3 grammar many years ago.

There are 0 guests and 0 other users also viewing this topic