GEOSX
TimeHistoryCollection.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2019 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2019 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2019 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All right reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_TimeHistoryCollection_HPP_
20 #define GEOSX_TimeHistoryCollection_HPP_
21 
26 #include "dataRepository/BufferOpsDevice.hpp"
27 
28 #include <functional>
29 
30 namespace geosx
31 {
32 using namespace dataRepository;
33 
40 {
41 public:
43  HistoryCollection( string const & name, Group * parent ):
44  TaskBase( name, parent ),
45  m_collectionCount( 1 ),
46  m_timeBufferCall(),
47  m_bufferCalls()
48  { }
49 
50 
51  void InitializePostSubGroups( Group * const group ) override
52  {
53  GEOSX_UNUSED_VAR( group );
54  m_bufferCalls.resize( m_collectionCount );
55  }
56 
61  virtual localIndex getCollectionCount( ) const
62  {
63  return m_collectionCount;
64  }
65 
72  virtual HistoryMetadata getMetadata( ProblemManager & problemManager, localIndex collectionIdx )
73  {
74  GEOSX_UNUSED_VAR( problemManager );
75  GEOSX_UNUSED_VAR( collectionIdx );
76  return HistoryMetadata( );
77  }
78 
83  virtual const string & getTargetName( ) const = 0;
84 
89  virtual void Execute( real64 const time_n,
90  real64 const dt,
91  integer const cycleNumber,
92  integer const eventCounter,
93  real64 const eventProgress,
94  Group * domain ) override
95  {
96  GEOSX_UNUSED_VAR( cycleNumber );
97  GEOSX_UNUSED_VAR( eventCounter );
98  GEOSX_UNUSED_VAR( eventProgress );
99  for( localIndex collectionIdx = 0; collectionIdx < getCollectionCount(); ++collectionIdx )
100  {
101  // std::function defines the == and =! comparable against nullptr_t to check the
102  // function pointer is actually assigned (an error would be thrown on the call attempt even so)
103  GEOSX_ERROR_IF( m_bufferCalls[collectionIdx] == nullptr,
104  "History collection buffer retrieval function is unassigned, did you declare a related TimeHistoryOutput event?" );
105  // using GEOSX_ERROR_IF_EQ caused type issues since the values are used in streams
106  // TODO : grab the metadata again, determine if the size has changed, update the buffer call if so...
107  buffer_unit_type * buffer = m_bufferCalls[collectionIdx]();
108  DomainPartition & domainPart = dynamicCast< DomainPartition & >( *domain );
109  updateSetsIndices( domainPart );
110  collect( domainPart, time_n, dt, collectionIdx, buffer );
111  }
112  int rank = MpiWrapper::Comm_rank();
113  if( rank == 0 && m_timeBufferCall )
114  {
115  buffer_unit_type * timeBuffer = m_timeBufferCall();
116  memcpy( timeBuffer, &time_n, sizeof(time_n) );
117  }
118  }
119 
127  void registerBufferCall( localIndex collectionIdx, std::function< buffer_unit_type *() > bufferCall )
128  {
129  GEOSX_ERROR_IF( collectionIdx >= this->getCollectionCount( ), "Invalid collection index specified." );
130  m_bufferCalls[collectionIdx] = bufferCall;
131  }
132 
138  {
139  return HistoryMetadata( "Time", 1, std::type_index( typeid(real64) ) );
140  }
141 
148  void registerTimeBufferCall( std::function< buffer_unit_type *() > timeBufferCall )
149  {
150  m_timeBufferCall = timeBufferCall;
151  }
152 
158  {
159  return 0;
160  }
161 
170  virtual std::unique_ptr< HistoryCollection > getMetaCollector( ProblemManager & problemManager, localIndex metaIdx )
171  {
172  GEOSX_UNUSED_VAR( problemManager );
173  GEOSX_UNUSED_VAR( metaIdx );
174  return std::unique_ptr< HistoryCollection >( nullptr );
175  }
176 
181  virtual void updateSetsIndices ( DomainPartition & domain ) = 0;
182 
183 protected:
184 
193  virtual void collect( DomainPartition & domain, real64 const time_n, real64 const dt, localIndex const collectionIdx, buffer_unit_type * & buffer ) = 0;
194 
195 protected:
199  std::function< buffer_unit_type *() > m_timeBufferCall;
201  std::vector< std::function< buffer_unit_type *() > > m_bufferCalls;
202 };
203 
204 }
205 
206 #endif
void registerBufferCall(localIndex collectionIdx, std::function< buffer_unit_type *() > bufferCall)
Register a callback that gives the current head of the time history data buffer.
localIndex m_collectionCount
The number of discrete collection operations described by metadata this collection collects...
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
virtual std::unique_ptr< HistoryCollection > getMetaCollector(ProblemManager &problemManager, localIndex metaIdx)
Get a pointer to a collector of meta-information for this collector.
virtual void Execute(real64 const time_n, real64 const dt, integer const cycleNumber, integer const eventCounter, real64 const eventProgress, Group *domain) override
Collects history data.
void InitializePostSubGroups(Group *const group) override
Called by Initialize() after to initializing sub-Groups.
signed char buffer_unit_type
Type stored in communication buffers.
Definition: DataTypes.hpp:146
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:122
virtual HistoryMetadata getMetadata(ProblemManager &problemManager, localIndex collectionIdx)
Get the metadata for what this collector collects.
#define GEOSX_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:78
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
This is the class handling the operation flow of the problem being ran in GEOSX.
void registerTimeBufferCall(std::function< buffer_unit_type *() > timeBufferCall)
Register a callback that gives the current head of the time data buffer.
virtual localIndex getNumMetaCollectors() const
Get the number of collectors of meta-information (set indices, etc) writing time-independent informat...
std::vector< std::function< buffer_unit_type *() > > m_bufferCalls
Callbacks to get the current buffer head to write history data into.
HistoryCollection(string const &name, Group *parent)
Constructor.
#define GEOSX_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:103
HistoryMetadata getTimeMetadata() const
Get a metadata object relating the the Time variable itself.
std::function< buffer_unit_type *() > m_timeBufferCall
Callbacks to get the current time buffer head to write time data into.
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
A minimal class to specify information about time history information being collected and output...
virtual localIndex getCollectionCount() const
Get the number of discrete collection operations this collector conducts.