From ec7eabe691b609fd0ef8b9c3047a3f69913959f2 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Sun, 30 Jul 2017 17:37:20 +0200 Subject: [PATCH] Convert to std::unique_ptr --- include/deal.II/base/quadrature.h | 7 +- source/base/quadrature.cc | 95 +++++++------------ source/base/quadrature_lib.cc | 6 +- tests/base/quadrature_is_tensor_product.cc | 2 +- .../base/quadrature_is_tensor_product.output | 2 +- 5 files changed, 40 insertions(+), 72 deletions(-) diff --git a/include/deal.II/base/quadrature.h b/include/deal.II/base/quadrature.h index 4aebe91b02..50d578fbb0 100644 --- a/include/deal.II/base/quadrature.h +++ b/include/deal.II/base/quadrature.h @@ -22,6 +22,7 @@ #include #include #include +#include DEAL_II_NAMESPACE_OPEN @@ -130,7 +131,7 @@ public: /** * Copy constructor. */ - Quadrature (const Quadrature &q) = default; + Quadrature (const Quadrature &q); /** * Move constructor. Construct a new quadrature object by transferring the @@ -170,7 +171,7 @@ public: * Assignment operator. Copies contents of #weights and #quadrature_points * as well as size. */ - Quadrature &operator = (const Quadrature &) = default; + Quadrature &operator = (const Quadrature &); /** * Test for equality of two quadratures. @@ -261,7 +262,7 @@ protected: * Stores the one-dimensional tensor basis objects in case this object * can be represented by a tensor product. */ - typename std::conditional,dim>>::type tensor_basis; + std::unique_ptr,dim>> tensor_basis; }; diff --git a/source/base/quadrature.cc b/source/base/quadrature.cc index 7e6b090997..98aa8bada2 100644 --- a/source/base/quadrature.cc +++ b/source/base/quadrature.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -42,8 +43,7 @@ Quadrature::Quadrature (const unsigned int n_q) quadrature_points (n_q, Point()), weights (n_q, 0), is_tensor_product_flag (dim==1) -{ -} +{} @@ -91,16 +91,18 @@ Quadrature::Quadrature (const Point &point) : quadrature_points(std::vector > (1, point)), weights(std::vector (1, 1.)), - is_tensor_product_flag (true) + is_tensor_product_flag (true), + tensor_basis (new std::array, dim>()) { for (unsigned int i=0; i > quad_vec_1d (1, Point<1>(point[i])); - tensor_basis[i] = Quadrature<1>(quad_vec_1d, weights); + (*tensor_basis)[i] = Quadrature<1>(quad_vec_1d, weights); } } + template <> Quadrature<1>::Quadrature (const Point<1> &point) : @@ -111,6 +113,7 @@ Quadrature<1>::Quadrature (const Point<1> &point) } + template <> Quadrature<0>::Quadrature (const SubQuadrature &, const Quadrature<1> &) @@ -161,9 +164,10 @@ Quadrature::Quadrature (const SubQuadrature &q1, if (is_tensor_product_flag) { + tensor_basis.reset(new std::array, dim>()); for (unsigned int i=0; i, dim>()); for (unsigned int i=0; i +template Quadrature::Quadrature (const Quadrature &q) : Subscriptor(), @@ -275,65 +281,28 @@ Quadrature::Quadrature (const Quadrature &q) weights (q.weights), is_tensor_product_flag (q.is_tensor_product_flag) { - if (is_tensor_product_flag) - tensor_basis = q.tensor_basis; + if (dim>1 && is_tensor_product_flag) + tensor_basis = std_cxx14::make_unique, dim>> (*q.tensor_basis); } -template <> -Quadrature<1>::Quadrature (const Quadrature<1> &q) - : - Subscriptor(), - quadrature_points (q.quadrature_points), - weights (q.weights), - is_tensor_product_flag (q.is_tensor_product_flag) -{}*/ - - - -/*template +template Quadrature & Quadrature::operator= (const Quadrature &q) { weights = q.weights; quadrature_points = q.quadrature_points; is_tensor_product_flag = q.is_tensor_product_flag; - tensor_basis = q.tensor_basis; - return *this; -} - -template <> -Quadrature<1> & -Quadrature<1>::operator= (const Quadrature<1> &q) -{ - std::cout << tensor_basis << std::endl; - - Assert (q.size() == q.weights.size(), ExcInternalError()); - Assert (q.size() == q.quadrature_points.size(), ExcInternalError()); - for (unsigned int i=0; i1 && is_tensor_product_flag) { - std::cout << weights[i] << std::endl; - std::cout << quadrature_points[i] << std::endl; + if (tensor_basis == nullptr) + tensor_basis = std_cxx14::make_unique, dim>> (*q.tensor_basis); + else + *tensor_basis = *q.tensor_basis; } - - weights = q.weights; - quadrature_points = q.quadrature_points; - is_tensor_product_flag = q.is_tensor_product_flag; - tensor_basis = q.tensor_basis; return *this; -}*/ - +} @@ -365,8 +334,9 @@ Quadrature::get_tensor_basis () const Assert (this->is_tensor_product_flag == true, ExcMessage("This function only makes sense if " "this object represents a tensor product!")); + Assert (tensor_basis != nullptr, ExcInternalError()); - return tensor_basis; + return *tensor_basis; } @@ -398,14 +368,14 @@ QAnisotropic::QAnisotropic(const Quadrature<1> &qx) } Assert (k==this->size(), ExcInternalError()); this->is_tensor_product_flag = true; - //this->tensor_basis[0] = qx; } template -QAnisotropic::QAnisotropic(const Quadrature<1> &, - const Quadrature<1> &) +QAnisotropic::QAnisotropic(const Quadrature<1> &qx, + const Quadrature<1> &qy) + : Quadrature(qx.size()*qy.size()) { Assert (dim==2, ExcImpossibleInDim(dim)); } @@ -427,8 +397,8 @@ QAnisotropic<2>::QAnisotropic(const Quadrature<1> &qx, } Assert (k==this->size(), ExcInternalError()); this->is_tensor_product_flag = true; - this->tensor_basis[0] = qx; - this->tensor_basis[1] = qy; + const std::array, 2> q_array = {qx, qy}; + this->tensor_basis = std_cxx14::make_unique, 2>>(q_array); } @@ -462,9 +432,8 @@ QAnisotropic<3>::QAnisotropic(const Quadrature<1> &qx, } Assert (k==this->size(), ExcInternalError()); this->is_tensor_product_flag = true; - this->tensor_basis[0] = qx; - this->tensor_basis[1] = qy; - this->tensor_basis[2] = qz; + const std::array, 3> q_array = {qx, qy, qz}; + this->tensor_basis = std_cxx14::make_unique, 3>>(q_array); } diff --git a/source/base/quadrature_lib.cc b/source/base/quadrature_lib.cc index 23fc5b2ba6..afc11887f4 100644 --- a/source/base/quadrature_lib.cc +++ b/source/base/quadrature_lib.cc @@ -939,14 +939,12 @@ QSorted::QSorted(const Quadrature &quad) : std::placeholders::_1, std::placeholders::_2)); - this->quadrature_points = quad.get_points(); - Assert (quad.size() == quad.get_points().size(), ExcInternalError()); - Assert (quad.size() == quad.get_weights().size(), ExcInternalError()); - Assert (this->quadrature_points.size()==quad.size(), ExcInternalError()); for (unsigned int i=0; iweights[i] = quad.weight(permutation[i]); this->quadrature_points[i] = quad.point(permutation[i]); + if (permutation[i] != i) + this->is_tensor_product_flag = false; } } diff --git a/tests/base/quadrature_is_tensor_product.cc b/tests/base/quadrature_is_tensor_product.cc index 0f076b59f8..fec03146a3 100644 --- a/tests/base/quadrature_is_tensor_product.cc +++ b/tests/base/quadrature_is_tensor_product.cc @@ -76,7 +76,7 @@ print_is_tensor_product() deallog << "QGaussLobattoChebyshev<" << dim << ">: " << q_11.is_tensor_product() << std::endl; - QSorted q_16(QGauss(2)); + QSorted q_16(QGauss(3)); deallog << "QSorted<" << dim << ">: " << q_16.is_tensor_product() << std::endl; diff --git a/tests/base/quadrature_is_tensor_product.output b/tests/base/quadrature_is_tensor_product.output index ab53fc52fa..d355ebb8c2 100644 --- a/tests/base/quadrature_is_tensor_product.output +++ b/tests/base/quadrature_is_tensor_product.output @@ -11,7 +11,7 @@ DEAL::QWeddle<1>: true DEAL::QGaussChebyshev<1>: true DEAL::QGaussRadauChebyshev<1>: true DEAL::QGaussLobattoChebyshev<1>: true -DEAL::QSorted<1>: true +DEAL::QSorted<1>: false DEAL::QTelles<1>: true DEAL::QAnisotropic<1>: true DEAL::QGaussLog<1>: true -- 2.39.5