From 57a8b886d16e01c9508846799e1d5c3e82bf651c Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 9 May 2018 09:46:19 +0800 Subject: [PATCH] Simplify a function that returns an array. Previously, it used a reference to an array as an output argument. Now, we can just return a std::array<...,dim>. --- include/deal.II/base/polynomial_space.h | 23 ++++++------- include/deal.II/base/polynomials_p.h | 14 ++++---- source/base/polynomial_space.cc | 46 ++++++++++--------------- source/fe/fe_dgp_monomial.cc | 10 +++--- 4 files changed, 42 insertions(+), 51 deletions(-) diff --git a/include/deal.II/base/polynomial_space.h b/include/deal.II/base/polynomial_space.h index 929470015b..4784250620 100644 --- a/include/deal.II/base/polynomial_space.h +++ b/include/deal.II/base/polynomial_space.h @@ -213,12 +213,14 @@ protected: /** * Compute numbers in x, y and z direction. Given an index n in the - * d-dimensional polynomial space, compute the indices i,j,k such that + * d-dimensional polynomial space, return the indices i,j,k such that * pn(x,y,z) = * pi(x)pj(y)pk(z). + * + * In 1d and 2d, obviously only i and i,j are returned. */ - void compute_index (const unsigned int n, - unsigned int (&index)[dim>0?dim:1]) const; + std::array + compute_index (const unsigned int n) const; private: /** @@ -246,14 +248,11 @@ private: /* -------------- declaration of explicit specializations --- */ template <> -void PolynomialSpace<1>::compute_index(const unsigned int n, - unsigned int (&index)[1]) const; +std::array PolynomialSpace<1>::compute_index(const unsigned int n) const; template <> -void PolynomialSpace<2>::compute_index(const unsigned int n, - unsigned int (&index)[2]) const; +std::array PolynomialSpace<2>::compute_index(const unsigned int n) const; template <> -void PolynomialSpace<3>::compute_index(const unsigned int n, - unsigned int (&index)[3]) const; +std::array PolynomialSpace<3>::compute_index(const unsigned int n) const; @@ -304,10 +303,9 @@ template void PolynomialSpace::output_indices(StreamType &out) const { - unsigned int ix[dim]; for (unsigned int i=0; i ix = compute_index(i); out << i << "\t"; for (unsigned int d=0; d PolynomialSpace::compute_derivative (const unsigned int i, const Point &p) const { - unsigned int indices[dim]; - compute_index (i, indices); + const std::array indices = compute_index (i); double v [dim][order+1]; { diff --git a/include/deal.II/base/polynomials_p.h b/include/deal.II/base/polynomials_p.h index c89b0f47da..a1750700d2 100644 --- a/include/deal.II/base/polynomials_p.h +++ b/include/deal.II/base/polynomials_p.h @@ -71,9 +71,11 @@ public: /** * For the nth polynomial $p_n(x,y,z)=x^i y^j z^k$ this function * gives the degrees i,j,k in the x,y,z directions. + * + * In 1d and 2d, obviously only i and i,j are returned. */ - void directional_degrees(unsigned int n, - unsigned int (°rees)[dim]) const; + std::array + directional_degrees(unsigned int n) const; private: @@ -100,11 +102,11 @@ PolynomialsP::degree() const template -inline void -PolynomialsP::directional_degrees(unsigned int n, - unsigned int (°rees)[dim]) const +inline +std::array +PolynomialsP::directional_degrees(unsigned int n) const { - this->compute_index(n,degrees); + return this->compute_index(n); } DEAL_II_NAMESPACE_CLOSE diff --git a/source/base/polynomial_space.cc b/source/base/polynomial_space.cc index 664d29ef79..ddb9ef9835 100644 --- a/source/base/polynomial_space.cc +++ b/source/base/polynomial_space.cc @@ -43,24 +43,21 @@ PolynomialSpace<0>::compute_n_pols (const unsigned int) template <> -void +std::array PolynomialSpace<1>:: -compute_index (const unsigned int i, - unsigned int (&index)[1]) const +compute_index (const unsigned int i) const { Assert(i -void +std::array PolynomialSpace<2>:: -compute_index (const unsigned int i, - unsigned int (&index)[2]) const +compute_index (const unsigned int i) const { Assert(i -void +std::array PolynomialSpace<3>:: -compute_index (const unsigned int i, - unsigned int (&index)[3]) const +compute_index (const unsigned int i) const { Assert(i::compute_value (const unsigned int i, const Point &p) const { - unsigned int ix[dim]; - compute_index(i,ix); + const auto ix = compute_index(i); // take the product of the // polynomials in the various space // directions @@ -154,8 +146,7 @@ Tensor<1,dim> PolynomialSpace::compute_grad (const unsigned int i, const Point &p) const { - unsigned int ix[dim]; - compute_index(i,ix); + const auto ix = compute_index(i); Tensor<1,dim> result; for (unsigned int d=0; d PolynomialSpace::compute_grad_grad (const unsigned int i, const Point &p) const { - unsigned int ix[dim]; - compute_index(i,ix); + const auto ix = compute_index(i); Tensor<2,dim> result; for (unsigned int d=0; d::has_support_on_face (const unsigned int shape_index, support_on_face=true; else { - unsigned int degrees[2]; - this->poly_space.directional_degrees(shape_index, degrees); + const std::array degrees + = this->poly_space.directional_degrees(shape_index); + if ((face_index==0 && degrees[1]==0) || (face_index==3 && degrees[0]==0)) support_on_face=true; @@ -436,8 +437,9 @@ FE_DGPMonomial<3>::has_support_on_face (const unsigned int shape_index, support_on_face=true; else { - unsigned int degrees[3]; - this->poly_space.directional_degrees(shape_index, degrees); + const std::array degrees + = this->poly_space.directional_degrees(shape_index); + if ((face_index==0 && degrees[1]==0) || (face_index==2 && degrees[2]==0) || (face_index==5 && degrees[0]==0)) -- 2.39.5