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++);
100 return next_free_dof;
105 template <
int spacedim>
112 if (dof_handler.
get_fe().dofs_per_vertex > 0)
114 for (
unsigned int vertex=0; vertex<GeometryInfo<2>::vertices_per_cell; ++vertex)
119 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_vertex; ++
d)
120 cell->set_vertex_dof_index (vertex, d, next_free_dof++);
123 if (dof_handler.
get_fe().dofs_per_line > 0)
124 for (
unsigned int side=0; side<GeometryInfo<2>::faces_per_cell; ++side)
126 const typename DoFHandler<2,spacedim>::line_iterator
127 line = cell->line(side);
134 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_line; ++
d)
135 line->set_dof_index (d, next_free_dof++);
140 if (dof_handler.
get_fe().dofs_per_quad > 0)
141 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_quad; ++
d)
142 cell->set_dof_index (d, next_free_dof++);
144 return next_free_dof;
148 template <
int spacedim>
155 if (dof_handler.
get_fe().dofs_per_vertex > 0)
157 for (
unsigned int vertex=0; vertex<GeometryInfo<3>::vertices_per_cell; ++vertex)
162 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_vertex; ++
d)
163 cell->set_vertex_dof_index (vertex, d, next_free_dof++);
166 if (dof_handler.
get_fe().dofs_per_line > 0)
167 for (
unsigned int l=0; l<GeometryInfo<3>::lines_per_cell; ++
l)
169 const typename DoFHandler<3,spacedim>::line_iterator
170 line = cell->line(l);
177 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_line; ++
d)
178 line->set_dof_index (d, next_free_dof++);
182 if (dof_handler.
get_fe().dofs_per_quad > 0)
183 for (
unsigned int q=0; q<GeometryInfo<3>::quads_per_cell; ++q)
185 const typename DoFHandler<3,spacedim>::quad_iterator
186 quad = cell->quad(q);
193 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_quad; ++
d)
194 quad->set_dof_index (d, next_free_dof++);
199 if (dof_handler.
get_fe().dofs_per_hex > 0)
200 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_hex; ++
d)
201 cell->set_dof_index (d, next_free_dof++);
203 return next_free_dof;
213 template <
int dim,
int spacedim>
226 endc = dof_handler.
end();
228 for (; cell != endc; ++cell)
233 = Implementation::distribute_dofs_on_cell (dof_handler,
238 for (cell = dof_handler.
begin_active(); cell != endc; ++cell)
239 if (!cell->is_artificial())
240 cell->update_cell_dof_indices_cache ();
242 return next_free_dof;
272 template <
int spacedim>
276 typename DoFHandler<1,spacedim>::level_cell_iterator &cell,
277 unsigned int next_free_dof)
279 const unsigned int dim = 1;
282 if (cell->
get_fe().dofs_per_vertex > 0)
283 for (
unsigned int v=0; v<GeometryInfo<1>::vertices_per_cell; ++v)
285 typename DoFHandler<dim,spacedim>::level_cell_iterator neighbor = cell->neighbor(v);
290 if (neighbor->user_flag_set() &&
291 (neighbor->level() == cell->level()))
297 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_vertex; ++
d)
298 cell->set_mg_vertex_dof_index (cell->level(), 0,
d,
299 neighbor->mg_vertex_dof_index (cell->level(), 1,
d));
301 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_vertex; ++
d)
302 cell->set_mg_vertex_dof_index (cell->level(), 1,
d,
303 neighbor->mg_vertex_dof_index (cell->level(), 0,
d));
311 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_vertex; ++
d)
312 cell->set_mg_vertex_dof_index (cell->level(), v,
d, next_free_dof++);
316 if (cell->
get_fe().dofs_per_line > 0)
317 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_line; ++
d)
318 cell->set_mg_dof_index (cell->level(),
d, next_free_dof++);
321 cell->set_user_flag ();
323 return next_free_dof;
327 template <
int spacedim>
331 typename DoFHandler<2,spacedim>::level_cell_iterator &cell,
332 unsigned int next_free_dof)
334 const unsigned int dim = 2;
335 if (cell->
get_fe().dofs_per_vertex > 0)
337 for (
unsigned int vertex=0; vertex<GeometryInfo<2>::vertices_per_cell; ++vertex)
342 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_vertex; ++
d)
343 cell->set_mg_vertex_dof_index (cell->level(), vertex,
d, next_free_dof++);
346 if (cell->
get_fe().dofs_per_line > 0)
347 for (
unsigned int side=0; side<GeometryInfo<2>::faces_per_cell; ++side)
349 typename DoFHandler<dim,spacedim>::line_iterator line = cell->line(side);
356 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_line; ++
d)
357 line->set_mg_dof_index (cell->level(),
d, next_free_dof++);
362 if (cell->
get_fe().dofs_per_quad > 0)
363 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_quad; ++
d)
364 cell->set_mg_dof_index (cell->level(),
d, next_free_dof++);
368 cell->set_user_flag ();
370 return next_free_dof;
374 template <
int spacedim>
378 typename DoFHandler<3,spacedim>::level_cell_iterator &cell,
379 unsigned int next_free_dof)
381 const unsigned int dim = 3;
382 if (cell->
get_fe().dofs_per_vertex > 0)
384 for (
unsigned int vertex=0; vertex<GeometryInfo<3>::vertices_per_cell; ++vertex)
389 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_vertex; ++
d)
390 cell->set_mg_vertex_dof_index (cell->level(), vertex,
d, next_free_dof++);
393 if (cell->
get_fe().dofs_per_line > 0)
394 for (
unsigned int l=0; l<GeometryInfo<3>::lines_per_cell; ++
l)
396 typename DoFHandler<dim,spacedim>::line_iterator line = cell->line(l);
403 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_line; ++
d)
404 line->set_mg_dof_index (cell->level(),
d, next_free_dof++);
408 if (cell->
get_fe().dofs_per_quad > 0)
409 for (
unsigned int q=0; q<GeometryInfo<3>::quads_per_cell; ++q)
411 typename DoFHandler<dim,spacedim>::quad_iterator quad = cell->quad(q);
418 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_quad; ++
d)
419 quad->set_mg_dof_index (cell->level(),
d, next_free_dof++);
424 if (cell->
get_fe().dofs_per_hex > 0)
425 for (
unsigned int d=0;
d<cell->
get_fe().dofs_per_hex; ++
d)
426 cell->set_mg_dof_index (cell->level(),
d, next_free_dof++);
431 cell->set_user_flag ();
433 return next_free_dof;
437 template <
int dim,
int spacedim>
440 distribute_dofs_on_level (
const unsigned int offset,
443 const unsigned int level)
445 const ::Triangulation<dim,spacedim> &tria
448 if (level>=tria.n_levels())
459 std::vector<bool> user_flags;
460 tria.save_user_flags(user_flags);
463 unsigned int next_free_dof = offset;
464 typename DoFHandler<dim,spacedim>::level_cell_iterator
465 cell = dof_handler.
begin(level),
466 endc = dof_handler.
end(level);
468 for (; cell != endc; ++cell)
471 (cell->level_subdomain_id() == level_subdomain_id))
473 = Implementation::distribute_mg_dofs_on_cell (dof_handler, cell, next_free_dof);
485 return next_free_dof;
508 template <
int spacedim>
511 renumber_dofs (
const std::vector<types::global_dof_index> &new_numbers,
514 const bool check_validity)
526 for (std::vector<types::global_dof_index>::iterator
530 *i = new_numbers[*i];
531 else if (check_validity)
542 for (
unsigned int level=0; level<dof_handler.
levels.size(); ++level)
543 for (std::vector<types::global_dof_index>::iterator
544 i=dof_handler.
levels[level]->dof_object.dofs.begin();
545 i!=dof_handler.
levels[level]->dof_object.dofs.end(); ++i)
547 *i = new_numbers[*i];
552 for (
typename DoFHandler<1,spacedim>::level_cell_iterator
553 cell = dof_handler.
begin();
554 cell != dof_handler.
end(); ++cell)
555 cell->update_cell_dof_indices_cache ();
558 template <
int spacedim>
561 renumber_mg_dofs (
const std::vector<::types::global_dof_index> &new_numbers,
564 const unsigned int level,
565 const bool check_validity)
573 if ((i->get_coarsest_level() <= level) &&
574 (i->get_finest_level() >= level))
575 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_vertex; ++
d)
579 i->set_index (level, d,
589 for (std::vector<types::global_dof_index>::iterator
590 i=dof_handler.mg_levels[level]->dof_object.dofs.begin();
591 i!=dof_handler.mg_levels[level]->dof_object.dofs.end();
605 template <
int spacedim>
608 renumber_dofs (
const std::vector<types::global_dof_index> &new_numbers,
611 const bool check_validity)
623 for (std::vector<types::global_dof_index>::iterator
630 else if (check_validity)
640 for (std::vector<types::global_dof_index>::iterator
641 i=dof_handler.
faces->lines.dofs.begin();
642 i!=dof_handler.
faces->lines.dofs.end(); ++i)
648 for (
unsigned int level=0; level<dof_handler.
levels.size(); ++level)
650 for (std::vector<types::global_dof_index>::iterator
651 i=dof_handler.
levels[level]->dof_object.dofs.begin();
652 i!=dof_handler.
levels[level]->dof_object.dofs.end(); ++i)
662 for (
typename DoFHandler<2,spacedim>::level_cell_iterator
663 cell = dof_handler.
begin();
664 cell != dof_handler.
end(); ++cell)
665 cell->update_cell_dof_indices_cache ();
668 template <
int spacedim>
671 renumber_mg_dofs (
const std::vector<::types::global_dof_index> &new_numbers,
674 const unsigned int level,
675 const bool check_validity)
683 if ((i->get_coarsest_level() <= level) &&
684 (i->get_finest_level() >= level))
685 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_vertex; ++
d)
689 i->set_index (level, d,
698 if (dof_handler.
get_fe().dofs_per_line > 0)
701 std::vector<bool> user_flags;
709 typename DoFHandler<2,spacedim>::level_cell_iterator cell,
710 endc = dof_handler.
end(level);
711 for (cell = dof_handler.
begin(level); cell != endc; ++cell)
712 for (
unsigned int line=0; line < GeometryInfo<2>::faces_per_cell; ++line)
713 cell->face(line)->set_user_flag();
716 cell != dof_handler.
end(); ++cell)
717 for (
unsigned int l=0; l<GeometryInfo<2>::lines_per_cell; ++
l)
718 if (cell->line(l)->user_flag_set())
720 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_line; ++
d)
724 cell->line(l)->set_mg_dof_index (level, d, ((indices.
n_elements() == 0) ?
730 cell->line(l)->clear_user_flag();
736 for (std::vector<types::global_dof_index>::iterator i=dof_handler.mg_levels[level]->dof_object.dofs.begin();
737 i!=dof_handler.mg_levels[level]->dof_object.dofs.end(); ++i)
751 template <
int spacedim>
754 renumber_dofs (
const std::vector<types::global_dof_index> &new_numbers,
757 const bool check_validity)
769 for (std::vector<types::global_dof_index>::iterator
776 else if (check_validity)
786 for (std::vector<types::global_dof_index>::iterator
787 i=dof_handler.
faces->lines.dofs.begin();
788 i!=dof_handler.
faces->lines.dofs.end(); ++i)
793 for (std::vector<types::global_dof_index>::iterator
794 i=dof_handler.
faces->quads.dofs.begin();
795 i!=dof_handler.
faces->quads.dofs.end(); ++i)
801 for (
unsigned int level=0; level<dof_handler.
levels.size(); ++level)
803 for (std::vector<types::global_dof_index>::iterator
804 i=dof_handler.
levels[level]->dof_object.dofs.begin();
805 i!=dof_handler.
levels[level]->dof_object.dofs.end(); ++i)
815 for (
typename DoFHandler<3,spacedim>::level_cell_iterator
816 cell = dof_handler.
begin();
817 cell != dof_handler.
end(); ++cell)
818 cell->update_cell_dof_indices_cache ();
821 template <
int spacedim>
824 renumber_mg_dofs (
const std::vector<::types::global_dof_index> &new_numbers,
827 const unsigned int level,
828 const bool check_validity)
836 if ((i->get_coarsest_level() <= level) &&
837 (i->get_finest_level() >= level))
838 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_vertex; ++
d)
842 i->set_index (level, d,
851 if (dof_handler.
get_fe().dofs_per_line > 0 ||
852 dof_handler.
get_fe().dofs_per_quad > 0)
855 std::vector<bool> user_flags;
862 typename DoFHandler<3,spacedim>::level_cell_iterator cell,
863 endc = dof_handler.
end(level);
864 for (cell = dof_handler.
begin(level); cell != endc; ++cell)
865 for (
unsigned int line=0; line < GeometryInfo<3>::lines_per_cell; ++line)
866 cell->line(line)->set_user_flag();
869 cell != dof_handler.
end(); ++cell)
870 for (
unsigned int l=0; l<GeometryInfo<3>::lines_per_cell; ++
l)
871 if (cell->line(l)->user_flag_set())
873 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_line; ++
d)
877 cell->line(l)->set_mg_dof_index (level, d, ((indices.
n_elements() == 0) ?
883 cell->line(l)->clear_user_flag();
889 for (cell = dof_handler.
begin(level); cell != endc; ++cell)
890 for (
unsigned int quad=0; quad < GeometryInfo<3>::quads_per_cell; ++quad)
891 cell->quad(quad)->set_user_flag();
894 cell != dof_handler.
end(); ++cell)
895 for (
unsigned int l=0; l<GeometryInfo<3>::quads_per_cell; ++
l)
896 if (cell->quad(l)->user_flag_set())
898 for (
unsigned int d=0;
d<dof_handler.
get_fe().dofs_per_quad; ++
d)
902 cell->quad(l)->set_mg_dof_index (level, d, ((indices.
n_elements() == 0) ?
908 cell->quad(l)->clear_user_flag();
915 for (std::vector<types::global_dof_index>::iterator i=dof_handler.mg_levels[level]->dof_object.dofs.begin();
916 i!=dof_handler.mg_levels[level]->dof_object.dofs.end(); ++i)
935 template <
int dim,
int spacedim>
943 template <
int dim,
int spacedim>
950 Implementation::distribute_dofs (0,
967 = std::vector<types::global_dof_index> (1,
971 = std::vector<IndexSet> (1,
973 number_cache_current = number_cache;
977 template <
int dim,
int spacedim>
981 std::vector<NumberCache> &number_caches)
const 983 std::vector<bool> user_flags;
988 for (
unsigned int level = 0; level < dof_handler.
get_triangulation().n_levels(); ++level)
992 number_caches[level].n_global_dofs = next_free_dof;
993 number_caches[level].n_locally_owned_dofs = next_free_dof;
994 number_caches[level].locally_owned_dofs = complete_index_set(next_free_dof);
995 number_caches[level].locally_owned_dofs_per_processor.resize(1);
996 number_caches[level].locally_owned_dofs_per_processor[0] = complete_index_set(next_free_dof);
997 number_caches[level].n_locally_owned_dofs_per_processor.resize(1);
998 number_caches[level].n_locally_owned_dofs_per_processor[0] = next_free_dof;
1003 template <
int dim,
int spacedim>
1010 Implementation::renumber_dofs (new_numbers,
IndexSet(0),
1030 = std::vector<types::global_dof_index> (1,
1034 = std::vector<IndexSet> (1,
1036 number_cache_current = number_cache;
1041 template <
int dim,
int spacedim>
1054 typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
1057 std::vector<types::subdomain_id> current_subdomain_ids(tr->
n_active_cells());
1060 for (
unsigned int index=0; cell != endc; cell++, index++)
1062 current_subdomain_ids[index] = cell->subdomain_id();
1063 cell->set_subdomain_id(true_subdomain_ids[index]);
1071 for (
unsigned int index=0; cell != endc; cell++, index++)
1072 cell->set_subdomain_id(true_subdomain_ids[index]);
1084 for (
unsigned int index=0; cell != endc; cell++, index++)
1085 cell->set_subdomain_id(current_subdomain_ids[index]);
1088 template <
int dim,
int spacedim>
1092 std::vector<NumberCache> &number_caches)
const 1101 template <
int dim,
int spacedim>
1109 #ifndef DEAL_II_WITH_MPI 1120 typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
1123 std::vector<types::subdomain_id> current_subdomain_ids(tr->
n_active_cells());
1126 for (
unsigned int index=0; cell != endc; cell++, index++)
1128 current_subdomain_ids[index] = cell->subdomain_id();
1129 cell->set_subdomain_id(true_subdomain_ids[index]);
1132 std::vector<types::global_dof_index> global_gathered_numbers (dof_handler.
n_dofs (), 0);
1136 if (new_numbers.size () == dof_handler.
n_dofs ())
1138 global_gathered_numbers = new_numbers;
1145 std::vector<types::global_dof_index> gathered_new_numbers (dof_handler.
n_dofs (), 0);
1152 std::vector<types::global_dof_index> new_numbers_copy (new_numbers);
1158 std::vector<int> displs(n_cpu),
1162 int cur_count = new_numbers_copy.size ();
1163 int ierr = MPI_Allgather (&cur_count, 1, MPI_INT,
1164 &rcounts[0], 1, MPI_INT,
1168 for (
unsigned int i = 0; i < n_cpu; i++)
1171 shift += rcounts[i];
1173 Assert(((
int)new_numbers_copy.size()) ==
1176 ierr = MPI_Allgatherv (&new_numbers_copy[0], new_numbers_copy.size (),
1177 DEAL_II_DOF_INDEX_MPI_TYPE,
1178 &gathered_new_numbers[0], &rcounts[0],
1180 DEAL_II_DOF_INDEX_MPI_TYPE,
1190 std::vector<unsigned int> flag_1 (dof_handler.
n_dofs (), 0),
1191 flag_2 (dof_handler.
n_dofs (), 0);
1192 for (
unsigned int i = 0; i < n_cpu; i++)
1203 global_gathered_numbers[target] = value;
1210 Assert(*std::max_element(flag_1.begin(), flag_1.end()) == 1,
1212 Assert(*std::min_element(flag_1.begin(), flag_1.end()) == 1,
1214 Assert((*std::max_element(flag_2.begin(), flag_2.end())) == 1,
1216 Assert((*std::min_element(flag_2.begin(), flag_2.end())) == 1,
1228 for (
unsigned int i = 0;
1238 for (
unsigned int index=0; cell != endc; cell++, index++)
1239 cell->set_subdomain_id(current_subdomain_ids[index]);
1245 #ifdef DEAL_II_WITH_P4EST 1266 std::vector<unsigned int> tree_index;
1267 std::vector<typename ::internal::p4est::types<dim>::quadrant> quadrants;
1268 std::vector<::types::global_dof_index> dofs;
1270 unsigned int bytes_for_buffer ()
const 1272 return (
sizeof(
unsigned int)*2 +
1273 tree_index.size() *
sizeof(
unsigned int) +
1274 quadrants.size() *
sizeof(typename ::internal::p4est
1275 ::types<dim>::quadrant) +
1279 void pack_data (std::vector<char> &buffer)
const 1281 buffer.resize(bytes_for_buffer());
1283 char *ptr = &buffer[0];
1285 const unsigned int num_cells = tree_index.size();
1286 const unsigned int num_dofs = dofs.size();
1287 std::memcpy(ptr, &num_cells,
sizeof(
unsigned int));
1288 ptr +=
sizeof(
unsigned int);
1289 std::memcpy(ptr, &num_dofs,
sizeof(
unsigned int));
1290 ptr +=
sizeof(
unsigned int);
1294 num_cells*
sizeof(
unsigned int));
1295 ptr += num_cells*
sizeof(
unsigned int);
1299 num_cells *
sizeof(typename ::internal::p4est::
1300 types<dim>::quadrant));
1301 ptr += num_cells*
sizeof(typename ::internal::p4est::types<dim>::
1310 Assert (ptr == &buffer[0]+buffer.size(),
1314 void unpack_data(
const std::vector<char> &buffer)
1316 const char *ptr = &buffer[0];
1317 unsigned int num_cells;
1318 unsigned int num_dofs;
1319 memcpy(&num_cells, ptr,
sizeof(
unsigned int));
1320 ptr+=
sizeof(
unsigned int);
1321 memcpy(&num_dofs, ptr,
sizeof(
unsigned int));
1322 ptr+=
sizeof(
unsigned int);
1324 tree_index.resize(num_cells);
1325 std::memcpy(&tree_index[0],
1327 num_cells*
sizeof(
unsigned int));
1328 ptr += num_cells*
sizeof(
unsigned int);
1330 quadrants.resize(num_cells);
1331 std::memcpy(&quadrants[0],
1333 num_cells *
sizeof(typename ::internal::p4est::
1334 types<dim>::quadrant));
1335 ptr += num_cells*
sizeof(typename ::internal::p4est::types<dim>::
1338 dofs.resize(num_dofs);
1340 std::memcpy(&dofs[0],
1345 Assert (ptr == &buffer[0]+buffer.size(),
1355 template <
int dim,
int spacedim>
1358 const unsigned int tree_index,
1359 const typename DoFHandler<dim,spacedim>::level_cell_iterator &dealii_cell,
1360 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
1361 const std::map<
unsigned int, std::set<::types::subdomain_id> > &vertices_with_ghost_neighbors,
1366 if (dealii_cell->has_children())
1368 typename ::internal::p4est::types<dim>::quadrant
1370 internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
1373 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1374 fill_dofindices_recursively<dim,spacedim>(tria,
1376 dealii_cell->child(c),
1378 vertices_with_ghost_neighbors,
1388 if (dealii_cell->user_flag_set() && !dealii_cell->is_ghost())
1395 std::set<::types::subdomain_id> send_to;
1396 for (
unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
1398 const std::map<unsigned int, std::set<::types::subdomain_id> >::const_iterator
1399 neighbor_subdomains_of_vertex
1400 = vertices_with_ghost_neighbors.find (dealii_cell->vertex_index(v));
1402 if (neighbor_subdomains_of_vertex ==
1403 vertices_with_ghost_neighbors.end())
1406 Assert(neighbor_subdomains_of_vertex->second.size()!=0,
1409 send_to.insert(neighbor_subdomains_of_vertex->second.begin(),
1410 neighbor_subdomains_of_vertex->second.end());
1413 if (send_to.size() > 0)
1418 std::vector<::types::global_dof_index>
1419 local_dof_indices (dealii_cell->
get_fe().dofs_per_cell);
1420 dealii_cell->get_dof_indices (local_dof_indices);
1422 for (std::set<::types::subdomain_id>::iterator it=send_to.begin();
1423 it!=send_to.end(); ++it)
1425 const ::types::subdomain_id subdomain = *it;
1434 typename std::map<::types::subdomain_id, typename types<dim>::cellinfo>::iterator
1436 = needs_to_get_cell.insert (std::make_pair(subdomain,
1437 typename types<dim>::cellinfo()))
1440 p->second.tree_index.push_back(tree_index);
1441 p->second.quadrants.push_back(p4est_cell);
1443 p->second.dofs.push_back(dealii_cell->
get_fe().dofs_per_cell);
1444 p->second.dofs.insert(p->second.dofs.end(),
1445 local_dof_indices.begin(),
1446 local_dof_indices.end());
1453 template <
int dim,
int spacedim>
1455 get_mg_dofindices_recursively (
1457 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
1458 const typename DoFHandler<dim,spacedim>::level_cell_iterator &dealii_cell,
1459 const typename ::internal::p4est::types<dim>::quadrant &quadrant,
1460 typename types<dim>::cellinfo &cell_info)
1462 if (internal::p4est::quadrant_is_equal<dim>(p4est_cell, quadrant))
1468 std::vector<::types::global_dof_index>
1469 local_dof_indices (dealii_cell->
get_fe().dofs_per_cell);
1470 dealii_cell->get_mg_dof_indices (local_dof_indices);
1472 cell_info.dofs.push_back(dealii_cell->
get_fe().dofs_per_cell);
1473 cell_info.dofs.insert(cell_info.dofs.end(),
1474 local_dof_indices.begin(),
1475 local_dof_indices.end());
1479 if (! dealii_cell->has_children())
1482 if (! internal::p4est::quadrant_is_ancestor<dim> (p4est_cell, quadrant))
1485 typename ::internal::p4est::types<dim>::quadrant
1487 internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
1489 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1490 get_mg_dofindices_recursively<dim,spacedim> (tria, p4est_child[c],
1491 dealii_cell->child(c),
1492 quadrant, cell_info);
1496 template <
int dim,
int spacedim>
1499 const unsigned int tree_index,
1500 const typename DoFHandler<dim,spacedim>::level_cell_iterator &dealii_cell,
1501 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
1505 if (dealii_cell->has_children())
1507 typename ::internal::p4est::types<dim>::quadrant
1509 internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
1512 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1513 find_marked_mg_ghost_cells_recursively<dim,spacedim>(tria,
1515 dealii_cell->child(c),
1517 neighbor_cell_list);
1522 typename types<dim>::cellinfo &cell_info = neighbor_cell_list[dealii_cell->level_subdomain_id()];
1524 cell_info.tree_index.push_back(tree_index);
1525 cell_info.quadrants.push_back(p4est_cell);
1530 template <
int dim,
int spacedim>
1532 set_mg_dofindices_recursively (
1534 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
1535 const typename DoFHandler<dim,spacedim>::level_cell_iterator &dealii_cell,
1536 const typename ::internal::p4est::types<dim>::quadrant &quadrant,
1539 if (internal::p4est::quadrant_is_equal<dim>(p4est_cell, quadrant))
1544 std::vector<::types::global_dof_index>
1545 dof_indices (dealii_cell->
get_fe().dofs_per_cell);
1546 dealii_cell->get_mg_dof_indices(dof_indices);
1548 bool complete =
true;
1549 for (
unsigned int i=0; i<dof_indices.size(); ++i)
1552 Assert((dof_indices[i] ==
1555 (dof_indices[i]==dofs[i]),
1557 dof_indices[i]=dofs[i];
1564 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1565 (dealii_cell)->set_user_flag();
1568 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1569 (dealii_cell)->clear_user_flag();
1572 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1573 (dealii_cell)->set_mg_dof_indices(dof_indices);
1577 if (! dealii_cell->has_children())
1580 if (! internal::p4est::quadrant_is_ancestor<dim> (p4est_cell, quadrant))
1583 typename ::internal::p4est::types<dim>::quadrant
1585 internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
1587 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1588 set_mg_dofindices_recursively<dim,spacedim> (tria, p4est_child[c],
1589 dealii_cell->child(c),
1596 template <
int dim,
int spacedim>
1600 const std::vector<::types::global_dof_index> &coarse_cell_to_p4est_tree_permutation,
1601 const std::vector<::types::global_dof_index> &p4est_tree_to_coarse_cell_permutation)
1605 typedef std::map<::types::subdomain_id, typename types<dim>::cellinfo> cellmap_t;
1606 cellmap_t neighbor_cell_list;
1607 for (std::set<::types::subdomain_id>::iterator it = level_ghost_owners.begin();
1608 it != level_ghost_owners.end();
1610 neighbor_cell_list.insert(std::make_pair(*it,
typename types<dim>::cellinfo()));
1612 for (
typename DoFHandler<dim,spacedim>::level_cell_iterator
1613 cell = dof_handler.
begin(0);
1614 cell != dof_handler.
end(0);
1617 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
1618 internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
1620 find_marked_mg_ghost_cells_recursively<dim,spacedim>
1622 coarse_cell_to_p4est_tree_permutation[cell->index()],
1625 neighbor_cell_list);
1630 std::vector<std::vector<char> > sendbuffers (level_ghost_owners.size());
1631 std::vector<MPI_Request> requests (level_ghost_owners.size());
1634 for (
typename cellmap_t::iterator it = neighbor_cell_list.begin();
1635 it!=neighbor_cell_list.end();
1645 it->second.pack_data (sendbuffers[idx]);
1646 const int ierr = MPI_Isend(sendbuffers[idx].data(), sendbuffers[idx].size(),
1647 MPI_BYTE, it->first,
1648 1100101, tria.get_communicator(), &requests[idx]);
1653 std::vector<std::vector<char> > reply_buffers (level_ghost_owners.size());
1654 std::vector<MPI_Request> reply_requests (level_ghost_owners.size());
1656 for (
unsigned int idx=0; idx<level_ghost_owners.size(); ++idx)
1658 std::vector<char> receive;
1659 typename types<dim>::cellinfo cellinfo;
1663 int ierr = MPI_Probe(MPI_ANY_SOURCE, 1100101, tria.get_communicator(), &status);
1665 ierr = MPI_Get_count(&status, MPI_BYTE, &len);
1667 receive.resize(len);
1669 char *ptr = &receive[0];
1670 ierr = MPI_Recv(ptr, len, MPI_BYTE, status.MPI_SOURCE, status.MPI_TAG,
1671 tria.get_communicator(), &status);
1674 cellinfo.unpack_data(receive);
1677 for (
unsigned int c=0; c<cellinfo.tree_index.size(); ++c)
1679 typename DoFHandler<dim,spacedim>::level_cell_iterator
1682 p4est_tree_to_coarse_cell_permutation[cellinfo.tree_index[c]],
1685 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
1686 internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
1688 get_mg_dofindices_recursively<dim,spacedim> (tria,
1691 cellinfo.quadrants[c],
1696 cellinfo.pack_data(reply_buffers[idx]);
1697 ierr = MPI_Isend(&(reply_buffers[idx])[0], reply_buffers[idx].size(),
1698 MPI_BYTE, status.MPI_SOURCE,
1699 1100102, tria.get_communicator(), &reply_requests[idx]);
1704 for (
unsigned int idx=0; idx<level_ghost_owners.size(); ++idx)
1706 std::vector<char> receive;
1707 typename types<dim>::cellinfo cellinfo;
1711 int ierr = MPI_Probe(MPI_ANY_SOURCE, 1100102, tria.get_communicator(), &status);
1713 ierr = MPI_Get_count(&status, MPI_BYTE, &len);
1715 receive.resize(len);
1717 char *ptr = &receive[0];
1718 ierr = MPI_Recv(ptr, len, MPI_BYTE, status.MPI_SOURCE, status.MPI_TAG,
1719 tria.get_communicator(), &status);
1722 cellinfo.unpack_data(receive);
1723 if (cellinfo.tree_index.size()==0)
1728 for (
unsigned int c=0; c<cellinfo.tree_index.size(); ++c, dofs+=1+dofs[0])
1730 typename DoFHandler<dim,spacedim>::level_cell_iterator
1733 p4est_tree_to_coarse_cell_permutation[cellinfo.tree_index[c]],
1736 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
1737 internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
1741 set_mg_dofindices_recursively<dim,spacedim> (tria,
1744 cellinfo.quadrants[c],
1751 if (requests.size() > 0)
1753 const int ierr = MPI_Waitall(requests.size(), &requests[0], MPI_STATUSES_IGNORE);
1756 if (reply_requests.size() > 0)
1758 const int ierr = MPI_Waitall(reply_requests.size(), &reply_requests[0], MPI_STATUSES_IGNORE);
1765 template <
int spacedim>
1769 const std::vector<::types::global_dof_index> &,
1770 const std::vector<::types::global_dof_index> &)
1778 template <
int dim,
int spacedim>
1780 set_dofindices_recursively (
1782 const typename ::internal::p4est::types<dim>::quadrant &p4est_cell,
1783 const typename DoFHandler<dim,spacedim>::level_cell_iterator &dealii_cell,
1784 const typename ::internal::p4est::types<dim>::quadrant &quadrant,
1787 if (internal::p4est::quadrant_is_equal<dim>(p4est_cell, quadrant))
1793 std::vector<::types::global_dof_index>
1794 dof_indices (dealii_cell->
get_fe().dofs_per_cell);
1795 dealii_cell->update_cell_dof_indices_cache();
1796 dealii_cell->get_dof_indices(dof_indices);
1798 bool complete =
true;
1799 for (
unsigned int i=0; i<dof_indices.size(); ++i)
1802 Assert((dof_indices[i] ==
1805 (dof_indices[i]==dofs[i]),
1807 dof_indices[i]=dofs[i];
1814 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1815 (dealii_cell)->set_user_flag();
1818 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1819 (dealii_cell)->clear_user_flag();
1822 <
typename DoFHandler<dim,spacedim>::level_cell_iterator &>
1823 (dealii_cell)->set_dof_indices(dof_indices);
1828 if (! dealii_cell->has_children())
1831 if (! internal::p4est::quadrant_is_ancestor<dim> (p4est_cell, quadrant))
1834 typename ::internal::p4est::types<dim>::quadrant
1836 internal::p4est::init_quadrant_children<dim>(p4est_cell, p4est_child);
1838 for (
unsigned int c=0; c<GeometryInfo<dim>::max_children_per_cell; ++c)
1839 set_dofindices_recursively<dim,spacedim> (tria, p4est_child[c],
1840 dealii_cell->child(c),
1846 template <
int spacedim>
1848 communicate_dof_indices_on_marked_cells
1850 const std::map<
unsigned int, std::set<::types::subdomain_id> > &,
1851 const std::vector<::types::global_dof_index> &,
1852 const std::vector<::types::global_dof_index> &)
1859 template <
int dim,
int spacedim>
1861 communicate_dof_indices_on_marked_cells
1863 const std::map<
unsigned int, std::set<::types::subdomain_id> > &vertices_with_ghost_neighbors,
1864 const std::vector<::types::global_dof_index> &coarse_cell_to_p4est_tree_permutation,
1865 const std::vector<::types::global_dof_index> &p4est_tree_to_coarse_cell_permutation)
1867 #ifndef DEAL_II_WITH_P4EST 1868 (void)vertices_with_ghost_neighbors;
1881 std::map<::types::subdomain_id, typename types<dim>::cellinfo>
1883 cellmap_t needs_to_get_cells;
1885 for (
typename DoFHandler<dim,spacedim>::level_cell_iterator
1886 cell = dof_handler.
begin(0);
1887 cell != dof_handler.
end(0);
1890 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
1891 internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
1893 fill_dofindices_recursively<dim,spacedim>
1895 coarse_cell_to_p4est_tree_permutation[cell->index()],
1898 vertices_with_ghost_neighbors,
1899 needs_to_get_cells);
1904 std::vector<std::vector<char> > sendbuffers (needs_to_get_cells.size());
1905 std::vector<std::vector<char> >::iterator buffer = sendbuffers.begin();
1906 std::vector<MPI_Request> requests (needs_to_get_cells.size());
1910 for (
typename cellmap_t::iterator it=needs_to_get_cells.begin();
1911 it!=needs_to_get_cells.end();
1912 ++it, ++buffer, ++idx)
1914 const unsigned int num_cells = it->second.tree_index.size();
1927 it->second.pack_data (*buffer);
1928 const int ierr = MPI_Isend(&(*buffer)[0], buffer->size(),
1929 MPI_BYTE, it->first,
1930 123, tr->get_communicator(), &requests[idx]);
1938 std::set<::types::subdomain_id> senders;
1940 std::vector<::types::global_dof_index> local_dof_indices;
1942 cell, endc = dof_handler.
end();
1944 for (cell = dof_handler.
begin_active(); cell != endc; ++cell)
1945 if (!cell->is_artificial())
1947 if (cell->is_ghost())
1949 if (cell->user_flag_set())
1950 senders.insert(cell->subdomain_id());
1954 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
1955 cell->get_dof_indices (local_dof_indices);
1956 if (local_dof_indices.end() !=
1957 std::find (local_dof_indices.begin(),
1958 local_dof_indices.end(),
1960 cell->set_user_flag();
1962 cell->clear_user_flag();
1970 std::vector<char> receive;
1971 for (
unsigned int i=0; i<senders.size(); ++i)
1975 int ierr = MPI_Probe(MPI_ANY_SOURCE, 123, tr->get_communicator(), &status);
1977 ierr = MPI_Get_count(&status, MPI_BYTE, &len);
1979 receive.resize(len);
1981 char *ptr = &receive[0];
1982 ierr = MPI_Recv(ptr, len, MPI_BYTE, status.MPI_SOURCE, status.MPI_TAG,
1983 tr->get_communicator(), &status);
1986 typename types<dim>::cellinfo cellinfo;
1987 cellinfo.unpack_data(receive);
1988 unsigned int cells = cellinfo.tree_index.size();
1993 for (
unsigned int c=0; c<cells; ++c, dofs+=1+dofs[0])
1995 typename DoFHandler<dim,spacedim>::level_cell_iterator
1998 p4est_tree_to_coarse_cell_permutation[cellinfo.tree_index[c]],
2001 typename ::internal::p4est::types<dim>::quadrant p4est_coarse_cell;
2002 internal::p4est::init_coarse_quadrant<dim>(p4est_coarse_cell);
2006 set_dofindices_recursively<dim,spacedim> (*tr,
2009 cellinfo.quadrants[c],
2016 if (requests.size() > 0)
2018 const int ierr = MPI_Waitall(requests.size(), &requests[0], MPI_STATUSES_IGNORE);
2026 unsigned int sum_send=0;
2027 unsigned int sum_recv=0;
2028 unsigned int sent=needs_to_get_cells.size();
2029 unsigned int recv=senders.size();
2031 int ierr = MPI_Allreduce(&sent, &sum_send, 1, MPI_UNSIGNED, MPI_SUM, tr->get_communicator());
2033 ierr = MPI_Allreduce(&recv, &sum_recv, 1, MPI_UNSIGNED, MPI_SUM, tr->get_communicator());
2042 cell, endc = dof_handler.
end();
2044 for (cell = dof_handler.
begin_active(); cell != endc; ++cell)
2045 if (!cell->is_artificial())
2046 cell->update_cell_dof_indices_cache();
2065 const int ierr = MPI_Barrier(tr->get_communicator());
2078 #endif // DEAL_II_WITH_P4EST 2082 template <
int dim,
int spacedim>
2090 #ifndef DEAL_II_WITH_P4EST 2106 const ::types::global_dof_index n_initial_local_dofs =
2113 std::vector<::types::global_dof_index> renumbering(n_initial_local_dofs);
2114 for (
unsigned int i=0; i<renumbering.size(); ++i)
2118 std::vector<::types::global_dof_index> local_dof_indices;
2122 endc = dof_handler.
end();
2124 for (; cell != endc; ++cell)
2125 if (cell->is_ghost() &&
2140 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2141 cell->get_dof_indices (local_dof_indices);
2142 for (
unsigned int i=0; i<cell->
get_fe().dofs_per_cell; ++i)
2144 renumbering[local_dof_indices[i]]
2152 for (std::vector<::types::global_dof_index>::iterator it=renumbering.begin();
2153 it!=renumbering.end(); ++it)
2162 1, DEAL_II_DOF_INDEX_MPI_TYPE,
2164 1, DEAL_II_DOF_INDEX_MPI_TYPE,
2168 const ::types::global_dof_index
2169 shift = std::accumulate (number_cache
2170 .n_locally_owned_dofs_per_processor.begin(),
2175 for (std::vector<::types::global_dof_index>::iterator it=renumbering.begin();
2176 it!=renumbering.end(); ++it)
2185 Implementation::renumber_dofs (renumbering,
IndexSet(0),
2186 dof_handler,
false);
2191 = std::accumulate (number_cache
2192 .n_locally_owned_dofs_per_processor.begin(),
2207 for (
unsigned int i=0; i<n_cpus; ++i)
2234 std::vector<bool> user_flags;
2240 cell != dof_handler.
end(); ++cell)
2241 if (!cell->is_artificial())
2242 cell->set_user_flag();
2248 std::map<unsigned int, std::set<::types::subdomain_id> >
2249 vertices_with_ghost_neighbors;
2259 communicate_dof_indices_on_marked_cells (dof_handler,
2260 vertices_with_ghost_neighbors,
2262 tr->p4est_tree_to_coarse_cell_permutation);
2264 communicate_dof_indices_on_marked_cells (dof_handler,
2265 vertices_with_ghost_neighbors,
2267 tr->p4est_tree_to_coarse_cell_permutation);
2274 std::vector<::types::global_dof_index> local_dof_indices;
2277 cell != dof_handler.
end(); ++cell)
2278 if (!cell->is_artificial())
2280 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2281 cell->get_dof_indices (local_dof_indices);
2282 if (local_dof_indices.end() !=
2283 std::find (local_dof_indices.begin(),
2284 local_dof_indices.end(),
2287 if (cell->is_ghost())
2299 #endif // DEAL_II_WITH_P4EST 2301 number_cache_current = number_cache;
2306 template <
int dim,
int spacedim>
2310 std::vector<NumberCache> &number_caches)
const 2312 #ifndef DEAL_II_WITH_P4EST 2314 (void)number_caches;
2326 ExcMessage(
"Multigrid DoFs can only be distributed on a parallel Triangulation if the flag construct_multigrid_hierarchy is set in the constructor."));
2334 for (
unsigned int level = 0; level < n_levels; ++level)
2340 const unsigned int n_initial_local_dofs =
2346 std::vector<::types::global_dof_index> renumbering(n_initial_local_dofs);
2350 if (level<tr->n_levels())
2352 std::vector<::types::global_dof_index> local_dof_indices;
2354 typename DoFHandler<dim,spacedim>::level_cell_iterator
2355 cell = dof_handler.
begin(level),
2356 endc = dof_handler.
end(level);
2358 for (; cell != endc; ++cell)
2374 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2375 cell->get_mg_dof_indices (local_dof_indices);
2376 for (
unsigned int i=0; i<cell->
get_fe().dofs_per_cell; ++i)
2378 renumbering[local_dof_indices[i]]
2386 for (std::vector<::types::global_dof_index>::iterator it=renumbering.begin();
2387 it!=renumbering.end(); ++it)
2396 1, DEAL_II_DOF_INDEX_MPI_TYPE,
2398 1, DEAL_II_DOF_INDEX_MPI_TYPE,
2402 const ::types::global_dof_index
2403 shift = std::accumulate (number_cache
2404 .n_locally_owned_dofs_per_processor.begin(),
2409 for (std::vector<::types::global_dof_index>::iterator it=renumbering.begin();
2410 it!=renumbering.end(); ++it)
2419 Implementation::renumber_mg_dofs (renumbering,
IndexSet(0),
2420 dof_handler, level,
false);
2425 = std::accumulate (number_cache
2426 .n_locally_owned_dofs_per_processor.begin(),
2441 for (
unsigned int i=0; i<n_cpus; ++i)
2473 std::vector<bool> user_flags;
2479 typename DoFHandler<dim,spacedim>::level_cell_iterator
2480 cell, endc = dof_handler.
end();
2481 for (cell = dof_handler.
begin(); cell != endc; ++cell)
2482 if (cell->level_subdomain_id() != ::numbers::artificial_subdomain_id
2483 && !cell->is_locally_owned_on_level())
2484 cell->set_user_flag();
2490 communicate_mg_ghost_cells(*tr,
2493 tr->p4est_tree_to_coarse_cell_permutation);
2502 communicate_mg_ghost_cells(*tr,
2505 tr->p4est_tree_to_coarse_cell_permutation);
2510 typename DoFHandler<dim,spacedim>::level_cell_iterator
2511 cell, endc = dof_handler.
end();
2512 for (cell = dof_handler.
begin(); cell != endc; ++cell)
2513 if (cell->level_subdomain_id() != ::numbers::artificial_subdomain_id
2514 && !cell->is_locally_owned_on_level())
2528 std::vector<::types::global_dof_index> local_dof_indices;
2529 typename DoFHandler<dim,spacedim>::level_cell_iterator
2530 cell, endc = dof_handler.
end();
2532 for (cell = dof_handler.
begin(); cell != endc; ++cell)
2533 if (cell->level_subdomain_id() != ::numbers::artificial_subdomain_id)
2535 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2536 cell->get_mg_dof_indices (local_dof_indices);
2537 if (local_dof_indices.end() !=
2538 std::find (local_dof_indices.begin(),
2539 local_dof_indices.end(),
2548 #endif // DEAL_II_WITH_P4EST 2552 template <
int dim,
int spacedim>
2567 #ifndef DEAL_II_WITH_P4EST 2578 number_cache.locally_owned_dofs =
IndexSet (dof_handler.
n_dofs());
2581 std::vector<::types::global_dof_index> new_numbers_sorted (new_numbers);
2582 std::sort(new_numbers_sorted.begin(), new_numbers_sorted.end());
2583 std::vector<::types::global_dof_index>::const_iterator it = new_numbers_sorted.begin();
2584 const unsigned int n_blocks = dof_handler.
get_fe().n_blocks();
2585 std::vector<std::pair<::types::global_dof_index,unsigned int> > block_indices(n_blocks);
2586 block_indices[0].first = *it++;
2587 block_indices[0].second = 1;
2588 unsigned int current_block = 0, n_filled_blocks = 1;
2589 for ( ; it != new_numbers_sorted.end(); ++it)
2595 for (
unsigned int i=0; i<n_filled_blocks; ++i)
2596 if (*it == block_indices[current_block].first
2597 +block_indices[current_block].second)
2599 block_indices[current_block].second++;
2605 if (current_block == n_filled_blocks-1)
2616 if (n_filled_blocks < n_blocks)
2618 block_indices[n_filled_blocks].first = *it;
2619 block_indices[n_filled_blocks].second = 1;
2620 current_block = n_filled_blocks;
2632 unsigned int sum = 0;
2633 for (
unsigned int i=0; i<n_filled_blocks; ++i)
2634 sum += block_indices[i].second;
2635 if (sum == new_numbers.size())
2636 for (
unsigned int i=0; i<n_filled_blocks; ++i)
2637 number_cache.locally_owned_dofs.add_range (block_indices[i].first,
2638 block_indices[i].first+
2639 block_indices[i].second);
2641 number_cache.locally_owned_dofs.add_indices(new_numbers_sorted.begin(),
2642 new_numbers_sorted.end());
2646 number_cache.locally_owned_dofs.compress();
2647 Assert (number_cache.locally_owned_dofs.n_elements() == new_numbers.size(),
2651 Assert (number_cache.locally_owned_dofs.n_elements() ==
2660 std::vector<::types::global_dof_index> local_dof_indices;
2664 endc = dof_handler.
end();
2666 for (; cell != endc; ++cell)
2667 if (!cell->is_artificial())
2669 local_dof_indices.resize (cell->
get_fe().dofs_per_cell);
2670 cell->get_dof_indices (local_dof_indices);
2671 for (
unsigned int i=0; i<cell->
get_fe().dofs_per_cell; ++i)
2679 local_dof_indices[i]
2684 cell->set_dof_indices (local_dof_indices);
2691 Implementation::renumber_dofs (new_numbers,
2704 std::vector<bool> user_flags;
2710 cell, endc = dof_handler.
end();
2711 for (cell = dof_handler.
begin_active(); cell != endc; ++cell)
2712 if (!cell->is_artificial())
2713 cell->set_user_flag();
2717 std::map<unsigned int, std::set<::types::subdomain_id> >
2718 vertices_with_ghost_neighbors;
2725 communicate_dof_indices_on_marked_cells (dof_handler,
2726 vertices_with_ghost_neighbors,
2728 tr->p4est_tree_to_coarse_cell_permutation);
2730 communicate_dof_indices_on_marked_cells (dof_handler,
2731 vertices_with_ghost_neighbors,
2733 tr->p4est_tree_to_coarse_cell_permutation);
2741 std::ostringstream oss;
2742 number_cache.locally_owned_dofs.block_write(oss);
2743 std::string oss_str=oss.str();
2744 std::vector<char> my_data(oss_str.begin(), oss_str.end());
2745 unsigned int my_size = oss_str.size();
2748 const unsigned int max_size
2753 my_data.resize(max_size);
2755 std::vector<char> buffer(max_size*n_cpus);
2756 const int ierr = MPI_Allgather(&my_data[0], max_size, MPI_BYTE,
2757 &buffer[0], max_size, MPI_BYTE,
2761 number_cache.locally_owned_dofs_per_processor.resize (n_cpus);
2762 number_cache.n_locally_owned_dofs_per_processor.resize (n_cpus);
2763 for (
unsigned int i=0; i<n_cpus; ++i)
2765 std::stringstream strstr;
2766 strstr.write(&buffer[i*max_size],max_size);
2770 number_cache.locally_owned_dofs_per_processor[i]
2771 .block_read(strstr);
2772 number_cache.n_locally_owned_dofs_per_processor[i]
2773 = number_cache.locally_owned_dofs_per_processor[i].n_elements();
2776 number_cache.n_global_dofs
2777 = std::accumulate (number_cache
2778 .n_locally_owned_dofs_per_processor.begin(),
2780 .n_locally_owned_dofs_per_processor.end(),
2787 number_cache_current = number_cache;
2797 #include "dof_handler_policy.inst" 2800 DEAL_II_NAMESPACE_CLOSE
unsigned int n_active_cells() const
std::vector< MGVertexDoFs > mg_vertex_dofs
void fill_vertices_with_ghost_neighbors(std::map< unsigned int, std::set<::types::subdomain_id > > &vertices_with_ghost_neighbors)
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
const std::vector< types::subdomain_id > & get_true_subdomain_ids_of_cells() 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)
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)
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
static ::ExceptionBase & ExcMessage(std::string arg1)
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
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
virtual void distribute_dofs(::DoFHandler< dim, spacedim > &dof_handler, NumberCache &number_cache) const
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
const std::set< types::subdomain_id > & level_ghost_owners() const
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
#define AssertThrowMPI(error_code)
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
static ::ExceptionBase & ExcNotImplemented()
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
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
static ::ExceptionBase & ExcInternalError()
IndexSet locally_owned_dofs