]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix invalid loop range in SymmetricTensor class constructor; add test 3678/head
authorJean-Paul Pelteret <jppelteret@gmail.com>
Fri, 16 Dec 2016 08:26:44 +0000 (09:26 +0100)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Sat, 17 Dec 2016 10:06:18 +0000 (11:06 +0100)
Fixes #3674

doc/news/changes/minor/20161216Jean-PaulPelteret [new file with mode: 0644]
include/deal.II/base/symmetric_tensor.h
tests/base/symmetric_tensor_36.cc [new file with mode: 0644]
tests/base/symmetric_tensor_36.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20161216Jean-PaulPelteret b/doc/news/changes/minor/20161216Jean-PaulPelteret
new file mode 100644 (file)
index 0000000..41a2252
--- /dev/null
@@ -0,0 +1,6 @@
+Fixed: The SymmetricTensor copy constructor that accepted another
+SymmetricTensor of a different number type had an error in its internal data
+initialization loop range. This bug was only triggered when copying rank-4
+tensors.
+<br>
+(Jean-Paul Pelteret, 2016/12/16)
index f5f9b69505c8783ef111e4f2bf6bf4a734e3a3b2..8e82632dadb1bce93db3db358f55a64a6975bc82 100644 (file)
@@ -986,7 +986,7 @@ inline
 SymmetricTensor<rank,dim,Number>::
 SymmetricTensor (const SymmetricTensor<rank,dim,OtherNumber> &initializer)
 {
-  for (unsigned int i=0; i<n_independent_components; ++i)
+  for (unsigned int i=0; i<base_tensor_type::dimension; ++i)
     data[i] = initializer.data[i];
 }
 
diff --git a/tests/base/symmetric_tensor_36.cc b/tests/base/symmetric_tensor_36.cc
new file mode 100644 (file)
index 0000000..43b0d33
--- /dev/null
@@ -0,0 +1,113 @@
+// ---------------------------------------------------------------------
+//
+// 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 the tensor copy constructors for different number types
+
+#include "../tests.h"
+#include <deal.II/base/symmetric_tensor.h>
+#include <deal.II/base/tensor.h>
+#include <deal.II/base/logstream.h>
+
+// These boost functions are bundled with deal.II
+#include <boost/type_traits.hpp>
+
+#include <complex>
+#include <fstream>
+#include <iomanip>
+#include <typeinfo>
+
+// Some number types cannot be converted to floats/doubles;
+// for example, complex numbers cannot be converted to primitive numbers
+// So in these cases we disable the test if NumberType1 cannot be constructed
+// from NumberType2
+template<int rank, int dim,
+         template<int,int,typename> class TensorType,
+         typename NumberType1,
+         typename NumberType2>
+typename boost::disable_if<boost::is_constructible<NumberType1,NumberType2>,void>::type
+test_tensor_constructor ()
+{}
+
+template<int rank, int dim,
+         template<int,int,typename> class TensorType,
+         typename NumberType1,
+         typename NumberType2>
+typename boost::enable_if<boost::is_constructible<NumberType1,NumberType2>,void>::type
+test_tensor_constructor ()
+{
+  deallog
+      << "Rank " << rank << ", "
+      << "Dim " << dim << ":"
+      << "  From " << typeid(NumberType2).name()
+      << "  To " << typeid(NumberType1).name()
+      << " ... "
+      << std::flush;
+  TensorType<rank,dim,NumberType2> tmp2;
+  TensorType<rank,dim,NumberType1> tmp1 (tmp2);
+  deallog << "OK" << std::endl;
+}
+
+template<int rank, int dim,
+         template<int,int,typename> class TensorType,
+         typename NumberType1>
+void
+test_fixed_NT_2()
+{
+  test_tensor_constructor<rank,dim,TensorType,NumberType1,float>();
+  test_tensor_constructor<rank,dim,TensorType,NumberType1,double>();
+  test_tensor_constructor<rank,dim,TensorType,NumberType1,std::complex<float> >();
+  test_tensor_constructor<rank,dim,TensorType,NumberType1,std::complex<double> >();
+}
+
+template<int rank, int dim,
+         template<int,int,typename> class TensorType>
+void
+test_fixed_NT_1()
+{
+  test_fixed_NT_2<rank,dim,TensorType,float>();
+  test_fixed_NT_2<rank,dim,TensorType,double>();
+  test_fixed_NT_2<rank,dim,TensorType,std::complex<float> >();
+  test_fixed_NT_2<rank,dim,TensorType,std::complex<double> >();
+}
+
+template<int rank, int dim>
+void
+test_fixed_TensorType()
+{
+  test_fixed_NT_1<rank,dim,Tensor>();
+  test_fixed_NT_1<rank,dim,SymmetricTensor>();
+}
+
+template<int dim>
+void
+test_fixed_rank()
+{
+  test_fixed_TensorType<2,dim>();
+  test_fixed_TensorType<4,dim>();
+}
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog << std::setprecision(5);
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  test_fixed_rank<2>();
+  test_fixed_rank<3>();
+
+  deallog << "All OK" << std::endl;
+}
diff --git a/tests/base/symmetric_tensor_36.output b/tests/base/symmetric_tensor_36.output
new file mode 100644 (file)
index 0000000..4ba392b
--- /dev/null
@@ -0,0 +1,98 @@
+
+DEAL::Rank 2, Dim 2:  From f  To f ... OK
+DEAL::Rank 2, Dim 2:  From d  To f ... OK
+DEAL::Rank 2, Dim 2:  From f  To d ... OK
+DEAL::Rank 2, Dim 2:  From d  To d ... OK
+DEAL::Rank 2, Dim 2:  From f  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 2:  From d  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 2:  From NSt3__17complexIfEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 2:  From NSt3__17complexIdEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 2:  From f  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 2:  From d  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 2:  From NSt3__17complexIfEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 2:  From NSt3__17complexIdEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 2:  From f  To f ... OK
+DEAL::Rank 2, Dim 2:  From d  To f ... OK
+DEAL::Rank 2, Dim 2:  From f  To d ... OK
+DEAL::Rank 2, Dim 2:  From d  To d ... OK
+DEAL::Rank 2, Dim 2:  From f  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 2:  From d  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 2:  From NSt3__17complexIfEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 2:  From NSt3__17complexIdEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 2:  From f  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 2:  From d  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 2:  From NSt3__17complexIfEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 2:  From NSt3__17complexIdEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 2:  From f  To f ... OK
+DEAL::Rank 4, Dim 2:  From d  To f ... OK
+DEAL::Rank 4, Dim 2:  From f  To d ... OK
+DEAL::Rank 4, Dim 2:  From d  To d ... OK
+DEAL::Rank 4, Dim 2:  From f  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 2:  From d  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 2:  From NSt3__17complexIfEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 2:  From NSt3__17complexIdEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 2:  From f  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 2:  From d  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 2:  From NSt3__17complexIfEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 2:  From NSt3__17complexIdEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 2:  From f  To f ... OK
+DEAL::Rank 4, Dim 2:  From d  To f ... OK
+DEAL::Rank 4, Dim 2:  From f  To d ... OK
+DEAL::Rank 4, Dim 2:  From d  To d ... OK
+DEAL::Rank 4, Dim 2:  From f  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 2:  From d  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 2:  From NSt3__17complexIfEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 2:  From NSt3__17complexIdEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 2:  From f  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 2:  From d  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 2:  From NSt3__17complexIfEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 2:  From NSt3__17complexIdEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 3:  From f  To f ... OK
+DEAL::Rank 2, Dim 3:  From d  To f ... OK
+DEAL::Rank 2, Dim 3:  From f  To d ... OK
+DEAL::Rank 2, Dim 3:  From d  To d ... OK
+DEAL::Rank 2, Dim 3:  From f  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 3:  From d  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 3:  From NSt3__17complexIfEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 3:  From NSt3__17complexIdEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 3:  From f  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 3:  From d  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 3:  From NSt3__17complexIfEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 3:  From NSt3__17complexIdEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 3:  From f  To f ... OK
+DEAL::Rank 2, Dim 3:  From d  To f ... OK
+DEAL::Rank 2, Dim 3:  From f  To d ... OK
+DEAL::Rank 2, Dim 3:  From d  To d ... OK
+DEAL::Rank 2, Dim 3:  From f  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 3:  From d  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 3:  From NSt3__17complexIfEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 3:  From NSt3__17complexIdEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 2, Dim 3:  From f  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 3:  From d  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 3:  From NSt3__17complexIfEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 2, Dim 3:  From NSt3__17complexIdEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 3:  From f  To f ... OK
+DEAL::Rank 4, Dim 3:  From d  To f ... OK
+DEAL::Rank 4, Dim 3:  From f  To d ... OK
+DEAL::Rank 4, Dim 3:  From d  To d ... OK
+DEAL::Rank 4, Dim 3:  From f  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 3:  From d  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 3:  From NSt3__17complexIfEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 3:  From NSt3__17complexIdEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 3:  From f  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 3:  From d  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 3:  From NSt3__17complexIfEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 3:  From NSt3__17complexIdEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 3:  From f  To f ... OK
+DEAL::Rank 4, Dim 3:  From d  To f ... OK
+DEAL::Rank 4, Dim 3:  From f  To d ... OK
+DEAL::Rank 4, Dim 3:  From d  To d ... OK
+DEAL::Rank 4, Dim 3:  From f  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 3:  From d  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 3:  From NSt3__17complexIfEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 3:  From NSt3__17complexIdEE  To NSt3__17complexIfEE ... OK
+DEAL::Rank 4, Dim 3:  From f  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 3:  From d  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 3:  From NSt3__17complexIfEE  To NSt3__17complexIdEE ... OK
+DEAL::Rank 4, Dim 3:  From NSt3__17complexIdEE  To NSt3__17complexIdEE ... OK
+DEAL::All 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.