Reference documentation for deal.II version 9.1.0-pre
fe_bdm.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2017 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/polynomials_p.h>
18 #include <deal.II/base/qprojector.h>
19 #include <deal.II/base/quadrature_lib.h>
20 #include <deal.II/base/std_cxx14/memory.h>
21 #include <deal.II/base/table.h>
22 
23 #include <deal.II/dofs/dof_accessor.h>
24 
25 #include <deal.II/fe/fe.h>
26 #include <deal.II/fe/fe_bdm.h>
27 #include <deal.II/fe/fe_tools.h>
28 #include <deal.II/fe/fe_values.h>
29 #include <deal.II/fe/mapping.h>
30 
31 #include <deal.II/grid/tria.h>
32 #include <deal.II/grid/tria_iterator.h>
33 
34 #include <iostream>
35 #include <sstream>
36 
37 
38 DEAL_II_NAMESPACE_OPEN
39 
40 template <int dim>
41 FE_BDM<dim>::FE_BDM(const unsigned int deg)
42  : FE_PolyTensor<PolynomialsBDM<dim>, dim>(
43  deg,
44  FiniteElementData<dim>(get_dpo_vector(deg),
45  dim,
46  deg + 1,
47  FiniteElementData<dim>::Hdiv),
48  get_ria_vector(deg),
49  std::vector<ComponentMask>(PolynomialsBDM<dim>::compute_n_pols(deg),
50  std::vector<bool>(dim, true)))
51 {
52  Assert(dim >= 2, ExcImpossibleInDim(dim));
53  Assert(
54  deg > 0,
55  ExcMessage(
56  "Lowest order BDM element are degree 1, but you asked for degree 0"));
57 
58  const unsigned int n_dofs = this->dofs_per_cell;
59 
60  this->mapping_type = mapping_bdm;
61  // These must be done first, since
62  // they change the evaluation of
63  // basis functions
64 
65  // Set up the generalized support
66  // points
68 
69  // Now compute the inverse node matrix, generating the correct
70  // basis functions from the raw ones. For a discussion of what
71  // exactly happens here, see FETools::compute_node_matrix.
73  this->inverse_node_matrix.reinit(n_dofs, n_dofs);
74  this->inverse_node_matrix.invert(M);
75  // From now on, the shape functions provided by FiniteElement::shape_value
76  // and similar functions will be the correct ones, not
77  // the raw shape functions from the polynomial space anymore.
78 
79  // Embedding errors become pretty large, so we just replace the
80  // regular threshold in both "computing_..." functions by 1.
82  FETools::compute_embedding_matrices(*this, this->prolongation, true, 1.);
83 
85  for (unsigned int i = 0; i < GeometryInfo<dim>::max_children_per_face; ++i)
86  face_embeddings[i].reinit(this->dofs_per_face, this->dofs_per_face);
87  FETools::compute_face_embedding_matrices(*this, face_embeddings, 0, 0, 1.);
88  this->interface_constraints.reinit((1 << (dim - 1)) * this->dofs_per_face,
89  this->dofs_per_face);
90  unsigned int target_row = 0;
91  for (unsigned int d = 0; d < GeometryInfo<dim>::max_children_per_face; ++d)
92  for (unsigned int i = 0; i < face_embeddings[d].m(); ++i)
93  {
94  for (unsigned int j = 0; j < face_embeddings[d].n(); ++j)
95  this->interface_constraints(target_row, j) = face_embeddings[d](i, j);
96  ++target_row;
97  }
98 }
99 
100 
101 
102 template <int dim>
103 std::string
105 {
106  // note that the
107  // FETools::get_fe_by_name
108  // function depends on the
109  // particular format of the string
110  // this function returns, so they
111  // have to be kept in synch
112 
113  // note that this->degree is the maximal
114  // polynomial degree and is thus one higher
115  // than the argument given to the
116  // constructor
117  std::ostringstream namebuf;
118  namebuf << "FE_BDM<" << dim << ">(" << this->degree - 1 << ")";
119 
120  return namebuf.str();
121 }
122 
123 
124 template <int dim>
125 std::unique_ptr<FiniteElement<dim, dim>>
127 {
128  return std_cxx14::make_unique<FE_BDM<dim>>(*this);
129 }
130 
131 
132 
133 template <int dim>
134 void
136  const std::vector<Vector<double>> &support_point_values,
137  std::vector<double> & nodal_values) const
138 {
139  Assert(support_point_values.size() == this->generalized_support_points.size(),
140  ExcDimensionMismatch(support_point_values.size(),
141  this->generalized_support_points.size()));
142  AssertDimension(support_point_values[0].size(), dim);
143  Assert(nodal_values.size() == this->dofs_per_cell,
144  ExcDimensionMismatch(nodal_values.size(), this->dofs_per_cell));
145 
146  // First do interpolation on faces. There, the component evaluated
147  // depends on the face direction and orientation.
148 
149  // The index of the first dof on this face or the cell
150  unsigned int dbase = 0;
151  // The index of the first generalized support point on this face or the cell
152  unsigned int pbase = 0;
153  for (unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell; ++f)
154  {
155  // Old version with no moments in 2D. See comment below in
156  // initialize_support_points()
157  if (test_values_face.size() == 0)
158  {
159  for (unsigned int i = 0; i < this->dofs_per_face; ++i)
160  nodal_values[dbase + i] =
161  support_point_values[pbase + i]
163  pbase += this->dofs_per_face;
164  }
165  else
166  {
167  for (unsigned int i = 0; i < this->dofs_per_face; ++i)
168  {
169  double s = 0.;
170  for (unsigned int k = 0; k < test_values_face.size(); ++k)
171  s +=
172  support_point_values
174  test_values_face[k][i];
175  nodal_values[dbase + i] = s;
176  }
177  pbase += test_values_face.size();
178  }
179  dbase += this->dofs_per_face;
180  }
181 
182  AssertDimension(dbase,
184  AssertDimension(pbase,
185  this->generalized_support_points.size() -
186  test_values_cell.size());
187 
188  // Done for BDM1
189  if (dbase == this->dofs_per_cell)
190  return;
191 
192  // What's missing are the interior
193  // degrees of freedom. In each
194  // point, we take all components of
195  // the solution.
196  Assert((this->dofs_per_cell - dbase) % dim == 0, ExcInternalError());
197 
198  for (unsigned int d = 0; d < dim; ++d, dbase += test_values_cell[0].size())
199  {
200  for (unsigned int i = 0; i < test_values_cell[0].size(); ++i)
201  {
202  double s = 0.;
203  for (unsigned int k = 0; k < test_values_cell.size(); ++k)
204  s += support_point_values[pbase + k][d] * test_values_cell[k][i];
205  nodal_values[dbase + i] = s;
206  }
207  }
208 
209  Assert(dbase == this->dofs_per_cell, ExcInternalError());
210 }
211 
212 
213 
214 template <int dim>
215 std::vector<unsigned int>
216 FE_BDM<dim>::get_dpo_vector(const unsigned int deg)
217 {
218  // compute the number of unknowns per cell interior/face/edge
219  //
220  // for the number of interior dofs, this is the number of
221  // polynomials up to degree deg-2 in dim dimensions.
222  //
223  // the element is face-based and we have as many degrees of freedom
224  // on the faces as there are polynomials of degree up to
225  // deg. Observe the odd convention of
226  // PolynomialSpace::compute_n_pols()!
227 
228  std::vector<unsigned int> dpo(dim + 1, 0u);
229  dpo[dim] =
230  (deg > 1 ? dim * PolynomialSpace<dim>::compute_n_pols(deg - 1) : 0u);
231  dpo[dim - 1] = PolynomialSpace<dim - 1>::compute_n_pols(deg + 1);
232 
233  return dpo;
234 }
235 
236 
237 
238 template <int dim>
239 std::vector<bool>
240 FE_BDM<dim>::get_ria_vector(const unsigned int deg)
241 {
242  if (dim == 1)
243  {
244  Assert(false, ExcImpossibleInDim(1));
245  return std::vector<bool>();
246  }
247 
248  const unsigned int dofs_per_cell = PolynomialsBDM<dim>::compute_n_pols(deg);
249  const unsigned int dofs_per_face =
251 
252  Assert(GeometryInfo<dim>::faces_per_cell * dofs_per_face <= dofs_per_cell,
253  ExcInternalError());
254 
255  // all dofs need to be
256  // non-additive, since they have
257  // continuity requirements.
258  // however, the interior dofs are
259  // made additive
260  std::vector<bool> ret_val(dofs_per_cell, false);
261  for (unsigned int i = GeometryInfo<dim>::faces_per_cell * dofs_per_face;
262  i < dofs_per_cell;
263  ++i)
264  ret_val[i] = true;
265 
266  return ret_val;
267 }
268 
269 
270 namespace internal
271 {
272  namespace FE_BDM
273  {
274  namespace
275  {
276  // This function sets up the values of the polynomials we want to
277  // take moments with in the quadrature points. In fact, we multiply
278  // thos by the weights, such that the sum of function values and
279  // test_values over quadrature points yields the interpolated degree
280  // of freedom.
281  template <int dim>
282  void
283  initialize_test_values(std::vector<std::vector<double>> &test_values,
284  const Quadrature<dim> & quadrature,
285  const unsigned int deg)
286  {
287  PolynomialsP<dim> poly(deg);
288  std::vector<Tensor<1, dim>> dummy1;
289  std::vector<Tensor<2, dim>> dummy2;
290  std::vector<Tensor<3, dim>> dummy3;
291  std::vector<Tensor<4, dim>> dummy4;
292 
293  test_values.resize(quadrature.size());
294 
295  for (unsigned int k = 0; k < quadrature.size(); ++k)
296  {
297  test_values[k].resize(poly.n());
298  poly.compute(quadrature.point(k),
299  test_values[k],
300  dummy1,
301  dummy2,
302  dummy3,
303  dummy4);
304  for (unsigned int i = 0; i < poly.n(); ++i)
305  {
306  test_values[k][i] *= quadrature.weight(k);
307  }
308  }
309  }
310 
311  // This specialization only serves to avoid error messages. Nothing
312  // useful can be computed in dimension zero and thus the vector
313  // length stays zero.
314  template <>
315  void
316  initialize_test_values(std::vector<std::vector<double>> &,
317  const Quadrature<0> &,
318  const unsigned int)
319  {}
320  } // namespace
321  } // namespace FE_BDM
322 } // namespace internal
323 
324 
325 template <int dim>
326 void
328 {
329  // Our support points are quadrature points on faces and inside the
330  // cell. First on the faces, we have to test polynomials of degree
331  // up to deg, which means we need dg+1 points in each direction. The
332  // fact that we do not have tensor product polynomials will be
333  // considered later. In 2D, we can use point values.
334  QGauss<dim - 1> face_points(deg + 1);
335 
336  // Copy the quadrature formula to the face points.
337  this->generalized_face_support_points.resize(face_points.size());
338  for (unsigned int k = 0; k < face_points.size(); ++k)
339  this->generalized_face_support_points[k] = face_points.point(k);
340 
341  // In the interior, we only test with polynomials of degree up to
342  // deg-2, thus we use deg points. Note that deg>=1 and the lowest
343  // order element has no points in the cell, such that we have to
344  // distinguish this case.
345  QGauss<dim> cell_points(deg == 1 ? 0 : deg);
346 
347  // Compute the size of the whole support point set
348  const unsigned int npoints =
349  cell_points.size() + GeometryInfo<dim>::faces_per_cell * face_points.size();
350 
351  this->generalized_support_points.resize(npoints);
352 
354  for (unsigned int k = 0;
355  k < face_points.size() * GeometryInfo<dim>::faces_per_cell;
356  ++k)
357  this->generalized_support_points[k] =
359  0, true, false, false, this->dofs_per_face));
360 
361  // Currently, for backward compatibility, we do not use moments, but
362  // point values on faces in 2D. In 3D, this is impossible, since the
363  // moments are only taken with respect to PolynomialsP.
364  if (dim > 2)
365  internal::FE_BDM::initialize_test_values(test_values_face,
366  face_points,
367  deg);
368 
369  if (deg <= 1)
370  return;
371 
372  // Remember where interior points start
373  const unsigned int ibase =
374  face_points.size() * GeometryInfo<dim>::faces_per_cell;
375  for (unsigned int k = 0; k < cell_points.size(); ++k)
376  {
377  this->generalized_support_points[ibase + k] = cell_points.point(k);
378  }
379  // Finally, compute the values of
380  // the test functions in the
381  // interior quadrature points
382 
383  internal::FE_BDM::initialize_test_values(test_values_cell,
384  cell_points,
385  deg - 2);
386 }
387 
388 
389 
390 /*-------------- Explicit Instantiations -------------------------------*/
391 #include "fe_bdm.inst"
392 
393 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
Definition: fe_bdm.cc:135
std::vector< std::vector< double > > test_values_cell
Definition: fe_bdm.h:121
void initialize_support_points(const unsigned int bdm_degree)
Definition: fe_bdm.cc:327
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1366
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
void compute_face_embedding_matrices(const FiniteElement< dim, spacedim > &fe, FullMatrix< number >(&matrices)[GeometryInfo< dim >::max_children_per_face], const unsigned int face_coarse, const unsigned int face_fine, const double threshold=1.e-12)
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
Definition: fe_bdm.h:60
const Point< dim > & point(const unsigned int i) const
static std::vector< bool > get_ria_vector(const unsigned int degree)
Definition: fe_bdm.cc:240
FE_BDM(const unsigned int p)
Definition: fe_bdm.cc:41
unsigned int size() const
static::ExceptionBase & ExcMessage(std::string arg1)
size_type n() const
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
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
double weight(const unsigned int i) const
virtual std::string get_name() const override
Definition: fe_bdm.cc:104
size_type m() const
unsigned int n() const
const unsigned int dofs_per_cell
Definition: fe_base.h:297
static unsigned int compute_n_pols(const unsigned int n)
static Quadrature< dim > project_to_all_faces(const SubQuadrature &quadrature)
virtual std::unique_ptr< FiniteElement< dim, dim > > clone() const override
Definition: fe_bdm.cc:126
std::vector< std::vector< double > > test_values_face
Definition: fe_bdm.h:115
static std::vector< unsigned int > get_dpo_vector(const unsigned int degree)
Definition: fe_bdm.cc:216
static unsigned int compute_n_pols(unsigned int degree)
const unsigned int dofs_per_face
Definition: fe_base.h:290
void reinit_restriction_and_prolongation_matrices(const bool isotropic_restriction_only=false, const bool isotropic_prolongation_only=false)
void compute(const Point< dim > &unit_point, std::vector< double > &values, std::vector< Tensor< 1, dim >> &grads, std::vector< Tensor< 2, dim >> &grad_grads, std::vector< Tensor< 3, dim >> &third_derivatives, std::vector< Tensor< 4, dim >> &fourth_derivatives) const
static::ExceptionBase & ExcInternalError()