17 #ifndef GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
18 #define GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
21 #include "codingUtilities/Utilities.hpp"
22 #include "codingUtilities/traits.hpp"
23 #include "LvArray/src/limits.hpp"
25 #include <type_traits>
30 template<
typename T >
31 class InterObjectRelation;
36 template<
typename T >
37 struct is_packable_helper;
39 template<
typename T >
40 constexpr
bool is_noncontainer_type_packable = std::is_trivial< T >::value ||
41 std::is_arithmetic< T >::value ||
42 traits::is_tensorT< T > ||
43 traits::is_string< T >;
45 template<
typename T >
46 constexpr
bool is_container = !is_noncontainer_type_packable< T >;
49 constexpr
bool is_packable_array =
false;
51 template<
typename T,
int NDIM,
typename PERMUTATION >
52 constexpr
bool is_packable_array< Array< T, NDIM, PERMUTATION > > = is_packable_helper< T >::value;
54 template<
typename T,
int NDIM,
int USD >
55 constexpr
bool is_packable_array< ArrayView< T, NDIM, USD > > = is_packable_helper< T >::value;
57 template<
typename T,
int NDIM,
int USD >
58 constexpr
bool is_packable_array< ArraySlice< T, NDIM, USD > > = is_packable_helper< T >::value;
60 template<
typename T >
61 constexpr
bool is_packable_array< ArrayOfArrays< T > > = is_packable_helper< T >::value;
64 constexpr
bool is_packable_set =
false;
66 template<
typename T >
67 constexpr
bool is_packable_set< SortedArray< T > > = is_packable_helper< T >::value;
71 constexpr
bool is_packable_map =
false;
73 template<
typename T_KEY,
typename T_VAL,
typename SORTED >
74 constexpr
bool is_packable_map< mapBase< T_KEY, T_VAL, SORTED > > = is_packable_helper< T_KEY >::value &&
75 is_packable_helper< T_VAL >::value;
78 template<
typename T >
79 struct is_packable_helper
81 static constexpr
bool value = is_noncontainer_type_packable< T > ||
82 is_packable_array< T > ||
83 is_packable_map< T > ||
87 template<
typename T >
88 constexpr
bool is_packable = is_packable_helper< T >::value;
90 template<
typename T >
91 constexpr
bool is_packable_by_index = is_packable_array< T >;
94 constexpr
bool is_map_packable_by_index =
false;
96 template<
typename T_KEY,
typename T_VAL,
typename SORTED >
97 constexpr
bool is_map_packable_by_index< mapBase< T_KEY, T_VAL, SORTED > > = is_packable< T_KEY > &&
98 is_packable_by_index< T_VAL >;
100 template<
typename T >
101 constexpr
bool can_memcpy_helper = std::is_arithmetic< T >::value ||
102 std::is_enum< T >::value ||
103 traits::is_tensorT< T >;
105 template<
typename T >
106 constexpr
bool can_memcpy = can_memcpy_helper< std::remove_const_t< std::remove_pointer_t< T > > >;
111 template<
bool DO_PACKING,
typename T >
112 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
117 template<
bool DO_PACKING >
120 const string & var );
123 template<
bool DO_PACKING,
typename T >
126 SortedArray< T >
const & var );
129 template<
bool DO_PACKING,
typename T >
130 typename std::enable_if< traits::is_tensorT< T >,
localIndex >::type
135 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD >
136 typename std::enable_if< is_packable< T >,
localIndex >::type
138 ArrayView< T, NDIM, USD >
const & var );
141 template<
bool DO_PACKING,
typename T >
144 ArrayOfArrays< T >
const & var );
147 template<
bool DO_PACKING,
typename T >
150 ArrayOfSets< T >
const & var );
153 template<
bool DO_PACKING,
typename MAP_TYPE >
154 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
156 MAP_TYPE
const & var );
159 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
162 std::pair< T_FIRST, T_SECOND >
const & var );
165 template<
bool DO_PACKING,
typename T >
168 InterObjectRelation< T >
const & var );
172 template<
bool DO_PACKING,
typename T >
173 typename std::enable_if< !is_packable< T >,
localIndex >::type
177 GEOS_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable." );
184 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
185 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
188 INDEX_TYPE
const length );
191 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
192 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
195 INDEX_TYPE
const length );
198 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
199 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
201 arraySlice1d< T, USD >
const & var,
202 INDEX_TYPE
const length );
205 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE,
int USD >
206 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
208 arraySlice1d< T, USD >
const & var,
209 INDEX_TYPE
const length );
214 template<
bool DO_PACKING,
typename T,
int NDIM,
int USD,
typename T_indices >
215 typename std::enable_if< is_packable< T >,
localIndex >::type
217 ArrayView< T, NDIM, USD >
const & var,
218 const T_indices & indices );
221 template<
bool DO_PACKING,
typename T,
typename T_indices >
223 ArrayOfArrays< T >
const & var,
224 T_indices
const & indices );
227 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
228 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
230 MAP_TYPE
const & var,
231 T_INDICES
const & indices );
234 template<
bool DO_PACKING,
typename T,
typename T_INDICES >
235 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >,
localIndex >::type
240 GEOS_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
247 template<
typename T >
248 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
259 template<
typename T >
260 typename std::enable_if< traits::is_tensorT< T >,
localIndex >::type
265 template<
typename T >
268 SortedArray< T > & var );
271 template<
typename T,
int NDIM,
typename PERMUTATION >
272 typename std::enable_if< is_packable< T >,
localIndex >::type
274 Array< T, NDIM, PERMUTATION > & var );
277 template<
typename T >
279 ArrayOfArrays< T > & var );
289 template<
typename T >
291 ArrayOfSets< T > & var );
294 template<
typename MAP_TYPE >
295 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
300 template<
typename T_FIRST,
typename T_SECOND >
303 std::pair< T_FIRST, T_SECOND > & var );
306 template<
typename T >
309 InterObjectRelation< T > & var );
312 template<
typename T >
313 typename std::enable_if< !is_packable< T >,
localIndex >::type
317 GEOS_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable." );
324 template<
typename T,
typename INDEX_TYPE >
325 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
328 INDEX_TYPE
const expectedLength );
331 template<
typename T,
typename INDEX_TYPE >
332 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
335 INDEX_TYPE
const expectedLength );
338 template<
typename T,
typename INDEX_TYPE,
int USD >
339 typename std::enable_if< std::is_trivial< T >::value,
localIndex >::type
341 arraySlice1d< T, USD >
const & var,
342 INDEX_TYPE
const length );
345 template<
typename T,
typename INDEX_TYPE,
int USD >
346 typename std::enable_if< !std::is_trivial< T >::value,
localIndex >::type
348 arraySlice1d< T, USD >
const & var,
349 INDEX_TYPE
const length );
354 template<
typename T,
int NDIM,
int USD,
typename T_indices >
357 ArrayView< T, NDIM, USD >
const & var,
358 const T_indices & indices );
361 template<
typename T,
typename T_indices >
364 ArrayOfArrays< T > & var,
365 T_indices
const & indices );
368 template<
typename MAP_TYPE,
typename T_INDICES >
369 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
372 T_INDICES
const & indices );
375 template<
typename T,
typename T_INDICES >
376 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >,
localIndex >::type
381 GEOS_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
386 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
389 arraySlice1d< INDEX_TYPE const >
const & indices,
390 INDEX_TYPE
const length );
393 template<
typename T,
typename INDEX_TYPE >
396 arraySlice1d< INDEX_TYPE const >
const & indices,
397 INDEX_TYPE & length );
400 template<
bool DO_PACKING,
int USD >
402 SortedArray< localIndex >
const & var,
403 SortedArray< globalIndex >
const & unmappedGlobalIndices,
404 arraySlice1d< globalIndex const, USD >
const & localToGlobal );
407 template<
typename SORTED >
409 SortedArray< localIndex > & var,
410 SortedArray< globalIndex > & unmappedGlobalIndices,
411 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap,
412 bool const clearExistingSet );
415 template<
typename T >
418 ArrayOfSets< T >
const & var );
421 template<
typename T >
424 ArrayOfSets< T > & var );
428 template<
bool DO_PACKING,
int USD >
431 arraySlice1d< localIndex const, USD >
const & var,
434 arraySlice1d< globalIndex const >
const & localToGlobalMap );
437 template<
typename SORTED >
440 array1d< globalIndex > & unmappedGlobalIndices,
441 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap );
446 std::unordered_map< globalIndex, localIndex >
const & globalToLocalMap );
449 template<
typename SORTED,
int USD >
453 arraySlice1d< localIndex, USD > & var,
454 array1d< globalIndex > & unmappedGlobalIndices,
456 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap );
459 template<
bool DO_PACKING >
462 arrayView1d< localIndex const >
const & var,
463 arrayView1d< localIndex const >
const & indices,
464 arrayView1d< globalIndex const >
const & localToGlobalMap,
465 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
468 template<
bool DO_PACKING >
472 arrayView1d< localIndex const >
const & indices,
473 arrayView1d< globalIndex const >
const & localToGlobalMap );
476 template<
typename SORTED0,
typename SORTED1 >
480 arrayView1d< localIndex >
const & var,
481 array1d< localIndex >
const & indices,
482 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap,
483 mapBase< globalIndex, localIndex, SORTED1 >
const & relatedObjectGlobalToLocalMap );
487 template<
bool DO_PACKING,
typename SORTED >
490 arrayView1d< arrayView1d< localIndex const >
const >
const & var,
491 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
492 arrayView1d< localIndex const >
const & indices,
493 arrayView1d< globalIndex const >
const & localToGlobalMap,
494 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
497 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
501 arrayView1d< localIndex_array > & var,
502 array1d< localIndex > & indices,
503 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
504 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
505 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap );
508 template<
typename SORTED0 >
513 array1d< localIndex > & indices,
514 mapBase< globalIndex, localIndex, SORTED0 >
const & globalToLocalMap );
517 template<
bool DO_PACKING,
typename SORTED >
520 arrayView1d< SortedArray< localIndex >
const >
const & var,
521 mapBase<
localIndex, SortedArray< globalIndex >, SORTED >
const & unmappedGlobalIndices,
522 arrayView1d< localIndex const >
const & indices,
523 arrayView1d< globalIndex const >
const & localToGlobalMap,
524 arrayView1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
527 template<
typename SORTED0,
typename SORTED1,
typename SORTED2 >
533 mapBase<
localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
534 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
535 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap,
536 bool const clearFlag );
539 template<
bool DO_PACKING,
int USD0,
int USD1 >
542 arrayView2d< localIndex const, USD0 >
const & var,
543 arrayView1d< localIndex >
const & indices,
544 arraySlice1d< globalIndex const, USD1 >
const & localToGlobalMap );
547 template<
typename SORTED,
int USD >
551 arrayView2d< localIndex, USD >
const & var,
552 array1d< localIndex > & indices,
553 mapBase< globalIndex, localIndex, SORTED >
const & globalToLocalMap );
556 template<
bool DO_PACKING,
typename SORTED,
int USD0 >
559 arrayView2d< localIndex const, USD0 >
const & var,
560 mapBase<
localIndex, array1d< globalIndex >, SORTED >
const & unmappedGlobalIndices,
561 arrayView1d< localIndex const >
const & indices,
562 arraySlice1d< globalIndex const >
const & localToGlobalMap,
563 arraySlice1d< globalIndex const >
const & relatedObjectLocalToGlobalMap );
566 template<
typename SORTED0,
typename SORTED1,
typename SORTED2,
int USD >
570 arrayView2d< localIndex, USD >
const & var,
572 mapBase<
localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
573 mapBase< globalIndex, localIndex, SORTED1 >
const & globalToLocalMap,
574 mapBase< globalIndex, localIndex, SORTED2 >
const & relatedObjectGlobalToLocalMap );
577 template<
bool DO_PACKING,
typename MAP_TYPE >
578 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
582 template<
typename MAP_TYPE >
583 typename std::enable_if< is_packable_map< MAP_TYPE >,
localIndex >::type
587 template<
bool DO_PACKING,
typename MAP_TYPE,
typename T_INDICES >
588 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
589 Pack(
buffer_unit_type * & buffer, MAP_TYPE
const & var, T_INDICES
const & packIndices );
592 template<
typename MAP_TYPE,
typename T_INDICES >
593 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >,
localIndex >::type
594 Unpack(
buffer_unit_type const * & buffer, MAP_TYPE &
map, T_INDICES
const & unpackIndices );
597 template<
bool DO_PACKING,
typename T_FIRST,
typename T_SECOND >
599 Pack(
buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND >
const & var );
602 template<
typename T_FIRST,
typename T_SECOND >
604 Unpack(
buffer_unit_type const * & buffer, std::pair< T_FIRST, T_SECOND > & var );
607 template<
bool DO_PACKING,
typename T >
610 InterObjectRelation< T >
const & var );
612 template<
typename ... VARPACK >
614 PackSize( VARPACK
const && ... pack )
617 return Pack< false >( junk, pack ... );
620 template<
typename ... VARPACK >
622 PackSize( VARPACK && ... pack )
625 return Pack< false >( junk, pack ... );
628 #ifdef GEOSX_USE_ARRAY_BOUNDS_CHECK
630 template<
bool DO_PACKING,
typename T,
typename T_INDICES >
631 typename std::enable_if< !is_packable_by_index< T > &&
632 !is_map_packable_by_index< T >,
localIndex >::type
635 GEOS_ERROR(
"Trying to pack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
640 template<
typename T,
typename T_INDICES >
641 typename std::enable_if< !is_packable_by_index< T > &&
642 !is_map_packable_by_index< T >,
localIndex >::type
645 GEOS_ERROR(
"Trying to unpack data type ("<<
typeid(T).name()<<
") but type is not packable by index." );
650 template<
bool DO_PACKING,
typename T,
typename INDEX_TYPE >
653 arraySlice1d< T >
const & var,
654 arraySlice1d< INDEX_TYPE >
const & indices,
655 INDEX_TYPE
const length );
658 template<
typename T,
typename INDEX_TYPE >
661 arraySlice1d< T > & var,
662 arraySlice1d< INDEX_TYPE >
const & indices,
663 INDEX_TYPE & length );
670 #include "BufferOps_inline.hpp"
#define GEOS_RESTRICT
preprocessor variable for the C99 restrict keyword for use with pointers
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
array1d< localIndex > localIndex_array
A 1-dimensional array of geos::localIndex types.
LvArray::ArrayOfArraysView< T, INDEX_TYPE const, CONST_SIZES, LvArray::ChaiBuffer > ArrayOfArraysView
View of array of variable-sized arrays. See LvArray::ArrayOfArraysView for details.
GEOSX_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
signed char buffer_unit_type
Type stored in communication buffers.
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.