Debian Codegraph @

packages/seacas/libraries/ioss/src/exonull/Ioexnl_Utils.h

raw
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
10 #include "Ioss_CoordinateFrame.h"
11 #include "Ioss_ElementBlock.h"
12 #include "Ioss_ElementTopology.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 "ioexnl_export.h"
27
28 namespace 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
43 namespace Ioss {
44 class GroupingEntity;
45
46 using CoordinateFrameContainer = std::vector<CoordinateFrame>;
47 } // namespace Ioss
48
49 namespace Ioexnl {
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 IOEXNL_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 IOEXNL_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
76 using TopologyMap = tsl::hopscotch_map<NameTopoKey, int, NameTopoKeyHash>;
77 #elif defined EXU_USE_ROBIN
78 using TopologyMap = tsl::robin_map<NameTopoKey, int, NameTopoKeyHash>;
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 IOEXNL_EXPORT const char *Version();
85 IOSS_NODISCARD IOEXNL_EXPORT bool check_processor_info(const std::string &filename,
86 int exodusFilePtr, int processor_count,
87 int processor_id);
88
89 IOSS_NODISCARD IOEXNL_EXPORT Ioss::EntityType map_exodus_type(ex_entity_type type);
90 IOSS_NODISCARD IOEXNL_EXPORT ex_entity_type map_exodus_type(Ioss::EntityType type);
91
92 IOEXNL_EXPORT void update_last_time_attribute(int exodusFilePtr, double value);
93 IOEXNL_EXPORT bool read_last_time_attribute(int exodusFilePtr, double *value);
94
95 IOSS_NODISCARD IOEXNL_EXPORT bool type_match(const std::string &type, const char *substring);
96 IOSS_NODISCARD IOEXNL_EXPORT int64_t extract_id(const std::string &name_id);
97 IOEXNL_EXPORT bool set_id(const Ioss::GroupingEntity *entity, Ioexnl::EntityIdSet *idset);
98 IOEXNL_EXPORT int64_t get_id(const Ioss::GroupingEntity *entity, Ioexnl::EntityIdSet *idset);
99 IOEXNL_EXPORT void decode_surface_name(Ioexnl::SideSetMap &fs_map, Ioexnl::SideSetSet &fs_set,
100 const std::string &name);
101 IOEXNL_EXPORT void fix_bad_name(char *name);
102
103 IOEXNL_EXPORT void exodus_error(int exoid, int lineno, const char *function,
104 const char *filename);
105 IOEXNL_EXPORT void exodus_error(int exoid, int lineno, const char *function, const char *filename,
106 const std::string &extra);
107
108 IOEXNL_EXPORT int add_map_fields(int exoid, Ioss::ElementBlock *block, int64_t my_element_count,
109 size_t name_length);
110
111 IOEXNL_EXPORT void add_coordinate_frames(int exoid, Ioss::Region *region);
112 IOEXNL_EXPORT void write_coordinate_frames(int exoid,
113 const Ioss::CoordinateFrameContainer &frames);
114
115 IOEXNL_EXPORT bool find_displacement_field(Ioss::NameList &fields,
116 const Ioss::GroupingEntity *block, int ndim,
117 std::string *disp_name);
118
119 IOSS_NODISCARD IOEXNL_EXPORT std::string get_entity_name(int exoid, ex_entity_type type,
120 int64_t id, const std::string &basename,
121 int length, bool &db_has_name);
122
123 IOEXNL_EXPORT void filter_element_list(Ioss::Region *region, Ioss::Int64Vector &elements,
124 Ioss::Int64Vector &sides, bool remove_omitted_elements);
125
126 IOEXNL_EXPORT bool filter_node_list(Ioss::Int64Vector &nodes,
127 const std::vector<unsigned char> &node_connectivity_status);
128
129 template <typename T>
130 void filter_node_list(T *data, std::vector<T> &dbvals,
131 const std::vector<int64_t> &active_node_index)
132 {
133 for (size_t i = 0; i < active_node_index.size(); i++) {
134 data[i] = dbvals[active_node_index[i]];
135 }
136 }
137
138 IOEXNL_EXPORT void separate_surface_element_sides(Ioss::Int64Vector &element,
139 Ioss::Int64Vector &sides, Ioss::Region *region,
140 Ioexnl::TopologyMap &topo_map,
141 Ioexnl::TopologyMap &side_map,
142 Ioss::SurfaceSplitType split_type,
143 const std::string &surface_name);
144
145 IOEXNL_EXPORT void write_reduction_attributes(int exoid, const Ioss::GroupingEntity *ge);
146 template <typename T> void write_reduction_attributes(int exoid, const std::vector<T *> &entities)
147 {
148 // For the entity, write all "reduction attributes"
149 for (const auto &ge : entities) {
150 write_reduction_attributes(exoid, ge);
151 }
152 }
153 } // namespace Ioexnl