OOFEM 3.0
Loading...
Searching...
No Matches
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 - 2025 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#ifndef flotmtrx_h
36#define flotmtrx_h
37
38#include "oofemenv.h"
39#include "contextioresulttype.h"
40#include "contextmode.h"
41#include "numerics.h"
42
43#include <vector>
44#include <iosfwd>
45#include <initializer_list>
46#include <algorithm>
47#include <string>
48
49namespace oofem {
50class FloatArray;
51template<std::size_t N> class FloatArrayF;
52template<std::size_t M, std::size_t N> class FloatMatrixF;
53class IntArray;
54class DataStream;
55
82
84#ifdef _USE_EIGEN
85 : public MatrixXXd
86#endif
87{
88#ifdef _USE_EIGEN
89 public:
90 OOFEM_EIGEN_DERIVED(FloatMatrix,MatrixXXd);
91 FloatMatrix(int r, int c): MatrixXXd(r,c) {}
92#else
93protected:
95 std::size_t nRows;
97 std::size_t nColumns;
99 std :: vector< double >values;
100
101public:
102 constexpr static int Dim = 2;
103 typedef double Scalar;
109 FloatMatrix(std::size_t n, std::size_t m) : nRows(n), nColumns(m), values(n * m) {}
115 FloatMatrix(FloatMatrix && mat) noexcept : nRows(mat.nRows), nColumns(mat.nColumns), values( std :: move(mat.values) ) {}
118 nRows = mat.nRows;
119 nColumns = mat.nColumns;
120 values = mat.values;
121 return * this;
122 }
124 nRows = std :: move(mat.nRows);
125 nColumns = std :: move(mat.nColumns);
126 values = std :: move(mat.values);
127 return * this;
128 }
129 inline int rows() const { return (int)nRows; }
130 inline int cols() const { return (int)nColumns; }
131
138 inline double &operator()(std::size_t i, std::size_t j)
139 {
140 #ifndef NDEBUG
141 this->checkBounds(i + 1, j + 1);
142 #endif
143 return values [ j * nRows + i ];
144 }
145
150 inline double operator()(std::size_t i, std::size_t j) const
151 {
152 #ifndef NDEBUG
153 this->checkBounds(i + 1, j + 1);
154 #endif
155 return values [ j * nRows + i ];
156 }
157 inline const double *data() const { return values.data(); }
158 inline double *data() { return values.data(); }
159#endif
160
161 template<std::size_t N, std::size_t M>
163 resize(N,M); // FIXME: useless 0-write
164 for(Index c=0; c<cols(); c++) for(Index r=0; r<rows(); r++) (*this)(r,c)=mat(r,c);
165 }
166
167 void _resize_internal(int nr, int nc);
168 FloatMatrix(std :: initializer_list< std :: initializer_list< double > > ini){ (*this)=FloatMatrix::fromIniList(ini); }
169 FloatMatrix &operator=(std :: initializer_list< std :: initializer_list< double > >mat){ (*this)=fromIniList(mat); return *this; }
170 static FloatMatrix fromIniList(std :: initializer_list< std :: initializer_list< double > >);
171 static FloatMatrix fromCols(std :: initializer_list< FloatArray >mat);
172 template<std::size_t M, std::size_t N>
174
183 static FloatMatrix fromArray(const FloatArray &vector, bool transpose = false);
184
185 template<std::size_t N, std::size_t M>
187 this->assignFloatMatrixF(mat);
188 return *this;
189 }
190
197 void checkBounds(Index i, Index j) const;
199 //[[deprecated("use rows() instead")]]
200 inline int giveNumberOfRows() const { return rows(); }
202 //[[deprecated("use cols() instead")]]
203 inline int giveNumberOfColumns() const { return cols(); }
204
205
206
208 inline bool isSquare() const { return rows() == cols(); }
210 inline bool isNotEmpty() const { return rows() > 0 && cols() > 0; }
211
213 bool isAllFinite() const;
214
221 inline double at(std::size_t i, std::size_t j) const
222 {
223 return (*this)(i-1,j-1);
224 }
225
231 inline double &at(std::size_t i, std::size_t j)
232 {
233 return (*this)(i-1,j-1);
234 }
235
241 void assemble(const FloatMatrix &src, const IntArray &loc);
249 void assemble(const FloatMatrix &src, const IntArray &rowind, const IntArray &colind);
257 void assembleT(const FloatMatrix &src, const IntArray &rowind, const IntArray &colind);
258
264 double computeFrobeniusNorm() const;
270 double computeNorm(char p) const;
278 double computeReciprocalCondition(char p = '1') const;
279 /*
280 * Computes the eigenvalues of a symmetric matrix.
281 * The receiver must be square and symmetric.
282 * @param lambda Eigenvalues.
283 * @param v Eigenvectors (stored column wise).
284 * @param neigs If set, only neigs largest eigenvalues are computed.
285 * @return True if successful.
286 */
287 //bool computeEigenValuesSymmetric(FloatArray &lambda, FloatMatrix &v, int neigs = 0) const;
292 void beDiagonal(const FloatArray &diag);
297 double giveTrace() const;
302 double giveDeterminant() const;
303
305 void zero();
307 void beUnitMatrix();
309 void bePinvID();
314 void beTranspositionOf(const FloatMatrix &src);
319 void beProductOf(const FloatMatrix &a, const FloatMatrix &b);
323 void addProductOf(const FloatMatrix &a, const FloatMatrix &b);
327 void addTProductOf(const FloatMatrix &a, const FloatMatrix &b);
332 void beTProductOf(const FloatMatrix &a, const FloatMatrix &b);
337 void beProductTOf(const FloatMatrix &a, const FloatMatrix &b);
342 void beDyadicProductOf(const FloatArray &vec1, const FloatArray &vec2);
348 void beNMatrixOf(const FloatArray &n, int nsd);
354 void beLocalCoordSys(const FloatArray &normal);
363 void setSubMatrix(const FloatMatrix &src, int sr, int sc);
371 void setTSubMatrix(const FloatMatrix &src, int sr, int sc);
380 void beSubMatrixOf(const FloatMatrix &src, Index topRow, Index bottomRow, Index topCol, Index bottomCol);
387 void beSubMatrixOf(const FloatMatrix &src, const IntArray &indxRow, const IntArray &indxCol);
394 void addSubVectorRow(const FloatArray &src, int sr, int sc);
401 void addSubVectorCol(const FloatArray &src, int sr, int sc);
402
409 void copySubVectorRow(const FloatArray &src, int sr, int sc);
415 void setColumn(const FloatArray &src, int c);
421 void copyColumn(FloatArray &dest, int c) const;
427 bool beInverseOf(const FloatMatrix &src);
435 bool solveForRhs(const FloatArray &b, FloatArray &answer, bool transpose = false);
442 bool solveForRhs(const FloatMatrix &B, FloatMatrix &answer, bool transpose = false);
451 void plusProductSymmUpper(const FloatMatrix &a, const FloatMatrix &b, double dV);
458 void plusDyadSymmUpper(const FloatArray &a, double dV);
465 void plusProductUnsym(const FloatMatrix &a, const FloatMatrix &b, double dV);
472 void plusDyadUnsym(const FloatArray &a, const FloatArray &b, double dV);
473
482 void plus_Nt_a_otimes_b_B(const FloatMatrix &N, const FloatArray &a, const FloatArray &b, const FloatMatrix &B, double dV = 1);
483
489 void add(const FloatMatrix &a);
496 void add(double s, const FloatMatrix &a);
501 void subtract(const FloatMatrix &a);
506 void times(double f);
510 void negated();
514 void symmetrized();
521 void rotatedWith(const FloatMatrix &r, char mode = 'n');
522 #ifndef _USE_EIGEN
530 void resize(Index rows, Index cols);
531 #endif
537 void resizeWithData(Index, Index);
538
540 void clear() { resize(0,0); }
549 bool jaco_(FloatArray &eval, FloatMatrix &v, int nf);
550
552 void printYourself() const;
557 void printYourself(const std::string &name) const;
558
564 void printYourselfToFile(const std::string filename, const bool showDimensions=true) const;
565
567 void pY() const;
568
573 void writeCSV(const std :: string &name) const;
574
579 inline const double *givePointer() const { return data(); }
580 inline double *givePointer() { return data(); }
581
588 void beMatrixFormOfStress(const FloatArray &aArray);
589 void beMatrixForm(const FloatArray &aArray);
590
596 void changeComponentOrder();
597
598 // Overloaded methods:
599 contextIOResultType storeYourself(DataStream &stream) const;
600 contextIOResultType restoreYourself(DataStream &stream);
601 int givePackSize(DataStream &buff) const;
602
603 friend std :: ostream &operator<<(std :: ostream &out, const FloatMatrix &r);
604
605}; // class FloatMatrix
606
607#ifndef _USE_EIGEN
608 //@name operators
610
611 OOFEM_EXPORT FloatMatrix &operator *= ( FloatMatrix & x, const double & a );
612 OOFEM_EXPORT FloatMatrix operator * ( const FloatMatrix & x, const double & a );
613 OOFEM_EXPORT FloatMatrix operator * ( const double & a, const FloatMatrix & x);
614 OOFEM_EXPORT FloatMatrix operator *( const FloatMatrix & a, const FloatMatrix & b ) ;
615 OOFEM_EXPORT FloatArray operator *( const FloatMatrix & a, const FloatArray & b ) ;
616 OOFEM_EXPORT FloatMatrix operator +( const FloatMatrix & a, const FloatMatrix & b ) ;
617 OOFEM_EXPORT FloatMatrix operator -( const FloatMatrix & a, const FloatMatrix & b ) ;
618 OOFEM_EXPORT FloatMatrix &operator += ( FloatMatrix & a, const FloatMatrix & b ) ;
619 OOFEM_EXPORT FloatMatrix &operator -= ( FloatMatrix & a, const FloatMatrix & b ) ;
621#endif
622
623
624} // end namespace oofem
625#endif // flotmtrx_h
#define N(a, b)
double operator()(std::size_t i, std::size_t j) const
FloatMatrix(std ::initializer_list< std ::initializer_list< double > > ini)
const double * givePointer() const
FloatMatrix(FloatMatrix &&mat) noexcept
Copy constructor.
FloatMatrix & operator=(std ::initializer_list< std ::initializer_list< double > >mat)
double * givePointer()
std::size_t nRows
Number of rows.
Definition floatmatrix.h:95
std ::vector< double > values
Values of matrix stored column wise.
Definition floatmatrix.h:99
double & at(std::size_t i, std::size_t j)
static FloatMatrix fromIniList(std ::initializer_list< std ::initializer_list< double > >)
std::size_t nColumns
Number of columns.
Definition floatmatrix.h:97
void resize(Index rows, Index cols)
Definition floatmatrix.C:79
*Sets size of receiver to be an empty matrix It will have zero rows and zero columns size void clear()
FloatMatrix & operator=(FloatMatrix &&mat) noexcept
const double * data() const
void checkBounds(Index i, Index j) const
int giveNumberOfColumns() const
Returns number of columns of receiver.
FloatMatrix & operator=(const FloatMatrix &mat)
Assignment operator, adjusts size of the receiver if necessary.
FloatMatrix()
Creates zero sized matrix.
double & operator()(std::size_t i, std::size_t j)
void assignFloatMatrixF(const FloatMatrixF< N, M > &mat)
bool isNotEmpty() const
Tests for empty matrix.
FloatMatrix & operator=(const FloatMatrixF< N, M > &mat)
FloatMatrix(const FloatMatrix &mat)
Copy constructor.
int giveNumberOfRows() const
Returns number of rows of receiver.
static constexpr int Dim
double at(std::size_t i, std::size_t j) const
FloatMatrix(const FloatMatrixF< N, M > &src)
bool isSquare() const
Returns nonzero if receiver is square matrix.
FloatMatrix(std::size_t n, std::size_t m)
FloatArray operator+(const FloatArray &x, const FloatArray &y)
Definition floatarray.C:978
FloatMatrixF< M, N > transpose(const FloatMatrixF< N, M > &mat)
Constructs transposed matrix.
FloatArray operator-(const FloatArray &x, const FloatArray &y)
Definition floatarray.C:985
FloatArrayF< N > assemble(const FloatArrayF< M > &x, int const (&c)[M])
Assemble components into zero matrix.
FloatArray & operator+=(FloatArray &x, const FloatArray &y)
Definition floatarray.C:992
std::ostream & operator<<(std ::ostream &out, const Dictionary &r)
Definition dictionary.C:247
int Index
Definition numerics.h:73
FloatMatrixF< N, N > diag(const FloatArrayF< N > &v)
FloatMatrixF< N, M > zero()
Constructs a zero matrix (this is the default behavior when constructing a matrix,...
FloatArray & operator-=(FloatArray &x, const FloatArray &y)
Definition floatarray.C:998
FloatArray operator*(const double &a, const FloatArray &x)
Definition floatarray.C:964
FloatArray & operator*=(FloatArray &x, const double &a)
Vector multiplication by scalar.
Definition floatarray.C:958
#define OOFEM_EXPORT
Definition oofemcfg.h:7

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011