IOSS 2.0
Iotm_TextMeshNodeset.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
26#include "Iotm_TextMeshFuncs.h"
28
29// clang-format on
30// ####################### End Clang Header Tool Managed Headers ########################
31namespace Iotm {
32 namespace text_mesh {
33
34 using ErrorHandler = std::function<void(const std::ostringstream &)>;
35
36 template <typename EntityId> using NodesetDataType = EntityId;
37
38 template <typename EntityId>
39 struct NodesetData : public EntityGroupData<NodesetDataType<EntityId>>
40 {
42 };
43
44 template <typename EntityId> class Nodesets : public EntityGroup<NodesetData<EntityId>>
45 {
46 public:
48 : EntityGroup<NodesetData<EntityId>>("NODESET", "NODELIST_",
49 {"BLOCK_", "SURFACE_", "ASSEMBLY_"})
50 {
51 }
52 };
53
54 template <typename EntityId> class NodesetParser
55 {
56 public:
58 {
59 ErrorHandler errorHandler = [](const std::ostringstream &errmsg) {
61 };
62 set_error_handler(errorHandler);
63 }
64
65 void set_error_handler(ErrorHandler errorHandler) { m_errorHandler = errorHandler; }
66
67 std::string get_name() { return m_name; }
68
69 const std::vector<EntityId> &get_nodeset_data() { return m_nodeList; }
70
71 // Expected format for nodeset string data is:
72 // "[name=<name>;] data=node_1,node_2,....,node_n"
73 // Only data keyword is required
74 void parse(const std::string &parseData)
75 {
76 auto options = get_tokens(parseData, ";");
77
78 for (const auto &option : options) {
79 parse_option_group(option);
80 }
81 }
82
83 private:
84 void parse_option(std::string optionName, const std::string &optionValue)
85 {
86 convert_to_lowercase(optionName);
87
88 if (optionName == "name") {
89 parse_name(optionValue);
90 }
91 else if (optionName == "data") {
92 parse_node_data(optionValue);
93 }
94 else {
95 std::ostringstream errmsg;
96 errmsg << "Unrecognized nodeset option: " << optionName;
97 m_errorHandler(errmsg);
98 }
99 }
100
101 void parse_option_group(const std::string &option)
102 {
103 if (!option.empty()) {
104 auto optionTokens = get_tokens(option, "=");
105
106 if (optionTokens.size() != 2) {
107 std::ostringstream errmsg;
108 errmsg << "Unrecognized nodeset option: " << option;
109 m_errorHandler(errmsg);
110 }
111
112 parse_option(optionTokens[0], optionTokens[1]);
113 }
114 }
115
116 void parse_name(const std::string &data) { m_name = data; }
117
118 void parse_node_data(const std::string &data)
119 {
120 auto nodesetData = get_tokens(data, ",");
121
122 for (const std::string &nodeString : nodesetData) {
123 if (!is_positive_number(nodeString)) {
124 std::ostringstream errmsg;
125 errmsg << "Unrecognized nodeset node id: " << nodeString;
126 m_errorHandler(errmsg);
127 }
128 EntityId node = std::stoull(nodeString);
129 m_nodeList.push_back(node);
130 }
131 }
132
133 std::vector<EntityId> m_nodeList{};
134 std::string m_name{};
136 };
137
138 } // namespace text_mesh
139} // namespace Iotm
EntityGroup(const std::string &type, const std::string &namePrefix, const std::vector< std::string > &invalidNamePrefixes)
Definition Iotm_TextMeshEntityGroup.h:64
std::string m_name
Definition Iotm_TextMeshNodeset.h:134
const std::vector< EntityId > & get_nodeset_data()
Definition Iotm_TextMeshNodeset.h:69
std::string get_name()
Definition Iotm_TextMeshNodeset.h:67
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshNodeset.h:65
void parse_name(const std::string &data)
Definition Iotm_TextMeshNodeset.h:116
void parse_option_group(const std::string &option)
Definition Iotm_TextMeshNodeset.h:101
NodesetParser()
Definition Iotm_TextMeshNodeset.h:57
void parse_node_data(const std::string &data)
Definition Iotm_TextMeshNodeset.h:118
void parse_option(std::string optionName, const std::string &optionValue)
Definition Iotm_TextMeshNodeset.h:84
void parse(const std::string &parseData)
Definition Iotm_TextMeshNodeset.h:74
ErrorHandler m_errorHandler
Definition Iotm_TextMeshNodeset.h:135
std::vector< EntityId > m_nodeList
Definition Iotm_TextMeshNodeset.h:133
Nodesets()
Definition Iotm_TextMeshNodeset.h:47
Definition Iotm_TextMeshAdjacencyGraph.h:39
bool is_positive_number(const std::string &str)
Definition Iotm_TextMeshFuncs.h:106
std::function< void(const std::ostringstream &)> ErrorHandler
Definition Iotm_TextMeshAdjacencyGraph.h:41
void convert_to_lowercase(std::string &str)
Definition Iotm_TextMeshFuncs.h:101
std::vector< std::string > get_tokens(const std::string &str, const std::string &separators)
Definition Iotm_TextMeshFuncs.h:76
void default_error_handler(const std::ostringstream &message)
Definition Iotm_TextMeshFuncs.h:40
EntityId NodesetDataType
Definition Iotm_TextMeshNodeset.h:36
A namespace for the textmesh database format.
Definition Iotm_DatabaseIO.C:95
int64_t EntityId
Definition Iotm_TextMesh.h:33
Definition Iotm_TextMeshEntityGroup.h:43
Definition Iotm_TextMeshNodeset.h:40
NodesetDataType< EntityId > DataType
Definition Iotm_TextMeshNodeset.h:41