Debian Codegraph @

packages/seacas/libraries/ioss/src/text_mesh/Iotm_TextMeshSideset.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_TextMeshSidesetSplitter.h"
31 #include "Iotm_TextMeshSidesetSkinner.h"
32
33 // clang-format on
34 // ####################### End Clang Header Tool Managed Headers ########################
35 namespace Iotm {
36 namespace text_mesh {
37
38 using ErrorHandler = std::function<void(const std::ostringstream &)>;
39
40 template <typename EntityId> using SidesetDataType = std::pair<EntityId, int>;
41
42 template <typename EntityId, typename Topology>
43 struct SidesetData : public EntityGroupData<SidesetDataType<EntityId>>
44 {
45 using DataType = SidesetDataType<EntityId>;
46 using BaseClass = EntityGroupData<SidesetDataType<EntityId>>;
47
48 void set_split_type(SplitType splitType) { m_sidesetSplitter.set_split_type(splitType); }
49 SplitType get_split_type() const { return m_sidesetSplitter.get_split_type(); }
50
51 void set_skin_blocks(const std::vector<std::string> &skinBlocks)
52 {
53 m_sidesetSkinner.set_skin_blocks(skinBlocks);
54 }
55
56 void set_error_handler(ErrorHandler errorHandler)
57 {
58 m_sidesetSkinner.set_error_handler(errorHandler);
59 m_sidesetSplitter.set_error_handler(errorHandler);
60 }
61
62 void split(const std::vector<ElementData<EntityId, Topology>> &elementData)
63 {
64 m_sidesetSplitter.split(*this, elementData);
65 }
66
67 void skin_blocks(const TextMeshData<EntityId, Topology> &textMeshData)
68 {
69 m_sidesetSkinner.skin_blocks(textMeshData, BaseClass::data);
70 }
71
72 std::vector<size_t> get_sideblock_indices_local_to_proc(const SideBlockInfo &info,
73 int proc) const
74 {
75 return m_sidesetSplitter.get_indices_local_to_proc(info.sideIndex, proc);
76 }
77
78 SideBlockInfo get_side_block_info(const std::string &sideBlockName) const
79 {
80 return m_sidesetSplitter.get_side_block_info(sideBlockName);
81 }
82
83 std::vector<SideBlockInfo> get_side_block_info() const
84 {
85 return m_sidesetSplitter.get_side_block_info();
86 }
87
88 bool has_default_exodus_name() const
89 {
90 if (BaseClass::has_name()) {
91 std::pair<unsigned, bool> result = get_id_from_part_name(BaseClass::name, "SURFACE_");
92 return result.second;
93 }
94
95 return false;
96 }
97
98 SidesetSkinner<EntityId, Topology> m_sidesetSkinner;
99 SidesetSplitter<EntityId, Topology> m_sidesetSplitter;
100 };
101
102 template <typename EntityId, typename Topology>
103 class Sidesets : public EntityGroup<SidesetData<EntityId, Topology>>
104 {
105 public:
106 using BaseClass = EntityGroup<SidesetData<EntityId, Topology>>;
107
108 Sidesets() : BaseClass("SIDESET", "SURFACE_", {"BLOCK_", "NODELIST_", "ASSEMBLY_"}) {}
109
110 void set_error_handler(ErrorHandler errorHandler) override
111 {
112 BaseClass::set_error_handler(errorHandler);
113
114 for (SidesetData<EntityId, Topology> &sidesetData : BaseClass::m_groupDataVec) {
115 sidesetData.set_error_handler(errorHandler);
116 }
117 }
118
119 void finalize_parse(const TextMeshData<EntityId, Topology> &data)
120 {
121 BaseClass::finalize_parse();
122
123 for (SidesetData<EntityId, Topology> &sidesetData : BaseClass::m_groupDataVec) {
124 sidesetData.skin_blocks(data);
125 sidesetData.split(data.elementDataVec);
126 }
127 }
128 };
129
130 template <typename EntityId> class SidesetParser
131 {
132 public:
133 SidesetParser() : m_splitType(NO_SPLIT)
134 {
135 ErrorHandler errorHandler = [](const std::ostringstream &errmsg) {
136 default_error_handler(errmsg);
137 };
138 set_error_handler(errorHandler);
139 }
140
141 void set_error_handler(ErrorHandler errorHandler) { m_errorHandler = errorHandler; }
142
143 std::string get_name() { return m_name; }
144
145 const std::vector<std::pair<EntityId, int>> &get_sideset_data() { return m_elemSidePairs; }
146
147 SplitType get_split_type() { return m_splitType; }
148
149 const std::vector<std::string> &get_skin_blocks() const { return m_skinnedBlocks; }
150
151 // Expected format for sideset string data is:
152 // "name=<name>; data=elem_1,side_1,elem_2,side_2,....,elem_n,side_n;
153 // split=<block|topology|none>; skin=<{block list}|all>;" Cannot specify skin and data at the
154 // same time
155 void parse(const std::string &parseData)
156 {
157 auto options = get_tokens(parseData, ";");
158
159 for (const auto &option : options) {
160 parse_option_group(option);
161 }
162 }
163
164 void verify_parse() const
165 {
166 if (!m_skinnedBlocks.empty() && !m_elemSidePairs.empty()) {
167 std::ostringstream errmsg;
168 errmsg << "Error! Sideset with name: " << m_name
169 << " is attempting to set element/side pair data *AND* use skinning.";
170 m_errorHandler(errmsg);
171 }
172 }
173
174 private:
175 void parse_option(std::string optionName, const std::string &optionValue)
176 {
177 convert_to_lower_case(optionName);
178
179 if (optionName == "name") {
180 parse_name(optionValue);
181 }
182 else if (optionName == "data") {
183 parse_element_side_pairs(optionValue);
184 }
185 else if (optionName == "split") {
186 parse_split_type(optionValue);
187 }
188 else if (optionName == "skin") {
189 parse_skin_blocks(optionValue);
190 }
191 else {
192 std::ostringstream errmsg;
193 errmsg << "Unrecognized sideset option: " << optionName;
194 m_errorHandler(errmsg);
195 }
196 }
197
198 void parse_option_group(const std::string &option)
199 {
200 if (!option.empty()) {
201 auto optionTokens = get_tokens(option, "=");
202
203 if (optionTokens.size() != 2) {
204 std::ostringstream errmsg;
205 errmsg << "Unrecognized sideset option: " << option;
206 m_errorHandler(errmsg);
207 }
208
209 parse_option(optionTokens[0], optionTokens[1]);
210 }
211 }
212
213 void parse_name(const std::string &data) { m_name = data; }
214
215 void parse_skin_blocks(const std::string &data) { m_skinnedBlocks = get_tokens(data, ","); }
216
217 void parse_element_side_pairs(const std::string &data)
218 {
219 auto sidesetData = get_tokens(data, ",");
220
221 if (sidesetData.size() % 2 != 0) {
222 std::ostringstream errmsg;
223 errmsg << "Unmatched element/ordinal pairs in sideset data: " << data;
224 m_errorHandler(errmsg);
225 }
226
227 for (unsigned i = 0; i < sidesetData.size(); i += 2) {
228 EntityId elem = std::stoull(sidesetData[i]);
229 int side = std::stoi(sidesetData[i + 1]);
230
231 if (side <= 0) {
232 std::ostringstream errmsg;
233 errmsg << "Invalid element/ordinal pair {" << sidesetData[i] << ","
234 << sidesetData[i + 1] << "}";
235 m_errorHandler(errmsg);
236 }
237
238 m_elemSidePairs.push_back(std::make_pair(elem, side));
239 }
240 }
241
242 void parse_split_type(std::string splitName)
243 {
244 convert_to_lower_case(splitName);
245
246 if (splitName == "none") {
247 m_splitType = NO_SPLIT;
248 }
249 else if (splitName == "block") {
250 m_splitType = ELEMENT_BLOCK;
251 }
252 else if (splitName == "topology") {
253 m_splitType = TOPOLOGY;
254 }
255 else {
256 std::ostringstream errmsg;
257 errmsg << "Unrecognized sideset split type: " << splitName;
258 m_errorHandler(errmsg);
259 }
260 }
261
262 std::vector<std::pair<EntityId, int>> m_elemSidePairs{};
263 std::string m_name{};
264 std::vector<std::string> m_skinnedBlocks{};
265 SplitType m_splitType{NO_SPLIT};
266 ErrorHandler m_errorHandler;
267 };
268
269 } // namespace text_mesh
270 } // namespace Iotm