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