20 #ifndef GEOS_DATAREPOSITORY_WRAPPERHELPERS_HPP_
21 #define GEOS_DATAREPOSITORY_WRAPPERHELPERS_HPP_
25 #define RESTART_TYPE_LOGGING 0
28 #include "BufferOps.hpp"
29 #include "BufferOpsDevice.hpp"
35 #include "codingUtilities/traits.hpp"
36 #include "LvArray/src/system.hpp"
38 #if defined(GEOS_USE_PYGEOSX)
39 #include "LvArray/src/python/python.hpp"
43 #include <conduit.hpp>
48 #if RESTART_TYPE_LOGGING
49 #include <unordered_set>
54 namespace dataRepository
56 namespace wrapperHelpers
61 inline void logOutputType(
string const & typeString,
string const & msg )
63 #if RESTART_TYPE_LOGGING
64 static std::unordered_set< string > m_types;
66 if( !m_types.count( typeString ) )
68 m_types.insert( typeString );
77 template<
typename T,
typename ... INDICES >
78 string getIndicesToComponent( T
const &,
int const component, INDICES
const ... existingIndices )
81 return LvArray::indexing::getIndexString( existingIndices ... );
84 template<
typename ... INDICES >
85 string getIndicesToComponent(
R1Tensor const &,
int const component, INDICES
const ... existingIndices )
86 {
return LvArray::indexing::getIndexString( existingIndices ..., component ); }
88 template<
typename T >
89 T
const * getPointerToComponent( T
const & var,
int const component )
96 real64 const * getPointerToComponent(
R1Tensor const & var,
int const component )
99 return &var[ component ];
104 template<
typename T >
109 void set(
integer const, Span< string const > )
111 GEOS_ERROR(
"Dimension labels are only available in Array wrappers" );
114 Span< string const > get(
integer const )
const
116 GEOS_ERROR(
"Dimension labels are only available in Array wrappers" );
121 template<
typename T,
int NDIM,
typename PERM >
122 class ArrayDimLabels<
Array< T, NDIM, PERM > >
126 void set(
integer const dim, Span< string const > labels )
130 m_values[dim].resize( labels.size() );
131 std::copy( labels.begin(), labels.end(), m_values[dim].begin() );
134 Span< string const > get(
integer const dim )
const
138 return { m_values[dim].begin(), m_values[dim].end() };
146 template<
typename T >
147 inline std::enable_if_t< traits::HasMemberFunction_size< T >,
size_t >
148 size( T
const & value )
149 {
return value.size(); }
151 template<
typename T >
152 inline std::enable_if_t< !traits::HasMemberFunction_size< T >,
size_t >
158 dataPtr(
string & var )
159 {
return const_cast< char *
>( var.data() ); }
162 dataPtr( Path & var )
163 {
return const_cast< char *
>( var.data() ); }
165 template<
typename T >
166 inline std::enable_if_t< traits::HasMemberFunction_data< T >,
typename traits::Pointer< T > >
168 {
return value.data(); }
170 template<
typename T >
171 inline std::enable_if_t< !traits::HasMemberFunction_data< T >,
typename traits::Pointer< T > >
176 inline typename traits::ConstPointer< T >
177 dataPtr( T
const & value )
178 {
return dataPtr(
const_cast< T &
>( value ) ); }
181 template<
typename T >
182 inline std::enable_if_t< traits::HasMemberFunction_resize< T > >
184 { value.resize( newSize ); }
186 template<
typename T >
187 inline std::enable_if_t< !traits::HasMemberFunction_resize< T > >
192 template<
typename T >
194 resizeDefault( T & value,
196 DefaultValue< T >
const & defaultValue,
198 { value.resizeDefault( newSize, defaultValue.value ); }
202 template<
typename T,
int NDIM,
typename PERMUTATION >
204 resizeDimensions( Array< T, NDIM, PERMUTATION > & value,
int num_dims,
localIndex const *
const dims )
205 { value.resize( num_dims, dims ); }
207 template<
typename T >
209 resizeDimensions( T & value,
int num_dims,
localIndex const *
const dims )
216 resize( value, dims[ 0 ] );
220 template<
typename T >
223 {
return sizeof( *dataPtr( std::declval< T >() ) ); }
226 template<
typename T >
228 byteSize( T
const & value )
229 {
return wrapperHelpers::size( value ) * byteSizeOfElement< T >(); }
232 template<
typename T >
234 numElementsFromByteSize(
localIndex const byteSize )
237 return byteSize / byteSizeOfElement< T >();
244 template<
typename T >
245 std::enable_if_t< traits::HasMemberFunction_reserveValues< T const > >
246 reserveValuesIfAvailable( T & value,
localIndex const newCapacity )
249 double const oldValueCapacity = value.valueCapacity();
250 localIndex const newValueCapacity = oldValueCapacity * newCapacity / oldCapacity;
251 value.reserveValues( newValueCapacity );
254 template<
typename T >
255 std::enable_if_t< !traits::HasMemberFunction_reserveValues< T const > >
256 reserveValuesIfAvailable( T &,
localIndex const )
261 template<
typename T >
262 std::enable_if_t< traits::HasMemberFunction_reserve< T > >
263 reserve( T & value,
localIndex const newCapacity )
265 value.reserve( newCapacity );
266 detail::reserveValuesIfAvailable( value, newCapacity );
269 template<
typename T,
271 typename PERMUTATION >
272 void reserve( Array< T, NDIM, PERMUTATION > & value,
localIndex newCapacity )
275 for(
int i=1; i<NDIM; ++i )
277 newCapacity *= dims[ i ];
279 value.reserve( newCapacity );
282 template<
typename T >
283 std::enable_if_t< !traits::HasMemberFunction_reserve< T > >
288 template<
typename T >
289 std::enable_if_t< traits::HasMemberFunction_capacity< T const >,
localIndex >
290 capacity( T
const & value )
291 {
return value.capacity(); }
293 template<
typename T >
294 std::enable_if_t< !traits::HasMemberFunction_capacity< T const >,
localIndex >
295 capacity( T
const & value )
296 {
return wrapperHelpers::size( value ); }
300 template<
typename T >
301 std::enable_if_t< traits::HasMemberFunction_setName< T > >
302 setName( T & value,
string const & name )
303 { value.setName( name ); }
305 template<
typename T >
306 std::enable_if_t< !traits::HasMemberFunction_setName< T > >
310 template<
typename T >
311 std::enable_if_t< traits::HasMemberFunction_move< T > >
312 move( T & value, LvArray::MemorySpace
const space,
bool const touch )
313 { value.move( space, touch ); }
315 template<
typename T >
316 std::enable_if_t< !traits::HasMemberFunction_move< T > >
323 template<
typename T >
324 std::enable_if_t< !bufferOps::can_memcpy< typename traits::Pointer< T > > >
325 pushDataToConduitNode( T
const & var, conduit::Node & node )
327 internal::logOutputType( LvArray::system::demangleType( var ),
"Packing for output: " );
330 localIndex const byteSize = bufferOps::PackSize( var );
333 conduit::DataType
const dtype( conduitTypeInfo< buffer_unit_type >::id, byteSize );
336 conduit::Node & valuesNode = node[
"__values__" ];
337 valuesNode.set( dtype );
341 bufferOps::Pack< true >( buffer, var );
345 template<
typename T >
346 std::enable_if_t< !bufferOps::can_memcpy< typename traits::Pointer< T > > >
347 pullDataFromConduitNode( T & var, conduit::Node
const & node )
349 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
352 localIndex const byteSize = valuesNode.dtype().number_of_elements();
356 localIndex const bytesRead = bufferOps::Unpack( buffer, var );
363 pushDataToConduitNode(
string const & var, conduit::Node & node )
365 internal::logOutputType( LvArray::system::demangleType( var ),
"Output via external pointer: " );
367 constexpr
int conduitTypeID = conduitTypeInfo< signed char >::id;
368 conduit::DataType
const dtype( conduitTypeID, var.size() );
370 signed char *
const ptr =
const_cast< signed char *
>(
reinterpret_cast< signed char const *
>( var.data() ) );
371 node[
"__values__" ].set_external( dtype, ptr );
377 pushDataToConduitNode( Path
const & var, conduit::Node & node )
379 pushDataToConduitNode(
static_cast< string const &
>(var), node );
383 template<
typename T >
384 std::enable_if_t< bufferOps::can_memcpy< typename traits::Pointer< T > > >
385 pushDataToConduitNode( T
const & var, conduit::Node & node )
387 internal::logOutputType( LvArray::system::demangleType( var ),
"Output via external pointer: " );
389 constexpr
int conduitTypeID = conduitTypeInfo< typename traits::Pointer< T > >::id;
390 constexpr
int sizeofConduitType = conduitTypeInfo< typename traits::Pointer< T > >::sizeOfConduitType;
392 conduit::DataType
const dtype( conduitTypeID, numBytes / sizeofConduitType );
394 void *
const ptr =
const_cast< void *
>(
static_cast< void const *
>( dataPtr( var ) ) );
395 node[
"__values__" ].set_external( dtype, ptr );
399 template<
typename T >
400 std::enable_if_t< bufferOps::can_memcpy< typename traits::Pointer< T > > >
401 pullDataFromConduitNode( T & var, conduit::Node
const & node )
403 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
405 localIndex const byteSize = LvArray::integerConversion< localIndex >( valuesNode.dtype().strided_bytes() );
406 localIndex const numElements = numElementsFromByteSize< T >( byteSize );
408 resize( var, numElements );
410 std::memcpy( dataPtr( var ), valuesNode.data_ptr(), byteSize );
414 template<
typename T >
415 std::enable_if_t< bufferOps::can_memcpy< T > >
416 pullDataFromConduitNode( SortedArray< T > & var, conduit::Node
const & node )
418 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
420 localIndex const byteSize = LvArray::integerConversion< localIndex >( valuesNode.dtype().strided_bytes() );
421 localIndex const numElements = numElementsFromByteSize< T >( byteSize );
423 T
const *
const values =
reinterpret_cast< T
const *
>( valuesNode.data_ptr() );
424 var.insert( values, values + numElements );
429 template<
typename T,
int NDIM,
typename PERMUTATION >
430 std::enable_if_t< bufferOps::can_memcpy< T > >
431 pushDataToConduitNode( Array< T, NDIM, PERMUTATION >
const & var,
432 conduit::Node & node )
434 internal::logOutputType( LvArray::system::demangleType( var ),
"Output array via external pointer: " );
437 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
438 constexpr
int sizeofConduitType = conduitTypeInfo< T >::sizeOfConduitType;
439 conduit::DataType
const dtype( conduitTypeID, var.size() *
sizeof( T ) / sizeofConduitType );
440 void *
const ptr =
const_cast< void *
>(
static_cast< void const *
>( var.data() ) );
441 node[
"__values__" ].set_external( dtype, ptr );
444 camp::idx_t temp[ NDIM + 1 ];
445 for(
int i = 0; i < NDIM; ++i )
447 temp[ i ] = var.size( i );
451 constexpr
int const implicitDimensionLength = conduitTypeInfo< T >::numConduitValues;
452 constexpr
bool const hasImplicitDimension = implicitDimensionLength != 1;
453 constexpr
int totalNumDimensions = NDIM + hasImplicitDimension;
454 if( hasImplicitDimension )
456 temp[ NDIM ] = implicitDimensionLength;
460 conduit::DataType
const dimensionType( conduitTypeInfo< camp::idx_t >::id, totalNumDimensions );
461 node[
"__dimensions__" ].set( dimensionType, temp );
464 constexpr std::array< camp::idx_t, NDIM >
const perm =
to_stdArray( RAJA::as_array< PERMUTATION >::get());
465 for(
int i = 0; i < NDIM; ++i )
467 temp[ i ] = perm[ i ];
470 if( hasImplicitDimension )
475 node[
"__permutation__" ].set( dimensionType, temp );
479 template<
typename T,
int NDIM,
typename PERMUTATION >
480 std::enable_if_t< bufferOps::can_memcpy< T > >
481 pullDataFromConduitNode( Array< T, NDIM, PERMUTATION > & var,
482 conduit::Node
const & node )
485 constexpr
int const implicitDimensionLength = conduitTypeInfo< T >::numConduitValues;
486 constexpr
bool const hasImplicitDimension = implicitDimensionLength != 1;
487 constexpr
int totalNumDimensions = NDIM + hasImplicitDimension;
490 conduit::Node
const & permutationNode = node.fetch_existing(
"__permutation__" );
491 GEOS_ERROR_IF_NE( permutationNode.dtype().number_of_elements(), totalNumDimensions );
493 constexpr std::array< camp::idx_t, NDIM >
const perm =
to_stdArray( RAJA::as_array< PERMUTATION >::get());
494 camp::idx_t
const *
const permFromConduit = permutationNode.value();
495 for(
int i = 0; i < NDIM; ++i )
498 "The permutation of the data in conduit and the provided Array don't match." );
501 if( hasImplicitDimension )
504 "The permutation of the data in conduit and the provided Array don't match." );
508 conduit::Node
const & dimensionNode = node.fetch_existing(
"__dimensions__" );
509 GEOS_ERROR_IF_NE( dimensionNode.dtype().number_of_elements(), totalNumDimensions );
510 camp::idx_t
const *
const dims = dimensionNode.value();
512 if( hasImplicitDimension )
517 var.resize( NDIM, dims );
520 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
521 localIndex numBytesFromArray = var.size() *
sizeof( T );
523 std::memcpy( var.data(), valuesNode.data_ptr(), numBytesFromArray );
528 template<
typename T,
typename INDEX_TYPE >
529 std::enable_if_t< bufferOps::can_memcpy< T > >
530 pushDataToConduitNode( ArrayOfArrays< T, INDEX_TYPE >
const & var2,
531 conduit::Node & node )
533 ArrayOfArraysView< T const, INDEX_TYPE >
const & var = var2.toViewConst();
534 internal::logOutputType( LvArray::system::demangleType( var ),
"Output array via external pointer: " );
537 INDEX_TYPE
const numArrays = var.size();
538 conduit::DataType
const numArraysType( conduitTypeInfo< INDEX_TYPE >::id, 1 );
539 node[
"__numberOfArrays__" ].set( numArraysType,
const_cast< void *
>(
static_cast< void const *
>(&numArrays) ) );
542 INDEX_TYPE
const *
const offsets = var.getOffsets();
543 conduit::DataType
const offsetsType( conduitTypeInfo< INDEX_TYPE >::id, numArrays+1 );
544 node[
"__offsets__" ].set_external( offsetsType,
const_cast< void *
>(
static_cast< void const *
>( offsets ) ) );
547 INDEX_TYPE
const *
const sizes = var.getSizes();
548 conduit::DataType
const sizesType( conduitTypeInfo< INDEX_TYPE >::id, numArrays );
549 node[
"__sizes__" ].set_external( sizesType,
const_cast< void *
>(
static_cast< void const *
>( sizes ) ) );
552 T *
const values =
const_cast< T *
>(var.getValues());
553 for( INDEX_TYPE i = 0; i < numArrays; ++i )
555 INDEX_TYPE
const curOffset = offsets[ i ];
556 INDEX_TYPE
const nextOffset = offsets[ i + 1 ];
557 for( INDEX_TYPE j = curOffset + var.sizeOfArray( i ); j < nextOffset; ++j )
559 if constexpr ( std::is_arithmetic< T >::value )
570 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
571 constexpr
int sizeofConduitType = conduitTypeInfo< T >::sizeOfConduitType;
572 conduit::DataType
const dtype( conduitTypeID, offsets[numArrays] *
sizeof( T ) / sizeofConduitType );
575 node[
"__values__" ].set_external( dtype, values );
578 template<
typename T,
typename INDEX_TYPE >
579 std::enable_if_t< bufferOps::can_memcpy< T > >
580 pullDataFromConduitNode( ArrayOfArrays< T, INDEX_TYPE > & var,
581 conduit::Node
const & node )
585 conduit::Node
const & numArraysNode = node.fetch_existing(
"__numberOfArrays__" );
586 INDEX_TYPE
const *
const numArrays = numArraysNode.value();
589 conduit::Node
const & offsetsNode = node.fetch_existing(
"__offsets__" );
590 conduit::DataType
const & offsetsDataType = offsetsNode.dtype();
591 INDEX_TYPE
const *
const offsets = offsetsNode.value();
592 INDEX_TYPE
const sizeOffsets = offsetsDataType.number_of_elements();
595 conduit::Node
const & sizesNode = node.fetch_existing(
"__sizes__" );
596 conduit::DataType
const & sizesDataType = sizesNode.dtype();
597 INDEX_TYPE
const *
const sizes = sizesNode.value();
598 INDEX_TYPE
const sizeSizes = sizesDataType.number_of_elements();
605 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
606 conduit::DataType
const & valuesDataType = valuesNode.dtype();
607 const INDEX_TYPE valuesSize = valuesDataType.number_of_elements();
610 INDEX_TYPE
const arraySizeEstimate = (*numArrays)==0 ? 0 : valuesSize / (*numArrays);
611 var.resize( *numArrays, arraySizeEstimate );
612 var.reserveValues( valuesSize );
616 for( INDEX_TYPE i = 0; i < *numArrays; ++i )
618 INDEX_TYPE
const arrayAllocation = offsets[i+1] - offsets[i];
619 var.setCapacityOfArray( i, arrayAllocation );
620 var.resizeArray( i, sizes[ i ] );
621 allocatedSize += arrayAllocation;
631 ArrayOfArraysView< T const, INDEX_TYPE >
const & varView = var.toViewConst();
632 INDEX_TYPE
const *
const varOffsets = varView.getOffsets();
633 INDEX_TYPE
const *
const varSizes = varView.getSizes();
639 for( INDEX_TYPE i = 0; i<*numArrays; ++i )
646 localIndex numBytesFromArray = allocatedSize *
sizeof( T );
648 std::memcpy(
const_cast< T *
>(varView.getValues()), valuesNode.data_ptr(), numBytesFromArray );
653 template<
typename T >
654 void pushDataToConduitNode( InterObjectRelation< T >
const & var,
655 conduit::Node & node )
656 {
return pushDataToConduitNode( var.base(), node ); }
658 template<
typename T >
659 void pullDataFromConduitNode( InterObjectRelation< T > & var,
660 conduit::Node
const & node )
661 {
return pullDataFromConduitNode( var.base(), node ); }
665 template<
typename T,
int NDIM,
int USD >
666 std::enable_if_t< std::is_arithmetic< T >::value || traits::is_tensorT< T > >
667 addBlueprintField( ArrayView< T const, NDIM, USD >
const & var,
668 conduit::Node & fields,
669 string const & fieldName,
670 string const & topology,
671 stdVector< string >
const & componentNames )
675 using ConduitType =
typename conduitTypeInfo< T >::type;
676 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
677 constexpr
int numComponentsPerValue = conduitTypeInfo< T >::numConduitValues;
679 localIndex const totalNumberOfComponents = numComponentsPerValue * var.size() / var.size( 0 );
680 if( !componentNames.empty() )
685 var.move( hostMemorySpace,
false );
687 conduit::DataType dtype( conduitTypeID, var.size( 0 ) );
688 dtype.set_stride(
sizeof( ConduitType ) * numComponentsPerValue * var.strides()[ 0 ] );
691 LvArray::forValuesInSliceWithIndices( var[ 0 ], [&fields, &fieldName, &topology, &componentNames, totalNumberOfComponents, &dtype, &curComponent]
692 ( T
const & val,
auto const ... indices )
694 for(
int i = 0; i < numComponentsPerValue; ++i )
697 if( totalNumberOfComponents == 1 )
701 else if( componentNames.empty() )
703 string indexString = internal::getIndicesToComponent( val, i, indices ... );
704 indexString.erase( indexString.begin() );
705 indexString.pop_back();
706 indexString.pop_back();
707 name = fieldName + indexString;
711 name = componentNames[ curComponent++ ];
714 conduit::Node & field = fields[ name ];
715 field[
"association" ] =
"element";
716 field[
"volume_dependent" ] =
"false";
717 field[
"topology" ] = topology;
719 void const * pointer = internal::getPointerToComponent( val, i );
720 field[
"values" ].set_external( dtype,
const_cast< void *
>( pointer ) );
725 template<
typename T >
726 void addBlueprintField( T
const &,
727 conduit::Node & fields,
730 stdVector< string >
const & )
732 GEOS_ERROR( GEOS_FMT(
"Cannot create a mcarray out of {}\nWas trying to write it to {}",
733 LvArray::system::demangleType< T >(),
738 template<
typename T,
int NDIM,
int USD >
739 std::enable_if_t< std::is_arithmetic< T >::value || traits::is_tensorT< T > >
740 populateMCArray( ArrayView< T const, NDIM, USD >
const & var,
741 conduit::Node & node,
742 stdVector< string >
const & componentNames )
746 using ConduitType =
typename conduitTypeInfo< T >::type;
747 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
748 constexpr
int numComponentsPerValue = conduitTypeInfo< T >::numConduitValues;
750 if( !componentNames.empty() )
755 var.move( hostMemorySpace,
false );
757 conduit::DataType dtype( conduitTypeID, var.size( 0 ) );
758 dtype.set_stride(
sizeof( ConduitType ) * numComponentsPerValue * var.strides()[ 0 ] );
761 LvArray::forValuesInSliceWithIndices( var[ 0 ], [&componentNames, &node, &dtype, &curComponent]
762 ( T
const & val,
auto const ... indices )
764 for(
int i = 0; i < numComponentsPerValue; ++i )
766 string const name = componentNames.empty() ? internal::getIndicesToComponent( val, i, indices ... ) :
767 componentNames[ curComponent++ ];
769 void const * pointer = internal::getPointerToComponent( val, i );
770 node[ name ].set_external( dtype,
const_cast< void *
>( pointer ) );
775 template<
typename T >
776 void populateMCArray( T
const &,
777 conduit::Node & node,
778 stdVector< string >
const & )
780 GEOS_ERROR( GEOS_FMT(
"Cannot create a mcarray out of {}\nWas trying to write it to {}",
781 LvArray::system::demangleType< T >(),
786 template<
typename T >
787 std::enable_if_t< std::is_arithmetic< T >::value, std::unique_ptr< Array< T, 1 > > >
788 averageOverSecondDim( ArrayView< T const, 1, 0 >
const & var )
790 std::unique_ptr< Array< T, 1 > > ret = std::make_unique< Array< T, 1 > >();
792 ret->resize( var.size() );
793 ret->template setValues< serialPolicy >( var );
798 template<
typename T,
int NDIM,
int USD >
799 std::enable_if_t< std::is_arithmetic< T >::value, std::unique_ptr<
Array< T, NDIM - 1 > > >
800 averageOverSecondDim( ArrayView< T const, NDIM, USD >
const & var )
802 std::unique_ptr<
Array< T, NDIM - 1 > > ret = std::make_unique<
Array< T, NDIM - 1 > >();
805 newDims[ 0 ] = var.size( 0 );
806 for(
int i = 2; i < NDIM; ++i )
808 newDims[ i - 1 ] = var.size( i );
811 ret->resize( NDIM - 1, newDims );
813 ArrayView< T, NDIM - 1 >
const & output = *ret;
816 forAll< serialPolicy >( var.size( 0 ), [var, numSamples, &output] (
localIndex const i )
818 LvArray::sumOverFirstDimension( var[ i ], output[ i ] );
820 LvArray::forValuesInSlice( output[ i ], [numSamples] ( T & val )
829 template<
typename T >
830 std::unique_ptr< int > averageOverSecondDim( T
const & )
832 GEOS_ERROR( GEOS_FMT(
"Cannot average over the second dimension of {}", LvArray::system::demangleType< T >() ) );
833 return std::unique_ptr< int >(
nullptr );
836 template<
typename T,
int NDIM,
int USD >
837 int numArrayDims( ArrayView< T const, NDIM, USD >
const &
GEOS_UNUSED_PARAM( var ) )
842 template<
typename T >
848 template<
typename T >
854 template<
typename T,
int NDIM,
int USD >
855 localIndex numArrayComp( ArrayView< T const, NDIM, USD >
const & var )
857 return LvArray::indexing::multiplyAll< NDIM - 1 >( var.dims() + 1 );
860 template<
typename T >
866 template<
typename T >
872 template<
bool DO_PACKING,
typename T,
typename IDX >
873 inline std::enable_if_t< bufferOps::is_packable_by_index< T >,
localIndex >
875 {
return bufferOps::PackByIndex< DO_PACKING >( buffer, var, idx ); }
877 template<
bool DO_PACKING,
typename T,
typename IDX >
878 inline std::enable_if_t< !bufferOps::is_packable_by_index< T >,
localIndex >
881 GEOS_ERROR( GEOS_FMT(
"Trying to pack data type ({}) by index. Operation not supported.",
882 LvArray::system::demangleType< T >() ) );
886 template<
typename T,
typename IDX >
887 inline std::enable_if_t< bufferOps::is_packable_by_index< T >,
localIndex >
889 {
return bufferOps::UnpackByIndex( buffer, var, idx ); }
891 template<
typename T,
typename IDX >
892 inline std::enable_if_t< !bufferOps::is_packable_by_index< T >,
localIndex >
895 GEOS_ERROR( GEOS_FMT(
"Trying to unpack data type ({}) by index. Operation not supported.",
896 LvArray::system::demangleType< T >() ) );
901 template<
bool DO_PACKING,
typename T >
902 inline std::enable_if_t< bufferOps::is_container< T > || bufferOps::can_memcpy< T >,
localIndex >
903 PackDevice(
buffer_unit_type * & buffer, T
const & var, parallelDeviceEvents & events )
904 {
return bufferOps::PackDevice< DO_PACKING >( buffer, var, events ); }
907 template<
bool DO_PACKING,
typename T >
908 inline std::enable_if_t< !bufferOps::is_container< T > && !bufferOps::can_memcpy< T >,
localIndex >
911 GEOS_ERROR( GEOS_FMT(
"Trying to pack data type ({}) on device. Operation not supported.",
912 LvArray::system::demangleType< T >() ) );
916 template<
bool DO_PACKING,
typename T,
typename IDX >
917 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
918 PackByIndexDevice(
buffer_unit_type * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events )
919 {
return bufferOps::PackByIndexDevice< DO_PACKING >( buffer, var, idx, events ); }
921 template<
bool DO_PACKING,
typename T,
typename IDX >
922 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
923 PackByIndexDevice(
buffer_unit_type * &, T
const &, IDX &, parallelDeviceEvents & )
925 GEOS_ERROR( GEOS_FMT(
"Trying to pack data type ({}) by index on device. Operation not supported.",
926 LvArray::system::demangleType< T >() ) );
930 template<
typename T >
931 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
932 UnpackDevice(
buffer_unit_type const * & buffer, T
const & var, parallelDeviceEvents & events )
933 {
return bufferOps::UnpackDevice( buffer, var, events ); }
935 template<
typename T >
936 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
937 UnpackDevice(
buffer_unit_type const * &, T
const &, parallelDeviceEvents & )
939 GEOS_ERROR( GEOS_FMT(
"Trying to unpack data type ({}) on device. Operation not supported.",
940 LvArray::system::demangleType< T >() ) );
944 template<
typename T,
typename IDX >
945 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
946 UnpackByIndexDevice(
buffer_unit_type const * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events, MPI_Op op=MPI_REPLACE )
947 {
return bufferOps::UnpackByIndexDevice( buffer, var, idx, events, op ); }
949 template<
typename T,
typename IDX >
950 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
951 UnpackByIndexDevice(
buffer_unit_type const * &, T &, IDX &, parallelDeviceEvents &, MPI_Op )
953 GEOS_ERROR( GEOS_FMT(
"Trying to unpack data type ({}) by index on device. Operation not supported.",
954 LvArray::system::demangleType< T >() ) );
959 template<
bool DO_PACKING,
typename T >
961 PackDataDevice(
buffer_unit_type * & buffer, T
const & var, parallelDeviceEvents & events )
962 {
return bufferOps::PackDataDevice< DO_PACKING >( buffer, var, events ); }
964 template<
bool DO_PACKING,
typename T,
typename IDX >
965 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
966 PackDataByIndexDevice(
buffer_unit_type * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events )
967 {
return bufferOps::PackDataByIndexDevice< DO_PACKING >( buffer, var, idx, events ); }
969 template<
bool DO_PACKING,
typename T,
typename IDX >
970 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
971 PackDataByIndexDevice(
buffer_unit_type * &, T
const &, IDX &, parallelDeviceEvents & )
973 GEOS_ERROR( GEOS_FMT(
"Trying to pack data type ({}) by index on device. Operation not supported.",
974 LvArray::system::demangleType< T >() ) );
978 template<
typename T >
979 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
980 UnpackDataDevice(
buffer_unit_type const * & buffer, T
const & var, parallelDeviceEvents & events )
981 {
return bufferOps::UnpackDataDevice( buffer, var, events ); }
983 template<
typename T >
984 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
985 UnpackDataDevice(
buffer_unit_type const * &, T
const &, parallelDeviceEvents & )
987 GEOS_ERROR( GEOS_FMT(
"Trying to unpack data type ({}) on device. Operation not supported.",
988 LvArray::system::demangleType< T >() ) );
992 template<
typename T,
typename IDX >
993 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
994 UnpackDataByIndexDevice(
buffer_unit_type const * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events, MPI_Op op )
995 {
return bufferOps::UnpackDataByIndexDevice( buffer, var, idx, events, op ); }
997 template<
typename T,
typename IDX >
998 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
999 UnpackDataByIndexDevice(
buffer_unit_type const * &, T
const &, IDX &, parallelDeviceEvents &, MPI_Op )
1001 GEOS_ERROR( GEOS_FMT(
"Trying to unpack data type ({}) by index on device. Operation not supported.",
1002 LvArray::system::demangleType< T >() ) );
1006 #if defined(GEOS_USE_PYGEOSX)
1008 template<
typename T >
1009 inline std::enable_if_t< LvArray::python::CanCreate< T >, PyObject * >
1010 createPythonObject( T &
object )
1011 {
return LvArray::python::create(
object ); }
1013 template<
typename T >
1014 inline std::enable_if_t< !LvArray::python::CanCreate< T >, PyObject * >
1015 createPythonObject( T & )
1024 #undef RESTART_TYPE_LOGGING
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
#define GEOS_DEBUG_VAR(...)
Mark a debug variable and silence compiler warnings.
#define GEOS_UNUSED_PARAM(X)
Mark an unused argument and silence compiler warnings.
#define GEOS_ERROR_IF_LE(lhs, rhs)
Raise a hard error if one value compares less than or equal to the other.
#define GEOS_ERROR(...)
Raise a hard error and terminate the program.
#define GEOS_ERROR_IF_LT(lhs, rhs)
Raise a hard error if one value compares less than the other.
#define GEOS_ERROR_IF_GE(lhs, rhs)
Raise a hard error if one value compares greater than or equal to the other.
#define GEOS_LOG(...)
Log a message on screen.
#define GEOS_ERROR_IF_NE_MSG(lhs, rhs,...)
Raise a hard error if two values are not equal.
#define GEOS_ERROR_IF_NE(lhs, rhs)
Raise a hard error if two values are not equal.
stdVector< string > string_array
A 1-dimensional array of geos::string types.
LvArray::Array< T, NDIM, PERMUTATION, localIndex, LvArray::ChaiBuffer > Array
Multidimensional array type. See LvArray:Array for details.
std::set< T > set
A set of local indices.
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
constexpr stdArray< T, N > to_stdArray(std::array< T, N > const &arr)
Convert an std::array to an stdArray.
Tensor< real64, 3 > R1Tensor
Alias for a local (stack-based) rank-1 tensor type.
signed char buffer_unit_type
Type stored in communication buffers.
int integer
Signed integer type.
LvArray::ArrayView< T, NDIM, USD, localIndex, LvArray::ChaiBuffer > ArrayView
Multidimensional array view type. See LvArray:ArrayView for details.