You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/manual/manual/extensions/capd/index.rst
+3-206Lines changed: 3 additions & 206 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,210 +5,7 @@ CAPD (rigorous numerics in dynamical systems)
5
5
6
6
Main author: `Maël Godard <https://godardma.github.io>`_
7
7
8
-
This page describes how to use the CAPD library with Codac. CAPD is a C++ library for rigorous numerics in dynamical systems.
8
+
.. toctree::
9
9
10
-
To use CAPD with Codac, you first need to install the CAPD library. You can find the installation instructions on the `CAPD website <http://capd.ii.uj.edu.pl/html/capd_compilation.html>`_.
11
-
12
-
Note that as CAPD is a C++ only library, the content present in this page is **only available in C++**.
13
-
14
-
15
-
Installing the ``codac-capd`` extension
16
-
---------------------------------------
17
-
18
-
To install the ``codac-capd`` extension, you need to install the Codac library from its sources. This can be done :ref:`by using CMake <sec-install-cpp>` with the option ``WITH_CAPD=ON``. For example:
capd::Interval capd_interval = to_capd(codac_interval); // convert to CAPD interval
74
-
codac2::Interval codac_interval2 = to_codac(capd_interval); // convert back to Codac interval
75
-
76
-
77
-
Example
78
-
-------
79
-
80
-
.. image:: img/pendulum.png
81
-
:alt:State variables of the pendulum
82
-
:align:right
83
-
:width:130px
84
-
85
-
For this example we will consider the pendulum with friction.
86
-
87
-
The state variables of the pendulum are its angle :math:`\theta` and its angular velocity :math:`\omega`. The pendulum follows the following dynamic:
88
-
89
-
.. math::
90
-
91
-
\left(\begin{array}{c}
92
-
\dot{\theta}\\
93
-
\dot{\omega}
94
-
\end{array}\right)=\left(\begin{array}{c}
95
-
\omega\\
96
-
-\sin(\theta)\cdot\frac{g}{l}-0.5\omega
97
-
\end{array}\right),
98
-
99
-
100
-
where :math:`g` is the gravity constant and :math:`l` is the length of the pendulum.
101
-
102
-
This equation can be passed to the CAPD library as follows:
103
-
104
-
.. tabs::
105
-
106
-
.. group-tab:: C++
107
-
108
-
.. literalinclude:: src.cpp
109
-
:language: c++
110
-
:start-after: [codac-capd-2-beg]
111
-
:end-before: [codac-capd-2-end]
112
-
:dedent: 2
113
-
114
-
To solve this ODE, an ``IOdeSolver`` object is necessary.
115
-
116
-
.. tabs::
117
-
118
-
.. group-tab:: C++
119
-
120
-
.. literalinclude:: src.cpp
121
-
:language: c++
122
-
:start-after: [codac-capd-3-beg]
123
-
:end-before: [codac-capd-3-end]
124
-
:dedent: 2
125
-
126
-
CAPD then uses an ``ITimeMap`` to make the link between a time step and the solution of the ODE at this time. The ``I`` here stands for ``Interval`` as the solution is an interval guaranteed to enclose the solution. Here we will integrate the ODE between :math:`t_0=0s` and :math:`t_f=20s`.
127
-
128
-
.. tabs::
129
-
130
-
.. group-tab:: C++
131
-
132
-
.. literalinclude:: src.cpp
133
-
:language: c++
134
-
:start-after: [codac-capd-4-beg]
135
-
:end-before: [codac-capd-4-end]
136
-
:dedent: 2
137
-
138
-
To completly define the ODE, we need to define the initial conditions. Here we will set the initial angle to :math:`\theta_0=-\frac{\pi}{2}` and the
139
-
initial angular velocity to :math:`\omega_0=0`. For the purpose of this example, we will add a small uncertainty to the initial conditions. The initial conditions are then defined as follows:
140
-
141
-
.. tabs::
142
-
143
-
.. group-tab:: C++
144
-
145
-
.. literalinclude:: src.cpp
146
-
:language: c++
147
-
:start-after: [codac-capd-5-beg]
148
-
:end-before: [codac-capd-5-end]
149
-
:dedent: 2
150
-
151
-
There are then two ways to get the result of the integration depending on the use case.
152
-
153
-
If the desired result is the solution of the ODE at a given time (here say :math:`T=1s`), we can do as follows:
154
-
155
-
.. tabs::
156
-
157
-
.. group-tab:: C++
158
-
159
-
.. literalinclude:: src.cpp
160
-
:language: c++
161
-
:start-after: [codac-capd-6-beg]
162
-
:end-before: [codac-capd-6-end]
163
-
:dedent: 2
164
-
165
-
**Be careful, this method modifies the initial set** ``s`` **in place**.
166
-
167
-
If the desired result is the solution curve (or tube) of the ODE on the time domain :math:`[t_0,t_f]`, we can do as follows:
168
-
169
-
.. tabs::
170
-
171
-
.. group-tab:: C++
172
-
173
-
.. literalinclude:: src.cpp
174
-
:language: c++
175
-
:start-after: [codac-capd-7-beg]
176
-
:end-before: [codac-capd-7-end]
177
-
:dedent: 2
178
-
179
-
The variable ``solution`` is the desired solution curve (or tube). The operator ``solution(t)`` gives the solution at time :math:`t`.
180
-
It can be converted into a Codac ``SlicedTube<IntervalVector>`` with the function ``to_codac``. This functions takes two arguments:
181
-
182
-
- the ``capd::ITimeMap::SolutionCurve`` to convert.
183
-
- a ``codac2::TDomain`` object defining the temporal domain of the tube.
184
-
185
-
The resulting ``SlicedTube`` will have the same time domain as the one given in argument, completed with the CAPD gates. An example of conversion is :
186
-
187
-
.. tabs::
188
-
189
-
.. group-tab:: C++
190
-
191
-
.. literalinclude:: src.cpp
192
-
:language: c++
193
-
:start-after: [codac-capd-8-beg]
194
-
:end-before: [codac-capd-8-end]
195
-
:dedent: 2
196
-
197
-
A full display can be done with the following code:
198
-
199
-
.. tabs::
200
-
201
-
.. group-tab:: C++
202
-
203
-
.. literalinclude:: src.cpp
204
-
:language: c++
205
-
:start-after: [codac-capd-9-beg]
206
-
:end-before: [codac-capd-9-end]
207
-
:dedent: 4
208
-
209
-
The result is the following figure, with in green the initial set (:math:`t=0s`) and in red the final set (:math:`t=20s`). The ``SlicedTube`` is displayed in blue with a black edge for better visibility. The orange rectangles correspond to the gates (degenerate slices).
210
-
211
-
.. figure:: img/pendulum_result.png
212
-
:width:500px
213
-
214
-
Result of the CAPD integration of the pendulum, enclosed in a Codac tube.
0 commit comments