From ad3ee8a326d8aa00ece3baeb313ce2e9c5ed9c3a Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Mon, 16 Oct 2017 09:31:31 +0200 Subject: [PATCH] Add static member data for SymmetricTensor rank. --- include/deal.II/base/symmetric_tensor.h | 433 ++++++++++++------------ 1 file changed, 219 insertions(+), 214 deletions(-) diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index 99be8718cf..d39ee90e3b 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -528,11 +528,11 @@ namespace internal * @ingroup geomprimitives * @author Wolfgang Bangerth, 2005 */ -template +template class SymmetricTensor { public: - static_assert(rank%2==0, "A SymmetricTensor must have even rank!"); + static_assert(rank_%2==0, "A SymmetricTensor must have even rank!"); /** * Provide a way to get the dimension of an object without explicit @@ -544,13 +544,18 @@ public: */ static const unsigned int dimension = dim; + /** + * Publish the rank of this tensor to the outside world. + */ + static const unsigned int rank = rank_; + /** * An integer denoting the number of independent components that fully * describe a symmetric tensor. In $d$ space dimensions, this number equals * $\frac 12 (d^2+d)$ for symmetric tensors of rank 2. */ static const unsigned int n_independent_components - = internal::SymmetricTensorAccessors::StorageType:: + = internal::SymmetricTensorAccessors::StorageType:: n_independent_components; /** @@ -583,7 +588,7 @@ public: * rank 2. * * The size of the array passed is equal to - * SymmetricTensor::n_independent_component; the reason for using + * SymmetricTensor::n_independent_component; the reason for using * the object from the internal namespace is to work around bugs in some * older compilers. */ @@ -596,7 +601,7 @@ public: */ template explicit - SymmetricTensor (const SymmetricTensor &initializer); + SymmetricTensor (const SymmetricTensor &initializer); /** * Assignment operator from symmetric tensors with different underlying scalar type. @@ -604,7 +609,7 @@ public: * @p Number. */ template - SymmetricTensor &operator = (const SymmetricTensor &rhs); + SymmetricTensor &operator = (const SymmetricTensor &rhs); /** * This operator assigns a scalar to a tensor. To avoid confusion with what @@ -618,7 +623,7 @@ public: * Convert the present symmetric tensor into a full tensor with the same * elements, but using the different storage scheme of full tensors. */ - operator Tensor () const; + operator Tensor () const; /** * Test for equality of two tensors. @@ -634,13 +639,13 @@ public: * Add another tensor. */ template - SymmetricTensor &operator += (const SymmetricTensor &); + SymmetricTensor &operator += (const SymmetricTensor &); /** * Subtract another tensor. */ template - SymmetricTensor &operator -= (const SymmetricTensor &); + SymmetricTensor &operator -= (const SymmetricTensor &); /** * Scale the tensor by factor, i.e. multiply all components by @@ -685,7 +690,7 @@ public: * they write it into the first argument to the function. */ template - typename internal::SymmetricTensorAccessors::double_contraction_result::type + typename internal::SymmetricTensorAccessors::double_contraction_result::type operator * (const SymmetricTensor<2,dim,OtherNumber> &s) const; /** @@ -693,31 +698,31 @@ public: * symmetric tensor given as argument. */ template - typename internal::SymmetricTensorAccessors::double_contraction_result::type + typename internal::SymmetricTensorAccessors::double_contraction_result::type operator * (const SymmetricTensor<4,dim,OtherNumber> &s) const; /** * Return a read-write reference to the indicated element. */ - Number &operator() (const TableIndices &indices); + Number &operator() (const TableIndices &indices); /** * Return an element by value. */ - Number operator() (const TableIndices &indices) const; + Number operator() (const TableIndices &indices) const; /** * Access the elements of a row of this symmetric tensor. This function is * called for constant tensors. */ - internal::SymmetricTensorAccessors::Accessor + internal::SymmetricTensorAccessors::Accessor operator [] (const unsigned int row) const; /** * Access the elements of a row of this symmetric tensor. This function is * called for non-constant tensors. */ - internal::SymmetricTensorAccessors::Accessor + internal::SymmetricTensorAccessors::Accessor operator [] (const unsigned int row); /** @@ -726,7 +731,7 @@ public: * Exactly the same as operator(). */ Number - operator [] (const TableIndices &indices) const; + operator [] (const TableIndices &indices) const; /** * Return a read-write reference to the indicated element. @@ -734,7 +739,7 @@ public: * Exactly the same as operator(). */ Number & - operator [] (const TableIndices &indices); + operator [] (const TableIndices &indices); /** * Access to an element according to unrolled index. The function @@ -773,7 +778,7 @@ public: */ static unsigned int - component_to_unrolled_index (const TableIndices &indices); + component_to_unrolled_index (const TableIndices &indices); /** * The opposite of the previous function: given an index $i$ in the unrolled @@ -781,7 +786,7 @@ public: * tensors) or $(k,l,m,n)$ (for rank-4 tensors) corresponds to it. */ static - TableIndices + TableIndices unrolled_to_component_indices (const unsigned int i); /** @@ -816,7 +821,7 @@ private: * A structure that describes properties of the base tensor. */ typedef - internal::SymmetricTensorAccessors::StorageType + internal::SymmetricTensorAccessors::StorageType base_tensor_descriptor; /** @@ -875,10 +880,10 @@ namespace internal { namespace SymmetricTensorAccessors { - template - Accessor:: + template + Accessor:: Accessor (tensor_type &tensor, - const TableIndices &previous_indices) + const TableIndices &previous_indices) : tensor (tensor), previous_indices (previous_indices) @@ -886,30 +891,30 @@ namespace internal - template - Accessor - Accessor::operator[] (const unsigned int i) + template + Accessor + Accessor::operator[] (const unsigned int i) { - return Accessor (tensor, - merge (previous_indices, i, rank-P)); + return Accessor (tensor, + merge (previous_indices, i, rank_-P)); } - template - Accessor - Accessor::operator[] (const unsigned int i) const + template + Accessor + Accessor::operator[] (const unsigned int i) const { - return Accessor (tensor, - merge (previous_indices, i, rank-P)); + return Accessor (tensor, + merge (previous_indices, i, rank_-P)); } - template - Accessor:: + template + Accessor:: Accessor (tensor_type &tensor, - const TableIndices &previous_indices) + const TableIndices &previous_indices) : tensor (tensor), previous_indices (previous_indices) @@ -917,28 +922,28 @@ namespace internal - template - typename Accessor::reference - Accessor::operator[] (const unsigned int i) + template + typename Accessor::reference + Accessor::operator[] (const unsigned int i) { - return tensor(merge (previous_indices, i, rank-1)); + return tensor(merge (previous_indices, i, rank_-1)); } - template - typename Accessor::reference - Accessor::operator[] (const unsigned int i) const + template + typename Accessor::reference + Accessor::operator[] (const unsigned int i) const { - return tensor(merge (previous_indices, i, rank-1)); + return tensor(merge (previous_indices, i, rank_-1)); } } } -template +template inline -SymmetricTensor::SymmetricTensor () +SymmetricTensor::SymmetricTensor () { // Some auto-differentiable numbers need explicit // zero initialization. @@ -947,10 +952,10 @@ SymmetricTensor::SymmetricTensor () } -template +template template inline -SymmetricTensor::SymmetricTensor (const Tensor<2,dim,OtherNumber> &t) +SymmetricTensor::SymmetricTensor (const Tensor<2,dim,OtherNumber> &t) { Assert (rank == 2, ExcNotImplemented()); switch (dim) @@ -992,11 +997,11 @@ SymmetricTensor::SymmetricTensor (const Tensor<2,dim,OtherNumbe -template +template template inline -SymmetricTensor:: -SymmetricTensor (const SymmetricTensor &initializer) +SymmetricTensor:: +SymmetricTensor (const SymmetricTensor &initializer) { for (unsigned int i=0; i::value(initializer.data[i]); @@ -1005,9 +1010,9 @@ SymmetricTensor (const SymmetricTensor &initializer) -template +template inline -SymmetricTensor::SymmetricTensor (const Number (&array) [n_independent_components]) +SymmetricTensor::SymmetricTensor (const Number (&array) [n_independent_components]) : data (*reinterpret_cast(array)) { @@ -1019,11 +1024,11 @@ SymmetricTensor::SymmetricTensor (const Number (&array) [n_inde -template +template template inline -SymmetricTensor & -SymmetricTensor::operator = (const SymmetricTensor &t) +SymmetricTensor & +SymmetricTensor::operator = (const SymmetricTensor &t) { for (unsigned int i=0; i::operator = (const SymmetricTensor +template inline -SymmetricTensor & -SymmetricTensor::operator = (const Number &d) +SymmetricTensor & +SymmetricTensor::operator = (const Number &d) { Assert (d==internal::NumberType::value(0.0), ExcMessage ("Only assignment with zero is allowed")); (void) d; @@ -1362,44 +1367,44 @@ namespace internal -template +template inline -SymmetricTensor:: -operator Tensor () const +SymmetricTensor:: +operator Tensor () const { return internal::SymmetricTensor::convert_to_tensor (*this); } -template +template inline bool -SymmetricTensor::operator == -(const SymmetricTensor &t) const +SymmetricTensor::operator == +(const SymmetricTensor &t) const { return data == t.data; } -template +template inline bool -SymmetricTensor::operator != -(const SymmetricTensor &t) const +SymmetricTensor::operator != +(const SymmetricTensor &t) const { return data != t.data; } -template +template template inline -SymmetricTensor & -SymmetricTensor::operator += -(const SymmetricTensor &t) +SymmetricTensor & +SymmetricTensor::operator += +(const SymmetricTensor &t) { data += t.data; return *this; @@ -1407,12 +1412,12 @@ SymmetricTensor::operator += -template +template template inline -SymmetricTensor & -SymmetricTensor::operator -= -(const SymmetricTensor &t) +SymmetricTensor & +SymmetricTensor::operator -= +(const SymmetricTensor &t) { data -= t.data; return *this; @@ -1420,11 +1425,11 @@ SymmetricTensor::operator -= -template +template template inline -SymmetricTensor & -SymmetricTensor::operator *= (const OtherNumber &d) +SymmetricTensor & +SymmetricTensor::operator *= (const OtherNumber &d) { data *= d; return *this; @@ -1432,11 +1437,11 @@ SymmetricTensor::operator *= (const OtherNumber &d) -template +template template inline -SymmetricTensor & -SymmetricTensor::operator /= (const OtherNumber &d) +SymmetricTensor & +SymmetricTensor::operator /= (const OtherNumber &d) { data /= d; return *this; @@ -1444,10 +1449,10 @@ SymmetricTensor::operator /= (const OtherNumber &d) -template +template inline -SymmetricTensor -SymmetricTensor::operator - () const +SymmetricTensor +SymmetricTensor::operator - () const { SymmetricTensor tmp = *this; tmp.data = -tmp.data; @@ -1456,24 +1461,24 @@ SymmetricTensor::operator - () const -template +template inline void -SymmetricTensor::clear () +SymmetricTensor::clear () { data.clear (); } -template +template inline std::size_t -SymmetricTensor::memory_consumption () +SymmetricTensor::memory_consumption () { // all memory consists of statically allocated memory of the current // object, no pointers - return sizeof(SymmetricTensor); + return sizeof(SymmetricTensor); } @@ -1593,11 +1598,11 @@ namespace internal -template +template template inline -typename internal::SymmetricTensorAccessors::double_contraction_result::type -SymmetricTensor::operator * (const SymmetricTensor<2,dim,OtherNumber> &s) const +typename internal::SymmetricTensorAccessors::double_contraction_result::type +SymmetricTensor::operator * (const SymmetricTensor<2,dim,OtherNumber> &s) const { // need to have two different function calls // because a scalar and rank-2 tensor are not @@ -1608,14 +1613,14 @@ SymmetricTensor::operator * (const SymmetricTensor<2,dim,OtherN -template +template template inline -typename internal::SymmetricTensorAccessors::double_contraction_result::type -SymmetricTensor::operator * (const SymmetricTensor<4,dim,OtherNumber> &s) const +typename internal::SymmetricTensorAccessors::double_contraction_result::type +SymmetricTensor::operator * (const SymmetricTensor<4,dim,OtherNumber> &s) const { typename internal::SymmetricTensorAccessors:: - double_contraction_result::type tmp; + double_contraction_result::type tmp; tmp.data = internal::perform_double_contraction (data,s.data); return tmp; } @@ -1933,10 +1938,10 @@ namespace internal -template +template inline Number & -SymmetricTensor::operator () (const TableIndices &indices) +SymmetricTensor::operator () (const TableIndices &indices) { for (unsigned int r=0; r::operator () (const TableIndices &indices -template +template inline Number -SymmetricTensor::operator () -(const TableIndices &indices) const +SymmetricTensor::operator () +(const TableIndices &indices) const { for (unsigned int r=0; r - TableIndices + template + TableIndices get_partially_filled_indices (const unsigned int row, const std::integral_constant &) { - return TableIndices (row, - numbers::invalid_unsigned_int); + return TableIndices (row, + numbers::invalid_unsigned_int); } - template - TableIndices + template + TableIndices get_partially_filled_indices (const unsigned int row, const std::integral_constant &) { - return TableIndices (row, - numbers::invalid_unsigned_int, - numbers::invalid_unsigned_int, - numbers::invalid_unsigned_int); + return TableIndices (row, + numbers::invalid_unsigned_int, + numbers::invalid_unsigned_int, + numbers::invalid_unsigned_int); } } } -template -internal::SymmetricTensorAccessors::Accessor -SymmetricTensor::operator [] (const unsigned int row) const +template +internal::SymmetricTensorAccessors::Accessor +SymmetricTensor::operator [] (const unsigned int row) const { return internal::SymmetricTensorAccessors:: - Accessor (*this, - internal::SymmetricTensor::get_partially_filled_indices (row, - std::integral_constant())); + Accessor (*this, + internal::SymmetricTensor::get_partially_filled_indices (row, + std::integral_constant())); } -template -internal::SymmetricTensorAccessors::Accessor -SymmetricTensor::operator [] (const unsigned int row) +template +internal::SymmetricTensorAccessors::Accessor +SymmetricTensor::operator [] (const unsigned int row) { return internal::SymmetricTensorAccessors:: - Accessor (*this, - internal::SymmetricTensor::get_partially_filled_indices (row, - std::integral_constant())); + Accessor (*this, + internal::SymmetricTensor::get_partially_filled_indices (row, + std::integral_constant())); } -template +template inline Number -SymmetricTensor::operator [] (const TableIndices &indices) const +SymmetricTensor::operator [] (const TableIndices &indices) const { return operator()(indices); } -template +template inline Number & -SymmetricTensor::operator [] (const TableIndices &indices) +SymmetricTensor::operator [] (const TableIndices &indices) { return operator()(indices); } @@ -2063,10 +2068,10 @@ namespace internal -template +template inline Number -SymmetricTensor::access_raw_entry (const unsigned int index) const +SymmetricTensor::access_raw_entry (const unsigned int index) const { AssertIndexRange (index, n_independent_components); return data[internal::SymmetricTensor::entry_to_indices(*this, index)]; @@ -2074,10 +2079,10 @@ SymmetricTensor::access_raw_entry (const unsigned int index) co -template +template inline Number & -SymmetricTensor::access_raw_entry (const unsigned int index) +SymmetricTensor::access_raw_entry (const unsigned int index) { AssertIndexRange (index, n_independent_components); return data[internal::SymmetricTensor::entry_to_indices(*this, index)]; @@ -2166,10 +2171,10 @@ namespace internal -template +template inline typename numbers::NumberTraits::real_type -SymmetricTensor::norm () const +SymmetricTensor::norm () const { return internal::compute_norm (data); } @@ -2257,11 +2262,11 @@ namespace internal // // this function is for tensors of ranks not already handled // above - template + template inline unsigned int component_to_unrolled_index - (const TableIndices &indices) + (const TableIndices &indices) { (void)indices; Assert (false, ExcNotImplemented()); @@ -2272,11 +2277,11 @@ namespace internal } -template +template inline unsigned int -SymmetricTensor::component_to_unrolled_index -(const TableIndices &indices) +SymmetricTensor::component_to_unrolled_index +(const TableIndices &indices) { return internal::SymmetricTensor::component_to_unrolled_index (indices); } @@ -2360,42 +2365,42 @@ namespace internal // // this function is for tensors of a rank not already handled // above - template + template inline - TableIndices + TableIndices unrolled_to_component_indices (const unsigned int i, - const std::integral_constant &) + const std::integral_constant &) { (void)i; - Assert ((i < dealii::SymmetricTensor::n_independent_components), - ExcIndexRange(i, 0, dealii::SymmetricTensor::n_independent_components)); + Assert ((i < dealii::SymmetricTensor::n_independent_components), + ExcIndexRange(i, 0, dealii::SymmetricTensor::n_independent_components)); Assert (false, ExcNotImplemented()); - return TableIndices(); + return TableIndices(); } } } } -template +template inline -TableIndices -SymmetricTensor::unrolled_to_component_indices +TableIndices +SymmetricTensor::unrolled_to_component_indices (const unsigned int i) { return internal::SymmetricTensor::unrolled_to_component_indices (i, - std::integral_constant()); + std::integral_constant()); } -template +template template inline void -SymmetricTensor::serialize(Archive &ar, const unsigned int) +SymmetricTensor::serialize(Archive &ar, const unsigned int) { ar &data; } @@ -2418,13 +2423,13 @@ SymmetricTensor::serialize(Archive &ar, const unsigned int) * * @relates SymmetricTensor */ -template +template inline -SymmetricTensor::type> -operator+(const SymmetricTensor &left, - const SymmetricTensor &right) +SymmetricTensor::type> +operator+(const SymmetricTensor &left, + const SymmetricTensor &right) { - SymmetricTensor::type> tmp = left; + SymmetricTensor::type> tmp = left; tmp += right; return tmp; } @@ -2442,13 +2447,13 @@ operator+(const SymmetricTensor &left, * * @relates SymmetricTensor */ -template +template inline -SymmetricTensor::type> -operator-(const SymmetricTensor &left, - const SymmetricTensor &right) +SymmetricTensor::type> +operator-(const SymmetricTensor &left, + const SymmetricTensor &right) { - SymmetricTensor::type> tmp = left; + SymmetricTensor::type> tmp = left; tmp -= right; return tmp; } @@ -2461,13 +2466,13 @@ operator-(const SymmetricTensor &left, * * @relates SymmetricTensor */ -template +template inline -Tensor::type> -operator+(const SymmetricTensor &left, - const Tensor &right) +Tensor::type> +operator+(const SymmetricTensor &left, + const Tensor &right) { - return Tensor(left) + right; + return Tensor(left) + right; } @@ -2478,13 +2483,13 @@ operator+(const SymmetricTensor &left, * * @relates SymmetricTensor */ -template +template inline -Tensor::type> -operator+(const Tensor &left, - const SymmetricTensor &right) +Tensor::type> +operator+(const Tensor &left, + const SymmetricTensor &right) { - return left + Tensor(right); + return left + Tensor(right); } @@ -2495,13 +2500,13 @@ operator+(const Tensor &left, * * @relates SymmetricTensor */ -template +template inline -Tensor::type> -operator-(const SymmetricTensor &left, - const Tensor &right) +Tensor::type> +operator-(const SymmetricTensor &left, + const Tensor &right) { - return Tensor(left) - right; + return Tensor(left) - right; } @@ -2512,13 +2517,13 @@ operator-(const SymmetricTensor &left, * * @relates SymmetricTensor */ -template +template inline -Tensor::type> -operator-(const Tensor &left, - const SymmetricTensor &right) +Tensor::type> +operator-(const Tensor &left, + const SymmetricTensor &right) { - return left - Tensor(right); + return left - Tensor(right); } @@ -3118,10 +3123,10 @@ eigenvectors (const SymmetricTensor<2,dim,Number> &T, * @relates SymmetricTensor * @author Wolfgang Bangerth, 2005 */ -template +template inline -SymmetricTensor -transpose (const SymmetricTensor &t) +SymmetricTensor +transpose (const SymmetricTensor &t) { return t; } @@ -3457,13 +3462,13 @@ symmetrize (const Tensor<2,dim,Number> &t) * * @relates SymmetricTensor */ -template +template inline -SymmetricTensor -operator * (const SymmetricTensor &t, +SymmetricTensor +operator * (const SymmetricTensor &t, const Number &factor) { - SymmetricTensor tt = t; + SymmetricTensor tt = t; tt *= factor; return tt; } @@ -3477,11 +3482,11 @@ operator * (const SymmetricTensor &t, * * @relates SymmetricTensor */ -template +template inline -SymmetricTensor +SymmetricTensor operator * (const Number &factor, - const SymmetricTensor &t) + const SymmetricTensor &t) { // simply forward to the other operator return t*factor; @@ -3514,10 +3519,10 @@ operator * (const Number &factor, * @relates SymmetricTensor * @relates EnableIfScalar */ -template +template inline -SymmetricTensor::type>::type> -operator * (const SymmetricTensor &t, +SymmetricTensor::type>::type> +operator * (const SymmetricTensor &t, const OtherNumber &factor) { // form the product. we have to convert the two factors into the final @@ -3526,7 +3531,7 @@ operator * (const SymmetricTensor &t, // operator*(float,std::complex) // (as well as with switched arguments and double<->float). typedef typename ProductType::type product_type; - SymmetricTensor tt(t); + SymmetricTensor tt(t); // we used to shorten the following by 'tt *= product_type(factor);' // which requires that a converting constructor // 'product_type::product_type(const OtherNumber) is defined. @@ -3550,11 +3555,11 @@ operator * (const SymmetricTensor &t, * @relates SymmetricTensor * @relates EnableIfScalar */ -template +template inline -SymmetricTensor::type>::type> +SymmetricTensor::type>::type> operator * (const Number &factor, - const SymmetricTensor &t) + const SymmetricTensor &t) { // simply forward to the other operator with switched arguments return (t*factor); @@ -3567,13 +3572,13 @@ operator * (const Number &factor, * * @relates SymmetricTensor */ -template +template inline -SymmetricTensor::type>::type> -operator / (const SymmetricTensor &t, +SymmetricTensor::type>::type> +operator / (const SymmetricTensor &t, const OtherNumber &factor) { - SymmetricTensor::type> tt = t; + SymmetricTensor::type> tt = t; tt /= factor; return tt; } @@ -3586,13 +3591,13 @@ operator / (const SymmetricTensor &t, * * @relates SymmetricTensor */ -template +template inline -SymmetricTensor -operator * (const SymmetricTensor &t, +SymmetricTensor +operator * (const SymmetricTensor &t, const double factor) { - SymmetricTensor tt = t; + SymmetricTensor tt = t; tt *= factor; return tt; } @@ -3605,13 +3610,13 @@ operator * (const SymmetricTensor &t, * * @relates SymmetricTensor */ -template +template inline -SymmetricTensor +SymmetricTensor operator * (const double factor, - const SymmetricTensor &t) + const SymmetricTensor &t) { - SymmetricTensor tt = t; + SymmetricTensor tt = t; tt *= factor; return tt; } @@ -3623,13 +3628,13 @@ operator * (const double factor, * * @relates SymmetricTensor */ -template +template inline -SymmetricTensor -operator / (const SymmetricTensor &t, +SymmetricTensor +operator / (const SymmetricTensor &t, const double factor) { - SymmetricTensor tt = t; + SymmetricTensor tt = t; tt /= factor; return tt; } -- 2.39.5