0% found this document useful (0 votes)
63 views4 pages

Introductory Modelica Exercises

This document provides exercises for introductory Modelica modeling. It includes instructions to install OpenModelica and complete simple textual and graphical modeling exercises, such as simulating and plotting a simple model with one differential equation. Additional exercises demonstrate modeling techniques like using when equations to model hybrid systems, developing models of physical systems using components from the Modelica standard library, and adding controllers to regulated systems.

Uploaded by

Sreerag V N
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views4 pages

Introductory Modelica Exercises

This document provides exercises for introductory Modelica modeling. It includes instructions to install OpenModelica and complete simple textual and graphical modeling exercises, such as simulating and plotting a simple model with one differential equation. Additional exercises demonstrate modeling techniques like using when equations to model hybrid systems, developing models of physical systems using components from the Modelica standard library, and adding controllers to regulated systems.

Uploaded by

Sreerag V N
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Exercises to Introductory

Modelica Tutorial
1 Short Introduction to Graphical Modeling
Install OpenModelica and start OpenModelica OMNotebook. Also and start the OpenModelica Connectio
Graphical Connection Editor called OMedit..
Do the RL-Circuit exercise in the course slides.

2 Simple Textual Modeling Exercises


2 HelloWorld
.
1
Simulate and plot the following example with one differential equation and one initial condition. Start by
in the cell and pushing shift-enter.
model HelloWorld "A simple equation"
parameter Real a = -1;
Real x(start=1);
equation
der(x)= a*x;
end HelloWorld;
{HelloWorld}
Push shift-tab for command completion, fill in the name HelloWorld, and simulate it!
simulate(HelloWorld, startTime=0, stopTime=1, numberOfIntervals=500,
tolerance=1e-10)
[done]
Push shift-tab for command completion, fill in a variable name (x), and plot it!
plo
true

2 Try DrModelica with VanDerPol


.
2
Locate the VanDerPol model in DrModelica (link from Section 2.1), run it, change it slightly, and re-run it
Change the endTime to 10, then simulate and plot.
Change the lambda parameter to 10, then simulate for 50 seconds and plot. Why is the plot looking like th
2 DAE Example
.
3
Simulate and plot following example which includes an algebraic equation with no derivatives.

1
class DAEexample
Real x(start=0.9, fixed=true);
Real y(start=0);
equation
der(y)+(1+0.5*sin(y))*der(x) = sin(time);
x - y = exp(-0.9*x)*cos(y);
end DAEexample;
{DAEexample}
Simulate the example
simulate(DAEexample, stopTime = 1)
[done]
Plot the results. Notice that while the start value of x is fixed, the start value of y is not fixed. Non-fixed st
values are treated by the simulator as "guess" values. During initializiation this guess value will be tried a
starting value, but the simulator can change them in order to produce a set of consistent initial [Link]
linear system of equations needs to be solved during initialization, such guess values will be used by the
simulator as a starting point (guess value) for root-finding algorithms such as Newton's method..
plot({x,y})
true

2 A Simple Systems of Equations


.
4
Develop a Modelica model that solves the equation system below with initial conditions. Hint: initial cond
are often specified using the start attribute.

model ...

2 Functions
.
5
a) Write a function, sum2, which calculates the sum of Real numbers, for a vector of arbitrary size.

function sum2
...
end sum2;
{sum2}
b) Write a function, average, which calculates the average of Real numbers, in a vector of arbitrary size. T
function average should make use of a function call to sum2
function average
...

2
end average;
{average}
Test the functions
average({1,2,3})
2.0

2 Hybrid Modeling with BouncingBall


.
6
Locate the BouncingBall model in one of the hybrid modeling sections of DrModelica (the when-Equation
in Section 2.9), run it, change it slightly, and re-run it.

3 Simple Graphical Design Using the Graphical Connection


Editor
3 DC Motor
.
1
Make a simple DC-motor using the Modelica standard library that has the following structure:

model ...
[1:7]: error: unexpected token: .

You can simulate and plot the model directly from the graphical editor. Simulate for 15s and plot the varia
the outgoing rotational speed on the inertia axis and the voltage on the voltage source (denoted u in the fig
the same plot.

Option: You can also save the model, load it and simulate it using OMShell or OMNotebook. You can also

3
the graphical editor text view and copy/paste the model into a cell in OMNotebook.

Hint: if you use the plot command in OMNotebook and you have difficulty finding the names of the varia
plot, you can flatten the model by calling instantiateModel, which exposes all variable names.

3 Spring and Inertia (Extra)


.
2
Add a torsional spring to the outgoing shaft and another inertia element. Simulate again and see the result
Adjust some parameters (right-click on corresponding model component icon) to make a rather stiff spring

model ...
[1:7]: error: unexpected token: .

3 Adding controller (extra)


.
3
Add a PI controller to the system and try to control the rotational speed of the outgoing shaft. Verify the re
using a step signal for input. Tune the PI controller by changing its parameters. Right-click on the PI Cont
Icon to change parameters.

model ...
[1:7]: error: unexpected token: .

Common questions

Powered by AI

The command completion feature, activated by shift-tab, enhances modeling efficiency in OMNotebook by allowing quick access to command suggestions, reducing the likelihood of errors in typing commands manually. It speeds up the development process by offering real-time suggestions for model names, parameters, and variable commands, enabling users to focus on model logic and structure rather than syntax errors, thus improving productivity and accuracy in model building and simulation .

Plotting model results plays a crucial role in verifying the correctness of a Modelica simulation. Visualizing variables over time allows modelers to assess whether the simulation behaves as expected. It helps in identifying issues like anomalies or unexpected dynamics in the simulation output, facilitating debugging and model refinement. Consistently accurate plots matching theoretical or expected trends serve as indicators of model validity and robustness .

Using OpenModelica's Graphical Connection Editor (OMedit), one can simulate and plot Modelica models interactively. The user can build models graphically and simulate them directly within the editor. In OMedit, after constructing the model, it can be simulated using the simulate command. The simulation results can then be visualized by plotting the variables of interest through the plot command. OMNotebook and OMShell can also be used to save, load, and simulate models .

Changing the 'lambda' parameter in the VanDerPol model affects the model's behavior significantly. When 'lambda' is set to 10 and the model is simulated for 50 seconds, it shows an altered dynamical pattern than if 'lambda' were another value. This indicates that the model is quite sensitive to changes in its parameters, impacting the system's oscillatory dynamics and stability .

Incorporating a PI controller into a Modelica model provides the benefit of automated control over the rotational speed, enhancing the system's response to changing conditions. The PI controller aims to minimize the error between desired and actual speed by adjusting control inputs. However, challenges include correctly tuning the controller parameters to achieve desired performance without oscillations or instability. The right-click interface in OpenModelica helps in adjusting these parameters, but it requires careful tuning for optimal performance .

Using a step signal in a PI-controlled system introduces challenges like overshooting and transient oscillations due to abrupt changes. These can destabilize the system if not properly managed. Mitigation strategies include tuning PI controller parameters to dampen responses, thereby stabilizing the system after a step input. Adjusting these parameters in OpenModelica's right-click PI controller interface allows for fine-tuning that optimizes system response to step inputs .

In Modelica, specifying initial conditions using 'start' attributes directly influences solver behavior during DAE system initialization. The solver uses these conditions to estimate initial variable values, crucial for achieving system balance and consistent starting points. For fixed start values, the solver adheres strictly to them, whereas non-fixed values serve as initial guesses that the solver adjusts through algorithms like Newton's method to meet constraint equations, thus ensuring system initialization feasibility .

In Modelica, the 'start' attribute is used to specify initial conditions for model variables. In the DAE example, the start value of 'x' is fixed, meaning it is treated as a constant initial condition that does not change during initialization. In contrast, the start value of 'y' is not fixed, so it acts as a guess value. The simulator uses this guess value as a starting point for root-finding algorithms, potentially adjusting it to achieve consistent equations during initialization .

Hybrid modeling combines continuous dynamics with discrete transitions. The BouncingBall model exemplifies this by using when-equations to handle state transitions upon impact, which is not captured by continuous dynamics alone. The model switches between free-fall physics and a state change when the ball hits the ground. Adjustments to parameters and rerunning simulations help study the impact of these transitions on the system's behavior .

When developing a Modelica model of a DC motor, it is essential to ensure that all components, like the motor, torsional spring, and additional inertia, are correctly represented with accurate parameters. Adding a torsional spring and inertia influences the system's mechanical response, requiring parameter adjustments to reflect desired stiffness and inertial properties. This can be done by modifying parameters via the graphical interface. Simulating these adjustments helps verify the effects on system dynamics and ensure the model's realism and stability .

You might also like