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