From 68aa36602039d5748624df870c0f4ce235a07cf1 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Fri, 16 Dec 2016 09:26:44 +0100 Subject: [PATCH] Fix invalid loop range in SymmetricTensor class constructor; add test Fixes #3674 --- .../changes/minor/20161216Jean-PaulPelteret | 6 + include/deal.II/base/symmetric_tensor.h | 2 +- tests/base/symmetric_tensor_36.cc | 113 ++++++++++++++++++ tests/base/symmetric_tensor_36.output | 98 +++++++++++++++ 4 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 doc/news/changes/minor/20161216Jean-PaulPelteret create mode 100644 tests/base/symmetric_tensor_36.cc create mode 100644 tests/base/symmetric_tensor_36.output diff --git a/doc/news/changes/minor/20161216Jean-PaulPelteret b/doc/news/changes/minor/20161216Jean-PaulPelteret new file mode 100644 index 0000000000..41a2252469 --- /dev/null +++ b/doc/news/changes/minor/20161216Jean-PaulPelteret @@ -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. +
+(Jean-Paul Pelteret, 2016/12/16) diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index f5f9b69505..8e82632dad 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -986,7 +986,7 @@ inline SymmetricTensor:: SymmetricTensor (const SymmetricTensor &initializer) { - for (unsigned int i=0; i +#include +#include + +// These boost functions are bundled with deal.II +#include + +#include +#include +#include +#include + +// 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 class TensorType, + typename NumberType1, + typename NumberType2> +typename boost::disable_if,void>::type +test_tensor_constructor () +{} + +template class TensorType, + typename NumberType1, + typename NumberType2> +typename boost::enable_if,void>::type +test_tensor_constructor () +{ + deallog + << "Rank " << rank << ", " + << "Dim " << dim << ":" + << " From " << typeid(NumberType2).name() + << " To " << typeid(NumberType1).name() + << " ... " + << std::flush; + TensorType tmp2; + TensorType tmp1 (tmp2); + deallog << "OK" << std::endl; +} + +template class TensorType, + typename NumberType1> +void +test_fixed_NT_2() +{ + test_tensor_constructor(); + test_tensor_constructor(); + test_tensor_constructor >(); + test_tensor_constructor >(); +} + +template class TensorType> +void +test_fixed_NT_1() +{ + test_fixed_NT_2(); + test_fixed_NT_2(); + test_fixed_NT_2 >(); + test_fixed_NT_2 >(); +} + +template +void +test_fixed_TensorType() +{ + test_fixed_NT_1(); + test_fixed_NT_1(); +} + +template +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 index 0000000000..4ba392bbc9 --- /dev/null +++ b/tests/base/symmetric_tensor_36.output @@ -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 -- 2.39.5