]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add a function to remove row and column from LAPACKFullMatrix 5651/head
authorDenis Davydov <davydden@gmail.com>
Wed, 20 Dec 2017 12:30:21 +0000 (13:30 +0100)
committerDenis Davydov <davydden@gmail.com>
Wed, 20 Dec 2017 17:54:27 +0000 (18:54 +0100)
doc/news/changes/minor/20171220DenisDavydov [new file with mode: 0644]
include/deal.II/lac/lapack_full_matrix.h
source/lac/lapack_full_matrix.cc
tests/lapack/full_matrix_30.cc [new file with mode: 0644]
tests/lapack/full_matrix_30.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20171220DenisDavydov b/doc/news/changes/minor/20171220DenisDavydov
new file mode 100644 (file)
index 0000000..2b54783
--- /dev/null
@@ -0,0 +1,4 @@
+New: LAPACKFullMatrix::remove_row_and_column() to remove certain row and column
+of the matrix.
+<br>
+(Denis Davydov, 2017/12/20)
index 518fede4b3cf1d89a76cd11975e26baa49a3700e..884e650e22459698ccbd51301067dfe098a399f5 100644 (file)
@@ -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
index d4155d510fbce89740152aa3fef57807064a7c64..53b3154b0a6398f71f82bee0cf7e5172f817883c 100644 (file)
@@ -85,16 +85,42 @@ template <typename number>
 void
 LAPACKFullMatrix<number>::grow_or_shrink (const size_type n)
 {
-  TransposeTable<number> copy(*this);
   const size_type s = std::min(std::min(this->m(), n), this->n());
+  TransposeTable<number> copy(std::move(*this));
   this->TransposeTable<number>::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 <typename number>
+void
+LAPACKFullMatrix<number>::remove_row_and_column (const size_type row, const size_type col)
+{
+  Assert (row<this->n_rows(), ExcIndexRange(row,0,this->n_rows()));
+  Assert (col<this->n_cols(), ExcIndexRange(col,0,this->n_cols()));
+
+  const size_type nrows = this->n_rows()-1;
+  const size_type ncols = this->n_cols()-1;
+
+  TransposeTable<number> copy(std::move(*this));
+  this->TransposeTable<number>::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 <typename number>
 void
 LAPACKFullMatrix<number>::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 (file)
index 0000000..2232fc5
--- /dev/null
@@ -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 <deal.II/lac/lapack_full_matrix.h>
+
+#include <iostream>
+
+
+template <typename NumberType>
+void
+test()
+{
+  const unsigned int n_rows = 6;
+  const unsigned int n_cols = 9;
+  LAPACKFullMatrix<NumberType> 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<double>();
+}
diff --git a/tests/lapack/full_matrix_30.output b/tests/lapack/full_matrix_30.output
new file mode 100644 (file)
index 0000000..73fd9d7
--- /dev/null
@@ -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. 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.