]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test. 15331/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 8 Jun 2023 23:30:15 +0000 (17:30 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 8 Jun 2023 23:30:15 +0000 (17:30 -0600)
tests/tensors/copy_from_01.cc [new file with mode: 0644]
tests/tensors/copy_from_01.output [new file with mode: 0644]

diff --git a/tests/tensors/copy_from_01.cc b/tests/tensors/copy_from_01.cc
new file mode 100644 (file)
index 0000000..d5e68e0
--- /dev/null
@@ -0,0 +1,53 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 - 2018 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+// Check copy_to() and copy_from() between tensors and full matrices.
+
+#include <deal.II/base/tensor.h>
+
+#include <deal.II/lac/full_matrix.h>
+
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  const unsigned int matrix_dimension = 4;
+
+  Tensor<2, matrix_dimension> myTensor;
+
+  FullMatrix<double> myMatrix(matrix_dimension, matrix_dimension);
+
+  for (unsigned int i = 0; i < matrix_dimension; i++)
+    for (unsigned int j = 0; j < matrix_dimension; j++)
+      {
+        myMatrix(i, j) = i + j;
+      }
+
+  myMatrix.copy_to(myTensor);
+
+  deallog << myTensor.dimension << std::endl;
+  deallog.get_file_stream() << myTensor << std::endl;
+
+  myTensor *= 2;
+  myMatrix.copy_from(myTensor);
+  for (unsigned int i = 0; i < matrix_dimension; i++)
+    for (unsigned int j = 0; j < matrix_dimension; j++)
+      {
+        Assert(myMatrix(i, j) == 2. * (i + j), ExcInternalError());
+      }
+}
diff --git a/tests/tensors/copy_from_01.output b/tests/tensors/copy_from_01.output
new file mode 100644 (file)
index 0000000..4f29e0d
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::4
+0.00000 1.00000 2.00000 3.00000 1.00000 2.00000 3.00000 4.00000 2.00000 3.00000 4.00000 5.00000 3.00000 4.00000 5.00000 6.00000

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.