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() : id_(0), elementCount_(0), sharedWithProc_(-1) {}
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
105 using FaceUnorderedSet = tsl::hopscotch_set<Face, FaceHash, FaceEqual>;
106 // using FaceUnorderedSet = tsl::hopscotch_pg_set<Face, FaceHash, FaceEqual>;
107 #elif defined USE_ROBIN
108 using FaceUnorderedSet = tsl::robin_set<Face, FaceHash, FaceEqual>;
109 // using FaceUnorderedSet = tsl::robin_pg_set<Face, FaceHash, FaceEqual>;
110 #endif
111 class FaceGenerator
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:
120 Ioss::Region & region_;
121 FaceUnorderedSet faces_;
122 };
123 } // namespace Ioss
124
125 #endif
Ioss::Face::elementCount_
int elementCount_
Definition: Ioss_FaceGenerator.h:72
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Ioss::FaceGenerator
Definition: Ioss_FaceGenerator.h:111
Ioss::FaceGenerator::generate_faces
void generate_faces(INT)
Definition: Ioss_FaceGenerator.C:292
Ioss::Face::connectivity_
std::array< size_t, 4 > connectivity_
Definition: Ioss_FaceGenerator.h:74
Ioss::FaceHash
Definition: Ioss_FaceGenerator.h:77
Ioss::Face::element
size_t element[2]
Definition: Ioss_FaceGenerator.h:71
Ioss::Face::Face
Face(size_t id, std::array< size_t, 4 > conn)
Definition: Ioss_FaceGenerator.h:59
Ioss::Face::sharedWithProc_
int sharedWithProc_
Definition: Ioss_FaceGenerator.h:73
Ioss::FaceGenerator::region_
Ioss::Region & region_
Definition: Ioss_FaceGenerator.h:120
Ioss::Face::id_
size_t id_
Definition: Ioss_FaceGenerator.h:70
Ioss::Face::add_element
void add_element(size_t element_id) const
Definition: Ioss_FaceGenerator.h:64
Ioss::FaceUnorderedSet
tsl::robin_set< Face, FaceHash, FaceEqual > FaceUnorderedSet
Definition: Ioss_FaceGenerator.h:108
Ioss::FaceGenerator::faces_
FaceUnorderedSet faces_
Definition: Ioss_FaceGenerator.h:121
Ioss::Face
Definition: Ioss_FaceGenerator.h:55
Ioss::FaceHash::operator()
size_t operator()(const Face &face) const
Definition: Ioss_FaceGenerator.h:79
tsl::robin_set< Face, FaceHash, FaceEqual >
INT
int INT
Definition: Ioss_StructuredBlock.h:53
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Ioss::FaceGenerator::FaceGenerator
FaceGenerator(Ioss::Region &region)
Definition: Ioss_FaceGenerator.C:287
tsl::hopscotch_set
Definition: hopscotch_set.h:73
Ioss::Face::Face
Face()
Definition: Ioss_FaceGenerator.h:58
anonymous_namespace{io_info.C}::id
int64_t id(Ioss::GroupingEntity *entity)
Definition: io_info.C:92
robin_set.h
Ioss::FaceGenerator::faces
FaceUnorderedSet & faces()
Definition: Ioss_FaceGenerator.h:117
Ioss::FaceEqual::operator()
bool operator()(const Face &left, const Face &right) const
Definition: Ioss_FaceGenerator.h:84
Ioss::FaceEqual
Definition: Ioss_FaceGenerator.h:82
hopscotch_set.h