From: Denis Davydov Date: Wed, 20 Dec 2017 12:30:21 +0000 (+0100) Subject: add a function to remove row and column from LAPACKFullMatrix X-Git-Tag: v9.0.0-rc1~635^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b50a10595262e676209ae5ec49aa1cec9ce60150;p=dealii.git add a function to remove row and column from LAPACKFullMatrix --- diff --git a/doc/news/changes/minor/20171220DenisDavydov b/doc/news/changes/minor/20171220DenisDavydov new file mode 100644 index 0000000000..2b54783547 --- /dev/null +++ b/doc/news/changes/minor/20171220DenisDavydov @@ -0,0 +1,4 @@ +New: LAPACKFullMatrix::remove_row_and_column() to remove certain row and column +of the matrix. +
+(Denis Davydov, 2017/12/20) diff --git a/include/deal.II/lac/lapack_full_matrix.h b/include/deal.II/lac/lapack_full_matrix.h index 518fede4b3..884e650e22 100644 --- a/include/deal.II/lac/lapack_full_matrix.h +++ b/include/deal.II/lac/lapack_full_matrix.h @@ -199,6 +199,27 @@ public: */ void grow_or_shrink (const size_type size); + /** + * Remove row @p row and column @p col from the matrix. + * \f[ + * \left( + * \begin{array}{ccc} + * \mathbf A_{11} & \mathbf a_{12} & \mathbf A_{13} \\ + * \mathbf a_{21}^T & a_{22} & \mathbf a_{23}^T \\ + * \mathbf A_{31} & \mathbf a_{32} & \mathbf A_{33} + * \end{array} + * \right) + * \rightarrow + * \left( + * \begin{array}{cc} + * \mathbf A_{11} & \mathbf A_{13} \\ + * \mathbf A_{31} & \mathbf A_{33} + * \end{array} + * \right) + * \f] + */ + void remove_row_and_column (const size_type row, const size_type col); + /** * Regenerate the current matrix by one that has the same properties as if * it were created by the constructor of this class with the same argument diff --git a/source/lac/lapack_full_matrix.cc b/source/lac/lapack_full_matrix.cc index d4155d510f..53b3154b0a 100644 --- a/source/lac/lapack_full_matrix.cc +++ b/source/lac/lapack_full_matrix.cc @@ -85,16 +85,42 @@ template void LAPACKFullMatrix::grow_or_shrink (const size_type n) { - TransposeTable copy(*this); const size_type s = std::min(std::min(this->m(), n), this->n()); + TransposeTable copy(std::move(*this)); this->TransposeTable::reinit (n, n); - for (unsigned int i = 0; i < s; ++i) - for (unsigned int j = 0; j < s; ++j) + for (size_type i = 0; i < s; ++i) + for (size_type j = 0; j < s; ++j) (*this)(i,j) = copy(i,j); } +template +void +LAPACKFullMatrix::remove_row_and_column (const size_type row, const size_type col) +{ + Assert (rown_rows(), ExcIndexRange(row,0,this->n_rows())); + Assert (coln_cols(), ExcIndexRange(col,0,this->n_cols())); + + const size_type nrows = this->n_rows()-1; + const size_type ncols = this->n_cols()-1; + + TransposeTable copy(std::move(*this)); + this->TransposeTable::reinit (nrows, ncols); + + for (size_type j = 0; j < ncols; ++j) + { + const size_type jj = ( j < col ? j : j+1); + for (size_type i = 0; i < nrows; ++i) + { + const size_type ii = ( i < row ? i : i+1); + (*this)(i,j) = copy(ii,jj); + } + } +} + + + template void LAPACKFullMatrix::reinit (const size_type m, diff --git a/tests/lapack/full_matrix_30.cc b/tests/lapack/full_matrix_30.cc new file mode 100644 index 0000000000..2232fc5098 --- /dev/null +++ b/tests/lapack/full_matrix_30.cc @@ -0,0 +1,50 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// test LAPACKFullMatrix removing row and column from a matrix + +#include "../tests.h" +#include + +#include + + +template +void +test() +{ + const unsigned int n_rows = 6; + const unsigned int n_cols = 9; + LAPACKFullMatrix A(n_rows,n_cols); + + for (unsigned int i = 0; i < n_rows; ++i) + for (unsigned int j = 0; j < n_cols; ++j) + A(i,j) = 10*(i+1)+(j+1); + + A.remove_row_and_column(2,7); // <-- 3x and x8 are removed + A.print_formatted(deallog.get_file_stream(), 0, false, 2); +} + + +int main() +{ + const std::string logname = "output"; + std::ofstream logfile(logname.c_str()); + logfile.precision(5); + deallog.attach(logfile); + + test(); +} diff --git a/tests/lapack/full_matrix_30.output b/tests/lapack/full_matrix_30.output new file mode 100644 index 0000000000..73fd9d7494 --- /dev/null +++ b/tests/lapack/full_matrix_30.output @@ -0,0 +1,6 @@ + +11. 12. 13. 14. 15. 16. 17. 19. +21. 22. 23. 24. 25. 26. 27. 29. +41. 42. 43. 44. 45. 46. 47. 49. +51. 52. 53. 54. 55. 56. 57. 59. +61. 62. 63. 64. 65. 66. 67. 69.