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 T *host_data_ptr = host_data.data();
536
537 // Extract the data from disk to the underlying memory pointed to by host_data_ptr.
538 int retval = internal_get_field_data(field, host_data_ptr, data_size);
539
540 // At this point, transform the field if specified...
541 if (retval >= 0)
542 field.transform(host_data_ptr);
543
544 // Copy the data to the device. (No op if data is in HostSpace.)
545 Kokkos::deep_copy(data, host_data);
546
547 return retval;
548 }
549
550 /** \brief Read field data from the database file into memory using a 2-D Kokkos:::View.
551 *
552 * \tparam T The data type
553 * \tparam Args The other template arguments for data.
554 * \param[in] field_name The name of the field to read.
555 * \param[out] data The data.
556 * \returns The number of values read.
557 *
558 */
559 template <typename T, typename... Args>
560 int Ioss::GroupingEntity::get_field_data(const std::string & field_name,
561 Kokkos::View<T **, Args...> &data) const
562 {
563 typedef Kokkos::View<T **, Args...> ViewType;
564
565 verify_field_exists(field_name, "input");
566
567 Ioss::Field field = get_field(field_name);
568
569 // Resize the view
570 int new_view_size_left = field.raw_count();
571 int new_view_size_right = field.raw_storage()->component_count();
572 Kokkos::resize(data, new_view_size_left, new_view_size_right);
573 size_t data_size = new_view_size_left * new_view_size_right * sizeof(T);
574
575 // Create and allocate an array to hold the data temporarily.
576 // This is necessary to ensure the data is placed in the correct
577 // location in the 2-D array, avoiding incorrect placement due
578 // to Views with padded dimensions.
579 T *data_array = new T[data_size];
580
581 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
582 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
583
584 // Extract the data from disk to the underlying memory pointed to by host_data_ptr.
585 int retval = internal_get_field_data(field, data_array, data_size);
586
587 // At this point, transform the field if specified...
588 if (retval >= 0)
589 field.transform(data_array);
590
591 // Copy the data to the host Mirror view.
592 // The host mirror view has the same layout as the device view.
593 // For CUDA, this will be LayoutLeft. In this case, the loop order
594 // chosen here will be slower than the reversed loop order.
595 // However, The time for this extra in-memory copy is small
596 // compared with the time to copy from disk into memory.
597 for (int i = 0; i < new_view_size_left; ++i) {
598 for (int j = 0; j < new_view_size_right; ++j) {
599 host_data(i, j) = data_array[new_view_size_right * i + j];
600 }
601 }
602
603 // Delete the temporary array
604 delete[] data_array;
605
606 // Copy the data to the device. (No op if data is in HostSpace.)
607 Kokkos::deep_copy(data, host_data);
608
609 return retval;
610 }
611
612 /** \brief Write field data from memory into the database file using a 1-D Kokkos::View.
613 *
614 * \tparam T The data type
615 * \tparam Args The other template arguments for data.
616 * \param[in] field_name The name of the field to write.
617 * \param[in] data The data.
618 * \returns The number of values written.
619 *
620 */
621 template <typename T, typename... Args>
622 int Ioss::GroupingEntity::put_field_data(const std::string & field_name,
623 Kokkos::View<T *, Args...> &data) const
624 {
625 typedef Kokkos::View<T *, Args...> ViewType;
626
627 verify_field_exists(field_name, "output");
628
629 Ioss::Field field = get_field(field_name);
630 size_t data_size = field.raw_count() * field.raw_storage()->component_count() * sizeof(T);
631
632 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
633 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
634
635 // Copy the data to the host. (No op if data is in HostSpace.)
636 Kokkos::deep_copy(host_data, data);
637
638 // Extract a pointer to the underlying allocated memory of the host view.
639 T *host_data_ptr = host_data.data();
640
641 // Transform the field
642 field.transform(host_data_ptr);
643
644 // Copy the data to disk from the underlying memory pointed to by host_data_ptr.
645 return internal_put_field_data(field, host_data_ptr, data_size);
646 }
647
648 /** \brief Write field data from memory into the database file using a 2-D Kokkos::View.
649 *
650 * \tparam T The data type
651 * \tparam Args The other template arguments for data.
652 * \param[in] field_name The name of the field to write.
653 * \param[in] data The data.
654 * \returns The number of values written.
655 *
656 */
657 template <typename T, typename... Args>
658 int Ioss::GroupingEntity::put_field_data(const std::string & field_name,
659 Kokkos::View<T **, Args...> &data) const
660 {
661 typedef Kokkos::View<T **, Args...> ViewType;
662
663 verify_field_exists(field_name, "output");
664
665 Ioss::Field field = get_field(field_name);
666
667 int view_size_left = data.extent(0);
668 int view_size_right = data.extent(1);
669 size_t data_size = field.raw_count() * field.raw_storage()->component_count() * sizeof(T);
670
671 if (view_size_left * view_size_right * sizeof(T) != data_size) {
672 std::ostringstream errmsg;
673 errmsg << "\nERROR: View dimensions are inconsistent with field raw count or raw storage "
674 "component count"
675 << "for field" << field_name << "\n\n";
676 IOSS_ERROR(errmsg);
677 }
678
679 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
680 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
681
682 // Copy the data to the host. (No op if data is in HostSpace.)
683 Kokkos::deep_copy(host_data, data);
684
685 // Create and allocate an array to hold the data temporarily.
686 // This is necessary to ensure the data is taken from the correct
687 // location in the 2-D array, avoiding incorrect location due
688 // to Views with padded dimensions.
689 T *data_array = new T[data_size];
690
691 // Copy the data from the host Mirror view.
692 // The host mirror view has the same layout as the device view.
693 // For CUDA, this will be LayoutLeft. In this case, the loop order
694 // chosen here will be slower than the reversed loop order.
695 // However, The time for this extra in-memory copy is small
696 // compared with the time to copy to disk from memory.
697 for (int i = 0; i < view_size_left; ++i) {
698 for (int j = 0; j < view_size_right; ++j) {
699 data_array[view_size_right * i + j] = host_data(i, j);
700 }
701 }
702
703 // Transform the field
704 field.transform(data_array);
705
706 // Copy the data to disk from the underlying memory pointed to by data_array.
707 int retval = internal_put_field_data(field, data_array, data_size);
708
709 // Delete the temporary array
710 delete[] data_array;
711
712 return retval;
713 }
714 #endif
715
716 #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:45
Ioss_CodeTypes.h
Ioss::Property
A named value that has a known type.
Definition: Ioss_Property.h:47
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::GroupingEntity::verify_field_exists
void verify_field_exists(const std::string &field_name, const std::string &inout) const
Definition: Ioss_GroupingEntity.C:286
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::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::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::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_DatabaseIO.h
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::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::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
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:73
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
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