-
Notifications
You must be signed in to change notification settings - Fork 4
/
Matrix.h
76 lines (62 loc) · 1.71 KB
/
Matrix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// Matrix.h
// TopOpt
//
// Created by Morten Nobel-Joergensen on 4/30/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#ifndef TopOpt_Matrix_h
#define TopOpt_Matrix_h
#include <vector>
#include <cassert>
#ifndef tfloat
#define tfloat double
#endif
/// Column-major order storage of matrix
/// Example m x n (2 x 3)
/// 1 2 3
/// 4 5 6
/// is stored [1 4 2 5 3 6]
///
/// M_ij is the i-th row and the j-th column
class Matrix {
public:
Matrix(int rows, int columns);
Matrix(const Matrix& m);
~Matrix();
void set(const Matrix& m);
void add(int i, int j, tfloat value);
void set(int i, int j, tfloat value);
tfloat get(int i, int j) const;
void fixedDofs(std::vector<int> &fixeddofs);
tfloat maxDiff(const Matrix &m);
tfloat sum();
void print();
void multiply(const Matrix &m, Matrix *dest);
Matrix multiply(const Matrix &m);
tfloat& operator[] (const int nIndex);
void fill(tfloat value);
int getDataCount(){ return dataCount; }
int getRows(){ return rows; }
int getColumns(){ return columns; }
tfloat vTransposeMultMMultV(tfloat *v);
// Solve Ab=x
bool solve(tfloat const * const b, tfloat *x);
bool solve(tfloat const * const b, tfloat *x, std::vector<int> &freedofs);
void setDataColumnOrder(tfloat *d);
bool isBanded(){ return false; }
inline int getIndex(int i, int j) const {
assert(i >= 0);
assert(j >= 0);
assert(i < rows);
assert(j < columns);
return i+j*rows;
}
private:
tfloat *data;
int rows;
int columns;
int dataCount;
bool solveGaussianElimination(tfloat const * const b, tfloat *x);
};
#endif