Reference documentation for deal.II version GIT relicensing-548-gff2bfe761d 2024-05-07 19:30: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
dof_tools_constraints.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2013 - 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#include <deal.II/base/table.h>
19
23
24#include <deal.II/fe/fe.h>
25#include <deal.II/fe/fe_tools.h>
27
31#include <deal.II/grid/tria.h>
33
36
38#include <deal.II/lac/vector.h>
39
40#ifdef DEAL_II_WITH_MPI
42#endif
43
44#include <algorithm>
45#include <array>
46#include <memory>
47#include <numeric>
48
50
51
52
53namespace DoFTools
54{
55 namespace internal
56 {
57 namespace
58 {
59 inline bool
60 check_primary_dof_list(
61 const FullMatrix<double> &face_interpolation_matrix,
62 const std::vector<types::global_dof_index> &primary_dof_list)
63 {
64 const unsigned int N = primary_dof_list.size();
65
66 FullMatrix<double> tmp(N, N);
67 for (unsigned int i = 0; i < N; ++i)
68 for (unsigned int j = 0; j < N; ++j)
69 tmp(i, j) = face_interpolation_matrix(primary_dof_list[i], j);
70
71 // then use the algorithm from FullMatrix::gauss_jordan on this matrix
72 // to find out whether it is singular. the algorithm there does pivoting
73 // and at the end swaps rows back into their proper order -- we omit
74 // this step here, since we don't care about the inverse matrix, all we
75 // care about is whether the matrix is regular or singular
76
77 // first get an estimate of the size of the elements of this matrix, for
78 // later checks whether the pivot element is large enough, or whether we
79 // have to fear that the matrix is not regular
80 double diagonal_sum = 0;
81 for (unsigned int i = 0; i < N; ++i)
82 diagonal_sum += std::fabs(tmp(i, i));
83 const double typical_diagonal_element = diagonal_sum / N;
84
85 // initialize the array that holds the permutations that we find during
86 // pivot search
87 std::vector<unsigned int> p(N);
88 for (unsigned int i = 0; i < N; ++i)
89 p[i] = i;
90
91 for (unsigned int j = 0; j < N; ++j)
92 {
93 // pivot search: search that part of the line on and right of the
94 // diagonal for the largest element
95 double max = std::fabs(tmp(j, j));
96 unsigned int r = j;
97 for (unsigned int i = j + 1; i < N; ++i)
98 {
99 if (std::fabs(tmp(i, j)) > max)
100 {
101 max = std::fabs(tmp(i, j));
102 r = i;
103 }
104 }
105 // check whether the pivot is too small. if that is the case, then
106 // the matrix is singular and we shouldn't use this set of primary
107 // dofs
108 if (max < 1.e-12 * typical_diagonal_element)
109 return false;
110
111 // row interchange
112 if (r > j)
113 {
114 for (unsigned int k = 0; k < N; ++k)
115 std::swap(tmp(j, k), tmp(r, k));
116
117 std::swap(p[j], p[r]);
118 }
119
120 // transformation
121 const double hr = 1. / tmp(j, j);
122 tmp(j, j) = hr;
123 for (unsigned int k = 0; k < N; ++k)
124 {
125 if (k == j)
126 continue;
127 for (unsigned int i = 0; i < N; ++i)
128 {
129 if (i == j)
130 continue;
131 tmp(i, k) -= tmp(i, j) * tmp(j, k) * hr;
132 }
133 }
134 for (unsigned int i = 0; i < N; ++i)
135 {
136 tmp(i, j) *= hr;
137 tmp(j, i) *= -hr;
138 }
139 tmp(j, j) = hr;
140 }
141
142 // everything went fine, so we can accept this set of primary dofs (at
143 // least as far as they have already been collected)
144 return true;
145 }
146
147
148
170 template <int dim, int spacedim>
171 void
172 select_primary_dofs_for_face_restriction(
175 const FullMatrix<double> &face_interpolation_matrix,
176 std::vector<bool> &primary_dof_mask)
177 {
178 // TODO: the implementation makes the assumption that all faces have the
179 // same number of dofs
182 const unsigned int face_no = 0;
183 (void)face_no;
184
185 Assert(fe1.n_dofs_per_face(face_no) >= fe2.n_dofs_per_face(face_no),
187 AssertDimension(primary_dof_mask.size(), fe1.n_dofs_per_face(face_no));
188
193 Assert((dim < 3) ||
194 (fe2.n_dofs_per_quad(face_no) <= fe1.n_dofs_per_quad(face_no)),
196
197 // the idea here is to designate as many DoFs in fe1 per object (vertex,
198 // line, quad) as primary as there are such dofs in fe2 (indices are
199 // int, because we want to avoid the 'unsigned int < 0 is always false
200 // warning for the cases at the bottom in 1d and 2d)
201 //
202 // as mentioned in the paper, it is not always easy to find a set of
203 // primary dofs that produces an invertible matrix. to this end, we
204 // check in each step whether the matrix is still invertible and simply
205 // discard this dof if the matrix is not invertible anymore.
206 //
207 // the cases where we did have trouble in the past were with adding more
208 // quad dofs when Q3 and Q4 elements meet at a refined face in 3d (see
209 // the hp/crash_12 test that tests that we can do exactly this, and
210 // failed before we had code to compensate for this case). the other
211 // case are system elements: if we have say a Q1Q2 vs a Q2Q3 element,
212 // then we can't just take all primary dofs on a line from a single base
213 // element, since the shape functions of that base element are
214 // independent of that of the other one. this latter case shows up when
215 // running hp/hp_constraints_q_system_06
216
217 std::vector<types::global_dof_index> primary_dof_list;
218 unsigned int index = 0;
219 for (int v = 0;
220 v < static_cast<signed int>(GeometryInfo<dim>::vertices_per_face);
221 ++v)
222 {
223 unsigned int dofs_added = 0;
224 unsigned int i = 0;
225 while (dofs_added < fe2.n_dofs_per_vertex())
226 {
227 // make sure that we were able to find a set of primary dofs and
228 // that the code down below didn't just reject all our efforts
230
231 // tentatively push this vertex dof
232 primary_dof_list.push_back(index + i);
233
234 // then see what happens. if it succeeds, fine
235 if (check_primary_dof_list(face_interpolation_matrix,
236 primary_dof_list) == true)
237 ++dofs_added;
238 else
239 // well, it didn't. simply pop that dof from the list again
240 // and try with the next dof
241 primary_dof_list.pop_back();
242
243 // forward counter by one
244 ++i;
245 }
246 index += fe1.n_dofs_per_vertex();
247 }
248
249 for (int l = 0;
250 l < static_cast<signed int>(GeometryInfo<dim>::lines_per_face);
251 ++l)
252 {
253 // same algorithm as above
254 unsigned int dofs_added = 0;
255 unsigned int i = 0;
256 while (dofs_added < fe2.n_dofs_per_line())
257 {
259
260 primary_dof_list.push_back(index + i);
261 if (check_primary_dof_list(face_interpolation_matrix,
262 primary_dof_list) == true)
263 ++dofs_added;
264 else
265 primary_dof_list.pop_back();
266
267 ++i;
268 }
269 index += fe1.n_dofs_per_line();
270 }
271
272 for (int q = 0;
273 q < static_cast<signed int>(GeometryInfo<dim>::quads_per_face);
274 ++q)
275 {
276 // same algorithm as above
277 unsigned int dofs_added = 0;
278 unsigned int i = 0;
279 while (dofs_added < fe2.n_dofs_per_quad(q))
280 {
282
283 primary_dof_list.push_back(index + i);
284 if (check_primary_dof_list(face_interpolation_matrix,
285 primary_dof_list) == true)
286 ++dofs_added;
287 else
288 primary_dof_list.pop_back();
289
290 ++i;
291 }
292 index += fe1.n_dofs_per_quad(q);
293 }
294
295 AssertDimension(index, fe1.n_dofs_per_face(face_no));
296 AssertDimension(primary_dof_list.size(), fe2.n_dofs_per_face(face_no));
297
298 // finally copy the list into the mask
299 std::fill(primary_dof_mask.begin(), primary_dof_mask.end(), false);
300 for (const auto dof : primary_dof_list)
301 primary_dof_mask[dof] = true;
302 }
303
304
305
310 template <int dim, int spacedim>
311 void
312 ensure_existence_of_primary_dof_mask(
315 const FullMatrix<double> &face_interpolation_matrix,
316 std::unique_ptr<std::vector<bool>> &primary_dof_mask)
317 {
318 // TODO: the implementation makes the assumption that all faces have the
319 // same number of dofs
322 const unsigned int face_no = 0;
323
324 if (primary_dof_mask == nullptr)
325 {
326 primary_dof_mask =
327 std::make_unique<std::vector<bool>>(fe1.n_dofs_per_face(face_no));
328 select_primary_dofs_for_face_restriction(fe1,
329 fe2,
330 face_interpolation_matrix,
331 *primary_dof_mask);
332 }
333 }
334
335
336
342 template <int dim, int spacedim>
343 void
344 ensure_existence_of_face_matrix(
347 std::unique_ptr<FullMatrix<double>> &matrix)
348 {
349 // TODO: the implementation makes the assumption that all faces have the
350 // same number of dofs
353 const unsigned int face_no = 0;
354
355 if (matrix == nullptr)
356 {
357 matrix = std::make_unique<FullMatrix<double>>(
358 fe2.n_dofs_per_face(face_no), fe1.n_dofs_per_face(face_no));
359 fe1.get_face_interpolation_matrix(fe2, *matrix, face_no);
360 }
361 }
362
363
364
368 template <int dim, int spacedim>
369 void
370 ensure_existence_of_subface_matrix(
373 const unsigned int subface,
374 std::unique_ptr<FullMatrix<double>> &matrix)
375 {
376 // TODO: the implementation makes the assumption that all faces have the
377 // same number of dofs
380 const unsigned int face_no = 0;
381
382 if (matrix == nullptr)
383 {
384 matrix = std::make_unique<FullMatrix<double>>(
385 fe2.n_dofs_per_face(face_no), fe1.n_dofs_per_face(face_no));
387 subface,
388 *matrix,
389 face_no);
390 }
391 }
392
393
394
400 void
401 ensure_existence_of_split_face_matrix(
402 const FullMatrix<double> &face_interpolation_matrix,
403 const std::vector<bool> &primary_dof_mask,
404 std::unique_ptr<std::pair<FullMatrix<double>, FullMatrix<double>>>
405 &split_matrix)
406 {
407 AssertDimension(primary_dof_mask.size(), face_interpolation_matrix.m());
408 Assert(std::count(primary_dof_mask.begin(),
409 primary_dof_mask.end(),
410 true) ==
411 static_cast<signed int>(face_interpolation_matrix.n()),
413
414 if (split_matrix == nullptr)
415 {
416 split_matrix = std::make_unique<
417 std::pair<FullMatrix<double>, FullMatrix<double>>>();
418
419 const unsigned int n_primary_dofs = face_interpolation_matrix.n();
420 const unsigned int n_dofs = face_interpolation_matrix.m();
421
422 Assert(n_primary_dofs <= n_dofs, ExcInternalError());
423
424 // copy and invert the primary component, copy the dependent
425 // component
426 split_matrix->first.reinit(n_primary_dofs, n_primary_dofs);
427 split_matrix->second.reinit(n_dofs - n_primary_dofs,
428 n_primary_dofs);
429
430 unsigned int nth_primary_dof = 0, nth_dependent_dof = 0;
431
432 for (unsigned int i = 0; i < n_dofs; ++i)
433 if (primary_dof_mask[i] == true)
434 {
435 for (unsigned int j = 0; j < n_primary_dofs; ++j)
436 split_matrix->first(nth_primary_dof, j) =
437 face_interpolation_matrix(i, j);
438 ++nth_primary_dof;
439 }
440 else
441 {
442 for (unsigned int j = 0; j < n_primary_dofs; ++j)
443 split_matrix->second(nth_dependent_dof, j) =
444 face_interpolation_matrix(i, j);
445 ++nth_dependent_dof;
446 }
447
448 AssertDimension(nth_primary_dof, n_primary_dofs);
449 AssertDimension(nth_dependent_dof, n_dofs - n_primary_dofs);
450
451 // TODO[WB]: We should make sure very small entries are removed
452 // after inversion
453 split_matrix->first.gauss_jordan();
454 }
455 }
456
457
463 template <int dim, int spacedim>
464 unsigned int
465 n_finite_elements(const DoFHandler<dim, spacedim> &dof_handler)
466 {
467 if (dof_handler.has_hp_capabilities() == true)
468 return dof_handler.get_fe_collection().size();
469 else
470 return 1;
471 }
472
473
474
485 template <typename number1, typename number2>
486 void
487 filter_constraints(
488 const std::vector<types::global_dof_index> &primary_dofs,
489 const std::vector<types::global_dof_index> &dependent_dofs,
490 const FullMatrix<number1> &face_constraints,
491 AffineConstraints<number2> &constraints)
492 {
493 Assert(face_constraints.n() == primary_dofs.size(),
494 ExcDimensionMismatch(primary_dofs.size(), face_constraints.n()));
495 Assert(face_constraints.m() == dependent_dofs.size(),
496 ExcDimensionMismatch(dependent_dofs.size(),
497 face_constraints.m()));
498
499 const unsigned int n_primary_dofs = primary_dofs.size();
500 const unsigned int n_dependent_dofs = dependent_dofs.size();
501
502 // check for a couple conditions that happened in parallel distributed
503 // mode
504 for (unsigned int row = 0; row != n_dependent_dofs; ++row)
505 Assert(dependent_dofs[row] != numbers::invalid_dof_index,
507 for (unsigned int col = 0; col != n_primary_dofs; ++col)
508 Assert(primary_dofs[col] != numbers::invalid_dof_index,
510
511 // Build constraints in a vector of pairs that can be
512 // arbitrarily large, but that holds up to 25 elements without
513 // external memory allocation. This is good enough for hanging
514 // node constraints of Q4 elements in 3d, so covers most
515 // common cases. Sort the primary dofs to add a sorted list to the
516 // affine constraints, which increases performance there.
518 boost::container::small_vector<std::pair<size_type, size_type>, 25>
519 sorted_primary_dofs;
520 sorted_primary_dofs.reserve(n_primary_dofs);
521 for (unsigned int i = 0; i < n_primary_dofs; ++i)
522 sorted_primary_dofs.emplace_back(primary_dofs[i], i);
523 std::sort(sorted_primary_dofs.begin(), sorted_primary_dofs.end());
524
525 boost::container::small_vector<std::pair<size_type, number2>, 25>
526 entries;
527 entries.reserve(n_primary_dofs);
528 for (unsigned int row = 0; row != n_dependent_dofs; ++row)
529 if (constraints.is_constrained(dependent_dofs[row]) == false)
530 {
531 // Check if we have an identity constraint, i.e.,
532 // something of the form
533 // U(dependent_dof[row])==U(primary_dof[row]),
534 // where
535 // dependent_dof[row] == primary_dof[row].
536 // This can happen in the hp context where we have previously
537 // unified DoF indices, for example, the middle node on the
538 // face of a Q4 element will have gotten the same index
539 // as the middle node of the Q2 element on the neighbor
540 // cell. But because the other Q4 nodes will still have to be
541 // constrained, so the middle node shows up again here.
542 //
543 // If we find such a constraint, then it is trivially
544 // satisfied, and we can move on to the next dependent
545 // DoF (row). The only thing we should make sure is that the
546 // row of the matrix really just contains this one entry.
547 {
548 bool is_trivial_constraint = false;
549
550 for (unsigned int i = 0; i < n_primary_dofs; ++i)
551 if (face_constraints(row, i) == 1.0)
552 if (dependent_dofs[row] == primary_dofs[i])
553 {
554 is_trivial_constraint = true;
555
556 for (unsigned int ii = 0; ii < n_primary_dofs; ++ii)
557 if (ii != i)
558 Assert(face_constraints(row, ii) == 0.0,
560
561 break;
562 }
563
564 if (is_trivial_constraint == true)
565 continue;
566 }
567
568 // then enter those constraints that are larger than
569 // 1e-14; since numbers are normalized for the subface
570 // interpolation matrices, we do not need to normalize here.
571 // everything else probably originated from
572 // inexact inversion of matrices and similar effects. having
573 // those constraints in here will only lead to problems because
574 // it makes sparsity patterns fuller than necessary without
575 // producing any significant effect. do this in two steps, first
576 // filling a vector and then adding to the constraints in order
577 // to reduce the number of memory allocations.
578 entries.clear();
579 for (const auto &[dof_index, unsorted_index] :
580 sorted_primary_dofs)
581 if (std::fabs(face_constraints(row, unsorted_index)) >= 1e-14)
582 entries.emplace_back(dof_index,
583 face_constraints(row, unsorted_index));
584 constraints.add_constraint(dependent_dofs[row],
585 entries,
586 /* inhomogeneity= */ 0.);
587 }
588 }
589
590 } // namespace
591
592
593
594 template <typename number, int spacedim>
595 void
597 const DoFHandler<1, spacedim> & /*dof_handler*/,
598 AffineConstraints<number> & /*constraints*/)
599 {
600 // nothing to do for dof handlers in 1d
601 }
602
603
604
605 template <typename number, int spacedim>
606 void
608 const ::DoFHandler<1, spacedim> & /*dof_handler*/,
609 AffineConstraints<number> & /*constraints*/,
610 std::integral_constant<int, 1>)
611 {
612 // nothing to do for dof handlers in 1d
613 }
614
615
616
617 template <typename number, int spacedim>
618 void
620 const DoFHandler<1, spacedim> & /*dof_handler*/,
621 AffineConstraints<number> & /*constraints*/,
622 std::integral_constant<int, 1>)
623 {
624 // nothing to do for dof handlers in 1d
625 }
626
627
628
629 template <int dim_, int spacedim, typename number>
630 void
632 const DoFHandler<dim_, spacedim> &dof_handler,
633 AffineConstraints<number> &constraints,
634 std::integral_constant<int, 2>)
635 {
636 const unsigned int dim = 2;
637
638 std::vector<types::global_dof_index> dofs_on_mother;
639 std::vector<types::global_dof_index> dofs_on_children;
640
641 // Build constraints in a vector of pairs that can be
642 // arbitrarily large, but that holds up to 25 elements without
643 // external memory allocation. This is good enough for hanging
644 // node constraints of Q4 elements in 3d, so covers most
645 // common cases.
646 boost::container::small_vector<
647 std::pair<typename AffineConstraints<number>::size_type, number>,
648 25>
649 constraint_entries;
650
651 // loop over all lines; only on lines there can be constraints. We do so
652 // by looping over all active cells and checking whether any of the faces
653 // are refined which can only be from the neighboring cell because this
654 // one is active. In that case, the face is subject to constraints
655 //
656 // note that even though we may visit a face twice if the neighboring
657 // cells are equally refined, we can only visit each face with hanging
658 // nodes once
659 for (const auto &cell : dof_handler.active_cell_iterators())
660 {
661 // artificial cells can at best neighbor ghost cells, but we're not
662 // interested in these interfaces
663 if (cell->is_artificial())
664 continue;
665
666 for (const unsigned int face : cell->face_indices())
667 if (cell->face(face)->has_children())
668 {
669 // in any case, faces can have at most two active FE indices,
670 // but here the face can have only one (namely the same as that
671 // from the cell we're sitting on), and each of the children can
672 // have only one as well. check this
673 Assert(cell->face(face)->n_active_fe_indices() == 1,
675 Assert(cell->face(face)->fe_index_is_active(
676 cell->active_fe_index()) == true,
678 for (unsigned int c = 0; c < cell->face(face)->n_children();
679 ++c)
680 if (!cell->neighbor_child_on_subface(face, c)
681 ->is_artificial())
682 Assert(cell->face(face)->child(c)->n_active_fe_indices() ==
683 1,
685
686 // right now, all that is implemented is the case that both
687 // sides use the same FE
688 for (unsigned int c = 0; c < cell->face(face)->n_children();
689 ++c)
690 if (!cell->neighbor_child_on_subface(face, c)
691 ->is_artificial())
692 Assert(cell->face(face)->child(c)->fe_index_is_active(
693 cell->active_fe_index()) == true,
695
696 // ok, start up the work
697 const FiniteElement<dim, spacedim> &fe = cell->get_fe();
698 const types::fe_index fe_index = cell->active_fe_index();
699
700 const unsigned int n_dofs_on_mother =
701 2 * fe.n_dofs_per_vertex() +
702 fe.n_dofs_per_line(),
703 n_dofs_on_children =
704 fe.n_dofs_per_vertex() +
705 2 * fe.n_dofs_per_line();
706
707 dofs_on_mother.resize(n_dofs_on_mother);
708 // we might not use all of those in case of artificial cells, so
709 // do not resize(), but reserve() and use push_back later.
710 dofs_on_children.clear();
711 dofs_on_children.reserve(n_dofs_on_children);
712
713 Assert(n_dofs_on_mother == fe.constraints().n(),
714 ExcDimensionMismatch(n_dofs_on_mother,
715 fe.constraints().n()));
716 Assert(n_dofs_on_children == fe.constraints().m(),
717 ExcDimensionMismatch(n_dofs_on_children,
718 fe.constraints().m()));
719
721 this_face = cell->face(face);
722
723 // fill the dofs indices. Use same enumeration scheme as in
724 // @p{FiniteElement::constraints()}
725 unsigned int next_index = 0;
726 for (unsigned int vertex = 0; vertex < 2; ++vertex)
727 for (unsigned int dof = 0; dof != fe.n_dofs_per_vertex();
728 ++dof)
729 dofs_on_mother[next_index++] =
730 this_face->vertex_dof_index(vertex, dof, fe_index);
731 for (unsigned int dof = 0; dof != fe.n_dofs_per_line(); ++dof)
732 dofs_on_mother[next_index++] =
733 this_face->dof_index(dof, fe_index);
734 AssertDimension(next_index, dofs_on_mother.size());
735
736 for (unsigned int dof = 0; dof != fe.n_dofs_per_vertex(); ++dof)
737 dofs_on_children.push_back(
738 this_face->child(0)->vertex_dof_index(1, dof, fe_index));
739 for (unsigned int child = 0; child < 2; ++child)
740 {
741 // skip artificial cells
742 if (cell->neighbor_child_on_subface(face, child)
743 ->is_artificial())
744 continue;
745 for (unsigned int dof = 0; dof != fe.n_dofs_per_line();
746 ++dof)
747 dofs_on_children.push_back(
748 this_face->child(child)->dof_index(dof, fe_index));
749 }
750 // note: can get fewer DoFs when we have artificial cells
751 Assert(dofs_on_children.size() <= n_dofs_on_children,
753
754 // for each row in the AffineConstraints object for this line:
755 for (unsigned int row = 0; row != dofs_on_children.size();
756 ++row)
757 {
758 constraint_entries.clear();
759 constraint_entries.reserve(dofs_on_mother.size());
760 for (unsigned int i = 0; i != dofs_on_mother.size(); ++i)
761 constraint_entries.emplace_back(dofs_on_mother[i],
762 fe.constraints()(row, i));
763
764 constraints.add_constraint(dofs_on_children[row],
765 constraint_entries,
766 0.);
767 }
768 }
769 else
770 {
771 // this face has no children, but it could still be that it is
772 // shared by two cells that use a different FE index. check a
773 // couple of things, but ignore the case that the neighbor is an
774 // artificial cell
775 if (!cell->at_boundary(face) &&
776 !cell->neighbor(face)->is_artificial())
777 {
778 Assert(cell->face(face)->n_active_fe_indices() == 1,
780 Assert(cell->face(face)->fe_index_is_active(
781 cell->active_fe_index()) == true,
783 }
784 }
785 }
786 }
787
788
789
790 template <int dim_, int spacedim, typename number>
791 void
793 const DoFHandler<dim_, spacedim> &dof_handler,
794 AffineConstraints<number> &constraints,
795 std::integral_constant<int, 3>)
796 {
797 const unsigned int dim = 3;
798
799 std::vector<types::global_dof_index> dofs_on_mother;
800 std::vector<types::global_dof_index> dofs_on_children;
801
802 // Build constraints in a vector of pairs that can be
803 // arbitrarily large, but that holds up to 25 elements without
804 // external memory allocation. This is good enough for hanging
805 // node constraints of Q4 elements in 3d, so covers most
806 // common cases.
807 boost::container::small_vector<
808 std::pair<typename AffineConstraints<number>::size_type, number>,
809 25>
810 constraint_entries;
811
812 // loop over all quads; only on quads there can be constraints. We do so
813 // by looping over all active cells and checking whether any of the faces
814 // are refined which can only be from the neighboring cell because this
815 // one is active. In that case, the face is subject to constraints
816 //
817 // note that even though we may visit a face twice if the neighboring
818 // cells are equally refined, we can only visit each face with hanging
819 // nodes once
820 for (const auto &cell : dof_handler.active_cell_iterators())
821 {
822 // artificial cells can at best neighbor ghost cells, but we're not
823 // interested in these interfaces
824 if (cell->is_artificial())
825 continue;
826
827 for (const unsigned int face : cell->face_indices())
828 if (cell->face(face)->has_children())
829 {
830 // first of all, make sure that we treat a case which is
831 // possible, i.e. either no dofs on the face at all or no
832 // anisotropic refinement
833 if (cell->get_fe().n_dofs_per_face(face) == 0)
834 continue;
835
836 Assert(cell->face(face)->refinement_case() ==
839
840 // in any case, faces can have at most two active FE indices,
841 // but here the face can have only one (namely the same as that
842 // from the cell we're sitting on), and each of the children can
843 // have only one as well. check this
844 AssertDimension(cell->face(face)->n_active_fe_indices(), 1);
845 Assert(cell->face(face)->fe_index_is_active(
846 cell->active_fe_index()) == true,
848 for (unsigned int c = 0; c < cell->face(face)->n_children();
849 ++c)
850 if (!cell->neighbor_child_on_subface(face, c)
851 ->is_artificial())
853 cell->face(face)->child(c)->n_active_fe_indices(), 1);
854
855 // right now, all that is implemented is the case that both
856 // sides use the same fe, and not only that but also that all
857 // lines bounding this face and the children have the same FE
858 for (unsigned int c = 0; c < cell->face(face)->n_children();
859 ++c)
860 if (!cell->neighbor_child_on_subface(face, c)
861 ->is_artificial())
862 {
863 Assert(cell->face(face)->child(c)->fe_index_is_active(
864 cell->active_fe_index()) == true,
866 for (unsigned int e = 0; e < 4; ++e)
867 {
868 Assert(cell->face(face)
869 ->child(c)
870 ->line(e)
871 ->n_active_fe_indices() == 1,
873 Assert(cell->face(face)
874 ->child(c)
875 ->line(e)
876 ->fe_index_is_active(
877 cell->active_fe_index()) == true,
879 }
880 }
881 for (unsigned int e = 0; e < 4; ++e)
882 {
883 Assert(cell->face(face)->line(e)->n_active_fe_indices() ==
884 1,
886 Assert(cell->face(face)->line(e)->fe_index_is_active(
887 cell->active_fe_index()) == true,
889 }
890
891 // ok, start up the work
892 const FiniteElement<dim> &fe = cell->get_fe();
893 const types::fe_index fe_index = cell->active_fe_index();
894
895 const unsigned int n_dofs_on_mother = fe.n_dofs_per_face(face);
896 const unsigned int n_dofs_on_children =
897 (5 * fe.n_dofs_per_vertex() + 12 * fe.n_dofs_per_line() +
898 4 * fe.n_dofs_per_quad(face));
899
900 // TODO[TL]: think about this and the following in case of
901 // anisotropic refinement
902
903 dofs_on_mother.resize(n_dofs_on_mother);
904 // we might not use all of those in case of artificial cells, so
905 // do not resize(), but reserve() and use push_back later.
906 dofs_on_children.clear();
907 dofs_on_children.reserve(n_dofs_on_children);
908
909 Assert(n_dofs_on_mother == fe.constraints().n(),
910 ExcDimensionMismatch(n_dofs_on_mother,
911 fe.constraints().n()));
912 Assert(n_dofs_on_children == fe.constraints().m(),
913 ExcDimensionMismatch(n_dofs_on_children,
914 fe.constraints().m()));
915
917 this_face = cell->face(face);
918
919 // fill the dofs indices. Use same enumeration scheme as in
920 // @p{FiniteElement::constraints()}
921 unsigned int next_index = 0;
922 for (unsigned int vertex = 0; vertex < 4; ++vertex)
923 for (unsigned int dof = 0; dof != fe.n_dofs_per_vertex();
924 ++dof)
925 dofs_on_mother[next_index++] =
926 this_face->vertex_dof_index(vertex, dof, fe_index);
927 for (unsigned int line = 0; line < 4; ++line)
928 for (unsigned int dof = 0; dof != fe.n_dofs_per_line(); ++dof)
929 dofs_on_mother[next_index++] =
930 this_face->line(line)->dof_index(dof, fe_index);
931 for (unsigned int dof = 0; dof != fe.n_dofs_per_quad(face);
932 ++dof)
933 dofs_on_mother[next_index++] =
934 this_face->dof_index(dof, fe_index);
935 AssertDimension(next_index, dofs_on_mother.size());
936
937 // TODO: assert some consistency assumptions
938
939 // TODO[TL]: think about this in case of anisotropic refinement
940
941 Assert(dof_handler.get_triangulation()
943 ((this_face->child(0)->vertex_index(3) ==
944 this_face->child(1)->vertex_index(2)) &&
945 (this_face->child(0)->vertex_index(3) ==
946 this_face->child(2)->vertex_index(1)) &&
947 (this_face->child(0)->vertex_index(3) ==
948 this_face->child(3)->vertex_index(0))),
950
951 for (unsigned int dof = 0; dof != fe.n_dofs_per_vertex(); ++dof)
952 dofs_on_children.push_back(
953 this_face->child(0)->vertex_dof_index(3, dof));
954
955 // dof numbers on the centers of the lines bounding this face
956 for (unsigned int line = 0; line < 4; ++line)
957 for (unsigned int dof = 0; dof != fe.n_dofs_per_vertex();
958 ++dof)
959 dofs_on_children.push_back(
960 this_face->line(line)->child(0)->vertex_dof_index(
961 1, dof, fe_index));
962
963 // next the dofs on the lines interior to the face; the order of
964 // these lines is laid down in the FiniteElement class
965 // documentation
966 for (unsigned int dof = 0; dof < fe.n_dofs_per_line(); ++dof)
967 dofs_on_children.push_back(
968 this_face->child(0)->line(1)->dof_index(dof, fe_index));
969 for (unsigned int dof = 0; dof < fe.n_dofs_per_line(); ++dof)
970 dofs_on_children.push_back(
971 this_face->child(2)->line(1)->dof_index(dof, fe_index));
972 for (unsigned int dof = 0; dof < fe.n_dofs_per_line(); ++dof)
973 dofs_on_children.push_back(
974 this_face->child(0)->line(3)->dof_index(dof, fe_index));
975 for (unsigned int dof = 0; dof < fe.n_dofs_per_line(); ++dof)
976 dofs_on_children.push_back(
977 this_face->child(1)->line(3)->dof_index(dof, fe_index));
978
979 // dofs on the bordering lines
980 for (unsigned int line = 0; line < 4; ++line)
981 for (unsigned int child = 0; child < 2; ++child)
982 {
983 for (unsigned int dof = 0; dof != fe.n_dofs_per_line();
984 ++dof)
985 dofs_on_children.push_back(
986 this_face->line(line)->child(child)->dof_index(
987 dof, fe_index));
988 }
989
990 // finally, for the dofs interior to the four child faces
991 for (unsigned int child = 0; child < 4; ++child)
992 {
993 // skip artificial cells
994 if (cell->neighbor_child_on_subface(face, child)
995 ->is_artificial())
996 continue;
997 for (unsigned int dof = 0; dof != fe.n_dofs_per_quad(face);
998 ++dof)
999 dofs_on_children.push_back(
1000 this_face->child(child)->dof_index(dof, fe_index));
1001 }
1002
1003 // note: can get fewer DoFs when we have artificial cells:
1004 Assert(dofs_on_children.size() <= n_dofs_on_children,
1006
1007 // For each row in the AffineConstraints object for
1008 // this line, add the constraint. Ignore rows that
1009 // have already been added (e.g., in 3d degrees of
1010 // freedom on edges with hanging nodes will be visited
1011 // more than once).
1012 for (unsigned int row = 0; row != dofs_on_children.size();
1013 ++row)
1014 if (constraints.is_constrained(dofs_on_children[row]) ==
1015 false)
1016 {
1017 constraint_entries.clear();
1018 constraint_entries.reserve(dofs_on_mother.size());
1019 for (unsigned int i = 0; i != dofs_on_mother.size(); ++i)
1020 constraint_entries.emplace_back(dofs_on_mother[i],
1021 fe.constraints()(row,
1022 i));
1023
1024 constraints.add_constraint(dofs_on_children[row],
1025 constraint_entries,
1026 0.);
1027 }
1028 }
1029 else
1030 {
1031 // this face has no children, but it could still be that it is
1032 // shared by two cells that use a different FE index. check a
1033 // couple of things, but ignore the case that the neighbor is an
1034 // artificial cell
1035 if (!cell->at_boundary(face) &&
1036 !cell->neighbor(face)->is_artificial())
1037 {
1038 Assert(cell->face(face)->n_active_fe_indices() == 1,
1040 Assert(cell->face(face)->fe_index_is_active(
1041 cell->active_fe_index()) == true,
1043 }
1044 }
1045 }
1046 }
1047
1048
1049
1050 template <int dim_, int spacedim, typename number>
1051 void
1053 const DoFHandler<dim_, spacedim> &dof_handler,
1054 AffineConstraints<number> &constraints,
1055 std::integral_constant<int, 2>)
1056 {
1057 // Parts of this function are very similar to
1058 // make_oldstyle_hanging_node_constraints.
1059 // Therefore, only the parts that differ from the
1060 // make_oldstyle_hanging_node_constraints are commented on.
1061
1062 const unsigned int dim = 2;
1063
1064 std::vector<types::global_dof_index> face_dof_indices;
1065 std::map<types::global_dof_index, std::set<types::global_dof_index>>
1066 depends_on;
1067
1068 // loop over all lines
1069 for (const auto &cell : dof_handler.active_cell_iterators())
1070 {
1071 // skip artificial cells
1072 if (cell->is_artificial())
1073 continue;
1074
1075 // loop over all faces:
1076 for (const unsigned int f : cell->face_indices())
1077 {
1078 // check if the neighbor is refined; if so, we need to
1079 // treat the constraints on this interface
1080 if (!cell->face(f)->has_children())
1081 continue;
1082
1083 Assert(cell->face(f)->n_active_fe_indices() == 1,
1085 Assert(cell->face(f)->fe_index_is_active(
1086 cell->active_fe_index()) == true,
1088
1089#ifdef DEBUG
1090 for (unsigned int c = 0; c < cell->face(f)->n_children(); ++c)
1091 {
1092 if (cell->neighbor_child_on_subface(f, c)->is_artificial())
1093 continue;
1094
1095 Assert(cell->face(f)->child(c)->n_active_fe_indices() == 1,
1097
1098 Assert(cell->face(f)->child(c)->fe_index_is_active(
1099 cell->active_fe_index()) == true,
1101 }
1102#endif // DEBUG
1103
1104 // Ok, start up the work:
1105 const FiniteElement<dim, spacedim> &fe = cell->get_fe();
1106
1107 const unsigned int n_dofs = fe.n_dofs_per_line();
1108 face_dof_indices.resize(n_dofs);
1109
1110 cell->face(f)->get_dof_indices(face_dof_indices);
1111 const std::vector<types::global_dof_index> dof_on_mother_face =
1112 face_dof_indices;
1113
1114 cell->face(f)->child(0)->get_dof_indices(face_dof_indices);
1115 const std::vector<types::global_dof_index> dof_on_child_face_0 =
1116 face_dof_indices;
1117
1118 cell->face(f)->child(1)->get_dof_indices(face_dof_indices);
1119 const std::vector<types::global_dof_index> dof_on_child_face_1 =
1120 face_dof_indices;
1121
1122 // As the Nedelec elements are oriented, we need to take care of
1123 // the orientation of the lines.
1124 // Remark: "false" indicates the line is not flipped.
1125 // "true" indicates the line is flipped.
1126
1127 // get the orientation of the faces
1128 const bool direction_mother = (cell->face(f)->vertex_index(0) >
1129 cell->face(f)->vertex_index(1)) ?
1130 false :
1131 true;
1132 const bool direction_child_0 =
1133 (cell->face(f)->child(0)->vertex_index(0) >
1134 cell->face(f)->child(0)->vertex_index(1)) ?
1135 false :
1136 true;
1137 const bool direction_child_1 =
1138 (cell->face(f)->child(1)->vertex_index(0) >
1139 cell->face(f)->child(1)->vertex_index(1)) ?
1140 false :
1141 true;
1142
1143 for (unsigned int row = 0; row < n_dofs; ++row)
1144 {
1145 constraints.add_line(dof_on_child_face_0[row]);
1146 constraints.add_line(dof_on_child_face_1[row]);
1147 }
1148
1149 for (unsigned int row = 0; row < n_dofs; ++row)
1150 {
1151 for (unsigned int dof_i_on_mother = 0;
1152 dof_i_on_mother < n_dofs;
1153 ++dof_i_on_mother)
1154 {
1155 // We need to keep in mind that, if we use a FE_System
1156 // with multiple FE_NedelecSZ blocks inside, we need
1157 // to consider, that n_dofs depends on the number
1158 // of FE_NedelecSZ blocks used.
1159 unsigned int shift_0 =
1160 (direction_mother == direction_child_0) ? 0 : n_dofs;
1161 constraints.add_entry(dof_on_child_face_0[row],
1162 dof_on_mother_face[dof_i_on_mother],
1163 fe.constraints()(row + shift_0,
1164 dof_i_on_mother));
1165
1166 unsigned int shift_1 =
1167 (direction_mother == direction_child_1) ? 0 : n_dofs;
1168 constraints.add_entry(dof_on_child_face_1[row],
1169 dof_on_mother_face[dof_i_on_mother],
1170 fe.constraints()(row + shift_1,
1171 dof_i_on_mother));
1172 }
1173 }
1174 }
1175 }
1176 }
1177
1178
1179 template <int dim_, int spacedim, typename number>
1180 void
1182 const DoFHandler<dim_, spacedim> &dof_handler,
1183 AffineConstraints<number> &constraints,
1184 std::integral_constant<int, 3>)
1185 {
1186 // Parts of this function are very similar to
1187 // make_oldstyle_hanging_node_constraints.
1188 // Therefore, only the parts that differ from the
1189 // make_oldstyle_hanging_node_constraints are commented on.
1190
1191 const unsigned int dim = 3;
1192
1193 std::vector<types::global_dof_index> dofs_on_mother;
1194 std::vector<types::global_dof_index> dofs_on_children;
1195
1196 // loop over all quads
1197 for (const auto &cell : dof_handler.active_cell_iterators())
1198 {
1199 // skip artificial cells
1200 if (cell->is_artificial())
1201 continue;
1202
1203 // loop over all faces
1204 for (const unsigned int face : cell->face_indices())
1205 {
1206 // skip cells without children
1207 if (cell->face(face)->has_children() == false)
1208 continue;
1209
1210 if (cell->get_fe().n_dofs_per_face(face) == 0)
1211 continue;
1212
1213 Assert(cell->face(face)->refinement_case() ==
1216
1217 AssertDimension(cell->face(face)->n_active_fe_indices(), 1);
1218
1219 Assert(cell->face(face)->fe_index_is_active(
1220 cell->active_fe_index()) == true,
1222
1223#ifdef DEBUG
1224
1225 for (unsigned int c = 0; c < cell->face(face)->n_children(); ++c)
1226 {
1227 if (cell->neighbor_child_on_subface(face, c)->is_artificial())
1228 continue;
1229
1231 cell->face(face)->child(c)->n_active_fe_indices(), 1);
1232
1233 Assert(cell->face(face)->child(c)->fe_index_is_active(
1234 cell->active_fe_index()) == true,
1236
1237 for (unsigned int e = 0;
1238 e < GeometryInfo<dim>::vertices_per_face;
1239 ++e)
1240 {
1241 Assert(cell->face(face)
1242 ->child(c)
1243 ->line(e)
1244 ->n_active_fe_indices() == 1,
1246
1247 Assert(
1248 cell->face(face)->child(c)->line(e)->fe_index_is_active(
1249 cell->active_fe_index()) == true,
1251 }
1252 }
1253
1254 for (unsigned int e = 0; e < GeometryInfo<dim>::vertices_per_face;
1255 ++e)
1256 {
1257 Assert(cell->face(face)->line(e)->n_active_fe_indices() == 1,
1259
1260 Assert(cell->face(face)->line(e)->fe_index_is_active(
1261 cell->active_fe_index()) == true,
1263 }
1264#endif // DEBUG
1265
1266 // Ok, start up the work
1267 const FiniteElement<dim, spacedim> &fe = cell->get_fe();
1268 const unsigned int fe_index = cell->active_fe_index();
1269
1270 // get the polynomial degree
1271 unsigned int degree(fe.degree);
1272
1273 // get the number of DoFs on mother and children;
1274 // number of DoFs on the mother
1275 const unsigned int n_dofs_on_mother = fe.n_dofs_per_face(face);
1276 dofs_on_mother.resize(n_dofs_on_mother);
1277
1278 const unsigned int n_lines_on_mother =
1280
1281 // number of internal lines of the children;
1282 // for more details see description of the
1283 // GeometryInfo<dim> class
1284 // .................
1285 // . | .
1286 // . c2 1 c3 .
1287 // . | .
1288 // .---2---+---3---.
1289 // . | .
1290 // . c0 0 c1 .
1291 // . | .
1292 // .................
1293 const unsigned int n_internal_lines_on_children = 4;
1294
1295 // number of external lines of the children
1296 // +---6--------7--+
1297 // | . |
1298 // 1 c2 . c3 3
1299 // | . |
1300 // |...............|
1301 // | . |
1302 // 0 c0 . c1 2
1303 // | . |
1304 // +---4---+---5---+
1305 const unsigned int n_external_lines_on_children = 8;
1306
1307 const unsigned int n_lines_on_children =
1308 n_internal_lines_on_children + n_external_lines_on_children;
1309
1310 // we only consider the isotropic case here
1311 const unsigned int n_children_per_face =
1313 const unsigned int n_children_per_line =
1314 GeometryInfo<dim - 1>::max_children_per_face;
1315
1316 // number of DoFs on the children
1317 // Remark: Nedelec elements have no DoFs on the vertices,
1318 // therefore we skip the vertices
1319 const unsigned int n_dofs_on_children =
1320 (n_lines_on_children * fe.n_dofs_per_line() +
1321 n_children_per_face * fe.n_dofs_per_quad(face));
1322
1323 dofs_on_children.clear();
1324 dofs_on_children.reserve(n_dofs_on_children);
1325
1326 AssertDimension(n_dofs_on_mother, fe.constraints().n());
1327 AssertDimension(n_dofs_on_children, fe.constraints().m());
1328
1329 // get the current face
1330 const typename DoFHandler<dim, dim>::face_iterator this_face =
1331 cell->face(face);
1332
1333 // fill the DoFs on the mother:
1334 unsigned int next_index = 0;
1335
1336 // DoFs on vertices:
1337 // Nedelec elements have no DoFs on the vertices
1338
1339 // DoFs on lines:
1340 for (unsigned int line = 0;
1341 line < GeometryInfo<dim>::lines_per_face;
1342 ++line)
1343 for (unsigned int dof = 0; dof != fe.n_dofs_per_line(); ++dof)
1344 dofs_on_mother[next_index++] =
1345 this_face->line(line)->dof_index(dof, fe_index);
1346
1347 // DoFs on the face:
1348 for (unsigned int dof = 0; dof != fe.n_dofs_per_quad(face); ++dof)
1349 dofs_on_mother[next_index++] =
1350 this_face->dof_index(dof, fe_index);
1351
1352 // check that we have added all DoFs
1353 AssertDimension(next_index, dofs_on_mother.size());
1354
1355 // the implementation does not support anisotropic refinement
1356 Assert(!dof_handler.get_triangulation()
1359
1360 // fill the DoF on the children:
1361 // DoFs on vertices:
1362 // Nedelec elements have no DoFs on the vertices
1363
1364 // DoFs on lines:
1365 // the DoFs on the interior lines to the children; the order
1366 // of these lines is shown above (see
1367 // n_internal_lines_on_children)
1368 for (unsigned int dof = 0; dof < fe.n_dofs_per_line(); ++dof)
1369 dofs_on_children.push_back(
1370 this_face->child(0)->line(1)->dof_index(dof, fe_index));
1371
1372 for (unsigned int dof = 0; dof < fe.n_dofs_per_line(); ++dof)
1373 dofs_on_children.push_back(
1374 this_face->child(2)->line(1)->dof_index(dof, fe_index));
1375
1376 for (unsigned int dof = 0; dof < fe.n_dofs_per_line(); ++dof)
1377 dofs_on_children.push_back(
1378 this_face->child(0)->line(3)->dof_index(dof, fe_index));
1379
1380 for (unsigned int dof = 0; dof < fe.n_dofs_per_line(); ++dof)
1381 dofs_on_children.push_back(
1382 this_face->child(1)->line(3)->dof_index(dof, fe_index));
1383
1384 // DoFs on the bordering lines:
1385 // DoFs on the exterior lines to the children; the order of
1386 // these lines is shown above (see n_external_lines_on_children)
1387 for (unsigned int line = 0;
1388 line < GeometryInfo<dim>::lines_per_face;
1389 ++line)
1390 for (unsigned int child = 0; child < n_children_per_line;
1391 ++child)
1392 for (unsigned int dof = 0; dof < fe.n_dofs_per_line(); ++dof)
1393 dofs_on_children.push_back(
1394 this_face->line(line)->child(child)->dof_index(dof,
1395 fe_index));
1396
1397 // DoFs on the faces of the four children:
1398 for (unsigned int child = 0; child < n_children_per_face; ++child)
1399 {
1400 // skip artificial cells
1401 if (cell->neighbor_child_on_subface(face, child)
1402 ->is_artificial())
1403 continue;
1404
1405 for (unsigned int dof = 0; dof < fe.n_dofs_per_quad(face);
1406 ++dof)
1407 dofs_on_children.push_back(
1408 this_face->child(child)->dof_index(dof, fe_index));
1409 } // rof: child
1410
1411 // consistency check:
1412 // note: we can get fewer DoFs when we have artificial cells
1413 Assert(dofs_on_children.size() <= n_dofs_on_children,
1415
1416 // As the Nedelec elements are oriented, we need to take care of
1417 // the orientation of the lines.
1418 // Remark: "false" indicates the line is not flipped.
1419 // "true" indicates the line is flipped.
1420
1421 // Orientation - Lines:
1422 // get the orientation from the edges from the mother cell
1423 std::vector<bool> direction_mother(
1425 for (unsigned int line = 0;
1426 line < GeometryInfo<dim>::lines_per_face;
1427 ++line)
1428 if (this_face->line(line)->vertex_index(0) >
1429 this_face->line(line)->vertex_index(1))
1430 direction_mother[line] = true;
1431
1432 // get the orientation from the intern edges of the children
1433 std::vector<bool> direction_child_intern(
1434 n_internal_lines_on_children, false);
1435
1436 // get the global vertex index of vertex in the center;
1437 // we need this vertex index, to compute the direction
1438 // of the internal edges
1439 unsigned int center = this_face->child(0)->vertex_index(3);
1440
1441 // compute the direction of the internal edges
1442 for (unsigned int line = 0; line < n_internal_lines_on_children;
1443 ++line)
1444 if (line % 2 == 0)
1445 {
1446 direction_child_intern[line] =
1447 this_face->line(line)->child(0)->vertex_index(1) <
1448 center ?
1449 false :
1450 true;
1451 }
1452 else
1453 {
1454 direction_child_intern[line] =
1455 this_face->line(line)->child(0)->vertex_index(1) >
1456 center ?
1457 false :
1458 true;
1459 }
1460
1461 // compute the direction of the outer edges
1462 std::vector<bool> direction_child(n_external_lines_on_children,
1463 false);
1464 for (unsigned int line = 0;
1465 line < GeometryInfo<dim>::lines_per_face;
1466 ++line)
1467 {
1468 if (this_face->line(line)->child(0)->vertex_index(0) >
1469 this_face->line(line)->child(0)->vertex_index(1))
1470 direction_child[2 * line] = true;
1471 if (this_face->line(line)->child(1)->vertex_index(0) >
1472 this_face->line(line)->child(1)->vertex_index(1))
1473 direction_child[2 * line + 1] = true;
1474 }
1475
1476
1477 // Orientation - Faces:
1478 bool mother_flip_x = false;
1479 bool mother_flip_y = false;
1480 bool mother_flip_xy = false;
1481 std::vector<bool> child_flip_x(n_children_per_face, false);
1482 std::vector<bool> child_flip_y(n_children_per_face, false);
1483 std::vector<bool> child_flip_xy(n_children_per_face, false);
1484 const unsigned int
1485 vertices_adjacent_on_face[GeometryInfo<dim>::vertices_per_face]
1486 [2] = {{1, 2}, {0, 3}, {3, 0}, {2, 1}};
1487
1488 {
1489 // Mother
1490 // get the position of the vertex with the highest number
1491 unsigned int current_glob = cell->face(face)->vertex_index(0);
1492 unsigned int current_max = 0;
1493 for (unsigned int v = 1;
1494 v < GeometryInfo<dim>::vertices_per_face;
1495 ++v)
1496 if (current_glob < this_face->vertex_index(v))
1497 {
1498 current_max = v;
1499 current_glob = this_face->vertex_index(v);
1500 }
1501
1502 // if the vertex with the highest DoF index is in the lower row
1503 // of the face, the face is flipped in y direction
1504 if (current_max < 2)
1505 mother_flip_y = true;
1506
1507 // if the vertex with the highest DoF index is on the left side
1508 // of the face is flipped in x direction
1509 if (current_max % 2 == 0)
1510 mother_flip_x = true;
1511
1512 // get the minor direction of the face of the mother
1513 if (this_face->vertex_index(
1514 vertices_adjacent_on_face[current_max][0]) <
1515 this_face->vertex_index(
1516 vertices_adjacent_on_face[current_max][1]))
1517 mother_flip_xy = true;
1518 }
1519
1520 // Children:
1521 // get the orientation of the faces of the children
1522 for (unsigned int child = 0; child < n_children_per_face; ++child)
1523 {
1524 unsigned int current_max = 0;
1525 unsigned int current_glob =
1526 this_face->child(child)->vertex_index(0);
1527
1528 for (unsigned int v = 1;
1529 v < GeometryInfo<dim>::vertices_per_face;
1530 ++v)
1531 if (current_glob < this_face->child(child)->vertex_index(v))
1532 {
1533 current_max = v;
1534 current_glob = this_face->child(child)->vertex_index(v);
1535 }
1536
1537 if (current_max < 2)
1538 child_flip_y[child] = true;
1539
1540 if (current_max % 2 == 0)
1541 child_flip_x[child] = true;
1542
1543 if (this_face->child(child)->vertex_index(
1544 vertices_adjacent_on_face[current_max][0]) <
1545 this_face->child(child)->vertex_index(
1546 vertices_adjacent_on_face[current_max][1]))
1547 child_flip_xy[child] = true;
1548
1549 child_flip_xy[child] = mother_flip_xy;
1550 }
1551
1552 // copy the constraint matrix, since we need to modify that matrix
1553 std::vector<std::vector<double>> constraints_matrix(
1554 n_lines_on_children * fe.n_dofs_per_line() +
1555 n_children_per_face * fe.n_dofs_per_quad(),
1556 std::vector<double>(dofs_on_mother.size(), 0));
1557
1558 {
1559 // copy the constraint matrix
1560 // internal lines
1561 for (unsigned int line = 0; line < n_internal_lines_on_children;
1562 ++line)
1563 {
1564 unsigned int row_start = line * fe.n_dofs_per_line();
1565 unsigned int line_mother = line / 2;
1566 unsigned int row_mother =
1567 (line_mother * 2) * fe.n_dofs_per_line();
1568 for (unsigned int row = 0; row < fe.n_dofs_per_line();
1569 ++row)
1570 for (unsigned int i = 0;
1571 i < n_lines_on_mother * fe.n_dofs_per_line();
1572 ++i)
1573 constraints_matrix[row + row_start][i] =
1574 fe.constraints()(row + row_mother, i);
1575 }
1576
1577 for (unsigned int line = 0; line < n_internal_lines_on_children;
1578 ++line)
1579 {
1580 unsigned int row_start = line * fe.n_dofs_per_line();
1581 unsigned int line_mother = line / 2;
1582 unsigned int row_mother =
1583 (line_mother * 2) * fe.n_dofs_per_line();
1584 for (unsigned int row = 0; row < fe.n_dofs_per_line();
1585 ++row)
1586 for (unsigned int i =
1587 n_lines_on_mother * fe.n_dofs_per_line();
1588 i < dofs_on_mother.size();
1589 ++i)
1590 constraints_matrix[row + row_start][i] =
1591 fe.constraints()(row + row_mother, i);
1592 }
1593
1594 // external lines
1595 unsigned int row_offset =
1596 n_internal_lines_on_children * fe.n_dofs_per_line();
1597 for (unsigned int line = 0; line < n_external_lines_on_children;
1598 line++)
1599 {
1600 unsigned int row_start = line * fe.n_dofs_per_line();
1601 unsigned int line_mother = line / 2;
1602 unsigned int row_mother =
1603 (line_mother * 2) * fe.n_dofs_per_line();
1604 for (unsigned int row = row_offset;
1605 row < row_offset + fe.n_dofs_per_line();
1606 ++row)
1607 for (unsigned int i = 0; i < dofs_on_mother.size(); ++i)
1608 constraints_matrix[row + row_start][i] =
1609 fe.constraints()(row + row_mother, i);
1610 }
1611
1612 // copy the weights for the faces
1613 row_offset = n_lines_on_children * fe.n_dofs_per_line();
1614 for (unsigned int face = 0; face < n_children_per_face; ++face)
1615 {
1616 unsigned int row_start = face * fe.n_dofs_per_quad();
1617 for (unsigned int row = row_offset;
1618 row < row_offset + fe.n_dofs_per_quad();
1619 row++)
1620 for (unsigned int i = 0; i < dofs_on_mother.size(); ++i)
1621 constraints_matrix[row + row_start][i] =
1622 fe.constraints()(row, i);
1623 }
1624 }
1625
1626 // Modify the matrix
1627 // Edge - Edge:
1628 // Interior edges: the interior edges have support on the
1629 // corresponding edges and faces loop over all 4 intern edges
1630 for (unsigned int i = 0;
1631 i < n_internal_lines_on_children * fe.n_dofs_per_line();
1632 ++i)
1633 {
1634 unsigned int line_i = i / fe.n_dofs_per_line();
1635 unsigned int tmp_i = i % degree;
1636
1637 // loop over the edges of the mother cell
1638 for (unsigned int j = 0;
1639 j < n_lines_on_mother * fe.n_dofs_per_line();
1640 ++j)
1641 {
1642 unsigned int line_j = j / fe.n_dofs_per_line();
1643 unsigned int tmp_j = j % degree;
1644
1645 if ((line_i < 2 && line_j < 2) ||
1646 (line_i >= 2 && line_j >= 2))
1647 {
1648 if (direction_child_intern[line_i] !=
1649 direction_mother[line_j])
1650 {
1651 if ((tmp_i + tmp_j) % 2 == 1)
1652 { // anti-symmetric
1653 constraints_matrix[i][j] *= -1.0;
1654 }
1655 }
1656 }
1657 else
1658 {
1659 if (direction_mother[line_i])
1660 {
1661 if ((tmp_i + tmp_j) % 2 == 1)
1662 { // anti-symmetric
1663 constraints_matrix[i][j] *= -1.0;
1664 }
1665 }
1666 }
1667 }
1668 }
1669
1670 // Exterior edges:
1671 for (unsigned int i =
1672 n_internal_lines_on_children * fe.n_dofs_per_line();
1673 i < n_lines_on_children * fe.n_dofs_per_line();
1674 ++i)
1675 {
1676 unsigned int line_i = (i / fe.n_dofs_per_line()) - 4;
1677 unsigned int tmp_i = i % degree;
1678
1679 // loop over the edges of the mother cell
1680 for (unsigned int j = 0;
1681 j < n_lines_on_mother * fe.n_dofs_per_line();
1682 ++j)
1683 {
1684 unsigned int line_j = j / fe.n_dofs_per_line();
1685 unsigned int tmp_j = j % degree;
1686
1687 if (direction_child[line_i] != direction_mother[line_j])
1688 {
1689 if ((tmp_i + tmp_j) % 2 == 1)
1690 { // anti-symmetric
1691 constraints_matrix[i][j] *= -1.0;
1692 }
1693 }
1694 }
1695 }
1696
1697 // Note:
1698 // We need to keep in mind that, if we use a FE_System
1699 // with multiple FE_NedelecSZ blocks inside, we need
1700 // to consider, that fe.n_dofs_per_line() depends on the number
1701 // of FE_NedelecSZ blocks used.
1702 const unsigned int n_blocks = fe.n_dofs_per_line() / degree;
1703
1704 // Edge - Face
1705 // Interior edges: for x-direction
1706 for (unsigned int i = 0; i < 2 * fe.n_dofs_per_line(); ++i)
1707 {
1708 unsigned int line_i = i / fe.n_dofs_per_line();
1709 unsigned int tmp_i = i % degree;
1710
1711 unsigned int start_j =
1712 n_lines_on_mother * fe.n_dofs_per_line();
1713
1714 for (unsigned int block = 0; block < n_blocks; ++block)
1715 {
1716 // Type 1:
1717 for (unsigned int jy = 0; jy < degree - 1; ++jy)
1718 for (unsigned int jx = 0; jx < degree - 1; ++jx)
1719 {
1720 unsigned int j = start_j + jx + (jy * (degree - 1));
1721 if (direction_child_intern[line_i] != mother_flip_y)
1722 {
1723 if ((jy + tmp_i) % 2 == 0)
1724 { // anti-symmetric case
1725 constraints_matrix[i][j] *= -1.0;
1726 }
1727 }
1728 }
1729
1730 start_j += (degree - 1) * (degree - 1);
1731
1732 // Type 2:
1733 for (unsigned int jy = 0; jy < degree - 1; ++jy)
1734 for (unsigned int jx = 0; jx < degree - 1; ++jx)
1735 {
1736 unsigned int j = start_j + jx + (jy * (degree - 1));
1737
1738 if (direction_child_intern[line_i] != mother_flip_y)
1739 {
1740 if ((jy + tmp_i) % 2 == 0)
1741 { // anti-symmetric case
1742 constraints_matrix[i][j] *= -1.0;
1743 }
1744 }
1745 }
1746 start_j += (degree - 1) * (degree - 1);
1747
1748 // Type 3.1:
1749 // nothing to do
1750 start_j += degree - 1;
1751
1752 // Type 3.2:
1753 // nothing to do
1754 start_j += degree - 1;
1755 }
1756 }
1757
1758 // Interior edges: for y-direction
1759 for (unsigned int i = 2 * fe.n_dofs_per_line();
1760 i < 4 * fe.n_dofs_per_line();
1761 i++)
1762 {
1763 unsigned int line_i = i / fe.n_dofs_per_line();
1764 unsigned int tmp_i = i % degree;
1765
1766 unsigned int start_j =
1767 n_lines_on_mother * fe.n_dofs_per_line();
1768
1769 for (unsigned int block = 0; block < n_blocks; block++)
1770 {
1771 // Type 1:
1772 for (unsigned int jy = 0; jy < degree - 1; ++jy)
1773 for (unsigned int jx = 0; jx < degree - 1; ++jx)
1774 {
1775 unsigned int j = start_j + jx + (jy * (degree - 1));
1776 if (direction_child_intern[line_i] != mother_flip_x)
1777 {
1778 if ((jx + tmp_i) % 2 == 0)
1779 { // anti-symmetric case
1780 constraints_matrix[i][j] *= -1.0;
1781 }
1782 }
1783 }
1784
1785 start_j += (degree - 1) * (degree - 1);
1786
1787 // Type 2:
1788 for (unsigned int jy = 0; jy < degree - 1; ++jy)
1789 for (unsigned int jx = 0; jx < degree - 1; ++jx)
1790 {
1791 unsigned int j = start_j + jx + (jy * (degree - 1));
1792 if (direction_child_intern[line_i] != mother_flip_x)
1793 {
1794 if ((jx + tmp_i) % 2 == 0)
1795 { // anti-symmetric case
1796 constraints_matrix[i][j] *= -1.0;
1797 }
1798 }
1799 }
1800 start_j += (degree - 1) * (degree - 1);
1801
1802 // Type 3.1:
1803 // nothing to do
1804 start_j += degree - 1;
1805
1806 // Type 3.2:
1807 // nothing to do
1808 start_j += degree - 1;
1809 }
1810 }
1811
1812 // Face - Face
1813 unsigned int degree_square = (degree - 1) * (degree - 1);
1814 {
1815 // Face
1816 unsigned int i = n_lines_on_children * fe.n_dofs_per_line();
1817 for (unsigned int child_face = 0;
1818 child_face < n_children_per_face;
1819 ++child_face)
1820 for (unsigned int block = 0; block < n_blocks; ++block)
1821 {
1822 unsigned int block_size = fe.n_dofs_per_quad() / n_blocks;
1823
1824 // check if the counting of the DoFs is correct:
1825 Assert((block == 0 &&
1826 i != n_lines_on_children * fe.n_dofs_per_line() +
1827 child_face * fe.n_dofs_per_quad()) ==
1828 false,
1830
1831 // Type 1:
1832 for (unsigned int iy = 0; iy < degree - 1; ++iy)
1833 for (unsigned int ix = 0; ix < degree - 1; ++ix)
1834 {
1835 // Type 1 on mother:
1836 unsigned int j =
1837 n_lines_on_mother * fe.n_dofs_per_line() +
1838 block * block_size;
1839 for (unsigned int jy = 0; jy < degree - 1; ++jy)
1840 for (unsigned int jx = 0; jx < degree - 1; ++jx)
1841 {
1842 if (child_flip_x[child_face] !=
1843 mother_flip_x) // x - direction (x-flip)
1844 {
1845 if ((ix + jx) % 2 == 1)
1846 { // anti-symmetric in x
1847 constraints_matrix[i][j] *= -1.0;
1848 }
1849 }
1850
1851 if (child_flip_y[child_face] !=
1852 mother_flip_y) // y - direction (y-flip)
1853 {
1854 if ((iy + jy) % 2 == 1)
1855 { // anti-symmetric in y
1856 constraints_matrix[i][j] *= -1.0;
1857 }
1858 }
1859
1860 j++;
1861 }
1862 i++;
1863 }
1864
1865 // Type 2:
1866 for (unsigned int iy = 0; iy < degree - 1; ++iy)
1867 for (unsigned int ix = 0; ix < degree - 1; ++ix)
1868 {
1869 // Type 2 on mother:
1870 unsigned int j =
1871 n_lines_on_mother * fe.n_dofs_per_line() +
1872 degree_square + block * block_size;
1873 for (unsigned int jy = 0; jy < degree - 1; ++jy)
1874 for (unsigned int jx = 0; jx < degree - 1; ++jx)
1875 {
1876 if (child_flip_x[child_face] !=
1877 mother_flip_x) // x - direction (x-flip)
1878 {
1879 if ((ix + jx) % 2 == 1)
1880 { // anti-symmetric in x
1881 constraints_matrix[i][j] *= -1.0;
1882 }
1883 }
1884
1885 if (child_flip_y[child_face] !=
1886 mother_flip_y) // y - direction (y-flip)
1887 {
1888 if ((iy + jy) % 2 == 1)
1889 { // anti-symmetric in y
1890 constraints_matrix[i][j] *= -1.0;
1891 }
1892 }
1893
1894 j++;
1895 }
1896
1897 i++;
1898 }
1899
1900
1901 // Type 3 (y):
1902 for (unsigned int iy = 0; iy < degree - 1; ++iy)
1903 {
1904 // Type 2 on mother:
1905 unsigned int j =
1906 n_lines_on_mother * fe.n_dofs_per_line() +
1907 degree_square + block * block_size;
1908 for (unsigned int jy = 0; jy < degree - 1; ++jy)
1909 for (unsigned int jx = 0; jx < degree - 1; ++jx)
1910 {
1911 if (child_flip_x[child_face] !=
1912 mother_flip_x) // x - direction (x-flip)
1913 {
1914 if ((jx) % 2 == 0)
1915 { // anti-symmetric in x
1916 constraints_matrix[i][j] *= -1.0;
1917 }
1918 }
1919
1920 if (child_flip_y[child_face] !=
1921 mother_flip_y) // y - direction (y-flip)
1922 {
1923 if ((iy + jy) % 2 == 1)
1924 { // anti-symmetric in y
1925 constraints_matrix[i][j] *= -1.0;
1926 }
1927 }
1928
1929 j++;
1930 }
1931
1932 // Type 3 on mother:
1933 j = n_lines_on_mother * fe.n_dofs_per_line() +
1934 2 * degree_square + block * block_size;
1935 for (unsigned int jy = 0; jy < degree - 1; ++jy)
1936 {
1937 if (child_flip_y[child_face] !=
1938 mother_flip_y) // y - direction (y-flip)
1939 {
1940 if ((iy + jy) % 2 == 1)
1941 { // anti-symmetric in y
1942 constraints_matrix[i][j] *= -1.0;
1943 }
1944 }
1945
1946 j++;
1947 }
1948 i++;
1949 }
1950
1951 // Type 3 (x):
1952 for (unsigned int ix = 0; ix < degree - 1; ++ix)
1953 {
1954 // Type 2 on mother:
1955 unsigned int j =
1956 n_lines_on_mother * fe.n_dofs_per_line() +
1957 degree_square + block * block_size;
1958 for (unsigned int jy = 0; jy < degree - 1; ++jy)
1959 for (unsigned int jx = 0; jx < degree - 1; ++jx)
1960 {
1961 if (child_flip_x[child_face] !=
1962 mother_flip_x) // x - direction (x-flip)
1963 {
1964 if ((ix + jx) % 2 == 1)
1965 { // anti-symmetric in x
1966 constraints_matrix[i][j] *= -1.0;
1967 }
1968 }
1969
1970 if (child_flip_y[child_face] !=
1971 mother_flip_y) // y - direction (y-flip)
1972 {
1973 if ((jy) % 2 == 0)
1974 { // anti-symmetric in y
1975 constraints_matrix[i][j] *= -1.0;
1976 }
1977 }
1978
1979 j++;
1980 } // rof: Dof j
1981
1982 // Type 3 on mother:
1983 j = n_lines_on_mother * fe.n_dofs_per_line() +
1984 2 * degree_square + (degree - 1) +
1985 block * block_size;
1986 for (unsigned int jx = 0; jx < degree - 1; ++jx)
1987 {
1988 if (child_flip_x[child_face] !=
1989 mother_flip_x) // x - direction (x-flip)
1990 {
1991 if ((ix + jx) % 2 == 1)
1992 { // anti-symmetric in x
1993 constraints_matrix[i][j] *= -1.0;
1994 }
1995 }
1996
1997 j++;
1998 }
1999 i++;
2000 }
2001 }
2002 }
2003
2004 // Next, after we have adapted the signs in the constraint matrix,
2005 // based on the directions of the edges, we need to modify the
2006 // constraint matrix based on the orientation of the faces (i.e.
2007 // if x and y direction are exchanged on the face)
2008
2009 // interior edges:
2010 for (unsigned int i = 0;
2011 i < n_internal_lines_on_children * fe.n_dofs_per_line();
2012 ++i)
2013 {
2014 // check if x and y are permuted on the parent's face
2015 if (mother_flip_xy)
2016 {
2017 // copy the constraints:
2018 std::vector<double> constraints_matrix_old(
2019 dofs_on_mother.size(), 0);
2020 for (unsigned int j = 0; j < dofs_on_mother.size(); ++j)
2021 {
2022 constraints_matrix_old[j] = constraints_matrix[i][j];
2023 }
2024
2025 unsigned int j_start =
2026 n_lines_on_mother * fe.n_dofs_per_line();
2027 for (unsigned block = 0; block < n_blocks; block++)
2028 {
2029 // Type 1
2030 for (unsigned int jy = 0; jy < degree - 1; ++jy)
2031 for (unsigned int jx = 0; jx < degree - 1; ++jx)
2032 {
2033 unsigned int j_old =
2034 j_start + jx + (jy * (degree - 1));
2035 unsigned int j_new =
2036 j_start + jy + (jx * (degree - 1));
2037 constraints_matrix[i][j_new] =
2038 constraints_matrix_old[j_old];
2039 }
2040 j_start += degree_square;
2041
2042 // Type 2
2043 for (unsigned int jy = 0; jy < degree - 1; ++jy)
2044 for (unsigned int jx = 0; jx < degree - 1; ++jx)
2045 {
2046 unsigned int j_old =
2047 j_start + jx + (jy * (degree - 1));
2048 unsigned int j_new =
2049 j_start + jy + (jx * (degree - 1));
2050 constraints_matrix[i][j_new] =
2051 -constraints_matrix_old[j_old];
2052 }
2053 j_start += degree_square;
2054
2055 // Type 3
2056 for (unsigned int j = j_start;
2057 j < j_start + (degree - 1);
2058 j++)
2059 {
2060 constraints_matrix[i][j] =
2061 constraints_matrix_old[j + (degree - 1)];
2062 constraints_matrix[i][j + (degree - 1)] =
2063 constraints_matrix_old[j];
2064 }
2065 j_start += 2 * (degree - 1);
2066 }
2067 }
2068 }
2069
2070 {
2071 // faces:
2072 const unsigned int deg = degree - 1;
2073
2074 // copy the constraints
2075 std::vector<std::vector<double>> constraints_matrix_old(
2076 4 * fe.n_dofs_per_quad(),
2077 std::vector<double>(fe.n_dofs_per_quad(), 0));
2078 for (unsigned int i = 0;
2079 i < n_children_per_face * fe.n_dofs_per_quad();
2080 ++i)
2081 for (unsigned int j = 0; j < fe.n_dofs_per_quad(); ++j)
2082 constraints_matrix_old[i][j] = constraints_matrix
2083 [i + (n_lines_on_children * fe.n_dofs_per_line())]
2084 [j + (n_lines_on_mother * fe.n_dofs_per_line())];
2085
2086 // permute rows (on child)
2087 for (unsigned int child = 0; child < n_children_per_face;
2088 ++child)
2089 {
2090 if (!child_flip_xy[child])
2091 continue;
2092
2093 unsigned int i_start_new =
2094 n_lines_on_children * fe.n_dofs_per_line() +
2095 (child * fe.n_dofs_per_quad());
2096 unsigned int i_start_old = child * fe.n_dofs_per_quad();
2097
2098 unsigned int j_start =
2099 n_lines_on_mother * fe.n_dofs_per_line();
2100
2101 for (unsigned int block = 0; block < n_blocks; block++)
2102 {
2103 // Type 1:
2104 for (unsigned int ix = 0; ix < deg; ++ix)
2105 {
2106 for (unsigned int iy = 0; iy < deg; ++iy)
2107 {
2108 for (unsigned int j = 0;
2109 j < fe.n_dofs_per_quad();
2110 ++j)
2111 constraints_matrix[i_start_new + iy +
2112 (ix * deg)][j + j_start] =
2113 constraints_matrix_old[i_start_old + ix +
2114 (iy * deg)][j];
2115 }
2116 }
2117 i_start_new += deg * deg;
2118 i_start_old += deg * deg;
2119
2120 // Type 2:
2121 for (unsigned int ix = 0; ix < deg; ++ix)
2122 {
2123 for (unsigned int iy = 0; iy < deg; ++iy)
2124 {
2125 for (unsigned int j = 0;
2126 j < fe.n_dofs_per_quad();
2127 j++)
2128 constraints_matrix[i_start_new + iy +
2129 (ix * deg)][j + j_start] =
2130 -constraints_matrix_old[i_start_old + ix +
2131 (iy * deg)][j];
2132 }
2133 }
2134 i_start_new += deg * deg;
2135 i_start_old += deg * deg;
2136
2137 // Type 3:
2138 for (unsigned int ix = 0; ix < deg; ++ix)
2139 {
2140 for (unsigned int j = 0; j < fe.n_dofs_per_quad();
2141 ++j)
2142 constraints_matrix[i_start_new + ix][j +
2143 j_start] =
2144 constraints_matrix_old[i_start_old + ix + deg]
2145 [j];
2146 for (unsigned int j = 0; j < fe.n_dofs_per_quad();
2147 ++j)
2148 constraints_matrix[i_start_new + ix +
2149 deg][j + j_start] =
2150 constraints_matrix_old[i_start_old + ix][j];
2151 } // rof: ix
2152
2153 i_start_new += 2 * deg;
2154 i_start_old += 2 * deg;
2155 }
2156 }
2157
2158 // update the constraints_old
2159 for (unsigned int i = 0;
2160 i < n_children_per_face * fe.n_dofs_per_quad();
2161 i++)
2162 for (unsigned int j = 0; j < fe.n_dofs_per_quad(); j++)
2163 constraints_matrix_old[i][j] = constraints_matrix
2164 [i + (n_lines_on_children * fe.n_dofs_per_line())]
2165 [j + (n_lines_on_mother * fe.n_dofs_per_line())];
2166
2167 // Mother
2168 if (mother_flip_xy)
2169 {
2170 unsigned int i_start =
2171 n_lines_on_children * fe.n_dofs_per_line();
2172
2173 unsigned int j_start_new =
2174 n_lines_on_mother * fe.n_dofs_per_line();
2175 unsigned int j_start_old = 0;
2176
2177 for (unsigned int block = 0; block < n_blocks; ++block)
2178 {
2179 // Type 1:
2180 for (unsigned int jx = 0; jx < deg; ++jx)
2181 {
2182 for (unsigned int jy = 0; jy < deg; ++jy)
2183 {
2184 for (unsigned int i = 0;
2185 i <
2186 n_children_per_face * fe.n_dofs_per_quad();
2187 ++i)
2188 constraints_matrix[i + i_start][j_start_new +
2189 jy +
2190 (jx * deg)] =
2191 constraints_matrix_old[i][j_start_old + jx +
2192 (jy * deg)];
2193 }
2194 }
2195 j_start_new += deg * deg;
2196 j_start_old += deg * deg;
2197
2198 // Type 2:
2199 for (unsigned int jx = 0; jx < deg; ++jx)
2200 {
2201 for (unsigned int jy = 0; jy < deg; ++jy)
2202 {
2203 for (unsigned int i = 0;
2204 i <
2205 n_children_per_face * fe.n_dofs_per_quad();
2206 ++i)
2207 constraints_matrix[i + i_start][j_start_new +
2208 jy +
2209 (jx * deg)] =
2210 -constraints_matrix_old[i][j_start_old +
2211 jx + (jy * deg)];
2212 }
2213 }
2214 j_start_new += deg * deg;
2215 j_start_old += deg * deg;
2216
2217 // Type 3:
2218 for (unsigned int jx = 0; jx < deg; ++jx)
2219 {
2220 for (unsigned int i = 0;
2221 i < n_children_per_face * fe.n_dofs_per_quad();
2222 ++i)
2223 {
2224 constraints_matrix[i + i_start][j_start_new +
2225 jx] =
2226 constraints_matrix_old[i][j_start_old + jx +
2227 deg];
2228 constraints_matrix[i + i_start][j_start_new +
2229 jx + deg] =
2230 constraints_matrix_old[i][j_start_old + jx];
2231 }
2232 }
2233 j_start_new += 2 * deg;
2234 j_start_old += 2 * deg;
2235 }
2236 }
2237 }
2238
2239 // For each row in the AffineConstraints object for
2240 // this line, add the constraint. We split this into the different
2241 // cases.
2242
2243 // internal edges:
2244 for (unsigned int line = 0; line < n_internal_lines_on_children;
2245 ++line)
2246 {
2247 unsigned int row_start = line * fe.n_dofs_per_line();
2248
2249 for (unsigned int row = 0; row < fe.n_dofs_per_line(); ++row)
2250 {
2251 constraints.add_line(dofs_on_children[row_start + row]);
2252 for (unsigned int i = 0; i < dofs_on_mother.size(); ++i)
2253 {
2254 constraints.add_entry(
2255 dofs_on_children[row_start + row],
2256 dofs_on_mother[i],
2257 constraints_matrix[row_start + row][i]);
2258 }
2259 constraints.set_inhomogeneity(
2260 dofs_on_children[row_start + row], 0.);
2261 }
2262 }
2263
2264 // Exterior edges
2265 for (unsigned int line = 0; line < n_external_lines_on_children;
2266 ++line)
2267 {
2268 unsigned int row_start =
2269 (4 * fe.n_dofs_per_line()) + (line * fe.n_dofs_per_line());
2270
2271 for (unsigned int row = 0; row < fe.n_dofs_per_line(); ++row)
2272 {
2273 constraints.add_line(dofs_on_children[row_start + row]);
2274 for (unsigned int i = 0; i < dofs_on_mother.size(); ++i)
2275 {
2276 constraints.add_entry(
2277 dofs_on_children[row_start + row],
2278 dofs_on_mother[i],
2279 constraints_matrix[row_start + row][i]);
2280 }
2281 constraints.set_inhomogeneity(
2282 dofs_on_children[row_start + row], 0.);
2283 }
2284 }
2285
2286 // Faces:
2287 for (unsigned int f = 0; f < n_children_per_face; ++f)
2288 {
2289 unsigned int row_start =
2290 (n_lines_on_children * fe.n_dofs_per_line()) +
2291 (f * fe.n_dofs_per_quad());
2292
2293 for (unsigned int row = 0; row < fe.n_dofs_per_quad(); ++row)
2294 {
2295 constraints.add_line(dofs_on_children[row_start + row]);
2296
2297 for (unsigned int i = 0; i < dofs_on_mother.size(); ++i)
2298 {
2299 constraints.add_entry(
2300 dofs_on_children[row_start + row],
2301 dofs_on_mother[i],
2302 constraints_matrix[row_start + row][i]);
2303 }
2304
2305 constraints.set_inhomogeneity(
2306 dofs_on_children[row_start + row], 0.);
2307 }
2308 }
2309 }
2310 }
2311 }
2312
2313
2314 template <int dim, int spacedim, typename number>
2315 void
2317 const DoFHandler<dim, spacedim> &dof_handler,
2318 AffineConstraints<number> &constraints)
2319 {
2320 // note: this function is going to be hard to understand if you haven't
2321 // read the hp-paper. however, we try to follow the notation laid out
2322 // there, so go read the paper before you try to understand what is going
2323 // on here
2324
2325
2326 // a matrix to be used for constraints below. declared here and simply
2327 // resized down below to avoid permanent re-allocation of memory
2328 FullMatrix<double> constraint_matrix;
2329
2330 // similarly have arrays that will hold primary and dependent dof numbers,
2331 // as well as a scratch array needed for the complicated case below
2332 std::vector<types::global_dof_index> primary_dofs;
2333 std::vector<types::global_dof_index> dependent_dofs;
2334 std::vector<types::global_dof_index> scratch_dofs;
2335
2336 // caches for the face and subface interpolation matrices between
2337 // different (or the same) finite elements. we compute them only once,
2338 // namely the first time they are needed, and then just reuse them
2339 Table<2, std::unique_ptr<FullMatrix<double>>> face_interpolation_matrices(
2340 n_finite_elements(dof_handler), n_finite_elements(dof_handler));
2342 subface_interpolation_matrices(
2343 n_finite_elements(dof_handler),
2344 n_finite_elements(dof_handler),
2346
2347 // similarly have a cache for the matrices that are split into their
2348 // primary and dependent parts, and for which the primary part is
2349 // inverted. these two matrices are derived from the face interpolation
2350 // matrix
2351 // as described in the @ref hp_paper "hp-paper"
2352 Table<2,
2353 std::unique_ptr<std::pair<FullMatrix<double>, FullMatrix<double>>>>
2354 split_face_interpolation_matrices(n_finite_elements(dof_handler),
2355 n_finite_elements(dof_handler));
2356
2357 // finally, for each pair of finite elements, have a mask that states
2358 // which of the degrees of freedom on the coarse side of a refined face
2359 // will act as primary dofs.
2361 n_finite_elements(dof_handler), n_finite_elements(dof_handler));
2362
2363 // loop over all faces
2364 //
2365 // note that even though we may visit a face twice if the neighboring
2366 // cells are equally refined, we can only visit each face with hanging
2367 // nodes once
2368 for (const auto &cell : dof_handler.active_cell_iterators())
2369 {
2370 // artificial cells can at best neighbor ghost cells, but we're not
2371 // interested in these interfaces
2372 if (cell->is_artificial())
2373 continue;
2374
2375 for (const unsigned int face : cell->face_indices())
2376 if (cell->face(face)->has_children())
2377 {
2378 // first of all, make sure that we treat a case which is
2379 // possible, i.e. either no dofs on the face at all or no
2380 // anisotropic refinement
2381 if (cell->get_fe().n_dofs_per_face(face) == 0)
2382 continue;
2383
2384 Assert(cell->face(face)->refinement_case() ==
2387
2388 // so now we've found a face of an active cell that has
2389 // children. that means that there are hanging nodes here.
2390
2391 // in any case, faces can have at most two sets of active FE
2392 // indices, but here the face can have only one (namely the same
2393 // as that from the cell we're sitting on), and each of the
2394 // children can have only one as well. check this
2395 Assert(cell->face(face)->n_active_fe_indices() == 1,
2397 Assert(cell->face(face)->fe_index_is_active(
2398 cell->active_fe_index()) == true,
2400 for (unsigned int c = 0; c < cell->face(face)->n_children();
2401 ++c)
2402 if (!cell->neighbor_child_on_subface(face, c)
2403 ->is_artificial())
2404 Assert(cell->face(face)->child(c)->n_active_fe_indices() ==
2405 1,
2407
2408 // first find out whether we can constrain each of the subfaces
2409 // to the mother face. in the lingo of the hp-paper, this would
2410 // be the simple case. note that we can short-circuit this
2411 // decision if the dof_handler doesn't support hp at all
2412 //
2413 // ignore all interfaces with artificial cells
2414 FiniteElementDomination::Domination mother_face_dominates =
2416
2417 // auxiliary variable which holds FE indices of the mother face
2418 // and its subfaces. This knowledge will be needed in hp-case
2419 // with neither_element_dominates.
2420 std::set<types::fe_index> fe_ind_face_subface;
2421 fe_ind_face_subface.insert(cell->active_fe_index());
2422
2423 if (dof_handler.has_hp_capabilities())
2424 for (unsigned int c = 0;
2425 c < cell->face(face)->n_active_descendants();
2426 ++c)
2427 {
2428 const auto subcell =
2429 cell->neighbor_child_on_subface(face, c);
2430 if (!subcell->is_artificial())
2431 {
2432 mother_face_dominates =
2433 mother_face_dominates &
2434 (cell->get_fe().compare_for_domination(
2435 subcell->get_fe(), /*codim=*/1));
2436 fe_ind_face_subface.insert(
2437 subcell->active_fe_index());
2438 }
2439 }
2440
2441 switch (mother_face_dominates)
2442 {
2445 {
2446 // Case 1 (the simple case and the only case that can
2447 // happen for non-hp-DoFHandlers): The coarse element
2448 // dominates the elements on the subfaces (or they are
2449 // all the same)
2450 //
2451 // so we are going to constrain the DoFs on the face
2452 // children against the DoFs on the face itself
2453 primary_dofs.resize(
2454 cell->get_fe().n_dofs_per_face(face));
2455
2456 cell->face(face)->get_dof_indices(
2457 primary_dofs, cell->active_fe_index());
2458
2459 // Now create constraints for the subfaces and
2460 // assemble it. ignore all interfaces with artificial
2461 // cells because we can only get to such interfaces if
2462 // the current cell is a ghost cell
2463 for (unsigned int c = 0;
2464 c < cell->face(face)->n_children();
2465 ++c)
2466 {
2467 if (cell->neighbor_child_on_subface(face, c)
2468 ->is_artificial())
2469 continue;
2470
2471 const typename DoFHandler<dim, spacedim>::
2472 active_face_iterator subface =
2473 cell->face(face)->child(c);
2474
2475 Assert(subface->n_active_fe_indices() == 1,
2477
2478 const types::fe_index subface_fe_index =
2479 subface->nth_active_fe_index(0);
2480
2481 // we sometime run into the situation where for
2482 // example on one big cell we have a FE_Q(1) and on
2483 // the subfaces we have a mixture of FE_Q(1) and
2484 // FE_Nothing. In that case, the face domination is
2485 // either_element_can_dominate for the whole
2486 // collection of subfaces, but on the particular
2487 // subface between FE_Q(1) and FE_Nothing, there are
2488 // no constraints that we need to take care of. in
2489 // that case, just continue
2490 if (cell->get_fe().compare_for_domination(
2491 subface->get_fe(subface_fe_index),
2492 /*codim=*/1) ==
2494 continue;
2495
2496 // Same procedure as for the mother cell. Extract
2497 // the face DoFs from the cell DoFs.
2498 dependent_dofs.resize(
2499 subface->get_fe(subface_fe_index)
2500 .n_dofs_per_face(face, c));
2501 subface->get_dof_indices(dependent_dofs,
2502 subface_fe_index);
2503
2504 for (const types::global_dof_index dependent_dof :
2505 dependent_dofs)
2506 {
2507 (void)dependent_dof;
2508 Assert(dependent_dof !=
2511 }
2512
2513 // Now create the element constraint for this
2514 // subface.
2515 //
2516 // As a side remark, one may wonder the following:
2517 // neighbor_child is clearly computed correctly,
2518 // i.e. taking into account face_orientation (just
2519 // look at the implementation of that function).
2520 // however, we don't care about this here, when we
2521 // ask for subface_interpolation on subface c. the
2522 // question rather is: do we have to translate 'c'
2523 // here as well?
2524 //
2525 // the answer is in fact 'no'. if one does that,
2526 // results are wrong: constraints are added twice
2527 // for the same pair of nodes but with differing
2528 // weights. in addition, one can look at the
2529 // deal.II/project_*_03 tests that look at exactly
2530 // this case: there, we have a mesh with at least
2531 // one face_orientation==false and hanging nodes,
2532 // and the results of those tests show that the
2533 // result of projection verifies the approximation
2534 // properties of a finite element onto that mesh
2535 ensure_existence_of_subface_matrix(
2536 cell->get_fe(),
2537 subface->get_fe(subface_fe_index),
2538 c,
2539 subface_interpolation_matrices
2540 [cell->active_fe_index()][subface_fe_index][c]);
2541
2542 // Add constraints to global AffineConstraints
2543 // object.
2544 filter_constraints(primary_dofs,
2545 dependent_dofs,
2546 *(subface_interpolation_matrices
2547 [cell->active_fe_index()]
2548 [subface_fe_index][c]),
2549 constraints);
2550 } // loop over subfaces
2551
2552 break;
2553 } // Case 1
2554
2557 {
2558 // Case 2 (the "complex" case): at least one (the
2559 // neither_... case) of the finer elements or all of
2560 // them (the other_... case) is dominating. See the hp-
2561 // paper for a way how to deal with this situation
2562 //
2563 // since this is something that can only happen for hp-
2564 // dof handlers, add a check here...
2565 Assert(dof_handler.has_hp_capabilities() == true,
2567
2568 const ::hp::FECollection<dim, spacedim>
2569 &fe_collection = dof_handler.get_fe_collection();
2570 // we first have to find the finite element that is able
2571 // to generate a space that all the other ones can be
2572 // constrained to. At this point we potentially have
2573 // different scenarios:
2574 //
2575 // 1) sub-faces dominate mother face and there is a
2576 // dominating FE among sub faces. We could loop over sub
2577 // faces to find the needed FE index. However, this will
2578 // not work in the case when ...
2579 //
2580 // 2) there is no dominating FE among sub faces (e.g.
2581 // Q1xQ2 vs Q2xQ1), but subfaces still dominate mother
2582 // face (e.g. Q2xQ2). To cover this case we would have
2583 // to find the least dominating element amongst all
2584 // finite elements on sub faces.
2585 //
2586 // 3) Finally, it could happen that we got here because
2587 // neither_element_dominates (e.g. Q1xQ1xQ2 and Q1xQ2xQ1
2588 // for subfaces and Q2xQ1xQ1 for mother face). This
2589 // requires finding the least dominating element amongst
2590 // all finite elements on sub faces and the mother face.
2591 //
2592 // Note that the last solution covers the first two
2593 // scenarios, thus we stick with it assuming that we
2594 // won't lose much time/efficiency.
2595 // TODO: Change set to types::fe_index
2596 const types::fe_index dominating_fe_index =
2597 fe_collection.find_dominating_fe_extended(
2598 {fe_ind_face_subface.begin(),
2599 fe_ind_face_subface.end()},
2600 /*codim=*/1);
2601
2603 dominating_fe_index != numbers::invalid_fe_index,
2604 ExcMessage(
2605 "Could not find a least face dominating FE."));
2606
2607 const FiniteElement<dim, spacedim> &dominating_fe =
2608 dof_handler.get_fe(dominating_fe_index);
2609
2610 // first get the interpolation matrix from the mother to
2611 // the virtual dofs
2612 Assert(dominating_fe.n_dofs_per_face(face) <=
2613 cell->get_fe().n_dofs_per_face(face),
2615
2616 ensure_existence_of_face_matrix(
2617 dominating_fe,
2618 cell->get_fe(),
2619 face_interpolation_matrices[dominating_fe_index]
2620 [cell->active_fe_index()]);
2621
2622 // split this matrix into primary and dependent
2623 // components. invert the primary component
2624 ensure_existence_of_primary_dof_mask(
2625 cell->get_fe(),
2626 dominating_fe,
2627 (*face_interpolation_matrices
2628 [dominating_fe_index][cell->active_fe_index()]),
2629 primary_dof_masks[dominating_fe_index]
2630 [cell->active_fe_index()]);
2631
2632 ensure_existence_of_split_face_matrix(
2633 *face_interpolation_matrices[dominating_fe_index]
2634 [cell->active_fe_index()],
2635 (*primary_dof_masks[dominating_fe_index]
2636 [cell->active_fe_index()]),
2637 split_face_interpolation_matrices
2638 [dominating_fe_index][cell->active_fe_index()]);
2639
2640 const FullMatrix<double>
2641 &restrict_mother_to_virtual_primary_inv =
2642 (split_face_interpolation_matrices
2643 [dominating_fe_index][cell->active_fe_index()]
2644 ->first);
2645
2646 const FullMatrix<double>
2647 &restrict_mother_to_virtual_dependent =
2648 (split_face_interpolation_matrices
2649 [dominating_fe_index][cell->active_fe_index()]
2650 ->second);
2651
2652 // now compute the constraint matrix as the product
2653 // between the inverse matrix and the dependent part
2654 constraint_matrix.reinit(
2655 cell->get_fe().n_dofs_per_face(face) -
2656 dominating_fe.n_dofs_per_face(face),
2657 dominating_fe.n_dofs_per_face(face));
2658 restrict_mother_to_virtual_dependent.mmult(
2659 constraint_matrix,
2660 restrict_mother_to_virtual_primary_inv);
2661
2662 // then figure out the global numbers of primary and
2663 // dependent dofs and apply constraints
2664 scratch_dofs.resize(
2665 cell->get_fe().n_dofs_per_face(face));
2666 cell->face(face)->get_dof_indices(
2667 scratch_dofs, cell->active_fe_index());
2668
2669 // split dofs into primary and dependent components
2670 primary_dofs.clear();
2671 dependent_dofs.clear();
2672 for (unsigned int i = 0;
2673 i < cell->get_fe().n_dofs_per_face(face);
2674 ++i)
2675 if ((*primary_dof_masks[dominating_fe_index]
2676 [cell
2677 ->active_fe_index()])[i] ==
2678 true)
2679 primary_dofs.push_back(scratch_dofs[i]);
2680 else
2681 dependent_dofs.push_back(scratch_dofs[i]);
2682
2683 AssertDimension(primary_dofs.size(),
2684 dominating_fe.n_dofs_per_face(face));
2685 AssertDimension(dependent_dofs.size(),
2686 cell->get_fe().n_dofs_per_face(face) -
2687 dominating_fe.n_dofs_per_face(face));
2688
2689 filter_constraints(primary_dofs,
2690 dependent_dofs,
2691 constraint_matrix,
2692 constraints);
2693
2694
2695
2696 // next we have to deal with the subfaces. do as
2697 // discussed in the hp-paper
2698 for (unsigned int sf = 0;
2699 sf < cell->face(face)->n_children();
2700 ++sf)
2701 {
2702 // ignore interfaces with artificial cells as well
2703 // as interfaces between ghost cells in 2d
2704 if (cell->neighbor_child_on_subface(face, sf)
2705 ->is_artificial() ||
2706 (dim == 2 && cell->is_ghost() &&
2707 cell->neighbor_child_on_subface(face, sf)
2708 ->is_ghost()))
2709 continue;
2710
2711 Assert(cell->face(face)
2712 ->child(sf)
2713 ->n_active_fe_indices() == 1,
2715
2716 const types::fe_index subface_fe_index =
2717 cell->face(face)->child(sf)->nth_active_fe_index(
2718 0);
2719 const FiniteElement<dim, spacedim> &subface_fe =
2720 dof_handler.get_fe(subface_fe_index);
2721
2722 // first get the interpolation matrix from the
2723 // subface to the virtual dofs
2724 Assert(dominating_fe.n_dofs_per_face(face) <=
2725 subface_fe.n_dofs_per_face(face),
2727 ensure_existence_of_subface_matrix(
2728 dominating_fe,
2729 subface_fe,
2730 sf,
2731 subface_interpolation_matrices
2732 [dominating_fe_index][subface_fe_index][sf]);
2733
2734 const FullMatrix<double>
2735 &restrict_subface_to_virtual = *(
2736 subface_interpolation_matrices
2737 [dominating_fe_index][subface_fe_index][sf]);
2738
2739 constraint_matrix.reinit(
2740 subface_fe.n_dofs_per_face(face),
2741 dominating_fe.n_dofs_per_face(face));
2742
2743 restrict_subface_to_virtual.mmult(
2744 constraint_matrix,
2745 restrict_mother_to_virtual_primary_inv);
2746
2747 dependent_dofs.resize(
2748 subface_fe.n_dofs_per_face(face));
2749 cell->face(face)->child(sf)->get_dof_indices(
2750 dependent_dofs, subface_fe_index);
2751
2752 filter_constraints(primary_dofs,
2753 dependent_dofs,
2754 constraint_matrix,
2755 constraints);
2756 } // loop over subfaces
2757
2758 break;
2759 } // Case 2
2760
2762 // there are no continuity requirements between the two
2763 // elements. record no constraints
2764 break;
2765
2766 default:
2767 // we shouldn't get here
2769 }
2770 }
2771 else
2772 {
2773 // this face has no children, but it could still be that it is
2774 // shared by two cells that use a different FE index
2775 Assert(cell->face(face)->fe_index_is_active(
2776 cell->active_fe_index()) == true,
2778
2779 // see if there is a neighbor that is an artificial cell. in
2780 // that case, we're not interested in this interface. we test
2781 // this case first since artificial cells may not have an
2782 // active FE index set, etc
2783 if (!cell->at_boundary(face) &&
2784 cell->neighbor(face)->is_artificial())
2785 continue;
2786
2787 // Only if there is a neighbor with a different active FE index
2788 // and the same h-level, some action has to be taken.
2789 if ((dof_handler.has_hp_capabilities()) &&
2790 !cell->face(face)->at_boundary() &&
2791 (cell->neighbor(face)->active_fe_index() !=
2792 cell->active_fe_index()) &&
2793 (!cell->face(face)->has_children() &&
2794 !cell->neighbor_is_coarser(face)))
2795 {
2796 const typename DoFHandler<dim,
2797 spacedim>::level_cell_iterator
2798 neighbor = cell->neighbor(face);
2799
2800 // see which side of the face we have to constrain
2801 switch (
2802 cell->get_fe().compare_for_domination(neighbor->get_fe(),
2803 /*codim=*/1))
2804 {
2806 {
2807 // Get DoFs on dominating and dominated side of the
2808 // face
2809 primary_dofs.resize(
2810 cell->get_fe().n_dofs_per_face(face));
2811 cell->face(face)->get_dof_indices(
2812 primary_dofs, cell->active_fe_index());
2813
2814 // break if the n_primary_dofs == 0, because we are
2815 // attempting to constrain to an element that has no
2816 // face dofs
2817 if (primary_dofs.empty())
2818 break;
2819
2820 dependent_dofs.resize(
2821 neighbor->get_fe().n_dofs_per_face(face));
2822 cell->face(face)->get_dof_indices(
2823 dependent_dofs, neighbor->active_fe_index());
2824
2825 // make sure the element constraints for this face
2826 // are available
2827 ensure_existence_of_face_matrix(
2828 cell->get_fe(),
2829 neighbor->get_fe(),
2830 face_interpolation_matrices
2831 [cell->active_fe_index()]
2832 [neighbor->active_fe_index()]);
2833
2834 // Add constraints to global constraint matrix.
2835 filter_constraints(
2836 primary_dofs,
2837 dependent_dofs,
2838 *(face_interpolation_matrices
2839 [cell->active_fe_index()]
2840 [neighbor->active_fe_index()]),
2841 constraints);
2842
2843 break;
2844 }
2845
2847 {
2848 // we don't do anything here since we will come back
2849 // to this face from the other cell, at which time
2850 // we will fall into the first case clause above
2851 break;
2852 }
2853
2856 {
2857 // it appears as if neither element has any
2858 // constraints on its neighbor. this may be because
2859 // neither element has any DoFs on faces at all. or
2860 // that the two elements are actually the same,
2861 // although they happen to run under different
2862 // fe_indices (this is what happens in
2863 // hp/hp_hanging_nodes_01 for example).
2864 //
2865 // another possibility is what happens in crash_13.
2866 // there, we have FESystem(FE_Q(1),FE_DGQ(0)) vs.
2867 // FESystem(FE_Q(1),FE_DGQ(1)). neither of them
2868 // dominates the other.
2869 //
2870 // a final possibility is that we have something
2871 // like FESystem(FE_Q(1),FE_Q(1)) vs
2872 // FESystem(FE_Q(1),FE_Nothing()), see
2873 // hp/fe_nothing_18/19.
2874 //
2875 // in any case, the point is that it doesn't matter.
2876 // there is nothing to do here.
2877 break;
2878 }
2879
2881 {
2882 // make sure we don't get here twice from each cell
2883 if (cell < neighbor)
2884 break;
2885
2886 // our best bet is to find the common space among
2887 // other FEs in FECollection and then constrain both
2888 // FEs to that one. More precisely, we follow the
2889 // strategy outlined on page 17 of the hp-paper:
2890 // First we find the dominant FE space S. Then we
2891 // divide our dofs in primary and dependent such
2892 // that I^{face,primary}_{S^{face}->S} is
2893 // invertible. And finally constrain dependent dofs
2894 // to primary dofs based on the interpolation
2895 // matrix.
2896
2897 const types::fe_index this_fe_index =
2898 cell->active_fe_index();
2899 const types::fe_index neighbor_fe_index =
2900 neighbor->active_fe_index();
2901 std::set<types::fe_index> fes;
2902 fes.insert(this_fe_index);
2903 fes.insert(neighbor_fe_index);
2904 const ::hp::FECollection<dim, spacedim>
2905 &fe_collection = dof_handler.get_fe_collection();
2906
2907 // TODO: Change set to types::fe_index
2908 const types::fe_index dominating_fe_index =
2909 fe_collection.find_dominating_fe_extended(
2910 {fes.begin(), fes.end()}, /*codim=*/1);
2911
2913 dominating_fe_index != numbers::invalid_fe_index,
2914 ExcMessage(
2915 "Could not find the dominating FE for " +
2916 cell->get_fe().get_name() + " and " +
2917 neighbor->get_fe().get_name() +
2918 " inside FECollection."));
2919
2920 const FiniteElement<dim, spacedim> &dominating_fe =
2921 fe_collection[dominating_fe_index];
2922
2923 // TODO: until we hit the second face, the code is a
2924 // copy-paste from h-refinement case...
2925
2926 // first get the interpolation matrix from main FE
2927 // to the virtual dofs
2928 Assert(dominating_fe.n_dofs_per_face(face) <=
2929 cell->get_fe().n_dofs_per_face(face),
2931
2932 ensure_existence_of_face_matrix(
2933 dominating_fe,
2934 cell->get_fe(),
2935 face_interpolation_matrices
2936 [dominating_fe_index][cell->active_fe_index()]);
2937
2938 // split this matrix into primary and dependent
2939 // components. invert the primary component
2940 ensure_existence_of_primary_dof_mask(
2941 cell->get_fe(),
2942 dominating_fe,
2943 (*face_interpolation_matrices
2944 [dominating_fe_index]
2945 [cell->active_fe_index()]),
2946 primary_dof_masks[dominating_fe_index]
2947 [cell->active_fe_index()]);
2948
2949 ensure_existence_of_split_face_matrix(
2950 *face_interpolation_matrices
2951 [dominating_fe_index][cell->active_fe_index()],
2952 (*primary_dof_masks[dominating_fe_index]
2953 [cell->active_fe_index()]),
2954 split_face_interpolation_matrices
2955 [dominating_fe_index][cell->active_fe_index()]);
2956
2957 const FullMatrix<
2958 double> &restrict_mother_to_virtual_primary_inv =
2959 (split_face_interpolation_matrices
2960 [dominating_fe_index][cell->active_fe_index()]
2961 ->first);
2962
2963 const FullMatrix<
2964 double> &restrict_mother_to_virtual_dependent =
2965 (split_face_interpolation_matrices
2966 [dominating_fe_index][cell->active_fe_index()]
2967 ->second);
2968
2969 // now compute the constraint matrix as the product
2970 // between the inverse matrix and the dependent part
2971 constraint_matrix.reinit(
2972 cell->get_fe().n_dofs_per_face(face) -
2973 dominating_fe.n_dofs_per_face(face),
2974 dominating_fe.n_dofs_per_face(face));
2975 restrict_mother_to_virtual_dependent.mmult(
2976 constraint_matrix,
2977 restrict_mother_to_virtual_primary_inv);
2978
2979 // then figure out the global numbers of primary and
2980 // dependent dofs and apply constraints
2981 scratch_dofs.resize(
2982 cell->get_fe().n_dofs_per_face(face));
2983 cell->face(face)->get_dof_indices(
2984 scratch_dofs, cell->active_fe_index());
2985
2986 // split dofs into primary and dependent components
2987 primary_dofs.clear();
2988 dependent_dofs.clear();
2989 for (unsigned int i = 0;
2990 i < cell->get_fe().n_dofs_per_face(face);
2991 ++i)
2992 if ((*primary_dof_masks[dominating_fe_index]
2993 [cell->active_fe_index()])
2994 [i] == true)
2995 primary_dofs.push_back(scratch_dofs[i]);
2996 else
2997 dependent_dofs.push_back(scratch_dofs[i]);
2998
2999 AssertDimension(primary_dofs.size(),
3000 dominating_fe.n_dofs_per_face(
3001 face));
3003 dependent_dofs.size(),
3004 cell->get_fe().n_dofs_per_face(face) -
3005 dominating_fe.n_dofs_per_face(face));
3006
3007 filter_constraints(primary_dofs,
3008 dependent_dofs,
3009 constraint_matrix,
3010 constraints);
3011
3012 // now do the same for another FE this is pretty
3013 // much the same we do above to resolve h-refinement
3014 // constraints
3015 Assert(dominating_fe.n_dofs_per_face(face) <=
3016 neighbor->get_fe().n_dofs_per_face(face),
3018
3019 ensure_existence_of_face_matrix(
3020 dominating_fe,
3021 neighbor->get_fe(),
3022 face_interpolation_matrices
3023 [dominating_fe_index]
3024 [neighbor->active_fe_index()]);
3025
3026 const FullMatrix<double>
3027 &restrict_secondface_to_virtual =
3028 *(face_interpolation_matrices
3029 [dominating_fe_index]
3030 [neighbor->active_fe_index()]);
3031
3032 constraint_matrix.reinit(
3033 neighbor->get_fe().n_dofs_per_face(face),
3034 dominating_fe.n_dofs_per_face(face));
3035
3036 restrict_secondface_to_virtual.mmult(
3037 constraint_matrix,
3038 restrict_mother_to_virtual_primary_inv);
3039
3040 dependent_dofs.resize(
3041 neighbor->get_fe().n_dofs_per_face(face));
3042 cell->face(face)->get_dof_indices(
3043 dependent_dofs, neighbor->active_fe_index());
3044
3045 filter_constraints(primary_dofs,
3046 dependent_dofs,
3047 constraint_matrix,
3048 constraints);
3049
3050 break;
3051 }
3052
3054 {
3055 // nothing to do here
3056 break;
3057 }
3058
3059 default:
3060 // we shouldn't get here
3062 }
3063 }
3064 }
3065 }
3066 }
3067 } // namespace internal
3068
3069
3070
3071 template <int dim, int spacedim, typename number>
3072 void
3074 AffineConstraints<number> &constraints)
3075 {
3076 Assert(dof_handler.has_active_dofs(),
3077 ExcMessage(
3078 "The given DoFHandler does not have any DoFs. Did you forget to "
3079 "call dof_handler.distribute_dofs()?"));
3080
3081 // Decide whether to use make_hanging_node_constraints_nedelec,
3082 // the new or old make_hanging_node_constraints
3083 // function. If all the FiniteElement or all elements in a FECollection
3084 // support the new face constraint matrix, the new code will be used.
3085 // Otherwise, the old implementation is used for the moment.
3086 if (dof_handler.get_fe().get_name().find("FE_NedelecSZ") !=
3087 std::string::npos)
3089 dof_handler, constraints, std::integral_constant<int, dim>());
3090 else if (dof_handler.get_fe_collection().hp_constraints_are_implemented())
3091 internal::make_hp_hanging_node_constraints(dof_handler, constraints);
3092 else
3094 dof_handler, constraints, std::integral_constant<int, dim>());
3095 }
3096
3097
3098
3099 namespace internal
3100 {
3101 template <typename FaceIterator, typename number>
3102 void
3104 const FaceIterator &face_1,
3106 const FullMatrix<double> &transformation,
3107 AffineConstraints<number> &affine_constraints,
3108 const ComponentMask &component_mask,
3109 const unsigned char combined_orientation,
3110 const number periodicity_factor,
3111 const unsigned int level)
3112 {
3113 static const int dim = FaceIterator::AccessorType::dimension;
3114 static const int spacedim = FaceIterator::AccessorType::space_dimension;
3115
3116 const bool use_mg = (level != numbers::invalid_unsigned_int);
3117
3118 // If we don't use multigrid, we should be in the case where face_1 is
3119 // active, i.e. has no children. In the case of multigrid, constraints
3120 // between cells on the same level are set up.
3121
3122 Assert(use_mg || (!face_1->has_children()), ExcInternalError());
3123
3124 Assert(face_1->n_active_fe_indices() == 1, ExcInternalError());
3125
3126 // TODO: the implementation makes the assumption that all faces have the
3127 // same number of dofs
3129 face_1->get_fe(face_1->nth_active_fe_index(0)).n_unique_faces(), 1);
3131 face_2->get_fe(face_2->nth_active_fe_index(0)).n_unique_faces(), 1);
3132 const unsigned int face_no = 0;
3133
3134 // If we don't use multigrid and face_2 does have children,
3135 // then we need to iterate over these children and set periodic
3136 // constraints in the inverse direction. In the case of multigrid,
3137 // we don't need to do this, since constraints between cells on
3138 // the same level are set up.
3139
3140 if ((!use_mg) && face_2->has_children())
3141 {
3142 Assert(face_2->n_children() ==
3145
3146 const unsigned int dofs_per_face =
3147 face_1->get_fe(face_1->nth_active_fe_index(0))
3148 .n_dofs_per_face(face_no);
3149 FullMatrix<double> child_transformation(dofs_per_face, dofs_per_face);
3150 FullMatrix<double> subface_interpolation(dofs_per_face,
3151 dofs_per_face);
3152
3153 for (unsigned int c = 0; c < face_2->n_children(); ++c)
3154 {
3155 // get the interpolation matrix recursively from the one that
3156 // interpolated from face_1 to face_2 by multiplying from the left
3157 // with the one that interpolates from face_2 to its child
3158 const auto &fe = face_1->get_fe(face_1->nth_active_fe_index(0));
3159 fe.get_subface_interpolation_matrix(fe,
3160 c,
3161 subface_interpolation,
3162 face_no);
3163 subface_interpolation.mmult(child_transformation, transformation);
3164
3166 face_2->child(c),
3167 child_transformation,
3168 affine_constraints,
3169 component_mask,
3170 combined_orientation,
3171 periodicity_factor);
3172 }
3173 return;
3174 }
3175
3176 //
3177 // If we reached this point then both faces are active. Now all
3178 // that is left is to match the corresponding DoFs of both faces.
3179 //
3180
3181 const types::fe_index face_1_index = face_1->nth_active_fe_index(0);
3182 const types::fe_index face_2_index = face_2->nth_active_fe_index(0);
3183 Assert(face_1->get_fe(face_1_index) == face_2->get_fe(face_2_index),
3184 ExcMessage(
3185 "Matching periodic cells need to use the same finite element"));
3186
3187 const FiniteElement<dim, spacedim> &fe = face_1->get_fe(face_1_index);
3188
3189 Assert(component_mask.represents_n_components(fe.n_components()),
3190 ExcMessage(
3191 "The number of components in the mask has to be either "
3192 "zero or equal to the number of components in the finite "
3193 "element."));
3194
3195 const unsigned int dofs_per_face = fe.n_dofs_per_face(face_no);
3196
3197 std::vector<types::global_dof_index> dofs_1(dofs_per_face);
3198 std::vector<types::global_dof_index> dofs_2(dofs_per_face);
3199
3200 if (use_mg)
3201 face_1->get_mg_dof_indices(level, dofs_1, face_1_index);
3202 else
3203 face_1->get_dof_indices(dofs_1, face_1_index);
3204
3205 if (use_mg)
3206 face_2->get_mg_dof_indices(level, dofs_2, face_2_index);
3207 else
3208 face_2->get_dof_indices(dofs_2, face_2_index);
3209
3210 // If either of the two faces has an invalid dof index, stop. This is
3211 // so that there is no attempt to match artificial cells of parallel
3212 // distributed triangulations.
3213 //
3214 // While it seems like we ought to be able to avoid even calling
3215 // set_periodicity_constraints for artificial faces, this situation
3216 // can arise when a face that is being made periodic is only
3217 // partially touched by the local subdomain.
3218 // make_periodicity_constraints will be called recursively even for
3219 // the section of the face that is not touched by the local
3220 // subdomain.
3221 //
3222 // Until there is a better way to determine if the cells that
3223 // neighbor a face are artificial, we simply test to see if the face
3224 // does not have a valid dof initialization.
3225
3226 for (unsigned int i = 0; i < dofs_per_face; ++i)
3227 if (dofs_1[i] == numbers::invalid_dof_index ||
3228 dofs_2[i] == numbers::invalid_dof_index)
3229 {
3230 return;
3231 }
3232
3233 // In the case of shared Trinagulation with artificial cells all
3234 // cells have valid DoF indices, i.e., the check above does not work.
3235 if (const auto tria = dynamic_cast<
3237 &face_1->get_triangulation()))
3238 if (tria->with_artificial_cells() &&
3239 (affine_constraints.get_local_lines().size() != 0))
3240 for (unsigned int i = 0; i < dofs_per_face; ++i)
3241 if ((affine_constraints.get_local_lines().is_element(dofs_1[i]) ==
3242 false) ||
3243 (affine_constraints.get_local_lines().is_element(dofs_2[i]) ==
3244 false))
3245 {
3246 return;
3247 }
3248
3249 // Well, this is a hack:
3250 //
3251 // There is no
3252 // face_to_face_index(face_index,
3253 // face_orientation,
3254 // face_flip,
3255 // face_rotation)
3256 // function in FiniteElementData, so we have to use
3257 // face_to_cell_index(face_index, face
3258 // face_orientation,
3259 // face_flip,
3260 // face_rotation)
3261 // But this will give us an index on a cell - something we cannot work
3262 // with directly. But luckily we can match them back :-]
3263
3264 std::map<unsigned int, unsigned int> cell_to_rotated_face_index;
3265
3266 // Build up a cell to face index for face_2:
3267 for (unsigned int i = 0; i < dofs_per_face; ++i)
3268 {
3269 const unsigned int cell_index = fe.face_to_cell_index(
3270 i,
3271 // It doesn't really matter, just assume we're on the first face...
3272 0);
3273 cell_to_rotated_face_index[cell_index] = i;
3274 }
3275
3276 // Build constraints in a vector of pairs that can be
3277 // arbitrarily large, but that holds up to 25 elements without
3278 // external memory allocation. This is good enough for hanging
3279 // node constraints of Q4 elements in 3d, so covers most
3280 // common cases.
3281 boost::container::small_vector<
3282 std::pair<typename AffineConstraints<number>::size_type, number>,
3283 25>
3284 constraint_entries;
3285
3286 //
3287 // Loop over all dofs on face 2 and constrain them against all
3288 // matching dofs on face 1:
3289 //
3290 for (unsigned int i = 0; i < dofs_per_face; ++i)
3291 {
3292 // Obey the component mask
3293 if ((component_mask.n_selected_components(fe.n_components()) !=
3294 fe.n_components()) &&
3295 !component_mask[fe.face_system_to_component_index(i, face_no)
3296 .first])
3297 continue;
3298
3299 // We have to be careful to treat so called "identity
3300 // constraints" special. These are constraints of the form
3301 // x1 == constraint_factor * x_2. In this case, if the constraint
3302 // x2 == 1./constraint_factor * x1 already exists we are in trouble.
3303 //
3304 // Consequently, we have to check that we have indeed such an
3305 // "identity constraint". We do this by looping over all entries
3306 // of the row of the transformation matrix and check whether we
3307 // find exactly one nonzero entry. If this is the case, set
3308 // "is_identity_constrained" to true and record the corresponding
3309 // index and constraint_factor.
3310
3311 bool is_identity_constrained = false;
3312 unsigned int target = numbers::invalid_unsigned_int;
3313 number constraint_factor = periodicity_factor;
3314
3315 constexpr double eps = 1.e-13;
3316 for (unsigned int jj = 0; jj < dofs_per_face; ++jj)
3317 {
3318 const auto entry = transformation(i, jj);
3319 if (std::abs(entry) > eps)
3320 {
3321 if (is_identity_constrained)
3322 {
3323 // We did encounter more than one nonzero entry, so
3324 // the dof is not identity constrained. Set the
3325 // boolean to false and break out of the for loop.
3326 is_identity_constrained = false;
3327 break;
3328 }
3329 is_identity_constrained = true;
3330 target = jj;
3331 constraint_factor = entry * periodicity_factor;
3332 }
3333 }
3334
3335 // Next, we work on all constraints that are not identity
3336 // constraints, i.e., constraints that involve an interpolation
3337 // step that constrains the current dof (on face 2) to more than
3338 // one dof on face 1.
3339
3340 if (!is_identity_constrained)
3341 {
3342 // The current dof is already constrained. There is nothing
3343 // left to do.
3344 if (affine_constraints.is_constrained(dofs_2[i]))
3345 continue;
3346
3347 constraint_entries.clear();
3348 constraint_entries.reserve(dofs_per_face);
3349
3350 for (unsigned int jj = 0; jj < dofs_per_face; ++jj)
3351 {
3352 // Get the correct dof index on face_1 respecting the
3353 // given orientation:
3354 const unsigned int j =
3355 cell_to_rotated_face_index[fe.face_to_cell_index(
3356 jj, 0, combined_orientation)];
3357
3358 if (std::abs(transformation(i, jj)) > eps)
3359 constraint_entries.emplace_back(dofs_1[j],
3360 transformation(i, jj));
3361 }
3362
3363 // Enter the constraint::
3364 affine_constraints.add_constraint(dofs_2[i],
3365 constraint_entries,
3366 0.);
3367
3368
3369 // Continue with next dof.
3370 continue;
3371 }
3372
3373 // We are left with an "identity constraint".
3374
3375 // Get the correct dof index on face_1 respecting the given
3376 // orientation:
3377 const unsigned int j =
3378 cell_to_rotated_face_index[fe.face_to_cell_index(
3379 target, 0, combined_orientation)];
3380
3381 auto dof_left = dofs_1[j];
3382 auto dof_right = dofs_2[i];
3383
3384 // If dof_left is already constrained, or dof_left < dof_right we
3385 // flip the order to ensure that dofs are constrained in a stable
3386 // manner on different MPI processes.
3387 if (affine_constraints.is_constrained(dof_left) ||
3388 (dof_left < dof_right &&
3389 !affine_constraints.is_constrained(dof_right)))
3390 {
3391 std::swap(dof_left, dof_right);
3392 constraint_factor = 1. / constraint_factor;
3393 }
3394
3395 // Next, we try to enter the constraint
3396 // dof_left = constraint_factor * dof_right;
3397
3398 // If both degrees of freedom are constrained, there is nothing we
3399 // can do. Simply continue with the next dof.
3400 if (affine_constraints.is_constrained(dof_left) &&
3401 affine_constraints.is_constrained(dof_right))
3402 continue;
3403
3404 // We have to be careful that adding the current identity
3405 // constraint does not create a constraint cycle. Thus, check for
3406 // a dependency cycle:
3407
3408 bool constraints_are_cyclic = true;
3409 number cycle_constraint_factor = constraint_factor;
3410
3411 for (auto test_dof = dof_right; test_dof != dof_left;)
3412 {
3413 if (!affine_constraints.is_constrained(test_dof))
3414 {
3415 constraints_are_cyclic = false;
3416 break;
3417 }
3418
3419 const auto &constraint_entries =
3420 *affine_constraints.get_constraint_entries(test_dof);
3421 if (constraint_entries.size() == 1)
3422 {
3423 test_dof = constraint_entries[0].first;
3424 cycle_constraint_factor *= constraint_entries[0].second;
3425 }
3426 else
3427 {
3428 constraints_are_cyclic = false;
3429 break;
3430 }
3431 }
3432
3433 // In case of a dependency cycle we, either
3434 // - do nothing if cycle_constraint_factor == 1. In this case all
3435 // degrees
3436 // of freedom are already periodically constrained,
3437 // - otherwise, force all dofs to zero (by setting dof_left to
3438 // zero). The reasoning behind this is the fact that
3439 // cycle_constraint_factor != 1 occurs in situations such as
3440 // x1 == x2 and x2 == -1. * x1. This system is only solved by
3441 // x_1 = x_2 = 0.
3442
3443 if (constraints_are_cyclic)
3444 {
3445 if (std::abs(cycle_constraint_factor - number(1.)) > eps)
3446 affine_constraints.constrain_dof_to_zero(dof_left);
3447 }
3448 else
3449 {
3450 affine_constraints.add_constraint(
3451 dof_left, {{dof_right, constraint_factor}}, 0.);
3452 // The number 1e10 in the assert below is arbitrary. If the
3453 // absolute value of constraint_factor is too large, then probably
3454 // the absolute value of periodicity_factor is too large or too
3455 // small. This would be equivalent to an evanescent wave that has
3456 // a very small wavelength. A quick calculation shows that if
3457 // |periodicity_factor| > 1e10 -> |np.exp(ikd)|> 1e10, therefore k
3458 // is imaginary (evanescent wave) and the evanescent wavelength is
3459 // 0.27 times smaller than the dimension of the structure,
3460 // lambda=((2*pi)/log(1e10))*d. Imaginary wavenumbers can be
3461 // interesting in some cases
3462 // (https://doi.org/10.1103/PhysRevA.94.033813).In order to
3463 // implement the case of in which the wavevector can be imaginary
3464 // it would be necessary to rewrite this function and the dof
3465 // ordering method should be modified.
3466 // Let's take the following constraint a*x1 + b*x2 = 0. You could
3467 // just always pick x1 = b/a*x2, but in practice this is not so
3468 // stable if a could be a small number -- intended to be zero, but
3469 // just very small due to roundoff. Of course, constraining x2 in
3470 // terms of x1 has the same problem. So one chooses x1 = b/a*x2 if
3471 // |b|<|a|, and x2 = a/b*x1 if |a|<|b|.
3472 Assert(std::abs(constraint_factor) < 1e10,
3473 ExcMessage("The periodicity constraint is too large. "
3474 "The parameter periodicity_factor might "
3475 "be too large or too small."));
3476 }
3477 } /* for dofs_per_face */
3478 }
3479 } // namespace internal
3480
3481
3482 namespace
3483 {
3484 // Internally used in make_periodicity_constraints.
3485 //
3486 // Build up a (possibly rotated) interpolation matrix that is used in
3487 // set_periodicity_constraints with the help of user supplied matrix and
3488 // first_vector_components.
3489 template <int dim, int spacedim>
3491 compute_transformation(
3493 const FullMatrix<double> &matrix,
3494 const std::vector<unsigned int> &first_vector_components)
3495 {
3496 // TODO: the implementation makes the assumption that all faces have the
3497 // same number of dofs
3499 const unsigned int face_no = 0;
3500
3501 Assert(matrix.m() == matrix.n(), ExcInternalError());
3502
3503 const unsigned int n_dofs_per_face = fe.n_dofs_per_face(face_no);
3504
3505 if (matrix.m() == n_dofs_per_face)
3506 {
3507 // In case of m == n == n_dofs_per_face the supplied matrix is already
3508 // an interpolation matrix, so we use it directly:
3509 return matrix;
3510 }
3511
3512 if (first_vector_components.empty() && matrix.m() == 0)
3513 {
3514 // Just the identity matrix in case no rotation is specified:
3515 return IdentityMatrix(n_dofs_per_face);
3516 }
3517
3518 // The matrix describes a rotation and we have to build a transformation
3519 // matrix, we assume that for a 0* rotation we would have to build the
3520 // identity matrix
3521
3522 Assert(matrix.m() == spacedim, ExcInternalError());
3523
3524 const Quadrature<dim - 1> quadrature(
3525 fe.get_unit_face_support_points(face_no));
3526
3527 // have an array that stores the location of each vector-dof tuple we want
3528 // to rotate.
3529 using DoFTuple = std::array<unsigned int, spacedim>;
3530
3531 // start with a pristine interpolation matrix...
3532 FullMatrix<double> transformation = IdentityMatrix(n_dofs_per_face);
3533
3534 for (unsigned int i = 0; i < n_dofs_per_face; ++i)
3535 {
3536 std::vector<unsigned int>::const_iterator comp_it =
3537 std::find(first_vector_components.begin(),
3538 first_vector_components.end(),
3539 fe.face_system_to_component_index(i, face_no).first);
3540 if (comp_it != first_vector_components.end())
3541 {
3542 const unsigned int first_vector_component = *comp_it;
3543
3544 // find corresponding other components of vector
3545 DoFTuple vector_dofs;
3546 vector_dofs[0] = i;
3547 unsigned int n_found = 1;
3548
3549 Assert(
3550 *comp_it + spacedim <= fe.n_components(),
3551 ExcMessage(
3552 "Error: the finite element does not have enough components "
3553 "to define rotated periodic boundaries."));
3554
3555 for (unsigned int k = 0; k < n_dofs_per_face; ++k)
3556 if ((k != i) && (quadrature.point(k) == quadrature.point(i)) &&
3557 (fe.face_system_to_component_index(k, face_no).first >=
3558 first_vector_component) &&
3559 (fe.face_system_to_component_index(k, face_no).first <
3560 first_vector_component + spacedim))
3561 {
3562 vector_dofs[fe.face_system_to_component_index(k, face_no)
3563 .first -
3564 first_vector_component] = k;
3565 ++n_found;
3566 if (n_found == dim)
3567 break;
3568 }
3569
3570 // ... and rotate all dofs belonging to vector valued components
3571 // that are selected by first_vector_components:
3572 for (unsigned int i = 0; i < spacedim; ++i)
3573 {
3574 transformation[vector_dofs[i]][vector_dofs[i]] = 0.;
3575 for (unsigned int j = 0; j < spacedim; ++j)
3576 transformation[vector_dofs[i]][vector_dofs[j]] =
3577 matrix[i][j];
3578 }
3579 }
3580 }
3581 return transformation;
3582 }
3583 } /*namespace*/
3584
3585
3586 // Low level interface:
3587
3588
3589 template <typename FaceIterator, typename number>
3590 void
3592 const FaceIterator &face_1,
3594 AffineConstraints<number> &affine_constraints,
3595 const ComponentMask &component_mask,
3596 const unsigned char combined_orientation,
3597 const FullMatrix<double> &matrix,
3598 const std::vector<unsigned int> &first_vector_components,
3599 const number periodicity_factor)
3600 {
3601 static const int dim = FaceIterator::AccessorType::dimension;
3602 static const int spacedim = FaceIterator::AccessorType::space_dimension;
3603
3604#ifdef DEBUG
3605 const auto [orientation, rotation, flip] =
3606 ::internal::split_face_orientation(combined_orientation);
3607
3608 Assert((dim != 1) ||
3609 (orientation == true && flip == false && rotation == false),
3610 ExcMessage("The supplied orientation (orientation, rotation, flip) "
3611 "is invalid for 1d"));
3612
3613 Assert((dim != 2) || (flip == false && rotation == false),
3614 ExcMessage("The supplied orientation (orientation, rotation, flip) "
3615 "is invalid for 2d"));
3616
3617 Assert(face_1 != face_2,
3618 ExcMessage("face_1 and face_2 are equal! Cannot constrain DoFs "
3619 "on the very same face"));
3620
3621 Assert(face_1->at_boundary() && face_2->at_boundary(),
3622 ExcMessage("Faces for periodicity constraints must be on the "
3623 "boundary"));
3624
3625 Assert(matrix.m() == matrix.n(),
3626 ExcMessage("The supplied (rotation or interpolation) matrix must "
3627 "be a square matrix"));
3628
3629 Assert(first_vector_components.empty() || matrix.m() == spacedim,
3630 ExcMessage("first_vector_components is nonempty, so matrix must "
3631 "be a rotation matrix exactly of size spacedim"));
3632
3633 if (!face_1->has_children())
3634 {
3635 // TODO: the implementation makes the assumption that all faces have the
3636 // same number of dofs
3638 face_1->get_fe(face_1->nth_active_fe_index(0)).n_unique_faces(), 1);
3639 const unsigned int face_no = 0;
3640
3641 Assert(face_1->n_active_fe_indices() == 1, ExcInternalError());
3642 const unsigned int n_dofs_per_face =
3643 face_1->get_fe(face_1->nth_active_fe_index(0))
3644 .n_dofs_per_face(face_no);
3645
3646 Assert(matrix.m() == 0 ||
3647 (first_vector_components.empty() &&
3648 matrix.m() == n_dofs_per_face) ||
3649 (!first_vector_components.empty() && matrix.m() == spacedim),
3650 ExcMessage(
3651 "The matrix must have either size 0 or spacedim "
3652 "(if first_vector_components is nonempty) "
3653 "or the size must be equal to the # of DoFs on the face "
3654 "(if first_vector_components is empty)."));
3655 }
3656
3657 if (!face_2->has_children())
3658 {
3659 // TODO: the implementation makes the assumption that all faces have the
3660 // same number of dofs
3662 face_2->get_fe(face_2->nth_active_fe_index(0)).n_unique_faces(), 1);
3663 const unsigned int face_no = 0;
3664
3665 Assert(face_2->n_active_fe_indices() == 1, ExcInternalError());
3666 const unsigned int n_dofs_per_face =
3667 face_2->get_fe(face_2->nth_active_fe_index(0))
3668 .n_dofs_per_face(face_no);
3669
3670 Assert(matrix.m() == 0 ||
3671 (first_vector_components.empty() &&
3672 matrix.m() == n_dofs_per_face) ||
3673 (!first_vector_components.empty() && matrix.m() == spacedim),
3674 ExcMessage(
3675 "The matrix must have either size 0 or spacedim "
3676 "(if first_vector_components is nonempty) "
3677 "or the size must be equal to the # of DoFs on the face "
3678 "(if first_vector_components is empty)."));
3679 }
3680#endif
3681
3682 if (face_1->has_children() && face_2->has_children())
3683 {
3684 // In the case that both faces have children, we loop over all children
3685 // and apply make_periodicity_constraints() recursively:
3686
3687 Assert(face_1->n_children() ==
3689 face_2->n_children() ==
3692
3693 for (unsigned int i = 0; i < GeometryInfo<dim>::max_children_per_face;
3694 ++i)
3695 {
3696 // We need to access the subface indices without knowing the face
3697 // number. Hence, we pick the lowest-value face: i.e., face 2 in 2D
3698 // has subfaces {0, 1} and face 4 in 3D has subfaces {0, 1, 2, 3}.
3699 const unsigned int face_no = dim == 2 ? 2 : 4;
3700
3701 // Lookup the index for the second face. Like the assertions above,
3702 // this is only presently valid for hypercube meshes.
3703 const auto reference_cell = ReferenceCells::get_hypercube<dim>();
3704 const unsigned int j =
3705 reference_cell.child_cell_on_face(face_no,
3706 i,
3707 combined_orientation);
3708
3709 make_periodicity_constraints(face_1->child(i),
3710 face_2->child(j),
3711 affine_constraints,
3712 component_mask,
3713 combined_orientation,
3714 matrix,
3715 first_vector_components,
3716 periodicity_factor);
3717 }
3718 }
3719 else
3720 {
3721 // Otherwise at least one of the two faces is active and we need to do
3722 // some work and enter the constraints!
3723
3724 // The finite element that matters is the one on the active face:
3726 face_1->has_children() ?
3727 face_2->get_fe(face_2->nth_active_fe_index(0)) :
3728 face_1->get_fe(face_1->nth_active_fe_index(0));
3729
3730 // TODO: the implementation makes the assumption that all faces have the
3731 // same number of dofs
3733 const unsigned int face_no = 0;
3734
3735 const unsigned int n_dofs_per_face = fe.n_dofs_per_face(face_no);
3736
3737 // Sometimes we just have nothing to do (for all finite elements, or
3738 // systems which accidentally don't have any dofs on the boundary).
3739 if (n_dofs_per_face == 0)
3740 return;
3741
3742 const FullMatrix<double> transformation =
3743 compute_transformation(fe, matrix, first_vector_components);
3744
3745 if (!face_2->has_children())
3746 {
3747 // Performance hack: We do not need to compute an inverse if the
3748 // matrix is the identity matrix.
3749 if (first_vector_components.empty() && matrix.m() == 0)
3750 {
3752 face_1,
3753 transformation,
3754 affine_constraints,
3755 component_mask,
3756 combined_orientation,
3757 periodicity_factor);
3758 }
3759 else
3760 {
3761 FullMatrix<double> inverse(transformation.m());
3762 inverse.invert(transformation);
3763
3765 face_1,
3766 inverse,
3767 affine_constraints,
3768 component_mask,
3769 combined_orientation,
3770 periodicity_factor);
3771 }
3772 }
3773 else
3774 {
3775 Assert(!face_1->has_children(), ExcInternalError());
3776
3777 // Important note:
3778 // In 3d we have to take care of the fact that face_rotation gives
3779 // the relative rotation of face_1 to face_2, i.e. we have to invert
3780 // the rotation when constraining face_2 to face_1. Therefore
3781 // face_flip has to be toggled if face_rotation is true: In case of
3782 // inverted orientation, nothing has to be done.
3783
3784 const auto face_reference_cell = face_1->reference_cell();
3786 face_1,
3787 face_2,
3788 transformation,
3789 affine_constraints,
3790 component_mask,
3791 face_reference_cell.get_inverse_combined_orientation(
3792 combined_orientation),
3793 periodicity_factor);
3794 }
3795 }
3796 }
3797
3798
3799
3800 template <int dim, int spacedim, typename number>
3801 void
3803 const std::vector<GridTools::PeriodicFacePair<
3804 typename DoFHandler<dim, spacedim>::cell_iterator>> &periodic_faces,
3805 AffineConstraints<number> &constraints,
3806 const ComponentMask &component_mask,
3807 const std::vector<unsigned int> &first_vector_components,
3808 const number periodicity_factor)
3809 {
3810 // Loop over all periodic faces...
3811 for (auto &pair : periodic_faces)
3812 {
3813 using FaceIterator = typename DoFHandler<dim, spacedim>::face_iterator;
3814 const FaceIterator face_1 = pair.cell[0]->face(pair.face_idx[0]);
3815 const FaceIterator face_2 = pair.cell[1]->face(pair.face_idx[1]);
3816
3817 Assert(face_1->at_boundary() && face_2->at_boundary(),
3819
3820 Assert(face_1 != face_2, ExcInternalError());
3821
3822 // ... and apply the low level make_periodicity_constraints function to
3823 // every matching pair:
3825 face_2,
3826 constraints,
3827 component_mask,
3828 pair.orientation,
3829 pair.matrix,
3830 first_vector_components,
3831 periodicity_factor);
3832 }
3833 }
3834
3835
3836 // High level interface variants:
3837
3838
3839 template <int dim, int spacedim, typename number>
3840 void
3842 const types::boundary_id b_id1,
3843 const types::boundary_id b_id2,
3844 const unsigned int direction,
3845 ::AffineConstraints<number> &constraints,
3846 const ComponentMask &component_mask,
3847 const number periodicity_factor)
3848 {
3849 AssertIndexRange(direction, spacedim);
3850
3851 Assert(b_id1 != b_id2,
3852 ExcMessage("The boundary indicators b_id1 and b_id2 must be "
3853 "different to denote different boundaries."));
3854
3855 std::vector<GridTools::PeriodicFacePair<
3857 matched_faces;
3858
3859 // Collect matching periodic cells on the coarsest level:
3861 dof_handler, b_id1, b_id2, direction, matched_faces);
3862
3863 make_periodicity_constraints<dim, spacedim>(matched_faces,
3864 constraints,
3865 component_mask,
3866 std::vector<unsigned int>(),
3867 periodicity_factor);
3868 }
3869
3870
3871
3872 template <int dim, int spacedim, typename number>
3873 void
3875 const types::boundary_id b_id,
3876 const unsigned int direction,
3877 AffineConstraints<number> &constraints,
3878 const ComponentMask &component_mask,
3879 const number periodicity_factor)
3880 {
3881 AssertIndexRange(direction, spacedim);
3882
3883 Assert(dim == spacedim, ExcNotImplemented());
3884
3885 std::vector<GridTools::PeriodicFacePair<
3887 matched_faces;
3888
3889 // Collect matching periodic cells on the coarsest level:
3891 b_id,
3892 direction,
3893 matched_faces);
3894
3895 make_periodicity_constraints<dim, spacedim>(matched_faces,
3896 constraints,
3897 component_mask,
3898 std::vector<unsigned int>(),
3899 periodicity_factor);
3900 }
3901
3902
3903
3904 namespace internal
3905 {
3906 namespace Assembler
3907 {
3908 struct Scratch
3909 {};
3910
3911
3912 template <int dim, int spacedim>
3914 {
3915 unsigned int dofs_per_cell;
3916 std::vector<types::global_dof_index> parameter_dof_indices;
3917#ifdef DEAL_II_WITH_MPI
3918 std::vector<::LinearAlgebra::distributed::Vector<double>>
3920#else
3921 std::vector<::Vector<double>> global_parameter_representation;
3922#endif
3923 };
3924 } // namespace Assembler
3925
3926 namespace
3927 {
3933 template <int dim, int spacedim>
3934 void
3935 compute_intergrid_weights_3(
3937 const Assembler::Scratch &,
3939 const unsigned int coarse_component,
3940 const FiniteElement<dim, spacedim> &coarse_fe,
3941 const InterGridMap<DoFHandler<dim, spacedim>> &coarse_to_fine_grid_map,
3942 const std::vector<::Vector<double>> &parameter_dofs)
3943 {
3944 // for each cell on the parameter grid: find out which degrees of
3945 // freedom on the fine grid correspond in which way to the degrees of
3946 // freedom on the parameter grid
3947 //
3948 // since for continuous FEs some dofs exist on more than one cell, we
3949 // have to track which ones were already visited. the problem is that if
3950 // we visit a dof first on one cell and compute its weight with respect
3951 // to some global dofs to be non-zero, and later visit the dof again on
3952 // another cell and (since we are on another cell) recompute the weights
3953 // with respect to the same dofs as above to be zero now, we have to
3954 // preserve them. we therefore overwrite all weights if they are nonzero
3955 // and do not enforce zero weights since that might be only due to the
3956 // fact that we are on another cell.
3957 //
3958 // example:
3959 // coarse grid
3960 // | | |
3961 // *-----*-----*
3962 // | cell|cell |
3963 // | 1 | 2 |
3964 // | | |
3965 // 0-----1-----*
3966 //
3967 // fine grid
3968 // | | | | |
3969 // *--*--*--*--*
3970 // | | | | |
3971 // *--*--*--*--*
3972 // | | | | |
3973 // *--x--y--*--*
3974 //
3975 // when on cell 1, we compute the weights of dof 'x' to be 1/2 from
3976 // parameter dofs 0 and 1, respectively. however, when later we are on
3977 // cell 2, we again compute the prolongation of shape function 1
3978 // restricted to cell 2 to the global grid and find that the weight of
3979 // global dof 'x' now is zero. however, we should not overwrite the old
3980 // value.
3981 //
3982 // we therefore always only set nonzero values. why adding up is not
3983 // useful: dof 'y' would get weight 1 from parameter dof 1 on both cells
3984 // 1 and 2, but the correct weight is nevertheless only 1.
3985
3986 // vector to hold the representation of a single degree of freedom on
3987 // the coarse grid (for the selected fe) on the fine grid
3988
3989 copy_data.dofs_per_cell = coarse_fe.n_dofs_per_cell();
3990 copy_data.parameter_dof_indices.resize(copy_data.dofs_per_cell);
3991
3992 // get the global indices of the parameter dofs on this parameter grid
3993 // cell
3994 cell->get_dof_indices(copy_data.parameter_dof_indices);
3995
3996 // loop over all dofs on this cell and check whether they are
3997 // interesting for us
3998 for (unsigned int local_dof = 0; local_dof < copy_data.dofs_per_cell;
3999 ++local_dof)
4000 if (coarse_fe.system_to_component_index(local_dof).first ==
4001 coarse_component)
4002 {
4003 // the how-many-th parameter is this on this cell?
4004 const unsigned int local_parameter_dof =
4005 coarse_fe.system_to_component_index(local_dof).second;
4006
4007 copy_data.global_parameter_representation[local_parameter_dof] =
4008 0.;
4009
4010 // distribute the representation of @p{local_parameter_dof} on the
4011 // parameter grid cell
4012 // @p{cell} to the global data space
4013 coarse_to_fine_grid_map[cell]->set_dof_values_by_interpolation(
4014 parameter_dofs[local_parameter_dof],
4015 copy_data.global_parameter_representation[local_parameter_dof]);
4016 }
4017 }
4018
4019
4020
4026 template <int dim, int spacedim>
4027 void
4028 copy_intergrid_weights_3(
4029 const Assembler::CopyData<dim, spacedim> &copy_data,
4030 const unsigned int coarse_component,
4031 const FiniteElement<dim, spacedim> &coarse_fe,
4032 const std::vector<types::global_dof_index> &weight_mapping,
4033 const bool is_called_in_parallel,
4034 std::vector<std::map<types::global_dof_index, float>> &weights)
4035 {
4036 unsigned int pos = 0;
4037 for (unsigned int local_dof = 0; local_dof < copy_data.dofs_per_cell;
4038 ++local_dof)
4039 if (coarse_fe.system_to_component_index(local_dof).first ==
4040 coarse_component)
4041 {
4042 // now that we've got the global representation of each parameter
4043 // dof, we've only got to clobber the non-zero entries in that
4044 // vector and store the result
4045 //
4046 // what we have learned: if entry @p{i} of the global vector holds
4047 // the value @p{v[i]}, then this is the weight with which the
4048 // present dof contributes to @p{i}. there may be several such
4049 // @p{i}s and their weights' sum should be one. Then, @p{v[i]}
4050 // should be equal to @p{\sum_j w_{ij} p[j]} with @p{p[j]} be the
4051 // values of the degrees of freedom on the coarse grid. we can
4052 // thus compute constraints which link the degrees of freedom
4053 // @p{v[i]} on the fine grid to those on the coarse grid,
4054 // @p{p[j]}. Now to use these as real constraints, rather than as
4055 // additional equations, we have to identify representants among
4056 // the @p{i} for each @p{j}. this will be done by simply taking
4057 // the first @p{i} for which @p{w_{ij}==1}.
4058 //
4059 // guard modification of the weights array by a Mutex. since it
4060 // should happen rather rarely that there are several threads
4061 // operating on different intergrid weights, have only one mutex
4062 // for all of them
4063 for (types::global_dof_index i = 0;
4064 i < copy_data.global_parameter_representation[pos].size();
4065 ++i)
4066 // set this weight if it belongs to a parameter dof.
4067 if (weight_mapping[i] != numbers::invalid_dof_index)
4068 {
4069 // only overwrite old value if not by zero
4070 if (copy_data.global_parameter_representation[pos](i) != 0)
4071 {
4073 wi = copy_data.parameter_dof_indices[local_dof],
4074 wj = weight_mapping[i];
4075 weights[wi][wj] =
4076 copy_data.global_parameter_representation[pos](i);
4077 }
4078 }
4079 else if (!is_called_in_parallel)
4080 {
4081 // Note that when this function operates with distributed
4082 // fine grid, this assertion is switched off since the
4083 // condition does not necessarily hold
4084 Assert(copy_data.global_parameter_representation[pos](i) ==
4085 0,
4087 }
4088
4089 ++pos;
4090 }
4091 }
4092
4093
4094
4100 template <int dim, int spacedim>
4101 void
4102 compute_intergrid_weights_2(
4103 const DoFHandler<dim, spacedim> &coarse_grid,
4104 const unsigned int coarse_component,
4105 const InterGridMap<DoFHandler<dim, spacedim>> &coarse_to_fine_grid_map,
4106 const std::vector<::Vector<double>> &parameter_dofs,
4107 const std::vector<types::global_dof_index> &weight_mapping,
4108 std::vector<std::map<types::global_dof_index, float>> &weights)
4109 {
4110 Assembler::Scratch scratch;
4111 Assembler::CopyData<dim, spacedim> copy_data;
4112
4113 unsigned int n_interesting_dofs = 0;
4114 for (unsigned int local_dof = 0;
4115 local_dof < coarse_grid.get_fe().n_dofs_per_cell();
4116 ++local_dof)
4117 if (coarse_grid.get_fe().system_to_component_index(local_dof).first ==
4118 coarse_component)
4119 ++n_interesting_dofs;
4120
4121 copy_data.global_parameter_representation.resize(n_interesting_dofs);
4122
4123 bool is_called_in_parallel = false;
4124 for (std::size_t i = 0;
4125 i < copy_data.global_parameter_representation.size();
4126 ++i)
4127 {
4128#ifdef DEAL_II_WITH_MPI
4129 MPI_Comm communicator = MPI_COMM_SELF;
4130 try
4131 {
4132 const typename ::parallel::TriangulationBase<dim,
4133 spacedim>
4134 &tria = dynamic_cast<const typename ::parallel::
4135 TriangulationBase<dim, spacedim> &>(
4136 coarse_to_fine_grid_map.get_destination_grid()
4137 .get_triangulation());
4138 communicator = tria.get_communicator();
4139 is_called_in_parallel = true;
4140 }
4141 catch (std::bad_cast &)
4142 {
4143 // Nothing bad happened: the user used serial Triangulation
4144 }
4145
4146
4147 const IndexSet locally_relevant_dofs =
4149 coarse_to_fine_grid_map.get_destination_grid());
4150
4151 copy_data.global_parameter_representation[i].reinit(
4152 coarse_to_fine_grid_map.get_destination_grid()
4153 .locally_owned_dofs(),
4154 locally_relevant_dofs,
4155 communicator);
4156#else
4157 const types::global_dof_index n_fine_dofs = weight_mapping.size();
4158 copy_data.global_parameter_representation[i].reinit(n_fine_dofs);
4159#endif
4160 }
4161
4162 auto worker =
4163 [coarse_component,
4164 &coarse_grid,
4165 &coarse_to_fine_grid_map,
4166 &parameter_dofs](
4168 &cell,
4169 const Assembler::Scratch &scratch_data,
4170 Assembler::CopyData<dim, spacedim> &copy_data) {
4171 compute_intergrid_weights_3<dim, spacedim>(cell,
4172 scratch_data,
4173 copy_data,
4174 coarse_component,
4175 coarse_grid.get_fe(),
4176 coarse_to_fine_grid_map,
4177 parameter_dofs);
4178 };
4179
4180 auto copier =
4181 [coarse_component,
4182 &coarse_grid,
4183 &weight_mapping,
4184 is_called_in_parallel,
4185 &weights](const Assembler::CopyData<dim, spacedim> &copy_data) {
4186 copy_intergrid_weights_3<dim, spacedim>(copy_data,
4187 coarse_component,
4188 coarse_grid.get_fe(),
4189 weight_mapping,
4190 is_called_in_parallel,
4191 weights);
4192 };
4193
4194 WorkStream::run(coarse_grid.begin_active(),
4195 coarse_grid.end(),
4196 worker,
4197 copier,
4198 scratch,
4199 copy_data);
4200
4201#ifdef DEAL_II_WITH_MPI
4202 for (std::size_t i = 0;
4203 i < copy_data.global_parameter_representation.size();
4204 ++i)
4205 copy_data.global_parameter_representation[i].update_ghost_values();
4206#endif
4207 }
4208
4209
4210
4216 template <int dim, int spacedim>
4217 unsigned int
4218 compute_intergrid_weights_1(
4219 const DoFHandler<dim, spacedim> &coarse_grid,
4220 const unsigned int coarse_component,
4221 const DoFHandler<dim, spacedim> &fine_grid,
4222 const unsigned int fine_component,
4223 const InterGridMap<DoFHandler<dim, spacedim>> &coarse_to_fine_grid_map,
4224 std::vector<std::map<types::global_dof_index, float>> &weights,
4225 std::vector<types::global_dof_index> &weight_mapping)
4226 {
4227 // aliases to the finite elements used by the dof handlers:
4228 const FiniteElement<dim, spacedim> &coarse_fe = coarse_grid.get_fe(),
4229 &fine_fe = fine_grid.get_fe();
4230
4231 // global numbers of dofs
4232 const types::global_dof_index n_coarse_dofs = coarse_grid.n_dofs(),
4233 n_fine_dofs = fine_grid.n_dofs();
4234
4235 // local numbers of dofs
4236 const unsigned int fine_dofs_per_cell = fine_fe.n_dofs_per_cell();
4237
4238 // alias the number of dofs per cell belonging to the coarse_component
4239 // which is to be the restriction of the fine grid:
4240 const unsigned int coarse_dofs_per_cell_component =
4241 coarse_fe
4242 .base_element(
4243 coarse_fe.component_to_base_index(coarse_component).first)
4244 .n_dofs_per_cell();
4245
4246
4247 // Try to find out whether the grids stem from the same coarse grid.
4248 // This is a rather crude test, but better than nothing
4249 Assert(coarse_grid.get_triangulation().n_cells(0) ==
4250 fine_grid.get_triangulation().n_cells(0),
4252
4253 // check whether the map correlates the right objects
4254 Assert(&coarse_to_fine_grid_map.get_source_grid() == &coarse_grid,
4256 Assert(&coarse_to_fine_grid_map.get_destination_grid() == &fine_grid,
4258
4259
4260 // check whether component numbers are valid
4261 AssertIndexRange(coarse_component, coarse_fe.n_components());
4262 AssertIndexRange(fine_component, fine_fe.n_components());
4263
4264 // check whether respective finite elements are equal
4265 Assert(coarse_fe.base_element(
4266 coarse_fe.component_to_base_index(coarse_component).first) ==
4267 fine_fe.base_element(
4268 fine_fe.component_to_base_index(fine_component).first),
4270
4271#ifdef DEBUG
4272 // if in debug mode, check whether the coarse grid is indeed coarser
4273 // everywhere than the fine grid
4274 for (const auto &cell : coarse_grid.active_cell_iterators())
4275 Assert(cell->level() <= coarse_to_fine_grid_map[cell]->level(),
4277#endif
4278
4279 /*
4280 * From here on: the term `parameter' refers to the selected component
4281 * on the coarse grid and its analogon on the fine grid. The naming of
4282 * variables containing this term is due to the fact that
4283 * `selected_component' is longer, but also due to the fact that the
4284 * code of this function was initially written for a program where the
4285 * component which we wanted to match between grids was actually the
4286 * `parameter' variable.
4287 *
4288 * Likewise, the terms `parameter grid' and `state grid' refer to the
4289 * coarse and fine grids, respectively.
4290 *
4291 * Changing the names of variables would in principle be a good idea,
4292 * but would not make things simpler and would be another source of
4293 * errors. If anyone feels like doing so: patches would be welcome!
4294 */
4295
4296
4297
4298 // set up vectors of cell-local data; each vector represents one degree
4299 // of freedom of the coarse-grid variable in the fine-grid element
4300 std::vector<::Vector<double>> parameter_dofs(
4301 coarse_dofs_per_cell_component,
4302 ::Vector<double>(fine_dofs_per_cell));
4303 // for each coarse dof: find its position within the fine element and
4304 // set this value to one in the respective vector (all other values are
4305 // zero by construction)
4306 for (unsigned int local_coarse_dof = 0;
4307 local_coarse_dof < coarse_dofs_per_cell_component;
4308 ++local_coarse_dof)
4309 for (unsigned int fine_dof = 0; fine_dof < fine_fe.n_dofs_per_cell();
4310 ++fine_dof)
4311 if (fine_fe.system_to_component_index(fine_dof) ==
4312 std::make_pair(fine_component, local_coarse_dof))
4313 {
4314 parameter_dofs[local_coarse_dof](fine_dof) = 1.;
4315 break;
4316 }
4317
4318
4319 // find out how many DoFs there are on the grids belonging to the
4320 // components we want to match
4321 unsigned int n_parameters_on_fine_grid = 0;
4322 {
4323 // have a flag for each dof on the fine grid and set it to true if
4324 // this is an interesting dof. finally count how many true's there
4325 std::vector<bool> dof_is_interesting(fine_grid.n_dofs(), false);
4326 std::vector<types::global_dof_index> local_dof_indices(
4327 fine_fe.n_dofs_per_cell());
4328
4329 for (const auto &cell : fine_grid.active_cell_iterators() |
4330 IteratorFilters::LocallyOwnedCell())
4331 {
4332 cell->get_dof_indices(local_dof_indices);
4333 for (unsigned int i = 0; i < fine_fe.n_dofs_per_cell(); ++i)
4334 if (fine_fe.system_to_component_index(i).first ==
4335 fine_component)
4336 dof_is_interesting[local_dof_indices[i]] = true;
4337 }
4338
4339 n_parameters_on_fine_grid = std::count(dof_is_interesting.begin(),
4340 dof_is_interesting.end(),
4341 true);
4342 }
4343
4344
4345 // set up the weights mapping
4346 weights.clear();
4347 weights.resize(n_coarse_dofs);
4348
4349 weight_mapping.clear();
4350 weight_mapping.resize(n_fine_dofs, numbers::invalid_dof_index);
4351
4352 {
4353 std::vector<types::global_dof_index> local_dof_indices(
4354 fine_fe.n_dofs_per_cell());
4355 unsigned int next_free_index = 0;
4356 for (const auto &cell : fine_grid.active_cell_iterators() |
4357 IteratorFilters::LocallyOwnedCell())
4358 {
4359 cell->get_dof_indices(local_dof_indices);
4360 for (unsigned int i = 0; i < fine_fe.n_dofs_per_cell(); ++i)
4361 // if this DoF is a parameter dof and has not yet been
4362 // numbered, then do so
4363 if ((fine_fe.system_to_component_index(i).first ==
4364 fine_component) &&
4365 (weight_mapping[local_dof_indices[i]] ==
4367 {
4368 weight_mapping[local_dof_indices[i]] = next_free_index;
4369 ++next_free_index;
4370 }
4371 }
4372
4373 Assert(next_free_index == n_parameters_on_fine_grid,
4375 }
4376
4377
4378 // for each cell on the parameter grid: find out which degrees of
4379 // freedom on the fine grid correspond in which way to the degrees of
4380 // freedom on the parameter grid
4381 //
4382 // do this in a separate function to allow for multithreading there. see
4383 // this function also if you want to read more information on the
4384 // algorithm used.
4385 compute_intergrid_weights_2(coarse_grid,
4386 coarse_component,
4387 coarse_to_fine_grid_map,
4388 parameter_dofs,
4389 weight_mapping,
4390 weights);
4391
4392
4393 // ok, now we have all weights for each dof on the fine grid. if in
4394 // debug mode lets see if everything went smooth, i.e. each dof has sum
4395 // of weights one
4396 //
4397 // in other words this means that if the sum of all shape functions on
4398 // the parameter grid is one (which is always the case), then the
4399 // representation on the state grid should be as well (division of
4400 // unity)
4401 //
4402 // if the parameter grid has more than one component, then the
4403 // respective dofs of the other components have sum of weights zero, of
4404 // course. we do not explicitly ask which component a dof belongs to,
4405 // but this at least tests some errors
4406#ifdef DEBUG
4407 for (unsigned int col = 0; col < n_parameters_on_fine_grid; ++col)
4408 {
4409 double sum = 0;
4410 for (types::global_dof_index row = 0; row < n_coarse_dofs; ++row)
4411 if (weights[row].find(col) != weights[row].end())
4412 sum += weights[row][col];
4413 Assert((std::fabs(sum - 1) < 1.e-12) ||
4414 ((coarse_fe.n_components() > 1) && (sum == 0)),
4416 }
4417#endif
4418
4419
4420 return n_parameters_on_fine_grid;
4421 }
4422
4423
4424 } // namespace
4425 } // namespace internal
4426
4427
4428
4429 template <int dim, int spacedim>
4430 void
4432 const DoFHandler<dim, spacedim> &coarse_grid,
4433 const unsigned int coarse_component,
4434 const DoFHandler<dim, spacedim> &fine_grid,
4435 const unsigned int fine_component,
4436 const InterGridMap<DoFHandler<dim, spacedim>> &coarse_to_fine_grid_map,
4437 AffineConstraints<double> &constraints)
4438 {
4439 Assert(coarse_grid.get_fe_collection().size() == 1 &&
4440 fine_grid.get_fe_collection().size() == 1,
4441 ExcMessage("This function is not yet implemented for DoFHandlers "
4442 "using hp-capabilities."));
4443 // store the weights with which a dof on the parameter grid contributes to a
4444 // dof on the fine grid. see the long doc below for more info
4445 //
4446 // allocate as many rows as there are parameter dofs on the coarse grid and
4447 // as many columns as there are parameter dofs on the fine grid.
4448 //
4449 // weight_mapping is used to map the global (fine grid) parameter dof
4450 // indices to the columns
4451 //
4452 // in the original implementation, the weights array was actually of
4453 // FullMatrix<double> type. this wasted huge amounts of memory, but was
4454 // fast. nonetheless, since the memory consumption was quadratic in the
4455 // number of degrees of freedom, this was not very practical, so we now use
4456 // a vector of rows of the matrix, and in each row a vector of pairs
4457 // (colnum,value). this seems like the best tradeoff between memory and
4458 // speed, as it is now linear in memory and still fast enough.
4459 //
4460 // to save some memory and since the weights are usually (negative) powers
4461 // of 2, we choose the value type of the matrix to be @p{float} rather than
4462 // @p{double}.
4463 std::vector<std::map<types::global_dof_index, float>> weights;
4464
4465 // this is this mapping. there is one entry for each dof on the fine grid;
4466 // if it is a parameter dof, then its value is the column in weights for
4467 // that parameter dof, if it is any other dof, then its value is -1,
4468 // indicating an error
4469 std::vector<types::global_dof_index> weight_mapping;
4470
4471 const unsigned int n_parameters_on_fine_grid =
4472 internal::compute_intergrid_weights_1(coarse_grid,
4473 coarse_component,
4474 fine_grid,
4475 fine_component,
4476 coarse_to_fine_grid_map,
4477 weights,
4478 weight_mapping);
4479 (void)n_parameters_on_fine_grid;
4480
4481 // global numbers of dofs
4482 const types::global_dof_index n_coarse_dofs = coarse_grid.n_dofs(),
4483 n_fine_dofs = fine_grid.n_dofs();
4484
4485
4486 // get an array in which we store which dof on the coarse grid is a
4487 // parameter and which is not
4488 IndexSet coarse_dof_is_parameter;
4489 {
4490 std::vector<bool> mask(coarse_grid.get_fe(0).n_components(), false);
4491 mask[coarse_component] = true;
4492
4493 coarse_dof_is_parameter =
4494 extract_dofs<dim, spacedim>(coarse_grid, ComponentMask(mask));
4495 }
4496
4497 // now we know that the weights in each row constitute a constraint. enter
4498 // this into the constraints object
4499 //
4500 // first task: for each parameter dof on the parameter grid, find a
4501 // representant on the fine, global grid. this is possible since we use
4502 // conforming finite element. we take this representant to be the first
4503 // element in this row with weight identical to one. the representant will
4504 // become an unconstrained degree of freedom, while all others will be
4505 // constrained to this dof (and possibly others)
4506 std::vector<types::global_dof_index> representants(
4507 n_coarse_dofs, numbers::invalid_dof_index);
4508 for (types::global_dof_index parameter_dof = 0;
4509 parameter_dof < n_coarse_dofs;
4510 ++parameter_dof)
4511 if (coarse_dof_is_parameter.is_element(parameter_dof))
4512 {
4513 // if this is the line of a parameter dof on the coarse grid, then it
4514 // should have at least one dependent node on the fine grid
4515 Assert(weights[parameter_dof].size() > 0, ExcInternalError());
4516
4517 // find the column where the representant is mentioned
4518 std::map<types::global_dof_index, float>::const_iterator i =
4519 weights[parameter_dof].begin();
4520 for (; i != weights[parameter_dof].end(); ++i)
4521 if (i->second == 1)
4522 break;
4523 Assert(i != weights[parameter_dof].end(), ExcInternalError());
4524 const types::global_dof_index column = i->first;
4525
4526 // now we know in which column of weights the representant is, but we
4527 // don't know its global index. get it using the inverse operation of
4528 // the weight_mapping
4529 types::global_dof_index global_dof = 0;
4530 for (; global_dof < weight_mapping.size(); ++global_dof)
4531 if (weight_mapping[global_dof] ==
4532 static_cast<types::global_dof_index>(column))
4533 break;
4534 Assert(global_dof < weight_mapping.size(), ExcInternalError());
4535
4536 // now enter the representants global index into our list
4537 representants[parameter_dof] = global_dof;
4538 }
4539 else
4540 {
4541 // consistency check: if this is no parameter dof on the coarse grid,
4542 // then the respective row must be empty!
4543 Assert(weights[parameter_dof].empty(), ExcInternalError());
4544 }
4545
4546
4547
4548 // note for people that want to optimize this function: the largest part of
4549 // the computing time is spent in the following, rather innocent block of
4550 // code. basically, it must be the AffineConstraints::add_entry call which
4551 // takes the bulk of the time, but it is not known to the author how to make
4552 // it faster...
4553 std::vector<std::pair<types::global_dof_index, double>> constraint_line;
4554 for (types::global_dof_index global_dof = 0; global_dof < n_fine_dofs;
4555 ++global_dof)
4556 if (weight_mapping[global_dof] != numbers::invalid_dof_index)
4557 // this global dof is a parameter dof, so it may carry a constraint note
4558 // that for each global dof, the sum of weights shall be one, so we can
4559 // find out whether this dof is constrained in the following way: if the
4560 // only weight in this row is a one, and the representant for the
4561 // parameter dof of the line in which this one is is the present dof,
4562 // then we consider this dof to be unconstrained. otherwise, all other
4563 // dofs are constrained
4564 {
4565 const types::global_dof_index col = weight_mapping[global_dof];
4566 Assert(col < n_parameters_on_fine_grid, ExcInternalError());
4567
4568 types::global_dof_index first_used_row = 0;
4569
4570 {
4571 Assert(weights.size() > 0, ExcInternalError());
4572 std::map<types::global_dof_index, float>::const_iterator col_entry =
4573 weights[0].end();
4574 for (; first_used_row < n_coarse_dofs; ++first_used_row)
4575 {
4576 col_entry = weights[first_used_row].find(col);
4577 if (col_entry != weights[first_used_row].end())
4578 break;
4579 }
4580
4581 Assert(col_entry != weights[first_used_row].end(),
4583
4584 if ((col_entry->second == 1) &&
4585 (representants[first_used_row] == global_dof))
4586 // dof unconstrained or constrained to itself (in case this cell
4587 // is mapped to itself, rather than to children of itself)
4588 continue;
4589 }
4590
4591
4592 // otherwise enter all constraints
4593 constraint_line.clear();
4594 for (types::global_dof_index row = first_used_row;
4595 row < n_coarse_dofs;
4596 ++row)
4597 {
4598 const std::map<types::global_dof_index, float>::const_iterator j =
4599 weights[row].find(col);
4600 if ((j != weights[row].end()) && (j->second != 0))
4601 constraint_line.emplace_back(representants[row], j->second);
4602 }
4603
4604 constraints.add_constraint(global_dof, constraint_line, 0.);
4605 }
4606 }
4607
4608
4609
4610 template <int dim, int spacedim>
4611 void
4613 const DoFHandler<dim, spacedim> &coarse_grid,
4614 const unsigned int coarse_component,
4615 const DoFHandler<dim, spacedim> &fine_grid,
4616 const unsigned int fine_component,
4617 const InterGridMap<DoFHandler<dim, spacedim>> &coarse_to_fine_grid_map,
4618 std::vector<std::map<types::global_dof_index, float>>
4619 &transfer_representation)
4620 {
4621 Assert(coarse_grid.get_fe_collection().size() == 1 &&
4622 fine_grid.get_fe_collection().size() == 1,
4623 ExcMessage("This function is not yet implemented for DoFHandlers "
4624 "using hp-capabilities."));
4625 // store the weights with which a dof on the parameter grid contributes to a
4626 // dof on the fine grid. see the long doc below for more info
4627 //
4628 // allocate as many rows as there are parameter dofs on the coarse grid and
4629 // as many columns as there are parameter dofs on the fine grid.
4630 //
4631 // weight_mapping is used to map the global (fine grid) parameter dof
4632 // indices to the columns
4633 //
4634 // in the original implementation, the weights array was actually of
4635 // FullMatrix<double> type. this wasted huge amounts of memory, but was
4636 // fast. nonetheless, since the memory consumption was quadratic in the
4637 // number of degrees of freedom, this was not very practical, so we now use
4638 // a vector of rows of the matrix, and in each row a vector of pairs
4639 // (colnum,value). this seems like the best tradeoff between memory and
4640 // speed, as it is now linear in memory and still fast enough.
4641 //
4642 // to save some memory and since the weights are usually (negative) powers
4643 // of 2, we choose the value type of the matrix to be @p{float} rather than
4644 // @p{double}.
4645 std::vector<std::map<types::global_dof_index, float>> weights;
4646
4647 // this is this mapping. there is one entry for each dof on the fine grid;
4648 // if it is a parameter dof, then its value is the column in weights for
4649 // that parameter dof, if it is any other dof, then its value is -1,
4650 // indicating an error
4651 std::vector<types::global_dof_index> weight_mapping;
4652
4653 internal::compute_intergrid_weights_1(coarse_grid,
4654 coarse_component,
4655 fine_grid,
4656 fine_component,
4657 coarse_to_fine_grid_map,
4658 weights,
4659 weight_mapping);
4660
4661 // now compute the requested representation
4662 const types::global_dof_index n_global_parm_dofs =
4663 std::count_if(weight_mapping.begin(),
4664 weight_mapping.end(),
4665 [](const types::global_dof_index dof) {
4666 return dof != numbers::invalid_dof_index;
4667 });
4668
4669 // first construct the inverse mapping of weight_mapping
4670 std::vector<types::global_dof_index> inverse_weight_mapping(
4671 n_global_parm_dofs, numbers::invalid_dof_index);
4672 for (types::global_dof_index i = 0; i < weight_mapping.size(); ++i)
4673 {
4674 const types::global_dof_index parameter_dof = weight_mapping[i];
4675 // if this global dof is a parameter
4676 if (parameter_dof != numbers::invalid_dof_index)
4677 {
4678 Assert(parameter_dof < n_global_parm_dofs, ExcInternalError());
4679 Assert((inverse_weight_mapping[parameter_dof] ==
4682
4683 inverse_weight_mapping[parameter_dof] = i;
4684 }
4685 }
4686
4687 // next copy over weights array and replace respective numbers
4688 const types::global_dof_index n_rows = weight_mapping.size();
4689
4690 transfer_representation.clear();
4691 transfer_representation.resize(n_rows);
4692
4693 const types::global_dof_index n_coarse_dofs = coarse_grid.n_dofs();
4694 for (types::global_dof_index i = 0; i < n_coarse_dofs; ++i)
4695 {
4696 std::map<types::global_dof_index, float>::const_iterator j =
4697 weights[i].begin();
4698 for (; j != weights[i].end(); ++j)
4699 {
4700 const types::global_dof_index p = inverse_weight_mapping[j->first];
4701 Assert(p < n_rows, ExcInternalError());
4702
4703 transfer_representation[p][i] = j->second;
4704 }
4705 }
4706 }
4707
4708
4709
4710 template <int dim, int spacedim, typename number>
4711 void
4713 const DoFHandler<dim, spacedim> &dof,
4714 const types::boundary_id boundary_id,
4715 AffineConstraints<number> &zero_boundary_constraints,
4716 const ComponentMask &component_mask)
4717 {
4718 Assert(component_mask.represents_n_components(dof.get_fe(0).n_components()),
4719 ExcMessage("The number of components in the mask has to be either "
4720 "zero or equal to the number of components in the finite "
4721 "element."));
4722
4723 const unsigned int n_components = dof.get_fe_collection().n_components();
4724
4725 Assert(component_mask.n_selected_components(n_components) > 0,
4727
4728 // a field to store the indices on the face
4729 std::vector<types::global_dof_index> face_dofs;
4730 face_dofs.reserve(dof.get_fe_collection().max_dofs_per_face());
4731 // a field to store the indices on the cell
4732 std::vector<types::global_dof_index> cell_dofs;
4733 cell_dofs.reserve(dof.get_fe_collection().max_dofs_per_cell());
4734
4735 // In looping over faces, we will encounter some DoFs multiple
4736 // times (namely, the ones on vertices and (in 3d) edges shared
4737 // between multiple boundary faces. Keep track of which DoFs we
4738 // have already encountered, so that we do not have to consider
4739 // them a second time.
4740 std::set<types::global_dof_index> dofs_already_treated;
4741
4742 for (const auto &cell : dof.active_cell_iterators())
4743 if (!cell->is_artificial() && cell->at_boundary())
4744 {
4745 const FiniteElement<dim, spacedim> &fe = cell->get_fe();
4746
4747 // get global indices of dofs on the cell
4748 cell_dofs.resize(fe.n_dofs_per_cell());
4749 cell->get_dof_indices(cell_dofs);
4750
4751 for (const auto face_no : cell->face_indices())
4752 {
4753 const typename DoFHandler<dim, spacedim>::face_iterator face =
4754 cell->face(face_no);
4755
4756 // if face is on the boundary and satisfies the correct boundary
4757 // id property
4758 if (face->at_boundary() &&
4759 ((boundary_id == numbers::invalid_boundary_id) ||
4760 (face->boundary_id() == boundary_id)))
4761 {
4762 // get indices and physical location on this face
4763 face_dofs.resize(fe.n_dofs_per_face(face_no));
4764 face->get_dof_indices(face_dofs, cell->active_fe_index());
4765
4766 // enter those dofs into the list that match the component
4767 // signature.
4768 for (const types::global_dof_index face_dof : face_dofs)
4769 if (dofs_already_treated.find(face_dof) ==
4770 dofs_already_treated.end())
4771 {
4772 // Find out if a dof has a contribution in this
4773 // component, and if so, add it to the list
4774 const std::vector<types::global_dof_index>::iterator
4775 it_index_on_cell = std::find(cell_dofs.begin(),
4776 cell_dofs.end(),
4777 face_dof);
4778 Assert(it_index_on_cell != cell_dofs.end(),
4780 const unsigned int index_on_cell =
4781 std::distance(cell_dofs.begin(), it_index_on_cell);
4782 const ComponentMask &nonzero_component_array =
4783 cell->get_fe().get_nonzero_components(index_on_cell);
4784
4785 bool nonzero = false;
4786 for (unsigned int c = 0; c < n_components; ++c)
4787 if (nonzero_component_array[c] && component_mask[c])
4788 {
4789 nonzero = true;
4790 break;
4791 }
4792
4793 if (nonzero)
4794 {
4795 // Check that either (i) the DoF is not
4796 // yet constrained, or (ii) if it is, its
4797 // inhomogeneity is zero:
4798 if (zero_boundary_constraints.is_constrained(
4799 face_dof) == false)
4800 zero_boundary_constraints.constrain_dof_to_zero(
4801 face_dof);
4802 else
4803 Assert(zero_boundary_constraints
4804 .is_inhomogeneously_constrained(
4805 face_dof) == false,
4807 }
4808
4809 // We already dealt with this DoF. Make sure we
4810 // don't touch it again.
4811 dofs_already_treated.insert(face_dof);
4812 }
4813 }
4814 }
4815 }
4816 }
4817
4818
4819
4820 template <int dim, int spacedim, typename number>
4821 void
4823 const DoFHandler<dim, spacedim> &dof,
4824 AffineConstraints<number> &zero_boundary_constraints,
4825 const ComponentMask &component_mask)
4826 {
4829 zero_boundary_constraints,
4830 component_mask);
4831 }
4832
4833
4834} // end of namespace DoFTools
4835
4836
4837
4838// explicit instantiations
4839
4840#include "dof_tools_constraints.inst"
4841
4842
4843
void add_line(const size_type line_n)
void add_constraint(const size_type constrained_dof, const ArrayView< const std::pair< size_type, number > > &dependencies, const number inhomogeneity=0)
void add_entry(const size_type constrained_dof_index, const size_type column, const number weight)
const IndexSet & get_local_lines() const
void set_inhomogeneity(const size_type constrained_dof_index, const number value)
bool is_constrained(const size_type line_n) const
const std::vector< std::pair< size_type, number > > * get_constraint_entries(const size_type line_n) const
void constrain_dof_to_zero(const size_type constrained_dof)
bool represents_n_components(const unsigned int n) const
unsigned int n_selected_components(const unsigned int overall_number_of_components=numbers::invalid_unsigned_int) const
const hp::FECollection< dim, spacedim > & get_fe_collection() const
bool has_active_dofs() const
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
const Triangulation< dim, spacedim > & get_triangulation() const
bool has_hp_capabilities() const
types::global_dof_index n_dofs() const
unsigned int n_dofs_per_vertex() const
const unsigned int degree
Definition fe_data.h:452
unsigned int n_dofs_per_cell() const
unsigned int n_dofs_per_line() const
unsigned int n_dofs_per_face(unsigned int face_no=0, unsigned int child=0) const
unsigned int n_components() const
unsigned int n_unique_faces() const
unsigned int n_dofs_per_quad(unsigned int face_no=0) const
virtual std::string get_name() const =0
virtual const FiniteElement< dim, spacedim > & base_element(const unsigned int index) const
std::pair< unsigned int, unsigned int > component_to_base_index(const unsigned int component) const
virtual unsigned int face_to_cell_index(const unsigned int face_dof_index, const unsigned int face, const unsigned char combined_orientation=ReferenceCell::default_combined_face_orientation()) const
const std::vector< Point< dim - 1 > > & get_unit_face_support_points(const unsigned int face_no=0) const
virtual void get_subface_interpolation_matrix(const FiniteElement< dim, spacedim > &source, const unsigned int subface, FullMatrix< double > &matrix, const unsigned int face_no=0) const
std::pair< unsigned int, unsigned int > system_to_component_index(const unsigned int index) const
const FullMatrix< double > & constraints(const ::internal::SubfaceCase< dim > &subface_case=::internal::SubfaceCase< dim >::case_isotropic) const
virtual void get_face_interpolation_matrix(const FiniteElement< dim, spacedim > &source, FullMatrix< double > &matrix, const unsigned int face_no=0) const
std::pair< unsigned int, unsigned int > face_system_to_component_index(const unsigned int index, const unsigned int face_no=0) const
void mmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
size_type n() const
void invert(const FullMatrix< number2 > &M)
size_type m() const
size_type size() const
Definition index_set.h:1765
bool is_element(const size_type index) const
Definition index_set.h:1883
virtual MPI_Comm get_communicator() const
bool get_anisotropic_refinement_flag() const
unsigned int n_cells() const
unsigned int size() const
Definition collection.h:264
unsigned int find_dominating_fe_extended(const std::set< unsigned int > &fes, const unsigned int codim=0) const
bool hp_constraints_are_implemented() const
unsigned int max_dofs_per_face() const
unsigned int n_components() const
unsigned int max_dofs_per_cell() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
Point< 3 > center
unsigned int level
Definition grid_out.cc:4626
unsigned int cell_index
IteratorRange< active_cell_iterator > active_cell_iterators() const
static ::ExceptionBase & ExcInvalidIterator()
static ::ExceptionBase & ExcGridNotCoarser()
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcFiniteElementsDontMatch()
static ::ExceptionBase & ExcNoComponentSelected()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcGridsDontMatch()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
typename ActiveSelector::cell_iterator cell_iterator
typename ActiveSelector::line_iterator line_iterator
typename ActiveSelector::face_iterator face_iterator
typename ActiveSelector::active_cell_iterator active_cell_iterator
void compute_intergrid_transfer_representation(const DoFHandler< dim, spacedim > &coarse_grid, const unsigned int coarse_component, const DoFHandler< dim, spacedim > &fine_grid, const unsigned int fine_component, const InterGridMap< DoFHandler< dim, spacedim > > &coarse_to_fine_grid_map, std::vector< std::map< types::global_dof_index, float > > &transfer_representation)
void make_hanging_node_constraints(const DoFHandler< dim, spacedim > &dof_handler, AffineConstraints< number > &constraints)
void compute_intergrid_constraints(const DoFHandler< dim, spacedim > &coarse_grid, const unsigned int coarse_component, const DoFHandler< dim, spacedim > &fine_grid, const unsigned int fine_component, const InterGridMap< DoFHandler< dim, spacedim > > &coarse_to_fine_grid_map, AffineConstraints< double > &constraints)
void make_zero_boundary_constraints(const DoFHandler< dim, spacedim > &dof, const types::boundary_id boundary_id, AffineConstraints< number > &zero_boundary_constraints, const ComponentMask &component_mask={})
#define DEAL_II_ASSERT_UNREACHABLE()
Expression fabs(const Expression &x)
void make_hp_hanging_node_constraints(const DoFHandler< 1, spacedim > &, AffineConstraints< number > &)
void make_hanging_node_constraints_nedelec(const ::DoFHandler< 1, spacedim > &, AffineConstraints< number > &, std::integral_constant< int, 1 >)
void make_oldstyle_hanging_node_constraints(const DoFHandler< 1, spacedim > &, AffineConstraints< number > &, std::integral_constant< int, 1 >)
void set_periodicity_constraints(const FaceIterator &face_1, const std_cxx20::type_identity_t< FaceIterator > &face_2, const FullMatrix< double > &transformation, AffineConstraints< number > &affine_constraints, const ComponentMask &component_mask, const unsigned char combined_orientation, const number periodicity_factor, const unsigned int level=numbers::invalid_unsigned_int)
void make_periodicity_constraints(const FaceIterator &face_1, const std_cxx20::type_identity_t< FaceIterator > &face_2, AffineConstraints< number > &constraints, const ComponentMask &component_mask={}, const unsigned char combined_orientation=ReferenceCell::default_combined_face_orientation(), const FullMatrix< double > &matrix=FullMatrix< double >(), const std::vector< unsigned int > &first_vector_components=std::vector< unsigned int >(), const number periodicity_factor=1.)
IndexSet extract_locally_relevant_dofs(const DoFHandler< dim, spacedim > &dof_handler)
spacedim const Point< spacedim > & p
Definition grid_tools.h:990
const Triangulation< dim, spacedim > & tria
void collect_periodic_faces(const MeshType &mesh, const types::boundary_id b_id1, const types::boundary_id b_id2, const unsigned int direction, std::vector< PeriodicFacePair< typename MeshType::cell_iterator > > &matched_pairs, const Tensor< 1, MeshType::space_dimension > &offset=::Tensor< 1, MeshType::space_dimension >(), const FullMatrix< double > &matrix=FullMatrix< double >())
if(marked_vertices.size() !=0) for(auto it
@ matrix
Contents is actually a matrix.
types::global_dof_index size_type
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
T sum(const T &t, const MPI_Comm mpi_communicator)
void run(const std::vector< std::vector< Iterator > > &colored_iterators, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)
std::tuple< bool, bool, bool > split_face_orientation(const unsigned char combined_face_orientation)
const types::boundary_id invalid_boundary_id
Definition types.h:292
const types::fe_index invalid_fe_index
Definition types.h:243
static const unsigned int invalid_unsigned_int
Definition types.h:220
const types::global_dof_index invalid_dof_index
Definition types.h:252
const Iterator const std_cxx20::type_identity_t< Iterator > & end
Definition parallel.h:610
typename type_identity< T >::type type_identity_t
Definition type_traits.h:95
STL namespace.
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
unsigned short int fe_index
Definition types.h:59
std::vector<::LinearAlgebra::distributed::Vector< double > > global_parameter_representation
std::vector< types::global_dof_index > parameter_dof_indices
static unsigned int n_children(const RefinementCase< dim > &refinement_case)