| 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 |
|
| 7 |
#pragma once |
| 8 |
|
| 9 |
#include "Ioss_CodeTypes.h" |
| 10 |
#include <cstddef> // for size_t |
| 11 |
#include <stdint.h> |
| 12 |
#include <string> // for string |
| 13 |
#include <vector> // for vector |
| 14 |
|
| 15 |
#include "ioss_export.h" |
| 16 |
|
| 17 |
namespace Ioss { |
| 18 |
class GroupingEntity; |
| 19 |
class Transform; |
| 20 |
class VariableType; |
| 21 |
|
| 22 |
/** \brief Holds metadata for bulk data associated with a GroupingEntity. |
| 23 |
*/ |
| 24 |
class IOSS_EXPORT Field |
| 25 |
{ |
| 26 |
public: |
| 27 |
/** \brief The basic data type held in the field. |
| 28 |
*/ |
| 29 |
enum BasicType { |
| 30 |
INVALID = -1, |
| 31 |
REAL = 1, |
| 32 |
DOUBLE = 1, |
| 33 |
INTEGER = 4, |
| 34 |
INT32 = 4, |
| 35 |
INT64 = 8, |
| 36 |
COMPLEX, |
| 37 |
STRING, |
| 38 |
CHARACTER |
| 39 |
}; |
| 40 |
|
| 41 |
enum class InOut { INPUT, OUTPUT }; |
| 42 |
|
| 43 |
IOSS_NODISCARD static Ioss::Field::BasicType get_field_type(char /*dummy*/) |
| 44 |
{ |
| 45 |
return CHARACTER; |
| 46 |
} |
| 47 |
IOSS_NODISCARD static Ioss::Field::BasicType get_field_type(double /*dummy*/) { return DOUBLE; } |
| 48 |
IOSS_NODISCARD static Ioss::Field::BasicType get_field_type(int /*dummy*/) { return INTEGER; } |
| 49 |
IOSS_NODISCARD static Ioss::Field::BasicType get_field_type(unsigned int /*dummy*/) |
| 50 |
{ |
| 51 |
return INTEGER; |
| 52 |
} |
| 53 |
IOSS_NODISCARD static Ioss::Field::BasicType get_field_type(int64_t /*dummy*/) { return INT64; } |
| 54 |
IOSS_NODISCARD static Ioss::Field::BasicType get_field_type(uint64_t /*dummy*/) |
| 55 |
{ |
| 56 |
return INT64; |
| 57 |
} |
| 58 |
IOSS_NODISCARD static Ioss::Field::BasicType get_field_type(Complex /*dummy*/) |
| 59 |
{ |
| 60 |
return COMPLEX; |
| 61 |
} |
| 62 |
IOSS_NODISCARD static Ioss::Field::BasicType get_field_type(const std::string & /*dummy*/) |
| 63 |
{ |
| 64 |
return STRING; |
| 65 |
} |
| 66 |
|
| 67 |
/* \brief Categorizes the type of information held in the field. |
| 68 |
*/ |
| 69 |
enum RoleType { |
| 70 |
INTERNAL, |
| 71 |
MESH, /**< A field which is used to define the basic geometry |
| 72 |
or topology of the model and is not normally transient |
| 73 |
in nature. Examples would be element connectivity or |
| 74 |
nodal coordinates. */ |
| 75 |
ATTRIBUTE, /**< A field which is used to define an attribute on an |
| 76 |
EntityBlock derived class. Examples would be thickness |
| 77 |
of the elements in a shell element block or the radius |
| 78 |
of particles in a particle element block. */ |
| 79 |
MAP, |
| 80 |
COMMUNICATION, |
| 81 |
MESH_REDUCTION, /**< A field which summarizes some non-transient data |
| 82 |
about an entity (\sa REDUCTION). This could be an |
| 83 |
offset applied to an element block, or the units |
| 84 |
system of a model or the name of the solid model |
| 85 |
which this entity is modelling... */ |
| 86 |
INFORMATION = MESH_REDUCTION, |
| 87 |
REDUCTION, /**< A field which typically summarizes some transient data |
| 88 |
about an entity. The size of this field is typically not |
| 89 |
proportional to the number of entities in a GroupingEntity. |
| 90 |
An example would be average displacement over a group of |
| 91 |
nodes or the kinetic energy of a model. This data is also |
| 92 |
transient. */ |
| 93 |
TRANSIENT /**< A field which is typically calculated at multiple steps |
| 94 |
or times in an analysis. These are typically "results" |
| 95 |
data. Examples would be nodal displacement or element |
| 96 |
stress. */ |
| 97 |
}; |
| 98 |
|
| 99 |
Field(); |
| 100 |
|
| 101 |
// Create a field named 'name' that contains values of type 'type' |
| 102 |
// in a storage format of type 'storage'. There are 'value_count' |
| 103 |
// items in the field. If `value_count==0`, then the correct size |
| 104 |
// will be set when the field is added to a `GroupingEntity` |
| 105 |
Field(std::string name, BasicType type, const std::string &storage, RoleType role, |
| 106 |
size_t value_count = 0, size_t index = 0); |
| 107 |
|
| 108 |
Field(std::string name, BasicType type, const std::string &storage, int copies, RoleType role, |
| 109 |
size_t value_count = 0, size_t index = 0); |
| 110 |
|
| 111 |
Field(std::string name, BasicType type, const std::string &storage, |
| 112 |
const std::string &secondary, RoleType role, size_t value_count = 0, size_t index = 0); |
| 113 |
|
| 114 |
Field(std::string name, BasicType type, const VariableType *storage, RoleType role, |
| 115 |
size_t value_count = 0, size_t index = 0); |
| 116 |
|
| 117 |
// Compare two fields (used for STL container) |
| 118 |
IOSS_NODISCARD bool operator<(const Field &other) const; |
| 119 |
|
| 120 |
IOSS_NODISCARD bool operator==(const Ioss::Field &rhs) const; |
| 121 |
IOSS_NODISCARD bool operator!=(const Ioss::Field &rhs) const; |
| 122 |
IOSS_NODISCARD bool equal(const Ioss::Field &rhs) const; |
| 123 |
|
| 124 |
IOSS_NODISCARD bool is_valid() const { return type_ != INVALID; } |
| 125 |
IOSS_NODISCARD bool is_invalid() const { return type_ == INVALID; } |
| 126 |
|
| 127 |
IOSS_NODISCARD const std::string &get_name() const { return name_; } |
| 128 |
IOSS_NODISCARD std::string &get_name() { return name_; } |
| 129 |
|
| 130 |
/** \brief Get name of the 'component_indexth` component (1-based) |
| 131 |
* |
| 132 |
* \param[in] component_index 1-based index of the component to be named |
| 133 |
* \param[in] in_out Is the field being read or written |
| 134 |
* \param[in] suffix optional suffix separator to be used if the separator |
| 135 |
* on the field is set to '1' which means 'unset' |
| 136 |
* \returns name of the specified component |
| 137 |
*/ |
| 138 |
IOSS_NODISCARD std::string get_component_name(int component_index, InOut in_out, |
| 139 |
char suffix = 1) const; |
| 140 |
IOSS_NODISCARD int get_component_count(InOut in_out) const; |
| 141 |
|
| 142 |
Field &set_suffix_separator(char suffix_separator1, char suffix_separator2 = 2) |
| 143 |
{ |
| 144 |
suffixSeparator1_ = suffix_separator1; |
| 145 |
suffixSeparator2_ = suffix_separator2 == 2 ? suffix_separator1 : suffix_separator2; |
| 146 |
return *this; |
| 147 |
} |
| 148 |
IOSS_NODISCARD char get_suffix_separator(int index = 0) const |
| 149 |
{ |
| 150 |
return index == 0 ? suffixSeparator1_ : suffixSeparator2_; |
| 151 |
} |
| 152 |
Field &set_suffices_uppercase(bool true_false) |
| 153 |
{ |
| 154 |
sufficesUppercase_ = true_false; |
| 155 |
return *this; |
| 156 |
} |
| 157 |
IOSS_NODISCARD bool get_suffices_uppercase() const { return sufficesUppercase_; } |
| 158 |
|
| 159 |
const Field &set_zero_copy_enabled(bool true_false = true) const; |
| 160 |
IOSS_NODISCARD bool zero_copy_enabled() const { return zeroCopyable_; } |
| 161 |
|
| 162 |
/** \brief Get the basic data type of the data held in the field. |
| 163 |
* |
| 164 |
* \returns the basic data type of the data held in the field. |
| 165 |
*/ |
| 166 |
IOSS_NODISCARD BasicType get_type() const { return type_; } |
| 167 |
|
| 168 |
IOSS_NODISCARD const VariableType *raw_storage() const { return rawStorage_; } |
| 169 |
IOSS_NODISCARD const VariableType *transformed_storage() const { return transStorage_; } |
| 170 |
|
| 171 |
IOSS_NODISCARD size_t raw_count() const { return rawCount_; } // Number of items in field |
| 172 |
IOSS_NODISCARD size_t transformed_count() const |
| 173 |
{ |
| 174 |
return transCount_; |
| 175 |
} // Number of items in field |
| 176 |
|
| 177 |
IOSS_NODISCARD size_t get_size() const; // data size (in bytes) required to hold entire field |
| 178 |
IOSS_NODISCARD size_t get_basic_size() const; // data size (in bytes) of the basic type |
| 179 |
|
| 180 |
/** \brief Get the role (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.) of the data in the field. |
| 181 |
* |
| 182 |
* \returns The RoleType of the data in the field. |
| 183 |
*/ |
| 184 |
IOSS_NODISCARD RoleType get_role() const { return role_; } |
| 185 |
|
| 186 |
IOSS_NODISCARD size_t get_index() const { return index_; } |
| 187 |
const Field &set_index(size_t index) const |
| 188 |
{ |
| 189 |
index_ = index; |
| 190 |
return *this; |
| 191 |
} |
| 192 |
Field &set_index(size_t index) |
| 193 |
{ |
| 194 |
index_ = index; |
| 195 |
return *this; |
| 196 |
} |
| 197 |
|
| 198 |
void reset_count(size_t new_count); // new number of items in field |
| 199 |
void reset_type(BasicType new_type); // new type of items in field. |
| 200 |
|
| 201 |
// Verify that data_size is valid. Return value is the maximum |
| 202 |
// number of entities to get ('RawCount') |
| 203 |
// Throws runtime error if data_size too small. |
| 204 |
size_t verify(size_t data_size) const; |
| 205 |
|
| 206 |
// Verify that the type 'the_type' matches the field's type. |
| 207 |
// throws exception if the types don't match. |
| 208 |
void check_type(BasicType the_type) const; |
| 209 |
|
| 210 |
IOSS_NODISCARD bool is_type(BasicType the_type) const { return the_type == type_; } |
| 211 |
|
| 212 |
IOSS_NODISCARD std::string type_string() const; |
| 213 |
IOSS_NODISCARD static std::string type_string(BasicType type); |
| 214 |
|
| 215 |
IOSS_NODISCARD std::string role_string() const; |
| 216 |
IOSS_NODISCARD static std::string role_string(RoleType role); |
| 217 |
|
| 218 |
bool add_transform(Transform *my_transform); |
| 219 |
bool transform(void *data); |
| 220 |
IOSS_NODISCARD bool has_transform() const { return !transforms_.empty(); } |
| 221 |
|
| 222 |
private: |
| 223 |
std::string name_{}; |
| 224 |
|
| 225 |
size_t rawCount_{}; // Count of items in field before transformation |
| 226 |
size_t transCount_{}; // Count of items in field after transformed |
| 227 |
size_t size_{}; // maximum data size (in bytes) required to hold entire field |
| 228 |
mutable size_t |
| 229 |
index_{}; // Optional flag that can be used by a client to indicate an ordering. |
| 230 |
// Unused by field itself. Used by some DatabaeIO objects to set ordering. |
| 231 |
BasicType type_{INVALID}; |
| 232 |
RoleType role_{INTERNAL}; |
| 233 |
|
| 234 |
const VariableType *rawStorage_{nullptr}; // Storage type of raw field |
| 235 |
const VariableType *transStorage_{nullptr}; // Storage type after transformation |
| 236 |
|
| 237 |
std::vector<Transform *> transforms_{}; |
| 238 |
char suffixSeparator1_{1}; // Value = 1 means unset; use database default. |
| 239 |
char suffixSeparator2_{1}; // Value = 1 means unset; use database default. |
| 240 |
bool sufficesUppercase_{false}; // True if the suffices are uppercase on database... |
| 241 |
mutable bool zeroCopyable_{false}; // True if the field is zero-copyable. |
| 242 |
|
| 243 |
bool equal_(const Ioss::Field &rhs, bool quiet) const; |
| 244 |
}; |
| 245 |
IOSS_EXPORT std::ostream &operator<<(std::ostream &os, const Field &fld); |
| 246 |
} // namespace Ioss |