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 #include <unordered_set>
41 #include <utility>
42 
43 namespace Ioss {
44  class Region;
45 
46  class Face
47  {
48  public:
50  Face(size_t id, std::array<size_t, 4> conn)
51  : id_(id), elementCount_(0), sharedWithProc_(-1), connectivity_(std::move(conn))
52  {
53  }
54 
55  void add_element(size_t element_id) const
56  {
57  assert(elementCount_ < 2);
58  element[elementCount_++] = element_id;
59  }
60 
61  size_t id_;
62  mutable size_t element[2]{};
63  mutable int elementCount_; // Should be max of 2 solid elements...
64  mutable int sharedWithProc_;
65  std::array<size_t, 4> connectivity_{};
66  };
67 
68  struct FaceHash
69  {
70  size_t operator()(const Face &face) const { return face.id_; }
71  };
72 
73  struct FaceEqual
74  {
75  bool operator()(const Face &left, const Face &right) const
76  {
77  if (left.id_ != right.id_) {
78  return false;
79  }
80  // Hash (id_) is equal
81  // Check whether same vertices (can be in different order)
82  for (auto lvert : left.connectivity_) {
83  if (std::find(right.connectivity_.cbegin(), right.connectivity_.cend(), lvert) ==
84  right.connectivity_.cend()) {
85  // Not found, therefore not the same.
86  return false;
87  }
88  }
89  return true;
90  }
91  };
92 
93  using FaceUnorderedSet = std::unordered_set<Face, FaceHash, FaceEqual>;
95  {
96  public:
97  explicit FaceGenerator(Ioss::Region &region);
98 
99  template <typename INT> void generate_faces(INT /*dummy*/);
100  FaceUnorderedSet & faces() { return faces_; }
101 
102  private:
105  };
106 } // namespace Ioss
107 
108 #endif
int elementCount_
Definition: Ioss_FaceGenerator.h:63
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Definition: Ioss_FaceGenerator.h:94
std::array< size_t, 4 > connectivity_
Definition: Ioss_FaceGenerator.h:65
Definition: Ioss_FaceGenerator.h:68
Definition: json.h:1157
size_t element[2]
Definition: Ioss_FaceGenerator.h:62
Face(size_t id, std::array< size_t, 4 > conn)
Definition: Ioss_FaceGenerator.h:50
int sharedWithProc_
Definition: Ioss_FaceGenerator.h:64
Ioss::Region & region_
Definition: Ioss_FaceGenerator.h:103
size_t id_
Definition: Ioss_FaceGenerator.h:61
void add_element(size_t element_id) const
Definition: Ioss_FaceGenerator.h:55
FaceUnorderedSet faces_
Definition: Ioss_FaceGenerator.h:104
Definition: Ioss_FaceGenerator.h:46
size_t operator()(const Face &face) const
Definition: Ioss_FaceGenerator.h:70
int INT
Definition: Ioss_StructuredBlock.h:53
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Face()
Definition: Ioss_FaceGenerator.h:49
std::unordered_set< Face, FaceHash, FaceEqual > FaceUnorderedSet
Definition: Ioss_FaceGenerator.h:93
FaceUnorderedSet & faces()
Definition: Ioss_FaceGenerator.h:100
bool operator()(const Face &left, const Face &right) const
Definition: Ioss_FaceGenerator.h:75
Definition: Ioss_FaceGenerator.h:73