68 #include "xc_utils/src/kernel/CommandEntity.h" 69 #include "xc_basic/src/matrices/m_double.h" 78 #define MATRIX_VERY_LARGE_VALUE 1.0e213 111 static double MATRIX_NOT_VALID_ENTRY;
128 Matrix(
int nrows,
int ncols);
129 Matrix(
double *data,
int nrows,
int ncols);
130 Matrix(
const boost::python::list &l);
131 inline virtual ~
Matrix(
void) {}
134 int setData(
double *newData,
int nRows,
int nCols);
135 const double *getDataPtr(
void)
const;
136 double *getDataPtr(
void);
137 bool isEmpty(
void)
const;
138 int getDataSize(
void)
const;
139 int getNumBytes(
void)
const;
144 int resize(
int numRow,
int numCol);
152 Matrix getInverse(
void)
const;
154 double rowSum(
int i)
const;
158 double Norm2(
void)
const;
159 double Norm(
void)
const;
161 double RCond(
void)
const;
164 int addMatrixProduct(
double factThis,
const Matrix &A,
const Matrix &B,
double factOther);
165 int addMatrixTripleProduct(
double factThis,
const Matrix &A,
const Matrix &B,
double factOther);
170 const double &
operator()(
int row,
int col)
const;
175 template <
class TNSR>
176 Matrix &operator=(
const TNSR &);
178 inline bool isRow(
void)
const 179 {
return (numRows == 1); }
180 inline bool isColumn(
void)
const 181 {
return (numCols == 1); }
220 void Output(std::ostream &s)
const;
221 void Input(
const std::string &);
222 void write(std::ofstream &);
223 void read(std::ifstream &);
227 int Assemble(
const Matrix &V,
int init_row,
int init_col,
double fact = 1.0);
228 int AssembleTranspose(
const Matrix &V,
int init_row,
int init_col,
double fact = 1.0);
229 int Extract(
const Matrix &V,
int init_row,
int init_col,
double fact = 1.0);
232 friend std::ostream &operator<<(std::ostream &,
const Matrix &);
234 inline std::string toString(
void)
const 241 std::ostream &operator<<(std::ostream &,
const Matrix &);
249 inline bool Matrix::isEmpty(
void)
const 252 inline int Matrix::getDataSize()
const 253 {
return data.
Size(); }
255 inline int Matrix::getNumBytes(
void)
const 266 inline const double *Matrix::getDataPtr(
void)
const 269 inline double *Matrix::getDataPtr(
void)
285 if((row < 0) || (row >= numRows))
287 std::cerr << getClassName() <<
"::" << __FUNCTION__
288 <<
"; row " << row <<
" out of range [0, " 289 << numRows-1 << std::endl;
292 else if((col < 0) || (col >= numCols))
294 std::cerr << getClassName() <<
"::" << __FUNCTION__
295 <<
"; row " << col <<
" out of range [0, " 296 << numCols-1 << std::endl;
297 return MATRIX_NOT_VALID_ENTRY;
300 return data(col*numRows + row);
317 if((row < 0) || (row >= numRows))
319 std::cerr << getClassName() <<
"::" << __FUNCTION__
321 <<
" out of range [0, " << numRows-1 << std::endl;
324 else if((col < 0) || (col >= numCols))
326 std::cerr << getClassName() <<
"::" << __FUNCTION__
328 <<
" out of range [0, " << numCols-1 << std::endl;
329 return MATRIX_NOT_VALID_ENTRY;
332 return data(col*numRows + row);
340 template <
class TNSR>
346 std::cerr << getClassName() <<
"::" << __FUNCTION__
347 <<
"; BJtensor must be of rank 4.\n";
351 if(dim != V.dim(2) != V.dim(3) != V.dim(4))
353 std::cerr << getClassName() <<
"::" << __FUNCTION__
354 <<
"; BJtensor must have square dimensions.\n";
358 if(dim != 2 || dim != 3 || dim != 1)
360 std::cerr << getClassName() <<
"::" << __FUNCTION__
361 <<
"; BJtensor must be of dimension 2 or 3.\n";
367 if((numCols != 1) || (numRows != 1))
369 std::cerr << getClassName() <<
"::" << __FUNCTION__
370 <<
"; matrix must be 1x1 for BJtensor of dimension 3.\n";
373 (*this)(0,0)= V.cval(1,1,1,1);
378 if((numCols != 3) || (numRows != 3))
380 std::cerr << getClassName() <<
"::" << __FUNCTION__
381 <<
"; matrix must be 1x1 for BJtensor of dimension 3.\n";
384 (*this)(0,0)= V.cval(1,1,1,1);
385 (*this)(0,1)= V.cval(1,1,2,2);
386 (*this)(0,2)= V.cval(1,1,1,2);
388 (*this)(1,0)= V.cval(2,2,1,1);
389 (*this)(1,1)= V.cval(2,2,2,2);
390 (*this)(1,2)= V.cval(2,2,1,2);
392 (*this)(2,0)= V.cval(1,2,1,1);
393 (*this)(2,1)= V.cval(1,2,2,2);
394 (*this)(2,2)= V.cval(1,2,1,2);
399 if((numCols != 6) || (numRows != 6))
401 std::cerr << getClassName() <<
"::" << __FUNCTION__
402 <<
"; matrix must be 1x1 for BJtensor of dimension 3.\n";
405 (*this)(0,0)= V.cval(1,1,1,1);
406 (*this)(0,1)= V.cval(1,1,2,2);
407 (*this)(0,2)= V.cval(1,1,3,3);
408 (*this)(0,3)= V.cval(1,1,1,2);
409 (*this)(0,4)= V.cval(1,1,1,3);
410 (*this)(0,5)= V.cval(1,1,2,3);
412 (*this)(1,0)= V.cval(2,2,1,1);
413 (*this)(1,1)= V.cval(2,2,2,2);
414 (*this)(1,2)= V.cval(2,2,3,3);
415 (*this)(1,3)= V.cval(2,2,1,2);
416 (*this)(1,4)= V.cval(2,2,1,3);
417 (*this)(1,5)= V.cval(2,2,2,3);
419 (*this)(2,0)= V.cval(3,3,1,1);
420 (*this)(2,1)= V.cval(3,3,2,2);
421 (*this)(2,2)= V.cval(3,3,3,3);
422 (*this)(2,3)= V.cval(3,3,1,2);
423 (*this)(2,4)= V.cval(3,3,1,3);
424 (*this)(2,5)= V.cval(3,3,2,3);
426 (*this)(3,0)= V.cval(1,2,1,1);
427 (*this)(3,1)= V.cval(1,2,2,2);
428 (*this)(3,2)= V.cval(1,2,3,3);
429 (*this)(3,3)= V.cval(1,2,1,2);
430 (*this)(3,4)= V.cval(1,2,1,3);
431 (*this)(3,5)= V.cval(1,2,2,3);
433 (*this)(4,0)= V.cval(1,3,1,1);
434 (*this)(4,1)= V.cval(1,3,2,2);
435 (*this)(4,2)= V.cval(1,3,3,3);
436 (*this)(4,3)= V.cval(1,3,1,2);
437 (*this)(4,4)= V.cval(1,3,1,3);
438 (*this)(4,5)= V.cval(1,3,2,3);
440 (*this)(5,0)= V.cval(2,3,1,1);
441 (*this)(5,1)= V.cval(2,3,2,2);
442 (*this)(5,2)= V.cval(2,3,3,3);
443 (*this)(5,3)= V.cval(2,3,1,2);
444 (*this)(5,4)= V.cval(2,3,1,3);
445 (*this)(5,5)= V.cval(2,3,2,3);
double Norm2(void) const
Returns the squared modulus (euclidean norm) of the matrix.
Definition: Matrix.cpp:1530
Matrix transposed(const Matrix &m)
Return the transposed of the parameter.
Definition: Matrix.h:336
friend std::string to_string(const Matrix &)
Returns a string that represents the matrix.
Definition: Matrix.cpp:1336
Float vector abstraction.
Definition: Vector.h:93
double columnSum(int j) const
Returns the sum of the j-th row.
Definition: Matrix.cpp:1521
double OneNorm(void) const
Returns the value of the one norm.
Definition: Matrix.cpp:1574
void Input(const std::string &)
Read from string.
Definition: Matrix.cpp:1311
Vector getCol(int col) const
Return the column which index being passed as parameter.
Definition: Matrix.cpp:800
double rowNorm(void) const
Returns the maximum value of the elements of the vector that results that contains the row sums...
Definition: Matrix.cpp:1557
double & operator()(int row, int col)
Returns a reference to the data at location({row,col}).
Definition: Matrix.h:282
double Norm(void) const
Returns the modulus (euclidean norm) of the matrix.
Definition: Matrix.cpp:1552
void Zero(void)
Zero's out the Matrix.
Definition: Matrix.cpp:182
Matrix operator-(void) const
Unary minus operator.
Definition: Matrix.cpp:1084
int noCols() const
Returns the number of columns, numCols, of the Matrix.
Definition: Matrix.h:263
double columnNorm(void) const
Returns the maximum value of the elements of the vector that results that contains the column sums...
Definition: Matrix.cpp:1566
Matrix(void)
Default constructor.
Definition: Matrix.cpp:81
Vector of integers.
Definition: ID.h:93
m_double matrix_to_m_double(const Matrix &m)
Converts a Matrix into an m_double.
Definition: Matrix.cpp:1299
Matrix & operator-=(double fact)
A method to subtract fact from each component of the current Matrix.
Definition: Matrix.cpp:854
TCP_Socket is a sub-class of channel.
Definition: TCP_Socket.h:71
Vector operator^(const Vector &V) const
A method to return a new Vector, of size numCols, whose components are equal to the product of the tr...
Definition: Matrix.cpp:1064
Matrix operator*(double fact) const
A method to return a new Matrix, whose components are equal to the components of the current Matrix t...
Definition: Matrix.cpp:970
Definition: AuxMatrix.h:42
double RCond(void) const
Return an estimation of the reciprocal of the condition number.
Definition: Matrix.cpp:1616
int Size(void) const
Returns the size of the Vector.
Definition: Vector.h:228
TCP_SocketNoDelay is a sub-class of channel.
Definition: TCP_SocketNoDelay.h:72
int Assemble(const Matrix &, const ID &rows, const ID &cols, double fact=1.0)
Assembles the argument into the current Matrix.
Definition: Matrix.cpp:237
int getNumBytes(void) const
Number of bytes occupied by the vector.
Definition: Vector.h:232
int Invert(Matrix &res) const
Return the inverse matrix in the argument.
Definition: Matrix.cpp:442
bool isEmpty(void) const
Return true if the vector has no data.
Definition: Vector.h:251
Matrix operator/(double fact) const
A method to return a new Matrix whose components are equal to the components of the current Matrix di...
Definition: Matrix.cpp:986
int Solve(const Vector &V, Vector &res) const
Solve the equation {} for the Vector x, which is returned.
Definition: Matrix.cpp:298
void write(std::ofstream &)
Write to a binary file.
Definition: Matrix.cpp:1320
MPI_Channel is a sub-class of channel.
Definition: MPI_Channel.h:69
int noRows() const
Returns the number of rows, numRows, of the Matrix.
Definition: Matrix.h:259
int addMatrix(double factThis, const Matrix &other, double factOther)
Add a factor fact times the Matrix other to the current Matrix.
Definition: Matrix.cpp:512
Matrix & operator*=(double fact)
A method to multiply each component of the current Matrix by fact.
Definition: Matrix.cpp:874
void Output(std::ostream &s) const
Write to the argument stream.
Definition: Matrix.cpp:1266
Message between processes.
Definition: Message.h:76
Vector getRow(int row) const
Return the row which index being passed as parameter.
Definition: Matrix.cpp:791
Matrix & operator/=(double fact)
A method which will divide each component of the current Matrix by fact.
Definition: Matrix.cpp:896
Matrix getTrn(void) const
Return the transpuesta.
Definition: Matrix.cpp:1397
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:34
void read(std::ifstream &)
Read from a bynary file.
Definition: Matrix.cpp:1328
const double * getDataPtr(void) const
Return a pointer to the float date.
Definition: Vector.h:236
Matrix of floats.
Definition: Matrix.h:108
Matrix m_double_to_matrix(const m_double &m)
Converts a matrix of type m_double into other of type Matrix.
Definition: Matrix.cpp:1287
double rowSum(int i) const
Returns the sum of the i-th row.
Definition: Matrix.cpp:1512
Matrix operator+(double fact) const
A method to return a new Matrix, whose components are equal to the components of the current Matrix p...
Definition: Matrix.cpp:938
Matrix & operator+=(double fact)
A method to add fact to each component of the current Matrix.
Definition: Matrix.cpp:834
DP_Socket is a sub-class of channel.
Definition: UDP_Socket.h:76