16#ifndef dealii_tensor_product_matrix_h
17#define dealii_tensor_product_matrix_h
112template <
int dim,
typename Number,
int n_rows_1d = -1>
137 template <
typename T>
158 template <
typename T>
261 template <
typename Number>
270 std::pair<std::bitset<width>,
280 const auto &M_0 = left.second.first;
281 const auto &K_0 = left.second.second;
282 const auto &M_1 = right.second.first;
283 const auto &K_1 = right.second.second;
285 std::bitset<width>
mask;
287 for (
unsigned int v = 0; v <
width; ++v)
288 mask[v] = left.first[v] && right.first[v];
293 if (comparator(M_0, M_1))
295 else if (comparator(M_1, M_0))
297 else if (comparator(K_0, K_1))
334template <
int dim,
typename Number,
int n_rows_1d = -1>
340 std::bitset<::internal::VectorizedArrayTrait<Number>::width()>,
384 template <
typename T>
386 insert(
const unsigned int index,
const T &Ms,
const T &Ks);
514 template <
typename Number>
516 spectral_assembly(
const Number * mass_matrix,
517 const Number * derivative_matrix,
518 const unsigned int n_rows,
519 const unsigned int n_cols,
525 std::vector<bool> constrained_dofs(n_rows,
false);
527 for (
unsigned int i = 0; i < n_rows; ++i)
529 if (mass_matrix[i + i * n_rows] == 0.0)
531 Assert(derivative_matrix[i + i * n_rows] == 0.0,
534 for (
unsigned int j = 0; j < n_rows; ++j)
536 Assert(derivative_matrix[i + j * n_rows] == 0,
538 Assert(derivative_matrix[j + i * n_rows] == 0,
542 constrained_dofs[i] =
true;
546 const auto transpose_fill_nm = [&constrained_dofs](Number * out,
548 const unsigned int n,
549 const unsigned int m) {
550 for (
unsigned int mm = 0, c = 0; mm < m; ++mm)
551 for (
unsigned int nn = 0; nn < n; ++nn, ++c)
553 (mm == nn && constrained_dofs[mm]) ? Number(1.0) : in[c];
556 std::vector<::Vector<Number>> eigenvecs(n_rows);
560 transpose_fill_nm(&(mass_copy(0, 0)), mass_matrix, n_rows, n_cols);
561 transpose_fill_nm(&(deriv_copy(0, 0)), derivative_matrix, n_rows, n_cols);
566 for (
unsigned int i = 0, c = 0; i < n_rows; ++i)
567 for (
unsigned int j = 0; j < n_cols; ++j, ++c)
568 if (constrained_dofs[i] ==
false)
571 for (
unsigned int i = 0; i < n_rows; ++i, ++
eigenvalues)
577 template <std::
size_t dim,
typename Number>
584 const unsigned int n_rows_1d = mass_matrix[0].n_cols();
587 for (
unsigned int dir = 0; dir < dim; ++dir)
592 derivative_matrix[dir].n_rows());
594 derivative_matrix[dir].n_cols());
597 mass_matrix[dir].n_rows());
598 eigenvalues[dir].resize(mass_matrix[dir].n_cols());
599 internal::TensorProductMatrixSymmetricSum::spectral_assembly<Number>(
600 &(mass_matrix[dir](0, 0)),
601 &(derivative_matrix[dir](0, 0)),
602 mass_matrix[dir].n_rows(),
603 mass_matrix[dir].n_cols(),
611 template <std::
size_t dim,
typename Number, std::
size_t n_lanes>
622 const unsigned int n_rows_1d = mass_matrix[0].n_cols();
623 constexpr unsigned int macro_size =
625 const std::size_t nm_flat_size_max = n_rows_1d * n_rows_1d * macro_size;
626 const std::size_t n_flat_size_max = n_rows_1d * macro_size;
628 std::vector<Number> mass_matrix_flat;
629 std::vector<Number> deriv_matrix_flat;
630 std::vector<Number> eigenvalues_flat;
631 std::vector<Number> eigenvectors_flat;
632 mass_matrix_flat.resize(nm_flat_size_max);
633 deriv_matrix_flat.resize(nm_flat_size_max);
634 eigenvalues_flat.resize(n_flat_size_max);
635 eigenvectors_flat.resize(nm_flat_size_max);
636 std::array<unsigned int, macro_size> offsets_nm;
637 std::array<unsigned int, macro_size> offsets_n;
638 for (
unsigned int dir = 0; dir < dim; ++dir)
643 derivative_matrix[dir].n_rows());
645 derivative_matrix[dir].n_cols());
647 const unsigned int n_rows = mass_matrix[dir].n_rows();
648 const unsigned int n_cols = mass_matrix[dir].n_cols();
649 const unsigned int nm = n_rows * n_cols;
650 for (
unsigned int vv = 0; vv < macro_size; ++vv)
651 offsets_nm[vv] = nm * vv;
655 &(mass_matrix[dir](0, 0)),
657 mass_matrix_flat.data());
660 &(derivative_matrix[dir](0, 0)),
662 deriv_matrix_flat.data());
664 const Number *mass_cbegin = mass_matrix_flat.data();
665 const Number *deriv_cbegin = deriv_matrix_flat.data();
666 Number * eigenvec_begin = eigenvectors_flat.data();
667 Number * eigenval_begin = eigenvalues_flat.data();
668 for (
unsigned int lane = 0; lane < macro_size; ++lane)
669 internal::TensorProductMatrixSymmetricSum::spectral_assembly<
670 Number>(mass_cbegin + nm * lane,
671 deriv_cbegin + nm * lane,
674 eigenval_begin + n_rows * lane,
675 eigenvec_begin + nm * lane);
679 for (
unsigned int vv = 0; vv < macro_size; ++vv)
680 offsets_n[vv] = n_rows * vv;
682 eigenvalues_flat.data(),
686 eigenvectors_flat.data(),
694 template <std::
size_t dim,
typename Number>
695 inline std::array<Table<2, Number>, dim>
703 template <std::
size_t dim,
typename Number>
704 inline std::array<Table<2, Number>, dim>
707 std::array<Table<2, Number>, dim> mass_copy;
709 std::transform(mass_matrix.cbegin(),
721 template <std::
size_t dim,
typename Number>
722 inline std::array<Table<2, Number>, dim>
725 std::array<Table<2, Number>, dim> matrices;
727 std::fill(matrices.begin(), matrices.end(), matrix);
734 template <
int n_rows_1d_templated, std::
size_t dim,
typename Number>
739 const unsigned int n_rows_1d_non_templated,
740 const std::array<const Number *, dim> &mass_matrix,
741 const std::array<const Number *, dim> &derivative_matrix)
743 const unsigned int n_rows_1d = n_rows_1d_templated == 0 ?
744 n_rows_1d_non_templated :
746 const unsigned int n = Utilities::fixed_power<dim>(n_rows_1d);
749 Number *t = tmp.
begin();
756 eval({}, {}, {}, n_rows_1d, n_rows_1d);
760 const Number *A = derivative_matrix[0];
761 eval.template apply<0, false, false>(A, src, dst);
766 const Number *A0 = derivative_matrix[0];
767 const Number *M0 = mass_matrix[0];
768 const Number *A1 = derivative_matrix[1];
769 const Number *M1 = mass_matrix[1];
770 eval.template apply<0, false, false>(M0, src, t);
771 eval.template apply<1, false, false>(A1, t, dst);
772 eval.template apply<0, false, false>(A0, src, t);
773 eval.template apply<1, false, true>(M1, t, dst);
778 const Number *A0 = derivative_matrix[0];
779 const Number *M0 = mass_matrix[0];
780 const Number *A1 = derivative_matrix[1];
781 const Number *M1 = mass_matrix[1];
782 const Number *A2 = derivative_matrix[2];
783 const Number *M2 = mass_matrix[2];
784 eval.template apply<0, false, false>(M0, src, t + n);
785 eval.template apply<1, false, false>(M1, t + n, t);
786 eval.template apply<2, false, false>(A2, t, dst);
787 eval.template apply<1, false, false>(A1, t + n, t);
788 eval.template apply<0, false, false>(A0, src, t + n);
789 eval.template apply<1, false, true>(M1, t + n, t);
790 eval.template apply<2, false, true>(M2, t, dst);
799 template <
int n_rows_1d_templated, std::
size_t dim,
typename Number>
801 apply_inverse(Number * dst,
803 const unsigned int n_rows_1d_non_templated,
805 const std::array<const Number *, dim> &
eigenvalues,
806 const Number *inverted_eigenvalues =
nullptr)
808 const unsigned int n_rows_1d = n_rows_1d_templated == 0 ?
809 n_rows_1d_non_templated :
817 eval({}, {}, {}, n_rows_1d, n_rows_1d);
827 eval.template apply<0, true, false>(S, src, dst);
829 for (
unsigned int i = 0; i < n_rows_1d; ++i)
830 if (inverted_eigenvalues)
831 dst[i] *= inverted_eigenvalues[i];
835 eval.template apply<0, false, false>(S, dst, dst);
842 eval.template apply<0, true, false>(S0, src, dst);
843 eval.template apply<1, true, false>(S1, dst, dst);
845 for (
unsigned int i1 = 0, c = 0; i1 < n_rows_1d; ++i1)
846 for (
unsigned int i0 = 0; i0 < n_rows_1d; ++i0, ++c)
847 if (inverted_eigenvalues)
848 dst[c] *= inverted_eigenvalues[c];
852 eval.template apply<1, false, false>(S1, dst, dst);
853 eval.template apply<0, false, false>(S0, dst, dst);
861 eval.template apply<0, true, false>(S0, src, dst);
862 eval.template apply<1, true, false>(S1, dst, dst);
863 eval.template apply<2, true, false>(S2, dst, dst);
865 for (
unsigned int i2 = 0, c = 0; i2 < n_rows_1d; ++i2)
866 for (
unsigned int i1 = 0; i1 < n_rows_1d; ++i1)
867 for (
unsigned int i0 = 0; i0 < n_rows_1d; ++i0, ++c)
868 if (inverted_eigenvalues)
869 dst[c] *= inverted_eigenvalues[c];
874 eval.template apply<2, false, false>(S2, dst, dst);
875 eval.template apply<1, false, false>(S1, dst, dst);
876 eval.template apply<0, false, false>(S0, dst, dst);
885 template <
int n_rows_1d_templated, std::
size_t dim,
typename Number>
887 select_vmult(Number * dst,
890 const unsigned int n_rows_1d,
891 const std::array<const Number *, dim> &mass_matrix,
892 const std::array<const Number *, dim> &derivative_matrix);
896 template <
int n_rows_1d_templated, std::
size_t dim,
typename Number>
898 select_apply_inverse(Number * dst,
900 const unsigned int n_rows_1d,
902 const std::array<const Number *, dim> &
eigenvalues,
903 const Number *inverted_eigenvalues =
nullptr);
908template <
int dim,
typename Number,
int n_rows_1d>
913 for (
unsigned int d = 1;
d < dim; ++
d)
914 m *= mass_matrix[d].n_rows();
920template <
int dim,
typename Number,
int n_rows_1d>
925 for (
unsigned int d = 1;
d < dim; ++
d)
926 n *= mass_matrix[d].n_cols();
932template <
int dim,
typename Number,
int n_rows_1d>
938 std::lock_guard<std::mutex> lock(this->mutex);
939 this->vmult(dst_view, src_view, this->tmp_array);
944template <
int dim,
typename Number,
int n_rows_1d>
954 Number * dst = dst_view.
begin();
955 const Number *src = src_view.
begin();
957 std::array<const Number *, dim>
mass_matrix, derivative_matrix;
959 for (
unsigned int d = 0;
d < dim; ++
d)
962 derivative_matrix[
d] = &this->derivative_matrix[
d](0, 0);
965 const unsigned int n_rows_1d_non_templated = this->mass_matrix[0].n_rows();
968 internal::TensorProductMatrixSymmetricSum::vmult<
969 n_rows_1d == -1 ? 0 : n_rows_1d>(dst,
972 n_rows_1d_non_templated,
976 internal::TensorProductMatrixSymmetricSum::select_vmult<1>(
980 n_rows_1d_non_templated,
987template <
int dim,
typename Number,
int n_rows_1d>
996 Number * dst = dst_view.
begin();
997 const Number *src = src_view.
begin();
1001 for (
unsigned int d = 0;
d < dim; ++
d)
1007 const unsigned int n_rows_1d_non_templated = this->mass_matrix[0].n_rows();
1009 if (n_rows_1d != -1)
1010 internal::TensorProductMatrixSymmetricSum::apply_inverse<
1011 n_rows_1d == -1 ? 0 : n_rows_1d>(
1014 internal::TensorProductMatrixSymmetricSum::select_apply_inverse<1>(
1020template <
int dim,
typename Number,
int n_rows_1d>
1034template <
int dim,
typename Number,
int n_rows_1d>
1035template <
typename T>
1038 const T &derivative_matrix)
1040 reinit(mass_matrix, derivative_matrix);
1045template <
int dim,
typename Number,
int n_rows_1d>
1046template <
typename T>
1049 const T &mass_matrix,
1050 const T &derivative_matrix)
1053 internal::TensorProductMatrixSymmetricSum::convert<dim>(mass_matrix);
1054 this->derivative_matrix =
1055 internal::TensorProductMatrixSymmetricSum::convert<dim>(derivative_matrix);
1057 internal::TensorProductMatrixSymmetricSum::setup(this->mass_matrix,
1058 this->derivative_matrix,
1065template <
int dim,
typename Number,
int n_rows_1d>
1068 const bool precompute_inverse_diagonal)
1069 : compress_matrices(compress_matrices)
1070 , precompute_inverse_diagonal(precompute_inverse_diagonal)
1075template <
int dim,
typename Number,
int n_rows_1d>
1078 const AdditionalData &additional_data)
1079 : compress_matrices(additional_data.compress_matrices)
1080 , precompute_inverse_diagonal(additional_data.precompute_inverse_diagonal)
1085template <
int dim,
typename Number,
int n_rows_1d>
1088 const unsigned int size)
1090 if (compress_matrices ==
false)
1091 mass_and_derivative_matrices.resize(size * dim);
1098template <
int dim,
typename Number,
int n_rows_1d>
1099template <
typename T>
1102 const unsigned int index,
1107 internal::TensorProductMatrixSymmetricSum::convert<dim>(Ms_in);
1109 internal::TensorProductMatrixSymmetricSum::convert<dim>(Ks_in);
1111 for (
unsigned int d = 0;
d < dim; ++
d)
1113 if (compress_matrices ==
false)
1115 const MatrixPairType
matrix(Ms[d], Ks[d]);
1116 mass_and_derivative_matrices[
index * dim +
d] =
matrix;
1120 using VectorizedArrayTrait =
1123 std::bitset<VectorizedArrayTrait::width()>
mask;
1125 for (
unsigned int v = 0; v < VectorizedArrayTrait::width(); ++v)
1127 typename VectorizedArrayTrait::value_type a = 0.0;
1129 for (
unsigned int i = 0; i < Ms[
d].size(0); ++i)
1130 for (
unsigned int j = 0; j < Ms[
d].size(1); ++j)
1132 a +=
std::abs(VectorizedArrayTrait::get(Ms[d][i][j], v));
1133 a +=
std::abs(VectorizedArrayTrait::get(Ks[d][i][j], v));
1136 mask[v] = (a != 0.0);
1139 const MatrixPairTypeWithMask
matrix{
mask, {Ms[
d], Ks[
d]}};
1141 const auto ptr = cache.find(matrix);
1143 if (ptr != cache.end())
1145 const auto ptr_index = ptr->second;
1146 indices[
index * dim +
d] = ptr_index;
1149 for (
unsigned int v = 0; v < VectorizedArrayTrait::width();
1151 if ((mask[v] ==
true) && (ptr->first.first[v] ==
false))
1161 auto mask_new = ptr->first.first;
1162 auto Ms_new = ptr->first.second.first;
1163 auto Ks_new = ptr->first.second.second;
1165 for (
unsigned int v = 0; v < VectorizedArrayTrait::width();
1167 if (mask_new[v] ==
false && mask[v] ==
true)
1171 for (
unsigned int i = 0; i < Ms_new.size(0); ++i)
1172 for (
unsigned int j = 0; j < Ms_new.size(1); ++j)
1174 VectorizedArrayTrait::get(Ms_new[i][j], v) =
1175 VectorizedArrayTrait::get(Ms[d][i][j], v);
1176 VectorizedArrayTrait::get(Ks_new[i][j], v) =
1177 VectorizedArrayTrait::get(Ks[d][i][j], v);
1183 const MatrixPairTypeWithMask entry_new{mask_new,
1186 const auto ptr_ = cache.find(entry_new);
1189 cache[entry_new] = ptr_index;
1194 const auto size = cache.size();
1195 indices[
index * dim +
d] = size;
1204template <
int dim,
typename Number,
int n_rows_1d>
1208 const auto store = [&](
const unsigned int index,
1209 const MatrixPairType &M_and_K) {
1213 std::array<Table<2, Number>, 1> derivative_matrix;
1214 derivative_matrix[0] = M_and_K.second;
1219 internal::TensorProductMatrixSymmetricSum::setup(mass_matrix,
1224 for (
unsigned int i = 0, m = matrix_ptr[index], v = vector_ptr[index];
1228 for (
unsigned int j = 0; j <
mass_matrix[0].n_cols(); ++j, ++m)
1231 this->derivative_matrices[m] = derivative_matrix[0][i][j];
1239 if (compress_matrices ==
false)
1246 this->vector_ptr.resize(mass_and_derivative_matrices.size() + 1);
1247 this->matrix_ptr.resize(mass_and_derivative_matrices.size() + 1);
1249 for (
unsigned int i = 0; i < mass_and_derivative_matrices.size(); ++i)
1251 const auto &M = mass_and_derivative_matrices[i].first;
1253 this->vector_ptr[i + 1] = M.n_rows();
1254 this->matrix_ptr[i + 1] = M.n_rows() * M.n_cols();
1257 for (
unsigned int i = 0; i < mass_and_derivative_matrices.size(); ++i)
1259 this->vector_ptr[i + 1] += this->vector_ptr[i];
1260 this->matrix_ptr[i + 1] += this->matrix_ptr[i];
1263 this->mass_matrices.resize_fast(matrix_ptr.back());
1264 this->derivative_matrices.resize_fast(matrix_ptr.back());
1265 this->eigenvectors.resize_fast(matrix_ptr.back());
1266 this->eigenvalues.resize_fast(vector_ptr.back());
1268 for (
unsigned int i = 0; i < mass_and_derivative_matrices.size(); ++i)
1269 store(i, mass_and_derivative_matrices[i]);
1271 mass_and_derivative_matrices.clear();
1273 else if (cache.size() == indices.size())
1277 this->vector_ptr.resize(cache.size() + 1);
1278 this->matrix_ptr.resize(cache.size() + 1);
1280 std::map<unsigned int, MatrixPairType> inverted_cache;
1282 for (
const auto &i : cache)
1285 for (
unsigned int i = 0; i < indices.size(); ++i)
1287 const auto &M = inverted_cache[indices[i]].first;
1289 this->vector_ptr[i + 1] = M.n_rows();
1290 this->matrix_ptr[i + 1] = M.n_rows() * M.n_cols();
1293 for (
unsigned int i = 0; i < cache.size(); ++i)
1295 this->vector_ptr[i + 1] += this->vector_ptr[i];
1296 this->matrix_ptr[i + 1] += this->matrix_ptr[i];
1299 this->mass_matrices.resize_fast(matrix_ptr.back());
1300 this->derivative_matrices.resize_fast(matrix_ptr.back());
1301 this->eigenvectors.resize_fast(matrix_ptr.back());
1302 this->eigenvalues.resize_fast(vector_ptr.back());
1304 for (
unsigned int i = 0; i < indices.size(); ++i)
1305 store(i, inverted_cache[indices[i]]);
1314 this->vector_ptr.resize(cache.size() + 1);
1315 this->matrix_ptr.resize(cache.size() + 1);
1317 for (
const auto &i : cache)
1319 const auto &M = i.first.second.first;
1321 this->vector_ptr[i.second + 1] = M.n_rows();
1322 this->matrix_ptr[i.second + 1] = M.n_rows() * M.n_cols();
1325 for (
unsigned int i = 0; i < cache.size(); ++i)
1327 this->vector_ptr[i + 1] += this->vector_ptr[i];
1328 this->matrix_ptr[i + 1] += this->matrix_ptr[i];
1331 this->mass_matrices.resize_fast(matrix_ptr.back());
1332 this->derivative_matrices.resize_fast(matrix_ptr.back());
1333 this->eigenvectors.resize_fast(matrix_ptr.back());
1334 this->eigenvalues.resize_fast(vector_ptr.back());
1336 for (
const auto &i : cache)
1342 if (precompute_inverse_diagonal)
1347 for (
unsigned int i = 0; i < this->eigenvalues.size(); ++i)
1348 this->eigenvalues[i] = Number(1.0) / this->eigenvalues[i];
1349 std::swap(this->inverted_eigenvalues,
eigenvalues);
1359 std::vector<unsigned int> indices_ev;
1361 if (indices.size() > 0)
1364 const unsigned int n_cells = indices.size() / dim;
1365 std::map<std::array<unsigned int, dim>,
unsigned int> cache_ev;
1366 std::vector<unsigned int> cache_ev_idx(n_cells);
1368 for (
unsigned int i = 0, c = 0; i <
n_cells; ++i)
1370 std::array<unsigned int, dim> id;
1372 for (
unsigned int d = 0;
d < dim; ++
d, ++c)
1375 const auto id_ptr = cache_ev.find(
id);
1377 if (id_ptr == cache_ev.end())
1379 const auto size = cache_ev.size();
1380 cache_ev_idx[i] = size;
1381 cache_ev[id] = size;
1385 cache_ev_idx[i] = id_ptr->second;
1390 std::vector<unsigned int> new_indices;
1391 new_indices.reserve(indices.size() / dim * (dim + 1));
1393 for (
unsigned int i = 0, c = 0; i <
n_cells; ++i)
1395 for (
unsigned int d = 0;
d < dim; ++
d, ++c)
1396 new_indices.push_back(indices[c]);
1397 new_indices.push_back(cache_ev_idx[i]);
1401 indices_ev.resize(cache_ev.size() * dim);
1402 for (
const auto &entry : cache_ev)
1403 for (unsigned
int d = 0;
d < dim; ++
d)
1404 indices_ev[entry.second * dim + d] = entry.first[d];
1406 std::swap(this->indices, new_indices);
1410 const unsigned int n_diag =
1411 ((indices_ev.size() > 0) ? indices_ev.size() :
1412 (matrix_ptr.size() - 1)) /
1415 std::vector<unsigned int> new_vector_ptr(n_diag + 1, 0);
1416 std::vector<unsigned int> new_vector_n_rows_1d(n_diag, 0);
1418 for (
unsigned int i = 0; i < n_diag; ++i)
1420 const unsigned int c = (indices_ev.size() > 0) ?
1421 indices_ev[dim * i + 0] :
1424 const unsigned int n_rows = vector_ptr[c + 1] - vector_ptr[c];
1426 new_vector_n_rows_1d[i] = n_rows;
1430 for (
unsigned int i = 0; i < n_diag; ++i)
1431 new_vector_ptr[i + 1] += new_vector_ptr[i];
1433 this->inverted_eigenvalues.resize(new_vector_ptr.back());
1436 for (
unsigned int i = 0; i < n_diag; ++i)
1438 std::array<Number *, dim> evs;
1440 for (
unsigned int d = 0;
d < dim; ++
d)
1443 ->
eigenvalues[this->vector_ptr[(indices_ev.size() > 0) ?
1444 indices_ev[dim * i +
d] :
1447 const unsigned int mm = new_vector_n_rows_1d[i];
1450 for (
unsigned int i1 = 0, c = 0; i1 < mm; ++i1)
1451 for (
unsigned int i0 = 0; i0 < mm; ++i0, ++c)
1452 this->inverted_eigenvalues[new_vector_ptr[i] + c] =
1453 Number(1.0) / (evs[1][i1] + evs[0][i0]);
1457 for (
unsigned int i2 = 0, c = 0; i2 < mm; ++i2)
1458 for (
unsigned int i1 = 0; i1 < mm; ++i1)
1459 for (
unsigned int i0 = 0; i0 < mm; ++i0, ++c)
1460 this->inverted_eigenvalues[new_vector_ptr[i] + c] =
1461 Number(1.0) / (evs[2][i2] + evs[1][i1] + evs[0][i0]);
1466 std::swap(this->vector_ptr, new_vector_ptr);
1467 std::swap(this->vector_n_rows_1d, new_vector_n_rows_1d);
1470 this->eigenvalues.clear();
1476template <
int dim,
typename Number,
int n_rows_1d>
1483 Number * dst = dst_in.
begin();
1484 const Number *src = src_in.
begin();
1486 if (this->eigenvalues.empty() ==
false)
1490 unsigned int n_rows_1d_non_templated = 0;
1492 for (
unsigned int d = 0;
d < dim; ++
d)
1494 const unsigned int translated_index =
1495 (indices.size() > 0) ? indices[dim * index + d] : (dim *
index +
d);
1498 this->eigenvectors.data() + matrix_ptr[translated_index];
1500 this->eigenvalues.data() + vector_ptr[translated_index];
1501 n_rows_1d_non_templated =
1502 vector_ptr[translated_index + 1] - vector_ptr[translated_index];
1505 if (n_rows_1d != -1)
1506 internal::TensorProductMatrixSymmetricSum::apply_inverse<
1507 n_rows_1d == -1 ? 0 : n_rows_1d>(
1510 internal::TensorProductMatrixSymmetricSum::select_apply_inverse<1>(
1516 const Number * inverted_eigenvalues =
nullptr;
1517 unsigned int n_rows_1d_non_templated = 0;
1519 for (
unsigned int d = 0;
d < dim; ++
d)
1521 const unsigned int translated_index =
1522 (indices.size() > 0) ?
1523 indices[((dim == 1) ? 1 : (dim + 1)) *
index +
d] :
1527 this->eigenvectors.data() + matrix_ptr[translated_index];
1531 const unsigned int translated_index =
1532 ((indices.size() > 0) && (dim != 1)) ?
1533 indices[(dim + 1) *
index + dim] :
1536 inverted_eigenvalues =
1537 this->inverted_eigenvalues.data() + vector_ptr[translated_index];
1538 n_rows_1d_non_templated =
1540 (vector_ptr[translated_index + 1] - vector_ptr[translated_index]) :
1541 vector_n_rows_1d[translated_index];
1544 if (n_rows_1d != -1)
1545 internal::TensorProductMatrixSymmetricSum::apply_inverse<
1546 n_rows_1d == -1 ? 0 : n_rows_1d>(dst,
1548 n_rows_1d_non_templated,
1551 inverted_eigenvalues);
1553 internal::TensorProductMatrixSymmetricSum::select_apply_inverse<1>(
1556 n_rows_1d_non_templated,
1559 inverted_eigenvalues);
1565template <
int dim,
typename Number,
int n_rows_1d>
1581template <
int dim,
typename Number,
int n_rows_1d>
1586 if (matrix_ptr.size() == 0)
1589 return matrix_ptr.size() - 1;
void resize_fast(const size_type new_size)
std::complex< typename numbers::NumberTraits< number >::real_type > eigenvalue(const size_type i) const
void compute_generalized_eigenvalues_symmetric(LAPACKFullMatrix< number > &B, const number lower_bound, const number upper_bound, const number abs_accuracy, Vector< number > &eigenvalues, std::vector< Vector< number > > &eigenvectors, const types::blas_int itype=1)
std::size_t storage_size() const
AlignedVector< Number > mass_matrices
const bool precompute_inverse_diagonal
std::size_t memory_consumption() const
std::vector< unsigned int > matrix_ptr
void apply_inverse(const unsigned int index, const ArrayView< Number > &dst_in, const ArrayView< const Number > &src_in) const
AlignedVector< Number > eigenvectors
std::vector< unsigned int > vector_ptr
const bool compress_matrices
std::vector< MatrixPairType > mass_and_derivative_matrices
std::pair< std::bitset<::internal::VectorizedArrayTrait< Number >::width()>, MatrixPairType > MatrixPairTypeWithMask
std::pair< Table< 2, Number >, Table< 2, Number > > MatrixPairType
void reserve(const unsigned int size)
void insert(const unsigned int index, const T &Ms, const T &Ks)
AlignedVector< Number > inverted_eigenvalues
std::vector< unsigned int > indices
std::vector< unsigned int > vector_n_rows_1d
std::map< MatrixPairTypeWithMask, unsigned int, internal::TensorProductMatrixSymmetricSum::MatrixPairComparator< Number > > cache
AlignedVector< Number > eigenvalues
AlignedVector< Number > derivative_matrices
TensorProductMatrixSymmetricSumCollection(const AdditionalData &additional_data=AdditionalData())
void vmult(const ArrayView< Number > &dst, const ArrayView< const Number > &src, AlignedVector< Number > &tmp) const
std::array< Table< 2, Number >, dim > eigenvectors
std::array< Table< 2, Number >, dim > derivative_matrix
void reinit(const T &mass_matrix, const T &derivative_matrix)
void apply_inverse(const ArrayView< Number > &dst, const ArrayView< const Number > &src) const
void vmult(const ArrayView< Number > &dst, const ArrayView< const Number > &src) const
AlignedVector< Number > tmp_array
static constexpr int n_rows_1d_static
std::size_t memory_consumption() const
TensorProductMatrixSymmetricSum()=default
std::array< Table< 2, Number >, dim > mass_matrix
std::array< AlignedVector< Number >, dim > eigenvalues
TensorProductMatrixSymmetricSum(const T &mass_matrix, const T &derivative_matrix)
static constexpr std::size_t size()
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
#define AssertThrow(cond, exc)
@ matrix
Contents is actually a matrix.
void mass_matrix(FullMatrix< double > &M, const FEValuesBase< dim > &fe, const double factor=1.)
std::enable_if_t< std::is_fundamental< T >::value, std::size_t > memory_consumption(const T &t)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
constexpr T pow(const T base, const int iexp)
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
static const unsigned int invalid_unsigned_int
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
bool precompute_inverse_diagonal
AdditionalData(const bool compress_matrices=true, const bool precompute_inverse_diagonal=true)
typename VectorizedArrayTrait::value_type ScalarNumber
bool operator()(const MatrixPairType &left, const MatrixPairType &right) const
std::pair< std::bitset< width >, std::pair< Table< 2, Number >, Table< 2, Number > > > MatrixPairType
static constexpr std::size_t width
static constexpr std::size_t width()
std::array< Number, 1 > eigenvalues(const SymmetricTensor< 2, 1, Number > &T)
std::array< std::pair< Number, Tensor< 1, dim, Number > >, std::integral_constant< int, dim >::value > eigenvectors(const SymmetricTensor< 2, dim, Number > &T, const SymmetricTensorEigenvectorMethod method=SymmetricTensorEigenvectorMethod::ql_implicit_shifts)
void vectorized_load_and_transpose(const unsigned int n_entries, const Number *in, const unsigned int *offsets, VectorizedArray< Number, width > *out)
void vectorized_transpose_and_store(const bool add_into, const unsigned int n_entries, const VectorizedArray< Number, width > *in, const unsigned int *offsets, Number *out)