GEOS
Wrapper.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_DATAREPOSITORY_WRAPPER_HPP_
21 #define GEOS_DATAREPOSITORY_WRAPPER_HPP_
22 
23 // Source inclues
24 #include "wrapperHelpers.hpp"
25 #include "KeyNames.hpp"
26 #include "LvArray/src/limits.hpp"
27 #include "common/DataTypes.hpp"
28 #include "codingUtilities/SFINAE_Macros.hpp"
29 #include "LvArray/src/Macros.hpp"
30 #include "BufferOps.hpp"
31 #include "BufferOpsDevice.hpp"
32 #include "RestartFlags.hpp"
33 #include "codingUtilities/traits.hpp"
34 #include "common/GeosxConfig.hpp"
35 #include "DefaultValue.hpp"
36 #include "LvArray/src/system.hpp"
37 #include "WrapperBase.hpp"
38 
39 // System includes
40 #include <type_traits>
41 #include <cstdlib>
42 #include <type_traits>
43 
44 namespace geos
45 {
46 
47 namespace dataRepository
48 {
49 //template< typename U >
50 //static void totalViewType( char * const dataType );
51 
56 template< typename T >
57 class Wrapper final : public WrapperBase
58 {
59 public:
60 
64  using TYPE = T;
65 
70 
76  explicit Wrapper( string const & name,
77  Group & parent ):
78  WrapperBase( name, parent, rtTypes::getTypeName( typeid( T ) ) ),
79  m_ownsData( true ),
80  m_isClone( false ),
81  m_data( new T() ),
82  m_default()
83  {
84  if( traits::is_tensorT< T > || std::is_arithmetic< T >::value || traits::is_string< T > )
85  {
86  setSizedFromParent( 0 );
87  }
88 
89  setName();
90  }
91 
98  explicit Wrapper( string const & name,
99  Group & parent,
100  std::unique_ptr< T > object ):
101  WrapperBase( name, parent, rtTypes::getTypeName( typeid( T ) ) ),
102  m_ownsData( true ),
103  m_isClone( false ),
104  m_data( object.release() ),
105  m_default()
106  {
107  if( traits::is_tensorT< T > || std::is_arithmetic< T >::value || traits::is_string< T > )
108  {
109  setSizedFromParent( 0 );
110  }
111 
112  setName();
113  }
114 
121  explicit Wrapper( string const & name,
122  Group & parent,
123  T * object ):
124  WrapperBase( name, parent, rtTypes::getTypeName( typeid( T ) ) ),
125  m_ownsData( false ),
126  m_isClone( false ),
127  m_data( object ),
128  m_default()
129  {
130  if( traits::is_tensorT< T > || std::is_arithmetic< T >::value || traits::is_string< T > )
131  {
132  setSizedFromParent( 0 );
133  }
134 
135  setName();
136  }
137 
143  virtual ~Wrapper() noexcept override
144  {
145  if( m_ownsData )
146  {
147  delete m_data;
148  }
149  //tvTemplateInstantiation();
150  }
151 
158  Wrapper & operator=( Wrapper const & source )
159  {
160  m_data = source.m_data;
161  return *this;
162  }
163 
169  Wrapper & operator=( Wrapper && source )
170  {
171  m_data = std::move( source.m_data );
172  return *this;
173  }
174 
176 
181 
183  virtual std::unique_ptr< WrapperBase > clone( string const & name,
184  Group & parent ) override
185  {
186  std::unique_ptr< Wrapper< T > > clonedWrapper = std::make_unique< Wrapper< T > >( name, parent, m_data );
187  clonedWrapper->copyWrapperAttributes( *this );
188  clonedWrapper->m_isClone = true;
189  return clonedWrapper;
190  }
191 
192  virtual void copyWrapper( WrapperBase const & source ) override
193  {
194  GEOS_ERROR_IF( source.getName() != m_name, "Tried to copy wrapper with a different name" );
195  copyWrapperAttributes( source );
196  copyData( source );
197  }
198 
200  virtual void copyWrapperAttributes( WrapperBase const & source ) override
201  {
203  Wrapper< T > const & castedSource = dynamicCast< Wrapper< T > const & >( source );
204  m_ownsData = castedSource.m_ownsData;
205  m_default = castedSource.m_default;
206  m_dimLabels = castedSource.m_dimLabels;
207  }
208 
210  virtual const std::type_info & getTypeId() const noexcept override
211  {
212  return typeid(T);
213  }
214 
221  static Wrapper & cast( WrapperBase & wrapper )
222  {
223  GEOS_ERROR_IF( wrapper.getTypeId() != typeid( T ),
224  "Invalid downcast to Wrapper< " << LvArray::system::demangleType< T >() << " >" );
225  return static_cast< Wrapper< T > & >( wrapper );
226  }
227 
234  static Wrapper< T > const & cast( WrapperBase const & wrapper )
235  {
236  GEOS_ERROR_IF( wrapper.getTypeId() != typeid( T ),
237  "Invalid downcast to Wrapper< " << LvArray::system::demangleType< T >() << " >" );
238  return static_cast< Wrapper< T > const & >( wrapper );
239  }
240 
242 
243  virtual int numArrayDims() const override
244  {
245  return wrapperHelpers::numArrayDims( reference() );
246  }
247 
248  virtual localIndex numArrayComp() const override
249  {
250  return wrapperHelpers::numArrayComp( reference() );
251  }
252 
253  virtual Wrapper & setDimLabels( integer const dim, Span< string const > const labels ) override
254  {
255  m_dimLabels.set( dim, labels );
256  return *this;
257  }
258 
259  virtual Span< string const > getDimLabels( integer const dim ) const override
260  {
261  return m_dimLabels.get( dim );
262  }
263 
265 
267  virtual
268  HistoryMetadata getHistoryMetadata( localIndex const packCount = -1 ) const override final
269  {
270  return geos::getHistoryMetadata( getName(), referenceAsView( ), numArrayComp(), packCount );
271  }
272 
277 
280  virtual
281  bool isPackable( bool onDevice ) const override
282  {
283  if( onDevice )
284  {
285  // this isn't accurate if array/arraview return false for this, which I think they do
286  return bufferOps::can_memcpy< T >;
287  }
288  else
289  {
290  return bufferOps::is_packable< T >;
291  }
292  }
293 
296  virtual
297  localIndex unpack( buffer_unit_type const * & buffer, bool withMetadata, bool onDevice, parallelDeviceEvents & events ) override final
298  {
299  localIndex unpackedSize = 0;
300  if( withMetadata )
301  {
302  string name;
303  unpackedSize += bufferOps::Unpack( buffer, name );
304  GEOS_ERROR_IF( name != getName(), "buffer unpack leads to wrapper names that don't match" );
305  }
306  if( onDevice )
307  {
308  if( withMetadata )
309  {
310  unpackedSize += wrapperHelpers::UnpackDevice( buffer, referenceAsView(), events );
311  }
312  else
313  {
314  unpackedSize += wrapperHelpers::UnpackDataDevice( buffer, referenceAsView(), events );
315  }
316  }
317  else
318  {
319  unpackedSize += bufferOps::Unpack( buffer, *m_data );
320  }
321  return unpackedSize;
322  }
323 
326  virtual
328  arrayView1d< localIndex const > const & unpackIndices,
329  bool withMetadata,
330  bool onDevice,
331  parallelDeviceEvents & events,
332  MPI_Op op ) override final
333  {
334  localIndex unpackedSize = 0;
335 
336  if( withMetadata )
337  {
338  string name;
339  unpackedSize += bufferOps::Unpack( buffer, name );
340  GEOS_ERROR_IF( name != getName(), "buffer unpack leads to wrapper names that don't match" );
341  }
342  if( onDevice )
343  {
344  if( withMetadata )
345  {
346  unpackedSize += wrapperHelpers::UnpackByIndexDevice( buffer, referenceAsView(), unpackIndices, events, op );
347  }
348  else
349  {
350  unpackedSize += wrapperHelpers::UnpackDataByIndexDevice( buffer, referenceAsView(), unpackIndices, events, op );
351  }
352  }
353  else
354  {
355  unpackedSize += wrapperHelpers::UnpackByIndex( buffer, *m_data, unpackIndices );
356  }
357 
358  return unpackedSize;
359  }
360 
362 
364  void const * voidPointer() const override
365  { return wrapperHelpers::dataPtr( *m_data ); }
366 
368  virtual localIndex elementByteSize() const override
369  { return wrapperHelpers::byteSizeOfElement< T >(); }
370 
371  virtual size_t bytesAllocated() const override final
372  {
373  return m_isClone ? 0 : wrapperHelpers::byteSize< T >( *m_data );
374  }
375 
376 
384 
386  virtual localIndex size() const override
387  { return wrapperHelpers::size( *m_data ); }
388 
390  virtual void resize( int ndims, localIndex const * const dims ) override
391  {
392  wrapperHelpers::move( *m_data, hostMemorySpace, true );
393  wrapperHelpers::resizeDimensions( *m_data, ndims, dims );
394  }
395 
397  virtual void reserve( localIndex const newCapacity ) override
398  {
399  wrapperHelpers::move( *m_data, hostMemorySpace, true );
400  wrapperHelpers::reserve( reference(), newCapacity );
401  }
402 
404  virtual localIndex capacity() const override
405  {
406  // We don't use reference() here because that would return an ArrayView which has no capacity method.
407  return wrapperHelpers::capacity( *m_data );
408  }
409 
411  virtual void resize( localIndex const newSize ) override
412  {
413  wrapperHelpers::move( *m_data, hostMemorySpace, true );
414  wrapperHelpers::resizeDefault( reference(), newSize, m_default, this->getName() );
415  }
416 
418  struct copy_wrapper
419  {
420  template< typename U, int NDIM, typename PERMUTATION >
421  static void copy( Array< U, NDIM, PERMUTATION > const & array, localIndex const sourceIndex, localIndex const destIndex )
422  {
423  LvArray::forValuesInSliceWithIndices( array[ sourceIndex ],
424  [destIndex, &array]( U const & sourceVal, auto const ... indicesToErase )
425  {
426  array( destIndex, indicesToErase ... ) = sourceVal;
427  } );
428  }
429 
430  template< typename U >
431  static void copy( U const &, localIndex const, localIndex const )
432  {}
433 
434  template< typename U=T >
435  static std::enable_if_t< traits::hasCopyAssignmentOp< U > >
436  copyData( U & destinationData, U const & sourceData )
437  {
438  destinationData = sourceData;
439  }
440 
441  template< typename U=T >
442  static std::enable_if_t< !traits::hasCopyAssignmentOp< U > >
443  copyData( U &, U const & )
444  {}
445  };
447 
449  virtual void copy( localIndex const sourceIndex, localIndex const destIndex ) override
450  {
451  copy_wrapper::copy( reference(), sourceIndex, destIndex );
452  }
453 
454 
455 
456  virtual void copyData( WrapperBase const & source ) override
457  {
458  Wrapper< T > const & castedSource = dynamicCast< Wrapper< T > const & >( source );
459  copy_wrapper::copyData( *m_data, *castedSource.m_data );
460  }
461 
462 
464  struct erase_wrapper // This should probably be in LvArray?
465  {
466  template< typename TYPE >
467  static void erase( TYPE &, std::set< localIndex > const & )
468  {}
469 
470  template< typename TYPE >
471  static void erase( array1d< TYPE > & array, std::set< localIndex > const & indicesToErase )
472  {
473  int oldSize = array.size( 0 );
474  int numToErase = indicesToErase.size();
475  int newSize = oldSize - numToErase;
476  std::set< localIndex >::iterator it = indicesToErase.begin();
477  int offset = 0;
478  for( localIndex i=*it+1; i<oldSize; i++ )
479  {
480  if( i == *it + 1 )
481  {
482  offset++;
483  if( offset < numToErase )
484  {
485  it++;
486  }
487  }
488  array[i-offset] = array[i];
489  }
490  array.resize( newSize );
491  }
492 
493  template< typename TYPE >
494  static void erase( array2d< TYPE > & array, std::set< localIndex > const & indicesToErase )
495  {
496  int oldSize = array.size( 0 );
497  int numToErase = indicesToErase.size();
498  int newSize = oldSize - numToErase;
499  int dim1 = array.size( 1 );
500  std::set< localIndex >::iterator it = indicesToErase.begin();
501  int offset = 0;
502  for( localIndex i=*it+1; i<oldSize; i++ )
503  {
504  if( i == *it + 1 )
505  {
506  offset++;
507  if( offset < numToErase )
508  {
509  it++;
510  }
511  }
512  for( int j=0; j<dim1; j++ )
513  {
514  array[i-offset][j] = array[i][j];
515  }
516  }
517  array.resize( newSize );
518  }
519 
520  template< typename TYPE >
521  static void erase( array3d< TYPE > & array, std::set< localIndex > const & indicesToErase )
522  {
523  int oldSize = array.size( 0 );
524  int numToErase = indicesToErase.size();
525  int newSize = oldSize - numToErase;
526  int dim1 = array.size( 1 );
527  int dim2 = array.size( 2 );
528  std::set< localIndex >::iterator it = indicesToErase.begin();
529  int offset = 0;
530  for( localIndex i=*it+1; i<oldSize; i++ )
531  {
532  if( i == *it + 1 )
533  {
534  offset++;
535  if( offset < numToErase )
536  {
537  it++;
538  }
539  }
540  for( int j=0; j<dim1; j++ )
541  {
542  for( int k=0; k<dim2; k++ )
543  {
544  array[i-offset][j][k] = array[i][j][k];
545  }
546  }
547  }
548  array.resize( newSize );
549  }
550  };
552 
553 
555  void erase( std::set< localIndex > const & indicesToErase ) override
556  {
557  GEOS_ERROR_IF( indicesToErase.size() == 0, "Wrapper::erase() can only be called on a populated set of indices!" );
558  erase_wrapper::erase( reference(), indicesToErase );
559  }
560 
561 
563  virtual void move( LvArray::MemorySpace const space, bool const touch ) const override
564  { return wrapperHelpers::move( *m_data, space, touch ); }
565 
567  virtual Regex const & getTypeRegex() const override
568  { return rtTypes::getTypeRegex< T >( m_rtTypeName ); }
569 
571 
576 
581  T & reference()
582  { return *m_data; }
583 
590  { return referenceAsView(); }
591 
600  template< typename _T=T, typename=std::enable_if_t< traits::HasMemberFunction_toView< _T > > >
602  { return m_data->toView(); }
603 
607  template< typename _T=T, typename=std::enable_if_t< !traits::HasMemberFunction_toView< _T > > >
609  { return *m_data; }
610 
614  template< typename _T=T, typename=std::enable_if_t< traits::HasMemberFunction_toView< _T > > >
616  { return m_data->toViewConst(); }
617 
621  template< typename _T=T, typename=std::enable_if_t< !traits::HasMemberFunction_toView< _T > > >
622  T const & referenceAsView() const
623  { return *m_data; }
624 
626 
631 
635  virtual bool hasDefaultValue() const final override
636  {
637  return m_default.has_default_value;
638  }
639 
644  template< typename U=T >
645  DefaultValue< T > const &
647  {
648  return m_default;
649  }
650 
651 
656  template< typename U=T >
657  std::enable_if_t< DefaultValue< U >::has_default_value, typename DefaultValue< U >::value_type const & >
659  {
660  return m_default.value;
661  }
662 
668  template< typename U=T >
669  std::enable_if_t< DefaultValue< U >::has_default_value, Wrapper< T > & >
670  setDefaultValue( typename DefaultValue< U >::value_type const & defaultVal )
671  {
672  m_default.value = defaultVal;
673  return *this;
674  }
675 
681  template< typename U=T >
682  std::enable_if_t< !traits::is_array< U > && DefaultValue< U >::has_default_value, Wrapper< T > & >
683  setApplyDefaultValue( typename DefaultValue< U >::value_type const & defaultVal )
684  {
685  m_default.value = defaultVal;
686  *m_data = m_default.value;
687  return *this;
688  }
689 
695  template< typename U=T >
696  std::enable_if_t< traits::is_array< U > && DefaultValue< U >::has_default_value, Wrapper< T > & >
697  setApplyDefaultValue( typename DefaultValue< U >::value_type const & defaultVal )
698  {
699  m_default.value = defaultVal;
700  m_data->template setValues< serialPolicy >( m_default.value );
701  return *this;
702  }
703 
707  virtual string getDefaultValueString() const override
708  {
709  std::ostringstream ss;
710  ss << std::string( numArrayDims(), '{' ) << m_default << std::string( numArrayDims(), '}' );
711  return ss.str();
712  }
713 
714  virtual bool processInputFile( xmlWrapper::xmlNode const & targetNode,
715  xmlWrapper::xmlNodePos const & nodePos ) override
716  {
717  InputFlags const inputFlag = getInputFlag();
718  if( inputFlag >= InputFlags::OPTIONAL )
719  {
720  try
721  {
722  if( inputFlag == InputFlags::REQUIRED || !hasDefaultValue() )
723  {
725  getName(),
726  rtTypes::getTypeRegex< T >( getRTTypeName() ),
727  targetNode,
728  inputFlag == InputFlags::REQUIRED );
730  GEOS_FMT( "XML Node {} ({}) with name={} is missing required attribute '{}'."
731  "Available options are:\n {}\n For more details, please refer to documentation at:\n"
732  "http://geosx-geosx.readthedocs-hosted.com/en/latest/docs/sphinx/userGuide/Index.html",
733  targetNode.name(), nodePos.toString(), targetNode.attribute( "name" ).value(),
734  getName(), dumpInputOptions( true ) ),
735  InputError );
736  }
737  else
738  {
740  getName(),
741  rtTypes::getTypeRegex< T >( getRTTypeName() ),
742  targetNode,
744  }
745  }
746  catch( std::exception const & ex )
747  {
748  xmlWrapper::processInputException( ex, getName(), targetNode, nodePos );
749  }
750 
752  createDataContext( targetNode, nodePos );
753 
754  return true;
755  }
756 
757  return false;
758  }
759 
761 
767  void setName()
768  { wrapperHelpers::setName( reference(), m_conduitNode.path() ); }
769 
770 
772  void addBlueprintField( conduit::Node & fields,
773  string const & name,
774  string const & topology,
775  std::vector< string > const & componentNames = {} ) const override
776  { wrapperHelpers::addBlueprintField( reference(), fields, name, topology, componentNames ); }
777 
779  void populateMCArray( conduit::Node & node, std::vector< string > const & componentNames = {} ) const override
780  { wrapperHelpers::populateMCArray( reference(), node, componentNames ); }
781 
783  std::unique_ptr< WrapperBase > averageOverSecondDim( string const & name, Group & group ) const override
784  {
785  auto ptr = wrapperHelpers::averageOverSecondDim( reference() );
786  using U = typename decltype( ptr )::element_type;
787 
788  GEOS_ERROR_IF( ptr == nullptr, "Failed to average over the second dimension of." );
789 
790  auto ret = std::make_unique< Wrapper< U > >( name, group, std::move( ptr ) );
791  for( integer dim = 2; dim < numArrayDims(); ++dim )
792  {
793  ret->setDimLabels( dim - 1, getDimLabels( dim ) );
794  }
795 
796  return ret;
797  }
798 
800  void registerToWrite() const override
801  {
802  m_conduitNode.reset();
803 
805  {
806  return;
807  }
808 
809  move( hostMemorySpace, false );
810 
811  m_conduitNode[ "__sizedFromParent__" ].set( sizedFromParent() );
812 
813  wrapperHelpers::pushDataToConduitNode( *m_data, m_conduitNode );
814  }
815 
817  void finishWriting() const override
818  { m_conduitNode.reset(); }
819 
820 
822  bool loadFromConduit() override
823  {
825  {
826  m_conduitNode.reset();
827  return false;
828  }
829 
830  setSizedFromParent( m_conduitNode[ "__sizedFromParent__" ].value() );
831 
832  wrapperHelpers::pullDataFromConduitNode( *m_data, m_conduitNode );
833 
834  m_conduitNode.reset();
835 
836  return true;
837  }
838 
845 
846  /*
847  * @brief Set whether this wrapper is resized when its parent is resized.
848  * @param val an int that is converted into a bool
849  * @return a pointer to this wrapper
850  */
851 
856  {
858  return *this;
859  }
860 
865  {
867  return *this;
868  }
869 
874  {
876  return *this;
877  }
878 
883  {
884  WrapperBase::setInputFlag( input );
885  return *this;
886  }
887 
891  Wrapper< T > & setDescription( string const & description )
892  {
893  WrapperBase::setDescription( description );
894  return *this;
895  }
896 
900  Wrapper< T > & appendDescription( string const & description )
901  {
902  WrapperBase::appendDescription( description );
903  return *this;
904  }
905 
909  Wrapper< T > & setRegisteringObjects( string const & objectName )
910  {
912  return *this;
913  }
914 
919  {
920  WrapperBase::setRTTypeName( rtTypeName );
921  return *this;
922  }
923 
925 
926 #if defined(USE_TOTALVIEW_OUTPUT)
927  virtual string totalviewTypeName() const override
928  {
929  return LvArray::system::demangle( typeid( Wrapper< T > ).name() );
930  }
931 
932  virtual int setTotalviewDisplay() const override
933  {
934  //std::cout<<"executing Wrapper::setTotalviewDisplay()"<<std::endl;
935  WrapperBase::setTotalviewDisplay();
936  TV_ttf_add_row( "m_ownsData", "bool", &m_ownsData );
937  TV_ttf_add_row( "m_data", LvArray::system::demangle< T >().c_str(), m_data );
938  TV_ttf_add_row( "m_default", LvArray::system::demangle< DefaultValue< T > >().c_str(), &m_default );
939  return 0;
940  }
941 // void tvTemplateInstantiation();
942 #endif
943 
944 #if defined(GEOS_USE_PYGEOSX)
945  virtual PyObject * createPythonObject( ) override
946  { return wrapperHelpers::createPythonObject( reference() ); }
947 #endif
948 
949 private:
950 
964  template< bool DO_PACKING >
965  localIndex packImpl( buffer_unit_type * & buffer,
966  bool withMetadata,
967  bool onDevice,
968  parallelDeviceEvents & events ) const
969  {
970  localIndex packedSize = 0;
971 
972  if( withMetadata )
973  { packedSize += bufferOps::Pack< DO_PACKING >( buffer, getName() ); }
974  if( onDevice )
975  {
976  if( withMetadata )
977  {
978  packedSize += wrapperHelpers::PackDevice< DO_PACKING >( buffer, reference(), events );
979  }
980  else
981  {
982  packedSize += wrapperHelpers::PackDataDevice< DO_PACKING >( buffer, reference(), events );
983  }
984  }
985  else
986  {
987  packedSize += bufferOps::Pack< DO_PACKING >( buffer, *m_data );
988  }
989 
990  return packedSize;
991  }
992 
1006  template< bool DO_PACKING >
1007  localIndex packByIndexImpl( buffer_unit_type * & buffer,
1008  arrayView1d< localIndex const > const & packList,
1009  bool withMetadata,
1010  bool onDevice,
1011  parallelDeviceEvents & events ) const
1012  {
1013  localIndex packedSize = 0;
1014 
1015  if( withMetadata )
1016  { packedSize += bufferOps::Pack< DO_PACKING >( buffer, getName() ); }
1017  if( onDevice )
1018  {
1019  if( withMetadata )
1020  {
1021  packedSize += wrapperHelpers::PackByIndexDevice< DO_PACKING >( buffer, reference(), packList, events );
1022  }
1023  else
1024  {
1025  packedSize += wrapperHelpers::PackDataByIndexDevice< DO_PACKING >( buffer, reference(), packList, events );
1026  }
1027  }
1028  else
1029  {
1030  packedSize += wrapperHelpers::PackByIndex< DO_PACKING >( buffer, *m_data, packList );
1031  }
1032 
1033  return packedSize;
1034  }
1035 
1039  localIndex packPrivate( buffer_unit_type * & buffer,
1040  bool withMetadata,
1041  bool onDevice,
1042  parallelDeviceEvents & events ) const override final
1043  {
1044  return this->packImpl< true >( buffer, withMetadata, onDevice, events );
1045  }
1046 
1050  localIndex packByIndexPrivate( buffer_unit_type * & buffer,
1051  arrayView1d< localIndex const > const & packList,
1052  bool withMetadata,
1053  bool onDevice,
1054  parallelDeviceEvents & events ) const override final
1055  {
1056  return this->packByIndexImpl< true >( buffer, packList, withMetadata, onDevice, events );
1057  }
1058 
1062  localIndex packSizePrivate( bool withMetadata,
1063  bool onDevice,
1064  parallelDeviceEvents & events ) const override final
1065  {
1066  buffer_unit_type * dummy;
1067  return this->packImpl< false >( dummy, withMetadata, onDevice, events );
1068  }
1069 
1073  localIndex packByIndexSizePrivate( arrayView1d< localIndex const > const & packList,
1074  bool withMetadata,
1075  bool onDevice,
1076  parallelDeviceEvents & events ) const override final
1077  {
1078  buffer_unit_type * dummy;
1079  return this->packByIndexImpl< false >( dummy, packList, withMetadata, onDevice, events );
1080  }
1081 
1084  bool m_ownsData;
1085 
1086  bool m_isClone;
1087 
1089  T * m_data;
1090 
1092  DefaultValue< T > m_default;
1093 
1095  wrapperHelpers::ArrayDimLabels< T > m_dimLabels;
1096 };
1097 
1098 }
1099 
1100 } // end of namespace geos
1101 
1102 // Do not remove the following commented code since it's used for debugging with TotalView.
1103 //template< typename T >
1104 //int TV_ttf_display_type( geos::dataRepository::Wrapper<T> const * wrapper)
1105 //{
1106 // std::cout<<"Executing "<<wrapper->totalviewTypeName()<<"::TV_ttf_display_type()"<<std::endl;
1107 // return TV_ttf_format_raw;
1108 //}
1109 //
1110 //template int TV_ttf_display_type( geos::dataRepository::Wrapper<int> const * wrapper );
1111 //
1112 //template< typename T >
1113 //void geos::dataRepository::Wrapper<T>::tvTemplateInstantiation()
1114 //{
1115 // TV_ttf_display_type<T>(this);
1116 //}
1117 
1118 #endif /* GEOS_DATAREPOSITORY_WRAPPER_HPP_ */
#define GEOS_DECLTYPE_AUTO_RETURN
Doxygen can't parse a decltype( auto ) return type, using this gets around that.
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:142
#define GEOS_THROW_IF(EXP, msg, TYPE)
Conditionally throw an exception.
Definition: Logger.hpp:151
A minimal class to specify information about time history information being collected and output.
Lightweight non-owning wrapper over a contiguous range of elements.
Definition: Span.hpp:42
Base class for all wrappers containing common operations.
Definition: WrapperBase.hpp:56
InputFlags getInputFlag() const
Get the InputFlag of the wrapper.
string const & getName() const
Get name of the wrapper.
string const & getRTTypeName() const
int sizedFromParent() const
Check whether this wrapper is resized when its parent is resized.
RestartFlags getRestartFlags() const
Get the RestartFlags of the wrapper.
WrapperBase & setInputFlag(InputFlags const input)
Set the InputFlag of the wrapper.
conduit::Node & m_conduitNode
A reference to the corresponding conduit::Node.
string dumpInputOptions(bool const outputHeader) const
WrapperBase & setDescription(string const &description)
Set the description string of the wrapper.
WrapperBase & setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
virtual void copyWrapperAttributes(WrapperBase const &source)
Copy attributes from another wrapper.
WrapperBase & setRegisteringObjects(string const &objectName)
Add a new name to the list of groups that register this wrapper.
WrapperBase & setRestartFlags(RestartFlags flags)
Set the RestartFlags of the wrapper.
string m_rtTypeName
A string regex to validate the input values string to parse for the wrapped object.
WrapperBase & appendDescription(string const &description)
Add up more text to the existing description string of the wrapper.
void createDataContext(xmlWrapper::xmlNode const &targetNode, xmlWrapper::xmlNodePos const &nodePos)
Sets the m_dataContext to a DataFileContext by retrieving the attribute file line.
bool m_successfulReadFromInput
Flag to indicate if wrapped object was successfully read from input.
virtual std::type_info const & getTypeId() const =0
Get the typeid of T.
WrapperBase & setRTTypeName(string_view rtTypeName)
override the rtType to use when parsing an input value to the wrapped object. It can be useful to cha...
string m_name
Name of the object that is being wrapped.
WrapperBase & setPlotLevel(PlotLevel const flag)
Set the PlotLevel of the wrapper.
void addBlueprintField(conduit::Node &fields, string const &name, string const &topology, std::vector< string > const &componentNames={}) const override
Push the data in the wrapper into a Conduit blueprint field.
Definition: Wrapper.hpp:772
virtual Wrapper & setDimLabels(integer const dim, Span< string const > const labels) override
Set dimension labels for an array.
Definition: Wrapper.hpp:253
Wrapper< T > & setRTTypeName(string_view rtTypeName)
override the rtType to use when parsing an input value to the wrapped object. It can be useful to cha...
Definition: Wrapper.hpp:918
Wrapper< T > & setRestartFlags(RestartFlags flags)
Set the RestartFlags of the wrapper.
Definition: Wrapper.hpp:864
virtual const std::type_info & getTypeId() const noexcept override
Get the typeid of T.
Definition: Wrapper.hpp:210
Wrapper & operator=(Wrapper &&source)
Move Assignment Operator.
Definition: Wrapper.hpp:169
virtual void copyWrapperAttributes(WrapperBase const &source) override
Copy attributes from another wrapper.
Definition: Wrapper.hpp:200
Wrapper< T > & setInputFlag(InputFlags const input)
Set the InputFlag of the wrapper.
Definition: Wrapper.hpp:882
T TYPE
Alias for the wrapped type T.
Definition: Wrapper.hpp:64
void registerToWrite() const override
Register the wrapper's data for writing with Conduit.
Definition: Wrapper.hpp:800
std::enable_if_t< !traits::is_array< U > &&DefaultValue< U >::has_default_value, Wrapper< T > & > setApplyDefaultValue(typename DefaultValue< U >::value_type const &defaultVal)
Set and apply for default value.
Definition: Wrapper.hpp:683
virtual void resize(localIndex const newSize) override
Calls T::resize(newsize) if it exists.
Definition: Wrapper.hpp:411
virtual void reserve(localIndex const newCapacity) override
Calls T::reserve( newCapacity ) if it exists, otherwise a no-op.
Definition: Wrapper.hpp:397
virtual bool isPackable(bool onDevice) const override
Check whether wrapped type is can be packed into a buffer on host or device.
Definition: Wrapper.hpp:281
Wrapper< T > & setRegisteringObjects(string const &objectName)
Add a new name to the list of groups that register this wrapper.
Definition: Wrapper.hpp:909
static Wrapper< T > const & cast(WrapperBase const &wrapper)
Downcast base to a const typed wrapper.
Definition: Wrapper.hpp:234
GEOS_DECLTYPE_AUTO_RETURN referenceAsView() const
Provide access to wrapped object converted to a view, if possible.
Definition: Wrapper.hpp:615
void setName()
DO_NOT_DOCUMENT.
Definition: Wrapper.hpp:767
T & referenceAsView()
Provide access to wrapped object converted to a view, if possible.
Definition: Wrapper.hpp:608
virtual ~Wrapper() noexcept override
Default destructor.
Definition: Wrapper.hpp:143
Wrapper(string const &name, Group &parent, std::unique_ptr< T > object)
Constructor that takes ownership of an existing object.
Definition: Wrapper.hpp:98
std::enable_if_t< traits::is_array< U > &&DefaultValue< U >::has_default_value, Wrapper< T > & > setApplyDefaultValue(typename DefaultValue< U >::value_type const &defaultVal)
Set and apply for default value.
Definition: Wrapper.hpp:697
virtual std::unique_ptr< WrapperBase > clone(string const &name, Group &parent) override
Creates a clone of *this WrapperBase.
Definition: Wrapper.hpp:183
Wrapper< T > & setPlotLevel(PlotLevel const flag)
Set the PlotLevel of the wrapper.
Definition: Wrapper.hpp:873
virtual void copy(localIndex const sourceIndex, localIndex const destIndex) override
Calls T::copy(sourceIndex, destIndex)
Definition: Wrapper.hpp:449
virtual localIndex capacity() const override
Definition: Wrapper.hpp:404
GEOS_DECLTYPE_AUTO_RETURN referenceAsView()
Provide access to wrapped object converted to a view, if possible.
Definition: Wrapper.hpp:601
GEOS_DECLTYPE_AUTO_RETURN reference() const
const Accessor for m_data
Definition: Wrapper.hpp:589
void populateMCArray(conduit::Node &node, std::vector< string > const &componentNames={}) const override
Push the data in the wrapper into a Conduit Blueprint mcarray.
Definition: Wrapper.hpp:779
virtual size_t bytesAllocated() const override final
Definition: Wrapper.hpp:371
virtual localIndex unpack(buffer_unit_type const *&buffer, bool withMetadata, bool onDevice, parallelDeviceEvents &events) override final
Unpack the entire wrapped object from a buffer.
Definition: Wrapper.hpp:297
virtual HistoryMetadata getHistoryMetadata(localIndex const packCount=-1) const override final
Get a description of the wrapped data for time history collection/output.
Definition: Wrapper.hpp:268
Wrapper(string const &name, Group &parent, T *object)
Constructor that does not take ownership of an existing object.
Definition: Wrapper.hpp:121
Wrapper< T > & setDescription(string const &description)
Set the description string of the wrapper.
Definition: Wrapper.hpp:891
virtual localIndex numArrayComp() const override
Return the number of components in a multidimensional array.
Definition: Wrapper.hpp:248
Wrapper(string const &name, Group &parent)
Constructor that creates a new instance of wrapped type.
Definition: Wrapper.hpp:76
virtual bool processInputFile(xmlWrapper::xmlNode const &targetNode, xmlWrapper::xmlNodePos const &nodePos) override
Initialize the wrapper from the input xml node.
Definition: Wrapper.hpp:714
virtual void resize(int ndims, localIndex const *const dims) override
Calls T::resize( num_dims, dims )
Definition: Wrapper.hpp:390
Wrapper< T > & appendDescription(string const &description)
Add up more text to the existing description string of the wrapper.
Definition: Wrapper.hpp:900
void finishWriting() const override
Write the wrapped data into Conduit.
Definition: Wrapper.hpp:817
virtual localIndex size() const override
Calls T::size()
Definition: Wrapper.hpp:386
virtual localIndex unpackByIndex(buffer_unit_type const *&buffer, arrayView1d< localIndex const > const &unpackIndices, bool withMetadata, bool onDevice, parallelDeviceEvents &events, MPI_Op op) override final
For indexable types, unpack selected indices of wrapped object from a buffer.
Definition: Wrapper.hpp:327
T const & referenceAsView() const
Provide access to wrapped object converted to a view, if possible.
Definition: Wrapper.hpp:622
virtual string getDefaultValueString() const override
Return a string representing the default value.
Definition: Wrapper.hpp:707
bool loadFromConduit() override
Read the wrapped data from Conduit.
Definition: Wrapper.hpp:822
DefaultValue< T > const & getDefaultValueStruct() const
Accessor for m_default.
Definition: Wrapper.hpp:646
virtual int numArrayDims() const override
Return the number of dimensions of the array.
Definition: Wrapper.hpp:243
void const * voidPointer() const override
Definition: Wrapper.hpp:364
std::enable_if_t< DefaultValue< U >::has_default_value, Wrapper< T > & > setDefaultValue(typename DefaultValue< U >::value_type const &defaultVal)
Setter for default value.
Definition: Wrapper.hpp:670
Wrapper< T > & setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
Definition: Wrapper.hpp:855
virtual bool hasDefaultValue() const final override
Return true iff this wrapper has a valid default value.
Definition: Wrapper.hpp:635
std::enable_if_t< DefaultValue< U >::has_default_value, typename DefaultValue< U >::value_type const & > getDefaultValue() const
Accessor for default value.
Definition: Wrapper.hpp:658
Wrapper & operator=(Wrapper const &source)
Copy Assignment Operator.
Definition: Wrapper.hpp:158
virtual void copyWrapper(WrapperBase const &source) override
Copies the contents of a Wrapper into *this.
Definition: Wrapper.hpp:192
void erase(std::set< localIndex > const &indicesToErase) override
Calls T::erase(indicesToErase)
Definition: Wrapper.hpp:555
static Wrapper & cast(WrapperBase &wrapper)
Downcast base to a typed wrapper.
Definition: Wrapper.hpp:221
virtual Regex const & getTypeRegex() const override
Definition: Wrapper.hpp:567
virtual void copyData(WrapperBase const &source) override
Copy the the data contained in another wrapper into this wrapper.
Definition: Wrapper.hpp:456
T & reference()
Accessor for m_data.
Definition: Wrapper.hpp:581
virtual void move(LvArray::MemorySpace const space, bool const touch) const override
Calls T::move(space, touch)
Definition: Wrapper.hpp:563
std::unique_ptr< WrapperBase > averageOverSecondDim(string const &name, Group &group) const override
Create a new Wrapper with values averaged over the second dimension.
Definition: Wrapper.hpp:783
virtual localIndex elementByteSize() const override
Definition: Wrapper.hpp:368
virtual Span< string const > getDimLabels(integer const dim) const override
Get dimension labels of an array.
Definition: Wrapper.hpp:259
@ OPTIONAL
Optional in input.
@ REQUIRED
Required in input.
internal::Helper< T > DefaultValue
A templated alias to hold default values.
@ WRITE_AND_READ
Write and read from restart.
@ NO_WRITE
Do not write into restart.
pugi::xml_node xmlNode
Definition: xmlWrapper.hpp:59
std::enable_if_t< !internal::canParseVariable< T >, bool > readAttributeAsType(T &, string const &name, Regex const &, xmlNode const &, U const &)
Extract attribute in an xml tree, and translate its value into a typed variable. This SFINAE implemen...
Definition: xmlWrapper.hpp:446
void processInputException(std::exception const &ex, string const &targetAttributeName, xmlWrapper::xmlNode const &targetNode, xmlWrapper::xmlNodePos const &nodePos)
Helper method to process an exception that has been thrown during xml parsing.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
LvArray::Array< T, NDIM, PERMUTATION, localIndex, LvArray::ChaiBuffer > Array
Multidimensional array type. See LvArray:Array for details.
Definition: DataTypes.hpp:142
std::string string
String type.
Definition: DataTypes.hpp:91
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:85
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
void erase(OrderedVariableToManyElementRelation &relation, localIndex const firstIndex, localIndex const er, localIndex const esr, localIndex const ei)
Remove an element relation from an object in the relation.
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:109
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176
std::enable_if< can_history_io< T >, HistoryMetadata >::type getHistoryMetadata(string const &name, ArrayView< T const, 1, 0 > const &arr, localIndex const numComps, localIndex sizeOverride=-1)
Produce a HistoryMetadata object for a supported one-dimensional array type.
std::string_view string_view
String type.
Definition: DataTypes.hpp:94
Exception class used to report errors in user input.
Definition: Logger.hpp:502