GEOSX
WrapperBase.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 
17 #ifndef GEOSX_DATAREPOSITORY_WRAPPERBASE_HPP_
18 #define GEOSX_DATAREPOSITORY_WRAPPERBASE_HPP_
19 
20 #include "common/DataTypes.hpp"
21 #include "InputFlags.hpp"
22 #include "xmlWrapper.hpp"
23 #include "RestartFlags.hpp"
24 #include "rajaInterface/GEOS_RAJA_Interface.hpp"
26 
27 #include <string>
28 #include <memory>
29 #include <set>
30 
31 namespace conduit
32 {
33 class Node;
34 }
35 
36 
37 namespace geosx
38 {
39 namespace dataRepository
40 {
41 
42 class Group;
43 
49 {
50 public:
51 
55 
62  explicit WrapperBase( string const & name,
63  Group * const parent );
64 
66  WrapperBase() = delete;
67  WrapperBase( WrapperBase const & ) = delete;
68  WrapperBase( WrapperBase && ) = delete;
69  WrapperBase & operator=( WrapperBase const & ) = delete;
70  WrapperBase & operator=( WrapperBase && ) = delete;
72 
76  virtual ~WrapperBase();
77 
79 
86 
92  virtual localIndex size() const = 0;
93 
97  virtual void const * voidPointer() const = 0;
98 
103  virtual localIndex elementByteSize() const = 0;
104 
110  virtual void resize( int num_dims, localIndex const * const dims ) = 0;
111 
116  virtual void reserve( localIndex const newCapacity ) = 0;
117 
121  virtual localIndex capacity() const = 0;
122 
127  virtual void resize( localIndex newsize ) = 0;
128 
132  void resize();
133 
139  virtual void copy( localIndex const sourceIndex, localIndex const destIndex ) = 0;
140 
146  virtual void move( LvArray::MemorySpace const space, bool const touch ) const = 0;
147 
152  virtual string typeRegex() const = 0;
153 
155 
160  virtual bool hasDefaultValue() const = 0;
161 
166  virtual std::string getDefaultValueString() const = 0;
167 
173  virtual bool processInputFile( xmlWrapper::xmlNode const & targetNode ) = 0;
174 
183  virtual void addBlueprintField( conduit::Node & fields,
184  std::string const & name,
185  std::string const & topology,
186  std::vector< std::string > const & componentNames = {} ) const = 0;
187 
194  virtual void populateMCArray( conduit::Node & node, std::vector< std::string > const & componentNames = {} ) const = 0;
195 
204  virtual std::unique_ptr< WrapperBase > averageOverSecondDim( std::string const & name, Group & group ) const = 0;
205 
209 
214  virtual void registerToWrite() const = 0;
215 
219  virtual void finishWriting() const = 0;
220 
225  virtual bool loadFromConduit() = 0;
226 
228 
234  virtual HistoryMetadata getHistoryMetadata( localIndex const packCount ) const = 0;
235 
241 
248  virtual
249  bool isPackable( bool onDevice ) const = 0;
250 
259  virtual
260  localIndex Pack( buffer_unit_type * & buffer, bool withMetadata, bool onDevice ) const = 0;
261 
271  virtual
272  localIndex PackByIndex( buffer_unit_type * & buffer, arrayView1d< localIndex const > const & packList, bool withMetadata, bool onDevice ) const = 0;
273 
282  virtual
283  localIndex PackSize( bool withMetadata, bool onDevice ) const = 0;
284 
293  virtual
294  localIndex PackByIndexSize( arrayView1d< localIndex const > const & packList, bool withMetadata, bool onDevice ) const = 0;
295 
304  virtual
305  localIndex Unpack( buffer_unit_type const * & buffer, bool withMetadata, bool onDevice ) = 0;
306 
316  virtual
317  localIndex UnpackByIndex( buffer_unit_type const * & buffer, arrayView1d< localIndex const > const & unpackIndices, bool withMetadata, bool onDevice ) = 0;
318 
320 
324 
330  int sizedFromParent() const
331  {
332  return m_sizedFromParent;
333  }
334 
341  {
342  m_sizedFromParent = val;
343  return this;
344  }
345 
350  RestartFlags getRestartFlags() const { return m_restart_flags; }
351 
358  {
359  m_restart_flags = flags;
360  return this;
361  }
362 
367  PlotLevel getPlotLevel() const { return m_plotLevel; }
368 
375  {
376  m_plotLevel = flag;
377  return this;
378  }
379 
384  string const & getName() const
385  {
386  return m_name;
387  }
388 
395  {
396  if( input == InputFlags::OPTIONAL || input == InputFlags::REQUIRED )
397  {
398  this->setSizedFromParent( 0 );
399  m_restart_flags = RestartFlags::WRITE;
400  }
401  m_inputFlag = input;
402  return this;
403  }
404 
410  {
411  return m_inputFlag;
412  }
413 
419  WrapperBase * setDescription( string const & description )
420  {
421  m_description = description;
422  return this;
423  }
424 
429  string const & getDescription() const
430  {
431  return m_description;
432  }
433 
439  string dumpInputOptions( bool const outputHeader ) const;
440 
441 
446  std::set< string > const & getRegisteringObjects() const
447  {
448  return m_registeringObjects;
449  }
450 
456  WrapperBase * setRegisteringObjects( string const & objectName )
457  {
458  m_registeringObjects.insert( objectName );
459  return this;
460  }
461 
463 
467 
473  virtual void copyWrapperAttributes( WrapperBase const & source );
474 
484  virtual std::unique_ptr< WrapperBase > clone( string const & name,
485  Group * const parent ) = 0;
486 
491  virtual void copyData( WrapperBase const & source ) = 0;
492 
497  virtual void copyWrapper( WrapperBase const & source ) = 0;
498 
503  virtual std::type_info const & get_typeid() const = 0;
504 
506 
507 #if defined(USE_TOTALVIEW_OUTPUT)
508 
513  virtual string totalviewTypeName() const = 0;
514 
520  virtual int setTotalviewDisplay() const;
521 // static int TV_ttf_display_type( const WrapperBase * wrapper);
522 #endif
523 
524 protected:
525 
527 
528  conduit::Node & getConduitNode()
529  {
530  return m_conduitNode;
531  }
532 
534 
535 protected:
536 
538  string m_name;
539 
542 
545 
548 
551 
554 
557 
559  std::set< string > m_registeringObjects;
560 
562  conduit::Node & m_conduitNode;
563 };
564 
565 }
566 }
567 
568 #endif /* GEOSX_DATAREPOSITORY_WRAPPERBASE_HPP_ */
string m_name
Name of the object that is being wrapped.
int sizedFromParent() const
Check whether this wrapper is resized when its parent is resized.
InputFlags m_inputFlag
Flag to store if this wrapped object should be read from input.
pugi::xml_node xmlNode
Alias for the type of an xml node.
Definition: xmlWrapper.hpp:60
WrapperBase * setPlotLevel(PlotLevel const flag)
Set the PlotLevel of the wrapper.
InputFlags getInputFlag() const
Get the InputFlag of the wrapper.
string m_description
A string description of the wrapped object.
std::set< string > m_registeringObjects
A vector of the names of the objects that created this Wrapper.
RestartFlags m_restart_flags
Flag to determine the restart behavior for this wrapped object.
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:67
constexpr void copy(DST_VECTOR &&LVARRAY_RESTRICT_REF dstVector, SRC_VECTOR const &LVARRAY_RESTRICT_REF srcVector)
Copy srcVector into dstVector.
WrapperBase * setSizedFromParent(int val)
Set whether this wrapper is resized when its parent is resized.
Group * m_parent
Pointer to Group that holds this WrapperBase.
RestartFlags getRestartFlags() const
Get the RestartFlags of the wrapper.
string const & getName() const
Get name of the wrapper.
Base class for all wrappers containing common operations.
Definition: WrapperBase.hpp:48
WrapperBase * setRestartFlags(RestartFlags flags)
Set the RestartFlags of the wrapper.
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:146
MemorySpace
An enum containing the available memory spaces.
WrapperBase * setInputFlag(InputFlags const input)
Set the InputFlag of the wrapper.
std::set< string > const & getRegisteringObjects() const
Get the list of names of groups that registered this wrapper.
WrapperBase * setRegisteringObjects(string const &objectName)
Add a new name to the list of groups that register this wrapper.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
WrapperBase * setDescription(string const &description)
Set the description string of the wrapper.
int m_sizedFromParent
Integer to indicate whether or not this wrapped object should be resized when m_parent is resized...
std::string string
String type.
Definition: DataTypes.hpp:131
PlotLevel m_plotLevel
Flag to store the plotLevel.
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.
A minimal class to specify information about time history information being collected and output...
PlotLevel getPlotLevel() const
Get PlotLevel for this wrapper.
string const & getDescription() const
Get the description string of the wrapper.
conduit::Node & m_conduitNode
A reference to the corresponding conduit::Node.