| 1 |
// Copyright(C) 1999-2024 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 |
// See packages/seacas/LICENSE for details |
| 6 |
#pragma once |
| 7 |
|
| 8 |
#include "exo_entity.h" |
| 9 |
#include "util.h" |
| 10 |
|
| 11 |
#include <iostream> |
| 12 |
#include <string> |
| 13 |
#include <vector> |
| 14 |
|
| 15 |
#include "smart_assert.h" |
| 16 |
|
| 17 |
// |
| 18 |
// Notes: 1) Most functions will return a string as a result. An empty string |
| 19 |
// indicates success, while a non-empty string indicates an error or |
| 20 |
// a warning, either of which will be contained in the string. |
| 21 |
// |
| 22 |
|
| 23 |
class Exo_Entity; |
| 24 |
template <typename INT> class Exo_Block; |
| 25 |
|
| 26 |
template <typename INT> class Node_Set; |
| 27 |
template <typename INT> class Side_Set; |
| 28 |
|
| 29 |
template <typename INT> class Edge_Block; |
| 30 |
template <typename INT> class Face_Block; |
| 31 |
template <typename INT> class Assembly; |
| 32 |
|
| 33 |
template <typename INT> class Exo_Read |
| 34 |
{ |
| 35 |
public: |
| 36 |
Exo_Read() = delete; |
| 37 |
explicit Exo_Read(std::string fname); |
| 38 |
~Exo_Read(); |
| 39 |
const Exo_Read &operator=(const Exo_Read &) = delete; |
| 40 |
Exo_Read(const Exo_Read &) = delete; |
| 41 |
|
| 42 |
// File operations: |
| 43 |
|
| 44 |
std::string Open_Change_Set(const std::string &name); |
| 45 |
std::string Open_Change_Set(int index); |
| 46 |
void Get_Meta_Data(); // Reads metadata |
| 47 |
int Get_Change_Set_Index() const { return current_change_set_index; } |
| 48 |
const std::string &Get_Change_Set_Name() const |
| 49 |
{ |
| 50 |
return change_set_names[current_change_set_index]; |
| 51 |
} |
| 52 |
|
| 53 |
std::string Close_File(); |
| 54 |
std::string File_Name() const { return file_name; } |
| 55 |
int Open() const { return (file_id >= 0); } |
| 56 |
int IO_Word_Size() const { return io_word_size; } |
| 57 |
|
| 58 |
void modify_time_values(double scale, double offset) |
| 59 |
{ |
| 60 |
time_scale = scale; |
| 61 |
time_offset = offset; |
| 62 |
} |
| 63 |
|
| 64 |
// Global data: |
| 65 |
const std::string &Title() const { return title; } |
| 66 |
int Dimension() const { return dimension; } |
| 67 |
size_t Num_Nodes() const { return num_nodes; } |
| 68 |
size_t Num_Elements() const { return num_elmts; } |
| 69 |
size_t Num_Faces() const { return num_faces; } |
| 70 |
size_t Num_Edges() const { return num_edges; } |
| 71 |
size_t Num_Node_Sets() const { return num_node_sets; } |
| 72 |
size_t Num_Side_Sets() const { return num_side_sets; } |
| 73 |
size_t Num_Edge_Blocks() const { return num_edge_blocks; } |
| 74 |
size_t Num_Face_Blocks() const { return num_face_blocks; } |
| 75 |
size_t Num_Assembly() const { return num_assemblies; } |
| 76 |
|
| 77 |
// Times: |
| 78 |
int Num_Times() const { return (int)times.size(); } |
| 79 |
double Time(int time_num) const; |
| 80 |
|
| 81 |
// Change Sets: |
| 82 |
int Num_Change_Sets() const { return num_change_sets; } |
| 83 |
const NameList &Change_Set_Names() const { return change_set_names; } |
| 84 |
const std::vector<int> &Change_Set_Ids() const { return change_set_ids; } |
| 85 |
|
| 86 |
// Variables: |
| 87 |
|
| 88 |
size_t Num_Global_Vars() const { return global_vars.size(); } |
| 89 |
size_t Num_Nodal_Vars() const { return nodal_vars.size(); } |
| 90 |
size_t Num_Element_Vars() const { return elmt_vars.size(); } |
| 91 |
size_t Num_Element_Atts() const { return elmt_atts.size(); } |
| 92 |
size_t Num_NS_Vars() const { return ns_vars.size(); } |
| 93 |
size_t Num_SS_Vars() const { return ss_vars.size(); } |
| 94 |
size_t Num_EB_Vars() const { return eb_vars.size(); } |
| 95 |
size_t Num_FB_Vars() const { return fb_vars.size(); } |
| 96 |
const NameList &Global_Var_Names() const { return global_vars; } |
| 97 |
const NameList &Nodal_Var_Names() const { return nodal_vars; } |
| 98 |
const NameList &Element_Var_Names() const { return elmt_vars; } |
| 99 |
const NameList &Element_Att_Names() const { return elmt_atts; } |
| 100 |
const NameList &NS_Var_Names() const { return ns_vars; } |
| 101 |
const NameList &SS_Var_Names() const { return ss_vars; } |
| 102 |
const NameList &EB_Var_Names() const { return eb_vars; } |
| 103 |
const NameList &FB_Var_Names() const { return fb_vars; } |
| 104 |
|
| 105 |
const std::string &Global_Var_Name(int index) const; |
| 106 |
const std::string &Nodal_Var_Name(int index) const; |
| 107 |
const std::string &Element_Var_Name(int index) const; |
| 108 |
const std::string &Element_Att_Name(int index) const; |
| 109 |
const std::string &NS_Var_Name(int index) const; |
| 110 |
const std::string &SS_Var_Name(int index) const; |
| 111 |
const std::string &EB_Var_Name(int index) const; |
| 112 |
const std::string &FB_Var_Name(int index) const; |
| 113 |
|
| 114 |
// Element blocks: |
| 115 |
size_t Num_Element_Blocks() const { return num_elmt_blocks; } |
| 116 |
|
| 117 |
std::string Load_Element_Block_Description(size_t block_index) const; |
| 118 |
std::string Load_Element_Block_Descriptions() const; // Loads all blocks. |
| 119 |
std::string Free_Element_Block(size_t block_index) const; // Frees all dynamic memory. |
| 120 |
std::string Free_Element_Blocks() const; // Frees all blocks. |
| 121 |
|
| 122 |
// Number maps: |
| 123 |
std::string Load_Node_Map(); |
| 124 |
std::string Free_Node_Map(); |
| 125 |
const INT *Get_Node_Map() { return node_map; } |
| 126 |
std::string Load_Element_Map(); |
| 127 |
std::string Free_Element_Map(); |
| 128 |
const INT *Get_Element_Map() { return elmt_map; } |
| 129 |
inline INT Node_Map(size_t node_num) const; // numbers are global, 1-offset |
| 130 |
inline INT Element_Map(size_t elmt_num) const; // numbers are global, 1-offset |
| 131 |
|
| 132 |
// Nodal data: |
| 133 |
|
| 134 |
std::string Load_Nodal_Coordinates(); |
| 135 |
const double *X_Coords() const { return nodes; } |
| 136 |
const double *Y_Coords() const |
| 137 |
{ |
| 138 |
if (dimension < 2) { |
| 139 |
return nullptr; |
| 140 |
} |
| 141 |
return nodes == nullptr ? nullptr : nodes + num_nodes; |
| 142 |
} |
| 143 |
const double *Z_Coords() const |
| 144 |
{ |
| 145 |
if (dimension < 3) { |
| 146 |
return nullptr; |
| 147 |
} |
| 148 |
return nodes == nullptr ? nullptr : nodes + 2 * num_nodes; |
| 149 |
} |
| 150 |
void Free_Nodal_Coordinates(); |
| 151 |
|
| 152 |
// (First time step = 1.) |
| 153 |
std::string Load_Nodal_Results(int time_step_num, int var_index); |
| 154 |
const double *Get_Nodal_Results(int var_index) const; |
| 155 |
const double *Get_Nodal_Results(int t1, int t2, double proportion, |
| 156 |
int var_index) const; // Interpolated results |
| 157 |
void Free_Nodal_Results(); |
| 158 |
void Free_Nodal_Results(int var_index); |
| 159 |
|
| 160 |
// Global data: (NOTE: Global and Nodal data are always stored at the same |
| 161 |
// time step. Therefore, if current time step number |
| 162 |
// is changed, the results will all be deleted.) |
| 163 |
|
| 164 |
std::string Load_Global_Results(int time_step_num); |
| 165 |
std::string Load_Global_Results(int t1, int t2, double proportion); // Interpolated results |
| 166 |
const double *Get_Global_Results() const { return global_vals; } |
| 167 |
|
| 168 |
// Node/Side sets: |
| 169 |
|
| 170 |
Exo_Entity *Get_Entity_by_Index(EXOTYPE type, size_t block_index) const; |
| 171 |
Exo_Entity *Get_Entity_by_Id(EXOTYPE type, size_t id) const; |
| 172 |
Exo_Entity *Get_Entity_by_Name(EXOTYPE type, const std::string &name) const; |
| 173 |
|
| 174 |
Assembly<INT> *Get_Assembly_by_Id(size_t id) const; |
| 175 |
Assembly<INT> *Get_Assembly_by_Index(size_t assembly_index) const; |
| 176 |
Assembly<INT> *Get_Assembly_by_Name(const std::string &name) const; |
| 177 |
|
| 178 |
size_t Block_Id(size_t block_index) const; // Returns associated block id. |
| 179 |
Exo_Block<INT> *Get_Element_Block_by_Id(size_t id) const; |
| 180 |
Exo_Block<INT> *Get_Element_Block_by_Index(size_t block_index) const; |
| 181 |
Exo_Block<INT> *Get_Element_Block_by_Name(const std::string &name) const; |
| 182 |
|
| 183 |
Side_Set<INT> *Get_Side_Set_by_Id(size_t set_id) const; |
| 184 |
Side_Set<INT> *Get_Side_Set_by_Index(size_t side_set_index) const; |
| 185 |
Side_Set<INT> *Get_Side_Set_by_Name(const std::string &name) const; |
| 186 |
|
| 187 |
Node_Set<INT> *Get_Node_Set_by_Id(size_t set_id) const; |
| 188 |
Node_Set<INT> *Get_Node_Set_by_Index(size_t set_index) const; |
| 189 |
Node_Set<INT> *Get_Node_Set_by_Name(const std::string &name) const; |
| 190 |
|
| 191 |
Edge_Block<INT> *Get_Edge_Block_by_Id(size_t block_id) const; |
| 192 |
Edge_Block<INT> *Get_Edge_Block_by_Index(size_t set_index) const; |
| 193 |
Edge_Block<INT> *Get_Edge_Block_by_Name(const std::string &name) const; |
| 194 |
|
| 195 |
Face_Block<INT> *Get_Face_Block_by_Id(size_t block_id) const; |
| 196 |
Face_Block<INT> *Get_Face_Block_by_Index(size_t set_index) const; |
| 197 |
Face_Block<INT> *Get_Face_Block_by_Name(const std::string &name) const; |
| 198 |
|
| 199 |
// Misc functions: |
| 200 |
|
| 201 |
int Check_State() const; // Checks state of obj (not the file). |
| 202 |
int File_ID() const { return file_id; } // This is temporary. |
| 203 |
std::pair<int, size_t> Global_to_Block_Local(size_t global_elmt_num) const; |
| 204 |
|
| 205 |
private: |
| 206 |
std::string file_name{}; |
| 207 |
int file_id{-1}; // Exodus file id; also used to determine if file is open. |
| 208 |
|
| 209 |
// GENESIS info: |
| 210 |
|
| 211 |
std::string title{}; |
| 212 |
NameList coord_names{}; |
| 213 |
size_t num_nodes{0}; |
| 214 |
int dimension{0}; |
| 215 |
size_t num_elmts{0}; |
| 216 |
size_t num_faces{0}; |
| 217 |
size_t num_edges{0}; |
| 218 |
size_t num_elmt_blocks{0}; |
| 219 |
size_t num_node_sets{0}; |
| 220 |
size_t num_side_sets{0}; |
| 221 |
size_t num_edge_blocks{0}; |
| 222 |
size_t num_face_blocks{0}; |
| 223 |
size_t num_assemblies{0}; |
| 224 |
int num_change_sets{0}; |
| 225 |
int current_change_set_index{-2}; |
| 226 |
int io_word_size{0}; // Note: The "compute word size" is always 8. |
| 227 |
|
| 228 |
Exo_Block<INT> *eblocks{nullptr}; // Array. |
| 229 |
Node_Set<INT> *nsets{nullptr}; // Array. |
| 230 |
Side_Set<INT> *ssets{nullptr}; // Array. |
| 231 |
Edge_Block<INT> *edge_blocks{nullptr}; // Array. |
| 232 |
Face_Block<INT> *face_blocks{nullptr}; // Array. |
| 233 |
Assembly<INT> *assemblies{nullptr}; |
| 234 |
|
| 235 |
double *nodes{nullptr}; // Matrix; dimension by num_nodes (row major form). |
| 236 |
// I.e., all x's then all y's, etc. |
| 237 |
|
| 238 |
INT *node_map{nullptr}; // Array; num_nodes long when filled. |
| 239 |
INT *elmt_map{nullptr}; // Array; num_elmts long when filled. |
| 240 |
|
| 241 |
// RESULTS info: |
| 242 |
|
| 243 |
NameList global_vars{}; |
| 244 |
NameList nodal_vars{}; |
| 245 |
NameList elmt_vars{}; |
| 246 |
NameList elmt_atts{}; |
| 247 |
NameList ns_vars{}; |
| 248 |
NameList ss_vars{}; |
| 249 |
NameList eb_vars{}; |
| 250 |
NameList fb_vars{}; |
| 251 |
|
| 252 |
std::vector<int> change_set_ids{}; |
| 253 |
NameList change_set_names{}; |
| 254 |
|
| 255 |
double time_scale{1.0}; |
| 256 |
double time_offset{0.0}; |
| 257 |
|
| 258 |
std::vector<double> times{}; |
| 259 |
|
| 260 |
int cur_time{0}; // Current timestep number of the results (0 means none). |
| 261 |
double **results{nullptr}; // Array of pointers (to arrays of results data); |
| 262 |
// length is number of nodal variables. |
| 263 |
double *global_vals{nullptr}; // Array of global variables for the current timestep. |
| 264 |
double *global_vals2{nullptr}; // Array of global variables used if interpolating. |
| 265 |
|
| 266 |
// Internal methods: |
| 267 |
void Reset_Meta_Data(); |
| 268 |
}; |
| 269 |
|
| 270 |
template <typename INT> inline INT Exo_Read<INT>::Node_Map(size_t node_num) const |
| 271 |
{ |
| 272 |
SMART_ASSERT(Check_State()); |
| 273 |
SMART_ASSERT(node_num <= num_nodes); |
| 274 |
|
| 275 |
if (node_map) { |
| 276 |
return node_map[node_num - 1]; |
| 277 |
} |
| 278 |
return 0; |
| 279 |
} |
| 280 |
|
| 281 |
template <typename INT> inline INT Exo_Read<INT>::Element_Map(size_t elmt_num) const |
| 282 |
{ |
| 283 |
SMART_ASSERT(Check_State()); |
| 284 |
SMART_ASSERT(elmt_num <= num_elmts); |
| 285 |
|
| 286 |
if (elmt_map) { |
| 287 |
return elmt_map[elmt_num - 1]; |
| 288 |
} |
| 289 |
return 0; |
| 290 |
} |