deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17:20:01+00:00
\(\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\}}\)
Loading...
Searching...
No Matches
fe_q_bubbles.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2015 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
17
20
21#include <deal.II/fe/fe_dgq.h>
24#include <deal.II/fe/fe_tools.h>
26
28#include <deal.II/grid/tria.h>
29
30#include <memory>
31#include <sstream>
32#include <vector>
33
35
36
37namespace internal
38{
39 namespace FE_Q_Bubbles
40 {
41 namespace
42 {
43 template <int dim, int spacedim>
44 void
45 compute_embedding_matrices(
46 const ::FE_Q_Bubbles<dim, spacedim> &fe,
47 std::vector<std::vector<FullMatrix<double>>> &matrices,
48 const bool isotropic_only)
49 {
50 const unsigned int dpc = fe.n_dofs_per_cell();
51 const unsigned int degree = fe.degree;
52
53 // Initialize quadrature formula on fine cells
54 std::unique_ptr<Quadrature<dim>> q_fine;
55 Quadrature<1> q_dummy(std::vector<Point<1>>(1),
56 std::vector<double>(1, 1.));
57 switch (dim)
58 {
59 case 1:
60 if (spacedim == 1)
61 q_fine = std::make_unique<QGauss<dim>>(degree + 1);
62 else if (spacedim == 2)
63 q_fine =
64 std::make_unique<QAnisotropic<dim>>(QGauss<1>(degree + 1),
65 q_dummy);
66 else
67 q_fine =
68 std::make_unique<QAnisotropic<dim>>(QGauss<1>(degree + 1),
69 q_dummy,
70 q_dummy);
71 break;
72 case 2:
73 if (spacedim == 2)
74 q_fine = std::make_unique<QGauss<dim>>(degree + 1);
75 else
76 q_fine =
77 std::make_unique<QAnisotropic<dim>>(QGauss<1>(degree + 1),
78 QGauss<1>(degree + 1),
79 q_dummy);
80 break;
81 case 3:
82 q_fine = std::make_unique<QGauss<dim>>(degree + 1);
83 break;
84 default:
86 }
87
88 Assert(q_fine.get() != nullptr, ExcInternalError());
89 const unsigned int nq = q_fine->size();
90
91 // loop over all possible refinement cases
92 for (unsigned int ref_case =
95 ref_case <= RefinementCase<dim>::isotropic_refinement;
96 ++ref_case)
97 {
98 const unsigned int nc =
99 fe.reference_cell().n_children(RefinementCase<dim>(ref_case));
100
101 for (unsigned int i = 0; i < nc; ++i)
102 {
103 Assert(matrices[ref_case - 1][i].n() == dpc,
104 ExcDimensionMismatch(matrices[ref_case - 1][i].n(),
105 dpc));
106 Assert(matrices[ref_case - 1][i].m() == dpc,
107 ExcDimensionMismatch(matrices[ref_case - 1][i].m(),
108 dpc));
109 }
110
111 // create a respective refinement on the triangulation
114 tr.begin_active()->set_refine_flag(RefinementCase<dim>(ref_case));
116
118 dh.distribute_dofs(fe);
119
121 fe,
122 *q_fine,
126
127 const unsigned int n_dofs = dh.n_dofs();
128
129 FullMatrix<double> fine_mass(n_dofs);
130 FullMatrix<double> coarse_rhs_matrix(n_dofs, dpc);
131
132 std::vector<std::vector<types::global_dof_index>> child_ldi(
133 nc, std::vector<types::global_dof_index>(fe.n_dofs_per_cell()));
134
135 // now create the mass matrix and all the right_hand sides
136 unsigned int child_no = 0;
138 dh.begin_active();
139 for (; cell != dh.end(); ++cell, ++child_no)
140 {
141 fine.reinit(cell);
142 cell->get_dof_indices(child_ldi[child_no]);
143
144 for (unsigned int q = 0; q < nq; ++q)
145 for (unsigned int i = 0; i < dpc; ++i)
146 for (unsigned int j = 0; j < dpc; ++j)
147 {
148 const unsigned int gdi = child_ldi[child_no][i];
149 const unsigned int gdj = child_ldi[child_no][j];
150 fine_mass(gdi, gdj) += fine.shape_value(i, q) *
151 fine.shape_value(j, q) *
152 fine.JxW(q);
153 Point<dim> quad_tmp;
154 for (unsigned int k = 0; k < dim; ++k)
155 quad_tmp[k] = fine.quadrature_point(q)[k];
156 coarse_rhs_matrix(gdi, j) +=
157 fine.shape_value(i, q) * fe.shape_value(j, quad_tmp) *
158 fine.JxW(q);
159 }
160 }
161
162 // now solve for all right-hand sides simultaneously
163 ::FullMatrix<double> solution(n_dofs, dpc);
164 fine_mass.gauss_jordan();
165 fine_mass.mmult(solution, coarse_rhs_matrix);
166
167 // and distribute to the fine cell matrices
168 for (unsigned int child_no = 0; child_no < nc; ++child_no)
169 for (unsigned int i = 0; i < dpc; ++i)
170 for (unsigned int j = 0; j < dpc; ++j)
171 {
172 const unsigned int gdi = child_ldi[child_no][i];
173 // remove small entries
174 if (std::fabs(solution(gdi, j)) > 1.e-12)
175 matrices[ref_case - 1][child_no](i, j) = solution(gdi, j);
176 }
177 }
178 }
179 } // namespace
180 } // namespace FE_Q_Bubbles
181} // namespace internal
182
183
184template <int dim, int spacedim>
186 : FE_Q_Base<dim, spacedim>(TensorProductPolynomialsBubbles<dim>(
187 Polynomials::generate_complete_Lagrange_basis(
188 QGaussLobatto<1>(q_degree + 1).get_points())),
189 FiniteElementData<dim>(get_dpo_vector(q_degree),
190 1,
191 q_degree + 1,
192 FiniteElementData<dim>::H1),
193 get_riaf_vector(q_degree))
194 , n_bubbles((q_degree <= 1) ? 1 : dim)
195{
196 Assert(q_degree > 0,
197 ExcMessage("This element can only be used for polynomial degrees "
198 "greater than zero"));
199
200 this->initialize(QGaussLobatto<1>(q_degree + 1).get_points());
201
202 // adjust unit support point for discontinuous node
203 Point<dim> point;
204 for (unsigned int d = 0; d < dim; ++d)
205 point[d] = 0.5;
206 for (unsigned int i = 0; i < n_bubbles; ++i)
207 this->unit_support_points.push_back(point);
209
211 if (dim == spacedim)
212 {
213 internal::FE_Q_Bubbles::compute_embedding_matrices(*this,
214 this->prolongation,
215 false);
216 // Fill restriction matrices with L2-projection
218 }
219}
220
221
222
223template <int dim, int spacedim>
225 : FE_Q_Base<dim, spacedim>(
227 Polynomials::generate_complete_Lagrange_basis(points.get_points())),
228 FiniteElementData<dim>(get_dpo_vector(points.size() - 1),
229 1,
230 points.size(),
231 FiniteElementData<dim>::H1),
232 get_riaf_vector(points.size() - 1))
233 , n_bubbles((points.size() - 1 <= 1) ? 1 : dim)
234{
235 Assert(points.size() > 1,
236 ExcMessage("This element can only be used for polynomial degrees "
237 "at least one"));
238
239 this->initialize(points.get_points());
240
241 // adjust unit support point for discontinuous node
242 Point<dim> point;
243 for (unsigned int d = 0; d < dim; ++d)
244 point[d] = 0.5;
245 for (unsigned int i = 0; i < n_bubbles; ++i)
246 this->unit_support_points.push_back(point);
248
250 if (dim == spacedim)
251 {
252 internal::FE_Q_Bubbles::compute_embedding_matrices(*this,
253 this->prolongation,
254 false);
255 // Fill restriction matrices with L2-projection
257 }
258}
259
260
261
262template <int dim, int spacedim>
263std::string
265{
266 // note that the FETools::get_fe_by_name function depends on the
267 // particular format of the string this function returns, so they have to be
268 // kept in synch
269
270 std::ostringstream namebuf;
271 bool type = true;
272 const unsigned int n_points = this->degree;
273 std::vector<double> points(n_points);
274 const unsigned int dofs_per_cell = this->n_dofs_per_cell();
275 const std::vector<Point<dim>> &unit_support_points =
276 this->unit_support_points;
277 unsigned int index = 0;
278
279 // Decode the support points in one coordinate direction.
280 for (unsigned int j = 0; j < dofs_per_cell; ++j)
281 {
282 if ((dim > 1) ? (unit_support_points[j][1] == 0 &&
283 ((dim > 2) ? unit_support_points[j][2] == 0 : true)) :
284 true)
285 {
286 if (index == 0)
287 points[index] = unit_support_points[j][0];
288 else if (index == 1)
289 points[n_points - 1] = unit_support_points[j][0];
290 else
291 points[index - 1] = unit_support_points[j][0];
292
293 ++index;
294 }
295 }
296 // Do not consider the discontinuous node for dimension 1
297 Assert(index == n_points || (dim == 1 && index == n_points + n_bubbles),
299 "Could not decode support points in one coordinate direction."));
300
301 // Check whether the support points are equidistant.
302 for (unsigned int j = 0; j < n_points; ++j)
303 if (std::fabs(points[j] - static_cast<double>(j) / (this->degree - 1)) >
304 1e-15)
305 {
306 type = false;
307 break;
308 }
309
310 if (type == true)
311 {
312 if (this->degree > 3)
313 namebuf << "FE_Q_Bubbles<" << Utilities::dim_string(dim, spacedim)
314 << ">(QIterated(QTrapezoid()," << this->degree - 1 << "))";
315 else
316 namebuf << "FE_Q_Bubbles<" << Utilities::dim_string(dim, spacedim)
317 << ">(" << this->degree - 1 << ")";
318 }
319 else
320 {
321 // Check whether the support points come from QGaussLobatto.
322 const QGaussLobatto<1> points_gl(n_points);
323 type = true;
324 for (unsigned int j = 0; j < n_points; ++j)
325 if (points[j] != points_gl.point(j)[0])
326 {
327 type = false;
328 break;
329 }
330 if (type == true)
331 namebuf << "FE_Q_Bubbles<" << Utilities::dim_string(dim, spacedim)
332 << ">(" << this->degree - 1 << ")";
333 else
334 namebuf << "FE_Q_Bubbles<" << Utilities::dim_string(dim, spacedim)
335 << ">(QUnknownNodes(" << this->degree << "))";
336 }
337 return namebuf.str();
338}
339
340
341
342template <int dim, int spacedim>
343std::unique_ptr<FiniteElement<dim, spacedim>>
345{
346 return std::make_unique<FE_Q_Bubbles<dim, spacedim>>(*this);
347}
348
349
350
351template <int dim, int spacedim>
352void
355 const std::vector<Vector<double>> &support_point_values,
356 std::vector<double> &nodal_values) const
357{
358 Assert(support_point_values.size() == this->unit_support_points.size(),
359 ExcDimensionMismatch(support_point_values.size(),
360 this->unit_support_points.size()));
361 Assert(nodal_values.size() == this->n_dofs_per_cell(),
362 ExcDimensionMismatch(nodal_values.size(), this->n_dofs_per_cell()));
363 Assert(support_point_values[0].size() == this->n_components(),
364 ExcDimensionMismatch(support_point_values[0].size(),
365 this->n_components()));
366
367 for (unsigned int i = 0; i < this->n_dofs_per_cell() - 1; ++i)
368 {
369 const std::pair<unsigned int, unsigned int> index =
370 this->system_to_component_index(i);
371 nodal_values[i] = support_point_values[i](index.first);
372 }
373
374 // We don't use the bubble functions for local interpolation
375 for (unsigned int i = 0; i < n_bubbles; ++i)
376 nodal_values[nodal_values.size() - i - 1] = 0.;
377}
378
379
380
381template <int dim, int spacedim>
382void
384 const FiniteElement<dim, spacedim> &x_source_fe,
385 FullMatrix<double> &interpolation_matrix) const
386{
387 // We don't know how to do this properly, yet.
388 // However, for SolutionTransfer to work we need to provide an implementation
389 // for the case that the x_source_fe is identical to this FE
390 using FEQBUBBLES = FE_Q_Bubbles<dim, spacedim>;
391
393 (x_source_fe.get_name().find("FE_Q_Bubbles<") == 0) ||
394 (dynamic_cast<const FEQBUBBLES *>(&x_source_fe) != nullptr),
396 Assert(interpolation_matrix.m() == this->n_dofs_per_cell(),
397 ExcDimensionMismatch(interpolation_matrix.m(),
398 this->n_dofs_per_cell()));
399 Assert(interpolation_matrix.n() == x_source_fe.n_dofs_per_cell(),
400 ExcDimensionMismatch(interpolation_matrix.m(),
401 x_source_fe.n_dofs_per_cell()));
402
403 // Provide a short cut in case we are just inquiring the identity
404 auto casted_fe = dynamic_cast<const FEQBUBBLES *>(&x_source_fe);
405 if (casted_fe != nullptr && casted_fe->degree == this->degree)
406 for (unsigned int i = 0; i < interpolation_matrix.m(); ++i)
407 interpolation_matrix.set(i, i, 1.);
408 // else we need to do more...
409 else
410 Assert(
411 false,
412 (typename FiniteElement<dim,
413 spacedim>::ExcInterpolationNotImplemented()));
414}
415
416
417
418template <int dim, int spacedim>
419std::vector<bool>
421{
422 const unsigned int n_cont_dofs = Utilities::fixed_power<dim>(q_deg + 1);
423 const unsigned int n_bubbles = (q_deg <= 1 ? 1 : dim);
424 return std::vector<bool>(n_cont_dofs + n_bubbles, true);
425}
426
427
428
429template <int dim, int spacedim>
430std::vector<unsigned int>
432{
433 std::vector<unsigned int> dpo(dim + 1, 1U);
434 for (unsigned int i = 1; i < dpo.size(); ++i)
435 dpo[i] = dpo[i - 1] * (q_deg - 1);
436
437 // Then add the bubble functions; they are all associated with the
438 // cell interior
439 dpo[dim] += (q_deg <= 1 ? 1 : dim);
440 return dpo;
441}
442
443
444
445template <int dim, int spacedim>
446bool
448 const unsigned int shape_index,
449 const unsigned int face_index) const
450{
451 // discontinuous functions have no support on faces
452 if (shape_index >= this->n_dofs_per_cell() - n_bubbles)
453 return false;
454 else
456 face_index);
457}
458
459
460
461template <int dim, int spacedim>
462const FullMatrix<double> &
464 const unsigned int child,
465 const RefinementCase<dim> &refinement_case) const
466{
467 AssertIndexRange(refinement_case,
471 "Prolongation matrices are only available for refined cells!"));
472 AssertIndexRange(child, this->reference_cell().n_children(refinement_case));
473
474 Assert(this->prolongation[refinement_case - 1][child].n() != 0,
475 ExcMessage("This prolongation matrix has not been computed yet!"));
476 // finally return the matrix
477 return this->prolongation[refinement_case - 1][child];
478}
479
480
481
482template <int dim, int spacedim>
483const FullMatrix<double> &
485 const unsigned int child,
486 const RefinementCase<dim> &refinement_case) const
487{
488 AssertIndexRange(refinement_case,
492 "Restriction matrices are only available for refined cells!"));
493 AssertIndexRange(child, this->reference_cell().n_children(refinement_case));
494
495 Assert(this->restriction[refinement_case - 1][child].n() != 0,
496 ExcMessage("This restriction matrix has not been computed yet!"));
497
498 // finally return the matrix
499 return this->restriction[refinement_case - 1][child];
500}
501
502
503
504template <int dim, int spacedim>
507 const FiniteElement<dim, spacedim> &fe_other,
508 const unsigned int codim) const
509{
510 Assert(codim <= dim, ExcImpossibleInDim(dim));
511
512 // vertex/line/face domination
513 // (if fe_other is derived from FE_DGQ)
514 // ------------------------------------
515 if (codim > 0)
516 if (dynamic_cast<const FE_DGQ<dim, spacedim> *>(&fe_other) != nullptr)
517 // there are no requirements between continuous and discontinuous elements
519
520 // vertex/line/face domination
521 // (if fe_other is not derived from FE_DGQ)
522 // & cell domination
523 // ----------------------------------------
524 if (const FE_Q_Bubbles<dim, spacedim> *fe_bubbles_other =
525 dynamic_cast<const FE_Q_Bubbles<dim, spacedim> *>(&fe_other))
526 {
527 if (this->degree < fe_bubbles_other->degree)
529 else if (this->degree == fe_bubbles_other->degree)
531 else
533 }
534 else if (const FE_Nothing<dim> *fe_nothing =
535 dynamic_cast<const FE_Nothing<dim> *>(&fe_other))
536 {
537 if (fe_nothing->is_dominating())
539 else
540 // the FE_Nothing has no degrees of freedom and it is typically used
541 // in a context where we don't require any continuity along the
542 // interface
544 }
545
548}
549
550
551// explicit instantiations
552#include "fe/fe_q_bubbles.inst"
553
cell_iterator end() const
void distribute_dofs(const FiniteElement< dim, spacedim > &fe)
active_cell_iterator begin_active(const unsigned int level=0) const
types::global_dof_index n_dofs() const
const Point< spacedim > & quadrature_point(const unsigned int q_point) const
double JxW(const unsigned int q_point) const
const double & shape_value(const unsigned int i, const unsigned int q_point) const
void reinit(const TriaIterator< DoFCellAccessor< dim, spacedim, level_dof_access > > &cell)
const unsigned int q_degree
Definition fe_q_base.h:339
void initialize(const std::vector< Point< 1 > > &support_points_1d)
virtual bool has_support_on_face(const unsigned int shape_index, const unsigned int face_index) const override
virtual bool has_support_on_face(const unsigned int shape_index, const unsigned int face_index) const override
static std::vector< bool > get_riaf_vector(const unsigned int degree)
virtual void get_interpolation_matrix(const FiniteElement< dim, spacedim > &source, FullMatrix< double > &matrix) const override
virtual const FullMatrix< double > & get_restriction_matrix(const unsigned int child, const RefinementCase< dim > &refinement_case) const override
virtual FiniteElementDomination::Domination compare_for_domination(const FiniteElement< dim, spacedim > &fe_other, const unsigned int codim=0) const override final
virtual const FullMatrix< double > & get_prolongation_matrix(const unsigned int child, const RefinementCase< dim > &refinement_case) const override
const unsigned int n_bubbles
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
virtual std::unique_ptr< FiniteElement< dim, spacedim > > clone() const override
FE_Q_Bubbles(const unsigned int p)
virtual std::string get_name() const override
static std::vector< unsigned int > get_dpo_vector(const unsigned int degree)
unsigned int n_dofs_per_cell() const
virtual std::string get_name() const =0
std::vector< std::vector< FullMatrix< double > > > restriction
Definition fe.h:2547
void reinit_restriction_and_prolongation_matrices(const bool isotropic_restriction_only=false, const bool isotropic_prolongation_only=false)
std::vector< Point< dim > > unit_support_points
Definition fe.h:2585
std::vector< std::vector< FullMatrix< double > > > prolongation
Definition fe.h:2561
void mmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
void set(const size_type i, const size_type j, const number value)
size_type n() const
void gauss_jordan()
size_type m() const
Definition point.h:111
const std::vector< Point< dim > > & get_points() const
unsigned int size() const
virtual void execute_coarsening_and_refinement()
active_cell_iterator begin_active(const unsigned int level=0) const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ASSERT_UNREACHABLE()
#define DEAL_II_NOT_IMPLEMENTED()
#define Assert(cond, exc)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
typename ActiveSelector::active_cell_iterator active_cell_iterator
@ update_values
Shape function values.
@ update_JxW_values
Transformed quadrature weights.
@ update_quadrature_points
Transformed quadrature points.
const Mapping< dim, spacedim > & get_default_linear_mapping(const Triangulation< dim, spacedim > &triangulation)
Definition mapping.cc:314
std::size_t size
Definition mpi.cc:733
void compute_projection_matrices(const FiniteElement< dim, spacedim > &fe, std::vector< std::vector< FullMatrix< number > > > &matrices, const bool isotropic_only=false)
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
std::string dim_string(const int dim, const int spacedim)
Definition utilities.cc:547