IOSS 2.0

Ioss_GroupingEntity.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_GroupingEntity_h
34 #define IOSS_Ioss_GroupingEntity_h
35
36 #include <Ioss_CodeTypes.h> // for Complex
37 #include <Ioss_DatabaseIO.h> // for DatabaseIO
38 #include <Ioss_EntityType.h> // for EntityType
39 #include <Ioss_Field.h> // for Field, Field::RoleType, etc
40 #include <Ioss_FieldManager.h> // for FieldManager, NameList
41 #include <Ioss_Property.h> // for Property
42 #include <Ioss_PropertyManager.h> // for PropertyManager
43 #include <Ioss_State.h> // for State
44 #include <Ioss_VariableType.h> // for component_count()
45 #include <cstddef> // for size_t, nullptr
46 #include <cstdint> // for int64_t
47 #include <string> // for string
48 #include <vector> // for vector
49
50 #ifdef SEACAS_HAVE_KOKKOS
51 #include <Kokkos_Core.hpp> // for Kokkos::View
52 #endif
53
54 namespace Ioss {
55
56 class EntityBlock;
57
58 /** \brief Base class for all 'grouping' entities.
59 * The following derived classes are typical:
60 *
61 * -- NodeSet -- grouping of nodes (0d topology)
62 *
63 * -- EdgeSet -- grouping of edges (1d topology)
64 *
65 * -- FaceSet -- grouping of faces (2d topology) [Surface]
66 *
67 * Similarly, there is:
68 *
69 * -- NodeBlock -- grouping of 'similar' nodes (same degree of freedom, ...)
70 *
71 * -- ElementBlock -- grouping of 'similar' elements (same element topology,
72 * attributes, ...)
73 * 0d, 1d, 2d, 3d topology possible -- e.g., sphere, bar, quad, hex
74 *
75 * A Region is also a grouping entity, except that its list of subentites
76 * are other GroupingEntities. That is, it maintains a list of NodeBlocks,
77 * ElementBlocks, NodeLists, CommLists and Surfaces. [Similar to the
78 * "Composite Patter" in Design Patterns] All interface to GroupingEntities
79 * is through the Region class; clients of the IO subsystem have no direct
80 * access to the underlying GroupingEntities (other than the Region).
81 *
82 * Each GroupingEntity contains:
83 *
84 * -- name
85 *
86 * -- MeshEntities of the specified topological dimension
87 *
88 * -- Optional attributes, either global (applied to the groupingentity), or
89 * unique value(s) to be applied to each subentity.
90 *
91 * -- Data items
92 */
93 class GroupingEntity
94 {
95 public:
96 friend class Property;
97
98 GroupingEntity() = default;
99 GroupingEntity(DatabaseIO *io_database, const std::string &my_name, int64_t entity_count);
100 GroupingEntity(const GroupingEntity &) = delete;
101 GroupingEntity &operator=(const GroupingEntity &) = delete;
102
103 virtual ~GroupingEntity();
104
105 State get_state() const;
106
107 DatabaseIO * get_database() const;
108 void set_database(DatabaseIO *io_database);
109 virtual void delete_database();
110
111 /** \brief Get name of entity.
112 *
113 * This short-circuits the process of getting the name via the property.
114 * \returns The same information as: entity->get_property("name").get_string()
115 */
116 const std::string &name() const { return entityName; }
117
118 /** \brief Set the name of the entity.
119 *
120 * \param[in] new_name The new name of the entity.
121 */
122 void set_name(const std::string &new_name) { entityName = new_name; }
123
124 /** \brief Get a generated name based on the type of the entity and the id.
125 *
126 * For example, element block 10 would return "block_10"
127 * This is the default name if no name is assigned in the mesh database.
128 * \returns The generic name.
129 */
130 std::string generic_name() const;
131
132 /** Determine whether a name is an alias for this entity.
133 *
134 * \param[in] my_name Determine whether this name is an alias for this entity.
135 * \returns True if input name is an alias for this entity.
136 */
137 bool is_alias(const std::string &my_name) const;
138
139 /** \brief Get list of blocks that the entities in this GroupingEntity "touch".
140 *
141 * \param[out] block_members The blocks that the entities touch.
142 *
143 * For a SideSet, returns a list of the element blocks that the
144 * elements in the set belong to.
145 * For others, it returns an empty vector.
146 * Entries are pushed onto the "block_members" vector, so it will be
147 * appended to if it is not empty at entry to the function.
148 */
149 virtual void block_membership(std::vector<std::string> &block_members) {}
150
151 std::string get_filename() const;
152
153 /** \brief Get the name of the particular type of entity.
154 *
155 * \returns The name of the particular type of entity.
156 */
157 virtual std::string type_string() const = 0;
158
159 /** \brief Get a short name of the particular type of entity.
160 *
161 * \returns The short name of the particular type of entity.
162 */
163 virtual std::string short_type_string() const = 0;
164
165 /** \brief Get the EntityType, which indicates the particular type of GroupingEntity this is.
166 *
167 * \returns The particular EntityType of this GroupingEntity.
168 */
169 virtual EntityType type() const = 0;
170
171 // ========================================================================
172 // PROPERTIES
173 // ========================================================================
174 // Property-related information....
175 // Just forward it through to the property manager...
176 void property_add(const Property &new_prop);
177 void property_erase(const std::string &property_name);
178 bool property_exists(const std::string &property_name) const;
179 Property get_property(const std::string &property_name) const;
180 int property_describe(NameList *names) const;
181 size_t property_count() const;
182 /** Add a property, or change its value if it already exists with
183 a different value */
184 void property_update(const std::string &property, int64_t value) const;
185 void property_update(const std::string &property, const std::string &value) const;
186
187 // ========================================================================
188 // FIELDS
189 // ========================================================================
190 // Just forward these through to the field manager...
191 void field_add(const Field &new_field);
192 void field_erase(const std::string &field_name);
193 bool field_exists(const std::string &field_name) const;
194 Field get_field(const std::string &field_name) const;
195 const Field &get_fieldref(const std::string &field_name) const;
196 int field_describe(NameList *names) const;
197 int field_describe(Field::RoleType role, NameList *names) const;
198 size_t field_count() const;
199 size_t field_count(Field::RoleType role) const;
200
201 // Put this fields data into 'data'.
202 // Returns number of entities for which the field was read.
203 // Assumes 'data' is large enough to hold all values.
204 int get_field_data(const std::string &field_name, void *data, size_t data_size) const;
205
206 int put_field_data(const std::string &field_name, void *data, size_t data_size) const;
207
208 // Put this fields data into the specified std::vector space.
209 // Returns number of entities for which the field was read.
210 // Resizes 'data' to size needed to hold all values.
211 template <typename T>
212 int get_field_data(const std::string &field_name, std::vector<T> &data) const;
213
214 template <typename T>
215 int put_field_data(const std::string &field_name, const std::vector<T> &data) const;
216 template <typename T>
217 int put_field_data(const std::string &field_name, std::vector<T> &data) const;
218
219 #ifdef SEACAS_HAVE_KOKKOS
220 // Get and put this field's data into the specified Kokkos::View.
221 // Returns the number of entities for which the field was read.
222 // Resizes 'data' to size needed to hold all values;
223 // however, any Views that were previously created referencing the same
224 // underlying memory allocation as 'data' will remain the original size.
225 template <typename T, typename... Args>
226 int get_field_data(const std::string &field_name, Kokkos::View<T *, Args...> &data) const;
227
228 template <typename T, typename... Args>
229 int get_field_data(const std::string &field_name, Kokkos::View<T **, Args...> &data) const;
230
231 template <typename T, typename... Args>
232 int put_field_data(const std::string &field_name, Kokkos::View<T *, Args...> &data) const;
233
234 template <typename T, typename... Args>
235 int put_field_data(const std::string &field_name, Kokkos::View<T **, Args...> &data) const;
236 #endif
237
238 /** Get the number of bytes used to store the INT data type
239 *
240 * \returns The number of bytes.
241 */
242 Ioss::Field::BasicType field_int_type() const
243 {
244 if (database_ == nullptr || get_database()->int_byte_size_api() == 4) {
245 return Ioss::Field::INT32;
246 }
247
248 return Ioss::Field::INT64;
249 }
250
251 unsigned int hash() const { return hash_; }
252
253 int64_t entity_count() const { return get_property("entity_count").get_int(); }
254
255 protected:
256 void count_attributes() const;
257
258 bool set_state(State new_state)
259 {
260 entityState = new_state;
261 return true;
262 }
263
264 // Protected to give access to Region which is the only
265 // class that should delete the database. May have to make
266 // private and provide friend...
267 void really_delete_database();
268
269 // Handle implicit properties -- These are calcuated from data stored
270 // in the grouping entity instead of having an explicit value assigned.
271 // An example would be 'element_block_count' for a region.
272 // Note that even though this is a pure virtual function, an implementation
273 // is provided to return properties that are common to all grouping entities.
274 // Derived classes should call 'GroupingEntity::get_implicit_property'
275 // if the requested property is not specific to their type.
276 virtual Property get_implicit_property(const std::string &my_name) const = 0;
277
278 PropertyManager properties;
279 FieldManager fields;
280
281 virtual int64_t internal_get_field_data(const Field &field, void *data,
282 size_t data_size = 0) const = 0;
283 virtual int64_t internal_put_field_data(const Field &field, void *data,
284 size_t data_size = 0) const = 0;
285
286 int64_t entityCount = 0;
287
288 #if defined(IOSS_THREADSAFE)
289 mutable std::mutex m_;
290 #endif
291
292 private:
293 void verify_field_exists(const std::string &field_name, const std::string &inout) const;
294
295 std::string entityName;
296
297 DatabaseIO *database_ = nullptr;
298
299 mutable int64_t attributeCount = 0;
300 State entityState = STATE_CLOSED;
301 unsigned int hash_ = 0;
302 };
303 } // namespace Ioss
304
305 /** \brief Add a property to the entity's property manager.
306 *
307 * \param[in] new_prop The property to add.
308 */
309 inline void Ioss::GroupingEntity::property_add(const Ioss::Property &new_prop)
310 {
311 properties.add(new_prop);
312 }
313
314 /** \brief Remove a property from the entity's property manager.
315 *
316 * Assumes that the property with the given name already exists in the property manager.
317 *
318 * \param[in] property_name The name of the property to remove.
319 *
320 */
321 inline void Ioss::GroupingEntity::property_erase(const std::string &property_name)
322 {
323 properties.erase(property_name);
324 }
325
326 /** \brief Checks if a property exists in the entity's property manager.
327 *
328 * \param[in] property_name The property to check
329 * \returns True if the property exists.
330 */
331 inline bool Ioss::GroupingEntity::property_exists(const std::string &property_name) const
332 {
333 return properties.exists(property_name);
334 }
335
336 /** \brief Get the Property from the property manager associated with the entity.
337 *
338 * \param[in] property_name The name of the property to get
339 * \returns The property
340 *
341 */
342 inline Ioss::Property Ioss::GroupingEntity::get_property(const std::string &property_name) const
343 {
344 return properties.get(property_name);
345 }
346
347 /** \brief Get the names of all properties in the property manager for this entity.
348 *
349 * \param[out] names All the property names in the property manager.
350 * \returns The number of properties extracted from the property manager.
351 */
352 inline int Ioss::GroupingEntity::property_describe(NameList *names) const
353 {
354 return properties.describe(names);
355 }
356
357 /** \brief Get the number of properties defined in the property manager for this entity.
358 *
359 * \returns The number of properties.
360 */
361 inline size_t Ioss::GroupingEntity::property_count() const { return properties.count(); }
362
363 // ------------------------------------------------------------------------
364
365 /** \brief Remove a field from the entity's field manager.
366 *
367 * Assumes that a field with the given name exists in the field manager.
368 *
369 * \param[in] field_name The name of the field to remove.
370 */
371 inline void Ioss::GroupingEntity::field_erase(const std::string &field_name)
372 {
373 fields.erase(field_name);
374 }
375
376 /** \brief Checks if a field with a given name exists in the entity's field manager.
377 *
378 * \param[in] field_name The name of the field to check for.
379 * \returns True if the field exists in the entity's field manager.
380 *
381 */
382 inline bool Ioss::GroupingEntity::field_exists(const std::string &field_name) const
383 {
384 return fields.exists(field_name);
385 }
386
387 /** \brief Get a field from the entity's field manager.
388 *
389 * \param[in] field_name The name of the field to get.
390 * \returns The field object.
391 *
392 */
393 inline Ioss::Field Ioss::GroupingEntity::get_field(const std::string &field_name) const
394 {
395 return fields.get(field_name);
396 }
397
398 /** \brief Get a reference to a field from the entity's field manager.
399 *
400 * \param[in] field_name The name of the field to get.
401 * \returns A reference to the field object.
402 *
403 */
404 inline const Ioss::Field &Ioss::GroupingEntity::get_fieldref(const std::string &field_name) const
405 {
406 return fields.getref(field_name);
407 }
408
409 /** \brief Get the names of all fields in the entity's field manager.
410 *
411 * \param[out] names All field names in the entity's field manager.
412 * \returns The number of fields extracted from the entity's field manager.
413 *
414 */
415 inline int Ioss::GroupingEntity::field_describe(NameList *names) const
416 {
417 return fields.describe(names);
418 }
419
420 /** \brief Get the names of all fields of a specified RoleType in the entity's field manager.
421 *
422 * \param[in] role The role type (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.)
423 * \param[out] names All field names of the specified RoleType in the entity's field manager.
424 * \returns The number of fields extracted from the entity's field manager.
425 *
426 */
427 inline int Ioss::GroupingEntity::field_describe(Ioss::Field::RoleType role, NameList *names) const
428 {
429 return fields.describe(role, names);
430 }
431
432 /** \brief Get the number of fields in the entity's field manager.
433 *
434 * \returns The number of fields in the entity's field manager.
435 */
436 inline size_t Ioss::GroupingEntity::field_count() const { return fields.count(); }
437
438 /** \brief Read type 'T' field data from the database file into memory using a std::vector.
439 *
440 * \param[in] field_name The name of the field to read.
441 * \param[out] data The data.
442 * \returns The number of values read.
443 *
444 */
445 template <typename T>
446 int Ioss::GroupingEntity::get_field_data(const std::string &field_name, std::vector<T> &data) const
447 {
448 verify_field_exists(field_name, "input");
449
450 Ioss::Field field = get_field(field_name);
451 field.check_type(Ioss::Field::get_field_type(T(0)));
452
453 data.resize(field.raw_count() * field.raw_storage()->component_count());
454 size_t data_size = data.size() * sizeof(T);
455 int retval = internal_get_field_data(field, TOPTR(data), data_size);
456
457 // At this point, transform the field if specified...
458 if (retval >= 0) {
459 field.transform(TOPTR(data));
460 }
461
462 return retval;
463 }
464
465 /** \brief Write type 'T' field data from memory into the database file using a std::vector.
466 *
467 * \param[in] field_name The name of the field to write.
468 * \param[in] data The data.
469 * \returns The number of values written.
470 *
471 */
472 template <typename T>
473 int Ioss::GroupingEntity::put_field_data(const std::string & field_name,
474 const std::vector<T> &data) const
475 {
476 verify_field_exists(field_name, "output");
477
478 Ioss::Field field = get_field(field_name);
479 field.check_type(Ioss::Field::get_field_type(T(0)));
480 size_t data_size = data.size() * sizeof(T);
481 if (field.has_transform()) {
482 // Need non-const data since the transform will change the users data.
483 std::vector<T> nc_data(data);
484 field.transform(nc_data.data());
485 return internal_put_field_data(field, nc_data.data(), data_size);
486 }
487
488 T *my_data = const_cast<T *>(data.data());
489 return internal_put_field_data(field, my_data, data_size);
490 }
491
492 template <typename T>
493 int Ioss::GroupingEntity::put_field_data(const std::string &field_name, std::vector<T> &data) const
494 {
495 verify_field_exists(field_name, "output");
496
497 Ioss::Field field = get_field(field_name);
498 field.check_type(Ioss::Field::get_field_type(T(0)));
499 size_t data_size = data.size() * sizeof(T);
500 T * my_data = const_cast<T *>(data.data());
501 field.transform(my_data);
502 return internal_put_field_data(field, my_data, data_size);
503 }
504
505 #ifdef SEACAS_HAVE_KOKKOS
506
507 /** \brief Read field data from the database file into memory using a 1-D Kokkos:::View.
508 *
509 * \tparam T The data type.
510 * \tparam Args The other template arguments for data.
511 * \param[in] field_name The name of the field to read.
512 * \param[out] data The data.
513 * \returns The number of values read.
514 *
515 */
516 template <typename T, typename... Args>
517 int Ioss::GroupingEntity::get_field_data(const std::string & field_name,
518 Kokkos::View<T *, Args...> &data) const
519 {
520 typedef Kokkos::View<T *, Args...> ViewType;
521
522 verify_field_exists(field_name, "input");
523
524 Ioss::Field field = get_field(field_name);
525
526 // Resize the view
527 int new_view_size = field.raw_count() * field.raw_storage()->component_count();
528 Kokkos::resize(data, new_view_size);
529 size_t data_size = new_view_size * sizeof(T);
530
531 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
532 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
533
534 // Extract a pointer to the underlying allocated memory of the host view.
535 // Kokkos::View::ptr_on_device() will soon be changed to Kokkos::View::data(),
536 // in which case, TOPTR(data) will work.
537 T *host_data_ptr = host_data.ptr_on_device();
538
539 // Extract the data from disk to the underlying memory pointed to by host_data_ptr.
540 int retval = internal_get_field_data(field, host_data_ptr, data_size);
541
542 // At this point, transform the field if specified...
543 if (retval >= 0)
544 field.transform(host_data_ptr);
545
546 // Copy the data to the device. (No op if data is in HostSpace.)
547 Kokkos::deep_copy(data, host_data);
548
549 return retval;
550 }
551
552 /** \brief Read field data from the database file into memory using a 2-D Kokkos:::View.
553 *
554 * \tparam T The data type
555 * \tparam Args The other template arguments for data.
556 * \param[in] field_name The name of the field to read.
557 * \param[out] data The data.
558 * \returns The number of values read.
559 *
560 */
561 template <typename T, typename... Args>
562 int Ioss::GroupingEntity::get_field_data(const std::string & field_name,
563 Kokkos::View<T **, Args...> &data) const
564 {
565 typedef Kokkos::View<T **, Args...> ViewType;
566
567 verify_field_exists(field_name, "input");
568
569 Ioss::Field field = get_field(field_name);
570
571 // Resize the view
572 int new_view_size_left = field.raw_count();
573 int new_view_size_right = field.raw_storage()->component_count();
574 Kokkos::resize(data, new_view_size_left, new_view_size_right);
575 size_t data_size = new_view_size_left * new_view_size_right * sizeof(T);
576
577 // Create and allocate an array to hold the data temporarily.
578 // This is necessary to ensure the data is placed in the correct
579 // location in the 2-D array, avoiding incorrect placement due
580 // to Views with padded dimensions.
581 T *data_array = new T[data_size];
582
583 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
584 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
585
586 // Extract the data from disk to the underlying memory pointed to by host_data_ptr.
587 int retval = internal_get_field_data(field, data_array, data_size);
588
589 // At this point, transform the field if specified...
590 if (retval >= 0)
591 field.transform(data_array);
592
593 // Copy the data to the host Mirror view.
594 // The host mirror view has the same layout as the device view.
595 // For CUDA, this will be LayoutLeft. In this case, the loop order
596 // chosen here will be slower than the reversed loop order.
597 // However, The time for this extra in-memory copy is small
598 // compared with the time to copy from disk into memory.
599 for (int i = 0; i < new_view_size_left; ++i) {
600 for (int j = 0; j < new_view_size_right; ++j) {
601 host_data(i, j) = data_array[new_view_size_right * i + j];
602 }
603 }
604
605 // Delete the temporary array
606 delete[] data_array;
607
608 // Copy the data to the device. (No op if data is in HostSpace.)
609 Kokkos::deep_copy(data, host_data);
610
611 return retval;
612 }
613
614 /** \brief Write field data from memory into the database file using a 1-D Kokkos::View.
615 *
616 * \tparam T The data type
617 * \tparam Args The other template arguments for data.
618 * \param[in] field_name The name of the field to write.
619 * \param[in] data The data.
620 * \returns The number of values written.
621 *
622 */
623 template <typename T, typename... Args>
624 int Ioss::GroupingEntity::put_field_data(const std::string & field_name,
625 Kokkos::View<T *, Args...> &data) const
626 {
627 typedef Kokkos::View<T *, Args...> ViewType;
628
629 verify_field_exists(field_name, "output");
630
631 Ioss::Field field = get_field(field_name);
632 size_t data_size = field.raw_count() * field.raw_storage()->component_count() * sizeof(T);
633
634 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
635 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
636
637 // Copy the data to the host. (No op if data is in HostSpace.)
638 Kokkos::deep_copy(host_data, data);
639
640 // Extract a pointer to the underlying allocated memory of the host view.
641 // Kokkos::View::ptr_on_device() will soon be changed to Kokkos::View::data(),
642 // in which case, TOPTR(data) will work.
643 T *host_data_ptr = host_data.ptr_on_device();
644
645 // Transform the field
646 field.transform(host_data_ptr);
647
648 // Copy the data to disk from the underlying memory pointed to by host_data_ptr.
649 return internal_put_field_data(field, host_data_ptr, data_size);
650 }
651
652 /** \brief Write field data from memory into the database file using a 2-D Kokkos::View.
653 *
654 * \tparam T The data type
655 * \tparam Args The other template arguments for data.
656 * \param[in] field_name The name of the field to write.
657 * \param[in] data The data.
658 * \returns The number of values written.
659 *
660 */
661 template <typename T, typename... Args>
662 int Ioss::GroupingEntity::put_field_data(const std::string & field_name,
663 Kokkos::View<T **, Args...> &data) const
664 {
665 typedef Kokkos::View<T **, Args...> ViewType;
666
667 verify_field_exists(field_name, "output");
668
669 Ioss::Field field = get_field(field_name);
670
671 int view_size_left = data.extent(0);
672 int view_size_right = data.extent(1);
673 size_t data_size = field.raw_count() * field.raw_storage()->component_count() * sizeof(T);
674
675 if (view_size_left * view_size_right * sizeof(T) != data_size) {
676 std::ostringstream errmsg;
677 errmsg << "\nERROR: View dimensions are inconsistent with field raw count or raw storage "
678 "component count"
679 << "for field" << field_name << "\n\n";
680 IOSS_ERROR(errmsg);
681 }
682
683 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
684 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
685
686 // Copy the data to the host. (No op if data is in HostSpace.)
687 Kokkos::deep_copy(host_data, data);
688
689 // Create and allocate an array to hold the data temporarily.
690 // This is necessary to ensure the data is taken from the correct
691 // location in the 2-D array, avoiding incorrect location due
692 // to Views with padded dimensions.
693 T *data_array = new T[data_size];
694
695 // Copy the data from the host Mirror view.
696 // The host mirror view has the same layout as the device view.
697 // For CUDA, this will be LayoutLeft. In this case, the loop order
698 // chosen here will be slower than the reversed loop order.
699 // However, The time for this extra in-memory copy is small
700 // compared with the time to copy to disk from memory.
701 for (int i = 0; i < view_size_left; ++i) {
702 for (int j = 0; j < view_size_right; ++j) {
703 data_array[view_size_right * i + j] = host_data(i, j);
704 }
705 }
706
707 // Transform the field
708 field.transform(data_array);
709
710 // Copy the data to disk from the underlying memory pointed to by data_array.
711 int retval = internal_put_field_data(field, data_array, data_size);
712
713 // Delete the temporary array
714 delete[] data_array;
715
716 return retval;
717 }
718 #endif
719
720 #endif
Ioss::GroupingEntity::set_name
void set_name(const std::string &new_name)
Set the name of the entity.
Definition: Ioss_GroupingEntity.h:122
Ioss::GroupingEntity::entityName
std::string entityName
Definition: Ioss_GroupingEntity.h:295
Ioss::NameList
std::vector< std::string > NameList
Definition: Ioss_CodeTypes.h:44
Ioss_CodeTypes.h
Ioss::Property
A named value that has a known type.
Definition: Ioss_Property.h:47
Ioss::PropertyManager::describe
int describe(NameList *names) const
Get the names of all properties in the property manager.
Definition: Ioss_PropertyManager.C:121
Ioss::GroupingEntity::get_field
Field get_field(const std::string &field_name) const
Get a field from the entity&#39;s field manager.
Definition: Ioss_GroupingEntity.h:393
Ioss::FieldManager::erase
void erase(const std::string &field_name)
Remove a field from the field manager.
Definition: Ioss_FieldManager.C:106
Ioss::GroupingEntity::verify_field_exists
void verify_field_exists(const std::string &field_name, const std::string &inout) const
Definition: Ioss_GroupingEntity.C:286
Ioss::PropertyManager::get
Property get(const std::string &property_name) const
Get a property object from the property manager.
Definition: Ioss_PropertyManager.C:88
Ioss::GroupingEntity::attributeCount
int64_t attributeCount
Definition: Ioss_GroupingEntity.h:299
Ioss_Property.h
Ioss::GroupingEntity::property_count
size_t property_count() const
Get the number of properties defined in the property manager for this entity.
Definition: Ioss_GroupingEntity.h:361
Ioss
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:80
Ioss::PropertyManager::exists
bool exists(const std::string &property_name) const
Checks if a property exists in the database.
Definition: Ioss_PropertyManager.C:77
Ioss::GroupingEntity::type_string
virtual std::string type_string() const =0
Get the name of the particular type of entity.
Ioss::GroupingEntity::~GroupingEntity
virtual ~GroupingEntity()
Definition: Ioss_GroupingEntity.C:79
Ioss::GroupingEntity::get_filename
std::string get_filename() const
Get the file name associated with the database containing this entity.
Definition: Ioss_GroupingEntity.C:121
Ioss::GroupingEntity::property_describe
int property_describe(NameList *names) const
Get the names of all properties in the property manager for this entity.
Definition: Ioss_GroupingEntity.h:352
Ioss::GroupingEntity::name
const std::string & name() const
Get name of entity.
Definition: Ioss_GroupingEntity.h:116
Ioss::GroupingEntity::property_update
void property_update(const std::string &property, int64_t value) const
Definition: Ioss_GroupingEntity.C:299
Ioss::GroupingEntity::entityCount
int64_t entityCount
Definition: Ioss_GroupingEntity.h:286
Ioss::GroupingEntity::database_
DatabaseIO * database_
Definition: Ioss_GroupingEntity.h:297
Ioss::Property::get_int
int64_t get_int() const
Get the property value if it is of type INTEGER.
Definition: Ioss_Property.C:199
Ioss::GroupingEntity::field_count
size_t field_count() const
Get the number of fields in the entity&#39;s field manager.
Definition: Ioss_GroupingEntity.h:436
Ioss::GroupingEntity
Base class for all &#39;grouping&#39; entities. The following derived classes are typical: ...
Definition: Ioss_GroupingEntity.h:93
Ioss::Field::RoleType
RoleType
Definition: Ioss_Field.h:75
Ioss::FieldManager::getref
const Field & getref(const std::string &field_name) const
Get a reference to a field from the field manager.
Definition: Ioss_FieldManager.C:91
Ioss::Field::check_type
void check_type(BasicType the_type) const
Definition: Ioss_Field.C:172
Ioss::GroupingEntity::property_erase
void property_erase(const std::string &property_name)
Remove a property from the entity&#39;s property manager.
Definition: Ioss_GroupingEntity.h:321
Ioss::Field::INT32
Definition: Ioss_Field.h:57
Ioss::GroupingEntity::GroupingEntity
GroupingEntity()=default
Ioss::GroupingEntity::field_erase
void field_erase(const std::string &field_name)
Remove a field from the entity&#39;s field manager.
Definition: Ioss_GroupingEntity.h:371
Ioss::GroupingEntity::short_type_string
virtual std::string short_type_string() const =0
Get a short name of the particular type of entity.
Ioss_VariableType.h
Ioss::FieldManager::get
Field get(const std::string &field_name) const
Get a field from the field manager.
Definition: Ioss_FieldManager.C:76
Ioss::GroupingEntity::get_property
Property get_property(const std::string &property_name) const
Get the Property from the property manager associated with the entity.
Definition: Ioss_GroupingEntity.h:342
Ioss_PropertyManager.h
Ioss::FieldManager::describe
int describe(NameList *names) const
Get the names of all fields in the field manager.
Definition: Ioss_FieldManager.C:123
Ioss_DatabaseIO.h
Ioss::PropertyManager::erase
void erase(const std::string &property_name)
Remove a property from the property manager.
Definition: Ioss_PropertyManager.C:107
Ioss::State
State
Access states for a database.
Definition: Ioss_State.h:42
Ioss::GroupingEntity::get_field_data
int get_field_data(const std::string &field_name, void *data, size_t data_size) const
Read field data from the database file into memory using a pointer.
Definition: Ioss_GroupingEntity.C:215
Ioss::GroupingEntity::is_alias
bool is_alias(const std::string &my_name) const
Definition: Ioss_GroupingEntity.C:105
Ioss::PropertyManager::add
void add(const Property &new_prop)
Add a property to the property manager.
Definition: Ioss_PropertyManager.C:62
Ioss_State.h
Ioss::GroupingEntity::property_exists
bool property_exists(const std::string &property_name) const
Checks if a property exists in the entity&#39;s property manager.
Definition: Ioss_GroupingEntity.h:331
Ioss::GroupingEntity::internal_get_field_data
virtual int64_t internal_get_field_data(const Field &field, void *data, size_t data_size=0) const =0
Ioss::FieldManager::count
size_t count() const
Get the number of fields in the field manager.
Definition: Ioss_FieldManager.C:164
Ioss::GroupingEntity::get_fieldref
const Field & get_fieldref(const std::string &field_name) const
Get a reference to a field from the entity&#39;s field manager.
Definition: Ioss_GroupingEntity.h:404
Ioss::GroupingEntity::count_attributes
void count_attributes() const
Definition: Ioss_GroupingEntity.C:263
Ioss::GroupingEntity::fields
FieldManager fields
Definition: Ioss_GroupingEntity.h:279
Ioss::PropertyManager::count
size_t count() const
Definition: Ioss_PropertyManager.C:137
Ioss::FieldManager::exists
bool exists(const std::string &field_name) const
Checks if a field with a given name exists in the field manager.
Definition: Ioss_FieldManager.C:63
Ioss::GroupingEntity::really_delete_database
void really_delete_database()
Definition: Ioss_GroupingEntity.C:89
Ioss::GroupingEntity::entity_count
int64_t entity_count() const
Definition: Ioss_GroupingEntity.h:253
Ioss::GroupingEntity::get_state
State get_state() const
Get the current Ioss::State of the entity.
Definition: Ioss_GroupingEntity.C:155
Ioss::STATE_CLOSED
Definition: Ioss_State.h:49
Ioss::GroupingEntity::field_add
void field_add(const Field &new_field)
Add a field to the entity&#39;s field manager.
Definition: Ioss_GroupingEntity.C:189
Ioss::GroupingEntity::operator=
GroupingEntity & operator=(const GroupingEntity &)=delete
Ioss::VariableType::component_count
int component_count() const
Definition: Ioss_VariableType.h:136
Ioss::GroupingEntity::set_state
bool set_state(State new_state)
Definition: Ioss_GroupingEntity.h:258
Ioss::GroupingEntity::property_add
void property_add(const Property &new_prop)
Add a property to the entity&#39;s property manager.
Definition: Ioss_GroupingEntity.h:309
Ioss::GroupingEntity::internal_put_field_data
virtual int64_t internal_put_field_data(const Field &field, void *data, size_t data_size=0) const =0
Ioss::Field::raw_storage
const VariableType * raw_storage() const
Definition: Ioss_Field.h:133
Ioss_Field.h
Ioss::Field::raw_count
size_t raw_count() const
Definition: Ioss_Field.h:136
Ioss::GroupingEntity::block_membership
virtual void block_membership(std::vector< std::string > &block_members)
Get list of blocks that the entities in this GroupingEntity "touch".
Definition: Ioss_GroupingEntity.h:149
Ioss::GroupingEntity::type
virtual EntityType type() const =0
Get the EntityType, which indicates the particular type of GroupingEntity this is.
Ioss::GroupingEntity::get_database
DatabaseIO * get_database() const
Definition: Ioss_GroupingEntity.C:111
Ioss::GroupingEntity::set_database
void set_database(DatabaseIO *io_database)
Definition: Ioss_GroupingEntity.C:131
Ioss::Field::BasicType
BasicType
The basic data type held in the field.
Definition: Ioss_Field.h:52
Ioss::GroupingEntity::entityState
State entityState
Definition: Ioss_GroupingEntity.h:300
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Ioss::GroupingEntity::field_exists
bool field_exists(const std::string &field_name) const
Checks if a field with a given name exists in the entity&#39;s field manager.
Definition: Ioss_GroupingEntity.h:382
Ioss::GroupingEntity::get_implicit_property
virtual Property get_implicit_property(const std::string &my_name) const =0
Calculate and get an implicit property.
Definition: Ioss_GroupingEntity.C:166
Ioss::GroupingEntity::delete_database
virtual void delete_database()
Definition: Ioss_GroupingEntity.C:87
Ioss::Field::transform
bool transform(void *data)
Definition: Ioss_Field.C:251
Ioss::GroupingEntity::field_int_type
Ioss::Field::BasicType field_int_type() const
Definition: Ioss_GroupingEntity.h:242
Ioss::Field::has_transform
bool has_transform() const
Definition: Ioss_Field.h:166
Ioss::EntityType
EntityType
The particular type of GroupingEntity.
Definition: Ioss_EntityType.h:39
Ioss::GroupingEntity::put_field_data
int put_field_data(const std::string &field_name, void *data, size_t data_size) const
Write field data from memory into the database file using a pointer.
Definition: Ioss_GroupingEntity.C:239
Ioss::GroupingEntity::generic_name
std::string generic_name() const
Get a generated name based on the type of the entity and the id.
Definition: Ioss_GroupingEntity.C:96
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
Ioss::Field::INT64
Definition: Ioss_Field.h:58
Ioss::GroupingEntity::field_describe
int field_describe(NameList *names) const
Get the names of all fields in the entity&#39;s field manager.
Definition: Ioss_GroupingEntity.h:415
anonymous_namespace{Ioss_Utils.C}::data
std::vector< char > data
Definition: Ioss_Utils.C:78
Ioss::Field::get_field_type
static Ioss::Field::BasicType get_field_type(char)
Definition: Ioss_Field.h:64
Ioss_FieldManager.h
Ioss::GroupingEntity::properties
PropertyManager properties
Definition: Ioss_GroupingEntity.h:278
Ioss::GroupingEntity::hash
unsigned int hash() const
Definition: Ioss_GroupingEntity.h:251
Ioss_EntityType.h
Ioss::FieldManager
A collection of Ioss::Field objects.
Definition: Ioss_FieldManager.h:51
IOSS_ERROR
#define IOSS_ERROR(errmsg)
Definition: Ioss_Utils.h:64
Ioss::GroupingEntity::hash_
unsigned int hash_
Definition: Ioss_GroupingEntity.h:301
TOPTR
#define TOPTR(x)
Definition: Ioss_Utils.h:61