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

Error in using Modelica.SIunits package (Solved)

Error in using Modelica.SIunits package (Solved)

NOTE: ANSWER FOUND. The problem was that I failed to load the Modelica library in the shell. Any reason why this needs to be manually done, instead of done automatically on startup?

Hello, all:

I'm trying to use OpenModelica on OS X (Snow Leopard), and just downloaded the 1.7.0 release from the website. I've tried using a simple example in the Notebook:

Code:

package Examples

 
  model SimplePendulum
  import Modelica.Math.*;
  import SI = Modelica.SIunits;
   
  // type Angle = Real (
  //    final quantity="Angle",
  //    final unit="rad",
  //    displayUnit="deg");
  // type AngularVelocity = Real (
  //    final quantity="AngularVelocity",
  //    final unit="rad/s",
  //    displayUnit="rev/min");
    parameter Real L = 2;
    constant Real g = 9.81;
    SI.Angle phi(start=2, fixed=true);
    SI.AngularVelocity omega;
  equation
    der(phi) = omega;
    der(omega) = -(g/L) * sin(phi);
  end SimplePendulum;
 
end Examples;

Now, if I delete the import SI line and remove the comments from the type definitions and the "SI." in front of the "Angle" and "AngularVelocity" definitions, everything works as expected. However, if I leave the import SIunits statement in place, the simulation crashes, and gives me the following message:

Code:

[[/Users/aei/Documents/workspace/Modelica/SimplePendulum.mo:17:5-17:38:writable] Error: Class SI.Angle not found in scope Examples.SimplePendulum while instantiating phi.

Error: Error occured while flattening model Examples.SimplePendulum
[/Users/aei/Documents/workspace/Modelica/SimplePendulum.mo:17:5-17:38:writable] Error: Class SI.Angle not found in scope Examples.SimplePendulum while instantiating phi.
Error: Error occured while flattening model Examples.SimplePendulum

I've tried looking through the previous messages, and can't seem to find anything related to problems with importing SIunits. (Note that the import Modelica.Math command appears to work correctly.)

Any ideas what could be going wrong here?

Thanks,

--AEI

Edited by: aeismail - Aug-30-11 20:12:39

Re: Error in using Modelica.SIunits package (Solved)

Hi aeismail!
I had the same problem using the German version of OpenModelica 1.9.0 beta 4.

Just for anybody searching for the problem to use SIunits or an package from Modelica standard library:
e.g. running the EMF I received the message:
[<interactive>:5:3-5:62:writable] Error: Klasse SIunits.Voltage konnte nicht im Geltungsbereich von EMF gefunden werden.
Error: Error occurred while flattening model EMF


I solved it as you indicated, by entering once
loadModel(Modelica)

Maybe this helps someone else while starting off with Modelica current/smile
Ciao Uwe

There are 0 guests and 0 other users also viewing this topic
You are here: