AGXDynamics  2.35.0.2
MatrixTypes.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef MATRIX_TYPES_H
18 #define MATRIX_TYPES_H
19 
20 namespace agx
21 {
22 
48  class MatrixType {
49  public:
50 
56  enum Storage {
57  DENSE = 2,
60  };
61 
67  enum Type {
68  GENERIC = 0,
69  SQUARE = 2,
70  SYMMETRIC = 4,
75  };
76 
77  MatrixType() : m_storage(DENSE), m_type(GENERIC) { }
78 
79 
80  MatrixType(int type, int storage) {
81  m_storage = storage;
82  m_type = type;
83  }
84 
85  MatrixType & setSymmetric (bool t = true) {
86  (t)? m_type |= SYMMETRIC
87  : m_type &= ~SYMMETRIC;
88  return setGeneric(false);
89  }
90 
91  MatrixType & setSquare (bool t = true) {
92  (t)? m_type |= SQUARE
93  : m_type &= ~SQUARE;
94  return setGeneric(false);
95  }
96 
97  MatrixType & setSaddlePoint(bool t = true) {
98  (t)? m_type |= SADDLE_POINT
99  : m_type &= ~SADDLE_POINT;
100  return setGeneric(false).setSquare(true);
101  }
102 
103  MatrixType & setPositiveDefinite (bool t = true) {
104  (t)? m_type |= POSITIVE_DEFINITE
105  : m_type &= ~POSITIVE_DEFINITE;
106  return setGeneric(!t).setSquare(true);
107  }
108 
109  MatrixType & setGeneric (bool t = true ) {
110  if (t) { m_type = GENERIC ; }
111  return *this;
112  }
113 
114  MatrixType &setDense(bool t = true ) {
115  (t)? m_storage |= DENSE
116  : m_storage &= ~DENSE;
117  return *this;
118  }
119 
120  MatrixType &setSparse(bool t = true ) {
121  return setDense(!t);
122  }
123 
124  MatrixType &setUpperTriangle(bool t = true ) {
125  (t)? m_storage |= UPPER_TRIANGLE
126  : m_storage &= ~UPPER_TRIANGLE;
127  return setLowerTriangle(!t);
128  }
129 
130  MatrixType &setLowerTriangle(bool t = true ) {
131  (t)? m_storage |= LOWER_TRIANGLE
132  : m_storage &= ~LOWER_TRIANGLE;
133  return this->setSquare(true);
134  }
135 
136  bool isGeneric() const { return m_type == GENERIC ; }
137  bool isPositiveDefinite () const { return (m_type&POSITIVE_DEFINITE) != 0; }
138  bool isSaddlePoint () const { return (m_type&SADDLE_POINT) != 0; }
139  bool isSymmetric () const { return (m_type&SYMMETRIC) != 0; }
140  bool isDense() const { return (m_storage&DENSE) != 0; }
141  bool isSparse() const { return ! isDense() ; }
142  bool isUpperTriangle() const { return (m_storage&UPPER_TRIANGLE) != 0; }
143  bool isLowerTriangle() const { return (m_storage&LOWER_TRIANGLE) != 0; }
144  bool isSquare() const { return (m_type&SQUARE) != 0; }
145 
146  private:
147  int m_storage;
148  int m_type;
149  };
150 
151 }
152 #endif
agx::MatrixType::MatrixType
MatrixType()
Definition: MatrixTypes.h:77
agx::MatrixType::UPPER_TRIANGLE
@ UPPER_TRIANGLE
Only upper triangle is stored, dense or sparse.
Definition: MatrixTypes.h:58
agx::MatrixType::isPositiveDefinite
bool isPositiveDefinite() const
Definition: MatrixTypes.h:137
agx::MatrixType::isDense
bool isDense() const
Definition: MatrixTypes.h:140
agx::MatrixType::LOWER_TRIANGLE
@ LOWER_TRIANGLE
Only lower triangle is stored, dense or sparse.
Definition: MatrixTypes.h:59
agx::MatrixType::isLowerTriangle
bool isLowerTriangle() const
Definition: MatrixTypes.h:143
agx::MatrixType::isSparse
bool isSparse() const
Definition: MatrixTypes.h:141
agx::MatrixType
A class to distinguish between various types of matrices, both in terms of storage properties,...
Definition: MatrixTypes.h:48
agx::MatrixType::setGeneric
MatrixType & setGeneric(bool t=true)
Definition: MatrixTypes.h:109
agx::MatrixType::Storage
Storage
How the matrix is stored.
Definition: MatrixTypes.h:56
agx::MatrixType::SQUARE
@ SQUARE
Definition: MatrixTypes.h:69
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agx::MatrixType::MatrixType
MatrixType(int type, int storage)
Definition: MatrixTypes.h:80
agx::MatrixType::isSymmetric
bool isSymmetric() const
Definition: MatrixTypes.h:139
agx::MatrixType::isSquare
bool isSquare() const
Definition: MatrixTypes.h:144
agx::MatrixType::setPositiveDefinite
MatrixType & setPositiveDefinite(bool t=true)
Definition: MatrixTypes.h:103
agx::MatrixType::setSparse
MatrixType & setSparse(bool t=true)
Definition: MatrixTypes.h:120
agx::MatrixType::setSaddlePoint
MatrixType & setSaddlePoint(bool t=true)
Definition: MatrixTypes.h:97
agx::MatrixType::isUpperTriangle
bool isUpperTriangle() const
Definition: MatrixTypes.h:142
agx::MatrixType::setLowerTriangle
MatrixType & setLowerTriangle(bool t=true)
Definition: MatrixTypes.h:130
agx::MatrixType::SADDLE_POINT
@ SADDLE_POINT
Saddle point matrices, which may be symmetric or not, and positive definite or not.
Definition: MatrixTypes.h:72
agx::MatrixType::POSITIVE_DEFINITE
@ POSITIVE_DEFINITE
Positive definite matrices.
Definition: MatrixTypes.h:71
agx::MatrixType::SYMMETRIC
@ SYMMETRIC
Symmetric matrices.
Definition: MatrixTypes.h:70
agx::MatrixType::isGeneric
bool isGeneric() const
Definition: MatrixTypes.h:136
agx::MatrixType::setSquare
MatrixType & setSquare(bool t=true)
Definition: MatrixTypes.h:91
agx::MatrixType::isSaddlePoint
bool isSaddlePoint() const
Definition: MatrixTypes.h:138
agx::MatrixType::setUpperTriangle
MatrixType & setUpperTriangle(bool t=true)
Definition: MatrixTypes.h:124
agx::MatrixType::GENERIC
@ GENERIC
No special property.
Definition: MatrixTypes.h:68
agx::MatrixType::Type
Type
The kind of matrix we are dealing with.
Definition: MatrixTypes.h:67
agx::MatrixType::DENSE
@ DENSE
The entire matrix is stored, or it is sparse.
Definition: MatrixTypes.h:57
agx::MatrixType::setSymmetric
MatrixType & setSymmetric(bool t=true)
Definition: MatrixTypes.h:85
agx::MatrixType::setDense
MatrixType & setDense(bool t=true)
Definition: MatrixTypes.h:114