From 8adaf35c6c9f0e97202dd9556ff94440ed0e9ed3 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 23 Jun 2016 12:14:26 -0500 Subject: [PATCH] Make all functions of SymmetricTensor compile. It turns out that some of the functions of SymmetricTensor did either not compile outright, did not compile for rank==4, or did not compile if the underlying scalar is a complex number. Make things work. --- include/deal.II/base/symmetric_tensor.h | 116 ++++++++++++++++++------ 1 file changed, 87 insertions(+), 29 deletions(-) diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index e5f7c20d72..e9e2f4174a 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -704,7 +704,7 @@ public: /** * Access to an element according to unrolled index. The function - * s.access_raw_entry(i) does the same as + * s.access_raw_entry(unrolled_index) does the same as * s[s.unrolled_to_component_indices(i)], but more efficiently. */ Number @@ -712,7 +712,7 @@ public: /** * Access to an element according to unrolled index. The function - * s.access_raw_entry(i) does the same as + * s.access_raw_entry(unrolled_index) does the same as * s[s.unrolled_to_component_indices(i)], but more efficiently. */ Number & @@ -1016,7 +1016,7 @@ inline SymmetricTensor & SymmetricTensor::operator = (const Number d) { - Assert (d==0, ExcMessage ("Only assignment with zero is allowed")); + Assert (d==Number(), ExcMessage ("Only assignment with zero is allowed")); (void) d; data = 0; @@ -1025,23 +1025,49 @@ SymmetricTensor::operator = (const Number d) } +namespace internal +{ + namespace SymmetricTensor + { + template + dealii::Tensor<2,dim,Number> + convert_to_tensor (const dealii::SymmetricTensor<2,dim,Number> &s) + { + Number t[dim][dim]; + + // diagonal entries are stored first + for (unsigned int d=0; d(t); + } + + + template + dealii::Tensor<4,dim,Number> + convert_to_tensor (const dealii::SymmetricTensor<4,dim,Number> &) + { + Assert (false, ExcNotImplemented()); + return dealii::Tensor<4,dim,Number>(); + } + } +} + + template inline SymmetricTensor:: operator Tensor () const { - Assert (rank == 2, ExcNotImplemented()); - Number t[dim][dim]; - for (unsigned int d=0; d(t); + return internal::SymmetricTensor::convert_to_tensor (*this); } @@ -1165,8 +1191,9 @@ inline std::size_t SymmetricTensor::memory_consumption () { - return - internal::SymmetricTensorAccessors::StorageType::memory_consumption (); + // all memory consists of statically allocated memory of the current + // object, no pointers + return sizeof(SymmetricTensor); } @@ -1187,7 +1214,7 @@ namespace internal case 2: return (data[0] * sdata[0] + data[1] * sdata[1] + - 2*data[2] * sdata[2]); + Number(2.) * data[2] * sdata[2]); default: // Start with the non-diagonal part to avoid some multiplications by // 2. @@ -1231,7 +1258,7 @@ namespace internal for (unsigned int d=0; d::operator [] (const TableIndices &indices + +namespace internal +{ + namespace SymmetricTensor + { + template + unsigned int + entry_to_indices (const dealii::SymmetricTensor<2,dim,Number> &, + const unsigned int index) + { + return index; + } + + + template + dealii::TableIndices<2> + entry_to_indices (const dealii::SymmetricTensor<4,dim,Number> &, + const unsigned int index) + { + return + internal::SymmetricTensorAccessors::StorageType<4,dim,Number>::base_tensor_type:: + unrolled_to_component_indices(index); + } + + } +} + + + template inline Number SymmetricTensor::access_raw_entry (const unsigned int index) const { AssertIndexRange (index, data.dimension); - return data[index]; + return data[internal::SymmetricTensor::entry_to_indices(*this, index)]; } @@ -1684,7 +1740,7 @@ Number & SymmetricTensor::access_raw_entry (const unsigned int index) { AssertIndexRange (index, data.dimension); - return data[index]; + return data[internal::SymmetricTensor::entry_to_indices(*this, index)]; } @@ -1704,19 +1760,21 @@ namespace internal break; case 2: return_value = std::sqrt(data[0]*data[0] + data[1]*data[1] + - 2*data[2]*data[2]); + Number(2.) * data[2]*data[2]); break; case 3: return_value = std::sqrt(data[0]*data[0] + data[1]*data[1] + - data[2]*data[2] + 2*data[3]*data[3] + - 2*data[4]*data[4] + 2*data[5]*data[5]); + data[2]*data[2] + + Number(2.) * data[3]*data[3] + + Number(2.) * data[4]*data[4] + + Number(2.) * data[5]*data[5]); break; default: return_value = Number(); for (unsigned int d=0; d &t) -t.data[0]*t.data[5]*t.data[5] -t.data[1]*t.data[4]*t.data[4] -t.data[2]*t.data[3]*t.data[3] - +2*t.data[3]*t.data[4]*t.data[5] ); + +Number(2.) * t.data[3]*t.data[4]*t.data[5] ); default: Assert (false, ExcNotImplemented()); return 0; -- 2.39.5