# Modelica. Modeling and Simulation Based on Dymola Program

von ِAhmed Jaber (Autor) Mohammed Tubail (Autor) Mohammed Abu Hasna (Autor)

Bachelorarbeit 2013 92 Seiten

## Contents

ACKNOWLEDGMENTS

LIST OF ABBREVIATIONS

ABSTRACT

1 Introduction To Modelica
1.1 History
1.2 Features Of Modelica
1.3 What Can Modlica Be Used For
1.4 Modelica Standard Library (MSL)
1.5 Modelica Simulation Environments
1.6 Introduction To DYMOLA
1.6.1 Installing The Dymola Software
1.6.3 Installing a C compiler
1.6.4 Dymola Overview
1.7 Getting Started With Dymola (Pendulum Motion Example)

2 Syntax of Modelica
2.1 Comment
2.2 Identifiers and Keywords
2.2.1 Identifiers
2.2.2 Keywords
2.3 Data Types
2.3.1 Real Data Type
2.3.2 Integer Data Type
2.3.3 Boolean Data Type
2.3.4 String Data Type
2.3.5 User Define Types
2.4 Modelica Operator and Evaluation Order
2.5 IF Statement and Relation Operator
2.6 Build in Variable Called Time
2.7 Built-in Intrinsic Operators And Functions
2.8 Critical Points

3 Simulation of Electrical Networks
3.1 Electrical Connectors
3.2 Electrical components
3.2.1 Resistor
3.2.2 Inductor
3.2.3 Capacitor
3.2.4 Ideal Transformer
3.2.5 DC voltage source
3.2.6 AC sinusoidal voltage source
3.3 Electrical Circuit Examples
3.3.1 RC circuit
3.3.2 Series RLC Resonance Circuit
3.3.3 Ideal transformer circuit

4 Simulation of hydraulic networks
4.1 Hydraulic connector
4.2 Hydraulic components
4.2.1 Pipe
4.2.2 Water tank
4.2.3 Boundary Source/sink
4.2.4 Recovery Pump
4.2.5 Booster Pump
4.2.6 Valve
4.3 simple hydraulic networks
4.3.1 Two hydraulic tanks filled with water
4.3.2 Water recovery well
4.3.3 Water recovery well with logical control
4.4 Modeling,simulation and control of a water recovery and Irrigation system
4.5 Modeling and Simulation of a Wastewater Pumping Plant
4.5.1 Screen Station and Pump Station
4.5.2 Screening process
4.5.3 Pumping Process
4.5.4 Wastewater Pumping Plant model
4.5.5 Simulation Results

5 Introduction to Animation Using Dymola
5.1 Animation in Dymola
5.2 Multibody Library
5.3 Animation Example
5.3.1 Simple Ideal Pendulum Animation
5.3.2 Spring Animation
5.3.3 Double Pendulum Animation

CONCLUSION

References

## LIST OF ABBREVIATIONS

illustration not visible in this excerpt

## List of Figures

1.1 Declarative Equation and Textual Language

1.3 Dymola Modeling Window

1.4a Simple Pendulum

1.4b Free Body Diagram For Simple Pendulum

1.5 Create a New Model

1.6 Modelica Editor

1.7 Result of the Check

1.9 Simulation Plot

3.1 Pin connector symbol

3.2 Resistor Symbol

3.3 Inductor Symbol

3.4 Capacitor Symbol

3.5 Ideal Transformer Symbol

3.6 Dc voltage source symbol

3.7 AC sin voltage source symbol

3.8 RC circuit

3.9 Capacitor voltage at RC circuit

3.10 Resistor voltage at RC circuit

3.11 Resistor current at RC circuit

3.12 Capacitor current at RC circuit

3.13 Time constant at RC circuit

3.14 Series RLC resonance circuit

3.15 Resistor Voltage at RLC circuit

3.16 Resistor current at RLC circuit

3.17 Capacitor and inductor voltages at RLC circuit

3.18 Ideal transformer circuit

3.19 Primary voltage (V1) and secondary voltage (V2) of ideal transformer

3.20 Primary current (I1) and secondary current (I2) of ideal transformer

## List of Figures

4.1 pipe icon

4.2 water tank

4.3 Boundary Source/sink icon

4.4 recovery pump icon

4.5 Typical pump flow characteristic

4.6 Booster pump icon

4.7 Water Valve icon

4.8 Two hydraulic tanks filled with water

4.9 levels of water tanks

4.10 Water recovery well model

4.11 level of Water tank

4.12 Water recovery well with logical control

4.13 Water tank level with logical control

4.14 Water recovery well with logical control and user demand

4.15 Water tank level

4.16 Top level model of the system

4.17 Filling process controller

4.18 Distribution process controller

4.19 tanks water level

4.20 running pumps counter

4.21 water mass flow

4.22 water pressure

4.23 speed of booster pumps

4.24 New terminal pumping station (NTPS)

4.25 screen station

4.26 screening process

4.27 buffer chamber icon

4.28 Bar screen visualization

4.29 Decomposing the flow across the screen

4.30 Bar screen icon

4.31 Pumping Process

4.32 Pumping Process controller

4.33 System model

4.34 Simulation Scenario

4.35 Wastwater level in the screen champer

4.36 Inlet flow,Over flow and Transmitted flow

4.37 Discrete signal of the screen controller

4.38 level in the suction champer

4.39 Speed of booster pumps

5.1 Animation Using Multibody Library

5.2 Double Penduluem Animation

5.3 Simple Pendulum Digrame in Dymola

5.4 World Icon Parameter

5.5 Revolute Joint Parameters

5.6 Simple Pendulum Motion Initlization

5.7 The Body Part

5.8 Body Part Parameters

5.9 The 3D VIew of the Model

5.10 Result of 3D View Control

5.11 Expexted Path of Pendulum Motion

5.12 Spring Diagram

5.13 Spring properties in Dymola

5.14 3D View of Spring Model

5.15 Spring Velocity

5.16 Phase of Spring

5.17 Double Pendulum Digram

5.18 Body Box properties

5.19 3D model of Double Pendulum

## List of Tables

2.1 Floating Point Number

2.2 Modelica Character Escape Sequence

2.3 Modelica Operator

4.1 Level threshold settings

5.1 Contents of Multibody library

## ABSTRACT

Modelica is an object-oriented, declarative, multi-domain language for componen- toriented modeling of complex systems, e.g., systems containing mechanical, elec- trical, electronic, hydraulic, thermal, control, electric power or process-oriented sub- components. Modelica language is a textual description to define all parts of a model and to structure model components in libraries, called packages. Basically, all Mod- elica language elements are mapped to differential, algebraic and discrete equations. Using Modelica in design process for complex systems is very efficient and pro- vide several benefits results. In Modelica we can model and simulate all types of components such as electrical, mechanical, hydraulic etc. Furthermore, Modelica Association provide standard library which contains a lot of different components.

## Chapter 1 Introduction To Modelica

Modelica is an object-oriented, declarative, multi-domain language for component- oriented modeling of complex systems, e.g., systems containing mechanical, electri- cal, electronic, hydraulic, thermal, control, electric power or process-oriented sub- components. Modelica language is a textual description to define all parts of a model and to structure model components in libraries, called packages. Basically, all Mod- elica language elements are mapped to differential, algebraic and discrete equations.

### 1.1 History

The Modelica design effort was initiated in September 1996 by Hilding Elmqvist. The goal was to develop an object-oriented language for modeling technical systems in order to reuse and exchange dynamic system models in a standardized format. Modelica 1.0 is based on the PhD thesis of Hilding Elmqvist and on the experi- ence with modeling languages including Allan, Dymola, NMF, ObjectMath, Omola, SIDOPS and Smile. Although many people have contributed in developing Model- ica, the prime creator is Hilding Elmqvist. In September 1997, version 1.0 of the Modelica specification was released and considered the basis for a prototype imple- mentation within the commercial Dymola software system. In 2000, the non-profit Modelica Association was formed to manage the continually evolving Modelica language and the development of the free Modelica Standard Library. In the same year, the usage of Modelica in industrial applications started.

### 1.2 Features Of Modelica

- Modelica is based on equations instead of assignment statements. This permits a causal modeling that gives better reuse of classes since equations do not specify a certain data flow direction. Thus a Modelica class can adapt to more than one data flow context.
- Modelica has a multi-domain modeling capability, meaning that model compo- nents corresponding to physical objects from several different domains such as electrical, mechanical, thermodynamic, hydraulic, biological and control appli- cations can be described and connected.
- Modelica is an object-oriented language with a general class concept that unifies classes. This facilitates reuse of components and evolution of models.
- Typed declarative equation-based textual language, as shown in Figure 1.1.

illustration not visible in this excerpt

Fig. 1.1 Declarative Equation and Textual Language

- Modelica has a strong software component model, with constructs for creating and connecting components. Thus the language is ideally suited as an architec- tural description language for complex physical systems, and to some extent for software systems.

### 1.3 What Can Modlica Be Used For

Modelica can be used for simulating electronic circuits, automotive powertrains, power system stability, vehicle dynamics and hydraulic systems.

### 1.4 Modelica Standard Library (MSL)

In addition to define the specification for the Modelica language, the Modelica As- sociation publishes a standard library of Modelica models. This library, called the Modelica Standard Library (MSL), is available free of charge. MSL was developed so that users of the Modelica language would not have to create their own basic models for the common modeling domains. Note that the MSL is not a collec- tion of black box model. Instead, Modelica representation of all the models can be viewed to help understanding exactly what behaviour is modelled. The names of MSL’s components begin with ”Modelica.”. For example, the physical type ”Mod- elica.SIunits.Voltage” is a type defined in the ”SIunits” package nested inside the ”Modelica” package.

### 1.5 Modelica Simulation Environments

- CATIA Systems: from Dassault Systemes (based on Dymola kernel with Product Lifecycle Management (PLM) integration).
- Dymola: from Dynasim AB, Sweden (Dynasim was acquired by Dassault Sys- temes in 2006).
- LMS Imagine.Lab AMESim: from LMS International .
- MathModelica: from Wolfram Research, Sweden.
- OpenModelica: is an open-source Modelica-based modeling and simulation en- vironment intended for industrial and academic usage.

In these lecture notes, we will focus our study on Dymola environment.

### 1.6 Introduction To DYMOLA

Dymola ,Dynamic Modeling Laboratory, is a commercial modeling and simulation environment based on the open Modelica modeling language. It is developed by the Swedish company Dassault Systmes AB, Lund, a subsidiary of the shareholder company Dassault Systemes. Dymola is available as either a standalone product or integrated in CATIA Systems V6. The latest 2013 version of Dymola supports version 3.2 the Modelica language.

#### 1.6.1 Installing The Dymola Software

Dymola installation is a typical installation as any other program.

After installation Dymola will initially start in demo mode. While running in demo mode you can continue with installing the license file.

Sharable licenses are requested by Dymola froma license server. The information normally required on the client computer is just the name (or IP number) of the license server.

Start Dymola and select Help > License, and then the Setuptab. Enter the name or IP number of the server. If so instructed by the system administrator, also enter the port number. By default leave this field empty. As shown in Figure 1.2.

You have the option of installing the license file only for the currently logged in user, or for all users on this computer. The latter requires administrator rights. Click on the OK button. Dymola will ask for confirmation before overwriting your old license information.

After changing the license server setup you must restart Dymola to use the new server.

#### 1.6.3 Installing a C compiler

To translate models in Dymola, you must also install a supported C compiler. The C compiler is not distributed with Dymola. Dymola supports Microsoft Visual Studio

illustration not visible in this excerpt

2010, both the Professional and the Express edition. Dymola also supports older Microsoft compilers including Visual Studio 2008 Professional and Express edition in addition to Visual Studio 2005 Professional edition.

To download the free Visual Studio 2010 Express edition compiler, visit Microsoft’s website2.The C compiler can be installed before or after you install the Dymola. You can run Dymola and browse models however, in order to be able to translate a model you must have an installed C compiler.

#### 1.6.4 Dymola Overview

When Dymola runs, the main Dymola window appears. A Dymola main window operates in one of the two modes:

- Modeling: for finding, browsing and composing models and model components.
- Simulation: for making experiments on the model, plotting results, and animating behavior.

Dymola starts in Modeling mode. The active mode is selected by clicking on the tabs in the bottom right corner of the Dymola window, see Figure 1.3

illustration not visible in this excerpt

Fig. 1.3 Dymola Modeling Window3

### 1.7 Getting Started With Dymola (Pendulum Motion Example)

This example will show how to start and simulate models. Pendulum motion is modeled by an ordinary differential equation. Figures (1.4a-1.4b) show a simple pendulum and its free body diagram respectively. From the free body diagram:

T = −mgsinθ (1.1)

where T is the tension force along the rod, m is the mass of the pendulum and g is the gravity acceleration. Since:

τ = −mglsinθ (1.2)

where τ is the torque around the pivot point and r is the level arm vector and l is the length of the massless rod, the negative sign indicate that torque direction is clockwise. Using Newton second low for rotational system:

illustration not visible in this excerpt

Fig. 1.4a Simple Pendulum Fig. 1.4b Free Body Diagram For Simple Pendulum

τ=Iα (1.3)

where I is the moment of inertia and α is the angler acceleration. Since the acceleration is the second derivative of distance we have:

illustration not visible in this excerpt

(1.4)

illustration not visible in this excerpt

(1.5)

illustration not visible in this excerpt

(1.6)

From Equation (1.2) and Equations (1.4 through 1.6)

illustration not visible in this excerpt

(1.7)

illustration not visible in this excerpt

(1.8)

Using small angle approximation on Equation (1.8):

illustration not visible in this excerpt

(1.9)

Write the previous equation as first order differential equation:

illustration not visible in this excerpt

(1.10)

illustration not visible in this excerpt

(1.11)

dt where ω is the angular velocity.

To model The previous simple example using Dymola, the first step is creating new model as shown in Figure 1.5. A model can be inspected and edited in different

illustration not visible in this excerpt

Fig. 1.5 Create a New Model

views. When specifying a behavior directly in terms of equations, it is most convenient to work with the model as a Modelica Text layer. To display this layer, press the Modelica Text toolbar button, the second rightmost tool button. In Figure 1.6, write the following code:

model pendul

parameter Real L=2; constant Real g=9.81; Real theta;

Real omega; equation

der(theta) = omega;

der(omega) = -(g/L)*theta; end pendul;

Since the model should be simulated, it should be checked before saved. The check command performs some symbolic and syntactic checks that will capture a

illustration not visible in this excerpt

Fig. 1.6 Modelica Editor

number of errors might have been introduced by the user. The check is performed by clicking on the Check icon or by selecting the command (Edit =⇒ Check) or simply by clicking F8 key. The result of the check is shown in Figure 1.7

illustration not visible in this excerpt

Fig. 1.7 Result of the Check

The second step is initiating simulation.To enter the simulation mode, click on the simulation tab at the bottom right of the main window. The simulation panel is now activated and new toolbar buttons appear.To set up the simulation: select (Simulation ⇒ Setup) or click directly on the Experiment Setup toolbar button, the simulation setup window will appear as in Figure 1.8

Set the Stop time to 10 seconds. Click OK. To run the simulation select (Sim- ulation ⇒ Simulate) or click directly on the Simulate toolbar button. When the

illustration not visible in this excerpt

simulation is finished, the variable browser displays variables to plot.To see the plot better, maximize the plot window in the edit window.Then check the checkbox in front of theta to get the angle plotted as shown in Figure 1.9

illustration not visible in this excerpt

Fig. 1.9 Simulation Plot

## Chapter 2 Syntax of Modelica

The smallest building blocks in Modelica are single characters belonging to a char- acter set. The character set of the Modelica language is restricted to a unicode characters. Characters are combined to form lexical units, identifiers, and operators. Comments are not a lexical unit since they are eventually discarded by the Modelica translator.

### 2.1 Comment

There are two types of comments in Modelica, the first type, called regular com- ment, is ignored by Modelica translator. In contract, the other type, called docu- mentation comment, is not ignored. While regular comment is viewed with source code only, documentation comment, as the name suggests, will appear in both sim- ulation panel and the components help information. As shown in example 2.1.

Example 2.1

illustration not visible in this excerpt

### 2.2 Identifiers and Keywords

Identifier is sequence of letters or character used for naming items in the language. Keyword are reserved for the language use and can’t be used as identifiers. Modelica is a latter case-sensitive language.

#### 2.2.1 Identifiers

There are two forms of identifiers in Modelica language. The first form starts with a letter or an underscore followed by any number of latters, see Example 2.2.

illustration not visible in this excerpt

The second form, called Q-identifier, begins with a quote and any printable ASCII code and ends with backslash followed by a quote, as shown in Example

illustration not visible in this excerpt

#### 2.2.2 Keywords

In a computer programming languages, a keyword is a word that has a particu- lar meaning to the language. In Modelica language, a keyword is a reserved word identifies a syntactic form. Control flow constructs, such as if, then, and else are keywords. Keywords cannot be used as names of variables or functions.

### 2.3 Data Types

Real, Integer, Boolean, and String are the primitive built-in data types in Model- ica, user-defined data types are created to facilitate programming and provide more flexibility.

#### 2.3.1 Real Data Type

Real corresponding to the double data type in other programming language. Real is a primitive data type in Modelica which is usually 64-bit floating-point. There are many representations for floating point number illustrated in Table 2.1

Table 2.1 Floating Point Number

illustration not visible in this excerpt

#### 2.3.2 Integer Data Type

Literals of type Integer are sequences of decimal digits. A negative number is represented by minus sign before the number, as in Example 2.4.

illustration not visible in this excerpt

#### 2.3.3 Boolean Data Type

The two Boolean literal values are typically true and false.

#### 2.3.4 String Data Type

String literals appear between double quotation ”string here” some characters must be preceded by a backslash (\) in order to include them in a string, as shown in Table 2.2.

String concatenation can be accomplished by (+) sign, for example ”a”+”b” give the string ”ab”

Table 2.2 Modelica Character Escape Sequence

illustration not visible in this excerpt

#### 2.3.5 User Define Types

A user defined data type is a good programming tool for building new types that are more realistic, more readable and more closer to the real life objects. as shown in Example 2.5.

illustration not visible in this excerpt

### 2.4 Modelica Operator and Evaluation Order

Operator precedence determines the evaluation order of operators in an expression, Table 2.3 shows a list of operators.

### 2.5 IF Statement and Relation Operator

If statement simplest form is: if expression1 then expression2 else expression3. Expression1 must be logical expression so if the result is true then expression2 is executed, other wise if the result is false expression3 is executed. Ifstatements guarantee that their clauses are only evaluated if the appropriate condition is fulfilled, see Example 2.6.

Table 2.3 Modelica Operator

illustration not visible in this excerpt

Example 2.6

illustration not visible in this excerpt

The value of the variable x equals the sqrt of multiplying both value1 and value2. So the multiplication can’t be negative otherwise the sqrt will not be defined. So we use if-statement to make sure sqrt satisfies its condition. Relational operators (<, <=, >, >=, ==, <>) are only defined for scalar operands not vectors so. The result is Boolean (true or false). to apply relation operator on string data type, use strcmp(str1,str2).

### 2.6 Build in Variable Called Time

The time, a build-in variable available in all models and blocks, has a start value equal to the time value at which the simulation starts, see Example 2.7

Example 2.7

illustration not visible in this excerpt

### 2.7 Built-in Intrinsic Operators And Functions

Built-in operators in Modelica have the same syntax as a function call. They do not act like math functions which depend on input value. They depend on input value and simulation state. And we mean by intrinsic that they are implicitly included ; you don’t have to include a library in your code; and here are some examples on this operator :

- Mathematical and conversion functions. For example: abs(v), sign(v), sqrt(v).
- Derivatives and special-purpose operators with function syntax. For example: der(expr), delay(expr,delayTime).
- Event-related operators with function syntax. For example: initial(), terminal(), noEvent(expr).
- Array operators/functions. For example: promote(A,n)

### 2.8 Critical Points

- The main deference between Real and parameter Real is that Real can be changed during simulation like the position of pendulum but parameter Real can’t be changed during simulation like the mass of the pendulum.
- The main deference between parameter and constant that constant value can not be changed during simulation and the only way to change it is by modifying the source code on the other hand parameter can be changed by stopping the simulation and adjusting its value then restart the simulation.
- The deference between equality operator (=) and assignment operator (:=) is explained by Example 2.8 and Example 2.9.

Example 2.8

illustration not visible in this excerpt

Example 2.9

illustration not visible in this excerpt

- The der(x) is used to represent the derivative operator. The derivative operator can’t be applied on expressions and can’t be applied recursively e.g. der(der(x)) is illegal.

## Chapter 3 Simulation of Electrical Networks

This chapter describes the modeling and simulation of electrical circuits using the modelica language. It describes how to build models for electrical connectors and basic electrical components which are used in building electrical circuits. At the end of the chapter, examples of some electrical circuits will be created and simulated.

### 3.1 Electrical Connectors

Connectors represent input and output terminals of electrical components.It is a special class derived at modelica language.The following modelica code represents the electrical connector model.

illustration not visible in this excerpt

From the previous Modelica code, v is a real variable define the voltage of the con- nector and i is a flow variable define the current passing through the connector.

Connector symbol can be drawn by Dymola as shown in Fig. 3.1

illustration not visible in this excerpt

Fig. 3.1 Pin connector symbol

### 3.2 Electrical components

#### 3.2.1 Resistor

Resistor is a passive two terminals electrical component that represent the dissipated electrical energy in a system. At modelica language it can be defined as a model with main equation relates between the time-varying voltage v(t) across the resistor with value R and the time-varying current i(t) passing through it. It is described by the equation v(t)= R i(t).

The following modelica code represents the resistor model.

illustration not visible in this excerpt

The Modelica code in the previous example has three variables listed below:

- R which represents a real parameter holding the resistance value.
- v is real variable defines the voltage a cross resistor.
- i is real variable defines the current passing through resistor.

Resistor has two terminals then two connectors p and n must be declared. The two connectors must be added by dragging and dropping them in the diagram tab when drawing the resistor symbol.

The modelica code of resistor has four equations listed below with illustration:

- v = p.v - n.v, is the voltage drop a cross the resistor where p.v and n.v is the p connector and n connector voltages respectively.
- 0 = p.i + n.i, the sum of currents at connectors equals zero.
- i = p.i, the current passing through a resistor is the current flowing into its positive pin.
- R*i=v, Ohm’s law relating the voltage and current through resistor. Resistor symbol can be drawn by Dymola as shown in Fig. 3.2

[...]

1 Dymola Dynamic Modeling Laboratory Installation, page 14

2 http://www.microsoft.com

3 Dymola Dynamic Modeling Laboratory Getting started with Dymola, page 6

## Details

Seiten
92
Jahr
2013
ISBN (eBook)
9783656876274
ISBN (Buch)
9783656876281
Dateigröße
2.9 MB
Sprache
Englisch
Katalognummer
v286484
Institution / Hochschule
Islamic University - Gaza
Note
A
Schlagworte
modelica modeling simulation based dymola program