55 #define RESIZE(nr, nc) \ 57 this->nRows = nr; this->nColumns = nc; \ 58 int nsize = this->nRows * this->nColumns; \ 59 if ( nsize < ( int ) this->values.size() ) { \ 60 this->values.resize(nsize); \ 61 } else if ( nsize > ( int ) this->values.size() ) { \ 62 this->values.assign(nsize, 0.); \ 67 #include <boost/python.hpp> 68 #include <boost/python/extract.hpp> 72 #ifdef __LAPACK_MODULE 75 extern void dgecon_(
const char *
norm,
const int *n,
const double *a,
const int *lda,
76 const double *anorm,
double *rcond,
double *work,
int *iwork,
int *info,
int norm_len);
78 extern int dgetrf_(
const int *m,
const int *n,
double *a,
const int *lda,
int *lpiv,
int *info);
80 extern int dgetri_(
const int *n,
double *a,
const int *lda,
int *ipiv,
double *work,
const int *lwork,
int *info);
82 extern int dgesv_(
const int *n,
const int *nrhs,
double *a,
const int *lda,
int *ipiv,
const double *b,
const int *ldb,
int *info);
84 extern double dlange_(
const char *norm,
const int *m,
const int *n,
const double *a,
const int *lda,
double *work,
int norm_len);
86 extern int dsyevx_(
const char *jobz,
const char *range,
const char *uplo,
const int *n,
double *a,
const int *lda,
87 const double *vl,
const double *vu,
const int *il,
const int *iu,
88 const double *abstol,
int *m,
double *w,
double *z,
const int *ldz,
89 double *work,
int *lwork,
int *iwork,
int *ifail,
int *info,
90 int jobz_len,
int range_len,
int uplo_len);
92 extern void dgetrs_(
const char *trans,
const int *n,
const int *nrhs,
double *a,
const int *lda,
int *ipiv,
const double *b,
const int *ldb,
int *info);
94 extern void dgemm_(
const char *transa,
const char *transb,
const int *m,
const int *n,
const int *k,
const double *alpha,
95 const double *a,
const int *lda,
const double *b,
const int *ldb,
const double *beta,
double *c,
const int *ldc,
96 int a_columns,
int b_columns,
int c_columns);
98 extern void dger_(
const int *m,
const int *n,
const double *alpha,
const double *x,
const int *incx,
99 const double *y,
const int *incy,
double *a,
const int *lda,
100 int x_len,
int y_len,
int a_columns);
102 extern void dsyr_(
const char *uplo,
const int *n,
const double *alpha,
const double *x,
const int *incx,
103 double *a,
const int *lda,
int x_len,
int a_columns);
105 extern void daxpy_(
const int *n,
const double *alpha,
const double *x,
const int *incx,
double *y,
const int *incy,
int xsize,
int ysize);
107 extern void dscal_(
const int *n,
const double *alpha,
const double *x,
const int *incx,
int size);
133 RESIZE( mat.size(), mat.begin()->size() )
134 auto p = this->
values.begin();
135 for (
auto col : mat ) {
137 if ( this->
nRows != (
int ) col.size() ) {
138 OOFEM_ERROR(
"Initializer list has inconsistent column sizes.");
141 for (
auto x : col ) {
151 RESIZE( (
int ) mat.begin()->size(), ( int ) mat.size() );
152 auto p = this->
values.begin();
153 for (
auto col : mat ) {
155 if ( this->
nRows != (
int ) col.size() ) {
156 OOFEM_ERROR(
"Initializer list has inconsistent column sizes.");
159 for (
auto x : col ) {
171 RESIZE( mat.begin()->giveSize(), ( int ) mat.size() );
172 auto p = this->
values.begin();
173 for (
auto col : mat ) {
175 if ( this->
nRows != col.giveSize() ) {
176 OOFEM_ERROR(
"Initializer list has inconsistent column sizes.");
179 for (
auto x : col ) {
196 OOFEM_ERROR(
"matrix error on columns : %d < 0", j);
211 for (
double val :
values) {
212 if ( !std::isfinite(val) ) {
257 OOFEM_ERROR(
"dimensions of 'src' and 'loc' mismatch");
265 for (
int i = 1; i <= size; i++ ) {
266 if ( ( ii = loc.
at(i) ) ) {
267 for (
int j = 1; j <= size; j++ ) {
268 if ( ( jj = loc.
at(j) ) ) {
269 this->
at(ii, jj) += src.
at(i, j);
285 OOFEM_ERROR(
"row dimensions of 'src' and 'rowind' mismatch");
289 OOFEM_ERROR(
"column dimensions of 'src' and 'colind' mismatch");
293 for (
int i = 1; i <= nr; i++ ) {
294 if ( ( ii = rowind.
at(i) ) ) {
295 for (
int j = 1; j <= nc; j++ ) {
296 if ( ( jj = colind.
at(j) ) ) {
297 this->
at(ii, jj) += src.
at(i, j);
311 for (
int i = 1; i <= nr; i++ ) {
312 if ( ( ii = rowind [ i - 1 ] ) ) {
313 for (
int j = 1; j <= nc; j++ ) {
314 if ( ( jj = colind [ j - 1 ] ) ) {
315 this->
at(ii, jj) += src.
at(i, j);
329 for (
int i = 1; i <= nrows; i++ ) {
330 for (
int j = 1; j <= ncols; j++ ) {
331 this->
at(i, j) = src.
at(j, i);
342 OOFEM_ERROR(
"error in product A*B : dimensions do not match");
346 # ifdef __LAPACK_MODULE 347 double alpha = 1., beta = 0.;
353 for (
int i = 1; i <= aMatrix.
nRows; i++ ) {
354 for (
int j = 1; j <= bMatrix.
nColumns; j++ ) {
356 for (
int k = 1; k <= aMatrix.
nColumns; k++ ) {
357 coeff += aMatrix.
at(i, k) * bMatrix.
at(k, j);
360 this->
at(i, j) = coeff;
372 OOFEM_ERROR(
"error in product A*B : dimensions do not match");
376 # ifdef __LAPACK_MODULE 377 double alpha = 1., beta = 0.;
383 for (
int i = 1; i <= aMatrix.
nColumns; i++ ) {
384 for (
int j = 1; j <= bMatrix.
nColumns; j++ ) {
386 for (
int k = 1; k <= aMatrix.
nRows; k++ ) {
387 coeff += aMatrix.
at(k, i) * bMatrix.
at(k, j);
390 this->
at(i, j) = coeff;
402 OOFEM_ERROR(
"error in product A*B : dimensions do not match");
406 # ifdef __LAPACK_MODULE 407 double alpha = 1., beta = 0.;
413 for (
int i = 1; i <= aMatrix.
nRows; i++ ) {
414 for (
int j = 1; j <= bMatrix.
nRows; j++ ) {
416 for (
int k = 1; k <= aMatrix.
nColumns; k++ ) {
417 coeff += aMatrix.
at(i, k) * bMatrix.
at(j, k);
420 this->
at(i, j) = coeff;
432 OOFEM_ERROR(
"error in product A*B : dimensions do not match");
434 if ( aMatrix.
nRows != this->nRows || bMatrix.
nColumns != this->nColumns ) {
435 OOFEM_ERROR(
"error in product receiver : dimensions do not match");
439 # ifdef __LAPACK_MODULE 440 double alpha = 1., beta = 1.;
446 for (
int i = 1; i <= aMatrix.
nRows; i++ ) {
447 for (
int j = 1; j <= bMatrix.
nColumns; j++ ) {
449 for (
int k = 1; k <= aMatrix.
nColumns; k++ ) {
450 coeff += aMatrix.
at(i, k) * bMatrix.
at(k, j);
453 this->
at(i, j) += coeff;
464 OOFEM_ERROR(
"error in product A*B : dimensions do not match");
466 if ( aMatrix.
nColumns != this->nColumns || bMatrix.
nColumns != this->nRows ) {
467 OOFEM_ERROR(
"error in product receiver : dimensions do not match");
471 # ifdef __LAPACK_MODULE 472 double alpha = 1., beta = 1.;
478 for (
int i = 1; i <= aMatrix.
nColumns; i++ ) {
479 for (
int j = 1; j <= bMatrix.
nColumns; j++ ) {
481 for (
int k = 1; k <= aMatrix.
nRows; k++ ) {
482 coeff += aMatrix.
at(k, i) * bMatrix.
at(k, j);
485 this->
at(i, j) += coeff;
498 for (
int j = 1; j <= n2; j++ ) {
499 for (
int i = 1; i <= n1; i++ ) {
500 this->
at(i, j) = vec1.
at(i) * vec2.
at(j);
508 for (
int i = 0; i < n.
giveSize(); ++i ) {
509 for (
int j = 0; j < nsd; ++j ) {
510 ( * this )( j, i * nsd + j ) = n(i);
519 this->
at(1, 1) = normal(0);
520 }
else if ( normal.
giveSize() == 2 ) {
522 this->
at(1, 1) = normal(0);
523 this->
at(1, 2) = normal(1);
525 this->
at(2, 1) = normal(1);
526 this->
at(2, 2) = -normal(0);
528 }
else if ( normal.
giveSize() == 3 ) {
531 normal(1), -normal(2), normal(0)
541 this->
at(1, 1) = normal.
at(1);
542 this->
at(1, 2) = normal.
at(2);
543 this->
at(1, 3) = normal.
at(3);
545 this->
at(2, 1) = b.
at(1);
546 this->
at(2, 2) = b.
at(2);
547 this->
at(2, 3) = b.
at(3);
549 this->
at(3, 1) = t.
at(1);
550 this->
at(3, 2) = t.
at(2);
551 this->
at(3, 3) = t.
at(3);
564 int nr = sr + srcRows;
565 int nc = sc + srcCols;
568 OOFEM_ERROR(
"Sub matrix doesn't fit inside allocated space.");
573 for (
int j = 0; j < srcCols; j++ ) {
574 for (
int i = 0; i < srcRows; i++ ) {
575 ( * this )( sr + i, sc + j ) = src(i, j);
589 int nr = sr + srcCols;
590 int nc = sc + srcRows;
593 OOFEM_ERROR(
"Sub matrix doesn't fit inside allocated space");
598 for (
int i = 0; i < srcCols; i++ ) {
599 for (
int j = 0; j < srcRows; j++ ) {
600 ( * this )( sr + i, sc + j ) = src(j, i);
614 int nc = sc + srcCols;
621 for (
int j = 1; j <= srcCols; j++ ) {
622 this->
at(sr, sc + j) += src.
at(j);
633 int nr = sr + srcRows;
641 for (
int j = 1; j <= srcRows; j++ ) {
642 this->
at(sr + j, sc) += src.
at(j);
657 auto P = this->
values.begin() + ( c - 1 ) * nr;
658 std :: copy(src.
begin(), src.
end(), P);
672 auto P = this->
values.begin() + ( c - 1 ) * nr;
673 std :: copy( P, P + nr, dest.
begin() );
684 int nc = sc + srcCols;
691 for (
int j = 1; j <= srcCols; j++ ) {
692 this->
at(sr, sc + j) = src.
at(j);
712 #ifdef __LAPACK_MODULE 716 if ( this->
nRows < 20 ) {
718 int s1 = this->
nRows / 2;
719 int s2 = this->
nRows - s1;
721 dgemm_(
"t",
"n", & s1, & s1, & a.
nRows, & dV, a.
givePointer(), & a.
nRows, b.
givePointer(), & b.
nRows, & beta, this->
givePointer(), & this->
nRows, a.
nColumns, b.
nColumns, this->
nColumns);
723 dgemm_(
"t",
"n", & this->nRows, & s2, & a.
nRows, & dV, a.
givePointer(), & a.
nRows, & b.
givePointer() [ s1 * b.
nRows ], & b.
nRows, & beta, & this->
givePointer() [ s1 * this->
nRows ], & this->
nRows, a.
nColumns, b.
nColumns, this->
nColumns);
727 int block = ( this->
nRows - 1 ) / ( this->
nRows / 10 ) + 1;
730 while ( start < this->
nRows ) {
732 dgemm_(
"t",
"n", & end, & s, & a.
nRows, & dV, a.
givePointer(), & a.
nRows, & b.
givePointer() [ start * b.
nRows ], & b.
nRows, & beta, & this->
givePointer() [ start * this->
nRows ],
736 if ( end > this->nRows ) {
742 for (
int i = 1; i <=
nRows; i++ ) {
743 for (
int j = i; j <=
nColumns; j++ ) {
745 for (
int k = 1; k <= a.
nRows; k++ ) {
746 summ += a.
at(k, i) * b.
at(k, j);
749 this->
at(i, j) += summ * dV;
763 #ifdef __LAPACK_MODULE 770 for (
int i = 1; i <=
nRows; i++ ) {
771 for (
int j = i; j <=
nColumns; j++ ) {
772 this->
at(i, j) += a.
at(i) * a.
at(j) * dV;
790 #ifdef __LAPACK_MODULE 797 for (
int i = 1; i <=
nRows; i++ ) {
798 for (
int j = 1; j <=
nColumns; j++ ) {
800 for (
int k = 1; k <= a.
nRows; k++ ) {
801 summ += a.
at(k, i) * b.
at(k, j);
804 this->
at(i, j) += summ * dV;
818 #ifdef __LAPACK_MODULE 822 dger_(& sizeA, & sizeB, & dV, a.
givePointer(), & inc,
826 for (
int i = 1; i <=
nRows; i++ ) {
827 for (
int j = 1; j <=
nColumns; j++ ) {
828 this->
at(i, j) += a.
at(i) * b.
at(j) * dV;
849 this->
at(1, 1) = 1. / src.
at(1, 1);
851 }
else if (
nRows == 2 ) {
852 det = src.
at(1, 1) * src.
at(2, 2) - src.
at(1, 2) * src.
at(2, 1);
853 this->
at(1, 1) = src.
at(2, 2) / det;
854 this->
at(2, 1) = -src.
at(2, 1) / det;
855 this->
at(1, 2) = -src.
at(1, 2) / det;
856 this->
at(2, 2) = src.
at(1, 1) / det;
858 }
else if (
nRows == 3 ) {
859 det = src.
at(1, 1) * src.
at(2, 2) * src.
at(3, 3) + src.
at(1, 2) * src.
at(2, 3) * src.
at(3, 1) +
860 src.
at(1, 3) * src.
at(2, 1) * src.
at(3, 2) - src.
at(1, 3) * src.
at(2, 2) * src.
at(3, 1) -
861 src.
at(2, 3) * src.
at(3, 2) * src.
at(1, 1) - src.
at(3, 3) * src.
at(1, 2) * src.
at(2, 1);
863 this->
at(1, 1) = ( src.
at(2, 2) * src.
at(3, 3) - src.
at(2, 3) * src.
at(3, 2) ) / det;
864 this->
at(2, 1) = ( src.
at(2, 3) * src.
at(3, 1) - src.
at(2, 1) * src.
at(3, 3) ) / det;
865 this->
at(3, 1) = ( src.
at(2, 1) * src.
at(3, 2) - src.
at(2, 2) * src.
at(3, 1) ) / det;
866 this->
at(1, 2) = ( src.
at(1, 3) * src.
at(3, 2) - src.
at(1, 2) * src.
at(3, 3) ) / det;
867 this->
at(2, 2) = ( src.
at(1, 1) * src.
at(3, 3) - src.
at(1, 3) * src.
at(3, 1) ) / det;
868 this->
at(3, 2) = ( src.
at(1, 2) * src.
at(3, 1) - src.
at(1, 1) * src.
at(3, 2) ) / det;
869 this->
at(1, 3) = ( src.
at(1, 2) * src.
at(2, 3) - src.
at(1, 3) * src.
at(2, 2) ) / det;
870 this->
at(2, 3) = ( src.
at(1, 3) * src.
at(2, 1) - src.
at(1, 1) * src.
at(2, 3) ) / det;
871 this->
at(3, 3) = ( src.
at(1, 1) * src.
at(2, 2) - src.
at(1, 2) * src.
at(2, 1) ) / det;
884 #ifdef __LAPACK_MODULE 902 }
else if ( info < 0 ) {
912 for (
int i = 1; i <=
nRows; i++ ) {
913 this->
at(i, i) = 1.0;
917 for (
int i = 1; i <
nRows; i++ ) {
919 if ( fabs(piv) < 1.e-24 ) {
920 OOFEM_ERROR(
"pivot (%d,%d) to close to small (< 1.e-24)", i, i);
923 for (
int j = i + 1; j <=
nRows; j++ ) {
924 linkomb = tmp.
at(j, i) / tmp.
at(i, i);
925 for (
int k = i; k <=
nRows; k++ ) {
926 tmp.
at(j, k) -= tmp.
at(i, k) * linkomb;
929 for (
int k = 1; k <=
nRows; k++ ) {
930 this->
at(j, k) -= this->
at(i, k) * linkomb;
936 for (
int i = nRows; i > 1; i-- ) {
938 for (
int j = i - 1; j > 0; j-- ) {
939 linkomb = tmp.
at(j, i) / piv;
940 for (
int k = i; k > 0; k-- ) {
941 tmp.
at(j, k) -= tmp.
at(i, k) * linkomb;
944 for (
int k = nRows; k > 0; k-- ) {
946 this->
at(j, k) -= this->
at(i, k) * linkomb;
952 for (
int i = 1; i <=
nRows; i++ ) {
953 for (
int j = 1; j <=
nRows; j++ ) {
954 this->
at(i, j) /= tmp.
at(i, i);
963 int topRow,
int bottomRow,
int topCol,
int bottomCol)
971 if ( ( topRow < 1 ) || ( bottomRow < 1 ) || ( topCol < 1 ) || ( bottomCol < 1 ) ) {
975 if ( ( src.
nRows < bottomRow ) || ( src.
nColumns < bottomCol ) || ( ( bottomRow - topRow ) > src.
nRows ) ||
976 ( ( bottomCol - topCol ) > src.
nColumns ) ) {
987 this->
resize(bottomRow - topRm1, bottomCol - topCm1);
988 for (
int i = topRow; i <= bottomRow; i++ ) {
989 for (
int j = topCol; j <= bottomCol; j++ ) {
990 this->
at(i - topRm1, j - topCm1) = src.
at(i, j);
1014 this->
resize(szRow, szCol);
1016 for (
int i = 1; i <= szRow; i++ ) {
1017 for (
int j = 1; j <= szCol; j++ ) {
1018 this->
at(i, j) = src.
at( indxRow.
at(i), indxCol.
at(j) );
1041 #ifdef __LAPACK_MODULE 1047 for (
size_t i = 0; i < this->
values.size(); i++ ) {
1073 #ifdef __LAPACK_MODULE 1078 for (
size_t i = 0; i < this->
values.size(); i++ ) {
1099 #ifdef __LAPACK_MODULE 1105 for (
size_t i = 0; i < this->
values.size(); i++ ) {
1125 #ifdef __LAPACK_MODULE 1139 double piv, linkomb, help;
1152 for (
int i = 1; i <
nRows; i++ ) {
1154 piv = fabs( mtrx->
at(i, i) );
1156 for (
int j = i + 1; j <=
nRows; j++ ) {
1157 if ( fabs( mtrx->
at(j, i) ) > piv ) {
1159 piv = fabs( mtrx->
at(j, i) );
1163 if ( piv < 1.e-20 ) {
1168 if ( pivRow != i ) {
1169 for (
int j = i; j <=
nRows; j++ ) {
1170 help = mtrx->
at(i, j);
1171 mtrx->
at(i, j) = mtrx->
at(pivRow, j);
1172 mtrx->
at(pivRow, j) = help;
1174 help = answer.
at(i);
1175 answer.
at(i) = answer.
at(pivRow);
1176 answer.
at(pivRow) = help;
1179 for (
int j = i + 1; j <=
nRows; j++ ) {
1180 linkomb = mtrx->
at(j, i) / mtrx->
at(i, i);
1181 for (
int k = i; k <=
nRows; k++ ) {
1182 mtrx->
at(j, k) -= mtrx->
at(i, k) * linkomb;
1185 answer.
at(j) -= answer.
at(i) * linkomb;
1190 for (
int i = nRows; i >= 1; i-- ) {
1192 for (
int j = i + 1; j <=
nRows; j++ ) {
1193 help += mtrx->
at(i, j) * answer.
at(j);
1196 answer.
at(i) = ( answer.
at(i) - help ) / mtrx->
at(i, i);
1221 #ifdef __LAPACK_MODULE 1234 double piv, linkomb, help;
1247 for (
int i = 1; i <
nRows; i++ ) {
1249 piv = fabs( mtrx->
at(i, i) );
1251 for (
int j = i + 1; j <=
nRows; j++ ) {
1252 if ( fabs( mtrx->
at(j, i) ) > piv ) {
1254 piv = fabs( mtrx->
at(j, i) );
1258 if ( fabs(piv) < 1.e-20 ) {
1263 if ( pivRow != i ) {
1264 for (
int j = i; j <=
nRows; j++ ) {
1265 help = mtrx->
at(i, j);
1266 mtrx->
at(i, j) = mtrx->
at(pivRow, j);
1267 mtrx->
at(pivRow, j) = help;
1270 for (
int j = 1; j <= nPs; j++ ) {
1271 help = answer.
at(i, j);
1272 answer.
at(i, j) = answer.
at(pivRow, j);
1273 answer.
at(pivRow, j) = help;
1277 if ( fabs(piv) < 1.e-20 ) {
1278 OOFEM_ERROR(
"cannot solve, zero pivot encountered");
1281 for (
int j = i + 1; j <=
nRows; j++ ) {
1282 linkomb = mtrx->
at(j, i) / mtrx->
at(i, i);
1283 for (
int k = i; k <=
nRows; k++ ) {
1284 mtrx->
at(j, k) -= mtrx->
at(i, k) * linkomb;
1287 for (
int k = 1; k <= nPs; k++ ) {
1288 answer.
at(j, k) -= answer.
at(i, k) * linkomb;
1294 for (
int i = nRows; i >= 1; i-- ) {
1295 for (
int k = 1; k <= nPs; k++ ) {
1297 for (
int j = i + 1; j <=
nRows; j++ ) {
1298 help += mtrx->
at(i, j) * answer.
at(j, k);
1301 answer.
at(i, k) = ( answer.
at(i, k) - help ) / mtrx->
at(i, i);
1328 std :: fill(this->
values.begin(), this->
values.end(), 0.);
1341 for (
int i = 1; i <=
nRows; i++ ) {
1342 this->
at(i, i) = 1.0;
1365 this->
values.assign(rows * columns, 0.);
1383 this->
values.resize(rows * columns);
1388 for (
int i = 1; i <= ii; i++ ) {
1389 for (
int j = 1; j <= jj; j++ ) {
1390 this->
at(i, j) = old.
at(i, j);
1403 values.assign(rows * columns, 0.);
1404 this->
values.shrink_to_fit();
1419 }
else if (
nRows == 2 ) {
1421 }
else if (
nRows == 3 ) {
1426 OOFEM_ERROR(
"sorry, cannot compute the determinant of a matrix larger than 3x3");
1437 for (
int i = 0; i < n; ++i ) {
1438 (*this)(i, i) = diag[i];
1451 for (
int k = 0; k <
nRows; k++ ) {
1452 answer +=
values [ k * ( nRows + 1 ) ];
1461 printf(
"FloatMatrix with dimensions : %d %d\n",
1464 for (
int i = 1; i <=
nRows; ++i ) {
1465 for (
int j = 1; j <=
nColumns && j <= 100; ++j ) {
1466 printf(
"%10.3e ", this->
at(i, j) );
1472 printf(
" large matrix : coefficients not printed \n");
1480 std :: ofstream matrixfile (filename);
1481 if (matrixfile.is_open()) {
1483 matrixfile <<
"FloatMatrix with dimensions : " <<
nRows <<
", " <<
nColumns <<
"\n";
1484 matrixfile << std::scientific << std::right << std::setprecision(3);
1485 for (
int i = 1; i <=
nRows; ++i ) {
1486 for (
int j = 1; j <=
nColumns; ++j ) {
1487 matrixfile << std::setw(10) << this->
at(i, j) <<
"\t";
1504 for (
int i = 1; i <=
nRows; ++i ) {
1505 for (
int j = 1; j <=
nColumns && j <= 100; ++j ) {
1506 printf(
"%10.3e ", this->
at(i, j) );
1512 for (
int i = 1; i <=
nRows && i <= 20; ++i ) {
1513 for (
int j = 1; j <=
nColumns && j <= 10; ++j ) {
1514 printf(
"%10.3e ", this->
at(i, j) );
1516 if (
nColumns > 10 ) printf(
" ...");
1519 if (
nRows > 20 ) printf(
" ...\n");
1528 for (
int i = 1; i <=
nRows; ++i ) {
1529 for (
int j = 1; j <=
nColumns; ++j ) {
1530 printf(
"%20.15e", this->
at(i, j) );
1545 FILE *file = fopen(name.c_str(),
"w");
1546 for (
int i = 1; i <=
nRows; ++i ) {
1547 for (
int j = 1; j <=
nColumns; ++j ) {
1548 fprintf(file,
"%10.3e, ", this->
at(i, j) );
1551 fprintf(file,
"\n");
1563 if ( mode ==
'n' ) {
1566 }
else if ( mode ==
't' ) {
1581 OOFEM_ERROR(
"cannot symmetrize a non-square matrix");
1586 for (
int i = 2; i <=
nRows; i++ ) {
1587 for (
int j = 1; j < i; j++ ) {
1588 this->
at(i, j) = this->
at(j, i);
1598 for (
double &x : this->
values ) {
1607 for (
double &x : this->
values ) {
1615 return sqrt( std :: inner_product(this->
values.begin(), this->
values.end(), this->
values.begin(), 0.) );
1620 # ifdef __LAPACK_MODULE 1628 double col_sum, max_col = 0.0;
1629 for (
int j = 1; j <= this->
nColumns; j++ ) {
1631 for (
int i = 1; i <= this->
nRows; i++ ) {
1632 col_sum += fabs( this->
at(i, j) );
1634 if ( col_sum > max_col ) {
1669 this->
at(1, 1) = aArray.
at(1);
1670 this->
at(2, 2) = aArray.
at(2);
1671 this->
at(3, 3) = aArray.
at(3);
1672 this->
at(2, 3) = aArray.
at(4);
1673 this->
at(1, 3) = aArray.
at(5);
1674 this->
at(1, 2) = aArray.
at(6);
1675 this->
at(3, 2) = aArray.
at(7);
1676 this->
at(3, 1) = aArray.
at(8);
1677 this->
at(2, 1) = aArray.
at(9);
1678 }
else if ( aArray.
giveSize() == 6 ) {
1679 this->
at(1, 1) = aArray.
at(1);
1680 this->
at(2, 2) = aArray.
at(2);
1681 this->
at(3, 3) = aArray.
at(3);
1682 this->
at(2, 3) = aArray.
at(4);
1683 this->
at(1, 3) = aArray.
at(5);
1684 this->
at(1, 2) = aArray.
at(6);
1685 this->
at(3, 2) = aArray.
at(4);
1686 this->
at(3, 1) = aArray.
at(5);
1687 this->
at(2, 1) = aArray.
at(6);
1703 std :: swap( this->
at(4, 1), this->
at(6, 1) );
1705 std :: swap( this->
at(4, 2), this->
at(6, 2) );
1707 std :: swap( this->
at(4, 3), this->
at(6, 3) );
1709 std :: swap( this->
at(1, 4), this->
at(1, 6) );
1710 std :: swap( this->
at(2, 4), this->
at(2, 6) );
1711 std :: swap( this->
at(3, 4), this->
at(3, 6) );
1712 std :: swap( this->
at(4, 4), this->
at(6, 6) );
1713 std :: swap( this->
at(5, 4), this->
at(5, 6) );
1714 std :: swap( this->
at(6, 4), this->
at(4, 6) );
1716 std :: swap( this->
at(4, 5), this->
at(6, 5) );
1720 const int abq2oo [ 9 ] = {
1721 1, 2, 3, 6, 5, 4, 7, 9, 8
1725 for (
int i = 1; i <= 9; i++ ) {
1726 for (
int j = 1; j <= 9; j++ ) {
1727 tmp.
at(i, j) = this->
at(abq2oo [ i - 1 ], abq2oo [ j - 1 ]);
1746 # ifdef __LAPACK_MODULE 1747 int n = this->
nRows;
1784 this->
at(1, 1) = aArray.
at(1);
1785 this->
at(2, 2) = aArray.
at(2);
1786 this->
at(3, 3) = aArray.
at(3);
1787 this->
at(2, 3) = aArray.
at(4);
1788 this->
at(1, 3) = aArray.
at(5);
1789 this->
at(1, 2) = aArray.
at(6);
1790 this->
at(3, 2) = aArray.
at(7);
1791 this->
at(3, 1) = aArray.
at(8);
1792 this->
at(2, 1) = aArray.
at(9);
1793 }
else if ( aArray.
giveSize() == 6 ) {
1794 this->
at(1, 1) = aArray.
at(1);
1795 this->
at(2, 2) = aArray.
at(2);
1796 this->
at(3, 3) = aArray.
at(3);
1797 this->
at(2, 3) = aArray.
at(4);
1798 this->
at(1, 3) = aArray.
at(5);
1799 this->
at(1, 2) = aArray.
at(6);
1800 this->
at(3, 2) = aArray.
at(4);
1801 this->
at(3, 1) = aArray.
at(5);
1802 this->
at(2, 1) = aArray.
at(6);
1807 bool FloatMatrix :: computeEigenValuesSymmetric(
FloatArray &lambda,
FloatMatrix &v,
int neigs)
const 1809 #ifdef __LAPACK_MODULE 1810 double abstol = 1.0;
1811 int lda, n, ldz, info, found, lwork;
1826 lwork = ( n + 3 ) * n;
1829 dsyevx_(
"N",
"I",
"U",
1831 NULL, NULL, & one, & neigs,
1835 dsyevx_(
"N",
"A",
"U",
1837 NULL, NULL, NULL, NULL,
1859 if ( !stream.write(
nRows) ) {
1868 if ( !stream.write(this->givePointer(),
nRows *
nColumns) ) {
1929 double ssum, aa, co, si, tt, tol, sum, aij, aji;
1930 int ite, i, j, k, ih;
1942 for ( i = 1; i <= neq; i++ ) {
1943 for ( j = i + 1; j <= neq; j++ ) {
1945 if ( fabs( this->
at(i, j) - this->
at(j, i) ) > 1.0e-6 ) {
1956 for ( i = 1; i <= neq; i++ ) {
1957 eval.
at(i) = this->
at(i, i);
1960 tol = pow(c_b2, nf);
1962 for ( i = 1; i <= neq; ++i ) {
1963 for ( j = 1; j <= neq; ++j ) {
1964 sum += fabs( this->
at(i, j) );
1980 for ( j = 2; j <= neq; ++j ) {
1982 for ( i = 1; i <= ih; ++i ) {
1983 if ( ( fabs( this->
at(i, j) ) / sum ) > tol ) {
1984 ssum += fabs( this->
at(i, j) );
1986 aa = atan2( this->
at(i, j) * 2.0, eval.
at(i) - eval.
at(j) ) / 2.0;
2012 for ( k = 1; k < i; ++k ) {
2013 tt = this->
at(k, i);
2014 this->
at(k, i) = co * tt + si *this->
at(k, j);
2015 this->
at(k, j) = -si * tt + co *this->
at(k, j);
2017 v.
at(k, i) = co * tt + si *v.
at(k, j);
2018 v.
at(k, j) = -si * tt + co *v.
at(k, j);
2023 eval.
at(i) = co * tt + si *this->
at(i, j);
2024 aij = -si * tt + co *this->
at(i, j);
2026 v.
at(i, i) = co * tt + si *v.
at(i, j);
2027 v.
at(i, j) = -si * tt + co *v.
at(i, j);
2029 for ( k = i + 1; k < j; ++k ) {
2030 tt = this->
at(i, k);
2031 this->
at(i, k) = co * tt + si *this->
at(k, j);
2032 this->
at(k, j) = -si * tt + co *this->
at(k, j);
2034 v.
at(k, i) = co * tt + si *v.
at(k, j);
2035 v.
at(k, j) = -si * tt + co *v.
at(k, j);
2039 tt = this->
at(i, j);
2040 aji = co * tt + si *eval.
at(j);
2041 eval.
at(j) = -si * tt + co *eval.
at(j);
2044 v.
at(j, i) = co * tt + si *v.
at(j, j);
2045 v.
at(j, j) = -si * tt + co *v.
at(j, j);
2047 for ( k = j + 1; k <= neq; ++k ) {
2048 tt = this->
at(i, k);
2049 this->
at(i, k) = co * tt + si *this->
at(j, k);
2050 this->
at(j, k) = -si * tt + co *this->
at(j, k);
2052 v.
at(k, i) = co * tt + si *v.
at(k, j);
2053 v.
at(k, j) = -si * tt + co *v.
at(k, j);
2057 eval.
at(i) = co * eval.
at(i) + si * aji;
2058 eval.
at(j) = -si * aij + co *eval.
at(j);
2059 this->
at(i, j) = 0.0;
2071 }
while ( fabs(ssum) / sum > tol );
2074 for ( i = 1; i <= neq; i++ ) {
2075 for ( j = i; j <= neq; j++ ) {
2076 this->
at(i, j) = this->
at(j, i);
2086 FloatMatrix :: __setitem__(boost :: python :: api :: object t,
double val)
2088 this->
at(boost :: python :: extract< int >(t [ 0 ]) + 1, boost :: python :: extract< int >(t [ 1 ]) + 1) = val;
2092 FloatMatrix :: __getitem__(boost :: python :: api :: object t)
2094 return this->
at(boost :: python :: extract< int >(t [ 0 ]) + 1, boost :: python :: extract< int >(t [ 1 ]) + 1);
2101 for (
int i = 0; i < x.
nRows; ++i ) {
2102 for (
int j = 0; j < x.
nColumns; ++j ) {
2103 out <<
" " << x(i, j);
double giveDeterminant() const
Returns the trace (sum of diagonal components) of the receiver.
double computeNorm(char p) const
Computes the operator norm of the receiver.
int giveNumberOfColumns() const
Returns number of columns of receiver.
void initFromVector(const FloatArray &vector, bool transposed)
Assigns to receiver one column or one row matrix containing vector.
void bePinvID()
Sets receiver to the inverse of scaling matrix P multiplied by the deviatoric projector ID...
void addTProductOf(const FloatMatrix &a, const FloatMatrix &b)
Adds to the receiver product of .
void beVectorProductOf(const FloatArray &v1, const FloatArray &v2)
Computes vector product (or cross product) of vectors given as parameters, , and stores the result in...
void writeCSV(const std::string &name) const
Writes receiver as CSV (comma seperated values)
bool solveForRhs(const FloatArray &b, FloatArray &answer, bool transpose=false)
Solves the system of linear equations .
std::vector< double > values
Stored values.
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
double & at(int i)
Coefficient access function.
int max(int i, int j)
Returns bigger value form two given decimals.
void beSubMatrixOf(const FloatMatrix &src, int topRow, int bottomRow, int topCol, int bottomCol)
Assigns to the receiver the sub-matrix of another matrix.
int minimum() const
Finds the minimum component in the array.
void pY() const
Higher accuracy than printYourself.
bool isFinite() const
Returns true if no element is NAN or infinite.
void beDiagonal(const FloatArray &diag)
Modifies receiver to be a diagonal matrix with the components specified in diag.
bool isSquare() const
Returns nonzero if receiver is square matrix.
void negated()
Changes sign of receiver values.
const int * givePointer() const
Breaks encapsulation.
const double * givePointer() const
Exposes the internal values of the matrix.
void plusDyadUnsym(const FloatArray &a, const FloatArray &b, double dV)
Adds to the receiver the product .
int givePackSize(DataStream &buff) const
void printYourselfToFile(const std::string filename, const bool showDimensions=true) const
Print matrix to file.
Class implementing an array of integers.
int & at(int i)
Coefficient access function.
virtual int read(int *data, int count)=0
Reads count integer values into array pointed by data.
double computeReciprocalCondition(char p= '1') const
Computes the conditioning of the receiver.
contextIOResultType storeYourself(DataStream &stream) const
int nColumns
Number of columns.
void setSubMatrix(const FloatMatrix &src, int sr, int sc)
Adds the given matrix as sub-matrix to receiver.
void beMatrixForm(const FloatArray &aArray)
bool isNotEmpty() const
Tests for empty matrix.
void plusProductUnsym(const FloatMatrix &a, const FloatMatrix &b, double dV)
Adds to the receiver the product .
bool jaco_(FloatArray &eval, FloatMatrix &v, int nf)
Computes eigenvalues and eigenvectors of receiver (must be symmetric) The receiver is preserved...
FloatMatrix & operator=(std::initializer_list< std::initializer_list< double > >mat)
Assignment operator.
void checkBounds(int i, int j) const
Checks size of receiver towards requested bounds.
double dotProduct(const FloatArray &x) const
Computes the dot product (or inner product) of receiver and argument.
double giveTrace() const
Returns the trace of the receiver.
void copySubVectorRow(const FloatArray &src, int sr, int sc)
Copy (set) given vector to receiver row sr, starting at column sc.
void resizeWithData(int, int)
Checks size of receiver towards requested bounds.
void times(double f)
Multiplies receiver by factor f.
void rotatedWith(const FloatMatrix &r, char mode= 'n')
Returns the receiver 'a' transformed using give transformation matrix r.
void addProductOf(const FloatMatrix &a, const FloatMatrix &b)
Adds to the receiver product of .
int maximum() const
Finds the maximum component in the array.
void beLocalCoordSys(const FloatArray &normal)
Makes receiver the local coordinate for the given normal.
void plusProductSymmUpper(const FloatMatrix &a, const FloatMatrix &b, double dV)
Adds to the receiver the product .
double at(int i, int j) const
Coefficient access function.
void beNMatrixOf(const FloatArray &n, int nsd)
Assigns the receiver to be a repeated diagonal matrix.
void subtract(const FloatMatrix &a)
Subtracts matrix from the receiver.
contextIOResultType restoreYourself(DataStream &stream)
Class representing vector of real numbers.
void plusDyadSymmUpper(const FloatArray &a, double dV)
Adds to the receiver the dyadic product .
FloatMatrix()
Creates zero sized matrix.
Implementation of matrix containing floating point numbers.
double & operator()(int i, int j)
Coefficient access function.
double computeFrobeniusNorm() const
Computes the Frobenius norm of the receiver.
virtual int givePackSizeOfDouble(int count)=0
void beMatrixFormOfStress(const FloatArray &aArray)
Reciever will be a 3x3 matrix formed from a vector with either 9 or 6 components. ...
void changeComponentOrder()
Swaps the indices in the 6x6 matrix such that it converts between OOFEM's and Abaqus' way of writing ...
void addSubVectorCol(const FloatArray &src, int sr, int sc)
Adds given vector to receiver starting at given position.
double norm(const FloatArray &x)
void resize(int rows, int cols)
Checks size of receiver towards requested bounds.
void add(const FloatMatrix &a)
Adds matrix to the receiver.
void beDyadicProductOf(const FloatArray &vec1, const FloatArray &vec2)
Assigns to the receiver the dyadic product .
void copyColumn(FloatArray &dest, int c) const
Fetches the values from the specified column.
void beTProductOf(const FloatMatrix &a, const FloatMatrix &b)
Assigns to the receiver product of .
void setColumn(const FloatArray &src, int c)
Sets the values of the matrix in specified column.
void beTranspositionOf(const FloatMatrix &src)
Assigns to the receiver the transposition of parameter.
const double * givePointer() const
Gives the pointer to the raw data, breaking encapsulation.
void printYourself() const
Prints matrix to stdout. Useful for debugging.
std::vector< double >::iterator end()
void beProductTOf(const FloatMatrix &a, const FloatMatrix &b)
Assigns to the receiver product of .
void zero()
Zeroes all coefficient of receiver.
std::vector< double > values
Values of matrix stored column wise.
int min(int i, int j)
Returns smaller value from two given decimals.
void beUnitMatrix()
Sets receiver to unity matrix.
void hardResize(int r, int c)
Resizing that enforces reallocation of memory.
void setTSubMatrix(const FloatMatrix &src, int sr, int sc)
Adds the given matrix as sub-matrix to receiver.
void beProductOf(const FloatMatrix &a, const FloatMatrix &b)
Assigns to the receiver product of .
int giveSize() const
Returns the size of receiver.
the oofem namespace is to define a context or scope in which all oofem names are defined.
void assemble(const FloatMatrix &src, const IntArray &loc)
Assembles the contribution using localization array into receiver.
friend std::ostream & operator<<(std::ostream &out, const FloatMatrix &r)
void beInverseOf(const FloatMatrix &src)
Modifies receiver to become inverse of given parameter.
double normalize()
Normalizes receiver.
int giveNumberOfRows() const
Returns number of rows of receiver.
void addSubVectorRow(const FloatArray &src, int sr, int sc)
Adds given vector to receiver starting at given position.
void symmetrized()
Initializes the lower half of the receiver according to the upper half.
void add(const FloatArray &src)
Adds array src to receiver.
std::vector< double >::iterator begin()
void resize(int s)
Resizes receiver towards requested size.
virtual int givePackSizeOfInt(int count)=0