19 #include <deal.II/base/geometry_info.h> 20 #include <deal.II/base/utilities.h> 21 #include <deal.II/base/memory_consumption.h> 22 #include <deal.II/grid/tria.h> 23 #include <deal.II/grid/tria_iterator.h> 24 #include <deal.II/dofs/dof_handler.h> 25 #include <deal.II/dofs/dof_accessor.h> 26 #include <deal.II/dofs/dof_handler_policy.h> 27 #include <deal.II/fe/fe.h> 28 #include <deal.II/distributed/shared_tria.h> 29 #include <deal.II/distributed/tria.h> 35 DEAL_II_NAMESPACE_OPEN
65 template <
int spacedim>
74 if (dof_handler.
get_fe().dofs_per_vertex > 0)
75 for (
unsigned int v=0; v<GeometryInfo<1>::vertices_per_cell; ++v)
77 if (cell->vertex_dof_index (v,0) ==
79 for (
unsigned int d=0;
80 d<dof_handler.
get_fe().dofs_per_vertex; ++d)
82 Assert ((cell->vertex_dof_index (v,d) ==
85 cell->set_vertex_dof_index (v, d, next_free_dof++);
88 for (
unsigned int d=0;
89 d<dof_handler.
get_fe().dofs_per_vertex; ++d)
90 Assert ((cell->vertex_dof_index (v,d) !=
96 for (
unsigned int d=0;
97 d<dof_handler.
get_fe().dofs_per_line; ++d)
98 cell->set_dof_index (d, next_free_dof++);
102 cell->set_user_flag ();
104 return next_free_dof;
109 template <
int spacedim>
116 if (dof_handler.
get_fe().dofs_per_vertex > 0)
118 for (
unsigned int vertex=0; vertex<GeometryInfo<2>::vertices_per_cell; ++vertex)
123 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_vertex; ++d)
124 cell->set_vertex_dof_index (vertex, d, next_free_dof++);
127 if (dof_handler.
get_fe().dofs_per_line > 0)
128 for (
unsigned int side=0; side<GeometryInfo<2>::faces_per_cell; ++side)
130 const typename DoFHandler<2,spacedim>::line_iterator
131 line = cell->line(side);
138 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_line; ++d)
139 line->set_dof_index (d, next_free_dof++);
144 if (dof_handler.
get_fe().dofs_per_quad > 0)
145 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_quad; ++d)
146 cell->set_dof_index (d, next_free_dof++);
150 cell->set_user_flag ();
152 return next_free_dof;
156 template <
int spacedim>
163 if (dof_handler.
get_fe().dofs_per_vertex > 0)
165 for (
unsigned int vertex=0; vertex<GeometryInfo<3>::vertices_per_cell; ++vertex)
170 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_vertex; ++d)
171 cell->set_vertex_dof_index (vertex, d, next_free_dof++);
174 if (dof_handler.
get_fe().dofs_per_line > 0)
175 for (
unsigned int l=0; l<GeometryInfo<3>::lines_per_cell; ++l)
177 const typename DoFHandler<3,spacedim>::line_iterator
178 line = cell->line(l);
185 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_line; ++d)
186 line->set_dof_index (d, next_free_dof++);
190 if (dof_handler.
get_fe().dofs_per_quad > 0)
191 for (
unsigned int q=0; q<GeometryInfo<3>::quads_per_cell; ++q)
193 const typename DoFHandler<3,spacedim>::quad_iterator
194 quad = cell->quad(q);
201 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_quad; ++d)
202 quad->set_dof_index (d, next_free_dof++);
207 if (dof_handler.
get_fe().dofs_per_hex > 0)
208 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_hex; ++d)
209 cell->set_dof_index (d, next_free_dof++);
214 cell->set_user_flag ();
216 return next_free_dof;
226 template <
int dim,
int spacedim>
233 const ::Triangulation<dim,spacedim> &tria
241 std::vector<bool> user_flags;
242 tria.save_user_flags(user_flags);
248 endc = dof_handler.
end();
250 for (; cell != endc; ++cell)
253 (cell->subdomain_id() == subdomain_id))
255 = Implementation::distribute_dofs_on_cell (dof_handler,
260 for (cell = dof_handler.
begin_active(); cell != endc; ++cell)
261 if (!cell->is_artificial())
262 cell->update_cell_dof_indices_cache ();
267 return next_free_dof;
297 template <
int spacedim>
301 typename DoFHandler<1,spacedim>::level_cell_iterator &cell,
302 unsigned int next_free_dof)
304 const unsigned int dim = 1;
307 if (cell->
get_fe().dofs_per_vertex > 0)
308 for (
unsigned int v=0; v<GeometryInfo<1>::vertices_per_cell; ++v)
310 typename DoFHandler<dim,spacedim>::level_cell_iterator neighbor = cell->neighbor(v);
315 if (neighbor->user_flag_set() &&
316 (neighbor->level() == cell->level()))
322 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_vertex; ++d)
323 cell->set_mg_vertex_dof_index (cell->level(), 0, d,
324 neighbor->mg_vertex_dof_index (cell->level(), 1, d));
326 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_vertex; ++d)
327 cell->set_mg_vertex_dof_index (cell->level(), 1, d,
328 neighbor->mg_vertex_dof_index (cell->level(), 0, d));
336 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_vertex; ++d)
337 cell->set_mg_vertex_dof_index (cell->level(), v, d, next_free_dof++);
341 if (cell->
get_fe().dofs_per_line > 0)
342 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_line; ++d)
343 cell->set_mg_dof_index (cell->level(), d, next_free_dof++);
346 cell->set_user_flag ();
348 return next_free_dof;
352 template <
int spacedim>
356 typename DoFHandler<2,spacedim>::level_cell_iterator &cell,
357 unsigned int next_free_dof)
359 const unsigned int dim = 2;
360 if (cell->
get_fe().dofs_per_vertex > 0)
362 for (
unsigned int vertex=0; vertex<GeometryInfo<2>::vertices_per_cell; ++vertex)
367 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_vertex; ++d)
368 cell->set_mg_vertex_dof_index (cell->level(), vertex, d, next_free_dof++);
371 if (cell->
get_fe().dofs_per_line > 0)
372 for (
unsigned int side=0; side<GeometryInfo<2>::faces_per_cell; ++side)
374 typename DoFHandler<dim,spacedim>::line_iterator line = cell->line(side);
381 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_line; ++d)
382 line->set_mg_dof_index (cell->level(), d, next_free_dof++);
387 if (cell->
get_fe().dofs_per_quad > 0)
388 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_quad; ++d)
389 cell->set_mg_dof_index (cell->level(), d, next_free_dof++);
393 cell->set_user_flag ();
395 return next_free_dof;
399 template <
int spacedim>
403 typename DoFHandler<3,spacedim>::level_cell_iterator &cell,
404 unsigned int next_free_dof)
406 const unsigned int dim = 3;
407 if (cell->
get_fe().dofs_per_vertex > 0)
409 for (
unsigned int vertex=0; vertex<GeometryInfo<3>::vertices_per_cell; ++vertex)
414 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_vertex; ++d)
415 cell->set_mg_vertex_dof_index (cell->level(), vertex, d, next_free_dof++);
418 if (cell->
get_fe().dofs_per_line > 0)
419 for (
unsigned int l=0; l<GeometryInfo<3>::lines_per_cell; ++l)
421 typename DoFHandler<dim,spacedim>::line_iterator line = cell->line(l);
428 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_line; ++d)
429 line->set_mg_dof_index (cell->level(), d, next_free_dof++);
433 if (cell->
get_fe().dofs_per_quad > 0)
434 for (
unsigned int q=0; q<GeometryInfo<3>::quads_per_cell; ++q)
436 typename DoFHandler<dim,spacedim>::quad_iterator quad = cell->quad(q);
443 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_quad; ++d)
444 quad->set_mg_dof_index (cell->level(), d, next_free_dof++);
449 if (cell->
get_fe().dofs_per_hex > 0)
450 for (
unsigned int d=0; d<cell->
get_fe().dofs_per_hex; ++d)
451 cell->set_mg_dof_index (cell->level(), d, next_free_dof++);
456 cell->set_user_flag ();
458 return next_free_dof;
462 template <
int dim,
int spacedim>
465 distribute_dofs_on_level (
const unsigned int offset,
468 const unsigned int level)
470 const ::Triangulation<dim,spacedim> &tria
473 if (level>=tria.n_levels())
484 std::vector<bool> user_flags;
485 tria.save_user_flags(user_flags);
488 unsigned int next_free_dof = offset;
489 typename DoFHandler<dim,spacedim>::level_cell_iterator
490 cell = dof_handler.
begin(level),
491 endc = dof_handler.
end(level);
493 for (; cell != endc; ++cell)
496 (cell->level_subdomain_id() == level_subdomain_id))
498 = Implementation::distribute_mg_dofs_on_cell (dof_handler, cell, next_free_dof);
510 return next_free_dof;
533 template <
int spacedim>
536 renumber_dofs (
const std::vector<types::global_dof_index> &new_numbers,
539 const bool check_validity)
551 for (std::vector<types::global_dof_index>::iterator
555 *i = new_numbers[*i];
556 else if (check_validity)
565 ExcInternalError ());
567 for (
unsigned int level=0; level<dof_handler.
levels.size(); ++level)
568 for (std::vector<types::global_dof_index>::iterator
569 i=dof_handler.
levels[level]->dof_object.dofs.begin();
570 i!=dof_handler.
levels[level]->dof_object.dofs.end(); ++i)
572 *i = new_numbers[*i];
577 for (
typename DoFHandler<1,spacedim>::level_cell_iterator
578 cell = dof_handler.
begin();
579 cell != dof_handler.
end(); ++cell)
580 cell->update_cell_dof_indices_cache ();
583 template <
int spacedim>
586 renumber_mg_dofs (
const std::vector<::types::global_dof_index> &new_numbers,
589 const unsigned int level,
590 const bool check_validity)
598 if ((i->get_coarsest_level() <= level) &&
599 (i->get_finest_level() >= level))
600 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_vertex; ++d)
604 i->set_index (level, d,
614 for (std::vector<types::global_dof_index>::iterator
615 i=dof_handler.mg_levels[level]->dof_object.dofs.begin();
616 i!=dof_handler.mg_levels[level]->dof_object.dofs.end();
621 Assert(*i<new_numbers.size(), ExcInternalError());
630 template <
int spacedim>
633 renumber_dofs (
const std::vector<types::global_dof_index> &new_numbers,
636 const bool check_validity)
648 for (std::vector<types::global_dof_index>::iterator
655 else if (check_validity)
663 ExcInternalError ());
665 for (std::vector<types::global_dof_index>::iterator
666 i=dof_handler.
faces->lines.dofs.begin();
667 i!=dof_handler.
faces->lines.dofs.end(); ++i)
673 for (
unsigned int level=0; level<dof_handler.
levels.size(); ++level)
675 for (std::vector<types::global_dof_index>::iterator
676 i=dof_handler.
levels[level]->dof_object.dofs.begin();
677 i!=dof_handler.
levels[level]->dof_object.dofs.end(); ++i)
687 for (
typename DoFHandler<2,spacedim>::level_cell_iterator
688 cell = dof_handler.
begin();
689 cell != dof_handler.
end(); ++cell)
690 cell->update_cell_dof_indices_cache ();
693 template <
int spacedim>
696 renumber_mg_dofs (
const std::vector<::types::global_dof_index> &new_numbers,
699 const unsigned int level,
700 const bool check_validity)
708 if ((i->get_coarsest_level() <= level) &&
709 (i->get_finest_level() >= level))
710 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_vertex; ++d)
714 i->set_index (level, d,
723 if (dof_handler.
get_fe().dofs_per_line > 0)
726 std::vector<bool> user_flags;
734 for (
typename DoFHandler<2,spacedim>::level_cell_iterator cell = dof_handler.
begin(level);
735 cell != dof_handler.
end(level); ++cell)
736 for (
unsigned int line=0; line < GeometryInfo<2>::faces_per_cell; ++line)
737 cell->face(line)->set_user_flag();
740 cell != dof_handler.
end(); ++cell)
741 for (
unsigned int l=0; l<GeometryInfo<2>::lines_per_cell; ++l)
742 if (cell->line(l)->user_flag_set())
744 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_line; ++d)
748 cell->line(l)->set_mg_dof_index (level, d, ((indices.
n_elements() == 0) ?
754 cell->line(l)->clear_user_flag();
760 for (std::vector<types::global_dof_index>::iterator i=dof_handler.mg_levels[level]->dof_object.dofs.begin();
761 i!=dof_handler.mg_levels[level]->dof_object.dofs.end(); ++i)
765 Assert(*i<new_numbers.size(), ExcInternalError());
775 template <
int spacedim>
778 renumber_dofs (
const std::vector<types::global_dof_index> &new_numbers,
781 const bool check_validity)
793 for (std::vector<types::global_dof_index>::iterator
800 else if (check_validity)
808 ExcInternalError ());
810 for (std::vector<types::global_dof_index>::iterator
811 i=dof_handler.
faces->lines.dofs.begin();
812 i!=dof_handler.
faces->lines.dofs.end(); ++i)
817 for (std::vector<types::global_dof_index>::iterator
818 i=dof_handler.
faces->quads.dofs.begin();
819 i!=dof_handler.
faces->quads.dofs.end(); ++i)
825 for (
unsigned int level=0; level<dof_handler.
levels.size(); ++level)
827 for (std::vector<types::global_dof_index>::iterator
828 i=dof_handler.
levels[level]->dof_object.dofs.begin();
829 i!=dof_handler.
levels[level]->dof_object.dofs.end(); ++i)
839 for (
typename DoFHandler<3,spacedim>::level_cell_iterator
840 cell = dof_handler.
begin();
841 cell != dof_handler.
end(); ++cell)
842 cell->update_cell_dof_indices_cache ();
845 template <
int spacedim>
848 renumber_mg_dofs (
const std::vector<::types::global_dof_index> &new_numbers,
851 const unsigned int level,
852 const bool check_validity)
860 if ((i->get_coarsest_level() <= level) &&
861 (i->get_finest_level() >= level))
862 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_vertex; ++d)
866 i->set_index (level, d,
875 if (dof_handler.
get_fe().dofs_per_line > 0 ||
876 dof_handler.
get_fe().dofs_per_quad > 0)
879 std::vector<bool> user_flags;
886 for (
typename DoFHandler<3,spacedim>::level_cell_iterator cell = dof_handler.
begin(level);
887 cell != dof_handler.
end(level); ++cell)
888 for (
unsigned int line=0; line < GeometryInfo<3>::lines_per_cell; ++line)
889 cell->line(line)->set_user_flag();
892 cell != dof_handler.
end(); ++cell)
893 for (
unsigned int l=0; l<GeometryInfo<3>::lines_per_cell; ++l)
894 if (cell->line(l)->user_flag_set())
896 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_line; ++d)
900 cell->line(l)->set_mg_dof_index (level, d, ((indices.
n_elements() == 0) ?
906 cell->line(l)->clear_user_flag();
912 for (
typename DoFHandler<3,spacedim>::level_cell_iterator cell = dof_handler.
begin(level);
913 cell != dof_handler.
end(level); ++cell)
914 for (
unsigned int quad=0; quad < GeometryInfo<3>::quads_per_cell; ++quad)
915 cell->quad(quad)->set_user_flag();
918 cell != dof_handler.
end(); ++cell)
919 for (
unsigned int l=0; l<GeometryInfo<3>::quads_per_cell; ++l)
920 if (cell->quad(l)->user_flag_set())
922 for (
unsigned int d=0; d<dof_handler.
get_fe().dofs_per_quad; ++d)
926 cell->quad(l)->set_mg_dof_index (level, d, ((indices.
n_elements() == 0) ?
932 cell->quad(l)->clear_user_flag();
939 for (std::vector<types::global_dof_index>::iterator i=dof_handler.mg_levels[level]->dof_object.dofs.begin();
940 i!=dof_handler.mg_levels[level]->dof_object.dofs.end(); ++i)
944 Assert(*i<new_numbers.size(), ExcInternalError());
959 template <
int dim,
int spacedim>
967 template <
int dim,
int spacedim>
974 Implementation::distribute_dofs (0,
991 = std::vector<types::global_dof_index> (1,
995 = std::vector<IndexSet> (1,
997 number_cache_current = number_cache;
1001 template <
int dim,
int spacedim>
1005 std::vector<NumberCache> &number_caches)
const 1007 std::vector<bool> user_flags;
1012 for (
unsigned int level = 0; level < dof_handler.
get_triangulation().n_levels(); ++level)
1016 number_caches[level].n_global_dofs = next_free_dof;
1017 number_caches[level].n_locally_owned_dofs = next_free_dof;
1018 number_caches[level].locally_owned_dofs = complete_index_set(next_free_dof);
1019 number_caches[level].locally_owned_dofs_per_processor.resize(1);
1020 number_caches[level].locally_owned_dofs_per_processor[0] = complete_index_set(next_free_dof);
1021 number_caches[level].n_locally_owned_dofs_per_processor.resize(1);
1022 number_caches[level].n_locally_owned_dofs_per_processor[0] = next_free_dof;
1027 template <
int dim,
int spacedim>
1034 Implementation::renumber_dofs (new_numbers,
IndexSet(0),
1054 = std::vector<types::global_dof_index> (1,
1058 = std::vector<IndexSet> (1,
1060 number_cache_current = number_cache;
1065 template <
int dim,
int spacedim>
1077 Assert(tr != 0, ExcInternalError());
1078 typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
1081 std::vector<types::subdomain_id> current_subdomain_ids(tr->
n_active_cells());
1084 for (
unsigned int index=0; cell != endc; cell++, index++)
1086 current_subdomain_ids[index] = cell->subdomain_id();
1087 cell->set_subdomain_id(true_subdomain_ids[index]);
1095 for (
unsigned int index=0; cell != endc; cell++, index++)
1096 cell->set_subdomain_id(true_subdomain_ids[index]);
1108 for (
unsigned int index=0; cell != endc; cell++, index++)
1109 cell->set_subdomain_id(current_subdomain_ids[index]);
1112 template <
int dim,
int spacedim>
1116 std::vector<NumberCache> &number_caches)
const 1125 template <
int dim,
int spacedim>
1133 #ifndef DEAL_II_WITH_MPI 1137 Assert (
false, ExcNotImplemented());
1143 Assert(tr != 0, ExcInternalError());
1144 typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
1147 std::vector<types::subdomain_id> current_subdomain_ids(tr->
n_active_cells());
1150 for (
unsigned int index=0; cell != endc; cell++, index++)
1152 current_subdomain_ids[index] = cell->subdomain_id();
1153 cell->set_subdomain_id(true_subdomain_ids[index]);
1156 std::vector<types::global_dof_index> global_gathered_numbers (dof_handler.
n_dofs (), 0);
1160 if (new_numbers.size () == dof_handler.
n_dofs ())
1162 global_gathered_numbers = new_numbers;
1167 ExcInternalError());
1169 std::vector<types::global_dof_index> gathered_new_numbers (dof_handler.
n_dofs (), 0);
1176 std::vector<types::global_dof_index> new_numbers_copy (new_numbers);
1182 std::vector<int> displs(n_cpu),
1186 int cur_count = new_numbers_copy.size ();
1187 MPI_Allgather (&cur_count, 1, MPI_INT,
1188 &rcounts[0], 1, MPI_INT,
1191 for (
unsigned int i = 0; i < n_cpu; i++)
1194 shift += rcounts[i];
1196 Assert(((
int)new_numbers_copy.size()) ==
1198 ExcInternalError());
1199 MPI_Allgatherv (&new_numbers_copy[0], new_numbers_copy.size (),
1200 DEAL_II_DOF_INDEX_MPI_TYPE,
1201 &gathered_new_numbers[0], &rcounts[0],
1203 DEAL_II_DOF_INDEX_MPI_TYPE,
1212 std::vector<unsigned int> flag_1 (dof_handler.
n_dofs (), 0),
1213 flag_2 (dof_handler.
n_dofs (), 0);
1214 for (
unsigned int i = 0; i < n_cpu; i++)
1223 Assert(target < dof_handler.
n_dofs(), ExcInternalError());
1224 Assert(value < dof_handler.
n_dofs(), ExcInternalError());
1225 global_gathered_numbers[target] = value;
1232 Assert(*std::max_element(flag_1.begin(), flag_1.end()) == 1,
1233 ExcInternalError());
1234 Assert(*std::min_element(flag_1.begin(), flag_1.end()) == 1,
1235 ExcInternalError());
1236 Assert((*std::max_element(flag_2.begin(), flag_2.end())) == 1,
1237 ExcInternalError());
1238 Assert((*std::min_element(flag_2.begin(), flag_2.end())) == 1,
1239 ExcInternalError());
1250 for (
unsigned int i = 0;
1260 for (
unsigned int index=0; cell != endc; cell++, index++)
1261 cell->set_subdomain_id(current_subdomain_ids[index]);
1267 #ifdef DEAL_II_WITH_P4EST 1286 std::vector<unsigned int> tree_index;
1287 std::vector<typename ::internal::p4est::types<dim>::quadrant> quadrants;
1288 std::vector<::types::global_dof_index> dofs;
1290 unsigned int bytes_for_buffer ()
const 1292 return (
sizeof(
unsigned int) +
1293 tree_index.size() *
sizeof(
unsigned int) +
1294 quadrants.size() *
sizeof(typename ::internal::p4est
1295 ::types<dim>::quadrant) +
1299 void pack_data (std::vector<char> &buffer)
const 1301 buffer.resize(bytes_for_buffer());
1303 char *ptr = &buffer[0];
1305 const unsigned int num_cells = tree_index.size();
1306 std::memcpy(ptr, &num_cells,
sizeof(
unsigned int));
1307 ptr +=
sizeof(
unsigned int);
1311 num_cells*
sizeof(
unsigned int));
1312 ptr += num_cells*
sizeof(
unsigned int);
1316 num_cells *
sizeof(typename ::internal::p4est::
1317 types<dim>::quadrant));
1318 ptr += num_cells*
sizeof(typename ::internal::p4est::types<dim>::
1326 Assert (ptr == &buffer[0]+buffer.size(),
1327 ExcInternalError());
1335 template <
int dim,
int spacedim>
1338 const unsigned int tree_index,
1339 const typename DoFHandler<dim,spacedim>::level_cell_iterator &dealii_cell,
1340 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
1341 const std::map<
unsigned int, std::set<::types::subdomain_id> > &vertices_with_ghost_neighbors,
1346 if (dealii_cell->has_children())
1348 typename ::internal::p4est::types<dim>::quadrant
1350 internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
1353 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1354 fill_dofindices_recursively<dim,spacedim>(tria,
1356 dealii_cell->child(c),
1358 vertices_with_ghost_neighbors,
1368 if (dealii_cell->user_flag_set() && !dealii_cell->is_ghost())
1370 Assert (!dealii_cell->is_artificial(), ExcInternalError());
1375 std::set<::types::subdomain_id> send_to;
1376 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
1378 const std::map<unsigned int, std::set<::types::subdomain_id> >::const_iterator
1379 neighbor_subdomains_of_vertex
1380 = vertices_with_ghost_neighbors.find (dealii_cell->vertex_index(v));
1382 if (neighbor_subdomains_of_vertex ==
1383 vertices_with_ghost_neighbors.end())
1386 Assert(neighbor_subdomains_of_vertex->second.size()!=0,
1387 ExcInternalError());
1389 send_to.insert(neighbor_subdomains_of_vertex->second.begin(),
1390 neighbor_subdomains_of_vertex->second.end());
1393 if (send_to.size() > 0)
1398 std::vector<::types::global_dof_index>
1399 local_dof_indices (dealii_cell->
get_fe().dofs_per_cell);
1400 dealii_cell->get_dof_indices (local_dof_indices);
1402 for (std::set<::types::subdomain_id>::iterator it=send_to.begin();
1403 it!=send_to.end(); ++it)
1405 const ::types::subdomain_id subdomain = *it;
1414 typename std::map<::types::subdomain_id, typename types<dim>::cellinfo>::iterator
1416 = needs_to_get_cell.insert (std::make_pair(subdomain,
1417 typename types<dim>::cellinfo()))
1420 p->second.tree_index.push_back(tree_index);
1421 p->second.quadrants.push_back(p4est_cell);
1423 p->second.dofs.push_back(dealii_cell->
get_fe().dofs_per_cell);
1424 p->second.dofs.insert(p->second.dofs.end(),
1425 local_dof_indices.begin(),
1426 local_dof_indices.end());
1433 template <
int dim,
int spacedim>
1436 const unsigned int tree_index,
1437 const typename DoFHandler<dim,spacedim>::level_cell_iterator &dealii_cell,
1438 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
1439 const std::map<
unsigned int, std::set<::types::subdomain_id> > &vertices_with_ghost_neighbors,
1441 const unsigned int level)
1443 if (dealii_cell->level()>(int)level)
1447 if (dealii_cell->has_children())
1449 typename ::internal::p4est::types<dim>::quadrant
1451 internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
1454 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1455 fill_mg_dofindices_recursively<dim,spacedim>(tria,
1457 dealii_cell->child(c),
1459 vertices_with_ghost_neighbors,
1464 if (dealii_cell->level()<(int)level)
1468 Assert(dealii_cell->level()==(int)level, ExcInternalError());
1480 std::set<::types::subdomain_id> send_to;
1481 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
1483 const std::map<unsigned int, std::set<::types::subdomain_id> >::const_iterator
1484 neighbor_subdomains_of_vertex
1485 = vertices_with_ghost_neighbors.find (dealii_cell->vertex_index(v));
1487 if (neighbor_subdomains_of_vertex ==
1488 vertices_with_ghost_neighbors.end())
1491 Assert(neighbor_subdomains_of_vertex->second.size()!=0,
1492 ExcInternalError());
1494 send_to.insert(neighbor_subdomains_of_vertex->second.begin(),
1495 neighbor_subdomains_of_vertex->second.end());
1499 if (dealii_cell->has_children())
1501 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1507 send_to.insert(dest);
1513 if (dealii_cell->active())
1515 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
1517 if (dealii_cell->at_boundary(f))
1519 typename DoFHandler<dim,spacedim>::level_cell_iterator neighbor = dealii_cell->neighbor(f);
1520 if (!neighbor->has_children())
1523 for (
unsigned int subface=0; subface<GeometryInfo<dim>::max_children_per_face; ++subface)
1525 typename DoFHandler<dim,spacedim>::level_cell_iterator child = dealii_cell->neighbor_child_on_subface(f,subface);
1529 send_to.insert(dest);
1538 if (dealii_cell->active())
1540 for (
unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
1542 if (dealii_cell->at_boundary(f))
1544 typename DoFHandler<dim,spacedim>::level_cell_iterator neighbor = dealii_cell->neighbor(f);
1545 if (neighbor->level()>=dealii_cell->level())
1551 send_to.insert(dest);
1558 if (send_to.size() > 0)
1563 std::vector<::types::global_dof_index>
1564 local_dof_indices (dealii_cell->
get_fe().dofs_per_cell);
1565 dealii_cell->get_mg_dof_indices (local_dof_indices);
1567 for (std::set<::types::subdomain_id>::iterator it=send_to.begin();
1568 it!=send_to.end(); ++it)
1570 const ::types::subdomain_id subdomain = *it;
1579 typename std::map<::types::subdomain_id, typename types<dim>::cellinfo>::iterator
1581 = needs_to_get_cell.insert (std::make_pair(subdomain,
1582 typename types<dim>::cellinfo()))
1585 p->second.tree_index.push_back(tree_index);
1586 p->second.quadrants.push_back(p4est_cell);
1588 p->second.dofs.push_back(dealii_cell->
get_fe().dofs_per_cell);
1589 p->second.dofs.insert(p->second.dofs.end(),
1590 local_dof_indices.begin(),
1591 local_dof_indices.end());
1599 template <
int dim,
int spacedim>
1601 set_dofindices_recursively (
1603 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
1604 const typename DoFHandler<dim,spacedim>::level_cell_iterator &dealii_cell,
1605 const typename ::internal::p4est::types<dim>::quadrant &quadrant,
1608 if (internal::p4est::quadrant_is_equal<dim>(p4est_cell, quadrant))
1610 Assert(!dealii_cell->has_children(), ExcInternalError());
1611 Assert(dealii_cell->is_ghost(), ExcInternalError());
1614 std::vector<::types::global_dof_index>
1615 dof_indices (dealii_cell->
get_fe().dofs_per_cell);
1616 dealii_cell->update_cell_dof_indices_cache();
1617 dealii_cell->get_dof_indices(dof_indices);
1619 bool complete =
true;
1620 for (
unsigned int i=0; i<dof_indices.size(); ++i)
1623 Assert((dof_indices[i] ==
1626 (dof_indices[i]==dofs[i]),
1627 ExcInternalError());
1628 dof_indices[i]=dofs[i];
1635 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1636 (dealii_cell)->set_user_flag();
1639 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1640 (dealii_cell)->clear_user_flag();
1643 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1644 (dealii_cell)->set_dof_indices(dof_indices);
1649 if (! dealii_cell->has_children())
1652 if (! internal::p4est::quadrant_is_ancestor<dim> (p4est_cell, quadrant))
1655 typename ::internal::p4est::types<dim>::quadrant
1657 internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
1659 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1660 set_dofindices_recursively<dim,spacedim> (tria, p4est_child[c],
1661 dealii_cell->child(c),
1666 template <
int dim,
int spacedim>
1668 set_mg_dofindices_recursively (
1670 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
1671 const typename DoFHandler<dim,spacedim>::level_cell_iterator &dealii_cell,
1672 const typename ::internal::p4est::types<dim>::quadrant &quadrant,
1676 if (internal::p4est::quadrant_is_equal<dim>(p4est_cell, quadrant))
1678 Assert(dealii_cell->level_subdomain_id()!=::numbers::artificial_subdomain_id, ExcInternalError());
1679 Assert(dealii_cell->level()==(int)level, ExcInternalError());
1682 std::vector<::types::global_dof_index>
1683 dof_indices (dealii_cell->
get_fe().dofs_per_cell);
1684 dealii_cell->get_mg_dof_indices(dof_indices);
1686 bool complete =
true;
1687 for (
unsigned int i=0; i<dof_indices.size(); ++i)
1690 Assert((dof_indices[i] ==
1693 (dof_indices[i]==dofs[i]),
1694 ExcInternalError());
1695 dof_indices[i]=dofs[i];
1702 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1703 (dealii_cell)->set_user_flag();
1706 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1707 (dealii_cell)->clear_user_flag();
1710 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1711 (dealii_cell)->set_mg_dof_indices(dof_indices);
1715 if (! dealii_cell->has_children())
1718 if (! internal::p4est::quadrant_is_ancestor<dim> (p4est_cell, quadrant))
1721 typename ::internal::p4est::types<dim>::quadrant
1723 internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
1725 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1726 set_mg_dofindices_recursively<dim,spacedim> (tria, p4est_child[c],
1727 dealii_cell->child(c),
1728 quadrant, dofs, level);
1734 template <
int spacedim>
1736 communicate_dof_indices_on_marked_cells
1738 const std::map<
unsigned int, std::set<::types::subdomain_id> > &,
1739 const std::vector<::types::global_dof_index> &,
1740 const std::vector<::types::global_dof_index> &)
1742 Assert (
false, ExcNotImplemented());
1747 template <
int dim,
int spacedim>
1749 communicate_dof_indices_on_marked_cells
1751 const std::map<
unsigned int, std::set<::types::subdomain_id> > &vertices_with_ghost_neighbors,
1752 const std::vector<::types::global_dof_index> &coarse_cell_to_p4est_tree_permutation,
1753 const std::vector<::types::global_dof_index> &p4est_tree_to_coarse_cell_permutation)
1755 #ifndef DEAL_II_WITH_P4EST 1756 (void)vertices_with_ghost_neighbors;
1757 Assert (
false, ExcNotImplemented());
1763 Assert (tr != 0, ExcInternalError());
1769 std::map<::types::subdomain_id, typename types<dim>::cellinfo>
1771 cellmap_t needs_to_get_cells;
1773 for (
typename DoFHandler<dim,spacedim>::level_cell_iterator
1774 cell = dof_handler.
begin(0);
1775 cell != dof_handler.
end(0);
1778 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
1779 internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
1781 fill_dofindices_recursively<dim,spacedim>
1783 coarse_cell_to_p4est_tree_permutation[cell->index()],
1786 vertices_with_ghost_neighbors,
1787 needs_to_get_cells);
1792 std::vector<std::vector<char> > sendbuffers (needs_to_get_cells.size());
1793 std::vector<std::vector<char> >::iterator buffer = sendbuffers.begin();
1794 std::vector<MPI_Request> requests (needs_to_get_cells.size());
1798 for (
typename cellmap_t::iterator it=needs_to_get_cells.begin();
1799 it!=needs_to_get_cells.end();
1800 ++it, ++buffer, ++idx)
1802 const unsigned int num_cells = it->second.tree_index.size();
1805 Assert(num_cells==it->second.quadrants.size(), ExcInternalError());
1806 Assert(num_cells>0, ExcInternalError());
1815 it->second.pack_data (*buffer);
1816 MPI_Isend(&(*buffer)[0], buffer->size(),
1817 MPI_BYTE, it->first,
1825 std::set<::types::subdomain_id> senders;
1827 std::vector<::types::global_dof_index> local_dof_indices;
1829 cell, endc = dof_handler.
end();
1831 for (cell = dof_handler.
begin_active(); cell != endc; ++cell)
1832 if (!cell->is_artificial())
1834 if (cell->is_ghost())
1836 if (cell->user_flag_set())
1837 senders.insert(cell->subdomain_id());
1841 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
1842 cell->get_dof_indices (local_dof_indices);
1843 if (local_dof_indices.end() !=
1844 std::find (local_dof_indices.begin(),
1845 local_dof_indices.end(),
1847 cell->set_user_flag();
1849 cell->clear_user_flag();
1857 std::vector<char> receive;
1858 typename types<dim>::cellinfo cellinfo;
1859 for (
unsigned int i=0; i<senders.size(); ++i)
1864 MPI_Get_count(&status, MPI_BYTE, &len);
1865 receive.resize(len);
1867 char *ptr = &receive[0];
1868 MPI_Recv(ptr, len, MPI_BYTE, status.MPI_SOURCE, status.MPI_TAG,
1872 memcpy(&cells, ptr,
sizeof(
unsigned int));
1873 ptr+=
sizeof(
unsigned int);
1876 unsigned int *treeindex=
reinterpret_cast<unsigned int *
>(ptr);
1877 ptr+=cells*
sizeof(
unsigned int);
1878 typename ::internal::p4est::types<dim>::quadrant *quadrant
1879 =
reinterpret_cast<typename ::internal::p4est::types<dim>::quadrant *
>(ptr);
1880 ptr+=cells*
sizeof(typename ::internal::p4est::types<dim>::quadrant);
1886 for (
unsigned int c=0; c<cells; ++c, dofs+=1+dofs[0])
1888 typename DoFHandler<dim,spacedim>::level_cell_iterator
1891 p4est_tree_to_coarse_cell_permutation[treeindex[c]],
1894 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
1895 internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
1897 Assert(cell->
get_fe().dofs_per_cell==dofs[0], ExcInternalError());
1899 set_dofindices_recursively<dim,spacedim> (*tr,
1909 if (requests.size() > 0)
1910 MPI_Waitall(requests.size(), &requests[0], MPI_STATUSES_IGNORE);
1916 unsigned int sum_send=0;
1917 unsigned int sum_recv=0;
1918 unsigned int sent=needs_to_get_cells.size();
1919 unsigned int recv=senders.size();
1921 MPI_Allreduce(&sent, &sum_send, 1, MPI_UNSIGNED, MPI_SUM, tr->
get_communicator());
1922 MPI_Allreduce(&recv, &sum_recv, 1, MPI_UNSIGNED, MPI_SUM, tr->
get_communicator());
1923 Assert(sum_send==sum_recv, ExcInternalError());
1930 cell, endc = dof_handler.
end();
1932 for (cell = dof_handler.
begin_active(); cell != endc; ++cell)
1933 if (!cell->is_artificial())
1934 cell->update_cell_dof_indices_cache();
1959 template <
int spacedim>
1961 communicate_mg_dof_indices_on_marked_cells
1963 const std::map<
unsigned int, std::set<::types::subdomain_id> > &,
1964 const std::vector<::types::global_dof_index> &,
1965 const std::vector<::types::global_dof_index> &,
1968 Assert (
false, ExcNotImplemented());
1973 template <
int dim,
int spacedim>
1975 communicate_mg_dof_indices_on_marked_cells
1977 const std::map<
unsigned int, std::set<::types::subdomain_id> > &vertices_with_ghost_neighbors,
1978 const std::vector<::types::global_dof_index> &coarse_cell_to_p4est_tree_permutation,
1979 const std::vector<::types::global_dof_index> &p4est_tree_to_coarse_cell_permutation,
1980 const unsigned int level)
1982 #ifndef DEAL_II_WITH_P4EST 1984 (void)vertices_with_ghost_neighbors;
1985 (void)coarse_cell_to_p4est_tree_permutation;
1986 (void)p4est_tree_to_coarse_cell_permutation;
1988 Assert (
false, ExcNotImplemented());
1994 Assert (tr != 0, ExcInternalError());
2000 std::map<::types::subdomain_id, typename types<dim>::cellinfo>
2002 cellmap_t needs_to_get_cells;
2004 for (
typename DoFHandler<dim,spacedim>::level_cell_iterator
2005 cell = dof_handler.
begin(0);
2006 cell != dof_handler.
end(0);
2009 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
2010 internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
2012 fill_mg_dofindices_recursively<dim,spacedim>
2014 coarse_cell_to_p4est_tree_permutation[cell->index()],
2017 vertices_with_ghost_neighbors,
2024 std::vector<std::vector<char> > sendbuffers (needs_to_get_cells.size());
2025 std::vector<std::vector<char> >::iterator buffer = sendbuffers.begin();
2026 std::vector<MPI_Request> requests (needs_to_get_cells.size());
2030 for (
typename cellmap_t::iterator it=needs_to_get_cells.begin();
2031 it!=needs_to_get_cells.end();
2032 ++it, ++buffer, ++idx)
2034 const unsigned int num_cells = it->second.tree_index.size();
2037 Assert(num_cells==it->second.quadrants.size(), ExcInternalError());
2038 Assert(num_cells>0, ExcInternalError());
2047 it->second.pack_data (*buffer);
2048 MPI_Isend(&(*buffer)[0], buffer->size(),
2049 MPI_BYTE, it->first,
2056 std::set<::types::subdomain_id> senders;
2058 std::vector<::types::global_dof_index> local_dof_indices;
2059 typename DoFHandler<dim,spacedim>::level_cell_iterator
2060 cell, endc = dof_handler.
end(level);
2062 for (cell = dof_handler.
begin(level); cell != endc; ++cell)
2064 if (cell->level_subdomain_id()==::numbers::artificial_subdomain_id)
2068 else if (cell->level_subdomain_id()==dof_handler.
get_triangulation().locally_owned_subdomain())
2071 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2072 cell->get_mg_dof_indices (local_dof_indices);
2073 if (local_dof_indices.end() !=
2074 std::find (local_dof_indices.begin(),
2075 local_dof_indices.end(),
2077 cell->set_user_flag();
2079 cell->clear_user_flag();
2084 if (cell->user_flag_set())
2085 senders.insert(cell->level_subdomain_id());
2093 std::vector<char> receive;
2094 typename types<dim>::cellinfo cellinfo;
2095 for (
unsigned int i=0; i<senders.size(); ++i)
2100 MPI_Get_count(&status, MPI_BYTE, &len);
2101 receive.resize(len);
2104 Assert(senders.find(status.MPI_SOURCE)!=senders.end(), ExcInternalError());
2107 char *ptr = &receive[0];
2108 MPI_Recv(ptr, len, MPI_BYTE, status.MPI_SOURCE, status.MPI_TAG,
2112 memcpy(&cells, ptr,
sizeof(
unsigned int));
2113 ptr+=
sizeof(
unsigned int);
2116 unsigned int *treeindex=
reinterpret_cast<unsigned int *
>(ptr);
2117 ptr+=cells*
sizeof(
unsigned int);
2118 typename ::internal::p4est::types<dim>::quadrant *quadrant
2119 =
reinterpret_cast<typename ::internal::p4est::types<dim>::quadrant *
>(ptr);
2120 ptr+=cells*
sizeof(typename ::internal::p4est::types<dim>::quadrant);
2126 for (
unsigned int c=0; c<cells; ++c, dofs+=1+dofs[0])
2128 typename DoFHandler<dim,spacedim>::level_cell_iterator
2131 p4est_tree_to_coarse_cell_permutation[treeindex[c]],
2134 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
2135 internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
2137 Assert(cell->
get_fe().dofs_per_cell==dofs[0], ExcInternalError());
2139 set_mg_dofindices_recursively<dim,spacedim> (*tr,
2150 if (requests.size() > 0)
2151 MPI_Waitall(requests.size(), &requests[0], MPI_STATUSES_IGNORE);
2157 unsigned int sum_send=0;
2158 unsigned int sum_recv=0;
2159 unsigned int sent=needs_to_get_cells.size();
2160 unsigned int recv=senders.size();
2162 MPI_Allreduce(&sent, &sum_send, 1, MPI_UNSIGNED, MPI_SUM, tr->
get_communicator());
2163 MPI_Allreduce(&recv, &sum_recv, 1, MPI_UNSIGNED, MPI_SUM, tr->
get_communicator());
2164 Assert(sum_send==sum_recv, ExcInternalError());
2194 #endif // DEAL_II_WITH_P4EST 2198 template <
int dim,
int spacedim>
2206 #ifndef DEAL_II_WITH_P4EST 2208 Assert (
false, ExcNotImplemented());
2215 Assert (tr != 0, ExcInternalError());
2222 const ::types::global_dof_index n_initial_local_dofs =
2229 std::vector<::types::global_dof_index> renumbering(n_initial_local_dofs);
2230 for (
unsigned int i=0; i<renumbering.size(); ++i)
2234 std::vector<::types::global_dof_index> local_dof_indices;
2238 endc = dof_handler.
end();
2240 for (; cell != endc; ++cell)
2241 if (cell->is_ghost() &&
2256 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2257 cell->get_dof_indices (local_dof_indices);
2258 for (
unsigned int i=0; i<cell->
get_fe().dofs_per_cell; ++i)
2260 renumbering[local_dof_indices[i]]
2268 for (std::vector<::types::global_dof_index>::iterator it=renumbering.begin();
2269 it!=renumbering.end(); ++it)
2278 1, DEAL_II_DOF_INDEX_MPI_TYPE,
2280 1, DEAL_II_DOF_INDEX_MPI_TYPE,
2283 const ::types::global_dof_index
2284 shift = std::accumulate (number_cache
2285 .n_locally_owned_dofs_per_processor.begin(),
2290 for (std::vector<::types::global_dof_index>::iterator it=renumbering.begin();
2291 it!=renumbering.end(); ++it)
2300 Implementation::renumber_dofs (renumbering,
IndexSet(0),
2301 dof_handler,
false);
2306 = std::accumulate (number_cache
2307 .n_locally_owned_dofs_per_processor.begin(),
2322 for (
unsigned int i=0; i<n_cpus; ++i)
2337 ExcInternalError());
2344 ExcInternalError());
2349 std::vector<bool> user_flags;
2355 cell != dof_handler.
end(); ++cell)
2356 if (!cell->is_artificial())
2357 cell->set_user_flag();
2363 std::map<unsigned int, std::set<::types::subdomain_id> >
2364 vertices_with_ghost_neighbors;
2374 communicate_dof_indices_on_marked_cells (dof_handler,
2375 vertices_with_ghost_neighbors,
2377 tr->p4est_tree_to_coarse_cell_permutation);
2379 communicate_dof_indices_on_marked_cells (dof_handler,
2380 vertices_with_ghost_neighbors,
2382 tr->p4est_tree_to_coarse_cell_permutation);
2389 std::vector<::types::global_dof_index> local_dof_indices;
2392 cell != dof_handler.
end(); ++cell)
2393 if (!cell->is_artificial())
2395 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2396 cell->get_dof_indices (local_dof_indices);
2397 if (local_dof_indices.end() !=
2398 std::find (local_dof_indices.begin(),
2399 local_dof_indices.end(),
2402 if (cell->is_ghost())
2414 #endif // DEAL_II_WITH_P4EST 2416 number_cache_current = number_cache;
2421 template <
int dim,
int spacedim>
2425 std::vector<NumberCache> &number_caches)
const 2427 #ifndef DEAL_II_WITH_P4EST 2429 (void)number_caches;
2430 Assert (
false, ExcNotImplemented());
2437 Assert (tr != 0, ExcInternalError());
2441 ExcMessage(
"Multigrid DoFs can only be distributed on a parallel Triangulation if the flag construct_multigrid_hierarchy is set in the constructor."));
2449 for (
unsigned int level = 0; level < n_levels; ++level)
2455 const unsigned int n_initial_local_dofs =
2461 std::vector<::types::global_dof_index> renumbering(n_initial_local_dofs);
2465 if (level<tr->n_levels())
2467 std::vector<::types::global_dof_index> local_dof_indices;
2469 typename DoFHandler<dim,spacedim>::level_cell_iterator
2470 cell = dof_handler.
begin(level),
2471 endc = dof_handler.
end(level);
2473 for (; cell != endc; ++cell)
2489 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2490 cell->get_mg_dof_indices (local_dof_indices);
2491 for (
unsigned int i=0; i<cell->
get_fe().dofs_per_cell; ++i)
2493 renumbering[local_dof_indices[i]]
2501 for (std::vector<::types::global_dof_index>::iterator it=renumbering.begin();
2502 it!=renumbering.end(); ++it)
2511 1, DEAL_II_DOF_INDEX_MPI_TYPE,
2513 1, DEAL_II_DOF_INDEX_MPI_TYPE,
2516 const ::types::global_dof_index
2517 shift = std::accumulate (number_cache
2518 .n_locally_owned_dofs_per_processor.begin(),
2523 for (std::vector<::types::global_dof_index>::iterator it=renumbering.begin();
2524 it!=renumbering.end(); ++it)
2533 Implementation::renumber_mg_dofs (renumbering,
IndexSet(0),
2534 dof_handler, level,
false);
2539 = std::accumulate (number_cache
2540 .n_locally_owned_dofs_per_processor.begin(),
2555 for (
unsigned int i=0; i<n_cpus; ++i)
2570 ExcInternalError());
2577 ExcInternalError());
2581 std::vector<bool> user_flags;
2586 if (level < tr->n_levels())
2588 typename DoFHandler<dim,spacedim>::level_cell_iterator
2589 cell, endc = dof_handler.
end(level);
2590 for (cell = dof_handler.
begin(level); cell != endc; ++cell)
2591 if (cell->level_subdomain_id() != ::numbers::artificial_subdomain_id)
2592 cell->set_user_flag();
2597 const std::vector<bool> locally_active_vertices
2602 std::map<unsigned int, std::set<::types::subdomain_id> >
2603 vertices_with_ghost_neighbors;
2605 vertices_with_ghost_neighbors);
2611 communicate_mg_dof_indices_on_marked_cells( dof_handler,
2612 vertices_with_ghost_neighbors,
2614 tr->p4est_tree_to_coarse_cell_permutation,
2616 communicate_mg_dof_indices_on_marked_cells( dof_handler,
2617 vertices_with_ghost_neighbors,
2619 tr->p4est_tree_to_coarse_cell_permutation,
2626 if (level < tr->n_levels())
2628 std::vector<::types::global_dof_index> local_dof_indices;
2629 typename DoFHandler<dim,spacedim>::level_cell_iterator
2630 cell, endc = dof_handler.
end(level);
2632 for (cell = dof_handler.
begin(level); cell != endc; ++cell)
2633 if (cell->level_subdomain_id() != ::numbers::artificial_subdomain_id)
2635 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2636 cell->get_mg_dof_indices (local_dof_indices);
2637 if (local_dof_indices.end() !=
2638 std::find (local_dof_indices.begin(),
2639 local_dof_indices.end(),
2650 #endif // DEAL_II_WITH_P4EST 2654 template <
int dim,
int spacedim>
2665 ExcInternalError());
2669 #ifndef DEAL_II_WITH_P4EST 2670 Assert (
false, ExcNotImplemented());
2680 number_cache.locally_owned_dofs =
IndexSet (dof_handler.
n_dofs());
2683 std::vector<::types::global_dof_index> new_numbers_sorted (new_numbers);
2684 std::sort(new_numbers_sorted.begin(), new_numbers_sorted.end());
2685 std::vector<::types::global_dof_index>::const_iterator it = new_numbers_sorted.begin();
2686 const unsigned int n_blocks = dof_handler.
get_fe().n_blocks();
2687 std::vector<std::pair<::types::global_dof_index,unsigned int> > block_indices(n_blocks);
2688 block_indices[0].first = *it++;
2689 block_indices[0].second = 1;
2690 unsigned int current_block = 0, n_filled_blocks = 1;
2691 for ( ; it != new_numbers_sorted.end(); ++it)
2697 for (
unsigned int i=0; i<n_filled_blocks; ++i)
2698 if (*it == block_indices[current_block].first
2699 +block_indices[current_block].second)
2701 block_indices[current_block].second++;
2707 if (current_block == n_filled_blocks-1)
2718 if (n_filled_blocks < n_blocks)
2720 block_indices[n_filled_blocks].first = *it;
2721 block_indices[n_filled_blocks].second = 1;
2722 current_block = n_filled_blocks;
2734 unsigned int sum = 0;
2735 for (
unsigned int i=0; i<n_filled_blocks; ++i)
2736 sum += block_indices[i].second;
2737 if (sum == new_numbers.size())
2738 for (
unsigned int i=0; i<n_filled_blocks; ++i)
2739 number_cache.locally_owned_dofs.add_range (block_indices[i].first,
2740 block_indices[i].first+
2741 block_indices[i].second);
2743 number_cache.locally_owned_dofs.add_indices(new_numbers_sorted.begin(),
2744 new_numbers_sorted.end());
2748 number_cache.locally_owned_dofs.compress();
2749 Assert (number_cache.locally_owned_dofs.n_elements() == new_numbers.size(),
2750 ExcInternalError());
2753 Assert (number_cache.locally_owned_dofs.n_elements() ==
2755 ExcInternalError());
2762 std::vector<::types::global_dof_index> local_dof_indices;
2766 endc = dof_handler.
end();
2768 for (; cell != endc; ++cell)
2769 if (!cell->is_artificial())
2771 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2772 cell->get_dof_indices (local_dof_indices);
2773 for (
unsigned int i=0; i<cell->
get_fe().dofs_per_cell; ++i)
2781 local_dof_indices[i]
2786 cell->set_dof_indices (local_dof_indices);
2793 Implementation::renumber_dofs (new_numbers,
2804 Assert (tr != 0, ExcInternalError());
2806 std::vector<bool> user_flags;
2812 cell, endc = dof_handler.
end();
2813 for (cell = dof_handler.
begin_active(); cell != endc; ++cell)
2814 if (!cell->is_artificial())
2815 cell->set_user_flag();
2819 std::map<unsigned int, std::set<::types::subdomain_id> >
2820 vertices_with_ghost_neighbors;
2827 communicate_dof_indices_on_marked_cells (dof_handler,
2828 vertices_with_ghost_neighbors,
2830 tr->p4est_tree_to_coarse_cell_permutation);
2832 communicate_dof_indices_on_marked_cells (dof_handler,
2833 vertices_with_ghost_neighbors,
2835 tr->p4est_tree_to_coarse_cell_permutation);
2843 std::ostringstream oss;
2844 number_cache.locally_owned_dofs.block_write(oss);
2845 std::string oss_str=oss.str();
2846 std::vector<char> my_data(oss_str.begin(), oss_str.end());
2847 unsigned int my_size = oss_str.size();
2850 const unsigned int max_size
2855 my_data.resize(max_size);
2857 std::vector<char> buffer(max_size*n_cpus);
2858 MPI_Allgather(&my_data[0], max_size, MPI_BYTE,
2859 &buffer[0], max_size, MPI_BYTE,
2862 number_cache.locally_owned_dofs_per_processor.resize (n_cpus);
2863 number_cache.n_locally_owned_dofs_per_processor.resize (n_cpus);
2864 for (
unsigned int i=0; i<n_cpus; ++i)
2866 std::stringstream strstr;
2867 strstr.write(&buffer[i*max_size],max_size);
2871 number_cache.locally_owned_dofs_per_processor[i]
2872 .block_read(strstr);
2873 number_cache.n_locally_owned_dofs_per_processor[i]
2874 = number_cache.locally_owned_dofs_per_processor[i].n_elements();
2877 number_cache.n_global_dofs
2878 = std::accumulate (number_cache
2879 .n_locally_owned_dofs_per_processor.begin(),
2881 .n_locally_owned_dofs_per_processor.end(),
2888 number_cache_current = number_cache;
2898 #include "dof_handler_policy.inst" 2901 DEAL_II_NAMESPACE_CLOSE
unsigned int n_active_cells() const
std::vector< MGVertexDoFs > mg_vertex_dofs
std::vector< bool > mark_locally_active_vertices_on_level(const unsigned int level) const
void fill_vertices_with_ghost_neighbors(std::map< unsigned int, std::set<::types::subdomain_id > > &vertices_with_ghost_neighbors)
const std::vector< types::subdomain_id > & get_true_subdomain_ids_of_cells() const
const types::subdomain_id invalid_subdomain_id
virtual void distribute_dofs(::DoFHandler< dim, spacedim > &dof_handler, NumberCache &number_cache) const
cell_iterator begin(const unsigned int level=0) const
size_type nth_index_in_set(const unsigned int local_index) const
virtual void renumber_dofs(const std::vector< types::global_dof_index > &new_numbers, ::DoFHandler< dim, spacedim > &dof_handler, NumberCache &number_cache) const
void load_user_flags(std::istream &in)
::ExceptionBase & ExcMessage(std::string arg1)
cell_iterator end() const
virtual void distribute_dofs(::DoFHandler< dim, spacedim > &dof_handler, NumberCache &number_cache) const
SmartPointer< const FiniteElement< dim, spacedim >, DoFHandler< dim, spacedim > > selected_fe
std::vector<::internal::DoFHandler::DoFLevel< dim > * > levels
ActiveSelector::active_cell_iterator active_cell_iterator
active_cell_iterator begin_active(const unsigned int level=0) const
#define AssertThrow(cond, exc)
void fill_level_vertices_with_ghost_neighbors(const unsigned int level, std::map< unsigned int, std::set<::types::subdomain_id > > &vertices_with_ghost_neighbors)
const FiniteElement< dim, spacedim > & get_fe() const
types::global_dof_index n_locally_owned_dofs
active_cell_iterator begin_active(const unsigned int level=0) const
unsigned int n_locally_owned_dofs() const
ActiveSelector::cell_iterator cell_iterator
unsigned int global_dof_index
#define Assert(cond, exc)
virtual void renumber_dofs(const std::vector< types::global_dof_index > &new_numbers, ::DoFHandler< dim, spacedim > &dof_handler, NumberCache &number_cache) const
size_type index_within_set(const size_type global_index) const
virtual void distribute_mg_dofs(::DoFHandler< dim, spacedim > &dof_handler, std::vector< NumberCache > &number_caches) const
virtual MPI_Comm get_communicator() const
types::global_dof_index n_dofs() const
::internal::DoFHandler::DoFFaces< dim > * faces
unsigned int subdomain_id
virtual void distribute_dofs(::DoFHandler< dim, spacedim > &dof_handler, NumberCache &number_cache) const
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
void add_range(const size_type begin, const size_type end)
const types::subdomain_id artificial_subdomain_id
virtual void distribute_mg_dofs(::DoFHandler< dim, spacedim > &dof_handler, std::vector< NumberCache > &number_caches) const
std::vector< types::global_dof_index > n_locally_owned_dofs_per_processor
virtual void distribute_mg_dofs(::DoFHandler< dim, spacedim > &dof_handler, std::vector< NumberCache > &number_caches) const
bool with_artificial_cells() const
unsigned int this_mpi_process(const MPI_Comm &mpi_communicator)
void save_user_flags(std::ostream &out) const
const Triangulation< dim, spacedim > & get_triangulation() const
Iterator points to a valid object.
std::vector< IndexSet > locally_owned_dofs_per_processor
bool is_element(const size_type index) const
types::global_dof_index n_global_dofs
void subdomain_wise(DoFHandlerType &dof_handler)
types::subdomain_id locally_owned_subdomain() const
const IndexSet & locally_owned_dofs() const
size_type n_elements() const
T max(const T &t, const MPI_Comm &mpi_communicator)
virtual void renumber_dofs(const std::vector< types::global_dof_index > &new_numbers, ::DoFHandler< dim, spacedim > &dof_handler, NumberCache &number_cache) const
std::vector< types::global_dof_index > vertex_dofs
std::vector< types::global_dof_index > coarse_cell_to_p4est_tree_permutation
IndexSet locally_owned_dofs