| 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_TextMeshEntityGroup.h" |
| 29 |
|
| 30 |
// clang-format on |
| 31 |
// ####################### End Clang Header Tool Managed Headers ######################## |
| 32 |
namespace 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 |
{ |
| 42 |
using DataType = NodesetDataType<EntityId>; |
| 43 |
}; |
| 44 |
|
| 45 |
template <typename EntityId> class Nodesets : public EntityGroup<NodesetData<EntityId>> |
| 46 |
{ |
| 47 |
public: |
| 48 |
Nodesets() |
| 49 |
: EntityGroup<NodesetData<EntityId>>("NODESET", "NODELIST_", |
| 50 |
{"BLOCK_", "SURFACE_", "ASSEMBLY_"}) |
| 51 |
{ |
| 52 |
} |
| 53 |
}; |
| 54 |
|
| 55 |
template <typename EntityId> class NodesetParser |
| 56 |
{ |
| 57 |
public: |
| 58 |
NodesetParser() |
| 59 |
{ |
| 60 |
ErrorHandler errorHandler = [](const std::ostringstream &errmsg) { |
| 61 |
default_error_handler(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{}; |
| 136 |
ErrorHandler m_errorHandler; |
| 137 |
}; |
| 138 |
|
| 139 |
} // namespace text_mesh |
| 140 |
} // namespace Iotm |