Reference documentation for deal.II version 9.1.0-pre
fe_rt_bubbles.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/base/qprojector.h>
18 #include <deal.II/base/quadrature_lib.h>
19 #include <deal.II/base/std_cxx14/memory.h>
20 #include <deal.II/base/table.h>
21 
22 #include <deal.II/dofs/dof_accessor.h>
23 
24 #include <deal.II/fe/fe.h>
25 #include <deal.II/fe/fe_rt_bubbles.h>
26 #include <deal.II/fe/fe_tools.h>
27 #include <deal.II/fe/fe_values.h>
28 #include <deal.II/fe/mapping.h>
29 
30 #include <deal.II/grid/tria.h>
31 #include <deal.II/grid/tria_iterator.h>
32 
33 #include <sstream>
34 
35 
36 DEAL_II_NAMESPACE_OPEN
37 
38 
39 template <int dim>
40 FE_RT_Bubbles<dim>::FE_RT_Bubbles(const unsigned int deg)
42  deg,
43  FiniteElementData<dim>(get_dpo_vector(deg),
44  dim,
45  deg + 1,
46  FiniteElementData<dim>::Hdiv),
47  get_ria_vector(deg),
48  std::vector<ComponentMask>(PolynomialsRT_Bubbles<dim>::compute_n_pols(
49  deg),
50  std::vector<bool>(dim, true)))
51 {
52  Assert(dim >= 2, ExcImpossibleInDim(dim));
53  Assert(
54  deg >= 1,
55  ExcMessage(
56  "Lowest order RT_Bubbles element is degree 1, but you requested for degree 0"));
57  const unsigned int n_dofs = this->dofs_per_cell;
58 
60  // Initialize support points and quadrature weights
62  // Compute the inverse node matrix to get
63  // the correct basis functions
65  this->inverse_node_matrix.reinit(n_dofs, n_dofs);
66  this->inverse_node_matrix.invert(M);
67 
68  // Reinit the vectors of prolongation matrices to the
69  // right sizes. There are no restriction matrices implemented
70  for (unsigned int ref_case = RefinementCase<dim>::cut_x;
71  ref_case < RefinementCase<dim>::isotropic_refinement + 1;
72  ++ref_case)
73  {
74  const unsigned int nc =
76 
77  for (unsigned int i = 0; i < nc; ++i)
78  this->prolongation[ref_case - 1][i].reinit(n_dofs, n_dofs);
79  }
80  // Fill prolongation matrices with embedding operators
81  // set tolerance to 1, as embedding error accumulate quickly
82  FETools::compute_embedding_matrices(*this, this->prolongation, true, 1.0);
84  for (unsigned int i = 0; i < GeometryInfo<dim>::max_children_per_face; ++i)
85  face_embeddings[i].reinit(this->dofs_per_face, this->dofs_per_face);
86  FETools::compute_face_embedding_matrices<dim, double>(*this,
87  face_embeddings,
88  0,
89  0);
90  this->interface_constraints.reinit((1 << (dim - 1)) * this->dofs_per_face,
91  this->dofs_per_face);
92  unsigned int target_row = 0;
93  for (unsigned int d = 0; d < GeometryInfo<dim>::max_children_per_face; ++d)
94  for (unsigned int i = 0; i < face_embeddings[d].m(); ++i)
95  {
96  for (unsigned int j = 0; j < face_embeddings[d].n(); ++j)
97  this->interface_constraints(target_row, j) = face_embeddings[d](i, j);
98  ++target_row;
99  }
100 }
101 
102 
103 
104 template <int dim>
105 std::string
107 {
108  // Note: this->degree is the maximal polynomial degree and is thus one higher
109  // than the argument given to the constructor
110  std::ostringstream namebuf;
111  namebuf << "FE_RT_Bubbles<" << dim << ">(" << this->degree << ")";
112 
113  return namebuf.str();
114 }
115 
116 
117 
118 template <int dim>
119 std::unique_ptr<FiniteElement<dim, dim>>
121 {
122  return std_cxx14::make_unique<FE_RT_Bubbles<dim>>(*this);
123 }
124 
125 
126 //---------------------------------------------------------------------------
127 // Auxiliary and internal functions
128 //---------------------------------------------------------------------------
129 
130 
131 
132 template <int dim>
133 void
135 {
136  this->generalized_support_points.resize(this->dofs_per_cell);
138 
139  // Index of the point being entered
140  unsigned int current = 0;
141 
142  // On the faces, we choose as many Gauss-Lobatto points
143  // as required to determine the normal component uniquely.
144  // This is the deg of the RT_Bubble element plus one.
145  if (dim > 1)
146  {
147  QGaussLobatto<dim - 1> face_points(deg + 1);
148  Assert(face_points.size() == this->dofs_per_face, ExcInternalError());
149  for (unsigned int k = 0; k < this->dofs_per_face; ++k)
150  this->generalized_face_support_points[k] = face_points.point(k);
151  Quadrature<dim> faces =
153  for (unsigned int k = 0;
154  k < this->dofs_per_face * GeometryInfo<dim>::faces_per_cell;
155  ++k)
156  this->generalized_support_points[k] =
158  0, true, false, false, this->dofs_per_face));
159 
160  current = this->dofs_per_face * GeometryInfo<dim>::faces_per_cell;
161  }
162 
163  if (deg == 1)
164  return;
165 
166  // In the interior, we need anisotropic Gauss-Lobatto quadratures,
167  // one for each direction
168  QGaussLobatto<1> high(deg + 1);
169  std::vector<Point<1>> pts = high.get_points();
170  pts.erase(pts.begin());
171  pts.erase(pts.end() - 1);
172 
173  std::vector<double> wts(pts.size(), 1);
174  Quadrature<1> low(pts, wts);
175 
176  for (unsigned int d = 0; d < dim; ++d)
177  {
178  std::unique_ptr<QAnisotropic<dim>> quadrature;
179  switch (dim)
180  {
181  case 1:
182  quadrature = std_cxx14::make_unique<QAnisotropic<dim>>(high);
183  break;
184  case 2:
185  quadrature = std_cxx14::make_unique<QAnisotropic<dim>>(
186  ((d == 0) ? low : high), ((d == 1) ? low : high));
187  break;
188  case 3:
189  quadrature =
190  std_cxx14::make_unique<QAnisotropic<dim>>(((d == 0) ? low : high),
191  ((d == 1) ? low : high),
192  ((d == 2) ? low :
193  high));
194  break;
195  default:
196  Assert(false, ExcNotImplemented());
197  }
198 
199  for (unsigned int k = 0; k < quadrature->size(); ++k)
200  this->generalized_support_points[current++] = quadrature->point(k);
201  }
202  Assert(current == this->dofs_per_cell, ExcInternalError());
203 }
204 
205 
206 
207 template <int dim>
208 std::vector<unsigned int>
209 FE_RT_Bubbles<dim>::get_dpo_vector(const unsigned int deg)
210 {
211  // We have (deg+1)^(dim-1) DoFs per face...
212  unsigned int dofs_per_face = 1;
213  for (unsigned int d = 1; d < dim; ++d)
214  dofs_per_face *= deg + 1;
215 
216  // ...plus the interior DoFs for the total of dim*(deg+1)^dim
217  const unsigned int interior_dofs = dim * (deg - 1) * pow(deg + 1, dim - 1);
218 
219  std::vector<unsigned int> dpo(dim + 1);
220  dpo[dim - 1] = dofs_per_face;
221  dpo[dim] = interior_dofs;
222 
223  return dpo;
224 }
225 
226 
227 
228 template <>
229 std::vector<bool>
230 FE_RT_Bubbles<1>::get_ria_vector(const unsigned int)
231 {
232  Assert(false, ExcImpossibleInDim(1));
233  return std::vector<bool>();
234 }
235 
236 
237 
238 template <int dim>
239 std::vector<bool>
240 FE_RT_Bubbles<dim>::get_ria_vector(const unsigned int deg)
241 {
242  const unsigned int dofs_per_cell =
244  unsigned int dofs_per_face = deg + 1;
245  for (unsigned int d = 2; d < dim; ++d)
246  dofs_per_face *= deg + 1;
247  // All face dofs need to be non-additive, since they have
248  // continuity requirements. The interior dofs are
249  // made additive.
250  std::vector<bool> ret_val(dofs_per_cell, false);
251  for (unsigned int i = GeometryInfo<dim>::faces_per_cell * dofs_per_face;
252  i < dofs_per_cell;
253  ++i)
254  ret_val[i] = true;
255 
256  return ret_val;
257 }
258 
259 
260 
261 template <int dim>
262 void
264  const std::vector<Vector<double>> &support_point_values,
265  std::vector<double> & nodal_values) const
266 {
267  Assert(support_point_values.size() == this->generalized_support_points.size(),
268  ExcDimensionMismatch(support_point_values.size(),
269  this->generalized_support_points.size()));
270  Assert(nodal_values.size() == this->dofs_per_cell,
271  ExcDimensionMismatch(nodal_values.size(), this->dofs_per_cell));
272  Assert(support_point_values[0].size() == this->n_components(),
273  ExcDimensionMismatch(support_point_values[0].size(),
274  this->n_components()));
275 
276  // First do interpolation on faces. There, the component
277  // evaluated depends on the face direction and orientation.
278  unsigned int fbase = 0;
279  unsigned int f = 0;
280  for (; f < GeometryInfo<dim>::faces_per_cell;
281  ++f, fbase += this->dofs_per_face)
282  {
283  for (unsigned int i = 0; i < this->dofs_per_face; ++i)
284  {
285  nodal_values[fbase + i] = support_point_values[fbase + i](
287  }
288  }
289 
290  // The remaining points form dim chunks, one for each component.
291  const unsigned int istep = (this->dofs_per_cell - fbase) / dim;
292  Assert((this->dofs_per_cell - fbase) % dim == 0, ExcInternalError());
293 
294  f = 0;
295  while (fbase < this->dofs_per_cell)
296  {
297  for (unsigned int i = 0; i < istep; ++i)
298  {
299  nodal_values[fbase + i] = support_point_values[fbase + i](f);
300  }
301  fbase += istep;
302  ++f;
303  }
304  Assert(fbase == this->dofs_per_cell, ExcInternalError());
305 }
306 
307 
308 
309 // explicit instantiations
310 #include "fe_rt_bubbles.inst"
311 
312 
313 DEAL_II_NAMESPACE_CLOSE
virtual void convert_generalized_support_point_values_to_dof_values(const std::vector< Vector< double >> &support_point_values, std::vector< double > &nodal_values) const override
std::vector< Point< dim > > generalized_support_points
Definition: fe.h:2470
void compute_embedding_matrices(const FiniteElement< dim, spacedim > &fe, std::vector< std::vector< FullMatrix< number >>> &matrices, const bool isotropic_only=false, const double threshold=1.e-12)
FullMatrix< double > interface_constraints
Definition: fe.h:2445
static unsigned int compute_n_pols(const unsigned int degree)
virtual std::string get_name() const override
static std::vector< unsigned int > get_dpo_vector(const unsigned int degree)
const unsigned int degree
Definition: fe_base.h:313
STL namespace.
FullMatrix< double > compute_node_matrix(const FiniteElement< dim, spacedim > &fe)
std::vector< Point< dim-1 > > generalized_face_support_points
Definition: fe.h:2476
const Point< dim > & point(const unsigned int i) const
const std::vector< Point< dim > > & get_points() const
static::ExceptionBase & ExcMessage(std::string arg1)
static::ExceptionBase & ExcImpossibleInDim(int arg1)
std::vector< std::vector< FullMatrix< double > > > prolongation
Definition: fe.h:2433
void invert(const FullMatrix< number2 > &M)
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
#define Assert(cond, exc)
Definition: exceptions.h:1227
FE_RT_Bubbles(const unsigned int k)
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void initialize_support_points(const unsigned int rt_degree)
unsigned int n_components() const
const unsigned int dofs_per_cell
Definition: fe_base.h:297
virtual std::unique_ptr< FiniteElement< dim, dim > > clone() const override
static unsigned int n_children(const RefinementCase< dim > &refinement_case)
static Quadrature< dim > project_to_all_faces(const SubQuadrature &quadrature)
const unsigned int dofs_per_face
Definition: fe_base.h:290
static::ExceptionBase & ExcNotImplemented()
static::ExceptionBase & ExcInternalError()
static std::vector< bool > get_ria_vector(const unsigned int degree)