From c0e08cbec7cffddd5107396fefcf0a554a96020e Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Wed, 4 Mar 2020 10:39:48 -0600 Subject: [PATCH] simplify code --- examples/step-69/step-69.cc | 58 ++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/examples/step-69/step-69.cc b/examples/step-69/step-69.cc index 9b60e7b915..3da38595cb 100644 --- a/examples/step-69/step-69.cc +++ b/examples/step-69/step-69.cc @@ -828,13 +828,13 @@ namespace Step69 // have to create a temporary SparseMatrix iterator. We simply hide // this in the get_entry() function. - template - DEAL_II_ALWAYS_INLINE inline typename Matrix::value_type - get_entry(const Matrix &matrix, const Iterator &it) + template + DEAL_II_ALWAYS_INLINE inline SparseMatrix::value_type + get_entry(const SparseMatrix &matrix, const IteratorType &it) { - const auto global_index = it->global_index(); - const typename Matrix::const_iterator matrix_iterator(&matrix, - global_index); + const auto global_index = it->global_index(); + const SparseMatrix::const_iterator matrix_iterator(&matrix, + global_index); return matrix_iterator->value(); } @@ -842,14 +842,14 @@ namespace Step69 // get_value(): Given an iterator and a value, it sets the // entry pointed to by the iterator in the matrix. - template + template DEAL_II_ALWAYS_INLINE inline void - set_entry(Matrix & matrix, - const Iterator & it, - typename Matrix::value_type value) + set_entry(SparseMatrix & matrix, + const IteratorType & it, + SparseMatrix::value_type value) { - const auto global_index = it->global_index(); - typename Matrix::iterator matrix_iterator(&matrix, global_index); + const auto global_index = it->global_index(); + SparseMatrix::iterator matrix_iterator(&matrix, global_index); matrix_iterator->value() = value; } @@ -862,13 +862,14 @@ namespace Step69 // gather_get_entry() is to retrieve those entries and store // them into a Tensor<1, dim> for our convenience. - template + template DEAL_II_ALWAYS_INLINE inline Tensor<1, k> - gather_get_entry(const std::array &U, const T2 it) + gather_get_entry(const std::array, k> &c_ij, + const IteratorType it) { Tensor<1, k> result; for (unsigned int j = 0; j < k; ++j) - result[j] = get_entry(U[j], it); + result[j] = get_entry(c_ij[j], it); return result; } @@ -893,13 +894,15 @@ namespace Step69 // constant complexity, which is the case of the current implementation // using deal.II matrices. - template + template DEAL_II_ALWAYS_INLINE inline Tensor<1, k> - gather(const std::array &U, const T2 i, const T3 l) + gather(const std::array, k> &n_ij, + const unsigned int i, + const unsigned int j) { Tensor<1, k> result; - for (unsigned int j = 0; j < k; ++j) - result[j] = U[j](i, l); + for (unsigned int l = 0; l < k; ++l) + result[l] = n_ij[l](i, j); return result; } @@ -908,9 +911,10 @@ namespace Step69 // state at a node i and return it as a // Tensor<1,problem_dimension> for our convenience. - template - DEAL_II_ALWAYS_INLINE inline Tensor<1, k> gather(const std::array &U, - const T2 i) + template + DEAL_II_ALWAYS_INLINE inline Tensor<1, k> + gather(const std::array, k> &U, + const unsigned int i) { Tensor<1, k> result; for (unsigned int j = 0; j < k; ++j) @@ -926,12 +930,14 @@ namespace Step69 // primarily used to write the updated nodal values, stored as // Tensor<1,problem_dimension>, into the global objects. - template + template DEAL_II_ALWAYS_INLINE inline void - scatter(std::array &U, const T2 &result, const T3 i) + scatter(std::array, k> &U, + const Tensor<1, ((identity::type)k)> & tensor, + const unsigned int i) { - for (unsigned int j = 0; j < k1; ++j) - U[j].local_element(i) = result[j]; + for (unsigned int j = 0; j < k; ++j) + U[j].local_element(i) = tensor[j]; } } // namespace -- 2.39.5