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:
58  Face() = default;
59  Face(size_t id, std::array<size_t, 4> conn) : hashId_(id), connectivity_(std::move(conn)) {}
60 
61  void add_element(size_t element_id) const
62  {
63  assert(elementCount_ < 2);
64  element[elementCount_++] = element_id;
65  }
66 
67  size_t hashId_{0};
68 
69  // NOTE: Not used at all by `Face` or `FaceGenerator` class, but are used by
70  // skinner to give a consistent element id in cases where there
71  // is a hash collision (face.id).
72 
73  // NOTE: For interior faces, this will not be the same value for each
74  // face where the `hashId_` *will* be consistent for interior faces.
75  // Should only use this as an id if `elementCount_` is 1.
76 
77  // NOTE: This could be used to do parallel or block boundary
78  // collision since it is calculated as 10*element_id + local_face,
79  // you could recover element_id and local_face and then set up
80  // parallel communication maps. May need to save the proc it is
81  // shared with also (which is available in git history)
82  mutable size_t element[2]{};
83  mutable int elementCount_{0}; // Should be max of 2 solid elements...
84  std::array<size_t, 4> connectivity_{};
85  };
86 
87  struct FaceHash
88  {
89  size_t operator()(const Face &face) const { return face.hashId_; }
90  };
91 
92  struct FaceEqual;
93 
94 #if defined USE_STD
95  using FaceUnorderedSet = std::unordered_set<Face, FaceHash, FaceEqual>;
96 #elif defined USE_HOPSCOTCH
98  // using FaceUnorderedSet = tsl::hopscotch_pg_set<Face, FaceHash, FaceEqual>;
99 #elif defined USE_ROBIN
101  // using FaceUnorderedSet = tsl::robin_pg_set<Face, FaceHash, FaceEqual>;
102 #endif
104  {
105  public:
106  explicit FaceGenerator(Ioss::Region &region);
107  ~FaceGenerator() = default;
108 
109  template <typename INT> void generate_faces(INT /*dummy*/, bool block_by_block = false);
110  FaceUnorderedSet & faces(const std::string &name = "ALL") { return faces_[name]; }
111 
112  private:
113  template <typename INT> void generate_block_faces(INT /*dummy*/);
114  template <typename INT> void generate_model_faces(INT /*dummy*/);
116  std::map<std::string, FaceUnorderedSet> faces_;
117  };
118 
119  struct FaceEqual
120  {
121  bool operator()(const Face &left, const Face &right) const
122  {
123  if (left.hashId_ != right.hashId_) {
124  return false;
125  }
126  // Hash (hashId_) is equal
127  // Check whether same vertices (can be in different order)
128  // Most (All?) of the time, there are no hashId_ collisions, so this test will not
129  // find a difference and the function will return 'true'
130  // However, for some reason, removing this check does not change the execution time
131  // appreiciably...
132  for (auto lvert : left.connectivity_) {
133  if (std::find(right.connectivity_.cbegin(), right.connectivity_.cend(), lvert) ==
134  right.connectivity_.cend()) {
135  // Not found, therefore not the same.
136  return false;
137  }
138  }
139  return true;
140  }
141  };
142 
143 } // namespace Ioss
144 
145 #endif
Ioss::FaceGenerator::region_
Ioss::Region & region_
Definition: Ioss_FaceGenerator.h:115
robin_set.h
Ioss::FaceGenerator::faces_
std::map< std::string, FaceUnorderedSet > faces_
Definition: Ioss_FaceGenerator.h:116
Ioss::FaceUnorderedSet
tsl::robin_set< Face, FaceHash, FaceEqual > FaceUnorderedSet
Definition: Ioss_FaceGenerator.h:100
Ioss::Face::add_element
void add_element(size_t element_id) const
Definition: Ioss_FaceGenerator.h:61
tsl::robin_set
Definition: robin_set.h:82
Ioss::Face::connectivity_
std::array< size_t, 4 > connectivity_
Definition: Ioss_FaceGenerator.h:84
Ioss::FaceGenerator::FaceGenerator
FaceGenerator(Ioss::Region &region)
Definition: Ioss_FaceGenerator.C:335
Ioss::FaceEqual::operator()
bool operator()(const Face &left, const Face &right) const
Definition: Ioss_FaceGenerator.h:121
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Ioss::Face::element
size_t element[2]
Definition: Ioss_FaceGenerator.h:82
Ioss::Face::hashId_
size_t hashId_
Definition: Ioss_FaceGenerator.h:67
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
INT
int INT
Definition: Ioss_StructuredBlock.h:53
Ioss::FaceEqual
Definition: Ioss_FaceGenerator.h:119
Ioss::Face
Definition: Ioss_FaceGenerator.h:55
Ioss::FaceHash::operator()
size_t operator()(const Face &face) const
Definition: Ioss_FaceGenerator.h:89
anonymous_namespace{io_info.C}::id
int64_t id(Ioss::GroupingEntity *entity)
Definition: io_info.C:94
tsl::hopscotch_set
Definition: hopscotch_set.h:73
Ioss::FaceGenerator::generate_block_faces
void generate_block_faces(INT)
Definition: Ioss_FaceGenerator.C:350
Ioss::FaceHash
Definition: Ioss_FaceGenerator.h:87
Ioss::FaceGenerator::generate_model_faces
void generate_model_faces(INT)
Definition: Ioss_FaceGenerator.C:413
Ioss::Face::elementCount_
int elementCount_
Definition: Ioss_FaceGenerator.h:83
Ioss::FaceGenerator::~FaceGenerator
~FaceGenerator()=default
Ioss::FaceGenerator
Definition: Ioss_FaceGenerator.h:103
Ioss::FaceGenerator::faces
FaceUnorderedSet & faces(const std::string &name="ALL")
Definition: Ioss_FaceGenerator.h:110
anonymous_namespace{io_info.C}::name
std::string name(const Ioss::GroupingEntity *entity)
Definition: io_info.C:89
Ioss::Face::Face
Face(size_t id, std::array< size_t, 4 > conn)
Definition: Ioss_FaceGenerator.h:59
hopscotch_set.h
Ioss::FaceGenerator::generate_faces
void generate_faces(INT, bool block_by_block=false)
Definition: Ioss_FaceGenerator.C:340
Ioss::Face::Face
Face()=default