| 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 "util.h" |
| 9 |
|
| 10 |
#include <exodusII.h> |
| 11 |
#include <iostream> |
| 12 |
#include <string> |
| 13 |
#include <vector> |
| 14 |
|
| 15 |
#if defined(EX_API_VERS_NODOT) |
| 16 |
#if EX_API_VERS_NODOT > 467 |
| 17 |
using EXOTYPE = ex_entity_type; |
| 18 |
#else |
| 19 |
using EXOTYPE = int; |
| 20 |
#endif |
| 21 |
#else |
| 22 |
using EXOTYPE = int; |
| 23 |
#endif |
| 24 |
|
| 25 |
template <typename INT> class Exo_Read; |
| 26 |
|
| 27 |
class Exo_Entity |
| 28 |
{ |
| 29 |
public: |
| 30 |
Exo_Entity() = default; |
| 31 |
Exo_Entity(int file_id, size_t id); |
| 32 |
Exo_Entity(int file_id, size_t id, size_t nnodes); |
| 33 |
virtual ~Exo_Entity(); |
| 34 |
Exo_Entity(const Exo_Entity &) = delete; |
| 35 |
const Exo_Entity &operator=(const Exo_Entity &) = delete; |
| 36 |
|
| 37 |
virtual size_t Size() const { return numEntity; } |
| 38 |
|
| 39 |
size_t Id() const { return id_; } |
| 40 |
size_t Index() const { return index_; } |
| 41 |
|
| 42 |
void initialize(int file_id, size_t id); |
| 43 |
|
| 44 |
bool is_valid_var(size_t var_index) const; |
| 45 |
size_t var_count() const { return numVars; } |
| 46 |
std::string Load_Results(int time_step, int var_index); |
| 47 |
std::string Load_Results(int t1, int t2, double proportion, int var_index); // Interpolation |
| 48 |
|
| 49 |
const double *Get_Results(int var_index) const; |
| 50 |
void Free_Results(); |
| 51 |
|
| 52 |
int attr_count() const { return numAttr; } |
| 53 |
std::string Load_Attributes(int attr_index); |
| 54 |
const double *Get_Attributes(int attr_index) const; |
| 55 |
void Free_Attributes(); |
| 56 |
|
| 57 |
const std::string &Get_Attribute_Name(int attr_index) const; |
| 58 |
const std::string &Name() const { return name_; } |
| 59 |
const NameList &Attribute_Names() const { return attributeNames; } |
| 60 |
int Find_Attribute_Index(const std::string &name) const; |
| 61 |
|
| 62 |
// Return "Element Block", "Nodeset", "Sideset, depending on underlying type. |
| 63 |
virtual const char *label() const = 0; |
| 64 |
|
| 65 |
// Return "block", "nodelist", "surface", depending on underlying type. |
| 66 |
virtual const char *short_label() const = 0; |
| 67 |
|
| 68 |
bool generatedName_{true}; |
| 69 |
|
| 70 |
protected: |
| 71 |
std::string name_{}; |
| 72 |
int fileId{-1}; |
| 73 |
ex_entity_id id_{EX_INVALID_ID}; |
| 74 |
size_t index_{0}; // 0-offset index into Exodus nodeset list. |
| 75 |
size_t numEntity{0}; // Number of items (nodes, sides, elements) |
| 76 |
|
| 77 |
private: |
| 78 |
// Return EX_ELEM_BLOCK, EX_NODE_SET, ... of underlying type |
| 79 |
virtual EXOTYPE exodus_type() const = 0; |
| 80 |
|
| 81 |
virtual int Check_State() const = 0; |
| 82 |
virtual void entity_load_params() = 0; |
| 83 |
void internal_load_params(); |
| 84 |
|
| 85 |
void get_truth_table() const; |
| 86 |
|
| 87 |
mutable int *truth_{nullptr}; // Array; holds local truth table for this entity |
| 88 |
int currentStep{0}; // Time step number of the current results. |
| 89 |
int numVars{0}; // Total number of variables in the file. |
| 90 |
double **results_{nullptr}; // Array of pointers (length numVars) |
| 91 |
// to arrays of results (length num_entity). |
| 92 |
int numAttr{0}; // Total number of attributes in the file. |
| 93 |
std::vector<double *> attributes_{}; // Array of pointers (length numAttr) |
| 94 |
// to arrays of attributes (length num_entity). |
| 95 |
NameList attributeNames{}; |
| 96 |
|
| 97 |
template <typename INT> friend class Exo_Read; |
| 98 |
}; |