From: David Wells Date: Tue, 21 Mar 2023 21:14:10 +0000 (-0400) Subject: Move some FullMatrix functions with Tensors into the header. X-Git-Tag: v9.5.0-rc1~436^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3fb76d0c3c05c714a58df07db3dc47930828800;p=dealii.git Move some FullMatrix functions with Tensors into the header. --- diff --git a/include/deal.II/lac/full_matrix.h b/include/deal.II/lac/full_matrix.h index 462571b9bb..2d246856fb 100644 --- a/include/deal.II/lac/full_matrix.h +++ b/include/deal.II/lac/full_matrix.h @@ -1191,6 +1191,66 @@ FullMatrix::copy_from(const MatrixType &M) +template +template +void +FullMatrix::copy_from(const Tensor<2, dim> &T, + const unsigned int src_r_i, + const unsigned int src_r_j, + const unsigned int src_c_i, + const unsigned int src_c_j, + const size_type dst_r, + const size_type dst_c) +{ + Assert(!this->empty(), ExcEmptyMatrix()); + AssertIndexRange(src_r_j - src_r_i, this->m() - dst_r); + AssertIndexRange(src_c_j - src_c_i, this->n() - dst_c); + AssertIndexRange(src_r_j, dim); + AssertIndexRange(src_c_j, dim); + AssertIndexRange(src_r_i, src_r_j + 1); + AssertIndexRange(src_c_i, src_c_j + 1); + + for (size_type i = 0; i < src_r_j - src_r_i + 1; ++i) + for (size_type j = 0; j < src_c_j - src_c_i + 1; ++j) + { + const unsigned int src_r_index = static_cast(i + src_r_i); + const unsigned int src_c_index = static_cast(j + src_c_i); + (*this)(i + dst_r, j + dst_c) = number(T[src_r_index][src_c_index]); + } +} + + + +template +template +void +FullMatrix::copy_to(Tensor<2, dim> & T, + const size_type src_r_i, + const size_type src_r_j, + const size_type src_c_i, + const size_type src_c_j, + const unsigned int dst_r, + const unsigned int dst_c) const +{ + Assert(!this->empty(), ExcEmptyMatrix()); + AssertIndexRange(src_r_j - src_r_i, dim - dst_r); + AssertIndexRange(src_c_j - src_c_i, dim - dst_c); + AssertIndexRange(src_r_j, this->m()); + AssertIndexRange(src_r_j, this->n()); + AssertIndexRange(src_r_i, src_r_j + 1); + AssertIndexRange(src_c_j, src_c_j + 1); + + for (size_type i = 0; i < src_r_j - src_r_i + 1; ++i) + for (size_type j = 0; j < src_c_j - src_c_i + 1; ++j) + { + const unsigned int dst_r_index = static_cast(i + dst_r); + const unsigned int dst_c_index = static_cast(j + dst_c); + T[dst_r_index][dst_c_index] = double((*this)(i + src_r_i, j + src_c_i)); + } +} + + + template template void diff --git a/include/deal.II/lac/full_matrix.templates.h b/include/deal.II/lac/full_matrix.templates.h index e3b93fd147..c60726c6fb 100644 --- a/include/deal.II/lac/full_matrix.templates.h +++ b/include/deal.II/lac/full_matrix.templates.h @@ -1666,64 +1666,6 @@ FullMatrix::right_invert(const FullMatrix &A) } -template -template -void -FullMatrix::copy_from(const Tensor<2, dim> &T, - const unsigned int src_r_i, - const unsigned int src_r_j, - const unsigned int src_c_i, - const unsigned int src_c_j, - const size_type dst_r, - const size_type dst_c) -{ - Assert(!this->empty(), ExcEmptyMatrix()); - AssertIndexRange(src_r_j - src_r_i, this->m() - dst_r); - AssertIndexRange(src_c_j - src_c_i, this->n() - dst_c); - AssertIndexRange(src_r_j, dim); - AssertIndexRange(src_c_j, dim); - AssertIndexRange(src_r_i, src_r_j + 1); - AssertIndexRange(src_c_i, src_c_j + 1); - - for (size_type i = 0; i < src_r_j - src_r_i + 1; ++i) - for (size_type j = 0; j < src_c_j - src_c_i + 1; ++j) - { - const unsigned int src_r_index = static_cast(i + src_r_i); - const unsigned int src_c_index = static_cast(j + src_c_i); - (*this)(i + dst_r, j + dst_c) = number(T[src_r_index][src_c_index]); - } -} - - -template -template -void -FullMatrix::copy_to(Tensor<2, dim> & T, - const size_type src_r_i, - const size_type src_r_j, - const size_type src_c_i, - const size_type src_c_j, - const unsigned int dst_r, - const unsigned int dst_c) const -{ - Assert(!this->empty(), ExcEmptyMatrix()); - AssertIndexRange(src_r_j - src_r_i, dim - dst_r); - AssertIndexRange(src_c_j - src_c_i, dim - dst_c); - AssertIndexRange(src_r_j, this->m()); - AssertIndexRange(src_r_j, this->n()); - AssertIndexRange(src_r_i, src_r_j + 1); - AssertIndexRange(src_c_j, src_c_j + 1); - - for (size_type i = 0; i < src_r_j - src_r_i + 1; ++i) - for (size_type j = 0; j < src_c_j - src_c_i + 1; ++j) - { - const unsigned int dst_r_index = static_cast(i + dst_r); - const unsigned int dst_c_index = static_cast(j + dst_c); - T[dst_r_index][dst_c_index] = double((*this)(i + src_r_i, j + src_c_i)); - } -} - - template template diff --git a/source/lac/full_matrix.inst.in b/source/lac/full_matrix.inst.in index a6c3ee23f9..90b48df135 100644 --- a/source/lac/full_matrix.inst.in +++ b/source/lac/full_matrix.inst.in @@ -25,61 +25,8 @@ for (S : REAL_AND_COMPLEX_SCALARS) template void FullMatrix::print(std::ostream &, const unsigned int, const unsigned int) const; - - template void FullMatrix::copy_from<1>(const Tensor<2, 1> &, - const unsigned int, - const unsigned int, - unsigned int, - const unsigned int, - const size_type, - const size_type); - - template void FullMatrix::copy_from<2>(const Tensor<2, 2> &, - const unsigned int, - const unsigned int, - unsigned int, - const unsigned int, - const size_type, - const size_type); - - template void FullMatrix::copy_from<3>(const Tensor<2, 3> &, - const unsigned int, - const unsigned int, - unsigned int, - const unsigned int, - const size_type, - const size_type); - } - - -for (S : REAL_SCALARS) - { - template void FullMatrix::copy_to<1>(Tensor<2, 1> &, - const size_type, - const size_type, - const size_type, - const size_type, - const unsigned int, - const unsigned int) const; - - template void FullMatrix::copy_to<2>(Tensor<2, 2> &, - const size_type, - const size_type, - const size_type, - const size_type, - const unsigned int, - const unsigned int) const; - - template void FullMatrix::copy_to<3>(Tensor<2, 3> &, - const size_type, - const size_type, - const size_type, - const size_type, - const unsigned int, - const unsigned int) const; } - for (S1, S2 : REAL_SCALARS) { template FullMatrix &FullMatrix::operator=(