Program listing for file kernel/src/utils/SiconosAlgebra/SimpleMatrix.hpp

Program listing for file kernel/src/utils/SiconosAlgebra/SimpleMatrix.hpp#

  1#ifndef __SimpleMatrix__
  2#define __SimpleMatrix__
  3
  4#include <iosfwd>
  5#include "SiconosSerialization.hpp"
  6#include "SiconosVisitor.hpp"
  7#include "SiconosAlgebraTypeDef.hpp"
  8#include "SiconosFwd.hpp"
  9#include "SiconosMatrix.hpp"
 10#include "SiconosVector.hpp"
 11
 12
 13
 14
 15
 16
 17class BlockVector;
 18
 19
 20class SimpleMatrix: public SiconosMatrix
 21{
 22protected:
 23  ACCEPT_SERIALIZATION(SimpleMatrix);
 24
 25
 26  MATRIX_UBLAS_TYPE mat;
 27
 28
 29private:
 30
 31  SP::VInt _ipiv;
 32
 33
 34  bool _isPLUFactorized = false;
 35
 36
 37  bool _isPLUFactorizedInPlace = false;
 38
 39
 40  bool _isCholeskyFactorized = false;
 41
 42
 43  bool _isCholeskyFactorizedInPlace = false;
 44
 45
 46  bool _isQRFactorized = false;
 47
 48
 49  bool _isPLUInversed = false;
 50
 51
 52  SP::NumericsMatrix _numericsMatrix;
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65  void private_prod(unsigned int startRow, const SiconosVector& x, SiconosVector& y, bool init);
 66
 67
 68
 69  void private_addprod(unsigned int startRow, unsigned int startCol, const SiconosVector& x, SiconosVector& res);
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87public:
 88
 89  SimpleMatrix();
 90
 91
 92  SimpleMatrix(unsigned int row, unsigned int col, Siconos::UBLAS_TYPE typ = Siconos::DENSE, unsigned int upper = 1, unsigned int lower = 1);
 93
 94
 95  SimpleMatrix(unsigned int row, unsigned int col, double inputValue,
 96               Siconos::UBLAS_TYPE typ = Siconos::DENSE,
 97               unsigned int upper = 1, unsigned int lower = 1);
 98
 99
100  SimpleMatrix(const SimpleMatrix& smat);
101
102
103  SimpleMatrix(const SimpleMatrix& A , const Index& coord );
104
105
106  SimpleMatrix(const SiconosMatrix& m);
107
108
109  SimpleMatrix(const DenseMat& m);
110
111
112  SimpleMatrix(const TriangMat& m);
113
114
115  SimpleMatrix(const SymMat& m);
116
117
118  SimpleMatrix(const BandedMat& m);
119
120
121  SimpleMatrix(const SparseMat& m);
122
123
124  SimpleMatrix(const SparseCoordinateMat& m);
125
126
127  SimpleMatrix(const ZeroMat& m);
128
129
130  SimpleMatrix(const IdentityMat& m);
131
132
133  SimpleMatrix(const std::string& file, bool ascii = true);
134
135
136  ~SimpleMatrix();
137
138
139  void updateNumericsMatrix() override;
140
141  NumericsMatrix * numericsMatrix() const override
142  {
143    return _numericsMatrix.get();
144  };
145
146
147  inline bool isPLUInversed() const override
148  {
149    return _isPLUInversed;
150  }
151
152
153  inline bool isPLUFactorized() const override
154  {
155    return _isPLUFactorized;
156  }
157
158
159  inline bool isPLUFactorizedInPlace() const override
160  {
161    return _isPLUFactorizedInPlace;
162  }
163
164  inline bool isCholeskyFactorized() const override
165  {
166    return _isCholeskyFactorized;
167  }
168
169
170  inline bool isCholeskyFactorizedInPlace() const
171  {
172    return _isCholeskyFactorizedInPlace;
173  }
174
175
176  inline bool isQRFactorized() const
177  {
178    return _isQRFactorized;
179  }
180
181
182  inline SP::VInt ipiv() const override
183  {
184    return _ipiv;
185  }
186
187
188  bool checkSymmetry(double tol) const override;
189
190
191  const DenseMat getDense(unsigned int row = 0, unsigned int col = 0) const override;
192
193
194  const TriangMat getTriang(unsigned int row = 0, unsigned int col = 0) const override;
195
196
197  const SymMat getSym(unsigned int row = 0, unsigned int col = 0) const override;
198
199
200  const BandedMat getBanded(unsigned int row = 0, unsigned int col = 0) const override;
201
202
203  const SparseMat getSparse(unsigned int row = 0, unsigned int col = 0) const override;
204
205
206  const SparseCoordinateMat getSparseCoordinate(unsigned int row = 0, unsigned int col = 0) const override;
207
208
209  const ZeroMat getZero(unsigned int row = 0, unsigned int col = 0) const override;
210
211
212  const IdentityMat getIdentity(unsigned int row = 0, unsigned int col = 0) const override;
213
214
215  DenseMat* dense(unsigned int row = 0, unsigned int col = 0) const override;
216
217
218  TriangMat* triang(unsigned int row = 0, unsigned int col = 0) const override;
219
220
221  SymMat* sym(unsigned int row = 0, unsigned int col = 0) const override;
222
223
224  BandedMat* banded(unsigned int row = 0, unsigned int col = 0) const override;
225
226
227  SparseMat* sparse(unsigned int row = 0, unsigned int col = 0) const override;
228
229
230  SparseCoordinateMat* sparseCoordinate(unsigned int row = 0, unsigned int col = 0) const override;
231
232
233  ZeroMat* zero_mat(unsigned int row = 0, unsigned int col = 0) const override;
234
235
236  IdentityMat* identity(unsigned int row = 0, unsigned int col = 0) const override;
237
238
239  double* getArray(unsigned int row = 0, unsigned int col = 0) const override;
240
241
242  void zero() override;
243
244
245  void randomize() override;
246
247
248  void randomize_sym() override;
249
250
251  void eye() override;
252
253
254  unsigned copyData(double* data) const;
255
256  void assign(const SimpleMatrix &smat);
257
258
259
260  unsigned int size(unsigned int index) const override;
261
262
263  void resize(unsigned int row, unsigned int col, unsigned int lower = 0, unsigned int upper = 0, bool preserve = true) override;
264
265
266  double normInf() const override;
267
268
269  void normInfByColumn(SP::SiconosVector vIn) const;
270
271
272  double det() const;
273
274
275  void display() const override;
276
277  void displayExpert(bool  brief = true) const override;
278
279  std::string toString() const override;
280
281
282  double& operator()(unsigned int i, unsigned int j) override;
283
284
285  double operator()(unsigned int i, unsigned int j) const override;
286
287
288  double getValue(unsigned int i, unsigned int j) const override;
289
290
291  void setValue(unsigned int i, unsigned int j, double value) override;
292
293
294  void setBlock(unsigned int posRow, unsigned int posCol, const SiconosMatrix& m);
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319  void getRow(unsigned int row, SiconosVector& vOut) const override;
320
321
322  void getCol(unsigned int col, SiconosVector& vOut) const override;
323
324
325  void setRow(unsigned int row , const SiconosVector& vIn) override;
326
327
328  void setCol(unsigned int col, const SiconosVector& vIn) override;
329
330
331  void getSubCol(unsigned int index, unsigned int pos, SP::SiconosVector vOut) const;
332
333
334  void getSubRow(unsigned int index, unsigned int pos, SP::SiconosVector vOut) const;
335
336
337  void setSubCol(unsigned int index, unsigned int pos, SP::SiconosVector vIn);
338
339
340  void setSubRow(unsigned int index, unsigned int pos, SP::SiconosVector vIn);
341
342
343  void addBlock(unsigned int i, unsigned int j, const SiconosMatrix& m);
344
345
346  void subBlock(unsigned int i, unsigned int j, const SiconosMatrix& m);
347
348
349  void trans() override;
350
351
352  void trans(const SiconosMatrix& mat) override;
353
354
355  SimpleMatrix& operator = (const SiconosMatrix& m) override;
356
357
358  SimpleMatrix& operator = (const SimpleMatrix& m);
359
360
361  SimpleMatrix& operator = (const DenseMat& m) override;
362
363
364  SimpleMatrix& operator +=(const SiconosMatrix& m) override;
365
366
367  SimpleMatrix& operator -=(const SiconosMatrix& m) override;
368
369
370  void PLUFactorizationInPlace() override;
371
372
373  void Factorize() override;
374
375
376  void PLUInverseInPlace() override;
377
378
379  void PLUForwardBackwardInPlace(SiconosMatrix& B) override;
380  void Solve(SiconosMatrix& B) override;
381
382
383  void PLUForwardBackwardInPlace(SiconosVector& B) override;
384  void Solve(SiconosVector& B) override;
385
386
387  void SolveByLeastSquares(SiconosMatrix& B);
388
389
390  void SolveByLeastSquares(SiconosVector& B);
391
392
393
394  void resetLU() override;
395
396
397
398  void resetCholesky();
399
400
401  void resetQR();
402
403
404  void resetFactorizationFlags() override;
405
406
407
408
409  ACCEPT_STD_VISITORS();
410
411  friend std::ostream& operator<<(std::ostream& os, const SimpleMatrix& sm);
412
413  friend const SimpleMatrix operator * (const SiconosMatrix&, double);
414
415  friend  SP::SimpleMatrix operator * (const SP::SimpleMatrix, const SP::SimpleMatrix);
416
417  friend  void operator +=(SP::SiconosMatrix, SP::SimpleMatrix);
418
419  friend  SimpleMatrix operator * (double , const SiconosMatrix&);
420
421  friend const SimpleMatrix operator /(const SiconosMatrix&, double);
422
423  friend const SimpleMatrix operator +(const SiconosMatrix&, const SiconosMatrix&);
424
425  friend SP::SimpleMatrix operator +(const SP::SimpleMatrix, const SP::SimpleMatrix);
426
427  friend void add(const SiconosMatrix&, const SiconosMatrix&, SiconosMatrix&);
428
429  friend const SimpleMatrix operator -(const SiconosMatrix&, const SiconosMatrix&);
430
431  friend void sub(const SiconosMatrix&, const SiconosMatrix&, SiconosMatrix&);
432
433  friend bool operator == (const SiconosMatrix&, const SiconosMatrix&);
434
435  friend bool operator!= (const SiconosMatrix&, const SiconosMatrix&);
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465};
466
467
468
469#endif