The most basic Modelica model is a differential equation. In this example, a differential equation is implemented and simulated. Also, the process of creating an icon representing the model graphically is described in detail.
MODELS USED IN THIS TUTORIAL
There is a long tradition that the first example in any computer language is a trivial program printing the string "Hello World". Since Modelica, the language used in SystemModeler, is an equation-based language, printing a string does not make much sense. Instead our Hello World Modelica class solves a trivial differential equation:
The variable x in this equation is a dynamic variable (and a state variable) whose value can change over time. The time derivative is the derivative of x, written as der(x) in Modelica. All Modelica classes have a class declaration (block, model, package, etc.). In this example you will declare the class as a model.
This will open the New Class dialog box, in which you will specify a name and description for the model. Give the model the name "HelloWorld" and the description "A differential equation". Also uncheck the Icon section, as you will create your own icon later. If the Icon section is checked, an icon can be selected for the new class from a set of predefined icons.
After clicking the OK button, the model will be created and become visible in the Class Browser. At the same time, the model will also be opened in a class window. Click the Modelica Text View button in the toolbar to switch to the Modelica Text View of the class window.
The symbol » in the second row contains hidden graphical information about the model and is automatically updated whenever you edit the model in any of the graphical views of the class window. Note that the description you entered in the dialog box has been added to the model. Now it is just a matter of adding the variable and the equation. You will do that by editing the definition of the model directly in the Modelica Text View.
The HelloWorld model is now ready. Before simulating the model, you may want to verify its correctness by clicking the Validate Class button in the toolbar.
This starts Simulation Center, and the HelloWorld model will automatically be translated into an executable. An experiment is created for the HelloWorld model in the Experiment Browser of Simulation Center.
The Settings view of the HelloWorld experiment in the Experiment Browser.
Plotting the variable x in the HelloWorld model in Simulation Center.
Choose a suitable drawing tool, for example the Rectangle Tool, by clicking its corresponding button in the toolbar. This will change the appearance of the cursor. To start drawing, hold down the left mouse button and drag the cursor until you have the size and shape of the rectangle that you want. Release the mouse button to create the rectangle. To edit or view the rectangle properties, double-click the rectangle.
Remove the border pattern, set the corner radius to 25, change the fill color to Dark Green, and select Solid as the fill pattern. When done, click the OK button. Next, press the Esc key to clear the selection in the icon view. Finally, choose the Text Tool and draw a text item covering the entire rectangle, and change the text to "Hello World" and the color to White in the Text Properties dialog box.
The reason why it was necessary to clear the selection before drawing the text item deserves an explanation. Without clearing the selection, you would have ended up moving the rectangle instead of adding a text item, as all drawing tools can also be used to move selected items.
The icon of the HelloWorld model.