From 313623c5705132a3234010a39352ac32cd77f84d Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Fri, 16 Aug 2019 05:11:27 +0200 Subject: [PATCH] Add get_coarse_cell_id to CellID Conflicts: include/deal.II/grid/tria.h --- doc/news/changes/minor/20190815PeterMunch | 3 ++ include/deal.II/base/types.h | 18 +++++++++ include/deal.II/grid/cell_id.h | 24 ++++++++--- include/deal.II/grid/tria.h | 49 +++++++++++++++++++++++ source/grid/cell_id.cc | 10 ++--- 5 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 doc/news/changes/minor/20190815PeterMunch diff --git a/doc/news/changes/minor/20190815PeterMunch b/doc/news/changes/minor/20190815PeterMunch new file mode 100644 index 0000000000..2a003390cd --- /dev/null +++ b/doc/news/changes/minor/20190815PeterMunch @@ -0,0 +1,3 @@ +New: Add method to get the coarse-grid cell from CellID. +
+(Peter Munch, 2019/08/15) diff --git a/include/deal.II/base/types.h b/include/deal.II/base/types.h index 0d6ceb677c..ff94c95891 100644 --- a/include/deal.II/base/types.h +++ b/include/deal.II/base/types.h @@ -95,6 +95,18 @@ namespace types # define DEAL_II_DOF_INDEX_MPI_TYPE MPI_UNSIGNED #endif +#ifdef DEAL_II_WITH_64BIT_INDICES + /** + * The type used for coarse-cell ids. + */ + using coarse_cell_id = unsigned long long int; +#else + /** + * The type used for coarse-cell ids. + */ + using coarse_cell_id = unsigned int; +#endif + /** * The type used to denote boundary indicators associated with every piece * of the boundary and, in the case of meshes that describe manifolds in @@ -188,6 +200,12 @@ namespace numbers const types::global_dof_index invalid_dof_index = static_cast(-1); + /** + * An invalid value for coarse-cell ids. + */ + const types::coarse_cell_id invalid_coarse_cell_id = + static_cast(-1); + /** * Invalid material_id which we need in several places as a default value. * We assume that all material_ids lie in the range [0, diff --git a/include/deal.II/grid/cell_id.h b/include/deal.II/grid/cell_id.h index 4cffac1d4f..702dc4de06 100644 --- a/include/deal.II/grid/cell_id.h +++ b/include/deal.II/grid/cell_id.h @@ -85,7 +85,7 @@ public: * and the number of children of a cell in the current space dimension (i.e., * GeometryInfo::max_children_per_cell). */ - CellId(const unsigned int coarse_cell_id, + CellId(const types::coarse_cell_id coarse_cell_id, const std::vector &child_indices); /** @@ -99,9 +99,9 @@ public: * GeometryInfo::max_children_per_cell). The array * @p child_indices must have at least @p n_child_indices valid entries. */ - CellId(const unsigned int coarse_cell_id, - const unsigned int n_child_indices, - const std::uint8_t *child_indices); + CellId(const types::coarse_cell_id coarse_cell_id, + const unsigned int n_child_indices, + const std::uint8_t * child_indices); /** * Construct a CellId object with a given binary representation that was @@ -161,12 +161,18 @@ public: void serialize(Archive &ar, const unsigned int version); + /** + * Return the id of the coarse cell. + */ + types::coarse_cell_id + get_coarse_cell_id() const; + private: /** * The number of the coarse cell within whose tree the cell * represented by the current object is located. */ - unsigned int coarse_cell_id; + types::coarse_cell_id coarse_cell_id; /** * The number of child indices stored in the child_indices array. This is @@ -308,6 +314,14 @@ CellId::operator<(const CellId &other) const return true; // other.id is longer } + +inline types::coarse_cell_id +CellId::get_coarse_cell_id() const +{ + return coarse_cell_id; +} + + DEAL_II_NAMESPACE_CLOSE #endif diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index 56efe27523..65826ba89a 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -3483,6 +3483,34 @@ public: std::pair, std::bitset<3>>> & get_periodic_face_map() const; + /** + * Translate the unique id of a coarse cell to its index. + * + * @note For serial and shared triangulation both id and index are the same. + * For distributed triangulations setting both might differ, since the + * id might correspond to a global id and the index to a local id. + * + * @param coarse_cell_id Unique id of the coarse cell. + * @return Index of the coarse cell within the current triangulation. + */ + virtual unsigned int + coarse_cell_id_to_coarse_cell_index( + const types::coarse_cell_id coarse_cell_id) const; + + + /** + * Translate the index of coarse cell to its unique id. + * + * @note: See the note of the method + * translate_coarse_cell_id_to_coarse_cell_index(). + * + * @param coarse_cell_index Index of the coarse cell. + * @return Id of the coarse cell. + */ + virtual types::coarse_cell_id + coarse_cell_index_to_coarse_cell_id( + const unsigned int coarse_cell_index) const; + BOOST_SERIALIZATION_SPLIT_MEMBER() @@ -4282,6 +4310,27 @@ Triangulation::load(Archive &ar, const unsigned int) } + +template +inline unsigned int +Triangulation::coarse_cell_id_to_coarse_cell_index( + const types::coarse_cell_id coarse_cell_id) const +{ + return coarse_cell_id; +} + + + +template +inline types::coarse_cell_id +Triangulation::coarse_cell_index_to_coarse_cell_id( + const unsigned int coarse_cell_index) const +{ + return coarse_cell_index; +} + + + /* -------------- declaration of explicit specializations ------------- */ template <> diff --git a/source/grid/cell_id.cc b/source/grid/cell_id.cc index 25a2670f7b..ff5c3d5548 100644 --- a/source/grid/cell_id.cc +++ b/source/grid/cell_id.cc @@ -22,7 +22,7 @@ DEAL_II_NAMESPACE_OPEN CellId::CellId() - : coarse_cell_id(numbers::invalid_unsigned_int) + : coarse_cell_id(numbers::invalid_coarse_cell_id) , n_child_indices(numbers::invalid_unsigned_int) { // initialize the child indices to invalid values @@ -35,7 +35,7 @@ CellId::CellId() -CellId::CellId(const unsigned int coarse_cell_id, +CellId::CellId(const types::coarse_cell_id coarse_cell_id, const std::vector &id) : coarse_cell_id(coarse_cell_id) , n_child_indices(id.size()) @@ -46,9 +46,9 @@ CellId::CellId(const unsigned int coarse_cell_id, -CellId::CellId(const unsigned int coarse_cell_id, - const unsigned int n_child_indices, - const std::uint8_t *id) +CellId::CellId(const types::coarse_cell_id coarse_cell_id, + const unsigned int n_child_indices, + const std::uint8_t * id) : coarse_cell_id(coarse_cell_id) , n_child_indices(n_child_indices) { -- 2.39.5