Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
q_collection.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2019 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_q_collection_h
17 #define dealii_q_collection_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/memory_consumption.h>
22 #include <deal.II/base/quadrature.h>
23 #include <deal.II/base/subscriptor.h>
24 
25 #include <deal.II/fe/fe.h>
26 
27 #include <memory>
28 #include <vector>
29 
30 DEAL_II_NAMESPACE_OPEN
31 
32 namespace hp
33 {
47  template <int dim>
48  class QCollection : public Subscriptor
49  {
50  public:
55  QCollection() = default;
56 
63  explicit QCollection(const Quadrature<dim> &quadrature);
64 
71  template <class... QTypes>
72  explicit QCollection(const QTypes &... quadrature_objects);
73 
98  void
99  push_back(const Quadrature<dim> &new_quadrature);
100 
107  const Quadrature<dim> &operator[](const unsigned int index) const;
108 
112  unsigned int
113  size() const;
114 
121  unsigned int
122  max_n_quadrature_points() const;
123 
128  std::size_t
129  memory_consumption() const;
130 
135 
136  private:
141  std::vector<std::shared_ptr<const Quadrature<dim>>> quadratures;
142  };
143 
144 
145 
146  /* --------------- inline functions ------------------- */
147 
148  template <int dim>
149  template <class... QTypes>
150  QCollection<dim>::QCollection(const QTypes &... quadrature_objects)
151  {
152  static_assert(is_base_of_all<Quadrature<dim>, QTypes...>::value,
153  "Not all of the input arguments of this function "
154  "are derived from Quadrature<dim>!");
155 
156  // loop over all of the given arguments and add the quadrature objects to
157  // this collection. Inlining the definition of q_pointers causes internal
158  // compiler errors on GCC 7.1.1 so we define it separately:
159  const auto q_pointers = {&quadrature_objects...};
160  for (const auto p : q_pointers)
161  push_back(*p);
162  }
163 
164 
165 
166  template <int dim>
167  inline unsigned int
169  {
170  return quadratures.size();
171  }
172 
173 
174 
175  template <int dim>
176  inline unsigned int
178  {
179  Assert(quadratures.size() > 0,
180  ExcMessage("You can't call this function for an empty collection"));
181 
182  unsigned int m = 0;
183  for (unsigned int i = 0; i < quadratures.size(); ++i)
184  if (quadratures[i]->size() > m)
185  m = quadratures[i]->size();
186 
187  return m;
188  }
189 
190 
191 
192  template <int dim>
193  inline const Quadrature<dim> &QCollection<dim>::
194  operator[](const unsigned int index) const
195  {
196  Assert(index < quadratures.size(),
197  ExcIndexRange(index, 0, quadratures.size()));
198  return *quadratures[index];
199  }
200 
201 
202 
203  template <int dim>
205  {
206  quadratures.push_back(std::make_shared<const Quadrature<dim>>(quadrature));
207  }
208 
209 
210 
211  template <int dim>
212  inline std::size_t
214  {
215  return (sizeof(*this) + MemoryConsumption::memory_consumption(quadratures));
216  }
217 
218 
219  template <int dim>
220  inline void
222  {
223  quadratures.push_back(
224  std::make_shared<const Quadrature<dim>>(new_quadrature));
225  }
226 
227 } // namespace hp
228 
229 
230 DEAL_II_NAMESPACE_CLOSE
231 
232 #endif
std::size_t memory_consumption() const
Definition: q_collection.h:213
QCollection()=default
std::vector< std::shared_ptr< const Quadrature< dim > > > quadratures
Definition: q_collection.h:141
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
const Quadrature< dim > & operator[](const unsigned int index) const
Definition: q_collection.h:194
static ::ExceptionBase & ExcMessage(std::string arg1)
unsigned int max_n_quadrature_points() const
Definition: q_collection.h:177
#define Assert(cond, exc)
Definition: exceptions.h:1407
#define DeclException0(Exception0)
Definition: exceptions.h:473
unsigned int size() const
Definition: q_collection.h:168
Definition: hp.h:117
static ::ExceptionBase & ExcNoQuadrature()
void push_back(const Quadrature< dim > &new_quadrature)
Definition: q_collection.h:221
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)