IOSS 2.0
Loading...
Searching...
No Matches
Iotm_TextMeshSideset.h
Go to the documentation of this file.
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"
32
33// clang-format on
34// ####################### End Clang Header Tool Managed Headers ########################
35namespace 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 {
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
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
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
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
100 };
101
102 template <typename EntityId, typename Topology>
103 class Sidesets : public EntityGroup<SidesetData<EntityId, Topology>>
104 {
105 public:
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
115 sidesetData.set_error_handler(errorHandler);
116 }
117 }
118
120 {
122
124 sidesetData.skin_blocks(data);
125 sidesetData.split(data.elementDataVec);
126 }
127 }
128 };
129
130 template <typename EntityId> class SidesetParser
131 {
132 public:
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
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") {
248 }
249 else if (splitName == "block") {
251 }
252 else if (splitName == "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{};
267 };
268
269 } // namespace text_mesh
270} // namespace Iotm
Definition Iotm_TextMeshEntityGroup.h:53
std::vector< SidesetData< EntityId, Topology > > m_groupDataVec
Definition Iotm_TextMeshEntityGroup.h:252
void finalize_parse()
Definition Iotm_TextMeshEntityGroup.h:87
virtual void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshEntityGroup.h:68
Definition Iotm_TextMeshSideset.h:131
void verify_parse() const
Definition Iotm_TextMeshSideset.h:164
const std::vector< std::string > & get_skin_blocks() const
Definition Iotm_TextMeshSideset.h:149
std::vector< std::pair< EntityId, int > > m_elemSidePairs
Definition Iotm_TextMeshSideset.h:262
void parse(const std::string &parseData)
Definition Iotm_TextMeshSideset.h:155
std::string m_name
Definition Iotm_TextMeshSideset.h:263
ErrorHandler m_errorHandler
Definition Iotm_TextMeshSideset.h:266
void parse_skin_blocks(const std::string &data)
Definition Iotm_TextMeshSideset.h:215
void parse_option(std::string optionName, const std::string &optionValue)
Definition Iotm_TextMeshSideset.h:175
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshSideset.h:141
void parse_split_type(std::string splitName)
Definition Iotm_TextMeshSideset.h:242
SplitType m_splitType
Definition Iotm_TextMeshSideset.h:265
void parse_option_group(const std::string &option)
Definition Iotm_TextMeshSideset.h:198
void parse_element_side_pairs(const std::string &data)
Definition Iotm_TextMeshSideset.h:217
SidesetParser()
Definition Iotm_TextMeshSideset.h:133
std::string get_name()
Definition Iotm_TextMeshSideset.h:143
void parse_name(const std::string &data)
Definition Iotm_TextMeshSideset.h:213
const std::vector< std::pair< EntityId, int > > & get_sideset_data()
Definition Iotm_TextMeshSideset.h:145
SplitType get_split_type()
Definition Iotm_TextMeshSideset.h:147
std::vector< std::string > m_skinnedBlocks
Definition Iotm_TextMeshSideset.h:264
Definition Iotm_TextMeshSidesetSkinner.h:41
Definition Iotm_TextMeshSidesetSplitter.h:67
Definition Iotm_TextMeshSideset.h:104
void set_error_handler(ErrorHandler errorHandler) override
Definition Iotm_TextMeshSideset.h:110
void finalize_parse(const TextMeshData< EntityId, Topology > &data)
Definition Iotm_TextMeshSideset.h:119
Sidesets()
Definition Iotm_TextMeshSideset.h:108
std::function< void(const std::ostringstream &)> ErrorHandler
Definition Iotm_TextMeshAdjacencyGraph.h:35
std::pair< EntityId, int > SidesetDataType
Definition Iotm_TextMeshSideset.h:40
std::vector< std::string > get_tokens(const std::string &str, const std::string &separators)
Definition Iotm_TextMeshFuncs.h:68
void default_error_handler(const std::ostringstream &message)
Definition Iotm_TextMeshFuncs.h:32
void convert_to_lower_case(std::string &str)
Definition Iotm_TextMeshFuncs.h:93
std::pair< unsigned, bool > get_id_from_part_name(const std::string &name, const std::string &prefix)
Definition Iotm_TextMeshFuncs.h:118
SplitType
Definition Iotm_TextMeshSidesetSplitter.h:49
@ TOPOLOGY
Definition Iotm_TextMeshSidesetSplitter.h:49
@ NO_SPLIT
Definition Iotm_TextMeshSidesetSplitter.h:49
@ ELEMENT_BLOCK
Definition Iotm_TextMeshSidesetSplitter.h:49
A namespace for the textmesh database format.
Definition Iotm_DatabaseIO.C:95
int64_t EntityId
Definition Iotm_TextMesh.h:33
Definition Iotm_TextMeshDataTypes.h:277
Definition Iotm_TextMeshEntityGroup.h:37
std::string name
Definition Iotm_TextMeshEntityGroup.h:43
std::vector< DataType > data
Definition Iotm_TextMeshEntityGroup.h:45
bool has_name() const
Definition Iotm_TextMeshEntityGroup.h:48
Definition Iotm_TextMeshSidesetSplitter.h:39
std::vector< size_t > sideIndex
Definition Iotm_TextMeshSidesetSplitter.h:45
Definition Iotm_TextMeshSidesetSplitter.h:64
std::vector< size_t > get_sideblock_indices_local_to_proc(const SideBlockInfo &info, int proc) const
Definition Iotm_TextMeshSideset.h:72
SideBlockInfo get_side_block_info(const std::string &sideBlockName) const
Definition Iotm_TextMeshSideset.h:78
void split(const std::vector< ElementData< EntityId, Topology > > &elementData)
Definition Iotm_TextMeshSideset.h:62
SidesetSplitter< EntityId, Topology > m_sidesetSplitter
Definition Iotm_TextMeshSideset.h:99
void set_split_type(SplitType splitType)
Definition Iotm_TextMeshSideset.h:48
void set_skin_blocks(const std::vector< std::string > &skinBlocks)
Definition Iotm_TextMeshSideset.h:51
SidesetDataType< EntityId > DataType
Definition Iotm_TextMeshSideset.h:45
SplitType get_split_type() const
Definition Iotm_TextMeshSideset.h:49
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshSideset.h:56
std::vector< SideBlockInfo > get_side_block_info() const
Definition Iotm_TextMeshSideset.h:83
bool has_default_exodus_name() const
Definition Iotm_TextMeshSideset.h:88
void skin_blocks(const TextMeshData< EntityId, Topology > &textMeshData)
Definition Iotm_TextMeshSideset.h:67
SidesetSkinner< EntityId, Topology > m_sidesetSkinner
Definition Iotm_TextMeshSideset.h:98
Definition Iotm_TextMeshDataTypes.h:315