IOSS 2.0
Loading...
Searching...
No Matches
Ioex_Utils.h
Go to the documentation of this file.
1/*
2 * Copyright(C) 1999-2020, 2022, 2023, 2024 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8#pragma once
9
11#include "Ioss_ElementBlock.h"
13#include "Ioss_Utils.h"
14#include <cassert>
15#include <exodusII.h>
16#include <map>
17#include <set>
18#include <stddef.h>
19#include <stdint.h>
20#include <string>
21#include <vector>
22
23#include "Ioss_CodeTypes.h"
24#include "Ioss_EntityType.h"
25#include "Ioss_SurfaceSplit.h"
26#include "ioex_export.h"
27
28namespace Ioss {
29 class ElementBlock;
30 class Region;
31} // namespace Ioss
32
33#define EXU_USE_HOPSCOTCH
34#if defined EXU_USE_HOPSCOTCH
35#include <hopscotch_map.h>
36#elif defined EXU_USE_ROBIN
37#include <robin_map.h>
38#endif
39
40// Contains code that is common between the file-per-processor and
41// parallel exodus and base exodus classes.
42
43namespace Ioss {
44 class GroupingEntity;
45
46 using CoordinateFrameContainer = std::vector<CoordinateFrame>;
47} // namespace Ioss
48
49namespace Ioex {
50 using EntityIdSet = std::set<std::pair<int64_t, int64_t>>;
51 using SideSetSet = std::set<std::string>;
52 using SideSetMap = std::map<std::string, const std::string, std::less<>>;
53
54 using NameTopoKey = std::pair<std::string, const Ioss::ElementTopology *>;
55 struct IOEX_EXPORT NameTopoKeyCompare
56 {
57 IOSS_NODISCARD bool operator()(const NameTopoKey &lhs, const NameTopoKey &rhs) const
58 {
59 assert(lhs.second != nullptr);
60 assert(rhs.second != nullptr);
61 return lhs.first < rhs.first ||
62 (!(rhs.first < lhs.first) && lhs.second->name() < rhs.second->name());
63 }
64 };
65
66 struct IOEX_EXPORT NameTopoKeyHash
67 {
68 IOSS_NODISCARD size_t operator()(const NameTopoKey &name_topo) const
69 {
70 return std::hash<std::string>{}(name_topo.first) +
71 std::hash<size_t>{}((size_t)name_topo.second);
72 }
73 };
74
75#if defined EXU_USE_HOPSCOTCH
77#elif defined EXU_USE_ROBIN
79#else
80 // This is the original method that was used in IOSS prior to using hopscotch or robin map.
81 using TopologyMap = std::map<NameTopoKey, int, NameTopoKeyCompare>;
82#endif
83
84 IOSS_NODISCARD IOEX_EXPORT const char *Version();
85 IOEX_EXPORT bool check_processor_info(const std::string &filename, int exodusFilePtr,
86 int processor_count, int processor_id);
87
88 IOSS_NODISCARD IOEX_EXPORT Ioss::EntityType map_exodus_type(ex_entity_type type);
89 IOSS_NODISCARD IOEX_EXPORT ex_entity_type map_exodus_type(Ioss::EntityType type);
90
91 IOEX_EXPORT void update_last_time_attribute(int exodusFilePtr, double value);
92 IOEX_EXPORT bool read_last_time_attribute(int exodusFilePtr, double *value);
93
94 IOSS_NODISCARD IOEX_EXPORT bool type_match(const std::string &type, const char *substring);
95 IOSS_NODISCARD IOEX_EXPORT int64_t extract_id(const std::string &name_id);
96 IOEX_EXPORT bool set_id(const Ioss::GroupingEntity *entity, Ioex::EntityIdSet *idset);
97 IOEX_EXPORT int64_t get_id(const Ioss::GroupingEntity *entity, Ioex::EntityIdSet *idset);
98 IOEX_EXPORT void decode_surface_name(Ioex::SideSetMap &fs_map, Ioex::SideSetSet &fs_set,
99 const std::string &name);
100 IOEX_EXPORT void fix_bad_name(char *name);
101
102 IOEX_EXPORT void exodus_error(int exoid, int lineno, const char *function, const char *filename);
103 IOEX_EXPORT void exodus_error(int exoid, int lineno, const char *function, const char *filename,
104 const std::string &extra);
105
106 IOEX_EXPORT int add_map_fields(int exoid, Ioss::ElementBlock *block, int64_t my_element_count,
107 size_t name_length);
108
109 IOEX_EXPORT void add_coordinate_frames(int exoid, Ioss::Region *region);
110 IOEX_EXPORT void write_coordinate_frames(int exoid, const Ioss::CoordinateFrameContainer &frames);
111
112 IOEX_EXPORT bool find_displacement_field(Ioss::NameList &fields,
113 const Ioss::GroupingEntity *block, int ndim,
114 std::string *disp_name);
115
116 IOSS_NODISCARD IOEX_EXPORT std::string get_entity_name(int exoid, ex_entity_type type, int64_t id,
117 const std::string &basename, int length,
118 bool &db_has_name);
119
120 IOEX_EXPORT bool filter_node_list(Ioss::Int64Vector &nodes,
121 const std::vector<unsigned char> &node_connectivity_status);
122
123 template <typename T>
124 void filter_node_list(T *data, std::vector<T> &dbvals,
125 const std::vector<int64_t> &active_node_index)
126 {
127 for (size_t i = 0; i < active_node_index.size(); i++) {
128 data[i] = dbvals[active_node_index[i]];
129 }
130 }
131
132 IOEX_EXPORT void filter_element_list(Ioss::Region *region, Ioss::Int64Vector &elements,
133 Ioss::Int64Vector &sides, bool remove_omitted_elements);
134
135 IOEX_EXPORT void separate_surface_element_sides(Ioss::Int64Vector &element,
136 Ioss::Int64Vector &sides, Ioss::Region *region,
137 Ioex::TopologyMap &topo_map,
138 Ioex::TopologyMap &side_map,
139 Ioss::SurfaceSplitType split_type,
140 const std::string &surface_name);
141
142 IOEX_EXPORT void write_reduction_attributes(int exoid, const Ioss::GroupingEntity *ge);
143 template <typename T> void write_reduction_attributes(int exoid, const std::vector<T *> &entities)
144 {
145 // For the entity, write all "reduction attributes"
146 for (const auto &ge : entities) {
148 }
149 }
150} // namespace Ioex
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:54
std::set< EntityId > EntityIdSet
Definition UnitTestIotmTextMeshFixture.h:62
A collection of elements having the same topology.
Definition Ioss_ElementBlock.h:29
Base class for all 'grouping' entities. The following derived classes are typical:
Definition Ioss_GroupingEntity.h:67
A grouping entity that contains other grouping entities.
Definition Ioss_Region.h:90
Definition hopscotch_map.h:82
Definition robin_map.h:90
A namespace for the exodus database format.
Definition Ioex_BaseDatabaseIO.C:198
bool set_id(const Ioss::GroupingEntity *entity, Ioex::EntityIdSet *idset)
Definition Ioex_Utils.C:297
std::set< std::string > SideSetSet
Definition Ioex_Utils.h:51
bool find_displacement_field(Ioss::NameList &fields, const Ioss::GroupingEntity *block, int ndim, std::string *disp_name)
Definition Ioex_Utils.C:409
bool check_processor_info(const std::string &filename, int exodusFilePtr, int processor_count, int processor_id)
Definition Ioex_Utils.C:191
void write_coordinate_frames(int exoid, const Ioss::CoordinateFrameContainer &frames)
Definition Ioex_Utils.C:591
int64_t extract_id(const std::string &name_id)
Definition Ioex_Utils.C:326
Ioss::EntityType map_exodus_type(ex_entity_type type)
Definition Ioex_Utils.C:121
void separate_surface_element_sides(Ioss::Int64Vector &element, Ioss::Int64Vector &sides, Ioss::Region *region, Ioex::TopologyMap &topo_map, Ioex::TopologyMap &side_map, Ioss::SurfaceSplitType split_type, const std::string &surface_name)
Definition Ioex_Utils.C:674
std::map< std::string, const std::string, std::less<> > SideSetMap
Definition Ioex_Utils.h:52
void add_coordinate_frames(int exoid, Ioss::Region *region)
Definition Ioex_Utils.C:601
void filter_element_list(Ioss::Region *region, Ioss::Int64Vector &elements, Ioss::Int64Vector &sides, bool remove_omitted_elements)
Definition Ioex_Utils.C:637
void decode_surface_name(Ioex::SideSetMap &fs_map, Ioex::SideSetSet &fs_set, const std::string &name)
Definition Ioex_Utils.C:259
bool type_match(const std::string &type, const char *substring)
Definition Ioex_Utils.C:242
IOSS_NODISCARD IOEX_EXPORT const char * Version()
int add_map_fields(int exoid, Ioss::ElementBlock *block, int64_t my_element_count, size_t name_length)
Definition Ioex_Utils.C:527
void update_last_time_attribute(int exodusFilePtr, double value)
Definition Ioex_Utils.C:104
std::pair< std::string, const Ioss::ElementTopology * > NameTopoKey
Definition Ioex_Utils.h:54
bool read_last_time_attribute(int exodusFilePtr, double *value)
Definition Ioex_Utils.C:161
std::set< std::pair< int64_t, int64_t > > EntityIdSet
Definition Ioex_BaseDatabaseIO.h:75
void exodus_error(int exoid, int lineno, const char *function, const char *filename)
Definition Ioex_Utils.C:501
int64_t get_id(const Ioss::GroupingEntity *entity, Ioex::EntityIdSet *idset)
Definition Ioex_Utils.C:345
bool filter_node_list(Ioss::Int64Vector &nodes, const std::vector< unsigned char > &node_connectivity_status)
Definition Ioex_Utils.C:611
void fix_bad_name(char *name)
Definition Ioex_Utils.C:442
void write_reduction_attributes(int exoid, const Ioss::GroupingEntity *ge)
Definition Ioex_Utils.C:751
std::string get_entity_name(int exoid, ex_entity_type type, int64_t id, const std::string &basename, int length, bool &db_has_name)
Definition Ioex_Utils.C:458
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
std::vector< int64_t > Int64Vector
Definition Ioss_CodeTypes.h:22
SurfaceSplitType
Method used to split sidesets into homogeneous blocks.
Definition Ioss_SurfaceSplit.h:11
std::vector< CoordinateFrame > CoordinateFrameContainer
Definition Ioex_Utils.h:46
std::vector< std::string > NameList
Definition Ioss_CodeTypes.h:23
EntityType
The particular type of GroupingEntity.
Definition Ioss_EntityType.h:12
Definition Ioex_Utils.h:56
IOSS_NODISCARD bool operator()(const NameTopoKey &lhs, const NameTopoKey &rhs) const
Definition Ioex_Utils.h:57
Definition Ioex_Utils.h:67
IOSS_NODISCARD size_t operator()(const NameTopoKey &name_topo) const
Definition Ioex_Utils.h:68