GEOS
WrapperBase.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 
18 #ifndef GEOS_DATAREPOSITORY_WRAPPERBASE_HPP_
19 #define GEOS_DATAREPOSITORY_WRAPPERBASE_HPP_
20 
21 #include "common/DataTypes.hpp"
22 #include "common/GEOS_RAJA_Interface.hpp"
23 #include "common/Span.hpp"
24 #include "dataRepository/WrapperLimits.hpp"
25 #include "InputFlags.hpp"
26 #include "xmlWrapper.hpp"
27 #include "RestartFlags.hpp"
28 #include "HistoryDataSpec.hpp"
29 #include "DataContext.hpp"
30 
31 #if defined(GEOS_USE_PYGEOSX)
32 #include "LvArray/src/python/python.hpp"
33 #endif
34 
35 #include <string>
36 #include <memory>
37 #include <set>
38 
39 namespace conduit
40 {
41 class Node;
42 }
43 
44 
45 namespace geos
46 {
47 namespace dataRepository
48 {
49 
50 class Group;
51 
57 {
58 public:
59 
64 
71  explicit WrapperBase( string const & name,
72  Group & parent,
73  string const & rtTypeName );
74 
76  WrapperBase() = delete;
77  WrapperBase( WrapperBase const & ) = delete;
78  WrapperBase( WrapperBase && ) = delete;
79  WrapperBase & operator=( WrapperBase const & ) = delete;
80  WrapperBase & operator=( WrapperBase && ) = delete;
82 
86  virtual ~WrapperBase();
87 
89 
97 
102  virtual localIndex size() const = 0;
103 
107  virtual void const * voidPointer() const = 0;
108 
113  virtual localIndex elementByteSize() const = 0;
114 
118  virtual size_t bytesAllocated() const = 0;
119 
120 
126  virtual void resize( int num_dims, localIndex const * const dims ) = 0;
127 
132  virtual void reserve( localIndex const newCapacity ) = 0;
133 
137  virtual localIndex capacity() const = 0;
138 
143  virtual void resize( localIndex newsize ) = 0;
144 
148  void resize();
149 
155  virtual void copy( localIndex const sourceIndex, localIndex const destIndex ) = 0;
156 
161  virtual void erase( std::set< localIndex > const & indicesToErase ) = 0;
162 
168  virtual void move( LvArray::MemorySpace const space, bool const touch ) const = 0;
169 
173  virtual Regex const & getTypeRegex() const = 0;
174 
178  string const & getRTTypeName() const
179  { return m_rtTypeName; }
180 
188  {
189  m_rtTypeName = rtTypeName;
190  return *this;
191  }
192 
194 
199  virtual bool hasDefaultValue() const = 0;
200 
205  virtual string getDefaultValueString() const = 0;
206 
212  virtual string getLimitsString() const = 0;
213 
220  virtual bool processInputFile( xmlWrapper::xmlNode const & targetNode,
221  xmlWrapper::xmlNodePos const & nodePos ) = 0;
222 
231  virtual void addBlueprintField( conduit::Node & fields,
232  string const & name,
233  string const & topology,
234  stdVector< string > const & componentNames = {} ) const = 0;
235 
242  virtual void populateMCArray( conduit::Node & node, stdVector< string > const & componentNames = {} ) const = 0;
243 
252  virtual std::unique_ptr< WrapperBase > averageOverSecondDim( string const & name, Group & group ) const = 0;
253 
258 
262  virtual void registerToWrite() const = 0;
263 
267  virtual void finishWriting() const = 0;
268 
273  virtual bool loadFromConduit() = 0;
274 
276 
282  virtual HistoryMetadata getHistoryMetadata( localIndex const packCount ) const = 0;
283 
290 
296  virtual bool isPackable( bool onDevice ) const = 0;
297 
310  template< bool DO_PACKING >
312  bool withMetadata,
313  bool onDevice,
314  parallelDeviceEvents & events ) const
315  {
316  return DO_PACKING ? packPrivate( buffer, withMetadata, onDevice, events ) : packSizePrivate( withMetadata, onDevice, events );
317  }
318 
332  template< bool DO_PACKING >
334  arrayView1d< localIndex const > const & packList,
335  bool withMetadata,
336  bool onDevice,
337  parallelDeviceEvents & events ) const
338  {
339  return DO_PACKING ? packByIndexPrivate( buffer, packList, withMetadata, onDevice, events ) : packByIndexSizePrivate( packList, withMetadata, onDevice, events );
340  }
341 
353  virtual localIndex unpack( buffer_unit_type const * & buffer,
354  bool withMetadata,
355  bool onDevice,
356  parallelDeviceEvents & events ) = 0;
357 
371  virtual localIndex unpackByIndex( buffer_unit_type const * & buffer,
372  arrayView1d< localIndex const > const & unpackIndices,
373  bool withMetadata,
374  bool onDevice,
375  parallelDeviceEvents & events,
376  MPI_Op op=MPI_REPLACE ) = 0;
377 
379 
384 
389  int sizedFromParent() const
390  {
391  return m_sizedFromParent;
392  }
393 
400  {
401  m_sizedFromParent = val;
402  return *this;
403  }
404 
410 
417  {
418  m_restart_flags = flags;
419  return *this;
420  }
421 
426  PlotLevel getPlotLevel() const { return m_plotLevel; }
427 
434  {
435  m_plotLevel = flag;
436  return *this;
437  }
438 
443  string const & getName() const
444  {
445  return m_name;
446  }
447 
452  string getPath() const;
453 
458  DataContext const & getDataContext() const
459  { return *m_dataContext; }
460 
465  { return *m_parent; }
466 
470  Group const & getParent() const
471  { return *m_parent; }
472 
479  {
480  if( input == InputFlags::OPTIONAL || input == InputFlags::REQUIRED )
481  {
482  this->setSizedFromParent( 0 );
484  }
485  m_inputFlag = input;
486 
487  return *this;
488  }
489 
495  {
496  return m_inputFlag;
497  }
498 
505  {
507  }
508 
514  WrapperBase & setDescription( string const & description )
515  {
516  m_description = description;
517  return *this;
518  }
519 
525  WrapperBase & appendDescription( string const & description )
526  {
527  m_description += description;
528  return *this;
529  }
530 
535  string const & getDescription() const
536  {
537  return m_description;
538  }
539 
544  wrapperLimits::LimitsMode getLimitsMode() const
545  {
546  return m_limitsMode;
547  }
548 
553  std::set< string > const & getRegisteringObjects() const
554  {
555  return m_registeringObjects;
556  }
557 
563  WrapperBase & setRegisteringObjects( string const & objectName )
564  {
565  m_registeringObjects.insert( objectName );
566  return *this;
567  }
568 
570 
575 
580  virtual void copyWrapperAttributes( WrapperBase const & source );
581 
591  virtual std::unique_ptr< WrapperBase > clone( string const & name, Group & parent ) = 0;
592 
597  virtual void copyData( WrapperBase const & source ) = 0;
598 
603  virtual void copyWrapper( WrapperBase const & source ) = 0;
604 
609  virtual std::type_info const & getTypeId() const = 0;
610 
615  virtual int numArrayDims() const = 0;
616 
621  virtual localIndex numArrayComp() const = 0;
622 
636  virtual WrapperBase & setDimLabels( integer dim, Span< string const > labels ) = 0;
637 
645  virtual Span< string const > getDimLabels( integer dim ) const = 0;
646 
648 
649 #if defined(USE_TOTALVIEW_OUTPUT)
655  virtual string totalviewTypeName() const = 0;
656 
662  virtual int setTotalviewDisplay() const;
663 // static int TV_ttf_display_type( const WrapperBase * wrapper);
664 #endif
665 
666 #if defined(GEOS_USE_PYGEOSX)
671  virtual PyObject * createPythonObject( ) = 0;
672 #endif
673 
674 protected:
675 
677 
678  conduit::Node & getConduitNode()
679  {
680  return m_conduitNode;
681  }
682 
684 
690  void createDataContext( xmlWrapper::xmlNode const & targetNode,
691  xmlWrapper::xmlNodePos const & nodePos );
692 
693 protected:
694 
696  string m_name;
697 
700 
703 
706 
709 
712 
715 
718 
720  wrapperLimits::LimitsMode m_limitsMode;
721 
723  string m_rtTypeName;
724 
726  std::set< string > m_registeringObjects;
727 
729  conduit::Node & m_conduitNode;
730 
732  std::unique_ptr< DataContext > m_dataContext;
733 
734 private:
735 
747  virtual localIndex packPrivate( buffer_unit_type * & buffer, bool withMetadata, bool onDevice, parallelDeviceEvents & events ) const = 0;
748 
760  virtual localIndex packSizePrivate( bool withMetadata, bool onDevice, parallelDeviceEvents & events ) const = 0;
761 
762 
775  virtual localIndex packByIndexPrivate( buffer_unit_type * & buffer,
776  arrayView1d< localIndex const > const & packList,
777  bool withMetadata,
778  bool onDevice,
779  parallelDeviceEvents & events ) const = 0;
780 
792  virtual localIndex packByIndexSizePrivate( arrayView1d< localIndex const > const & packList,
793  bool withMetadata,
794  bool onDevice,
795  parallelDeviceEvents & events ) const = 0;
796 };
797 
798 }
799 }
800 
801 #endif /* GEOS_DATAREPOSITORY_WRAPPERBASE_HPP_ */
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:57
InputFlags getInputFlag() const
Get the InputFlag of the wrapper.
virtual localIndex unpack(buffer_unit_type const *&buffer, bool withMetadata, bool onDevice, parallelDeviceEvents &events)=0
Unpack the entire wrapped object from a buffer.
virtual bool hasDefaultValue() const =0
Return true iff this wrapper has a valid default value.
string const & getName() const
Get name of the wrapper.
string const & getDescription() const
Get the description string of the wrapper.
virtual localIndex size() const =0
Calls T::size()
wrapperLimits::LimitsMode m_limitsMode
Enforcement mode of the (optional) attribute limits.
virtual localIndex numArrayComp() const =0
Return the number of components in a multidimensional array.
localIndex packByIndex(buffer_unit_type *&buffer, arrayView1d< localIndex const > const &packList, bool withMetadata, bool onDevice, parallelDeviceEvents &events) const
Concrete implementation of the packing by index method.
PlotLevel m_plotLevel
Flag to store the plotLevel.
std::set< string > const & getRegisteringObjects() const
Get the list of names of groups that registered this wrapper.
string const & getRTTypeName() const
virtual bool processInputFile(xmlWrapper::xmlNode const &targetNode, xmlWrapper::xmlNodePos const &nodePos)=0
Initialize the wrapper from the input xml node.
int sizedFromParent() const
Check whether this wrapper is resized when its parent is resized.
virtual void addBlueprintField(conduit::Node &fields, string const &name, string const &topology, stdVector< string > const &componentNames={}) const =0
Push the data in the wrapper into a Conduit blueprint field.
RestartFlags getRestartFlags() const
Get the RestartFlags of the wrapper.
WrapperBase & setInputFlag(InputFlags const input)
Set the InputFlag of the wrapper.
wrapperLimits::LimitsMode getLimitsMode() const
Get the enforcement mode of the (optional) attribute limits.
virtual void resize(localIndex newsize)=0
Calls T::resize(newsize) if it exists.
WrapperBase(string const &name, Group &parent, string const &rtTypeName)
Constructor.
conduit::Node & m_conduitNode
A reference to the corresponding conduit::Node.
virtual void move(LvArray::MemorySpace const space, bool const touch) const =0
Calls T::move(space, touch)
Group * m_parent
Pointer to Group that holds this WrapperBase.
virtual void erase(std::set< localIndex > const &indicesToErase)=0
Calls T::erase(indicesToErase)
virtual void finishWriting() const =0
Write the wrapped data into Conduit.
int m_sizedFromParent
Integer to indicate whether or not this wrapped object should be resized when m_parent is resized.
DataContext const & getDataContext() const
WrapperBase & setDescription(string const &description)
Set the description string of the wrapper.
virtual void populateMCArray(conduit::Node &node, stdVector< string > const &componentNames={}) const =0
Push the data in the wrapper into a Conduit Blueprint mcarray.
virtual void reserve(localIndex const newCapacity)=0
Calls T::reserve( newCapacity ) if it exists, otherwise a no-op.
virtual WrapperBase & setDimLabels(integer dim, Span< string const > labels)=0
Set dimension labels for an array.
virtual void copyData(WrapperBase const &source)=0
Copy the the data contained in another wrapper into this wrapper.
virtual bool loadFromConduit()=0
Read the wrapped data from Conduit.
WrapperBase & setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
virtual void resize(int num_dims, localIndex const *const dims)=0
Calls T::resize( num_dims, dims )
virtual localIndex elementByteSize() const =0
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.
virtual void registerToWrite() const =0
Register the wrapper's data for writing with Conduit.
WrapperBase & setRestartFlags(RestartFlags flags)
Set the RestartFlags of the wrapper.
Group const & getParent() const
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.
virtual localIndex unpackByIndex(buffer_unit_type const *&buffer, arrayView1d< localIndex const > const &unpackIndices, bool withMetadata, bool onDevice, parallelDeviceEvents &events, MPI_Op op=MPI_REPLACE)=0
For indexable types, unpack selected indices of wrapped object from a buffer.
virtual localIndex capacity() const =0
std::unique_ptr< DataContext > m_dataContext
A DataContext object that can helps to contextualize this Group.
virtual std::unique_ptr< WrapperBase > averageOverSecondDim(string const &name, Group &group) const =0
Create a new Wrapper with values averaged over the second dimension.
void createDataContext(xmlWrapper::xmlNode const &targetNode, xmlWrapper::xmlNodePos const &nodePos)
Sets the m_dataContext to a DataFileContext by retrieving the attribute file line.
virtual string getLimitsString() const =0
Return a string representing the allowed value range.
bool getSuccessfulReadFromInput() const
Returns flag that indicates whether the contents of the wrapper have been successfully read from the ...
virtual size_t bytesAllocated() const =0
string m_description
A string description of the wrapped object.
PlotLevel getPlotLevel() const
Get PlotLevel for this wrapper.
void resize()
Calls resize(newsize) where newsize is taken from the parent Group.
virtual ~WrapperBase()
Default destructor.
virtual void copy(localIndex const sourceIndex, localIndex const destIndex)=0
Calls T::copy(sourceIndex, destIndex)
bool m_successfulReadFromInput
Flag to indicate if wrapped object was successfully read from input.
virtual bool isPackable(bool onDevice) const =0
Check whether wrapped type is can be packed into a buffer on host or device.
std::set< string > m_registeringObjects
A vector of the names of the objects that created this Wrapper.
virtual Regex const & getTypeRegex() const =0
virtual string getDefaultValueString() const =0
Return a string representing the default value.
virtual std::type_info const & getTypeId() const =0
Get the typeid of T.
virtual void const * voidPointer() const =0
virtual void copyWrapper(WrapperBase const &source)=0
Copies the contents of a Wrapper into *this.
virtual int numArrayDims() const =0
Return the number of dimensions of the array.
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...
virtual HistoryMetadata getHistoryMetadata(localIndex const packCount) const =0
Get a description of the wrapped data for time history collection/output.
virtual Span< string const > getDimLabels(integer dim) const =0
Get dimension labels of an array.
localIndex pack(buffer_unit_type *&buffer, bool withMetadata, bool onDevice, parallelDeviceEvents &events) const
Concrete implementation of the packing method.
InputFlags m_inputFlag
Flag to store if this wrapped object should be read from input.
string m_name
Name of the object that is being wrapped.
WrapperBase & setPlotLevel(PlotLevel const flag)
Set the PlotLevel of the wrapper.
RestartFlags m_restart_flags
Flag to determine the restart behavior for this wrapped object.
string getPath() const
Return the path to this Wrapper in the data repository.
virtual std::unique_ptr< WrapperBase > clone(string const &name, Group &parent)=0
Creates a clone of *this WrapperBase.
@ OPTIONAL
Optional in input.
@ REQUIRED
Required in input.
pugi::xml_node xmlNode
Definition: xmlWrapper.hpp:59
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:84
@ Node
location is node (like displacements in finite elements)
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:108
int integer
Signed integer type.
Definition: DataTypes.hpp:81
std::string_view string_view
String type.
Definition: DataTypes.hpp:93
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector