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 */
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. */
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... */
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 Field();
103
104 // Create a field named 'name' that contains values of type 'type'
105 // in a storage format of type 'storage'. There are 'value_count'
106 // items in the field. If `value_count==0`, then the correct size
107 // will be set when the field is added to a `GroupingEntity`
108 Field(std::string name, BasicType type, const std::string &storage, RoleType role,
109 size_t value_count = 0, size_t index = 0);
110
111 Field(std::string name, BasicType type, const std::string &storage, int copies, RoleType role,
112 size_t value_count = 0, size_t index = 0);
113
114 Field(std::string name, BasicType type, const std::string &storage,
115 const std::string &secondary, RoleType role, size_t value_count = 0, size_t index = 0);
116
117 Field(std::string name, BasicType type, const VariableType *storage, RoleType role,
118 size_t value_count = 0, size_t index = 0);
119
120 // Compare two fields (used for STL container)
121 IOSS_NODISCARD bool operator<(const Field &other) const;
122
123 IOSS_NODISCARD bool operator==(const Ioss::Field &rhs) const;
124 IOSS_NODISCARD bool operator!=(const Ioss::Field &rhs) const;
125 IOSS_NODISCARD bool equal(const Ioss::Field &rhs) const;
126
127 IOSS_NODISCARD bool is_valid() const { return type_ != INVALID; }
128 IOSS_NODISCARD bool is_invalid() const { return type_ == INVALID; }
129
130 IOSS_NODISCARD const std::string &get_name() const { return name_; }
131 IOSS_NODISCARD std::string &get_name() { return name_; }
132
133 /** \brief Get name of the 'component_indexth` component (1-based)
134 *
135 * \param[in] component_index 1-based index of the component to be named
136 * \param[in] in_out Is the field being read or written
137 * \param[in] suffix optional suffix separator to be used if the separator
138 * on the field is set to '1' which means 'unset'
139 * \returns name of the specified component
140 */
141 IOSS_NODISCARD std::string get_component_name(int component_index, InOut in_out,
142 char suffix = 1) const;
143 IOSS_NODISCARD int get_component_count(InOut in_out) const;
144
145 Field &set_suffix_separator(char suffix_separator1, char suffix_separator2 = 2)
146 {
147 suffixSeparator1_ = suffix_separator1;
148 suffixSeparator2_ = suffix_separator2 == 2 ? suffix_separator1 : suffix_separator2;
149 return *this;
150 }
151 IOSS_NODISCARD char get_suffix_separator(int index = 0) const
152 {
153 return index == 0 ? suffixSeparator1_ : suffixSeparator2_;
154 }
156 {
157 sufficesUppercase_ = true_false;
158 return *this;
159 }
161
162 const Field &set_zero_copy_enabled(bool true_false = true) const;
164
165 /** \brief Get the basic data type of the data held in the field.
166 *
167 * \returns the basic data type of the data held in the field.
168 */
170
173
174 IOSS_NODISCARD size_t raw_count() const { return rawCount_; } // Number of items in field
176 {
177 return transCount_;
178 } // Number of items in field
179
180 IOSS_NODISCARD size_t get_size() const; // data size (in bytes) required to hold entire field
181 IOSS_NODISCARD size_t get_basic_size() const; // data size (in bytes) of the basic type
182
183 /** \brief Get the role (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.) of the data in the field.
184 *
185 * \returns The RoleType of the data in the field.
186 */
188
189 IOSS_NODISCARD size_t get_index() const { return index_; }
190 const Field &set_index(size_t index) const
191 {
192 index_ = index;
193 return *this;
194 }
195 Field &set_index(size_t index)
196 {
197 index_ = index;
198 return *this;
199 }
200
201 void reset_count(size_t new_count); // new number of items in field
202 void reset_type(BasicType new_type); // new type of items in field.
203
204 // Verify that data_size is valid. Return value is the maximum
205 // number of entities to get ('RawCount')
206 // Throws runtime error if data_size too small.
207 size_t verify(size_t data_size) const;
208
209 // Verify that the type 'the_type' matches the field's type.
210 // throws exception if the types don't match.
211 void check_type(BasicType the_type) const;
212
213 IOSS_NODISCARD bool is_type(BasicType the_type) const { return the_type == type_; }
214
215 IOSS_NODISCARD std::string type_string() const;
216 IOSS_NODISCARD static std::string type_string(BasicType type);
217
218 IOSS_NODISCARD std::string role_string() const;
219 IOSS_NODISCARD static std::string role_string(RoleType role);
220
221 bool add_transform(Transform *my_transform);
222 bool transform(void *data);
223 IOSS_NODISCARD bool has_transform() const { return !transforms_.empty(); }
224
225 private:
226 std::string name_{};
227
228 size_t rawCount_{}; // Count of items in field before transformation
229 size_t transCount_{}; // Count of items in field after transformed
230 size_t size_{}; // maximum data size (in bytes) required to hold entire field
231 mutable size_t
232 index_{}; // Optional flag that can be used by a client to indicate an ordering.
233 // Unused by field itself. Used by some DatabaeIO objects to set ordering.
236
237 const VariableType *rawStorage_{nullptr}; // Storage type of raw field
238 const VariableType *transStorage_{nullptr}; // Storage type after transformation
239
240 std::vector<std::shared_ptr<Transform>> transforms_{};
241 char suffixSeparator1_{1}; // Value = 1 means unset; use database default.
242 char suffixSeparator2_{1}; // Value = 1 means unset; use database default.
243 bool sufficesUppercase_{false}; // True if the suffices are uppercase on database...
244 mutable bool zeroCopyable_{false}; // True if the field is zero-copyable.
245
246 bool equal_(const Ioss::Field &rhs, bool quiet) const;
247 };
248 IOSS_EXPORT std::ostream &operator<<(std::ostream &os, const Field &fld);
249} // namespace Ioss
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:56
std::complex< double > Complex
Definition Ioss_CodeTypes.h:82
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:399
size_t index_
Definition Ioss_Field.h:232
Field & set_index(size_t index)
Definition Ioss_Field.h:195
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:213
IOSS_NODISCARD bool operator!=(const Ioss::Field &rhs) const
Definition Ioss_Field.C:397
IOSS_NODISCARD const VariableType * raw_storage() const
Definition Ioss_Field.h:171
RoleType role_
Definition Ioss_Field.h:235
IOSS_NODISCARD BasicType get_type() const
Get the basic data type of the data held in the field.
Definition Ioss_Field.h:169
IOSS_NODISCARD bool has_transform() const
Definition Ioss_Field.h:223
IOSS_NODISCARD bool is_valid() const
Definition Ioss_Field.h:127
std::vector< std::shared_ptr< Transform > > transforms_
Definition Ioss_Field.h:240
IOSS_NODISCARD std::string & get_name()
Definition Ioss_Field.h:131
IOSS_NODISCARD bool operator<(const Field &other) const
const VariableType * rawStorage_
Definition Ioss_Field.h:237
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
Definition Ioss_Field.h:174
RoleType
Definition Ioss_Field.h:72
@ INFORMATION
Definition Ioss_Field.h:89
@ REDUCTION
Definition Ioss_Field.h:90
@ MESH
Definition Ioss_Field.h:74
@ TRANSIENT
Definition Ioss_Field.h:96
@ COMMUNICATION
Definition Ioss_Field.h:83
@ MESH_REDUCTION
Definition Ioss_Field.h:84
@ MAP
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:163
IOSS_NODISCARD const VariableType * transformed_storage() const
Definition Ioss_Field.h:172
IOSS_NODISCARD bool get_suffices_uppercase() const
Definition Ioss_Field.h:160
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:70
static IOSS_NODISCARD Ioss::Field::BasicType get_field_type(const std::string &)
Definition Ioss_Field.h:65
size_t rawCount_
Definition Ioss_Field.h:228
size_t size_
Definition Ioss_Field.h:230
BasicType type_
Definition Ioss_Field.h:234
IOSS_NODISCARD bool operator==(const Ioss::Field &rhs) const
Definition Ioss_Field.C:395
Field & set_suffix_separator(char suffix_separator1, char suffix_separator2=2)
Definition Ioss_Field.h:145
char suffixSeparator1_
Definition Ioss_Field.h:241
bool zeroCopyable_
Definition Ioss_Field.h:244
IOSS_NODISCARD const std::string & get_name() const
Definition Ioss_Field.h:130
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_
Definition Ioss_Field.h:243
IOSS_NODISCARD bool is_invalid() const
Definition Ioss_Field.h:128
const VariableType * transStorage_
Definition Ioss_Field.h:238
IOSS_NODISCARD char get_suffix_separator(int index=0) const
Definition Ioss_Field.h:151
std::string name_
Definition Ioss_Field.h:226
IOSS_NODISCARD size_t get_index() const
Definition Ioss_Field.h:189
Field & set_suffices_uppercase(bool true_false)
Definition Ioss_Field.h:155
char suffixSeparator2_
Definition Ioss_Field.h:242
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:187
const Field & set_index(size_t index) const
Definition Ioss_Field.h:190
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
Definition Ioss_Field.h:175
size_t transCount_
Definition Ioss_Field.h:229
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:41