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 * For a SideSet, returns a list of the element blocks that the
142 * elements in the set belong to.
143 * For others, it returns an empty vector.
144 * Entries are pushed onto the "block_members" vector, so it will be
145 * appended to if it is not empty at entry to the function.
146 */
147 virtual void block_membership(std::vector<std::string> & /* block_members */) {}
148
149 std::string get_filename() const;
150
151 /** \brief Get the name of the particular type of entity.
152 *
153 * \returns The name of the particular type of entity.
154 */
155 virtual std::string type_string() const = 0;
156
157 /** \brief Get a short name of the particular type of entity.
158 *
159 * \returns The short name of the particular type of entity.
160 */
161 virtual std::string short_type_string() const = 0;
162
163 /** \brief What does this entity contain
164 *
165 * \returns The name of the thing this entitiy contains.
166 */
167 virtual std::string contains_string() const = 0;
168
169 /** \brief Get the EntityType, which indicates the particular type of GroupingEntity this is.
170 *
171 * \returns The particular EntityType of this GroupingEntity.
172 */
173 virtual EntityType type() const = 0;
174
175 // ========================================================================
176 // PROPERTIES
177 // ========================================================================
178 // Property-related information....
179 // Just forward it through to the property manager...
180 void property_add(const Property &new_prop);
181 void property_erase(const std::string &property_name);
182 bool property_exists(const std::string &property_name) const;
183 Property get_property(const std::string &property_name) const;
184 int property_describe(NameList *names) const;
185 size_t property_count() const;
186 /** Add a property, or change its value if it already exists with
187 a different value */
188 void property_update(const std::string &property, int64_t value) const;
189 void property_update(const std::string &property, const std::string &value) const;
190
191 // ========================================================================
192 // FIELDS
193 // ========================================================================
194 // Just forward these through to the field manager...
195 void field_add(const Field &new_field);
196 void field_erase(const std::string &field_name);
197 bool field_exists(const std::string &field_name) const;
198 Field get_field(const std::string &field_name) const;
199 const Field &get_fieldref(const std::string &field_name) const;
200 int field_describe(NameList *names) const;
201 int field_describe(Field::RoleType role, NameList *names) const;
202 size_t field_count() const;
203 size_t field_count(Field::RoleType role) const;
204
205 // Put this fields data into 'data'.
206 // Returns number of entities for which the field was read.
207 // Assumes 'data' is large enough to hold all values.
208 int get_field_data(const std::string &field_name, void *data, size_t data_size) const;
209
210 int put_field_data(const std::string &field_name, void *data, size_t data_size) const;
211
212 // Put this fields data into the specified std::vector space.
213 // Returns number of entities for which the field was read.
214 // Resizes 'data' to size needed to hold all values.
215 template <typename T>
216 int get_field_data(const std::string &field_name, std::vector<T> &data) const;
217
218 template <typename T>
219 int put_field_data(const std::string &field_name, const std::vector<T> &data) const;
220 template <typename T>
221 int put_field_data(const std::string &field_name, std::vector<T> &data) const;
222
223 #ifdef SEACAS_HAVE_KOKKOS
224 // Get and put this field's data into the specified Kokkos::View.
225 // Returns the number of entities for which the field was read.
226 // Resizes 'data' to size needed to hold all values;
227 // however, any Views that were previously created referencing the same
228 // underlying memory allocation as 'data' will remain the original size.
229 template <typename T, typename... Args>
230 int get_field_data(const std::string &field_name, Kokkos::View<T *, Args...> &data) const;
231
232 template <typename T, typename... Args>
233 int get_field_data(const std::string &field_name, Kokkos::View<T **, Args...> &data) const;
234
235 template <typename T, typename... Args>
236 int put_field_data(const std::string &field_name, Kokkos::View<T *, Args...> &data) const;
237
238 template <typename T, typename... Args>
239 int put_field_data(const std::string &field_name, Kokkos::View<T **, Args...> &data) const;
240 #endif
241
242 /** Get the number of bytes used to store the INT data type
243 *
244 * \returns The number of bytes.
245 */
246 Ioss::Field::BasicType field_int_type() const
247 {
248 if (database_ == nullptr || get_database()->int_byte_size_api() == 4) {
249 return Ioss::Field::INT32;
250 }
251
252 return Ioss::Field::INT64;
253 }
254
255 unsigned int hash() const { return hash_; }
256
257 int64_t entity_count() const { return get_property("entity_count").get_int(); }
258
259 protected:
260 void count_attributes() const;
261
262 bool set_state(State new_state)
263 {
264 entityState = new_state;
265 return true;
266 }
267
268 // Protected to give access to Region which is the only
269 // class that should delete the database. May have to make
270 // private and provide friend...
271 void really_delete_database();
272
273 // Handle implicit properties -- These are calcuated from data stored
274 // in the grouping entity instead of having an explicit value assigned.
275 // An example would be 'element_block_count' for a region.
276 // Note that even though this is a pure virtual function, an implementation
277 // is provided to return properties that are common to all grouping entities.
278 // Derived classes should call 'GroupingEntity::get_implicit_property'
279 // if the requested property is not specific to their type.
280 virtual Property get_implicit_property(const std::string &my_name) const = 0;
281
282 PropertyManager properties;
283 FieldManager fields;
284
285 virtual int64_t internal_get_field_data(const Field &field, void *data,
286 size_t data_size = 0) const = 0;
287 virtual int64_t internal_put_field_data(const Field &field, void *data,
288 size_t data_size = 0) const = 0;
289
290 int64_t entityCount = 0;
291
292 #if defined(IOSS_THREADSAFE)
293 mutable std::mutex m_;
294 #endif
295
296 private:
297 void verify_field_exists(const std::string &field_name, const std::string &inout) const;
298
299 std::string entityName;
300
301 DatabaseIO *database_ = nullptr;
302
303 mutable int64_t attributeCount = 0;
304 State entityState = STATE_CLOSED;
305 unsigned int hash_ = 0;
306 };
307 } // namespace Ioss
308
309 /** \brief Add a property to the entity's property manager.
310 *
311 * \param[in] new_prop The property to add.
312 */
313 inline void Ioss::GroupingEntity::property_add(const Ioss::Property &new_prop)
314 {
315 properties.add(new_prop);
316 }
317
318 /** \brief Remove a property from the entity's property manager.
319 *
320 * Assumes that the property with the given name already exists in the property manager.
321 *
322 * \param[in] property_name The name of the property to remove.
323 *
324 */
325 inline void Ioss::GroupingEntity::property_erase(const std::string &property_name)
326 {
327 properties.erase(property_name);
328 }
329
330 /** \brief Checks if a property exists in the entity's property manager.
331 *
332 * \param[in] property_name The property to check
333 * \returns True if the property exists.
334 */
335 inline bool Ioss::GroupingEntity::property_exists(const std::string &property_name) const
336 {
337 return properties.exists(property_name);
338 }
339
340 /** \brief Get the Property from the property manager associated with the entity.
341 *
342 * \param[in] property_name The name of the property to get
343 * \returns The property
344 *
345 */
346 inline Ioss::Property Ioss::GroupingEntity::get_property(const std::string &property_name) const
347 {
348 return properties.get(property_name);
349 }
350
351 /** \brief Get the names of all properties in the property manager for this entity.
352 *
353 * \param[out] names All the property names in the property manager.
354 * \returns The number of properties extracted from the property manager.
355 */
356 inline int Ioss::GroupingEntity::property_describe(NameList *names) const
357 {
358 return properties.describe(names);
359 }
360
361 /** \brief Get the number of properties defined in the property manager for this entity.
362 *
363 * \returns The number of properties.
364 */
365 inline size_t Ioss::GroupingEntity::property_count() const { return properties.count(); }
366
367 // ------------------------------------------------------------------------
368
369 /** \brief Remove a field from the entity's field manager.
370 *
371 * Assumes that a field with the given name exists in the field manager.
372 *
373 * \param[in] field_name The name of the field to remove.
374 */
375 inline void Ioss::GroupingEntity::field_erase(const std::string &field_name)
376 {
377 fields.erase(field_name);
378 }
379
380 /** \brief Checks if a field with a given name exists in the entity's field manager.
381 *
382 * \param[in] field_name The name of the field to check for.
383 * \returns True if the field exists in the entity's field manager.
384 *
385 */
386 inline bool Ioss::GroupingEntity::field_exists(const std::string &field_name) const
387 {
388 return fields.exists(field_name);
389 }
390
391 /** \brief Get a field from the entity's field manager.
392 *
393 * \param[in] field_name The name of the field to get.
394 * \returns The field object.
395 *
396 */
397 inline Ioss::Field Ioss::GroupingEntity::get_field(const std::string &field_name) const
398 {
399 return fields.get(field_name);
400 }
401
402 /** \brief Get a reference to a field from the entity's field manager.
403 *
404 * \param[in] field_name The name of the field to get.
405 * \returns A reference to the field object.
406 *
407 */
408 inline const Ioss::Field &Ioss::GroupingEntity::get_fieldref(const std::string &field_name) const
409 {
410 return fields.getref(field_name);
411 }
412
413 /** \brief Get the names of all fields in the entity's field manager.
414 *
415 * \param[out] names All field names in the entity's field manager.
416 * \returns The number of fields extracted from the entity's field manager.
417 *
418 */
419 inline int Ioss::GroupingEntity::field_describe(NameList *names) const
420 {
421 return fields.describe(names);
422 }
423
424 /** \brief Get the names of all fields of a specified RoleType in the entity's field manager.
425 *
426 * \param[in] role The role type (MESH, ATTRIBUTE, TRANSIENT, REDUCTION, etc.)
427 * \param[out] names All field names of the specified RoleType in the entity's field manager.
428 * \returns The number of fields extracted from the entity's field manager.
429 *
430 */
431 inline int Ioss::GroupingEntity::field_describe(Ioss::Field::RoleType role, NameList *names) const
432 {
433 return fields.describe(role, names);
434 }
435
436 /** \brief Get the number of fields in the entity's field manager.
437 *
438 * \returns The number of fields in the entity's field manager.
439 */
440 inline size_t Ioss::GroupingEntity::field_count() const { return fields.count(); }
441
442 /** \brief Read type 'T' field data from the database file into memory using a std::vector.
443 *
444 * \param[in] field_name The name of the field to read.
445 * \param[out] data The data.
446 * \returns The number of values read.
447 *
448 */
449 template <typename T>
450 int Ioss::GroupingEntity::get_field_data(const std::string &field_name, std::vector<T> &data) const
451 {
452 verify_field_exists(field_name, "input");
453
454 Ioss::Field field = get_field(field_name);
455 field.check_type(Ioss::Field::get_field_type(T(0)));
456
457 data.resize(field.raw_count() * field.raw_storage()->component_count());
458 size_t data_size = data.size() * sizeof(T);
459 int retval = internal_get_field_data(field, TOPTR(data), data_size);
460
461 // At this point, transform the field if specified...
462 if (retval >= 0) {
463 field.transform(TOPTR(data));
464 }
465
466 return retval;
467 }
468
469 /** \brief Write type 'T' field data from memory into the database file using a std::vector.
470 *
471 * \param[in] field_name The name of the field to write.
472 * \param[in] data The data.
473 * \returns The number of values written.
474 *
475 */
476 template <typename T>
477 int Ioss::GroupingEntity::put_field_data(const std::string & field_name,
478 const std::vector<T> &data) const
479 {
480 verify_field_exists(field_name, "output");
481
482 Ioss::Field field = get_field(field_name);
483 field.check_type(Ioss::Field::get_field_type(T(0)));
484 size_t data_size = data.size() * sizeof(T);
485 if (field.has_transform()) {
486 // Need non-const data since the transform will change the users data.
487 std::vector<T> nc_data(data);
488 field.transform(nc_data.data());
489 return internal_put_field_data(field, nc_data.data(), data_size);
490 }
491
492 T *my_data = const_cast<T *>(data.data());
493 return internal_put_field_data(field, my_data, data_size);
494 }
495
496 template <typename T>
497 int Ioss::GroupingEntity::put_field_data(const std::string &field_name, std::vector<T> &data) const
498 {
499 verify_field_exists(field_name, "output");
500
501 Ioss::Field field = get_field(field_name);
502 field.check_type(Ioss::Field::get_field_type(T(0)));
503 size_t data_size = data.size() * sizeof(T);
504 T * my_data = const_cast<T *>(data.data());
505 field.transform(my_data);
506 return internal_put_field_data(field, my_data, data_size);
507 }
508
509 #ifdef SEACAS_HAVE_KOKKOS
510
511 /** \brief Read field data from the database file into memory using a 1-D Kokkos:::View.
512 *
513 * \tparam T The data type.
514 * \tparam Args The other template arguments for data.
515 * \param[in] field_name The name of the field to read.
516 * \param[out] data The data.
517 * \returns The number of values read.
518 *
519 */
520 template <typename T, typename... Args>
521 int Ioss::GroupingEntity::get_field_data(const std::string & field_name,
522 Kokkos::View<T *, Args...> &data) const
523 {
524 typedef Kokkos::View<T *, Args...> ViewType;
525
526 verify_field_exists(field_name, "input");
527
528 Ioss::Field field = get_field(field_name);
529
530 // Resize the view
531 int new_view_size = field.raw_count() * field.raw_storage()->component_count();
532 Kokkos::resize(data, new_view_size);
533 size_t data_size = new_view_size * sizeof(T);
534
535 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
536 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
537
538 // Extract a pointer to the underlying allocated memory of the host view.
539 T *host_data_ptr = host_data.data();
540
541 // Extract the data from disk to the underlying memory pointed to by host_data_ptr.
542 int retval = internal_get_field_data(field, host_data_ptr, data_size);
543
544 // At this point, transform the field if specified...
545 if (retval >= 0)
546 field.transform(host_data_ptr);
547
548 // Copy the data to the device. (No op if data is in HostSpace.)
549 Kokkos::deep_copy(data, host_data);
550
551 return retval;
552 }
553
554 /** \brief Read field data from the database file into memory using a 2-D Kokkos:::View.
555 *
556 * \tparam T The data type
557 * \tparam Args The other template arguments for data.
558 * \param[in] field_name The name of the field to read.
559 * \param[out] data The data.
560 * \returns The number of values read.
561 *
562 */
563 template <typename T, typename... Args>
564 int Ioss::GroupingEntity::get_field_data(const std::string & field_name,
565 Kokkos::View<T **, Args...> &data) const
566 {
567 typedef Kokkos::View<T **, Args...> ViewType;
568
569 verify_field_exists(field_name, "input");
570
571 Ioss::Field field = get_field(field_name);
572
573 // Resize the view
574 int new_view_size_left = field.raw_count();
575 int new_view_size_right = field.raw_storage()->component_count();
576 Kokkos::resize(data, new_view_size_left, new_view_size_right);
577 size_t data_size = new_view_size_left * new_view_size_right * sizeof(T);
578
579 // Create and allocate an array to hold the data temporarily.
580 // This is necessary to ensure the data is placed in the correct
581 // location in the 2-D array, avoiding incorrect placement due
582 // to Views with padded dimensions.
583 T *data_array = new T[data_size];
584
585 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
586 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
587
588 // Extract the data from disk to the underlying memory pointed to by host_data_ptr.
589 int retval = internal_get_field_data(field, data_array, data_size);
590
591 // At this point, transform the field if specified...
592 if (retval >= 0)
593 field.transform(data_array);
594
595 // Copy the data to the host Mirror view.
596 // The host mirror view has the same layout as the device view.
597 // For CUDA, this will be LayoutLeft. In this case, the loop order
598 // chosen here will be slower than the reversed loop order.
599 // However, The time for this extra in-memory copy is small
600 // compared with the time to copy from disk into memory.
601 for (int i = 0; i < new_view_size_left; ++i) {
602 for (int j = 0; j < new_view_size_right; ++j) {
603 host_data(i, j) = data_array[new_view_size_right * i + j];
604 }
605 }
606
607 // Delete the temporary array
608 delete[] data_array;
609
610 // Copy the data to the device. (No op if data is in HostSpace.)
611 Kokkos::deep_copy(data, host_data);
612
613 return retval;
614 }
615
616 /** \brief Write field data from memory into the database file using a 1-D Kokkos::View.
617 *
618 * \tparam T The data type
619 * \tparam Args The other template arguments for data.
620 * \param[in] field_name The name of the field to write.
621 * \param[in] data The data.
622 * \returns The number of values written.
623 *
624 */
625 template <typename T, typename... Args>
626 int Ioss::GroupingEntity::put_field_data(const std::string & field_name,
627 Kokkos::View<T *, Args...> &data) const
628 {
629 typedef Kokkos::View<T *, Args...> ViewType;
630
631 verify_field_exists(field_name, "output");
632
633 Ioss::Field field = get_field(field_name);
634 size_t data_size = field.raw_count() * field.raw_storage()->component_count() * sizeof(T);
635
636 // Create a host mirror view. (No memory allocation if data is in HostSpace.)
637 typename ViewType::HostMirror host_data = Kokkos::create_mirror_view(data);
638
639 // Copy the data to the host. (No op if data is in HostSpace.)
640 Kokkos::deep_copy(host_data, data);
641
642 // Extract a pointer to the underlying allocated memory of the host view.
643 T *host_data_ptr = host_data.data();
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:299
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's field manager.
Definition: Ioss_GroupingEntity.h:397
Ioss::GroupingEntity::verify_field_exists
void verify_field_exists(const std::string &field_name, const std::string &inout) const
Definition: Ioss_GroupingEntity.C:285
Ioss::GroupingEntity::attributeCount
int64_t attributeCount
Definition: Ioss_GroupingEntity.h:303
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:365
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:82
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:80
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:356
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:297
Ioss::GroupingEntity::entityCount
int64_t entityCount
Definition: Ioss_GroupingEntity.h:290
Ioss::GroupingEntity::database_
DatabaseIO * database_
Definition: Ioss_GroupingEntity.h:301
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's field manager.
Definition: Ioss_GroupingEntity.h:440
Ioss::GroupingEntity
Base class for all 'grouping' 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:175
Ioss::GroupingEntity::property_erase
void property_erase(const std::string &property_name)
Remove a property from the entity's property manager.
Definition: Ioss_GroupingEntity.h:325
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's field manager.
Definition: Ioss_GroupingEntity.h:375
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:346
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:214
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's property manager.
Definition: Ioss_GroupingEntity.h:335
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's field manager.
Definition: Ioss_GroupingEntity.h:408
Ioss::GroupingEntity::count_attributes
void count_attributes() const
Definition: Ioss_GroupingEntity.C:262
Ioss::GroupingEntity::fields
FieldManager fields
Definition: Ioss_GroupingEntity.h:283
Ioss::GroupingEntity::contains_string
virtual std::string contains_string() const =0
What does this entity contain.
Ioss::GroupingEntity::really_delete_database
void really_delete_database()
Definition: Ioss_GroupingEntity.C:90
Ioss::GroupingEntity::entity_count
int64_t entity_count() const
Definition: Ioss_GroupingEntity.h:257
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'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:129
Ioss::GroupingEntity::set_state
bool set_state(State new_state)
Definition: Ioss_GroupingEntity.h:262
Ioss::GroupingEntity::property_add
void property_add(const Property &new_prop)
Add a property to the entity's property manager.
Definition: Ioss_GroupingEntity.h:313
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::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:304
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's field manager.
Definition: Ioss_GroupingEntity.h:386
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:88
Ioss::Field::transform
bool transform(void *data)
Definition: Ioss_Field.C:254
Ioss::GroupingEntity::field_int_type
Ioss::Field::BasicType field_int_type() const
Definition: Ioss_GroupingEntity.h:246
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:238
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::GroupingEntity::block_membership
virtual void block_membership(std::vector< std::string > &)
Get list of blocks that the entities in this GroupingEntity "touch".
Definition: Ioss_GroupingEntity.h:147
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's field manager.
Definition: Ioss_GroupingEntity.h:419
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:282
Ioss::GroupingEntity::hash
unsigned int hash() const
Definition: Ioss_GroupingEntity.h:255
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:65
Ioss::GroupingEntity::hash_
unsigned int hash_
Definition: Ioss_GroupingEntity.h:305
TOPTR
#define TOPTR(x)
Definition: Ioss_Utils.h:62