7#include "iotm_export.h"
21#include <unordered_map>
40 using ErrorHandler = std::function<void(
const std::ostringstream &)>;
57 return std::stoi(m_oldToken);
63 return std::stoul(m_oldToken);
69 return make_upper_case(m_oldToken);
76 bool has_number()
const {
return has_token() && m_isNumber; }
77 bool has_string()
const {
return has_token() && !has_number() && !has_newline(); }
84 if (char_is_newline()) {
94 while (has_more_input()) {
95 if (char_is_whitespace()) {
100 if (char_is_comma()) {
105 if (char_is_newline()) {
109 m_isNumber &= char_is_digit();
110 m_token += current_char();
120 bool char_is_digit() {
return std::isdigit(
static_cast<unsigned char>(current_char())); }
126 std::transform(str.begin(), str.end(), str.begin(), ::toupper);
130 std::string m_input{};
131 unsigned m_currentIndex{0};
133 std::string m_oldToken{};
134 std::string m_token{};
136 bool m_isNumber{
false};
176 if (!parameters.empty()) {
177 std::vector<std::string> optionGroups =
get_tokens(parameters,
"|");
190 m_data.partIds.finalize_parse();
192 m_data.nodesets.finalize_parse();
193 m_data.assemblies.finalize_parse();
211 std::ostringstream errmsg;
236 std::ostringstream errmsg;
237 errmsg <<
"Spatial dimension has already been parsed! Check syntax.";
241 if (option.size() == 2) {
244 std::ostringstream errmsg;
246 <<
" not defined to be 2 or 3.";
253 std::ostringstream errmsg;
254 errmsg <<
"Error! Invalid spatial dimension syntax.";
261 std::vector<double> swapVectorForDeallocation;
278 std::ostringstream errmsg;
279 errmsg <<
"Coordinates have already been parsed! Check syntax.";
283 if (coordinatesOptionGroup.size() > 1) {
284 const std::vector<std::string> &coordinateTokens =
287 for (
const auto &token : coordinateTokens) {
288 double coord = std::stod(token);
296 template <
typename DataType>
298 const std::string &entityType,
299 const std::set<std::string> &entitySetNames)
301 std::string groupName = groupData.
name;
304 if (entitySetNames.count(groupName) > 0) {
305 std::ostringstream errmsg;
306 errmsg <<
"Error! " << groupData.
type <<
" with id: " << groupData.
id
307 <<
" and name: " << groupData.
name <<
" is referencing " << entityType
308 <<
" with same name.";
313 template <
typename SrcDataGroup,
typename DestDataGroup>
315 const DestDataGroup &destGroup)
317 std::set<std::string> groupNames =
transform_to_set(destGroup.get_part_names());
319 for (
const auto &srcGroupData : srcGroup.get_group_data()) {
328 m_data.sidesets.get_group_data()) {
329 for (
const std::pair<EntityId, int> &elemSidePair : sidesetData.data) {
331 if (!std::binary_search(
m_data.elementDataVec.begin(),
m_data.elementDataVec.end(),
333 std::ostringstream errmsg;
334 errmsg <<
"Error! Sideset with id: " << sidesetData.id
335 <<
" and name: " << sidesetData.name <<
" has reference to invalid element '"
359 for (
const EntityId nodeId : nodesetData.data) {
360 if (
m_data.nodeIds.count(nodeId) == 0) {
361 std::ostringstream errmsg;
362 errmsg <<
"Error! Nodeset with id: " << nodesetData.id
363 <<
" and name: " << nodesetData.name <<
" has reference to invalid node '"
384 template <
typename T>
388 for (
const std::string &entry : assemblyData.
data) {
389 if (!group.is_registered(entry)) {
390 std::ostringstream errmsg;
391 errmsg <<
"Error! Assembly with id: " << assemblyData.
id
392 <<
" and name: " << assemblyData.
name <<
" has reference to invalid "
393 << group.get_group_type() <<
" '" << entry <<
"'.";
402 const AssemblyType assemblyType = assemblyData.get_assembly_type();
404 switch (assemblyType) {
405 case AssemblyType::BLOCK:
408 case AssemblyType::SIDESET:
411 case AssemblyType::NODESET:
414 case AssemblyType::ASSEMBLY:
418 std::ostringstream errmsg;
419 errmsg <<
"Error! Assembly with id: " << assemblyData.id
420 <<
" and name: " << assemblyData.name <<
" does not have a valid assembly type '"
421 << assemblyType <<
"'.";
436 for (
const std::string &assembly :
m_data.assemblies.get_part_names()) {
437 if (
m_data.assemblies.is_cyclic(assembly)) {
438 std::ostringstream errmsg;
439 errmsg <<
"Error! Assembly with name: '" << assembly <<
"' has a cyclic dependency.";
454 if (sidesetOptionGroup.size() > 1) {
457 parser.
parse(sidesetOptionGroup[1]);
470 if (nodesetOptionGroup.size() > 1) {
473 parser.
parse(nodesetOptionGroup[1]);
482 if (assemblyOptionGroup.size() > 1) {
485 parser.
parse(assemblyOptionGroup[1]);
497 out <<
"\nValid Options for TextMesh parameter string:\n"
498 "\tPROC_ID,ELEM_ID,TOPOLOGY,{NODE CONNECTIVITY LIST}[,PART_NAME[,PART_ID]] "
500 "element list .. first "
502 "\t|coordinates:x_1,y_1[,z_1], x_2,y_2[,z_2], ...., x_n,y_n[,z_n] (specifies "
504 "\t|sideset:[name=<name>;] data=elem_1,side_1,elem_2,side_2,....,elem_n,side_n; "
505 "[split=<block|topology|none>;] [skin=<block list|all>;]"
506 "(specifies sideset data)\n"
507 "\t|nodeset:[name=<name>;] data=node_1,node_2,....,node_n (specifies nodeset data)\n"
508 "\t|assembly:[name=<name>;] type=<assembly|block|sideset|nodeset>; "
509 "member=member_1,...,member_n (specifies assembly hierarchy)\n"
510 "\t|dimension:spatialDimension (specifies spatial dimension .. default is 3)\n"
511 "\t|help -- show this list\n\n";
516 std::ostringstream errmsg;
517 errmsg <<
"ERROR: Unrecognized option '" << optionType <<
"'. It will be ignored.\n";
523 for (
size_t i = 1; i < optionGroups.size(); i++) {
524 std::vector<std::string> optionGroup =
get_tokens(optionGroups[i],
":");
525 std::string optionType = optionGroup[0];
528 if (optionType ==
"coordinates") {
531 else if (optionType ==
"dimension") {
534 else if (optionType ==
"sideset") {
537 else if (optionType ==
"nodeset") {
540 else if (optionType ==
"assembly") {
543 else if (optionType ==
"help") {
590 m_data.partIds.set_error_handler(errorHandler);
591 m_data.coords.set_error_handler(errorHandler);
592 m_data.sidesets.set_error_handler(errorHandler);
593 m_data.nodesets.set_error_handler(errorHandler);
594 m_data.assemblies.set_error_handler(errorHandler);
601 ErrorHandler errorHandler = [](
const std::ostringstream &errmsg) {
627 m_data.add_element(elemData);
633 std::sort(
m_data.elementDataVec.begin(),
m_data.elementDataVec.end(),
673 std::vector<EntityId> nodeIds;
683 std::string partName;
689 partName =
"block_" + topology.name();
694 m_data.partIds.register_part_name_with_id(partName, partId);
697 m_data.partIds.register_part_name(partName);
715 if (!hasNextRequiredField) {
716 std::ostringstream errmsg;
718 <<
"Error! Each line must contain the following fields (with at least one node): "
719 "Processor, GlobalId, Element Topology, NodeIds. Error on line "
728 if (!requiredCondition) {
729 std::ostringstream errmsg;
730 errmsg <<
"Error! Each line should not contain more than the following fields (with at "
732 "Processor, GlobalId, Element Topology, NodeIds, Part Name, PartId. "
742 std::ostringstream errmsg;
743 errmsg <<
"Error! Topology = >>" << providedName <<
"<< is invalid from line "
748 if (!topology.defined_on_spatial_dimension(
m_data.spatialDim)) {
749 std::ostringstream errmsg;
750 errmsg <<
"Error on input line " <<
m_lineNumber <<
". Topology = " << topology
751 <<
" is not defined on spatial dimension = " <<
m_data.spatialDim
752 <<
" set in parser.";
759 size_t numTopologyNodes = topology.num_nodes();
760 if (numNodes != numTopologyNodes) {
761 std::ostringstream errmsg;
762 errmsg <<
"Error! The input line appears to contain " << numNodes
763 <<
" nodes, but the topology " << topology <<
" needs " << numTopologyNodes
Definition Iotm_TextMeshAssembly.h:164
void parse(const std::string &parseData)
Definition Iotm_TextMeshAssembly.h:185
AssemblyType get_assembly_type() const
Definition Iotm_TextMeshAssembly.h:178
const std::vector< std::string > & get_assembly_data()
Definition Iotm_TextMeshAssembly.h:180
std::string get_name()
Definition Iotm_TextMeshAssembly.h:176
void verify_parse() const
Definition Iotm_TextMeshAssembly.h:194
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshAssembly.h:174
Definition Iotm_TextMeshNodeset.h:56
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(const std::string &parseData)
Definition Iotm_TextMeshNodeset.h:75
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
void parse(const std::string &parseData)
Definition Iotm_TextMeshSideset.h:155
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshSideset.h:141
std::string get_name()
Definition Iotm_TextMeshSideset.h:143
const std::vector< std::pair< EntityId, int > > & get_sideset_data()
Definition Iotm_TextMeshSideset.h:145
SplitType get_split_type()
Definition Iotm_TextMeshSideset.h:147
Definition Iotm_TextMeshUtils.h:43
std::string get_string()
Definition Iotm_TextMeshUtils.h:66
int get_int()
Definition Iotm_TextMeshUtils.h:54
bool has_string() const
Definition Iotm_TextMeshUtils.h:77
unsigned get_unsigned()
Definition Iotm_TextMeshUtils.h:60
void set_input_string(const std::string &input)
Definition Iotm_TextMeshUtils.h:47
bool has_token() const
Definition Iotm_TextMeshUtils.h:74
bool has_newline() const
Definition Iotm_TextMeshUtils.h:75
bool char_is_comma()
Definition Iotm_TextMeshUtils.h:118
std::string make_upper_case(std::string str)
Definition Iotm_TextMeshUtils.h:124
TextMeshLexer()
Definition Iotm_TextMeshUtils.h:45
bool char_is_whitespace()
Definition Iotm_TextMeshUtils.h:117
bool has_more_input()
Definition Iotm_TextMeshUtils.h:115
void read_next_token()
Definition Iotm_TextMeshUtils.h:80
char current_char()
Definition Iotm_TextMeshUtils.h:122
bool has_number() const
Definition Iotm_TextMeshUtils.h:76
bool char_is_digit()
Definition Iotm_TextMeshUtils.h:120
void get_newline()
Definition Iotm_TextMeshUtils.h:72
bool char_is_newline()
Definition Iotm_TextMeshUtils.h:119
Definition Iotm_TextMeshUtils.h:140
void validate_dimension()
Definition Iotm_TextMeshUtils.h:207
int m_constructorEnforcedDimension
Definition Iotm_TextMeshUtils.h:555
std::vector< double > m_rawCoordinates
Definition Iotm_TextMeshUtils.h:559
void initialize_parse(const std::string ¶meters)
Definition Iotm_TextMeshUtils.h:174
void check_assembly_member_reference()
Definition Iotm_TextMeshUtils.h:399
bool enforced_dimension_provided()
Definition Iotm_TextMeshUtils.h:202
void finalize_parse()
Definition Iotm_TextMeshUtils.h:187
TextMeshOptionParser(TextMeshData< EntityId, Topology > &data)
Definition Iotm_TextMeshUtils.h:161
ErrorHandler m_errorHandler
Definition Iotm_TextMeshUtils.h:560
unsigned long m_parsedOptionMask
Definition Iotm_TextMeshUtils.h:552
TextMeshData< EntityId, Topology > & m_data
Definition Iotm_TextMeshUtils.h:562
void check_sideset_name_collision()
Definition Iotm_TextMeshUtils.h:343
void parse_coordinates_option(const std::vector< std::string > &coordinatesOptionGroup)
Definition Iotm_TextMeshUtils.h:275
void set_dimension()
Definition Iotm_TextMeshUtils.h:220
void validate_assemblies()
Definition Iotm_TextMeshUtils.h:445
void parse_sideset_option(const std::vector< std::string > &sidesetOptionGroup)
Definition Iotm_TextMeshUtils.h:452
void set_coordinates()
Definition Iotm_TextMeshUtils.h:265
int m_parsedDimension
Definition Iotm_TextMeshUtils.h:554
void check_assembly_name_collision()
Definition Iotm_TextMeshUtils.h:427
void check_assembly_cyclic_dependency()
Definition Iotm_TextMeshUtils.h:434
void validate_sidesets()
Definition Iotm_TextMeshUtils.h:350
bool parsed_dimension_provided()
Definition Iotm_TextMeshUtils.h:200
void check_nodeset_node_reference()
Definition Iotm_TextMeshUtils.h:356
TextMeshOptionParser(TextMeshData< EntityId, Topology > &data, unsigned enforcedDimension)
Definition Iotm_TextMeshUtils.h:155
void parse_nodeset_option(const std::vector< std::string > &nodesetOptionGroup)
Definition Iotm_TextMeshUtils.h:468
void parse_dimension_option(const std::vector< std::string > &option)
Definition Iotm_TextMeshUtils.h:233
void parse_assembly_option(const std::vector< std::string > &assemblyOptionGroup)
Definition Iotm_TextMeshUtils.h:480
std::string get_mesh_connectivity_description() const
Definition Iotm_TextMeshUtils.h:169
void check_sideset_element_reference()
Definition Iotm_TextMeshUtils.h:325
static constexpr int DEFAULT_DIMENSION
Definition Iotm_TextMeshUtils.h:143
void validate_nodesets()
Definition Iotm_TextMeshUtils.h:378
void parse_options(const std::vector< std::string > &optionGroups)
Definition Iotm_TextMeshUtils.h:521
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshUtils.h:167
void check_nodeset_name_collision()
Definition Iotm_TextMeshUtils.h:371
void deallocate_raw_coordinates()
Definition Iotm_TextMeshUtils.h:259
void check_name_collision_with_entity_sets(const EntityGroupData< DataType > &groupData, const std::string &entityType, const std::set< std::string > &entitySetNames)
Definition Iotm_TextMeshUtils.h:297
static constexpr int INVALID_DIMENSION
Definition Iotm_TextMeshUtils.h:142
void handle_unrecognized_option(const std::string &optionType)
Definition Iotm_TextMeshUtils.h:514
ParsedOptions
Definition Iotm_TextMeshUtils.h:145
@ PARSED_COORDINATES
Definition Iotm_TextMeshUtils.h:148
@ PARSED_NONE
Definition Iotm_TextMeshUtils.h:146
@ PARSED_ASSEMBLY
Definition Iotm_TextMeshUtils.h:151
@ PARSED_NODESET
Definition Iotm_TextMeshUtils.h:150
@ PARSED_DIMENSION
Definition Iotm_TextMeshUtils.h:147
@ PARSED_SIDESET
Definition Iotm_TextMeshUtils.h:149
bool parsed_coordinates_provided()
Definition Iotm_TextMeshUtils.h:273
void check_name_collision_with_group(const SrcDataGroup &srcGroup, const DestDataGroup &destGroup)
Definition Iotm_TextMeshUtils.h:314
std::string m_meshConnectivityDescription
Definition Iotm_TextMeshUtils.h:557
void check_assembly_member_reference_in_group(const AssemblyData &assemblyData, const T &group)
Definition Iotm_TextMeshUtils.h:385
void print_help_message(std::ostream &out=std::cout)
Definition Iotm_TextMeshUtils.h:495
Definition Iotm_TextMeshUtils.h:566
typename TopologyMapping::Topology Topology
Definition Iotm_TextMeshUtils.h:568
void initialize_parse(const std::string &meshDescription)
Definition Iotm_TextMeshUtils.h:615
std::string parse_string()
Definition Iotm_TextMeshUtils.h:705
EntityId parse_elem_id()
Definition Iotm_TextMeshUtils.h:654
TextMeshLexer m_lexer
Definition Iotm_TextMeshUtils.h:771
TextMeshData< EntityId, Topology > parse(const std::string &meshDescription)
Definition Iotm_TextMeshUtils.h:579
TopologyMapping m_topologyMapping
Definition Iotm_TextMeshUtils.h:772
void initialize_constructor()
Definition Iotm_TextMeshUtils.h:599
Topology parse_topology()
Definition Iotm_TextMeshUtils.h:660
TextMeshData< EntityId, Topology > m_data
Definition Iotm_TextMeshUtils.h:770
void validate_no_extra_fields()
Definition Iotm_TextMeshUtils.h:725
ErrorHandler m_errorHandler
Definition Iotm_TextMeshUtils.h:774
std::string parse_part(const Topology &topology)
Definition Iotm_TextMeshUtils.h:681
void parse_newline()
Definition Iotm_TextMeshUtils.h:707
ElementData< EntityId, Topology > parse_element()
Definition Iotm_TextMeshUtils.h:637
unsigned m_lineNumber
Definition Iotm_TextMeshUtils.h:769
int parse_proc_id()
Definition Iotm_TextMeshUtils.h:648
void initialize_connectivity_parse(const std::string &meshDescription)
Definition Iotm_TextMeshUtils.h:608
void validate_required_field(bool hasNextRequiredField)
Definition Iotm_TextMeshUtils.h:713
void validate_topology(const Topology &topology, const std::string &providedName)
Definition Iotm_TextMeshUtils.h:739
void validate_node_count(const Topology &topology, size_t numNodes)
Definition Iotm_TextMeshUtils.h:757
TextMeshOptionParser< EntityId, Topology > m_optionParser
Definition Iotm_TextMeshUtils.h:776
void finalize_parse()
Definition Iotm_TextMeshUtils.h:621
void parse_description()
Definition Iotm_TextMeshUtils.h:623
unsigned parse_unsigned()
Definition Iotm_TextMeshUtils.h:704
void set_error_handler(ErrorHandler errorHandler)
Definition Iotm_TextMeshUtils.h:587
int parse_int()
Definition Iotm_TextMeshUtils.h:703
TextMeshParser()
Definition Iotm_TextMeshUtils.h:577
std::vector< EntityId > parse_node_ids(const Topology &topology)
Definition Iotm_TextMeshUtils.h:671
TextMeshParser(unsigned enforcedDimension)
Definition Iotm_TextMeshUtils.h:571
Definition Iotm_TextMeshDataTypes.h:39
TopologyMapEntry Topology
Definition Iotm_TextMeshDataTypes.h:41
virtual void initialize_topology_map()=0
virtual Topology invalid_topology() const =0
Topology topology(const std::string &textMeshName) const
Definition Iotm_TextMeshDataTypes.h:45
void convert_to_upper_case(std::string &str)
Definition Iotm_TextMeshFuncs.h:88
std::function< void(const std::ostringstream &)> ErrorHandler
Definition Iotm_TextMeshAdjacencyGraph.h:35
AssemblyType
Definition Iotm_TextMeshAssembly.h:39
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::set< T > transform_to_set(const std::vector< T > &dataAsVector)
Definition Iotm_TextMeshFuncs.h:107
A namespace for the textmesh database format.
Definition Iotm_DatabaseIO.C:95
int64_t EntityId
Definition Iotm_TextMesh.h:33
Definition Iotm_TextMeshAssembly.h:56
void set_assembly_type(AssemblyType type_)
Definition Iotm_TextMeshAssembly.h:59
Definition Iotm_TextMeshDataTypes.h:288
Definition Iotm_TextMeshDataTypes.h:277
Topology topology
Definition Iotm_TextMeshDataTypes.h:280
std::string partName
Definition Iotm_TextMeshDataTypes.h:282
int proc
Definition Iotm_TextMeshDataTypes.h:278
EntityId identifier
Definition Iotm_TextMeshDataTypes.h:279
std::vector< EntityId > nodeIds
Definition Iotm_TextMeshDataTypes.h:281
Definition Iotm_TextMeshEntityGroup.h:37
std::string name
Definition Iotm_TextMeshEntityGroup.h:43
std::string type
Definition Iotm_TextMeshEntityGroup.h:44
unsigned id
Definition Iotm_TextMeshEntityGroup.h:42
std::vector< DataType > data
Definition Iotm_TextMeshEntityGroup.h:45
Definition Iotm_TextMeshNodeset.h:41
Definition Iotm_TextMeshSidesetSplitter.h:64
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
Definition Iotm_TextMeshDataTypes.h:315