GEOSX
BufferOps.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 TotalEnergies
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
15 
16 
17 #ifndef GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
18 #define GEOS_DATAREPOSITORY_BUFFEROPS_HPP_
19 
20 #include "common/DataTypes.hpp"
21 #include "codingUtilities/Utilities.hpp"
22 #include "codingUtilities/traits.hpp"
23 #include "LvArray/src/limits.hpp"
24 
25 #include <type_traits>
26 
27 namespace geos
28 {
29 
30 template< typename T >
31 class InterObjectRelation;
32 
33 namespace bufferOps
34 {
35 
36 template< typename T >
37 struct is_packable_helper;
38 
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 >;
44 
45 template< typename T >
46 constexpr bool is_container = !is_noncontainer_type_packable< T >;
47 
48 template< typename >
49 constexpr bool is_packable_array = false;
50 
51 template< typename T, int NDIM, typename PERMUTATION >
52 constexpr bool is_packable_array< Array< T, NDIM, PERMUTATION > > = is_packable_helper< T >::value;
53 
54 template< typename T, int NDIM, int USD >
55 constexpr bool is_packable_array< ArrayView< T, NDIM, USD > > = is_packable_helper< T >::value;
56 
57 template< typename T, int NDIM, int USD >
58 constexpr bool is_packable_array< ArraySlice< T, NDIM, USD > > = is_packable_helper< T >::value;
59 
60 template< typename T >
61 constexpr bool is_packable_array< ArrayOfArrays< T > > = is_packable_helper< T >::value;
62 
63 template< typename >
64 constexpr bool is_packable_set = false;
65 
66 template< typename T >
67 constexpr bool is_packable_set< SortedArray< T > > = is_packable_helper< T >::value;
68 
69 
70 template< typename >
71 constexpr bool is_packable_map = false;
72 
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;
76 
77 
78 template< typename T >
79 struct is_packable_helper
80 {
81  static constexpr bool value = is_noncontainer_type_packable< T > ||
82  is_packable_array< T > ||
83  is_packable_map< T > ||
84  is_packable_set< T >;
85 };
86 
87 template< typename T >
88 constexpr bool is_packable = is_packable_helper< T >::value;
89 
90 template< typename T >
91 constexpr bool is_packable_by_index = is_packable_array< T >;
92 
93 template< typename >
94 constexpr bool is_map_packable_by_index = false;
95 
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 >;
99 
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 >;
104 
105 template< typename T >
106 constexpr bool can_memcpy = can_memcpy_helper< std::remove_const_t< std::remove_pointer_t< T > > >;
107 
108 //------------------------------------------------------------------------------
109 // Pack(buffer,var)
110 //------------------------------------------------------------------------------
111 template< bool DO_PACKING, typename T >
112 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
113 Pack( buffer_unit_type * & buffer,
114  T const & var );
115 
116 //------------------------------------------------------------------------------
117 template< bool DO_PACKING >
119 Pack( buffer_unit_type * & buffer,
120  const string & var );
121 
122 //------------------------------------------------------------------------------
123 template< bool DO_PACKING, typename T >
125 Pack( buffer_unit_type * & buffer,
126  SortedArray< T > const & var );
127 
128 //------------------------------------------------------------------------------
129 template< bool DO_PACKING, typename T >
130 typename std::enable_if< traits::is_tensorT< T >, localIndex >::type
131 Pack( buffer_unit_type * & buffer,
132  T const & var );
133 
134 //------------------------------------------------------------------------------
135 template< bool DO_PACKING, typename T, int NDIM, int USD >
136 typename std::enable_if< is_packable< T >, localIndex >::type
137 Pack( buffer_unit_type * & buffer,
138  ArrayView< T, NDIM, USD > const & var );
139 
140 //------------------------------------------------------------------------------
141 template< bool DO_PACKING, typename T >
143 Pack( buffer_unit_type * & buffer,
144  ArrayOfArrays< T > const & var );
145 
146 //------------------------------------------------------------------------------
147 template< bool DO_PACKING, typename T >
149 Pack( buffer_unit_type * & buffer,
150  ArrayOfSets< T > const & var );
151 
152 //------------------------------------------------------------------------------
153 template< bool DO_PACKING, typename MAP_TYPE >
154 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
155 Pack( buffer_unit_type * & buffer,
156  MAP_TYPE const & var );
157 
158 //------------------------------------------------------------------------------
159 template< bool DO_PACKING, typename T_FIRST, typename T_SECOND >
161 Pack( buffer_unit_type * & buffer,
162  std::pair< T_FIRST, T_SECOND > const & var );
163 
164 //------------------------------------------------------------------------------
165 template< bool DO_PACKING, typename T >
167 Pack( buffer_unit_type * & buffer,
168  InterObjectRelation< T > const & var );
169 
170 //------------------------------------------------------------------------------
171 // fallthrough-implementation
172 template< bool DO_PACKING, typename T >
173 typename std::enable_if< !is_packable< T >, localIndex >::type
174 Pack( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
175  T const & GEOS_UNUSED_PARAM( var ) )
176 {
177  GEOS_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable." );
178  return 0;
179 }
180 
181 //------------------------------------------------------------------------------
182 // PackArray(buffer,var,length)
183 //------------------------------------------------------------------------------
184 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
185 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
186 PackPointer( buffer_unit_type * & buffer,
187  T const * const GEOS_RESTRICT var,
188  INDEX_TYPE const length );
189 
190 //------------------------------------------------------------------------------
191 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
192 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
193 PackPointer( buffer_unit_type * & buffer,
194  T const * const GEOS_RESTRICT var,
195  INDEX_TYPE const length );
196 
197 //------------------------------------------------------------------------------
198 template< bool DO_PACKING, typename T, typename INDEX_TYPE, int USD >
199 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
200 PackArray( buffer_unit_type * & buffer,
201  arraySlice1d< T, USD > const & var,
202  INDEX_TYPE const length );
203 
204 //------------------------------------------------------------------------------
205 template< bool DO_PACKING, typename T, typename INDEX_TYPE, int USD >
206 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
207 PackArray( buffer_unit_type * & buffer,
208  arraySlice1d< T, USD > const & var,
209  INDEX_TYPE const length );
210 
211 //------------------------------------------------------------------------------
212 // PackByIndex(buffer,var,indices)
213 //------------------------------------------------------------------------------
214 template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_indices >
215 typename std::enable_if< is_packable< T >, localIndex >::type
216 PackByIndex( buffer_unit_type * & buffer,
217  ArrayView< T, NDIM, USD > const & var,
218  const T_indices & indices );
219 
220 //------------------------------------------------------------------------------
221 template< bool DO_PACKING, typename T, typename T_indices >
222 localIndex PackByIndex( buffer_unit_type * & buffer,
223  ArrayOfArrays< T > const & var,
224  T_indices const & indices );
225 
226 //------------------------------------------------------------------------------
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
229 PackByIndex( buffer_unit_type * & buffer,
230  MAP_TYPE const & var,
231  T_INDICES const & indices );
232 
233 //------------------------------------------------------------------------------
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
236 PackByIndex( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ),
237  T const & GEOS_UNUSED_PARAM( var ),
238  T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
239 {
240  GEOS_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable by index." );
241  return 0;
242 }
243 
244 //------------------------------------------------------------------------------
245 // Unpack(buffer,var)
246 //------------------------------------------------------------------------------
247 template< typename T >
248 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
249 Unpack( buffer_unit_type const * & buffer,
250  T & var );
251 
252 //------------------------------------------------------------------------------
253 inline
255 Unpack( buffer_unit_type const * & buffer,
256  string & var );
257 
258 //------------------------------------------------------------------------------
259 template< typename T >
260 typename std::enable_if< traits::is_tensorT< T >, localIndex >::type
261 Unpack( buffer_unit_type const * & buffer,
262  T & var );
263 
264 //------------------------------------------------------------------------------
265 template< typename T >
267 Unpack( buffer_unit_type const * & buffer,
268  SortedArray< T > & var );
269 
270 //------------------------------------------------------------------------------
271 template< typename T, int NDIM, typename PERMUTATION >
272 typename std::enable_if< is_packable< T >, localIndex >::type
273 Unpack( buffer_unit_type const * & buffer,
274  Array< T, NDIM, PERMUTATION > & var );
275 
276 //------------------------------------------------------------------------------
277 template< typename T >
278 localIndex Unpack( buffer_unit_type const * & buffer,
279  ArrayOfArrays< T > & var );
280 
281 //------------------------------------------------------------------------------
282 inline
284 Unpack( buffer_unit_type const * & buffer,
285  ArrayOfArrays< array1d< globalIndex > > & var,
286  localIndex const subArrayIndex );
287 
288 //------------------------------------------------------------------------------
289 template< typename T >
290 localIndex Unpack( buffer_unit_type const * & buffer,
291  ArrayOfSets< T > & var );
292 
293 //------------------------------------------------------------------------------
294 template< typename MAP_TYPE >
295 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
296 Unpack( buffer_unit_type const * & buffer,
297  MAP_TYPE & map );
298 
299 //------------------------------------------------------------------------------
300 template< typename T_FIRST, typename T_SECOND >
302 Unpack( buffer_unit_type const * & buffer,
303  std::pair< T_FIRST, T_SECOND > & var );
304 
305 //------------------------------------------------------------------------------
306 template< typename T >
308 Unpack( buffer_unit_type const * & buffer,
309  InterObjectRelation< T > & var );
310 
311 //------------------------------------------------------------------------------
312 template< typename T >
313 typename std::enable_if< !is_packable< T >, localIndex >::type
314 Unpack( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
315  T & GEOS_UNUSED_PARAM( var ) )
316 {
317  GEOS_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable." );
318  return 0;
319 }
320 
321 //------------------------------------------------------------------------------
322 // UnpackArray(buffer,var,expectedLength)
323 //------------------------------------------------------------------------------
324 template< typename T, typename INDEX_TYPE >
325 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
326 UnpackPointer( buffer_unit_type const * & buffer,
327  T * const GEOS_RESTRICT var,
328  INDEX_TYPE const expectedLength );
329 
330 //------------------------------------------------------------------------------
331 template< typename T, typename INDEX_TYPE >
332 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
333 UnpackPointer( buffer_unit_type const * & buffer,
334  T * const GEOS_RESTRICT var,
335  INDEX_TYPE const expectedLength );
336 
337 //------------------------------------------------------------------------------
338 template< typename T, typename INDEX_TYPE, int USD >
339 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
340 UnpackArray( buffer_unit_type const * & buffer,
341  arraySlice1d< T, USD > const & var,
342  INDEX_TYPE const length );
343 
344 //------------------------------------------------------------------------------
345 template< typename T, typename INDEX_TYPE, int USD >
346 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
347 UnpackArray( buffer_unit_type const * & buffer,
348  arraySlice1d< T, USD > const & var,
349  INDEX_TYPE const length );
350 
351 //------------------------------------------------------------------------------
352 // UnpackByIndex(buffer,var,indices)
353 //------------------------------------------------------------------------------
354 template< typename T, int NDIM, int USD, typename T_indices >
356 UnpackByIndex( buffer_unit_type const * & buffer,
357  ArrayView< T, NDIM, USD > const & var,
358  const T_indices & indices );
359 
360 //------------------------------------------------------------------------------
361 template< typename T, typename T_indices >
363 UnpackByIndex( buffer_unit_type const * & buffer,
364  ArrayOfArrays< T > & var,
365  T_indices const & indices );
366 
367 //------------------------------------------------------------------------------
368 template< typename MAP_TYPE, typename T_INDICES >
369 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
370 UnpackByIndex( buffer_unit_type const * & buffer,
371  MAP_TYPE & map,
372  T_INDICES const & indices );
373 
374 //------------------------------------------------------------------------------
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
377 UnpackByIndex( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ),
378  T & GEOS_UNUSED_PARAM( var ),
379  T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
380 {
381  GEOS_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable by index." );
382  return 0;
383 }
384 
385 //------------------------------------------------------------------------------
386 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
387 localIndex Pack( buffer_unit_type * & buffer,
388  T const * const GEOS_RESTRICT var,
389  arraySlice1d< INDEX_TYPE const > const & indices,
390  INDEX_TYPE const length );
391 
392 //------------------------------------------------------------------------------
393 template< typename T, typename INDEX_TYPE >
394 localIndex Unpack( buffer_unit_type const * & buffer,
395  T * const GEOS_RESTRICT var,
396  arraySlice1d< INDEX_TYPE const > const & indices,
397  INDEX_TYPE & length );
398 
399 //------------------------------------------------------------------------------
400 template< bool DO_PACKING, int USD >
401 localIndex Pack( buffer_unit_type * & buffer,
402  SortedArray< localIndex > const & var,
403  SortedArray< globalIndex > const & unmappedGlobalIndices,
404  arraySlice1d< globalIndex const, USD > const & localToGlobal );
405 
406 //------------------------------------------------------------------------------
407 template< typename SORTED >
408 inline localIndex Unpack( buffer_unit_type const * & buffer,
409  SortedArray< localIndex > & var,
410  SortedArray< globalIndex > & unmappedGlobalIndices,
411  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap,
412  bool const clearExistingSet );
413 
414 //------------------------------------------------------------------------------
415 template< typename T >
417 Pack( buffer_unit_type * & buffer,
418  ArrayOfSets< T > const & var );
419 
420 //------------------------------------------------------------------------------
421 template< typename T >
423 Unpack( buffer_unit_type const * & buffer,
424  ArrayOfSets< T > & var );
425 
426 
427 //------------------------------------------------------------------------------
428 template< bool DO_PACKING, int USD >
430 Pack( buffer_unit_type * & buffer,
431  arraySlice1d< localIndex const, USD > const & var,
432  globalIndex const * const unmappedGlobalIndices,
433  localIndex const length,
434  arraySlice1d< globalIndex const > const & localToGlobalMap );
435 
436 //------------------------------------------------------------------------------
437 template< typename SORTED >
438 inline localIndex Unpack( buffer_unit_type const * & buffer,
439  localIndex_array & var,
440  array1d< globalIndex > & unmappedGlobalIndices,
441  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
442 
443 //------------------------------------------------------------------------------
444 inline localIndex UnpackSyncList( buffer_unit_type const * & buffer,
445  localIndex_array & var,
446  std::unordered_map< globalIndex, localIndex > const & globalToLocalMap );
447 
448 //------------------------------------------------------------------------------
449 template< typename SORTED, int USD >
450 inline
452 Unpack( buffer_unit_type const * & buffer,
453  arraySlice1d< localIndex, USD > & var,
454  array1d< globalIndex > & unmappedGlobalIndices,
455  localIndex const expectedLength,
456  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
457 
458 //------------------------------------------------------------------------------
459 template< bool DO_PACKING >
461 Pack( buffer_unit_type * & buffer,
462  arrayView1d< localIndex const > const & var,
463  arrayView1d< localIndex const > const & indices,
464  arrayView1d< globalIndex const > const & localToGlobalMap,
465  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
466 
467 //------------------------------------------------------------------------------
468 template< bool DO_PACKING >
470 Pack( buffer_unit_type * & buffer,
471  ArrayOfArraysView< array1d< globalIndex > const > const & var,
472  arrayView1d< localIndex const > const & indices,
473  arrayView1d< globalIndex const > const & localToGlobalMap );
474 
475 //------------------------------------------------------------------------------
476 template< typename SORTED0, typename SORTED1 >
477 inline
479 Unpack( buffer_unit_type const * & buffer,
480  arrayView1d< localIndex > const & var,
481  array1d< localIndex > const & indices,
482  mapBase< globalIndex, localIndex, SORTED0 > const & globalToLocalMap,
483  mapBase< globalIndex, localIndex, SORTED1 > const & relatedObjectGlobalToLocalMap );
484 
485 
486 //------------------------------------------------------------------------------
487 template< bool DO_PACKING, typename SORTED >
489 Pack( buffer_unit_type * & buffer,
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 );
495 
496 //------------------------------------------------------------------------------
497 template< typename SORTED0, typename SORTED1, typename SORTED2 >
498 inline
500 Unpack( buffer_unit_type const * & buffer,
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 );
506 
507 //------------------------------------------------------------------------------
508 template< typename SORTED0 >
509 inline
511 Unpack( buffer_unit_type const * & buffer,
512  ArrayOfArrays< array1d< globalIndex > > & var,
513  array1d< localIndex > & indices,
514  mapBase< globalIndex, localIndex, SORTED0 > const & globalToLocalMap );
515 
516 //------------------------------------------------------------------------------
517 template< bool DO_PACKING, typename SORTED >
519 Pack( buffer_unit_type * & buffer,
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 );
525 
526 //------------------------------------------------------------------------------
527 template< typename SORTED0, typename SORTED1, typename SORTED2 >
528 inline
530 Unpack( buffer_unit_type const * & buffer,
531  arrayView1d< SortedArray< localIndex > > & var,
532  localIndex_array & indices,
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 );
537 
538 //------------------------------------------------------------------------------
539 template< bool DO_PACKING, int USD0, int USD1 >
541 Pack( buffer_unit_type * & buffer,
542  arrayView2d< localIndex const, USD0 > const & var,
543  arrayView1d< localIndex > const & indices,
544  arraySlice1d< globalIndex const, USD1 > const & localToGlobalMap );
545 
546 //------------------------------------------------------------------------------
547 template< typename SORTED, int USD >
548 inline
550 Unpack( buffer_unit_type const * & buffer,
551  arrayView2d< localIndex, USD > const & var,
552  array1d< localIndex > & indices,
553  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
554 
555 //------------------------------------------------------------------------------
556 template< bool DO_PACKING, typename SORTED, int USD0 >
558 Pack( buffer_unit_type * & buffer,
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 );
564 
565 //------------------------------------------------------------------------------
566 template< typename SORTED0, typename SORTED1, typename SORTED2, int USD >
567 inline
569 Unpack( buffer_unit_type const * & buffer,
570  arrayView2d< localIndex, USD > const & var,
571  localIndex_array & indices,
572  mapBase< localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
573  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
574  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap );
575 
576 //------------------------------------------------------------------------------
577 template< bool DO_PACKING, typename MAP_TYPE >
578 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
579 Pack( buffer_unit_type * & buffer, MAP_TYPE const & var );
580 
581 //------------------------------------------------------------------------------
582 template< typename MAP_TYPE >
583 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
584 Unpack( buffer_unit_type const * & buffer, MAP_TYPE & map );
585 
586 //------------------------------------------------------------------------------
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 );
590 
591 //------------------------------------------------------------------------------
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 );
595 
596 //------------------------------------------------------------------------------
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 );
600 
601 //------------------------------------------------------------------------------
602 template< typename T_FIRST, typename T_SECOND >
604 Unpack( buffer_unit_type const * & buffer, std::pair< T_FIRST, T_SECOND > & var );
605 
606 //------------------------------------------------------------------------------
607 template< bool DO_PACKING, typename T >
609 Pack( buffer_unit_type * & buffer,
610  InterObjectRelation< T > const & var );
611 
612 template< typename ... VARPACK >
614 PackSize( VARPACK const && ... pack )
615 {
616  buffer_unit_type * junk = nullptr;
617  return Pack< false >( junk, pack ... );
618 }
619 
620 template< typename ... VARPACK >
622 PackSize( VARPACK && ... pack )
623 {
624  buffer_unit_type * junk = nullptr;
625  return Pack< false >( junk, pack ... );
626 }
627 
628 #ifdef GEOSX_USE_ARRAY_BOUNDS_CHECK
629 //------------------------------------------------------------------------------
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
633 Pack( buffer_unit_type * & GEOS_UNUSED_PARAM( buffer ), T const & GEOS_UNUSED_PARAM( var ), T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
634 {
635  GEOS_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable by index." );
636  return 0;
637 }
638 
639 //------------------------------------------------------------------------------
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
643 Unpack( buffer_unit_type const * & GEOS_UNUSED_PARAM( buffer ), T & GEOS_UNUSED_PARAM( var ), T_INDICES const & GEOS_UNUSED_PARAM( indices ) )
644 {
645  GEOS_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable by index." );
646  return 0;
647 }
648 
649 //------------------------------------------------------------------------------
650 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
652 Pack( buffer_unit_type * & buffer,
653  arraySlice1d< T > const & var,
654  arraySlice1d< INDEX_TYPE > const & indices,
655  INDEX_TYPE const length );
656 
657 //------------------------------------------------------------------------------
658 template< typename T, typename INDEX_TYPE >
660 Unpack( buffer_unit_type const * & buffer,
661  arraySlice1d< T > & var,
662  arraySlice1d< INDEX_TYPE > const & indices,
663  INDEX_TYPE & length );
664 
665 #endif /* GEOSX_USE_ARRAY_BOUNDS_CHECK */
666 
667 } /* namespace bufferOps */
668 } /* namespace geos */
669 
670 #include "BufferOps_inline.hpp"
671 
672 #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:71
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:122
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:220
array1d< localIndex > localIndex_array
A 1-dimensional array of geos::localIndex types.
Definition: DataTypes.hpp:438
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:326
GEOSX_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
mapBase< TKEY, TVAL, std::integral_constant< bool, true > > map
Ordered map type.
Definition: DataTypes.hpp:409
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:149
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.
Definition: DataTypes.hpp:322