IOSS 2.0
Loading...
Searching...
No Matches
Ioss_Field.h
Go to the documentation of this file.
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
17namespace 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,
38 CHARACTER
39 };
40
41 enum class InOut { INPUT, OUTPUT };
42
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; }
50 {
51 return INTEGER;
52 }
53 IOSS_NODISCARD static Ioss::Field::BasicType get_field_type(int64_t /*dummy*/) { return INT64; }
55 {
56 return INT64;
57 }
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 {
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. */
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 VariableType *storage, RoleType role,
112 size_t value_count = 0, size_t index = 0);
113
114 // Compare two fields (used for STL container)
115 IOSS_NODISCARD bool operator<(const Field &other) const;
116
117 IOSS_NODISCARD bool operator==(const Ioss::Field &rhs) const;
118 IOSS_NODISCARD bool operator!=(const Ioss::Field &rhs) const;
119 IOSS_NODISCARD bool equal(const Ioss::Field &rhs) const;
120
121 IOSS_NODISCARD bool is_valid() const { return type_ != INVALID; }
122 IOSS_NODISCARD bool is_invalid() const { return type_ == INVALID; }
123
124 IOSS_NODISCARD const std::string &get_name() const { return name_; }
125 IOSS_NODISCARD std::string &get_name() { return name_; }
126
127 /** \brief Get name of the 'component_indexth` component (1-based)
128 *
129 * \param[in] component_index 1-based index of the component to be named
130 * \param[in] in_out Is the field being read or written
131 * \param[in] suffix optional suffix separator to be used if the separator
132 * on the field is set to '1' which means 'unset'
133 * \returns name of the specified component
134 */
135 IOSS_NODISCARD std::string get_component_name(int component_index, InOut in_out,
136 char suffix = 1) const;
137 IOSS_NODISCARD int get_component_count(InOut in_out) const;
138
139 Field &set_suffix_separator(char suffix_separator)
140 {
141 suffixSeparator_ = suffix_separator;
142 return *this;
143 }
144 IOSS_NODISCARD char get_suffix_separator() const { return suffixSeparator_; }
146 {
147 sufficesUppercase_ = true_false;
148 return *this;
149 }
150 IOSS_NODISCARD bool get_suffices_uppercase() const { return sufficesUppercase_; }
151
152 const Field &set_zero_copy_enabled(bool true_false = true) const;
153 IOSS_NODISCARD bool zero_copy_enabled() const { return zeroCopyable_; }
154
155 /** \brief Get the basic data type of the data held in the field.
156 *
157 * \returns the basic data type of the data held in the field.
158 */
159 IOSS_NODISCARD BasicType get_type() const { return type_; }
160
161 IOSS_NODISCARD const VariableType *raw_storage() const { return rawStorage_; }
162 IOSS_NODISCARD const VariableType *transformed_storage() const { return transStorage_; }
163
164 IOSS_NODISCARD size_t raw_count() const { return rawCount_; } // Number of items in field
166 {
167 return transCount_;
168 } // Number of items in field
169
170 IOSS_NODISCARD size_t get_size() const; // data size (in bytes) required to hold entire field
171 IOSS_NODISCARD size_t get_basic_size() const; // data size (in bytes) of the basic type
172
173 /** \brief Get the role (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.) of the data in the field.
174 *
175 * \returns The RoleType of the data in the field.
176 */
177 IOSS_NODISCARD RoleType get_role() const { return role_; }
178
179 IOSS_NODISCARD size_t get_index() const { return index_; }
180 const Field &set_index(size_t index) const
181 {
182 index_ = index;
183 return *this;
184 }
185 Field &set_index(size_t index)
186 {
187 index_ = index;
188 return *this;
189 }
190
191 void reset_count(size_t new_count); // new number of items in field
192 void reset_type(BasicType new_type); // new type of items in field.
193
194 // Verify that data_size is valid. Return value is the maximum
195 // number of entities to get ('RawCount')
196 // Throws runtime error if data_size too small.
197 size_t verify(size_t data_size) const;
198
199 // Verify that the type 'the_type' matches the field's type.
200 // throws exception if the types don't match.
201 void check_type(BasicType the_type) const;
202
203 IOSS_NODISCARD bool is_type(BasicType the_type) const { return the_type == type_; }
204
205 IOSS_NODISCARD std::string type_string() const;
206 IOSS_NODISCARD static std::string type_string(BasicType type);
207
208 IOSS_NODISCARD std::string role_string() const;
209 IOSS_NODISCARD static std::string role_string(RoleType role);
210
211 bool add_transform(Transform *my_transform);
212 bool transform(void *data);
213 IOSS_NODISCARD bool has_transform() const { return !transforms_.empty(); }
214
215 private:
216 std::string name_{};
217
218 size_t rawCount_{}; // Count of items in field before transformation
219 size_t transCount_{}; // Count of items in field after transformed
220 size_t size_{}; // maximum data size (in bytes) required to hold entire field
221 mutable size_t
222 index_{}; // Optional flag that can be used by a client to indicate an ordering.
223 // Unused by field itself. Used by some DatabaeIO objects to set ordering.
224 BasicType type_{INVALID};
225 RoleType role_{INTERNAL};
226
227 const VariableType *rawStorage_{nullptr}; // Storage type of raw field
228 const VariableType *transStorage_{nullptr}; // Storage type after transformation
229
230 std::vector<Transform *> transforms_{};
231 char suffixSeparator_{1}; // Value = 1 means unset; use database default.
232 bool sufficesUppercase_{false}; // True if the suffices are uppercase on database...
233 mutable bool zeroCopyable_{false}; // True if the field is zero-copyable.
234
235 bool equal_(const Ioss::Field &rhs, bool quiet) const;
236 };
237} // namespace Ioss
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:54
std::complex< double > Complex
Definition Ioss_CodeTypes.h:90
Holds metadata for bulk data associated with a GroupingEntity.
Definition Ioss_Field.h:25
Field & set_index(size_t index)
Definition Ioss_Field.h:185
static IOSS_NODISCARD Ioss::Field::BasicType get_field_type(Complex)
Definition Ioss_Field.h:58
static IOSS_NODISCARD Ioss::Field::BasicType get_field_type(uint64_t)
Definition Ioss_Field.h:54
IOSS_NODISCARD bool is_type(BasicType the_type) const
Definition Ioss_Field.h:203
IOSS_NODISCARD const VariableType * raw_storage() const
Definition Ioss_Field.h:161
IOSS_NODISCARD BasicType get_type() const
Get the basic data type of the data held in the field.
Definition Ioss_Field.h:159
IOSS_NODISCARD bool has_transform() const
Definition Ioss_Field.h:213
IOSS_NODISCARD bool is_valid() const
Definition Ioss_Field.h:121
IOSS_NODISCARD std::string & get_name()
Definition Ioss_Field.h:125
IOSS_NODISCARD bool operator<(const Field &other) const
BasicType
The basic data type held in the field.
Definition Ioss_Field.h:29
@ COMPLEX
Definition Ioss_Field.h:36
@ STRING
Definition Ioss_Field.h:37
IOSS_NODISCARD size_t raw_count() const
Definition Ioss_Field.h:164
RoleType
Definition Ioss_Field.h:69
@ COMMUNICATION
Definition Ioss_Field.h:80
@ MAP
Definition Ioss_Field.h:79
@ INTERNAL
Definition Ioss_Field.h:70
IOSS_NODISCARD bool zero_copy_enabled() const
Definition Ioss_Field.h:153
IOSS_NODISCARD const VariableType * transformed_storage() const
Definition Ioss_Field.h:162
IOSS_NODISCARD bool get_suffices_uppercase() const
Definition Ioss_Field.h:150
static IOSS_NODISCARD Ioss::Field::BasicType get_field_type(double)
Definition Ioss_Field.h:47
static IOSS_NODISCARD Ioss::Field::BasicType get_field_type(unsigned int)
Definition Ioss_Field.h:49
static IOSS_NODISCARD Ioss::Field::BasicType get_field_type(const std::string &)
Definition Ioss_Field.h:62
IOSS_NODISCARD const std::string & get_name() const
Definition Ioss_Field.h:124
Field & set_suffix_separator(char suffix_separator)
Definition Ioss_Field.h:139
static IOSS_NODISCARD Ioss::Field::BasicType get_field_type(int64_t)
Definition Ioss_Field.h:53
static IOSS_NODISCARD Ioss::Field::BasicType get_field_type(int)
Definition Ioss_Field.h:48
IOSS_NODISCARD bool is_invalid() const
Definition Ioss_Field.h:122
IOSS_NODISCARD size_t get_index() const
Definition Ioss_Field.h:179
Field & set_suffices_uppercase(bool true_false)
Definition Ioss_Field.h:145
static IOSS_NODISCARD Ioss::Field::BasicType get_field_type(char)
Definition Ioss_Field.h:43
IOSS_NODISCARD RoleType get_role() const
Get the role (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.) of the data in the field.
Definition Ioss_Field.h:177
IOSS_NODISCARD char get_suffix_separator() const
Definition Ioss_Field.h:144
const Field & set_index(size_t index) const
Definition Ioss_Field.h:180
InOut
Definition Ioss_Field.h:41
IOSS_NODISCARD size_t transformed_count() const
Definition Ioss_Field.h:165
Definition Ioss_Transform.h:21
A generic variable type.
Definition Ioss_VariableType.h:66
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
std::ostream & OUTPUT()
Definition Ioss_Utils.h:611