IOSS 2.0
Loading...
Searching...
No Matches
Ioss_FaceGenerator.h
Go to the documentation of this file.
1// Copyright(C) 1999-2024 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// See packages/seacas/LICENSE for details
6
7#pragma once
8
9#include <algorithm>
10#include <array>
11#include <cassert>
12#include <cstddef>
13#include <map>
14#include <string>
15#include <vector>
16
17#include "ioss_export.h"
18
19#define FG_USE_ROBIN
20#if defined FG_USE_STD
21#include <unordered_set>
22#elif defined FG_USE_HOPSCOTCH
23#include <hopscotch_set.h>
24#elif defined FG_USE_ROBIN
25#include <robin_set.h>
26#endif
27
28#include <utility>
29
30namespace Ioss {
31 class Region;
32
33 class IOSS_EXPORT Face
34 {
35 public:
36 Face() = default;
37 Face(size_t id, std::array<size_t, 4> conn) : hashId_(id), connectivity_(conn) {}
38 explicit Face(std::array<size_t, 4> conn);
39
40 void add_element(size_t element_id) const
41 {
42 if (elementCount_ < 2) {
43 element[elementCount_++] = element_id;
44 }
45 else {
46 face_element_error(element_id);
47 }
48 }
49
50 void add_element(size_t element_id, size_t face_ordinal) const
51 {
52 add_element(element_id * 10 + face_ordinal);
53 }
54
55 void face_element_error(size_t element_id) const;
56
57 size_t hashId_{0};
58
59 // NOTE: Not used at all by `Face` or `FaceGenerator` class, but are used by
60 // skinner to give a consistent element id in cases where there
61 // is a hash collision (face.id).
62
63 // NOTE: For interior faces, this will not be the same value for each
64 // face where the `hashId_` *will* be consistent for interior faces.
65 // Should only use this as an id if `elementCount_` is 1.
66
67 // NOTE: This could be used to do parallel or block boundary
68 // collision since it is calculated as 10*element_id + local_face,
69 // you could recover element_id and local_face and then set up
70 // parallel communication maps. May need to save the proc it is
71 // shared with also (which is available in git history)
72 mutable std::array<size_t, 2> element{};
73 mutable int elementCount_{0}; // Should be max of 2 solid elements...
74 std::array<size_t, 4> connectivity_{};
75 };
76
77 struct IOSS_EXPORT FaceHash
78 {
79 size_t operator()(const Face &face) const { return face.hashId_; }
80 };
81
82 struct IOSS_EXPORT FaceEqual
83 {
84 bool operator()(const Face &left, const Face &right) const
85 {
86 if (left.hashId_ != right.hashId_) {
87 return false;
88 }
89 // Hash (hashId_) is equal
90 // Check whether same vertices (can be in different order)
91 // Most (All?) of the time, there are no hashId_ collisions, so this test will not
92 // find a difference and the function will return 'true'
93 // However, for some reason, removing this check does not change the execution time
94 // appreiciably...
95
96 // TODO: Loop can probably be replaced by std::all_of...
97 for (auto lvert : left.connectivity_) {
98 if (std::find(right.connectivity_.cbegin(), right.connectivity_.cend(), lvert) ==
99 right.connectivity_.cend()) {
100 // Not found, therefore not the same.
101 return false;
102 }
103 }
104 return true;
105 }
106 };
107
108#if defined FG_USE_STD
109 using FaceUnorderedSet = std::unordered_set<Face, FaceHash, FaceEqual>;
110#elif defined FG_USE_HOPSCOTCH
112 // using FaceUnorderedSet = tsl::hopscotch_pg_set<Face, FaceHash, FaceEqual>;
113#elif defined FG_USE_ROBIN
115 // using FaceUnorderedSet = tsl::robin_pg_set<Face, FaceHash, FaceEqual>;
116#endif
117 class IOSS_EXPORT FaceGenerator
118 {
119 public:
120 explicit FaceGenerator(Ioss::Region &region);
121
122 static size_t id_hash(size_t global_id);
123
124 template <typename INT>
125 void generate_faces(INT /*dummy*/, bool block_by_block = false, bool local_ids = false);
126 FaceUnorderedSet &faces(const std::string &name = "ALL") { return faces_[name]; }
127
128 //! Given a local node id (0-based), return the hashed value.
129 size_t node_id_hash(size_t local_node_id) const { return hashIds_[local_node_id]; }
130
131 private:
132 template <typename INT> void hash_node_ids(const std::vector<INT> &node_ids);
133 template <typename INT> void generate_block_faces(INT /*dummy*/, bool local_ids);
134 template <typename INT> void generate_model_faces(INT /*dummy*/, bool local_ids);
135
137 std::map<std::string, FaceUnorderedSet> faces_;
138 std::vector<size_t> hashIds_;
139 };
140
141} // namespace Ioss
Definition Ioss_FaceGenerator.h:118
Ioss::Region & region_
Definition Ioss_FaceGenerator.h:136
FaceUnorderedSet & faces(const std::string &name="ALL")
Definition Ioss_FaceGenerator.h:126
std::map< std::string, FaceUnorderedSet > faces_
Definition Ioss_FaceGenerator.h:137
size_t node_id_hash(size_t local_node_id) const
Given a local node id (0-based), return the hashed value.
Definition Ioss_FaceGenerator.h:129
std::vector< size_t > hashIds_
Definition Ioss_FaceGenerator.h:138
Definition Ioss_FaceGenerator.h:34
std::array< size_t, 4 > connectivity_
Definition Ioss_FaceGenerator.h:74
Face(size_t id, std::array< size_t, 4 > conn)
Definition Ioss_FaceGenerator.h:37
size_t hashId_
Definition Ioss_FaceGenerator.h:57
void add_element(size_t element_id) const
Definition Ioss_FaceGenerator.h:40
Face()=default
void add_element(size_t element_id, size_t face_ordinal) const
Definition Ioss_FaceGenerator.h:50
A grouping entity that contains other grouping entities.
Definition Ioss_Region.h:90
Definition hopscotch_set.h:82
Definition robin_set.h:90
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
tsl::robin_set< Face, FaceHash, FaceEqual > FaceUnorderedSet
Definition Ioss_FaceGenerator.h:114
Definition Ioss_FaceGenerator.h:83
bool operator()(const Face &left, const Face &right) const
Definition Ioss_FaceGenerator.h:84
Definition Ioss_FaceGenerator.h:78
size_t operator()(const Face &face) const
Definition Ioss_FaceGenerator.h:79