IOSS 2.0

Ioss_Field.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2017 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 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of NTESS nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 #ifndef IOSS_Ioss_Field_h
34 #define IOSS_Ioss_Field_h
35
36 #include <Ioss_CodeTypes.h>
37 #include <cstddef> // for size_t
38 #include <string> // for string
39 #include <vector> // for vector
40 namespace Ioss {
41 class GroupingEntity;
42 class Transform;
43 class VariableType;
44
45 /** \brief Holds metadata for bulk data associated with a GroupingEntity.
46 */
47 class Field
48 {
49 public:
50 /** \brief The basic data type held in the field.
51 */
52 enum BasicType {
53 INVALID = -1,
54 REAL = 1,
55 DOUBLE = 1,
56 INTEGER = 4,
57 INT32 = 4,
58 INT64 = 8,
59 COMPLEX,
60 STRING,
61 CHARACTER
62 };
63
64 static Ioss::Field::BasicType get_field_type(char /*dummy*/) { return CHARACTER; }
65 static Ioss::Field::BasicType get_field_type(double /*dummy*/) { return DOUBLE; }
66 static Ioss::Field::BasicType get_field_type(int /*dummy*/) { return INTEGER; }
67 static Ioss::Field::BasicType get_field_type(unsigned int /*dummy*/) { return INTEGER; }
68 static Ioss::Field::BasicType get_field_type(int64_t /*dummy*/) { return INT64; }
69 static Ioss::Field::BasicType get_field_type(uint64_t /*dummy*/) { return INT64; }
70 static Ioss::Field::BasicType get_field_type(Complex /*dummy*/) { return COMPLEX; }
71 static Ioss::Field::BasicType get_field_type(std::string /*dummy*/) { return STRING; }
72
73 /* \brief Categorizes the type of information held in the field.
74 */
75 enum RoleType {
76 INTERNAL,
77 MESH, /**< A field which is used to define the basic geometry
78 or topology of the model and is not normally transient
79 in nature. Examples would be element connectivity or
80 nodal coordinates. */
81 ATTRIBUTE, /**< A field which is used to define an attribute on an
82 EntityBlock derived class. Examples would be thickness
83 of the elements in a shell element block or the radius
84 of particles in a particle element block. */
85 COMMUNICATION,
86 INFORMATION,
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.
104 Field(std::string name, BasicType type, const std::string &storage, RoleType role,
105 size_t value_count, size_t index = 0);
106
107 Field(std::string name, BasicType type, const std::string &storage, int copies, RoleType role,
108 size_t value_count, size_t index = 0);
109
110 Field(std::string name, BasicType type, const VariableType *storage, RoleType role,
111 size_t value_count, size_t index = 0);
112
113 // Create a field from another field.
114 Field(const Field & /*from*/);
115 Field &operator=(const Field & /*from*/);
116
117 // Compare two fields (used for STL container)
118 bool operator<(const Field &other) const;
119
120 ~Field();
121
122 bool is_valid() const { return type_ != INVALID; }
123 bool is_invalid() const { return type_ == INVALID; }
124
125 const std::string &get_name() const { return name_; }
126
127 /** \brief Get the basic data type of the data held in the field.
128 *
129 * \returns the basic data type of the data held in the field.
130 */
131 BasicType get_type() const { return type_; }
132
133 const VariableType *raw_storage() const { return rawStorage_; }
134 const VariableType *transformed_storage() const { return transStorage_; }
135
136 size_t raw_count() const { return rawCount_; } // Number of items in field
137 size_t transformed_count() const { return transCount_; } // Number of items in field
138
139 size_t get_size() const; // data size (in bytes) required to hold entire field
140
141 /** \brief Get the role (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.) of the data in the field.
142 *
143 * \returns The RoleType of the data in the field.
144 */
145 RoleType get_role() const { return role_; }
146
147 size_t get_index() const { return index_; }
148 void set_index(size_t index) const { index_ = index; }
149
150 void reset_count(size_t new_count); // new number of items in field
151 void reset_type(BasicType new_type); // new type of items in field.
152
153 // Verify that data_size is valid. Return value is the maximum
154 // number of entities to get ('RawCount')
155 // Throws runtime error if data_size too small.
156 size_t verify(size_t data_size) const;
157
158 // Verify that the type 'the_type' matches the field's type.
159 // throws exception if the types don't match.
160 void check_type(BasicType the_type) const;
161
162 bool is_type(BasicType the_type) const { return the_type == type_; }
163
164 bool add_transform(Transform *my_transform);
165 bool transform(void *data);
166 bool has_transform() const { return !transforms_.empty(); }
167
168 private:
169 std::string name_;
170
171 size_t rawCount_{}; // Count of items in field before transformation
172 size_t transCount_{}; // Count of items in field after transformed
173 size_t size_{}; // maximum data size (in bytes) required to hold entire field
174 mutable size_t index_{}; // Optional flag that can be used by a client to indicate an ordering.
175 // Unused by field itself.
176 BasicType type_{INVALID};
177 RoleType role_{INTERNAL};
178
179 const VariableType *rawStorage_{}; // Storage type of raw field
180 const VariableType *transStorage_{}; // Storage type after transformation
181
182 std::vector<Transform *> transforms_;
183 };
184 } // namespace Ioss
185 #endif
Ioss_CodeTypes.h
Ioss::Field::operator<
bool operator<(const Field &other) const
Ioss::Field::transCount_
size_t transCount_
Definition: Ioss_Field.h:172
Ioss
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Ioss::Field::transformed_storage
const VariableType * transformed_storage() const
Definition: Ioss_Field.h:134
Ioss::Field::get_type
BasicType get_type() const
Get the basic data type of the data held in the field.
Definition: Ioss_Field.h:131
Ioss::Field::get_size
size_t get_size() const
Definition: Ioss_Field.C:205
Ioss::Field::get_role
RoleType get_role() const
Get the role (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.) of the data in the field.
Definition: Ioss_Field.h:145
Ioss::Field::reset_type
void reset_type(BasicType new_type)
Definition: Ioss_Field.C:198
Ioss::Field::MESH
Definition: Ioss_Field.h:77
Ioss::Field::REAL
Definition: Ioss_Field.h:54
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(uint64_t)
Definition: Ioss_Field.h:69
Ioss::Transform
Definition: Ioss_Transform.h:55
Ioss::Field::RoleType
RoleType
Definition: Ioss_Field.h:75
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(int)
Definition: Ioss_Field.h:66
Ioss::Field::check_type
void check_type(BasicType the_type) const
Definition: Ioss_Field.C:172
Ioss::Field::INT32
Definition: Ioss_Field.h:57
Ioss::Field::transformed_count
size_t transformed_count() const
Definition: Ioss_Field.h:137
Ioss::Field::is_invalid
bool is_invalid() const
Definition: Ioss_Field.h:123
Ioss::Field::operator=
Field & operator=(const Field &)
Ioss::Field::transforms_
std::vector< Transform * > transforms_
Definition: Ioss_Field.h:182
Ioss::Field::reset_count
void reset_count(size_t new_count)
Definition: Ioss_Field.C:189
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(unsigned int)
Definition: Ioss_Field.h:67
Ioss::Field::INFORMATION
Definition: Ioss_Field.h:86
Ioss::Field::TRANSIENT
Definition: Ioss_Field.h:93
Complex
std::complex< double > Complex
Definition: Ioss_CodeTypes.h:99
Ioss::Field::DOUBLE
Definition: Ioss_Field.h:55
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(std::string)
Definition: Ioss_Field.h:71
Ioss::Field::is_valid
bool is_valid() const
Definition: Ioss_Field.h:122
Ioss::Field::add_transform
bool add_transform(Transform *my_transform)
Definition: Ioss_Field.C:225
Ioss::Field::get_index
size_t get_index() const
Definition: Ioss_Field.h:147
Ioss::Field::INTEGER
Definition: Ioss_Field.h:56
Ioss::Field::REDUCTION
Definition: Ioss_Field.h:87
Ioss::Field::role_
RoleType role_
Definition: Ioss_Field.h:177
Ioss::Field::ATTRIBUTE
Definition: Ioss_Field.h:81
Ioss::VariableType
A generic variable type.
Definition: Ioss_VariableType.h:93
Ioss::Field::rawCount_
size_t rawCount_
Definition: Ioss_Field.h:171
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(int64_t)
Definition: Ioss_Field.h:68
Ioss::Field::~Field
~Field()
Ioss::Field::type_
BasicType type_
Definition: Ioss_Field.h:176
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(double)
Definition: Ioss_Field.h:65
Ioss::Field::raw_storage
const VariableType * raw_storage() const
Definition: Ioss_Field.h:133
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(Complex)
Definition: Ioss_Field.h:70
Ioss::Field::verify
size_t verify(size_t data_size) const
Definition: Ioss_Field.C:157
Ioss::Field::raw_count
size_t raw_count() const
Definition: Ioss_Field.h:136
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:73
Ioss::Field::set_index
void set_index(size_t index) const
Definition: Ioss_Field.h:148
Ioss::Field::Field
Field()
Create an empty field.
Definition: Ioss_Field.C:75
Ioss::Field::INVALID
Definition: Ioss_Field.h:53
Ioss::Field::BasicType
BasicType
The basic data type held in the field.
Definition: Ioss_Field.h:52
anonymous_namespace{io_info.C}::name
std::string name(Ioss::GroupingEntity *entity)
Definition: io_info.C:88
Ioss::Field::CHARACTER
Definition: Ioss_Field.h:61
Ioss::Field::rawStorage_
const VariableType * rawStorage_
Definition: Ioss_Field.h:179
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Ioss::Field::COMPLEX
Definition: Ioss_Field.h:59
Ioss::Field::STRING
Definition: Ioss_Field.h:60
Ioss::Field::size_
size_t size_
Definition: Ioss_Field.h:173
Ioss::Field::transform
bool transform(void *data)
Definition: Ioss_Field.C:251
Ioss::Field::INTERNAL
Definition: Ioss_Field.h:76
Ioss::Field::get_name
const std::string & get_name() const
Definition: Ioss_Field.h:125
Ioss::Field::index_
size_t index_
Definition: Ioss_Field.h:174
Ioss::Field::transStorage_
const VariableType * transStorage_
Definition: Ioss_Field.h:180
Ioss::Field::has_transform
bool has_transform() const
Definition: Ioss_Field.h:166
Ioss::Field::COMMUNICATION
Definition: Ioss_Field.h:85
Ioss::Field::is_type
bool is_type(BasicType the_type) const
Definition: Ioss_Field.h:162
Ioss::Field::name_
std::string name_
Definition: Ioss_Field.h:169
Ioss::Field::INT64
Definition: Ioss_Field.h:58
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(char)
Definition: Ioss_Field.h:64