OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
floatmatrix.h
Go to the documentation of this file.
1 /*
2  *
3  * ##### ##### ###### ###### ### ###
4  * ## ## ## ## ## ## ## ### ##
5  * ## ## ## ## #### #### ## # ##
6  * ## ## ## ## ## ## ## ##
7  * ## ## ## ## ## ## ## ##
8  * ##### ##### ## ###### ## ##
9  *
10  *
11  * OOFEM : Object Oriented Finite Element Code
12  *
13  * Copyright (C) 1993 - 2013 Borek Patzak
14  *
15  *
16  *
17  * Czech Technical University, Faculty of Civil Engineering,
18  * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33  */
34 
35 /*
36  * The original idea for this class comes from
37  * Dubois-Pelerin, Y.: "Object-Oriented Finite Elements: Programming concepts and Implementation",
38  * PhD Thesis, EPFL, Lausanne, 1992.
39  */
40 
41 #ifndef flotmtrx_h
42 #define flotmtrx_h
43 
44 #include "oofemcfg.h"
45 #include "contextioresulttype.h"
46 #include "contextmode.h"
47 
48 #include <vector>
49 #include <iosfwd>
50 #include <initializer_list>
51 #include <algorithm>
52 
53 #ifdef BOOST_PYTHON
54 namespace boost {
55 namespace python {
56 namespace api {
57 class object;
58 };
59 };
60 };
61 #endif
62 
63 namespace oofem {
64 class FloatArray;
65 class IntArray;
66 class DataStream;
67 
94 class OOFEM_EXPORT FloatMatrix
95 {
96 protected:
98  int nRows;
100  int nColumns;
102  std :: vector< double >values;
103 
104 public:
110  FloatMatrix(int n, int m) : nRows(n), nColumns(m), values(n * m) {}
112  FloatMatrix() : nRows(0), nColumns(0), values() {}
121  FloatMatrix(const FloatArray &vector, bool transpose = false);
123  FloatMatrix(const FloatMatrix &mat) : nRows(mat.nRows), nColumns(mat.nColumns), values(mat.values) {}
125  FloatMatrix(FloatMatrix && mat) : nRows(mat.nRows), nColumns(mat.nColumns), values( std :: move(mat.values) ) {}
127  FloatMatrix(std :: initializer_list< std :: initializer_list< double > >mat);
129  FloatMatrix &operator=(std :: initializer_list< std :: initializer_list< double > >mat);
131  FloatMatrix &operator=(std :: initializer_list< FloatArray >mat);
134  nRows = mat.nRows;
135  nColumns = mat.nColumns;
136  values = mat.values;
137  return * this;
138  }
140  nRows = std :: move(mat.nRows);
141  nColumns = std :: move(mat.nColumns);
142  values = std :: move(mat.values);
143  return * this;
144  }
147 
154  void checkBounds(int i, int j) const;
156  inline int giveNumberOfRows() const { return nRows; }
158  inline int giveNumberOfColumns() const { return nColumns; }
160  inline bool isSquare() const { return nRows == nColumns; }
162  inline bool isNotEmpty() const { return nRows > 0 && nColumns > 0; }
163 
165  bool isFinite() const;
166 
173 #ifdef DEBUG
174  double at(int i, int j) const;
175 #else
176  inline double at(int i, int j) const { return values [ ( j - 1 ) * nRows + i - 1 ]; }
177 #endif
178 
184 #ifdef DEBUG
185  double &at(int i, int j);
186 #else
187  inline double &at(int i, int j) { return values [ ( j - 1 ) * nRows + i - 1 ]; }
188 #endif
189 
196 #ifdef DEBUG
197  double &operator()(int i, int j);
198 #else
199  inline double &operator()(int i, int j) { return values [ j * nRows + i ]; }
200 #endif
201 
206 #ifdef DEBUG
207  double operator()(int i, int j) const;
208 #else
209  inline double operator()(int i, int j) const { return values [ j * nRows + i ]; }
210 #endif
211 
217  void assemble(const FloatMatrix &src, const IntArray &loc);
225  void assemble(const FloatMatrix &src, const IntArray &rowind, const IntArray &colind);
233  void assemble(const FloatMatrix &src, const int *rowind, const int *colind);
234 
240  double computeFrobeniusNorm() const;
246  double computeNorm(char p) const;
254  double computeReciprocalCondition(char p = '1') const;
255  /*
256  * Computes the eigenvalues of a symmetric matrix.
257  * The receiver must be square and symmetric.
258  * @param lambda Eigenvalues.
259  * @param v Eigenvectors (stored column wise).
260  * @param neigs If set, only neigs largest eigenvalues are computed.
261  * @return True if successful.
262  */
263  //bool computeEigenValuesSymmetric(FloatArray &lambda, FloatMatrix &v, int neigs = 0) const;
268  void beDiagonal(const FloatArray &diag);
273  double giveTrace() const;
278  double giveDeterminant() const;
279 
281  void zero();
283  void beUnitMatrix();
285  void bePinvID();
290  void beTranspositionOf(const FloatMatrix &src);
295  void beProductOf(const FloatMatrix &a, const FloatMatrix &b);
299  void addProductOf(const FloatMatrix &a, const FloatMatrix &b);
303  void addTProductOf(const FloatMatrix &a, const FloatMatrix &b);
308  void beTProductOf(const FloatMatrix &a, const FloatMatrix &b);
313  void beProductTOf(const FloatMatrix &a, const FloatMatrix &b);
318  void beDyadicProductOf(const FloatArray &vec1, const FloatArray &vec2);
324  void beNMatrixOf(const FloatArray &n, int nsd);
330  void beLocalCoordSys(const FloatArray &normal);
339  void setSubMatrix(const FloatMatrix &src, int sr, int sc);
347  void setTSubMatrix(const FloatMatrix &src, int sr, int sc);
356  void beSubMatrixOf(const FloatMatrix &src, int topRow, int bottomRow, int topCol, int bottomCol);
363  void beSubMatrixOf(const FloatMatrix &src, const IntArray &indxRow, const IntArray &indxCol);
370  void addSubVectorRow(const FloatArray &src, int sr, int sc);
377  void addSubVectorCol(const FloatArray &src, int sr, int sc);
378 
385  void copySubVectorRow(const FloatArray &src, int sr, int sc);
391  void setColumn(const FloatArray &src, int c);
397  void copyColumn(FloatArray &dest, int c) const;
402  void beInverseOf(const FloatMatrix &src);
410  bool solveForRhs(const FloatArray &b, FloatArray &answer, bool transpose = false);
417  void solveForRhs(const FloatMatrix &B, FloatMatrix &answer, bool transpose = false);
426  void plusProductSymmUpper(const FloatMatrix &a, const FloatMatrix &b, double dV);
433  void plusDyadSymmUpper(const FloatArray &a, double dV);
440  void plusProductUnsym(const FloatMatrix &a, const FloatMatrix &b, double dV);
447  void plusDyadUnsym(const FloatArray &a, const FloatArray &b, double dV);
448 
454  void add(const FloatMatrix &a);
461  void add(double s, const FloatMatrix &a);
466  void subtract(const FloatMatrix &a);
471  void times(double f);
475  void negated();
482  void initFromVector(const FloatArray &vector, bool transposed);
486  void symmetrized();
493  void rotatedWith(const FloatMatrix &r, char mode = 'n');
501  void resize(int rows, int cols);
507  void resizeWithData(int, int);
514  void hardResize(int r, int c);
516  void clear() {
517  this->nRows = 0;
518  this->nColumns = 0;
519  }
528  bool jaco_(FloatArray &eval, FloatMatrix &v, int nf);
529 
531  void printYourself() const;
536  void printYourself(const std::string &name) const;
537 
543  void printYourselfToFile(const std::string filename, const bool showDimensions=true) const;
544 
546  void pY() const;
547 
552  void writeCSV(const std :: string &name) const;
553 
558  inline const double *givePointer() const { return values.data(); }
559  inline double *givePointer() { return values.data(); }
560 
567  void beMatrixFormOfStress(const FloatArray &aArray);
568  void beMatrixForm(const FloatArray &aArray);
569 
575  void changeComponentOrder();
576 
577  // Overloaded methods:
578  contextIOResultType storeYourself(DataStream &stream) const;
579  contextIOResultType restoreYourself(DataStream &stream);
580  int givePackSize(DataStream &buff) const;
581 
582  friend std :: ostream &operator<<(std :: ostream &out, const FloatMatrix &r);
583 
584 
585 #ifdef BOOST_PYTHON
586  void __setitem__(boost :: python :: api :: object t, double val);
587  double __getitem__(boost :: python :: api :: object t);
588  void beCopyOf(const FloatMatrix &src) { this->operator=(src); }
589 #endif
590 };
591 } // end namespace oofem
592 #endif // flotmtrx_h
int nRows
Number of rows.
Definition: floatmatrix.h:98
int giveNumberOfColumns() const
Returns number of columns of receiver.
Definition: floatmatrix.h:158
double & at(int i, int j)
Coefficient access function.
Definition: floatmatrix.h:187
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
double operator()(int i, int j) const
Coefficient access function.
Definition: floatmatrix.h:209
bool isSquare() const
Returns nonzero if receiver is square matrix.
Definition: floatmatrix.h:160
const double * givePointer() const
Exposes the internal values of the matrix.
Definition: floatmatrix.h:558
Class implementing an array of integers.
Definition: intarray.h:61
int nColumns
Number of columns.
Definition: floatmatrix.h:100
~FloatMatrix()
Destructor.
Definition: floatmatrix.h:146
bool isNotEmpty() const
Tests for empty matrix.
Definition: floatmatrix.h:162
std::ostream & operator<<(std::ostream &out, const Dictionary &r)
Definition: dictionary.C:253
FloatMatrix & operator=(const FloatMatrix &mat)
Assignment operator, adjusts size of the receiver if necessary.
Definition: floatmatrix.h:133
double * givePointer()
Definition: floatmatrix.h:559
FloatMatrix & operator=(FloatMatrix &&mat)
Definition: floatmatrix.h:139
double at(int i, int j) const
Coefficient access function.
Definition: floatmatrix.h:176
Class representing vector of real numbers.
Definition: floatarray.h:82
FloatMatrix()
Creates zero sized matrix.
Definition: floatmatrix.h:112
Implementation of matrix containing floating point numbers.
Definition: floatmatrix.h:94
double & operator()(int i, int j)
Coefficient access function.
Definition: floatmatrix.h:199
std::vector< double > values
Values of matrix stored column wise.
Definition: floatmatrix.h:102
FloatMatrix(const FloatMatrix &mat)
Copy constructor.
Definition: floatmatrix.h:123
FloatMatrix(int n, int m)
Creates matrix of given size.
Definition: floatmatrix.h:110
the oofem namespace is to define a context or scope in which all oofem names are defined.
void clear()
Sets size of receiver to be an empty matrix. It will have zero rows and zero columns size...
Definition: floatmatrix.h:516
int giveNumberOfRows() const
Returns number of rows of receiver.
Definition: floatmatrix.h:156
FloatMatrix(FloatMatrix &&mat)
Copy constructor.
Definition: floatmatrix.h:125

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:28 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011