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"
37 #if defined(GEOS_USE_PYGEOSX)
38 #include "LvArray/src/python/python.hpp"
42 #include <conduit.hpp>
47 #if RESTART_TYPE_LOGGING
48 #include <unordered_set>
53 namespace dataRepository
55 namespace wrapperHelpers
60 inline void logOutputType(
string const & typeString,
string const & msg )
62 #if RESTART_TYPE_LOGGING
63 static std::unordered_set< string > m_types;
65 if( !m_types.count( typeString ) )
67 m_types.insert( typeString );
76 template<
typename T,
typename ... INDICES >
77 string getIndicesToComponent( T
const &,
int const component, INDICES
const ... existingIndices )
80 return LvArray::indexing::getIndexString( existingIndices ... );
83 template<
typename ... INDICES >
84 string getIndicesToComponent(
R1Tensor const &,
int const component, INDICES
const ... existingIndices )
85 {
return LvArray::indexing::getIndexString( existingIndices ..., component ); }
87 template<
typename T >
88 T
const * getPointerToComponent( T
const & var,
int const component )
95 real64 const * getPointerToComponent(
R1Tensor const & var,
int const component )
98 return &var[ component ];
103 template<
typename T >
108 void set(
integer const, Span< string const > )
110 GEOS_ERROR(
"Dimension labels are only available in Array wrappers" );
113 Span< string const > get(
integer const )
const
115 GEOS_ERROR(
"Dimension labels are only available in Array wrappers" );
120 template<
typename T,
int NDIM,
typename PERM >
121 class ArrayDimLabels<
Array< T, NDIM, PERM > >
125 void set(
integer const dim, Span< string const > labels )
129 m_values[dim].resize( labels.size() );
130 std::copy( labels.begin(), labels.end(), m_values[dim].begin() );
133 Span< string const > get(
integer const dim )
const
137 return { m_values[dim].begin(), m_values[dim].end() };
145 template<
typename T >
146 inline std::enable_if_t< traits::HasMemberFunction_size< T >,
size_t >
147 size( T
const & value )
148 {
return value.size(); }
150 template<
typename T >
151 inline std::enable_if_t< !traits::HasMemberFunction_size< T >,
size_t >
157 dataPtr(
string & var )
158 {
return const_cast< char *
>( var.data() ); }
161 dataPtr( Path & var )
162 {
return const_cast< char *
>( var.data() ); }
164 template<
typename T >
165 inline std::enable_if_t< traits::HasMemberFunction_data< T >,
typename traits::Pointer< T > >
167 {
return value.data(); }
169 template<
typename T >
170 inline std::enable_if_t< !traits::HasMemberFunction_data< T >,
typename traits::Pointer< T > >
175 inline typename traits::ConstPointer< T >
176 dataPtr( T
const & value )
177 {
return dataPtr(
const_cast< T &
>( value ) ); }
180 template<
typename T >
181 inline std::enable_if_t< traits::HasMemberFunction_resize< T > >
183 { value.resize( newSize ); }
185 template<
typename T >
186 inline std::enable_if_t< !traits::HasMemberFunction_resize< T > >
192 template<
typename T,
int NDIM,
typename PERMUTATION >
193 inline std::enable_if_t< DefaultValue< Array< T, NDIM, PERMUTATION > >::has_default_value >
194 resizeDefault( Array< T, NDIM, PERMUTATION > & value,
196 DefaultValue< Array< T, NDIM, PERMUTATION > >
const & defaultValue )
197 { value.resizeDefault( newSize, defaultValue.value ); }
199 template<
typename T >
202 { resize( value, newSize ); }
205 template<
typename T,
int NDIM,
typename PERMUTATION >
207 resizeDimensions( Array< T, NDIM, PERMUTATION > & value,
int num_dims,
localIndex const *
const dims )
208 { value.resize( num_dims, dims ); }
210 template<
typename T >
212 resizeDimensions( T & value,
int num_dims,
localIndex const *
const dims )
219 resize( value, dims[ 0 ] );
223 template<
typename T >
226 {
return sizeof( *dataPtr( std::declval< T >() ) ); }
229 template<
typename T >
231 byteSize( T
const & value )
232 {
return wrapperHelpers::size( value ) * byteSizeOfElement< T >(); }
235 template<
typename T >
237 numElementsFromByteSize(
localIndex const byteSize )
240 return byteSize / byteSizeOfElement< T >();
244 template<
typename T >
245 std::enable_if_t< traits::HasMemberFunction_reserve< T > >
246 reserve( T & value,
localIndex const newCapacity )
247 { value.reserve( newCapacity ); }
249 template<
typename T >
250 std::enable_if_t< !traits::HasMemberFunction_reserve< T > >
255 template<
typename T >
256 std::enable_if_t< traits::HasMemberFunction_capacity< T const >,
localIndex >
257 capacity( T
const & value )
258 {
return value.capacity(); }
260 template<
typename T >
261 std::enable_if_t< !traits::HasMemberFunction_capacity< T const >,
localIndex >
262 capacity( T
const & value )
263 {
return wrapperHelpers::size( value ); }
267 template<
typename T >
268 std::enable_if_t< traits::HasMemberFunction_setName< T > >
269 setName( T & value,
string const & name )
270 { value.setName( name ); }
272 template<
typename T >
273 std::enable_if_t< !traits::HasMemberFunction_setName< T > >
277 template<
typename T >
278 std::enable_if_t< traits::HasMemberFunction_move< T > >
279 move( T & value, LvArray::MemorySpace
const space,
bool const touch )
280 { value.move( space, touch ); }
282 template<
typename T >
283 std::enable_if_t< !traits::HasMemberFunction_move< T > >
290 template<
typename T >
291 std::enable_if_t< !bufferOps::can_memcpy< typename traits::Pointer< T > > >
292 pushDataToConduitNode( T
const & var, conduit::Node & node )
294 internal::logOutputType( LvArray::system::demangleType( var ),
"Packing for output: " );
297 localIndex const byteSize = bufferOps::PackSize( var );
300 conduit::DataType
const dtype( conduitTypeInfo< buffer_unit_type >::id, byteSize );
303 conduit::Node & valuesNode = node[
"__values__" ];
304 valuesNode.set( dtype );
308 bufferOps::Pack< true >( buffer, var );
312 template<
typename T >
313 std::enable_if_t< !bufferOps::can_memcpy< typename traits::Pointer< T > > >
314 pullDataFromConduitNode( T & var, conduit::Node
const & node )
316 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
319 localIndex const byteSize = valuesNode.dtype().number_of_elements();
323 localIndex const bytesRead = bufferOps::Unpack( buffer, var );
330 pushDataToConduitNode(
string const & var, conduit::Node & node )
332 internal::logOutputType( LvArray::system::demangleType( var ),
"Output via external pointer: " );
334 constexpr
int conduitTypeID = conduitTypeInfo< signed char >::id;
335 conduit::DataType
const dtype( conduitTypeID, var.size() );
337 signed char *
const ptr =
const_cast< signed char *
>(
reinterpret_cast< signed char const *
>( var.data() ) );
338 node[
"__values__" ].set_external( dtype, ptr );
344 pushDataToConduitNode( Path
const & var, conduit::Node & node )
346 pushDataToConduitNode(
static_cast< string const &
>(var), node );
350 template<
typename T >
351 std::enable_if_t< bufferOps::can_memcpy< typename traits::Pointer< T > > >
352 pushDataToConduitNode( T
const & var, conduit::Node & node )
354 internal::logOutputType( LvArray::system::demangleType( var ),
"Output via external pointer: " );
356 constexpr
int conduitTypeID = conduitTypeInfo< typename traits::Pointer< T > >::id;
357 constexpr
int sizeofConduitType = conduitTypeInfo< typename traits::Pointer< T > >::sizeOfConduitType;
359 conduit::DataType
const dtype( conduitTypeID, numBytes / sizeofConduitType );
361 void *
const ptr =
const_cast< void *
>(
static_cast< void const *
>( dataPtr( var ) ) );
362 node[
"__values__" ].set_external( dtype, ptr );
366 template<
typename T >
367 std::enable_if_t< bufferOps::can_memcpy< typename traits::Pointer< T > > >
368 pullDataFromConduitNode( T & var, conduit::Node
const & node )
370 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
372 localIndex const byteSize = LvArray::integerConversion< localIndex >( valuesNode.dtype().strided_bytes() );
373 localIndex const numElements = numElementsFromByteSize< T >( byteSize );
375 resize( var, numElements );
377 std::memcpy( dataPtr( var ), valuesNode.data_ptr(), byteSize );
381 template<
typename T >
382 std::enable_if_t< bufferOps::can_memcpy< T > >
383 pullDataFromConduitNode( SortedArray< T > & var, conduit::Node
const & node )
385 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
387 localIndex const byteSize = LvArray::integerConversion< localIndex >( valuesNode.dtype().strided_bytes() );
388 localIndex const numElements = numElementsFromByteSize< T >( byteSize );
390 T
const *
const values =
reinterpret_cast< T
const *
>( valuesNode.data_ptr() );
391 var.insert( values, values + numElements );
396 template<
typename T,
int NDIM,
typename PERMUTATION >
397 std::enable_if_t< bufferOps::can_memcpy< T > >
398 pushDataToConduitNode( Array< T, NDIM, PERMUTATION >
const & var,
399 conduit::Node & node )
401 internal::logOutputType( LvArray::system::demangleType( var ),
"Output array via external pointer: " );
404 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
405 constexpr
int sizeofConduitType = conduitTypeInfo< T >::sizeOfConduitType;
406 conduit::DataType
const dtype( conduitTypeID, var.size() *
sizeof( T ) / sizeofConduitType );
407 void *
const ptr =
const_cast< void *
>(
static_cast< void const *
>( var.data() ) );
408 node[
"__values__" ].set_external( dtype, ptr );
411 camp::idx_t temp[ NDIM + 1 ];
412 for(
int i = 0; i < NDIM; ++i )
414 temp[ i ] = var.size( i );
418 constexpr
int const implicitDimensionLength = conduitTypeInfo< T >::numConduitValues;
419 constexpr
bool const hasImplicitDimension = implicitDimensionLength != 1;
420 constexpr
int totalNumDimensions = NDIM + hasImplicitDimension;
421 if( hasImplicitDimension )
423 temp[ NDIM ] = implicitDimensionLength;
427 conduit::DataType
const dimensionType( conduitTypeInfo< camp::idx_t >::id, totalNumDimensions );
428 node[
"__dimensions__" ].set( dimensionType, temp );
431 constexpr std::array< camp::idx_t, NDIM >
const perm = RAJA::as_array< PERMUTATION >::get();
432 for(
int i = 0; i < NDIM; ++i )
434 temp[ i ] = perm[ i ];
437 if( hasImplicitDimension )
442 node[
"__permutation__" ].set( dimensionType, temp );
446 template<
typename T,
int NDIM,
typename PERMUTATION >
447 std::enable_if_t< bufferOps::can_memcpy< T > >
448 pullDataFromConduitNode( Array< T, NDIM, PERMUTATION > & var,
449 conduit::Node
const & node )
452 constexpr
int const implicitDimensionLength = conduitTypeInfo< T >::numConduitValues;
453 constexpr
bool const hasImplicitDimension = implicitDimensionLength != 1;
454 constexpr
int totalNumDimensions = NDIM + hasImplicitDimension;
457 conduit::Node
const & permutationNode = node.fetch_existing(
"__permutation__" );
458 GEOS_ERROR_IF_NE( permutationNode.dtype().number_of_elements(), totalNumDimensions );
460 constexpr std::array< camp::idx_t, NDIM >
const perm = RAJA::as_array< PERMUTATION >::get();
461 camp::idx_t
const *
const permFromConduit = permutationNode.value();
462 for(
int i = 0; i < NDIM; ++i )
465 "The permutation of the data in conduit and the provided Array don't match." );
468 if( hasImplicitDimension )
471 "The permutation of the data in conduit and the provided Array don't match." );
475 conduit::Node
const & dimensionNode = node.fetch_existing(
"__dimensions__" );
476 GEOS_ERROR_IF_NE( dimensionNode.dtype().number_of_elements(), totalNumDimensions );
477 camp::idx_t
const *
const dims = dimensionNode.value();
479 if( hasImplicitDimension )
484 var.resize( NDIM, dims );
487 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
488 localIndex numBytesFromArray = var.size() *
sizeof( T );
490 std::memcpy( var.data(), valuesNode.data_ptr(), numBytesFromArray );
495 template<
typename T,
typename INDEX_TYPE >
496 std::enable_if_t< bufferOps::can_memcpy< T > >
497 pushDataToConduitNode( ArrayOfArrays< T, INDEX_TYPE >
const & var2,
498 conduit::Node & node )
500 ArrayOfArraysView< T const, INDEX_TYPE >
const & var = var2.toViewConst();
501 internal::logOutputType( LvArray::system::demangleType( var ),
"Output array via external pointer: " );
504 INDEX_TYPE
const numArrays = var.size();
505 conduit::DataType
const numArraysType( conduitTypeInfo< INDEX_TYPE >::id, 1 );
506 node[
"__numberOfArrays__" ].set( numArraysType,
const_cast< void *
>(
static_cast< void const *
>(&numArrays) ) );
509 INDEX_TYPE
const *
const offsets = var.getOffsets();
510 conduit::DataType
const offsetsType( conduitTypeInfo< INDEX_TYPE >::id, numArrays+1 );
511 node[
"__offsets__" ].set_external( offsetsType,
const_cast< void *
>(
static_cast< void const *
>( offsets ) ) );
514 INDEX_TYPE
const *
const sizes = var.getSizes();
515 conduit::DataType
const sizesType( conduitTypeInfo< INDEX_TYPE >::id, numArrays );
516 node[
"__sizes__" ].set_external( sizesType,
const_cast< void *
>(
static_cast< void const *
>( sizes ) ) );
519 T *
const values =
const_cast< T *
>(var.getValues());
520 for( INDEX_TYPE i = 0; i < numArrays; ++i )
522 INDEX_TYPE
const curOffset = offsets[ i ];
523 INDEX_TYPE
const nextOffset = offsets[ i + 1 ];
524 for( INDEX_TYPE j = curOffset + var.sizeOfArray( i ); j < nextOffset; ++j )
526 if constexpr ( std::is_arithmetic< T >::value )
537 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
538 constexpr
int sizeofConduitType = conduitTypeInfo< T >::sizeOfConduitType;
539 conduit::DataType
const dtype( conduitTypeID, offsets[numArrays] *
sizeof( T ) / sizeofConduitType );
542 node[
"__values__" ].set_external( dtype, values );
545 template<
typename T,
typename INDEX_TYPE >
546 std::enable_if_t< bufferOps::can_memcpy< T > >
547 pullDataFromConduitNode( ArrayOfArrays< T, INDEX_TYPE > & var,
548 conduit::Node
const & node )
552 conduit::Node
const & numArraysNode = node.fetch_existing(
"__numberOfArrays__" );
553 INDEX_TYPE
const *
const numArrays = numArraysNode.value();
556 conduit::Node
const & offsetsNode = node.fetch_existing(
"__offsets__" );
557 conduit::DataType
const & offsetsDataType = offsetsNode.dtype();
558 INDEX_TYPE
const *
const offsets = offsetsNode.value();
559 INDEX_TYPE
const sizeOffsets = offsetsDataType.number_of_elements();
562 conduit::Node
const & sizesNode = node.fetch_existing(
"__sizes__" );
563 conduit::DataType
const & sizesDataType = sizesNode.dtype();
564 INDEX_TYPE
const *
const sizes = sizesNode.value();
565 INDEX_TYPE
const sizeSizes = sizesDataType.number_of_elements();
572 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
573 conduit::DataType
const & valuesDataType = valuesNode.dtype();
574 const INDEX_TYPE valuesSize = valuesDataType.number_of_elements();
577 INDEX_TYPE
const arraySizeEstimate = (*numArrays)==0 ? 0 : valuesSize / (*numArrays);
578 var.resize( *numArrays, arraySizeEstimate );
579 var.reserveValues( valuesSize );
583 for( INDEX_TYPE i = 0; i < *numArrays; ++i )
585 INDEX_TYPE
const arrayAllocation = offsets[i+1] - offsets[i];
586 var.setCapacityOfArray( i, arrayAllocation );
587 var.resizeArray( i, sizes[ i ] );
588 allocatedSize += arrayAllocation;
598 ArrayOfArraysView< T const, INDEX_TYPE >
const & varView = var.toViewConst();
599 INDEX_TYPE
const *
const varOffsets = varView.getOffsets();
600 INDEX_TYPE
const *
const varSizes = varView.getSizes();
606 for( INDEX_TYPE i = 0; i<*numArrays; ++i )
613 localIndex numBytesFromArray = allocatedSize *
sizeof( T );
615 std::memcpy(
const_cast< T *
>(varView.getValues()), valuesNode.data_ptr(), numBytesFromArray );
620 template<
typename T >
621 void pushDataToConduitNode( InterObjectRelation< T >
const & var,
622 conduit::Node & node )
623 {
return pushDataToConduitNode( var.base(), node ); }
625 template<
typename T >
626 void pullDataFromConduitNode( InterObjectRelation< T > & var,
627 conduit::Node
const & node )
628 {
return pullDataFromConduitNode( var.base(), node ); }
632 template<
typename T,
int NDIM,
int USD >
633 std::enable_if_t< std::is_arithmetic< T >::value || traits::is_tensorT< T > >
634 addBlueprintField( ArrayView< T const, NDIM, USD >
const & var,
635 conduit::Node & fields,
636 string const & fieldName,
637 string const & topology,
638 std::vector< string >
const & componentNames )
642 using ConduitType =
typename conduitTypeInfo< T >::type;
643 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
644 constexpr
int numComponentsPerValue = conduitTypeInfo< T >::numConduitValues;
646 localIndex const totalNumberOfComponents = numComponentsPerValue * var.size() / var.size( 0 );
647 if( !componentNames.empty() )
652 var.move( hostMemorySpace,
false );
654 conduit::DataType dtype( conduitTypeID, var.size( 0 ) );
655 dtype.set_stride(
sizeof( ConduitType ) * numComponentsPerValue * var.strides()[ 0 ] );
658 LvArray::forValuesInSliceWithIndices( var[ 0 ], [&fields, &fieldName, &topology, &componentNames, totalNumberOfComponents, &dtype, &curComponent]
659 ( T
const & val,
auto const ... indices )
661 for(
int i = 0; i < numComponentsPerValue; ++i )
664 if( totalNumberOfComponents == 1 )
668 else if( componentNames.empty() )
670 string indexString = internal::getIndicesToComponent( val, i, indices ... );
671 indexString.erase( indexString.begin() );
672 indexString.pop_back();
673 indexString.pop_back();
674 name = fieldName + indexString;
678 name = componentNames[ curComponent++ ];
681 conduit::Node & field = fields[ name ];
682 field[
"association" ] =
"element";
683 field[
"volume_dependent" ] =
"false";
684 field[
"topology" ] = topology;
686 void const * pointer = internal::getPointerToComponent( val, i );
687 field[
"values" ].set_external( dtype,
const_cast< void *
>( pointer ) );
692 template<
typename T >
693 void addBlueprintField( T
const &,
694 conduit::Node & fields,
697 std::vector< string >
const & )
699 GEOS_ERROR(
"Cannot create a mcarray out of " << LvArray::system::demangleType< T >() <<
700 "\nWas trying to write it to " << fields.path() );
704 template<
typename T,
int NDIM,
int USD >
705 std::enable_if_t< std::is_arithmetic< T >::value || traits::is_tensorT< T > >
706 populateMCArray( ArrayView< T const, NDIM, USD >
const & var,
707 conduit::Node & node,
708 std::vector< string >
const & componentNames )
712 using ConduitType =
typename conduitTypeInfo< T >::type;
713 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
714 constexpr
int numComponentsPerValue = conduitTypeInfo< T >::numConduitValues;
716 if( !componentNames.empty() )
721 var.move( hostMemorySpace,
false );
723 conduit::DataType dtype( conduitTypeID, var.size( 0 ) );
724 dtype.set_stride(
sizeof( ConduitType ) * numComponentsPerValue * var.strides()[ 0 ] );
727 LvArray::forValuesInSliceWithIndices( var[ 0 ], [&componentNames, &node, &dtype, &curComponent]
728 ( T
const & val,
auto const ... indices )
730 for(
int i = 0; i < numComponentsPerValue; ++i )
732 string const name = componentNames.empty() ? internal::getIndicesToComponent( val, i, indices ... ) :
733 componentNames[ curComponent++ ];
735 void const * pointer = internal::getPointerToComponent( val, i );
736 node[ name ].set_external( dtype,
const_cast< void *
>( pointer ) );
741 template<
typename T >
742 void populateMCArray( T
const &,
743 conduit::Node & node,
744 std::vector< string >
const & )
746 GEOS_ERROR(
"Cannot create a mcarray out of " << LvArray::system::demangleType< T >() <<
747 "\nWas trying to write it to " << node.path() );
751 template<
typename T >
752 std::enable_if_t< std::is_arithmetic< T >::value, std::unique_ptr< Array< T, 1 > > >
753 averageOverSecondDim( ArrayView< T const, 1, 0 >
const & var )
755 std::unique_ptr< Array< T, 1 > > ret = std::make_unique< Array< T, 1 > >();
757 ret->resize( var.size() );
758 ret->template setValues< serialPolicy >( var );
763 template<
typename T,
int NDIM,
int USD >
764 std::enable_if_t< std::is_arithmetic< T >::value, std::unique_ptr<
Array< T, NDIM - 1 > > >
765 averageOverSecondDim( ArrayView< T const, NDIM, USD >
const & var )
767 std::unique_ptr<
Array< T, NDIM - 1 > > ret = std::make_unique<
Array< T, NDIM - 1 > >();
770 newDims[ 0 ] = var.size( 0 );
771 for(
int i = 2; i < NDIM; ++i )
773 newDims[ i - 1 ] = var.size( i );
776 ret->resize( NDIM - 1, newDims );
778 ArrayView< T, NDIM - 1 >
const & output = *ret;
781 forAll< serialPolicy >( var.size( 0 ), [var, numSamples, &output] (
localIndex const i )
783 LvArray::sumOverFirstDimension( var[ i ], output[ i ] );
785 LvArray::forValuesInSlice( output[ i ], [numSamples] ( T & val )
794 template<
typename T >
795 std::unique_ptr< int > averageOverSecondDim( T
const & )
797 GEOS_ERROR(
"Cannot average over the second dimension of " << LvArray::system::demangleType< T >() );
798 return std::unique_ptr< int >(
nullptr );
801 template<
typename T,
int NDIM,
int USD >
802 int numArrayDims( ArrayView< T const, NDIM, USD >
const &
GEOS_UNUSED_PARAM( var ) )
807 template<
typename T >
813 template<
typename T,
int NDIM,
int USD >
814 localIndex numArrayComp( ArrayView< T const, NDIM, USD >
const & var )
816 return LvArray::indexing::multiplyAll< NDIM - 1 >( var.dims() + 1 );
819 template<
typename T >
825 template<
typename T >
831 template<
bool DO_PACKING,
typename T,
typename IDX >
832 inline std::enable_if_t< bufferOps::is_packable_by_index< T >,
localIndex >
834 {
return bufferOps::PackByIndex< DO_PACKING >( buffer, var, idx ); }
836 template<
bool DO_PACKING,
typename T,
typename IDX >
837 inline std::enable_if_t< !bufferOps::is_packable_by_index< T >,
localIndex >
840 GEOS_ERROR(
"Trying to pack data type (" << LvArray::system::demangleType< T >() <<
") by index. Operation not supported." );
844 template<
typename T,
typename IDX >
845 inline std::enable_if_t< bufferOps::is_packable_by_index< T >,
localIndex >
847 {
return bufferOps::UnpackByIndex( buffer, var, idx ); }
849 template<
typename T,
typename IDX >
850 inline std::enable_if_t< !bufferOps::is_packable_by_index< T >,
localIndex >
853 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") by index. Operation not supported." );
858 template<
bool DO_PACKING,
typename T >
859 inline std::enable_if_t< bufferOps::is_container< T > || bufferOps::can_memcpy< T >,
localIndex >
860 PackDevice(
buffer_unit_type * & buffer, T
const & var, parallelDeviceEvents & events )
861 {
return bufferOps::PackDevice< DO_PACKING >( buffer, var, events ); }
864 template<
bool DO_PACKING,
typename T >
865 inline std::enable_if_t< !bufferOps::is_container< T > && !bufferOps::can_memcpy< T >,
localIndex >
868 GEOS_ERROR(
"Trying to pack data type (" << LvArray::system::demangleType< T >() <<
") on device. Operation not supported." );
872 template<
bool DO_PACKING,
typename T,
typename IDX >
873 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
874 PackByIndexDevice(
buffer_unit_type * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events )
875 {
return bufferOps::PackByIndexDevice< DO_PACKING >( buffer, var, idx, events ); }
877 template<
bool DO_PACKING,
typename T,
typename IDX >
878 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
879 PackByIndexDevice(
buffer_unit_type * &, T
const &, IDX &, parallelDeviceEvents & )
881 GEOS_ERROR(
"Trying to pack data type (" << LvArray::system::demangleType< T >() <<
") by index on device. Operation not supported." );
885 template<
typename T >
886 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
887 UnpackDevice(
buffer_unit_type const * & buffer, T
const & var, parallelDeviceEvents & events )
888 {
return bufferOps::UnpackDevice( buffer, var, events ); }
890 template<
typename T >
891 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
892 UnpackDevice(
buffer_unit_type const * &, T
const &, parallelDeviceEvents & )
894 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") on device. Operation not supported." );
898 template<
typename T,
typename IDX >
899 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
900 UnpackByIndexDevice(
buffer_unit_type const * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events, MPI_Op op=MPI_REPLACE )
901 {
return bufferOps::UnpackByIndexDevice( buffer, var, idx, events, op ); }
903 template<
typename T,
typename IDX >
904 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
905 UnpackByIndexDevice(
buffer_unit_type const * &, T &, IDX &, parallelDeviceEvents &, MPI_Op )
907 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") by index on device. Operation not supported." );
912 template<
bool DO_PACKING,
typename T >
914 PackDataDevice(
buffer_unit_type * & buffer, T
const & var, parallelDeviceEvents & events )
915 {
return bufferOps::PackDataDevice< DO_PACKING >( buffer, var, events ); }
917 template<
bool DO_PACKING,
typename T,
typename IDX >
918 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
919 PackDataByIndexDevice(
buffer_unit_type * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events )
920 {
return bufferOps::PackDataByIndexDevice< DO_PACKING >( buffer, var, idx, events ); }
922 template<
bool DO_PACKING,
typename T,
typename IDX >
923 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
924 PackDataByIndexDevice(
buffer_unit_type * &, T
const &, IDX &, parallelDeviceEvents & )
926 GEOS_ERROR(
"Trying to pack data type (" << LvArray::system::demangleType< T >() <<
") by index on device. Operation not supported." );
930 template<
typename T >
931 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
932 UnpackDataDevice(
buffer_unit_type const * & buffer, T
const & var, parallelDeviceEvents & events )
933 {
return bufferOps::UnpackDataDevice( buffer, var, events ); }
935 template<
typename T >
936 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
937 UnpackDataDevice(
buffer_unit_type const * &, T
const &, parallelDeviceEvents & )
939 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") on device. Operation not supported." );
943 template<
typename T,
typename IDX >
944 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
945 UnpackDataByIndexDevice(
buffer_unit_type const * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events, MPI_Op op )
946 {
return bufferOps::UnpackDataByIndexDevice( buffer, var, idx, events, op ); }
948 template<
typename T,
typename IDX >
949 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
950 UnpackDataByIndexDevice(
buffer_unit_type const * &, T
const &, IDX &, parallelDeviceEvents &, MPI_Op )
952 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") by index on device. Operation not supported." );
956 #if defined(GEOS_USE_PYGEOSX)
958 template<
typename T >
959 inline std::enable_if_t< LvArray::python::CanCreate< T >, PyObject * >
960 createPythonObject( T &
object )
961 {
return LvArray::python::create(
object ); }
963 template<
typename T >
964 inline std::enable_if_t< !LvArray::python::CanCreate< T >, PyObject * >
965 createPythonObject( T & )
974 #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_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(msg)
Raise a hard error and terminate the program.
#define GEOS_ERROR_IF_NE(lhs, rhs)
Raise a hard error if two values are not equal.
#define GEOS_ERROR_IF_NE_MSG(lhs, rhs, msg)
Raise a hard error if two values are not equal.
internal::Helper< T > DefaultValue
A templated alias to hold default values.
LvArray::Array< T, NDIM, PERMUTATION, localIndex, LvArray::ChaiBuffer > Array
Multidimensional array type. See LvArray:Array for details.
array1d< string > string_array
A 1-dimensional array of geos::string types.
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).
std::int32_t integer
Signed integer type.
Tensor< real64, 3 > R1Tensor
Alias for a local (stack-based) rank-1 tensor type.
signed char buffer_unit_type
Type stored in communication buffers.
LvArray::ArrayView< T, NDIM, USD, localIndex, LvArray::ChaiBuffer > ArrayView
Multidimensional array view type. See LvArray:ArrayView for details.