Skip to content

Commit a8dbe80

Browse files
committed
Working through Chapter 2 issues
When removing todo items I either fix them or at least add them as issues in GitHub.
1 parent 0afccd3 commit a8dbe80

File tree

6 files changed

+81
-46
lines changed

6 files changed

+81
-46
lines changed

text/source/behavior/discrete/bouncing.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,12 @@ following behavior from this model:
7878
.. plot:: ../plots/BB1.py
7979
:class: interactive
8080

81-
In this plot, we see that at around 0.48 seconds, the first impact with the
82-
surface occurs. This occurs because the condition ``h<0`` first becomes
83-
true at that moment. Note that what makes this a state event (unlike
84-
our example in :ref:`previous cooling examples <cooling-revisited>`) is the
85-
fact that this conditional expression references continuous variables
86-
other than ``time``.
87-
88-
.. todo:: link to previous cooling examples not showing up correctly
89-
do the referenced variables have to be continuous to make a state event?
81+
In this plot, we see that at around 0.48 seconds, the first impact
82+
with the surface occurs. This occurs because the condition ``h<0``
83+
first becomes true at that moment. Note that what makes this a state
84+
event (unlike our example in :ref:`previous cooling examples
85+
<cooling-revisited>`) is the fact that this conditional expression
86+
references variables other than ``time``.
9087

9188
As such, the simulation proceeds assuming the ball is in free fall
9289
until it identifies a solution trajectory where the value of the

text/source/behavior/discrete/decay.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ If we attempt to simulate this model for 5 seconds, we find that the
2222
simulation terminates after about 2 seconds with the following trajectory:
2323

2424
.. plot:: ../plots/Decay1.py
25-
:class: interactive
2625

2726
Again, numerical issues creep in. Even though mathematically it
2827
should not be possible for the value of ``x`` to drop below zero,
@@ -44,7 +43,6 @@ against evaluating the square root of a negative number, like this:
4443
Simulating this model we get the following trajectory [#tol]_:
4544

4645
.. plot:: ../plots/Decay2.py
47-
:class: interactive
4846

4947
Again, the simulation fails. But why? It fails for the same reason,
5048
a numerical exception that results from taking the square root of a
@@ -269,8 +267,6 @@ performance:
269267
.. plot:: ../plots/Decay5.py
270268
:class: interactive
271269

272-
.. todo:: Smooth operator?
273-
274270
.. [#tol] This model will not always fail. The failure depends on how
275271
much integration error is introduced and this, in turn,
276272
depends on the numerical tolerances used.

text/source/behavior/discrete/events.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,11 @@ should also be noted that even a simple variable assignment, *e.g.,*
5252
5353
can trigger an event to be generated.
5454

55-
.. todo::
56-
57-
Discuss smooth (and smoothOrder?)
58-
5955
Events and Functions
6056
^^^^^^^^^^^^^^^^^^^^
6157

6258
.. index:: ! sample
6359

64-
.. todo::
65-
66-
I Need to fill in this table more
67-
6860
In addition to being generated by conditional expressions, events can
6961
also be generated by certain functions in Modelica. The
7062
following is a list of functions and how they generate events:

text/source/behavior/discrete/hysteresis.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ simulation:
3131
.. plot:: ../plots/CC1_Q.py
3232
:class: interactive
3333

34-
.. todo:: the plot isn't showing this - it is just a solid blue background
35-
3634
What you see is that after around 0.2 seconds, the heater is
37-
constantly turning on and off. This is actually a real problem in
38-
control systems. If you look carefully at the way the furnace works
39-
in your own home, you will see that it does not turn on and off
40-
constantly as the temperature goes above and below the desired room
41-
temperature you have specified. Instead, it waits until the
42-
temperature gets some specified amount above or below the desired
43-
temperature before acting.
44-
45-
.. todo:: there seems to be a formatting problem around code{ChatteringControl}
35+
constantly turning on and off. This happens so frequently, in fact,
36+
that you would have to zoom in quite a bit on the plot to see the
37+
transitions. With normal scaling, there are so many transitions that
38+
the results resemble a filled rectangle.
39+
40+
This is actually a real problem in control systems. If you look
41+
carefully at the way the furnace works in your own home, you will see
42+
that it does not turn on and off constantly as the temperature goes
43+
above and below the desired room temperature you have specified.
44+
Instead, it waits until the temperature gets some specified amount
45+
above or below the desired temperature before acting.
4646

4747
This "band" that is introduced around the desired temperature is
48-
called hysteresis. The problem with the \code{ChatteringControl}
48+
called hysteresis. The problem with the ``ChatteringControl``
4949
model is that it doesn't have any hysteresis. Instead, it is
5050
constantly turning the heater off and on in response to miniscule
5151
changes in temperature.

text/source/behavior/discrete/measuring.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,15 @@ In this way, an ``algorithm`` section is very much like the way most
263263
programming languages work. The statements in the algorithm section
264264
are executed in order and each statement isn't interpreted as an
265265
equation, but rather as an assignment of an expression to a variable.
266-
The familiarity of assignment statements may make using ``algorithm`` sections attractive to people with a programming background who find the otherwise
267-
equation oriented aspects of Modelica disorienting and unfamiliar.
268-
But be aware that one big reason to avoid ``algorithm`` sections is because they interfere with the symbolic manipulation
266+
The familiarity of assignment statements may make using ``algorithm``
267+
sections attractive to people with a programming background who find
268+
the otherwise equation oriented aspects of Modelica disorienting and
269+
unfamiliar. But be aware that one big reason to avoid ``algorithm``
270+
sections is because they interfere with the symbolic manipulation
269271
performed by the Modelica compiler. This can result in both poor
270272
simulation performance and a loss of flexibility in how you compose
271-
your models.
272-
273-
.. todo:: what would be the alternative?
274-
note, reworded this because it sounded like it was saying familiarity with
275-
assignment statements is the reason to avoid them
273+
your models. So it is best to use an ``equation`` section whenever
274+
possible
276275

277276
In our case, there are no significant consequences to using the
278277
``algorithm`` section. Here is an example of how the previous

text/source/behavior/discrete/sampling.rst

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,66 @@ these lines one by one and discuss them. First we have:
8888
:language: modelica
8989
:lines: 5
9090

91-
.. todo::
91+
Note that we have done away with the ``0.1``. We no longer see any
92+
mention of the clock interval as a real number. Instead, we use the
93+
``Clock`` operator to the define clock interval for ``x`` as a
94+
rational number. This is important because it allows us to do exact
95+
comparisons between clocks. This brings us to the next line:
9296

93-
Finish this explanation after checking on the semantics of Clock
97+
.. literalinclude:: /ModelicaByExample/DiscreteBehavior/SynchronousSystems/SamplingWithClocks.mo
98+
:language: modelica
99+
:lines: 6
100+
101+
Again, we see the rational representation of the clock. What this
102+
means, in practice, is that the Modelica compiler can know for certain
103+
that these two clocks, ``x`` and ``y``, are identical because they are
104+
defined in terms of integer quantities which allow exact comparison.
105+
This means that when executing a simulation, we can know for certain
106+
that these two clocks will trigger simultaneously.
107+
108+
If we wanted to create a clock that was exactly two times slower than
109+
``x``, we can use the ``subSample`` operator to accomplish this. We
110+
see this in the definition of ``z``:
111+
112+
.. literalinclude:: /ModelicaByExample/DiscreteBehavior/SynchronousSystems/SamplingWithClocks.mo
113+
:language: modelica
114+
:lines: 7
115+
116+
Behind the scenes, the Modelica compiler can reason about these
117+
clocks. It knows that the ``x`` clock triggers every
118+
:math:`\frac{1}{10}` of a second. Using the information provided by
119+
the ``subSample`` operator the Modelica compiler can therefore deduce
120+
that ``z`` triggers every :math:`\frac{2}{10}` of a second.
121+
Conceptually, this means that ``z`` could also have been defined as:
122+
123+
.. code-block:: modelica
124+
125+
z = sample(time, Clock(2,10));
126+
127+
But by defining ``z`` using the ``subSample`` operator and defining it
128+
with respect to ``x`` we ensure that ``z`` is always triggering at
129+
half the frequency of ``x`` regardless of how ``x`` is defined.
130+
131+
In a similar way, we can define another clock, ``w`` that triggers 3 times more
132+
frequently than ``x`` by using the ``superSample`` operator:
133+
134+
.. literalinclude:: /ModelicaByExample/DiscreteBehavior/SynchronousSystems/SamplingWithClocks.mo
135+
:language: modelica
136+
:lines: 8
137+
138+
Again, we could have defined ``w`` directly using ``sample`` with:
139+
140+
.. code-block:: modelica
94141
142+
w = sample(time, Clock(1,30));
95143
96-
.. todo::
144+
But by using ``superSample``, we can ensure that ``w`` is always
145+
sampling three times faster than ``x`` and six times faster than ``z``
146+
(since ``z`` is also defined with respect to ``x``).
97147

98-
Cite Hilding's paper for detailed discussion of synchronous
99-
features.
148+
The synchronous clock features in Modelica are relatively new. To
149+
learn more about these synchronous features and their applications see
150+
[Elmqvist]_ and/or the Modelica Specification, version 3.3 or later.
100151

101152
.. [Elmqvist] "Fundamentals of Synchronous Control in Modelica",
102153
Hilding Elmqvist, Martin Otter and Sven-Erik Mattsson

0 commit comments

Comments
 (0)