]> https://gitweb.dealii.org/ - dealii.git/commitdiff
test double contraction
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Thu, 23 Aug 2012 16:57:57 +0000 (16:57 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Thu, 23 Aug 2012 16:57:57 +0000 (16:57 +0000)
git-svn-id: https://svn.dealii.org/trunk@26100 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/tensor_05.cc
tests/base/tensor_07.cc [new file with mode: 0644]
tests/base/tensor_07/cmp/generic [new file with mode: 0644]

index 41d7d6f35555fab52c5b10977c1d34e04c6247d6..91a918933ac59c09aceea0b6f9ca32164d7ad58b 100644 (file)
 
 int main ()
 {
-  std::ofstream logfile("tensor_05/output");
-  deallog << std::setprecision(3);
+  std::string logname = JobIdentifier::base_name(__FILE__) + std::string("/output");
+  std::ofstream logfile(logname.c_str());
   deallog.attach(logfile);
   deallog.depth_console(0);
+  deallog << std::setprecision(3);
   deallog.threshold_double(1.e-10);
 
   double a[3][3] = {{1, 2, 3}, {3, 4, 5}, {6, 7, 8}};
diff --git a/tests/base/tensor_07.cc b/tests/base/tensor_07.cc
new file mode 100644 (file)
index 0000000..442fe0a
--- /dev/null
@@ -0,0 +1,89 @@
+//----------------------------  tensor_05.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2006, 2012 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  tensor_05.cc  ---------------------------
+
+// check double_contract(Tensor<2,dim>,Tensor<2,dim>)
+
+#include "../tests.h"
+#include <deal.II/base/tensor.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <fstream>
+#include <iomanip>
+
+template <int dim>
+void test_constant()
+{
+  Tensor<2,dim> t;
+  for (unsigned int i=0;i<dim;++i)
+    for (unsigned int j=0;j<dim;++j)
+      t[i][j] = 2.;
+  deallog << "Constant dim " << dim << '\t' << double_contract(t,t)
+         << " compare " << 4*dim*dim << std::endl;
+}
+
+
+template <int dim>
+void test_equal()
+{
+  Tensor<2,dim> t;
+  unsigned int sum = 0;
+  for (unsigned int i=0;i<dim;++i)
+    for (unsigned int j=0;j<dim;++j)
+      {
+       t[i][j] = i+dim*j;
+       sum += (i+dim*j)*(i+dim*j);
+      }
+  
+  deallog << "Equal    dim " << dim << '\t' << double_contract(t,t)
+         << " compare " << sum << std::endl;
+}
+
+
+template <int dim>
+void test_unequal()
+{
+  Tensor<2,dim> s;
+  Tensor<2,dim> t;
+  unsigned int sum = 0;
+  for (unsigned int i=0;i<dim;++i)
+    for (unsigned int j=0;j<dim;++j)
+      {
+       s[i][j] = i+dim*j;
+       t[i][j] = dim*i+j;
+       sum += (i+dim*j)*(dim*i+j);
+      }
+  
+  deallog << "Unequal  dim " << dim << '\t' << double_contract(s,t)
+         << " compare " << sum << std::endl;
+}
+
+
+int main ()
+{
+  std::string logname = JobIdentifier::base_name(__FILE__) + std::string("/output");
+  std::ofstream logfile(logname.c_str());
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  test_constant<2>();
+  test_constant<3>();
+  test_constant<4>();
+
+  test_equal<2>();
+  test_equal<3>();
+  test_equal<4>();
+
+  test_unequal<2>();
+  test_unequal<3>();
+  test_unequal<4>();
+}
diff --git a/tests/base/tensor_07/cmp/generic b/tests/base/tensor_07/cmp/generic
new file mode 100644 (file)
index 0000000..4d35b35
--- /dev/null
@@ -0,0 +1,10 @@
+
+DEAL::Constant dim 2   16.0000 compare 16
+DEAL::Constant dim 3   36.0000 compare 36
+DEAL::Constant dim 4   64.0000 compare 64
+DEAL::Equal    dim 2   14.0000 compare 14
+DEAL::Equal    dim 3   204.000 compare 204
+DEAL::Equal    dim 4   1240.00 compare 1240
+DEAL::Unequal  dim 2   13.0000 compare 13
+DEAL::Unequal  dim 3   180.000 compare 180
+DEAL::Unequal  dim 4   1060.00 compare 1060

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.