76 template <
int dim,
typename Number =
double>
88 double downstream_size = 0;
90 for (
unsigned int d = 0;
d < dim; ++
d)
92 downstream_size += (rhs[
d] - lhs[
d]) * weight;
95 if (downstream_size < 0)
97 else if (downstream_size > 0)
101 for (
unsigned int d = 0;
d < dim; ++
d)
103 if (lhs[
d] == rhs[
d])
105 return lhs[
d] < rhs[
d];
125 template <
int dim,
int spacedim>
126 std::vector<unsigned char>
130 std::vector<unsigned char> local_component_association(
139 local_component_association[i] =
150 const unsigned int first_comp =
155 local_component_association[i] = first_comp;
162 for (
unsigned int c = first_comp; c < fe.
n_components(); ++c)
163 if (component_mask[c] ==
true)
165 local_component_association[i] = c;
170 Assert(std::find(local_component_association.begin(),
171 local_component_association.end(),
172 static_cast<unsigned char>(-1)) ==
173 local_component_association.end(),
176 return local_component_association;
196 template <
int dim,
int spacedim>
200 std::vector<unsigned char> &dofs_by_component)
202 const ::hp::FECollection<dim, spacedim> &fe_collection =
216 std::vector<std::vector<unsigned char>> local_component_association(
217 fe_collection.size());
218 for (
unsigned int f = 0; f < fe_collection.size(); ++f)
221 local_component_association[f] =
226 std::vector<types::global_dof_index> indices;
228 if (c->is_locally_owned())
230 const unsigned int fe_index = c->active_fe_index();
231 const unsigned int dofs_per_cell = c->get_fe().n_dofs_per_cell();
232 indices.resize(dofs_per_cell);
233 c->get_dof_indices(indices);
234 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
237 indices[i])] = local_component_association[fe_index][i];
249 template <
int dim,
int spacedim>
252 std::vector<unsigned char> & dofs_by_block)
254 const ::hp::FECollection<dim, spacedim> &fe_collection =
268 std::vector<std::vector<unsigned char>> local_block_association(
269 fe_collection.size());
270 for (
unsigned int f = 0; f < fe_collection.size(); ++f)
274 static_cast<unsigned char>(-1));
278 Assert(std::find(local_block_association[f].
begin(),
279 local_block_association[f].
end(),
280 static_cast<unsigned char>(-1)) ==
281 local_block_association[f].
end(),
286 std::vector<types::global_dof_index> indices;
288 if (cell->is_locally_owned())
290 const unsigned int fe_index = cell->active_fe_index();
291 const unsigned int dofs_per_cell = cell->get_fe().n_dofs_per_cell();
292 indices.resize(dofs_per_cell);
293 cell->get_dof_indices(indices);
294 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
297 indices[i])] = local_block_association[fe_index][i];
304 template <
int dim,
int spacedim,
typename Number>
309 const unsigned int component)
318 for (
unsigned int i = 0; i < fe_collection.size(); ++i)
320 Assert(fe_collection[i].is_primitive() ==
true,
327 const bool consider_components =
331 if (consider_components ==
false)
335 std::vector<unsigned char> component_dofs(
342 for (
unsigned int i = 0; i < dof_data.
size(); ++i)
343 if (component_dofs[i] ==
static_cast<unsigned char>(component))
348 std::vector<unsigned char> touch_count(dof_handler.
n_dofs(), 0);
352 endc = dof_handler.
end();
353 std::vector<types::global_dof_index> dof_indices;
354 dof_indices.reserve(fe_collection.max_dofs_per_cell());
356 for (
unsigned int present_cell = 0; cell != endc; ++cell, ++present_cell)
359 dof_indices.resize(dofs_per_cell);
360 cell->get_dof_indices(dof_indices);
362 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
365 if (!consider_components ||
369 dof_data(dof_indices[i]) += cell_data(present_cell);
372 ++touch_count[dof_indices[i]];
382 Assert(consider_components || (touch_count[i] != 0),
384 if (touch_count[i] != 0)
385 dof_data(i) /= touch_count[i];
391 template <
int dim,
int spacedim>
395 std::vector<bool> & selected_dofs)
400 "The given component mask is not sized correctly to represent the "
401 "components of the given finite element."));
432 if (component_mask[dofs_by_component[i]] ==
true)
433 selected_dofs[i] =
true;
438 template <
int dim,
int spacedim>
446 "The given component mask is not sized correctly to represent the "
447 "components of the given finite element."));
465 std::vector<types::global_dof_index> selected_dofs;
468 if (component_mask[dofs_by_component[i]] ==
true)
473 result.
add_indices(selected_dofs.begin(), selected_dofs.end());
479 template <
int dim,
int spacedim>
483 std::vector<bool> & selected_dofs)
486 extract_dofs<dim, spacedim>(
492 template <
int dim,
int spacedim>
498 return extract_dofs<dim, spacedim>(
504 template <
int dim,
int spacedim>
505 std::vector<IndexSet>
512 "The given component mask is not sized correctly to represent the "
513 "components of the given finite element."));
522 std::vector<IndexSet> index_per_comp(n_comps,
IndexSet(dof.
n_dofs()));
526 const auto &comp_i = dofs_by_component[i];
527 if (component_mask[comp_i])
528 index_per_comp[comp_i].add_index(
529 locally_owned_dofs.nth_index_in_set(i));
531 for (
auto &c : index_per_comp)
533 return index_per_comp;
538 template <
int dim,
int spacedim>
543 std::vector<bool> & selected_dofs)
550 "The given component mask is not sized correctly to represent the "
551 "components of the given finite element."));
560 std::fill_n(selected_dofs.begin(), dof.
n_dofs(
level),
false);
567 std::fill_n(selected_dofs.begin(), dof.
n_dofs(
level),
true);
572 std::fill_n(selected_dofs.begin(), dof.
n_dofs(
level),
false);
576 std::vector<unsigned char> local_component_asssociation =
580 local_selected_dofs[i] = component_mask[local_component_asssociation[i]];
587 c->get_mg_dof_indices(indices);
589 selected_dofs[indices[i]] = local_selected_dofs[i];
595 template <
int dim,
int spacedim>
600 std::vector<bool> & selected_dofs)
611 template <
int dim,
int spacedim>
615 std::vector<bool> & selected_dofs,
616 const std::set<types::boundary_id> &boundary_ids)
622 "This function can not be used with distributed triangulations. "
623 "See the documentation for more information."));
629 selected_dofs.clear();
630 selected_dofs.resize(dof_handler.
n_dofs(),
false);
638 template <
int dim,
int spacedim>
643 const std::set<types::boundary_id> &boundary_ids)
652 template <
int dim,
int spacedim>
656 const std::set<types::boundary_id> &boundary_ids)
660 ExcMessage(
"Component mask has invalid size."));
669 const bool check_boundary_id = (boundary_ids.size() != 0);
673 const bool check_vector_component =
679 std::vector<types::global_dof_index> face_dof_indices;
680 face_dof_indices.reserve(
692 if (cell->is_artificial() ==
false)
693 for (
const unsigned int face : cell->face_indices())
694 if (cell->at_boundary(face))
695 if (!check_boundary_id ||
696 (boundary_ids.find(cell->face(face)->boundary_id()) !=
703 const unsigned int n_vertices_per_cell =
706 const unsigned int n_vertices_per_face =
708 const unsigned int n_lines_per_face =
712 face_dof_indices.resize(dofs_per_face);
713 cell->face(face)->get_dof_indices(face_dof_indices,
714 cell->active_fe_index());
717 if (!check_vector_component)
718 selected_dofs.
add_index(face_dof_indices[i]);
733 (dim == 3 ? (i < n_vertices_per_face *
736 (i < n_vertices_per_face *
740 (i - n_vertices_per_face *
742 n_vertices_per_cell *
745 n_vertices_per_face *
749 n_vertices_per_cell *
759 selected_dofs.
add_index(face_dof_indices[i]);
763 const unsigned int first_nonzero_comp =
769 if (component_mask[first_nonzero_comp] ==
true)
770 selected_dofs.
add_index(face_dof_indices[i]);
775 return selected_dofs;
780 template <
int dim,
int spacedim>
785 std::vector<bool> & selected_dofs,
786 const std::set<types::boundary_id> &boundary_ids)
790 ExcMessage(
"This component mask has the wrong size."));
797 const bool check_boundary_id = (boundary_ids.size() != 0);
801 const bool check_vector_component =
805 selected_dofs.clear();
806 selected_dofs.resize(dof_handler.
n_dofs(),
false);
807 std::vector<types::global_dof_index> cell_dof_indices;
808 cell_dof_indices.reserve(
818 for (
const unsigned int face : cell->face_indices())
819 if (cell->at_boundary(face))
820 if (!check_boundary_id ||
821 (boundary_ids.find(cell->face(face)->boundary_id()) !=
827 cell_dof_indices.resize(dofs_per_cell);
828 cell->get_dof_indices(cell_dof_indices);
833 if (!check_vector_component)
834 selected_dofs[cell_dof_indices[i]] =
true;
841 selected_dofs[cell_dof_indices[i]] =
846 const unsigned int first_nonzero_comp =
852 selected_dofs[cell_dof_indices[i]] =
853 (component_mask[first_nonzero_comp] ==
true);
862 template <
int dim,
int spacedim,
typename number>
871 const std::function<
bool(
876 ->
bool {
return cell->is_locally_owned() && predicate(cell); };
878 std::vector<types::global_dof_index> local_dof_indices;
879 local_dof_indices.reserve(
883 std::set<types::global_dof_index> predicate_dofs;
887 endc = dof_handler.
end();
888 for (; cell != endc; ++cell)
889 if (!cell->is_artificial() && predicate(cell))
892 cell->get_dof_indices(local_dof_indices);
893 predicate_dofs.insert(local_dof_indices.begin(),
894 local_dof_indices.end());
898 std::set<types::global_dof_index> dofs_with_support_on_halo_cells;
900 const std::vector<typename DoFHandler<dim, spacedim>::active_cell_iterator>
904 active_cell_iterator>::const_iterator it =
906 it != halo_cells.end();
918 const unsigned int dofs_per_cell = (*it)->get_fe().n_dofs_per_cell();
919 local_dof_indices.resize(dofs_per_cell);
920 (*it)->get_dof_indices(local_dof_indices);
921 dofs_with_support_on_halo_cells.insert(local_dof_indices.begin(),
922 local_dof_indices.end());
934 std::set<types::global_dof_index> extra_halo;
935 for (
const auto dof : dofs_with_support_on_halo_cells)
941 const unsigned int line_size = line_ptr->size();
942 for (
unsigned int j = 0; j < line_size; ++j)
943 extra_halo.insert((*line_ptr)[j].first);
946 dofs_with_support_on_halo_cells.insert(extra_halo.begin(),
953 support_set.
add_indices(predicate_dofs.begin(), predicate_dofs.end());
957 halo_set.
add_indices(dofs_with_support_on_halo_cells.begin(),
958 dofs_with_support_on_halo_cells.end());
973 template <
int spacedim>
976 const ::DoFHandler<1, spacedim> &dof_handler)
979 return IndexSet(dof_handler.n_dofs());
983 template <
int spacedim>
986 const ::DoFHandler<2, spacedim> &dof_handler)
988 const unsigned int dim = 2;
990 IndexSet selected_dofs(dof_handler.n_dofs());
996 for (
const auto &cell : dof_handler.active_cell_iterators())
997 if (!cell->is_artificial())
999 for (
const unsigned int face : cell->face_indices())
1000 if (cell->face(face)->has_children())
1002 const typename ::DoFHandler<dim,
1003 spacedim>::line_iterator
1004 line = cell->face(face);
1008 selected_dofs.add_index(
1009 line->child(0)->vertex_dof_index(1, dof));
1011 for (
unsigned int child = 0; child < 2; ++child)
1013 if (cell->neighbor_child_on_subface(face, child)
1018 selected_dofs.add_index(
1019 line->child(child)->dof_index(dof));
1024 selected_dofs.compress();
1025 return selected_dofs;
1029 template <
int spacedim>
1032 const ::DoFHandler<3, spacedim> &dof_handler)
1034 const unsigned int dim = 3;
1036 IndexSet selected_dofs(dof_handler.n_dofs());
1037 IndexSet unconstrained_dofs(dof_handler.n_dofs());
1041 for (
const auto &cell : dof_handler.active_cell_iterators())
1042 if (!cell->is_artificial())
1043 for (
auto f : cell->face_indices())
1045 const typename ::DoFHandler<dim, spacedim>::face_iterator
1046 face = cell->face(f);
1047 if (cell->face(f)->has_children())
1049 for (
unsigned int child = 0; child < 4; ++child)
1050 if (!cell->neighbor_child_on_subface(f, child)
1054 std::vector<types::global_dof_index> ldi(
1056 face->child(child)->get_dof_indices(ldi);
1057 selected_dofs.add_indices(ldi.begin(), ldi.end());
1062 for (
unsigned int vertex = 0; vertex < 4; ++vertex)
1065 unconstrained_dofs.add_index(
1066 face->vertex_dof_index(vertex, dof));
1069 selected_dofs.subtract_set(unconstrained_dofs);
1070 return selected_dofs;
1077 template <
int dim,
int spacedim>
1080 std::vector<bool> & selected_dofs)
1082 const IndexSet selected_dofs_as_index_set =
1087 std::fill(selected_dofs.begin(), selected_dofs.end(),
false);
1088 for (
const auto index : selected_dofs_as_index_set)
1089 selected_dofs[index] =
true;
1094 template <
int dim,
int spacedim>
1103 template <
int dim,
int spacedim>
1107 std::vector<bool> & selected_dofs)
1113 std::fill_n(selected_dofs.begin(), dof_handler.
n_dofs(),
false);
1115 std::vector<types::global_dof_index> local_dof_indices;
1116 local_dof_indices.reserve(
1123 endc = dof_handler.
end();
1124 for (; cell != endc; ++cell)
1128 local_dof_indices.resize(dofs_per_cell);
1129 cell->get_dof_indices(local_dof_indices);
1130 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
1131 selected_dofs[local_dof_indices[i]] =
true;
1137 template <
int dim,
int spacedim>
1148 std::vector<types::global_dof_index> dof_indices;
1149 std::set<types::global_dof_index> global_dof_indices;
1153 endc = dof_handler.
end();
1154 for (; cell != endc; ++cell)
1155 if (cell->is_locally_owned())
1158 cell->get_dof_indices(dof_indices);
1162 global_dof_indices.insert(dof_index);
1165 dof_set.
add_indices(global_dof_indices.begin(), global_dof_indices.end());
1172 template <
int dim,
int spacedim>
1177 const unsigned int level)
1185 std::vector<types::global_dof_index> dof_indices;
1186 std::set<types::global_dof_index> global_dof_indices;
1188 const auto filtered_iterators_range =
1191 for (
const auto &cell : filtered_iterators_range)
1193 dof_indices.resize(cell->get_fe().n_dofs_per_cell());
1194 cell->get_mg_dof_indices(dof_indices);
1198 global_dof_indices.insert(dof_index);
1201 dof_set.
add_indices(global_dof_indices.begin(), global_dof_indices.end());
1208 template <
int dim,
int spacedim>
1224 std::vector<types::global_dof_index> dof_indices;
1225 std::vector<types::global_dof_index> dofs_on_ghosts;
1229 endc = dof_handler.
end();
1230 for (; cell != endc; ++cell)
1231 if (cell->is_ghost())
1234 cell->get_dof_indices(dof_indices);
1235 for (
const auto dof_index : dof_indices)
1237 dofs_on_ghosts.push_back(dof_index);
1241 std::sort(dofs_on_ghosts.begin(), dofs_on_ghosts.end());
1243 std::unique(dofs_on_ghosts.begin(),
1244 dofs_on_ghosts.end()));
1250 template <
int dim,
int spacedim>
1254 const unsigned int level,
1268 std::vector<types::global_dof_index> dof_indices;
1269 std::vector<types::global_dof_index> dofs_on_ghosts;
1275 for (; cell != endc; ++cell)
1285 cell->get_mg_dof_indices(dof_indices);
1286 for (
const auto dof_index : dof_indices)
1288 dofs_on_ghosts.push_back(dof_index);
1292 std::sort(dofs_on_ghosts.begin(), dofs_on_ghosts.end());
1294 std::unique(dofs_on_ghosts.begin(),
1295 dofs_on_ghosts.end()));
1302 template <
int dim,
int spacedim>
1306 std::vector<std::vector<bool>> & constant_modes)
1312 constant_modes = std::vector<std::vector<bool>>(0);
1320 std::vector<unsigned char> dofs_by_component(
1325 unsigned int n_selected_dofs = 0;
1326 for (
unsigned int i = 0; i < n_components; ++i)
1327 if (component_mask[i] ==
true)
1329 std::count(dofs_by_component.begin(), dofs_by_component.end(), i);
1333 std::vector<unsigned int> component_numbering(
1335 for (
unsigned int i = 0, count = 0; i < locally_owned_dofs.
n_elements();
1337 if (component_mask[dofs_by_component[i]])
1338 component_numbering[i] = count++;
1345 const ::hp::FECollection<dim, spacedim> &fe_collection =
1347 std::vector<Table<2, bool>> element_constant_modes;
1348 std::vector<std::vector<std::pair<unsigned int, unsigned int>>>
1349 constant_mode_to_component_translation(n_components);
1350 unsigned int n_constant_modes = 0;
1351 for (
unsigned int f = 0; f < fe_collection.size(); ++f)
1353 std::pair<Table<2, bool>, std::vector<unsigned int>> data =
1354 fe_collection[f].get_constant_modes();
1355 element_constant_modes.push_back(data.first);
1357 for (
unsigned int i = 0; i < data.second.size(); ++i)
1358 if (component_mask[data.second[i]])
1359 constant_mode_to_component_translation[data.second[i]]
1360 .emplace_back(n_constant_modes++, i);
1362 element_constant_modes[0].n_rows());
1366 constant_modes.clear();
1367 constant_modes.resize(n_constant_modes,
1368 std::vector<bool>(n_selected_dofs,
false));
1371 std::vector<types::global_dof_index> dof_indices;
1373 if (cell->is_locally_owned())
1375 dof_indices.resize(cell->get_fe().n_dofs_per_cell());
1376 cell->get_dof_indices(dof_indices);
1378 for (
unsigned int i = 0; i < dof_indices.size(); ++i)
1379 if (locally_owned_dofs.
is_element(dof_indices[i]))
1381 const unsigned int loc_index =
1383 const unsigned int comp = dofs_by_component[loc_index];
1384 if (component_mask[comp])
1385 for (
auto &indices :
1386 constant_mode_to_component_translation[comp])
1387 constant_modes[indices
1388 .first][component_numbering[loc_index]] =
1389 element_constant_modes[cell->active_fe_index()](
1397 template <
int dim,
int spacedim>
1400 std::vector<unsigned int> & active_fe_indices)
1407 endc = dof_handler.
end();
1408 for (; cell != endc; ++cell)
1409 active_fe_indices[cell->active_cell_index()] = cell->active_fe_index();
1412 template <
int dim,
int spacedim>
1413 std::vector<IndexSet>
1417 ExcMessage(
"The given DoFHandler has no DoFs."));
1425 "For parallel::distributed::Triangulation objects and "
1426 "associated DoF handler objects, asking for any information "
1427 "related to a subdomain other than the locally owned one does "
1428 "not make sense."));
1432 std::vector<::types::subdomain_id> subdomain_association(
1435 subdomain_association);
1449 const unsigned int n_subdomains =
1453 unsigned int max_subdomain_id = 0;
1456 std::max(max_subdomain_id, cell->subdomain_id());
1457 return max_subdomain_id + 1;
1462 ->get_communicator()));
1463 Assert(n_subdomains > *std::max_element(subdomain_association.begin(),
1464 subdomain_association.end()),
1467 std::vector<::IndexSet> index_sets(
1476 index < subdomain_association.size();
1480 if (subdomain_association[index] != this_subdomain)
1482 index_sets[this_subdomain].add_range(i_min, index);
1484 this_subdomain = subdomain_association[index];
1489 if (i_min == subdomain_association.size() - 1)
1491 index_sets[this_subdomain].add_index(i_min);
1497 index_sets[this_subdomain].add_range(i_min,
1498 subdomain_association.size());
1501 for (
unsigned int i = 0; i < n_subdomains; i++)
1507 template <
int dim,
int spacedim>
1508 std::vector<IndexSet>
1518 "For parallel::distributed::Triangulation objects and "
1519 "associated DoF handler objects, asking for any information "
1520 "related to a subdomain other than the locally owned one does "
1521 "not make sense."));
1529 std::vector<IndexSet> dof_set =
1550 std::vector<types::global_dof_index> local_dof_indices;
1551 std::set<types::global_dof_index> subdomain_halo_global_dof_indices;
1552 for (
typename std::vector<
1554 const_iterator it_cell = active_halo_layer.
begin();
1555 it_cell != active_halo_layer.end();
1563 "The subdomain ID of the halo cell should not match that of the vector entry."));
1566 cell->get_dof_indices(local_dof_indices);
1570 subdomain_halo_global_dof_indices.insert(local_dof_index);
1574 subdomain_halo_global_dof_indices.begin(),
1575 subdomain_halo_global_dof_indices.end());
1583 template <
int dim,
int spacedim>
1587 std::vector<types::subdomain_id> &subdomain_association)
1595 "For parallel::distributed::Triangulation objects and "
1596 "associated DoF handler objects, asking for any subdomain other "
1597 "than the locally owned one does not make sense."));
1599 Assert(subdomain_association.size() == dof_handler.
n_dofs(),
1613 std::vector<types::subdomain_id> cell_owners(
1619 cell_owners = tr->get_true_subdomain_ids_of_cells();
1620 Assert(tr->get_true_subdomain_ids_of_cells().size() ==
1621 tr->n_active_cells(),
1628 cell != dof_handler.
end();
1630 if (cell->is_locally_owned())
1631 cell_owners[cell->active_cell_index()] = cell->subdomain_id();
1635 std::fill_n(subdomain_association.begin(),
1639 std::vector<types::global_dof_index> local_dof_indices;
1640 local_dof_indices.reserve(
1647 endc = dof_handler.
end();
1648 for (; cell != endc; ++cell)
1651 cell_owners[cell->active_cell_index()];
1653 local_dof_indices.resize(dofs_per_cell);
1654 cell->get_dof_indices(local_dof_indices);
1660 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
1661 if (subdomain_association[local_dof_indices[i]] ==
1663 subdomain_association[local_dof_indices[i]] =
subdomain_id;
1664 else if (subdomain_association[local_dof_indices[i]] >
subdomain_id)
1666 subdomain_association[local_dof_indices[i]] =
subdomain_id;
1670 Assert(std::find(subdomain_association.begin(),
1671 subdomain_association.end(),
1673 subdomain_association.end(),
1679 template <
int dim,
int spacedim>
1685 std::vector<types::subdomain_id> subdomain_association(
1689 return std::count(subdomain_association.begin(),
1690 subdomain_association.end(),
1696 template <
int dim,
int spacedim>
1709 "For parallel::distributed::Triangulation objects and "
1710 "associated DoF handler objects, asking for any subdomain other "
1711 "than the locally owned one does not make sense."));
1715 std::vector<types::global_dof_index> local_dof_indices;
1716 local_dof_indices.reserve(
1724 std::vector<types::global_dof_index> subdomain_indices;
1728 endc = dof_handler.
end();
1729 for (; cell != endc; ++cell)
1730 if ((cell->is_artificial() ==
false) &&
1731 (cell->subdomain_id() == subdomain))
1734 local_dof_indices.resize(dofs_per_cell);
1735 cell->get_dof_indices(local_dof_indices);
1736 subdomain_indices.insert(subdomain_indices.end(),
1737 local_dof_indices.begin(),
1738 local_dof_indices.end());
1741 std::sort(subdomain_indices.begin(), subdomain_indices.end());
1742 subdomain_indices.erase(std::unique(subdomain_indices.begin(),
1743 subdomain_indices.end()),
1744 subdomain_indices.end());
1747 index_set.
add_indices(subdomain_indices.begin(), subdomain_indices.end());
1755 template <
int dim,
int spacedim>
1760 std::vector<unsigned int> & n_dofs_on_subdomain)
1765 std::fill(n_dofs_on_subdomain.begin(), n_dofs_on_subdomain.end(), 0);
1774 return cell.subdomain_id() == subdomain;
1776 ExcMessage(
"There are no cells for the given subdomain!"));
1778 std::vector<types::subdomain_id> subdomain_association(
1782 std::vector<unsigned char> component_association(dof_handler.
n_dofs());
1784 std::vector<bool>(),
1785 component_association);
1787 for (
unsigned int c = 0; c < dof_handler.
get_fe(0).n_components(); ++c)
1790 if ((subdomain_association[i] == subdomain) &&
1791 (component_association[i] ==
static_cast<unsigned char>(c)))
1792 ++n_dofs_on_subdomain[c];
1804 template <
int dim,
int spacedim>
1807 const std::vector<unsigned char> & dofs_by_component,
1808 const std::vector<unsigned int> & target_component,
1809 const bool only_once,
1810 std::vector<types::global_dof_index> &dofs_per_component,
1811 unsigned int & component)
1830 for (
unsigned int dd = 0; dd <
d; ++dd, ++component)
1831 dofs_per_component[target_component[component]] +=
1832 std::count(dofs_by_component.begin(),
1833 dofs_by_component.end(),
1840 for (
unsigned int dd = 1; dd <
d; ++dd)
1841 dofs_per_component[target_component[component -
d + dd]] =
1842 dofs_per_component[target_component[component -
d]];
1849 template <
int dim,
int spacedim>
1852 const std::vector<unsigned char> & dofs_by_component,
1853 const std::vector<unsigned int> & target_component,
1854 const bool only_once,
1855 std::vector<types::global_dof_index> &dofs_per_component,
1856 unsigned int & component)
1861 for (
unsigned int fe = 1; fe < fe_collection.
size(); ++fe)
1863 Assert(fe_collection[fe].n_components() ==
1864 fe_collection[0].n_components(),
1866 Assert(fe_collection[fe].n_base_elements() ==
1867 fe_collection[0].n_base_elements(),
1869 for (
unsigned int b = 0;
b < fe_collection[0].n_base_elements(); ++
b)
1871 Assert(fe_collection[fe].base_element(
b).n_components() ==
1872 fe_collection[0].base_element(
b).n_components(),
1874 Assert(fe_collection[fe].base_element(
b).n_base_elements() ==
1875 fe_collection[0].base_element(
b).n_base_elements(),
1898 template <
int dim,
int spacedim>
1910 template <
int dim,
int spacedim>
1912 all_elements_are_primitive(
1913 const ::hp::FECollection<dim, spacedim> &fe_collection)
1915 for (
unsigned int i = 0; i < fe_collection.size(); ++i)
1916 if (fe_collection[i].is_primitive() ==
false)
1927 template <
int dim,
int spacedim>
1931 std::vector<types::global_dof_index> &dofs_per_component,
1932 const bool only_once,
1933 const std::vector<unsigned int> & target_component)
1935 dofs_per_component =
1941 template <
int dim,
int spacedim>
1942 std::vector<types::global_dof_index>
1945 const bool only_once,
1946 const std::vector<unsigned int> &target_component_)
1952 std::vector<unsigned int> target_component = target_component_;
1953 if (target_component.size() == 0)
1955 target_component.resize(n_components);
1956 for (
unsigned int i = 0; i < n_components; ++i)
1957 target_component[i] = i;
1960 Assert(target_component.size() == n_components,
1964 const unsigned int max_component =
1965 *std::max_element(target_component.begin(), target_component.end());
1966 const unsigned int n_target_components = max_component + 1;
1968 std::vector<types::global_dof_index> dofs_per_component(
1973 if (n_components == 1)
1976 return dofs_per_component;
1982 std::vector<unsigned char> dofs_by_component(
1989 unsigned int component = 0;
2000 Assert((internal::all_elements_are_primitive(
2002 (std::accumulate(dofs_per_component.begin(),
2003 dofs_per_component.end(),
2009#ifdef DEAL_II_WITH_MPI
2015 std::vector<types::global_dof_index> local_dof_count =
2018 const int ierr = MPI_Allreduce(local_dof_count.data(),
2019 dofs_per_component.data(),
2020 n_target_components,
2023 tria->get_communicator());
2028 return dofs_per_component;
2034 template <
int dim,
int spacedim>
2037 std::vector<types::global_dof_index> &dofs_per_block,
2038 const std::vector<unsigned int> & target_block)
2045 template <
int dim,
int spacedim>
2046 std::vector<types::global_dof_index>
2048 const std::vector<unsigned int> &target_block_)
2050 const ::hp::FECollection<dim, spacedim> &fe_collection =
2059 const unsigned int n_blocks = fe_collection[0].n_blocks();
2061 std::vector<unsigned int> target_block = target_block_;
2062 if (target_block.size() == 0)
2064 target_block.resize(fe_collection[0].
n_blocks());
2065 for (
unsigned int i = 0; i <
n_blocks; ++i)
2066 target_block[i] = i;
2071 for (
unsigned int f = 1; f < fe_collection.size(); ++f)
2073 ExcMessage(
"This function can only work if all elements in a "
2074 "collection have the same number of blocks."));
2080 std::vector<types::global_dof_index> dofs_per_block(1);
2081 dofs_per_block[0] = dof_handler.
n_dofs();
2082 return dofs_per_block;
2086 const unsigned int max_block =
2087 *std::max_element(target_block.begin(), target_block.end());
2088 const unsigned int n_target_blocks = max_block + 1;
2090 std::vector<types::global_dof_index> dofs_per_block(n_target_blocks);
2094 for (
unsigned int this_fe = fe_collection.size() - 1;
2095 this_fe < fe_collection.size();
2100 std::vector<unsigned char> dofs_by_block(
2105 for (
unsigned int block = 0; block < fe.
n_blocks(); ++block)
2106 dofs_per_block[target_block[block]] +=
2107 std::count(dofs_by_block.begin(), dofs_by_block.end(), block);
2109#ifdef DEAL_II_WITH_MPI
2116 std::vector<types::global_dof_index> local_dof_count =
2118 const int ierr = MPI_Allreduce(local_dof_count.data(),
2119 dofs_per_block.data(),
2123 tria->get_communicator());
2129 return dofs_per_block;
2134 template <
int dim,
int spacedim>
2137 std::vector<types::global_dof_index> &mapping)
2140 mapping.insert(mapping.end(),
2144 std::vector<types::global_dof_index> dofs_on_face;
2156 endc = dof_handler.
end();
2157 for (; cell != endc; ++cell)
2158 for (
const unsigned int f : cell->face_indices())
2159 if (cell->at_boundary(f))
2161 const unsigned int dofs_per_face =
2163 dofs_on_face.resize(dofs_per_face);
2164 cell->face(f)->get_dof_indices(dofs_on_face,
2165 cell->active_fe_index());
2166 for (
unsigned int i = 0; i < dofs_per_face; ++i)
2168 mapping[dofs_on_face[i]] = next_boundary_index++;
2176 template <
int dim,
int spacedim>
2179 const std::set<types::boundary_id> &boundary_ids,
2180 std::vector<types::global_dof_index> &mapping)
2187 mapping.insert(mapping.end(),
2192 if (boundary_ids.size() == 0)
2195 std::vector<types::global_dof_index> dofs_on_face;
2201 endc = dof_handler.
end();
2202 for (; cell != endc; ++cell)
2203 for (
const unsigned int f : cell->face_indices())
2204 if (boundary_ids.find(cell->face(f)->boundary_id()) !=
2207 const unsigned int dofs_per_face =
2209 dofs_on_face.resize(dofs_per_face);
2210 cell->face(f)->get_dof_indices(dofs_on_face,
2211 cell->active_fe_index());
2212 for (
unsigned int i = 0; i < dofs_per_face; ++i)
2214 mapping[dofs_on_face[i]] = next_boundary_index++;
2225 template <
int dim,
int spacedim>
2237 for (
unsigned int fe_index = 0; fe_index < fe_collection.
size();
2241 Assert(fe_collection[fe_index].has_support_points(),
2244 fe_collection[fe_index].get_unit_support_points()));
2249 (in_mask.
size() == 0 ?
2266 endc = dof_handler.
end();
2268 std::vector<types::global_dof_index> local_dof_indices;
2269 for (; cell != endc; ++cell)
2271 if (cell->is_artificial() ==
false)
2273 hp_fe_values.reinit(cell);
2278 cell->get_dof_indices(local_dof_indices);
2280 const std::vector<Point<spacedim>> &points =
2282 for (
unsigned int i = 0; i < cell->
get_fe().n_dofs_per_cell();
2285 const unsigned int dof_comp =
2290 support_points[local_dof_indices[i]] = points[i];
2296 template <
int dim,
int spacedim>
2305 std::map<types::global_dof_index, Point<spacedim>> x_support_points;
2315 Assert(x_support_points.find(i) != x_support_points.end(),
2318 support_points[i] = x_support_points[i];
2324 template <
int dim,
int spacedim>
2336 "This function can not be used with distributed triangulations. "
2337 "See the documentation for more information."));
2350 template <
int dim,
int spacedim>
2363 "This function can not be used with distributed triangulations. "
2364 "See the documentation for more information."));
2375 template <
int dim,
int spacedim>
2383 support_points.clear();
2396 template <
int dim,
int spacedim>
2404 support_points.clear();
2414 template <
int spacedim>
2422 using dof_map_t = std::map<types::global_dof_index, Point<spacedim>>;
2424 using point_map_t = std::map<Point<spacedim>,
2425 std::vector<types::global_dof_index>,
2428 point_map_t point_map;
2431 for (
typename dof_map_t::const_iterator it = support_points.begin();
2432 it != support_points.end();
2435 std::vector<types::global_dof_index> &v = point_map[it->second];
2436 v.push_back(it->first);
2440 for (
typename point_map_t::iterator it = point_map.begin();
2441 it != point_map.end();
2444 out << it->first <<
" \"";
2445 const std::vector<types::global_dof_index> &v = it->second;
2446 for (
unsigned int i = 0; i < v.size(); ++i)
2460 template <
int dim,
int spacedim>
2469 const unsigned int nb = fe.
n_blocks();
2471 tables_by_block.resize(1);
2472 tables_by_block[0].reinit(nb, nb);
2473 tables_by_block[0].fill(
none);
2481 tables_by_block[0](ib, jb) |= table(i, j);
2489 tables_by_block.resize(fe_collection.
size());
2491 for (
unsigned int f = 0; f < fe_collection.
size(); ++f)
2495 const unsigned int nb = fe.
n_blocks();
2496 tables_by_block[f].reinit(nb, nb);
2497 tables_by_block[f].fill(
none);
2504 tables_by_block[f](ib, jb) |= table(i, j);
2513 template <
int dim,
int spacedim>
2517 const unsigned int level,
2518 const std::vector<bool> & selected_dofs,
2524 std::vector<types::global_dof_index> indices;
2528 for (cell = dof_handler.
begin(
level); cell != endc; ++cell)
2529 if (cell->is_locally_owned_on_level())
2535 for (cell = dof_handler.
begin(
level); cell != endc; ++cell)
2536 if (cell->is_locally_owned_on_level())
2539 cell->get_mg_dof_indices(indices);
2541 if (selected_dofs.size() != 0)
2546 if (selected_dofs.size() == 0)
2547 block_list.
add(i, indices[j] - offset);
2550 if (selected_dofs[j])
2551 block_list.
add(i, indices[j] - offset);
2559 template <
int dim,
int spacedim>
2563 const unsigned int level,
2564 const bool interior_only)
2572 std::vector<types::global_dof_index> indices;
2573 std::vector<bool> exclude;
2575 for (cell = dof_handler.
begin(
level); cell != endc; ++cell)
2578 cell->get_mg_dof_indices(indices);
2584 std::fill(exclude.begin(), exclude.end(),
false);
2586 for (
const unsigned int face : cell->face_indices())
2587 if (cell->at_boundary(face) ||
2588 cell->neighbor(face)->level() != cell->level())
2593 block_list.
add(0, indices[j]);
2597 for (
const auto index : indices)
2598 block_list.
add(0, index);
2604 template <
int dim,
int spacedim>
2608 const unsigned int level,
2609 const bool interior_dofs_only,
2610 const bool boundary_dofs)
2620 std::vector<types::global_dof_index> indices;
2621 std::vector<bool> exclude;
2623 for (
unsigned int block = 0; pcell != endc; ++pcell)
2625 if (pcell->is_active())
2628 for (
unsigned int child = 0; child < pcell->n_children(); ++child)
2631 pcell->child(child);
2636 indices.resize(n_dofs);
2637 exclude.resize(n_dofs);
2638 std::fill(exclude.begin(), exclude.end(),
false);
2639 cell->get_mg_dof_indices(indices);
2641 if (interior_dofs_only)
2645 for (
unsigned int d = 0;
d < dim; ++
d)
2647 const unsigned int face =
2656 for (
const unsigned int face :
2658 if (cell->at_boundary(face))
2664 for (
unsigned int i = 0; i < n_dofs; ++i)
2666 block_list.
add(block, indices[i]);
2672 template <
int dim,
int spacedim>
2673 std::vector<unsigned int>
2676 const unsigned int level,
2677 const bool interior_only,
2678 const bool boundary_patches,
2679 const bool level_boundary_patches,
2680 const bool single_cell_patches,
2681 const bool invert_vertex_mapping)
2688 exclude_boundary_dofs,
2690 level_boundary_patches,
2691 single_cell_patches,
2692 invert_vertex_mapping);
2695 template <
int dim,
int spacedim>
2696 std::vector<unsigned int>
2699 const unsigned int level,
2700 const BlockMask & exclude_boundary_dofs,
2701 const bool boundary_patches,
2702 const bool level_boundary_patches,
2703 const bool single_cell_patches,
2704 const bool invert_vertex_mapping)
2712 std::vector<unsigned int> vertex_cell_count(
2716 std::vector<bool> vertex_boundary(
2719 std::vector<unsigned int> vertex_mapping(
2724 std::vector<unsigned int> vertex_dof_count(
2729 for (cell = dof_handler.
begin(
level); cell != endc; ++cell)
2730 for (
const unsigned int v : cell->vertex_indices())
2732 const unsigned int vg = cell->vertex_index(v);
2734 ++vertex_cell_count[vg];
2735 for (
unsigned int d = 0;
d < dim; ++
d)
2738 if (cell->at_boundary(face))
2739 vertex_boundary[vg] =
true;
2740 else if ((!level_boundary_patches) &&
2741 (cell->neighbor(face)->level() !=
2742 static_cast<int>(
level)))
2743 vertex_boundary[vg] =
true;
2749 for (
unsigned int vg = 0; vg < vertex_dof_count.size(); ++vg)
2750 if ((!single_cell_patches && vertex_cell_count[vg] < 2) ||
2751 (!boundary_patches && vertex_boundary[vg]))
2752 vertex_dof_count[vg] = 0;
2755 unsigned int n_vertex_count = 0;
2756 for (
unsigned int vg = 0; vg < vertex_mapping.size(); ++vg)
2757 if (vertex_dof_count[vg] != 0)
2758 vertex_mapping[vg] = n_vertex_count++;
2761 for (
unsigned int vg = 0; vg < vertex_mapping.size(); ++vg)
2762 if (vertex_dof_count[vg] != 0)
2763 vertex_dof_count[vertex_mapping[vg]] = vertex_dof_count[vg];
2767 vertex_dof_count.resize(n_vertex_count);
2771 block_list.
reinit(vertex_dof_count.size(),
2775 std::vector<types::global_dof_index> indices;
2776 std::vector<bool> exclude;
2778 for (cell = dof_handler.
begin(
level); cell != endc; ++cell)
2782 cell->get_mg_dof_indices(indices);
2784 for (
const unsigned int v : cell->vertex_indices())
2786 const unsigned int vg = cell->vertex_index(v);
2787 const unsigned int block = vertex_mapping[vg];
2793 if (exclude_boundary_dofs.
size() == 0 ||
2799 std::fill(exclude.begin(), exclude.end(),
false);
2801 for (
unsigned int d = 0;
d < dim; ++
d)
2803 const unsigned int a_face =
2805 const unsigned int face =
2818 for (
unsigned int j = 0; j < indices.size(); ++j)
2820 block_list.
add(block, indices[j]);
2824 for (
const auto index : indices)
2825 block_list.
add(block, index);
2830 if (invert_vertex_mapping)
2833 unsigned int n_vertex_count = 0;
2834 for (
unsigned int vg = 0; vg < vertex_mapping.size(); ++vg)
2836 vertex_mapping[n_vertex_count++] = vg;
2839 vertex_mapping.resize(n_vertex_count);
2842 return vertex_mapping;
2846 template <
int dim,
int spacedim>
2852 std::set<types::global_dof_index> dofs_on_patch;
2853 std::vector<types::global_dof_index> local_dof_indices;
2858 for (
unsigned int i = 0; i < patch.size(); ++i)
2862 Assert(cell->is_artificial() ==
false,
2863 ExcMessage(
"This function can not be called with cells that are "
2864 "not either locally owned or ghost cells."));
2866 cell->get_dof_indices(local_dof_indices);
2867 dofs_on_patch.insert(local_dof_indices.begin(),
2868 local_dof_indices.end());
2872 return dofs_on_patch.size();
2877 template <
int dim,
int spacedim>
2878 std::vector<types::global_dof_index>
2883 std::set<types::global_dof_index> dofs_on_patch;
2884 std::vector<types::global_dof_index> local_dof_indices;
2889 for (
unsigned int i = 0; i < patch.size(); ++i)
2893 Assert(cell->is_artificial() ==
false,
2894 ExcMessage(
"This function can not be called with cells that are "
2895 "not either locally owned or ghost cells."));
2897 cell->get_dof_indices(local_dof_indices);
2898 dofs_on_patch.insert(local_dof_indices.begin(),
2899 local_dof_indices.end());
2902 Assert((dofs_on_patch.size() == count_dofs_on_patch<dim, spacedim>(patch)),
2909 return std::vector<types::global_dof_index>(dofs_on_patch.begin(),
2910 dofs_on_patch.end());
2920#include "dof_tools.inst"
const std::vector< std::pair< size_type, number > > * get_constraint_entries(const size_type line_n) const
size_type n_constraints() const
unsigned int size() const
unsigned int n_selected_blocks(const unsigned int overall_number_of_blocks=numbers::invalid_unsigned_int) const
bool represents_n_components(const unsigned int n) const
bool represents_the_all_selected_mask() const
unsigned int size() const
unsigned int n_selected_components(const unsigned int overall_number_of_components=numbers::invalid_unsigned_int) const
unsigned int first_selected_component(const unsigned int overall_number_of_components=numbers::invalid_unsigned_int) const
cell_iterator end() const
const FiniteElement< dim, spacedim > & get_fe(const unsigned int index=0) const
const hp::FECollection< dim, spacedim > & get_fe_collection() const
const IndexSet & locally_owned_mg_dofs(const unsigned int level) const
types::global_dof_index n_boundary_dofs() const
const Triangulation< dim, spacedim > & get_triangulation() const
const IndexSet & locally_owned_dofs() const
active_cell_iterator begin_active(const unsigned int level=0) const
bool has_hp_capabilities() const
types::global_dof_index n_dofs() const
cell_iterator begin(const unsigned int level=0) const
types::global_dof_index n_locally_owned_dofs() const
const std::vector< Point< spacedim > > & get_quadrature_points() const
const FEValues< dim, spacedim > & get_present_fe_values() const
unsigned int n_dofs_per_vertex() const
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_blocks() const
unsigned int n_components() const
std::pair< unsigned int, types::global_dof_index > system_to_block_index(const unsigned int component) const
const ComponentMask & get_nonzero_components(const unsigned int i) const
virtual const FiniteElement< dim, spacedim > & base_element(const unsigned int index) const
ComponentMask component_mask(const FEValuesExtractors::Scalar &scalar) const
bool is_primitive() const
virtual bool has_support_on_face(const unsigned int shape_index, const unsigned int face_index) const
virtual unsigned int face_to_cell_index(const unsigned int face_dof_index, const unsigned int face, const bool face_orientation=true, const bool face_flip=false, const bool face_rotation=false) const
unsigned int component_to_block_index(const unsigned int component) const
std::pair< unsigned int, unsigned int > system_to_component_index(const unsigned int index) const
unsigned int element_multiplicity(const unsigned int index) const
unsigned int n_base_elements() const
std::pair< unsigned int, unsigned int > face_system_to_component_index(const unsigned int index, const unsigned int face_no=0) const
size_type index_within_set(const size_type global_index) const
size_type n_elements() const
bool is_element(const size_type index) const
void add_index(const size_type index)
void fill_binary_vector(VectorType &vector) const
void subtract_set(const IndexSet &other)
size_type nth_index_in_set(const size_type local_index) const
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
virtual types::subdomain_id locally_owned_subdomain() const
unsigned int n_active_cells() const
unsigned int n_levels() const
unsigned int n_vertices() const
unsigned int size() const
unsigned int max_dofs_per_face() const
ComponentMask component_mask(const FEValuesExtractors::Scalar &scalar) const
unsigned int n_components() const
unsigned int max_dofs_per_cell() const
void push_back(const Quadrature< dim_in > &new_quadrature)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
@ update_quadrature_points
Transformed quadrature points.
IteratorRange< active_cell_iterator > active_cell_iterators() const
IteratorRange< FilteredIterator< BaseIterator > > filter_iterators(IteratorRange< BaseIterator > i, const Predicate &p)
IteratorRange< cell_iterator > cell_iterators_on_level(const unsigned int level) const
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcInvalidBoundaryIndicator()
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
virtual void reinit(const size_type m, const size_type n, const ArrayView< const unsigned int > &row_lengths) override
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
void add(const size_type i, const size_type j)
void reference_cell(Triangulation< dim, spacedim > &tria, const ReferenceCell &reference_cell)
std::enable_if< IsBlockVector< VectorType >::value, unsignedint >::type n_blocks(const VectorType &vector)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
std::string compress(const std::string &input)
const types::boundary_id internal_face_boundary_id
const types::subdomain_id artificial_subdomain_id
const types::subdomain_id invalid_subdomain_id
static const unsigned int invalid_unsigned_int
const types::global_dof_index invalid_dof_index
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
unsigned int subdomain_id
#define DEAL_II_DOF_INDEX_MPI_TYPE