From dd8046fd1b25ab6244ec0f5bf425969e3412c49d Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Thu, 25 Jan 2018 10:13:07 +0100 Subject: [PATCH] Introduce begin/end_raw and switch element access to const& --- doc/news/changes/minor/20180125DanielArndt | 5 + include/deal.II/base/symmetric_tensor.h | 84 +++++++++++-- include/deal.II/base/tensor.h | 134 +++++++++++++++++++++ 3 files changed, 213 insertions(+), 10 deletions(-) create mode 100644 doc/news/changes/minor/20180125DanielArndt diff --git a/doc/news/changes/minor/20180125DanielArndt b/doc/news/changes/minor/20180125DanielArndt new file mode 100644 index 0000000000..71160b03b1 --- /dev/null +++ b/doc/news/changes/minor/20180125DanielArndt @@ -0,0 +1,5 @@ +New: Tensor::begin_raw, Tensor::end_raw, SymmetricTensor::begin_raw +and SymmetricTensor::end_raw provide access to the underlying storage for Tensor +and SymmetricTensor. +
+(Daniel Arndt, 2018/01/25) diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index df62374d06..cc621fb730 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -603,6 +603,31 @@ public: explicit SymmetricTensor (const SymmetricTensor &initializer); + /** + * Return a pointer to the first element of the underlying storage. + */ + Number * + begin_raw(); + + /** + * Return a const pointer to the first element of the underlying storage. + */ + const Number * + begin_raw() const; + + /** + * Return a pointer to the element past the end of the underlying storage. + */ + Number * + end_raw(); + + /** + * Return a const pointer to the element past the end of the underlying + * storage. + */ + const Number * + end_raw() const; + /** * Assignment operator from symmetric tensors with different underlying scalar type. * This obviously requires that the @p OtherNumber type is convertible to @@ -707,9 +732,9 @@ public: Number &operator() (const TableIndices &indices); /** - * Return an element by value. + * Return a @p const reference to the value referred to by the argument. */ - Number operator() (const TableIndices &indices) const; + const Number &operator() (const TableIndices &indices) const; /** * Access the elements of a row of this symmetric tensor. This function is @@ -726,11 +751,11 @@ public: operator [] (const unsigned int row); /** - * Return an element by value. + * Return a @p const reference to the value referred to by the argument. * * Exactly the same as operator(). */ - Number + const Number & operator [] (const TableIndices &indices) const; /** @@ -746,7 +771,7 @@ public: * s.access_raw_entry(unrolled_index) does the same as * s[s.unrolled_to_component_indices(i)], but more efficiently. */ - Number + const Number & access_raw_entry (const unsigned int unrolled_index) const; /** @@ -1684,7 +1709,7 @@ namespace internal template inline - Number + const Number & symmetric_tensor_access (const TableIndices<2> &indices, const typename SymmetricTensorAccessors::StorageType<2,dim,Number>::base_tensor_type &data) { @@ -1833,7 +1858,7 @@ namespace internal template inline - Number + const Number & symmetric_tensor_access (const TableIndices<4> &indices, const typename SymmetricTensorAccessors::StorageType<4,dim,Number>::base_tensor_type &data) { @@ -1952,7 +1977,7 @@ SymmetricTensor::operator () (const TableIndices &indic template inline -Number +const Number & SymmetricTensor::operator () (const TableIndices &indices) const { @@ -2021,7 +2046,7 @@ SymmetricTensor::operator [] (const unsigned int row) template inline -Number +const Number & SymmetricTensor::operator [] (const TableIndices &indices) const { return operator()(indices); @@ -2039,6 +2064,45 @@ SymmetricTensor::operator [] (const TableIndices &indic +template +inline +Number * +SymmetricTensor::begin_raw() +{ + return std::addressof(this->access_raw_entry(0)); +} + + + +template +inline +const Number * +SymmetricTensor::begin_raw() const +{ + return std::addressof(this->access_raw_entry(0)); +} + + + +template +inline +Number * +SymmetricTensor::end_raw() +{ + return begin_raw()+n_independent_components; +} + + + +template +inline +const Number * +SymmetricTensor::end_raw() const +{ + return begin_raw()+n_independent_components; +} + + namespace internal { @@ -2070,7 +2134,7 @@ namespace internal template inline -Number +const Number & SymmetricTensor::access_raw_entry (const unsigned int index) const { AssertIndexRange (index, n_independent_components); diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 18a7821e46..1c25a60d21 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -151,6 +151,31 @@ public: template Tensor (const OtherNumber &initializer); + /** + * Return a pointer to the first element of the underlying storage. + */ + Number * + begin_raw(); + + /** + * Return a const pointer to the first element of the underlying storage. + */ + const Number * + begin_raw() const; + + /** + * Return a pointer to the element past the end of the underlying storage. + */ + Number * + end_raw(); + + /** + * Return a const pointer to the element past the end of the underlying + * storage. + */ + const Number * + end_raw() const; + /** * Return a reference to the encapsulated Number object. Since rank-0 * tensors are scalars, this is a natural operation. @@ -425,6 +450,30 @@ public: */ Number &operator [] (const TableIndices &indices); + /** + * Return a pointer to the first element of the underlying storage. + */ + Number * + begin_raw(); + + /** + * Return a const pointer to the first element of the underlying storage. + */ + const Number * + begin_raw() const; + + /** + * Return a pointer to the element past the end of the underlying storage. + */ + Number * + end_raw(); + + /** + * Return a pointer to the element past the end of the underlying storage. + */ + const Number * + end_raw() const; + /** * Assignment operator from tensors with different underlying scalar type. * This obviously requires that the @p OtherNumber type is convertible to @p @@ -653,6 +702,7 @@ DEAL_II_CUDA_HOST_DEV Tensor<0,dim,Number>::Tensor () } + template template inline @@ -662,6 +712,7 @@ Tensor<0,dim,Number>::Tensor (const OtherNumber &initializer) } + template template inline @@ -671,6 +722,47 @@ Tensor<0,dim,Number>::Tensor (const Tensor<0,dim,OtherNumber> &p) } + +template +inline +Number * +Tensor<0,dim,Number>::begin_raw() +{ + return std::addressof(value); +} + + + +template +inline +const Number * +Tensor<0,dim,Number>::begin_raw() const +{ + return std::addressof(value); +} + + + +template +inline +Number * +Tensor<0,dim,Number>::end_raw() +{ + return begin_raw()+n_independent_components; +} + + + +template +inline +const Number * +Tensor<0,dim,Number>::end_raw() const +{ + return begin_raw()+n_independent_components; +} + + + template inline DEAL_II_CUDA_HOST_DEV Tensor<0,dim,Number>::operator Number &() @@ -945,6 +1037,7 @@ Tensor::operator[] (const TableIndices &indices) const } + template inline Number & @@ -956,6 +1049,47 @@ Tensor::operator[] (const TableIndices &indices) } + +template +inline +Number * +Tensor::begin_raw() +{ + return std::addressof(this->operator[](this->unrolled_to_component_indices(0))); +} + + + +template +inline +const Number * +Tensor::begin_raw() const +{ + return std::addressof(this->operator[](this->unrolled_to_component_indices(0))); +} + + + +template +inline +Number * +Tensor::end_raw() +{ + return begin_raw()+n_independent_components; +} + + + +template +inline +const Number * +Tensor::end_raw() const +{ + return begin_raw()+n_independent_components; +} + + + template template inline -- 2.39.5