Reference documentation for deal.II version Git 354f154960 2021-01-18 17:44:59 +0100
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
q_collection.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2020 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 
24 
25 #include <memory>
26 #include <vector>
27 
29 
30 namespace hp
31 {
43  template <int dim>
44  class QCollection : public Subscriptor
45  {
46  public:
51  QCollection() = default;
52 
56  template <int dim_in>
57  QCollection(const QCollection<dim_in> &other);
58 
65  template <int dim_in>
66  explicit QCollection(const Quadrature<dim_in> &quadrature);
67 
74  template <class... QTypes>
75  explicit QCollection(const QTypes &... quadrature_objects);
76 
101  template <int dim_in>
102  void
103  push_back(const Quadrature<dim_in> &new_quadrature);
104 
111  const Quadrature<dim> &operator[](const unsigned int index) const;
112 
117  bool
118  operator==(const QCollection<dim> &q_collection) const;
119 
123  unsigned int
124  size() const;
125 
132  unsigned int
133  max_n_quadrature_points() const;
134 
139  std::size_t
140  memory_consumption() const;
141 
146 
147  private:
152  std::vector<std::shared_ptr<const Quadrature<dim>>> quadratures;
153  };
154 
155 
156 
157  /* --------------- inline functions ------------------- */
158 
159  template <int dim>
160  template <int dim_in>
162  {
163  for (unsigned int i = 0; i < other.size(); ++i)
164  push_back(other[i]);
165  }
166 
167 
168 
169  template <int dim>
170  template <class... QTypes>
171  QCollection<dim>::QCollection(const QTypes &... quadrature_objects)
172  {
173  // loop over all of the given arguments and add the quadrature objects to
174  // this collection. Inlining the definition of q_pointers causes internal
175  // compiler errors on GCC 7.1.1 so we define it separately:
176  if (is_base_of_all<Quadrature<dim>, QTypes...>::value)
177  {
178  const auto q_pointers = {
179  (reinterpret_cast<const Quadrature<dim> *>(&quadrature_objects))...};
180  for (const auto p : q_pointers)
181  push_back(*p);
182  }
183  else if (is_base_of_all<Quadrature<1>, QTypes...>::value)
184  {
185  const auto q_pointers = {
186  (reinterpret_cast<const Quadrature<1> *>(&quadrature_objects))...};
187  for (const auto p : q_pointers)
188  push_back(*p);
189  }
190  else
191  {
192  Assert(false, ExcNotImplemented());
193  }
194  }
195 
196 
197 
198  template <int dim>
199  inline unsigned int
201  {
202  return quadratures.size();
203  }
204 
205 
206 
207  template <int dim>
208  inline unsigned int
210  {
211  Assert(quadratures.size() > 0,
212  ExcMessage("You can't call this function for an empty collection"));
213 
214  unsigned int m = 0;
215  for (unsigned int i = 0; i < quadratures.size(); ++i)
216  if (quadratures[i]->size() > m)
217  m = quadratures[i]->size();
218 
219  return m;
220  }
221 
222 
223 
224  template <int dim>
225  inline const Quadrature<dim> &QCollection<dim>::
226  operator[](const unsigned int index) const
227  {
228  AssertIndexRange(index, quadratures.size());
229  return *quadratures[index];
230  }
231 
232 
233 
234  template <int dim>
235  inline bool
237  {
238  const unsigned int n_quadratures = size();
239  if (n_quadratures != q_collection.size())
240  return false;
241 
242  for (unsigned int i = 0; i < n_quadratures; ++i)
243  if (!(*quadratures[i] == q_collection[i]))
244  return false;
245 
246  return true;
247  }
248 
249 
250 
251  template <int dim>
252  template <int dim_in>
254  {
255  quadratures.push_back(std::make_shared<const Quadrature<dim>>(quadrature));
256  }
257 
258 
259 
260  template <int dim>
261  inline std::size_t
263  {
264  return (sizeof(*this) + MemoryConsumption::memory_consumption(quadratures));
265  }
266 
267 
268  template <int dim>
269  template <int dim_in>
270  inline void
272  {
273  quadratures.push_back(
274  std::make_shared<const Quadrature<dim>>(new_quadrature));
275  }
276 
277 } // namespace hp
278 
279 
281 
282 #endif
std::size_t memory_consumption() const
Definition: q_collection.h:262
#define AssertIndexRange(index, range)
Definition: exceptions.h:1691
QCollection()=default
std::vector< std::shared_ptr< const Quadrature< dim > > > quadratures
Definition: q_collection.h:152
const Quadrature< dim > & operator[](const unsigned int index) const
Definition: q_collection.h:226
static ::ExceptionBase & ExcMessage(std::string arg1)
unsigned int max_n_quadrature_points() const
Definition: q_collection.h:209
#define Assert(cond, exc)
Definition: exceptions.h:1466
#define DeclException0(Exception0)
Definition: exceptions.h:470
unsigned int size() const
Definition: q_collection.h:200
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:380
Definition: hp.h:117
void push_back(const Quadrature< dim_in > &new_quadrature)
Definition: q_collection.h:271
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:379
static ::ExceptionBase & ExcNoQuadrature()
static ::ExceptionBase & ExcNotImplemented()
bool operator==(const QCollection< dim > &q_collection) const
Definition: q_collection.h:236
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)