69 Assert(construction_data.comm == this->mpi_communicator,
70 ExcMessage(
"MPI communicators do not match!"));
73 settings = construction_data.settings;
78 this->set_mesh_smoothing(
80 typename ::Triangulation<dim, spacedim>::MeshSmoothing
>(
84 this->set_mesh_smoothing(
86 typename ::Triangulation<dim, spacedim>::MeshSmoothing
>(
89 this->set_mesh_smoothing(construction_data.smoothing);
92 this->coarse_cell_id_to_coarse_cell_index_vector.clear();
93 this->coarse_cell_index_to_coarse_cell_id_vector.clear();
96 if (construction_data.coarse_cell_vertices.empty())
99 currently_processing_create_triangulation_for_internal_usage =
true;
101 currently_processing_create_triangulation_for_internal_usage =
false;
104 auto cell = this->begin();
106 cell->set_level_subdomain_id(
111 this->coarse_cell_id_to_coarse_cell_index_vector.emplace_back(
113 this->coarse_cell_index_to_coarse_cell_id_vector.emplace_back(
119 this->coarse_cell_index_to_coarse_cell_id_vector =
120 construction_data.coarse_cell_index_to_coarse_cell_id;
123 std::map<types::coarse_cell_id, unsigned int>
124 coarse_cell_id_to_coarse_cell_index_vector;
125 for (
unsigned int i = 0;
126 i < construction_data.coarse_cell_index_to_coarse_cell_id.size();
128 coarse_cell_id_to_coarse_cell_index_vector
129 [construction_data.coarse_cell_index_to_coarse_cell_id[i]] = i;
131 for (
auto i : coarse_cell_id_to_coarse_cell_index_vector)
132 this->coarse_cell_id_to_coarse_cell_index_vector.emplace_back(i);
135 currently_processing_prepare_coarsening_and_refinement_for_internal_usage =
137 currently_processing_create_triangulation_for_internal_usage =
true;
140 currently_processing_prepare_coarsening_and_refinement_for_internal_usage =
142 currently_processing_create_triangulation_for_internal_usage =
false;
145 auto cell_infos = construction_data.cell_infos;
150 std::sort(cell_info.begin(),
154 const CellId a_id(a.id);
155 const CellId b_id(b.id);
157 const auto a_coarse_cell_index =
158 this->coarse_cell_id_to_coarse_cell_index(
159 a_id.get_coarse_cell_id());
160 const auto b_coarse_cell_index =
161 this->coarse_cell_id_to_coarse_cell_index(
162 b_id.get_coarse_cell_id());
169 if (a_coarse_cell_index != b_coarse_cell_index)
170 return a_coarse_cell_index < b_coarse_cell_index;
177 for (
const auto &cell : this->cell_iterators())
179 if (cell->is_active())
180 cell->set_subdomain_id(
183 cell->set_level_subdomain_id(
188 for (
unsigned int level = 0;
192 auto cell = this->begin(
level);
197 while (cell_info->id != cell->id().template to_binary<dim>())
201 if (cell->is_active())
202 cell->set_subdomain_id(cell_info->subdomain_id);
206 construct_multigrid_hierarchy)
207 cell->set_level_subdomain_id(cell_info->level_subdomain_id);
212 this->update_number_cache();
213 this->update_cell_relations();
256 const ::Triangulation<dim, spacedim> *other_tria_ptr = &other_tria;
265 if (
dynamic_cast<const ::parallel::TriangulationBase<dim, spacedim>
266 *
>(&other_tria) ==
nullptr)
272 this->partitioner(serial_tria,
274 this->mpi_communicator));
277 if (this->is_multilevel_hierarchy_constructed())
281 other_tria_ptr = &serial_tria;
287 this->mpi_communicator,
291 this->create_triangulation(construction_data);
326 this->signals.pre_distributed_repartition();
332 this->partitioner_distributed->partition(*
this),
337 this->coarse_cell_id_to_coarse_cell_index_vector.clear();
338 this->coarse_cell_index_to_coarse_cell_id_vector.clear();
341 this->create_triangulation(construction_data);
344 this->signals.post_distributed_repartition();
403 coarse_cell_id_to_coarse_cell_index(
404 const
types::coarse_cell_id coarse_cell_id)
const
406 const auto coarse_cell_index = std::lower_bound(
407 coarse_cell_id_to_coarse_cell_index_vector.begin(),
408 coarse_cell_id_to_coarse_cell_index_vector.end(),
410 [](
const std::pair<types::coarse_cell_id, unsigned int> &pair,
412 if (coarse_cell_index !=
413 coarse_cell_id_to_coarse_cell_index_vector.cend())
414 return coarse_cell_index->second;
458#ifdef DEAL_II_WITH_MPI
461 this->cell_attached_data.n_attached_deserialize == 0,
463 "Not all SolutionTransfer objects have been deserialized after the last call to load()."));
464 Assert(this->n_cells() > 0,
465 ExcMessage(
"Can not save() an empty Triangulation."));
473 unsigned int n_locally_owned_cells = this->n_locally_owned_active_cells();
475 unsigned int global_first_cell = 0;
477 int ierr = MPI_Exscan(&n_locally_owned_cells,
482 this->mpi_communicator);
485 global_first_cell *=
sizeof(
unsigned int);
490 std::string fname = std::string(filename) +
".info";
491 std::ofstream f(fname);
492 f <<
"version nproc n_attached_fixed_size_objs n_attached_variable_size_objs n_global_active_cells"
496 << this->cell_attached_data.pack_callbacks_fixed.size() <<
" "
497 << this->cell_attached_data.pack_callbacks_variable.size() <<
" "
498 << this->n_global_active_cells() << std::endl;
502 this->save_attached_data(global_first_cell,
503 this->n_global_active_cells(),
509 int ierr = MPI_Info_create(&info);
512 const std::string fname_tria = filename +
"_triangulation.data";
516 ierr = MPI_File_open(this->mpi_communicator,
518 MPI_MODE_CREATE | MPI_MODE_WRONLY,
523 ierr = MPI_File_set_size(fh, 0);
527 ierr = MPI_Barrier(this->mpi_communicator);
529 ierr = MPI_Info_free(&info);
536 this->mpi_communicator,
540 std::vector<char> buffer;
544 const std::uint64_t buffer_size = buffer.size();
546 std::uint64_t offset = 0;
554 this->mpi_communicator);
558 ierr = MPI_File_write_at(
560 myrank *
sizeof(std::uint64_t),
568 const std::uint64_t global_position =
569 mpisize *
sizeof(std::uint64_t) + offset;
581 ierr = MPI_File_close(&fh);
597#ifdef DEAL_II_WITH_MPI
598 Assert(this->n_cells() == 0,
599 ExcMessage(
"load() only works if the Triangulation is empty!"));
602 unsigned int version, numcpus, attached_count_fixed,
603 attached_count_variable, n_global_active_cells;
605 std::string fname = std::string(filename) +
".info";
606 std::ifstream f(fname);
608 std::string firstline;
609 getline(f, firstline);
610 f >> version >> numcpus >> attached_count_fixed >>
611 attached_count_variable >> n_global_active_cells;
615 ExcMessage(
"Incompatible version found in .info file."));
628 int ierr = MPI_Info_create(&info);
631 const std::string fname_tria = filename +
"_triangulation.data";
634 ierr = MPI_File_open(this->mpi_communicator,
641 ierr = MPI_Info_free(&info);
645 std::uint64_t buffer_size;
647 ierr = MPI_File_read_at(
649 myrank *
sizeof(std::uint64_t),
656 std::uint64_t offset = 0;
664 this->mpi_communicator);
668 const std::uint64_t global_position =
669 mpisize *
sizeof(std::uint64_t) + offset;
672 std::vector<char> buffer(buffer_size);
682 ierr = MPI_File_close(&fh);
685 auto construction_data = ::Utilities::template unpack<
690 construction_data.
comm = this->mpi_communicator;
692 this->create_triangulation(construction_data);
696 unsigned int n_locally_owned_cells = this->n_locally_owned_active_cells();
698 unsigned int global_first_cell = 0;
700 int ierr = MPI_Exscan(&n_locally_owned_cells,
705 this->mpi_communicator);
708 global_first_cell *=
sizeof(
unsigned int);
710 Assert(this->n_global_active_cells() == n_global_active_cells,
711 ExcMessage(
"Number of global active cells differ!"));
715 this->cell_attached_data.n_attached_data_sets = 0;
716 this->cell_attached_data.n_attached_deserialize =
717 attached_count_fixed + attached_count_variable;
720 this->load_attached_data(global_first_cell,
721 this->n_global_active_cells(),
722 this->n_locally_owned_active_cells(),
724 attached_count_fixed,
725 attached_count_variable);
727 this->update_cell_relations();
728 this->update_periodic_face_map();
729 this->update_number_cache();
759 for (
const auto &cell : this->active_cell_iterators())
760 if (!cell->is_artificial())
761 number_of_global_coarse_cells =
762 std::max(number_of_global_coarse_cells,
763 cell->id().get_coarse_cell_id());
765 number_of_global_coarse_cells =
767 this->mpi_communicator) +
770 this->number_cache.number_of_global_coarse_cells =
771 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)