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