1OneStepNSProblem formalisation for several interactions
2=======================================================
3
4rst file generated from devNotes (tex). Should be reviewed.
5Uncomment DevNotes.rst to check outputs.
6
7..
8
9   +-----------+----------------+
10   | author    | F. Pérignon    |
11   +===========+================+
12   | date      | May 16, 2006   |
13   +-----------+----------------+
14   | version   | ?              |
15   +-----------+----------------+
16
17LinearDS - Linear Time Invariant Relations
18------------------------------------------
19
20   ..
21      General notations
22      ~~~~~~~~~~~~~~~~~
23
24      We consider :math:`n` dynamical systems of the form:
25
26      .. math::
27
28	 \dot x_i = A_i x_i + R_i
29
30      | Each system if of dimension :math:`n_i`, and we denote
31      :math:`N = \displaystyle{\sum_{i=1}^{n} n_i}`.
32      | An interaction, :math:`I_{\alpha}` is composed with a non smooth law,
33      :math:`nslaw_{\alpha}` and a relation:
34
35      .. math::
36
37	 y_{\alpha} = C_{\alpha}X_{\alpha} + D_{\alpha}\lambda_{\alpha}
38
39      | The “dimension” of the interaction, ie the size of vector
40      :math:`y_{\alpha}`, is denoted :math:`m_{\alpha}` and we set:
41
42      .. math::
43
44	 M = \sum_{\alpha=1}^{m} m_{\alpha}
45
46      :math:`m` being the number of interactions in the Non Smooth Dynamical
47      System.
48      | :math:`X_{\alpha}` is a vector that represents the DS concerned by the
49      interaction. Its dimension is noted :math:`N_{\alpha}`, this for
50      :math:`n_{\alpha}` systems in the interaction.
51      | :math:`C_{\alpha}` is a :math:`m_{\alpha} \times N_{\alpha}`
52      row-blocks matrix and :math:`D_{\alpha}` a
53      :math:`m_{\alpha} \times m_{\alpha}` square matrix.
54
55      .. math::
56
57	 C_{\alpha}=\left[\begin{array}{ccc}
58	 C_{\alpha}^i & C_{\alpha}^j & ...\end{array}\right]
59
60      | with :math:`i,j,...\in \mathcal{DS}_{\alpha}` which is the set of DS
61      belonging to interaction :math:`\alpha`.
62      | We also have the following relation:
63
64      .. math::
65
66	 \left[\begin{array}{c}
67	 R_{\alpha}^i \\
68	 R_{\alpha}^j \\
69	 ...
70	 \end{array}\right] = B_{\alpha}\lambda_{\alpha}
71	 =\left[\begin{array}{c}
72	 B_{\alpha}^i \\
73	 B_{\alpha}^j \\
74	 ...
75	 \end{array}\right]\lambda_{\alpha}
76
77      | :math:`R_{\alpha}^i` represents the contribution of interaction
78      :math:`\alpha` on the reaction of the dynamical system :math:`i`, and
79      :math:`B_{\alpha}^i` is a :math:`n_i \times m_{\alpha}` block matrix.
80      | And so:
81
82      .. math::
83
84	 R_i = \sum_{\beta\in\mathcal{I}_i}R_{\beta}^i=\sum_{\beta\in\mathcal{I}_i}B^i_{\beta} \lambda_{\beta}
85
86      | with :math:`\mathcal{I}_i` the set of interactions in which dynamical
87      system number :math:`i` is involved.
88      | Introducing the time discretization, we get:
89
90      .. math::
91
92	 \begin{aligned}
93	 x_i^{k+1}-x_i^k = h A_i x_i^{k+1} + h R_i^{k+1}  \\
94	 \nonumber\\
95	 y_{\alpha}^{k+1} = C_{\alpha}X_{\alpha}^{k+1} + D_{\alpha}\lambda_{\alpha}^{k+1}\\
96	 \nonumber\\
97	 R_i^{k+1} = \sum_{\beta\in\mathcal{I}_i}B^i_{\beta} \lambda_{\beta}^{k+1}\end{aligned}
98
99      ie, with :math:`W_i = (I-h A_i)^{-1}`:
100
101      .. math::
102
103	 \begin{aligned}
104	 x_i^{k+1}&=& W_i x_i^{k} + hW_i R_i^{k+1}  \\
105	 \nonumber\\
106	 y_{\alpha}^{k+1} &=& C_{\alpha}W_{\alpha} X_{\alpha}^{k} + C_{\alpha}hW_{\alpha}\sum_{\beta\in\mathcal{I}_i}B^i_{\beta} \lambda_{\beta}^{k+1} + D_{\alpha}\lambda_{\alpha}^{k+1} \\
107	 &=& C_{\alpha}W_{\alpha} X_{\alpha}^{k} + (C_{\alpha}hW_{\alpha}B_{\alpha} + D_{\alpha}) \lambda_{\alpha}^{k+1} + \sum_{\beta\neq\alpha}(\sum_{i\in\mathcal{DS}_{\alpha}\cap\in\mathcal{DS}_{\beta}} hC_{\alpha}^iW_i B^i_{\beta} \lambda_{\beta}^{k+1})\end{aligned}
108
109      with
110
111      .. math::
112
113	 \label{Walpha}
114	 W_{\alpha}=\left[\begin{array}{ccc}
115	 W_i &  0   & ... \\
116	 0   &  W_j & ...\\
117	 0  & ... & ... \\
118	 \end{array}\right]
119
120      | the block-diagonal matrix of all the :math:`W` for the dynamical
121      systems involved in interaction :math:`\alpha`.
122      | The global-assembled :math:`Y` vector, of dimension M, composed by
123      :math:`m` :math:`y_{\alpha}` subvectors, is given by:
124
125      .. math::
126
127	 \begin{aligned}
128	 Y_{k+1} = q_{OSNSP} + M_{OSNSP}\Lambda_{k+1}\end{aligned}
129
130      or,
131
132      .. math::
133
134	 \begin{aligned}
135	 Y_{k+1} =\left[\begin{array}{c}
136	 y_1 \\
137	 ...  \\
138	 y_m
139	 \end{array}\right]_{k+1}
140	 &=&\left[\begin{array}{ccc}
141	 C_1^1 & \ldots & C_1^n \\
142	 \vdots & \ldots & \vdots \\
143	 C_m^1 & \ldots & C_m^n
144	 \end{array}\right]\left[\begin{array}{cccc}
145	 W_1 & 0 & \ldots &0 \\
146	 0  & W_2 & \ddots & \vdots \\
147	 \vdots &\ddots  & \ddots & \vdots \\
148	 &&0& W_n
149	 \end{array}\right]
150	 \left[\begin{array}{c}
151	 x_1  \\
152	 \vdots \\
153	 \vdots \\
154	 x_n
155	 \end{array}\right]_k \\
156	 &+&\left[\begin{array}{cccc}
157	 D_1+h\sum_{j\in \mathcal{DS}_1}C_1^jW_jB_1^j & h\displaystyle{\sum_{j\in \mathcal{DS}_1\cap\mathcal{DS}_2}C_1^jW_jB_2^j} & \ldots &\\
158	 \vdots&\ddots& &\\
159	 & h\displaystyle{\sum_{j\in \mathcal{DS}_m}C_m^jW_jB_{m-1}^j}  & D_m+h\displaystyle{\sum_{j\in \mathcal{DS}_m\cap\mathcal{DS}_{m-1}}C_m^jW_jB_m^j} \\
160	 \end{array}\right]\left[\begin{array}{c}
161	 \lambda_1  \\
162	 \vdots \\
163	 \lambda_m
164	 \end{array}\right]_{k+1} \nonumber\end{aligned}
165
166      To sum it up, the block-diagonal term of matrix :math:`M_{OSNSP}`, for
167      block-row :math:`\alpha` is:
168
169      .. math::
170
171	 D_{\alpha}+h\sum_{j\in \mathcal{DS}_{\alpha}}C_{\alpha}^jW_jB_{\alpha}^j
172
173      This is an :math:`m_{\alpha}\times m_{\alpha}` square matrix. The
174      extra-diagonal block term, in position (:math:`\alpha,\beta`) is:
175
176      .. math::
177
178	 h\sum_{j\in \mathcal{DS}_{\alpha}\cap\mathcal{DS}_{\beta}}C_{\alpha}^jW_jB_{\beta}^j
179
180      | and is a :math:`m_{\alpha}\times m_{\beta}` matrix. This matrix
181      differs from 0 when interactions :math:`\alpha` and :math:`\beta` are
182      coupled, ie have common DS.
183
184      Or, for the relation l of interaction :math:`\alpha`, we get:
185
186      .. math::
187
188	 D_{\alpha,l}+h\sum_{j\in \mathcal{DS}_{\alpha}}C_{\alpha,l}^jW_jB_{\alpha}^j
189
190      for the diagonal, and
191
192      .. math::
193
194	 h\sum_{j\in \mathcal{DS}_{\alpha}\cap\mathcal{DS}_{\beta}}C_{\alpha,l}^jW_jB_{\beta}^j
195
196      | for extra-diagonal terms.
197      | :math:`D_{\alpha,l}`, row number :math:`l` of :math:`D_{\alpha}`, the
198      same for :math:`C_{\alpha,l}`
199
200      Finally, the linked-Interaction map provides, for each interaction
201      (named “current interaction”), the list of all the interactions (named
202      “linked interaction”) that have common dynamical system with the
203      “current interaction”.
204
205      A simple example
206      ~~~~~~~~~~~~~~~~
207
208      We consider :math:`n=3` dynamical systems and :math:`m=2` interactions:
209
210      .. math::
211
212	 \begin{aligned}
213	 I_{\mu}& \rightarrow& \mathcal{DS}_{\mu} = \{DS_1, DS_3\}, m_{\mu} = 3 \\
214	 I_{\theta}&\rightarrow& \mathcal{DS}_{\theta} = \{DS_2, DS_3\}, m_{\theta} = 1  \\\end{aligned}
215
216      The linked-interaction map is :
217
218      .. math::
219
220	 \begin{aligned}
221	 I_{\mu} &\rightarrow& I_{\theta}, commonDS = DS_3 \\
222	 I_{\theta} &\rightarrow&I_{\mu}, commonDS = DS_3 \\\end{aligned}
223
224      And:
225
226      .. math::
227
228	 \begin{aligned}
229	 M &=& 4, N = \displaystyle{\sum_{i=1}^{3} n_i} \\
230	 \mathcal{I}_1 &=& \{I_{\mu} \}\\
231	 \mathcal{I}_2 &=& \{I_{\theta}\} \\
232	 \mathcal{I}_3 &=& \{I_{\mu}, I_{\theta}\} \\\end{aligned}
233
234      .. math::
235
236	 \begin{aligned}
237	 y_1 = \left[\begin{array}{ccc}
238	 C_1^1 & C_1^3 \end{array}\right]
239	 \left[\begin{array}{c}
240	 x_1 \\
241	 x_3
242	 \end{array}\right]
243	 + D_1\lambda_1 \\
244	 y_2 = \left[\begin{array}{ccc}
245	 C_2^2 & C_2^3 \end{array}\right]
246	 \left[\begin{array}{c}
247	 x_2 \\
248	 x_3
249	 \end{array}\right]
250	 + D_2\lambda_2 \end{aligned}
251
252      .. math::
253
254	 \begin{aligned}
255	 \left[\begin{array}{c}
256	 R_1 \\
257	 R_2 \\
258	 R_3 \end{array}\right]=
259	 \left[\begin{array}{c}
260	 B_1^1\lambda_1  \\
261	 B_2^2\lambda_2  \\
262	 B_1^3\lambda_1 + B_2^3\lambda_2
263	 \end{array}\right]\end{aligned}
264
265      .. math::
266
267	 \begin{aligned}
268	 M_{OSNSP} &=& \left[\begin{array}{cc}
269	 D_1+hC_1^1W_1B_1^1+hC_1^3W_3B_1^3 & hC_1^3W_3B_2^3 \\
270	 hC_2^3W_3B_1^3 & D_2+hC_2^2W_2B_2^2+hC_2^3W_3B_2^3
271	 \end{array}\right]\left[\begin{array}{c}
272	 \lambda_1  \\
273	 \lambda_2
274	 \end{array}\right]_{k+1} \end{aligned}
275
276      relative degree
277      ~~~~~~~~~~~~~~~
278
279      Let us consider the global vector
280
281      .. math::
282
283	 \begin{aligned}
284	 Y =\left[\begin{array}{c}
285	 y_1 \\
286	 ...  \\
287	 y_M
288	 \end{array}\right] = CX + D\Lambda\end{aligned}
289
290      We denote by :math:`r_j` the relative degree of equation :math:`j`,
291      :math:`j\in [1..M]`. We have:
292
293      .. math::
294
295	 \begin{aligned}
296	 y_j = \displaystyle{\sum_{i=1}^n C_j^i x_i +D_{j,j}\lambda_j + \sum_{i\neq j, i=1}^m D_{j,i} \lambda_i } \end{aligned}
297
298      | :math:`D_{j,i}` a scalar and :math:`C_j^i` a :math:`1 \times n_i`
299      line-vector.
300      | If :math:`D_{jj} \neq 0`, then :math:`r_j=0`. Else, we should consider
301      the first derivative of :math:`y_j`.
302      | Before that, recall that:
303
304      .. math::
305
306	 \begin{aligned}
307	 R_i = \displaystyle{\sum_{k=1}^M B_k^i \lambda_j}\end{aligned}
308
309      | Through many of the :math:`B_j^i` are equal to zero, we keep them all
310      in the following lines.
311      | Then:
312
313      .. math::
314
315	 \begin{aligned}
316	 \dot y_j &=& \displaystyle{\sum_{i=1}^n C_j^i (A_i x_i +  \sum_{k=1}^M B_k^i \lambda_k  ) + f(\lambda_k)_{k\neq j}} \\
317	 &=& \displaystyle{\sum_{i=1}^n C_j^i (A_i x_i + B_j^i \lambda_j + \sum_{k=1,k\neq j}^M B_k^i \lambda_k  ) + \ldots}\end{aligned}
318
319      | So, if :math:`\displaystyle{\sum_{i=1}^n C_j^i B_j^i} \neq 0` (note
320      that this corresponds to the product between line :math:`j` of :math:`C`
321      and column :math:`j` of :math:`B`) then :math:`r_j=1` else we consider
322      the next derivative, and so on.
323      | In derivative :math:`r`, the coefficient of :math:`\lambda_j` will be:
324
325      .. math::
326
327	 \begin{aligned}
328	 coeff_j&=& \displaystyle{\sum_{i=1}^n C_j^i (A_i)^{r-1} B_j^i }\end{aligned}
329
330      if :math:`coeff_j\neq 0` then :math:`r_j = r`.
331
332      LagrangianDS - Lagrangian Linear Relations
333      ------------------------------------------
334
335      General notations
336      ~~~~~~~~~~~~~~~~~
337
338      We consider :math:`n` dynamical systems, lagrangian and non linear, of
339      the form:
340
341      .. math::
342
343	 M_i(q_i) \ddot q_i + N_i(\dot q_i, q_i) = F_{Int,i}(\dot q_i , q_i , t)+F_{Ext,i}(t) + p_i
344
345      | Each system if of dimension :math:`n_i`, and we denote
346      :math:`N = \displaystyle{\sum_{i=1}^{n} n_i}`.
347      | An interaction, :math:`I_{\alpha}` is composed with a non smooth law,
348      :math:`nslaw_{\alpha}` and a relation:
349
350      .. math::
351
352	 y_{\alpha} = H_{\alpha}Q_{\alpha} + b_{\alpha}
353
354      | The “dimension” of the interaction, ie the size of vector
355      :math:`y_{\alpha}`, is denoted :math:`m_{\alpha}` and we set:
356
357      .. math::
358
359	 M_y = \sum_{\alpha=1}^{m} m_{\alpha}
360
361      :math:`m` being the number of interactions in the Non Smooth Dynamical
362      System.
363      | :math:`Q_{\alpha}` is a vector that represents the DS concerned by the
364      interaction. Its dimension is noted :math:`N_{\alpha}`, this for
365      :math:`n_{\alpha}` systems in the interaction.
366      | :math:`H_{\alpha}` is a :math:`m_{\alpha} \times N_{\alpha}`
367      row-blocks matrix and :math:`b_{\alpha}` a :math:`m_{\alpha}` vector.
368
369      .. math::
370
371	 H_{\alpha}=\left[\begin{array}{ccc}
372	 H_{\alpha}^i & H_{\alpha}^j & ...\end{array}\right]
373
374      | with :math:`i,j,...\in \mathcal{DS}_{\alpha}` which is the set of DS
375      belonging to interaction :math:`\alpha`.
376      | We also have the following relation:
377
378      .. math::
379
380	 \left[\begin{array}{c}
381	 R_{\alpha}^i \\
382	 R_{\alpha}^j \\
383	 ...
384	 \end{array}\right] = {}^tH_{\alpha}\lambda_{\alpha}
385	 =\left[\begin{array}{c}
386	 {}^tH_{\alpha}^i \\
387	 {}^tH_{\alpha}^j \\
388	 ...
389	 \end{array}\right]\lambda_{\alpha}
390
391      | :math:`R_{\alpha}^i` represents the contribution of interaction
392      :math:`\alpha` on the reaction of the dynamical system :math:`i`, and
393      :math:`{}tH_{\alpha}^i` is a :math:`n_i \times m_{\alpha}` block matrix.
394      | And so:
395
396      .. math:: R_i = \sum_{\beta\in\mathcal{I}_i}R_{\beta}^i=\sum_{\beta\in\mathcal{I}_i}{}H^i_{\beta} \lambda_{\beta}
397
398      | with :math:`\mathcal{I}_i` the set of interactions in which dynamical
399      system number :math:`i` is involved.
400      | Introducing the time dicretisation, we get:
401
402      .. math::
403
404	 \begin{aligned}
405	 \dot q_i^{k+1} = \dot q_{free,i} + W_iR_i^{k+1}
406	 \nonumber\\
407	 \dot y_{\alpha}^{k+1} = H_{\alpha}\dot Q_{\alpha}^{k+1} \\
408	 \nonumber\\
409	 R_i^{k+1} = \sum_{\beta\in\mathcal{I}_i}H^i_{\beta} \lambda_{\beta}^{k+1}\end{aligned}
410
411      ie,
412
413      .. math::
414
415	 \begin{aligned}
416	   y_{\alpha}^{k+1} &=& H_{\alpha} Q_{\alpha}^{free} + H_{\alpha}W_{\alpha}{}^tH_{\alpha}\lambda_{\alpha}+\sum_{i\in \mathcal{DS}_{\alpha}}\sum_{\beta\in\mathcal{I}_i,\alpha\neq\beta}H_{\alpha}^iW_iH_{\beta}^j\lambda_{\beta}\end{aligned}
417
418      with :math:`W_{\alpha}` given by .
419
420      The global-assembled :math:`Y` vector, of dimension M, composed by
421      :math:`m` :math:`y_{\alpha}` subvectors, is given by:
422
423      .. math::
424
425	 \begin{aligned}
426	 Y_{k+1} = q_{OSNSP} + M_{OSNSP}\Lambda_{k+1}\end{aligned}
427
428      with:
429
430      .. math::
431
432	 \begin{aligned}
433	 q_{OSNSP}^{\alpha} = H_{\alpha} Q_{\alpha}^{free}\end{aligned}
434
435      and for :math:`M_{OSNSP}`, the block-diagonal term for block-row
436      :math:`\alpha` is
437
438      .. math::
439
440	 \sum_{j\in \mathcal{DS}_{\alpha}}H_{\alpha}^jW_j{}^tH_{\alpha}^j
441
442      an :math:`m_{\alpha}\times m_{\alpha}` square matrix. The extra-diagonal
443      block term, in position (:math:`\alpha,\beta`) is:
444
445      .. math::
446
447	 \sum_{j\in \mathcal{DS}_{\alpha}\cap\mathcal{DS}_{\beta}}H_{\alpha}^jW_j{}^tH_{\beta}^j
448
449      | and is a :math:`m_{\alpha}\times m_{\beta}` matrix. This matrix
450      differs from 0 when interactions :math:`\alpha` and :math:`\beta` are
451      coupled, ie have common DS.
452
453      Or, for the relation l of interaction :math:`\alpha`, we get:
454
455      .. math::
456
457	 \sum_{j\in \mathcal{DS}_{\alpha}}H_{\alpha,l}^jW_j{}^tH_{\alpha}^j
458
459      for the diagonal, and
460
461      .. math::
462
463	 \sum_{j\in \mathcal{DS}_{\alpha}\cap\mathcal{DS}_{\beta}}H_{\alpha,l}^jW_j{}^tH_{\beta}^j
464
465      | for extra-diagonal terms.
466      | :math:`H_{\alpha,l}`, row number :math:`l` of :math:`H_{\alpha}`.
467
468      WARNING: depending on linear and non linear case for the DS, there
469      should be a factor h ahead W. See Bouncing Ball template.
470
471      Block matrix approach
472      ---------------------
473
474      The built of the OSNSProblem matrix could be computed using block matrix
475      structure. This section describe these matrices. It is not implemented
476      in Siconos. Using previous notations, :math:`n` is the number of DS.
477      :math:`m` the number of interations.
478
479      Block matrix of DS
480      ~~~~~~~~~~~~~~~~~~
481
482      .. math::
483
484	 \boldsymbol{M}  \boldsymbol{\dot X}=\boldsymbol{A} \boldsymbol{X} + \boldsymbol{R}
485
486      where :math:`\boldsymbol{M}=diag(M_1,...M_n)` and
487      :math:`\boldsymbol{A}=diag(A_1,..,A_n)`.
488
489      .. math::
490
491	 \boldsymbol{R}=\boldsymbol{B}\boldsymbol{\lambda}
492
493      .. math::
494
495	 \boldsymbol{B}=\left( \begin{array} {c} B^1_{1}...B^1_m\\.\\.\\
496	     B^n_1...B^n_m  \end{array}\right)
497
498       Some of :math:`B^i_j` doesn’t exist.
499
500      Block matrix of interaction
501      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
502
503      .. math::
504
505	 \boldsymbol{Y}= \boldsymbol{C}  \boldsymbol{X}+
506	 \boldsymbol{D} \boldsymbol{\lambda}
507
508      with :math:` \boldsymbol{D}=diag(D_1..D_m)` and
509
510      .. math::
511
512	 \boldsymbol{C}=\left( \begin{array} {c}
513	     C^1_{1}..C^n_1\\.\\.\\C^1_{m}...C^n_{m} \end{array}\right)
514
515       Some of :math:`C^i_j` doesn’t exist.
516
517      OSNSProblem using block matrices
518      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
519
520      The Matrix of the OSNS Problem could be assembled using the following
521      block-product-matrices
522      :math:`\boldsymbol{C}\boldsymbol{W}\boldsymbol{B}`.
523
524      Dynamical Systems formulations in Siconos.
525      ==========================================
526
527      +-----------+------------------+
528      | author    | F. Pérignon      |
529      +===========+==================+
530      | date      | March 22, 2006   |
531      +-----------+------------------+
532      | version   | Kernel 1.1.4     |
533      +-----------+------------------+
534
535      Class Diagram
536      -------------
537
538      There are four possible formulation for dynamical systems in Siconos,
539      two for first order systems and two for second order Lagrangian systems.
540      The main class is DynamicalSystem, all other derived from this one, as
541      shown in the following diagram:
542
543      |image| [DSDiagram]
544
545      General non linear first order dynamical systems
546      :math:`\rightarrow` class *DynamicalSystem*
547      ------------------------------------------------
548
549      | This is the top class for dynamical systems. All other systems classes
550      derived from this one.
551
552      A general dynamical systems is described by the following set of
553      :math:`n` equations, completed with initial conditions:
554
555      .. math::
556
557	 \begin{aligned}
558	   \dot x &=& f(x,t) + T(x) u(x, \dot x, t) + r \\
559	   x(t_0)&=&x_0 \end{aligned}
560
561      -  :math:`x`: state of the system - Vector of size :math:`n`.
562
563      -  :math:`f(x,t)`: vector field - Vector of size :math:`n`.
564
565      -  :math:`u(x, \dot x, t)`: control term - Vector of size :math:`uSize`.
566
567      -  :math:`T(x)`: :math:`n\times uSize` matrix, related to control term.
568
569      -  :math:`r`: input due to non-smooth behavior - Vector of size
570	 :math:`n`.
571
572      | The Jacobian matrix, :math:`\nabla_x f(x,t)`, of :math:`f` according
573      to :math:`x`, :math:`n\times n` square matrix, is also a member of the
574      class.
575
576      | Initial conditions are given by the member :math:`x_0`, vector of size
577      :math:`n`. This corresponds to x value when simulation is starting, ie
578      after a call to strategy->initialize().
579
580      There are plug-in functions in this class for :math:`f` (vectorField),
581      :math:`jacobianX`, :math:`u` and :math:`T`. All of them can handle a
582      vector of user-defined parameters.
583
584      First order linear dynamical systems :math:`\rightarrow` class *LinearDS*
585      -------------------------------------------------------------------------
586
587      Derived from DynamicalSystem, described by the set of :math:`n`
588      equations and initial conditions:
589
590      .. math::
591
592	 \begin{aligned}
593	   \dot x &=& A(t)x(t)+Tu(t)+b(t)+r \\
594	   x(t_0)&=&x_0 \end{aligned}
595
596      With:
597
598      -  :math:`A(t)`: :math:`n\times n` matrix, state independent but
599	 possibly time-dependent.
600
601      -  :math:`b(t)`: Vector of size :math:`n`, possibly time-dependent.
602
603      | Other variables are those of DynamicalSystem class.
604      | :math:`A` and :math:`B` have corresponding plug-in functions.
605
606      | Warning: time dependence for :math:`A` and :math:`b` is not available
607      at the time in the simulation part for this kind of dynamical systems.
608
609      Links with vectorField and its Jacobian are:
610
611      .. math::
612
613	 \begin{aligned}
614	   f(x,t) &=& A(t)x(t)+b(t) \\
615	   jacobianX&=&\nabla_x f(x,t) = A(t) \end{aligned}
616
617      Second order non linear Lagrangian dynamical systems
618      :math:`\rightarrow` class *LagrangianDS*
619      ----------------------------------------------------
620
621      Lagrangian second order non linear systems are described by the
622      following set of\ :math:`nDof` equations + initial conditions:
623
624      .. math::
625
626	 \begin{aligned}
627	  M(q) \ddot q + NNL(\dot q, q) + F_{Int}(\dot q , q , t) &=& F_{Ext}(t) + p \\
628	  q(t_0) &=& q0 \\
629	  \dot q(t_0) &=& velocity0 \end{aligned}
630
631      With:
632
633      -  :math:`M(q)`: :math:`nDof\times nDof` matrix of inertia.
634
635      -  :math:`q`: state of the system - Vector of size :math:`nDof`.
636
637      -  :math:`\dot q` or :math:`velocity`: derivative of the state according
638	 to time - Vector of size :math:`nDof`.
639
640      -  :math:`NNL(\dot q, q)`: non linear terms, time-independent - Vector
641	 of size :math:`nDof`.
642
643      -  :math:`F_{Int}(\dot q , q , t)`: time-dependent linear terms - Vector
644	 of size :math:`nDof`.
645
646      -  :math:`F_{Ext}(t)`: external forces, time-dependent BUT do not depend
647	 on state - Vector of size :math:`nDof`.
648
649      -  :math:`p`: input due to non-smooth behavior - Vector of size
650	 :math:`nDof`.
651
652      The following Jacobian are also member of this class:
653
654      -  jacobianQFInt = :math:`\nabla_q F_{Int}(t,q,\dot q)` -
655	 :math:`nDof\times nDof` matrix.
656
657      -  jacobianVelocityFInt = :math:`\nabla_{\dot q} F_{Int}(t,q,\dot q)` -
658	 :math:`nDof\times nDof` matrix.
659
660      -  jacobianQNNL = :math:`\nabla_q NNL(q,\dot q)` -
661	 :math:`nDof\times nDof` matrix.
662
663      -  jacobianVelocityNNL = :math:`\nabla_{\dot q}NNL(q,\dot q)` -
664	 :math:`nDof\times nDof` matrix.
665
666      | There are plug-in functions in this class for :math:`F_{int}`,
667      :math:`F_{Ext}`, :math:`M`, :math:`NNL` and the four Jacobian matrices.
668      All of them can handle a vector of user-defined parameters.
669
670      Links with first order dynamical system are:
671
672      .. math::
673
674	 \begin{aligned}
675	   n &= &2nDof \\
676	   x &=&\left[\begin{array}{c}q \\ \dot q \end{array}\right] \\
677	   f(x,t) &=&  \left[\begin{array}{c} \dot q \\ M^{-1}(F_{Ext}-F_{Int}-NNL) \end{array}\right] \\
678	   \\
679	   \nabla_x f(x,t) &=&
680	   \left[\begin{array}{cc}
681	       0_{nDof\times nDof} & I_{nDof\times nDof} \\
682	       \nabla_q(M^{-1})(F_{Ext}-F_{Int}-NNL) -M^{-1}\nabla_q(F_{Int}+NNL) &  -M^{-1}\nabla_{\dot q}(F_{Int}+NNL)
683	     \end{array}\right] \\
684	   r &=& \left[\begin{array}{c} 0_{nDof} \\ p \end{array}\right] \\
685	   u(x,\dot x,t) &=& u_L(\dot q, q, t) \text{  (not yet implemented)} \\
686	   T(x) &=& \left[\begin{array}{c} 0_{nDof} \\ T_L(q) \end{array}\right] \text{  (not yet implemented)} \\\end{aligned}
687
688      | With :math:`0_{n}` a vector of zero of size :math:`n`,
689      :math:`0_{n\times m}` a :math:`n\times m` zero matrix and
690      :math:`I_{n\times n}`, identity :math:`n\times n` matrix.
691
692      Warning: control terms (:math:`Tu`) are not fully implemented in
693      Lagrangian systems. This will be part of future version.
694
695      Second order linear and time-invariant Lagrangian dynamical systems :math:`\rightarrow` class *LagrangianLinearTIDS*
696      --------------------------------------------------------------------------------------------------------------------
697
698      .. math::
699
700	 \begin{aligned}
701	 M \ddot q + C \dot q + K q =  F_{Ext}(t) + p\end{aligned}
702
703      With:
704
705      -  :math:`C`: constant viscosity :math:`nDof\times nDof` matrix
706
707      -  :math:`K`: constant rigidity :math:`nDof\times nDof` matrix
708
709      And:
710
711      .. math::
712
713	 \begin{aligned}
714	 F_{Int} &=& C \dot q + K q \\
715	 NNL &=& 0_{nDof} \end{aligned}
716
717      Dynamical Systems implementation in Siconos.
718      ============================================
719
720      +-----------+--------------------+
721      | author    | F. Pérignon        |
722      +===========+====================+
723      | date      | November 7, 2006   |
724      +-----------+--------------------+
725      | version   | Kernel 1.3.0       |
726      +-----------+--------------------+
727
728      Introduction
729      ------------
730
731      | This document is only a sequel of notes and remarks on the way
732      Dynamical Systems are implemented in Siconos.
733      | It has to be completed, reviewed, reorganized etc etc for a future
734      Developpers’Guide.
735      | See also documentation in Doc/User/DynamicalSystemsInSiconos for a
736      description of various dynamical systems types.
737
738      Class Diagram
739      -------------
740
741      There are four possible formulation for dynamical systems in Siconos,
742      two for first order systems and two for second order Lagrangian systems.
743      The main class is DynamicalSystem, all other derived from this one, as
744      shown in the following diagram:
745
746      |image| [DSDiagram]
747
748      Construction
749      ------------
750
751      Each constructor must:
752
753      -  initialize all the members of the class and of the top-class if it
754	 exists
755
756      -  allocate memory and set value for all required inputs
757
758      -  allocate memory and set value for optional input if they are given as
759	 argument (in xml for example)
760
761      -  check that given data are coherent and that the system is complete
762	 (for example, in the LagrangianDS if the internal forces are given as
763	 a plug-in, their Jacobian are also required. If they are not given,
764	 this leads to an exception).
765
766      | No memory allocation is made for unused members :math:`\Rightarrow`
767      requires if statements in simulation. (if!=NULL ...).
768
769      DynamicalSystem
770      ~~~~~~~~~~~~~~~
771
772      | **Required data:**
773      | n, x0, f, jacobianXF
774      | **Optional:**
775      | T,u
776
777      | **Always allocated in constructor:**
778      | x, x0, xFree, r, rhs, jacobianXF
779
780      Warning: default constructor is always private or protected and apart
781      from the others and previous rules or remarks do not always apply to it.
782      This for DS class and any of the derived ones.
783
784      LagrangianDS
785      ~~~~~~~~~~~~
786
787      | **Required data:**
788      | ndof, q0, velocity0, mass
789      | **Optional:**
790      | fInt and its Jacobian, fExt, NNL and its Jacobian.
791
792      | **Always allocated in constructor:**
793      | mass, q, q0, qFree, velocity, velocity0, velocityFree, p.
794      | All other pointers to vectors/matrices are set to NULL by default.
795      | Memory vectors are required but allocated during call to initMemory
796      function.
797
798      Various rules:
799
800      -  fInt (NNL) given as a plug-in :math:`\Rightarrow` check that
801	 JacobianQ/Velocity are present (matrices or plug-in)
802
803      -  any of the four Jacobian present :math:`\Rightarrow` allocate memory
804	 for block-matrix jacobianX (connectToDS function)
805
806      -
807
808      | check: end of constructor or in initialize?
809      | computeF and JacobianF + corresponding set functions: virtual or not?
810
811      Specific flags or members
812      -------------------------
813
814      -  isAllocatedIn: to check inside-class memory allocation
815
816      -  isPlugin: to check if operators are computed with plug-in or just
817	 directly set as a matrix or vector
818
819      -  workMatrix: used to save some specific matrices in order to avoid
820	 recomputation if possible (inverse of mass ...)
821
822      plug-in management
823      ------------------
824
825      | DynamicalSystem class has a member named parameterList which is a
826      :math:`map<string, SimpleVector*>`, ie a list of pointers to
827      SimpleVector\*, with a string as a key to identified them. For example,
828      :math:`parametersList["mass"]` is a SimpleVector\*, which corresponds to
829      the last argument given in mass plug-in function.
830      | By default, each parameters vectors must be initialized with a
831      SimpleVector of size 1, as soon as the plug-in is declared. Moreover, to
832      each vector corresponds a flag in isAllocatedIn map, to check if the
833      corresponding vector has been allocated inside the class or not.
834      | For example, in DynamicalSystem, if
835      :math:`isPlugin["vectorField"]==true`, then, during call to constructor
836      or set function, it is necessary to defined the corresponding parameter:
837      | :math:`parametersList["vectorField"] = new SimpleVector(1)`
838      | and to complete the :math:`isAllocatedIn` flag:
839      | :math:`isAllocatedIn["parameter_for_vectorField"] = true`.
840
841      Interactions
842      ============
843
844      +-----------+--------------------+
845      | author    | F. Pérignon        |
846      +===========+====================+
847      | date      | November 7, 2006   |
848      +-----------+--------------------+
849      | version   | Kernel 1.3.0       |
850      +-----------+--------------------+
851
852      Introduction
853      ------------
854
855      | This document is only a sequel of notes and remarks on the way
856      Interactions are implemented in Siconos.
857      | It has to be completed, reviewed, reorganized etc etc for a future
858      Developpers’Guide.
859      | See also documentation in Doc/User/Interaction.
860
861      Class Diagram
862      -------------
863
864      Description
865      -----------
866
867      review of interactions (for EventDriven implementation) 17th May 2006.
868
869      | variable *nInter* renamed in *interactionSize*: represents the size of
870      *y* and *:math:`\lambda`*. NOT the number of relations !!
871
872      | add a variable *nsLawSize* that depends on the non-smooth law type.
873      | Examples:
874
875      NewtonImpact -> *nsLawSize* = 1
876
877      Friction 2D -> *nsLawSize* = 2
878
879      Friction 3D -> *nsLawSize* = 3
880
881      ...
882
883      | *nsLawSize* = n with n dim of matrix D in : :math:`y=Cx+D\lambda`, D
884      supposed to be a full-ranked matrix.
885      | Warning: this case is represented by only one relation of size n.
886
887      *numberOfRelations*: number of relations in the interaction,
888      *numberOfRelations* =
889      :math:`{\displaystyle \frac{{\textit{interactionSize}}}{{\textit{nsLawSize}}}}`.
890
891      Notes on the Non Smooth Dynamical System construction
892      =====================================================
893
894      +-----------+--------------------+
895      | author    | F. Pérignon        |
896      +===========+====================+
897      | date      | November 7, 2006   |
898      +-----------+--------------------+
899      | version   | Kernel 1.3.0       |
900      +-----------+--------------------+
901
902      Introduction
903      ------------
904
905      Class Diagram
906      -------------
907
908      Description
909      -----------
910
911      Objects must be constructed in the following order:
912
913      DynamicalSystems
914
915      NonSmoothLaw: depends on nothing
916
917      Relation: no link with an interaction during construction, this will be
918      done during initialization.
919
920      | Interaction: default constructor is private and copy is forbidden. Two
921      constructors: xml and from data. Required data are a DSSet, a
922      NonSmoothLaw and a Relation (+ dim of the Interaction and a number).
923      | Interaction has an initialize function which allocates memory for y
924      and lambda, links correctly the relation and initializes it .... This
925      function is called at the end of the constructor. That may be better to
926      call it in simulation->initialize? Pb: xml constructor needs memory
927      allocation for y and lambda if they are provided in the input xml file.
928
929      NonSmoothDynamicalSystem: default is private, copy fobidden. Two
930      constructors: xml and from data. Required data are the DSSet and the
931      InteractionsSet. The topology is declared and constructed (but empty)
932      during constructor call of the nsds, but initialize in the Simulation,
933      this because it can not be initialize until the nsds has been fully
934      described (ie this to allow user to add DS, Inter ...) at any time in
935      the model, but before simulation initialization).
936
937      misc
938      ----
939
940      no need to keep a number for Interactions? Only used in xml for OSI, to
941      know which Interactions it holds.
942
943      pb: the number of saved derivatives for y and lambda in Interactions is
944      set to 2. This must depends on the relative degree which is computes
945      during Simulation initialize and thus too late. It is so not available
946      when memory is allocated (Interaction construction). Problem-> to be
947      reviewed.
948
949      OneStepIntegrator and derived classes.
950      ======================================
951
952      +-----------+--------------------+
953      | author    | F. Pérignon        |
954      +===========+====================+
955      | date      | November 7, 2006   |
956      +-----------+--------------------+
957      | version   | Kernel 1.3.0       |
958      +-----------+--------------------+
959
960      Introduction
961      ------------
962
963      | This document is only a sequel of notes and remarks on the way
964      OneStepIntegrators are implemented in Siconos.
965      | It has to be completed, reviewed, reorganized etc etc for a future
966      Developpers’Guide.
967      | See also documentation in Doc/User/OneStepIntegrator for a description
968      of various OSI.
969
970      Class Diagram
971      -------------
972
973      Misc
974      ----
975
976      OSI review for consistency between Lsodar and Moreau:
977
978      -  add set of DynamicalSystem\*
979
980      -  add set of Interaction\*
981
982      -  add link to strategy that owns the OSI
983
984      -  remove td object in OSI -> future: replace it by a set of td (one per
985	 ds)
986
987      -  add strat in constructors arg list
988
989      | osi -> strat -> Model -> nsds -> topology
990      | osi -> strat -> timeDiscretisation
991
992      | let a timeDiscretisation object in the OSI? set of td (one per ds)?
993      | create a class of object that corresponds to DS on the simulation side
994      ?
995      | will contain the DS, its discretization, theta for Moreau ... ?
996      | Allow setStrategyPtr operation? Warning: need reinitialisation.
997
998      | Required input by user:
999
1000      -  list of DS or list of Interactions ?
1001
1002      -  pointer to strategy
1003
1004      -  ...
1005
1006      Construction
1007      ------------
1008
1009      Each constructor must:
1010
1011      -
1012
1013      Moreau
1014      ~~~~~~
1015
1016      | Two maps: one for W, and one for theta. To each DS corresponds a theta
1017      and a W.
1018      | Strategy arg in each constructor.
1019
1020      | **Required data:**
1021
1022      | **Optional:**
1023
1024      | **Always allocated in constructor:**
1025
1026      Warning: default constructor is always private or protected and apart
1027      from the others and previous rules or remarks do not always apply to it.
1028
1029      Lsodar
1030      ~~~~~~
1031
1032      | **Required data:**
1033
1034      | **Optional:**
1035
1036      | **Always allocated in constructor:**
1037
1038      First Order Nonlinear Relation
1039      ===============================
1040
1041      +-----------+----------------+
1042      | author    | 0. Bonnefon    |
1043      +===========+================+
1044      | date      | July, 1 2009   |
1045      +-----------+----------------+
1046      | version   | Kernel 3.0.0   |
1047      +-----------+----------------+
1048
1049      Computation of the number of Index Set and various levels
1050      =========================================================
1051
1052      +-----------+----------------------+
1053      | author    | V. Acary             |
1054      +===========+======================+
1055      | date      | Septembre 16, 2011   |
1056      +-----------+----------------------+
1057      | version   | Kernel 3.3.0         |
1058      +-----------+----------------------+
1059
1060      In this chapter, we give some hints on the automatic computation of the
1061      number of index sets, the number of derivatives in the Interaction and
1062      the levelMin and LevelMax.
1063
1064      Why is the relative degree not relevant ?
1065      -----------------------------------------
1066
1067      In this section, we give a very brief overview of the notion of relative
1068      degree.
1069
1070      First order Linear complementary systems
1071      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1072
1073      A Linear Complementarity System (LCS) is defined by
1074
1075      .. math::
1076
1077	 \label{eq:LCS-bis}
1078	   \begin{cases}
1079	     \dot x = A x +B \lambda \\
1080	      y = C x + D \lambda\\
1081	     0 \leq  y \perp \lambda \geq 0 \\
1082	   \end{cases}
1083
1084      [Relative degree in the SISO case] Let us consider a linear system in
1085      state representation given by the quadruplet
1086      :math:`(A,B,C,D) \in {\mbox{\rm $I\!\!R$}}^{n\times n}\times{\mbox{\rm $I\!\!R$}}^{n \times m}\times {\mbox{\rm $I\!\!R$}}^{m\times n}\times{\mbox{\rm $I\!\!R$}}^{m\times m} `:
1087
1088      .. math::
1089
1090	 \label{eq:LS}
1091		 \begin{cases}
1092		   \dot x = A x +B \lambda \\
1093		   y = C x + D \lambda
1094		 \end{cases}
1095
1096      -  In the Single Input/ Single Output (SISO) case (:math:`m=1`), the
1097	 relative degree is defined by the first non zero Markov parameters :
1098
1099	 .. math::
1100
1101	    \label{eq:Markov-Parameter}
1102		      D, CB, CAB, CA^2B, \ldots, CA^{r-1}B, \ldots
1103
1104      -  In the multiple input/multiple output (MIMO) case (:math:`m>1`), an
1105	 *uniform* relative degree is defined as follows. If :math:`D` is non
1106	 singular, the relative degree is equal to :math:`0`. Otherwise, it is
1107	 assumed to be the first positive integer :math:`r` such that
1108
1109	 .. math::
1110
1111	    \label{eq:mimo-r}
1112		      CA^{i}B =0, \quad i=0\ldots q-2
1113
1114	 while
1115
1116	 .. math::
1117
1118	    \label{eq:mimo-r2}
1119		      CA^{r-1}B \text{ is non singular}.
1120
1121      The Markov parameters arise naturally when we derive with respect to
1122      time the output :math:`y`,
1123
1124      .. math::
1125
1126	 \begin{aligned}
1127	       \label{eq:y-derive}
1128	       y &=& C x + D \lambda \\
1129	       \dot y &=& CA x + CB \lambda, \text{ if } D= 0  \\
1130	       \ddot y &=& CA^2 x + CAB \lambda, \text{ if }  D=0, CB=0\\
1131	       &\ldots& \\
1132	       y^{(r)} &=& CA^{r} x + CA^{r-1}B \lambda, \text{ if } D=0, CB=0, CA^{r-2}B=0, r=1\ldots r-2 \\
1133	       &\ldots&
1134	     \end{aligned}
1135
1136      and the first non zero Markov parameter allows us to define the output
1137      :math:`y` directly in terms of the input :math:`\lambda`.
1138
1139      In continuous time, the nature of solutions depends strongly on the
1140      relative degree. When we want to perform the time–integration of such
1141      systems, we need also to reduce the relative degree or to known it to
1142      correctly operate.
1143
1144      We can observe that the relative degree :math:`0` is well defined only
1145      by the relation (:math:`D` nonsingular) and by the nonsmooth law.
1146      Indeed, let us imagine that the nonsmooth law is defined by
1147      :math:`0\leq\dot y \perp \lambda \geq 0 `. We can easily see that the
1148      relative degree is reduced.
1149
1150      In the MIMO, the computation of non uniform relative degree is hard
1151      task. This is also the case for nonlinear systems.
1152
1153      Second order Lagrangian systems
1154      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1155
1156      Let us consider a second order linear and time-invariant Lagrangian
1157      dynamical system (see § [Sec:LagrangianLineatTIDS])
1158
1159      .. math::
1160
1161	 \label{eq:rd1}
1162	   \begin{cases}
1163	     M \dot v + C v + K q = F_{Ext}(t) + p \\
1164	     \dot q = v
1165	   \end{cases}
1166
1167      together with a Lagrangian linear relation
1168
1169      .. math::
1170
1171	 y= Cq + e + D \lambda + Fz,
1172	   \label{eq:rd2}
1173
1174      .. math::
1175
1176	 p = C^t \lambda
1177	 \label{eq:rd3}
1178
1179      and a simple nonsmooth law,
1180
1181      .. math::
1182
1183	 0\leq y \perp \lambda \geq 0
1184	 \label{eq:rd4}
1185
1186      If :math:`D>0`, the relative degree is uniformly zero and the system can
1187      be solved without deriving the output ([eq:rd2]). Indeed, we known that
1188      the solution of the LCP
1189
1190      .. math::
1191
1192	 0\leq Cq + e + D \lambda + Fz, \perp \lambda \geq 0
1193	 \label{eq:rd5}
1194
1195      is unique and Lipschitz with respect to :math:`q`. It can be denoted as
1196      :math:`\lambda(q) = \mbox{SOL}(D,Cq + e +Fz)`. Therefore, the
1197      differential equation ([eq:rd1]) reduces to a standard ODE with a
1198      Lipschitz RHS
1199
1200      .. math::
1201
1202	 \label{eq:rd6}
1203	   \begin{cases}
1204	     M \dot v + C v + K q = F_{Ext}(t) + C^t \lambda(q)  \\
1205	     \dot q = v
1206	   \end{cases}
1207
1208      In the case that we deal with unilateral contact, we usually have
1209      :math:`D=0` and the relative degree of the system is :math:`2`. In this
1210      case, the output has to be differentiated as
1211
1212      .. math::
1213
1214	 \label{eq:rd7}
1215	    \dot y= C \dot q,
1216
1217      and an impact law has to added, for instance the newton’s impact law
1218
1219      .. math::
1220
1221	 \label{eq:rd8}
1222	   \text{ if } y=0, \text{ when } \dot y^+= -e y^-
1223
1224      In the same vein, the equations of motion ([eq:rd1]) is not sufficient
1225      since the velocity may encounter jumps. The dynamics is usually replaced
1226      by a measure differential equation of the form
1227
1228      .. math::
1229
1230	 \label{eq:rd10}
1231	   \begin{cases}
1232	     M dv + C v^+(t) dt + K q(t) dt = F_{Ext}(t)dt + di \\
1233	     \dot q = v
1234	   \end{cases}
1235
1236      where :math:`di` is the measure that can be related to :math:`p` thanks
1237      to
1238
1239      .. math::
1240
1241	 \label{eq:rd11}
1242	   di = p dt + \sigma \delta _{t^*}
1243
1244      is only one jump is expected at :math:`{t^*}`.
1245
1246      Conclusion for the implementation
1247      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1248
1249      From the continuous time mathematical analysis, the relative degree is
1250      very important to know if we have to compute the derivatives of the
1251      output :math:`y^{(n)}` and to consider various levels for the input
1252      :math:`p , \sigma, ....`
1253
1254      However in the numerical practice, the time –discretization makes an
1255      assumption on the relative degree and treats the nonsmooth law at
1256      different levels. The resulting time discretized system posseses more or
1257      less variables.
1258
1259      Consider for instance ([eq:rd1]) in the case of the Moreau scheme
1260
1261      | [eq:MoreauTS] M(v\ :sub:`k+1`-v:sub:`k`) + h (K q\ :sub:`k+`\ + C
1262      v\ :sub:`k+`) = p\ :sub:`k+1` = G(q\ :sub:`k+1`) :sub:`k+1`,
1263      | q\ :sub:`k+1` = q\ :sub:`k` + h v\ :sub:`k+`,
1264      | y\ :sub:`k+1` = G\ :sup:``\ (q:sub:`k+1`) v\ :sub:`k+1`
1265
1266      | l \|y\ :sup:``\ :sub:`k+1` 0 0 y\ :sup:``\ :sub:`k+1` + e
1267      y\ :sup:``\ :sub:`k` :sup:``\ :sub:`k+1` 0,
1268      |  :sup:``\ :sub:`k+1` =0.[eq:MoreauTSd]
1269
1270      , I
1271
1272      and the Schatzman–Paoli scheme
1273
1274      | M(q\ :sub:`k+1`-2q:sub:`k`\ +q\ :sub:`k-1`) + h\ :sup:`2` (K
1275      q\ :sub:`k+`\ + C v\ :sub:`k+`) = p\ :sub:`k+1`,
1276      | v\ :sub:`k+1`\ =,
1277      | y\ :sub:`k+1` = h()
1278      | p\ :sub:`k+1`\ = G() :sub:`k+1`
1279      | 0 y\ :sub:`k+1` :sub:`k+1` 0 .
1280
1281      We can see easily that the number of derivatives (or levels) that we
1282      store for :math:`y` and :math:`\lambda` is independent on the relative
1283      degree but is chosen by the OneStepIntegrator with respect to the type
1284      of systems.
1285
1286      How to define and compute the various levels and the number of indexSets
1287      -------------------------------------------------------------------------
1288
1289      :math:`y` related variables
1290      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1291
1292      The size of the vector y in the Interaction depends on
1293
1294      -  the OneStepIntegrator type.
1295
1296	 -  see the difference between the Moreau and Schatzman Paoli scheme,
1297
1298	 -  plan the time–discontinuous Galerkin scheme
1299
1300	 -  plan the Higher Order Moreau sweeping process (HOSP)
1301
1302      -  the Simulation type.
1303
1304	 -  In Timestepping or Event-driven we do not need the same number of
1305	    stored :math:`y`
1306
1307      -  the NonSmoothLaw type.
1308
1309	 -  If we consider some cases with or without friction in Timestepping
1310	    or Event-driven, we need to adapt the number of stored :math:`y`
1311
1312      Since the various levels of y are used to build the index sets we will
1313      need from :math:`0` to a computed size that depends on the previous
1314      criteria. Only a part will be used in the OneStepNSProblem.
1315
1316      :math:`\lambda` related variables
1317      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1318
1319      The size of the vector lambda in the Interaction depends on the same
1320      criteria than in the previous section. Only, the number of lambda is not
1321      the same as y since a multiplier lambda[i] is not necessarily related to
1322      y[i]
1323
1324      Rules for implementation
1325      ------------------------
1326
1327      We can define new members in Interaction:
1328
1329      -  \_lowerlevelForOutput, this value is to :math:`0` by default
1330
1331      -  \_upperlevelForOutput, this value must be computed at initialization
1332	 with respect to the previous criteria
1333
1334      -  \_lowerlevelForInput, this value must be computed at initialization
1335	 with respect to the previous criteria
1336
1337      -  \_upperlevelForInput, this value must be computed at initialization
1338	 with respect to the previous criteria
1339
1340      This level are computed in Simulation::ComputeLevelsForInputAndOutput. A
1341      visitor is used for the OneStepIntegrator. Furthermore, four global
1342      levels are computed
1343
1344      -  \_levelMinForOutput this value is the minimum level for the output
1345	 Interaction::\_lowerlevelForOutput for all the interactions
1346
1347      -  \_levelMaxForOutput this value is the maximum level for the output
1348	 Interaction::\_upperlevelForOutput for all the interactions
1349
1350      -  \_levelMinForInput this value is the minimum level for the output
1351	 Interaction::\_lowerlevelForInput for all the interactions
1352
1353      -  \_levelMaxForInput this value is the maximum level for the output
1354	 Interaction::\_upperlevelForInput for all the interactions
1355
1356      -  the values y[i] must be initialized from \_lowerlevelForOutput to
1357	 \_upperlevelForOutput.
1358
1359      -  the values lamdba[i] must be initialized from \_lowerlevelForInput to
1360	 \_upperlevelForInput.
1361
1362      -  the values y[i] in Interaction must be used in priority to store the
1363	 i-th derivative of :math:`y`. When it is needed, higher index
1364	 :math:`i` can be used for other triggering variables. For instance,
1365	 for an Event–Driven scheme with a Lagrangian systems with friction,
1366	 sliding velocity must be stored.
1367
1368      -  the values of lamdba[i] must stored the various multiplier for the
1369	 nonsmooth law. We affect the same index :math:`i` as for the level of
1370	 y[i] present in the corresponding nonsmooth law.
1371
1372      -  The number of IndexSets should follows \_levelMaxForY.
1373
1374      For the dynamical systems :
1375
1376      -  The number of levels for \_r and \_p in the DS should follow
1377	 \_lowerlevelForInput and \_upperlevelForOutput of the associated
1378	 interactions. This is done in Interaction::initialize.
1379
1380      -  A new variable should be added in the LagrangianDS to store the
1381	 multiplier at the position level (\_tau ?) to avoid the use of
1382	 \_p[0]. Indeed, we will continue to assume that \_p is the input in
1383	 the equation of motion. For lambda we can use lambda[0]
1384
1385      TODO LIST AND QUESTIONS
1386
1387      -  What about the case of multiples interactions on a DS with various
1388	 \_lowerlevelForInput and \_upperlevelForOutput ? Normally, all the
1389	 levels should be correctly initialized thanks to the proposed
1390	 implementation (r2821)
1391
1392      -  DynamicalSystem::\_r should be a VectorOfVectors
1393
1394      -  DynamicalSystem::\_r is split in LagrangianDS. a first part is
1395	 LagrangianDS::\_p. The other is not implemented !!
1396	 LagrangianDS::\_tau ?
1397
1398      Newton’s linearization for First Order Systems
1399      ==============================================
1400
1401      +---------------+------------------------+
1402      | author        | O.Bonnefon, V. Acary   |
1403      +===============+========================+
1404      | date          | Sept, 07, 2007         |
1405      +---------------+------------------------+
1406      | last update   | Feb, 2011              |
1407      +---------------+------------------------+
1408      |               | April, 2014            |
1409      +---------------+------------------------+
1410      | version       |                        |
1411      +---------------+------------------------+
1412
1413      This section is devoted to the implementation and the study of the
1414      algorithm. The interval of integration is :math:`[0,T]`, :math:`T>0`,
1415      and a grid :math:`t_{0}=0`, :math:`t_{k+1}=t_{k}+h`, :math:`k \geq 0`,
1416      :math:`t_{N}=T` is constructed. The approximation of a function
1417      :math:`f(\cdot)` on :math:`[0,T]` is denoted as :math:`f^{N}(\cdot)`,
1418      and is a piecewise constant function, constant on the intervals
1419      :math:`[t_{k},t_{k+1})`. We denote :math:`f^{N}(t_{k})` as
1420      :math:`f_{k}`. The time-step is :math:`h>0`.
1421
1422      Various first order dynamical systems with input/output relations
1423      -----------------------------------------------------------------
1424
1425      FirstOrderR. Fully nonlinear case
1426      '''''''''''''''''''''''''''''''''
1427
1428      Let us introduce the following system,
1429
1430      .. math::
1431
1432	 \begin{array}{l}
1433	 M \dot{x}(t) = f(x(t),t) + r(t)  \\[2mm]
1434	 y(t) = h(t,x(t),\lambda (t)) \\[2mm]
1435	 r(t) = g(t,x(t),\lambda (t) ) \\[2mm]
1436	 \end{array}
1437	 \label{first-DS}
1438
1439      where :math:`\lambda(t) \in {\mbox{\rm $I\!\!R$}}^m` and
1440      :math:`y(t) \in {\mbox{\rm $I\!\!R$}}^m` are complementary variables
1441      related through a multi-valued mapping. According to the class of
1442      systems, we are studying, the function :math:`f` and :math:`g` are
1443      defined by a fully nonlinear framework or by affine functions. We have
1444      decided to present the time-discretization in its full generality and
1445      specialize the algorithms for each cases in Section [Sec:Spec]. This
1446      fully nonlinear case is not implemented in Siconos yet. This fully
1447      general case is not yet implemented in Siconos.
1448
1449      This case is implemented in Siconos with the relation FirstOrderR using
1450      the subtype NonLinearR
1451
1452      FirstOrderType1R
1453      ''''''''''''''''
1454
1455      Let us introduce a new notation,
1456
1457      .. math::
1458
1459	 \begin{array}{l}
1460	 M \dot{x}(t) = f(x(t),t) + r(t)  \\[2mm]
1461	 y(t) = h(t,x(t)) \\[2mm]
1462	 r(t) = g(t,\lambda (t) ) \\[2mm]
1463	 \end{array}
1464	 \label{first-DS1}
1465
1466      This case is implemented in Siconos with the relation FirstOrderType1R.
1467
1468      FirstOrderType2R
1469      ''''''''''''''''
1470
1471      Let us introduce a new notation,
1472
1473      .. math::
1474
1475	 \begin{array}{l}
1476	 M \dot{x}(t) = f(x(t),t) + r(t)  \\[2mm]
1477	 y(t) = h(t,x(t),\lambda (t)) \\[2mm]
1478	 r(t) = g(t,\lambda (t) ) \\[2mm]
1479	 \end{array}
1480	 \label{first-DS2}
1481
1482      This case is implemented in Siconos with the relation FirstOrderType2R.
1483
1484      Linear case
1485      ''''''''''''
1486
1487      Let us introduce a new notation,
1488
1489      .. math::
1490
1491	 \begin{array}{l}
1492	 M \dot{x}(t) = Ax(t) + r(t)  +b(t)\\[2mm]
1493	 y(t) = h(x(t),\lambda (t),z) = Cx + Fz + D \lambda  \\[2mm]
1494	 r(t) = g(t,\lambda (t) ) = B \lambda \\[2mm]
1495	 \end{array}
1496	 \label{first-DS3}
1497
1498      Time–discretizations
1499      --------------------
1500
1501      Standard :math:`\theta-\gamma` scheme.
1502      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1503
1504      Let us now proceed with the time discretization of ([first-DS3]) by a
1505      fully implicit scheme :
1506
1507      .. math::
1508
1509	 \begin{array}{l}
1510	     \label{eq:toto1}
1511	      M x_{k+1} = M x_{k} +h\theta f(x_{k+1},t_{k+1})+h(1-\theta) f(x_k,t_k) + h \gamma r(t_{k+1})
1512	      + h(1-\gamma)r(t_k)  \\[2mm]
1513	      y_{k+1} =  h(t_{k+1},x_{k+1},\lambda_{k+1}) \\[2mm]
1514	      r_{k+1} =  g(t_{k+1},x_{k+1},\lambda_{k+1})\\[2mm]
1515	      \mbox{NsLaw} ( y_{k+1} , \lambda_{k+1})
1516	   \end{array}
1517
1518      where :math:`\theta = [0,1]` and :math:`\gamma \in [0,1]`. As in , we
1519      call the problem the “one–step nonsmooth problem”.
1520
1521      In the Siconos/Kernel module, the use of :math:`\gamma` is activated in
1522      the class EulerMoreauOSI by the boolean \_useGamma.
1523
1524      This time-discretization is slightly more general than a standard
1525      implicit Euler scheme. The main discrepancy lies in the choice of a
1526      :math:`\theta`-method to integrate the nonlinear term. For
1527      :math:`\theta=0`, we retrieve the explicit integration of the smooth and
1528      single valued term :math:`f`. Moreover for :math:`\gamma =0`, the term
1529      :math:`g` is explicitly evaluated. The flexibility in the choice of
1530      :math:`\theta` and :math:`\gamma` allows the user to improve and control
1531      the accuracy, the stability and the numerical damping of the proposed
1532      method. For instance, if the smooth dynamics given by :math:`f` is
1533      stiff, or if we have to use big step sizes for practical reasons, the
1534      choice of :math:`\theta > 1/2` offers better stability with the respect
1535      to :math:`h`.
1536
1537      Full :math:`\theta-\gamma` scheme
1538      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1539
1540      Another possible time–discretization is as follows.
1541
1542      .. math::
1543
1544	 \begin{array}{l}
1545	     \label{eq:toto1-ter}
1546	     M x_{k+1} = M x_{k} + h\theta f(x_{k+1},t_{k+1})+h(1-\theta) f(x_k,t_k) + h r(t_{k+\gamma}) \\[2mm]
1547	     y_{k+\gamma} = h(t_{k+\gamma},x_{k+\gamma},\lambda _{k+\gamma}) \\[2mm]
1548	     r_{k+\gamma} = g(t_{k+\gamma},x_{k+\gamma},\lambda _{k+\gamma})\\[2mm]
1549	     \mbox{NsLaw} ( y_{k+\gamma} , \lambda_{k+\gamma})
1550	   \end{array}
1551
1552      We call the scheme ([eq:toto1-ter]) the full :math:`\theta-\gamma`
1553      scheme since it uses also the evaluation at :math:`t_{k+\gamma}` for the
1554      relation.
1555
1556      In the Siconos/Kernel module, the time–stepping scheme is activated in
1557      the class EulerMoreauOSI by the boolean \_useGammaForRelation.
1558
1559      Another possibility for the time discretization in the nonlinear case
1560      would be
1561
1562      .. math::
1563
1564	 \begin{array}{l}
1565	     \label{eq:toto1-quat}
1566	     M x_{k+1} = M x_{k} +h f(x_{k+\theta},t_{k+\theta}) + h r(t_{k+\gamma}) \\[2mm]
1567	     y_{k+\gamma} =  h(t_{k+\gamma},x_{k+\gamma},\lambda _{k+\gamma}) \\[2mm]
1568	     r_{k+\gamma} = g(t_{k+\gamma},x_{k+\gamma},\lambda _{k+\gamma})\\[2mm]
1569	     \mbox{NsLaw} ( y_{k+\gamma} , \lambda_{k+\gamma})
1570	   \end{array}
1571
1572      This scheme has not been yet implemented in Siconos/Kernel.
1573
1574      Newton’s linearization of ([eq:toto1])
1575      --------------------------------------
1576
1577      Due to the fact that two of the studied classes of systems that are
1578      studied in this paper are affine functions in terms of :math:`f` and
1579      :math:`g`, we propose to solve the "one–step nonsmooth problem”
1580      ([eq:toto1]) by performing an external Newton linearization.
1581
1582      Newton’s linearization of the first line of ([eq:toto1])
1583      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1584
1585      The first line of the problem ([eq:toto1]) can be written under the form
1586      of a residue :math:`\mathcal R` depending only on :math:`x_{k+1}` and
1587      :math:`r_{k+1}` such that
1588
1589      .. math::
1590
1591	 \label{eq:NL3}  \mathcal R (x_{k+1},r _{k+1}) =0
1592
1593      with
1594
1595      .. math::
1596
1597	 \mathcal R(x,r) = M(x - x_{k}) -h\theta f( x , t_{k+1}) - h(1-\theta)f(x_k,t_k) - h\gamma r- h(1-\gamma)r_k.
1598
1599      The solution of this system of nonlinear equations is sought as a limit
1600      of the sequence
1601      :math:`\{ x^{\alpha}_{k+1},r^{\alpha}_{k+1} \}_{\alpha \in {\mbox{\rm $I\!\!N$}}}`
1602      such that
1603
1604      .. math::
1605
1606	 \label{eq:NL7}   \begin{cases}     x^{0}_{k+1} = x_k \\ \\     r^{0}_{k+1} = r_k \\ \\     \mathcal R_L( x^{\alpha+1}_{k+1},r^{\alpha+1}_{k+1}) = \mathcal     R(x^{\alpha}_{k+1},r^{\alpha}_{k+1})  + \left[ \nabla_{x} \mathcal     R(x^{\alpha}_{k+1},r^{\alpha}_{k+1})\right] (x^{\alpha+1}_{k+1}-x^{\alpha}_{k+1} ) +     \left[ \nabla_{r} \mathcal R(x^{\alpha}_{k+1},r^{\alpha}_{k+1})\right] (r^{\alpha+1}_{k+1} - r^{\alpha}_{k+1} ) =0 \end{cases}
1607
1608      What about :math:`r^0_{k+1}` ?
1609
1610      The residu :math:`\mathcal R _{\free}` is also defined (useful for
1611      implementation only):\
1612
1613      .. math::
1614
1615	 \mathcal R _{\free}(x) \stackrel{\Delta}{=}  M(x - x_{k}) -h\theta f( x , t_{k+1}) - h(1-\theta)f(x_k,t_k),
1616
1617      \ which yields\
1618
1619      .. math::
1620
1621	 \mathcal R (x,r) = \mathcal R _{\free}(x)   - h\gamma r - h(1-\gamma)r_k.
1622
1623      .. math::
1624
1625	 \mathcal R (x^{\alpha}_{k+1},r^{\alpha}_{k+1}) = \fbox{$\mathcal R^{\alpha}_{k+1} \stackrel{\Delta}{=}  \mathcal R_{\free}(x^{\alpha}_{k+1})  - h\gamma r^{\alpha}_{k+1} - h(1-\gamma)r_k$}\label{eq:rfree-1}
1626
1627      .. math::
1628
1629	 \mathcal R_{\free}(x^{\alpha}_{k+1},r^{\alpha}_{k+1} )=\fbox{$ \mathcal R _{\free, k+1} ^{\alpha} \stackrel{\Delta}{=}  M(x^{\alpha}_{k+1} - x_{k}) -h\theta f( x^{\alpha}_{k+1} , t_{k+1}) - h(1-\theta)f(x_k,t_k)$}
1630
1631      The special case of Newton’s linearization of ([eq:toto1]) with FirstOrderType2R ([first-DS2])
1632      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1633
1634      Let us now proceed with the time discretization of ([eq:toto1]) with
1635      FirstOrderType2R ([first-DS2]) by a fully implicit scheme :
1636
1637      .. math::
1638
1639	 \begin{array}{l}    \label{eq:mlcp2-toto1-DS2}     M x_{k+1} = M x_{k} +h\theta f(x_{k+1},t_{k+1})+h(1-\theta) f(x_k,t_k) + h \gamma r(t_{k+1})     + h(1-\gamma)r(t_k)  \\[2mm]     y_{k+1} =  h(t_{k+1},x_{k+1},\lambda _{k+1}) \\[2mm]     r_{k+1} = g(t_{k+1},\lambda_{k+1})\\[2mm]  \end{array}
1640
1641      Newton’s linearization of the first line of ([eq:mlcp2-toto1-DS2])
1642      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1643
1644      The linearization of the first line of the
1645      problem ([eq:mlcp2-toto1-DS2]) is similar to the previous case so that
1646      ([eq:rfree-2]) is still valid.
1647
1648      Newton’s linearization of the second line of ([eq:mlcp2-toto1-DS2])
1649      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1650
1651      The linearization of the second line of the
1652      problem ([eq:mlcp2-toto1-DS2]) is similar to the previous case so that
1653      ([eq:NL11y]) is still valid.
1654
1655      Newton’s linearization of the third line of ([eq:mlcp2-toto1-DS2])
1656      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1657
1658      Since
1659      :math:` K^{\alpha}_{k+1} = \nabla_xg(t_{k+1},\lambda ^{\alpha}_{k+1}) = 0 `,
1660      the linearization of the third line of ([eq:mlcp2-toto1-DS2]) reads as
1661
1662      .. math::
1663
1664	 \label{eq:mlcp2-rrL}  \begin{array}{l}    \boxed{r^{\alpha+1}_{k+1} = g(t_{k+1},\lambda ^{\alpha}_{k+1})     + B^{\alpha}_{k+1} ( \lambda^{\alpha+1}-  \lambda^{\alpha}_{k+1} )}         \end{array}
1665
1666      Reduction to a linear relation between :math:`x^{\alpha+1}_{k+1}` and\ :math:`\lambda^{\alpha+1}_{k+1}`
1667      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1668
1669      Inserting ([eq:mlcp2-rrL]) into ([eq:rfree-11]), we get the following
1670      linear relation between :math:`x^{\alpha+1}_{k+1}`
1671      and\ :math:`\lambda^{\alpha+1}_{k+1}`, we get the linear relation
1672
1673      .. math::
1674
1675	 \label{eq:mlcp2-rfree-13}  \begin{array}{l} \boxed{   x^{\alpha+1}_{k+1}\stackrel{\Delta}{=} x^\alpha_p + \left[ h \gamma (W^{\alpha}_{k+1})^{-1}    B^{\alpha}_{k+1} \lambda^{\alpha+1}_{k+1}\right]}   \end{array}
1676
1677      with
1678
1679      .. math::\boxed{x^\alpha_p \stackrel{\Delta}{=}  h\gamma(W^{\alpha}_{k+1} )^{-1}\left[g(t_{k+1},\lambda^{\alpha}_{k+1})     -B^{\alpha}_{k+1} (\lambda^{\alpha}_{k+1}) \right ] +x^\alpha_{\free}}
1680
1681      and
1682
1683      .. math::
1684
1685      \label{eq:mlcp2-NL9}  \begin{array}{l}    W^{\alpha}_{k+1} \stackrel{\Delta}{=} M-h\theta A^{\alpha}_{k+1}\\  \end{array}
1686
1687      Reduction to a linear relation between :math:`y^{\alpha+1}_{k+1}` and\ :math:`\lambda^{\alpha+1}_{k+1}`
1688      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1689
1690      Inserting ([eq:mlcp2-rfree-13]) into ([eq:NL11y]), we get the following
1691      linear relation between :math:`y^{\alpha+1}_{k+1}` and
1692      :math:`\lambda^{\alpha+1}_{k+1}`,
1693
1694      .. math::
1695
1696	 \begin{array}{l} y^{\alpha+1}_{k+1} = y_p + \left[ h \gamma C^{\alpha}_{k+1} ( W^{\alpha}_{k+1})^{-1}  B^{\alpha}_{k+1} + D^{\alpha}_{k+1} \right]\lambda^{\alpha+1}_{k+1}   \end{array}
1697
1698      with
1699
1700      .. math::
1701
1702	 \boxed{y_p = y^{\alpha}_{k+1} -\mathcal R^{\alpha}_{yk+1} + C^{\alpha}_{k+1}(x_q) -D^{\alpha}_{k+1} \lambda^{\alpha}_{k+1} }
1703
1704      The special case of Newton’s linearization of ([eq:toto1]) with FirstOrderType1R ([first-DS1])
1705      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1706
1707      Let us now proceed with the time discretization of ([eq:toto1]) with
1708      FirstOrderType1R ([first-DS1]) by a fully implicit scheme :
1709
1710      .. math::
1711
1712	 \begin{array}{l}    \label{eq:mlcp3-toto1-DS1}     M x_{k+1} = M x_{k} +h\theta f(x_{k+1},t_{k+1})+h(1-\theta) f(x_k,t_k) + h \gamma r(t_{k+1})     + h(1-\gamma)r(t_k)  \\[2mm]     y_{k+1} =  h(t_{k+1},x_{k+1}) \\[2mm]     r_{k+1} = g(t_{k+1}\lambda_{k+1})\\[2mm]  \end{array}
1713
1714      The previous derivation is valid with :math:` D^{\alpha}_{k+1} =0`.
1715
1716      Time–discretization of the linear case ([first-DS3])
1717      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1718
1719      Let us now proceed with the time discretization of ([eq:toto1]) with
1720      FirstOrderLinearR ([first-DS3]) by a fully implicit scheme :
1721
1722      .. math::
1723
1724	 \begin{array}{l}    \label{eq:toto1-DS3}     M x^{\alpha+1}_{k+1} = M x_{k} +h\theta A x^{\alpha+1}_{k+1}+h(1-\theta) A x_k + h \gamma r^{\alpha+1}_{k+1}+ h(1-\gamma)r(t_k)  +hb\\[2mm]     y^{\alpha+1}_{k+1} =  C x^{\alpha+1}_{k+1} + D \lambda ^{\alpha+1}_{k+1} +Fz +e\\[2mm]     r^{\alpha+1}_{k+1} = B \lambda ^{\alpha+1}_{k+1} \\[2mm]  \end{array}
1725
1726      .. math::
1727
1728	 R_{\free} = M(x^{\alpha}_{k+1} - x_{k}) -h\theta A x^{\alpha}_{k+1} - h(1-\theta) A x_k -hb_{k+1}
1729
1730      \
1731
1732      .. math::
1733
1734	 R_{\free} = W(x^{\alpha}_{k+1} - x_{k}) -h A x_{k} -hb_{k+1}
1735
1736      Resulting Newton step (only one step)
1737      '''''''''''''''''''''''''''''''''''''
1738
1739      For the sake of simplicity, let us assume that :math:`\gamma =1`
1740
1741      .. math::
1742
1743	 \begin{array}{l}     (M -h\theta A)x^{\alpha+1}_{k+1} = M x_{k} +h(1-\theta) A x_k + hr^{\alpha+1}_{k+1} + hb\\[2mm]     y^{\alpha+1}_{k+1} =  C x^{\alpha+1}_{k+1} + D \lambda ^{\alpha+1}_{k+1} +Fz + e \\[2mm]     r^{\alpha+1}_{k+1} = B \lambda ^{\alpha+1}_{k+1}\\[2mm]  \end{array}
1744
1745      that lead to with: :math:` (M -h\theta A) = W`
1746
1747      .. math::
1748
1749	 \begin{array}{l}     x^{\alpha+1}_{k+1} = W^{-1}(M x_{k} +h(1-\theta) A x_k + r^{\alpha+1}_{k+1} +hb) = x\free + W^{-1}(r^{\alpha+1}_{k+1})\\[2mm]     y^{\alpha+1}_{k+1} =  ( D+hCW^{-1}B) \lambda ^{\alpha+1}_{k+1} +Fz + CW^{-1}(M     x_k+h(1-\theta)Ax_k + hb) +e \\[2mm]  \end{array}
1750
1751      with
1752      :math:`x_{\free} = x^{\alpha}_{k+1} + W^{-1}(-R_{\free})= x^{\alpha}_{k+1} - W^{-1}(W(x^{\alpha}_{k+1}- x_k) -hAx_k-hb_{k+1} )= W^{-1}(Mx_k +h(1-\theta)Ax_k +h b_{k+1})`
1753
1754      .. math::
1755
1756	 \begin{array}{l}     y^{\alpha+1}_{k+1} =  ( D+hCW^{-1}B) \lambda ^{\alpha+1}_{k+1} +Fz + Cx_{\free}+e\\[2mm]     r^{\alpha+1}_{k+1} = B \lambda ^{\alpha+1}_{k+1}\\[2mm]  \end{array}
1757
1758      Coherence with previous formulation
1759      '''''''''''''''''''''''''''''''''''
1760
1761      .. math::
1762
1763	 y_p = y^{\alpha}_{k+1} -\mathcal R^{\alpha}_{yk+1} + C^{\alpha}_{k+1}(x_p -x^{\alpha}_{k+1}) -D^{\alpha}_{k+1} \lambda^{\alpha}_{k+1}
1764
1765      \
1766
1767      .. math::
1768
1769	 y_p = Cx_k + D \lambda _k  + C(\tilde x_{\free}) -D \lambda_k +Fz + e
1770
1771      \
1772
1773      .. math::
1774
1775	 y_p = Cx_k   + C(\tilde x_{\free})  +Fz + e
1776
1777      \
1778
1779      .. math::
1780
1781	 y_p = Cx_k   + C(\tilde x_{\free})  +Fz + e
1782
1783      \
1784
1785      .. math::
1786
1787	 y_p = C(x_{\free})  +Fz + e
1788
1789      Newton’s linearization of  ([eq:toto1-ter])
1790      --------------------------------------------
1791
1792      In this section, we deal with only with the FirstOrderType2R case.
1793
1794      .. math::
1795
1796	 \begin{array}{l}
1797	       \label{eq:full-toto1-ter}
1798	       M x_{k+1} = M x_{k} +h \theta f(x_{k+1},t_{k+1}) +h(1-\theta)f(x_{k},t_{k}) + h r_{k+\gamma} \\[2mm]
1799	       y_{k+\gamma} =  h(t_{k+\gamma},x_{k+\gamma},\lambda _{k+\gamma}) \\[2mm]
1800	       r_{k+\gamma} = g(t_{k+\gamma},\lambda_{k+\gamma})\\[2mm]
1801	     \end{array}
1802
1803      Newton’s linearization of the first line of ([eq:full-toto1-ter])
1804      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1805
1806      The first line of the problem ([eq:full-toto1-ter]) can be written under
1807      the form of a residue :math:`\mathcal R` depending only on
1808      :math:`x_{k+1}` and :math:`r_{k+\gamma}` such that
1809
1810      .. math::
1811
1812	 \label{eq:full-NL3}
1813	   \mathcal R (x_{k+1},r _{k+\gamma}) =0
1814
1815      with
1816
1817      .. math::
1818
1819	 \mathcal R(x,r) = M(x - x_{k}) -h\theta f( x , t_{k+1}) - h(1-\theta)f(x_k,t_k) - h r.
1820
1821      The solution of this system of nonlinear equations is sought as a limit
1822      of the sequence
1823      :math:`\{ x^{\alpha}_{k+1},r^{\alpha}_{k+\gamma} \}_{\alpha \in {\mbox{\rm $I\!\!N$}}}`
1824      such that
1825
1826      .. math::
1827
1828	 \label{eq:full-NL7}
1829	    \begin{cases}
1830	      x^{0}_{k+1} = x_k \\ \\
1831	      r^{0}_{k+\gamma} = (1-\gamma ) r_{k} + \gamma r^0_{k+1}  = r_k \\ \\
1832	      \mathcal R_L( x^{\alpha+1}_{k+1},r^{\alpha+1}_{k+\gamma}) = \mathcal
1833	      R(x^{\alpha}_{k+1},r^{\alpha}_{k+\gamma})  + \left[ \nabla_{x} \mathcal
1834	      R(x^{\alpha}_{k+1},r^{\alpha}_{k+\gamma})\right] (x^{\alpha+1}_{k+1}-x^{\alpha}_{k+1} ) + \\[2mm]
1835	      \qquad\qquad\qquad\qquad\qquad\qquad\left[ \nabla_{r} \mathcal R(x^{\alpha}_{k+1},r^{\alpha}_{k+\gamma})\right] (r^{\alpha+1}_{k+\gamma} - r^{\alpha}_{k+\gamma} ) =0
1836	  \end{cases}
1837
1838      What about :math:`r^0_{k+\gamma}` ?
1839
1840      The residu free is also defined (useful for implementation only):
1841
1842      .. math::
1843
1844	 \mathcal R _{\free}(x) \stackrel{\Delta}{=}  M(x - x_{k}) -h\theta f( x , t_{k+1}) - h(1-\theta)f(x_k,t_k).
1845
1846      We get
1847
1848      .. math::
1849
1850	 \mathcal R (x^{\alpha}_{k+1},r^{\alpha}_{k+\gamma}) = \fbox{$\mathcal R^{\alpha}_{k+1} \stackrel{\Delta}{=}  \mathcal R_{\free}(x^{\alpha}_{k+1} )  - h r^{\alpha}_{k+\gamma}$}\label{eq:full-rfree-1}
1851
1852      .. math::
1853
1854	 \mathcal R
1855	 _{\free}(x^{\alpha}_{k+1} )=\fbox{$ \mathcal R _{\free, k+1} ^{\alpha} \stackrel{\Delta}{=}  M(x^{\alpha}_{k+1} - x_{k}) -h\theta f( x^{\alpha}_{k+1} , t_{k+1}) - h(1-\theta)f(x_k,t_k)$}
1856
1857      The computation of the Jacobian of :math:`\mathcal R` with respect to
1858      :math:`x`, denoted by :math:`   W^{\alpha}_{k+1}` leads to
1859
1860      .. math::
1861
1862	 \label{eq:full-NL9}
1863	    \begin{array}{l}
1864	     W^{\alpha}_{k+1} \stackrel{\Delta}{=} \nabla_{x} \mathcal R (x^{\alpha}_{k+1})= M - h  \theta \nabla_{x} f(  x^{\alpha}_{k+1}, t_{k+1} ).\\
1865	  \end{array}
1866
1867      At each time–step, we have to solve the following linearized problem,
1868
1869      .. math::
1870
1871	 \label{eq:full-NL10}
1872	     \mathcal R^{\alpha}_{k+1} + W^{\alpha}_{k+1} (x^{\alpha+1}_{k+1} -
1873	     x^{\alpha}_{k+1}) - h  (r^{\alpha+1}_{k+\gamma} - r^{\alpha}_{k+\gamma} )  =0 ,
1874
1875      By using ([eq:full-rfree-1]), we get
1876
1877      .. math::
1878
1879	 \label{eq:full-rfree-2}
1880	   \mathcal R _{\free}(x^{\alpha}_{k+1})  - h  r^{\alpha+1}_{k+\gamma}   + W^{\alpha}_{k+1} (x^{\alpha+1}_{k+1} -
1881	     x^{\alpha}_{k+1})  =0
1882
1883      .. math::
1884
1885	 \boxed{ x^{\alpha+1}_{k+1} = h(W^{\alpha}_{k+1})^{-1}r^{\alpha+1}_{\gamma+1} +x^\alpha_{\free}}
1886
1887      with :
1888
1889      .. math::
1890
1891	 \boxed{x^\alpha_{\free}\stackrel{\Delta}{=}x^{\alpha}_{k+1}-(W^{\alpha}_{k+1})^{-1}\mathcal R_{\free,k+1}^{\alpha} \label{eq:full-rfree-12}}
1892
1893      The matrix :math:`W` is clearly non singular for small :math:`h`.
1894
1895      Note that the linearization is equivalent to the case ([eq:rfree-2]) and
1896      ([eq:rfree-12]) with :math:`\gamma=1` and replacing :math:`r_{k+1}` by
1897      :math:`r_{k+\gamma}`.
1898
1899      Newton’s linearization of the second line of ([eq:full-toto1-ter])
1900      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1901
1902      The same operation is performed with the second equation of
1903      ([eq:full-toto1-ter])
1904
1905      .. math::
1906
1907	 \begin{array}{l}
1908	     \mathcal R_y(x,y,\lambda)=y-h(t_{k+\gamma},\gamma x + (1-\gamma) x_k ,\lambda) =0\\ \\
1909	   \end{array}
1910
1911      which is linearized as
1912
1913      .. math::
1914
1915	 \label{eq:full-NL9}
1916	   \begin{array}{l}
1917	     \mathcal R_{Ly}(x^{\alpha+1}_{k+1},y^{\alpha+1}_{k+\gamma},\lambda^{\alpha+1}_{k+\gamma}) = \mathcal
1918	     R_{y}(x^{\alpha}_{k+1},y^{\alpha}_{k+\gamma},\lambda^{\alpha}_{k+\gamma}) +
1919	     (y^{\alpha+1}_{k+\gamma}-y^{\alpha}_{k+\gamma})- \\[2mm] \qquad  \qquad \qquad \qquad  \qquad \qquad
1920	     \gamma C^{\alpha}_{k+1}(x^{\alpha+1}_{k+1}-x^{\alpha}_{k+1}) - D^{\alpha}_{k+\gamma}(\lambda^{\alpha+1}_{k+\gamma}-\lambda^{\alpha}_{k+\gamma})=0
1921	   \end{array}
1922
1923      This leads to the following linear equation
1924
1925      .. math::
1926
1927	 \boxed{y^{\alpha+1}_{k+\gamma} =  y^{\alpha}_{k+\gamma}
1928	   -\mathcal R^{\alpha}_{y,k+1}+ \\
1929	   \gamma C^{\alpha}_{k+1}(x^{\alpha+1}_{k+1}-x^{\alpha}_{k+1}) +
1930	   D^{\alpha}_{k+\gamma}(\lambda^{\alpha+1}_{k+\gamma}-\lambda^{\alpha}_{k+\gamma})}. \label{eq:full-NL11y}
1931
1932      with,
1933
1934      .. math::
1935
1936	 \begin{array}{l}
1937	   C^{\alpha}_{k+\gamma} = \nabla_xh(t_{k+1}, x^{\alpha}_{k+\gamma},\lambda^{\alpha}_{k+\gamma} ) \\ \\
1938	   D^{\alpha}_{k+\gamma} = \nabla_{\lambda}h(t_{k+1}, x^{\alpha}_{k+\gamma},\lambda^{\alpha}_{k+\gamma})
1939	  \end{array}
1940
1941      and
1942
1943      .. math::
1944
1945	 \fbox{$
1946	 \mathcal R^{\alpha}_{yk+1} \stackrel{\Delta}{=} y^{\alpha}_{k+\gamma} - h(x^{\alpha}_{k+\gamma},\lambda^{\alpha}_{k+\gamma})$}
1947
1948      Note that the linearization is equivalent to the case ([eq:NL11y]) by
1949      replacing :math:`\lambda_{k+1}` by :math:`\lambda_{k+\gamma}` and
1950      :math:`x_{k+1}` by :math:`x_{k+\gamma}`.
1951
1952      Newton’s linearization of the third line of ([eq:full-toto1-ter])
1953      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1954
1955      The same operation is performed with the third equation of
1956      ([eq:full-toto1-ter])
1957
1958      .. math::
1959
1960	 \begin{array}{l}
1961	     \mathcal R_r(r,\lambda)=r-g(\lambda,t_{k+1}) =0\\ \\  \end{array}
1962
1963      which is linearized as
1964
1965      .. math::
1966
1967	 \label{eq:full-NL9}
1968	   \begin{array}{l}
1969	       \mathcal R_{L\lambda}(r^{\alpha+1}_{k+\gamma},\lambda^{\alpha+1}_{k+\gamma}) = \mathcal
1970	       R_{r,k+\gamma}^{\alpha} + (r^{\alpha+1}_{k+\gamma} - r^{\alpha}_{k+\gamma}) - B^{\alpha}_{k+\gamma}(\lambda^{\alpha+1}_{k+\gamma} -
1971	       \lambda^{\alpha}_{k+\gamma})=0
1972	     \end{array}
1973
1974      .. math::
1975
1976	 \label{eq:full-rrL}
1977	   \begin{array}{l}
1978	     \boxed{r^{\alpha+1}_{k+\gamma} = g(\lambda ^{\alpha}_{k+\gamma},t_{k+\gamma}) -B^{\alpha}_{k+\gamma}
1979	       \lambda^{\alpha}_{k+\gamma} + B^{\alpha}_{k+\gamma} \lambda^{\alpha+1}_{k+\gamma}}
1980	   \end{array}
1981
1982      with,
1983
1984      .. math::
1985
1986	 \begin{array}{l}
1987	   B^{\alpha}_{k+\gamma} = \nabla_{\lambda}g(\lambda ^{\alpha}_{k+\gamma},t_{k+\gamma})
1988	  \end{array}
1989
1990      and the residue for :math:`r`:
1991
1992      .. math::
1993
1994	 \boxed{\mathcal
1995	       R_{rk+\gamma}^{\alpha} = r^{\alpha}_{k+\gamma} - g(\lambda ^{\alpha}_{k+\gamma},t_{k+\gamma})}
1996
1997      Note that the linearization is equivalent to the case ([eq:rrL]) by
1998      replacing :math:`\lambda_{k+1}` by :math:`\lambda_{k+\gamma}` and
1999      :math:`x_{k+1}` by :math:`x_{k+\gamma}`.
2000
2001      Reduction to a linear relation between :math:`x^{\alpha+1}_{k+1}` and :math:`\lambda^{\alpha+1}_{k+\gamma}`
2002      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
2003
2004      Inserting ([eq:full-rrL]) into ([eq:full-rfree-12]), we get the
2005      following linear relation between :math:`x^{\alpha+1}_{k+1}` and
2006      :math:`\lambda^{\alpha+1}_{k+1}`,
2007
2008      .. math::
2009
2010	 \begin{array}{l}
2011	      x^{\alpha+1}_{k+1} = h(W^{\alpha}_{k+1} )^{-1}\left[g(\lambda^{\alpha}_{k+\gamma},t_{k+\gamma}) +
2012	     B^{\alpha}_{k+\gamma} (\lambda^{\alpha+1}_{k+\gamma} - \lambda^{\alpha}_{k+\gamma}) \right ] +x^\alpha_{free}
2013	 \end{array}
2014
2015      that is
2016
2017      .. math::
2018
2019	 \begin{array}{l}
2020	 \boxed{x^{\alpha+1}_{k+1}=x_p + h (W^{\alpha}_{k+1})^{-1}    B^{\alpha}_{k+\gamma} \lambda^{\alpha+1}_{k+\gamma}}
2021	    \end{array}
2022	   \label{eq:full-rfree-13}
2023
2024      with
2025
2026      .. math::
2027
2028	 \boxed{x_p \stackrel{\Delta}{=}  h(W^{\alpha}_{k+1} )^{-1}\left[g(\lambda^{\alpha}_{k+\gamma},t_{k+\gamma}) -B^{\alpha}_{k+\gamma} (\lambda^{\alpha}_{k+\gamma}) \right ] +x^\alpha_{free}}
2029
2030      Reduction to a linear relation between :math:`y^{\alpha+1}_{k+\gamma}` and :math:`\lambda^{\alpha+1}_{k+\gamma}`
2031      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
2032
2033      Inserting ([eq:full-rfree-13]) into ([eq:full-NL11y]), we get the
2034      following linear relation between :math:`y^{\alpha+1}_{k+1}` and
2035      :math:`\lambda^{\alpha+1}_{k+1}`,
2036
2037      .. math::
2038
2039	 \begin{array}{l}
2040	  y^{\alpha+1}_{k+1} = y_p + \left[ h \gamma C^{\alpha}_{k+\gamma} ( W^{\alpha}_{k+1})^{-1}  B^{\alpha}_{k+1} + D^{\alpha}_{k+1} \right]\lambda^{\alpha+1}_{k+1}
2041	    \end{array}
2042
2043      with
2044
2045      .. math::
2046
2047	 y_p = y^{\alpha}_{k+1} -\mathcal R^{\alpha}_{yk+1} + \gamma C^{\alpha}_{k+1}(x_q) - D^{\alpha}_{k+1} \lambda^{\alpha}_{k+1}
2048
2049      that is
2050
2051      .. math::
2052
2053	 \boxed{
2054	 y_p =  h(x^{\alpha}_{k+\gamma},\lambda^{\alpha}_{k+\gamma}) + \gamma C^{\alpha}_{k+1}(x_q) - D^{\alpha}_{k+1} \lambda^{\alpha}_{k+1} }
2055
2056      The linear case
2057      '''''''''''''''
2058
2059      .. math::
2060
2061	 \begin{array}{lcl}
2062	     y_p &=&  h(x^{\alpha}_{k+\gamma},\lambda^{\alpha}_{k+\gamma}) + \gamma C^{\alpha}_{k+1}(x_q) - D^{\alpha}_{k+1} \lambda^{\alpha}_{k+1}\\
2063		 &=&  C^{\alpha}_{k+1} x^{\alpha}_{k+\gamma} + D^{\alpha}_{k+1}\lambda^{\alpha}_{k+\gamma}  + \gamma C^{\alpha}_{k+1}(x_q) - D^{\alpha}_{k+1} \lambda^{\alpha}_{k+1} \\
2064		 &=& C^{\alpha}_{k+1}  (x^{\alpha}_{k+\gamma} + \gamma x_p - \gamma x^{\alpha}_{k+1} ) \\
2065		 &=& C^{\alpha}_{k+1}  ((1-\gamma) x_{k} + \gamma x_{free} ) \text {since } x_p =x_{free}
2066	 \end{array}
2067
2068      Implementation details
2069      ''''''''''''''''''''''
2070
2071      For the moment (Feb. 2011), we set
2072      :math:`x_q=(1-\gamma) x_{k} + \gamma x_{free} ` in the linear case. The
2073      nonlinear case is not yet implemented since we need to change the
2074      management of `` Halpha`` Relation to be able to compute the mid–point
2075      values.
2076
2077      Newton’s linearization for Lagrangian systems
2078      =============================================
2079
2080      +-----------+------------------+
2081      | author    | V. Acary         |
2082      +===========+==================+
2083      | date      | Sept, 20, 2011   |
2084      +-----------+------------------+
2085      | version   |                  |
2086      +-----------+------------------+
2087
2088      This section is devoted to the implementation and the study of the
2089      algorithm. The interval of integration is :math:`[0,T]`, :math:`T>0`,
2090      and a grid :math:`t_{0}=0`, :math:`t_{k+1}=t_{k}+h`, :math:`k \geq 0`,
2091      :math:`t_{N}=T` is constructed. The approximation of a function
2092      :math:`f(\cdot)` on :math:`[0,T]` is denoted as :math:`f^{N}(\cdot)`,
2093      and is a piecewise constant function, constant on the intervals
2094      :math:`[t_{k},t_{k+1})`. We denote :math:`f^{N}(t_{k})` as
2095      :math:`f_{k}`. The time-step is :math:`h>0`.
2096
2097      Various second order dynamical systems with input/output relations
2098      ------------------------------------------------------------------
2099
2100      Lagrangian dynamical systems
2101      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2102
2103      The class LagrangianDS defines and computes a generic ndof-dimensional
2104      Lagrangian Non Linear Dynamical System of the form :
2105
2106      .. math::
2107
2108	 \begin{cases}
2109	     M(q,z) \dot v + N(v, q, z) + F_{Int}(v , q , t, z) = F_{Ext}(t, z) + p \\
2110	     \dot q = v
2111	   \end{cases}
2112
2113      where
2114
2115      -  :math:`q \in R^{ndof} ` is the set of the generalized coordinates,
2116
2117      -  :math:` \dot q =v \in R^{ndof} ` the velocity, i. e. the time
2118	 derivative of the generalized coordinates (Lagrangian systems).
2119
2120      -  :math:` \ddot q =\dot v \in R^{ndof} ` the acceleration, i. e. the
2121	 second time derivative of the generalized coordinates.
2122
2123      -  :math:` p \in R^{ndof} ` the reaction forces due to the Non Smooth
2124	 Interaction.
2125
2126      -  :math:` M(q) \in R^{ndof \times ndof}
2127	    ` is the inertia term saved in the SiconosMatrix mass.
2128
2129      -  :math:`
2130	    N(\dot q, q) \in R^{ndof}` is the non linear inertia term saved in
2131	 the SiconosVector \_NNL.
2132
2133      -  :math:` F_{Int}(\dot q , q , t) \in
2134	    R^{ndof} ` are the internal forces saved in the SiconosVector
2135	 fInt.
2136
2137      -  :math:` F_{Ext}(t) \in R^{ndof} ` are the external forces saved in
2138	 the SiconosVector fExt.
2139
2140      -  :math:` z \in R^{zSize}` is a vector of arbitrary algebraic
2141	 variables, some sort of discrete state.
2142
2143      The equation of motion is also shortly denoted as:
2144
2145      .. math::
2146
2147	 M(q,z) \dot v = F(v, q, t, z) + p
2148
2149      where :math:`F(v, q, t, z) \in R^{ndof} ` collects the total forces
2150      acting on the system, that is
2151
2152      .. math::
2153
2154	 F(v, q, t, z) =  F_{Ext}(t, z) -  NNL(v, q, z) + F_{Int}(v, q , t, z)
2155
2156      This vector is stored in the SiconosVector \_Forces
2157
2158      Fully nonlinear case
2159      ~~~~~~~~~~~~~~~~~~~~
2160
2161      Let us introduce the following system,
2162
2163      .. math::
2164
2165	 \label{eq:FullyNonLinear}
2166	   \begin{cases}
2167	     M(q,z) \dot v = F(v, q, t, z) + p  \\
2168	     \dot q = v \\
2169	     y = h(t,q,\lambda) \\
2170	     p = g(t,q,\lambda)
2171	   \end{cases}
2172
2173      where :math:`\lambda(t) \in {\mbox{\rm $I\!\!R$}}^m` and
2174      :math:`y(t) \in {\mbox{\rm $I\!\!R$}}^m` are complementary variables
2175      related through a multi-valued mapping. According to the class of
2176      systems, we are studying, the function :math:`F` , :math:`h` and
2177      :math:`g` are defined by a fully nonlinear framework or by affine
2178      functions. This fully nonlinear case is not implemented in Siconos yet.
2179      This fully general case is not yet implemented in Siconos.
2180
2181      Lagrangian Rheonomous relations
2182      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2183
2184      .. math::
2185
2186	 \label{eq:RheonomousNonLinear}
2187	   \begin{cases}
2188	     M(q,z) \dot v = F(v, q, t, z) + p \\
2189	     \dot q = v \\
2190	     y = h(t,q) \\
2191	     p = G(t,q)\lambda)
2192	   \end{cases}
2193
2194      Lagrangian Scleronomous relations
2195      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2196
2197      .. math::
2198
2199	 \label{eq:ScleronomousNonLinear}
2200	   \begin{cases}
2201	     M(q,z) \dot v  = F(v, q, t, z) + p  \\
2202	     \dot q = v \\
2203	     y = h(q) \\
2204	     p = G(q)\lambda
2205	   \end{cases}
2206
2207      Fully Linear case
2208      '''''''''''''''''
2209
2210      .. math::
2211
2212	 \label{eq:FullyLinear}
2213	   \begin{cases}
2214	     M \dot v   +C v + Kq = F_{Ext}(t, z) + p  \\
2215	     \dot q = v \\
2216	     y = C q + e + D\lambda  + F z \\
2217	     p = C^T\lambda
2218	   \end{cases}
2219
2220      Moreau–Jean event-capturing scheme
2221      ----------------------------------
2222
2223      In this section, a time-discretization method of the Lagrange dynamical
2224      equation ([eq:11]), consistent with the nonsmooth character of the
2225      solution, is presented. It is assumed in this section, as in the other
2226      sections, that :math:`v^+(\cdot)=\dot{q}^{+}(\cdot)` is a locally
2227      bounded variation function. The equation of motion reads as,
2228
2229      .. math::
2230
2231	 \label{eq:11-b}
2232	   \begin{cases}
2233	     M(q(t)) {dv} +N(q(t),v^{+}(t)) dt+  F_{\mathrm{int}}(t, q(t), v^+(t))\,dt = F_{\mathrm{ext}}(t)\,dt + dr \\ \\
2234	    v^+(t)=\dot{q}^+(t) \\ \\
2235	   q(0)=q_{0} \in {\mathcal C}(0),\;\dot{q}(0^{-})=\dot{q}_{0}
2236	   \end{cases}
2237
2238      We also assume that :math:`F_{\mathrm{int}}(\cdot)` and
2239      :math:`F_{\mathrm{ext}}(\cdot)` are continuous with respect to time.
2240      This assumption is made for the sake of simplicity to avoid the notation
2241      :math:`F^+_{\mathrm{int}}(\cdot)` and :math:`F^+_{\mathrm{ext}}(\cdot)`.
2242      Finally, we will condense the nonlinear inertia terms and the internal
2243      forces to lighten the notation. We obtain
2244
2245      .. math::
2246
2247	 \label{eq:11-c}
2248	   \begin{cases}
2249	     M(q(t)) {dv} + F(t, q(t), v^+(t))\,dt = F_{\mathrm{ext}}(t)\,dt + dr \\ \\
2250	    v^+(t)=\dot{q}^+(t) \\ \\
2251	   q(0)=q_{0} \in {\mathcal C}(0),\;\dot{q}(0^{-})=\dot{q}_{0}
2252	   \end{cases}
2253
2254      The NSCD method, also known as the Contact Dynamics (CD) is due to the
2255      seminal works of J.J.  and M.  (See also ). A lot of improvements and
2256      variants have been proposed over the years. In this Section, we take
2257      liberties with these original works, but we choose to present a version
2258      of the NSCD method which preserves the essential of the original work.
2259      Some extra developments and interpretations are added which are only
2260      under our responsibility. To come back to the source of the NSCD method,
2261      we encourage to read the above references.
2262
2263      The Linear Time-invariant NonSmooth Lagrangian Dynamics
2264      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2265
2266      For the sake of simplicity of the presentation, the linear
2267      time-invariant case is considered first. The nonlinear case will be
2268      examined later in this chapter.
2269
2270      .. math::
2271
2272	 \label{eq:11-a}
2273	   \begin{cases}
2274	     M dv + (K q(t) + C v^+(t))\,dt = F_{\mathrm{ext}}(t)\,dt + dr  \\ \\
2275	     v^+(t)=\dot{q}^+(t)
2276	   \end{cases}
2277
2278      Time–discretization of the Dynamics
2279      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2280
2281      Integrating both sides of this equation over a time step
2282      :math:`(t_k,t_{k+1}]` of length :math:`h>0`, one obtains
2283
2284      .. math::
2285
2286	 \begin{aligned}
2287	   \begin{cases}
2288	     \displaystyle \int_{(t_k,t_{k+1}]} M dv + \int_{t_k}^{t_{k+1}} (C v^+(t)
2289	       + K q(t)) \,dt = \displaystyle \int_{t_k}^{t_{k+1}} F_{\mathrm{ext}}\,dt +
2290		 \displaystyle \int_{(t_k,t_{k+1}]} dr \:, \\ \\
2291	      q(t_{k+1}) = q(t_{k}) + \displaystyle \int_{t_k}^{t_{k+1}} v^+(t)\,dt
2292	    \end{cases}\end{aligned}
2293
2294      By definition of the differential measure :math:`dv`, we obtain
2295
2296      .. math::
2297
2298	 \begin{aligned}
2299	 \label{eq:19}
2300	 &  \displaystyle \int_{(t_k,t_{k+1}]} M \,dv = M \int_{(t_k,t_{k+1}]}\,dv = M\,(v^+(t_{k+1})-v^+(t_{k}))  &\end{aligned}
2301
2302      Note that the right velocities are involved in this formulation. The
2303      impulsion :math:`\displaystyle \int_{(t_k,t_{k+1}]} dr` of the reaction
2304      on the time interval :math:`(t_k,t_{k+1}]` emerges as a natural unknown.
2305      The equation of the nonsmooth motion can be written under an integral
2306      form as:
2307
2308      .. math::
2309
2310	 \begin{aligned}
2311	   \begin{cases}
2312	      M\,(v(t_{k+1})-v(t_{k})) =   \displaystyle   \int_{t_k}^{t_{k+1}} (- C v^+(t)
2313	       - K q(t) +  F_{\mathrm{ext}}(t))\,dt +
2314		 \displaystyle \int_{(t_k,t_{k+1}]} dr \:, \\ \\
2315	      q(t_{k+1}) = q(t_{k}) + \displaystyle \int_{t_k}^{t_{k+1}} v^+(t)\,dt
2316	    \end{cases}\end{aligned}
2317
2318      Choosing a numerical method boils down to choose a method of
2319      approximation for the remaining integral terms. Since discontinuities of
2320      the derivative :math:`v(\cdot)` are to be expected if some shocks are
2321      occurring, i.e.. :math:`dr` has some atoms within the interval
2322      :math:`(t_k,t_{k+1}]`, it is not relevant to use high order
2323      approximations integration schemes for :math:`dr` (this was pointed out
2324      in remark [remark1023]). It may be shown on some examples that, on the
2325      contrary, such high order schemes may generate artefact numerical
2326      oscillations (see ).
2327
2328      The following notation will be used:
2329
2330      -  :math:`q_{k}` is an approximation of :math:`q(t_{k})` and
2331	 :math:`q_{k+1}` is an approximation of :math:`q(t_{k+1})`,
2332
2333      -  :math:`v_{k}` is an approximation of :math:`v^+(t_{k})` and
2334	 :math:`v_{k+1}` is an approximation of :math:`v^+(t_{k+1})`,
2335
2336      -  :math:`p_{k+1}` is an approximation of
2337	 :math:` \displaystyle \int_{(t_k,t_{k+1}]} \,dr`.
2338
2339      A popular first order numerical scheme, the so called
2340      :math:`\theta`-method, is used for the term supposed to be sufficiently
2341      smooth:
2342
2343      .. math::
2344
2345	 \begin{aligned}
2346	   \displaystyle \int_{t_k}^{t_{k+1}} C v + K q \,dt  &\approx&
2347	   h \left[ \theta (C v_{k+1}+K q_{k+1}) + (1-\theta) (C v_{k}+K q_{k}) \right]   \nonumber \\
2348	   \displaystyle \int_{t_k}^{t_{k+1}} F_{\mathrm{ext}}(t) \,dt &\approx&
2349	   h\left[\theta  (F_{\mathrm{ext}})_{k+1}+(1-\theta)  (F_{\mathrm{ext}})_{k}  \right]  \nonumber \end{aligned}
2350
2351      The displacement, assumed to be absolutely continuous, is approximated
2352      by:
2353
2354      .. math::
2355
2356	 \begin{aligned}
2357	 &  q_{k+1} = q_{k} +  h\,\left[\theta v_{k+1}+(1-\theta) v_{k}  \right] & \nonumber\end{aligned}
2358
2359      Taking into account all these discretizations, the following
2360      time-discretized equation of motion is obtained:
2361
2362      .. math::
2363
2364	 \label{eq:NSCD-discret}
2365	 \begin{cases}
2366	     M (v_{k+1}-v_{k}) + h\left[\theta  (C  v_{k+1}+K q_{k+1}) + (1-\theta) (C v_{k}+K q_{k})  \right] = \\ \\
2367	     \quad\quad\quad\quad\quad = h\left[\theta  (F_{\mathrm{ext}})_{k+1}+(1-\theta)  (F_{\mathrm{ext}})_{k}  \right] + p_{k+1} \\  \\
2368	     q_{k+1} = q_{k} +  h\left[\theta v_{k+1}+(1-\theta) v_{k} \right]
2369	 \end{cases}
2370
2371      Finally, introducing the expression of :math:`q_{k+1}` in the first
2372      equation of ([eq:NSCD-discret]), one obtains:
2373
2374      .. math::
2375
2376	 \begin{aligned}
2377	   \label{eq:23}
2378	 &  \left[M+h\theta C + h^2 \theta^2 K\right] (v_{k+1} -v_{k}) = - h  C v_{k} - h K q_{k} - h^2 \theta  K v_{k} & \nonumber \\ \nonumber \\
2379	 &+  h\left[\theta  (F_{\mathrm{ext}})_{k+1})+(1-\theta)  (F_{\mathrm{ext}})_{k}  \right]  + p_{k+1}  \:, &\end{aligned}
2380
2381      which can be written as:
2382
2383      .. math::
2384
2385	 \begin{aligned}
2386	   \label{eq:24}
2387	    v_{k+1} = v_{\mathrm{free}}  + \widehat{M}^{-1} p_{k+1}\end{aligned}
2388
2389      where,
2390
2391      -  the matrix
2392
2393	 .. math::
2394
2395	 \widehat{M} = \left[M+h\theta C + h^2 \theta^2 K \right]  \label{eq:2002}
2396
2397	 is usually called the iteration matrix.
2398
2399      -  The vector
2400
2401	 .. math::
2402
2403	    \label{eq:2003}
2404	    \begin{array}{ll}
2405	    v_{\mathrm{free}}  & = v_{k} + \widehat{M}^{-1} \left[   - h  C v_{k} - h K q_{k} - h^2 \theta  K v_{k} \right. \\ \\
2406	    & \left. +  h\left[ \theta  (F_{\mathrm{ext}})_{k+1})+(1-\theta)  (F_{\mathrm{ext}})_{k} \right] \right]
2407	    \end{array}
2408
2409	 is the so-called “free” velocity, i.e., the velocity of the system
2410	 when reaction forces are null.
2411
2412      Comments
2413      ^^^^^^^^
2414
2415      Let us make some comments on the above developments:
2416
2417      -  The iteration matrix
2418	 :math:` \widehat{M} = \left[M+h\theta C + h^2 \theta^2 K \right] ` is
2419	 supposed to be invertible, since the mass matrix :math:`M` is usually
2420	 positive definite and :math:`h` is supposed to be small enough. The
2421	 matrices :math:`C` and :math:`K` are usually semi-definite positive
2422	 since rigid motions are allowed to bodies.
2423
2424      -  When :math:`\theta=0`, the :math:`\theta`-scheme is the explicit
2425	 Euler scheme. When :math:`\theta=1`, the :math:`\theta`-scheme is the
2426	 fully implicit Euler scheme. When dealing with a plain ODE
2427
2428	 .. math::
2429
2430	 M\ddot{q}(t)  + C \dot{q}(t) + K q(t)  = F(t)
2431
2432	 the :math:`\theta-`\ scheme is unconditionally stable for
2433	 :math:`0.5 < \theta \leq 1`. It is conditionally stable otherwise.
2434
2435      -  The equation ([eq:24]) is a linear form of the dynamical equation. It
2436	 appears as an affine relation between the two unknowns,
2437	 :math:`v_{k+1}` that is an approximation of the right derivative of
2438	 the Lagrange variable at time :math:`t_{k+1}`, and the impulse
2439	 :math:`p_{k+1}`. Notice that this scheme is fully implicit. Nonsmooth
2440	 laws have to be treated by implicit methods.
2441
2442      -  From a numerical point of view, two major features appear. First, the
2443	 different terms in the numerical algorithm will keep finite values.
2444	 When the time step :math:`h` vanishes, the scheme copes with finite
2445	 jumps. Secondly, the use of differential measures of the time
2446	 interval :math:`(t_k,t_{k+1}]`, i.e..,
2447	 :math:`dv((t_{k},t_{k+1}])=v^+(t_{k+1})-v^+(t_{k})` and
2448	 :math:`dr((t_{k},t_{k+1}])`, offers a rigorous treatment of the
2449	 nonsmooth evolutions. It is to be noticed that approximations of the
2450	 acceleration are ignored.
2451
2452      These remarks on the contact dynamics method might be viewed only as
2453      some numerical tricks. In fact, the mathematical study of the second
2454      order MDI by Moreau provides a sound mathematical ground to this
2455      numerical scheme. It is noteworthy that convergence results have been
2456      proved for such time-stepping schemes , see below.
2457
2458      The Nonlinear NonSmooth Lagrangian Dynamics
2459      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2460
2461      Time–discretization of the Dynamics
2462      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2463
2464      Starting from the nonlinear dynamics ([eq:11-c]), the integration of
2465      both sides of this equation over a time step :math:`(t_k,t_{k+1}]` of
2466      length :math:`h>0` yields
2467
2468      .. math::
2469
2470	 \begin{aligned}
2471	   \begin{cases}
2472	     \displaystyle \int_{(t_k,t_{k+1}]} M(q) dv + \int_{t_k}^{t_{k+1}} F(t, q(t), v^+(t)) \,dt = \displaystyle \int_{t_k}^{t_{k+1}} F_{\mathrm{ext}}(t)\,dt +
2473		 \displaystyle \int_{(t_k,t_{k+1}]} dr \:, \\ \\
2474	      q(t_{k+1}) = q(t_{k}) + \displaystyle \int_{t_k}^{t_{k+1}} v^+(t)\,dt
2475	    \end{cases}\end{aligned}
2476
2477      The first term is generally approximated by
2478
2479      .. math::
2480
2481	 \label{eq:19-NL}
2482	   \displaystyle \int_{(t_k,t_{k+1}]} M(q) \,dv \approx  M(q_{k+\gamma})\,(v_{k+1}-v_{k})
2483
2484      where :math:`q_{k+\gamma}` generalizes the standard notation for
2485      :math:`\gamma \in [0,1]` such that
2486
2487      .. math::
2488
2489	 \label{eq:NL1}
2490	   q_{k+\gamma} = (1-\gamma) q_{k} + \gamma\,  q_{k+1}
2491
2492      The *a priori* smooth terms are evaluated with a :math:`\theta`-method,
2493      chosen in this context for its energy conservation ability,
2494
2495      .. math::
2496
2497	 \begin{aligned}
2498	   \displaystyle \int_{t_k}^{t_{k+1}} F(t,q,v) \,dt  &\approx&
2499	   h  \tilde F_{k+\theta} \end{aligned}
2500
2501      where :math:`\tilde F_{k+\theta}` is an approximation with the following
2502      dependencies
2503
2504      .. math::
2505
2506	 \tilde F(t_k,q_k,v_k,t_{k+1},q_{k+1},v_{k+1},t_{k+\theta},q_{k+\theta},v_{k+\theta})
2507
2508      The mid-values :math:`t_{k+\theta},q_{k+\theta},v_{k+\theta}` are
2509      defined by
2510
2511      .. math::
2512
2513	 \label{eq:NSCD-discret-b}
2514	   \left\{\begin{array}{l}
2515	   t_{k+\theta} = \theta t_{k+1}+(1-\theta) t_{k}\\
2516	   q_{k+\theta} = \theta q_{k+1}+(1-\theta) q_{k}\\
2517	   v_{k+\theta} = \theta v_{k+1}+(1-\theta) v_{k}
2518	   \end{array}\right.,\quad  \theta \in [0,1]
2519
2520      [eq:Simo] The choice of the approximated function
2521      :math:`\tilde F(\cdot)` strongly depends on the nature of the internal
2522      forces that are modeled. For the linear elastic behavior of homogeneous
2523      continuum media, this approximation can be made by:
2524
2525      .. math::
2526
2527	 \tilde F_{k+\theta} = \frac 1 2 K{{\,:\,}}\left[E(q_{k})+E(q_{k+1})\right] {{\,:\,}}F(q_{k+1/2})
2528
2529      where :math:`E(:cdot)` is the Green-Lagrange strain tensor, which leads
2530      to an energy conserving algorithm as in . For nonlinear elastic other
2531      smooth nonlinear behaviors, we refer to the work of and references
2532      therein for the choice of the discretization and the value of
2533      :math:`\theta`.
2534
2535      The displacement, assumed to be absolutely continuous is approximated
2536      by:
2537
2538      .. math::
2539
2540	 \begin{aligned}
2541	 &  q_{k+1} = q_{k} +  h\,v_{k+\theta}  & \nonumber\end{aligned}
2542
2543      The following nonlinear time–discretized equation of motion is obtained:
2544
2545      .. math::
2546
2547	 \label{eq:NSCD-discret-nl}
2548	 \begin{cases}
2549	     M(q_{k+\gamma}) (v_{k+1}-v_{k}) + h \tilde F_{k+\theta} = p_{k+1} \\  \\
2550	     q_{k+1} = q_{k} +  h v_{k+\theta}
2551	 \end{cases}
2552
2553      In its full generality and at least formally, substituting the
2554      expression of :math:`q_{k+\gamma},q_{k+1}` and :math:`q_{k+\theta}`, the
2555      first line of the problem can be written under the form of a residue
2556      :math:`\mathcal R` depending only on :math:`v_{k+1}` such that
2557
2558      .. math::
2559
2560	 \label{eq:NL3}
2561	   \mathcal R (v_{k+1}) = p_{k+1}
2562
2563      In the last expression, we have omitted the dependence to the known
2564      values at the beginning the time–step, i.e. :math:`q_k` and :math:`v_k`.
2565
2566      Linearizing the Dynamics
2567      ^^^^^^^^^^^^^^^^^^^^^^^^
2568
2569      The system of equations ([eq:NL3]) for :math:`v_{k+1}` and
2570      :math:`p_{k+1}` can be linearized yielding a Newton’s procedure for
2571      solving it. This linearization needs the knowledge of the Jacobian
2572      matrix :math:`\nabla \mathcal R (\cdot)` with respect to its argument to
2573      construct the tangent linear model.
2574
2575      Let us consider that the we have to solve the following equations,
2576
2577      .. math::
2578
2579	 \label{eq:NL4}
2580	   \mathcal R (u) = 0
2581
2582      by a Newton’s method where
2583
2584      .. math::
2585
2586	 \label{eq:NL6}
2587	     \mathcal R (u) =   M(q_{k+\gamma} ) (v_{k+1}-v_{k}) + h \tilde F_{k+\theta}
2588
2589      The solution of this system of nonlinear equations is sought as a limit
2590      of the sequence :math:`\{ u^{\tau}_{k+1}\}_{\tau \in \nbN}` such that
2591
2592      .. math::
2593
2594	 \label{eq:NL7}
2595	    \begin{cases}
2596	      u^{0}_{k+1} = v_k \\ \\
2597	      \mathcal R_L( u^{\tau+1}_{k+1}) =  \mathcal R (u^{\tau}_{k+1}) + \nabla \mathcal R (u^{\tau}_{k+1} )(u^{\tau+1}_{k+1}-u^{\tau}_{k+1} ) =0
2598	  \end{cases}
2599
2600      In practice, all the nonlinearities are not treated in the same manner
2601      and the Jacobian matrices for the nonlinear terms involved in the
2602      Newton’s algorithm are only computed in their natural variables. In the
2603      following, we consider some of the most widely used approaches.
2604
2605      The Nonlinear Mass Matrix
2606      '''''''''''''''''''''''''
2607
2608      The derivation of the Jacobian of the first term of
2609      :math:`\mathcal R (\cdot)` implies to compute
2610
2611      .. math::
2612
2613	 \label{eq:NL2000}
2614	    \nabla_u  \left(M(q_{k+\gamma}(u) ) (u-v_{k})\right) \text{ with } q_{k+\gamma}(u) = q_k + \gamma h[(1-\theta) v_k+ \theta u].
2615
2616      One gets
2617
2618      .. math::
2619
2620	 \label{eq:NL8}
2621	   \begin{array}{ll}
2622	     \nabla_u  \left(M(q_{k+\gamma}(u) ) (u-v_{k})\right) &=   M(q_{k+\gamma}(u))  + \left[ \nabla_u M(q_{k+\gamma}(u) ) \right] (u-v_{k}) \\ \\
2623						  &=    M(q_{k+\gamma}(u)) + \left[h \gamma\theta \nabla_{q} M(q_{k+\gamma}(u))\right]  (u-v_{k})
2624	 \end{array}
2625
2626      The notation :math:`\nabla_{u}M(q_{k+\gamma}(u))(u-v_{k})` is to be
2627      understood as follows:
2628
2629      .. math::
2630
2631	 \nabla_{u}M(q_{k+\gamma}(u))(u-v_{k})=\frac{\partial}{\partial u}[M(q_{k+\gamma}(u))(u-v_{k})]
2632
2633      which is denoted as
2634      :math:`\frac{\partial M_{ij}}{\partial q^{l}}(q_{k+\gamma}(u))(u^{l}-v_{k}^{l})`
2635      in tensorial notation. [remarkBABAS]
2636
2637      A very common approximation consists in considering that the mass matrix
2638      evolves slowly with the configuration in a single time–step, that is,
2639      the term :math:`\nabla_{q} M(q_{k+\gamma})` is neglected and one gets,
2640
2641      .. math::
2642
2643	 \label{eq:NL9}
2644	     \nabla_u  (M(q_{k+\gamma}(u) ) (u-v_{k})) \approx  M(q_{k+\gamma}(u) )
2645
2646      The Jacobian matrix :math:`\nabla \mathcal R (\cdot)` is evaluated in
2647      :math:`u^{\tau}_{k+1}` which yields for the equation ([eq:NL9])
2648
2649      .. math::
2650
2651	 \label{eq:NL10}
2652	     \nabla_u  (M(q_{k+\gamma} ) (u^{\tau}_{k+1}-v_{k})) \approx  M(q_k + \gamma h [(1-\theta)v_k+\theta u^{\tau}_{k+1}] ) )
2653
2654      The prediction of the position which plays an important role will be
2655      denoted by
2656
2657      .. math::
2658
2659	 \label{eq:NL555}
2660	   \tilde q^{\tau}_{k+1}= q_k + \gamma h [(1-\theta)v_k+\theta u^{\tau}_{k+1}]
2661
2662      Very often, the matrix :math:`M(q_{k+\gamma})` is only evaluated at the
2663      first Newton’s iteration with :math:`u^{0}_{k+1}= v_k` leading the
2664      approximation for the whole step:
2665
2666      .. math::
2667
2668	 M(q_k + \gamma h [(1-\theta)v_k+\theta u^{\tau}_{k+1}] ) )\approx M(q_k + h \gamma v_k)
2669	 \label{eq:NL11}
2670
2671      Another way to interpret the approximation ([eq:NL11]) is to remark that
2672      this evaluation is just an explicit evaluation of the predictive
2673      position ([eq:NL555]) given by :math:`\theta=0`:
2674
2675      .. math::
2676
2677	 \label{eq:NL5}
2678	   \tilde q_{k+1}= q_k + h \gamma v_k
2679
2680      Using this prediction, the problem ([eq:NSCD-discret-nl]) is written as
2681      follows:
2682
2683      .. math::
2684
2685	 \label{eq:NSCD-discret2}
2686	 \begin{cases}
2687	     M(\tilde q_{k+1}) (v_{k+1}-v_{k}) + h \tilde F_{k+\theta} = p_{k+1} \\  \\
2688	     q_{k+1} = q_{k} +  h v_{k+\theta} \\ \\
2689	     \tilde q_{k+1}= q_k + h \gamma v_k
2690	 \end{cases}
2691
2692      The Nonlinear Term :math:`F(t,q,v)`
2693      '''''''''''''''''''''''''''''''''''
2694
2695      The remaining nonlinear term is linearized providing the Jacobian
2696      matrices of :math:`F(t,q,v)` with respect to :math:`q` and :math:`v`.
2697      This expression depends strongly on the choice of the approximation
2698      :math:`\tilde F_{k+\theta}`. Let us consider a pedagogical example,
2699      which is not necessarily the best as the Remark [eq:Simo] suggests but
2700      which is one of the simplest,
2701
2702      .. math::
2703
2704	 \label{eq:NL13}
2705	   \tilde F_{k+\theta} = (1-\theta) F(t_k,q_k,v_k) + \theta F(t_{k+1},q_{k+1},v_{k+1})
2706
2707      The computation of the Jacobian of
2708      :math:`  \tilde F_{k+\theta}(t,q(u),u)` for
2709
2710      .. math::
2711
2712	 q(u) = q_k+h[(1-\theta)v_k+\theta u]
2713
2714      is given for this example by
2715
2716      .. math::
2717
2718	 \label{eq:NL12}
2719	   \begin{array}{ll}
2720	     \nabla_u  \tilde F_{k+\theta}(t,q,u) &= \theta \nabla_u  F(t,q(u),u) \\ \\
2721	     &= \theta \nabla_q F(t_{k+1},q(u)   ,u) \nabla_{u} q(u) + \theta \nabla_{u} F(t,q(u),u)    \\ \\
2722	     &= h \theta^2 \nabla_q F(t, q(u)   ,u) + \theta \nabla_{u} F(t,q(u),u) \\
2723	   \end{array}
2724
2725      The standard tangent stiffness and damping matrices :math:`K_t` and
2726      :math:`C_t` are defined by
2727
2728      .. math::
2729
2730	 \label{eq:NL14}
2731	   \begin{array}{ll}
2732	   K_t(t,q,u) &= \nabla_q F(t, q   ,u) \\ \\
2733	   C_t(t,q,u) &= \nabla_u F(t, q   ,u) \\
2734	 \end{array}
2735
2736      In this case, the Jacobian of :math:`  \tilde F_{k+\theta}(t,q(u),u)`
2737      may be written as
2738
2739      .. math::
2740
2741	 \label{eq:NL15}
2742	   \begin{array}{ll}
2743	     \nabla_u  \tilde F_{k+\theta}(t,q,u) &=  h \theta^2  K_t(t,q,u) + \theta C_t(t, q   ,u)  \\
2744	   \end{array}
2745
2746      The complete Newton’s iteration can then be written as
2747
2748      .. math::
2749
2750	 \label{eq:NL16}
2751	    \widehat M^{\tau+1}_{k+1} (u^{\tau+1}_{k+1}-u^{\tau}_{k+1})  =  \mathcal R (u^{\tau}_{k+1}) +p^{\tau+1}_{k+1}
2752
2753      where the iteration matrix is evaluated as
2754
2755      .. math::
2756
2757	 \widehat M^{\tau+1}_{k+1} = (M(\tilde q^{\tau}_{k+1}) +  h^2 \theta^2  K_t(t_{k+1},q^{\tau}_{k+1},u^{\tau}_{k+1}) + \theta h C_t(t, q^{\tau}_{k+1}   ,u^{\tau}_{k+1}))\label{eq:NL17}
2758
2759      (compare with ([eq:2002])).
2760
2761      The choice of :math:`\theta=0` leads to an explicit evaluation of the
2762      position and the nonlinear forces terms. This choice can be interesting
2763      if the time–step has to be chosen relatively small due to the presence a
2764      very rapid dynamical process. This can be the case in crashes
2765      applications or in fracture dynamics . In this case, the iteration
2766      matrix reduces to
2767      :math:`\widehat M^{\tau+1}_{k+1} = M(\tilde q^{\tau}_{k+1})` avoiding
2768      the expensive evaluation of the tangent operator at each time–step.
2769
2770      This choice must not be misunderstood. The treatment of the nonsmooth
2771      dynamics continues to be implicit.
2772
2773      Schatzman–Paoli ’scheme and its linearizations
2774      ----------------------------------------------
2775
2776      The scheme
2777      ~~~~~~~~~~
2778
2779      | M(q\ :sub:`k`)(q\ :sub:`k+1`-2q:sub:`k`\ +q\ :sub:`k-1`) - h\ :sup:`2`
2780      F(v\ :sub:`k+`, q\ :sub:`k+`, t\ :sub:`k+theta`) = p\ :sub:`k+1`,
2781      | v\ :sub:`k+1`\ =,
2782      | y\ :sub:`k+1` = h()
2783      | p\ :sub:`k+1`\ = G() :sub:`k+1`
2784      | 0 y\ :sub:`k+1` :sub:`k+1` 0 .
2785
2786      Should we have
2787
2788      .. math::
2789
2790	 v_{k+1}={\displaystyle \frac{q_{k+1}-q_{k-1}}{2h}}
2791
2792      or
2793
2794      .. math::
2795
2796	 v_{k+1}={\displaystyle \frac{q_{k+1}-q_{k}}{h}}
2797
2798       ? This question is particularly important for the initialization and
2799      the proposed :math:`\theta`-scheme
2800
2801      The Newton linearization
2802      ~~~~~~~~~~~~~~~~~~~~~~~~
2803
2804      Let us define the residu on :math:`q`
2805
2806      .. math::
2807
2808	 \label{eq:residu}
2809	   \mathcal R(q) =   M(q)(q-2q_{k}+q_{k-1})  + h^2 F( (\theta v(q)+ (1-\theta) v_k),\theta q+ (1-\theta) q_k),  t_{k+\theta})  -  p_{k+1}
2810
2811      with
2812
2813      .. math::
2814
2815	 \label{eq:residu-linq1}
2816	   v(q) = {\displaystyle \frac{q-q_{k-1}}{2h}}
2817
2818      that is
2819
2820      .. math::
2821
2822	 \label{eq:residu-linq2}
2823	   \mathcal R(q) =   M(q)(q-2q_{k}+q_{k-1})  + h^2 F( (\theta {\displaystyle \frac{q-q_{k-1}}{2h}} + (1-\theta) v_k),\theta q+ (1-\theta) q_k),  t_{k+\theta})   -  p_{k+1}
2824
2825      Neglecting :math:`\nabla_q  M(q)` we get
2826
2827      .. math::
2828
2829	 \label{eq:iterationmatrix}
2830	  \nabla_q \mathcal R(q^\nu) =   M(q^\nu) + h^2  \theta K(q^\nu,v^\nu) + {\displaystyle \frac{1}{2}} h  \theta C(q^\nu,v^\nu)
2831
2832      and we have to solve
2833
2834      .. math::
2835
2836	 \label{eq:iterationloop}
2837	  \nabla_q \mathcal R(q^\nu)(q^{\nu+1}-q^\nu) = -  \mathcal R(q^\nu) .
2838
2839      Linear version of the scheme
2840      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2841
2842      | M(q\ :sub:`k+1`-2q:sub:`k`\ +q\ :sub:`k-1`) + h\ :sup:`2` (K
2843      q\ :sub:`k+`\ + C v\ :sub:`k+`) = p\ :sub:`k+1`,
2844      | v\ :sub:`k+1`\ =,
2845      | y\ :sub:`k+1` = h()
2846      | p\ :sub:`k+1`\ = G() :sub:`k+1`
2847      | 0 y\ :sub:`k+1` :sub:`k+1` 0 .
2848
2849      Let us define the residu on :math:`q`
2850
2851      .. math::
2852
2853	 \label{eq:residu-linq}
2854	   \mathcal R(q) =   M(q-2q_{k}+q_{k-1})  + h^2 (K(\theta q+ (1-\theta) q_k))+ C (\theta v(q)+ (1-\theta) v_k))  -  p_{k+1}
2855
2856      with
2857
2858      .. math::
2859
2860	 \label{eq:residu-linq1}
2861	   v(q) = {\displaystyle \frac{q-q_{k-1}}{2h}}
2862
2863      that is
2864
2865      .. math::
2866
2867	 \label{eq:residu-linq2}
2868	   \mathcal R(q) =   M(q-2q_{k}+q_{k-1})  + h^2 (K(\theta q+ (1-\theta) q_k)))+  h^2 C (\theta {\displaystyle \frac{q-q_{k-1}}{2h}}+ (1-\theta) v_k))  -  p_{k+1}
2869
2870      In this linear case, assuming that :math:`q^0=q^\nu = q_k`, we get
2871
2872      .. math::
2873
2874	 \label{eq:residu-linq2}
2875	   \mathcal R(q^\nu) =   M(-q_{k}+q_{k-1})  + h^2 (K q_k)+  h^2 C (\theta {\displaystyle \frac{q_k-q_{k-1}}{2h}}+ (1-\theta) v_k))  -  p_{k+1}
2876
2877      What about mixing OnestepIntegrator in Simulation?
2878      --------------------------------------------------
2879
2880      Let us consider that we have two simple linear Lagrangian Dynamical
2881      systems
2882
2883      .. math::
2884
2885	 \label{eq:FullyLinear1}
2886	   \begin{cases}
2887	     M_1 \dot v_1  = F_{1,Ext}(t) + p_1   \\
2888	     \dot q_1 = v_1
2889	   \end{cases}
2890
2891      and
2892
2893      .. math::
2894
2895	 \label{eq:FullyLinear1}
2896	   \begin{cases}
2897	     M_2 \dot v_2   = F_{2,Ext}(t) + p_2  \\
2898	     \dot q_2 = v_2 \\
2899	   \end{cases}
2900
2901      These Dynamical systems ([eq:FullyLinear1]) and ([eq:FullyLinear1])
2902      might numerically solved by choosing two different time–stepping
2903      schemes. Let us choose for instance Moreau’s scheme
2904      for([eq:FullyLinear1])
2905
2906      .. math::
2907
2908	 \label{eq:FullyLinear1-TS}
2909	   \begin{cases}
2910	     M_1 (v_{1,k+1}-v_{1,k})  = F_{1,Ext}(t_{k+1}) + p_{1,k+1}   \\
2911	     q_{1,k+1} = q_{k}+ h  v_{1,k+\theta}
2912	   \end{cases}
2913
2914      and Schatzman–Paoli’s sheme for ([eq:FullyLinear1])
2915
2916      .. math::
2917
2918	 \label{eq:FullyLinear1-TS}
2919	   \begin{cases}
2920	     M_2(q_{2,k+1}-2q_{2,k}+q_{2,k-1})  = F_{2,Ext}(t_{k+1}) + p_{2,k+1}  \\
2921	     v_{2,k+1} = {\displaystyle \frac{q_{2,k+1}-q_{2,k-1}}{2h}} \\
2922	   \end{cases}
2923
2924      Let us consider known that we have a LagrangianLinearTIR between this
2925      two DSs such that
2926
2927      .. math::
2928
2929	 \label{eq:LTIR-2DS}
2930	   \begin{array}{l}
2931	   y = q_1-q_2 \geq 0 \\ \\
2932	   p = \left[
2933	   \begin{array}{c}
2934	     1 \\
2935	     -1
2936	   \end{array}\right] \lambda
2937	 \end{array}
2938
2939      and a complementarity condition
2940
2941      .. math::
2942
2943	 \label{eq:CP}
2944	   0\leq y \perp \lambda \geq 0
2945
2946      Many questions are raised when we want to deal with the discrete
2947      systems:
2948
2949      -  Which rules should we use for the discretization of ([eq:CP]) ?
2950
2951	 .. math::
2952
2953	    \label{eq:CP-TS1}
2954		\text{ if } \bar y_{k+1}\leq 0, \text{ then }  0\leq \dot y _{k+1} + e \dot y_{k} \perp \hat \lambda_{k+1}\geq 0
2955
2956	 or
2957
2958	 .. math::
2959
2960	    \label{eq:CP-TS2}
2961		0\leq y _{k+1} + e y_{k-1} \perp \tilde \lambda_{k+1}\geq 0
2962
2963      -  Should we assume that :math:`y_{k+1} = q_{1,k+1}-q_{2,k+1}` and
2964	 :math:`\dot y_{k+1} = v_{1,k+1}-v_{2,k+1}`
2965
2966      -  How can we link :math:`\hat \lambda_{k+1}` and
2967	 :math:`\tilde \lambda_{k+1}` with :math:`p_{1,k+1}` and
2968	 :math:`p_{2,k+1}` ?
2969
2970      The third is the more difficult question and is seems that it is not
2971      reasonable to deal with two DS related by one interaction with different
2972      osi.In practice, this should be avoided in Siconos.
2973
2974      NewtonEuler Dynamical Systems
2975      =============================
2976
2977      +------------+-------------------------------------------------------------------+--------------+
2978      | Author     | O. Bonnefon                                                       | 2010         |
2979      +------------+-------------------------------------------------------------------+--------------+
2980      | Revision   | section [Sec:NE:sub:`m`\ otion] to [Sec:NE:sub:`T`\ D] V. Acary   | 05/09/2011   |
2981      +------------+-------------------------------------------------------------------+--------------+
2982      | Revision   | section [Sec:NE:sub:`m`\ otion] V. Acary                          | 01/06/2016   |
2983      +------------+-------------------------------------------------------------------+--------------+
2984      | Revision   | complete edition V. Acary                                         | 06/01/2017   |
2985      +------------+-------------------------------------------------------------------+--------------+
2986
2987      The equations of motion
2988      -----------------------
2989
2990      In the maximal coordinates framework, the most natural choice for the
2991      kinematic variables and for the formulation of the equations of motion
2992      is the Newton/Euler formalism, where the equation of motion describes
2993      the translational and rotational dynamics of each body using a specific
2994      choice of parameters. For the translational motion, the position of the
2995      center of mass :math:`x_{\cg}\in {\mbox{\rm $I\!\!R$}}^3` and its
2996      velocity :math:`v_{\cg} = \dot x_{\cg} \in {\mbox{\rm $I\!\!R$}}^3` is
2997      usually chosen. For the orientation of the body is usually defined by
2998      the rotation matrix :math:`R` of the body-fixed frame with respect to a
2999      given inertial frame.
3000
3001      For the rotational motion, a common choice is to choose the rotational
3002      velocity :math:`\Omega \in {\mbox{\rm $I\!\!R$}}^3` of the body
3003      expressed in the body–fixed frame. This choice comes from the
3004      formulation of a rigid body motion of a point :math:`X` in the inertial
3005      frame as
3006
3007      .. math::
3008
3009	 \label{eq:1}
3010	   x(t) = \Phi(t,X) = x_{\cg}(t) + R(t) X.
3011
3012      The velocity of this point can be written as
3013
3014      .. math::
3015
3016	 \label{eq:2}
3017	   \dot x(t) = v_{\cg}(t) + \dot R(t) X
3018
3019      Since :math:`R^\top R=I`, we get
3020      :math:`R^\top \dot R + \dot R^\top R =0`. We can conclude that it exists
3021      a matrix :math:`\tilde \Omega := R^\top \dot R ` such that
3022      :math:`\tilde \Omega + \tilde \Omega^\top=0`, i.e. a skew symmetric
3023      matrix. The notation :math:`\tilde \Omega` comes from the fact that
3024      there is a bijection between the skew symmetric matrix in
3025      :math:`{\mbox{\rm $I\!\!R$}}^{3\times3}` and
3026      :math:`{\mbox{\rm $I\!\!R$}}^3` such that
3027
3028      .. math::
3029
3030	 \label{eq:3}
3031	   \tilde \Omega x  = \Omega \times x, \quad \forall x\in {\mbox{\rm $I\!\!R$}}^3.
3032
3033      The rotational velocity is then related to the :math:`R` by :
3034
3035      .. math::
3036
3037	 \label{eq:angularvelocity}
3038	   \widetilde \Omega = R^\top \dot R, \text { or equivalently, } \dot R  = R \widetilde \Omega
3039
3040      Using these coordinates, the equations of motion are given by
3041
3042      .. math::
3043
3044	 \label{eq:motion-NewtonEuler}
3045	   \left\{\begin{array}{rcl}
3046	       m \;\dot v_{\cg}  & = &f(t,x_{\cg}, v_{\cg},  R,  \Omega) \\
3047	       I \dot \Omega + \Omega \times I \Omega &= & M(t,x_{\cg}, v_{\cg}, R, \Omega) \\
3048	       \dot x_{\cg}&=& v_{\cg}\\
3049	       \dot R  &=& R \widetilde \Omega
3050	     \end{array}
3051	   \right.
3052
3053      where :math:`m> 0` is the mass,
3054      :math:`I\in {\mbox{\rm $I\!\!R$}}^{3\times 3}` is the matrix of moments
3055      of inertia around the center of mass and the axis of the body–fixed
3056      frame.
3057
3058      The vectors :math:`f(\cdot)\in {\mbox{\rm $I\!\!R$}}^3` and
3059      :math:`M(\cdot)\in {\mbox{\rm $I\!\!R$}}^3` are the total forces and
3060      torques applied to the body. It is important to outline that the total
3061      applied forces :math:`f(\cdot)` has to be expressed in a consistent
3062      frame w.r.t. to :math:`v_{\cg}`. In our case, it hae to be expressed in
3063      the inertial frame. The same applies for the moment :math:`M` that has
3064      to be expressed in the body-fixed frame. If we consider a moment
3065      :math:`m(\cdot)` expressed in the inertial frame, then is has to be
3066      convected to the body–fixed frame thanks to
3067
3068      .. math::
3069
3070	 \label{eq:convected_moment}
3071	   M (\cdot) =R^\top  m (\cdot)
3072
3073      If we perform the time derivation of :math:`RR^\top =I` rather than
3074      :math:`R^\top R=I`, we get :math:`R \dot R^\top + \dot R R^\top =0`. We
3075      can conclude that it exists a matrix
3076      :math:`\tilde \omega := \dot R R^\top ` such that
3077      :math:`\tilde \omega + \tilde \omega^\top=0`, i.e. a skew symmetric
3078      matrix. Clearly, we have
3079
3080      .. math::
3081
3082	 \label{eq:4}
3083	    \tilde \omega = R \tilde \Omega R^\top
3084
3085      and it can be proved that is equivalent to :math:` \omega =R \Omega`.
3086      The vector :math:`\omega` is the rotational velocity expressed in the
3087      inertial frame. The equation of motion can also be expressed in the
3088      inertial frame as follows
3089
3090      .. math::
3091
3092	 \label{eq:motion-NewtonEuler-inertial}
3093	   \left\{\begin{array}{rcl}
3094	       m \;\dot v_{\cg}  & = &f(t,x_{\cg}, v_{\cg},  R,  R^T \omega) \\
3095	       J(R) \dot \omega + \omega \times J(R) \omega &= & m(t,x_{\cg}, v_{\cg}, R, \omega) \\
3096	       \dot x_{\cg}&=& v_{\cg}\\
3097	       \dot R  &=& \widetilde \omega R
3098	     \end{array}
3099	   \right.
3100
3101      where the matrix :math:`J(R) = R I R^T` is the inertia matrix in the
3102      inertial frame. Defining the angular momentum with respect to the
3103      inertial frame as
3104
3105      .. math::
3106
3107	 \label{eq:1}
3108	   \pi(t) = J(R(t)) \omega(t)
3109
3110      the equation of the angular motion is derived from the balance equation
3111      of the angular momentum
3112
3113      .. math::
3114
3115	 \label{eq:5}
3116	   \dot \pi(t) = m(t,x_{\cg}, v_{\cg}, R, \omega)).
3117
3118      For a given constant (time invariant) :math:`\tilde \Omega`, let us
3119      consider the differential equation
3120
3121      .. math::
3122
3123	 \label{eq:5}
3124	   \begin{cases}
3125	     \dot R(t) = R \tilde \Omega\\
3126	     R(0) = I
3127	   \end{cases}
3128
3129      Let us recall the definition of the matrix exponential,
3130
3131      .. math::
3132
3133	 \label{eq:6}
3134	   \exp(A) = \sum_{k=0}^{\infty} \frac {1}{k!} A^k
3135
3136      A trivial solution of is :math:`R(t) = \exp(t\tilde\Omega) ` since
3137
3138      .. math::
3139
3140	 \label{eq:7}
3141	   \frac {d}{dt}(\exp(At)) = \exp(At) A.
3142
3143      More generally, with the initial condition :math:`R(t_0)= R_0`, we get
3144      the solution
3145
3146      .. math::
3147
3148	 R(t) = R_0 \exp((t-t_0)\tilde\Omega)\label{eq:8}
3149
3150      Another interpretation is as follows. From a (incremental) rotation
3151      vector, :math:`\Omega` and its associated matrix :math:`\tilde \Omega`,
3152      we obtain a rotation matrix by the exponentation of
3153      :math:`\tilde \Omega`:
3154
3155      .. math::
3156
3157	 \label{eq:9}
3158	   R = \exp(\tilde\Omega).
3159
3160      Since we note that :math:`\tilde \Omega^ 3 = - \theta^2 \tilde \Omega`
3161      with :math:`\theta = \|\Omega\|`, it is possible to get a closed form of
3162      the matrix exponential of :math:`\tilde \Omega`
3163
3164      .. math::
3165
3166	 \label{eq:10}
3167	   \begin{array}[lcl]{lcl}
3168	     \exp(\tilde \Omega) &=& \sum_{k=0}^{\infty} \frac {1}{k!} (\tilde \Omega)^k \\
3169				 &=&  I_{3\times 3} + \sum_{k=1}^{\infty} \frac {(-1)^{k-1}}{(2k-1)!}  \theta ^{2k-1} \tilde \Omega + (\sum_{k=0}^{\infty} \frac {(-1)^{k-1}}{(2k)!} \theta)^{2k-2} \tilde \Omega^2\\[2mm]
3170				 &=&  I_{3\times 3} + \frac{\sin{\theta}} {\theta} \tilde \Omega +  \frac{(\cos{\theta}-1)}{\theta^2}\tilde \Omega^2
3171	   \end{array}
3172
3173      that is
3174
3175      .. math::
3176
3177	 \label{eq:11}
3178	   R =  I_{3\times 3} + \frac{\sin{\theta}} {\theta} \tilde \Omega +  \frac{(\cos{\theta}-1)}{\theta^2}\tilde \Omega^2
3179
3180      The formula is the Euler–Rodrigues formula that allows to compute the
3181      rotation matrix on closed form.
3182
3183      todo :
3184
3185      -  add the formulation in the inertial frame of the Euler equation with
3186	 :math:`\omega =R \Omega`.
3187
3188      -  Check that is the Euler-Rodrigues formula and not the Olinde
3189	 Rodrigues formula. (division by :math:`\theta`)
3190
3191      In the numerical practice, the choice of the rotation matrix is not
3192      convenient since it introduces redundant parameters. Since :math:`R`
3193      must belong to :math:`SO^+(3)`, we have also to satisfy
3194      :math:`\det(R)=1` and :math:`R^{-1}=R^\top`. In general, we use a
3195      reduced vector of parameters :math:`p\in{\mbox{\rm $I\!\!R$}}^{n_p}`
3196      such :math:`R = \Phi(p)` and :math:`\dot p = \psi(p)\Omega `. We denote
3197      by :math:`q` the vector of coordinates of the position and the
3198      orientation of the body, and by :math:`v` the body twist:
3199
3200      .. math::
3201
3202	 q \coloneqq \begin{bmatrix}
3203	     x_{\cg}\\
3204	     p
3205	   \end{bmatrix},\quad
3206	   v \coloneqq \begin{bmatrix}
3207	      v_{\cg}\\
3208	      \Omega
3209	    \end{bmatrix}.
3210
3211      The relation between :math:`v` and the time derivative of :math:`q` is
3212
3213      .. math::
3214
3215	 \label{eq:TT}
3216	   \dot q =
3217	   \begin{bmatrix}
3218	      \dot x_{\cg}\\
3219	      \psi(p) \dot p
3220	    \end{bmatrix}
3221	    =
3222	    \begin{bmatrix}
3223	      I & 0 \\
3224	      0 & \psi(p)
3225	    \end{bmatrix}
3226	    v
3227	    \coloneqq
3228	    T(q) v
3229
3230      with :math:`T(q) \in {\mbox{\rm $I\!\!R$}}^{{3+n_p}\times 6}`. Note that
3231      the twist :math:`v` is not directly the time derivative of the
3232      coordinate vector as a major difference with Lagrangian systems.
3233
3234      The Newton-Euler equation in compact form may be written as:
3235
3236      .. math::
3237
3238	 \label{eq:Newton-Euler-compact}
3239	 \boxed{ \left \{
3240	  \begin{aligned}
3241	   &\dot q=T(q)v, \\
3242	   & M \dot v = F(t, q, v)
3243	  \end{aligned}
3244	  \right.}
3245
3246      where :math:`M\in{\mbox{\rm $I\!\!R$}}^{6\times6}` is the total inertia
3247      matrix
3248
3249      .. math::
3250
3251	 M:= \begin{pmatrix}
3252	     m I_{3\times 3} & 0 \\
3253	     0 & I
3254	   \end{pmatrix},
3255
3256      and :math:`F(t, q, v)\in {\mbox{\rm $I\!\!R$}}^6` collects all the
3257      forces and torques applied to the body
3258
3259      .. math::
3260
3261	 F(t,q,v):= \begin{pmatrix}
3262	     f(t,x_{\cg},  v_{\cg}, R, \Omega ) \\
3263	     I \Omega \times \Omega + M(t,x_{\cg}, v_{\cg}, R, \Omega )
3264	   \end{pmatrix}.
3265
3266      When a collection of bodies is considered, we will use the same notation
3267      as in ([eq:Newton-Euler-compact]) extending the definition of the
3268      variables :math:`q,v` and the operators :math:`M,F` in a straightforward
3269      way.
3270
3271      Basic elements of Lie groups and Lie algebras theory.
3272      -----------------------------------------------------
3273
3274      Let us recall the definitions of the Lie group Theory taken from and .
3275
3276      Differential equation (evolving) on a manifold :math:`\mathcal M`
3277      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3278
3279      A :math:`d`-dimensional manifold :math:`\mathcal M` is a
3280      :math:`d`-dimensional smooth surface
3281      :math:` M\subset {\mbox{\rm $I\!\!R$}}^n` for some :math:`n\geq d`.
3282
3283      Let :math:`\mathcal M` be a :math:`d`-dimensional manifold and suppose
3284      that :math:`\rho(t) \in\mathcal M` is a smooth curve such that
3285      :math:`\rho(0) = p`. A tangent vector at :math:`p` is defined as
3286
3287      .. math::
3288
3289	 \label{eq:12}
3290	     a = \left. \frac{d}{dt} (\rho(t)) \right|_{t=0}.
3291
3292      The set of all tangents at :math:`p` is called the tangent space at
3293      :math:`p` and denoted by :math:`T\mathcal M|_p`. It has the structure of
3294      a linear space.
3295
3296      A (tangent) vector field on :math:`\mathcal M` is a smooth function
3297      :math:`F : \mathcal M \rightarrow T\mathcal M` such that
3298      :math:`F (p) \in T\mathcal M|_p` for all :math:`p \in \mathcal M`. The
3299      collection of all vector fields on :math:`\mathcal M` is denoted by
3300      :math:`\mathcal X(\mathcal M)`.
3301
3302      [Differential equation (evolving) on :math:`\mathcal M`] Let :math:`F`
3303      be a tangent vector field on :math:`\mathcal M`. By a differential
3304      equation (evolving) on :math:`\mathcal M` we mean a differential
3305      equation of the form
3306
3307      .. math::
3308
3309	 \dot y =F(y), t\geq  0, y(0)\in \mathcal M\label{eq:13}
3310
3311      where :math:`F \in \mathcal X(\mathcal M)`. Whenever convenient, we
3312      allow :math:`F` in  to be a function of time, :math:`F = F(t,y)`. The
3313      flow of :math:`F` is the solution operator
3314      :math:`\Psi_{t,F} : \mathcal M \rightarrow  \mathcal M` such that
3315
3316      .. math::
3317
3318	 y(t) = \Psi_{t,F} (y0).\label{eq:14}
3319
3320      Lie algebra and Lie group
3321      ~~~~~~~~~~~~~~~~~~~~~~~~~
3322
3323      [commutator] Given two vector fields :math:`F, G` on
3324      :math:`{\mbox{\rm $I\!\!R$}}^n` , the commutator :math:`H = [F, G]` can
3325      be computed componentwise at a given point
3326      :math:`y ∈ {\mbox{\rm $I\!\!R$}}^n` as
3327
3328      .. math::
3329
3330	 H_i(y)= \sum_{j=1}^n  G_j(y)\frac{\partial F_i(y)}{\partial y_j}   −F_j(y) \frac{\partial G_i(y)}{\partial y_j} .\label{eq:15}
3331
3332      [lemma:LieBracket] The commutator of vector fields satisfies the
3333      identities
3334
3335      .. math::
3336
3337	 \label{eq:16}
3338	   \begin{array}[lclr]{lclr}
3339	     \protect{[}F, G]&=& −\protect{[}G, F ] & (skew symmetry), \\
3340	     \protect{[} \alpha F,G] &=& \alpha \protect{[}F,G], \alpha \in {\mbox{\rm $I\!\!R$}}&  \\
3341	     \protect{[}F + G, H]&=& \protect{[}F, H] + \protect{[}G, H] & (bilinearity),\\
3342	     0 &=&  \protect{[}F,\protect{[}G,H]]+\protect{[}G,\protect{[}H,F]]+\protect{[}H,\protect{[}F,G]] &(Jacobi’s identity).
3343	   \end{array}
3344
3345      A Lie algebra of vector fields is a collection of vector fields which is
3346      closed under linear combination and commutation. In other words, letting
3347      :math:`\mathfrak g` denote the Lie algebra,
3348
3349      .. math::
3350
3351	 \begin{array}[lclr]{l}
3352	     B \in \mathfrak g \implies \alpha B \in \mathfrak  g \text{ for all } \alpha ∈ R .\\
3353	     B_1,B_2 \in\mathfrak g \implies B_1 +B_2, [B_1,B_2]\in\mathfrak g\label{eq:17}
3354	     \end{array}
3355
3356      Given a collection of vector fields :math:`B = {B_1 , B_2 , \ldots}`,
3357      the least Lie algebra of vector fields containing :math:`B` is called
3358      the Lie algebra generated by :math:`B`
3359
3360      A Lie algebra is a linear space :math:`V` equipped with a Lie bracket, a
3361      bilinear, skew-symmetric mapping
3362
3363      .. math::
3364
3365	 \label{eq:18}
3366	     [ \cdot , \cdot ] : V \times V \rightarrow V
3367
3368      that obeys identities from Lemma [lemma:LieBracket]
3369
3370      [(General) Lie algebra] A Lie algebra homomorphism is a linear map
3371      between two Lie algebras,
3372      :math:`\varphi : \mathfrak g \rightarrow \mathfrak h`, satisfying the
3373      identity
3374
3375      .. math::
3376
3377	 \varphi ([v, w]_{\mathfrak g}) = [\varphi(v), \varphi(w)]_{\mathfrak h}, v, w in \mathfrak g\label{eq:19}.
3378
3379      An invertible homomorphism is called an isomorphism.
3380
3381      A Lie group is a differential manifold :math:`\mathcal G` equipped with
3382      a product
3383      :math:`\glaw : \mathcal G\times \mathcal G →\rightarrow \mathcal  G`
3384      satisfying
3385
3386      .. math::
3387
3388	 \label{eq:20}
3389	     \begin{array}[lclr]{lr}
3390	       p \glaw(q \glaw r) = (p\glaw q)\glaw r, \forall  p, q, r ∈ \mathcal G &\text{(associativity)}\\
3391	       \exists I \in \mathcal G \text{ such that } I\glaw p = p \glaw I = p,  \forall p \in \mathcal G&\text{(identity element)}\ \\
3392	       \forall p \in \mathcal G, \exists  p^{-1}  \in \mathcal G \text{ such that }  p^{-1}\glaw p = I&\text{(inverse) }\ \\
3393	       \text{ The maps}  (p, r)  \rightarrow p\glaw r \text{ and }  p  \rightarrow p^{-1} \text{are smooth functions }&\text{(smoothness)}\
3394	     \end{array}
3395
3396      [Lie algebra :math:`\mathfrak g ` of a Lie group :math:`\mathcal G`] The
3397      Lie algebra :math:`\mathfrak g` of a Lie group :math:`\mathcal G` is
3398      defined as the linear space of all tangents to :math:`G` at the identity
3399      :math:`I`. The Lie bracket in :math:`\mathfrak g` is defined as
3400
3401      .. math::
3402
3403	 [a,b]= \left.\frac{\partial^2 }{\partial s\partial t} \rho(s)\sigma(t)\rho(-s)\right|_{s=t=0}\label{eq:21}
3404
3405      where :math:`\rho(s)` and :math:`\sigma(t)` are two smooth curves on
3406      :math:`\mathcal G` such that :math:`\rho(0) = \sigma(0) = I`, and
3407      :math:`\dot \rho(0) = a` and :math:`\dot \sigma(0) = b`.
3408
3409      Actions of a group :math:`\mathcal G` on manifold :math:`\mathcal M`
3410      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3411
3412      A left action of Lie Group :math:`\mathcal G` on a manifold
3413      :math:`\mathcal M` is a smooth map
3414      :math:`\Lambda^l: \mathcal G \times  \mathcal M \rightarrow \mathcal M`
3415      satisfying
3416
3417      .. math::
3418
3419	 \label{eq:22}
3420	   \begin{array}[lcl]{rcl}
3421	     \Lambda^l(I,y) &=& y, \quad \forall y \in \mathcal M \\
3422	     \Lambda^l(p,\Lambda(r,y)) &=& \Lambda^l(p\glaw r, y) , \quad \forall p,r \in \mathcal G,\quad  \forall y \in \mathcal M .
3423	   \end{array}
3424
3425      A right action of Lie Group :math:`\mathcal G` on a manifold
3426      :math:`\mathcal M` is a smooth map
3427      :math:`\Lambda^r: \mathcal M \times \mathcal G   \rightarrow \mathcal M`
3428      satisfying
3429
3430      .. math::
3431
3432	 \label{eq:23}
3433	   \begin{array}[lcl]{rcl}
3434	     \Lambda^r(y,I) &=& y, \quad \forall y \in \mathcal M \\
3435	     \Lambda^r(\Lambda(y,r), p) &=& \Lambda^r(y,  r\glaw p) , \quad \forall p,r \in \mathcal G,\quad  \forall y \in \mathcal M .
3436	   \end{array}
3437
3438      A given smooth curve
3439      :math:`S(\cdot) : t\in {\mbox{\rm $I\!\!R$}}\mapsto S(t)\in \mathcal G`
3440      in :math:`\mathcal G` such that :math:`S(0)= I` produces a flow
3441      :math:`\Lambda^l(S(t),\cdot)` (resp. :math:`\Lambda^r(\cdot, S(t))`) on
3442      :math:`\mathcal M` and by differentiation we find a tangent vector field
3443
3444      .. math::
3445
3446	 \label{eq:24}
3447	   F(y) = \left. \frac{d}{dt} (\Lambda^l(S(t),y) \right|_{t=0}\quad( \text{resp.  }  F(y) = \left. \frac{d}{dt} (\Lambda^r(y,S(t)) \right|_{t=0} )
3448
3449      that defines a ordinary differential equation on a Lie Group
3450
3451      .. math::
3452
3453	 \label{eq:25}
3454	   \dot y(t) = F(y(t)) = \left. \frac{d}{dt} (\Lambda^l(S(t),y) \right|_{t=0}  \quad( \text{resp.  }\dot y(t) = F(y(t)) = \left. \frac{d}{dt} (\Lambda^r(y,S(t)) \right|_{t=0})
3455
3456      Let
3457      :math:`\lambda^l_{*} : \mathfrak g \rightarrow \mathcal X(\mathcal M) `
3458      (resp.
3459      :math:`\lambda^r_{*} : \mathfrak g \rightarrow \mathcal X(\mathcal M) `
3460      be defined as
3461
3462      .. math::
3463
3464	 \lambda^l_{*}(a)(y) = \left.\frac{d}{ds}{ \Lambda^l (\rho(s), y)}\right|_{s=0} \quad (\text{ resp. }  \lambda^r_{*}(a)(y) = \left.\frac{d}{ds}{ \Lambda^r (y, \rho(s))}\right|_{s=0})\label{eq:26}
3465
3466      where :math:`\rho(s)` is a curve in :math:`\mathcal G` such that
3467      :math:`\rho(0)=I` and :math:`\dot\rho (0)=a`. Then :math:`\lambda^l_{8}`
3468      is a linear map between Lie algebras such that
3469
3470      .. math::
3471
3472	 [a, b]_{\mathfrak g} = [\lambda^l_{*}(a), \lambda^l_{*}(b)]_{\mathcal X(\mathcal M)}.\label{eq:27}
3473
3474      The following product between an element of an algebra
3475      :math:`a \in \mathfrak g` with an element of a group
3476      :math:`\sigma  \in \mathcal G` can be defined. This will served as a
3477      basis for defining the exponential map.
3478
3479      We define the left product
3480      :math:`(\cdot, \cdot)^l : \mathfrak g \times \mathcal G \rightarrow  \mathcal G`
3481      of an element of an algebra :math:`a \in \mathfrak g` with an element of
3482      a group :math:`\sigma  \in \mathcal G` as
3483
3484      .. math::
3485
3486	 (a, \sigma)^l = a \cdot \sigma = \left.\frac{d}{ds} \rho(s) \glaw \sigma \right|_{s=0}\label{eq:28}
3487
3488      where :math:`\rho(s)` is a smooth curve such that :math:`\dot\rho(0)=a`
3489      and :math:`\rho(0)=I`. In the same way, we can define the right product
3490      :math:`(\cdot, \cdot)^r : \mathcal G \times \mathfrak g  \rightarrow   \mathcal G`
3491
3492      .. math::
3493
3494	 \label{eq:29}
3495	   (\sigma,a)^r = \sigma \cdot a  = \left.\frac{d}{ds} \sigma \glaw \rho(s)   \right|_{s=0}
3496
3497      Exponential map
3498      ~~~~~~~~~~~~~~~
3499
3500      Let :math:`\mathcal G` be a Lie group and :math:`\mathfrak g` its Lie
3501      algebra. The exponential mapping
3502      :math:`exp : \mathfrak g \rightarrow \mathcal G` is defined as
3503      :math:`\exp(a) = \sigma(1)` where :math:`\sigma (t)` satisfies the
3504      differential equation
3505
3506      .. math::
3507
3508	 \dot \sigma(t) = a \cdot \sigma(t), \quad \sigma (0) = I.\label{eq:30}
3509
3510      Let us define :math:`a^k` as
3511
3512      .. math::
3513
3514	 \label{eq:31}
3515	   \left\{\begin{array}[l]{l}
3516	     a^k = \underbrace{a\glaw a \glaw \ldots a\glaw a}_{k \text{ times}} \text{ for } k \geq 1 \\
3517	     a^0  = I
3518	   \end{array}\right.
3519
3520      The exponential map can be expressed as
3521
3522      .. math::
3523
3524	 \label{eq:32}
3525	   \exp(at) = \sum_{k=0}^\infty \frac{(ta)^k}{k!}
3526
3527      since it is a solution of . A simple computation allows to check this
3528      claim:
3529
3530      .. math::
3531
3532	 \label{eq:33}
3533	    \frac{d}{dt}\exp(at) = \sum_{k=1}^\infty  k t^{k-1} \frac{a^k}{k!} = a \glaw \sum_{k=0}^\infty  t^{k} \frac{a^k}{k!} = a \glaw \exp(at).
3534
3535      A similar computation gives
3536
3537      .. math::
3538
3539	 \label{eq:34}
3540	   \frac{d}{dt}\exp(at)  = \sum_{k=0}^\infty  t^{k} \frac{a^k}{k!} \glaw a = \exp(at) \glaw a.
3541
3542      The exponential mapping :math:`exp : \mathfrak g \rightarrow \mathcal G`
3543      can also be defined as :math:`\exp(a) = \sigma(1)` where
3544      :math:`\sigma (t)` satisfies the differential equation
3545
3546      .. math::
3547
3548	 \label{eq:35}
3549	   \dot \sigma(t) = \sigma(t) \cdot a, \quad \sigma (0) = I.
3550
3551      [Theorem:solutionofLieODE] Let
3552      :math:`\Lambda^l:\mathcal G\times\mathcal M \rightarrow \mathcal M` be a
3553      left group action and
3554      :math:`\lambda^l_{∗} : \mathfrak g\rightarrow \mathcal X(\mathcal M)`
3555      the corresponding Lie algebra homomorphism. For any
3556      :math:`a \in \mathfrak g` the flow of the vector field
3557      :math:`F = \lambda^l_{a}(a)`, i.e. the solution of the equation
3558
3559      .. math::
3560
3561	 \dot y(t) = F(y(t)) = \lambda^l_{*}(a)(y(t)),\quad  t \geq 0, y(0) = y_0 \in \mathcal M,\label{eq:36}
3562
3563      is given as
3564
3565      .. math::
3566
3567	 y(t) = \Lambda^l(\exp(ta), y_0).\label{eq:37}
3568
3569      Let :math:`\Lambda^r:\mathcal M\times\mathcal G \rightarrow \mathcal M`
3570      be a right group action and
3571      :math:`\lambda^r_{∗} : \mathfrak g\rightarrow \mathcal X(\mathcal M)`
3572      the corresponding Lie algebra homomorphism. For any
3573      :math:`a \in \mathfrak g` the flow of the vector field
3574      :math:`F = \lambda^r_{*}(a)`, i.e. the solution of the equation
3575
3576      .. math::
3577
3578	 \dot y(t) = F(y(t)) = \lambda^r_{*}(a)(y(t)),\quad  t \geq 0, y(0) = y_0 \in \mathcal M,\label{eq:38}
3579
3580      is given as
3581
3582      .. math::
3583
3584	 y(t) = \Lambda^r(y_0,\exp(ta)).\label{eq:39}
3585
3586      Translation (Trivialization) maps
3587      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3588
3589      The left and right translation maps defined by
3590
3591      .. math::
3592
3593	 \label{eq:148}
3594	   \begin{array}{rcl}
3595	     L_z  : \mathcal G \times \mathcal G &\rightarrow& \mathcal G \quad \text{ (left translation map )} \\
3596	     y &\mapsto&  z \glaw y
3597	   \end{array}
3598
3599      and
3600
3601      .. math::
3602
3603	 \label{eq:149}
3604	   \begin{array}{rcl}
3605	     R_z(y)  :  \mathcal G \times  \mathcal G  & \rightarrow& \mathcal G \quad \text{ (right translation map )} \\
3606	     y  &\mapsto&  y \glaw z
3607	   \end{array}
3608
3609      If we identify the manifold :math:`\mathcal M` with the group
3610      :math:`\mathcal G`, The left and right translations can be interpreted
3611      as the simplest example of group action on the manifold. Note that the
3612      left translation map can be viewed as a left or right action on the
3613      group.
3614
3615      If we consider :math:`L_z(y)` as a right group action
3616      :math:` L_z(y) = \Lambda^r( z, y) =z \glaw y `, by differentiation we
3617      get a
3618      :math:`L'_z : T \mathfrak g \cong  \mathfrak g \rightarrow T_z\mathcal G`
3619      with :math:`\dot\rho (0)=a` such that
3620
3621      .. math::
3622
3623	 \label{eq:150}
3624	   \lambda^r_{*}(a)(z) = L'_z(a) = \left.\frac{d}{ds}{ \Lambda^r (z, \rho(s))}\right|_{s=0} = z \glaw a
3625
3626      The map
3627
3628      .. math::
3629
3630	 \label{eq:152}
3631	   \begin{array}{rcl}
3632	   L'_z  : \mathfrak g &\rightarrow& T_z\mathcal G  \\
3633		  a &\mapsto&  z \glaw a
3634	   \end{array}
3635
3636      determines an isomorphism of :math:`\mathfrak g` with the tangent space
3637      :math:`T_z\mathcal G`. In other words, the tangent space can be
3638      identified to :math:`\mathfrak g` as
3639
3640      .. math::
3641
3642	 \label{eq:153}
3643	   T_z\mathcal G =\{L'_z(a) = z \glaw a \mid a \in \mathfrak g  \}
3644
3645      Respectively, if we consider :math:`R_z(y)` as a left group action
3646      :math:` R_z(y) = \Lambda^l( y, z) =y \glaw z `, by differentiation we
3647      get a
3648      :math:`R'_z : T \mathfrak g \cong  \mathfrak g \rightarrow T_z\mathcal G`
3649      with :math:`\dot\rho (0)=a` such that
3650
3651      .. math::
3652
3653	 \label{eq:150}
3654	   \lambda^l_{*}(a)(z) = R'_z(a) = \left.\frac{d}{ds}{ \Lambda^l (\rho(s),z)}\right|_{s=0} = a \glaw z
3655
3656      The map
3657
3658      .. math::
3659
3660	 \label{eq:152}
3661	   \begin{array}{rcl}
3662	   R'_z  : \mathfrak g &\rightarrow& T_z\mathcal G  \\
3663		  a &\mapsto&  a \glaw z
3664	   \end{array}
3665
3666      determines an isomorphism of :math:`\mathfrak g` with the tangent space
3667      :math:`T_z\mathcal G`. In other words, the tangent space can be
3668      identified to :math:`\mathfrak g` as
3669
3670      .. math::
3671
3672	 \label{eq:153}
3673	   T_z\mathcal G =\{R'_z(a) = a \glaw z \mid a \in \mathfrak g  \}
3674
3675      Any tangent vector :math:`F : \mathcal G \rightarrow T_z\mathcal G` can
3676      be written in either of the forms
3677
3678      .. math::
3679
3680	 \label{eq:155}
3681	   F(z) = L'_z(f(a)) = R'_z(g(z))
3682
3683      where :math:`f,g \mathcal G \rightarrow \mathfrak g`.
3684
3685      Adjoint representation
3686      ~~~~~~~~~~~~~~~~~~~~~~
3687
3688      Let :math:`p \in \mathcal G` and let :math:`\sigma (t)` be a smooth
3689      curve on :math:`\mathcal G` such that :math:`\sigma (0)` = I and
3690      :math:`\dot \sigma(0) = b \in \mathfrak g`. The adjoint representation
3691      is defined as
3692
3693      .. math::
3694
3695	 \operatorname{Ad}_p(b) =\left. \frac{d}{dt} p\sigma(t)p^{-1}\right|_{t=0}\label{eq:40}
3696
3697      The derivative of :math:`\operatorname{Ad}` with respect to the first
3698      argument is denoted :math:`\operatorname{ad}`. Let :math:`\rho(s)` be a
3699      smooth curve on :math:`\mathcal G` such that :math:`\rho(0) = I` and
3700      :math:`\dot \rho(0) = a`, it yields:
3701
3702      .. math::
3703
3704	 \label{eq:41}
3705	     \operatorname{ad}_a(b) = \left.\frac{d}{ds} \operatorname{Ad}_{\rho(s)}(b)\right|_{s=0}  = [a, b]
3706
3707      The adjoint representation can also be expressed with the map
3708
3709      .. math::
3710
3711	 \label{eq:154}
3712	   \operatorname{Ad}_p(b)  = (L_p \glaw R_{p^{-1}})' (b) = (L'_p \glaw R'_{p^{-1}}) (b) = p \glaw b \glaw p^{-1}
3713
3714      For a tangent vector given in , we have
3715
3716      .. math::
3717
3718	 \label{eq:151}
3719	   g(z) = Ad_z(f(z))
3720
3721      Another important relation relating :math:`\operatorname{Ad}`,
3722      :math:`\operatorname{ad}` and :math:`\exp` is
3723
3724      .. math::
3725
3726	 \label{eq:164}
3727	   \operatorname{Ad}_{\exp(a)} =\exp{\operatorname{ad}_a}
3728
3729      Differential of the exponential map
3730      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3731
3732      There are multiple ways to represent the differential of
3733      :math:`\exp(\cdot)` at a point :math:`a\in \mathfrak g`. Let us start by
3734      the following definition of the differential map at
3735      :math:`a\in\mathfrak g`
3736
3737      .. math::
3738
3739	 \label{eq:147}
3740	   \begin{array}{lcl}
3741	     \exp_a' & : & \mathfrak g \rightarrow  T_{exp(a)}\mathcal G\\
3742		     & &  v \mapsto \exp'_a(v)  = \left.\frac{d}{dt} \exp(a+tv)\right|_{t=0}
3743	   \end{array}
3744
3745      The definition is very similar to the definition of the directional
3746      derivative of :math:`\exp` in the direction :math:`v \in \mathfrak g` at
3747      a point :math:`a\in\mathfrak g`. Using the expression of the tangent
3748      space at :math:`\exp(a)`, we can defined another expression of the
3749      differential map denoted as
3750      :math:`\operatorname{d^l exp}_a : \mathfrak g  \rightarrow \mathfrak g`
3751      such that
3752
3753      .. math::
3754
3755	 \label{eq:156}
3756	   \operatorname{d^l exp}_a = L'_{\exp^{-1}(a)} \glaw \exp_a' = L'_{\exp(-a)} \glaw \exp_a'
3757
3758      This expression appears as a trivialization of the differential map
3759      :math:`\exp'_a`. Using the expression of :math:`L'_z` in . In , an
3760      explicit formula relates :math:`\operatorname{d^l exp}_{a}` to the
3761      iteration of the adjoint operator:
3762
3763      .. math::
3764
3765	 \label{eq:43}
3766	   \operatorname{d^l exp}_a(b) = \sum_{k=0}^\infty \frac{(-1)^k}{(k+1)!} (\operatorname{ad}_a(b))^k \coloneqq \frac{e - \exp\glaw\operatorname{ad}_a}{\operatorname{ad}_a}(b)
3767
3768      where :math:`(\operatorname{ad}_a)^k` is the kth iteration of the
3769      adjoint operator:
3770
3771      .. math::
3772
3773	 \label{eq:44}
3774	   \left\{\begin{array}[l]{l}
3775	     (\operatorname{ad}_a)^k(b) = \underbrace{[a, [ a, [ \ldots, a, [ a, b]]]}_{k \text{ times}} \text{ for } k \geq 1 \\
3776	     (\operatorname{ad}_a)^0(b)  = b
3777	   \end{array}\right.
3778
3779      It is also possible to define the right trivialized differential of the
3780      exponential map
3781
3782      .. math::
3783
3784	 \label{eq:162}
3785	   \operatorname{d^r exp}_a = R'_{\exp^{-1}(a)} \glaw \exp_a' = R'_{\exp(-a)} \glaw \exp_a'
3786
3787      that is
3788
3789      .. math::
3790
3791	 \label{eq:163}
3792	   \operatorname{d^r exp}_a(b) = \exp'_a(b) \glaw \exp(-a)
3793
3794      With these expression, we have equivalently for
3795
3796      .. math::
3797
3798	 \label{eq:157}
3799	    \exp_a'(b)  = \exp_a \glaw \operatorname{d^l exp}_a(b)\quad \text{ and } \exp_a'(b)  = \operatorname{d^r exp}_a(b) \glaw   \exp(a)
3800
3801      To avoid to burden to much the notation, we introduced the unified
3802      definition of the differential map that corresponds to
3803      :math:`\operatorname{dexp}=\operatorname{d^r exp}`
3804
3805      The differential of the exponential mapping, denoted by
3806      :math:`\operatorname{dexp}_a : \mathfrak g \times \mathfrak g \rightarrow \mathfrak g`
3807      is defined as the “right trivialized” tangent of the exponential map
3808
3809      .. math::
3810
3811	 \label{eq:42}
3812	   \frac{d}{dt} (\exp(a(t))) = \operatorname{dexp}_{a(t)}(a'(t)) \exp(a(t))
3813
3814      An explicit formula relates :math:`\operatorname{dexp}_{a}` to the
3815      iteration of the adjoint operator:
3816
3817      .. math::
3818
3819	 \label{eq:43}
3820	   \operatorname{dexp}_a(b) = \sum_{k=0}^\infty \frac{1}{(k+1)!} (\operatorname{ad}_a(b))^k \coloneqq \frac{\exp\glaw\operatorname{ad}_a-e}{\operatorname{ad}_a}(b)
3821
3822      Say what is not the Jacobian in :math:`{\mbox{\rm $I\!\!R$}}^4`
3823
3824      As for :math:`\operatorname{Ad}_a` and :math:`\operatorname{ad}_a`, the
3825      mapping :math:`\operatorname{dexp}_{a}(b)` is a linear mapping in its
3826      second argument for a fixed :math:`a`. Using the relation , we can also
3827      relate the right and the lest trivialization tangent
3828
3829      .. math::
3830
3831	 \label{eq:165}
3832	 \operatorname{d^l exp}_a (b) =   (\operatorname{Ad}_{\exp(a)} \glaw \operatorname{dexp}(a))(b) = (\exp(\operatorname{ad}_{-a}) \glaw \frac{e - \exp\glaw\operatorname{ad}_a}{\operatorname{ad}_a})(b) = \frac{e - \exp\glaw\operatorname{ad}_{-a}}{\operatorname{ad}_a}(b) = \operatorname{dexp}_{-a}(b)
3833
3834      It is also possible to define the the “left trivialized” tangent of the
3835      exponential map
3836
3837      .. math::
3838
3839	 \label{eq:46}
3840	    \frac{d}{dt} (\exp(a(t))) =  \exp(a(t)) \operatorname{d^l exp}_{a(t)}(a'(t)) = \exp(a(t)) \operatorname{dexp}_{-a(t)}(a'(t))
3841
3842      other notation and Lie derivative
3843
3844      .. math::
3845
3846	 \label{eq:178}
3847	       Df \cdot \widehat \Omega (p) = (\widehat \Omega^r f )(p)
3848
3849      Inverse of the exponential map
3850      ''''''''''''''''''''''''''''''
3851
3852      The function :math:`\operatorname{dexp}_{a}` is an analytical function
3853      so it possible to invert it to get
3854
3855      .. math::
3856
3857	 \label{eq:45}
3858	   \operatorname{dexp}^{-1}_{a} = \sum_{k=0}^\infty \frac{B_k}{(k)!} (\operatorname{ad}_a)^k(b)
3859
3860      where :math:`B_k` are the Bernouilli number.
3861
3862      Differential of a map :math:`f : \mathcal G \rightarrow \mathfrak g`
3863      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3864
3865      We follow the notation developed in . Let us first define the
3866      differential of the map :math:`f : \mathcal G \rightarrow \mathfrak g`
3867      as
3868
3869      .. math::
3870
3871	 \label{eq:166}
3872	   \begin{array}[rcl]{rcl}
3873	     f'_z : T_z\mathcal G &\rightarrow&T_{f(z)}\mathfrak g \cong  \mathfrak g\\
3874	     b &\mapsto& \left.\frac{d}{dt} f(z\glaw \exp(t L'_{z^{-1}}(b))) \right|_{t=0}
3875	   \end{array}
3876
3877      The image of :math:`b` by :math:`f'_z` is obtained by first identifying
3878      :math:`b` with an element of :math:`v \in \mathfrak g` thanks to the
3879      left representation of :math:`T_{f(z)}\mathfrak g` view the left
3880      translation map :math:`v= t L'_z(b)`. The exponential mapping transforms
3881      :math:`v` an element :math:`y` of the Lie Group :math:`\mathcal G`. Then
3882      :math:`f'_z` is obtained by
3883
3884      .. math::
3885
3886	 \label{eq:167}
3887	   f'_z(b) = \lim_{t\rightarrow 0} \frac{f(z\glaw y) - f(z)}{t}
3888
3889      As we have done for the exponential mapping, it is possible to get a
3890      left trivialization of
3891
3892      .. math::
3893
3894	 \label{eq:169}
3895	   \operatorname{d}f_z = (f\glaw L_z)' = f'_z \glaw L'_z
3896
3897      thus
3898
3899      .. math::
3900
3901	 \label{eq:170}
3902	   \operatorname{d}f_z (a) =  f'_z \glaw L'_z(a) = f'_z(L'_z(a)) =  \left.\frac{d}{dt} f(z\glaw \exp(t a )) \right|_{t=0}
3903
3904      Newton Method
3905      '''''''''''''
3906
3907      Let us imagine that we want to solve :math:`f(y) = 0 ` for
3908      :math:`y \in \mathcal G`. A newton method can be written as
3909
3910       Lie group :math:`SO(3)` of finite rotations and Lie algebra :math:`\mathfrak{so}(3)` of infinitesimal rotations
3911      ----------------------------------------------------------------------------------------------------------------
3912
3913      The presentation is this section follows the notation and the
3914      developments taken from . For more details on Lie groups and Lie
3915      algebra, we refer to and .
3916
3917      The Lie group :math:`SO(3)` is the group of linear proper orthogonal
3918      transformations in :math:`{\mbox{\rm $I\!\!R$}}^3` that may be
3919      represented by a set of matrices in
3920      :math:`{\mbox{\rm $I\!\!R$}}^{3\times 3}` as
3921
3922      .. math::
3923
3924	 \label{eq:47}
3925	   SO(3) = \{R \in {\mbox{\rm $I\!\!R$}}^{3\times3}\mid R^TR=I , det(R) = +1  \}
3926
3927      with the group law given by :math:`R_1\glaw R_2 = R_1R_2` for
3928      :math:`R_1,R_2\in SO(3)`. The identity element is
3929      :math:`e = I_{3\times 3}`. At any point of :math:`R\in SO(3)`, the
3930      tangent space :math:`T_RSO(3)` is the set of tangent vectors at a point
3931      :math:`R`.
3932
3933      Left representation of the tangent space at :math:`R`, :math:`T_RSO(3)`
3934      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
3935
3936      Let :math:`S(t)` be a smooth curve
3937      :math:`S(\cdot) : {\mbox{\rm $I\!\!R$}}\rightarrow SO(3)` in
3938      :math:`SO(3)`. An element :math:`a` of the tangent space at :math:`R` is
3939      given by
3940
3941      .. math::
3942
3943	 \label{eq:174}
3944	   a  = \left.\frac{d}{dt} S(t)\right|_{t=0}
3945
3946      such that :math:`S(0)= R`. Since :math:`S(t)\in SO(3)`, we have
3947      :math:`\frac{d}{dt} (S(t)) = \dot S(t)S^T(t) +  S(t) \dot S^T(t) =0`. At
3948      :math:`t=0`, we get :math:`a R^T +  R a^T =0`. We conclude that it
3949      exists a skew–symmetric matrix :math:`\tilde \Omega = R^T a` such that
3950      :math:`\tilde \Omega^T + \tilde \Omega =0`. Hence, a possible
3951      representation of :math:`T_RSO(3)` is
3952
3953      .. math::
3954
3955	 \label{eq:49}
3956	   T_RSO(3) = \{ a = R \tilde \Omega \in {\mbox{\rm $I\!\!R$}}^{3\times 3} \mid \tilde \Omega^T + \tilde \Omega =0 \}.
3957
3958      For :math:`R=I`, the tangent space is directly given by the set of
3959      skew–symmetric matrices:
3960
3961      .. math::
3962
3963	 \label{eq:50}
3964	   T_ISO(3) = \{ \tilde \Omega\in {\mbox{\rm $I\!\!R$}}^{3\times 3} \mid \tilde \Omega^T + \tilde \Omega =0 \}.
3965
3966      The tangent space :math:`T_ISO(3)` with the Lie Bracket
3967      :math:`[\cdot,\cdot]` defined by the matrix commutator
3968
3969      .. math::
3970
3971	 \label{eq:51}
3972	   [A,B] = AB-BA
3973
3974      is a Lie algebra that is denoted by
3975
3976      .. math::
3977
3978	 \label{eq:53}
3979	   \mathfrak{so}(3) =\{\Omega\in {\mbox{\rm $I\!\!R$}}^{3\times 3} \mid \Omega + \tilde \Omega^T =0\}.
3980
3981      For skew symmetric matrices, the commutator can be expressed with the
3982      cross product in :math:`{\mbox{\rm $I\!\!R$}}^3`
3983
3984      .. math::
3985
3986	 \label{eq:52}
3987	   [\tilde \Omega, \tilde \Gamma] = \tilde \Omega \tilde \Gamma - \tilde \Gamma \tilde \Omega= \widetilde{\Omega \times \Gamma }
3988
3989      We use :math:`T_ISO(3) \cong  \mathfrak{so}(3)` whenever there is no
3990      ambiguity.
3991
3992      The notation :math:`\tilde \Omega` is implied by the fact that the Lie
3993      algebra is isomorphic to :math:`{\mbox{\rm $I\!\!R$}}^3` thanks to the
3994      operator
3995      :math:`\widetilde{(\cdot)} :{\mbox{\rm $I\!\!R$}}^3 \rightarrow \mathfrak{so}(3)`
3996      and defined by
3997
3998      .. math::
3999
4000	 \label{eq:54}
4001	  \widetilde{(\cdot)}: \Omega \mapsto \tilde \Omega =
4002	   \begin{bmatrix}
4003	     0 & -\Omega_3 & \Omega_2 \\
4004	     \Omega_3 & 0 & -\Omega_1 \\
4005	     -\Omega_2  & \Omega_1 & 0
4006	   \end{bmatrix}
4007
4008      Note that :math:`\tilde \Omega x = \Omega \times x`.
4009
4010       A special (right) action of Lie Group :math:`\mathcal G` on a manifold :math:`\mathcal M`.
4011      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
4012
4013      Let us come back to the representation of :math:`T_RSO(3)` given in . It
4014      is clear it can expressed with a representation that relies on
4015      :math:`\mathfrak{so}(3)`
4016
4017      .. math::
4018
4019	 \label{eq:58}
4020	    T_RSO(3) = \{ a = R \tilde \Omega \in {\mbox{\rm $I\!\!R$}}^{3\times 3} \mid \tilde \Omega \in \mathfrak{so}(3) \}.
4021
4022      With , we see that there is a linear map that relates :math:`T_RSO(3)`
4023      to :math:`\mathfrak{so}(3)`. This can be formalize by noting that the
4024      left translation map for a point :math:`R \in SO(3)`
4025
4026      .. math::
4027
4028	 \label{eq:59}
4029	   \begin{array}[lcl]{rcl}
4030	     L_R& :&   SO(3)  \rightarrow  SO(3)\\
4031		& &  S  \mapsto L_R(S) = R \glaw S = RS\\
4032	   \end{array}
4033
4034      which is diffeomorphism on :math:`SO(3)` is a group action. In our case,
4035      we identify the manifold and the group. Hence, the mapping :math:`L_R`
4036      can be viewed as a left or a right group action. We choose a right
4037      action such that :math:`\Lambda^r(R,S) = L_{R}(S) =  R \glaw S `. By
4038      differentiation, we get a mapping
4039      :math:`L'_R: T_I\mathfrak{so(3)} \cong \mathfrak{so(3)} \rightarrow T_R SO(3)`.
4040      For a given :math:`\tilde\Omega \in \mathfrak{so(3)}` and a point
4041      :math:`R`, the differential :math:`L'_R` by computing the tangent vector
4042      field :math:`\lambda^r_{*}(a)(R)` of the group action
4043      :math:`\Lambda^r(R,S)` for a smooth curve
4044      :math:`S(t) : {\mbox{\rm $I\!\!R$}}\rightarrow S0(3)` such that
4045      :math:`\dot S(0) = \tilde\Omega`:
4046
4047      .. math::
4048
4049	 \label{eq:60}
4050	    \lambda^r_{*}(a)(R) \coloneqq  \left. \frac{d}{dt} \Lambda^r(R,S(t)) \right|_{t=0} = \left. \frac{d}{dt} L_{R}(S(t)) \right|_{t=0} =  \left. \frac{d}{dt} R \glaw S(t) \right|_{t=0} =  R \glaw \dot S(0) = R \tilde\Omega \in X(\mathcal M)
4051
4052      Therefore, the vector field in is a tangent vector field that defines a
4053      Lie-Type ordinary differential equation
4054
4055      .. math::
4056
4057	 \label{eq:61}
4058	   \dot R(t) = \lambda^r_{*}(a)(R(t)) = R(t)  \tilde \Omega
4059
4060      In , the linear operator :math:`\lambda^r_{*}(a)` is defined as the
4061      directional derivative with respect to :math:`S` an denoted
4062      :math:`DL_R(S)`. It defines a diffeomorphism between :math:`T_SSO(3)`
4063      and :math:`T_{RS}SO(3)`. In particular, for :math:`S=I_{3\times3}`, we
4064      get
4065
4066      .. math::
4067
4068	 \label{eq:62}
4069	   \begin{array}{rcl}
4070	     DL_R(I_{3\times3}) : \mathfrak{so}(3) & \rightarrow & T_R SO(3) \\
4071	     \tilde \Omega &\mapsto &DL_R(I_{3\times3}). \tilde \Omega = R \tilde \Omega
4072	   \end{array}
4073
4074      We end up with a possible representation of :math:`T_{R} SO(3)` as
4075
4076      .. math::
4077
4078	 \label{eq:63}
4079	   T_{R} SO(3) =\{\tilde \Omega_R \mid \tilde \Omega_R = DL_R(I_{3\times3}). \tilde \Omega = R \tilde \Omega, \tilde \Omega \in\mathfrak{so}(3)  \}.
4080
4081      In other words, a tangent vector
4082      :math:`\tilde \Omega \in \mathfrak{so}(3)` defines a left invariant
4083      vector field on :math:`SO(3)` at the point :math:`R` given by
4084      :math:`R \tilde \Omega`.
4085
4086      what happens at :math:`S(0)=R`, with
4087      :math:` a =R \tilde \Omega =\dot S(0)` and then
4088      :math:`\dot y(t) = F(y(t)) = R \tilde \Omega y(t) =  R\Omega \times y(t)= \dot S(0) y(t) `.
4089      What else ?
4090
4091      Exponential map :math:`\operatorname{expm}\mathfrak{so(3)} \rightarrow SO(3)`
4092      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
4093
4094      The relations and shows that is possible to define tangent vector field
4095      from a group action. We can directly apply
4096      Theorem [Theorem:solutionofLieODE] and we get that the solution of
4097
4098      .. math::
4099
4100	 \label{eq:130}
4101	   \begin{cases}
4102	   \dot R(t) = \lambda^r_{*}(a)(R(t)) = R(t)  \tilde \Omega \\
4103	   R(0) = R_0
4104	 \end{cases}
4105
4106      is
4107
4108      .. math::
4109
4110	 \label{eq:138}
4111	   R(t) = R_0 \operatorname{expm}(t \tilde \Omega)
4112
4113      Let us do the computation in this case. Let us assume that the solution
4114      can be sought as :math:`R(t) = \Lambda^r(y_o,S(t))`. The initial
4115      condition imposes that
4116      :math:`R(0) = R_0 = \Lambda(R_0,I) = \Lambda(R_0,S(0))` that implies
4117      :math:`S(0)=I`. Since :math:`\Lambda(R_0,S(t))` is the flow that is
4118      produces by :math:`S(t)` and let us try to find the relation satisfied
4119      by :math:`S(\cdot)`. For a smooth curve :math:`T(s) \in SO(3)` such that
4120      :math:`\dot T(0)= \tilde \Omega`, we have
4121
4122      .. math::
4123
4124	 \label{eq:64}
4125	   \begin{array}[lcl]{lcl}
4126	     \dot R(t) = \lambda^r_*(\tilde \Omega)(R(t)) &=& \left. \frac{d}{ds}\Lambda^r(R(t),T(s)) \right|_{s=0} \\
4127					 &=& \left. \frac{d}{ds} \Lambda^r(\Lambda(R_0, S(t)),T(s)) \right|_{s=0} \\
4128					 &=& \left. \frac{d}{ds} (\Lambda^r(R_0, S(t)\glaw T(s)) \right|_{s=0} \\
4129					 &=& D_2 \Lambda^r(R_0, \glaw S(t) \glaw \dot T(0) ) \\
4130					 &=& D_2 \Lambda^r(R_0,  S(t)\glaw \tilde \Omega )
4131	   \end{array}
4132
4133      On the other side, the relation :math:`y(t) = \Lambda^r(y_0,S(t))` gives
4134      :math:`\dot y(t) = D_2 \Lambda^r(y_0,S'(t))` and we conclude that
4135
4136      .. math::
4137
4138	 \label{eq:65}
4139	   \begin{cases}
4140	     \dot S(t) =  S(t)\glaw\tilde\Omega    = S(t) \tilde \Omega\\
4141	     S(0) = I.
4142	   \end{cases}
4143
4144      The ordinary differential equation  is a matrix ODE that admits the
4145      following solution
4146
4147      .. math::
4148
4149	 \label{eq:66}
4150	   S(t) = \operatorname{expm}(t\tilde\Omega)
4151
4152      where
4153      :math:`\exp : {\mbox{\rm $I\!\!R$}}^{3\times 3} \rightarrow {\mbox{\rm $I\!\!R$}}^{3\times 3}`
4154      is the matrix exponential defined by
4155
4156      .. math::
4157
4158	 \label{eq:67}
4159	   \begin{array}[lcl]{lcl}
4160	     \operatorname{expm}(A) &=& \sum_{k=0}^{\infty} \frac {1}{k!} (A)^k.
4161	   \end{array}
4162
4163      We conclude that
4164      :math:`R(t) =\Lambda(R_0,S(t)) = R_0\operatorname{expm}(t\tilde\Omega)`
4165      is the solution of .
4166
4167      We can use the closed form solution for the matrix exponential of
4168      :math:`t \tilde\Omega  \in \mathfrak{so}(3)` as
4169
4170      .. math::
4171
4172	 \label{eq:68}
4173	   \operatorname{expm}(t\tilde\Omega) = I_{3\times 3} + \frac{\sin{t\theta}} {\theta}  \tilde\Omega  +  \frac{(\cos{t \theta}-1)}{\theta^2} \tilde\Omega^2
4174
4175      with :math:`\theta = \|\Omega\|`. For given
4176      :math:`\tilde \Omega \in\mathfrak{so}(3)`, we have
4177
4178      .. math::
4179
4180	 \label{eq:69}
4181	   \det(\tilde \Omega) = \det(\tilde \Omega^T) = \det (-\tilde \Omega^T) = (-1)^3 \det(\tilde \Omega ) = - \det (\tilde \Omega )
4182
4183      that implies that :math:`\det(\tilde \Omega ) =0 `. From , we conclude
4184      that
4185
4186      .. math::
4187
4188	 \label{eq:70}
4189	   \det( \operatorname{expm}(t\tilde \Omega)) = 1.
4190
4191      Furthermore, we have
4192      :math:`\operatorname{expm}(t\tilde \Omega)\operatorname{expm}( -t\tilde \Omega) = \operatorname{expm}(t(\tilde \Omega-\tilde \Omega)) = I`.
4193      We can verify that
4194      :math:`\operatorname{expm}(t\tilde \Omega) \in SO(3)`.
4195
4196      Adjoint representation
4197      ''''''''''''''''''''''
4198
4199      In the case of :math:`SO(3)`, the definition of the operator
4200      :math:`\operatorname{Ad}` gives
4201
4202      .. math::
4203
4204	 \label{eq:121}
4205	   \operatorname{Ad}_R(\tilde\Omega)  = R \tilde\Omega R^T
4206
4207      and then mapping :math:`\operatorname{ad}_{\tilde\Omega}(\tilde \Gamma)`
4208      is defined by
4209
4210      .. math::
4211
4212	 \label{eq:56}
4213	   \operatorname{ad}_{\tilde\Omega}(\tilde\Gamma) = \tilde \Omega \tilde\Gamma - \tilde \Gamma \tilde\Omega  =  [\tilde \Omega,\tilde \Gamma] = \widetilde{\Omega \times \Gamma}.
4214
4215      Using the isomorphism between :math:`\mathfrak so(3)` and
4216      :math:`{\mbox{\rm $I\!\!R$}}^3`, it possible the define the mapping
4217      :math:`\operatorname{ad}_{\Omega}(\Gamma) : {\mbox{\rm $I\!\!R$}}^3\times{\mbox{\rm $I\!\!R$}}^3 \rightarrow {\mbox{\rm $I\!\!R$}}^3`
4218      with the realization of the Lie algebra in
4219      :math:`{\mbox{\rm $I\!\!R$}}^3` as
4220
4221      .. math::
4222
4223	 \label{eq:55}
4224	   \operatorname{ad}_\Omega(\Gamma) = \tilde\Omega \Gamma = \Omega\times\Gamma
4225
4226      Differential of the exponential map :math:`\operatorname{dexpm}`
4227      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
4228
4229      The differential of the exponential mapping, denoted by
4230      :math:`\operatorname{dexpm}` is defined as the ’right trivialized’
4231      tangent of the exponential map
4232
4233      .. math::
4234
4235	 \label{eq:71}
4236	   \frac{d}{dt} (\exp(\tilde \Omega(t))) = \operatorname{dexp}_{\tilde\Omega(t)}(\frac{d \tilde{\Omega}(t)}{dt}) \exp(\tilde\Omega(t))
4237
4238      The differential of the exponential mapping, denoted by
4239      :math:`\operatorname{dexpm}` is defined as the ’left trivialized’
4240      tangent of the exponential map
4241
4242      .. math::
4243
4244	 \label{eq:72}
4245	    \frac{d}{dt} (\exp(\tilde \Omega(t))) = \operatorname{dexp}_{\tilde\Omega(t)}(\frac{d \tilde{\Omega}(t)}{dt}) \exp(\tilde\Omega(t))
4246
4247      Using the formula  and the fact that
4248      :math:`\operatorname{ad}_\Omega(\Gamma) = \Tilde\Omega \Gamma`, we can
4249      write the differential as
4250
4251      .. math::
4252
4253	 \label{eq:122}
4254	   \begin{array}{lcl}
4255	     \operatorname{dexp}_{\tilde\Omega}(\tilde\Gamma) &=& \sum_{k=0}^\infty \frac{1}{(k+1)!} \operatorname{ad}_{\tilde \Omega}^k (\tilde\Gamma) \\
4256						&=& \sum_{k=0}^\infty \frac{1}{(k+1)!} \tilde\Omega^k \tilde \Gamma \\
4257	   \end{array}
4258
4259      Using again the fact that
4260      :math:`\tilde\Omega^3 = -\theta^2 \tilde\Omega`, we get
4261
4262      .. math::
4263
4264	 \label{eq:123}
4265	    \begin{array}{lcl}
4266	      \operatorname{dexp}_{\tilde\Omega} &=& \sum_{k=0}^\infty  \frac{1}{(k+1)!} \tilde\Omega^k \\
4267				   &=& I  + \sum_{k=0}^\infty  \frac{(-1)^k}{((2(k+1))!} \theta^{2k} \tilde\Omega + \sum_{k=0}^\infty  \frac{(-1)^k}{((2(k+1)+1)!} \theta^{2k} \tilde\Omega^2\\
4268	   \end{array}
4269
4270      Hence, we get
4271
4272      .. math::
4273
4274	 \label{eq:124}
4275	    \begin{array}{lcl}
4276	      \operatorname{dexp}_{\tilde\Omega}  &=& I  + \frac{(1-\cos(\theta))}{\theta^2}\tilde\Omega + \frac{(\theta-\sin(\theta))}{\theta^3}\tilde\Omega^2
4277	   \end{array}
4278
4279      Since :math:`\operatorname{dexp}_{\tilde\Omega}` is a linear mapping
4280      from :math:`\mathfrak{so(3)}` to :math:`\mathfrak{so(3)}`, we will use
4281      the following notation
4282
4283      .. math::
4284
4285	 \label{eq:172}
4286	   \operatorname{dexp}_{\tilde\Omega}\tilde\Gamma  \coloneqq T(\Omega)\tilde\Gamma
4287
4288      with
4289
4290      .. math::
4291
4292	 \label{eq:173}
4293	    T(\Omega) \coloneqq I  + \frac{(1-\cos(\theta))}{\theta^2}\tilde\Omega + \frac{(\theta-\sin(\theta))}{\theta^3}\tilde\Omega^2  \in {\mbox{\rm $I\!\!R$}}^{3\times 3}
4294
4295      Newton method and differential of a map :math:`f : \mathcal G \rightarrow \mathfrak g`
4296      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4297
4298      Finally, let us define the differential of the map
4299      :math:`f : SO(3) \rightarrow \mathfrak {so}(3)` as
4300
4301      .. math::
4302
4303	 \label{eq:183}
4304	   \begin{array}[rcl]{rcl}
4305	     f'_R : T_RSO(3) &\rightarrow&T_{f(R)}\mathfrak {so}(3) \cong  \mathfrak {so}(3)\\
4306		    a &\mapsto& \left.\frac{d}{dt} f(R\glaw \operatorname{expm}(t L'_{R^{-1}}(a))) \right|_{t=0}
4307	   \end{array}
4308
4309      The image of :math:`b` by :math:`f'_z` is obtained by first identifying
4310      :math:`a` with an element of :math:`\tilde\Omega \in \mathfrak {so}(3)`
4311      thanks to the left representation of :math:`T_{f(R)}\mathfrak {so}(3)`
4312      view the left translation map :math:`\tilde\Omega= t L'_R(b)`. The
4313      exponential mapping transforms :math:`\tilde\Omega` an element :math:`S`
4314      of the Lie Group :math:`SO(3)`. Then :math:`f'_z` is obtained by
4315
4316      .. math::
4317
4318	 \label{eq:184}
4319	   f'_R(b) = \lim_{t\rightarrow 0} \frac{f(R\glaw S) - f(R)}{t}
4320
4321      As we have done for the exponential mapping, it is possible to get a
4322      left trivialization of
4323
4324      .. math::
4325
4326	 \label{eq:185}
4327	   \operatorname{d}f_R = (f\circ L_R)' = f'_R \circ L'_R
4328
4329      thus
4330
4331      .. math::
4332
4333	 \label{eq:186}
4334	   \operatorname{d}f_R (\tilde\Omega) =  f'_R \circ L'_R(\tilde\Omega) = f'_R(L'_R(\tilde\Omega)) =  \left.\frac{d}{dt} f(R\glaw \operatorname{expm}(t \tilde\Omega )) \right|_{t=0}
4335
4336      The computation of this differential is non linear with respect to
4337      :math:`\tilde\Omega`.
4338
4339      not clear if we write :math:`\operatorname{d}f_R (\tilde\Omega)`. Better
4340      understand the link with
4341      :math:`\operatorname{dexp}_{\tilde \Omega}{\tilde\Gamma}`
4342
4343      Sometimes, it can be formally written as
4344
4345      .. math::
4346
4347	 \label{eq:180}
4348	   \operatorname{d}f_R (\tilde\Omega) = C(\tilde\Omega)\tilde\Omega
4349
4350      Nevertheless, an explicit expression of :math:`C(\cdot)` is not
4351      necessarily trivial.
4352
4353      Let us consider a first simple example of a mapping
4354      :math:`f(R) = \widetilde{R  x}` for a given
4355      :math:`x\in{\mbox{\rm $I\!\!R$}}^3`. The computation yields
4356
4357      .. math::
4358
4359	 \label{eq:181}
4360	   \begin{array}{rcl}
4361	     \operatorname{d}f_R (\tilde\Omega) &=& \widetilde{ \left.\frac{d}{dt} R \exp(t \tilde\Omega) x  \right|_{t=0}} \\
4362				    &=& \widetilde{R \left.\frac{d}{dt}\exp(t \tilde\Omega)\right|_{t=0}  x} \\
4363				    &=& \widetilde{R \left. \operatorname{dexp}_{\tilde\Omega}(\tilde\Omega)\exp(t \tilde\Omega) \right|_{t=0}  x} \\
4364				    &=& \widetilde{R \operatorname{dexp}_{\tilde\Omega}(\tilde\Omega) x} \\
4365				    &=& \widetilde{R T(\Omega) \tilde\Omega  x} \\
4366				    &=& \widetilde{-R T(\Omega) \tilde x \Omega }
4367	   \end{array}
4368
4369      In that case, it is difficult to find a expression as in , but
4370      considering the function :math:`g(R)` such that
4371      :math:`f(R) = \widetilde g(x)` we get
4372
4373      .. math::
4374
4375	 \label{eq:181}
4376	   \begin{array}{rcl}
4377	     \operatorname{d}g_R (\tilde\Omega)  =- R T(\Omega) \tilde x \Omega  = C(\Omega) \Omega
4378	   \end{array}
4379
4380      with
4381
4382      .. math::
4383
4384	 \label{eq:182}
4385	    C(\Omega) = -R T(\Omega) \tilde x
4386
4387      Lie group of unit quaternions :math:`{\mbox{\rm $I\!\!H$}}_1` and pure imaginary quaternions :math:`{\mbox{\rm $I\!\!H$}}_p`.
4388      -----------------------------------------------------------------------------------------------------------------------------
4389
4390      In Siconos we choose to parametrize the rotation with a unit quaternion
4391      :math:`p \in {\mbox{\rm $I\!\!H$}}` such that :math:`R = \Phi(p)`. This
4392      parameterization has no singularity and has only one redundant variable
4393      that is determined by imposing :math:`\|p\|=1`.
4394
4395      Quaternion definition.
4396      ''''''''''''''''''''''
4397
4398      There is many ways to define quaternions. The most convenient one is to
4399      define a quaternion as a :math:`2\times 2` complex matrix, that is an
4400      element of
4401      :math:`{\mbox{\rm $~\vrule height6.6pt width0.5pt depth0.25pt\!\!$C}}^{2\times 2}`.
4402      For this end, we write for
4403      :math:`z \in {\mbox{\rm $~\vrule height6.6pt width0.5pt depth0.25pt\!\!$C}}`,
4404      :math:`z=a+ib` with :math:`a,b \in {\mbox{\rm $I\!\!R$}}^2` and
4405      :math:`i^2=-1` and its conjugate :math:`\bar z= a-ib`. Let
4406      :math:`{e, \bf, i, j, k}` the following matrices in
4407      :math:`{\mbox{\rm $~\vrule height6.6pt width0.5pt depth0.25pt\!\!$C}}^{2\times 2}`
4408
4409      .. math::
4410
4411	 \label{eq:127}
4412	   e =
4413	   \begin{bmatrix}
4414	     1 & 0 \\
4415	     0 & 1  \\
4416	   \end{bmatrix},
4417	   \quad   \bf{i} =
4418	   \begin{bmatrix}
4419	     i & 0 \\
4420	     0 & -i  \\
4421	   \end{bmatrix}
4422	   \quad   \bf{j} =
4423	   \begin{bmatrix}
4424	     0 & 1 \\
4425	     -1 & 0  \\
4426	   \end{bmatrix}
4427	    \quad   \bf{k} =
4428	   \begin{bmatrix}
4429	     0 & i \\
4430	     i & 0  \\
4431	   \end{bmatrix}
4432
4433      Let :math:`{\mbox{\rm $I\!\!H$}}` be the set of all matrices of the form
4434
4435      .. math::
4436
4437	 \label{eq:128}
4438	     p_0 e + p_1 {\bf i} + p_2 {\bf j} + p_3 {\bf k}
4439
4440      where :math:`(p_0,p_1,p_2,p_3) \in {\mbox{\rm $I\!\!R$}}^4`. Every
4441      Matrix in :math:`{\mbox{\rm $I\!\!H$}}` is of the form
4442
4443      .. math::
4444
4445	 \label{eq:129}
4446	     \begin{bmatrix}
4447	       x &y  \\
4448	       - \bar y  & \bar x
4449	     \end{bmatrix}
4450
4451      where :math:`x = p_0 + i p_1` and :math:`y = p_2 + i p_3`. The matrices
4452      in :math:`{\mbox{\rm $I\!\!H$}}` are called quaternions.
4453
4454      The null quaternion generated by
4455      :math:`[0,0,0,0] \in {\mbox{\rm $I\!\!R$}}^4` is denoted by :math:`0` .
4456      Quaternions of the form :math:`p_1 \bf {i} + p_2 \bf{j} + p_3 \bf{k}`
4457      are called pure quaternions. The set of pure quaternions is denoted by
4458      :math:`{\mbox{\rm $I\!\!H$}}_p`.
4459
4460      With the definition of :math:`{\mbox{\rm $I\!\!H$}}` as a set of complex
4461      matrices, It can be show that :math:`{\mbox{\rm $I\!\!H$}}` is a real
4462      vector space of dimension :math:`4` with basis
4463      :math:`{e, \bf, i, j, k}`. Furthermore, with the matrix product,
4464      :math:`{\mbox{\rm $I\!\!H$}}` is a real algebra.
4465
4466      Representation of quaternions
4467      '''''''''''''''''''''''''''''
4468
4469      Thanks to the equations ,   and  , we see that there are several manner
4470      to represent a quaternion :math:`p\in {\mbox{\rm $I\!\!H$}}`. It can be
4471      represented as a complex matrix as in . It can also be represented as a
4472      vector in :math:`{\mbox{\rm $I\!\!R$}}^4` , :math:`p= [p_0,p_1,p_2,p_3]`
4473      with the isomorphism . In other words, :math:`{\mbox{\rm $I\!\!H$}}` is
4474      isomorphic to :math:`{\mbox{\rm $I\!\!R$}}^4`. The first element
4475      :math:`p_0` can also be viewed as a scalar and three last ones as a
4476      vector in :math:`{\mbox{\rm $I\!\!R$}}^3` denoted by
4477      :math:`\vv{p} = [p_1,p_2,p_3]`, and in that case,
4478      :math:`{\mbox{\rm $I\!\!H$}}` is viewed as
4479      :math:`{\mbox{\rm $I\!\!R$}}\times {\mbox{\rm $I\!\!R$}}^3`. The
4480      quaternion can be written as :math:`p=(p_0,\vv{p})`.
4481
4482      Quaternion product
4483      ''''''''''''''''''
4484
4485      The quaternion product denoted by :math:`p \glaw q ` for
4486      :math:`p,q\in {\mbox{\rm $I\!\!H$}}_1` is naturally defined as the
4487      product of complex matrices. With its representation in
4488      :math:`{\mbox{\rm $I\!\!R$}}\times {\mbox{\rm $I\!\!R$}}^3`, the
4489      quaternion product is defined by
4490
4491      .. math::
4492
4493	 \label{eq:73}
4494	   p \glaw q =
4495	   \begin{bmatrix}
4496	     p_oq_o - \vv{p}\vv{q} \\
4497	     p_0\vv{q}+q_o\vv{p} + \vv{p}\times\vv{q}
4498	   \end{bmatrix}.
4499
4500      Since the product is a matrix product, it is not communicative, but it
4501      is associative. The identity element for the quaternion product is
4502
4503      .. math::
4504
4505	 e=  \begin{bmatrix}
4506	     1 & 0 \\
4507	     0 & 1  \\
4508	   \end{bmatrix} =(1,\vv{0})\label{eq:57}.
4509
4510      Let us note that
4511
4512      .. math::
4513
4514	 \label{eq:74}
4515	   (0,\vv{p})\glaw (0,\vv(q)) = - (0,\vv{q})\glaw (0,\vv{p}).
4516
4517      The quaternion multiplication can also be represented as a matrix
4518      operation in :math:`{\mbox{\rm $I\!\!R$}}^{4\times4}`. Indeed, we have
4519
4520      .. math::
4521
4522	 \label{eq:75}
4523	   p \glaw q  =
4524	   \begin{bmatrix}
4525	     q_0 p_0 -q_1p_1-q_2p_2-q_3p_3\\
4526	     q_0 p_1 +q_1p_0-q_2p_3+q_3p_2\\
4527	     q_0 p_2 +q_1p_3+q_2p_0-q_3p_1\\
4528	     q_0 p_3 -q_1p_2+q_2p_1+q_3p_0\\
4529	   \end{bmatrix}
4530
4531      that can be represented as
4532
4533      .. math::
4534
4535	 \label{eq:76}
4536	   p \glaw q  =
4537	   \begin{bmatrix}
4538	     p_0 & -p_1 & -p_2 & -p_3 \\
4539	     p_1 & p_0 & -p_3 & p_2 \\
4540	     p_2 & p_3 & p_0 & -p_1 \\
4541	     p_3 & -p_2 & p_1 & p_0 \\
4542	   \end{bmatrix}
4543	   \begin{bmatrix}
4544	     q_0\\
4545	     q_1\\
4546	     q_2\\
4547	     q_3
4548	   \end{bmatrix} := [p_\glaw]q
4549
4550      or
4551
4552      .. math::
4553
4554	 \label{eq:77}
4555	   p \glaw q  =
4556	   \begin{bmatrix}
4557	     q_0 & -q_1 & -q_2 & -q_3 \\
4558	     q_1 & q_0 & q_3 & -q_2 \\
4559	     q_2 & -q_3 & q_0 & q_1 \\
4560	     q_3 & q_2 & -q_1 & q_0 \\
4561	   \end{bmatrix}
4562	   \begin{bmatrix}
4563	     p_0\\
4564	     p_1\\
4565	     p_2\\
4566	     p_3
4567	   \end{bmatrix} := [{}_\glaw q] p
4568
4569      Adjoint quaternion, inverse and norm
4570      ''''''''''''''''''''''''''''''''''''
4571
4572      The adjoint quaternion of :math:`p` is denoted by
4573
4574      .. math::
4575
4576	 p^\star = \overline{  \begin{bmatrix}
4577	       x &y  \\
4578	       - \bar y  & \bar x
4579	     \end{bmatrix}}^T
4580	   =\begin{bmatrix}
4581	     \bar x & - y  \\
4582	     \bar y  &  x
4583	   \end{bmatrix} =
4584	   \begin{bmatrix}
4585	     p_0, -p_1, -p_2, -p_3
4586	   \end{bmatrix} = (p_0, - \vv{p})
4587
4588      We note that
4589
4590      .. math::
4591
4592	 \label{eq:131}
4593	   p \glaw p^\star =
4594	   \begin{bmatrix}
4595	       x &y  \\
4596	       - \bar y  & \bar x
4597	     \end{bmatrix}
4598	     \begin{bmatrix}
4599	     \bar x & - y  \\
4600	     \bar y  &  x
4601	   \end{bmatrix} = \det(\begin{bmatrix}
4602	       x &y  \\
4603	       - \bar y  & \bar x
4604	     \end{bmatrix}) e = (x\bar x + y \bar y) e  = (p^2_0 + p^2_1+ p_2^2 + p_3^2)e
4605
4606      The norm of a quaternion is given by
4607      :math:`|p|^2=p^\top p = p_o^2+p_1^2+p_2^2+p_3^2`. In particular, we have
4608      :math:`p \glaw p^\star = p^\star \glaw p = |p|^2 e`. This allows to
4609      define the reciprocal of a non zero quaternion by
4610
4611      .. math::
4612
4613	 \label{eq:78}
4614	   p ^{-1} = \frac 1 {|p|^2} p^\star
4615
4616      A quaternion :math:`p` is said to be unit if :math:`|p| =1`.
4617
4618      Unit quaternion and rotation
4619      ''''''''''''''''''''''''''''
4620
4621      For two vectors :math:`x\in {\mbox{\rm $I\!\!R$}}^3` and
4622      :math:`x'\in {\mbox{\rm $I\!\!R$}}^3`, we define the quaternion
4623      :math:`p_x = (0,x)\in {\mbox{\rm $I\!\!H$}}_p` and
4624      :math:`p_{x'} = (0,x')\in {\mbox{\rm $I\!\!H$}}_p`. For a given unit
4625      quaternion :math:`p`, the transformation
4626
4627      .. math::
4628
4629	 \label{eq:79}
4630	   p_{x'} = p \glaw p_x \glaw  p^\star
4631
4632      defines a rotation :math:`R` such that :math:`x'  = R x` given by
4633
4634      .. math::
4635
4636	 \label{eq:80}
4637	   x' = (p_0^2- p^\top \vv{p}) x +2 p_0(\vv{p}\times x) +  2 (\vv{p}^\top x) p = R x
4638
4639      The rotation matrix may be computed as
4640
4641      .. math::
4642
4643	 \label{eq:81}
4644	   R = \Phi(p) =
4645	   \begin{bmatrix}
4646	     1-2 p_2^2- 2 p_3^2 & 2(p_1p_2-p_3p_0) & 2(p_1p_3+p_2p_0)\\
4647	     2(p_1p_2+p_3p_0) & 1-2 p_1^2- 2 p_3^2 & 2(p_2p_3-p_1p_0)\\
4648	     2(p_1p_3-p_2p_0) & 2(p_2p_3+p_1p_0)  & 1-2 p_1^2- 2 p_2^2\\
4649	   \end{bmatrix}
4650
4651      Computation of the time derivative of a unit quaternion associated with a rotation.
4652      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
4653
4654      The derivation with respect to time can obtained as follows. The
4655      rotation transformation for a unit quaternion is given by
4656
4657      .. math::
4658
4659	 \label{eq:82}
4660	   p_{x'}(t) = p(t) \glaw p_x \glaw p^\star(t) =  p(t) \glaw p_x \glaw p^{-1}(t)
4661
4662      and can be derived as
4663
4664      .. math::
4665
4666	 \label{eq:83}
4667	   \begin{array}{lcl}
4668	     \dot p_{x'}(t) &=& \dot p(t) \glaw p_x \glaw p^{-1}(t) + p(t) \glaw p_x \glaw \dot p^{-1}(t) \\
4669			   &=& \dot p(t) \glaw p^{-1}(t)  \glaw   p_{x'}(t)  +      p_{x'}(t) \glaw p(t)  \glaw \dot p^{-1}(t)
4670	   \end{array}
4671
4672      From :math:`p(t) \glaw p^{-1}(t) =e`, we get
4673
4674      .. math::
4675
4676	 \label{eq:84}
4677	   \dot p(t) \glaw p^{-1}(t) + p \glaw \dot p^{-1}(t) = 0
4678
4679      so ([eq:82]) can be rewritten
4680
4681      .. math::
4682
4683	 \label{eq:85}
4684	   \begin{array}{lcl}
4685	     \dot p_{x'}(t) = \dot p(t) \glaw p^{-1}(t)   \glaw   p_{x'}(t)  -    p_{x'}(t) \glaw  \dot p(t) \glaw p^{-1}(t)
4686	   \end{array}
4687
4688      The scalar part of :math:`\dot p(t) \glaw p^{-1}(t)` is
4689      :math:`(\dot p(t) \glaw p^{-1}(t))_0 = p_o \dot p_0 + \vv{p}^T\vv{\dot p}`.
4690      Since :math:`p` is a unit quaternion, we have
4691
4692      .. math::
4693
4694	 \label{eq:86}
4695	   |p|=1 \implies \frac{d}{dt} (p^\top p) = 0 =  \dot p^\top p + p^\top \dot p =   2( p_o \dot p_0 + \vv{p}^T\vv{\dot p}).
4696
4697      Therefore, the scalar part :math:`(\dot p(t) \glaw p^{-1}(t))_0 =0`. The
4698      quaternion product :math:`\dot p(t) \glaw p^{-1}(t)` and
4699      :math:`p_{x'}(t)` is a product of quaternions with zero scalar part
4700      (see ), so we have
4701
4702      .. math::
4703
4704	 \label{eq:87}
4705	   \begin{array}{lcl}
4706	     \dot p_{x'}(t) = 2 \dot p(t) \glaw p^{-1}(t)   \glaw p_{x'}(t).
4707	   \end{array}
4708
4709      In terms of vector of :math:`{\mbox{\rm $I\!\!R$}}^3`, this corresponds
4710      to
4711
4712      .. math::
4713
4714	 \label{eq:88}
4715	   \dot x'(t) = 2 \vv{ \dot p(t) \glaw p^{-1}(t) } \times x'(t).
4716
4717      Since :math:`x'(t) = R(t) x`, we have
4718      :math:`\dot x' = \dot R(t) x = \tilde \omega(t) R(t) x  = \tilde \omega(t) x'(t) `.
4719      Comparing and , we get
4720
4721      .. math::
4722
4723	 \label{eq:89}
4724	   \tilde \omega(t)  = 2 \vv{ \dot p(t) \glaw p^{-1}(t) }
4725
4726      or equivalently
4727
4728      .. math::
4729
4730	 \dot p(t) \glaw p^{-1}(t) = (0, \frac{\omega(t)}{2} )
4731	   \label{eq:90}
4732
4733      Finally, we can conclude that
4734
4735      .. math::
4736
4737	 \label{eq:91}
4738	   \dot p(t) = (0, \frac{\omega(t)}2 ) \glaw p(t).
4739
4740      Since :math:`\omega(t)=R(t)\Omega(t)`, we have
4741
4742      .. math::
4743
4744	 \label{eq:92}
4745	   (0, \omega(t) ) = (0, R(t) \Omega(t) ) = p(t) \glaw (0, \Omega(t) ) \glaw \bar p(t) = p(t) \glaw (0, \Omega(t) ) \glaw  p^{-1}(t)
4746
4747      and then
4748
4749      .. math::
4750
4751	 \label{eq:93}
4752	   \dot p(t) =\frac 1 2 p(t) \glaw(0, \Omega(t) ) .
4753
4754      The time derivation is compactly written
4755
4756      .. math::
4757
4758	 \label{eq:94}
4759	   \dot p = \frac  1 2 p  \glaw(0, \frac\Omega 2 ) =  [p_\glaw] p_{\frac \Omega 2} = \Psi(p)\frac \Omega 2,
4760
4761      and using the matrix representation of product of quaternion we get
4762
4763      .. math::
4764
4765	 \label{eq:95}
4766	   \Psi(p) =  \begin{bmatrix}
4767	     -p_1 & -p_2 & -p_3 \\
4768	     p_0 & -p_3 & p_2 \\
4769	     p_3 & p_0 & -p_1 \\
4770	     -p_2 & p_1 & p_0 \\
4771	   \end{bmatrix}
4772
4773      The relation can be also inverted by writing
4774
4775      .. math::
4776
4777	 \label{eq:96}
4778	    (0, \Omega(t) ) = 2 p^{-1}(t) \glaw \dot p(t)
4779
4780      Using again matrix representation of product of quaternion, we get
4781
4782      .. math::
4783
4784	 \label{eq:97}
4785	   \Omega(t)  = 2 \vv{p^{-1}(t) \glaw \dot p(t)}  = 2  \begin{bmatrix}
4786	     -p_1 & p_0 & p_3 & -p_2 \\
4787	     -p_2 & -p_3 & p_0 & p_1 \\
4788	     -p_3 & p_2 & -p_1  & p_0\\
4789	   \end{bmatrix}\dot p(t) = 2 \Psi(p)^\top \dot p(t)
4790
4791      Note that we have :math:`\Psi^\top(p)\Psi(p)= I_{4\times 4 }` and
4792      :math:`\Psi(p)\Psi^\top(p)= I_{3\times 3 }`
4793
4794      Lie group structure of unit quaternions.
4795      ''''''''''''''''''''''''''''''''''''''''
4796
4797      In terms of complex matrices, an unit quaternion :math:`p` satisfies
4798
4799      .. math::
4800
4801	 \label{eq:125}
4802	   \det\left(    \begin{bmatrix}
4803	       x &y  \\
4804	       - \bar y  & \bar x
4805	     \end{bmatrix} \right) =1
4806
4807      The set of all unit quaternions that we denote
4808      :math:`{\mbox{\rm $I\!\!H$}}_1` is the set of unitary matrices of
4809      determinant equal to :math:`1`. From , we get that
4810
4811      .. math::
4812
4813	 \label{eq:126}
4814	   p \glaw p^\star = e
4815
4816      It implies that the set :math:`{\mbox{\rm $I\!\!H$}}_1` is the set of
4817      special unitary complex matrices. The set is a Lie group usually denoted
4818      as :math:`SU(2)`. Since we used multiple representation of a quaternion,
4819      we continue to use :math:`{\mbox{\rm $I\!\!H$}}_1 \cong SU(2)` as a
4820      notation but with the Lie group structure implied by :math:`SU(2)`.
4821
4822      Let us compute the tangent vector at a point
4823      :math:`p \in {\mbox{\rm $I\!\!H$}}_1`. Let :math:`q(t)` be a smooth
4824      curve :math:`q(\cdot) : t\in {\mbox{\rm $I\!\!R$}}\mapsto q(t)\in H_1`
4825      in :math:`H_1` such that :math:`q(O)= p`. Since :math:`q(t)\in H_1`, we
4826      have :math:`|q(t)|=1` and then
4827      :math:`\frac{d}{dt} |q(t)| = 2(q_0(0) \dot q_0(0) + \vec{q}^T(0) \vec{\dot q}(0) ) =0`.
4828      At :math:`t=0`, we get
4829
4830      .. math::
4831
4832	 \label{eq:48}
4833	   2(p_0 a_0 + \vec{p}^T \vec{a})= 0.
4834
4835      This relation imposes that the quaternions
4836      :math:`2 p^\star \glaw a \in H_1` and :math:`2 a \glaw p^\star \in H_1`,
4837      that is, have to be pure quaternions. Therefore, it exists
4838      :math:`\omega \in {\mbox{\rm $I\!\!R$}}^3` and
4839      :math:`\Omega \in {\mbox{\rm $I\!\!R$}}^3` such that
4840
4841      .. math::
4842
4843	 \label{eq:132}
4844	   (0, \Omega) = 2 p ^\star \glaw a
4845
4846      and
4847
4848      .. math::
4849
4850	 \label{eq:132}
4851	   (0, \omega) = 2 a\glaw p^\star
4852
4853      In other terms, the tangent vector spaces at
4854      :math:`p \in {\mbox{\rm $I\!\!H$}}_1` can be represented as a left
4855      representation
4856
4857      .. math::
4858
4859	 \label{eq:133}
4860	   T_p{\mbox{\rm $I\!\!H$}}_1 = \{ a \mid a = p \glaw (0, \frac \Omega 2 ), \Omega \in {\mbox{\rm $I\!\!R$}}^3\}
4861
4862      or a right representation
4863
4864      .. math::
4865
4866	 \label{eq:1330}
4867	   T_p{{\mbox{\rm $I\!\!H$}}_1} = \{ a \mid a =  (0, \frac \omega 2 ) \glaw p, \omega \in {\mbox{\rm $I\!\!R$}}^3\}
4868
4869      At :math:`p=e`, we get the Lie algebra defined by
4870
4871      .. math::
4872
4873	 \label{eq:134}
4874	   \mathfrak h_1 =  T_e{{\mbox{\rm $I\!\!H$}}_1} =  \{ a = (0, \frac \Omega 2 ), \Omega \in {\mbox{\rm $I\!\!R$}}^3 \}
4875
4876      equipped with the Lie bracket given by the commutator
4877
4878      .. math::
4879
4880	 \label{eq:135}
4881	   [p,q] = p \glaw q- q\glaw p.
4882
4883      We can easily verify that for
4884      :math:`a = (0, \frac \Omega 2 ), \, b = (0, \frac \Gamma 2 ) \in \mathfrak h_1 `,
4885      we have
4886
4887      .. math::
4888
4889	 \label{eq:136}
4890	   [a,b] = (0, \frac \Omega 2 ) \glaw (0, \frac \Gamma 2 ) - (0, \frac \Gamma 2 ) \glaw  (0, \frac \Omega 2 )  = (0, \frac{\Omega\times \Gamma}{2}) \in \mathfrak h_1
4891
4892      As for :math:`\mathfrak so(3)`, the Lie algebra :math:`\mathfrak h_1` is
4893      isomorphic to :math:`{\mbox{\rm $I\!\!R$}}^3` thanks to the operator
4894      :math:`\widehat{(\cdot)} :{\mbox{\rm $I\!\!R$}}^3 \rightarrow \mathfrak h_1`
4895      and defined by
4896
4897      .. math::
4898
4899	 \label{eq:54}
4900	  \widehat{(\cdot)}: \Omega \mapsto \widehat \Omega = (0, \frac \Omega 2 )
4901
4902      With this operator, the Lie Bracket can be written
4903
4904      .. math::
4905
4906	 \label{eq:137}
4907	   [\widehat{\Omega},\widehat{\Gamma}] = \widehat{\Omega \times \Gamma}
4908
4909       A special (right) action of Lie Group :math:`\mathcal G` on a manifold :math:`\mathcal M`.
4910      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
4911
4912      Let us come back to the representation of
4913      :math:`T_p{\mbox{\rm $I\!\!H$}}_1` given in . It is clear it can
4914      expressed with a representation that relies on :math:`\mathfrak h_1`
4915
4916      .. math::
4917
4918	 \label{eq:158}
4919	    T_RSO(3) = \{ a = p \glaw  \widehat \Omega \mid \widehat \Omega \in \mathfrak h_1 \}.
4920
4921      With , we see that there is a linear map that relates
4922      :math:`T_p{\mbox{\rm $I\!\!H$}}_1` to :math:`\mathfrak h_1`. This linear
4923      map defines a vector field. A special group action is defined by the
4924      left translation map for a point :math:`p \in {\mbox{\rm $I\!\!H$}}_1`
4925
4926      .. math::
4927
4928	 \label{eq:159}
4929	   \begin{array}[lcl]{rcl}
4930	     L_p& :&   {\mbox{\rm $I\!\!H$}}_1 \rightarrow  {\mbox{\rm $I\!\!H$}}_1\\
4931		& &  q  \mapsto L_p(q) = p \glaw q\\
4932	   \end{array}
4933
4934      which is diffeomorphism on :math:`{\mbox{\rm $I\!\!H$}}_1`. In that
4935      case, we identify the manifold and the group. So, :math:`L_p` can be
4936      viewed as a left or a right group action. We choose a right action. For
4937      our application where
4938      :math:`\mathcal G = \mathcal M = {\mbox{\rm $I\!\!H$}}_1` and
4939      :math:`\Lambda^r(p,q) = L_{p}(q) =  p \glaw q `, we get
4940
4941      .. math::
4942
4943	 \label{eq:160}
4944	    \lambda^r_{*}(a)(p) = \left. \frac{d}{dt} L_{p}(q(t)) \right|_{t=0}  = \left. \frac{d}{dt} p \glaw q(t) \right|_{t=0} =  p \glaw \dot q(0) = p  \glaw \dot q(0)  \in X(\mathcal M)
4945
4946      for a smooth curve :math:`q(t)` in :math:`{\mbox{\rm $I\!\!H$}}_1`.
4947      Since :math:`q(\cdot)` is a smooth curve in
4948      :math:`{\mbox{\rm $I\!\!H$}}_1`, :math:`\dot q(0)` is a tangent vector
4949      at the point :math:`q(0)=I`, that is an element
4950      :math:`a = \widehat  \Omega  \in \mathfrak h_1 ` defined by the
4951      relation . Therefore, the vector field in is a tangent vector field and
4952      we get
4953
4954      .. math::
4955
4956	 \label{eq:161}
4957	   \dot p(t) = \lambda^r_{*}(a)(p(t)) = p(t)  \glaw \widehat \Omega
4958
4959      Exponential map :math:`\operatorname{expq}: \mathfrak h_1 \rightarrow {\mbox{\rm $I\!\!H$}}_1`
4960      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
4961
4962      We can directly apply Theorem [Theorem:solutionofLieODE] and we get that
4963      the solution of
4964
4965      .. math::
4966
4967	 \label{eq:130}
4968	   \begin{cases}
4969	   \dot p(t) = \lambda^r_{*}(a)(p(t)) = p(t) \glaw \widehat \Omega \\
4970	   p(0) = Rp_0
4971	 \end{cases}
4972
4973      is
4974
4975      .. math::
4976
4977	 \label{eq:138}
4978	   p(t) = p_0 \operatorname{expq}(t \widehat \Omega)
4979
4980      The exponential mapping
4981      :math:`\operatorname{expq}: \mathfrak h_1 \rightarrow {\mbox{\rm $I\!\!H$}}_1`
4982      can also be defined as
4983      :math:`\operatorname{expq}(\widehat \Omega) = q(1)` where :math:`q (t)`
4984      satisfies the differential equation
4985
4986      .. math::
4987
4988	 \label{eq:235}
4989	   \dot q(t) = q(t) \cdot \widehat \Omega , \quad q (0) = e.
4990
4991      Using the quaternion product, the exponential map can be expressed as
4992
4993      .. math::
4994
4995	 \label{eq:232}
4996	   \operatorname{expq}(t \widehat \Omega ) = \sum_{k=0}^\infty \frac{(t\widehat \Omega)^k}{k!}
4997
4998      since it is a solution of . A simple computation allows to check this
4999      claim:
5000
5001      .. math::
5002
5003	 \label{eq:233}
5004	    \frac{d}{dt}\operatorname{expq}(t \widehat \Omega ) = \sum_{k=1}^\infty  k t^{k-1} \frac{ \widehat \Omega ^k}{k!} =  \sum_{k=0}^\infty  t^{k} \frac{t \widehat \Omega ^k}{k!}\glaw  \widehat \Omega  =   \operatorname{expq}(t \widehat \Omega ) \glaw \widehat \Omega.
5005
5006      A closed form relation for the form the quaternion exponential can also
5007      be found by noting that
5008
5009      .. math::
5010
5011	 \label{eq:140}
5012	   \widehat \Omega ^2  = - \left(\frac \theta 2 \right)^2 e, \text{ and } \widehat \Omega ^3  = - \left(\frac \theta 2 \right)^2 \widehat \Omega.
5013
5014      A simple expansion of at :math:`t=1` equals
5015
5016      .. math::
5017
5018	 \label{eq:141}
5019	   \begin{array}{lcl}
5020	     \operatorname{expq}(\widehat \Omega ) &=& \sum_{k=0}^\infty \frac{(\widehat \Omega)^k}{k!}\\
5021				     &=& \sum_{k=0}^\infty \frac{(-1)^k}{(2k)!}\left(\frac \theta 2 \right)^{2k} e + \sum_{k=0}^\infty \frac{(-1)^k}{(2k+1)!} \left(\frac \theta 2 \right)^{2k+1} \widehat \Omega \\
5022				     &=& \cos(\frac \theta 2) e + \frac{\sin(\frac \theta 2)}{\frac \theta 2} \widehat \Omega \\
5023	   \end{array}
5024
5025      that is
5026
5027      .. math::
5028
5029	 \label{eq:144}
5030	   \operatorname{expq}(\widehat \Omega )  = (\cos(\frac \theta 2), \sin(\frac \theta 2) \frac{\Omega}{\theta}   ).
5031
5032      Adjoint representation
5033      ''''''''''''''''''''''
5034
5035      In the case of :math:`{\mbox{\rm $I\!\!H$}}_1`, the definition of the
5036      operator :math:`\operatorname{Ad}` gives
5037
5038      .. math::
5039
5040	 \label{eq:121}
5041	   \operatorname{Ad}_p(\widehat\Omega)  = p\glaw \widehat\Omega p^\star
5042
5043      and then mapping
5044      :math:`\operatorname{ad}_{\widehat\Omega}(\widehat \Gamma)` is defined
5045      by
5046
5047      .. math::
5048
5049	 \label{eq:56}
5050	   \operatorname{ad}_{\widehat\Omega}(\widehat\Gamma) = \widehat \Omega \widehat\Gamma - \widehat \Gamma \widehat\Omega  =  [\widehat \Omega,\widehat \Gamma] = \widehat{\Omega \times \Gamma}.
5051
5052      Using the isomorphism between :math:`\mathfrak h_1` and
5053      :math:`{\mbox{\rm $I\!\!R$}}^3`, we can use the the mapping
5054      :math:`\operatorname{ad}_{\Omega}(\Gamma) : {\mbox{\rm $I\!\!R$}}^3\times{\mbox{\rm $I\!\!R$}}^3 \rightarrow {\mbox{\rm $I\!\!R$}}^3`
5055      given by to get
5056
5057      .. math::
5058
5059	 \label{eq:145}
5060	    \operatorname{ad}_{\widehat\Omega}(\widehat\Gamma) = \widehat{\Omega \times \Gamma} = \widehat{\operatorname{ad}_{\Omega}(\Gamma)} =  \widehat{\tilde \Omega \Gamma}
5061
5062      Differential of the exponential map :math:`\operatorname{dexpq}`
5063      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
5064
5065      The differential of the exponential mapping, denoted by
5066      :math:`\operatorname{dexpq}` is defined as the ’right trivialized’
5067      tangent of the exponential map
5068
5069      .. math::
5070
5071	 \label{eq:71}
5072	   \frac{d}{dt} (\operatorname{expq}(\widehat \Omega(t))) = \operatorname{dexpq}_{\widehat\Omega(t)}(\frac{d \widehat{\Omega}(t)}{dt}) \operatorname{expq}(\widehat\Omega(t))
5073
5074      An explicit expression of
5075      :math:`\operatorname{dexp}_{\widehat\Omega}(\widehat\Gamma)` can also be
5076      developed either by developing the expansion and .
5077
5078      .. math::
5079
5080	 \label{eq:168}
5081	    \operatorname{dexpq}_{\widehat\Omega}(\Gamma) = \sum_{k=0}^\infty \frac{1}{(k+1)!} \operatorname{ad}_{\widehat\Omega}^k (\widehat\Gamma) = \widehat{T(\Omega)\Gamma}
5082
5083      Note that the time derivative in :math:`{\mbox{\rm $I\!\!R$}}^4` is not
5084      differential mapping. The standard time derivative of
5085      :math:`\operatorname{expq}` in the expression gives
5086
5087      .. math::
5088
5089	 \label{eq:171}
5090	     \frac{d}{dt}\operatorname{expq}(\widehat \Gamma(t)) = (- \frac{\sin(\theta)}{\theta} \Omega^T\Gamma, \frac{\sin(\theta)}{\theta}\Gamma  +\frac{\theta \cos(\theta)-\sin(\theta)}{\theta^3}\Omega^T\Omega \Gamma  )
5091
5092      that can be expressed in :math:`{\mbox{\rm $I\!\!R$}}^4` by
5093
5094      .. math::
5095
5096	 \label{eq:175}
5097	   \frac{d}{dt}\operatorname{expq}(\widehat \Gamma(t))  = \nabla \operatorname{expq}(\widehat\Omega) \widehat{\dot\Omega}
5098
5099      with
5100
5101      .. math::
5102
5103	 \label{eq:176}
5104	   \nabla \operatorname{expq}(\widehat\Omega) =
5105	   \begin{bmatrix}
5106	     - \frac{\sin(\theta)}{\theta} \Omega^T \\
5107	     \frac{\sin(\theta)}{\theta}I  +\frac{\theta \cos(\theta)-\sin(\theta)}{\theta^3}\Omega^T\Omega
5108	   \end{bmatrix}
5109
5110      Clearly, we have
5111
5112      .. math::
5113
5114	 \label{eq:177}
5115	   \nabla \operatorname{expq}(\widehat\Omega) \neq  \operatorname{dexpq}_{\widehat\Omega}
5116
5117      Directional derivative and Jacobians of functions of a quaternion
5118      '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
5119
5120      experimental
5121
5122      Let
5123      :math:`f : {\mbox{\rm $I\!\!H$}}_1 \rightarrow {\mbox{\rm $I\!\!R$}}` be
5124      a mapping from the group to :math:`{\mbox{\rm $I\!\!R$}}^3`. The
5125      directional derivative of :math:`f` in the direction
5126      :math:`\widehat \Omega \in \mathfrak h_1` at
5127      :math:`p\in {\mbox{\rm $I\!\!H$}}_1` is defined by
5128
5129      .. math::
5130
5131	 \label{eq:139}
5132	  df_p(\widehat \Omega) =\left. \frac{d}{dt} f(p\glaw \operatorname{expq}(t\widehat \Omega)) \right|_{t=0}
5133
5134      As a first simple example let us choose
5135      :math:`f(p) = \vv{p \glaw p_x \glaw p^\star}` for a given
5136      :math:`x \in {\mbox{\rm $I\!\!R$}}^3 `, we get
5137
5138      .. math::
5139
5140	 \label{eq:142}
5141	   \begin{array}{lcl}
5142	     D Id \cdot \widehat \Omega (p) = (\widehat \Omega^r f )(p) &=& \left. \frac{d}{dt}\vv{p\glaw \operatorname{expq}(t\widehat \Omega) \glaw p_x \glaw (p \glaw \operatorname{expq}(t\widehat \Omega))^\star}  \right|_{t=0}\\
5143									& = & \vv{p\glaw \frac{d}{dt}\left. \operatorname{expq}(t\widehat \Omega) \right|_{t=0} \glaw p_x \glaw p^\star +  p \glaw p_x \glaw (p \glaw\frac{d}{dt}\left. \operatorname{expq}(t\widehat \Omega) \right|_{t=0})^\star}\\
5144	   \end{array}
5145
5146      We have form the definition of the time derivative of the exponential
5147
5148      .. math::
5149
5150	 \label{eq:143}
5151	   \begin{array}{lcl}
5152	     \frac{d}{dt}\left. \operatorname{expq}(t\widehat \Omega) \right|_{t=0} &=&  \left. \operatorname{dexpq}_{\widehat\Omega}(\widehat \Omega)\operatorname{expq}(t\widehat \Omega) \right|_{t=0} \\
5153								     &=&  \operatorname{dexpq}_{\widehat\Omega}(\widehat \Omega)
5154	   \end{array}
5155
5156      Then, the directional derivative can be written
5157
5158      .. math::
5159
5160	 \label{eq:146}
5161	   \begin{array}{lcl}
5162	     D Id \cdot \widehat \Omega (p) &=& \vv{p\glaw \operatorname{dexpq}_{\widehat\Omega}(\widehat \Omega)\glaw p_x \glaw p^\star  + p \glaw p_x \glaw (\operatorname{dexpq}_{\widehat\Omega}(\widehat \Omega))^* \glaw  p^\star } \\
5163	   &=& \vv{p\glaw ( \operatorname{dexpq}_{\widehat\Omega}(\widehat \Omega)\glaw p_x +   p_x \glaw (\operatorname{dexpq}_{\widehat\Omega}(\widehat \Omega))^*) \glaw  p^\star }
5164	   \end{array}
5165
5166      Newton-Euler equation in quaternion form
5167      ----------------------------------------
5168
5169      Computation of :math:`T` for unit quaternion
5170      ''''''''''''''''''''''''''''''''''''''''''''
5171
5172      The operator :math:`T(q)` is directly obtained as
5173
5174      .. math::
5175
5176	 T(q)=\frac 1 2 \label{eq:98}
5177	   \begin{bmatrix}
5178	     2 I_{3\times 3} & & 0_{3\times 3} & \\
5179	     &   -p_1 & -p_2 & -p_3 \\
5180	     0_{4\times 3}  &  p_0 & -p_3 & p_2 \\
5181	     & p_3 & p_0 & -p_1 \\
5182	     & -p_2 & p_1 & p_0
5183	   \end{bmatrix}
5184
5185      todo :
5186
5187      -  computation of the directional derivative of
5188	 :math:`R(\Omega)= exp(\tilde \Omega)` in the direction
5189	 :math:`\tilde\Omega`, to get :math:`T(\Omega)`
5190
5191      Quaternion representation
5192      '''''''''''''''''''''''''
5193
5194      If the Lie group is described by unit quaternion, we get
5195
5196      .. math::
5197
5198	 \label{eq:99}
5199	   SO(3) = \{p = (p_0,\vv{p}) \in {\mbox{\rm $I\!\!R$}}^{4}\mid |p|=1  \}
5200
5201      with the composition law :math:`p_1\glaw p_2` given by the quaternion
5202      product.
5203
5204      Note that the concept of exponential map for Lie group that are not
5205      parameterized by matrices is also possible.
5206
5207      Mechanical systems with bilateral and unilateral constraints
5208      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5209
5210      Let us consider that the system ([eq:Newton-Euler-compact]) is subjected
5211      to :math:`m` constraints, with :math:`m_{e}` holonomic bilateral
5212      constraints
5213
5214      .. math::
5215
5216	 \label{eq:bilateral-constraints}
5217	   h^\alpha(q)=0, \alpha \in \mathcal{E}\subset{\mbox{\rm $I\!\!N$}},  |\mathcal E| = m_e,
5218
5219      and :math:`m_{i}` unilateral constraints
5220
5221      .. math::
5222
5223	 \label{eq:unilateral-constraints}
5224	   g_{\n}^\alpha(q)\geq 0, \alpha \in \mathcal{I}\subset{\mbox{\rm $I\!\!N$}},  |\mathcal I| = m_i.
5225
5226      Let us denote as :math:`J^\alpha_h(q) = \nabla^\top_q h^\alpha(q)  ` the
5227      Jacobian matrix of the bilateral constraint :math:`h^\alpha(q)` with
5228      respect to :math:`q` and as :math:`J^\alpha_{g_\n}(q)` respectively for
5229      :math:`g_{\n}^\alpha(q)` . The bilateral constraints at the velocity
5230      level can be obtained as:
5231
5232      .. math::
5233
5234	 \label{eq:bilateral-constraints-velocity}
5235	  0 = \dot h^\alpha(q)= J^\alpha_h(q)\dot q = J^\alpha_h(q) T(q) v \coloneqq H^\alpha(q)  v,\quad  \alpha \in \mathcal{E}.
5236
5237      By duality and introducing a Lagrange multiplier
5238      :math:`\lambda^\alpha, \alpha \in \mathcal E`, the constraint generates
5239      a force applied to the body equal to
5240      :math:`H^{\alpha,\top}(q)\lambda^\alpha`. For the unilateral
5241      constraints, a Lagrange multiplier
5242      :math:`\lambda_{\n}^\alpha, \alpha \in \mathcal I` is also associated
5243      and the constraints at the velocity level can also be derived as
5244
5245      .. math::
5246
5247	 \label{eq:unilateral-constraints-velocity}
5248	  0 \leq  \dot g_\n^\alpha(q)= J^\alpha_{g_\n}(q) \dot q = J^\alpha_{g_\n}(q)  T(q) v , \text{ if } g_{\n}^\alpha(q) = 0,\quad  \alpha \in \mathcal{I}.
5249
5250      Again, the force applied to the body is given by
5251      :math:`(J^\alpha_{g_\n}(q) T(q))^\top\lambda^\alpha_\n`. Nevertheless,
5252      there is no reason that :math:`\lambda^\alpha_\n =r^\alpha_\n` and
5253      :math:`u_\n = J^\alpha_{g_\n}(q) T(q) v` if the :math:`g_n` is not
5254      chosen as the signed distance (the gap function). This is the reason why
5255      we prefer directly define the normal and the tangential local relative
5256      velocity with respect to the twist vector as
5257
5258      .. math::
5259
5260	 \label{eq:unilateral-constraints-velocity-kinematic1}
5261	    u^\alpha_\n  \coloneqq G_\n^\alpha(q) v, \quad u^\alpha_\t  \coloneqq G_\t^\alpha(q) v, \quad \alpha \in \mathcal{I},
5262
5263      and the associated force as :math:`G_\n^{\alpha,\top}(q) r^{\alpha}_\n `
5264      and :math:`G_\t^{\alpha,\top}(q) r^{\alpha}_\t`. For the sake of
5265      simplicity, we use the notation
5266      :math:`u^\alpha  \coloneqq G^\alpha(q) v` and its associated total force
5267      generated by the contact :math:`\alpha` as
5268      :math:`G^{\alpha,\top}(q) r^{\alpha} \coloneqq G_\n^{\alpha,\top}(q) r^{\alpha}_\n + G_\t^{\alpha,\top}(q) r^{\alpha}_\t `.
5269
5270      The complete system of equation of motion can finally be written as
5271
5272      |    q = T(q)v ,
5273      |    M v = F(t,q,v) + H\ :sup:``\ (q) + G\ :sup:``\ (q) r,
5274      | [0.5ex]   
5275
5276      | ll H\ :sup:``\ (q) v = 0 ,& E
5277      | .
5278
5279      | ll r\ :sup:``\ = 0 , & g\ :sub:``\ :sup:``\ (q) > 0,
5280      | K\ :sup:`,\*` u\ :sup:``  r\ :sup:``, & g\ :sub:``\ :sup:``\ (q) = 0,
5281      | u\ :sub:``\ :sup:`,+` = -e:sub:`r`\ :sup:``\ u\ :sub:``\ :sup:`,-`, &
5282      g\ :sub:``\ :sup:``\ (q) = 0 u\ :sub:``\ :sup:`,-` 0,
5283
5284      } & I [eq:NewtonEuler-uni]
5285
5286      where the definition of the variables
5287      :math:`\lambda\in {\mbox{\rm $I\!\!R$}}^{m_e}, r\in {\mbox{\rm $I\!\!R$}}^{3m_i}`
5288      and the operators :math:`H,G` are extended to collect all the variables
5289      for each constraints.
5290
5291      Note that all the constraints are written at the velocity integrators.
5292      Another strong advantage is the straightforward introduction of the
5293      contact dissipation processes that are naturally written at the velocity
5294      level such as the Newton impact law and the Coulomb friction. Indeed, in
5295      Mechanics, dissipation processes are always given in terms of rates of
5296      changes, or if we prefer, in terms of velocities.
5297
5298      Siconos Notation
5299      ''''''''''''''''
5300
5301      In the siconos notation, we have for the applied torques on the system
5302      the following decomposition
5303
5304      .. math::
5305
5306	 F(t,q,v):= \begin{pmatrix}
5307	     f(t,x_{\cg},  v_{\cg}, R, \Omega ) \\
5308	     I \Omega \times \Omega + M(t,x_{\cg}, v_{\cg}, R, \Omega )
5309	   \end{pmatrix}
5310	   := \begin{pmatrix}
5311	     f_{ext}(t)  - f_{int}(x_{\cg},  v_{\cg}, R, \Omega ) \\
5312	     - M_{gyr}(\Omega) + M_{ext}(t) -  M_{int}(x_{\cg}, v_{\cg}, R, \Omega )
5313	   \end{pmatrix}.
5314
5315      with
5316
5317      .. math::
5318
5319	 M_{gyr} := \begin{pmatrix}
5320	      \Omega \times I\Omega
5321	   \end{pmatrix}
5322
5323      In the siconos notation, we have for the relation
5324
5325      .. math::
5326
5327	 \label{eq:100}
5328	    C =   J^\alpha(q) \quad CT = J^\alpha(q)T(q)
5329
5330      Time integration scheme in scheme
5331      ---------------------------------
5332
5333      Moreau–Jean scheme based on a :math:`\theta`-method
5334      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5335
5336      The complete Moreau–Jean scheme based on a :math:`\theta`-method is
5337      written as follows
5338
5339      .. math::
5340
5341	 \label{eq:Moreau--Jean-theta}
5342	     \begin{cases}
5343	       ~~\begin{array}{l}
5344		 q_{k+1} = q_{k} + h T(q_{k+\theta}) v_{k+\theta} \quad \\[1ex]
5345		 M(v_{k+1}-v_k) - h  F(t_{k+\theta}, q_{k+\theta},v_{k+\theta}) =  H^\top(q_{k+1}) Q_{k+1} + G^\top(q_{k+1}) P_{k+1},\quad\,\\[1ex]
5346	       \end{array}\\
5347	       ~~\begin{array}{lcl}
5348		 \begin{array}{l}
5349		   H^\alpha(q_{k+1}) v_{k+1}  =  0\\
5350		 \end{array} & \left. \begin{array}{l}
5351		   \vphantom{H^\alpha(q_{k+1}) v_{k+1}  =  0}\\[1ex]
5352		 \end{array}\right\}    &\alpha \in \mathcal E  \\[1ex]
5353	       ~~~P_{k+1}^\alpha= 0, &
5354	       \left. \begin{array}{l}
5355		   \vphantom{P_{k+1}^\alpha= 0,  \delta^\alpha_{k+1}=0}\\[1ex]
5356		 \end{array}\right\}   & \alpha \not\in \mathcal I^\nu \\[1ex]
5357			   \begin{array}{l}
5358		   {K}^{\alpha,*} \ni \widehat u_{k+1}^\alpha~ \bot~ P_{k+1}^\alpha \in {K}^\alpha \\
5359	       \end{array} &
5360	       \left.\begin{array}{l}
5361		   \vphantom{{K}^{\alpha,*} \ni \widehat u_{k+1}^\alpha~ \bot~ P_{k+1}^\alpha \in {K}^\alpha} \\
5362		 \end{array}\right\}
5363	       &\alpha \in \mathcal I^\nu\\
5364	   \end{array}
5365	 \end{cases}
5366
5367      where :math:`\mathcal I^\nu` is the set of forecast constraints, that
5368      may be evaluated as
5369
5370      .. math::
5371
5372	 \label{eq:101}
5373	   \mathcal I^\nu = \{\alpha \mid \bar g_\n^\alpha \coloneqq g_\n + \frac h 2 u^\alpha_\n \leq 0\}.
5374
5375      Semi-explicit version Moreau–Jean scheme based on a :math:`\theta`-method
5376      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5377
5378      .. math::
5379
5380	 \label{eq:Moreau--Jean-explicit}
5381	     \begin{cases}
5382	       ~~\begin{array}{l}
5383		 q_{k+1} = q_{k} + h T(q_{k}) v_{k+\theta} \quad \\[1ex]
5384		 M(v_{k+1}-v_k) - h  F(t_{k}, q_{k},v_{k}) =  H^\top(q_{k}) Q_{k+1}+  G^\top(q_{k}) P_{k+1},\quad\,\\[1ex]
5385	       \end{array}\\
5386	       ~~\begin{array}{lcl}
5387		 \begin{array}{l}
5388		   H^\alpha(q_{k+1}) v_{k+1}  =  0\\
5389		 \end{array} & \left. \begin{array}{l}
5390		   \vphantom{H^\alpha(q_{k+1}) v_{k+1}  =  0}\\[1ex]
5391		 \end{array}\right\}    &\alpha \in \mathcal E  \\[1ex]
5392	       ~~P_{k+1}^\alpha= 0, &
5393	       \left. \begin{array}{l}
5394		   \vphantom{P_{k+1}^\alpha= 0,  \delta^\alpha_{k+1}=0}\\[1ex]
5395		 \end{array}\right\}   & \alpha \not\in \mathcal I^\nu \\[1ex]
5396			   \begin{array}{l}
5397		   {K}^{\alpha,*} \ni \widehat u_{k+1}^\alpha~ \bot~ P_{k+1}^\alpha \in {K}^\alpha \\
5398	       \end{array} &
5399	       \left.\begin{array}{l}
5400		   \vphantom{{K}^{\alpha,*} \ni \widehat u_{k+1}^\alpha~ \bot~ P_{k+1}^\alpha \in {K}^\alpha} \\
5401		 \end{array}\right\}
5402	       &\alpha \in \mathcal I^\nu\\
5403	   \end{array}
5404	 \end{cases}
5405
5406      In this version, the new velocity :math:`v_{k+1}` can be computed
5407      explicitly, assuming that the inverse of :math:`M` is easily written, as
5408
5409      .. math::
5410
5411	 \label{eq:Moreau--Jean-theta--explicit-v}
5412	   v_{k+1}   =  v_k + M^{-1} h  F(t_{k}, q_{k},v_{k}) +  M^{-1} (H^\top(q_{k}) Q_{k+1}+  G^\top(q_{k}) P_{k+1})
5413
5414      Nearly implicit version Moreau–Jean scheme based on a :math:`\theta`-method implemented in siconos
5415      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5416
5417      A first simplification is made considering a given value of
5418      :math:`q_{k+1}` in :math:`T()`, :math:`H()` and :math:`G()` denoted by
5419      :math:`\bar q_k`. This limits the computation of the Jacobians of this
5420      operators with respect to :math:`q`.
5421
5422      .. math::
5423
5424	 \label{eq:Moreau--Jean-theta-nearly}
5425	     \begin{cases}
5426	       ~~\begin{array}{l}
5427		 q_{k+1} = q_{k} + h T(\bar q_k) v_{k+\theta} \quad \\[1ex]
5428		 M(v_{k+1}-v_k) - h  \theta F(t_{k+1}, q_{k+1},v_{k+1}) - h (1- \theta) F(t_{k}, q_{k},v_{k})  =  H^\top(\bar q_k) Q_{k+1} + G^\top(\bar q_k) P_{k+1},\quad\,\\[1ex]
5429	       \end{array}\\
5430	       ~~\begin{array}{lcl}
5431		 \begin{array}{l}
5432		   H^\alpha(\bar q_k) v_{k+1}  =  0\\
5433		 \end{array} & \left. \begin{array}{l}
5434		   \vphantom{H^\alpha(q_{k+1}) v_{k+1}  =  0}\\[1ex]
5435		 \end{array}\right\}    &\alpha \in \mathcal E  \\[1ex]
5436	       ~~P_{k+1}^\alpha= 0, &
5437	       \left. \begin{array}{l}
5438		   \vphantom{P_{k+1}^\alpha= 0,  \delta^\alpha_{k+1}=0}\\[1ex]
5439		 \end{array}\right\}   & \alpha \not\in \mathcal I^\nu \\[1ex]
5440			   \begin{array}{l}
5441		   {K}^{\alpha,*} \ni \widehat u_{k+1}^\alpha~ \bot~ P_{k+1}^\alpha \in {K}^\alpha \\
5442	       \end{array} &
5443	       \left.\begin{array}{l}
5444		   \vphantom{{K}^{\alpha,*} \ni \widehat u_{k+1}^\alpha~ \bot~ P_{k+1}^\alpha \in {K}^\alpha} \\
5445		 \end{array}\right\}
5446	       &\alpha \in \mathcal I^\nu\\
5447	   \end{array}
5448	 \end{cases}
5449
5450      The nonlinear residu is defined as
5451
5452      .. math::
5453
5454	 \label{eq:Moreau--Jean-theta--nearly-residu}
5455	   \mathcal R(v) =  M(v-v_k) - h  \theta F(t_{k+1}, q(v),v) - h (1- \theta) F(t_{k}, q_{k},v_{k}) - H^\top(\bar q_k) Q_{k+1} - G^\top(\bar q_k) P_{k+1}
5456
5457      with
5458
5459      .. math::
5460
5461	 \label{eq:Moreau--Jean-theta--nearly-residu1}
5462	   q(v) = q_{k} + h T(\bar q_k)) ((1-\theta) v_k + \theta v).
5463
5464      At each time step, we have to solve
5465
5466      .. math::
5467
5468	 \label{eq:Moreau--Jean-theta--nearly-residu2}
5469	   \mathcal R(v_{k+1}) =  0
5470
5471      together with the constraints.
5472
5473      Let us write a linearization of the problem to design a Newton
5474      procedure:
5475
5476      .. math::
5477
5478	 \label{eq:Moreau--Jean-theta--nearly-residu3}
5479	   \nabla^\top_v \mathcal R(v^{\tau}_{k+1})(v^{\tau+1}_{k+1}-v^{\tau}_{k+1}) = -  \mathcal R(v^{\tau}_{k+1}).
5480
5481      The computation of :math:` \nabla^\top_v \mathcal R(v^{\tau}_{k+1})` is
5482      as follows
5483
5484      .. math::
5485
5486	 \label{eq:102}
5487	   \nabla^\top_v \mathcal R(v) = M - h \theta \nabla_v F(t_{k+1}, q(v),v)
5488
5489      with
5490
5491      .. math::
5492
5493	 \label{eq:103}
5494	   \begin{array}{lcl}
5495	     \nabla_v F(t_{k+1}, q(v),v) &=& D_2 F(t_{k+1}, q(v),v) \nabla_v q(v) + D_3 F(t_{k+1}, q(v),v) \\
5496					 &=& h \theta D_2 F(t_{k+1}, q(v),v) T(\bar q_k) + D_3 F(t_{k+1}, q(v),v) \\
5497	   \end{array}
5498
5499      where :math:`D_i` denotes the derivation with respect the :math:`i^{th}`
5500      variable. The complete Jacobian is then given by
5501
5502      .. math::
5503
5504	 \label{eq:104}
5505	   \nabla^\top_v \mathcal R(v) = M - h \theta D_3 F(t_{k+1}, q(v),v) - h^2 \theta^2 D_2 F(t_{k+1}, q(v),v) T(\bar q_k)
5506
5507      In siconos, we ask the user to provide the functions
5508      :math:`D_3 F(t_{k+1}, q ,v )` and :math:`D_2 F(t_{k+1}, q,v)`.
5509
5510      Let us denote by :math:`W^{\tau}` the inverse of Jacobian of the residu,
5511
5512      .. math::
5513
5514	 \label{eq:105}
5515	   W^{\tau} = (M - h \theta D_3 F(t_{k+1}, q(v),v) - h^2 \theta^2 D_2 F(t_{k+1}, q(v),v) T(\bar q_k))^{-1}.
5516
5517      and by :math:`\mathcal R_{free}(v)` the free residu,
5518
5519      .. math::
5520
5521	 \label{eq:106}
5522	   \mathcal R_{free}(v) =  M(v-v_k) - h  \theta F(t_{k+1}, q(v),v) - h (1- \theta) F(t_{k}, q_{k},v_{k}).
5523
5524      The linear equation [eq:Moreau–Jean-theta–nearly-residu3] that we have
5525      to solve is equivalent to
5526
5527      .. math::
5528
5529	 \label{eq:107}
5530	   \boxed{v^{\tau+1}_{k+1} = v^{\tau}_{k+1} - W  \mathcal R_{free}(v^\tau_{k+1}) + W   H^\top(\bar q_k) Q^{\tau+1}_{k+1} + W G^\top(\bar q_k) P^{\tau+1}_{k+1}}
5531
5532      We define :math:`v_{free}` as
5533
5534      .. math::
5535
5536	 \label{eq:108}
5537	   v_{free}  = v^{\tau}_{k+1} - W  \mathcal R_{free}(v^\tau_{k+1})
5538
5539      The local velocity at contact can be written
5540
5541      .. math::
5542
5543	 \label{eq:109}
5544	   u^{\tau+1}_{\n,k+1} = G(\bar q_k) [  v_{free}^{\tau} + W   H^\top(\bar q_k) Q^{\tau+1}_{k+1} + W G^\top(\bar q_k) P^{\tau+1}_{k+1}]
5545
5546      and for the equality constraints
5547
5548      .. math::
5549
5550	 \label{eq:110}
5551	   u^{\tau+1}_{k+1} = H(\bar q_k) [  v_{free}^{\tau} + W   H^\top(\bar q_k) Q^{\tau+1}_{k+1} + W G^\top(\bar q_k) P^{\tau+1}_{k+1}]
5552
5553      Finally, we get a linear relation between :math:`u^{\tau+1}_{\n,k+1}`
5554      and the multiplier
5555
5556      .. math::
5557
5558	 \label{eq:111}
5559	  \boxed{ u^{\tau+1}_{k+1} =
5560	   \begin{bmatrix}
5561	     H(\bar q_k) \\
5562	     G(\bar q_k)
5563	   \end{bmatrix} v_{free}^{\tau}
5564	   +
5565	   \begin{bmatrix}
5566	     H(\bar q_k)W   H^\top(\bar q_k) & H(\bar q_k)W   G^\top(\bar q_k) \\
5567	     G(\bar q_k)W   H^\top(\bar q_k) & G(\bar q_k)W   G^\top(\bar q_k) \\
5568	   \end{bmatrix}
5569	   \begin{bmatrix}
5570	     Q^{\tau+1}_{k+1} \\
5571	     P^{\tau+1}_{k+1}
5572	   \end{bmatrix}}
5573
5574      choices for :math:`\bar q_k`
5575      ''''''''''''''''''''''''''''
5576
5577      Two choices are possible for :math:`\bar q_k`
5578
5579      #. :math:`\bar q_k = q_k`
5580
5581      #. :math:`\bar q_k = q^{\tau}_{k+1}`
5582
5583      todo list:
5584
5585      -  add the projection step for the unit quaternion
5586
5587      -  describe the computation of H and G that can be hybrid
5588
5589      Computation of the Jacobian in special case
5590      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5591
5592      Moment of gyroscopic forces
5593      '''''''''''''''''''''''''''
5594
5595      Let us denote by the basis vector :math:`e_i` given the :math:`i^{th}`
5596      column of the identity matrix :math:`I_{3\times3}`. The Jacobian of
5597      :math:`M_{gyr}` is given by
5598
5599      .. math::
5600
5601	 \label{eq:112}
5602	   \nabla^\top_\Omega M_{gyr}(\Omega) = \nabla^\top_\Omega (\Omega \times I \Omega) =
5603	   \begin{bmatrix}
5604	     e_i \times I \Omega + \Omega \times I e_i, i =1,2,3
5605	   \end{bmatrix}
5606
5607      Linear internal wrench
5608      ''''''''''''''''''''''
5609
5610      If the internal wrench is given by
5611
5612      .. math::
5613
5614	 \label{eq:113}
5615	   F_{int}(t,q,v) =
5616	   \begin{bmatrix}
5617	     f_{int}(t,q,v)\\
5618	     M_{int}(t,q,v)
5619	   \end{bmatrix}
5620	   = C v + K q, \quad C \in {\mbox{\rm $I\!\!R$}}^{6\times 6}, \quad K \in {\mbox{\rm $I\!\!R$}}^{6\times 7 }
5621
5622      we get
5623
5624      .. math::
5625
5626	 \label{eq:114}
5627	   \begin{array}{lcl}
5628	     \nabla_v F(t_{k+1}, q(v),v)  &=& h \theta K T(\bar q_k) + C \\
5629	     \nabla^\top_v \mathcal R(v) &=& M - h \theta C - h^2 \theta^2 K T(\bar q_k)
5630	   \end{array}
5631
5632      External moment given in the inertial frame
5633      '''''''''''''''''''''''''''''''''''''''''''
5634
5635      If the external moment denoted by :math:`m_{ext} (t)` is expressed in
5636      inertial frame, we have
5637
5638      .. math::
5639
5640	 \label{eq:115}
5641	   M_{ext}(q,t) = R^T m_{ext}(t)= \Phi(p) m_{ext}(t)
5642
5643      In that case, :math:`  M_{ext}(q,t)` appears as a function :math:`q` and
5644      we need to compute its Jacobian w.r.t :math:`q`. This computation needs
5645      the computation of
5646
5647      .. math::
5648
5649	 \label{eq:116}
5650	   \nabla_{p} M_{ext}(q,t) = \nabla_{p} \Phi(p) m_{ext}(t)
5651
5652      Let us compute first
5653
5654      .. math::
5655
5656	 \label{eq:117}
5657	   \Phi(p) m_{ext}(t)  =
5658	   \begin{bmatrix}
5659	     (1-2 p_2^2- 2 p_3^2)m_{ext,1} + 2(p_1p_2-p_3p_0)m_{ext,2} + 2(p_1p_3+p_2p_0)m_{ext,3}\\
5660	     2(p_1p_2+p_3p_0)m_{ext,1}  +(1-2 p_1^2- 2 p_3^2)m_{ext,2} + 2(p_2p_3-p_1p_0)m_{ext,3}\\
5661	     2(p_1p_3-p_2p_0)m_{ext,1}  + 2(p_2p_3+p_1p_0)m_{ext,2}  + (1-2 p_1^2- 2 p_2^2)m_{ext,3}\\
5662	   \end{bmatrix}
5663
5664      Then we get
5665
5666      .. math::
5667
5668	 \label{eq:118}
5669	   \begin{array}{l}
5670	   \nabla_{p} \Phi(p) m_{ext}(t)  =\\
5671	   \begin{bmatrix}
5672	     -2 p_3 m_{ext,2} + 2 p_2 m_{ext,3} & 2p_2 m_{ext,2}+2 p_3 m_{ext,3}  & -4 p_2 m_{ext,1} +2p_1 m_{ext,2}+2 p_0 m_{ext,3} & -3 p_3 m_{ext,1} -2p_0 m_{ext,2} +2 p_1m_{ext,3}  \\
5673	     2p_3 m_{ext,1} -2p_1m_{ext,3}  & 2p_2m_{ext,1} -4p_1 m_{ext,2} -2p_1 m_{ext,3} & & &  \\
5674	   \end{bmatrix}
5675	   \end{array}
5676
5677      Siconos implementation
5678      ~~~~~~~~~~~~~~~~~~~~~~
5679
5680      The
5681      expression: \ :math:`\mathcal R_{free}(v^\tau_{k+1}) = M(v-v_k) - h  \theta F(t_{k+1}, q(v^\tau_{k+1}),v^\tau_{k+1}) - h (1- \theta) F(t_{k}, q_{k},v_{k})`
5682      is computed in MoreauJeanOSI::computeResidu() and saved in
5683      ds->workspace(DynamicalSystem::freeresidu)
5684
5685      The
5686      expression: \ :math:`\mathcal R(v^\tau_{k+1}) =\mathcal R_{free}(v^\tau_{k+1}) - h (1- \theta) F(t_{k}, q_{k},v_{k}) - H^\top(\bar q_k) Q_{k+1} - G^\top(\bar q_k) P_{k+1}  `
5687      is computed in MoreauJeanOSI::computeResidu() and saved in
5688      ds->workspace(DynamicalSystem::free).
5689
5690      really a bad name for the buffer ds->workspace(DynamicalSystem::free).
5691      Why we are chosing this name ? to save some memory ?
5692
5693      The
5694      expression: \ :math:`v_{free}  = v^{\tau}_{k+1} - W  \mathcal R_{free}(v^\tau_{k+1})`
5695      is compute in MoreauJeanOSI::computeFreeState() and saved in
5696      d->workspace(DynamicalSystem::free).
5697
5698      | The computation: 
5699      :math:`v^{\tau+1}_{k+1} = v_{free} + W   H^\top(\bar q_k) Q^{\tau+1}_{k+1} + W G^\top(\bar q_k) P^{\tau+1}_{k+1}`
5700      is done in MoreauJeanOSI::updateState and stored in d->twist().
5701
5702      NewtonEulerR: computation of :math:`\nabla _qH`
5703      ===============================================
5704
5705      Gradient computation, case of NewtonEuler with quaternion
5706      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5707
5708      In the section, :math:`q` is the quaternion of the dynamical system.
5709
5710      [figCase]
5711
5712      The normal vector :math:`N` is view as a constant.
5713
5714      .. math::
5715
5716	 ~\tilde h(q)=P_c(\frac{q}{\|q\|})
5717
5718      .. math::
5719
5720	 ^t \nabla h(q)(\delta q) = \lim _{e \to 0}\frac{(\tilde h (q+e\delta q)-\tilde h (q)).N}{e}
5721
5722      :math:`\nabla _q h` consist in computing
5723      :math:`P_c(\frac{q+\delta q}{\|q+\delta q\|})-P_c(q)`.
5724
5725      .. math::
5726
5727	 GP(q)=qG_0P_0~^cq
5728
5729      .. math::
5730
5731	 GP(\frac{q+\delta q}{\|q+\delta q\|})=(q+\delta q)G_0P_0~^c(q+\delta q)\frac{1}{\|q+\delta q\|^2}
5732
5733      .. math::
5734
5735	 =(q+\delta q)~^cqGP(q)q~^c(q+\delta q)\frac{1}{\|q+\delta q\|^2}
5736
5737      .. math::
5738
5739	 =((1,0,0,0)+\delta q~^cq)GP(q)((1,0,0,0)+q~^c\delta q)\frac{1}{\|q+\delta q\|^2}
5740
5741      .. math::
5742
5743	 =GP(q)+\delta q~^cqGP(q) + GP(q)q~^c\delta q+0(\delta q)^2\frac{1}{\|q+\delta q\|^2}
5744
5745       So, because G is independant of :math:`q`:
5746
5747      .. math::
5748
5749	 P(\frac{q+\delta q}{\|q+\delta q\|})-P(q)=qGP(\frac{q+\delta q}{\|q+\delta q\|})-GP(q)=\delta q~^cqGP(q) + GP(q)q~^c\delta q+0(\delta q)^2 + GP(q)\frac{1}{\|q+\delta q\|^2}
5750
5751       For the directional derivation, we chose
5752      :math:`\delta q = \epsilon * (1,0,0,0)`. using a equivalent to
5753      :math:`\frac{1}{1+\epsilon}`
5754
5755      .. math::
5756
5757	 \lim_{\epsilon \to 0}\frac{P(\frac{q+\delta q}{\|q+\delta q\|})-P(q)}{\epsilon}=~^cqGP(q) + GP(q)q-2q_iGP(q)
5758
5759       For the directional derivation, we chose
5760      :math:`\delta q = \epsilon * (0,1,0,0)=\epsilon * e_i`
5761
5762      .. math::
5763
5764	 \lim_{\epsilon \to 0}\frac{P(\frac{q+\delta q}{\|q+\delta q\|})-P(q)}{\epsilon}=e_i~^cqGP(q) - GP(q)qe_i-2q_iGP(q)
5765
5766       Application to the NewtonEulerRImpact:
5767
5768      .. math::
5769
5770	 H:\mathbb{R}^7 \to \mathbb{R}
5771
5772      .. math::
5773
5774	 \nabla _q H \in \mathcal{M}^{1,7}
5775
5776      .. math::
5777
5778	 \nabla _q H =\left(\begin{array}{c} N_x\\N_y\\N_z\\
5779	 (~^cqGP(q) + GP(q)q-2q_0GP(q)).N\\
5780	 (e_2~^cqGP(q) - GP(q)qe_2-2q_1GP(q)).N\\
5781	 (e_3~^cqGP(q) - GP(q)qe_3-2q_2GP(q)).N\\
5782	 (e_4~^cqGP(q) - GP(q)qe_4-2q_3GP(q)).N\\
5783	 \end{array}\right)
5784
5785      Ball case
5786      ~~~~~~~~~
5787
5788      It is the case where :math:`GP=-N`: for :math:`e2`:
5789
5790      .. math::
5791
5792	 (0,1,0,0).(q_0,-\underline p).(0,-N)=
5793
5794      .. math::
5795
5796	 \left(\left(\begin{array}{c}1\\0\\0\end{array}\right).\underline p,\left(\begin{array}{c}q_0\\0\\0\end{array}\right) -\left(\begin{array}{c}1\\0\\0\end{array}\right)*\underline p \right).(0,-N)=
5797
5798      .. math::
5799
5800	 \left(?, -\underline p_x~N-\left(\left(\begin{array}{c}q_0\\0\\0\end{array}\right)- \left(\begin{array}{c}1\\0\\0\end{array}\right)*\underline p \right)*N\right)=
5801
5802       and:
5803
5804      .. math::
5805
5806	 (0,-N).(q_0,\underline p).(0,1,0,0)=
5807
5808      .. math::
5809
5810	 (N.\underline p,-q_0N-N*\underline p).(0,1,0,0)=
5811
5812      .. math::
5813
5814	 \left(?,(N.\underline p)\left(\begin{array}{c}1\\0\\0\end{array}\right) + \left(\begin{array}{c}1\\0\\0\end{array}\right)*(q_0N+N*\underline p)\right)=
5815
5816      .. math::
5817
5818	 \left(?,(N.\underline p)\left(\begin{array}{c}1\\0\\0\end{array}\right)+q_0 \left(\begin{array}{c}1\\0\\0\end{array}\right)*N+\left(\begin{array}{c}1\\0\\0\end{array}\right)*(N*\underline p)\right)
5819
5820       sub then and get the resulting vector.N:
5821
5822      .. math::
5823
5824	 \left[ -\underline p_x~N -N.\underline p~\left(\begin{array}{c}1\\0\\0\end{array}\right)+()*N-\left(\begin{array}{c}1\\0\\0\end{array}\right)*(N*\underline p)\right].N=
5825
5826      .. math::
5827
5828	 -\underline p_x-N_xN.\underline p+0-(\left(\begin{array}{c}1\\0\\0\end{array}\right)*(N*\underline p)).N=
5829
5830       using :math:`a*(b*c)=b(a.c)-c(a.b)` leads to
5831
5832      .. math::
5833
5834	 -q_1-N_xN.\underline p-(q_1~N-N_x~\underline p).N=
5835
5836      .. math::
5837
5838	 -q_1-N_xN.\underline p-q_1+N_xN.\underline p=-2q_1
5839
5840       for :math:`e1=(1,0,0,0)`:
5841
5842      .. math::
5843
5844	 (q_0,-\underline p).(0,-N)=(?,-q_0N+\underline p*N)
5845
5846      .. math::
5847
5848	 (0,-N).(q_0,\underline p)=(?,-q_0N-\underline p*N)
5849
5850       So
5851
5852      .. math::
5853
5854	 \nabla _q H =\left(\begin{array}{c} N_x\\N_y\\N_z\\
5855	 0\\
5856	 0\\
5857	 0\\
5858	 0\\
5859	 \end{array}\right)
5860
5861      Case FC3D: using the local frame and momentum
5862      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5863
5864      .. math::
5865
5866	 \left(\begin{array}{c}m \dot V\\I \dot \Omega + \Omega I \Omega \end{array}\right)= \left(\begin{array}{c}Fect+R\\Mext _{R_{obj}} + (R*PG) _{R_{obj}} \end{array}\right)
5867
5868      with \* vectoriel product, :math:`R` reaction in the globla frame.
5869      :math:`P` the point of contact. :math:`r` is the reaction in the local
5870      frame. :math:`M_{R_{obj}toR_{abs}}=M_{R_{abs}toR_{obj}}^t r=R` with:
5871
5872      .. math::
5873
5874	 M_{R_{C}toR_{abs}}=\left(\begin{array}{ccc} nx&t_1x&t_2x \\ny&t_1y&t_2y\\nz&t_1z&t_2z \end{array}\right)
5875
5876       we have :
5877
5878      .. math::
5879
5880	 \left(\begin{array}{c}R\\(R*PG) _{R_{obj}}\end{array}\right)=\left(\begin{array}{c} I_3\\M_{R_{abs}toR_{obj}}N_{PG}\end{array}\right).R
5881
5882      .. math::
5883
5884	 =\left(\begin{array}{c} I_3\\M_{R_{abs}toR_{obj}}N_{PG}\end{array}\right).M_{R_{obj}toR_{abs}}r
5885
5886      .. math::
5887
5888	 N_{PG}=\left(\begin{array}{ccc} 0&PG_z&-PG_y\\-PG_z&0&PG_x\\PG_y&-PG_X&0\end{array}\right)
5889
5890       that is:
5891
5892      .. math::
5893
5894	 \left(\begin{array}{c}m \dot V\\I \dot \Omega + \Omega I \Omega \end{array}\right)=
5895	 \left(\begin{array}{c} M_{R_{C}toR_{abs}} \\
5896	   M_{R_{abs}toR_{obj}}N_{PG}M_{R_{C}toR_{abs}}
5897	 \end{array}\right) r
5898
5899      So :math:`jachqt=MN`
5900
5901      Case FC3D: using the local frame local velocities
5902      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5903
5904      [figCase]
5905
5906      We are looking for an operator named :math:`CT` such that:
5907
5908      .. math::
5909
5910	 V_C=\left(\begin{array}{c} V_N \\ V_T \\ V_S \end{array}\right)_{R_{C}}=CT \left(\begin{array}{c} V_{G1}~_{R_{abs}} \\ \Omega_1~_{R_{obj1}} \\ V_{G2}~_{R_{abs}}\\ \Omega_2~_{R_{obj2}} \end{array}\right)
5911
5912      .. math::
5913
5914	 V_c=V_{G1}~_{R_{abs}} + w_1 * G_1P~_{R_{abs}} -(V_{G2}~_{R_{abs}} + w_2 * G_1P~_{R_{abs}})
5915
5916      where :math:`w_1` and :math:`w_2` are given in :math:`R_{abs}`. We note
5917      :math:`M_{R_{obj1}toR_{abs}}` the matrice converting the object 1
5918      coordinate to the absolute coordinate. We note :math:`N_{GP}` the
5919      matrice such that :math:`w_1*G_1P~_{R_{abs}} = N_{GC} w_1`. Endly, we
5920      note :math:`M_{R_{abs}toR_C}` converting the absolute coordinate to the
5921      :math:`R_C` frame. we get:
5922
5923      .. math::
5924
5925	 CT= M_{R_{abs}toR_C}   \left(\begin{array}{cccc} I_3 & N_{G_1C}M_{R_{obj1}toR_{abs}} & -I_3 & -N_{G_2C}M_{R_{obj2}toR_{abs}} \end{array}\right)
5926
5927      Expression of :math:`M_{R_{obj1}toR_{abs}}`
5928      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5929
5930      Using quaternion, we get :
5931
5932      .. math::
5933
5934	 \label{eq:newton_Mobjtoabs}
5935	 M_{R_{obj1}toR_{abs}} = \left(\begin{array}{ccc} q \left(\begin{array}{c}1\\0\\0 \end{array}\right)~^cq & q \left(\begin{array}{c}  0\\1\\0 \end{array}\right)~ ^cq & q \left(\begin{array}{c}  0\\0\\1 \end{array}\right)~ ^cq  \end{array}\right)
5936
5937      Expression of :math:`N_1`
5938      ^^^^^^^^^^^^^^^^^^^^^^^^^
5939
5940      .. math::
5941
5942	 N_{GC}=\left(\begin{array}{ccc} 0&G_1C_z&-G_1C_y\\-G_1C_z&0&G_1C_x\\G_1C_y&-G_1C_X&0\end{array}\right)
5943
5944      Projection On constraints
5945      =========================
5946
5947      Velocity formulation
5948      ~~~~~~~~~~~~~~~~~~~~
5949
5950      The first step consists in doing a velocity formulation of the system:
5951
5952      .. math::
5953
5954	 \label{NE_Dyn1}
5955	 \begin{array}{l}
5956	   M \dot v = F_{ext}+B \lambda \\
5957	   \dot q = T v\\
5958	   y=h(q) \\
5959	   NSLAW(y,\lambda,...)\\
5960	 \end{array}
5961
5962      The constraint :math:`\dot q = T v` is suffisiant to keep a normal
5963      quaternion. Because of the speed formulation, :math:`h(q)` could violate
5964      the NSLAW. A solution coul be to add a formulation in position. We must
5965      underline that the constraints :math:`\mid Q \mid = 1` is implicit in
5966      this system. Endeed, the direction :math:`\dot q = T v` is tangential to
5967      the sphere.
5968
5969      Posion formulation
5970      ~~~~~~~~~~~~~~~~~~
5971
5972      It consists in writting a position formulation on the system:
5973
5974      .. math::
5975
5976	 \label{NE_Dyn1}
5977	 \begin{array}{l}
5978	 h(q) = \left(\begin{array}{l}
5979	   HI(q)\\HE(q)
5980	 \end{array}\right)
5981	 \end{array}
5982
5983      Approach using q
5984      ^^^^^^^^^^^^^^^^
5985
5986      | We are looking for :math:`q_1` from :math:`q_0`:
5987
5988      .. math::
5989
5990	 q_1=q_0+\nabla HI \Lambda _I + \nabla HE \Lambda _E
5991
5992      | Assume that :math:`h(q_0)` doesn’t satisfy the constraints, ie
5993      :math:` HI(q_0) \ngeq 0` or :math:` HE(q_0) \neq 0)`. Linearize
5994      :math:`h` leads to:
5995
5996      .. math::
5997
5998	 0 \leq HI(q_0) + \nabla ^t HI (\nabla HI  \Lambda _I + \nabla HE \Lambda _E) \bot \Lambda _I \geq 0
5999
6000      .. math::
6001
6002	 0=HE(q_0) + \nabla ^t HE (\nabla HI  \Lambda _I + \nabla HE \Lambda _E)
6003
6004      The getting system could be written has a MLCP:
6005
6006      .. math::
6007
6008	 C \ni h(q_0)+ \nabla ^t h(\nabla h\Lambda) , \Lambda \in C^*
6009
6010      In the case of a quaternion :math:`Q` for the rotation representation,
6011      it is noteworthy that this system doesn’t deal with the constraints
6012      :math:`\mid Q \mid = 1`. Thus, the direction :math:`(q_1,q_0)` can be
6013      normal to this constraint, in that case this approach doesn’t work. (It
6014      happens in practice) The solution that consists in normaliaed q after
6015      this formulation is not convenient because, it could be incompatible
6016      with :math:`\mid Q \mid = 1`. A better approach is to add this
6017      constraint.
6018
6019      The constraint :math:`\mid Q \mid = 1` in the system HE:
6020
6021      .. math::
6022
6023	 \tilde {HE}(q)= \left(\begin{array}{l}
6024	     HE(q)\\
6025	     \mid Q \mid -1
6026	 \end{array}\right)
6027
6028      The formulation described above can be done.
6029
6030      Approach using V
6031      ^^^^^^^^^^^^^^^^
6032
6033      It consists in building the OSNSP using :math:`CT` instead of :math:`C`.
6034
6035      .. math::
6036
6037	 \label{NE_projV}
6038	 h(q_1) = h(q_0)+\nabla ^t H \delta q
6039
6040      ie:
6041
6042      .. math::
6043
6044	 \label{NE_projV}
6045	 h(q_1) = h(q_0)+\nabla ^t H T V
6046
6047      We are looking for :math:`q_1` such that:
6048
6049      .. math::
6050
6051	 q_1-q_0 = \nabla H \Lambda
6052
6053      We have
6054
6055      .. math::
6056
6057	 \delta q=TV, \qquad ^tT\delta q=^tTTV, \qquad(^tTT)^{-1}~^tT\delta q=V
6058
6059      ie
6060
6061      .. math::
6062
6063	 h(q_1)=h(q_0)+^t\nabla _q hT(^tTT)^{-1}~^tT\nabla _q h\Lambda
6064
6065      With :math:`C=^t\nabla _q h` leading to the prolem:
6066
6067      .. math::
6068
6069	 K \ni h(q_0)+ CT~ (^tTT)^{-1}~ ^t(CT)   \Lambda \in K^*
6070
6071      Simulation of a Cam Follower System
6072      ===================================
6073
6074      | **M**\ ain Contributors: *Mario di Bernardo, Gustavo Osorio, Stefania
6075      Santini*
6076      | *University of Naples Federico II, Italy.*
6077
6078      The free body dynamics can be described by a linear second order system.
6079      An external input is considered acting directly on the follower. This
6080      input is a non linear forcing component coming from the valve. The
6081      follower motion is constrained to a phase space region bounded by the
6082      cam position. The non conservative Newton restitution law is used for
6083      the computation of the post impact velocity. The cam is assumed to be
6084      massive therefore only rotational displacement is allowed. Under these
6085      assumptions, the free body dynamics of the follower can be described by
6086
6087      .. math::
6088
6089	 \begin{aligned}
6090	   \label{eq:sols}
6091	   \mu\frac{d^2u(t)}{dt^2}+\zeta\frac{du(t)}{dt}+\kappa
6092	   u(t)=f_{v}(t),  \; \text{\hspace{5mm} \text{if} \hspace{3mm}$u(t) > c(t)$.}\end{aligned}
6093
6094      where :math:`\mu`, :math:`\zeta` and :math:`\kappa` are constant
6095      parameters for the follower mass, friction viscous damping and spring
6096      stiffness respectively. The state of the follower is given by the
6097      position :math:`u(t)` and velocity :math:`v(t)={\frac{du}{dt}}`. The
6098      external forcing is given by :math:`f_v(t)`. The cam angular position
6099      determines :math:`c(t)` that defines the holonomic (i.e. constraint only
6100      on the position) rheonomic (i.e. time varying) constraint. The dynamic
6101      behavior when impacts occurs (i.e. :math:`u(t) = c(t)`) is modelled via
6102      Newton’s impact law that in this case is given by
6103
6104      .. math::
6105
6106	 \begin{aligned}
6107	   \label{eq:il}
6108	   v(t^+)=
6109	   \frac{dc}{dt}-r\left(v(t^-)-\frac{dc}{dt}\right)=(1+r)\frac{dc}{dt}-rv(t^-), \; \text{ \text{if}\hspace{3mm}$
6110	 u(t)=c(t)$.}\end{aligned}
6111
6112      where :math:`v(t^+)` and :math:`v(t^-)` are the post and pre impact
6113      velocities respectively, :math:`\frac{dc}{dt}` is the velocity vector of
6114      the cam at the contact point with the follower, and :math:`r \in [0,1]`
6115      is the restitution coefficient to model from plastic to elastic impacts.
6116      In Figure [Fig:cam-shaft] is presented the schematic diagram of the
6117      physical cam-follower system. In Figure [Fig:cam-shaft].a for
6118      :math:`t=0`, [Fig:cam-shaft].b for :math:`t=\beta`, and
6119      [Fig:cam-shaft].c the profile of the constraint position
6120      :math:`\delta c(t)`, velocity :math:`\frac{dc}{dt}(t)` and acceleration
6121      :math:`\frac{d^2c}{dt^2}(t)`. It is possible to visualize the follower
6122      displacement as a function of the cam position. It is also important to
6123      notice that different types of cams and followers profiles are used in
6124      practical applications.
6125
6126      (90,80)(0,0) (0,0) (0,52) (2,34.5) (26,46) (15,46) (9,62) (32,62)
6127      (38,40) (66,28) (2.5,6) (52.4,6) (18.5,-1) (69.4,-1)
6128
6129      (90,80)(-3,0) (0,0) (-3,75) (-3,49) (-3,25) (30,60) (58,60) (10,60)
6130      (32,-1)
6131
6132      [Fig:cam-shaft]
6133
6134      The cam-follower as a Lagrangian NSDS.
6135      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6136
6137      It is possible to completely describe the cam-follower system as a
6138      driven impact oscillator into the framework of *Lagrangian NSDS* using a
6139      translation in space. Setting :math:`\hat u(t)=u(t)-c(t)` and
6140      :math:`\hat
6141      v(t)= v(t)-dc/dt`, then equations ([eq:sols]) and ([eq:il]) can be
6142      expressed as (the argument :math:`t` will not be explicitly written)
6143
6144      .. math::
6145
6146	 \begin{aligned}
6147	   \label{eq:trans}
6148	   \mu\frac{d^2\hat u}{dt^2}+\zeta\frac{d\hat u}{dt}+\kappa
6149	   \hat u=f_{v}-\left(\mu\frac{d^2c}{dt^2}+\zeta\frac{dc}{dt}+\kappa
6150	   c\right)&\equiv &\hat f,  \; \text{\hspace{6.5mm} \text{if} \hspace{3mm}$\hat u >
6151	  0$.}\\
6152	 \hat v^+&=&-r \hat v^- , \; \text{ \text{if}\hspace{3mm}$\hat
6153	 u=0$.}\end{aligned}
6154
6155      Using the framework presented in [2] we have that the equation of motion
6156      of a Lagrangian system may be stated as follows :
6157
6158      .. math::
6159
6160	 \begin{aligned}
6161	   \label{eq:lag1}
6162	   M(q)\ddot q + Q(q,\dot q) + F(\dot q, q , t) = F_{ext}(t) + R\end{aligned}
6163
6164      From the ([eq:trans]) we can derive all of the terms which define a
6165      Lagrangian NSDS. In our case the model is completely linear:
6166
6167      .. math::
6168
6169	 \begin{aligned}
6170	   \nonumber
6171	   q&=& \left[\begin{array}{c}  \hat u  \end{array}\right]    \\
6172	   \nonumber
6173	   M(q)&=&  \left[\begin{array}{c} \mu  \end{array}\right] \\
6174	   \label{eq:lag2}
6175	   Q(q,\dot q )& = &\left[\begin{array}{c} 0  \end{array}\right]  \\
6176	   \nonumber
6177	   F(q, \dot q ) &=&  \left[\begin{array}{c} \zeta \end{array}\right] \dot q +  \left[\begin{array}{c} \kappa  \end{array}\right] q\\
6178	   \nonumber
6179	   F_{ext}& = & \left[\begin{array}{c} \hat f \end{array}\right]\end{aligned}
6180
6181      The unilateral constraint requires that:
6182
6183      .. math::
6184
6185	 \begin{aligned}
6186	 \label{eq:constr} \nonumber
6187	  \hat u \geq 0\end{aligned}
6188
6189      so we can obtain
6190
6191      .. math::
6192
6193	 \begin{aligned}
6194	 y &= & H^T q + b \\
6195	 \nonumber H^T &=&\left[\begin{array}{c} 1 \end{array}\right]\\
6196	 \nonumber b&=&0\end{aligned}
6197
6198      In the same way, the reaction force due to the constraint is written as
6199      follows:
6200
6201      .. math::
6202
6203	 \begin{aligned}
6204	 \nonumber R=H \lambda, \hspace{1cm}  \text{with }
6205	 H=\left[\begin{array}{c} 1
6206	 \end{array}\right]\end{aligned}
6207
6208      The unilataral contact law may be formulated as follow:
6209
6210      .. math::
6211
6212	 \begin{aligned}
6213	   \label{eq:119}
6214	   0 \leq y \perp \lambda\geq 0\end{aligned}
6215
6216      and the Newton’s impact law:
6217
6218      .. math::
6219
6220	 \begin{aligned}
6221	   \label{eq:120}
6222	 \text{If } y=0, \dot{y}^+ =-r\dot{y}^-\end{aligned}
6223
6224      Implementation in the platform
6225      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6226
6227      For the simulation of the cam follower system follow the steps
6228
6229      #. Move to the working directory ``sample/CamFollower``
6230
6231	 ``$cd sample/CamFollower ``
6232
6233      #. Clean the directory form binary files using the ``siconos`` command
6234
6235	 ``$siconos -c ``
6236
6237      #. Compile the file ``CamFollowerNoXml.cpp`` in the sample folder (*See*
6238	 the code at the end of the section)
6239
6240	 ``$siconos CamFollowerNoXml.cpp``
6241
6242      #. Change the simulation parameters (*i.e.* Follower initial position
6243	 and velocity, cam initial angle, simulations time, cam rotational
6244	 speed in rpm, etc.) in the file ``CamFollowerNoXml.cpp``.
6245
6246      Next we present the sample code for the ``CamFollowerNoXml.cpp`` file:
6247
6248      =
6249
6250      =
6251
6252      =
6253
6254      =
6255
6256      |
6257      |  int main(int argc, char\* argv[]) **{**
6258      |  **{**
6259
6260      =
6261
6262      =
6263
6264      =
6265
6266      =
6267
6268      =
6269
6270      |
6271      |  *// ======== Creation of the model =============
6272       *// User-defined main parameters
6273      **
6274
6275      | double rpm=358;
6276      |  double phi\_0=0;
6277
6278      unsigned int dsNumber = 1; *// the Follower and the ground
6279       unsigned int nDof = 1; *// degrees of freedom for the Follower
6280       double t0 = 0; *// initial computation time
6281       double T = 5; *// final computation time
6282       double h = 0.0001; *// time step
6283       int Kplot;
6284       Kplot=(int)(Tplot/h);
6285      *****
6286
6287      double position\_init = 0.4; *// initial position for lowest bead.
6288       double velocity\_init = 0.4; *// initial velocity for lowest bead.
6289       *// ======= Dynamical systems =========
6290       vector<DynamicalSystem \*> vectorDS; // the list of DS
6291       vectorDS.resize(dsNumber,NULL);
6292       SiconosMatrix \*Mass, \*K, \*C; // mass/rigidity/viscosity
6293       Mass = new SiconosMatrix(nDof,nDof);
6294       (\*Mass)(0,0) = 1.221;
6295       K = new SiconosMatrix(nDof,nDof);
6296       (\*K)(0,0) = 1430.8;
6297       C = new SiconosMatrix(nDof,nDof);
6298       (\*C)(0,0) = 0;
6299       // Initial positions and velocities
6300       vector<SimpleVector \*> position\_0;
6301       vector<SimpleVector \*> velocity\_0;
6302       position\_0.resize(dsNumber,NULL);
6303       velocity\_0.resize(dsNumber,NULL);
6304       position\_0[0] = new SimpleVector(nDof);
6305       velocity\_0[0] = new SimpleVector(nDof);
6306       (\*(position\_0[0]))(0) = position\_init;
6307       (\*(velocity\_0[0]))(0) = velocity\_init;
6308       vectorDS[0] =
6309       new
6310      LagrangianLinearTIDS(0,nDof,\*(position\_0[0]),\*(velocity\_0[0]),\*Mass,\*K,\*C);
6311       static\_cast<LagrangianDS\*>(vectorDS[0])
6312      ->setComputeFExtFunction(“FollowerPlugin.so”, “FollowerFExt”);
6313       // Example to set a list of parameters in FExt function.
6314       // 1 - Create a simple vector that contains the required parameters.
6315       // Here we set two parameters, the DS number.
6316       SimpleVector \* param = new SimpleVector(2);
6317       (\*param)(0)=rpm;
6318       (\*param)(1)=phi\_0;
6319       // 2 - Assign this param to the function FExt
6320
6321      static\_cast<LagrangianDS\*>(vectorDS[0])->setParametersListPtr(param,2);
6322       // 2 corresponds to the position of FExt in the stl vector of possible
6323      parameters.
6324       // 0 is mass, 1 FInt.
6325       // Now the cam rotational velocity in rpms will be available in FExt
6326      plugin.
6327       // ===== Interactions =====
6328       vector<Interaction\*> interactionVector;
6329       interactionVector.resize(1,NULL);
6330       vector<DynamicalSystem\*> \*dsConcerned =
6331       new vector<DynamicalSystem\*>(dsNumber);
6332       // ===== Non Smooth Law =====
6333       double e = 0.8;
6334      ***
6335
6336      | // Interaction Follower-floor
6337      |  SiconosMatrix \*H = new SiconosMatrix(1,nDof);
6338      |  (\*H)(0,0) = 1.0;
6339      |  NonSmoothLaw \* nslaw = new NewtonImpactLawNSL(e);
6340      |  Relation \* relation = new LagrangianLinearR(\*H);
6341      |  (\*dsConcerned)[0] = vectorDS[0];
6342
6343      | interactionVector[0] = new Interaction(“Follower-Ground”,0,1,
6344      dsConcerned);
6345      |  interactionVector[0]->setRelationPtr(relation);
6346      |  interactionVector[0]->setNonSmoothLawPtr(nslaw);
6347
6348      | // ===== Interactions =====
6349      |  // ===== NonSmoothDynamicalSystem =====
6350
6351      | bool isBVP =0;
6352      |  NonSmoothDynamicalSystem \* nsds =
6353      |  new NonSmoothDynamicalSystem(isBVP);
6354      | // Set DS of this NonSmoothDynamicalSystem
6355      |  nsds->setDynamicalSystems(vectorDS);
6356      |  // Set interactions of the NonSmoothDynamicalSystem
6357      |  nsds->setInteractions(interactionVector);
6358      |  // ===== Model =====
6359      |  Model \* Follower = new Model(t0,T);
6360      |  // set NonSmoothDynamicalSystem of this model
6361      |  Follower->setNonSmoothDynamicalSystemPtr(nsds);
6362      |  // ====== Strategy ======
6363      |  double theta = 0.5; // theta for Moreau integrator
6364      |  string solverName = “QP” ;
6365      |  Strategy\* S = new TimeStepping(Follower);
6366      |  // – Time discretisation –
6367      |  TimeDiscretisation \* t = new TimeDiscretisation(h,S);
6368      |  // – OneStepIntegrators –
6369      |  vector<OneStepIntegrator \*> vOSI;
6370      |  vOSI.resize(dsNumber,NULL);
6371      |  vOSI[0] = new Moreau(t,vectorDS[0],theta);
6372      |  S->setOneStepIntegrators(vOSI);
6373      |  // – OneStepNsProblem –
6374      |  OneStepNSProblem \* osnspb = new LCP(S,solverName,101,
6375      0.0001,“max”,0.6);
6376      |  S->setOneStepNSProblemPtr(osnspb); // set OneStepNSProblem of the
6377      strategy
6378      |  cout << “=== End of model loading === ” << endl;
6379      |  // ==== End of model definition======
6380      |  // ========= Computation============
6381      |  // — Strategy initialization —
6382      |  S->initialize();
6383      |  cout <<“End of strategy initialisation” << endl;
6384
6385      | int k = t->getK(); // Current step
6386      |  int N = t->getNSteps(); // Number of time steps
6387      |  // — Get the values to be plotted —
6388      |  // -> saved in a matrix dataPlot
6389      |  unsigned int outputSize = 8;
6390      |  SiconosMatrix DataPlot(Kplot+1,outputSize );
6391      |  // For the initial time step:
6392      |  // time
6393      |  DataPlot(k,0) = k\*t->getH();
6394      |  DataPlot(k,1) = static\_cast<LagrangianDS\*>(vectorDS[0])->getQ()(0);
6395      |  DataPlot(k,2) =
6396      static\_cast<LagrangianDS\*>(vectorDS[0])->getVelocity()(0);
6397      |  DataPlot(k,3) = (Follower->getNonSmoothDynamicalSystemPtr()->
6398      |  getInteractionPtr(0)->getLambda(1))(0);
6399      |  DataPlot(k,4) =
6400      static\_cast<LagrangianDS\*>(vectorDS[0])->getFExt()(0);
6401      |  // State of the Cam
6402      |  double CamEqForce,CamPosition,CamVelocity,CamAcceleration;
6403
6404      | CamEqForce=
6405      |  CamState(k\*t->getH(),rpm,CamPosition,CamVelocity,CamAcceleration);
6406      |  // Position of the Cam
6407      |  DataPlot(k, 5) = CamPosition;
6408      |  // Velocity of the Cam
6409      |  DataPlot(k, 6) = CamVelocity;
6410      |  // Acceleration of the Cam
6411      |  DataPlot(k, 7) =
6412      |  CamPosition+static\_cast<LagrangianDS\*>(vectorDS[0])->getQ()(0);
6413      |  // — Time loop —
6414      |  cout << “Start computation ... ” << endl;
6415      |  while(k < N)
6416      |  **{ **
6417
6418      =
6419
6420      =
6421
6422      =
6423
6424      =
6425
6426      =
6427
6428      |
6429      |  // — Get values to be plotted —
6430      |  DataPlot(k,0) = k\*t->getH();
6431      |  DataPlot(k,1) =
6432      |  static\_cast<LagrangianDS\*>(vectorDS[0])->getQ()(0);
6433      |  DataPlot(k,2) =
6434      |  static\_cast<LagrangianDS\*>(vectorDS[0])->getVelocity()(0);
6435      |  DataPlot(k,3) =
6436      |  (Follower->getNonSmoothDynamicalSystemPtr()->
6437      |  getInteractionPtr(0)->getLambda(1))(0);
6438      |  DataPlot(k,4) =
6439      static\_cast<LagrangianDS\*>(vectorDS[0])->getFExt()(0);
6440
6441      | CamEqForce=
6442      |  CamState(k\*t->getH(),rpm,CamPosition,CamVelocity,CamAcceleration);
6443      |  DataPlot(k, 5) = CamPosition;
6444      |  DataPlot(k, 6) = CamVelocity;
6445      |  DataPlot(k, 7) = CamPosition+
6446      |  static\_cast<LagrangianDS\*>(vectorDS[0])->getQ()(0);
6447
6448      | // transfer of state i+1 into state i and time incrementation
6449      |  S->nextStep();
6450
6451      | // get current time step
6452      |  k = t->getK();
6453      |  // solve ...
6454      |  S->computeFreeState();
6455      |  S->computeOneStepNSProblem();
6456      |  // update
6457      |  S->update();
6458      |  **} **
6459      |  // — Output files —
6460      |  DataPlot.rawWrite(“result.dat”, “ascii”);
6461
6462      | // — Free memory —
6463      |  delete osnspb;
6464      |  delete vOSI[0];
6465      |  delete t;
6466      |  delete S;
6467      |  delete Follower;
6468      |  delete nsds;
6469      |  delete interactionVector[0];
6470      |  delete relation;
6471      |  delete nslaw;
6472      |  delete H;
6473      |  delete dsConcerned;
6474      |  delete vectorDS[0];
6475      |  delete position\_0[0];
6476      |  delete velocity\_0[0];
6477      |  delete C;
6478      |  delete K;
6479      |  delete Mass;
6480
6481      |
6482      |  **}**
6483
6484      Simulation
6485      ~~~~~~~~~~
6486
6487      We have perform the simulation of the cam follower system for different
6488      values of the cam rotational speed with the SICONOS software package
6489      using a time-stepping numerical scheme with step size
6490      (:math:`h=1e^{-4}`) and an event-driven scheme with minimum step size
6491      (:math:`h_{min}=1e^{-12}`). Fig. [Fig:time:sub:`c`\ omparison] and
6492      [Fig:state:sub:`c`\ omparison] show the time simulations for different
6493      values of the cam rotational speed and Fig.
6494      [Fig:attractor:sub:`c`\ omparison] show the chaotic attractor at
6495      :math:`rpm=660` for impact and stroboscopic Poincarè sections.
6496
6497      (60,60)(0,-7) (0,0) (35,-4)
6498
6499      (60,60)(15,-7) (0,0) (35,-4)
6500
6501      (60,60)(-40,-2) (0,0) (35,-4)
6502
6503      [Fig:time:sub:`c`\ omparison]
6504
6505      (60,60)(0,-7) (0,0) (35,-4)
6506
6507      (60,60)(15,-7) (0,0) (35,-4)
6508
6509      (60,60)(0,-2) (0,0) (35,-4)
6510
6511      (60,60)(-17,-2) (0,0) (35,-4)
6512
6513      [Fig:state:sub:`c`\ omparison]
6514
6515      (60,60)(0,-7) (0,0) (35,-4)
6516
6517      (60,60)(15,-7) (0,0) (35,-4)
6518
6519      (60,60)(0,-2) (0,0) (35,-4)
6520
6521      (60,60)(-17,-2) (0,0) (35,-4)
6522
6523      [Fig:attractor:sub:`c`\ omparison]
6524
6525      Quartic Formulation
6526      ===================
6527
6528      Slidding ?
6529      ~~~~~~~~~~
6530
6531      It consists in finding :math:`\alpha >0` and
6532      :math:`R \in \partial K_{\mu}` such that
6533      :math:`-\alpha \left(\begin{array}{l} 0\\ R_T\end{array}\right)=MR+q`.
6534      That is :
6535
6536      .. math::
6537
6538	 \label{eq_quartic1}
6539	 \left[\begin{array}{c}
6540	 M+ \left(\begin{array}{ccc} 0&0&0\\ 0&\alpha&0 \\ 0&0&\alpha \end{array}\right)
6541	 \end{array}\right]R+q=0
6542
6543      :math:`R_T` is on a conic
6544      ^^^^^^^^^^^^^^^^^^^^^^^^^
6545
6546      The first line of the system [eq\ :sub:`q`\ uartic1] and the
6547      :math:`R \in \partial K_{\mu}` is the intersection between a plan and a
6548      cone in :math:`\mathbb{R}^3`, endeed:
6549
6550      .. math::
6551
6552	 \label{eq_quartic2}
6553	 \begin{array}{l}
6554	  \mu R_N =  \parallel R_T \parallel  \\
6555	 \frac{M_{11}}{\mu} \parallel R_T \parallel = -q_1-M_{12}R_{T1}-M_{13}R_{T2}
6556	 \end{array}
6557
6558      That is:
6559
6560      .. math::
6561
6562	 \label{eq_quartic2}
6563	 \begin{array}{l}
6564	 \mu^2 R_N^2 =  (R_{T1}^2 +R_{T1}^2)  \\
6565	 \frac{M_{11}^2}{\mu^2} (R_{T1}^2 +R_{T1}^2)=(-q_1-M_{12}R_{T1}-M_{13}R_{T2})^2
6566	 \end{array}
6567
6568      That means that :math:`R_T` is contained in a conic, focus and
6569      directrice are:
6570
6571      .. math::
6572
6573	 \label{eq_quartic3}
6574	 \begin{array}{l}
6575	 \mathcal{D} : q_1+M_{12}R_{T1}+M_{13}R_{T2} =0  \\
6576	 focus : \mathcal{O}\\
6577	 \frac{M_{11}^2}{\mu^2}  Dist(\mathcal{O}, R_T) ^2=Dist(\mathcal{D},R_T)^2 (M_{12}^2+M_{13}^2)\\
6578	 \frac{Dist(\mathcal{O}, R_T)}{Dist(\mathcal{D},R_T)}=\frac{\mu\sqrt{(M_{12}^2+M_{13}^2)}}{M_{11} }=e
6579	 \end{array}
6580
6581      The parametric equation is:
6582
6583      .. math::
6584
6585	 \label{eq_quartic4}
6586	 \begin{array}{l}
6587	 R_{T1}=r cos(\theta )\\
6588	 R_{T2}=r sin(\theta )\\
6589	 r=\frac{p}{1+ecos(\theta - \phi)}
6590	 \end{array}
6591
6592      With :math:`p` an simple expression of :math:`M_{11},M_{12},M_{13}`, and
6593      :math:`\phi` a constant angle between :math:`\mathcal{D}` and
6594      :math:`(O,R_{T1})`
6595
6596      The two last line of the system [eq\ :sub:`q`\ uartic1]
6597      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6598
6599      .. math::
6600
6601	 \label{eq_quartic5}
6602	 \frac{\parallel R_T \parallel}{\mu} \tilde M_{1.} +\left(\tilde M+\left(\begin{array}{cc} \alpha&0 \\ 0&\alpha \end{array}\right)\right)R_T+\tilde q=0
6603
6604      :math:`\tilde M` is symetric, so it exists a unitary matrix :math:`V`
6605      such that
6606      :math:`V \tilde M V^T = \left(\begin{array}{cc} d_1&0 \\ 0&d_2 \end{array}\right)`.
6607      One can get:
6608
6609      .. math::
6610
6611	 \label{eq_quartic6}
6612	 \frac{\parallel R_T \parallel}{\mu} V \tilde M_{1.} +V \left(\tilde M+\left(\begin{array}{cc} \alpha&0 \\ 0&\alpha \end{array}\right)\right)V^TVR_T+V\tilde q=0
6613
6614      Rename:
6615
6616      .. math::
6617
6618	 \label{eq_quartic7}
6619	   \frac{\parallel \bar R_T \parallel}{\mu} \bar M_{1.} +\left(\begin{array}{cc} d_1+\alpha&0 \\ 0&d_2+\alpha \end{array}\right)\overline R_T+\bar q=0
6620
6621      In the plan, either :math:`V` is a rotation or a symetrie. So
6622      :math:` \bar R_T=VR_T` is a conic with the same focus and a rotated
6623      directrice, it means that it exists :math:`\phi_1` such that :
6624
6625      .. math::
6626
6627	 \label{eq_quartic8}
6628	 \begin{array}{l}
6629	 \bar R_{T1}=r cos(\theta )\\
6630	 \bar R_{T2}=r sin(\theta )\\
6631	 r=\frac{p}{1+ecos(\theta - \phi_1)}
6632	 \end{array}
6633
6634      The equation [eq\ :sub:`q`\ uartic7] is :
6635
6636      .. math::
6637
6638	 \label{eq_quartic9}
6639	 \begin{array}{l}
6640	   (d_1+\alpha)\bar R_{T1}=-\bar q_1+a_1 \parallel R_T \parallel\\
6641	 (d_2+\alpha)\bar R_{T2}=-\bar q_2+a_2 \parallel R_T \parallel
6642	 \end{array}
6643
6644      The case (:math:`\bar R_{T1} = 0` or :math:`\bar R_{T2} = 0`) has to be
6645      examine. We try to eliminate :math:`alpha`:
6646
6647      .. math::
6648
6649	 \label{eq_quartic10}
6650	   \begin{array}{l}
6651	     d_1 \bar R_{T1} \bar R_{T2}+\alpha \bar R_{T1} \bar R_{T2} =-\bar q_1\bar R_{T2}+a_1 \bar R_{T2} \parallel R_T \parallel\\
6652	 d_2 \bar R_{T1} \bar R_{T2}+\alpha \bar R_{T1} \bar R_{T2} =-\bar q_2\bar R_{T1}+a_2 \bar R_{T1} \parallel R_T \parallel
6653	 \end{array}
6654
6655      that leads to:
6656
6657      .. math::
6658
6659	 \label{eq_quartic10}
6660	   (d_1-d_2) \bar R_{T1} \bar R_{T2}=-\bar q_1\bar R_{T2}+\bar q_2\bar R_{T1}+(a_1 \bar R_{T2}-a_2 \bar R_{T1}) \parallel R_T \parallel\\
6661
6662      The parametric expression of :math:`\bar R_T` leads to:
6663
6664      .. math::
6665
6666	 \label{eq_quartic11}
6667	 \begin{array}{l}
6668	   (d_1-d_2)r^2cos(\theta )sin(\theta )=-\bar q_1rsin(\theta )+\bar q_2rcos(\theta )+r(a_1 rsin(\theta )-a_2 rcos(\theta )) \\
6669	   \textrm{ie:}(d_1-d_2)rcos(\theta )sin(\theta )=-\bar q_1sin(\theta )+\bar q_2cos(\theta )+r(a_1 sin(\theta )-a_2 cos(\theta ))\\
6670	   \end{array}
6671
6672      with the expression of r:
6673
6674      .. math::
6675
6676	 \label{eq_quartic12}
6677	 \begin{array}{l}
6678	 (d_1-d_2)\frac{p}{1+ecos(\theta - \phi_1)}cos(\theta )sin(\theta )=\\-\bar q_1sin(\theta )+\bar q_2cos(\theta )+\frac{p}{1+ecos(\theta - \phi_1)}(a_1  sin(\theta )-a_2 cos(\theta ))\\\\
6679	 \textrm{ie:}(d_1-d_2)pcos(\theta )sin(\theta )=\\(1+ecos(\theta - \phi_1))(-\bar q_1sin(\theta )+\bar q_2cos(\theta ))+p(a_1  sin(\theta )-a_2 cos(\theta ))\\\\
6680	 \textrm{ie:}(d_1-d_2)pcos(\theta )sin(\theta )=\\(1+e(cos(\theta)cos(\phi_1)+sin(\theta)sin(\phi_1)))(-\bar q_1sin(\theta )+\bar q_2cos(\theta ))+p(a_1  sin(\theta )-a_2 cos(\theta ))\\\\
6681	 \textrm{ie:}(d_1-d_2)pcos(\theta )sin(\theta )+\\(1+ecos(\theta)cos(\phi_1)+esin(\theta)sin(\phi_1))(\bar q_1sin(\theta )-\bar q_2cos(\theta ))+p(-a_1  sin(\theta )+a_2 cos(\theta ))=0
6682	  \end{array}
6683
6684      rename :
6685
6686      .. math::
6687
6688	 \label{eq_quartic13}
6689	 \begin{array}{l}
6690	 Acos(\theta )^2+Bsin(\theta)^2+Csin(\theta )cos(\theta )+Dsin(\theta )+Ecos(\theta )=0
6691	  \end{array}
6692
6693      with
6694
6695      .. math::
6696
6697	 \label{eq_quartic12}
6698	 \begin{array}{l}
6699	 A=- e\bar q_2cos(\phi_1)\\
6700	 B=e \bar q_1sin(\phi_1)\\
6701	 C=(d_1-d_2)p+ecos(\phi_1)\bar q_1-esin(\phi_1)\bar q_2\\
6702	 D=\bar q_1-pa_1\\
6703	 E=-\bar q_2+pa_2\\
6704	 \end{array}
6705
6706      rename : Using the following set of unknown :
6707
6708      .. math::
6709
6710	 \label{eq_quartic14}
6711	 \begin{array}{l}
6712	 t=tan(\theta /2)\\
6713	 sin(\theta )=\frac{2t}{1+t^2}\\
6714	 cos(\theta )=\frac{1-t^2}{1+t^2}
6715	  \end{array}
6716
6717      leads to:
6718
6719      .. math::
6720
6721	 \label{eq_quartic13}
6722	 \begin{array}{l}
6723	   A\frac{(1-t^2)^2}{1+t^2} +B\frac{4t^2}{1+t^2}+ C\frac{2t(1-t^2)}{1+t^2}+D2t+E(1-t^2)=0\\
6724	 \textrm{ie:}A(1-t^2)^2 + 4Bt^2+C2t(1-t^2)+2Dt(1+t^2)+E(1-t^2)(1+t^2)=0\\\\
6725	 \textrm{ie:}P_4=A-E\qquad P_3=-2C+2D \qquad P_2=4B-2A \qquad P_1=2C+2D \qquad P_0=A+E
6726	  \end{array}
6727
6728      Finally, we get 4 possible values for :math:`R_T`, checking the sign of
6729      :math:`\alpha` and :math:`R_N` selects the solutions.
6730
6731      case :math:`R_{T12}=0`
6732      ^^^^^^^^^^^^^^^^^^^^^^
6733
6734      From [eq\ :sub:`q`\ uartic9], :math:`R_{T1}` leads to:
6735
6736      .. math::
6737
6738	 \label{eq_quartic14}
6739	 \begin{array}{l}
6740	   \parallel R_T \parallel=|\bar R_{T2}|=\frac{\bar q_1}{a_1}\\\\
6741	   \bar R_T=\left(\begin{array}{c} 0 \\ \pm \frac{\bar q_1}{a_1} \end{array}\right)
6742	  \end{array}
6743
6744      From [eq\ :sub:`q`\ uartic9], :math:`R_{T2}` leads to:
6745
6746      .. math::
6747
6748	 \label{eq_quartic14}
6749	 \begin{array}{l}
6750	   \parallel R_T \parallel=|\bar R_{T1}|=\frac{\bar q_2}{a_2}\\\\
6751	   \bar R_T=\left(\begin{array}{c}  \pm \frac{\bar q_2}{a_2} \\ 0 \end{array}\right)
6752	  \end{array}
6753
6754      From :math:`\bar R_T`, we have to check the coherence with the
6755      equation [eq\ :sub:`q`\ uartic8]. If it is on the conic, we compute R,
6756      and the sign condition of the equation [eq\ :sub:`q`\ uartic1] must be
6757      check.
6758
6759      Alart–Curnier Formulation
6760      =========================
6761
6762      Reduced formulation to local variables.
6763      ---------------------------------------
6764
6765      Formulation
6766      ~~~~~~~~~~~
6767
6768      Let us start with
6769
6770      .. math::
6771
6772	 \label{eq:AC-L7}
6773	   \begin{array}{l}
6774	   \varPhi_1(U,P) =  - U_{k+1}  + \widehat W P_{k+1}  + U_{\mathrm{free}}\\ \\
6775	   \varPhi_2(U,P) =  P_{\n} - \operatorname{proj}_{\nbR^{a}_+} (P_{\n} - \rho_{\n}\circ (U_{\n} +e \circ  U_{\n,k}) ) \\ \\
6776	   \varPhi_3(U,P) =  P_{\t} - \operatorname{proj}_{\widehat {\bf D}(P_{\n},U_{\n})} (P_{{\t}} - \rho_{\t}\circ \,U_{\t} )
6777	 \end{array}
6778
6779      where the modified friction disk for a contact :math:`\alpha` is
6780
6781      .. math::
6782
6783	 \label{eq:AC-L3}
6784	   \widehat {\bf D}^\alpha(P^\alpha_{\n,k+1},U_{\n,k+1}^{\alpha}) = {\bf D}(\mu(\operatorname{proj}_{\nbR_+} (P^\alpha_{\n,k+1} - \rho^\alpha_{\n}\,(U_{\n,k+1}^{\alpha}+e^\alpha U_{\n,k}^{\alpha}) )).
6785
6786      Structure of the Jacobians
6787      ~~~~~~~~~~~~~~~~~~~~~~~~~~
6788
6789      Let us denote the one element of the generalized Jacobian by
6790      :math:` H(U,P) \in \partial \Phi(U,P)` which has the structure
6791
6792      .. math::
6793
6794	 \label{eq:AC-L6}
6795	    H(U,P) =
6796	    \left[\begin{array}{cccc}
6797		- I & 0 &  \widehat W_{\n\n} & \widehat W_{\n\t} \\ \\
6798		0  & -I  &  \widehat W_{\t\n} & \widehat W_{\t\t} \\ \\
6799		\partial_{U_{\n}} \Phi_2(U,P) & 0 &   \partial_{P_{\n}} \Phi_2(U,P) & 0 \\ \\
6800		\partial_{U_{\n}} \Phi_3(U,P) &  \partial_{U_{\t}} \Phi_3(U,P) &  \partial_{P_{\n}} \Phi_3(U,P)  & \partial_{P_{\t}} \Phi_3(U,P)
6801	    \end{array}\right]
6802
6803      Computation of the gradients
6804      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6805
6806      Let us consider the single contact case.
6807
6808      Computation of the gradients of :math:`\Phi_2`
6809      ''''''''''''''''''''''''''''''''''''''''''''''
6810
6811      .. math::
6812
6813	 \label{eq:AC-T1}
6814	   \begin{array}{l}
6815	   \varPhi_2(U,P) =  P_{\n} - \operatorname{proj}_{\nbR^{a}_+} (P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) ) \\ \\
6816	 \end{array}
6817
6818      -  **If** :math:`P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) \geq 0 `, we
6819	 get
6820
6821	 .. math::
6822
6823	    \label{eq:AC-T2}
6824		\begin{array}{l}
6825		  \varPhi_2(U,P) =  + \rho_{\n} (U_{\n} +e  U_{\n,k})
6826		\end{array}
6827
6828	 and
6829
6830	 .. math::
6831
6832	    \label{eq:AC-T3}
6833		\begin{array}{l}
6834		 \partial_{U_{\n}} \varPhi_2(U,P) =  + \rho_{\n} \\ \\
6835		 \partial_{P_{\n}} \varPhi_2(U,P) =  0 \\ \\
6836		\end{array}
6837
6838      -  **If** :math:`P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k})  < 0 `, we get
6839
6840	 .. math::
6841
6842	    \label{eq:AC-T4}
6843		\begin{array}{l}
6844		  \varPhi_2(U,P) =  P_{\n}
6845		\end{array}
6846
6847	 and
6848
6849	 .. math::
6850
6851	    \label{eq:AC-T5}
6852		\begin{array}{l}
6853		 \partial_{U_{\n}} \varPhi_2(U,P) =  0 \\ \\
6854		 \partial_{P_{\n}} \varPhi_2(U,P) =  1 \\ \\
6855		\end{array}
6856
6857      Computation of the gradients of :math:`\Phi_3`
6858      ''''''''''''''''''''''''''''''''''''''''''''''
6859
6860      .. math::
6861
6862	 \label{eq:AC-TT1}
6863	   \begin{array}{l}
6864	   \varPhi_3(U,P) =  P_{\t} - \operatorname{proj}_{\widehat {\bf D}(P_{\n},U_{\n})} (P_{\t} - \rho_{\t} U_{\t} ) \\ \\
6865	 \end{array}
6866
6867      -  **If**
6868	 :math:`\|P_{\t} - \rho_{\t} U_{\t}\| \leq \mu \max (0 ,P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) ) `
6869	 , we get
6870
6871	 .. math::
6872
6873	    \label{eq:AC-TT2}
6874	      \begin{array}{l}
6875	      \varPhi_3(U,P) =  + \rho_{\t} U_{\t}
6876	    \end{array}
6877
6878	 and
6879
6880	 .. math::
6881
6882	    \label{eq:AC-TT3}
6883		\begin{array}{l}
6884		 \partial_{U_{\n}} \varPhi_3(U,P) =  0 \\ \\
6885		 \partial_{P_{\n}} \varPhi_3(U,P) =  0 \\ \\
6886		 \partial_{U_{\t}} \varPhi_3(U,P) =  + \rho_{\t} \\ \\
6887		 \partial_{P_{\t}} \varPhi_3(U,P) =  0 \\ \\
6888		\end{array}
6889
6890      -  **If**
6891	 :math:`\|P_{\t} - \rho_{\t} U_{\t}\| > \mu \max (0 ,P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) ) `
6892	 , we get
6893
6894	 .. math::
6895
6896	    \label{eq:AC-TT4}
6897	      \begin{array}{l}
6898	      \varPhi_3(U,P) =  P_{\t} - \mu \max(0,P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) )  {\displaystyle \frac{P_{\t} - \rho_{\t} U_{\t} }{ \| P_{\t} - \rho_{\t} U_{\t}\| }}
6899	    \end{array}
6900
6901	 -  **If** :math:`P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) \leq 0`, we
6902	    get
6903
6904	    .. math::
6905
6906	       \label{eq:AC-TT5}
6907		 \begin{array}{l}
6908		 \varPhi_3(U,P) =   P_{\t}
6909	       \end{array}
6910
6911	    and
6912
6913	    .. math::
6914
6915	       \label{eq:AC-TT6}
6916		  \begin{array}{l}
6917		    \partial_{U_{\n}} \varPhi_3(U,P) =  0 \\ \\
6918		    \partial_{P_{\n}} \varPhi_3(U,P) =  0 \\ \\
6919		    \partial_{U_{\t}} \varPhi_3(U,P) =  0 \\ \\
6920		    \partial_{P_{\t}} \varPhi_3(U,P) =  I_2 \\ \\
6921		  \end{array}
6922
6923	 -  **If** :math:`P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) > 0`, we
6924	    get
6925
6926	    .. math::
6927
6928	       \label{eq:AC-TT7}
6929		 \begin{array}{l}
6930		 \varPhi_3(U,P) =  P_{\t} - \mu (P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) )  {\displaystyle \frac{P_{\t} - \rho_{\t} U_{\t} }{ \| P_{\t} - \rho_{\t} U_{\t}\| }}
6931	       \end{array}
6932
6933	    and
6934
6935	    .. math::
6936
6937	       \label{eq:AC-TT8}
6938		  \begin{array}{l}
6939		    \partial_{U_{\n}} \varPhi_3(U,P) =  \mu \rho_{\n}  {\displaystyle \frac{P_{\t} - \rho_{\t} U_{\t} }{ \| P_{\t} - \rho_{\t} U_{\t}\| }}\text{{\bf WARNING} case was not taken into account}\\ \\
6940		    \partial_{P_{\n}} \varPhi_3(U,P) =  -\mu  {\displaystyle \frac{P_{\t} - \rho_{\t} U_{\t} }{ \| P_{\t} - \rho_{\t} U_{\t}\| }} \\ \\
6941		    \partial_{U_{\t}} \varPhi_3(U,P) =  \mu\rho_{\t}(P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) ) \Gamma(P_{\t} - \rho_{\t} U_{\t})  \\ \\
6942		    \partial_{P_{\t}} \varPhi_3(U,P) =  I_2-\mu(P_{\n} - \rho_{\n} (U_{\n} +e  U_{\n,k}) ) \Gamma(P_{\t} - \rho_{\t} U_{\t})  \\ \\
6943		  \end{array}
6944
6945      Rearranging the cases
6946      ~~~~~~~~~~~~~~~~~~~~~
6947
6948      **TO BE COMPLETED**
6949
6950      Formulation with global variables.
6951      ----------------------------------
6952
6953      Formulation
6954      ~~~~~~~~~~~
6955
6956      Let us start with
6957
6958      .. math::
6959
6960	 \label{eq:GAC-L1}
6961	   \begin{array}{l}
6962	   \Psi_{1}^{a}(v,U,P) =  - \widehat M v_{k+1}  +  H P_{k+1}  + q \\ \\
6963	   \Psi_{1}^{b}(v,U,P) =  - U_{k+1}  + H^\top v _{k+1}  + b \\ \\
6964	   \Psi_2(v,U,P) =  P_{\n} - \operatorname{proj}_{\nbR^{a}_+} (P_{\n} - \rho_{\n}\circ (U_{\n} +e \circ  U_{\n,k}) ) \\ \\
6965	   \Psi_3(v,U,P) =  P_{\t} - \operatorname{proj}_{\widehat {\bf D}(P_{\n},U_{\n})} (P_{{\t}} - \rho_{\t}\circ \,U_{\t} )
6966	 \end{array}
6967
6968      where the modified friction disk for a contact :math:`\alpha` is
6969
6970      .. math::
6971
6972	 \label{eq:GAC-L2}
6973	   \widehat {\bf D}^\alpha(P^\alpha_{\n,k+1},U_{\n,k+1}^{\alpha}) = {\bf D}(\mu(\operatorname{proj}_{\nbR_+} (P^\alpha_{\n,k+1} - \rho^\alpha_{\n}\,(U_{\n,k+1}^{\alpha}+e^\alpha U_{\n,k}^{\alpha}) )).
6974
6975      Structure of the Jacobians
6976      ~~~~~~~~~~~~~~~~~~~~~~~~~~
6977
6978      Let us denote the one element of the generalized Jacobian by
6979      :math:` H(v,U,P) \in \partial \Psi(s,U,P)` which has the structure
6980
6981      .. math::
6982
6983	 \label{eq:GAC-L3}
6984	    H(v,U,P) =
6985	    \left[\begin{array}{ccccc}
6986		- \widehat M & 0 & 0 & H_{\n} & H_{\t} \\ \\
6987		 H_{\n}^\top &  - I & 0 & 0 &0 \\ \\
6988		 H_{\t}^\top &  0  & -I & 0 &0 \\ \\
6989		 0 & \partial_{U_{\n}} \Psi_2(v,U,P) & 0 &   \partial_{P_{\n}} \Psi_2(v,U,P) & 0 \\ \\
6990		 0 & \partial_{U_{\n}} \Psi_3(v,U,P) &  \partial_{U_{\t}} \Psi_3(v,U,P) &  \partial_{P_{\n}} \Psi_3(v,U,P)  & \partial_{P_{\t}} \Psi_3(v,U,P)
6991	    \end{array}\right]
6992
6993      We clearly have
6994
6995      .. math::
6996
6997	 \label{eq:equivalentJacobian}
6998	   \begin{array}{lcl}
6999	      \partial_{U} \Psi_2(v,U,P) &=& \partial_{U} \Phi_2(U,P) \\
7000	      \partial_{P} \Psi_2(v,U,P) &=& \partial_{P} \Phi_2(U,P) \\
7001	      \partial_{U} \Psi_3(v,U,P) &=& \partial_{U} \Phi_3(U,P) \\
7002	      \partial_{P} \Psi_3(v,U,P) &=& \partial_{P} \Phi_3(U,P) \\
7003	   \end{array}
7004
7005      and we get
7006
7007      .. math::
7008
7009	 \label{eq:GAC-L4}
7010	    H(v,U,P) =
7011	    \left[\begin{array}{ccccc}
7012		- \widehat M & 0 & 0 & H_{\n} & H_{\t} \\ \\
7013		 H_{\n}^\top &  - I & 0 & 0 &0 \\ \\
7014		 H_{\t}^\top &  0  & -I & 0 &0 \\ \\
7015		 0 & \partial_{U_{\n}} \Phi_2(U,P) & 0 &   \partial_{P_{\n}} \Phi_2(U,P) & 0 \\ \\
7016		 0 & \partial_{U_{\n}} \Phi_3(U,P) &  \partial_{U_{\t}} \Phi_3(U,P) &  \partial_{P_{\n}} \Phi_3(U,P)  & \partial_{P_{\t}} \Phi_3(U,P)
7017	    \end{array}\right]
7018
7019      Simplification ?
7020      ~~~~~~~~~~~~~~~~
7021
7022      Since the second line :math:`\Psi_1^b` is linear, we should be able to
7023      derive a reduced Jacobian using the chain rule. Let us define
7024      :math:`\widetilde \Psi`
7025
7026      .. math::
7027
7028	 \label{eq:chainrule}
7029	   \widetilde \Psi(v,P)  = \Psi(v,H^\top v +b,P)
7030
7031      .. math::
7032
7033	 \label{eq:GAC-L5}
7034	   \begin{array}{l}
7035	   \widetilde \Psi_{1}(v,P) =  - \widehat M v_{k+1}  +  H P_{k+1}  + q \\ \\
7036	   \widetilde \Psi_2(v,P) =  P_{\n} - \operatorname{proj}_{\nbR^{a}_+} (P_{\n} - \rho_{\n}\circ (H^\top_{\n}v+b_{\n} +e \circ  U_{\n,k}) ) \\ \\
7037	   \widetilde \Psi_3(v,P) =  P_{\t} - \operatorname{proj}_{\widehat {\bf D}(P_{\n},U_{\n})} (P_{{\t}} - \rho_{\t}\circ \,(H^\top_\t v + b_\t) )
7038	 \end{array}
7039
7040      Chain rule
7041      ''''''''''
7042
7043      .. math::
7044
7045	 \label{eq:chainrule1}
7046	   \begin{array}{lcl}
7047	   \partial_v \widetilde \Psi_{2,3}(v,P) &=&  \partial_v \Psi_{2,3}(v,H^\top v +b,P)  \\ \\
7048	   &=& H_{\n}^\top \partial_{U_\n} \Phi_{2,3}(H^\top v + b,P) + H_{\t}^\top \partial_{U_\t} \Phi_{2,3}(H^\top v + b,P)
7049	 \end{array}
7050
7051      .. math::
7052
7053	 \label{eq:GAC-L6}
7054	    H(v,P) =
7055	    \left[\begin{array}{ccc}
7056		- \widehat M &   H_{\n} & H_{\t} \\ \\
7057		H_{\n}^\top \partial_{U_\n} \Phi_{2}(H^\top v + b,P) &   \partial_{P_{\n}} \Phi_2(H^\top v + b,P) & 0 \\ \\
7058		\begin{array}{c}
7059		  H_{\n}^\top \partial_{U_\n} \Phi_{3}(H^\top v + b,P) \\
7060		  \quad \quad + H_{\t}^\top \partial_{U_\t} \Phi_{3}(H^\top v + b,P)\\
7061	      \end{array}
7062	      &  \partial_{P_{\n}} \Phi_3(H^\top v + b,P)  & \partial_{P_{\t}} \Phi_3(H^\top v + b,P)
7063	    \end{array}\right]
7064
7065      discussion
7066      ''''''''''
7067
7068      -  Formulae has to be checked carefully
7069
7070      -  I do not known if there an interest in the simplification. With
7071	 sparse matrices, it is perhaps easier to deal with ([eq:GAC-L4])
7072
7073      .. |image| image:: ./DSClassDiagram.pdf
7074