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
53 namespace Ioss {
54 class Region;
55
56 class Face
57 {
58 public:
59 Face() = default;
60 Face(size_t id, std::array<size_t, 4> conn) : hashId_(id), connectivity_(std::move(conn)) {}
61
62 void add_element(size_t element_id) const
63 {
64 assert(elementCount_ < 2);
65 element[elementCount_++] = element_id;
66 }
67
68 size_t hashId_{0};
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
83 mutable size_t element[2]{};
84 mutable int elementCount_{0}; // Should be max of 2 solid elements...
85 std::array<size_t, 4> connectivity_{};
86 };
87
88 struct FaceHash
89 {
90 size_t operator()(const Face &face) const { return face.hashId_; }
91 };
92
93 struct FaceEqual
94 {
95 bool operator()(const Face &left, const Face &right) const
96 {
97 if (left.hashId_ != right.hashId_) {
98 return false;
99 }
100 // Hash (hashId_) is equal
101 // Check whether same vertices (can be in different order)
102 for (auto lvert : left.connectivity_) {
103 if (std::find(right.connectivity_.cbegin(), right.connectivity_.cend(), lvert) ==
104 right.connectivity_.cend()) {
105 // Not found, therefore not the same.
106 return false;
107 }
108 }
109 return true;
110 }
111 };
112
113 #if defined USE_STD
114 using FaceUnorderedSet = std::unordered_set<Face, FaceHash, FaceEqual>;
115 #elif defined USE_HOPSCOTCH
116 using FaceUnorderedSet = tsl::hopscotch_set<Face, FaceHash, FaceEqual>;
117 // using FaceUnorderedSet = tsl::hopscotch_pg_set<Face, FaceHash, FaceEqual>;
118 #elif defined USE_ROBIN
119 using FaceUnorderedSet = tsl::robin_set<Face, FaceHash, FaceEqual>;
120 // using FaceUnorderedSet = tsl::robin_pg_set<Face, FaceHash, FaceEqual>;
121 #endif
122 class FaceGenerator
123 {
124 public:
125 explicit FaceGenerator(Ioss::Region &region);
126 ~FaceGenerator()
127 {
128 std::cout << "FaceEqual Calls: " << fequal << "\t" << secondary << "\n";
129 }
130
131 template <typename INT> void generate_faces(INT /*dummy*/, bool block_by_block = false);
132 FaceUnorderedSet & faces(const std::string &name = "ALL") { return faces_[name]; }
133
134 static size_t fequal;
135 static size_t secondary;
136
137 private:
138 template <typename INT> void generate_block_faces(INT /*dummy*/);
139 template <typename INT> void generate_model_faces(INT /*dummy*/);
140 Ioss::Region & region_;
141 std::map<std::string, FaceUnorderedSet> faces_;
142 };
143
144 } // namespace Ioss
145
146 #endif
Ioss::FaceGenerator::region_
Ioss::Region & region_
Definition: Ioss_FaceGenerator.h:140
Ioss::FaceGenerator::fequal
static size_t fequal
Definition: Ioss_FaceGenerator.h:134
robin_set.h
Ioss::FaceGenerator::faces_
std::map< std::string, FaceUnorderedSet > faces_
Definition: Ioss_FaceGenerator.h:141
Ioss::FaceUnorderedSet
tsl::robin_set< Face, FaceHash, FaceEqual > FaceUnorderedSet
Definition: Ioss_FaceGenerator.h:119
Ioss::Face::add_element
void add_element(size_t element_id) const
Definition: Ioss_FaceGenerator.h:62
tsl::robin_set
Definition: robin_set.h:82
Ioss::Face::connectivity_
std::array< size_t, 4 > connectivity_
Definition: Ioss_FaceGenerator.h:85
Ioss::FaceGenerator::FaceGenerator
FaceGenerator(Ioss::Region &region)
Definition: Ioss_FaceGenerator.C:336
Ioss::FaceEqual::operator()
bool operator()(const Face &left, const Face &right) const
Definition: Ioss_FaceGenerator.h:95
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Ioss::Face::element
size_t element[2]
Definition: Ioss_FaceGenerator.h:83
Ioss::Face::hashId_
size_t hashId_
Definition: Ioss_FaceGenerator.h:68
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Ioss::FaceGenerator::~FaceGenerator
~FaceGenerator()
Definition: Ioss_FaceGenerator.h:126
INT
int INT
Definition: Ioss_StructuredBlock.h:53
Ioss::FaceEqual
Definition: Ioss_FaceGenerator.h:93
Ioss::Face
Definition: Ioss_FaceGenerator.h:56
Ioss::FaceHash::operator()
size_t operator()(const Face &face) const
Definition: Ioss_FaceGenerator.h:90
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:351
Ioss::FaceHash
Definition: Ioss_FaceGenerator.h:88
Ioss::FaceGenerator::generate_model_faces
void generate_model_faces(INT)
Definition: Ioss_FaceGenerator.C:408
Ioss::Face::elementCount_
int elementCount_
Definition: Ioss_FaceGenerator.h:84
Ioss::FaceGenerator::secondary
static size_t secondary
Definition: Ioss_FaceGenerator.h:135
Ioss::FaceGenerator
Definition: Ioss_FaceGenerator.h:122
Ioss::FaceGenerator::faces
FaceUnorderedSet & faces(const std::string &name="ALL")
Definition: Ioss_FaceGenerator.h:132
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:60
hopscotch_set.h
Ioss::FaceGenerator::generate_faces
void generate_faces(INT, bool block_by_block=false)
Definition: Ioss_FaceGenerator.C:341
Ioss::Face::Face
Face()=default