Skip to content

Commit

Permalink
Align comments in listings
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Nov 23, 2020
1 parent 4310626 commit 8b0b099
Showing 1 changed file with 51 additions and 52 deletions.
103 changes: 51 additions & 52 deletions chapters/synchronous.tex
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ \section{Clock Constructors}\label{clock-constructors}

\begin{example}
\begin{lstlisting}[language=modelica]
Clock c = Clock(angle > 0, 0.1) // before first tick of c:
// interval(c) = 0.1
Clock c = Clock(angle > 0, 0.1); // before first tick of c:
// interval(c) = 0.1
\end{lstlisting}
\end{example}

Expand All @@ -443,9 +443,9 @@ \section{Clock Constructors}\label{clock-constructors}

\begin{example}
\begin{lstlisting}[language=modelica]
Clock c1 = Clock(1, 10) // 100 ms, no solver
Clock c1 = Clock(1, 10); // 100 ms, no solver
Clock c2 = Clock(c1, "ImplicitTrapezoid"); // 100 ms, ImplicitTrapezoid solver
Clock c3 = Clock(c2, ""); // 100 ms, no solver
Clock c3 = Clock(c2, ""); // 100 ms, no solver
\end{lstlisting}
\end{example}
\end{semantics}
Expand Down Expand Up @@ -601,7 +601,7 @@ \subsection{Base-clock conversion operators}\label{base-clock-conversion-operato
Real y(start=1), yc;
equation
der(y) + y = 2;
yc = sample (y, Clock(0.1));
yc = sample(y, Clock(0.1));
initial equation
der(y) = 0;
\end{lstlisting}
Expand Down Expand Up @@ -679,7 +679,7 @@ \subsection{Sub-clock conversion operators}\label{sub-clock-conversion-operators
Clock u = Clock(x > 0);
Clock y1 = subSample(u, 4);
Clock y2 = superSample(y1, 2); // fine; y2 = subSample(u, 2)
Clock y3 = superSample(u, 2); // error
Clock y3 = superSample(u, 2); // error
Clock y4 = superSample(y1, 5); // error
\end{lstlisting}
\end{example}
Expand All @@ -703,14 +703,14 @@ \subsection{Sub-clock conversion operators}\label{sub-clock-conversion-operators
Note, due to the restriction of \lstinline!superSample! on event clocks, \lstinline!shiftSample! can only shift the number of ticks of the event clock, but cannot introduce new ticks. Example:
\begin{lstlisting}[language=modelica]
// Rational interval clock
Clock u = Clock(3, 10); // ticks: 0, 3/10, 6/10, ..
Clock y1 = shiftSample(u, 1, 3); // ticks: 1/10, 4/10,
...
Clock u = Clock(3, 10); // ticks: 0, 3/10, 6/10, ..
Clock y1 = shiftSample(u, 1, 3); // ticks: 1/10, 4/10,
$\ldots$
// Event clock
Clock u = Clock(sin(2 * pi * time) > 0, startInterval = 0.0)
// ticks: 0.0, 1.0, 2.0, 3.0, ...
Clock y1 = shiftSample(u, 2); // ticks: 2.0, 3.0, ...
Clock y2 = shiftSample(u, 2, 3); // error (resolution must be 1)
Clock u = Clock(sin(2 * pi * time) > 0, startInterval = 0.0);
// ticks: 0.0, 1.0, 2.0, 3.0, ...
Clock y1 = shiftSample(u, 2); // ticks: 2.0, 3.0, ...
Clock y2 = shiftSample(u, 2, 3); // error (resolution must be 1)
\end{lstlisting}
\end{nonnormative}
\end{semantics}
Expand All @@ -729,20 +729,20 @@ \subsection{Sub-clock conversion operators}\label{sub-clock-conversion-operators
\begin{lstlisting}[language=modelica]
// Rational interval clock 1

Clock u = Clock(3, 10); // ticks: 0, 3/10, 6/10, ..
Clock y1 = shiftSample(u, 3); // ticks: 9/10, 12/10, ..
Clock y2 = backSample(y1, 2); // ticks: 3/10, 6/10,
...
Clock y3 = backSample(y1, 4); // error (ticks before u)
Clock y4 = shiftSample(u, 2, 3); // ticks: 2/10, 5/10,
...
Clock y5 = backSample(y4, 1, 3); // ticks: 1/10, 4/10,
...
Clock u = Clock(3, 10); // ticks: 0, 3/10, 6/10, ..
Clock y1 = shiftSample(u, 3); // ticks: 9/10, 12/10, ..
Clock y2 = backSample(y1, 2); // ticks: 3/10, 6/10,
$\ldots$
Clock y3 = backSample(y1, 4); // error (ticks before u)
Clock y4 = shiftSample(u, 2, 3); // ticks: 2/10, 5/10,
$\ldots$
Clock y5 = backSample(y4, 1, 3); // ticks: 1/10, 4/10,
$\ldots$
// Event clock
Clock u = Clock(sin(2 * pi * time) > 0, startInterval=xx)
// ticks: 0, 1.0, 2.0, 3.0, ....
Clock y1 = shiftSample(u, 3); // ticks: 3.0, 4.0, ...
Clock y2 = backSample(y1, 2); // ticks: 1.0, 2.0, ...
Clock u = Clock(sin(2 * pi * time) > 0, startInterval = xx)
// ticks: 0, 1.0, 2.0, 3.0, ....
Clock y1 = shiftSample(u, 3); // ticks: 3.0, 4.0, ...
Clock y2 = backSample(y1, 2); // ticks: 1.0, 2.0, ...
\end{lstlisting}
\end{example}
\end{semantics}
Expand All @@ -762,7 +762,7 @@ \subsection{Sub-clock conversion operators}\label{sub-clock-conversion-operators

Let $a$ and $b$ be positive integers with $a < b$, and
\begin{lstlisting}[language=modelica]
yb = backSample (u, $a$, $b$)
yb = backSample(u, $a$, $b$)
ys = shiftSample(u, $b-a$, $b$)
\end{lstlisting}

Expand All @@ -787,7 +787,7 @@ \subsection{Sub-clock conversion operators}\label{sub-clock-conversion-operators
x = previous(x) + 0.1;
end when;
when clk2 then
y = noClock(x); // most recent value of x
y = noClock(x); // most recent value of x
z = sample(hold(x)); // left limit of x (infinitesimally delayed)!
end when;
end NoClockVsSampleHold;
Expand Down Expand Up @@ -928,20 +928,20 @@ \subsection{Base-clock Partitioning}\label{base-clock-partitioning}

After base clock partitioning, the following partitions are identified:
\begin{lstlisting}[language=modelica]
// Base partition 1 // clocked partition
ud1 = sample (y,c1); // incidence(e) = {ud1}
0 = f1(yd1, ud1, previous(ud1)); // incidence(e) = {yd1,ud1}
ud2 = superSample (yd1,2); // incidence(e) = {ud2, yd1}
0 = f2(yd2, ud2); // incidence(e) = {yd2, ud2}

// Base partition 2 // continuous-time partition
u = hold (yd2); // incidence(e) = {u}
0 = f3(der(x1), x1, u); // incidence(e) = {x1,u}
0 = f4(der(x2), x2, x1); // incidence(e) = {x2,x1}
0 = f6(y, x1, u); // incidence(e) = {y,x1,u}
// Base partition 1 -- clocked partition
ud1 = sample(y, c1); // incidence(e) = {ud1}
0 = f1(yd1, ud1, previous(ud1)); // incidence(e) = {yd1, ud1}
ud2 = superSample(yd1, 2); // incidence(e) = {ud2, yd1}
0 = f2(yd2, ud2); // incidence(e) = {yd2, ud2}

// Base partition 2 -- continuous-time partition
u = hold(yd2); // incidence(e) = {u}
0 = f3(der(x1), x1, u); // incidence(e) = {x1, u}
0 = f4(der(x2), x2, x1); // incidence(e) = {x2, x1}
0 = f6(y, x1, u); // incidence(e) = {y, x1, u}

// Identified as separate partition, but belonging to partition 2
0 = f5(der(x3), x3); // incidence(e) = {x3}
0 = f5(der(x3), x3); // incidence(e) = {x3}
\end{lstlisting}
\end{example}

Expand Down Expand Up @@ -980,15 +980,15 @@ \subsection{Sub-clock Partitioning}\label{sub-clock-partitioning}
\begin{lstlisting}[language=modelica]
// Base partition 1 (clocked partition)
// Sub-clock partition 1.1
ud1 = sample (y,c1); // incidence(e) = {ud1}
0 = f1(yd1,ud1,previous(yd1)); // incidence(e) = {yd1,ud1}
ud1 = sample(y, c1); // incidence(e) = {ud1}
0 = f1(yd1, ud1, previous(yd1)); // incidence(e) = {yd1,ud1}

// Sub-Clock partition 1.2
ud2 = superSample (yd1,2); // incidence(e) = {ud2}
0 = f2(yd2,ud2); // incidence(e) = {yd2,ud2}
ud2 = superSample(yd1, 2); // incidence(e) = {ud2}
0 = f2(yd2, ud2); // incidence(e) = {yd2,ud2}

// Base partition 2 (no sub-clock partitioning, since continuous-time)
u = hold (yd2);
u = hold(yd2);
0 = f3(der(x1), x1, u);
0 = f4(der(x2), x2, x1);
0 = f5(der(x3), x3);
Expand All @@ -1008,10 +1008,10 @@ \subsection{Sub-clock Inferencing}\label{sub-clock-inferencing}
It must be possible to determine that the constraint set is valid at compile time. However, in certain cases, it could be possible to defer providing actual numbers until run-time.
\end{nonnormative}

It is required that accumulated sub- and super sampling factors in the range of 1 to 2\textsuperscript{63} can be handled.
It is required that accumulated sub- and supersampling factors in the range of 1 to 2\textsuperscript{63} can be handled.

\begin{nonnormative}
64 bit internal representation of numerator and denominator with sign can be used and gives minimum resolution 1.08E-19 seconds and maximum range 9.22E+18 seconds = 2.92E+11 years.
64 bit internal representation of numerator and denominator with sign can be used and gives minimum resolution $1.08\times 10^{-19}$ seconds and maximum range $9.22\times 10^{18}$~seconds = $2.92\times 10^{11}$~years.
\end{nonnormative}

\section{Continuous-Time Equations in Clocked Partitions}\label{continuous-time-equations-in-clocked-partitions}
Expand Down Expand Up @@ -1220,16 +1220,16 @@ \subsection{Solver Methods}\label{solver-methods}
Assume the differential equation
\begin{lstlisting}[language=modelica]
input Real u;
Real x(start=1, fixed=true);
Real x(start = 1, fixed = true);
equation
der(x) = -x + u
\end{lstlisting}
shall be transformed to a clocked discretized continuous-time partition with the \lstinline!"ExplicitEuler"! method. The following model is a manual implementation:
\begin{lstlisting}[language=modelica]
input Real u;
parameter Real x_start = 1;
Real x(start=x_start); // previous(x) = x_start at first clock tick
Real der_x(start=0); // previous(der_x) = 0 at first clock tick
Real x(start = x_start); // previous(x) = x_start at first clock tick
Real der_x(start = 0); // previous(der_x) = 0 at first clock tick
protected
Boolean first(start=true);
equation
Expand All @@ -1240,8 +1240,7 @@ \subsection{Solver Methods}\label{solver-methods}
x = previous (x);
else
// second and further clock tick
x = previous (x) +
interval()*previous(der_x);
x = previous(x) + interval() * previous(der_x);
end if;
der_x = -x + u;
end when;
Expand Down

0 comments on commit 8b0b099

Please sign in to comment.