Debian Codegraph @

packages/seacas/libraries/ioss/src/text_mesh/Iotm_TextMeshSidesetSkinner.h

raw
1 // Copyright(C) 1999-2020, 2022 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 #pragma once
6
7 // ####################### Start Clang Header Tool Managed Headers ########################
8 // clang-format off
9 #include <ctype.h> // for toupper
10 #include <stddef.h> // for size_t
11 #include <algorithm> // for remove, etc
12 #include <iterator> // for insert_iterator
13 #include <map>
14 #include <set> // for set
15 #include <sstream> // for operator<<, etc
16 #include <string> // for basic_string, etc
17 #include <utility> // for pair
18 #include <vector> // for vector
19 #include <unordered_map>
20 #include <sstream> // for ostringstream
21 #include <iostream>
22 #include <functional>
23 #include <stdexcept>
24 #include <numeric>
25 #include <strings.h>
26
27 #include "Iotm_TextMeshFuncs.h"
28 #include "Iotm_TextMeshDataTypes.h"
29 #include "Iotm_TextMeshEntityGroup.h"
30 #include "Iotm_TextMeshAdjacencyGraph.h"
31
32 // clang-format on
33 // ####################### End Clang Header Tool Managed Headers ########################
34 namespace Iotm {
35 namespace text_mesh {
36
37 using ErrorHandler = std::function<void(const std::ostringstream &)>;
38
39 template <typename EntityId, typename Topology>
40 class SidesetSkinner : public SideAdjacencyGraph<EntityId, Topology>
41 {
42 public:
43 using BaseClass = SideAdjacencyGraph<EntityId, Topology>;
44
45 SidesetSkinner() = default;
46
47 ~SidesetSkinner() {}
48
49 size_t get_num_elements() const override
50 {
51 assert(m_textMeshData != nullptr);
52 return m_textMeshData->elementDataVec.size();
53 }
54
55 int get_element_proc(const size_t elemIndex) const override
56 {
57 assert(m_textMeshData != nullptr);
58 const ElementData<EntityId, Topology> &elemData = m_textMeshData->elementDataVec[elemIndex];
59 return elemData.proc;
60 }
61
62 bool element_has_any_node_on_proc(const size_t elemIndex, int proc) const override
63 {
64 assert(m_textMeshData != nullptr);
65 const ElementData<EntityId, Topology> &elemData = m_textMeshData->elementDataVec[elemIndex];
66
67 for (const EntityId &nodeId : elemData.nodeIds) {
68 const std::set<int> &procsForNode = m_textMeshData->procs_for_node(nodeId);
69 if (procsForNode.count(proc) > 0) {
70 return true;
71 }
72 }
73
74 return false;
75 }
76
77 const std::string &get_element_block_name(const size_t elemIndex) const override
78 {
79 assert(m_textMeshData != nullptr);
80 const ElementData<EntityId, Topology> &elemData = m_textMeshData->elementDataVec[elemIndex];
81 return elemData.partName;
82 }
83
84 const std::vector<EntityId> &get_element_node_ids(const size_t elemIndex) const override
85 {
86 assert(m_textMeshData != nullptr);
87 const ElementData<EntityId, Topology> &elemData = m_textMeshData->elementDataVec[elemIndex];
88 return elemData.nodeIds;
89 }
90
91 const Topology &get_element_topology(const size_t elemIndex) const override
92 {
93 assert(m_textMeshData != nullptr);
94 const ElementData<EntityId, Topology> &elemData = m_textMeshData->elementDataVec[elemIndex];
95 return elemData.topology;
96 }
97
98 EntityId get_element_id(const size_t elemIndex) const override
99 {
100 assert(m_textMeshData != nullptr);
101 const ElementData<EntityId, Topology> &elemData = m_textMeshData->elementDataVec[elemIndex];
102 return elemData.identifier;
103 }
104
105 void set_skin_blocks(const std::vector<std::string> &skinBlocks)
106 {
107 m_skinBlocks = skinBlocks;
108 }
109
110 void skin_blocks(const TextMeshData<EntityId, Topology> &textMeshData,
111 std::vector<std::pair<EntityId, int>> &elemSidePairs)
112 {
113 populate_skin_blocks(textMeshData.partIds);
114
115 if (!m_skinBlocks.empty()) {
116 set_text_mesh_data(textMeshData);
117 BaseClass::create_graph(m_skinBlocks);
118 reset_text_mesh_data();
119
120 for (auto iter = BaseClass::begin(); iter != BaseClass::end(); iter++) {
121 size_t elemIndex = iter->first;
122 const auto &faceConnections = iter->second;
123
124 std::vector<bool> hasConnection(faceConnections.numSides, false);
125 for (const auto &connection : faceConnections.connections) {
126 hasConnection[connection.thisSide - 1] = true;
127 }
128
129 for (unsigned i = 0; i < faceConnections.numSides; i++) {
130 if (!hasConnection[i]) {
131 EntityId elemId = textMeshData.elementDataVec[elemIndex].identifier;
132 int side = i + 1;
133 elemSidePairs.push_back(std::make_pair(elemId, side));
134 }
135 }
136 }
137 }
138 }
139
140 private:
141 void populate_skin_blocks(const PartIdMapping &partIds)
142 {
143 bool skinAll = false;
144 for (const std::string &block : m_skinBlocks) {
145 if (0 == strcasecmp("all", block.c_str())) {
146 skinAll = true;
147 break;
148 }
149 }
150
151 if (skinAll) {
152 m_skinBlocks = partIds.get_part_names();
153 }
154 }
155
156 void set_text_mesh_data(const TextMeshData<EntityId, Topology> &textMeshData)
157 {
158 m_textMeshData = &textMeshData;
159 }
160
161 void reset_text_mesh_data() { m_textMeshData = nullptr; }
162
163 const TextMeshData<EntityId, Topology> *m_textMeshData{nullptr};
164 std::vector<std::string> m_skinBlocks{};
165 };
166
167 } // namespace text_mesh
168 } // namespace Iotm