68 #include "xc_utils/src/nucleo/EntCmd.h" 69 #include "xc_basic/src/matrices/m_double.h" 78 #define MATRIX_VERY_LARGE_VALUE 1.0e213 85 static double MATRIX_NOT_VALID_ENTRY;
104 Matrix(
int nrows,
int ncols);
105 Matrix(
double *data,
int nrows,
int ncols);
106 Matrix(
const boost::python::list &l);
107 inline virtual ~
Matrix(
void) {}
110 int setData(
double *newData,
int nRows,
int nCols);
111 const double *getDataPtr(
void)
const;
112 double *getDataPtr(
void);
113 bool Nula(
void)
const;
114 int getDataSize(
void)
const;
115 int getNumBytes(
void)
const;
120 int resize(
int numRow,
int numCol);
123 int Assemble(
const Matrix &,
const ID &rows,
const ID &cols,
double fact = 1.0);
127 int Invert(
Matrix &res)
const;
129 double rowSum(
int i)
const;
133 double Norm2(
void)
const;
134 double Norm(
void)
const;
136 int addMatrix(
double factThis,
const Matrix &other,
double factOther);
137 int addMatrixProduct(
double factThis,
const Matrix &A,
const Matrix &B,
double factOther);
138 int addMatrixTripleProduct(
double factThis,
const Matrix &A,
const Matrix &B,
double factOther);
142 double &operator()(
int row,
int col);
143 const double &operator()(
int row,
int col)
const;
144 Matrix operator()(
const ID &rows,
const ID & cols)
const;
148 template <
class TNSR>
149 Matrix &operator=(
const TNSR &);
151 inline bool isRow(
void)
const 152 {
return (numRows == 1); }
153 inline bool isColumn(
void)
const 154 {
return (numCols == 1); }
160 Matrix &operator+=(
double fact);
161 Matrix &operator-=(
double fact);
162 Matrix &operator*=(
double fact);
163 Matrix &operator/=(
double fact);
170 Matrix operator+(
double fact)
const;
171 Matrix operator-(
double fact)
const;
172 Matrix operator*(
double fact)
const;
173 Matrix operator/(
double fact)
const;
192 void Output(std::ostream &s)
const;
193 void Input(
const std::string &);
194 void write(std::ofstream &);
195 void read(std::ifstream &);
199 int Assemble(
const Matrix &V,
int init_row,
int init_col,
double fact = 1.0);
200 int AssembleTranspose(
const Matrix &V,
int init_row,
int init_col,
double fact = 1.0);
201 int Extract(
const Matrix &V,
int init_row,
int init_col,
double fact = 1.0);
204 friend std::ostream &operator<<(std::ostream &s,
const Matrix &M);
206 inline std::string toString(
void)
const 219 inline bool Matrix::Nula(
void)
const 220 {
return data.Nulo(); }
222 inline int Matrix::getDataSize()
const 223 {
return data.Size(); }
225 inline int Matrix::getNumBytes(
void)
const 226 {
return data.getNumBytes(); }
228 inline int Matrix::noRows()
const 231 inline int Matrix::noCols()
const 234 inline const double *Matrix::getDataPtr(
void)
const 235 {
return data.getDataPtr(); }
237 inline double *Matrix::getDataPtr(
void)
238 {
return data.getDataPtr(); }
240 inline double &Matrix::operator()(
int row,
int col)
243 if((row < 0) || (row >= numRows))
245 std::cerr <<
"Matrix::operator() - row " << row <<
" our of range [0, " << numRows-1 << endln;
249 if((col < 0) || (col >= numCols))
251 std::cerr <<
"Matrix::operator() - row " << col <<
" our of range [0, " << numCols-1 << endln;
252 return MATRIX_NOT_VALID_ENTRY;
255 return data(col*numRows + row);
259 inline const double &Matrix::operator()(
int row,
int col)
const 262 if((row < 0) || (row >= numRows))
264 std::cerr <<
"Matrix::operator() - row " << row
265 <<
" our of range [0, " << numRows-1 << endln;
268 else if((col < 0) || (col >= numCols))
270 std::cerr <<
"Matrix::operator() - row " << col
271 <<
" our of range [0, " << numCols-1 << endln;
272 return MATRIX_NOT_VALID_ENTRY;
275 return data(col*numRows + row);
281 template <
class TNSR>
282 XC::Matrix &XC::Matrix::operator=(
const TNSR &V)
287 std::cerr <<
"Matrix::operator=() - BJtensor must be of rank 4\n";
291 if(dim != V.dim(2) != V.dim(3) != V.dim(4))
293 std::cerr <<
"Matrix::operator=() - BJtensor must have square dimensions\n";
297 if(dim != 2 || dim != 3 || dim != 1)
299 std::cerr <<
"Matrix::operator=() - BJtensor must be of dimension 2 or 3\n";
305 if((numCols != 1) || (numRows != 1))
307 std::cerr <<
"Matrix::operator=() - matrix must be 1x1 for XC::BJtensor of dimension 3\n";
310 (*this)(0,0)= V.cval(1,1,1,1);
315 if((numCols != 3) || (numRows != 3))
317 std::cerr <<
"Matrix::operator=() - matrix must be 1x1 for XC::BJtensor of dimension 3\n";
320 (*this)(0,0)= V.cval(1,1,1,1);
321 (*this)(0,1)= V.cval(1,1,2,2);
322 (*this)(0,2)= V.cval(1,1,1,2);
324 (*this)(1,0)= V.cval(2,2,1,1);
325 (*this)(1,1)= V.cval(2,2,2,2);
326 (*this)(1,2)= V.cval(2,2,1,2);
328 (*this)(2,0)= V.cval(1,2,1,1);
329 (*this)(2,1)= V.cval(1,2,2,2);
330 (*this)(2,2)= V.cval(1,2,1,2);
335 if((numCols != 6) || (numRows != 6))
337 std::cerr <<
"Matrix::operator=() - matrix must be 1x1 for XC::BJtensor of dimension 3\n";
340 (*this)(0,0)= V.cval(1,1,1,1);
341 (*this)(0,1)= V.cval(1,1,2,2);
342 (*this)(0,2)= V.cval(1,1,3,3);
343 (*this)(0,3)= V.cval(1,1,1,2);
344 (*this)(0,4)= V.cval(1,1,1,3);
345 (*this)(0,5)= V.cval(1,1,2,3);
347 (*this)(1,0)= V.cval(2,2,1,1);
348 (*this)(1,1)= V.cval(2,2,2,2);
349 (*this)(1,2)= V.cval(2,2,3,3);
350 (*this)(1,3)= V.cval(2,2,1,2);
351 (*this)(1,4)= V.cval(2,2,1,3);
352 (*this)(1,5)= V.cval(2,2,2,3);
354 (*this)(2,0)= V.cval(3,3,1,1);
355 (*this)(2,1)= V.cval(3,3,2,2);
356 (*this)(2,2)= V.cval(3,3,3,3);
357 (*this)(2,3)= V.cval(3,3,1,2);
358 (*this)(2,4)= V.cval(3,3,1,3);
359 (*this)(2,5)= V.cval(3,3,2,3);
361 (*this)(3,0)= V.cval(1,2,1,1);
362 (*this)(3,1)= V.cval(1,2,2,2);
363 (*this)(3,2)= V.cval(1,2,3,3);
364 (*this)(3,3)= V.cval(1,2,1,2);
365 (*this)(3,4)= V.cval(1,2,1,3);
366 (*this)(3,5)= V.cval(1,2,2,3);
368 (*this)(4,0)= V.cval(1,3,1,1);
369 (*this)(4,1)= V.cval(1,3,2,2);
370 (*this)(4,2)= V.cval(1,3,3,3);
371 (*this)(4,3)= V.cval(1,3,1,2);
372 (*this)(4,4)= V.cval(1,3,1,3);
373 (*this)(4,5)= V.cval(1,3,2,3);
375 (*this)(5,0)= V.cval(2,3,1,1);
376 (*this)(5,1)= V.cval(2,3,2,2);
377 (*this)(5,2)= V.cval(2,3,3,3);
378 (*this)(5,3)= V.cval(2,3,1,2);
379 (*this)(5,4)= V.cval(2,3,1,3);
380 (*this)(5,5)= V.cval(2,3,2,3);
double rowSum(int i) const
Returns the sum of the i-th row.
Definition: Matrix.cpp:1278
double columnNorm(void) const
Returns the maximum value of the elements of the vector that results that contains the column sums...
Definition: Matrix.cpp:1331
void read(std::ifstream &)
Lee la matriz de un archivo binario.
Definition: Matrix.cpp:1094
void Input(const std::string &)
Lectura desde cadena de caracteres.
Definition: Matrix.cpp:1077
double columnSum(int j) const
Returns the sum of the j-th row.
Definition: Matrix.cpp:1287
MPI_Channel is a sub-class of channel. It is implemented with Berkeley stream sockets using the TCP p...
Definition: MPI_Channel.h:69
void write(std::ofstream &)
Escribe la matriz en un archivo binario.
Definition: Matrix.cpp:1086
double Norm(void) const
Returns the modulus (euclidean norm) of the matrix.
Definition: Matrix.cpp:1317
DP_Socket is a sub-class of channel. It is implemented with Berkeley datagram sockets using the UDP p...
Definition: UDP_Socket.h:76
TCP_Socket is a sub-class of channel. It is implemented with Berkeley stream sockets using the TCP pr...
Definition: TCP_Socket.h:71
Matrix(void)
Constructor.
Definition: Matrix.cpp:81
double rowNorm(void) const
Returns the maximum value of the elements of the vector that results that contains the row sums...
Definition: Matrix.cpp:1322
Vector getCol(int col) const
Return the columna which index being passed as parameter.
Definition: Matrix.cpp:711
Matrix getTrn(void) const
Return the transpuesta.
Definition: Matrix.cpp:1163
friend std::string to_string(const Matrix &)
Returns a string that represents the matrix.
Definition: Matrix.cpp:1102
Matrix m_double_to_matrix(const m_double &m)
Convierte una matriz de tipo m_double otra de tipo Matrix.
Definition: Matrix.cpp:1053
double Norm2(void) const
Returns the squared modulus (euclidean norm) of the matrix.
Definition: Matrix.cpp:1296
Definition: AuxMatrix.h:42
TCP_SocketNoDelay is a sub-class of channel. It is implemented with Berkeley stream sockets using the...
Definition: TCP_SocketNoDelay.h:72
m_double matrix_to_m_double(const Matrix &m)
Convierte a una matriz de tipo m_double.
Definition: Matrix.cpp:1065
Message between processes.
Definition: Message.h:67
void Output(std::ostream &s) const
Output method.
Definition: Matrix.cpp:1032
================================================================================
Definition: ContinuaReprComponent.h:34
Vector getRow(int row) const
Return the fila which index being passed as parameter.
Definition: Matrix.cpp:702