From 2bbe643e491ff370943a5336bf8ca826ee6176dd Mon Sep 17 00:00:00 2001 From: danshapero Date: Thu, 7 Apr 2016 12:47:11 -0700 Subject: [PATCH] Added default constructor to Quadrature --- doc/news/changes.h | 7 +- include/deal.II/base/quadrature.h | 11 +++ include/deal.II/base/quadrature_lib.h | 16 ++++ tests/base/quadrature_move.cc | 82 +++++++++++++++++++ .../base/quadrature_move.with_cxx11=on.output | 18 ++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 tests/base/quadrature_move.cc create mode 100644 tests/base/quadrature_move.with_cxx11=on.output diff --git a/doc/news/changes.h b/doc/news/changes.h index 241d096123..c3b790306a 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -116,7 +116,12 @@ inconvenience this causes.
(Daniel Arndt, 2016/04/08) - + +
  • New: A move constructor has been added to Quadrature. +
    + (Daniel Shapero, 2016/04/08) +
  • +
  • Fixed: The multigrid transfer performed invalid data accesses on multigrid hierarchies that define the coarse level as a level larger than 0. This has been fixed. diff --git a/include/deal.II/base/quadrature.h b/include/deal.II/base/quadrature.h index 227fb4f75c..1a1413a8aa 100644 --- a/include/deal.II/base/quadrature.h +++ b/include/deal.II/base/quadrature.h @@ -125,6 +125,17 @@ public: */ Quadrature (const Quadrature &q); +#ifdef DEAL_II_WITH_CXX11 + /** + * Move constructor. Construct a new quadrature object by transferring the + * internal data of another quadrature object. + * + * @note this constructor is only available if deal.II is configured with + * C++11 support. + */ + Quadrature (Quadrature &&) = default; +#endif + /** * Construct a quadrature formula from given vectors of quadrature points * (which should really be in the unit cell) and the corresponding weights. diff --git a/include/deal.II/base/quadrature_lib.h b/include/deal.II/base/quadrature_lib.h index 1c39bbeed1..96e3950946 100644 --- a/include/deal.II/base/quadrature_lib.h +++ b/include/deal.II/base/quadrature_lib.h @@ -294,6 +294,14 @@ public: const double alpha = 1, const bool factor_out_singular_weight=false); +#ifdef DEAL_II_WITH_CXX11 + /** + * Move constructor. We cannot rely on the move constructor for `Quadrature`, + * since it does not know about the additional member `fraction` of this class. + */ + QGaussLogR(QGaussLogR &&) = default; +#endif + protected: /** * This is the length of interval $(0,origin)$, or 1 if either of the two @@ -577,6 +585,14 @@ public: QGaussRadauChebyshev(const unsigned int n, EndPoint ep=QGaussRadauChebyshev::left); +#ifdef DEAL_II_WITH_CXX11 + /** + * Move constructor. We cannot rely on the move constructor for `Quadrature`, + * since it does not know about the additional member `ep` of this class. + */ + QGaussRadauChebyshev(QGaussRadauChebyshev &&) = default; +#endif + private: const EndPoint ep; /// Computes the points of the quadrature formula. diff --git a/tests/base/quadrature_move.cc b/tests/base/quadrature_move.cc new file mode 100644 index 0000000000..eb0fec704b --- /dev/null +++ b/tests/base/quadrature_move.cc @@ -0,0 +1,82 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 1998 - 2015 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +#include "../tests.h" +#include +#include + +#include + + +template +std::string check_q_move(Args &&...args) +{ + Quad quad1(args...); + const unsigned int size1 = quad1.size(); + + std::vector weights1 = quad1.get_weights(); + + Quad quad2(std::move(quad1)); + const unsigned int size2 = quad2.size(); + + std::vector weights2 = quad2.get_weights(); + + if (size1 != size2) return "NOPE"; + + for (unsigned short i = 0; i < size1; ++i) + if (std::fabs(weights1[i] - weights2[i]) > 1.0e-16) + return "NOPE"; + + return "OK"; +} + + +template