IOSS  2.0
Ioss_FaceGenerator.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2017 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 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of NTESS nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 #ifndef IOSS_Ioss_FaceGenerator_h
34 #define IOSS_Ioss_FaceGenerator_h
35 
36 #include <algorithm>
37 #include <array>
38 #include <cassert>
39 #include <cstddef> // for size_t
40 
41 #define USE_ROBIN
42 #if defined USE_STD
43 #include <unordered_set>
44 #elif defined USE_HOPSCOTCH
45 #include <hash/hopscotch_set.h>
46 #elif defined USE_ROBIN
47 #include <hash/robin_set.h>
48 #endif
49 
50 #include <utility>
51 
52 namespace Ioss {
53  class Region;
54 
55  class Face
56  {
57  public:
59  Face(size_t id, std::array<size_t, 4> conn)
60  : id_(id), elementCount_(0), sharedWithProc_(-1), connectivity_(std::move(conn))
61  {
62  }
63 
64  void add_element(size_t element_id) const
65  {
66  assert(elementCount_ < 2);
67  element[elementCount_++] = element_id;
68  }
69 
70  size_t id_;
71  mutable size_t element[2]{};
72  mutable int elementCount_; // Should be max of 2 solid elements...
73  mutable int sharedWithProc_;
74  std::array<size_t, 4> connectivity_{};
75  };
76 
77  struct FaceHash
78  {
79  size_t operator()(const Face &face) const { return face.id_; }
80  };
81 
82  struct FaceEqual
83  {
84  bool operator()(const Face &left, const Face &right) const
85  {
86  if (left.id_ != right.id_) {
87  return false;
88  }
89  // Hash (id_) is equal
90  // Check whether same vertices (can be in different order)
91  for (auto lvert : left.connectivity_) {
92  if (std::find(right.connectivity_.cbegin(), right.connectivity_.cend(), lvert) ==
93  right.connectivity_.cend()) {
94  // Not found, therefore not the same.
95  return false;
96  }
97  }
98  return true;
99  }
100  };
101 
102 #if defined USE_STD
103  using FaceUnorderedSet = std::unordered_set<Face, FaceHash, FaceEqual>;
104 #elif defined USE_HOPSCOTCH
106  // using FaceUnorderedSet = tsl::hopscotch_pg_set<Face, FaceHash, FaceEqual>;
107 #elif defined USE_ROBIN
109  // using FaceUnorderedSet = tsl::robin_pg_set<Face, FaceHash, FaceEqual>;
110 #endif
112  {
113  public:
114  explicit FaceGenerator(Ioss::Region &region);
115 
116  template <typename INT> void generate_faces(INT /*dummy*/);
117  FaceUnorderedSet & faces() { return faces_; }
118 
119  private:
122  };
123 } // namespace Ioss
124 
125 #endif
int elementCount_
Definition: Ioss_FaceGenerator.h:72
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Definition: Ioss_FaceGenerator.h:111
void generate_faces(INT)
Definition: Ioss_FaceGenerator.C:292
std::array< size_t, 4 > connectivity_
Definition: Ioss_FaceGenerator.h:74
Definition: Ioss_FaceGenerator.h:77
size_t element[2]
Definition: Ioss_FaceGenerator.h:71
Face(size_t id, std::array< size_t, 4 > conn)
Definition: Ioss_FaceGenerator.h:59
int sharedWithProc_
Definition: Ioss_FaceGenerator.h:73
Ioss::Region & region_
Definition: Ioss_FaceGenerator.h:120
size_t id_
Definition: Ioss_FaceGenerator.h:70
void add_element(size_t element_id) const
Definition: Ioss_FaceGenerator.h:64
tsl::robin_set< Face, FaceHash, FaceEqual > FaceUnorderedSet
Definition: Ioss_FaceGenerator.h:108
FaceUnorderedSet faces_
Definition: Ioss_FaceGenerator.h:121
Definition: Ioss_FaceGenerator.h:55
size_t operator()(const Face &face) const
Definition: Ioss_FaceGenerator.h:79
int INT
Definition: Ioss_StructuredBlock.h:53
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
FaceGenerator(Ioss::Region &region)
Definition: Ioss_FaceGenerator.C:287
Definition: hopscotch_set.h:73
Face()
Definition: Ioss_FaceGenerator.h:58
int64_t id(Ioss::GroupingEntity *entity)
Definition: io_info.C:94
FaceUnorderedSet & faces()
Definition: Ioss_FaceGenerator.h:117
bool operator()(const Face &left, const Face &right) const
Definition: Ioss_FaceGenerator.h:84
Definition: Ioss_FaceGenerator.h:82