31 template <
int dim,
int spacedim>
43 template <
int dim,
int spacedim>
49 const
unsigned int n_partitions) {
52 , currently_processing_create_triangulation_for_internal_usage(
false)
53 , currently_processing_prepare_coarsening_and_refinement_for_internal_usage(
59 template <
int dim,
int spacedim>
67 Assert(construction_data.comm == this->mpi_communicator,
68 ExcMessage(
"MPI communicators do not match!"));
71 settings = construction_data.settings;
78 typename ::Triangulation<dim, spacedim>::MeshSmoothing
>(
84 typename ::Triangulation<dim, spacedim>::MeshSmoothing
>(
94 if (construction_data.coarse_cell_vertices.empty())
102 auto cell = this->
begin();
104 cell->set_level_subdomain_id(
118 construction_data.coarse_cell_index_to_coarse_cell_id;
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();
128 construction_data.coarse_cell_index_to_coarse_cell_id[i], i);
131 this->coarse_cell_id_to_coarse_cell_index_vector.end(),
132 [](
const auto &a,
const auto &b) {
133 return a.first < b.first;
147 auto cell_infos = construction_data.cell_infos;
151 for (
auto &cell_info : cell_infos)
152 std::sort(cell_info.begin(),
156 const CellId a_id(a.id);
157 const CellId b_id(b.id);
159 const auto a_coarse_cell_index =
160 this->coarse_cell_id_to_coarse_cell_index(
161 a_id.get_coarse_cell_id());
162 const auto b_coarse_cell_index =
163 this->coarse_cell_id_to_coarse_cell_index(
164 b_id.get_coarse_cell_id());
171 if (a_coarse_cell_index != b_coarse_cell_index)
172 return a_coarse_cell_index < b_coarse_cell_index;
181 if (cell->is_active())
182 cell->set_subdomain_id(
185 cell->set_level_subdomain_id(
190 for (
unsigned int level = 0;
191 level < cell_infos.size() && !cell_infos[level].empty();
194 auto cell = this->
begin(level);
195 auto cell_info = cell_infos[level].begin();
196 for (; cell_info != cell_infos[level].end(); ++cell_info)
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);
220 template <
int dim,
int spacedim>
230 "You have called the overload of\n"
232 " parallel::fullydistributed::Triangulation::"
233 "create_triangulation()\n"
235 "which takes 3 arguments. This function is not yet implemented for "
236 "this class. If you have not called this function directly, it "
237 "might have been called via a function from the GridGenerator or "
238 "GridIn namespace. To set up a fully-distributed Triangulation with "
239 "these utility functions, please start by using the same process to "
240 "set up a serial Triangulation, parallel::shared::Triangulation, or "
241 "a parallel::distributed::Triangulation. Once that is complete use "
242 "the copy_triangulation() member function to finish setting up the "
243 "original fully distributed Triangulation. Alternatively, you can "
244 "use TriangulationDescription::Utilities::"
245 "create_description_from_triangulation() or "
246 "create_description_from_triangulation_in_groups() to create the "
247 "description of the local partition, and pass that description to "
248 "parallel::fullydistributed::Triangulation::create_triangulation()."));
257 template <
int dim,
int spacedim>
266 const ::Triangulation<dim, spacedim> *other_tria_ptr = &other_tria;
275 if (
dynamic_cast<const ::parallel::TriangulationBase<dim, spacedim>
276 *
>(&other_tria) ==
nullptr)
291 other_tria_ptr = &serial_tria;
306 template <
int dim,
int spacedim>
319 template <
int dim,
int spacedim>
331 template <
int dim,
int spacedim>
336 this->
signals.pre_distributed_repartition();
354 this->
signals.post_distributed_repartition();
359 template <
int dim,
int spacedim>
368 template <
int dim,
int spacedim>
374 ExcMessage(
"No coarsening and refinement is supported!"));
376 return ::Triangulation<dim, spacedim>::
377 prepare_coarsening_and_refinement();
382 template <
int dim,
int spacedim>
386 const std::size_t mem =
398 template <
int dim,
int spacedim>
410 template <
int dim,
int spacedim>
414 const
types::coarse_cell_id coarse_cell_id)
const
416 const auto coarse_cell_index = std::lower_bound(
420 [](
const std::pair<types::coarse_cell_id, unsigned int> &pair,
422 if (coarse_cell_index !=
424 return coarse_cell_index->second;
431 template <
int dim,
int spacedim>
435 const unsigned int coarse_cell_index)
const
440 const auto coarse_cell_id =
443 ExcMessage(
"You are trying to access a dummy cell!"));
444 return coarse_cell_id;
448 template <
int dim,
int spacedim>
457 if (cell->is_locally_owned())
458 this->local_cell_relations.emplace_back(
464 template <
int dim,
int spacedim>
468#ifdef DEAL_II_WITH_MPI
473 "Not all SolutionTransfer objects have been deserialized after the last call to load()."));
475 ExcMessage(
"Can not save() an empty Triangulation."));
485 unsigned int global_first_cell = 0;
487 int ierr = MPI_Exscan(&n_locally_owned_cells,
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"
520 int ierr = MPI_Info_create(&info);
523 const std::string fname_tria = filename +
"_triangulation.data";
529 MPI_MODE_CREATE | MPI_MODE_WRONLY,
534 ierr = MPI_File_set_size(fh, 0);
540 ierr = MPI_Info_free(&info);
551 std::vector<char> buffer;
555 const std::uint64_t buffer_size = buffer.size();
557 std::uint64_t offset = 0;
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);
604 template <
int dim,
int spacedim>
608#ifdef DEAL_II_WITH_MPI
610 ExcMessage(
"load() only works if the Triangulation is empty!"));
613 unsigned int version, numcpus, attached_count_fixed,
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 >>
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";
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;
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<
712 unsigned int global_first_cell = 0;
714 int ierr = MPI_Exscan(&n_locally_owned_cells,
722 global_first_cell *=
sizeof(
unsigned int);
725 ExcMessage(
"Number of global active cells differ!"));
731 attached_count_fixed + attached_count_variable;
735 this->n_global_active_cells(),
738 attached_count_fixed,
739 attached_count_variable);
753 template <
int dim,
int spacedim>
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 =
774 number_of_global_coarse_cells;
784#include "distributed/fully_distributed_tria.inst"
@ limit_level_difference_at_vertices
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
std::vector< typename internal::CellAttachedDataSerializer< dim, spacedim >::cell_relation_t > local_cell_relations
virtual void set_mesh_smoothing(const MeshSmoothing mesh_smoothing)
std::vector< Point< spacedim > > vertices
void update_periodic_face_map()
void save_attached_data(const unsigned int global_first_cell, const unsigned int global_num_cells, const std::string &file_basename) const
void load_attached_data(const unsigned int global_first_cell, const unsigned int global_num_cells, const unsigned int local_num_cells, const std::string &file_basename, const unsigned int n_attached_deserialize_fixed, const unsigned int n_attached_deserialize_variable)
internal::CellAttachedData< dim, spacedim > cell_attached_data
unsigned int n_cells() const
DistributedTriangulationBase(const MPI_Comm mpi_communicator, const typename ::Triangulation< dim, spacedim >::MeshSmoothing smooth_grid=(::Triangulation< dim, spacedim >::none), const bool check_for_distorted_cells=false)
virtual std::size_t memory_consumption() const override
virtual types::global_cell_index n_global_active_cells() const override
const MPI_Comm mpi_communicator
unsigned int n_locally_owned_active_cells() const
virtual void update_number_cache()
virtual void clear() override
virtual void execute_coarsening_and_refinement() override
virtual void update_number_cache() override
bool currently_processing_create_triangulation_for_internal_usage
TriangulationDescription::Settings settings
Triangulation(const MPI_Comm mpi_communicator)
std::vector< types::coarse_cell_id > coarse_cell_index_to_coarse_cell_id_vector
virtual types::coarse_cell_id coarse_cell_index_to_coarse_cell_id(const unsigned int coarse_cell_index) const override
bool currently_processing_prepare_coarsening_and_refinement_for_internal_usage
void copy_triangulation(const ::Triangulation< dim, spacedim > &other_tria) override
void set_partitioner(const std::function< void(::Triangulation< dim, spacedim > &, const unsigned int)> &partitioner, const TriangulationDescription::Settings &settings)
ObserverPointer< const RepartitioningPolicyTools::Base< dim, spacedim > > partitioner_distributed
void update_cell_relations()
virtual bool prepare_coarsening_and_refinement() override
virtual unsigned int coarse_cell_id_to_coarse_cell_index(const types::coarse_cell_id coarse_cell_id) const override
std::vector< std::pair< types::coarse_cell_id, unsigned int > > coarse_cell_id_to_coarse_cell_index_vector
virtual void save(const std::string &filename) const override
std::function< void(::Triangulation< dim, spacedim > &, const unsigned int)> partitioner
virtual bool is_multilevel_hierarchy_constructed() const override
void create_triangulation(const TriangulationDescription::Description< dim, spacedim > &construction_data) override
virtual void load(const std::string &filename) override
virtual std::size_t memory_consumption() const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NOT_IMPLEMENTED()
IteratorRange< active_cell_iterator > active_cell_iterators() const
IteratorRange< cell_iterator > cell_iterators() const
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcNeedsMPI()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
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)
@ construct_multigrid_hierarchy
int File_write_at_c(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status *status)
int File_read_at_c(MPI_File fh, MPI_Offset offset, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status *status)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
T max(const T &t, const MPI_Comm mpi_communicator)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
const MPI_Datatype mpi_type_id_for_type
std::size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
constexpr unsigned int invalid_unsigned_int
constexpr types::subdomain_id artificial_subdomain_id
constexpr types::coarse_cell_id invalid_coarse_cell_id
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
global_cell_index coarse_cell_id