IOSS  2.0
Ioss_FaceGenerator.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2020 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6 
7 #ifndef IOSS_Ioss_FaceGenerator_h
8 #define IOSS_Ioss_FaceGenerator_h
9 
10 #include <algorithm>
11 #include <array>
12 #include <cassert>
13 #include <cstddef> // for size_t
14 
15 #define USE_ROBIN
16 #if defined USE_STD
17 #include <unordered_set>
18 #elif defined USE_HOPSCOTCH
19 #include <hash/hopscotch_set.h>
20 #elif defined USE_ROBIN
21 #include <hash/robin_set.h>
22 #endif
23 
24 #include <utility>
25 
26 namespace Ioss {
27  class Region;
28 
29  class Face
30  {
31  public:
32  Face() = default;
33  Face(size_t id, std::array<size_t, 4> conn) : hashId_(id), connectivity_(std::move(conn)) {}
34  Face(std::array<size_t, 4> conn);
35 
36  void add_element(size_t element_id) const
37  {
38  if (elementCount_ < 2) {
39  element[elementCount_++] = element_id;
40  }
41  else {
42  face_element_error(element_id);
43  }
44  }
45 
46  void face_element_error(size_t element_id) const;
47 
48  size_t hashId_{0};
49 
50  // NOTE: Not used at all by `Face` or `FaceGenerator` class, but are used by
51  // skinner to give a consistent element id in cases where there
52  // is a hash collision (face.id).
53 
54  // NOTE: For interior faces, this will not be the same value for each
55  // face where the `hashId_` *will* be consistent for interior faces.
56  // Should only use this as an id if `elementCount_` is 1.
57 
58  // NOTE: This could be used to do parallel or block boundary
59  // collision since it is calculated as 10*element_id + local_face,
60  // you could recover element_id and local_face and then set up
61  // parallel communication maps. May need to save the proc it is
62  // shared with also (which is available in git history)
63  mutable size_t element[2]{};
64  mutable int elementCount_{0}; // Should be max of 2 solid elements...
65  std::array<size_t, 4> connectivity_{};
66  };
67 
68  struct FaceHash
69  {
70  size_t operator()(const Face &face) const { return face.hashId_; }
71  };
72 
73  struct FaceEqual
74  {
75  bool operator()(const Face &left, const Face &right) const
76  {
77  if (left.hashId_ != right.hashId_) {
78  return false;
79  }
80  // Hash (hashId_) is equal
81  // Check whether same vertices (can be in different order)
82  // Most (All?) of the time, there are no hashId_ collisions, so this test will not
83  // find a difference and the function will return 'true'
84  // However, for some reason, removing this check does not change the execution time
85  // appreiciably...
86  for (auto lvert : left.connectivity_) {
87  if (std::find(right.connectivity_.cbegin(), right.connectivity_.cend(), lvert) ==
88  right.connectivity_.cend()) {
89  // Not found, therefore not the same.
90  return false;
91  }
92  }
93  return true;
94  }
95  };
96 
97 #if defined USE_STD
98  using FaceUnorderedSet = std::unordered_set<Face, FaceHash, FaceEqual>;
99 #elif defined USE_HOPSCOTCH
101  // using FaceUnorderedSet = tsl::hopscotch_pg_set<Face, FaceHash, FaceEqual>;
102 #elif defined USE_ROBIN
104  // using FaceUnorderedSet = tsl::robin_pg_set<Face, FaceHash, FaceEqual>;
105 #endif
107  {
108  public:
109  explicit FaceGenerator(Ioss::Region &region);
110  ~FaceGenerator() = default;
111 
112  static size_t id_hash(size_t global_id);
113 
114  template <typename INT> void generate_faces(INT /*dummy*/, bool block_by_block = false);
115  FaceUnorderedSet & faces(const std::string &name = "ALL") { return faces_[name]; }
116 
117  //! Given a local node id (0-based), return the hashed value.
118  size_t node_id_hash(size_t local_node_id) const { return hashIds_[local_node_id]; }
119 
120  private:
121  template <typename INT> void hash_node_ids(const std::vector<INT> &node_ids);
122  template <typename INT> void generate_block_faces(INT /*dummy*/);
123  template <typename INT> void generate_model_faces(INT /*dummy*/);
124 
126  std::map<std::string, FaceUnorderedSet> faces_;
127  std::vector<size_t> hashIds_;
128  };
129 
130 } // namespace Ioss
131 
132 #endif
Ioss::FaceGenerator::region_
Ioss::Region & region_
Definition: Ioss_FaceGenerator.h:125
robin_set.h
Ioss::FaceGenerator::hashIds_
std::vector< size_t > hashIds_
Definition: Ioss_FaceGenerator.h:127
Ioss::FaceGenerator::faces_
std::map< std::string, FaceUnorderedSet > faces_
Definition: Ioss_FaceGenerator.h:126
Ioss::FaceUnorderedSet
tsl::robin_set< Face, FaceHash, FaceEqual > FaceUnorderedSet
Definition: Ioss_FaceGenerator.h:103
Ioss::Face::add_element
void add_element(size_t element_id) const
Definition: Ioss_FaceGenerator.h:36
tsl::robin_set
Definition: robin_set.h:83
Ioss::FaceGenerator::id_hash
static size_t id_hash(size_t global_id)
Definition: Ioss_FaceGenerator.C:317
Ioss::Face::connectivity_
std::array< size_t, 4 > connectivity_
Definition: Ioss_FaceGenerator.h:65
Ioss::Face::face_element_error
void face_element_error(size_t element_id) const
Definition: Ioss_FaceGenerator.C:304
Ioss::FaceGenerator::FaceGenerator
FaceGenerator(Ioss::Region &region)
Definition: Ioss_FaceGenerator.C:330
Ioss::FaceEqual::operator()
bool operator()(const Face &left, const Face &right) const
Definition: Ioss_FaceGenerator.h:75
Ioss::FaceGenerator::hash_node_ids
void hash_node_ids(const std::vector< INT > &node_ids)
Definition: Ioss_FaceGenerator.C:345
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:40
Ioss::Face::element
size_t element[2]
Definition: Ioss_FaceGenerator.h:63
Ioss::Face::hashId_
size_t hashId_
Definition: Ioss_FaceGenerator.h:48
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:78
INT
int INT
Definition: Ioss_StructuredBlock.h:27
Ioss::FaceEqual
Definition: Ioss_FaceGenerator.h:74
Ioss::Face
Definition: Ioss_FaceGenerator.h:30
Ioss::FaceHash::operator()
size_t operator()(const Face &face) const
Definition: Ioss_FaceGenerator.h:70
anonymous_namespace{io_info.C}::id
int64_t id(Ioss::GroupingEntity *entity)
Definition: io_info.C:70
tsl::hopscotch_set
Definition: hopscotch_set.h:74
Ioss::FaceGenerator::generate_block_faces
void generate_block_faces(INT)
Definition: Ioss_FaceGenerator.C:353
Ioss::FaceHash
Definition: Ioss_FaceGenerator.h:69
Ioss::FaceGenerator::generate_model_faces
void generate_model_faces(INT)
Definition: Ioss_FaceGenerator.C:410
Ioss::Face::elementCount_
int elementCount_
Definition: Ioss_FaceGenerator.h:64
Ioss::FaceGenerator::~FaceGenerator
~FaceGenerator()=default
Ioss::FaceGenerator
Definition: Ioss_FaceGenerator.h:107
Ioss::FaceGenerator::faces
FaceUnorderedSet & faces(const std::string &name="ALL")
Definition: Ioss_FaceGenerator.h:115
Ioss::FaceGenerator::node_id_hash
size_t node_id_hash(size_t local_node_id) const
Given a local node id (0-based), return the hashed value.
Definition: Ioss_FaceGenerator.h:118
anonymous_namespace{io_info.C}::name
std::string name(const Ioss::GroupingEntity *entity)
Definition: io_info.C:65
Ioss::Face::Face
Face(size_t id, std::array< size_t, 4 > conn)
Definition: Ioss_FaceGenerator.h:33
hopscotch_set.h
Ioss::FaceGenerator::generate_faces
void generate_faces(INT, bool block_by_block=false)
Definition: Ioss_FaceGenerator.C:335
Ioss::Face::Face
Face()=default