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,
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 {
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. */
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  // Create a field from another field.
115  Field(const Field & /*from*/);
116  Field &operator=(const Field & /*from*/);
117 
118  // Compare two fields (used for STL container)
119  bool operator<(const Field &other) const;
120 
121  ~Field();
122 
123  bool is_valid() const { return type_ != INVALID; }
124  bool is_invalid() const { return type_ == INVALID; }
125 
126  const std::string &get_name() const { return name_; }
127 
128  /** \brief Get the basic data type of the data held in the field.
129  *
130  * \returns the basic data type of the data held in the field.
131  */
132  BasicType get_type() const { return type_; }
133 
134  const VariableType *raw_storage() const { return rawStorage_; }
135  const VariableType *transformed_storage() const { return transStorage_; }
136 
137  size_t raw_count() const { return rawCount_; } // Number of items in field
138  size_t transformed_count() const { return transCount_; } // Number of items in field
139 
140  size_t get_size() const; // data size (in bytes) required to hold entire field
141 
142  /** \brief Get the role (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.) of the data in the field.
143  *
144  * \returns The RoleType of the data in the field.
145  */
146  RoleType get_role() const { return role_; }
147 
148  size_t get_index() const { return index_; }
149  void set_index(size_t index) const { index_ = index; }
150 
151  void reset_count(size_t new_count); // new number of items in field
152  void reset_type(BasicType new_type); // new type of items in field.
153 
154  // Verify that data_size is valid. Return value is the maximum
155  // number of entities to get ('RawCount')
156  // Throws runtime error if data_size too small.
157  size_t verify(size_t data_size) const;
158 
159  // Verify that the type 'the_type' matches the field's type.
160  // throws exception if the types don't match.
161  void check_type(BasicType the_type) const;
162 
163  bool is_type(BasicType the_type) const { return the_type == type_; }
164 
165  bool add_transform(Transform *my_transform);
166  bool transform(void *data);
167  bool has_transform() const { return !transforms_.empty(); }
168 
169  private:
170  std::string name_;
171 
172  size_t rawCount_{}; // Count of items in field before transformation
173  size_t transCount_{}; // Count of items in field after transformed
174  size_t size_{}; // maximum data size (in bytes) required to hold entire field
175  mutable size_t index_{}; // Optional flag that can be used by a client to indicate an ordering.
176  // Unused by field itself.
179 
180  const VariableType *rawStorage_{}; // Storage type of raw field
181  const VariableType *transStorage_{}; // Storage type after transformation
182 
183  std::vector<Transform *> transforms_;
184  };
185 } // namespace Ioss
186 #endif
Ioss::Field::is_type
bool is_type(BasicType the_type) const
Definition: Ioss_Field.h:163
Ioss::Field::get_size
size_t get_size() const
Definition: Ioss_Field.C:208
Ioss::Field::REDUCTION
Definition: Ioss_Field.h:87
Ioss::Field::INTEGER
Definition: Ioss_Field.h:56
Complex
std::complex< double > Complex
Definition: Ioss_CodeTypes.h:115
Ioss::Field::Field
Field()
Create an empty field.
Definition: Ioss_Field.C:77
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Ioss::VariableType
A generic variable type.
Definition: Ioss_VariableType.h:86
Ioss::Transform
Definition: Ioss_Transform.h:46
Ioss::Field::transformed_count
size_t transformed_count() const
Definition: Ioss_Field.h:138
Ioss::Field::operator=
Field & operator=(const Field &)
Ioss::Field::transforms_
std::vector< Transform * > transforms_
Definition: Ioss_Field.h:183
Ioss::Field::index_
size_t index_
Definition: Ioss_Field.h:175
Ioss::Field::has_transform
bool has_transform() const
Definition: Ioss_Field.h:167
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(unsigned int)
Definition: Ioss_Field.h:67
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(Complex)
Definition: Ioss_Field.h:70
Ioss::Field::reset_type
void reset_type(BasicType new_type)
Definition: Ioss_Field.C:201
Ioss::Field::get_type
BasicType get_type() const
Get the basic data type of the data held in the field.
Definition: Ioss_Field.h:132
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(char)
Definition: Ioss_Field.h:64
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Ioss::Field::STRING
Definition: Ioss_Field.h:60
Ioss::Field::CHARACTER
Definition: Ioss_Field.h:61
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(uint64_t)
Definition: Ioss_Field.h:69
Ioss::Field::INTERNAL
Definition: Ioss_Field.h:76
Ioss::Field::INVALID
Definition: Ioss_Field.h:53
Ioss::Field::check_type
void check_type(BasicType the_type) const
Definition: Ioss_Field.C:175
Ioss::Field::size_
size_t size_
Definition: Ioss_Field.h:174
Ioss::Field::COMPLEX
Definition: Ioss_Field.h:59
Ioss::Field::operator<
bool operator<(const Field &other) const
Ioss::Field::type_
BasicType type_
Definition: Ioss_Field.h:177
Ioss::Field::transform
bool transform(void *data)
Definition: Ioss_Field.C:254
Ioss::Field::transCount_
size_t transCount_
Definition: Ioss_Field.h:173
Ioss::Field::INT64
Definition: Ioss_Field.h:58
Ioss::Field::role_
RoleType role_
Definition: Ioss_Field.h:178
Ioss::Field::set_index
void set_index(size_t index) const
Definition: Ioss_Field.h:149
Ioss::Field::COMMUNICATION
Definition: Ioss_Field.h:85
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(int64_t)
Definition: Ioss_Field.h:68
Ioss::Field::is_valid
bool is_valid() const
Definition: Ioss_Field.h:123
Ioss::Field::is_invalid
bool is_invalid() const
Definition: Ioss_Field.h:124
Ioss::Field::reset_count
void reset_count(size_t new_count)
Definition: Ioss_Field.C:192
Ioss::Field::~Field
~Field()
Ioss::Field::MESH
Definition: Ioss_Field.h:77
Ioss::Field::raw_count
size_t raw_count() const
Definition: Ioss_Field.h:137
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(std::string)
Definition: Ioss_Field.h:71
Ioss::Field::REAL
Definition: Ioss_Field.h:54
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(int)
Definition: Ioss_Field.h:66
Ioss::Field::rawStorage_
const VariableType * rawStorage_
Definition: Ioss_Field.h:180
Ioss::Field::INT32
Definition: Ioss_Field.h:57
Ioss::Field::get_index
size_t get_index() const
Definition: Ioss_Field.h:148
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:74
Ioss::Field::get_name
const std::string & get_name() const
Definition: Ioss_Field.h:126
Ioss::Field::transformed_storage
const VariableType * transformed_storage() const
Definition: Ioss_Field.h:135
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(double)
Definition: Ioss_Field.h:65
Ioss::Field::transStorage_
const VariableType * transStorage_
Definition: Ioss_Field.h:181
Ioss::Field::raw_storage
const VariableType * raw_storage() const
Definition: Ioss_Field.h:134
Ioss::Field::verify
size_t verify(size_t data_size) const
Definition: Ioss_Field.C:159
Ioss::Field::TRANSIENT
Definition: Ioss_Field.h:93
Ioss::Field::name_
std::string name_
Definition: Ioss_Field.h:170
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:146
Ioss::Field::BasicType
BasicType
The basic data type held in the field.
Definition: Ioss_Field.h:52
Ioss::Field::rawCount_
size_t rawCount_
Definition: Ioss_Field.h:172
Ioss::Field::RoleType
RoleType
Definition: Ioss_Field.h:75
anonymous_namespace{io_info.C}::name
std::string name(const Ioss::GroupingEntity *entity)
Definition: io_info.C:89
Ioss::Field::INFORMATION
Definition: Ioss_Field.h:86
Ioss::Field::add_transform
bool add_transform(Transform *my_transform)
Definition: Ioss_Field.C:228
Ioss_CodeTypes.h
Ioss::Field::DOUBLE
Definition: Ioss_Field.h:55
Ioss::Field::ATTRIBUTE
Definition: Ioss_Field.h:81