19#include <deal.II/base/mpi.templates.h>
46 template <
int dim,
int spacedim>
52 const bool check_for_distorted_cells)
54 check_for_distorted_cells)
55 , mpi_communicator(mpi_communicator)
56 , my_subdomain(
Utilities::MPI::this_mpi_process(
this->mpi_communicator))
57 , n_subdomains(
Utilities::MPI::n_mpi_processes(
this->mpi_communicator))
59#ifndef DEAL_II_WITH_MPI
66 template <
int dim,
int spacedim>
71#ifndef DEAL_II_WITH_MPI
77 if (const ::parallel::TriangulationBase<dim, spacedim> *
other_tria_x =
78 dynamic_cast<const ::parallel::TriangulationBase<dim, spacedim>
91 template <
int dim,
int spacedim>
100 number_cache.n_global_active_cells) +
107 template <
int dim,
int spacedim>
119 template <
int dim,
int spacedim>
122 : n_locally_owned_active_cells(0)
123 , number_of_global_coarse_cells(0)
129 template <
int dim,
int spacedim>
139 template <
int dim,
int spacedim>
148 template <
int dim,
int spacedim>
153 return number_cache.n_global_active_cells;
158 template <
int dim,
int spacedim>
162 return mpi_communicator;
167#ifdef DEAL_II_WITH_MPI
168 template <
int dim,
int spacedim>
173 number_cache.level_ghost_owners.clear();
174 number_cache.n_locally_owned_active_cells = 0;
176 if (this->n_levels() == 0)
183 number_cache.n_global_active_cells = 0;
184 number_cache.n_global_levels = 0;
191 for (
const auto &cell : this->active_cell_iterators())
192 if (cell->is_ghost())
193 number_cache.ghost_owners.insert(cell->subdomain_id());
195 Assert(number_cache.ghost_owners.size() <
200 if (this->n_levels() > 0)
201 number_cache.n_locally_owned_active_cells = std::count_if(
202 this->begin_active(),
205 [](
const auto &i) {
return i.is_locally_owned(); });
207 number_cache.n_locally_owned_active_cells = 0;
211 number_cache.n_global_active_cells =
213 number_cache.n_locally_owned_active_cells),
214 this->mpi_communicator);
216 number_cache.n_global_levels =
221 if (this->is_multilevel_hierarchy_constructed() ==
true)
223 number_cache.level_ghost_owners.clear();
226 if (this->n_levels() == 0)
230 for (
const auto &cell :
this->cell_iterators())
231 if (cell->level_subdomain_id() !=
numbers::artificial_subdomain_id &&
232 cell->level_subdomain_id() !=
this->locally_owned_subdomain())
233 this->number_cache.level_ghost_owners.insert(
234 cell->level_subdomain_id());
247 std::vector<MPI_Request> requests(
248 this->number_cache.level_ghost_owners.size());
249 unsigned int dummy = 0;
252 for (
const auto &
it : this->number_cache.level_ghost_owners)
259 this->mpi_communicator,
265 for (
const auto &
it : this->number_cache.level_ghost_owners)
273 this->mpi_communicator,
278 if (requests.size() > 0)
291 Assert(this->number_cache.level_ghost_owners.size() <
296 this->number_cache.number_of_global_coarse_cells = this->n_cells(0);
299 this->reset_global_cell_indices();
304 template <
int dim,
int spacedim>
313 template <
int dim,
int spacedim>
325 for (
const auto &i : this->reference_cells)
331 this->mpi_communicator);
334 this->reference_cells.clear();
336 this->reference_cells.emplace_back(
342 template <
int dim,
int spacedim>
352 template <
int dim,
int spacedim>
354 const std::set<types::subdomain_id>
357 return number_cache.ghost_owners;
362 template <
int dim,
int spacedim>
364 const std::set<types::subdomain_id>
367 return number_cache.level_ghost_owners;
372 template <
int dim,
int spacedim>
375 get_boundary_ids()
const
379 this->mpi_communicator);
384 template <
int dim,
int spacedim>
387 get_manifold_ids()
const
391 this->mpi_communicator);
396 template <
int dim,
int spacedim>
400#ifndef DEAL_II_WITH_MPI
406 if (
pst->with_artificial_cells() ==
false)
412 std::vector<unsigned int>
cell_counter(n_subdomains + 1);
415 for (
const auto &cell : this->active_cell_iterators())
419 for (
unsigned int i = 0; i < n_subdomains; ++i)
428 number_cache.active_cell_index_partitioner =
429 std::make_shared<const Utilities::MPI::Partitioner>(
432 this->mpi_communicator);
435 for (
const auto &cell : this->active_cell_iterators())
436 cell->set_global_active_cell_index(
439 Assert(this->is_multilevel_hierarchy_constructed() ==
false,
447 this->n_locally_owned_active_cells();
458 this->mpi_communicator);
463 std::pair<types::global_cell_index, types::global_cell_index>
my_range;
466 for (
const auto &cell :
this->active_cell_iterators())
467 if (cell->is_locally_owned())
468 cell->set_global_active_cell_index(
cell_index++);
476 GridTools::exchange_cell_data_to_ghosts<types::global_cell_index>(
478 [](
const auto &cell) {
return cell->global_active_cell_index(); },
480 cell->set_global_active_cell_index(
id);
489 IndexSet is_ghost(this->n_global_active_cells());
492 number_cache.active_cell_index_partitioner =
493 std::make_shared<const Utilities::MPI::Partitioner>(
494 is_local, is_ghost, this->mpi_communicator);
497 if (this->is_multilevel_hierarchy_constructed() ==
true)
501 this->n_global_levels(), 0);
503 for (
auto cell :
this->cell_iterators())
504 if (cell->level_subdomain_id() ==
this->locally_owned_subdomain())
508 std::vector<types::global_cell_index>
cell_index(
509 this->n_global_levels(), 0);
514 this->n_global_levels(),
517 this->mpi_communicator);
522 this->mpi_communicator,
528 std::pair<types::global_cell_index, types::global_cell_index>>
530 for (
unsigned int l = 0; l < this->n_global_levels(); ++l)
533 for (
auto cell :
this->cell_iterators())
534 if (cell->level_subdomain_id() ==
this->locally_owned_subdomain())
539 for (
unsigned int l = 0; l < this->n_global_levels(); ++l)
544 this->n_global_levels());
549 [](
const auto &cell) {
return cell->global_level_cell_index(); },
551 cell->set_global_level_cell_index(
id);
555 number_cache.level_cell_index_partitioners.resize(
556 this->n_global_levels());
559 for (
unsigned int l = 0;
l < this->n_global_levels(); ++
l)
569 number_cache.level_cell_index_partitioners[
l] =
570 std::make_shared<const Utilities::MPI::Partitioner>(
571 is_local, is_ghost, this->mpi_communicator);
580 template <
int dim,
int spacedim>
593 ExcMessage(
"The vertex_locally_moved argument must not "
594 "contain vertices that are not locally owned"));
599 for (
unsigned int d = 0; d < spacedim; ++d)
602 const auto pack = [&](
const auto &cell) {
603 std::vector<Point<spacedim>>
vertices(cell->n_vertices());
605 for (
const auto v : cell->vertex_indices())
614 const auto unpack = [&](
const auto &cell,
const auto &
vertices) {
615 for (
const auto v : cell->vertex_indices())
620 if (this->is_multilevel_hierarchy_constructed())
627 GridTools::exchange_cell_data_to_ghosts<std::vector<Point<spacedim>>>(
635 template <
int dim,
int spacedim>
639 spacedim>::global_active_cell_index_partitioner()
const
641 return number_cache.active_cell_index_partitioner;
646 template <
int dim,
int spacedim>
650 spacedim>::global_level_cell_index_partitioner(
const unsigned int level)
656 return number_cache.level_cell_index_partitioners[
level];
661 template <
int dim,
int spacedim>
666 return number_cache.number_of_global_coarse_cells;
671 template <
int dim,
int spacedim>
677 const bool check_for_distorted_cells)
681 check_for_distorted_cells)
682 , cell_attached_data({0, 0, {}, {}})
683 , data_transfer(mpi_communicator)
688 template <
int dim,
int spacedim>
692 cell_attached_data = {0, 0, {}, {}};
693 data_transfer.
clear();
700 template <
int dim,
int spacedim>
708 auto tria =
const_cast<
711 if (this->cell_attached_data.n_attached_data_sets > 0)
714 tria->data_transfer.pack_data(
715 tria->local_cell_relations,
716 tria->cell_attached_data.pack_callbacks_fixed,
717 tria->cell_attached_data.pack_callbacks_variable);
723 tria->data_transfer.clear();
729 tria->cell_attached_data.n_attached_data_sets = 0;
730 tria->cell_attached_data.pack_callbacks_fixed.clear();
731 tria->cell_attached_data.pack_callbacks_variable.clear();
737 template <
int dim,
int spacedim>
741 if (this->n_global_levels() <= 1)
751 std::any_of(this->begin_active(this->n_global_levels() - 2),
752 this->end_active(this->n_global_levels() - 2),
754 return cell.is_locally_owned();
759 this->mpi_communicator) != 0;
764 template <
int dim,
int spacedim>
775 if (this->cell_attached_data.n_attached_deserialize > 0)
784 this->data_transfer.unpack_cell_status(this->local_cell_relations);
793 spacedim>::CELL_PERSIST),
801 template <
int dim,
int spacedim>
804 register_data_attach(
815 handle = 2 * cell_attached_data.pack_callbacks_variable.size();
816 cell_attached_data.pack_callbacks_variable.push_back(pack_callback);
820 handle = 2 * cell_attached_data.pack_callbacks_fixed.size() + 1;
821 cell_attached_data.pack_callbacks_fixed.push_back(pack_callback);
825 ++cell_attached_data.n_attached_data_sets;
832 template <
int dim,
int spacedim>
835 const unsigned int handle,
843 data_transfer.unpack_data(local_cell_relations, handle, unpack_callback);
846 --cell_attached_data.n_attached_data_sets;
847 if (cell_attached_data.n_attached_deserialize > 0)
848 --cell_attached_data.n_attached_deserialize;
857 if (cell_attached_data.n_attached_data_sets == 0 &&
858 cell_attached_data.n_attached_deserialize == 0)
861 cell_attached_data.pack_callbacks_fixed.
clear();
862 cell_attached_data.pack_callbacks_variable.clear();
863 data_transfer.clear();
866 for (
auto &
cell_rel : local_cell_relations)
877 template <
int dim,
int spacedim>
881 : variable_size_data_stored(
false)
882 , mpi_communicator(mpi_communicator)
887 template <
int dim,
int spacedim>
892 &pack_callbacks_fixed,
894 &pack_callbacks_variable)
896 Assert(src_data_fixed.size() == 0,
897 ExcMessage(
"Previously packed data has not been released yet!"));
964 for (
unsigned int c = 0;
993 spacedim>::CELL_INVALID) ?
1012 spacedim>::CELL_INVALID)
1026 if (variable_size_data_stored)
1063 sizeof(
unsigned int));
1067 sizeof(
unsigned int));
1083 if (variable_size_data_stored)
1134 this->mpi_communicator,
1142 sizes_fixed_cumulative.begin());
1147 if (variable_size_data_stored)
1167 std::accumulate(src_sizes_variable.begin(),
1168 src_sizes_variable.end(),
1169 std::vector<int>::size_type(0));
1181 std::back_inserter(src_data_fixed));
1188 (sizes_fixed_cumulative.size() > 1))
1191 sizes_fixed_cumulative.back() - sizes_fixed_cumulative.front();
1193 src_data_fixed.insert(src_data_fixed.end(),
1195 static_cast<char>(-1));
1201 if (variable_size_data_stored)
1209 std::move(data.begin(),
1211 std::back_inserter(src_data_variable));
1223 template <
int dim,
int spacedim>
1228 Assert(sizes_fixed_cumulative.size() > 0,
1232 Assert(dest_data_fixed.size() > 0,
1237 const unsigned int size = sizes_fixed_cumulative.front();
1259 template <
int dim,
int spacedim>
1263 const unsigned int handle,
1268 &unpack_callback)
const
1281 Assert(sizes_fixed_cumulative.size() > 0,
1285 Assert(dest_data_fixed.size() > 0,
1314 sizes_fixed_cumulative[sizes_fixed_cumulative.size() - 2];
1361 spacedim>::CELL_INVALID)
1369 std::memcpy(&offset,
1371 sizeof(
unsigned int));
1375 sizeof(
unsigned int));
1396 spacedim>::CELL_PERSIST:
1398 spacedim>::CELL_COARSEN:
1406 spacedim>::CELL_REFINE:
1414 spacedim>::CELL_INVALID:
1430 template <
int dim,
int spacedim>
1437#ifdef DEAL_II_WITH_MPI
1442 Assert(sizes_fixed_cumulative.size() > 0,
1447 const unsigned int bytes_per_cell = sizes_fixed_cumulative.back();
1486 sizes_fixed_cumulative.
data(),
1487 sizes_fixed_cumulative.size(),
1495 sizes_fixed_cumulative.
size() *
sizeof(
unsigned int);
1506 src_data_fixed.
data(),
1507 src_data_fixed.size(),
1521 if (variable_size_data_stored)
1524 std::string(
filename) +
"_variable.data";
1555 static_cast<std::size_t
>(
1556 std::numeric_limits<int>::max()),
1562 src_sizes_variable.
data(),
1563 src_sizes_variable.size(),
1590 src_data_variable.
data(),
1591 src_data_variable.size(),
1611 template <
int dim,
int spacedim>
1621#ifdef DEAL_II_WITH_MPI
1626 Assert(dest_data_fixed.size() == 0,
1627 ExcMessage(
"Previously loaded data has not been released yet!"));
1654 (variable_size_data_stored ? 1 : 0));
1658 sizes_fixed_cumulative.
data(),
1659 sizes_fixed_cumulative.size(),
1665 const unsigned int bytes_per_cell = sizes_fixed_cumulative.back();
1671 sizes_fixed_cumulative.
size() *
sizeof(
unsigned int);
1681 dest_data_fixed.
data(),
1682 dest_data_fixed.size(),
1695 if (variable_size_data_stored)
1698 std::string(
filename) +
"_variable.data";
1721 dest_sizes_variable.
data(),
1722 dest_sizes_variable.size(),
1731 std::accumulate(dest_sizes_variable.begin(),
1732 dest_sizes_variable.end(),
1753 dest_data_variable.
data(),
1754 dest_data_variable.size(),
1776 template <
int dim,
int spacedim>
1780 variable_size_data_stored =
false;
1783 sizes_fixed_cumulative.
clear();
1784 sizes_fixed_cumulative.shrink_to_fit();
1787 src_data_fixed.clear();
1788 src_data_fixed.shrink_to_fit();
1790 dest_data_fixed.clear();
1791 dest_data_fixed.shrink_to_fit();
1794 src_sizes_variable.clear();
1795 src_sizes_variable.shrink_to_fit();
1797 src_data_variable.clear();
1798 src_data_variable.shrink_to_fit();
1800 dest_sizes_variable.clear();
1801 dest_sizes_variable.shrink_to_fit();
1803 dest_data_variable.clear();
1804 dest_data_variable.shrink_to_fit();
1812#include "tria_base.inst"
const_iterator cend() const
const_iterator cbegin() const
value_type * data() const noexcept
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
virtual std::size_t memory_consumption() const
virtual void update_reference_cells()
virtual void clear() override
virtual void load(const std::string &filename)=0
typename ::Triangulation< dim, spacedim >::CellStatus CellStatus
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
typename std::pair< cell_iterator, CellStatus > cell_relation_t
const std::set< types::subdomain_id > & level_ghost_owners() const
virtual types::global_cell_index n_global_active_cells() const override
const std::set< types::subdomain_id > & ghost_owners() const
types::subdomain_id locally_owned_subdomain() const override
virtual unsigned int n_global_levels() const override
unsigned int n_locally_owned_active_cells() const
virtual types::coarse_cell_id n_global_coarse_cells() const override
virtual void update_number_cache()
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcNeedsMPI()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
IndexSet complete_index_set(const IndexSet::size_type N)
std::enable_if_t< std::is_fundamental< T >::value, std::size_t > memory_consumption(const T &t)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
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)
T sum(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
T max(const T &t, const MPI_Comm mpi_communicator)
std::vector< T > compute_set_union(const std::vector< T > &vec, const MPI_Comm comm)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
const MPI_Datatype mpi_type_id_for_type
size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
T unpack(const std::vector< char > &buffer, const bool allow_compression=true)
void release_all_unused_memory()
constexpr ReferenceCell make_reference_cell_from_int(const std::uint8_t kind)
static const unsigned int invalid_unsigned_int
const types::global_dof_index invalid_dof_index
bool is_nan(const double x)
unsigned int global_cell_index
const ::Triangulation< dim, spacedim > & tria