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 >
193 inline std::enable_if_t< traits::HasMemberFunction_resizeDefault< T > &&
194 DefaultValue< T >::has_default_value >
195 resizeDefault( T & value,
197 DefaultValue< T >
const & defaultValue,
199 { value.resizeDefault( newSize, defaultValue.value ); }
201 template<
typename T >
202 inline std::enable_if_t< !( traits::HasMemberFunction_resizeDefault< T > &&
203 DefaultValue< T >::has_default_value ) >
204 resizeDefault( T & value,
207 string const & name )
211 " wrapperHelpers::resizeDefault<{}>() called, but the SFINAE filter failed:\n"
212 " traits::HasMemberFunction_resizeDefault< {} > = {}\n "
213 " DefaultValue< {} >::has_default_value = {}",
214 LvArray::system::demangleType< T >(),
216 LvArray::system::demangleType< T >(),
217 LvArray::system::demangleType< T >(),
218 traits::HasMemberFunction_resizeDefault< T >,
219 LvArray::system::demangleType< T >(),
220 DefaultValue< T >::has_default_value ) );
224 resize( value, newSize );
228 template<
typename T,
int NDIM,
typename PERMUTATION >
230 resizeDimensions( Array< T, NDIM, PERMUTATION > & value,
int num_dims,
localIndex const *
const dims )
231 { value.resize( num_dims, dims ); }
233 template<
typename T >
235 resizeDimensions( T & value,
int num_dims,
localIndex const *
const dims )
242 resize( value, dims[ 0 ] );
246 template<
typename T >
249 {
return sizeof( *dataPtr( std::declval< T >() ) ); }
252 template<
typename T >
254 byteSize( T
const & value )
255 {
return wrapperHelpers::size( value ) * byteSizeOfElement< T >(); }
258 template<
typename T >
260 numElementsFromByteSize(
localIndex const byteSize )
263 return byteSize / byteSizeOfElement< T >();
267 template<
typename T >
268 std::enable_if_t< traits::HasMemberFunction_reserve< T > >
269 reserve( T & value,
localIndex const newCapacity )
270 { value.reserve( newCapacity ); }
272 template<
typename T >
273 std::enable_if_t< !traits::HasMemberFunction_reserve< T > >
278 template<
typename T >
279 std::enable_if_t< traits::HasMemberFunction_capacity< T const >,
localIndex >
280 capacity( T
const & value )
281 {
return value.capacity(); }
283 template<
typename T >
284 std::enable_if_t< !traits::HasMemberFunction_capacity< T const >,
localIndex >
285 capacity( T
const & value )
286 {
return wrapperHelpers::size( value ); }
290 template<
typename T >
291 std::enable_if_t< traits::HasMemberFunction_setName< T > >
292 setName( T & value,
string const & name )
293 { value.setName( name ); }
295 template<
typename T >
296 std::enable_if_t< !traits::HasMemberFunction_setName< T > >
300 template<
typename T >
301 std::enable_if_t< traits::HasMemberFunction_move< T > >
302 move( T & value, LvArray::MemorySpace
const space,
bool const touch )
303 { value.move( space, touch ); }
305 template<
typename T >
306 std::enable_if_t< !traits::HasMemberFunction_move< T > >
313 template<
typename T >
314 std::enable_if_t< !bufferOps::can_memcpy< typename traits::Pointer< T > > >
315 pushDataToConduitNode( T
const & var, conduit::Node & node )
317 internal::logOutputType( LvArray::system::demangleType( var ),
"Packing for output: " );
320 localIndex const byteSize = bufferOps::PackSize( var );
323 conduit::DataType
const dtype( conduitTypeInfo< buffer_unit_type >::id, byteSize );
326 conduit::Node & valuesNode = node[
"__values__" ];
327 valuesNode.set( dtype );
331 bufferOps::Pack< true >( buffer, var );
335 template<
typename T >
336 std::enable_if_t< !bufferOps::can_memcpy< typename traits::Pointer< T > > >
337 pullDataFromConduitNode( T & var, conduit::Node
const & node )
339 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
342 localIndex const byteSize = valuesNode.dtype().number_of_elements();
346 localIndex const bytesRead = bufferOps::Unpack( buffer, var );
353 pushDataToConduitNode(
string const & var, conduit::Node & node )
355 internal::logOutputType( LvArray::system::demangleType( var ),
"Output via external pointer: " );
357 constexpr
int conduitTypeID = conduitTypeInfo< signed char >::id;
358 conduit::DataType
const dtype( conduitTypeID, var.size() );
360 signed char *
const ptr =
const_cast< signed char *
>(
reinterpret_cast< signed char const *
>( var.data() ) );
361 node[
"__values__" ].set_external( dtype, ptr );
367 pushDataToConduitNode( Path
const & var, conduit::Node & node )
369 pushDataToConduitNode(
static_cast< string const &
>(var), node );
373 template<
typename T >
374 std::enable_if_t< bufferOps::can_memcpy< typename traits::Pointer< T > > >
375 pushDataToConduitNode( T
const & var, conduit::Node & node )
377 internal::logOutputType( LvArray::system::demangleType( var ),
"Output via external pointer: " );
379 constexpr
int conduitTypeID = conduitTypeInfo< typename traits::Pointer< T > >::id;
380 constexpr
int sizeofConduitType = conduitTypeInfo< typename traits::Pointer< T > >::sizeOfConduitType;
382 conduit::DataType
const dtype( conduitTypeID, numBytes / sizeofConduitType );
384 void *
const ptr =
const_cast< void *
>(
static_cast< void const *
>( dataPtr( var ) ) );
385 node[
"__values__" ].set_external( dtype, ptr );
389 template<
typename T >
390 std::enable_if_t< bufferOps::can_memcpy< typename traits::Pointer< T > > >
391 pullDataFromConduitNode( T & var, conduit::Node
const & node )
393 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
395 localIndex const byteSize = LvArray::integerConversion< localIndex >( valuesNode.dtype().strided_bytes() );
396 localIndex const numElements = numElementsFromByteSize< T >( byteSize );
398 resize( var, numElements );
400 std::memcpy( dataPtr( var ), valuesNode.data_ptr(), byteSize );
404 template<
typename T >
405 std::enable_if_t< bufferOps::can_memcpy< T > >
406 pullDataFromConduitNode( SortedArray< T > & var, conduit::Node
const & node )
408 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
410 localIndex const byteSize = LvArray::integerConversion< localIndex >( valuesNode.dtype().strided_bytes() );
411 localIndex const numElements = numElementsFromByteSize< T >( byteSize );
413 T
const *
const values =
reinterpret_cast< T
const *
>( valuesNode.data_ptr() );
414 var.insert( values, values + numElements );
419 template<
typename T,
int NDIM,
typename PERMUTATION >
420 std::enable_if_t< bufferOps::can_memcpy< T > >
421 pushDataToConduitNode( Array< T, NDIM, PERMUTATION >
const & var,
422 conduit::Node & node )
424 internal::logOutputType( LvArray::system::demangleType( var ),
"Output array via external pointer: " );
427 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
428 constexpr
int sizeofConduitType = conduitTypeInfo< T >::sizeOfConduitType;
429 conduit::DataType
const dtype( conduitTypeID, var.size() *
sizeof( T ) / sizeofConduitType );
430 void *
const ptr =
const_cast< void *
>(
static_cast< void const *
>( var.data() ) );
431 node[
"__values__" ].set_external( dtype, ptr );
434 camp::idx_t temp[ NDIM + 1 ];
435 for(
int i = 0; i < NDIM; ++i )
437 temp[ i ] = var.size( i );
441 constexpr
int const implicitDimensionLength = conduitTypeInfo< T >::numConduitValues;
442 constexpr
bool const hasImplicitDimension = implicitDimensionLength != 1;
443 constexpr
int totalNumDimensions = NDIM + hasImplicitDimension;
444 if( hasImplicitDimension )
446 temp[ NDIM ] = implicitDimensionLength;
450 conduit::DataType
const dimensionType( conduitTypeInfo< camp::idx_t >::id, totalNumDimensions );
451 node[
"__dimensions__" ].set( dimensionType, temp );
454 constexpr std::array< camp::idx_t, NDIM >
const perm = RAJA::as_array< PERMUTATION >::get();
455 for(
int i = 0; i < NDIM; ++i )
457 temp[ i ] = perm[ i ];
460 if( hasImplicitDimension )
465 node[
"__permutation__" ].set( dimensionType, temp );
469 template<
typename T,
int NDIM,
typename PERMUTATION >
470 std::enable_if_t< bufferOps::can_memcpy< T > >
471 pullDataFromConduitNode( Array< T, NDIM, PERMUTATION > & var,
472 conduit::Node
const & node )
475 constexpr
int const implicitDimensionLength = conduitTypeInfo< T >::numConduitValues;
476 constexpr
bool const hasImplicitDimension = implicitDimensionLength != 1;
477 constexpr
int totalNumDimensions = NDIM + hasImplicitDimension;
480 conduit::Node
const & permutationNode = node.fetch_existing(
"__permutation__" );
481 GEOS_ERROR_IF_NE( permutationNode.dtype().number_of_elements(), totalNumDimensions );
483 constexpr std::array< camp::idx_t, NDIM >
const perm = RAJA::as_array< PERMUTATION >::get();
484 camp::idx_t
const *
const permFromConduit = permutationNode.value();
485 for(
int i = 0; i < NDIM; ++i )
488 "The permutation of the data in conduit and the provided Array don't match." );
491 if( hasImplicitDimension )
494 "The permutation of the data in conduit and the provided Array don't match." );
498 conduit::Node
const & dimensionNode = node.fetch_existing(
"__dimensions__" );
499 GEOS_ERROR_IF_NE( dimensionNode.dtype().number_of_elements(), totalNumDimensions );
500 camp::idx_t
const *
const dims = dimensionNode.value();
502 if( hasImplicitDimension )
507 var.resize( NDIM, dims );
510 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
511 localIndex numBytesFromArray = var.size() *
sizeof( T );
513 std::memcpy( var.data(), valuesNode.data_ptr(), numBytesFromArray );
518 template<
typename T,
typename INDEX_TYPE >
519 std::enable_if_t< bufferOps::can_memcpy< T > >
520 pushDataToConduitNode( ArrayOfArrays< T, INDEX_TYPE >
const & var2,
521 conduit::Node & node )
523 ArrayOfArraysView< T const, INDEX_TYPE >
const & var = var2.toViewConst();
524 internal::logOutputType( LvArray::system::demangleType( var ),
"Output array via external pointer: " );
527 INDEX_TYPE
const numArrays = var.size();
528 conduit::DataType
const numArraysType( conduitTypeInfo< INDEX_TYPE >::id, 1 );
529 node[
"__numberOfArrays__" ].set( numArraysType,
const_cast< void *
>(
static_cast< void const *
>(&numArrays) ) );
532 INDEX_TYPE
const *
const offsets = var.getOffsets();
533 conduit::DataType
const offsetsType( conduitTypeInfo< INDEX_TYPE >::id, numArrays+1 );
534 node[
"__offsets__" ].set_external( offsetsType,
const_cast< void *
>(
static_cast< void const *
>( offsets ) ) );
537 INDEX_TYPE
const *
const sizes = var.getSizes();
538 conduit::DataType
const sizesType( conduitTypeInfo< INDEX_TYPE >::id, numArrays );
539 node[
"__sizes__" ].set_external( sizesType,
const_cast< void *
>(
static_cast< void const *
>( sizes ) ) );
542 T *
const values =
const_cast< T *
>(var.getValues());
543 for( INDEX_TYPE i = 0; i < numArrays; ++i )
545 INDEX_TYPE
const curOffset = offsets[ i ];
546 INDEX_TYPE
const nextOffset = offsets[ i + 1 ];
547 for( INDEX_TYPE j = curOffset + var.sizeOfArray( i ); j < nextOffset; ++j )
549 if constexpr ( std::is_arithmetic< T >::value )
560 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
561 constexpr
int sizeofConduitType = conduitTypeInfo< T >::sizeOfConduitType;
562 conduit::DataType
const dtype( conduitTypeID, offsets[numArrays] *
sizeof( T ) / sizeofConduitType );
565 node[
"__values__" ].set_external( dtype, values );
568 template<
typename T,
typename INDEX_TYPE >
569 std::enable_if_t< bufferOps::can_memcpy< T > >
570 pullDataFromConduitNode( ArrayOfArrays< T, INDEX_TYPE > & var,
571 conduit::Node
const & node )
575 conduit::Node
const & numArraysNode = node.fetch_existing(
"__numberOfArrays__" );
576 INDEX_TYPE
const *
const numArrays = numArraysNode.value();
579 conduit::Node
const & offsetsNode = node.fetch_existing(
"__offsets__" );
580 conduit::DataType
const & offsetsDataType = offsetsNode.dtype();
581 INDEX_TYPE
const *
const offsets = offsetsNode.value();
582 INDEX_TYPE
const sizeOffsets = offsetsDataType.number_of_elements();
585 conduit::Node
const & sizesNode = node.fetch_existing(
"__sizes__" );
586 conduit::DataType
const & sizesDataType = sizesNode.dtype();
587 INDEX_TYPE
const *
const sizes = sizesNode.value();
588 INDEX_TYPE
const sizeSizes = sizesDataType.number_of_elements();
595 conduit::Node
const & valuesNode = node.fetch_existing(
"__values__" );
596 conduit::DataType
const & valuesDataType = valuesNode.dtype();
597 const INDEX_TYPE valuesSize = valuesDataType.number_of_elements();
600 INDEX_TYPE
const arraySizeEstimate = (*numArrays)==0 ? 0 : valuesSize / (*numArrays);
601 var.resize( *numArrays, arraySizeEstimate );
602 var.reserveValues( valuesSize );
606 for( INDEX_TYPE i = 0; i < *numArrays; ++i )
608 INDEX_TYPE
const arrayAllocation = offsets[i+1] - offsets[i];
609 var.setCapacityOfArray( i, arrayAllocation );
610 var.resizeArray( i, sizes[ i ] );
611 allocatedSize += arrayAllocation;
621 ArrayOfArraysView< T const, INDEX_TYPE >
const & varView = var.toViewConst();
622 INDEX_TYPE
const *
const varOffsets = varView.getOffsets();
623 INDEX_TYPE
const *
const varSizes = varView.getSizes();
629 for( INDEX_TYPE i = 0; i<*numArrays; ++i )
636 localIndex numBytesFromArray = allocatedSize *
sizeof( T );
638 std::memcpy(
const_cast< T *
>(varView.getValues()), valuesNode.data_ptr(), numBytesFromArray );
643 template<
typename T >
644 void pushDataToConduitNode( InterObjectRelation< T >
const & var,
645 conduit::Node & node )
646 {
return pushDataToConduitNode( var.base(), node ); }
648 template<
typename T >
649 void pullDataFromConduitNode( InterObjectRelation< T > & var,
650 conduit::Node
const & node )
651 {
return pullDataFromConduitNode( var.base(), node ); }
655 template<
typename T,
int NDIM,
int USD >
656 std::enable_if_t< std::is_arithmetic< T >::value || traits::is_tensorT< T > >
657 addBlueprintField( ArrayView< T const, NDIM, USD >
const & var,
658 conduit::Node & fields,
659 string const & fieldName,
660 string const & topology,
661 std::vector< string >
const & componentNames )
665 using ConduitType =
typename conduitTypeInfo< T >::type;
666 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
667 constexpr
int numComponentsPerValue = conduitTypeInfo< T >::numConduitValues;
669 localIndex const totalNumberOfComponents = numComponentsPerValue * var.size() / var.size( 0 );
670 if( !componentNames.empty() )
675 var.move( hostMemorySpace,
false );
677 conduit::DataType dtype( conduitTypeID, var.size( 0 ) );
678 dtype.set_stride(
sizeof( ConduitType ) * numComponentsPerValue * var.strides()[ 0 ] );
681 LvArray::forValuesInSliceWithIndices( var[ 0 ], [&fields, &fieldName, &topology, &componentNames, totalNumberOfComponents, &dtype, &curComponent]
682 ( T
const & val,
auto const ... indices )
684 for(
int i = 0; i < numComponentsPerValue; ++i )
687 if( totalNumberOfComponents == 1 )
691 else if( componentNames.empty() )
693 string indexString = internal::getIndicesToComponent( val, i, indices ... );
694 indexString.erase( indexString.begin() );
695 indexString.pop_back();
696 indexString.pop_back();
697 name = fieldName + indexString;
701 name = componentNames[ curComponent++ ];
704 conduit::Node & field = fields[ name ];
705 field[
"association" ] =
"element";
706 field[
"volume_dependent" ] =
"false";
707 field[
"topology" ] = topology;
709 void const * pointer = internal::getPointerToComponent( val, i );
710 field[
"values" ].set_external( dtype,
const_cast< void *
>( pointer ) );
715 template<
typename T >
716 void addBlueprintField( T
const &,
717 conduit::Node & fields,
720 std::vector< string >
const & )
722 GEOS_ERROR(
"Cannot create a mcarray out of " << LvArray::system::demangleType< T >() <<
723 "\nWas trying to write it to " << fields.path() );
727 template<
typename T,
int NDIM,
int USD >
728 std::enable_if_t< std::is_arithmetic< T >::value || traits::is_tensorT< T > >
729 populateMCArray( ArrayView< T const, NDIM, USD >
const & var,
730 conduit::Node & node,
731 std::vector< string >
const & componentNames )
735 using ConduitType =
typename conduitTypeInfo< T >::type;
736 constexpr
int conduitTypeID = conduitTypeInfo< T >::id;
737 constexpr
int numComponentsPerValue = conduitTypeInfo< T >::numConduitValues;
739 if( !componentNames.empty() )
744 var.move( hostMemorySpace,
false );
746 conduit::DataType dtype( conduitTypeID, var.size( 0 ) );
747 dtype.set_stride(
sizeof( ConduitType ) * numComponentsPerValue * var.strides()[ 0 ] );
750 LvArray::forValuesInSliceWithIndices( var[ 0 ], [&componentNames, &node, &dtype, &curComponent]
751 ( T
const & val,
auto const ... indices )
753 for(
int i = 0; i < numComponentsPerValue; ++i )
755 string const name = componentNames.empty() ? internal::getIndicesToComponent( val, i, indices ... ) :
756 componentNames[ curComponent++ ];
758 void const * pointer = internal::getPointerToComponent( val, i );
759 node[ name ].set_external( dtype,
const_cast< void *
>( pointer ) );
764 template<
typename T >
765 void populateMCArray( T
const &,
766 conduit::Node & node,
767 std::vector< string >
const & )
769 GEOS_ERROR(
"Cannot create a mcarray out of " << LvArray::system::demangleType< T >() <<
770 "\nWas trying to write it to " << node.path() );
774 template<
typename T >
775 std::enable_if_t< std::is_arithmetic< T >::value, std::unique_ptr< Array< T, 1 > > >
776 averageOverSecondDim( ArrayView< T const, 1, 0 >
const & var )
778 std::unique_ptr< Array< T, 1 > > ret = std::make_unique< Array< T, 1 > >();
780 ret->resize( var.size() );
781 ret->template setValues< serialPolicy >( var );
786 template<
typename T,
int NDIM,
int USD >
787 std::enable_if_t< std::is_arithmetic< T >::value, std::unique_ptr<
Array< T, NDIM - 1 > > >
788 averageOverSecondDim( ArrayView< T const, NDIM, USD >
const & var )
790 std::unique_ptr<
Array< T, NDIM - 1 > > ret = std::make_unique<
Array< T, NDIM - 1 > >();
793 newDims[ 0 ] = var.size( 0 );
794 for(
int i = 2; i < NDIM; ++i )
796 newDims[ i - 1 ] = var.size( i );
799 ret->resize( NDIM - 1, newDims );
801 ArrayView< T, NDIM - 1 >
const & output = *ret;
804 forAll< serialPolicy >( var.size( 0 ), [var, numSamples, &output] (
localIndex const i )
806 LvArray::sumOverFirstDimension( var[ i ], output[ i ] );
808 LvArray::forValuesInSlice( output[ i ], [numSamples] ( T & val )
817 template<
typename T >
818 std::unique_ptr< int > averageOverSecondDim( T
const & )
820 GEOS_ERROR(
"Cannot average over the second dimension of " << LvArray::system::demangleType< T >() );
821 return std::unique_ptr< int >(
nullptr );
824 template<
typename T,
int NDIM,
int USD >
825 int numArrayDims( ArrayView< T const, NDIM, USD >
const &
GEOS_UNUSED_PARAM( var ) )
830 template<
typename T >
836 template<
typename T,
int NDIM,
int USD >
837 localIndex numArrayComp( ArrayView< T const, NDIM, USD >
const & var )
839 return LvArray::indexing::multiplyAll< NDIM - 1 >( var.dims() + 1 );
842 template<
typename T >
848 template<
typename T >
854 template<
bool DO_PACKING,
typename T,
typename IDX >
855 inline std::enable_if_t< bufferOps::is_packable_by_index< T >,
localIndex >
857 {
return bufferOps::PackByIndex< DO_PACKING >( buffer, var, idx ); }
859 template<
bool DO_PACKING,
typename T,
typename IDX >
860 inline std::enable_if_t< !bufferOps::is_packable_by_index< T >,
localIndex >
863 GEOS_ERROR(
"Trying to pack data type (" << LvArray::system::demangleType< T >() <<
") by index. Operation not supported." );
867 template<
typename T,
typename IDX >
868 inline std::enable_if_t< bufferOps::is_packable_by_index< T >,
localIndex >
870 {
return bufferOps::UnpackByIndex( buffer, var, idx ); }
872 template<
typename T,
typename IDX >
873 inline std::enable_if_t< !bufferOps::is_packable_by_index< T >,
localIndex >
876 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") by index. Operation not supported." );
881 template<
bool DO_PACKING,
typename T >
882 inline std::enable_if_t< bufferOps::is_container< T > || bufferOps::can_memcpy< T >,
localIndex >
883 PackDevice(
buffer_unit_type * & buffer, T
const & var, parallelDeviceEvents & events )
884 {
return bufferOps::PackDevice< DO_PACKING >( buffer, var, events ); }
887 template<
bool DO_PACKING,
typename T >
888 inline std::enable_if_t< !bufferOps::is_container< T > && !bufferOps::can_memcpy< T >,
localIndex >
891 GEOS_ERROR(
"Trying to pack data type (" << LvArray::system::demangleType< T >() <<
") on device. Operation not supported." );
895 template<
bool DO_PACKING,
typename T,
typename IDX >
896 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
897 PackByIndexDevice(
buffer_unit_type * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events )
898 {
return bufferOps::PackByIndexDevice< DO_PACKING >( buffer, var, idx, events ); }
900 template<
bool DO_PACKING,
typename T,
typename IDX >
901 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
902 PackByIndexDevice(
buffer_unit_type * &, T
const &, IDX &, parallelDeviceEvents & )
904 GEOS_ERROR(
"Trying to pack data type (" << LvArray::system::demangleType< T >() <<
") by index on device. Operation not supported." );
908 template<
typename T >
909 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
910 UnpackDevice(
buffer_unit_type const * & buffer, T
const & var, parallelDeviceEvents & events )
911 {
return bufferOps::UnpackDevice( buffer, var, events ); }
913 template<
typename T >
914 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
915 UnpackDevice(
buffer_unit_type const * &, T
const &, parallelDeviceEvents & )
917 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") on device. Operation not supported." );
921 template<
typename T,
typename IDX >
922 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
923 UnpackByIndexDevice(
buffer_unit_type const * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events, MPI_Op op=MPI_REPLACE )
924 {
return bufferOps::UnpackByIndexDevice( buffer, var, idx, events, op ); }
926 template<
typename T,
typename IDX >
927 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
928 UnpackByIndexDevice(
buffer_unit_type const * &, T &, IDX &, parallelDeviceEvents &, MPI_Op )
930 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") by index on device. Operation not supported." );
935 template<
bool DO_PACKING,
typename T >
937 PackDataDevice(
buffer_unit_type * & buffer, T
const & var, parallelDeviceEvents & events )
938 {
return bufferOps::PackDataDevice< DO_PACKING >( buffer, var, events ); }
940 template<
bool DO_PACKING,
typename T,
typename IDX >
941 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
942 PackDataByIndexDevice(
buffer_unit_type * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events )
943 {
return bufferOps::PackDataByIndexDevice< DO_PACKING >( buffer, var, idx, events ); }
945 template<
bool DO_PACKING,
typename T,
typename IDX >
946 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
947 PackDataByIndexDevice(
buffer_unit_type * &, T
const &, IDX &, parallelDeviceEvents & )
949 GEOS_ERROR(
"Trying to pack data type (" << LvArray::system::demangleType< T >() <<
") by index on device. Operation not supported." );
953 template<
typename T >
954 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
955 UnpackDataDevice(
buffer_unit_type const * & buffer, T
const & var, parallelDeviceEvents & events )
956 {
return bufferOps::UnpackDataDevice( buffer, var, events ); }
958 template<
typename T >
959 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
960 UnpackDataDevice(
buffer_unit_type const * &, T
const &, parallelDeviceEvents & )
962 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") on device. Operation not supported." );
966 template<
typename T,
typename IDX >
967 inline std::enable_if_t< bufferOps::is_container< T >,
localIndex >
968 UnpackDataByIndexDevice(
buffer_unit_type const * & buffer, T
const & var, IDX & idx, parallelDeviceEvents & events, MPI_Op op )
969 {
return bufferOps::UnpackDataByIndexDevice( buffer, var, idx, events, op ); }
971 template<
typename T,
typename IDX >
972 inline std::enable_if_t< !bufferOps::is_container< T >,
localIndex >
973 UnpackDataByIndexDevice(
buffer_unit_type const * &, T
const &, IDX &, parallelDeviceEvents &, MPI_Op )
975 GEOS_ERROR(
"Trying to unpack data type (" << LvArray::system::demangleType< T >() <<
") by index on device. Operation not supported." );
979 #if defined(GEOS_USE_PYGEOSX)
981 template<
typename T >
982 inline std::enable_if_t< LvArray::python::CanCreate< T >, PyObject * >
983 createPythonObject( T &
object )
984 {
return LvArray::python::create(
object ); }
986 template<
typename T >
987 inline std::enable_if_t< !LvArray::python::CanCreate< T >, PyObject * >
988 createPythonObject( T & )
997 #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_LOG_RANK_0(msg)
Log a message on screen on rank 0.
#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.
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.