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 Total, S.A
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 GEOSX_DATAREPOSITORY_BUFFEROPS_HPP_
18 #define GEOSX_DATAREPOSITORY_BUFFEROPS_HPP_
19 
20 #include "common/DataTypes.hpp"
21 #include "codingUtilities/Utilities.hpp"
22 #include "codingUtilities/static_if.hpp"
23 #include "codingUtilities/traits.hpp"
24 #include "LvArray/src/limits.hpp"
25 
26 #include <type_traits>
27 
28 namespace geosx
29 {
30 
31 template< typename T >
33 
34 namespace bufferOps
35 {
36 
37 template< typename T >
38 struct is_packable_helper;
39 
40 template< typename T >
41 constexpr bool is_noncontainer_type_packable = std::is_trivial< T >::value ||
42  std::is_arithmetic< T >::value ||
43  traits::is_tensorT< T > ||
44  traits::is_string< T >;
45 
46 template< typename T >
47 constexpr bool is_container = !is_noncontainer_type_packable< T >;
48 
49 template< typename >
50 constexpr bool is_packable_array = false;
51 
52 template< typename T, int NDIM, typename PERMUTATION >
53 constexpr bool is_packable_array< Array< T, NDIM, PERMUTATION > > = is_packable_helper< T >::value;
54 
55 template< typename T, int NDIM, int USD >
56 constexpr bool is_packable_array< ArrayView< T, NDIM, USD > > = is_packable_helper< T >::value;
57 
58 template< typename T, int NDIM, int USD >
59 constexpr bool is_packable_array< ArraySlice< T, NDIM, USD > > = is_packable_helper< T >::value;
60 
61 template< typename T >
62 constexpr bool is_packable_array< ArrayOfArrays< T > > = is_packable_helper< T >::value;
63 
64 template< typename >
65 constexpr bool is_packable_set = false;
66 
67 template< typename T >
68 constexpr bool is_packable_set< SortedArray< T > > = is_packable_helper< T >::value;
69 
70 
71 template< typename >
72 constexpr bool is_packable_map = false;
73 
74 template< typename T_KEY, typename T_VAL, typename SORTED >
75 constexpr bool is_packable_map< mapBase< T_KEY, T_VAL, SORTED > > = is_packable_helper< T_KEY >::value &&
76  is_packable_helper< T_VAL >::value;
77 
78 
79 template< typename T >
80 struct is_packable_helper
81 {
82  static constexpr bool value = is_noncontainer_type_packable< T > ||
83  is_packable_array< T > ||
84  is_packable_map< T > ||
85  is_packable_set< T >;
86 };
87 
88 template< typename T >
89 constexpr bool is_packable = is_packable_helper< T >::value;
90 
91 template< typename T >
92 constexpr bool is_packable_by_index = is_packable_array< T >;
93 
94 template< typename >
95 constexpr bool is_map_packable_by_index = false;
96 
97 template< typename T_KEY, typename T_VAL, typename SORTED >
98 constexpr bool is_map_packable_by_index< mapBase< T_KEY, T_VAL, SORTED > > = is_packable< T_KEY > &&
99  is_packable_by_index< T_VAL >;
100 
101 template< typename T >
102 constexpr bool can_memcpy_helper = std::is_arithmetic< T >::value ||
103  std::is_enum< T >::value ||
104  traits::is_tensorT< T >;
105 
106 template< typename T >
107 constexpr bool can_memcpy = can_memcpy_helper< std::remove_const_t< std::remove_pointer_t< T > > >;
108 
109 //------------------------------------------------------------------------------
110 // Pack(buffer,var)
111 //------------------------------------------------------------------------------
112 template< bool DO_PACKING, typename T >
113 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
114 Pack( buffer_unit_type * & buffer,
115  T const & var );
116 
117 //------------------------------------------------------------------------------
118 template< bool DO_PACKING >
120 Pack( buffer_unit_type * & buffer,
121  const string & var );
122 
123 //------------------------------------------------------------------------------
124 template< bool DO_PACKING, typename T >
126 Pack( buffer_unit_type * & buffer,
127  SortedArray< T > const & var );
128 
129 //------------------------------------------------------------------------------
130 template< bool DO_PACKING, typename T >
131 typename std::enable_if< traits::is_tensorT< T >, localIndex >::type
132 Pack( buffer_unit_type * & buffer,
133  T const & var );
134 
135 //------------------------------------------------------------------------------
136 template< bool DO_PACKING, typename T, int NDIM, int USD >
137 typename std::enable_if< is_packable< T >, localIndex >::type
138 Pack( buffer_unit_type * & buffer,
139  ArrayView< T, NDIM, USD > const & var );
140 
141 //------------------------------------------------------------------------------
142 template< bool DO_PACKING, typename T >
144 Pack( buffer_unit_type * & buffer,
145  ArrayOfArrays< T > const & var );
146 
147 //------------------------------------------------------------------------------
148 template< bool DO_PACKING, typename T >
150 Pack( buffer_unit_type * & buffer,
151  ArrayOfSets< T > const & var );
152 
153 //------------------------------------------------------------------------------
154 template< bool DO_PACKING, typename MAP_TYPE >
155 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
156 Pack( buffer_unit_type * & buffer,
157  MAP_TYPE const & var );
158 
159 //------------------------------------------------------------------------------
160 template< bool DO_PACKING, typename T_FIRST, typename T_SECOND >
162 Pack( buffer_unit_type * & buffer,
163  std::pair< T_FIRST, T_SECOND > const & var );
164 
165 //------------------------------------------------------------------------------
166 template< bool DO_PACKING, typename T >
168 Pack( buffer_unit_type * & buffer,
169  InterObjectRelation< T > const & var );
170 
171 //------------------------------------------------------------------------------
172 // fallthrough-implementation
173 template< bool DO_PACKING, typename T >
174 typename std::enable_if< !is_packable< T >, localIndex >::type
175 Pack( buffer_unit_type * & GEOSX_UNUSED_PARAM( buffer ),
176  T const & GEOSX_UNUSED_PARAM( var ) )
177 {
178  GEOSX_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable." );
179  return 0;
180 }
181 
182 //------------------------------------------------------------------------------
183 // PackArray(buffer,var,length)
184 //------------------------------------------------------------------------------
185 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
186 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
187 PackPointer( buffer_unit_type * & buffer,
188  T const * const GEOSX_RESTRICT var,
189  INDEX_TYPE const length );
190 
191 //------------------------------------------------------------------------------
192 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
193 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
194 PackPointer( buffer_unit_type * & buffer,
195  T const * const GEOSX_RESTRICT var,
196  INDEX_TYPE const length );
197 
198 //------------------------------------------------------------------------------
199 template< bool DO_PACKING, typename T, typename INDEX_TYPE, int USD >
200 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
201 PackArray( buffer_unit_type * & buffer,
202  arraySlice1d< T, USD > const & var,
203  INDEX_TYPE const length );
204 
205 //------------------------------------------------------------------------------
206 template< bool DO_PACKING, typename T, typename INDEX_TYPE, int USD >
207 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
208 PackArray( buffer_unit_type * & buffer,
209  arraySlice1d< T, USD > const & var,
210  INDEX_TYPE const length );
211 
212 //------------------------------------------------------------------------------
213 // PackByIndex(buffer,var,indices)
214 //------------------------------------------------------------------------------
215 template< bool DO_PACKING, typename T, int NDIM, int USD, typename T_indices >
216 typename std::enable_if< is_packable< T >, localIndex >::type
217 PackByIndex( buffer_unit_type * & buffer,
218  ArrayView< T, NDIM, USD > const & var,
219  const T_indices & indices );
220 
221 //------------------------------------------------------------------------------
222 template< bool DO_PACKING, typename T, typename T_indices >
223 localIndex PackByIndex( buffer_unit_type * & buffer,
224  ArrayOfArrays< T > const & var,
225  T_indices const & indices );
226 
227 //------------------------------------------------------------------------------
228 template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES >
229 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
230 PackByIndex( buffer_unit_type * & buffer,
231  MAP_TYPE const & var,
232  T_INDICES const & indices );
233 
234 //------------------------------------------------------------------------------
235 template< bool DO_PACKING, typename T, typename T_INDICES >
236 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >, localIndex >::type
237 PackByIndex( buffer_unit_type * & GEOSX_UNUSED_PARAM( buffer ),
238  T const & GEOSX_UNUSED_PARAM( var ),
239  T_INDICES const & GEOSX_UNUSED_PARAM( indices ) )
240 {
241  GEOSX_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable by index." );
242  return 0;
243 }
244 
245 //------------------------------------------------------------------------------
246 // Unpack(buffer,var)
247 //------------------------------------------------------------------------------
248 template< typename T >
249 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
250 Unpack( buffer_unit_type const * & buffer,
251  T & var );
252 
253 //------------------------------------------------------------------------------
254 inline
256 Unpack( buffer_unit_type const * & buffer,
257  string & var );
258 
259 //------------------------------------------------------------------------------
260 template< typename T >
261 typename std::enable_if< traits::is_tensorT< T >, localIndex >::type
262 Unpack( buffer_unit_type const * & buffer,
263  T & var );
264 
265 //------------------------------------------------------------------------------
266 template< typename T >
268 Unpack( buffer_unit_type const * & buffer,
269  SortedArray< T > & var );
270 
271 //------------------------------------------------------------------------------
272 template< typename T, int NDIM, typename PERMUTATION >
273 typename std::enable_if< is_packable< T >, localIndex >::type
274 Unpack( buffer_unit_type const * & buffer,
276 
277 //------------------------------------------------------------------------------
278 template< typename T >
279 localIndex Unpack( buffer_unit_type const * & buffer,
280  ArrayOfArrays< T > & var );
281 
282 //------------------------------------------------------------------------------
283 template< typename T >
284 localIndex Unpack( buffer_unit_type const * & buffer,
285  ArrayOfSets< T > & var );
286 
287 //------------------------------------------------------------------------------
288 template< typename MAP_TYPE >
289 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
290 Unpack( buffer_unit_type const * & buffer,
291  MAP_TYPE & map );
292 
293 //------------------------------------------------------------------------------
294 template< typename T_FIRST, typename T_SECOND >
296 Unpack( buffer_unit_type const * & buffer,
297  std::pair< T_FIRST, T_SECOND > & var );
298 
299 //------------------------------------------------------------------------------
300 template< typename T >
302 Unpack( buffer_unit_type const * & buffer,
303  InterObjectRelation< T > & var );
304 
305 //------------------------------------------------------------------------------
306 template< typename T >
307 typename std::enable_if< !is_packable< T >, localIndex >::type
308 Unpack( buffer_unit_type const * & GEOSX_UNUSED_PARAM( buffer ),
309  T & GEOSX_UNUSED_PARAM( var ) )
310 {
311  GEOSX_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable." );
312  return 0;
313 }
314 
315 //------------------------------------------------------------------------------
316 // UnpackArray(buffer,var,expectedLength)
317 //------------------------------------------------------------------------------
318 template< typename T, typename INDEX_TYPE >
319 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
320 UnpackPointer( buffer_unit_type const * & buffer,
321  T * const GEOSX_RESTRICT var,
322  INDEX_TYPE const expectedLength );
323 
324 //------------------------------------------------------------------------------
325 template< typename T, typename INDEX_TYPE >
326 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
327 UnpackPointer( buffer_unit_type const * & buffer,
328  T * const GEOSX_RESTRICT var,
329  INDEX_TYPE const expectedLength );
330 
331 //------------------------------------------------------------------------------
332 template< typename T, typename INDEX_TYPE, int USD >
333 typename std::enable_if< std::is_trivial< T >::value, localIndex >::type
334 UnpackArray( buffer_unit_type const * & buffer,
335  arraySlice1d< T, USD > const & var,
336  INDEX_TYPE const length );
337 
338 //------------------------------------------------------------------------------
339 template< typename T, typename INDEX_TYPE, int USD >
340 typename std::enable_if< !std::is_trivial< T >::value, localIndex >::type
341 UnpackArray( buffer_unit_type const * & buffer,
342  arraySlice1d< T, USD > const & var,
343  INDEX_TYPE const length );
344 
345 //------------------------------------------------------------------------------
346 // UnpackByIndex(buffer,var,indices)
347 //------------------------------------------------------------------------------
348 template< typename T, int NDIM, int USD, typename T_indices >
350 UnpackByIndex( buffer_unit_type const * & buffer,
352  const T_indices & indices );
353 
354 //------------------------------------------------------------------------------
355 template< typename T, typename T_indices >
357 UnpackByIndex( buffer_unit_type const * & buffer,
358  ArrayOfArrays< T > & var,
359  T_indices const & indices );
360 
361 //------------------------------------------------------------------------------
362 template< typename MAP_TYPE, typename T_INDICES >
363 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
364 UnpackByIndex( buffer_unit_type const * & buffer,
365  MAP_TYPE & map,
366  T_INDICES const & indices );
367 
368 //------------------------------------------------------------------------------
369 template< typename T, typename T_INDICES >
370 typename std::enable_if< !is_packable_by_index< T > && !is_map_packable_by_index< T >, localIndex >::type
371 UnpackByIndex( buffer_unit_type const * & GEOSX_UNUSED_PARAM( buffer ),
372  T & GEOSX_UNUSED_PARAM( var ),
373  T_INDICES const & GEOSX_UNUSED_PARAM( indices ) )
374 {
375  GEOSX_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable by index." );
376  return 0;
377 }
378 
379 //------------------------------------------------------------------------------
380 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
381 localIndex Pack( buffer_unit_type * & buffer,
382  T const * const GEOSX_RESTRICT var,
383  arraySlice1d< INDEX_TYPE const > const & indices,
384  INDEX_TYPE const length );
385 
386 //------------------------------------------------------------------------------
387 template< typename T, typename INDEX_TYPE >
388 localIndex Unpack( buffer_unit_type const * & buffer,
389  T * const GEOSX_RESTRICT var,
390  arraySlice1d< INDEX_TYPE const > const & indices,
391  INDEX_TYPE & length );
392 
393 //------------------------------------------------------------------------------
394 template< bool DO_PACKING, int USD >
395 localIndex Pack( buffer_unit_type * & buffer,
396  SortedArray< localIndex > const & var,
397  SortedArray< globalIndex > const & unmappedGlobalIndices,
398  arraySlice1d< globalIndex const, USD > const & localToGlobal );
399 
400 //------------------------------------------------------------------------------
401 template< typename SORTED >
402 inline localIndex Unpack( buffer_unit_type const * & buffer,
404  SortedArray< globalIndex > & unmappedGlobalIndices,
405  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap,
406  bool const clearExistingSet );
407 
408 //------------------------------------------------------------------------------
409 template< typename T >
411 Pack( buffer_unit_type * & buffer,
412  ArrayOfSets< T > const & var );
413 
414 //------------------------------------------------------------------------------
415 template< typename T >
417 Unpack( buffer_unit_type const * & buffer,
418  ArrayOfSets< T > & var );
419 
420 
421 //------------------------------------------------------------------------------
422 template< bool DO_PACKING, int USD >
424 Pack( buffer_unit_type * & buffer,
426  globalIndex const * const unmappedGlobalIndices,
427  localIndex const length,
428  arraySlice1d< globalIndex const > const & localToGlobalMap );
429 
430 //------------------------------------------------------------------------------
431 template< typename SORTED >
432 inline localIndex Unpack( buffer_unit_type const * & buffer,
433  localIndex_array & var,
434  array1d< globalIndex > & unmappedGlobalIndices,
435  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
436 
437 //------------------------------------------------------------------------------
438 inline localIndex UnpackSyncList( buffer_unit_type const * & buffer,
439  localIndex_array & var,
440  std::unordered_map< globalIndex, localIndex > const & globalToLocalMap );
441 
442 //------------------------------------------------------------------------------
443 template< typename SORTED, int USD >
444 inline
446 Unpack( buffer_unit_type const * & buffer,
448  array1d< globalIndex > & unmappedGlobalIndices,
449  localIndex const expectedLength,
450  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
451 
452 //------------------------------------------------------------------------------
453 template< bool DO_PACKING >
455 Pack( buffer_unit_type * & buffer,
457  arrayView1d< localIndex const > const & indices,
458  arrayView1d< globalIndex const > const & localToGlobalMap,
459  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
460 
461 //------------------------------------------------------------------------------
462 template< typename SORTED0, typename SORTED1 >
463 inline
465 Unpack( buffer_unit_type const * & buffer,
466  arrayView1d< localIndex > const & var,
467  array1d< localIndex > const & indices,
468  mapBase< globalIndex, localIndex, SORTED0 > const & globalToLocalMap,
469  mapBase< globalIndex, localIndex, SORTED1 > const & relatedObjectGlobalToLocalMap );
470 
471 
472 //------------------------------------------------------------------------------
473 template< bool DO_PACKING, typename SORTED >
475 Pack( buffer_unit_type * & buffer,
476  arrayView1d< arrayView1d< localIndex const > const > const & var,
477  mapBase< localIndex, array1d< globalIndex >, SORTED > const & unmappedGlobalIndices,
478  arrayView1d< localIndex const > const & indices,
479  arrayView1d< globalIndex const > const & localToGlobalMap,
480  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
481 
482 //------------------------------------------------------------------------------
483 template< typename SORTED0, typename SORTED1, typename SORTED2 >
484 inline
486 Unpack( buffer_unit_type const * & buffer,
488  array1d< localIndex > & indices,
489  mapBase< localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
490  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
491  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap );
492 
493 //------------------------------------------------------------------------------
494 template< bool DO_PACKING, typename SORTED >
496 Pack( buffer_unit_type * & buffer,
497  arrayView1d< SortedArray< localIndex > const > const & var,
498  mapBase< localIndex, SortedArray< globalIndex >, SORTED > const & unmappedGlobalIndices,
499  arrayView1d< localIndex const > const & indices,
500  arrayView1d< globalIndex const > const & localToGlobalMap,
501  arrayView1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
502 
503 //------------------------------------------------------------------------------
504 template< typename SORTED0, typename SORTED1, typename SORTED2 >
505 inline
507 Unpack( buffer_unit_type const * & buffer,
509  localIndex_array & indices,
510  mapBase< localIndex, SortedArray< globalIndex >, SORTED0 > & unmappedGlobalIndices,
511  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
512  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap,
513  bool const clearFlag );
514 
515 //------------------------------------------------------------------------------
516 template< bool DO_PACKING, int USD0, int USD1 >
518 Pack( buffer_unit_type * & buffer,
520  arrayView1d< localIndex > const & indices,
521  arraySlice1d< globalIndex const, USD1 > const & localToGlobalMap );
522 
523 //------------------------------------------------------------------------------
524 template< typename SORTED, int USD >
525 inline
527 Unpack( buffer_unit_type const * & buffer,
528  arrayView2d< localIndex, USD > const & var,
529  array1d< localIndex > & indices,
530  mapBase< globalIndex, localIndex, SORTED > const & globalToLocalMap );
531 
532 //------------------------------------------------------------------------------
533 template< bool DO_PACKING, typename SORTED, int USD0 >
535 Pack( buffer_unit_type * & buffer,
537  mapBase< localIndex, array1d< globalIndex >, SORTED > const & unmappedGlobalIndices,
538  arrayView1d< localIndex const > const & indices,
539  arraySlice1d< globalIndex const > const & localToGlobalMap,
540  arraySlice1d< globalIndex const > const & relatedObjectLocalToGlobalMap );
541 
542 //------------------------------------------------------------------------------
543 template< typename SORTED0, typename SORTED1, typename SORTED2, int USD >
544 inline
546 Unpack( buffer_unit_type const * & buffer,
547  arrayView2d< localIndex, USD > const & var,
548  localIndex_array & indices,
549  mapBase< localIndex, array1d< globalIndex >, SORTED0 > & unmappedGlobalIndices,
550  mapBase< globalIndex, localIndex, SORTED1 > const & globalToLocalMap,
551  mapBase< globalIndex, localIndex, SORTED2 > const & relatedObjectGlobalToLocalMap );
552 
553 //------------------------------------------------------------------------------
554 template< bool DO_PACKING, typename MAP_TYPE >
555 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
556 Pack( buffer_unit_type * & buffer, MAP_TYPE const & var );
557 
558 //------------------------------------------------------------------------------
559 template< typename MAP_TYPE >
560 typename std::enable_if< is_packable_map< MAP_TYPE >, localIndex >::type
561 Unpack( buffer_unit_type const * & buffer, MAP_TYPE & map );
562 
563 //------------------------------------------------------------------------------
564 template< bool DO_PACKING, typename MAP_TYPE, typename T_INDICES >
565 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
566 Pack( buffer_unit_type * & buffer, MAP_TYPE const & var, T_INDICES const & packIndices );
567 
568 //------------------------------------------------------------------------------
569 template< typename MAP_TYPE, typename T_INDICES >
570 typename std::enable_if< is_map_packable_by_index< MAP_TYPE >, localIndex >::type
571 Unpack( buffer_unit_type const * & buffer, MAP_TYPE & map, T_INDICES const & unpackIndices );
572 
573 //------------------------------------------------------------------------------
574 template< bool DO_PACKING, typename T_FIRST, typename T_SECOND >
576 Pack( buffer_unit_type * & buffer, std::pair< T_FIRST, T_SECOND > const & var );
577 
578 //------------------------------------------------------------------------------
579 template< typename T_FIRST, typename T_SECOND >
581 Unpack( buffer_unit_type const * & buffer, std::pair< T_FIRST, T_SECOND > & var );
582 
583 //------------------------------------------------------------------------------
584 template< bool DO_PACKING, typename T >
586 Pack( buffer_unit_type * & buffer,
587  InterObjectRelation< T > const & var );
588 
589 template< typename ... VARPACK >
591 PackSize( VARPACK const && ... pack )
592 {
593  buffer_unit_type * junk = nullptr;
594  return Pack< false >( junk, pack ... );
595 }
596 
597 template< typename ... VARPACK >
599 PackSize( VARPACK && ... pack )
600 {
601  buffer_unit_type * junk = nullptr;
602  return Pack< false >( junk, pack ... );
603 }
604 
605 #ifdef GEOSX_USE_ARRAY_BOUNDS_CHECK
606 //------------------------------------------------------------------------------
607 template< bool DO_PACKING, typename T, typename T_INDICES >
608 typename std::enable_if< !is_packable_by_index< T > &&
609  !is_map_packable_by_index< T >, localIndex >::type
610 Pack( buffer_unit_type * & GEOSX_UNUSED_PARAM( buffer ), T const & GEOSX_UNUSED_PARAM( var ), T_INDICES const & GEOSX_UNUSED_PARAM( indices ) )
611 {
612  GEOSX_ERROR( "Trying to pack data type ("<<typeid(T).name()<<") but type is not packable by index." );
613  return 0;
614 }
615 
616 //------------------------------------------------------------------------------
617 template< typename T, typename T_INDICES >
618 typename std::enable_if< !is_packable_by_index< T > &&
619  !is_map_packable_by_index< T >, localIndex >::type
620 Unpack( buffer_unit_type const * & GEOSX_UNUSED_PARAM( buffer ), T & GEOSX_UNUSED_PARAM( var ), T_INDICES const & GEOSX_UNUSED_PARAM( indices ) )
621 {
622  GEOSX_ERROR( "Trying to unpack data type ("<<typeid(T).name()<<") but type is not packable by index." );
623  return 0;
624 }
625 
626 //------------------------------------------------------------------------------
627 template< bool DO_PACKING, typename T, typename INDEX_TYPE >
629 Pack( buffer_unit_type * & buffer,
630  arraySlice1d< T > const & var,
631  arraySlice1d< INDEX_TYPE > const & indices,
632  INDEX_TYPE const length );
633 
634 //------------------------------------------------------------------------------
635 template< typename T, typename INDEX_TYPE >
637 Unpack( buffer_unit_type const * & buffer,
638  arraySlice1d< T > & var,
639  arraySlice1d< INDEX_TYPE > const & indices,
640  INDEX_TYPE & length );
641 
642 #endif /* GEOSX_USE_ARRAY_BOUNDS_CHECK */
643 
644 } /* namespace bufferOps */
645 } /* namespace geosx */
646 
647 #include "BufferOps_inline.hpp"
648 
649 #endif /* GEOSX_DATAREPOSITORY_BUFFEROPS_HPP_ */
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
Definition: DataTypes.hpp:128
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
This class provides an interface similar to an std::set.
Definition: SortedArray.hpp:35
Base template for ordered and unordered maps.
Definition: DataTypes.hpp:349
Contains portable access to std::numeric_limits and functions for converting between integral types...
This class implements an array of arrays like object with contiguous storage.
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:146
#define GEOSX_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:110
This class implements an array of sets like object with contiguous storage.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
#define GEOSX_RESTRICT
preprocessor variable for the C99 restrict keyword for use with pointers
Definition: GeosxMacros.hpp:95
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55
#define GEOSX_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
Definition: GeosxMacros.hpp:66