67 Assert(construction_data.comm == this->mpi_communicator,
68 ExcMessage(
"MPI communicators do not match!"));
71 settings = construction_data.settings;
76 this->set_mesh_smoothing(
78 typename ::Triangulation<dim, spacedim>::MeshSmoothing
>(
82 this->set_mesh_smoothing(
84 typename ::Triangulation<dim, spacedim>::MeshSmoothing
>(
87 this->set_mesh_smoothing(construction_data.smoothing);
90 this->coarse_cell_id_to_coarse_cell_index_vector.clear();
91 this->coarse_cell_index_to_coarse_cell_id_vector.clear();
94 if (construction_data.coarse_cell_vertices.empty())
97 currently_processing_create_triangulation_for_internal_usage =
true;
99 currently_processing_create_triangulation_for_internal_usage =
false;
102 auto cell = this->
begin();
104 cell->set_level_subdomain_id(
109 this->coarse_cell_id_to_coarse_cell_index_vector.emplace_back(
111 this->coarse_cell_index_to_coarse_cell_id_vector.emplace_back(
117 this->coarse_cell_index_to_coarse_cell_id_vector =
118 construction_data.coarse_cell_index_to_coarse_cell_id;
121 this->coarse_cell_id_to_coarse_cell_index_vector.resize(
122 construction_data.coarse_cell_index_to_coarse_cell_id.size());
123 for (
unsigned int i = 0;
124 i < construction_data.coarse_cell_index_to_coarse_cell_id.size();
126 this->coarse_cell_id_to_coarse_cell_index_vector[i] =
128 construction_data.coarse_cell_index_to_coarse_cell_id[i], i);
130 std::sort(this->coarse_cell_id_to_coarse_cell_index_vector.begin(),
131 this->coarse_cell_id_to_coarse_cell_index_vector.end(),
132 [](
const auto &a,
const auto &b) {
133 return a.first < b.first;
137 currently_processing_prepare_coarsening_and_refinement_for_internal_usage =
139 currently_processing_create_triangulation_for_internal_usage =
true;
142 currently_processing_prepare_coarsening_and_refinement_for_internal_usage =
144 currently_processing_create_triangulation_for_internal_usage =
false;
147 auto cell_infos = construction_data.cell_infos;
152 std::sort(cell_info.begin(),
159 const auto a_coarse_cell_index =
160 this->coarse_cell_id_to_coarse_cell_index(
162 const auto b_coarse_cell_index =
163 this->coarse_cell_id_to_coarse_cell_index(
171 if (a_coarse_cell_index != b_coarse_cell_index)
172 return a_coarse_cell_index < b_coarse_cell_index;
179 for (
const auto &cell : this->cell_iterators())
181 if (cell->is_active())
182 cell->set_subdomain_id(
185 cell->set_level_subdomain_id(
190 for (
unsigned int level = 0;
199 while (cell_info->id != cell->id().template to_binary<dim>())
203 if (cell->is_active())
204 cell->set_subdomain_id(cell_info->subdomain_id);
208 construct_multigrid_hierarchy)
209 cell->set_level_subdomain_id(cell_info->level_subdomain_id);
214 this->update_number_cache();
215 this->update_cell_relations();
266 const ::Triangulation<dim, spacedim> *other_tria_ptr = &other_tria;
275 if (
dynamic_cast<const ::parallel::TriangulationBase<dim, spacedim>
276 *
>(&other_tria) ==
nullptr)
282 this->partitioner(serial_tria,
284 this->mpi_communicator));
287 if (this->is_multilevel_hierarchy_constructed())
291 other_tria_ptr = &serial_tria;
297 this->mpi_communicator,
301 this->create_triangulation(construction_data);
336 this->signals.pre_distributed_repartition();
342 this->partitioner_distributed->partition(*
this),
347 this->coarse_cell_id_to_coarse_cell_index_vector.clear();
348 this->coarse_cell_index_to_coarse_cell_id_vector.clear();
351 this->create_triangulation(construction_data);
354 this->signals.post_distributed_repartition();
413 coarse_cell_id_to_coarse_cell_index(
414 const
types::coarse_cell_id coarse_cell_id)
const
416 const auto coarse_cell_index = std::lower_bound(
417 coarse_cell_id_to_coarse_cell_index_vector.begin(),
418 coarse_cell_id_to_coarse_cell_index_vector.end(),
420 [](
const std::pair<types::coarse_cell_id, unsigned int> &pair,
422 if (coarse_cell_index !=
423 coarse_cell_id_to_coarse_cell_index_vector.cend())
424 return coarse_cell_index->second;
453 this->local_cell_relations.
clear();
454 this->local_cell_relations.reserve(this->n_locally_owned_active_cells());
456 for (
const auto &cell : this->active_cell_iterators())
457 if (cell->is_locally_owned())
458 this->local_cell_relations.emplace_back(
468#ifdef DEAL_II_WITH_MPI
471 this->cell_attached_data.n_attached_deserialize == 0,
473 "Not all SolutionTransfer objects have been deserialized after the last call to load()."));
474 Assert(this->n_cells() > 0,
475 ExcMessage(
"Can not save() an empty Triangulation."));
483 unsigned int n_locally_owned_cells = this->n_locally_owned_active_cells();
485 unsigned int global_first_cell = 0;
487 int ierr = MPI_Exscan(&n_locally_owned_cells,
492 this->mpi_communicator);
495 global_first_cell *=
sizeof(
unsigned int);
500 std::string fname = std::string(filename) +
".info";
501 std::ofstream f(fname);
502 f <<
"version nproc n_attached_fixed_size_objs n_attached_variable_size_objs n_global_active_cells"
507 <<
" " << this->cell_attached_data.pack_callbacks_fixed.size()
508 <<
" " << this->cell_attached_data.pack_callbacks_variable.size()
509 <<
" " << this->n_global_active_cells() << std::endl;
513 this->save_attached_data(global_first_cell,
514 this->n_global_active_cells(),
520 int ierr = MPI_Info_create(&info);
523 const std::string fname_tria = filename +
"_triangulation.data";
527 ierr = MPI_File_open(this->mpi_communicator,
529 MPI_MODE_CREATE | MPI_MODE_WRONLY,
534 ierr = MPI_File_set_size(fh, 0);
538 ierr = MPI_Barrier(this->mpi_communicator);
540 ierr = MPI_Info_free(&info);
547 this->mpi_communicator,
551 std::vector<char> buffer;
555 const std::uint64_t buffer_size = buffer.size();
557 std::uint64_t offset = 0;
565 this->mpi_communicator);
569 ierr = MPI_File_write_at(
571 myrank *
sizeof(std::uint64_t),
579 const std::uint64_t global_position =
580 mpisize *
sizeof(std::uint64_t) + offset;
592 ierr = MPI_File_close(&fh);
608#ifdef DEAL_II_WITH_MPI
609 Assert(this->n_cells() == 0,
610 ExcMessage(
"load() only works if the Triangulation is empty!"));
613 unsigned int version, numcpus, attached_count_fixed,
614 attached_count_variable, n_global_active_cells;
616 std::string fname = std::string(filename) +
".info";
617 std::ifstream f(fname);
619 std::string firstline;
620 getline(f, firstline);
621 f >> version >> numcpus >> attached_count_fixed >>
622 attached_count_variable >> n_global_active_cells;
625 const auto expected_version = ::internal::
626 CellAttachedDataSerializer<dim, spacedim>::version_number;
629 ExcMessage(
"Incompatible version found in .info file."));
642 int ierr = MPI_Info_create(&info);
645 const std::string fname_tria = filename +
"_triangulation.data";
648 ierr = MPI_File_open(this->mpi_communicator,
655 ierr = MPI_Info_free(&info);
659 std::uint64_t buffer_size;
661 ierr = MPI_File_read_at(
663 myrank *
sizeof(std::uint64_t),
670 std::uint64_t offset = 0;
678 this->mpi_communicator);
682 const std::uint64_t global_position =
683 mpisize *
sizeof(std::uint64_t) + offset;
686 std::vector<char> buffer(buffer_size);
696 ierr = MPI_File_close(&fh);
699 auto construction_data = ::Utilities::template unpack<
704 construction_data.
comm = this->mpi_communicator;
706 this->create_triangulation(construction_data);
710 unsigned int n_locally_owned_cells = this->n_locally_owned_active_cells();
712 unsigned int global_first_cell = 0;
714 int ierr = MPI_Exscan(&n_locally_owned_cells,
719 this->mpi_communicator);
722 global_first_cell *=
sizeof(
unsigned int);
724 Assert(this->n_global_active_cells() == n_global_active_cells,
725 ExcMessage(
"Number of global active cells differ!"));
729 this->cell_attached_data.n_attached_data_sets = 0;
730 this->cell_attached_data.n_attached_deserialize =
731 attached_count_fixed + attached_count_variable;
734 this->load_attached_data(global_first_cell,
735 this->n_global_active_cells(),
736 this->n_locally_owned_active_cells(),
738 attached_count_fixed,
739 attached_count_variable);
741 this->update_cell_relations();
742 this->update_periodic_face_map();
743 this->update_number_cache();
762 for (
const auto &cell : this->active_cell_iterators())
763 if (!cell->is_artificial())
764 number_of_global_coarse_cells =
765 std::max(number_of_global_coarse_cells,
766 cell->id().get_coarse_cell_id());
768 number_of_global_coarse_cells =
770 this->mpi_communicator) +
773 this->number_cache.number_of_global_coarse_cells =
774 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)