Reference documentation for deal.II version 9.0.0
quadrature.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_quadrature_h
17 #define dealii_quadrature_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/point.h>
22 #include <deal.II/base/subscriptor.h>
23 #include <vector>
24 #include <array>
25 #include <memory>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
31 
82 template <int dim>
83 class Quadrature : public Subscriptor
84 {
85 public:
90  typedef Quadrature<dim-1> SubQuadrature;
91 
100  explicit Quadrature (const unsigned int n_quadrature_points = 0);
101 
110  Quadrature (const SubQuadrature &,
111  const Quadrature<1> &);
112 
129  explicit Quadrature (const Quadrature<dim != 1 ? 1 : 0> &quadrature_1d);
130 
134  Quadrature (const Quadrature<dim> &q);
135 
140  Quadrature (Quadrature<dim> &&) noexcept = default;
141 
147  Quadrature (const std::vector<Point<dim> > &points,
148  const std::vector<double> &weights);
149 
157  Quadrature (const std::vector<Point<dim> > &points);
158 
163  Quadrature (const Point<dim> &point);
164 
168  virtual ~Quadrature () = default;
169 
174  Quadrature &operator = (const Quadrature<dim> &);
175 
180  Quadrature &operator = (Quadrature<dim> &&) = default; // NOLINT
181 
185  bool operator == (const Quadrature<dim> &p) const;
186 
191  void initialize(const std::vector<Point<dim> > &points,
192  const std::vector<double> &weights);
193 
197  unsigned int size () const;
198 
202  const Point<dim> &point (const unsigned int i) const;
203 
207  const std::vector<Point<dim> > &get_points () const;
208 
212  double weight (const unsigned int i) const;
213 
217  const std::vector<double> &get_weights () const;
218 
223  std::size_t memory_consumption () const;
224 
229  template <class Archive>
230  void serialize (Archive &ar, const unsigned int version);
231 
237  bool is_tensor_product() const;
238 
244  typename std::conditional<dim==1, std::array<Quadrature<1>, dim>,const std::array<Quadrature<1>,dim>&>::type
245  get_tensor_basis() const;
246 
247 protected:
252  std::vector<Point<dim> > quadrature_points;
253 
258  std::vector<double> weights;
259 
268 
273  std::unique_ptr<std::array<Quadrature<1>,dim>> tensor_basis;
274 };
275 
276 
287 template <int dim>
288 class QAnisotropic : public Quadrature<dim>
289 {
290 public:
295  QAnisotropic(const Quadrature<1> &qx);
296 
300  QAnisotropic(const Quadrature<1> &qx,
301  const Quadrature<1> &qy);
302 
306  QAnisotropic(const Quadrature<1> &qx,
307  const Quadrature<1> &qy,
308  const Quadrature<1> &qz);
309 };
310 
311 
337 template <int dim>
338 class QIterated : public Quadrature<dim>
339 {
340 public:
345  QIterated (const Quadrature<1> &base_quadrature,
346  const unsigned int n_copies);
347 
351  DeclExceptionMsg (ExcInvalidQuadratureFormula,
352  "The quadrature formula you provided cannot be used "
353  "as the basis for iteration.");
354 };
355 
356 
357 
360 #ifndef DOXYGEN
361 
362 // ------------------- inline and template functions ----------------
363 
364 
365 template <int dim>
366 inline
367 unsigned int
368 Quadrature<dim>::size () const
369 {
370  return weights.size();
371 }
372 
373 
374 template <int dim>
375 inline
376 const Point<dim> &
377 Quadrature<dim>::point (const unsigned int i) const
378 {
379  AssertIndexRange(i, size());
380  return quadrature_points[i];
381 }
382 
383 
384 
385 template <int dim>
386 double
387 Quadrature<dim>::weight (const unsigned int i) const
388 {
389  AssertIndexRange(i, size());
390  return weights[i];
391 }
392 
393 
394 
395 template <int dim>
396 inline
397 const std::vector<Point<dim> > &
399 {
400  return quadrature_points;
401 }
402 
403 
404 
405 template <int dim>
406 inline
407 const std::vector<double> &
409 {
410  return weights;
411 }
412 
413 
414 
415 template <int dim>
416 inline
417 bool
419 {
420  return is_tensor_product_flag;
421 }
422 
423 
424 
425 template <int dim>
426 template <class Archive>
427 inline
428 void
429 Quadrature<dim>::serialize (Archive &ar, const unsigned int)
430 {
431  // forward to serialization
432  // function in the base class.
433  ar &static_cast<Subscriptor &>(*this);
434 
436 }
437 
438 
439 
440 /* -------------- declaration of explicit specializations ------------- */
441 
442 template <>
443 Quadrature<0>::Quadrature (const unsigned int);
444 template <>
446  const Quadrature<1> &);
447 template <>
449 
450 template <>
452  const Quadrature<1> &);
453 
454 template <>
456 
457 #endif // DOXYGEN
458 DEAL_II_NAMESPACE_CLOSE
459 
460 #endif
std::vector< double > weights
Definition: quadrature.h:258
const std::vector< Point< dim > > & get_points() const
const std::vector< double > & get_weights() const
Quadrature(const unsigned int n_quadrature_points=0)
Definition: quadrature.cc:41
#define AssertIndexRange(index, range)
Definition: exceptions.h:1284
const Point< dim > & point(const unsigned int i) const
STL namespace.
std::conditional< dim==1, std::array< Quadrature< 1 >, dim >, const std::array< Quadrature< 1 >, dim > & >::type get_tensor_basis() const
Definition: quadrature.cc:332
Definition: point.h:104
void initialize(const std::vector< Point< dim > > &points, const std::vector< double > &weights)
Definition: quadrature.cc:52
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:335
std::size_t memory_consumption() const
Definition: quadrature.cc:322
Quadrature< dim-1 > SubQuadrature
Definition: quadrature.h:90
std::unique_ptr< std::array< Quadrature< 1 >, dim > > tensor_basis
Definition: quadrature.h:273
bool is_tensor_product_flag
Definition: quadrature.h:267
std::vector< Point< dim > > quadrature_points
Definition: quadrature.h:252
unsigned int size() const
void serialize(Archive &ar, const unsigned int version)
bool is_tensor_product() const
double weight(const unsigned int i) const