IOSS  2.0
Ioss_Field.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2020 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 #ifndef IOSS_Ioss_Field_h
8 #define IOSS_Ioss_Field_h
9 
10 #include <Ioss_CodeTypes.h>
11 #include <cstddef> // for size_t
12 #include <string> // for string
13 #include <vector> // for vector
14 namespace Ioss {
15  class GroupingEntity;
16  class Transform;
17  class VariableType;
18 
19  /** \brief Holds metadata for bulk data associated with a GroupingEntity.
20  */
21  class Field
22  {
23  public:
24  /** \brief The basic data type held in the field.
25  */
26  enum BasicType {
27  INVALID = -1,
28  REAL = 1,
29  DOUBLE = 1,
30  INTEGER = 4,
31  INT32 = 4,
32  INT64 = 8,
35  CHARACTER
36  };
37 
38  static Ioss::Field::BasicType get_field_type(char /*dummy*/) { return CHARACTER; }
39  static Ioss::Field::BasicType get_field_type(double /*dummy*/) { return DOUBLE; }
40  static Ioss::Field::BasicType get_field_type(int /*dummy*/) { return INTEGER; }
41  static Ioss::Field::BasicType get_field_type(unsigned int /*dummy*/) { return INTEGER; }
42  static Ioss::Field::BasicType get_field_type(int64_t /*dummy*/) { return INT64; }
43  static Ioss::Field::BasicType get_field_type(uint64_t /*dummy*/) { return INT64; }
44  static Ioss::Field::BasicType get_field_type(Complex /*dummy*/) { return COMPLEX; }
45  static Ioss::Field::BasicType get_field_type(std::string /*dummy*/) { return STRING; }
46 
47  /* \brief Categorizes the type of information held in the field.
48  */
49  enum RoleType {
51  MESH, /**< A field which is used to define the basic geometry
52  or topology of the model and is not normally transient
53  in nature. Examples would be element connectivity or
54  nodal coordinates. */
55  ATTRIBUTE, /**< A field which is used to define an attribute on an
56  EntityBlock derived class. Examples would be thickness
57  of the elements in a shell element block or the radius
58  of particles in a particle element block. */
60  MESH_REDUCTION, /**< A field which summarizes some non-transient data
61  about an entity (\sa REDUCTION). This could be an
62  offset applied to an element block, or the units
63  system of a model or the name of the solid model
64  which this entity is modelling... */
66  REDUCTION, /**< A field which typically summarizes some transient data
67  about an entity. The size of this field is typically not
68  proportional to the number of entities in a GroupingEntity.
69  An example would be average displacement over a group of
70  nodes or the kinetic energy of a model. This data is also
71  transient. */
72  TRANSIENT /**< A field which is typically calculated at multiple steps
73  or times in an analysis. These are typically "results"
74  data. Examples would be nodal displacement or element
75  stress. */
76  };
77 
78  Field();
79 
80  // Create a field named 'name' that contains values of type 'type'
81  // in a storage format of type 'storage'. There are 'value_count'
82  // items in the field. If `value_count==0`, then the correct size
83  // will be set when the field is added to a `GroupingEntity`
84  Field(std::string name, BasicType type, const std::string &storage, RoleType role,
85  size_t value_count = 0, size_t index = 0);
86 
87  Field(std::string name, BasicType type, const std::string &storage, int copies, RoleType role,
88  size_t value_count = 0, size_t index = 0);
89 
90  Field(std::string name, BasicType type, const VariableType *storage, RoleType role,
91  size_t value_count = 0, size_t index = 0);
92 
93  // Create a field from another field.
94  Field(const Field & /*from*/);
95  Field &operator=(const Field & /*from*/);
96 
97  // Compare two fields (used for STL container)
98  bool operator<(const Field &other) const;
99 
101 
102  bool is_valid() const { return type_ != INVALID; }
103  bool is_invalid() const { return type_ == INVALID; }
104 
105  const std::string &get_name() const { return name_; }
106 
107  /** \brief Get the basic data type of the data held in the field.
108  *
109  * \returns the basic data type of the data held in the field.
110  */
111  BasicType get_type() const { return type_; }
112 
113  const VariableType *raw_storage() const { return rawStorage_; }
114  const VariableType *transformed_storage() const { return transStorage_; }
115 
116  size_t raw_count() const { return rawCount_; } // Number of items in field
117  size_t transformed_count() const { return transCount_; } // Number of items in field
118 
119  size_t get_size() const; // data size (in bytes) required to hold entire field
120 
121  /** \brief Get the role (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.) of the data in the field.
122  *
123  * \returns The RoleType of the data in the field.
124  */
125  RoleType get_role() const { return role_; }
126 
127  size_t get_index() const { return index_; }
128  void set_index(size_t index) const { index_ = index; }
129 
130  void reset_count(size_t new_count); // new number of items in field
131  void reset_type(BasicType new_type); // new type of items in field.
132 
133  // Verify that data_size is valid. Return value is the maximum
134  // number of entities to get ('RawCount')
135  // Throws runtime error if data_size too small.
136  size_t verify(size_t data_size) const;
137 
138  // Verify that the type 'the_type' matches the field's type.
139  // throws exception if the types don't match.
140  void check_type(BasicType the_type) const;
141 
142  bool is_type(BasicType the_type) const { return the_type == type_; }
143 
144  bool add_transform(Transform *my_transform);
145  bool transform(void *data);
146  bool has_transform() const { return !transforms_.empty(); }
147 
148  private:
149  std::string name_;
150 
151  size_t rawCount_{}; // Count of items in field before transformation
152  size_t transCount_{}; // Count of items in field after transformed
153  size_t size_{}; // maximum data size (in bytes) required to hold entire field
154  mutable size_t index_{}; // Optional flag that can be used by a client to indicate an ordering.
155  // Unused by field itself.
158 
159  const VariableType *rawStorage_{}; // Storage type of raw field
160  const VariableType *transStorage_{}; // Storage type after transformation
161 
162  std::vector<Transform *> transforms_;
163  };
164 } // namespace Ioss
165 #endif
Ioss::Field::is_type
bool is_type(BasicType the_type) const
Definition: Ioss_Field.h:142
Ioss::Field::get_size
size_t get_size() const
Definition: Ioss_Field.C:182
Ioss::Field::REDUCTION
@ REDUCTION
Definition: Ioss_Field.h:66
Ioss::Field::INTEGER
@ INTEGER
Definition: Ioss_Field.h:30
Complex
std::complex< double > Complex
Definition: Ioss_CodeTypes.h:85
Ioss::Field::Field
Field()
Create an empty field.
Definition: Ioss_Field.C:51
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:22
Ioss::VariableType
A generic variable type.
Definition: Ioss_VariableType.h:61
Ioss::Transform
Definition: Ioss_Transform.h:21
Ioss::Field::transformed_count
size_t transformed_count() const
Definition: Ioss_Field.h:117
Ioss::Field::operator=
Field & operator=(const Field &)
Ioss::Field::transforms_
std::vector< Transform * > transforms_
Definition: Ioss_Field.h:162
Ioss::Field::index_
size_t index_
Definition: Ioss_Field.h:154
Ioss::Field::has_transform
bool has_transform() const
Definition: Ioss_Field.h:146
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(unsigned int)
Definition: Ioss_Field.h:41
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(Complex)
Definition: Ioss_Field.h:44
Ioss::Field::reset_type
void reset_type(BasicType new_type)
Definition: Ioss_Field.C:175
Ioss::Field::get_type
BasicType get_type() const
Get the basic data type of the data held in the field.
Definition: Ioss_Field.h:111
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(char)
Definition: Ioss_Field.h:38
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:40
Ioss::Field::STRING
@ STRING
Definition: Ioss_Field.h:34
Ioss::Field::CHARACTER
@ CHARACTER
Definition: Ioss_Field.h:35
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(uint64_t)
Definition: Ioss_Field.h:43
Ioss::Field::INTERNAL
@ INTERNAL
Definition: Ioss_Field.h:50
Ioss::Field::INVALID
@ INVALID
Definition: Ioss_Field.h:27
Ioss::Field::check_type
void check_type(BasicType the_type) const
Definition: Ioss_Field.C:149
Ioss::Field::size_
size_t size_
Definition: Ioss_Field.h:153
Ioss::Field::COMPLEX
@ COMPLEX
Definition: Ioss_Field.h:33
Ioss::Field::operator<
bool operator<(const Field &other) const
Ioss::Field::type_
BasicType type_
Definition: Ioss_Field.h:156
Ioss::Field::transform
bool transform(void *data)
Definition: Ioss_Field.C:228
Ioss::Field::transCount_
size_t transCount_
Definition: Ioss_Field.h:152
Ioss::Field::INT64
@ INT64
Definition: Ioss_Field.h:32
Ioss::Field::role_
RoleType role_
Definition: Ioss_Field.h:157
Ioss::Field::MESH_REDUCTION
@ MESH_REDUCTION
Definition: Ioss_Field.h:60
Ioss::Field::set_index
void set_index(size_t index) const
Definition: Ioss_Field.h:128
Ioss::Field::COMMUNICATION
@ COMMUNICATION
Definition: Ioss_Field.h:59
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(int64_t)
Definition: Ioss_Field.h:42
Ioss::Field::is_valid
bool is_valid() const
Definition: Ioss_Field.h:102
Ioss::Field::is_invalid
bool is_invalid() const
Definition: Ioss_Field.h:103
Ioss::Field::reset_count
void reset_count(size_t new_count)
Definition: Ioss_Field.C:166
Ioss::Field::~Field
~Field()
Ioss::Field::MESH
@ MESH
Definition: Ioss_Field.h:51
Ioss::Field::raw_count
size_t raw_count() const
Definition: Ioss_Field.h:116
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(std::string)
Definition: Ioss_Field.h:45
Ioss::Field::REAL
@ REAL
Definition: Ioss_Field.h:28
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(int)
Definition: Ioss_Field.h:40
Ioss::Field::rawStorage_
const VariableType * rawStorage_
Definition: Ioss_Field.h:159
Ioss::Field::INT32
@ INT32
Definition: Ioss_Field.h:31
Ioss::Field::Field
Field(const Field &)
Ioss::Field::get_index
size_t get_index() const
Definition: Ioss_Field.h:127
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:48
Ioss::Field::get_name
const std::string & get_name() const
Definition: Ioss_Field.h:105
Ioss::Field::transformed_storage
const VariableType * transformed_storage() const
Definition: Ioss_Field.h:114
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(double)
Definition: Ioss_Field.h:39
Ioss::Field::transStorage_
const VariableType * transStorage_
Definition: Ioss_Field.h:160
Ioss::Field::raw_storage
const VariableType * raw_storage() const
Definition: Ioss_Field.h:113
Ioss::Field::verify
size_t verify(size_t data_size) const
Definition: Ioss_Field.C:133
Ioss::Field::TRANSIENT
@ TRANSIENT
Definition: Ioss_Field.h:72
Ioss::Field::name_
std::string name_
Definition: Ioss_Field.h:149
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:125
Ioss::Field::BasicType
BasicType
The basic data type held in the field.
Definition: Ioss_Field.h:26
Ioss::Field::rawCount_
size_t rawCount_
Definition: Ioss_Field.h:151
Ioss::Field::RoleType
RoleType
Definition: Ioss_Field.h:49
anonymous_namespace{io_info.C}::name
std::string name(const Ioss::GroupingEntity *entity)
Definition: io_info.C:65
Ioss::Field::INFORMATION
@ INFORMATION
Definition: Ioss_Field.h:65
Ioss::Field::add_transform
bool add_transform(Transform *my_transform)
Definition: Ioss_Field.C:202
Ioss_CodeTypes.h
Ioss::Field::DOUBLE
@ DOUBLE
Definition: Ioss_Field.h:29
Ioss::Field::ATTRIBUTE
@ ATTRIBUTE
Definition: Ioss_Field.h:55