70 Assert(construction_data.comm == this->mpi_communicator,
71 ExcMessage(
"MPI communicators do not match!"));
74 settings = construction_data.settings;
79 this->set_mesh_smoothing(
81 typename ::Triangulation<dim, spacedim>::MeshSmoothing
>(
85 this->set_mesh_smoothing(
87 typename ::Triangulation<dim, spacedim>::MeshSmoothing
>(
90 this->set_mesh_smoothing(construction_data.smoothing);
93 this->coarse_cell_id_to_coarse_cell_index_vector.clear();
94 this->coarse_cell_index_to_coarse_cell_id_vector.clear();
97 if (construction_data.coarse_cell_vertices.empty())
100 currently_processing_create_triangulation_for_internal_usage =
true;
102 currently_processing_create_triangulation_for_internal_usage =
false;
105 auto cell = this->begin();
107 cell->set_level_subdomain_id(
112 this->coarse_cell_id_to_coarse_cell_index_vector.emplace_back(
114 this->coarse_cell_index_to_coarse_cell_id_vector.emplace_back(
120 this->coarse_cell_index_to_coarse_cell_id_vector =
121 construction_data.coarse_cell_index_to_coarse_cell_id;
124 std::map<types::coarse_cell_id, unsigned int>
125 coarse_cell_id_to_coarse_cell_index_vector;
126 for (
unsigned int i = 0;
127 i < construction_data.coarse_cell_index_to_coarse_cell_id.size();
129 coarse_cell_id_to_coarse_cell_index_vector
130 [construction_data.coarse_cell_index_to_coarse_cell_id[i]] = i;
132 for (
auto i : coarse_cell_id_to_coarse_cell_index_vector)
133 this->coarse_cell_id_to_coarse_cell_index_vector.emplace_back(i);
136 currently_processing_prepare_coarsening_and_refinement_for_internal_usage =
138 currently_processing_create_triangulation_for_internal_usage =
true;
141 currently_processing_prepare_coarsening_and_refinement_for_internal_usage =
143 currently_processing_create_triangulation_for_internal_usage =
false;
146 auto cell_infos = construction_data.cell_infos;
151 std::sort(cell_info.begin(),
155 const CellId a_id(a.id);
156 const CellId b_id(b.id);
158 const auto a_coarse_cell_index =
159 this->coarse_cell_id_to_coarse_cell_index(
160 a_id.get_coarse_cell_id());
161 const auto b_coarse_cell_index =
162 this->coarse_cell_id_to_coarse_cell_index(
163 b_id.get_coarse_cell_id());
170 if (a_coarse_cell_index != b_coarse_cell_index)
171 return a_coarse_cell_index < b_coarse_cell_index;
178 for (
const auto &cell : this->cell_iterators())
180 if (cell->is_active())
181 cell->set_subdomain_id(
184 cell->set_level_subdomain_id(
189 for (
unsigned int level = 0;
193 auto cell = this->begin(
level);
198 while (cell_info->id != cell->id().template to_binary<dim>())
202 if (cell->is_active())
203 cell->set_subdomain_id(cell_info->subdomain_id);
207 construct_multigrid_hierarchy)
208 cell->set_level_subdomain_id(cell_info->level_subdomain_id);
213 this->update_number_cache();
214 this->update_cell_relations();
257 const ::Triangulation<dim, spacedim> *other_tria_ptr = &other_tria;
266 if (
dynamic_cast<const ::parallel::TriangulationBase<dim, spacedim>
267 *
>(&other_tria) ==
nullptr)
273 this->partitioner(serial_tria,
275 this->mpi_communicator));
278 if (this->is_multilevel_hierarchy_constructed())
282 other_tria_ptr = &serial_tria;
288 this->mpi_communicator,
292 this->create_triangulation(construction_data);
327 this->signals.pre_distributed_repartition();
333 this->partitioner_distributed->partition(*
this),
338 this->coarse_cell_id_to_coarse_cell_index_vector.clear();
339 this->coarse_cell_index_to_coarse_cell_id_vector.clear();
342 this->create_triangulation(construction_data);
345 this->signals.post_distributed_repartition();
404 coarse_cell_id_to_coarse_cell_index(
405 const
types::coarse_cell_id coarse_cell_id)
const
407 const auto coarse_cell_index = std::lower_bound(
408 coarse_cell_id_to_coarse_cell_index_vector.begin(),
409 coarse_cell_id_to_coarse_cell_index_vector.end(),
411 [](
const std::pair<types::coarse_cell_id, unsigned int> &pair,
413 Assert(coarse_cell_index !=
414 coarse_cell_id_to_coarse_cell_index_vector.cend(),
416 return coarse_cell_index->second;
458#ifdef DEAL_II_WITH_MPI
459 AssertThrow(this->cell_attached_data.pack_callbacks_variable.size() == 0,
463 this->cell_attached_data.n_attached_deserialize == 0,
465 "Not all SolutionTransfer objects have been deserialized after the last call to load()."));
466 Assert(this->n_cells() > 0,
467 ExcMessage(
"Can not save() an empty Triangulation."));
475 unsigned int n_locally_owned_cells = this->n_locally_owned_active_cells();
477 unsigned int global_first_cell = 0;
479 int ierr = MPI_Exscan(&n_locally_owned_cells,
484 this->mpi_communicator);
487 global_first_cell *=
sizeof(
unsigned int);
492 std::string fname = std::string(filename) +
".info";
493 std::ofstream f(fname.c_str());
494 f <<
"version nproc n_attached_fixed_size_objs n_attached_variable_size_objs n_global_active_cells"
498 << this->cell_attached_data.pack_callbacks_fixed.size() <<
" "
499 << this->cell_attached_data.pack_callbacks_variable.size() <<
" "
500 << this->n_global_active_cells() << std::endl;
504 this->save_attached_data(global_first_cell,
505 this->n_global_active_cells(),
511 int ierr = MPI_Info_create(&info);
514 const std::string fname_tria = filename +
"_triangulation.data";
518 ierr = MPI_File_open(this->mpi_communicator,
520 MPI_MODE_CREATE | MPI_MODE_WRONLY,
525 ierr = MPI_File_set_size(fh, 0);
529 ierr = MPI_Barrier(this->mpi_communicator);
531 ierr = MPI_Info_free(&info);
538 this->mpi_communicator,
542 std::vector<char> buffer;
546 const std::uint64_t buffer_size = buffer.size();
548 std::uint64_t offset = 0;
556 this->mpi_communicator);
560 ierr = MPI_File_write_at(
562 myrank *
sizeof(std::uint64_t),
570 const std::uint64_t global_position =
571 mpisize *
sizeof(std::uint64_t) + offset;
583 ierr = MPI_File_close(&fh);
599#ifdef DEAL_II_WITH_MPI
600 Assert(this->n_cells() == 0,
601 ExcMessage(
"load() only works if the Triangulation is empty!"));
604 unsigned int n_locally_owned_cells = this->n_locally_owned_active_cells();
606 unsigned int global_first_cell = 0;
608 int ierr = MPI_Exscan(&n_locally_owned_cells,
613 this->mpi_communicator);
616 global_first_cell *=
sizeof(
unsigned int);
619 unsigned int version, numcpus, attached_count_fixed,
620 attached_count_variable, n_global_active_cells;
622 std::string fname = std::string(filename) +
".info";
623 std::ifstream f(fname.c_str());
625 std::string firstline;
626 getline(f, firstline);
627 f >> version >> numcpus >> attached_count_fixed >>
628 attached_count_variable >> n_global_active_cells;
632 ExcMessage(
"Incompatible version found in .info file."));
633 Assert(this->n_global_active_cells() == n_global_active_cells,
634 ExcMessage(
"Number of global active cells differ!"));
647 int ierr = MPI_Info_create(&info);
650 const std::string fname_tria = filename +
"_triangulation.data";
653 ierr = MPI_File_open(this->mpi_communicator,
660 ierr = MPI_Info_free(&info);
664 std::uint64_t buffer_size;
666 ierr = MPI_File_read_at(
668 myrank *
sizeof(std::uint64_t),
675 std::uint64_t offset = 0;
683 this->mpi_communicator);
687 const std::uint64_t global_position =
688 mpisize *
sizeof(std::uint64_t) + offset;
691 std::vector<char> buffer(buffer_size);
701 ierr = MPI_File_close(&fh);
704 auto construction_data = ::Utilities::template unpack<
709 construction_data.
comm = this->mpi_communicator;
711 this->create_triangulation(construction_data);
716 this->cell_attached_data.n_attached_data_sets = 0;
717 this->cell_attached_data.n_attached_deserialize =
718 attached_count_fixed + attached_count_variable;
721 this->load_attached_data(global_first_cell,
722 this->n_global_active_cells(),
723 this->n_locally_owned_active_cells(),
725 attached_count_fixed,
726 attached_count_variable);
728 this->update_cell_relations();
729 this->update_periodic_face_map();
730 this->update_number_cache();
760 for (
const auto &cell : this->active_cell_iterators())
761 if (!cell->is_artificial())
762 number_of_global_coarse_cells =
763 std::max(number_of_global_coarse_cells,
764 cell->id().get_coarse_cell_id());
766 number_of_global_coarse_cells =
768 this->mpi_communicator) +
771 this->number_cache.number_of_global_coarse_cells =
772 number_of_global_coarse_cells;
Description< dim, spacedim > create_description_from_triangulation(const ::Triangulation< dim, spacedim > &tria, const MPI_Comm comm, const TriangulationDescription::Settings settings=TriangulationDescription::Settings::default_setting, const unsigned int my_rank_in=numbers::invalid_unsigned_int)