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  if constexpr ( traits::HasMemberFunction_resizeDefault< T > && DefaultValue< T >::has_default_value )
415  {
416  wrapperHelpers::resizeDefault( reference(), newSize, m_default, this->getName() );
417  }
418  else
419  {
420  wrapperHelpers::resize( reference(), newSize );
421  }
422  }
423 
425  struct copy_wrapper
426  {
427  template< typename U, int NDIM, typename PERMUTATION >
428  static void copy( Array< U, NDIM, PERMUTATION > const & array, localIndex const sourceIndex, localIndex const destIndex )
429  {
430  LvArray::forValuesInSliceWithIndices( array[ sourceIndex ],
431  [destIndex, &array]( U const & sourceVal, auto const ... indicesToErase )
432  {
433  array( destIndex, indicesToErase ... ) = sourceVal;
434  } );
435  }
436 
437  template< typename U >
438  static void copy( U const &, localIndex const, localIndex const )
439  {}
440 
441  template< typename U=T >
442  static std::enable_if_t< traits::hasCopyAssignmentOp< U > >
443  copyData( U & destinationData, U const & sourceData )
444  {
445  destinationData = sourceData;
446  }
447 
448  template< typename U=T >
449  static std::enable_if_t< !traits::hasCopyAssignmentOp< U > >
450  copyData( U &, U const & )
451  {}
452  };
454 
456  virtual void copy( localIndex const sourceIndex, localIndex const destIndex ) override
457  {
458  copy_wrapper::copy( reference(), sourceIndex, destIndex );
459  }
460 
461 
462 
463  virtual void copyData( WrapperBase const & source ) override
464  {
465  Wrapper< T > const & castedSource = dynamicCast< Wrapper< T > const & >( source );
466  copy_wrapper::copyData( *m_data, *castedSource.m_data );
467  }
468 
469 
471  struct erase_wrapper // This should probably be in LvArray?
472  {
473  template< typename TYPE >
474  static void erase( TYPE &, std::set< localIndex > const & )
475  {}
476 
477  template< typename TYPE >
478  static void erase( array1d< TYPE > & array, std::set< localIndex > const & indicesToErase )
479  {
480  int oldSize = array.size( 0 );
481  int numToErase = indicesToErase.size();
482  int newSize = oldSize - numToErase;
483  std::set< localIndex >::iterator it = indicesToErase.begin();
484  int offset = 0;
485  for( localIndex i=*it+1; i<oldSize; i++ )
486  {
487  if( i == *it + 1 )
488  {
489  offset++;
490  if( offset < numToErase )
491  {
492  it++;
493  }
494  }
495  array[i-offset] = array[i];
496  }
497  array.resize( newSize );
498  }
499 
500  template< typename TYPE >
501  static void erase( array2d< TYPE > & array, std::set< localIndex > const & indicesToErase )
502  {
503  int oldSize = array.size( 0 );
504  int numToErase = indicesToErase.size();
505  int newSize = oldSize - numToErase;
506  int dim1 = array.size( 1 );
507  std::set< localIndex >::iterator it = indicesToErase.begin();
508  int offset = 0;
509  for( localIndex i=*it+1; i<oldSize; i++ )
510  {
511  if( i == *it + 1 )
512  {
513  offset++;
514  if( offset < numToErase )
515  {
516  it++;
517  }
518  }
519  for( int j=0; j<dim1; j++ )
520  {
521  array[i-offset][j] = array[i][j];
522  }
523  }
524  array.resize( newSize );
525  }
526 
527  template< typename TYPE >
528  static void erase( array3d< TYPE > & array, std::set< localIndex > const & indicesToErase )
529  {
530  int oldSize = array.size( 0 );
531  int numToErase = indicesToErase.size();
532  int newSize = oldSize - numToErase;
533  int dim1 = array.size( 1 );
534  int dim2 = array.size( 2 );
535  std::set< localIndex >::iterator it = indicesToErase.begin();
536  int offset = 0;
537  for( localIndex i=*it+1; i<oldSize; i++ )
538  {
539  if( i == *it + 1 )
540  {
541  offset++;
542  if( offset < numToErase )
543  {
544  it++;
545  }
546  }
547  for( int j=0; j<dim1; j++ )
548  {
549  for( int k=0; k<dim2; k++ )
550  {
551  array[i-offset][j][k] = array[i][j][k];
552  }
553  }
554  }
555  array.resize( newSize );
556  }
557  };
559 
560 
562  void erase( std::set< localIndex > const & indicesToErase ) override
563  {
564  GEOS_ERROR_IF( indicesToErase.size() == 0, "Wrapper::erase() can only be called on a populated set of indices!" );
565  erase_wrapper::erase( reference(), indicesToErase );
566  }
567 
568 
570  virtual void move( LvArray::MemorySpace const space, bool const touch ) const override
571  { return wrapperHelpers::move( *m_data, space, touch ); }
572 
574  virtual Regex const & getTypeRegex() const override
575  { return rtTypes::getTypeRegex< T >( m_rtTypeName ); }
576 
578 
583 
588  T & reference()
589  { return *m_data; }
590 
597  { return referenceAsView(); }
598 
607  template< typename _T=T, typename=std::enable_if_t< traits::HasMemberFunction_toView< _T > > >
609  { return m_data->toView(); }
610 
614  template< typename _T=T, typename=std::enable_if_t< !traits::HasMemberFunction_toView< _T > > >
616  { return *m_data; }
617 
621  template< typename _T=T, typename=std::enable_if_t< traits::HasMemberFunction_toView< _T > > >
623  { return m_data->toViewConst(); }
624 
628  template< typename _T=T, typename=std::enable_if_t< !traits::HasMemberFunction_toView< _T > > >
629  T const & referenceAsView() const
630  { return *m_data; }
631 
633 
638 
642  virtual bool hasDefaultValue() const final override
643  {
644  return m_default.has_default_value;
645  }
646 
651  template< typename U=T >
652  DefaultValue< T > const &
654  {
655  return m_default;
656  }
657 
658 
663  template< typename U=T >
664  std::enable_if_t< DefaultValue< U >::has_default_value, typename DefaultValue< U >::value_type const & >
666  {
667  return m_default.value;
668  }
669 
675  template< typename U=T >
676  std::enable_if_t< DefaultValue< U >::has_default_value, Wrapper< T > & >
677  setDefaultValue( typename DefaultValue< U >::value_type const & defaultVal )
678  {
679  m_default.value = defaultVal;
680  return *this;
681  }
682 
688  template< typename U=T >
689  std::enable_if_t< !traits::is_array< U > && DefaultValue< U >::has_default_value, Wrapper< T > & >
690  setApplyDefaultValue( typename DefaultValue< U >::value_type const & defaultVal )
691  {
692  m_default.value = defaultVal;
693  *m_data = m_default.value;
694  return *this;
695  }
696 
702  template< typename U=T >
703  std::enable_if_t< traits::is_array< U > && DefaultValue< U >::has_default_value, Wrapper< T > & >
704  setApplyDefaultValue( typename DefaultValue< U >::value_type const & defaultVal )
705  {
706  m_default.value = defaultVal;
707  m_data->template setValues< serialPolicy >( m_default.value );
708  return *this;
709  }
710 
714  virtual string getDefaultValueString() const override
715  {
716  std::ostringstream ss;
717  ss << std::string( numArrayDims(), '{' ) << m_default << std::string( numArrayDims(), '}' );
718  return ss.str();
719  }
720 
721  virtual bool processInputFile( xmlWrapper::xmlNode const & targetNode,
722  xmlWrapper::xmlNodePos const & nodePos ) override
723  {
724  InputFlags const inputFlag = getInputFlag();
725  if( inputFlag >= InputFlags::OPTIONAL )
726  {
727  try
728  {
729  if( inputFlag == InputFlags::REQUIRED || !hasDefaultValue() )
730  {
732  getName(),
733  rtTypes::getTypeRegex< T >( getRTTypeName() ),
734  targetNode,
735  inputFlag == InputFlags::REQUIRED );
737  GEOS_FMT( "XML Node {} ({}) with name={} is missing required attribute '{}'.\n"
738  "For more details, please refer to documentation at:\n"
739  "http://geosx-geosx.readthedocs-hosted.com/en/latest/docs/sphinx/userGuide/Index.html",
740  targetNode.name(), nodePos.toString(), targetNode.attribute( "name" ).value(),
741  getName()),
742  InputError );
743  }
744  else
745  {
747  getName(),
748  rtTypes::getTypeRegex< T >( getRTTypeName() ),
749  targetNode,
751  }
752  }
753  catch( std::exception const & ex )
754  {
755  xmlWrapper::processInputException( ex, getName(), targetNode, nodePos );
756  }
757 
759  createDataContext( targetNode, nodePos );
760 
761  return true;
762  }
763 
764  return false;
765  }
766 
768 
774  void setName()
775  { wrapperHelpers::setName( reference(), m_conduitNode.path() ); }
776 
777 
779  void addBlueprintField( conduit::Node & fields,
780  string const & name,
781  string const & topology,
782  stdVector< string > const & componentNames = {} ) const override
783  { wrapperHelpers::addBlueprintField( reference(), fields, name, topology, componentNames ); }
784 
786  void populateMCArray( conduit::Node & node, stdVector< string > const & componentNames = {} ) const override
787  { wrapperHelpers::populateMCArray( reference(), node, componentNames ); }
788 
790  std::unique_ptr< WrapperBase > averageOverSecondDim( string const & name, Group & group ) const override
791  {
792  auto ptr = wrapperHelpers::averageOverSecondDim( reference() );
793  using U = typename decltype( ptr )::element_type;
794 
795  GEOS_ERROR_IF( ptr == nullptr, "Failed to average over the second dimension of." );
796 
797  auto ret = std::make_unique< Wrapper< U > >( name, group, std::move( ptr ) );
798  for( integer dim = 2; dim < numArrayDims(); ++dim )
799  {
800  ret->setDimLabels( dim - 1, getDimLabels( dim ) );
801  }
802 
803  return ret;
804  }
805 
807  void registerToWrite() const override
808  {
809  m_conduitNode.reset();
810 
812  {
813  return;
814  }
815 
816  move( hostMemorySpace, false );
817 
818  m_conduitNode[ "__sizedFromParent__" ].set( sizedFromParent() );
819 
820  wrapperHelpers::pushDataToConduitNode( *m_data, m_conduitNode );
821  }
822 
824  void finishWriting() const override
825  { m_conduitNode.reset(); }
826 
827 
829  bool loadFromConduit() override
830  {
832  {
833  m_conduitNode.reset();
834  return false;
835  }
836 
837  setSizedFromParent( m_conduitNode[ "__sizedFromParent__" ].value() );
838 
839  wrapperHelpers::pullDataFromConduitNode( *m_data, m_conduitNode );
840 
841  m_conduitNode.reset();
842 
843  return true;
844  }
845 
852 
853  /*
854  * @brief Set whether this wrapper is resized when its parent is resized.
855  * @param val an int that is converted into a bool
856  * @return a pointer to this wrapper
857  */
858 
863  {
865  return *this;
866  }
867 
872  {
874  return *this;
875  }
876 
881  {
883  return *this;
884  }
885 
890  {
891  WrapperBase::setInputFlag( input );
892  return *this;
893  }
894 
898  Wrapper< T > & setDescription( string const & description )
899  {
900  WrapperBase::setDescription( description );
901  return *this;
902  }
903 
907  Wrapper< T > & appendDescription( string const & description )
908  {
909  WrapperBase::appendDescription( description );
910  return *this;
911  }
912 
916  Wrapper< T > & setRegisteringObjects( string const & objectName )
917  {
919  return *this;
920  }
921 
926  {
927  WrapperBase::setRTTypeName( rtTypeName );
928  return *this;
929  }
930 
932 
933 #if defined(USE_TOTALVIEW_OUTPUT)
934  virtual string totalviewTypeName() const override
935  {
936  return LvArray::system::demangle( typeid( Wrapper< T > ).name() );
937  }
938 
939  virtual int setTotalviewDisplay() const override
940  {
941  //std::cout<<"executing Wrapper::setTotalviewDisplay()"<<std::endl;
942  WrapperBase::setTotalviewDisplay();
943  TV_ttf_add_row( "m_ownsData", "bool", &m_ownsData );
944  TV_ttf_add_row( "m_data", LvArray::system::demangle< T >().c_str(), m_data );
945  TV_ttf_add_row( "m_default", LvArray::system::demangle< DefaultValue< T > >().c_str(), &m_default );
946  return 0;
947  }
948 // void tvTemplateInstantiation();
949 #endif
950 
951 #if defined(GEOS_USE_PYGEOSX)
952  virtual PyObject * createPythonObject( ) override
953  { return wrapperHelpers::createPythonObject( reference() ); }
954 #endif
955 
956 private:
957 
971  template< bool DO_PACKING >
972  localIndex packImpl( buffer_unit_type * & buffer,
973  bool withMetadata,
974  bool onDevice,
975  parallelDeviceEvents & events ) const
976  {
977  localIndex packedSize = 0;
978 
979  if( withMetadata )
980  { packedSize += bufferOps::Pack< DO_PACKING >( buffer, getName() ); }
981  if( onDevice )
982  {
983  if( withMetadata )
984  {
985  packedSize += wrapperHelpers::PackDevice< DO_PACKING >( buffer, reference(), events );
986  }
987  else
988  {
989  packedSize += wrapperHelpers::PackDataDevice< DO_PACKING >( buffer, reference(), events );
990  }
991  }
992  else
993  {
994  packedSize += bufferOps::Pack< DO_PACKING >( buffer, *m_data );
995  }
996 
997  return packedSize;
998  }
999 
1013  template< bool DO_PACKING >
1014  localIndex packByIndexImpl( buffer_unit_type * & buffer,
1015  arrayView1d< localIndex const > const & packList,
1016  bool withMetadata,
1017  bool onDevice,
1018  parallelDeviceEvents & events ) const
1019  {
1020  localIndex packedSize = 0;
1021 
1022  if( withMetadata )
1023  { packedSize += bufferOps::Pack< DO_PACKING >( buffer, getName() ); }
1024  if( onDevice )
1025  {
1026  if( withMetadata )
1027  {
1028  packedSize += wrapperHelpers::PackByIndexDevice< DO_PACKING >( buffer, reference(), packList, events );
1029  }
1030  else
1031  {
1032  packedSize += wrapperHelpers::PackDataByIndexDevice< DO_PACKING >( buffer, reference(), packList, events );
1033  }
1034  }
1035  else
1036  {
1037  packedSize += wrapperHelpers::PackByIndex< DO_PACKING >( buffer, *m_data, packList );
1038  }
1039 
1040  return packedSize;
1041  }
1042 
1046  localIndex packPrivate( buffer_unit_type * & buffer,
1047  bool withMetadata,
1048  bool onDevice,
1049  parallelDeviceEvents & events ) const override final
1050  {
1051  return this->packImpl< true >( buffer, withMetadata, onDevice, events );
1052  }
1053 
1057  localIndex packByIndexPrivate( buffer_unit_type * & buffer,
1058  arrayView1d< localIndex const > const & packList,
1059  bool withMetadata,
1060  bool onDevice,
1061  parallelDeviceEvents & events ) const override final
1062  {
1063  return this->packByIndexImpl< true >( buffer, packList, withMetadata, onDevice, events );
1064  }
1065 
1069  localIndex packSizePrivate( bool withMetadata,
1070  bool onDevice,
1071  parallelDeviceEvents & events ) const override final
1072  {
1073  buffer_unit_type * dummy;
1074  return this->packImpl< false >( dummy, withMetadata, onDevice, events );
1075  }
1076 
1080  localIndex packByIndexSizePrivate( arrayView1d< localIndex const > const & packList,
1081  bool withMetadata,
1082  bool onDevice,
1083  parallelDeviceEvents & events ) const override final
1084  {
1085  buffer_unit_type * dummy;
1086  return this->packByIndexImpl< false >( dummy, packList, withMetadata, onDevice, events );
1087  }
1088 
1091  bool m_ownsData;
1092 
1093  bool m_isClone;
1094 
1096  T * m_data;
1097 
1099  DefaultValue< T > m_default;
1100 
1102  wrapperHelpers::ArrayDimLabels< T > m_dimLabels;
1103 };
1104 
1105 }
1106 
1107 } // end of namespace geos
1108 
1109 // Do not remove the following commented code since it's used for debugging with TotalView.
1110 //template< typename T >
1111 //int TV_ttf_display_type( geos::dataRepository::Wrapper<T> const * wrapper)
1112 //{
1113 // std::cout<<"Executing "<<wrapper->totalviewTypeName()<<"::TV_ttf_display_type()"<<std::endl;
1114 // return TV_ttf_format_raw;
1115 //}
1116 //
1117 //template int TV_ttf_display_type( geos::dataRepository::Wrapper<int> const * wrapper );
1118 //
1119 //template< typename T >
1120 //void geos::dataRepository::Wrapper<T>::tvTemplateInstantiation()
1121 //{
1122 // TV_ttf_display_type<T>(this);
1123 //}
1124 
1125 #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.
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.
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:925
Wrapper< T > & setRestartFlags(RestartFlags flags)
Set the RestartFlags of the wrapper.
Definition: Wrapper.hpp:871
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:889
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:807
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:690
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:916
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:622
void setName()
DO_NOT_DOCUMENT.
Definition: Wrapper.hpp:774
T & referenceAsView()
Provide access to wrapped object converted to a view, if possible.
Definition: Wrapper.hpp:615
virtual ~Wrapper() noexcept override
Default destructor.
Definition: Wrapper.hpp:143
void populateMCArray(conduit::Node &node, stdVector< string > const &componentNames={}) const override
Push the data in the wrapper into a Conduit Blueprint mcarray.
Definition: Wrapper.hpp:786
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:704
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:880
virtual void copy(localIndex const sourceIndex, localIndex const destIndex) override
Calls T::copy(sourceIndex, destIndex)
Definition: Wrapper.hpp:456
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:608
GEOS_DECLTYPE_AUTO_RETURN reference() const
const Accessor for m_data
Definition: Wrapper.hpp:596
virtual size_t bytesAllocated() const override final
Definition: Wrapper.hpp:371
void addBlueprintField(conduit::Node &fields, string const &name, string const &topology, stdVector< string > const &componentNames={}) const override
Push the data in the wrapper into a Conduit blueprint field.
Definition: Wrapper.hpp:779
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:898
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:721
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:907
void finishWriting() const override
Write the wrapped data into Conduit.
Definition: Wrapper.hpp:824
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:629
virtual string getDefaultValueString() const override
Return a string representing the default value.
Definition: Wrapper.hpp:714
bool loadFromConduit() override
Read the wrapped data from Conduit.
Definition: Wrapper.hpp:829
DefaultValue< T > const & getDefaultValueStruct() const
Accessor for m_default.
Definition: Wrapper.hpp:653
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:677
Wrapper< T > & setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
Definition: Wrapper.hpp:862
virtual bool hasDefaultValue() const final override
Return true iff this wrapper has a valid default value.
Definition: Wrapper.hpp:642
std::enable_if_t< DefaultValue< U >::has_default_value, typename DefaultValue< U >::value_type const & > getDefaultValue() const
Accessor for default value.
Definition: Wrapper.hpp:665
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:562
static Wrapper & cast(WrapperBase &wrapper)
Downcast base to a typed wrapper.
Definition: Wrapper.hpp:221
virtual Regex const & getTypeRegex() const override
Definition: Wrapper.hpp:574
virtual void copyData(WrapperBase const &source) override
Copy the the data contained in another wrapper into this wrapper.
Definition: Wrapper.hpp:463
T & reference()
Accessor for m_data.
Definition: Wrapper.hpp:588
virtual void move(LvArray::MemorySpace const space, bool const touch) const override
Calls T::move(space, touch)
Definition: Wrapper.hpp:570
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:790
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:463
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:188
LvArray::Array< T, NDIM, PERMUTATION, localIndex, LvArray::ChaiBuffer > Array
Multidimensional array type. See LvArray:Array for details.
Definition: DataTypes.hpp:150
std::string string
String type.
Definition: DataTypes.hpp:90
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:81
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.
std::vector< T, Allocator > stdVector
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:117
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:184
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:93
Exception class used to report errors in user input.
Definition: Logger.hpp:464