| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2005 - 2024 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_q_collection_h |
| 16 |
#define dealii_q_collection_h |
| 17 |
|
| 18 |
#include <deal.II/base/config.h> |
| 19 |
|
| 20 |
#include <deal.II/base/enable_observer_pointer.h> |
| 21 |
#include <deal.II/base/memory_consumption.h> |
| 22 |
#include <deal.II/base/quadrature.h> |
| 23 |
|
| 24 |
#include <deal.II/hp/collection.h> |
| 25 |
|
| 26 |
#include <memory> |
| 27 |
#include <vector> |
| 28 |
|
| 29 |
DEAL_II_NAMESPACE_OPEN |
| 30 |
|
| 31 |
namespace hp |
| 32 |
{ |
| 33 |
/** |
| 34 |
* This class implements a collection of quadrature objects in the same way |
| 35 |
* as the hp::FECollection implements a collection of finite element |
| 36 |
* classes. |
| 37 |
* |
| 38 |
* It implements the concepts stated in the |
| 39 |
* @ref hpcollection |
| 40 |
* topic described in the doxygen documentation. |
| 41 |
* |
| 42 |
* @ingroup hp hpcollection |
| 43 |
*/ |
| 44 |
template <int dim> |
| 45 |
class QCollection : public Collection<Quadrature<dim>> |
| 46 |
{ |
| 47 |
public: |
| 48 |
/** |
| 49 |
* Default constructor. Leads to an empty collection that can later be |
| 50 |
* filled using push_back(). |
| 51 |
*/ |
| 52 |
QCollection() = default; |
| 53 |
|
| 54 |
/** |
| 55 |
* Copy constructor. |
| 56 |
*/ |
| 57 |
template <int dim_in> |
| 58 |
QCollection(const QCollection<dim_in> &other); |
| 59 |
|
| 60 |
/** |
| 61 |
* Conversion constructor. This constructor creates a QCollection from a |
| 62 |
* single quadrature rule. More quadrature formulas can be added with |
| 63 |
* push_back(), if desired, though it would probably be clearer to add all |
| 64 |
* mappings the same way. |
| 65 |
*/ |
| 66 |
template <int dim_in> |
| 67 |
explicit QCollection(const Quadrature<dim_in> &quadrature); |
| 68 |
|
| 69 |
/** |
| 70 |
* Constructor. This constructor creates a QCollection from one or |
| 71 |
* more quadrature objects passed to the constructor. For this |
| 72 |
* call to be valid, all arguments need to be of types derived |
| 73 |
* from class Quadrature<dim>. |
| 74 |
*/ |
| 75 |
template <class... QTypes> |
| 76 |
explicit QCollection(const QTypes &...quadrature_objects); |
| 77 |
|
| 78 |
/** |
| 79 |
* Add a new quadrature rule to the QCollection. In most cases, you will |
| 80 |
* want to add quadrature rules in the same order as the elements were |
| 81 |
* added to the hp::FECollection for which this quadrature rule collection |
| 82 |
* is meant. If done this way, the hp::FEValues objects with which you will |
| 83 |
* use both hp::FECollection and hp::QCollection objects will automatically |
| 84 |
* choose corresponding elements and quadrature formulas. On the other hand, |
| 85 |
* it is possible to use arbitrary combinations of elements and quadrature |
| 86 |
* formulas in hp::FECollection and hp::QCollection objects when |
| 87 |
* specifically specifying appropriate indices in calls to |
| 88 |
* hp::FEValues::reinit() or hp::FEFaceValues::reinit(). In those cases, |
| 89 |
* there need not be a correspondence between elements of the |
| 90 |
* hp::FECollection and hp::QCollection objects; they need not even be of |
| 91 |
* the same size in this case. |
| 92 |
* |
| 93 |
* The same arguments about the order of elements of collections can, by |
| 94 |
* the way, also be made about the elements of hp::MappingCollection |
| 95 |
* objects. |
| 96 |
* |
| 97 |
* This class creates a copy of the given quadrature object, i.e., you can |
| 98 |
* do things like <tt>push_back(QGauss<dim>(3));</tt>. The internal copy |
| 99 |
* is later destroyed by this object upon destruction of the entire |
| 100 |
* collection. |
| 101 |
*/ |
| 102 |
template <int dim_in> |
| 103 |
void |
| 104 |
push_back(const Quadrature<dim_in> &new_quadrature); |
| 105 |
|
| 106 |
/** |
| 107 |
* Equality comparison operator. All stored Quadrature objects are compared |
| 108 |
* in order. |
| 109 |
*/ |
| 110 |
bool |
| 111 |
operator==(const QCollection<dim> &q_collection) const; |
| 112 |
|
| 113 |
/** |
| 114 |
* Return the maximum number of quadrature points over all the elements of |
| 115 |
* the collection. This is mostly useful to initialize arrays to allocate |
| 116 |
* the maximum amount of memory that may be used when re-sizing later on |
| 117 |
* to a articular quadrature formula from within this collection. |
| 118 |
*/ |
| 119 |
unsigned int |
| 120 |
max_n_quadrature_points() const; |
| 121 |
|
| 122 |
/** |
| 123 |
* Exception |
| 124 |
*/ |
| 125 |
DeclException0(ExcNoQuadrature); |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
/* --------------- inline functions ------------------- */ |
| 131 |
|
| 132 |
template <int dim> |
| 133 |
template <int dim_in> |
| 134 |
QCollection<dim>::QCollection(const QCollection<dim_in> &other) |
| 135 |
{ |
| 136 |
for (unsigned int i = 0; i < other.size(); ++i) |
| 137 |
push_back(other[i]); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
template <int dim> |
| 143 |
template <class... QTypes> |
| 144 |
QCollection<dim>::QCollection(const QTypes &...quadrature_objects) |
| 145 |
{ |
| 146 |
// loop over all of the given arguments and add the quadrature objects to |
| 147 |
// this collection. Inlining the definition of q_pointers causes internal |
| 148 |
// compiler errors on GCC 7.1.1 so we define it separately: |
| 149 |
if (is_base_of_all<Quadrature<dim>, QTypes...>::value) |
| 150 |
{ |
| 151 |
const auto q_pointers = { |
| 152 |
(reinterpret_cast<const Quadrature<dim> *>(&quadrature_objects))...}; |
| 153 |
for (const auto p : q_pointers) |
| 154 |
push_back(*p); |
| 155 |
} |
| 156 |
else if (is_base_of_all<Quadrature<1>, QTypes...>::value) |
| 157 |
{ |
| 158 |
const auto q_pointers = { |
| 159 |
(reinterpret_cast<const Quadrature<1> *>(&quadrature_objects))...}; |
| 160 |
for (const auto p : q_pointers) |
| 161 |
push_back(*p); |
| 162 |
} |
| 163 |
else |
| 164 |
{ |
| 165 |
DEAL_II_NOT_IMPLEMENTED(); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
template <int dim> |
| 172 |
inline unsigned int |
| 173 |
QCollection<dim>::max_n_quadrature_points() const |
| 174 |
{ |
| 175 |
Assert(this->size() > 0, |
| 176 |
ExcMessage("You can't call this function for an empty collection")); |
| 177 |
|
| 178 |
unsigned int max = 0; |
| 179 |
for (unsigned int i = 0; i < this->size(); ++i) |
| 180 |
max = std::max(max, this->operator[](i).size()); |
| 181 |
|
| 182 |
return max; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
template <int dim> |
| 188 |
inline bool |
| 189 |
QCollection<dim>::operator==(const QCollection<dim> &q_collection) const |
| 190 |
{ |
| 191 |
const unsigned int n_quadratures = this->size(); |
| 192 |
if (n_quadratures != q_collection.size()) |
| 193 |
return false; |
| 194 |
|
| 195 |
for (unsigned int i = 0; i < n_quadratures; ++i) |
| 196 |
if ((this->operator[](i) == q_collection[i]) == false) |
| 197 |
return false; |
| 198 |
|
| 199 |
return true; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
template <int dim> |
| 205 |
template <int dim_in> |
| 206 |
inline QCollection<dim>::QCollection(const Quadrature<dim_in> &quadrature) |
| 207 |
{ |
| 208 |
this->push_back(quadrature); |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
template <int dim> |
| 213 |
template <int dim_in> |
| 214 |
inline void |
| 215 |
QCollection<dim>::push_back(const Quadrature<dim_in> &new_quadrature) |
| 216 |
{ |
| 217 |
Collection<Quadrature<dim>>::push_back( |
| 218 |
std::make_shared<const Quadrature<dim>>(new_quadrature)); |
| 219 |
} |
| 220 |
|
| 221 |
} // namespace hp |
| 222 |
|
| 223 |
|
| 224 |
DEAL_II_NAMESPACE_CLOSE |
| 225 |
|
| 226 |
#endif |