1
votes

i'm trying to learn modelica and started with coding some simple examples from the tutorial:"Introduction to Object-Oriented Modeling and Simulation with OpenModelica" by Peter Fritzson Link . I'm working with dymola. There is one example called Moon Landing which i can't get running. After starting the Simulation i can't plot any of the variables. Here is my code:

model Example

class Rocket "rocket class"
  parameter String name;
  Real mass(start = 1038.3);
  Real altitude(start = 59404);
  Real velocity(start = -2003);
  Real thrust;
  Real acceleration;
  Real gravity;
  parameter Real massLossRate=0.000277;
equation 
  acceleration = (thrust-mass*gravity)/mass;
  der(mass) = -massLossRate * abs(thrust);
  der(altitude)=velocity;
  der(velocity)=acceleration;
end Rocket;

class CelesticalBody
  constant  Real   g = 6.672e-11;
  parameter Real   radius;
  parameter String name;
  parameter Real   mass;
end CelesticalBody;

class MoonLanding
  parameter Real force1 = 36350;
  parameter Real force2 = 1308;
 protected 
  parameter Real thrustEndTime = 210;
  parameter Real thrustDecreaseTime = 43.2;
 public 
  Rocket          apollo(name="apollo13");
  CelesticalBody  moon(name="moon",mass = 7.382e22, radius=1.738e6);
equation 
    apollo.thrust = if (time < thrustDecreaseTime) then force1
                  else if 
                         (time < thrustEndTime) then force2
                  else 0;
   apollo.gravity = moon.g*moon.mass/(apollo.altitude+moon.radius)^2;
end MoonLanding;


end Example;

Does someone knows where a mistake could be?

1
It works for me (I copied your code and simulated the class MoonLanding for 230 seconds). I have access to all variables. Can you see the classes (apollo, moon) on the simulation tab?Rene Just Nielsen
Hey, thank you for you answer. I allways tried to simulate the whole model containing all classes. But i have to simulate just the MoonLanding class. Any idea why it doesn't work when simulating the whole model?A.Schneider
The whole "model" is actually a "package" containing three "models". Models, packages, blocks etc. are special Modelica classes.Rene Just Nielsen

1 Answers

2
votes

As @Rene-Just-Nielsen indicated you have to simulate Example.MoonLanding and you should make Example a package (not model), and MoonLanding (Rocket, CelestialBody) model (not class):

package Example
  model Rocket "rocket class" 
    ...
  end Rocket;
  model CelestialBody 
    ...
  end CelestialBody
  model MoonLanding 
    ...
  end MoonLanding;
end Example;

(Basically the answer isn't mine but Rene's, and I agree with it.)

Some additional benefits of marking them as "package" and "model" are that:

  • Attempting to simulate a package (such as package Example) will give an error in Dymola, so this particular error would be detected.
  • The package browser is intended to show the contents of packages - not models.
  • MoonLanding uses time, but only models and blocks can use time (this is just given as a warning).