GEOS
BufferOps.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
16 
17 
18 #ifndef GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
19 #define GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
20 
21 #include "common/DataTypes.hpp"
22 #include "common/logger/Logger.hpp"
23 #include "codingUtilities/Utilities.hpp"
24 #include "codingUtilities/traits.hpp"
25 #include "LvArray/src/limits.hpp"
26 
27 #include <type_traits>
28 
29 namespace geos
30 {
31 
32 template< typename T >
33 class InterObjectRelation;
34 
35 namespace bufferOps
36 {
37 
38 template< typename T >
39 struct is_packable_helper;
40 
41 template< typename T >
42 constexpr bool is_noncontainer_type_packable = std::is_trivial< T >::value ||
43  std::is_arithmetic< T >::value ||
44  traits::is_tensorT< T > ||
45  traits::is_string< T >;
46 
47 template< typename T >
48 constexpr bool is_container = !is_noncontainer_type_packable< T >;
49 
50 template< typename >
51 constexpr bool is_packable_array = false;
52 
53 template< typename T, int NDIM, typename PERMUTATION >
54 constexpr bool is_packable_array< Array< T, NDIM, PERMUTATION > > = is_packable_helper< T >::value;
55 
56 template< typename T, int NDIM, int USD >
57 constexpr bool is_packable_array< ArrayView< T, NDIM, USD > > = is_packable_helper< T >::value;
58 
59 template< typename T, int NDIM, int USD >
60 constexpr bool is_packable_array< ArraySlice< T, NDIM, USD > > = is_packable_helper< T >::value;
61 
62 template< typename T >
63 constexpr bool is_packable_array< ArrayOfArrays< T > > = is_packable_helper< T >::value;
64 
65 
66 template< typename >
67 constexpr bool is_packable_vector = false;
68 
69 template< typename T >
70 constexpr bool is_packable_vector< std::vector< T > > = is_packable_helper< T >::value;
71 
72 
73 template< typename >
74 constexpr bool is_packable_set = false;
75 
76 template< typename T >
77 constexpr bool is_packable_set< SortedArray< T > > = is_packable_helper< T >::value;
78 
79 template< typename T >
80 constexpr bool is_packable_set< set< T > > = is_packable_helper< T >::value;
81 
82 
83 template< typename >
84 constexpr bool is_packable_map = false;
85 
86 template< typename T_KEY, typename T_VAL, typename SORTED >
87 constexpr bool is_packable_map< mapBase< T_KEY, T_VAL, SORTED > > = is_packable_helper< T_KEY >::value &&
88  is_packable_helper< T_VAL >::value;
89 
90 
91 template< typename T >
92 struct is_packable_helper
93 {
94  static constexpr bool value = is_noncontainer_type_packable< T > ||
95  is_packable_vector< T > ||
96  is_packable_array< T > ||
97  is_packable_map< T > ||
98  is_packable_set< T >;
99 };
100 
101 template< typename T >
102 constexpr bool is_packable = is_packable_helper< T >::value;
103 
104 template< typename T >
105 constexpr bool is_packable_by_index = is_packable_array< T > || is_packable_vector< T >;
106 
107 template< typename >
108 constexpr bool is_map_packable_by_index = false;
109 
110 template< typename T_KEY, typename T_VAL, typename SORTED >
111 constexpr bool is_map_packable_by_index< mapBase< T_KEY, T_VAL, SORTED > > = is_packable< T_KEY > &&
112  is_packable_by_index< T_VAL >;
113 
114 template< typename T >
115 constexpr bool can_memcpy_helper = std::is_arithmetic< T >::value ||
116  std::is_enum< T >::value ||
117  traits::is_tensorT< T >;
118 
119 template< typename T >
120 constexpr bool can_memcpy = can_memcpy_helper< std::remove_const_t< std::remove_pointer_t< T > > >;
121 
122 //------------------------------------------------------------------------------
123 // Pack(buffer,var)
124 //------------------------------------------------------------------------------
125 template< bool DO_PACKING, typename T >
126 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
127 Pack( buffer_unit_type * & buffer,
128  T const & var );
129 
130 //------------------------------------------------------------------------------
131 template< bool DO_PACKING >
133 Pack( buffer_unit_type * & buffer,
134  const string & var );
135 
136 //------------------------------------------------------------------------------
137 template< bool DO_PACKING, typename T, typename SET >
139 PackSet( buffer_unit_type * & buffer,
140  SET const & var );
141 
142 template< bool DO_PACKING, typename T >
144 Pack( buffer_unit_type * & buffer,
145  SortedArray< T > const & var )
146 { return PackSet< DO_PACKING, T >( buffer, var ); }
147 
148 template< bool DO_PACKING, typename T >
150 Pack( buffer_unit_type * & buffer,
151  set< T > const & var )
152 { return PackSet< DO_PACKING, T >( buffer, var ); }
153 
154 
155 
156 //------------------------------------------------------------------------------
157 template< bool DO_PACKING, typename T >
158 typename std::enable_if< traits::is_tensorT< T >, localIndex >::type
159 Pack( buffer_unit_type * & buffer,
160  T const & var );
161 
162 //------------------------------------------------------------------------------
163 template< bool DO_PACKING, typename T, int NDIM, int USD >
164 typename std::enable_if< is_packable< T >, localIndex >::type
165 Pack( buffer_unit_type * & buffer,
166  ArrayView< T, NDIM, USD > const & var );
167 
168 template< bool DO_PACKING, typename T >
170 Pack( buffer_unit_type * & buffer,
171  std::vector< T > const & var );
172 
173 //------------------------------------------------------------------------------
174 template< bool DO_PACKING, typename T >
176 Pack( buffer_unit_type * & buffer,
177  ArrayOfArrays< T > const & var );
178 
179 //------------------------------------------------------------------------------
180 template< bool DO_PACKING, typename T >
182 Pack( buffer_unit_type * & buffer,
183  ArrayOfSets< T > const & var );
184 
185 //------------------------------------------------------------------------------
186 template< bool DO_PACKING, typename MAP_TYPE >
187 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
188 Pack( buffer_unit_type * & buffer,
189  MAP_TYPE const & var );
190 
191 //------------------------------------------------------------------------------
192 template< bool DO_PACKING, typename T_FIRST, typename T_SECOND >
194 Pack( buffer_unit_type * & buffer,
195  std::pair< T_FIRST, T_SECOND > const & var );
196 
197 //------------------------------------------------------------------------------
198 template< bool DO_PACKING, typename T >
200 Pack( buffer_unit_type * & buffer,
201  InterObjectRelation< T > const & var );
202 
203 //------------------------------------------------------------------------------
204 // fallthrough-implementation
205 template< bool DO_PACKING, typename T >
206 typename std::enable_if< !is_packable< T >, localIndex >::type
207 Pack( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
208  T const & GEOS_UNUSED_PARAM( var ) )
209 {
210  GEOS_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable." );
211  return 0;
212 }
213 
214 //------------------------------------------------------------------------------
215 // PackArray(buffer,var,length)
216 //------------------------------------------------------------------------------
217 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
218 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
219 PackPointer( buffer_unit_type * & buffer,
220  T const * const GEOS_RESTRICT var,
221  INDEX_TYPE const length );
222 
223 //------------------------------------------------------------------------------
224 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
225 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
226 PackPointer( buffer_unit_type * & buffer,
227  T const * const GEOS_RESTRICT var,
228  INDEX_TYPE const length );
229 
230 //------------------------------------------------------------------------------
231 template< bool DO_PACKING, typename T, typename INDEX_TYPE, int USD >
232 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
233 PackArray( buffer_unit_type * & buffer,
234  arraySlice1d< T, USD > const & var,
235  INDEX_TYPE const length );
236 
237 //------------------------------------------------------------------------------
238 template< bool DO_PACKING, typename T, typename INDEX_TYPE, int USD >
239 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
240 PackArray( buffer_unit_type * & buffer,
241  arraySlice1d< T, USD > const & var,
242  INDEX_TYPE const length );
243 
244 //------------------------------------------------------------------------------
245 // PackByIndex(buffer,var,indices)
246 //------------------------------------------------------------------------------
247 template< bool DO_PACKING, typename T, typename T_indices >
248 typename std::enable_if< is_packable< T >, localIndex >::type
249 PackByIndex( buffer_unit_type * & buffer,
250  std::vector< T > const & var,
251  const T_indices & indices );
252 
253 //------------------------------------------------------------------------------
254 template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_indices >
255 typename std::enable_if< is_packable< T >, localIndex >::type
256 PackByIndex( buffer_unit_type * & buffer,
257  ArrayView< T, NDIM, USD > const & var,
258  const T_indices & indices );
259 
260 //------------------------------------------------------------------------------
261 template< bool DO_PACKING, typename T, typename T_indices >
262 localIndex PackByIndex( buffer_unit_type * & buffer,
263  ArrayOfArrays< T > const & var,
264  T_indices const & indices );
265 
266 //------------------------------------------------------------------------------
267 template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES >
268 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
269 PackByIndex( buffer_unit_type * & buffer,
270  MAP_TYPE const & var,
271  T_INDICES const & indices );
272 
273 //------------------------------------------------------------------------------
274 template< bool DO_PACKING, typename T, typename T_INDICES >
275 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >, localIndex >::type
276 PackByIndex( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
277  T const & GEOS_UNUSED_PARAM( var ),
278  T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
279 {
280  GEOS_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable by index." );
281  return 0;
282 }
283 
284 //------------------------------------------------------------------------------
285 // Unpack(buffer,var)
286 //------------------------------------------------------------------------------
287 template< typename T >
288 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
289 Unpack( buffer_unit_type const * & buffer,
290  T & var );
291 
292 //------------------------------------------------------------------------------
293 inline
295 Unpack( buffer_unit_type const * & buffer,
296  string & var );
297 
298 //------------------------------------------------------------------------------
299 template< typename T >
300 typename std::enable_if< traits::is_tensorT< T >, localIndex >::type
301 Unpack( buffer_unit_type const * & buffer,
302  T & var );
303 
304 //------------------------------------------------------------------------------
305 template< typename T, typename SET >
307 UnpackSet( buffer_unit_type const * & buffer,
308  SET & var );
309 
310 template< typename T >
312 Unpack( buffer_unit_type const * & buffer,
313  SortedArray< T > & var )
314 { return UnpackSet< T >( buffer, var ); }
315 
316 template< typename T >
318 Unpack( buffer_unit_type const * & buffer,
319  set< T > & var )
320 { return UnpackSet< T >( buffer, var ); }
321 
322 
323 //------------------------------------------------------------------------------
324 template< typename T, int NDIM, typename PERMUTATION >
325 typename std::enable_if< is_packable< T >, localIndex >::type
326 Unpack( buffer_unit_type const * & buffer,
327  Array< T, NDIM, PERMUTATION > & var );
328 
329 template< typename T >
330 typename std::enable_if< is_packable< T >, localIndex >::type
331 Unpack( buffer_unit_type const * & buffer,
332  std::vector< T > & var );
333 
334 
335 //------------------------------------------------------------------------------
336 template< typename T >
337 localIndex Unpack( buffer_unit_type const * & buffer,
338  ArrayOfArrays< T > & var );
339 
340 //------------------------------------------------------------------------------
341 inline
343 Unpack( buffer_unit_type const * & buffer,
344  ArrayOfArrays< array1d< globalIndex > > & var,
345  localIndex const subArrayIndex );
346 
347 //------------------------------------------------------------------------------
348 template< typename T >
349 localIndex Unpack( buffer_unit_type const * & buffer,
350  ArrayOfSets< T > & var );
351 
352 //------------------------------------------------------------------------------
353 template< typename MAP_TYPE >
354 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
355 Unpack( buffer_unit_type const * & buffer,
356  MAP_TYPE & map );
357 
358 //------------------------------------------------------------------------------
359 template< typename T_FIRST, typename T_SECOND >
361 Unpack( buffer_unit_type const * & buffer,
362  std::pair< T_FIRST, T_SECOND > & var );
363 
364 //------------------------------------------------------------------------------
365 template< typename T >
367 Unpack( buffer_unit_type const * & buffer,
368  InterObjectRelation< T > & var );
369 
370 //------------------------------------------------------------------------------
371 template< typename T >
372 typename std::enable_if< !is_packable< T >, localIndex >::type
373 Unpack( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
374  T & GEOS_UNUSED_PARAM( var ) )
375 {
376  GEOS_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable." );
377  return 0;
378 }
379 
380 //------------------------------------------------------------------------------
381 // UnpackArray(buffer,var,expectedLength)
382 //------------------------------------------------------------------------------
383 template< typename T, typename INDEX_TYPE >
384 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
385 UnpackPointer( buffer_unit_type const * & buffer,
386  T * const GEOS_RESTRICT var,
387  INDEX_TYPE const expectedLength );
388 
389 //------------------------------------------------------------------------------
390 template< typename T, typename INDEX_TYPE >
391 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
392 UnpackPointer( buffer_unit_type const * & buffer,
393  T * const GEOS_RESTRICT var,
394  INDEX_TYPE const expectedLength );
395 
396 //------------------------------------------------------------------------------
397 template< typename T, typename INDEX_TYPE, int USD >
398 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
399 UnpackArray( buffer_unit_type const * & buffer,
400  arraySlice1d< T, USD > const & var,
401  INDEX_TYPE const length );
402 
403 //------------------------------------------------------------------------------
404 template< typename T, typename INDEX_TYPE, int USD >
405 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
406 UnpackArray( buffer_unit_type const * & buffer,
407  arraySlice1d< T, USD > const & var,
408  INDEX_TYPE const length );
409 
410 //------------------------------------------------------------------------------
411 // UnpackByIndex(buffer,var,indices)
412 //------------------------------------------------------------------------------
413 template< typename T, typename T_indices >
415 UnpackByIndex( buffer_unit_type const * & buffer,
416  std::vector< T > & var,
417  T_indices const & indices );
418 
419 //------------------------------------------------------------------------------
420 template< typename T, int NDIM, int USD, typename T_indices >
422 UnpackByIndex( buffer_unit_type const * & buffer,
423  ArrayView< T, NDIM, USD > const & var,
424  const T_indices & indices );
425 
426 //------------------------------------------------------------------------------
427 template< typename T, typename T_indices >
429 UnpackByIndex( buffer_unit_type const * & buffer,
430  ArrayOfArrays< T > & var,
431  T_indices const & indices );
432 
433 //------------------------------------------------------------------------------
434 template< typename MAP_TYPE, typename T_INDICES >
435 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
436 UnpackByIndex( buffer_unit_type const * & buffer,
437  MAP_TYPE & map,
438  T_INDICES const & indices );
439 
440 //------------------------------------------------------------------------------
441 template< typename T, typename T_INDICES >
442 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >, localIndex >::type
443 UnpackByIndex( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
444  T & GEOS_UNUSED_PARAM( var ),
445  T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
446 {
447  GEOS_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable by index." );
448  return 0;
449 }
450 
451 //------------------------------------------------------------------------------
452 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
453 localIndex Pack( buffer_unit_type * & buffer,
454  T const * const GEOS_RESTRICT var,
455  arraySlice1d< INDEX_TYPE const > const & indices,
456  INDEX_TYPE const length );
457 
458 //------------------------------------------------------------------------------
459 template< typename T, typename INDEX_TYPE >
460 localIndex Unpack( buffer_unit_type const * & buffer,
461  T * const GEOS_RESTRICT var,
462  arraySlice1d< INDEX_TYPE const > const & indices,
463  INDEX_TYPE & length );
464 
465 //------------------------------------------------------------------------------
466 template< bool DO_PACKING, int USD >
467 localIndex Pack( buffer_unit_type * & buffer,
468  SortedArray< localIndex > const & var,
469  SortedArray< globalIndex > const & unmappedGlobalIndices,
470  arraySlice1d< globalIndex const, USD > const & localToGlobal );
471 
472 //------------------------------------------------------------------------------
473 template< typename SORTED >
474 inline localIndex Unpack( buffer_unit_type const * & buffer,
475  SortedArray< localIndex > & var,
476  SortedArray< globalIndex > & unmappedGlobalIndices,
477  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap,
478  bool const clearExistingSet );
479 
480 //------------------------------------------------------------------------------
481 template< typename T >
483 Pack( buffer_unit_type * & buffer,
484  ArrayOfSets< T > const & var );
485 
486 //------------------------------------------------------------------------------
487 template< typename T >
489 Unpack( buffer_unit_type const * & buffer,
490  ArrayOfSets< T > & var );
491 
492 
493 //------------------------------------------------------------------------------
494 template< bool DO_PACKING, int USD >
496 Pack( buffer_unit_type * & buffer,
497  arraySlice1d< localIndex const, USD > const & var,
498  globalIndex const * const unmappedGlobalIndices,
499  localIndex const length,
500  arraySlice1d< globalIndex const > const & localToGlobalMap );
501 
502 //------------------------------------------------------------------------------
503 template< typename SORTED >
504 inline localIndex Unpack( buffer_unit_type const * & buffer,
505  localIndex_array & var,
506  array1d< globalIndex > & unmappedGlobalIndices,
507  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
508 
509 //------------------------------------------------------------------------------
510 inline localIndex UnpackSyncList( buffer_unit_type const * & buffer,
511  localIndex_array & var,
512  std::unordered_map< globalIndex, localIndex > const & globalToLocalMap );
513 
514 //------------------------------------------------------------------------------
515 template< typename SORTED, int USD >
516 inline
518 Unpack( buffer_unit_type const * & buffer,
519  arraySlice1d< localIndex, USD > & var,
520  array1d< globalIndex > & unmappedGlobalIndices,
521  localIndex const expectedLength,
522  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
523 
524 //------------------------------------------------------------------------------
525 template< bool DO_PACKING >
527 Pack( buffer_unit_type * & buffer,
528  arrayView1d< localIndex const > const & var,
529  arrayView1d< localIndex const > const & indices,
530  arrayView1d< globalIndex const > const & localToGlobalMap,
531  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
532 
533 //------------------------------------------------------------------------------
534 template< bool DO_PACKING >
536 Pack( buffer_unit_type * & buffer,
537  ArrayOfArraysView< array1d< globalIndex > const > const & var,
538  arrayView1d< localIndex const > const & indices,
539  arrayView1d< globalIndex const > const & localToGlobalMap );
540 
541 //------------------------------------------------------------------------------
542 template< typename SORTED0, typename SORTED1 >
543 inline
545 Unpack( buffer_unit_type const * & buffer,
546  arrayView1d< localIndex > const & var,
547  array1d< localIndex > const & indices,
548  mapBase< globalIndex, localIndex, SORTED0 > const & globalToLocalMap,
549  mapBase< globalIndex, localIndex, SORTED1 > const & relatedObjectGlobalToLocalMap );
550 
551 
552 //------------------------------------------------------------------------------
553 template< bool DO_PACKING, typename SORTED >
555 Pack( buffer_unit_type * & buffer,
556  arrayView1d< arrayView1d< localIndex const > const > const & var,
557  mapBase< localIndex, array1d< globalIndex >, SORTED > const & unmappedGlobalIndices,
558  arrayView1d< localIndex const > const & indices,
559  arrayView1d< globalIndex const > const & localToGlobalMap,
560  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
561 
562 //------------------------------------------------------------------------------
563 template< typename SORTED0, typename SORTED1, typename SORTED2 >
564 inline
566 Unpack( buffer_unit_type const * & buffer,
567  arrayView1d< localIndex_array > & var,
568  array1d< localIndex > & indices,
569  mapBase< localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
570  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
571  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap );
572 
573 //------------------------------------------------------------------------------
574 template< typename SORTED0 >
575 inline
577 Unpack( buffer_unit_type const * & buffer,
578  ArrayOfArrays< array1d< globalIndex > > & var,
579  array1d< localIndex > & indices,
580  mapBase< globalIndex, localIndex, SORTED0 > const & globalToLocalMap );
581 
582 //------------------------------------------------------------------------------
583 template< bool DO_PACKING, typename SORTED >
585 Pack( buffer_unit_type * & buffer,
586  arrayView1d< SortedArray< localIndex > const > const & var,
587  mapBase< localIndex, SortedArray< globalIndex >, SORTED > const & unmappedGlobalIndices,
588  arrayView1d< localIndex const > const & indices,
589  arrayView1d< globalIndex const > const & localToGlobalMap,
590  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
591 
592 //------------------------------------------------------------------------------
593 template< typename SORTED0, typename SORTED1, typename SORTED2 >
594 inline
596 Unpack( buffer_unit_type const * & buffer,
597  arrayView1d< SortedArray< localIndex > > & var,
598  localIndex_array & indices,
599  mapBase< localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
600  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
601  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap,
602  bool const clearFlag );
603 
604 //------------------------------------------------------------------------------
605 template< bool DO_PACKING, int USD0, int USD1 >
607 Pack( buffer_unit_type * & buffer,
608  arrayView2d< localIndex const, USD0 > const & var,
609  arrayView1d< localIndex > const & indices,
610  arraySlice1d< globalIndex const, USD1 > const & localToGlobalMap );
611 
612 //------------------------------------------------------------------------------
613 template< typename SORTED, int USD >
614 inline
616 Unpack( buffer_unit_type const * & buffer,
617  arrayView2d< localIndex, USD > const & var,
618  array1d< localIndex > & indices,
619  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
620 
621 //------------------------------------------------------------------------------
622 template< bool DO_PACKING, typename SORTED, int USD0 >
624 Pack( buffer_unit_type * & buffer,
625  arrayView2d< localIndex const, USD0 > const & var,
626  mapBase< localIndex, array1d< globalIndex >, SORTED > const & unmappedGlobalIndices,
627  arrayView1d< localIndex const > const & indices,
628  arraySlice1d< globalIndex const > const & localToGlobalMap,
629  arraySlice1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
630 
631 //------------------------------------------------------------------------------
632 template< typename SORTED0, typename SORTED1, typename SORTED2, int USD >
633 inline
635 Unpack( buffer_unit_type const * & buffer,
636  arrayView2d< localIndex, USD > const & var,
637  localIndex_array & indices,
638  mapBase< localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
639  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
640  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap );
641 
642 //------------------------------------------------------------------------------
643 template< bool DO_PACKING, typename MAP_TYPE >
644 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
645 Pack( buffer_unit_type * & buffer, MAP_TYPE const & var );
646 
647 //------------------------------------------------------------------------------
648 template< typename MAP_TYPE >
649 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
650 Unpack( buffer_unit_type const * & buffer, MAP_TYPE & map );
651 
652 //------------------------------------------------------------------------------
653 template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES >
654 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
655 Pack( buffer_unit_type * & buffer, MAP_TYPE const & var, T_INDICES const & packIndices );
656 
657 //------------------------------------------------------------------------------
658 template< typename MAP_TYPE, typename T_INDICES >
659 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
660 Unpack( buffer_unit_type const * & buffer, MAP_TYPE & map, T_INDICES const & unpackIndices );
661 
662 //------------------------------------------------------------------------------
663 template< bool DO_PACKING, typename T_FIRST, typename T_SECOND >
665 Pack( buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND > const & var );
666 
667 //------------------------------------------------------------------------------
668 template< typename T_FIRST, typename T_SECOND >
670 Unpack( buffer_unit_type const * & buffer, std::pair< T_FIRST, T_SECOND > & var );
671 
672 //------------------------------------------------------------------------------
673 template< bool DO_PACKING, typename T >
675 Pack( buffer_unit_type * & buffer,
676  InterObjectRelation< T > const & var );
677 
678 template< typename ... VARPACK >
680 PackSize( VARPACK const && ... pack )
681 {
682  buffer_unit_type * junk = nullptr;
683  return Pack< false >( junk, pack ... );
684 }
685 
686 template< typename ... VARPACK >
688 PackSize( VARPACK && ... pack )
689 {
690  buffer_unit_type * junk = nullptr;
691  return Pack< false >( junk, pack ... );
692 }
693 
694 #ifdef GEOS_USE_ARRAY_BOUNDS_CHECK
695 //------------------------------------------------------------------------------
696 template< bool DO_PACKING, typename T, typename T_INDICES >
697 typename std::enable_if< !is_packable_by_index< T > &&
698  !is_map_packable_by_index< T >, localIndex >::type
699 Pack( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ), T const & GEOS_UNUSED_PARAM( var ), T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
700 {
701  GEOS_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable by index." );
702  return 0;
703 }
704 
705 //------------------------------------------------------------------------------
706 template< typename T, typename T_INDICES >
707 typename std::enable_if< !is_packable_by_index< T > &&
708  !is_map_packable_by_index< T >, localIndex >::type
709 Unpack( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ), T & GEOS_UNUSED_PARAM( var ), T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
710 {
711  GEOS_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable by index." );
712  return 0;
713 }
714 
715 //------------------------------------------------------------------------------
716 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
718 Pack( buffer_unit_type * & buffer,
719  arraySlice1d< T > const & var,
720  arraySlice1d< INDEX_TYPE > const & indices,
721  INDEX_TYPE const length );
722 
723 //------------------------------------------------------------------------------
724 template< typename T, typename INDEX_TYPE >
726 Unpack( buffer_unit_type const * & buffer,
727  arraySlice1d< T > & var,
728  arraySlice1d< INDEX_TYPE > const & indices,
729  INDEX_TYPE & length );
730 
731 #endif /* GEOS_USE_ARRAY_BOUNDS_CHECK */
732 
733 } /* namespace bufferOps */
734 } /* namespace geos */
735 
736 #include "BufferOps_inline.hpp"
737 
738 #endif /* GEOS_DATAREPOSITORY_BUFFEROPS_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.
Definition: GeosxMacros.hpp:72
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:157
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
array1d< localIndex > localIndex_array
A 1-dimensional array of geos::localIndex types.
Definition: DataTypes.hpp:399
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:88
LvArray::ArrayOfArraysView< T, INDEX_TYPE const, CONST_SIZES, LvArray::ChaiBuffer > ArrayOfArraysView
View of array of variable-sized arrays. See LvArray::ArrayOfArraysView for details.
Definition: DataTypes.hpp:286
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
Definition: DataTypes.hpp:369
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:109
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.
Definition: DataTypes.hpp:282