Program listing for file kernel/src/modelingTools/Interaction.hpp#
Return to documentation for this file
1#ifndef INTERACTION_H
2#define INTERACTION_H
3
4#include "RelationNamespace.hpp"
5#include "SiconosPointers.hpp"
6#include "SiconosVector.hpp"
7#include "SiconosMemory.hpp"
8#include "SiconosAlgebraTypeDef.hpp"
9#include <vector>
10
11
12class Interaction : public std::enable_shared_from_this<Interaction >
13{
14private:
15
16 ACCEPT_SERIALIZATION(Interaction);
17
18
19 static size_t __count;
20
21
22 size_t _number;
23
24
25 unsigned int _lowerLevelForOutput = 0;
26
27
28 unsigned int _upperLevelForOutput = 0;
29
30
31 unsigned int _lowerLevelForInput = 0;
32
33
34 unsigned int _upperLevelForInput = 0;
35
36
37 unsigned int _interactionSize = 0;
38
39
40 unsigned int _sizeOfDS = 0;
41
42
43 bool _has2Bodies = false;
44
45
46 VectorOfVectors _y;
47
48
49 VectorOfMemories _yMemory;
50
51
52 VectorOfVectors _lambda;
53
54
55 VectorOfMemories _lambdaMemory;
56
57
58 SP::NonSmoothLaw _nslaw;
59
60
61 SP::Relation _relation;
62
63
64 VectorOfBlockVectors _linkToDSVariables;
65
66 VectorOfSMatrices _relationMatrices;
67
68 VectorOfVectors _relationVectors;
69
70 struct _setLevels;
71 friend struct Interaction::_setLevels;
72
73
74
75
76 Interaction(const Interaction& inter) = delete;
77 Interaction& operator=(const Interaction&) = delete;
78
79protected:
80 Interaction() {}
81
82private:
83
84
85
86
87
88 void __initDataFirstOrder(VectorOfBlockVectors& DSlink, DynamicalSystem& ds1, DynamicalSystem& ds2);
89
90
91 void __initDSDataFirstOrder(DynamicalSystem& ds, VectorOfBlockVectors& DSlink);
92
93
94 void __initDataLagrangian(VectorOfBlockVectors& DSlink, DynamicalSystem& ds1, DynamicalSystem& ds2);
95
96
97 void __initDSDataLagrangian(DynamicalSystem& ds, VectorOfBlockVectors& DSlink);
98
99
100 void __initDataNewtonEuler(VectorOfBlockVectors& DSlink, DynamicalSystem& ds1, DynamicalSystem& ds2);
101
102
103 void __initDSDataNewtonEuler(DynamicalSystem& ds, VectorOfBlockVectors& DSlink);
104
105
106public:
107
108
109 Interaction(SP::NonSmoothLaw NSL, SP::Relation rel);
110
111
112 ~Interaction() {};
113
114
115 void reset();
116
117
118
119
120
121 void initializeLinkToDsVariables(DynamicalSystem& ds1,
122 DynamicalSystem& ds2);
123
124
125 void resetAllLambda() ;
126
127
128 void resetLambda(unsigned int level);
129
130
131 void initializeMemory(unsigned int steps);
132
133
134
135 inline size_t number() const
136 {
137 return _number;
138 }
139
140
141 inline void setLowerLevelForOutput(const unsigned int newVal)
142 {
143 _lowerLevelForOutput = newVal;
144 };
145
146
147 inline void setUpperLevelForOutput(const unsigned int newVal)
148 {
149 _upperLevelForOutput = newVal;
150 };
151
152
153 inline unsigned int lowerLevelForOutput()
154 {
155 return _lowerLevelForOutput;
156 };
157
158
159 inline unsigned int upperLevelForOutput()
160 {
161 return _upperLevelForOutput;
162 };
163
164
165 inline void setLowerLevelForInput(const unsigned int newVal)
166 {
167 _lowerLevelForInput = newVal;
168 };
169
170
171 inline void setUpperLevelForInput(const unsigned int newVal)
172 {
173 _upperLevelForInput = newVal;
174 };
175
176
177
178 inline unsigned int lowerLevelForInput()
179 {
180 return _lowerLevelForInput ;
181 };
182
183
184 inline unsigned int upperLevelForInput()
185 {
186 return _upperLevelForInput;
187 };
188
189
190 inline unsigned int dimension() const
191 {
192 return _interactionSize;
193 }
194
195
196 inline unsigned int getSizeOfDS() const
197 {
198 return _sizeOfDS;
199 }
200
201
202 void setHas2Bodies(bool val) {_has2Bodies = val;}
203
204
205 bool has2Bodies() const {return _has2Bodies;}
206
207
208
209
210 inline const SiconosVector getCopyOfy(const unsigned int i) const
211 {
212 assert(_y[i] && "_y[i]");
213 return *(_y[i]);
214 }
215
216
217 inline const VectorOfVectors y() const
218 {
219 return _y;
220 }
221
222
223
224 inline SP::SiconosVector y(const unsigned int i) const
225 {
226 assert(_y[i]);
227 return _y[i];
228 }
229
230
231 void setY(const VectorOfVectors& v);
232
233
234 void setYPtr(const VectorOfVectors& v);
235
236
237 void setY(const unsigned int i, const SiconosVector& v);
238
239
240 void setYPtr(const unsigned int i, SP::SiconosVector v);
241
242
243
244 inline SiconosMemory& yMemory(unsigned int level)
245 {
246 return _yMemory[level];
247 }
248
249 inline const SiconosVector& y_k(const unsigned int i) const
250 {
251 return _yMemory[i].getSiconosVector(0);
252 }
253
254
255
256
257
258 inline const VectorOfVectors getLambda() const
259 {
260 return _lambda;
261 }
262
263
264 inline const SiconosVector getLambda(const unsigned int i) const
265 {
266 assert(_lambda[i]);
267 return *(_lambda[i]);
268 }
269
270
271 inline SP::SiconosVector lambda(const unsigned int i) const
272 {
273 assert(_lambda[i]);
274 return _lambda[i];
275 }
276
277
278 inline SiconosMemory& lambdaMemory(unsigned int level)
279 {
280 return _lambdaMemory[level];
281 }
282
283
284 inline const SiconosVector& lambda_k(const unsigned int i) const
285 {
286 return _lambdaMemory[i].getSiconosVector(0);
287 }
288
289
290 void setLambda(const VectorOfVectors& v);
291
292
293 void setLambdaPtr(const VectorOfVectors& v);
294
295
296 void setLambda(const unsigned int i, const SiconosVector& newValue);
297
298
299 void setLambdaPtr(const unsigned int i, SP::SiconosVector newPtr);
300
301
302
303 inline SP::Relation relation() const
304 {
305 return _relation;
306 }
307
308
309 inline SP::NonSmoothLaw nonSmoothLaw() const
310 {
311 return _nslaw;
312 }
313
314
315 inline VectorOfBlockVectors & linkToDSVariables()
316 {
317 return _linkToDSVariables;
318 };
319
320 inline VectorOfVectors & relationVectors()
321 {
322 return _relationVectors;
323 };
324
325 inline VectorOfSMatrices & relationMatrices()
326 {
327 return _relationMatrices;
328 };
329
330
331
332
333 inline void setDSSizes(unsigned int s1)
334 {
335 _sizeOfDS = s1;
336 }
337
338
339 void swapInMemory();
340
341
342 void display(bool brief = true) const;
343
344
345 static inline size_t resetCount(size_t new_count=0)
346 {
347 size_t old_count = __count;
348 __count = new_count;
349 return old_count;
350 };
351
352
353 void computeOutput(double time, unsigned int derivativeNumber = 0);
354
355
356 void computeInput(double time, unsigned int level = 0);
357
358
359 SP::SiconosMatrix getLeftInteractionBlock() const;
360
361
362 SP::SiconosMatrix getLeftInteractionBlockForDS(unsigned int pos, unsigned int size, unsigned int sizeDS) const;
363
364
365 void getLeftInteractionBlockForDSProjectOnConstraints(unsigned int pos, SP::SiconosMatrix InteractionBlock) const;
366
367
368 SP::SiconosMatrix getRightInteractionBlockForDS(unsigned int pos, unsigned int sizeDS, unsigned size) const;
369
370
371 void getExtraInteractionBlock(SP::SiconosMatrix InteractionBlock) const;
372
373};
374
375#endif