]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test for contraction of complex-valued symmetric tensors. 2792/head
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Sat, 9 Jul 2016 02:09:19 +0000 (21:09 -0500)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Sat, 9 Jul 2016 02:09:19 +0000 (21:09 -0500)
tests/base/symmetric_tensor_33.cc [new file with mode: 0644]
tests/base/symmetric_tensor_33.output [new file with mode: 0644]

diff --git a/tests/base/symmetric_tensor_33.cc b/tests/base/symmetric_tensor_33.cc
new file mode 100644 (file)
index 0000000..112f047
--- /dev/null
@@ -0,0 +1,67 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 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.
+//
+// ---------------------------------------------------------------------
+
+// Check SymmetricTensor::norm() for complex-valued rank-2 tensors by
+// computing it via multiplication
+
+#include "../tests.h"
+#include <deal.II/base/symmetric_tensor.h>
+#include <deal.II/base/logstream.h>
+
+
+template <int rank, int dim>
+void check ()
+{
+  // build a regular tensor
+  SymmetricTensor<rank,dim> t, t_conj;
+
+  // build one in which all numbers are the same but purely imaginary
+  SymmetricTensor<rank,dim,std::complex<double> > ti, ti_conj;
+
+  // build one in which all numbers have both real and imaginary components
+  SymmetricTensor<rank,dim,std::complex<double> > tc, tc_conj;
+
+  for (unsigned int i=0; i<t.n_independent_components; ++i)
+    {
+      t.access_raw_entry(i)  = 1.0 * (i+1);
+      ti.access_raw_entry(i) = std::complex<double>(0,1.0*(i+1));
+      tc.access_raw_entry(i) = std::complex<double>(1.0*(i+1),1.0*(i+1));
+
+      t_conj.access_raw_entry(i)  = 1.0 * (i+1);
+      ti_conj.access_raw_entry(i) = std::complex<double>(0,-1.0*(i+1));
+      tc_conj.access_raw_entry(i) = std::complex<double>(1.0*(i+1),-1.0*(i+1));
+    }
+
+  deallog << t.norm() << " vs " << std::sqrt(t_conj*t) << std::endl
+          << ti.norm() << " vs " << std::sqrt(ti_conj*ti) << std::endl
+          << tc.norm() << " vs " << std::sqrt(tc_conj*tc) << std::endl
+          << std::endl;
+}
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog << std::setprecision(3);
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  deallog << "check rank 2 tensors" << std::endl;
+  check<2,1>();
+  check<2,2>();
+  check<2,3>();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/symmetric_tensor_33.output b/tests/base/symmetric_tensor_33.output
new file mode 100644 (file)
index 0000000..f3fd390
--- /dev/null
@@ -0,0 +1,15 @@
+
+DEAL::check rank 2 tensors
+DEAL::1.00 vs 1.00
+DEAL::1.00 vs (1.00,0.00)
+DEAL::1.41 vs (1.41,0.00)
+DEAL::
+DEAL::4.80 vs 4.80
+DEAL::4.80 vs (4.80,0.00)
+DEAL::6.78 vs (6.78,0.00)
+DEAL::
+DEAL::13.0 vs 13.0
+DEAL::13.0 vs (13.0,0.00)
+DEAL::18.3 vs (18.3,0.00)
+DEAL::
+DEAL::OK

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.