24 typedef std::vector<T> Vec_T_Type;
25 typedef const std::vector<T> Vec_T_Const_Type;
26 typedef std::vector<Vec_T_Type> Vec2D_T_Type;
30 SmallMatrix(
int size);
32 SmallMatrix(
int size, T v);
34 Vec_T_Type &operator[](
int i);
36 Vec_T_Const_Type &operator[](
int i)
const;
38 SmallMatrix<T> &operator=(
const SmallMatrix<T> &sm);
40 SmallMatrix<T> operator*(
const SmallMatrix<T> &other);
42 SmallMatrix<T> operator+(
const SmallMatrix<T> &other);
44 SmallMatrix<T> &operator*=(
const SmallMatrix<T> &other);
46 SmallMatrix<T> &operator+=(
const SmallMatrix<T> &other);
48 int multiply(
const SmallMatrix<T> &bMat, SmallMatrix<T> &cMat)
const;
50 int add(
const SmallMatrix<T> &bMat, SmallMatrix<T> &cMat)
const;
52 int innerProduct(
const SmallMatrix<T> &bMat, T &res)
const;
54 double innerProduct(
const SmallMatrix<T> &bMat)
const;
56 void trace(T &res)
const;
66 double computeInverse(SmallMatrix<T> &inverse)
const;
68 double computeDet()
const;
70 double computeScaling()
const;
82SmallMatrix<T>::SmallMatrix():
87SmallMatrix<T>::SmallMatrix(
int size):
88values_(size,Vec_T_Type(size)),
93SmallMatrix<T>::SmallMatrix(
int size, T v):
94values_( size, Vec_T_Type( size, v ) ),
99typename SmallMatrix<T>::Vec_T_Type &SmallMatrix<T>::operator[](
int i) {
101 return values_.at(i);
104typename SmallMatrix<T>::Vec_T_Const_Type &SmallMatrix<T>::operator[](
int i)
const{
106 return values_.at(i);
112 cMat[0][0] = values_[0][0]*bMat[0][0] + values_[0][1]*bMat[1][0];
113 cMat[0][1] = values_[0][0]*bMat[0][1] + values_[0][1]*bMat[1][1];
114 cMat[1][0] = values_[1][0]*bMat[0][0] + values_[1][1]*bMat[1][0];
115 cMat[1][1] = values_[1][0]*bMat[0][1] + values_[1][1]*bMat[1][1];
118 cMat[0][0] = values_[0][0]*bMat[0][0] + values_[0][1]*bMat[1][0] + values_[0][2]*bMat[2][0];
119 cMat[0][1] = values_[0][0]*bMat[0][1] + values_[0][1]*bMat[1][1] + values_[0][2]*bMat[2][1];
120 cMat[0][2] = values_[0][0]*bMat[0][2] + values_[0][1]*bMat[1][2] + values_[0][2]*bMat[2][2];
122 cMat[1][0] = values_[1][0]*bMat[0][0] + values_[1][1]*bMat[1][0] + values_[1][2]*bMat[2][0];
123 cMat[1][1] = values_[1][0]*bMat[0][1] + values_[1][1]*bMat[1][1] + values_[1][2]*bMat[2][1];
124 cMat[1][2] = values_[1][0]*bMat[0][2] + values_[1][1]*bMat[1][2] + values_[1][2]*bMat[2][2];
126 cMat[2][0] = values_[2][0]*bMat[0][0] + values_[2][1]*bMat[1][0] + values_[2][2]*bMat[2][0];
127 cMat[2][1] = values_[2][0]*bMat[0][1] + values_[2][1]*bMat[1][1] + values_[2][2]*bMat[2][1];
128 cMat[2][2] = values_[2][0]*bMat[0][2] + values_[2][1]*bMat[1][2] + values_[2][2]*bMat[2][2];
131 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"SmallMatrix wrong size!")
139 for(
int i=0; i< size_; i++){
140 for(
int j=0; j< size_;j++){
141 cMat[i][j] = values_[i][j]+bMat[i][j];
172int SmallMatrix<T>::innerProduct(
const SmallMatrix<T> &bMat, T &res)
const {
175 res = values_[0][0]*bMat[0][0] + values_[0][1]*bMat[0][1] +
176 values_[1][0]*bMat[1][0] + values_[1][1]*bMat[1][1];
179 res = values_[0][0]*bMat[0][0] + values_[0][1]*bMat[0][1] + values_[0][2]*bMat[0][2] +
180 values_[1][0]*bMat[1][0] + values_[1][1]*bMat[1][1] + values_[1][2]*bMat[1][2] +
181 values_[2][0]*bMat[2][0] + values_[2][1]*bMat[2][1] + values_[2][2]*bMat[2][2];
184 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"SmallMatrix wrong size!")
193 return values_[0][0]*bMat[0][0] + values_[0][1]*bMat[0][1] +
194 values_[1][0]*bMat[1][0] + values_[1][1]*bMat[1][1];
197 return values_[0][0]*bMat[0][0] + values_[0][1]*bMat[0][1] + values_[0][2]*bMat[0][2] +
198 values_[1][0]*bMat[1][0] + values_[1][1]*bMat[1][1] + values_[1][2]*bMat[1][2] +
199 values_[2][0]*bMat[2][0] + values_[2][1]*bMat[2][1] + values_[2][2]*bMat[2][2];
202 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"SmallMatrix wrong size!")
213 res = values_[0][0] + values_[1][1];
217 res = values_[0][0] + values_[1][1] + values_[2][2];
220 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"SmallMatrix wrong size!")
226void SmallMatrix<T>::scale(T scalar){
228 for (
int i=0; i<size_; i++) {
229 for (
int j=0; j<size_; j++) {
230 values_[i][j] *= scalar;
237int SmallMatrix<T>::size()
const{
242void SmallMatrix<T>::resize(UN size){
243 for (
int i=0; i<size_; i++)
244 values_[i].resize(size);
246 values_.resize(size,Vec_T_Type(size));
251typename SmallMatrix<T>::SmallMatrix &SmallMatrix<T>::operator=(
const SmallMatrix<T> &sm){
254 values_.resize(size_);
256 for (
int i=0; i<sm.size(); i++) {
257 values_.at(i) = sm[i];
264typename SmallMatrix<T>::SmallMatrix SmallMatrix<T>::operator*(
const SmallMatrix<T> &other){
266 size_ = other.size();
269 this->multiply(other, result);
275typename SmallMatrix<T>::SmallMatrix SmallMatrix<T>::operator+(
const SmallMatrix<T> &other){
277 size_ = other.size();
280 this->add(other, result);
286typename SmallMatrix<T>::SmallMatrix &SmallMatrix<T>::operator*=(
const SmallMatrix<T> &other){
288 this->multiply(other, *
this);
294typename SmallMatrix<T>::SmallMatrix &SmallMatrix<T>::operator+=(
const SmallMatrix<T> &other){
296 this->add(other, *
this);
302void SmallMatrix<T>::print()
const {
304 for (
int i=0; i<size_; i++) {
305 std::cout <<
"row "<< i <<
" values:";
306 for (
int j=0; j<size_; j++) {
307 std::cout <<
" "<< values_[i][j];
309 std::cout << std::endl;
314double SmallMatrix<T>::computeInverse(
SmallMatrix<T> &inverse)
const {
316 T det = this->computeDet();
318 inverse.resize(size_);
321 inverse[0][0] = values_[1][1] / det;
322 inverse[0][1] = (-values_[0][1]) / det;
323 inverse[1][0] = (-values_[1][0]) / det;
324 inverse[1][1] = values_[0][0] / det;
327 inverse[0][0] = (values_[1][1] * values_[2][2] - values_[1][2] * values_[2][1]) / det;
328 inverse[0][1] = (values_[0][2] * values_[2][1] - values_[0][1] * values_[2][2]) / det;
329 inverse[0][2] = (values_[0][1] * values_[1][2] - values_[0][2] * values_[1][1]) / det;
331 inverse[1][0] = (values_[1][2] * values_[2][0] - values_[1][0] * values_[2][2]) / det;
332 inverse[1][1] = (values_[0][0] * values_[2][2] - values_[0][2] * values_[2][0]) / det;
333 inverse[1][2] = (values_[0][2] * values_[1][0] - values_[0][0] * values_[1][2]) / det;
335 inverse[2][0] = (values_[1][0] * values_[2][1] - values_[1][1] * values_[2][0]) / det;
336 inverse[2][1] = (values_[0][1] * values_[2][0] - values_[0][0] * values_[2][1]) / det;
337 inverse[2][2] = (values_[0][0] * values_[1][1] - values_[0][1] * values_[1][0]) / det;
341 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Matrix size is not 2 or 3.")
350 det = values_[0][0] * values_[1][1] - values_[1][0] * values_[0][1];
353 det = values_[0][0] * values_[1][1] * values_[2][2] +
354 values_[0][1] * values_[1][2] * values_[2][0] +
355 values_[0][2] * values_[1][0] * values_[2][1] -
356 values_[2][0] * values_[1][1] * values_[0][2] -
357 values_[2][1] * values_[1][2] * values_[0][0] -
358 values_[2][2] * values_[1][0] * values_[0][1] ;
361 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Matrix size is not 2 or 3.")
372 scaling = std::sqrt( values_[0][0] * values_[0][0] + values_[1][0] * values_[1][0] );
375 double c1 = ( values_[1][0] * values_[2][1] - values_[2][0] * values_[1][1] );
376 double c2 = ( values_[2][0] * values_[0][1] - values_[0][0] * values_[2][1] );
377 double c3 = ( values_[0][0] * values_[1][1] - values_[1][0] * values_[0][1] );
379 scaling = std::sqrt( c1*c1 + c2*c2 + c3*c3 );
382 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
"Matrix size is not 2 or 3.")
This class represents a templated small Matrix of type T. Primarily created for 2x2 and 3x3 matrices....
Definition SmallMatrix.hpp:20
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36