16#ifndef dealii_grid_tools_h
17#define dealii_grid_tools_h
49#include <boost/archive/binary_iarchive.hpp>
50#include <boost/archive/binary_oarchive.hpp>
51#include <boost/random/mersenne_twister.hpp>
52#include <boost/serialization/array.hpp>
53#include <boost/serialization/vector.hpp>
55#ifdef DEAL_II_WITH_ZLIB
56# include <boost/iostreams/device/back_inserter.hpp>
57# include <boost/iostreams/filter/gzip.hpp>
58# include <boost/iostreams/filtering_stream.hpp>
59# include <boost/iostreams/stream.hpp>
66#ifdef DEAL_II_HAVE_CXX20
79 template <
int dim,
int spacedim>
88 class MappingCollection;
95 template <
int dim,
int spacedim>
102 template <
int dim,
int spacedim,
class MeshType>
108 using type =
typename MeshType::active_cell_iterator;
115 template <
int dim,
int spacedim>
146 template <
int dim,
int spacedim>
173 template <
int dim,
int spacedim>
204 template <
int dim,
int spacedim>
219 template <
int dim,
int spacedim>
224 (ReferenceCells::get_hypercube<dim>()
228 .ReferenceCell::get_default_linear_mapping<dim, spacedim>()
242 template <
int dim,
int spacedim>
247 (ReferenceCells::get_hypercube<dim>()
251 .ReferenceCell::get_default_linear_mapping<dim, spacedim>()
318 template <
int dim,
int spacedim>
383 template <
int dim,
int spacedim>
404 template <
typename Iterator>
407 const Iterator &
object,
422 template <
int dim,
int spacedim>
424 tuple<std::vector<Point<spacedim>>, std::vector<CellData<dim>>,
SubCellData>
449 template <
int dim,
int spacedim>
473 template <
int dim,
int spacedim>
479 const double tol = 1e-12);
491 const double tol = 1e-12);
511 template <
int dim,
int spacedim>
526 template <
int dim,
int spacedim>
633 template <
int dim,
typename Transformation,
int spacedim>
636 std::assignable_from<
777 std::map<
unsigned int,
Point<spacedim>>
856 const unsigned int max_iterations = 100);
886 const unsigned int max_iterations = 5);
1048 std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>,
1049 std::vector<std::vector<Point<dim>>>,
1050 std::vector<std::vector<unsigned int>>>
1094 template <
int dim,
int spacedim>
1097 std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>,
1098 std::vector<std::vector<Point<dim>>>,
1099 std::vector<std::vector<unsigned int>>,
1100 std::vector<unsigned int>>
1190 template <
int dim,
int spacedim>
1193 std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>,
1194 std::vector<std::vector<Point<dim>>>,
1195 std::vector<std::vector<unsigned int>>,
1196 std::vector<std::vector<Point<spacedim>>>,
1197 std::vector<std::vector<unsigned int>>>
1205 const double tolerance = 1e-10,
1206 const std::vector<bool> & marked_vertices = {},
1207 const bool enforce_unique_mapping =
true);
1225 template <
int dim,
int spacedim>
1250 std::vector<std::tuple<std::pair<int, int>,
1280 std::vector<std::tuple<unsigned int, unsigned int, unsigned int>>
1305 template <
int dim,
int spacedim>
1311 const std::vector<bool> & marked_vertices,
1312 const double tolerance,
1314 const bool enforce_unique_mapping =
false);
1324 template <
int structdim,
int spacedim>
1331 std::array<::Point<spacedim>, structdim + 1>;
1341 std::vector<std::tuple<std::pair<int, int>,
1355 std::vector<std::tuple<unsigned int, unsigned int, IntersectionType>>
1395 std::map<unsigned int, std::vector<unsigned int>>
1397 const std::vector<std::tuple<unsigned int, unsigned int, unsigned int>>
1409 template <
int structdim,
int dim,
int spacedim>
1415 const std::vector<bool> & marked_vertices,
1416 const double tolerance);
1456 template <
int dim,
int spacedim>
1457 std::map<unsigned int, Point<spacedim>>
1461 (ReferenceCells::get_hypercube<dim>()
1465 .ReferenceCell::get_default_linear_mapping<dim, spacedim>()
1478 template <
int spacedim>
1509 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1515 const std::vector<
bool> & marked_vertices = {});
1543 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1550 const std::vector<
bool> & marked_vertices = {});
1575 template <
class MeshType>
1578 std::vector<typename MeshType::active_cell_iterator>
1581 typename ::internal::ActiveCellIterator<MeshType::dimension,
1582 MeshType::space_dimension,
1586 const unsigned int vertex_index);
1653 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1657 std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
Point<dim>>
1659 std::pair<typename ::internal::
1660 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type,
1666 const std::vector<bool> &marked_vertices = {},
1667 const double tolerance = 1.e-10);
1679 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1685 typename ::internal::
1686 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type
1690 const std::vector<bool> &marked_vertices = {},
1691 const double tolerance = 1.e-10);
1699 template <
int dim,
int spacedim>
1700 std::pair<typename DoFHandler<dim, spacedim>::active_cell_iterator,
1706 const double tolerance = 1.e-10);
1759 template <
int dim,
int spacedim>
1760 std::pair<typename Triangulation<dim, spacedim>::active_cell_iterator,
1767 const std::vector<bool> &marked_vertices = {},
1768 const double tolerance = 1.e-10);
1786 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1790 std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
Point<dim>>
1792 std::pair<typename ::internal::
1793 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type,
1804 &vertex_to_cell_centers,
1807 const std::vector<bool> &marked_vertices = {},
1810 const double tolerance = 1.e-10,
1812 std::pair<BoundingBox<spacedim>,
1840 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1844 std::vector<std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
1847 std::vector<std::pair<
1848 typename ::internal::
1849 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type,
1856 const double tolerance,
1869 template <
int dim,
template <
int,
int>
class MeshType,
int spacedim>
1873 std::vector<std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
1876 std::vector<std::pair<
1877 typename ::internal::
1878 ActiveCellIterator<dim, spacedim, MeshType<dim, spacedim>>::type,
1885 const double tolerance = 1e-10,
1886 const std::vector<bool> & marked_vertices = {});
1911 template <
class MeshType>
2162 active_cell_iterator &)>
2277 std::tuple<std::vector<std::vector<unsigned int>>,
2278 std::map<unsigned int, unsigned int>,
2279 std::map<unsigned int, std::vector<unsigned int>>>
2322 template <
int spacedim>
2324 std::tuple<std::map<unsigned int, std::vector<unsigned int>>,
2325 std::map<unsigned int, unsigned int>,
2326 std::map<unsigned int, std::vector<unsigned int>>>
2343 template <
int dim,
int spacedim>
2345 std::set<typename Triangulation<dim, spacedim>::active_cell_iterator>>
2360 template <
int dim,
int spacedim>
2361 std::vector<std::vector<Tensor<1, spacedim>>>
2376 template <
int dim,
int spacedim>
2382 (ReferenceCells::get_hypercube<dim>()
2386 .ReferenceCell::get_default_linear_mapping<dim, spacedim>()
2401 template <
int dim,
int spacedim>
2402 std::map<unsigned int, types::global_vertex_index>
2417 template <
int dim,
int spacedim>
2418 std::pair<unsigned int, double>
2436 template <
int dim,
int spacedim>
2450 template <
int dim,
int spacedim>
2464 template <
int dim,
int spacedim>
2468 const unsigned int level,
2491 template <
int dim,
int spacedim>
2508 template <
int dim,
int spacedim>
2561 template <
int dim,
int spacedim>
2579 template <
int dim,
int spacedim>
2602 template <
int dim,
int spacedim>
2619 template <
int dim,
int spacedim>
2630 template <
int dim,
int spacedim>
2631 std::vector<types::subdomain_id>
2633 const std::vector<CellId> & cell_ids);
2645 template <
int dim,
int spacedim>
2648 std::vector<types::subdomain_id> &
subdomain);
2664 template <
int dim,
int spacedim>
2699 template <
int dim,
int spacedim>
2744 template <
typename MeshType>
2746 std::list<std::pair<
2747 typename MeshType::cell_iterator,
2762 template <
int dim,
int spacedim>
2778 template <
typename MeshType>
2803 template <
int dim,
int spacedim>
2861 template <
class MeshType>
2864 const typename MeshType::active_cell_iterator &cell);
2888 template <
class Container>
2889 std::vector<typename Container::cell_iterator>
2891 const std::vector<typename Container::active_cell_iterator> &
patch_cells);
2959 template <
class Container>
2962 const std::vector<typename Container::active_cell_iterator> &
patch,
2967 Container::space_dimension>::active_cell_iterator,
3001 template <
int dim,
int spacedim>
3004 std::vector<typename DoFHandler<dim, spacedim>::active_cell_iterator>>
3020 template <
typename CellIterator>
3126 template <
typename FaceIterator>
3129 std::bitset<3> & orientation,
3132 const unsigned int direction,
3141 template <
typename FaceIterator>
3146 const unsigned int direction,
3210 template <
typename MeshType>
3216 const unsigned int direction,
3248 template <
typename MeshType>
3253 const unsigned int direction,
3349 template <
int dim,
int spacedim>
3378 template <
int dim,
int spacedim>
3384 [](
const std::set<types::manifold_id> &manifold_ids) {
3385 if (manifold_ids.size() == 1)
3386 return *manifold_ids.
begin();
3479 template <
typename DataType,
typename MeshType>
3486 const DataType &)> & unpack,
3503 template <
typename DataType,
typename MeshType>
3510 const DataType &)> & unpack,
3526 template <
int spacedim>
3527 std::vector<std::vector<BoundingBox<spacedim>>>
3564 template <
int spacedim>
3587 template <
int dim,
int spacedim>
3613 template <
int dim,
int spacedim>
3614 std::map<unsigned int, std::set<::types::subdomain_id>>
3633 template <
int dim,
typename T>
3654 template <
class Archive>
3660 Assert(cell_ids.size() == data.size(),
3663 const std::size_t n_cells = cell_ids.size();
3665 for (
const auto &
id : cell_ids)
3680 template <
class Archive>
3686 std::size_t n_cells;
3689 cell_ids.reserve(n_cells);
3690 for (
unsigned int c = 0; c < n_cells; ++c)
3694 cell_ids.emplace_back(value);
3706 template <
class Archive>
3738 template <
int dim,
typename VectorType>
3833 const std::vector<unsigned int> &,
3850 const std::vector<
Point<2>> & points,
3851 const std::vector<unsigned int> &mask,
3862 const std::vector<
Point<3>> & points,
3863 const std::vector<unsigned int> &mask,
3900 <<
"The number of partitions you gave is " <<
arg1
3901 <<
", but must be greater than zero.");
3907 <<
"The subdomain id " <<
arg1
3908 <<
" has no cells associated with it.");
3919 <<
"The scaling factor must be positive, but it is " <<
arg1
3927 <<
"The given vertex with index " <<
arg1
3928 <<
" is not used in the given triangulation.");
3945 "The edges of the mesh are not consistently orientable.");
3982 template <
int dim,
typename Transformation,
int spacedim>
3985 std::assignable_from<
4002 for (; cell !=
endc; ++cell)
4019 for (; cell !=
endc; ++cell)
4020 for (
const unsigned int face : cell->face_indices())
4021 if (cell->face(face)->has_children() &&
4022 !cell->face(face)->at_boundary())
4024 Assert(cell->reference_cell() ==
4025 ReferenceCells::get_hypercube<dim>(),
4029 cell->face(face)->child(0)->vertex(1) =
4030 (cell->face(face)->vertex(0) + cell->face(face)->vertex(1)) /
4039 for (; cell !=
endc; ++cell)
4040 for (
const unsigned int face : cell->face_indices())
4041 if (cell->face(face)->has_children() &&
4042 !cell->face(face)->at_boundary())
4044 Assert(cell->reference_cell() ==
4045 ReferenceCells::get_hypercube<dim>(),
4049 cell->face(face)->child(0)->vertex(1) =
4050 (cell->face(face)->vertex(0) + cell->face(face)->vertex(1)) /
4052 cell->face(face)->child(0)->vertex(2) =
4053 (cell->face(face)->vertex(0) + cell->face(face)->vertex(2)) /
4055 cell->face(face)->child(1)->vertex(3) =
4056 (cell->face(face)->vertex(1) + cell->face(face)->vertex(3)) /
4058 cell->face(face)->child(2)->vertex(3) =
4059 (cell->face(face)->vertex(2) + cell->face(face)->vertex(3)) /
4063 cell->face(face)->child(0)->vertex(3) =
4064 (cell->face(face)->vertex(0) + cell->face(face)->vertex(1) +
4065 cell->face(face)->vertex(2) + cell->face(face)->vertex(3)) /
4076 template <
class MeshType>
4079 const typename MeshType::cell_iterator &cell)
4081 std::vector<typename MeshType::active_cell_iterator>
child_cells;
4083 if (cell->has_children())
4085 for (
unsigned int child = 0; child < cell->n_children(); ++child)
4086 if (cell->child(child)->has_children())
4088 const std::vector<typename MeshType::active_cell_iterator>
4103 template <
class MeshType>
4106 const typename MeshType::active_cell_iterator & cell,
4110 for (
const unsigned int n : cell->face_indices())
4111 if (!cell->at_boundary(n))
4113 if (MeshType::dimension == 1)
4134 if (cell->face(n)->has_children())
4138 for (
unsigned int c = 0;
4139 c < cell->face(n)->n_active_descendants();
4142 cell->neighbor_child_on_subface(n, c));
4156 template <
typename CellIterator>
4160 return sizeof(*this) +
matrix.memory_consumption();
4190 const unsigned int d1)
4201 template <
typename F>
4207 return (f(
center + step) - f(
center - step)) / (2.0 * step);
4216 template <
typename F>
4237 template <
int structdim,
typename F>
4262 template <
int spacedim,
int structdim,
typename F>
4265 const unsigned int row_n,
4275 ExcMessage(
"This function assumes that the last weight is a "
4276 "dependent variable (and hence we cannot take its "
4277 "derivative directly)."));
4280 "We cannot differentiate with respect to the variable "
4281 "that is assumed to be dependent."));
4298 template <
typename Iterator,
int spacedim,
int structdim>
4336 for (
unsigned int d = 0;
d < structdim; ++
d)
4341 x_k += object->vertex(i) *
4347 for (
const unsigned int i :
4355 for (
const unsigned int i :
4365 H_k += (
object->vertex(i) *
object->vertex(
j)) * tmp;
4372 for (
const unsigned int i :
4374 x_k += object->vertex(i) *
4393 template <
int structdim>
4407 if (v[i] < 0.0 || v[i] > 1.0)
4419 template <
typename Iterator>
4422 const Iterator &
object,
4425 const int spacedim = Iterator::AccessorType::space_dimension;
4426 const int structdim = Iterator::AccessorType::structure_dimension;
4430 if (structdim >= spacedim)
4432 else if (structdim == 1 || structdim == 2)
4434 using namespace internal::ProjectToObject;
4439 const int dim = Iterator::AccessorType::dimension;
4442 &manifold) !=
nullptr)
4491 const double step_size =
object->diameter() / 64.0;
4504 return object->get_manifold().get_new_point(
4516 const double distance =
4518 if (distance == 0.0)
4679 for (
unsigned int line_n = 0;
4689 return a.distance(trial_point) <
4690 b.distance(trial_point);
4710 template <
typename DataType,
4716 const std::function<
4721 const std::function<
void(
4724 const std::function<std::set<types::subdomain_id>(
4726 MeshType::space_dimension> &)>
4729# ifndef DEAL_II_WITH_MPI
4738 constexpr int dim = MeshType::dimension;
4739 constexpr int spacedim = MeshType::space_dimension;
4742 &
mesh.get_triangulation());
4746 "The function exchange_cell_data_to_ghosts() only works with parallel triangulations."));
4748 if (
const auto tria =
dynamic_cast<
4750 &
mesh.get_triangulation()))
4753 tria->with_artificial_cells(),
4755 "The functions GridTools::exchange_cell_data_to_ghosts() and "
4756 "GridTools::exchange_cell_data_to_level_ghosts() can only "
4757 "operate on a single layer of ghost cells. However, you have "
4758 "given a Triangulation object of type "
4759 "parallel::shared::Triangulation without artificial cells "
4760 "resulting in arbitrary numbers of ghost layers."));
4764 std::set<::types::subdomain_id> ghost_owners =
4767 std::vector<typename CellId::binary_type>>
4776 constexpr int spacedim = MeshType::space_dimension;
4790 mutex,
tria->get_communicator());
4798 std::vector<MPI_Request> requests(ghost_owners.size());
4800 unsigned int idx = 0;
4805 it.second.
size() *
sizeof(
it.second[0]),
4809 tria->get_communicator(),
4818 std::vector<std::vector<char>>
sendbuffers(ghost_owners.size());
4820 for (
unsigned int idx = 0; idx < ghost_owners.size(); ++idx)
4825 tria->get_communicator(),
4848 tria->get_communicator(),
4863 const std_cxx17::optional<DataType> data =
pack(
mesh_it);
4886 sizeof(std::size_t));
4901 tria->get_communicator(),
4913 tria->get_communicator(),
4928 tria->get_communicator(),
4941 auto received_data = Utilities::unpack<std::vector<DataType>>(
4950 const std::vector<typename CellId::binary_type> &
this_cell_list =
4982 if (requests.size() > 0)
5002 template <
typename DataType,
typename MeshType>
5006 const std::function<std_cxx17::optional<DataType>(
5007 const typename MeshType::active_cell_iterator &)> &pack,
5008 const std::function<
void(
const typename MeshType::active_cell_iterator &,
5009 const DataType &)> & unpack,
5010 const std::function<
bool(
const typename MeshType::active_cell_iterator &)>
5013# ifndef DEAL_II_WITH_MPI
5020 internal::exchange_cell_data<DataType,
5022 typename MeshType::active_cell_iterator>(
5027 [&](
const auto &process) {
5028 for (
const auto &cell :
mesh.active_cell_iterators())
5029 if (cell->is_ghost())
5032 [](
const auto &
tria) {
return tria.ghost_owners(); });
5038 template <
typename DataType,
typename MeshType>
5042 const std::function<std_cxx17::optional<DataType>(
5043 const typename MeshType::level_cell_iterator &)> &pack,
5044 const std::function<
void(
const typename MeshType::level_cell_iterator &,
5045 const DataType &)> & unpack,
5046 const std::function<
bool(
const typename MeshType::level_cell_iterator &)>
5049# ifndef DEAL_II_WITH_MPI
5056 internal::exchange_cell_data<DataType,
5058 typename MeshType::level_cell_iterator>(
5063 [&](
const auto &process) {
5064 for (
const auto &cell :
mesh.cell_iterators())
5065 if (cell->is_ghost_on_level())
5066 process(cell, cell->level_subdomain_id());
5068 [](
const auto &
tria) {
return tria.level_ghost_owners(); });
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
value_type * data() const noexcept
std::array< unsigned int, 4 > binary_type
Abstract base class for mapping classes.
numbers::NumberTraits< Number >::real_type distance(const Point< dim, Number > &p) const
typename MeshType::active_cell_iterator type
#define DEAL_II_DEPRECATED
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
#define DeclException0(Exception0)
static ::ExceptionBase & ExcMeshNotOrientable()
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcNeedsMPI()
static ::ExceptionBase & ExcNonExistentSubdomain(int arg1)
#define Assert(cond, exc)
static ::ExceptionBase & ExcVertexNotUsed(unsigned int arg1)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcTriangulationHasBeenRefined()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcInvalidNumberOfPartitions(int arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcScalingFactorNotPositive(double arg1)
#define AssertThrow(cond, exc)
typename ActiveSelector::active_cell_iterator active_cell_iterator
void copy_boundary_to_manifold_id(Triangulation< dim, spacedim > &tria, const bool reset_boundary_ids=false)
void copy_material_to_manifold_id(Triangulation< dim, spacedim > &tria, const bool compute_face_ids=false)
void map_boundary_to_manifold_ids(const std::vector< types::boundary_id > &src_boundary_ids, const std::vector< types::manifold_id > &dst_manifold_ids, Triangulation< dim, spacedim > &tria, const std::vector< types::boundary_id > &reset_boundary_ids={})
void assign_co_dimensional_manifold_indicators(Triangulation< dim, spacedim > &tria, const std::function< types::manifold_id(const std::set< types::manifold_id > &)> &disambiguation_function=[](const std::set< types::manifold_id > &manifold_ids) { if(manifold_ids.size()==1) return *manifold_ids.begin();else return numbers::flat_manifold_id;}, bool overwrite_only_flat_manifold_ids=true)
@ matrix
Contents is actually a matrix.
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
T sum(const T &t, const MPI_Comm mpi_communicator)
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)
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
const types::manifold_id flat_manifold_id
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
unsigned int subdomain_id
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
boost::geometry::index::rtree< LeafType, IndexType, IndexableGetter > RTree
DEAL_II_HOST constexpr SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &)
DEAL_II_HOST constexpr SymmetricTensor< 4, dim, Number > outer_product(const SymmetricTensor< 2, dim, Number > &t1, const SymmetricTensor< 2, dim, Number > &t2)
std::map< unsigned int, unsigned int > vertex_to_coinciding_vertex_group
std::map< unsigned int, std::vector< unsigned int > > coinciding_vertex_groups
const ::Triangulation< dim, spacedim > & tria