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