GEOSX
Wrapper.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_DATAREPOSITORY_WRAPPER_HPP_
20 #define GEOSX_DATAREPOSITORY_WRAPPER_HPP_
21 
22 // Source inclues
23 #include "wrapperHelpers.hpp"
24 #include "KeyNames.hpp"
25 #include "LvArray/src/limits.hpp"
26 #include "common/DataTypes.hpp"
27 #include "codingUtilities/SFINAE_Macros.hpp"
28 #include "LvArray/src/Macros.hpp"
29 #include "BufferOps.hpp"
30 #include "BufferOpsDevice.hpp"
31 #include "RestartFlags.hpp"
32 #include "codingUtilities/traits.hpp"
33 #include "common/GeosxConfig.hpp"
34 #include "DefaultValue.hpp"
35 #include "LvArray/src/system.hpp"
36 #include "WrapperBase.hpp"
37 
38 // System includes
39 #include <type_traits>
40 #include <cstdlib>
41 #include <type_traits>
42 
43 namespace geosx
44 {
45 
46 namespace dataRepository
47 {
48 //template< typename U >
49 //static void totalViewType( char * const dataType );
50 
55 template< typename T >
56 class Wrapper final : public WrapperBase
57 {
58 public:
59 
63  using TYPE = T;
64 
68 
75  explicit Wrapper( std::string const & name,
76  Group * const parent ):
77  WrapperBase( name, parent ),
78  m_ownsData( true ),
79  m_data( new T() ),
80  m_default()
81  {
82  if( traits::is_tensorT< T > || std::is_arithmetic< T >::value || traits::is_string< T > )
83  {
84  this->setSizedFromParent( 0 );
85  }
86 
87  setName();
88  }
89 
96  explicit Wrapper( std::string const & name,
97  Group * const parent,
98  std::unique_ptr< T > object ):
99  WrapperBase( name, parent ),
100  m_ownsData( true ),
101  m_data( object.release() ),
102  m_default()
103  {
104  if( traits::is_tensorT< T > || std::is_arithmetic< T >::value || traits::is_string< T > )
105  {
106  this->setSizedFromParent( 0 );
107  }
108 
109  setName();
110  }
111 
118  explicit Wrapper( std::string const & name,
119  Group * const parent,
120  T * object ):
121  WrapperBase( name, parent ),
122  m_ownsData( false ),
123  m_data( object ),
124  m_default()
125  {
126  if( traits::is_tensorT< T > || std::is_arithmetic< T >::value || traits::is_string< T > )
127  {
128  this->setSizedFromParent( 0 );
129  }
130 
131  setName();
132  }
133 
139  virtual ~Wrapper() noexcept override
140  {
141  if( m_ownsData )
142  {
143  delete m_data;
144  }
145  //tvTemplateInstantiation();
146  }
147 
154  Wrapper & operator=( Wrapper const & source )
155  {
156  m_data = source.m_data;
157  return *this;
158  }
159 
165  Wrapper & operator=( Wrapper && source )
166  {
167  m_data = std::move( source.m_data );
168  return *this;
169  }
170 
172 
176 
179  virtual std::unique_ptr< WrapperBase > clone( string const & name,
180  Group * const parent ) override
181  {
182  std::unique_ptr< WrapperBase >
183  clonedWrapper = std::make_unique< Wrapper< T > >( name, parent, this->m_data );
184  clonedWrapper->copyWrapperAttributes( *this );
185 
186  return clonedWrapper;
187  }
188 
189  virtual void copyWrapper( WrapperBase const & source ) override
190  {
191  GEOSX_ERROR_IF( source.getName() != this->m_name, "Tried to clone wrapper of with different name" );
193  Wrapper< T > const & castedSource = *cast( &source );
194  m_ownsData = castedSource.m_ownsData;
195  m_default = castedSource.m_default;
196  copyData( source );
197 
198  }
199 
201  virtual void copyWrapperAttributes( WrapperBase const & source ) override
202  {
204  Wrapper< T > const & castedSource = *cast( &source );
205  m_ownsData = castedSource.m_ownsData;
206  m_default = castedSource.m_default;
207  }
208 
210  virtual const std::type_info & get_typeid() const noexcept override
211  {
212  return typeid(T);
213  }
214 
216 
220 
228  static Wrapper< T > * cast( WrapperBase * const base )
229  {
230  return dynamicCast< Wrapper< T > * >( base );
231  }
232 
239  static Wrapper< T > const * cast( WrapperBase const * const base )
240  {
241  return dynamicCast< Wrapper< T > const * >( base );
242  }
243 
250  static Wrapper< T > & cast( WrapperBase & base )
251  {
252  return dynamicCast< Wrapper< T > & >( base );
253  }
254 
260  static Wrapper< T > const & cast( WrapperBase const & base )
261  {
262  return dynamicCast< Wrapper< T > const & >( base );
263  }
264 
266 
268  virtual
269  HistoryMetadata getHistoryMetadata( localIndex const packCount = -1 ) const override final
270  {
271  return geosx::getHistoryMetadata( getName(), this->referenceAsView( ), packCount );
272  }
273 
277 
281  virtual
282  bool isPackable( bool onDevice ) const override
283  {
284  if( onDevice )
285  {
286  // this isn't accurate if array/arraview return false for this, which I think they do
287  return bufferOps::can_memcpy< T >;
288  }
289  else
290  {
291  return bufferOps::is_packable< T >;
292  }
293  }
294 
297  virtual
298  localIndex Pack( buffer_unit_type * & buffer, bool withMetadata, bool onDevice ) const override final
299  {
300  localIndex packedSize = 0;
301  if( withMetadata ) packedSize += bufferOps::Pack< true >( buffer, this->getName() );
302  if( onDevice )
303  {
304  if( withMetadata )
305  {
306  packedSize += wrapperHelpers::PackDevice< true >( buffer, reference() );
307  }
308  else
309  {
310  packedSize += wrapperHelpers::PackDataDevice< true >( buffer, reference() );
311  }
312  }
313  else
314  {
315  packedSize += bufferOps::Pack< true >( buffer, *m_data );
316  }
317  return packedSize;
318  }
319 
322  virtual
323  localIndex PackByIndex( buffer_unit_type * & buffer, arrayView1d< localIndex const > const & packList, bool withMetadata, bool onDevice ) const override final
324  {
325  localIndex packedSize = 0;
326  if( sizedFromParent() == 1 )
327  {
328  if( withMetadata ) packedSize += bufferOps::Pack< true >( buffer, this->getName() );
329  if( onDevice )
330  {
331  if( withMetadata )
332  {
333  packedSize += wrapperHelpers::PackByIndexDevice< true >( buffer, reference(), packList );
334  }
335  else
336  {
337  packedSize += wrapperHelpers::PackDataByIndexDevice< true >( buffer, reference(), packList );
338  }
339  }
340  else
341  {
342  packedSize += wrapperHelpers::PackByIndex< true >( buffer, *m_data, packList );
343  }
344  }
345  return packedSize;
346  }
347 
350  virtual
351  localIndex PackSize( bool withMetadata, bool onDevice ) const override final
352  {
353  buffer_unit_type * buffer = nullptr;
354  localIndex packedSize = 0;
355  if( withMetadata ) packedSize += bufferOps::Pack< false >( buffer, this->getName() );
356  if( onDevice )
357  {
358  if( withMetadata )
359  {
360  packedSize += wrapperHelpers::PackDevice< false >( buffer, reference() );
361  }
362  else
363  {
364  packedSize += wrapperHelpers::PackDataDevice< false >( buffer, reference() );
365  }
366  }
367  else
368  {
369  packedSize += bufferOps::Pack< false >( buffer, *m_data );
370  }
371  return packedSize;
372  }
373 
376  virtual
377  localIndex PackByIndexSize( arrayView1d< localIndex const > const & packList, bool withMetadata, bool onDevice ) const override final
378  {
379  localIndex packedSize = 0;
380  buffer_unit_type * buffer = nullptr;
381  if( sizedFromParent() == 1 )
382  {
383  if( withMetadata ) packedSize += bufferOps::Pack< false >( buffer, this->getName() );
384  if( onDevice )
385  {
386  if( withMetadata )
387  {
388  packedSize += wrapperHelpers::PackByIndexDevice< false >( buffer, reference(), packList );
389  }
390  else
391  {
392  packedSize += wrapperHelpers::PackDataByIndexDevice< false >( buffer, reference(), packList );
393  }
394  }
395  else
396  {
397  packedSize += wrapperHelpers::PackByIndex< false >( buffer, *m_data, packList );
398  }
399  }
400  return packedSize;
401  }
402 
405  virtual
406  localIndex Unpack( buffer_unit_type const * & buffer, bool withMetadata, bool onDevice ) override final
407  {
408  localIndex unpackedSize = 0;
409  if( withMetadata )
410  {
411  string name;
412  unpackedSize += bufferOps::Unpack( buffer, name );
413  GEOSX_ERROR_IF( name != this->getName(), "buffer unpack leads to wrapper names that don't match" );
414  }
415  if( onDevice )
416  {
417  if( withMetadata )
418  {
419  unpackedSize += wrapperHelpers::UnpackDevice( buffer, referenceAsView() );
420  }
421  else
422  {
423  unpackedSize += wrapperHelpers::UnpackDataDevice( buffer, referenceAsView() );
424  }
425  }
426  else
427  {
428  unpackedSize += bufferOps::Unpack( buffer, *m_data );
429  }
430  return unpackedSize;
431  }
432 
435  virtual
436  localIndex UnpackByIndex( buffer_unit_type const * & buffer, arrayView1d< localIndex const > const & unpackIndices, bool withMetadata, bool onDevice ) override final
437  {
438  localIndex unpackedSize = 0;
439  if( sizedFromParent()==1 )
440  {
441  if( withMetadata )
442  {
443  string name;
444  unpackedSize += bufferOps::Unpack( buffer, name );
445  GEOSX_ERROR_IF( name != this->getName(), "buffer unpack leads to wrapper names that don't match" );
446  }
447  if( onDevice )
448  {
449  if( withMetadata )
450  {
451  unpackedSize += wrapperHelpers::UnpackByIndexDevice( buffer, referenceAsView(), unpackIndices );
452  }
453  else
454  {
455  unpackedSize += wrapperHelpers::UnpackDataByIndexDevice( buffer, referenceAsView(), unpackIndices );
456  }
457  }
458  else
459  {
460  unpackedSize += wrapperHelpers::UnpackByIndex( buffer, *m_data, unpackIndices );
461  }
462  }
463  return unpackedSize;
464  }
465 
467 
469  void const * voidPointer() const override
470  { return wrapperHelpers::dataPtr( *m_data ); }
471 
473  virtual localIndex elementByteSize() const override
474  { return wrapperHelpers::byteSizeOfElement< T >(); }
475 
482 
485  virtual localIndex size() const override
486  { return wrapperHelpers::size( *m_data ); }
487 
489  virtual void resize( int ndims, localIndex const * const dims ) override
490  {
491  wrapperHelpers::move( *m_data, LvArray::MemorySpace::CPU, true );
492  wrapperHelpers::resizeDimensions( *m_data, ndims, dims );
493  }
494 
496  virtual void reserve( localIndex const newCapacity ) override
497  {
498  wrapperHelpers::move( *m_data, LvArray::MemorySpace::CPU, true );
499  wrapperHelpers::reserve( reference(), newCapacity );
500  }
501 
503  virtual localIndex capacity() const override
504  {
505  // We don't use reference() here because that would return an ArrayView which has no capacity method.
506  return wrapperHelpers::capacity( *m_data );
507  }
508 
510  virtual void resize( localIndex const newSize ) override
511  {
512  wrapperHelpers::move( *m_data, LvArray::MemorySpace::CPU, true );
513  wrapperHelpers::resizeDefault( reference(), newSize, m_default );
514  }
515 
517  struct copy_wrapper
518  {
519  template< typename U, int NDIM, typename PERMUTATION >
520  static void copy( Array< U, NDIM, PERMUTATION > const & array, localIndex const sourceIndex, localIndex const destIndex )
521  {
522  LvArray::forValuesInSliceWithIndices( array[ sourceIndex ],
523  [destIndex, &array]( U const & sourceVal, auto const ... indices )
524  {
525  array( destIndex, indices ... ) = sourceVal;
526  } );
527  }
528 
529  template< typename U >
530  static void copy( U const &, localIndex const, localIndex const )
531  {}
532 
533  template< typename U=T >
534  static
535  typename std::enable_if< traits::hasCopyAssignmentOp< U >, void >::type
536  copyData( U & destinationData, U const & sourceData )
537  {
538  destinationData = sourceData;
539  }
540 
541  template< typename U=T >
542  static
543  typename std::enable_if< !traits::hasCopyAssignmentOp< U >, void >::type
544  copyData( U &, U const & )
545  {}
546 
547 
548  };
550 
552  virtual void copy( localIndex const sourceIndex, localIndex const destIndex ) override
553  {
554  if( this->sizedFromParent() )
555  {
556  copy_wrapper::copy( reference(), sourceIndex, destIndex );
557  }
558  }
559 
560 
561 
562  virtual void copyData( WrapperBase const & source ) override
563  {
564  Wrapper< T > const & castedSource = *cast( &source );
565  copy_wrapper::copyData( *m_data, *castedSource.m_data );
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 string typeRegex() const override
575  { return TypeRegex< T >::get(); }
576 
578 
582 
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 
637 
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  typename std::enable_if< DefaultValue< U >::has_default_value, typename DefaultValue< U >::value_type const & >::type
666  {
667  return m_default.value;
668  }
669 
675  template< typename U=T >
676  typename std::enable_if< DefaultValue< U >::has_default_value, Wrapper< T > * >::type
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  typename std::enable_if< !traits::is_array< U > && DefaultValue< U >::has_default_value, Wrapper< T > * >::type
691  {
692  m_default.value = defaultVal;
693  *m_data = m_default.value;
694  return this;
695  }
696 
702  template< typename U=T >
703  typename std::enable_if< traits::is_array< U > && DefaultValue< U >::has_default_value, Wrapper< T > * >::type
705  {
706  m_default.value = defaultVal;
707  m_data->template setValues< serialPolicy >( m_default.value );
708  return this;
709  }
710 
714  virtual std::string getDefaultValueString() const override
715  {
716  // Find the dimensionality of the wrapper value
717  std::string wrapper_type = rtTypes::typeNames( std::type_index( get_typeid()));
718  integer value_dim = 0;
719  if( wrapper_type.find( "array3d" ) != std::string::npos )
720  {
721  value_dim = 3;
722  }
723  else if( wrapper_type.find( "array2d" ) != std::string::npos )
724  {
725  value_dim = 2;
726  }
727  else if( wrapper_type.find( "array" ) != std::string::npos )
728  {
729  value_dim = 1;
730  }
731 
732  // Compose the default string
733  std::stringstream ss;
734 
735  for( integer ii=0; ii<value_dim; ++ii )
736  {
737  ss << "{";
738  }
739 
740  ss << m_default;
741 
742  for( integer ii=0; ii<value_dim; ++ii )
743  {
744  ss << "}";
745  }
746 
747  return ss.str();
748  }
749 
750  virtual bool processInputFile( xmlWrapper::xmlNode const & targetNode ) override
751  {
752  InputFlags const inputFlag = getInputFlag();
753  if( inputFlag >= InputFlags::OPTIONAL )
754  {
755  if( inputFlag == InputFlags::REQUIRED || !hasDefaultValue() )
756  {
757  bool const readSuccess = xmlWrapper::ReadAttributeAsType( reference(),
758  getName(),
759  targetNode,
760  inputFlag == InputFlags::REQUIRED );
761  GEOSX_ERROR_IF( !readSuccess,
762  "Input variable " + getName() + " is required in " + targetNode.path()
763  + ". Available options are: \n"+ dumpInputOptions( true )
764  + "\nFor more details, please refer to documentation at: \n"
765  + "http://geosx-geosx.readthedocs-hosted.com/en/latest/docs/sphinx/userGuide/Index.html \n" );
766 
767 
768  }
769  else
770  {
772  }
773 
774  return true;
775  }
776 
777  return false;
778  }
779 
781 
787  void setName()
788  { wrapperHelpers::setName( reference(), m_conduitNode.path() ); }
789 
790 
792  void addBlueprintField( conduit::Node & fields,
793  std::string const & name,
794  std::string const & topology,
795  std::vector< std::string > const & componentNames = {} ) const override
796  { wrapperHelpers::addBlueprintField( reference(), fields, name, topology, componentNames ); }
797 
799  void populateMCArray( conduit::Node & node, std::vector< std::string > const & componentNames = {} ) const override
800  { wrapperHelpers::populateMCArray( reference(), node, componentNames ); }
801 
803  std::unique_ptr< WrapperBase > averageOverSecondDim( std::string const & name, Group & group ) const override
804  {
805  auto ptr = wrapperHelpers::averageOverSecondDim( reference() );
806  using U = typename decltype( ptr )::element_type;
807 
808  GEOSX_ERROR_IF( ptr == nullptr, "Failed to average over the second dimension of." );
809 
810  return std::make_unique< Wrapper< U > >( name, &group, std::move( ptr ) );
811  }
812 
814  void registerToWrite() const override
815  {
816  m_conduitNode.reset();
817 
819  {
820  return;
821  }
822 
823  move( LvArray::MemorySpace::CPU, false );
824 
825  m_conduitNode[ "__sizedFromParent__" ].set( sizedFromParent() );
826 
827  wrapperHelpers::pushDataToConduitNode( *m_data, m_conduitNode );
828  }
829 
831  void finishWriting() const override
832  { m_conduitNode.reset(); }
833 
834 
836  bool loadFromConduit() override
837  {
839  {
840  m_conduitNode.reset();
841  return false;
842  }
843 
844  setSizedFromParent( m_conduitNode[ "__sizedFromParent__" ].value() );
845 
846  wrapperHelpers::pullDataFromConduitNode( *m_data, m_conduitNode );
847 
848  m_conduitNode.reset();
849 
850  return true;
851  }
852 
858 
860  /*
861  * @brief Set whether this wrapper is resized when its parent is resized.
862  * @param val an int that is converted into a bool
863  * @return a pointer to this wrapper
864  */
865 
870  {
872  return this;
873  }
874 
879  {
881  return this;
882  }
883 
888  {
890  return this;
891  }
892 
897  {
898  WrapperBase::setInputFlag( input );
899  return this;
900  }
901 
905  Wrapper< T > * setDescription( string const & description )
906  {
907  WrapperBase::setDescription( description );
908  return this;
909  }
910 
914  Wrapper< T > * setRegisteringObjects( string const & objectName )
915  {
917  return this;
918  }
919 
921 
922 #if defined(USE_TOTALVIEW_OUTPUT)
923  virtual string totalviewTypeName() const override
924  {
925  return LvArray::system::demangle( typeid( Wrapper< T > ).name() );
926  }
927 
928  virtual int setTotalviewDisplay() const override
929  {
930  //std::cout<<"executing Wrapper::setTotalviewDisplay()"<<std::endl;
931  WrapperBase::setTotalviewDisplay();
932  TV_ttf_add_row( "m_ownsData", "bool", &m_ownsData );
933  TV_ttf_add_row( "m_data", LvArray::system::demangle< T >().c_str(), m_data );
934  TV_ttf_add_row( "m_default", LvArray::system::demangle< DefaultValue< T > >().c_str(), &m_default );
935  return 0;
936  }
937 // void tvTemplateInstantiation();
938 #endif
939 
940 private:
943  bool m_ownsData;
944 
946  T * m_data;
947 
949  DefaultValue< T > m_default;
950 
951  Wrapper() = delete;
952 };
953 
954 }
955 } /* namespace geosx */
956 
957 //template< typename T >
958 //int TV_ttf_display_type( geosx::dataRepository::Wrapper<T> const * wrapper)
959 //{
960 // std::cout<<"Executing "<<wrapper->totalviewTypeName()<<"::TV_ttf_display_type()"<<std::endl;
961 // return TV_ttf_format_raw;
962 //}
963 //
964 //template int TV_ttf_display_type( geosx::dataRepository::Wrapper<int> const * wrapper );
965 //
966 //template< typename T >
967 //void geosx::dataRepository::Wrapper<T>::tvTemplateInstantiation()
968 //{
969 // TV_ttf_display_type<T>(this);
970 //}
971 
972 
973 #endif /* GEOSX_DATAREPOSITORY_WRAPPER_HPP_ */
string m_name
Name of the object that is being wrapped.
virtual void copy(localIndex const sourceIndex, localIndex const destIndex) override
Calls T::copy(sourceIndex, destIndex)
Definition: Wrapper.hpp:552
int sizedFromParent() const
Check whether this wrapper is resized when its parent is resized.
Wrapper & operator=(Wrapper const &source)
Copy Assignment Operator.
Definition: Wrapper.hpp:154
virtual void resize(int ndims, localIndex const *const dims) override
Calls T::resize( num_dims, dims )
Definition: Wrapper.hpp:489
GEOSX_DECLTYPE_AUTO_RETURN referenceAsView()
Provide access to wrapped object converted to a view, if possible.
Definition: Wrapper.hpp:608
#define GEOSX_DECLTYPE_AUTO_RETURN
Doxygen can&#39;t parse a decltype( auto ) return type, using this gets around that.
pugi::xml_node xmlNode
Alias for the type of an xml node.
Definition: xmlWrapper.hpp:60
Wrapper(std::string const &name, Group *const parent, T *object)
Constructor that does not take ownership of an existing object.
Definition: Wrapper.hpp:118
std::unique_ptr< WrapperBase > averageOverSecondDim(std::string const &name, Group &group) const override
Create a new Wrapper with values averaged over the second dimension.
Definition: Wrapper.hpp:803
T & referenceAsView()
Provide access to wrapped object converted to a view, if possible.
Definition: Wrapper.hpp:615
WrapperBase * setPlotLevel(PlotLevel const flag)
Set the PlotLevel of the wrapper.
Wrapper(std::string const &name, Group *const parent)
Constructor that creates a new instance of wrapped type.
Definition: Wrapper.hpp:75
virtual ~Wrapper() noexcept override
Default destructor.
Definition: Wrapper.hpp:139
virtual bool hasDefaultValue() const final override
Return true iff this wrapper has a valid default value.
Definition: Wrapper.hpp:642
void registerToWrite() const override
Register the wrapper&#39;s data for writing with Conduit.
Definition: Wrapper.hpp:814
void finishWriting() const override
Write the wrapped data into Conduit.
Definition: Wrapper.hpp:831
InputFlags getInputFlag() const
Get the InputFlag of the wrapper.
T TYPE
Alias for the wrapped type T.
Definition: Wrapper.hpp:63
virtual bool processInputFile(xmlWrapper::xmlNode const &targetNode) override
Initialize the wrapper from the input xml node.
Definition: Wrapper.hpp:750
std::enable_if< DefaultValue< U >::has_default_value, Wrapper< T > *>::type setDefaultValue(typename DefaultValue< U >::value_type const &defaultVal)
Setter for default value.
Definition: Wrapper.hpp:677
static std::enable_if_t< canParseVariable< T >, bool > ReadAttributeAsType(T &rval, string const &name, xmlNode const &targetNode, T_DEF const &defVal)
Extract attribute in an xml tree, and translate its value into a typed variable.
Definition: xmlWrapper.hpp:172
Wrapper & operator=(Wrapper &&source)
Move Assignment Operator.
Definition: Wrapper.hpp:165
static Wrapper< T > * cast(WrapperBase *const base)
Static function to cast a Wrapper base to a derived Wrapper<T>
Definition: Wrapper.hpp:228
Wrapper< T > * setDescription(string const &description)
Set the description string of the wrapper.
Definition: Wrapper.hpp:905
static string get()
Get the type&#39;s regex (default implementation).
Definition: DataTypes.hpp:947
std::enable_if< !traits::is_array< U > &&DefaultValue< U >::has_default_value, Wrapper< T > *>::type setApplyDefaultValue(typename DefaultValue< U >::value_type const &defaultVal)
Set and apply for default value.
Definition: Wrapper.hpp:690
Contains functions that interact with the system or runtime environment.
virtual void copyWrapperAttributes(WrapperBase const &source) override
Copy attributes from another wrapper.
Definition: Wrapper.hpp:201
GEOSX_DECLTYPE_AUTO_RETURN referenceAsView() const
Provide access to wrapped object converted to a view, if possible.
Definition: Wrapper.hpp:622
virtual localIndex Pack(buffer_unit_type *&buffer, bool withMetadata, bool onDevice) const override final
Pack the entire wrapped object into a buffer.
Definition: Wrapper.hpp:298
Contains portable access to std::numeric_limits and functions for converting between integral types...
string dumpInputOptions(bool const outputHeader) const
virtual void move(LvArray::MemorySpace const space, bool const touch) const override
Calls T::move(space, touch)
Definition: Wrapper.hpp:570
static Wrapper< T > const & cast(WrapperBase const &base)
Definition: Wrapper.hpp:260
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
void addBlueprintField(conduit::Node &fields, std::string const &name, std::string const &topology, std::vector< std::string > const &componentNames={}) const override
Push the data in the wrapper into a Conduit blueprint field.
Definition: Wrapper.hpp:792
constexpr void copy(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector)
Copy srcVector into dstVector.
Wrapper< T > * setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
Definition: Wrapper.hpp:869
WrapperBase * setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
static std::string typeNames(std::type_index const key)
Convert a std::type_index to a string.
Definition: DataTypes.hpp:501
virtual void copyWrapper(WrapperBase const &source) override
Copies the contents of a Wrapper into *this.
Definition: Wrapper.hpp:189
virtual localIndex PackByIndex(buffer_unit_type *&buffer, arrayView1d< localIndex const > const &packList, bool withMetadata, bool onDevice) const override final
For indexable types, pack selected indices of wrapped object into a buffer.
Definition: Wrapper.hpp:323
Wrapper< T > * setInputFlag(InputFlags const input)
Set the InputFlag of the wrapper.
Definition: Wrapper.hpp:896
virtual localIndex Unpack(buffer_unit_type const *&buffer, bool withMetadata, bool onDevice) override final
Unpack the entire wrapped object from a buffer.
Definition: Wrapper.hpp:406
virtual std::unique_ptr< WrapperBase > clone(string const &name, Group *const parent) override
Creates a clone of *this WrapperBase.
Definition: Wrapper.hpp:179
static Wrapper< T > & cast(WrapperBase &base)
Static function to cast a Wrapper base to a derived Wrapper<T>
Definition: Wrapper.hpp:250
virtual localIndex size() const override
Calls T::size()
Definition: Wrapper.hpp:485
void populateMCArray(conduit::Node &node, std::vector< std::string > const &componentNames={}) const override
Push the data in the wrapper into a Conduit Blueprint mcarray.
Definition: Wrapper.hpp:799
RestartFlags getRestartFlags() const
Get the RestartFlags of the wrapper.
internal::Helper< T > DefaultValue
A templated alias to hold default values.
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:282
string const & getName() const
Get name of the wrapper.
Base class for all wrappers containing common operations.
Definition: WrapperBase.hpp:48
Wrapper(std::string const &name, Group *const parent, std::unique_ptr< T > object)
Constructor that takes ownership of an existing object.
Definition: Wrapper.hpp:96
void setName()
DO_NOT_DOCUMENT.
Definition: Wrapper.hpp:787
WrapperBase * setRestartFlags(RestartFlags flags)
Set the RestartFlags of the wrapper.
virtual localIndex PackSize(bool withMetadata, bool onDevice) const override final
Get the buffer size needed to pack the entire wrapped object.
Definition: Wrapper.hpp:351
virtual localIndex elementByteSize() const override
Definition: Wrapper.hpp:473
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:146
MemorySpace
An enum containing the available memory spaces.
GEOSX_DECLTYPE_AUTO_RETURN reference() const
const Accessor for m_data
Definition: Wrapper.hpp:596
virtual localIndex capacity() const override
Definition: Wrapper.hpp:503
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:122
WrapperBase * setInputFlag(InputFlags const input)
Set the InputFlag of the wrapper.
virtual void resize(localIndex const newSize) override
Calls T::resize(newsize) if it exists.
Definition: Wrapper.hpp:510
WrapperBase * setRegisteringObjects(string const &objectName)
Add a new name to the list of groups that register this wrapper.
std::enable_if< traits::is_array< U > &&DefaultValue< U >::has_default_value, Wrapper< T > *>::type setApplyDefaultValue(typename DefaultValue< U >::value_type const &defaultVal)
Set and apply for default value.
Definition: Wrapper.hpp:704
Contains a bunch of macro definitions.
Wrapper< T > * setRegisteringObjects(string const &objectName)
Add a new name to the list of groups that register this wrapper.
Definition: Wrapper.hpp:914
virtual localIndex PackByIndexSize(arrayView1d< localIndex const > const &packList, bool withMetadata, bool onDevice) const override final
Get the buffer size needed to pack the selected indices wrapped object.
Definition: Wrapper.hpp:377
bool loadFromConduit() override
Read the wrapped data from Conduit.
Definition: Wrapper.hpp:836
T & reference()
Accessor for m_data.
Definition: Wrapper.hpp:588
virtual localIndex UnpackByIndex(buffer_unit_type const *&buffer, arrayView1d< localIndex const > const &unpackIndices, bool withMetadata, bool onDevice) override final
For indexable types, unpack selected indices of wrapped object from a buffer.
Definition: Wrapper.hpp:436
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
void forValuesInSliceWithIndices(T &value, LAMBDA &&f, INDICES const ... indices)
Apply the function f to the value value also passing f any indices used to reach value.
virtual const std::type_info & get_typeid() const noexcept override
Get the typeid of T.
Definition: Wrapper.hpp:210
virtual void copyData(WrapperBase const &source) override
Copy the the data contained in another wrapper into this wrapper.
Definition: Wrapper.hpp:562
Wrapper< T > * setRestartFlags(RestartFlags flags)
Set the RestartFlags of the wrapper.
Definition: Wrapper.hpp:878
static Wrapper< T > const * cast(WrapperBase const *const base)
Static function to cast a Wrapper base to a derived Wrapper<T>
Definition: Wrapper.hpp:239
WrapperBase * setDescription(string const &description)
Set the description string of the wrapper.
virtual void reserve(localIndex const newCapacity) override
Calls T::reserve( newCapacity ) if it exists, otherwise a no-op.
Definition: Wrapper.hpp:496
virtual void copyWrapperAttributes(WrapperBase const &source)
Copy attributes from another wrapper.
std::string string
String type.
Definition: DataTypes.hpp:131
#define GEOSX_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:103
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:269
std::enable_if< can_history_io< T >, HistoryMetadata >::type getHistoryMetadata(string const &name, ArrayView< T const, 1, 0 > const &arr, localIndex sizeOverride=-1)
Produce a HistoryMetadata object for a supported one-dimensional array type.
std::string demangle(char const *const name)
DefaultValue< T > const & getDefaultValueStruct() const
Accessor for m_default.
Definition: Wrapper.hpp:653
T const & referenceAsView() const
Provide access to wrapped object converted to a view, if possible.
Definition: Wrapper.hpp:629
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55
std::enable_if< DefaultValue< U >::has_default_value, typename DefaultValue< U >::value_type const &>::type getDefaultValue() const
Accessor for default value.
Definition: Wrapper.hpp:665
Wrapper< T > * setPlotLevel(PlotLevel const flag)
Set the PlotLevel of the wrapper.
Definition: Wrapper.hpp:887
A minimal class to specify information about time history information being collected and output...
void const * voidPointer() const override
Definition: Wrapper.hpp:469
virtual string typeRegex() const override
Calls TypeRegex< T >::get().
Definition: Wrapper.hpp:574
virtual std::string getDefaultValueString() const override
Return a string representing the default value.
Definition: Wrapper.hpp:714
conduit::Node & m_conduitNode
A reference to the corresponding conduit::Node.