GEOSX
EventBase.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_MANAGERS_EVENTS_EVENTSBASE_HPP_
20 #define GEOSX_MANAGERS_EVENTS_EVENTSBASE_HPP_
21 
22 #include "dataRepository/Group.hpp"
25 
26 
27 namespace geosx
28 {
29 
34 class EventBase : public ExecutableGroup
35 {
36 public:
42  explicit EventBase( std::string const & name,
43  Group * const parent );
44 
46  virtual ~EventBase() override;
47 
52  static string CatalogName() { return "EventBase"; }
53 
62  virtual void SignalToPrepareForExecution( real64 const time,
63  real64 const dt,
64  integer const cycle,
65  dataRepository::Group * domain ) override;
70  virtual void Execute( real64 const time_n,
71  real64 const dt,
72  integer const cycleNumber,
73  integer const eventCounter,
74  real64 const eventProgress,
75  dataRepository::Group * domain ) override;
76 
84  void Step( real64 const time,
85  real64 const dt,
86  integer const cycle,
87  dataRepository::Group * domain );
88 
103  virtual Group * CreateChild( string const & childKey, string const & childName ) override;
104 
108  virtual void ExpandObjectCatalogs() override;
109 
117  void GetTargetReferences();
118 
129  virtual void CheckEvents( real64 const time,
130  real64 const dt,
131  integer const cycle,
132  dataRepository::Group * domain );
133 
141  virtual void EstimateEventTiming( real64 const time,
142  real64 const dt,
143  integer const cycle,
144  dataRepository::Group * domain ) = 0;
145 
151  virtual real64 GetTimestepRequest( real64 const time ) override;
152 
158  virtual real64 GetEventTypeDtRequest( real64 const time )
159  {
160  GEOSX_UNUSED_VAR( time );
162  }
163 
164 
169  void GetExecutionOrder( array1d< integer > & eventCounters );
170 
179  void SetProgressIndicator( array1d< integer > & eventCounters );
180 
182  struct viewKeyStruct
183  {
184  static constexpr auto eventTargetString = "target";
185  static constexpr auto beginTimeString = "beginTime";
186  static constexpr auto endTimeString = "endTime";
187  static constexpr auto forceDtString = "forceDt";
188  static constexpr auto maxEventDtString = "maxEventDt";
189  static constexpr auto lastTimeString = "lastTime";
190  static constexpr auto lastCycleString = "lastCycle";
191  static constexpr auto eventForecastString = "eventForecast";
192  static constexpr auto targetExactStartStopString = "targetExactStartStop";
193  static constexpr auto currentSubEventString = "currentSubEvent";
194  static constexpr auto isTargetExecutingString = "isTargetExecuting";
195  static constexpr auto finalDtStretchString = "finalDtStretch";
196 
197  dataRepository::ViewKey eventTarget = { "target" };
198  dataRepository::ViewKey beginTime = { "beginTime" };
199  dataRepository::ViewKey endTime = { "endTime" };
200  dataRepository::ViewKey forceDt = { "forceDt" };
201  dataRepository::ViewKey maxEventDt = { "maxEventDt" };
202  dataRepository::ViewKey lastTime = { "lastTime" };
203  dataRepository::ViewKey lastCycle = { "lastCycle" };
204  dataRepository::ViewKey eventForecast = { "eventForecast" };
205  dataRepository::ViewKey targetExactStartStop = { "targetExactStartStop" };
206  dataRepository::ViewKey currentSubEvent = { "currentSubEvent" };
207  dataRepository::ViewKey isTargetExecuting = { "isTargetExecuting" };
208  } viewKeys;
210 
215 
221 
226  void SetExitFlag( integer flag ){ m_exitFlag = flag; }
227 
232  real64 GetCurrentEventDtRequest() const { return m_currentEventDtRequest; }
233 
242  { return m_eventForecast; }
243 
248  bool isReadyForExec() const
249  { return m_eventForecast <= 0; }
250 
255  bool hasToPrepareForExec() const
256  { return m_eventForecast == 1; }
257 
262  bool isIdle() const
263  { return m_eventForecast > 1; }
264 
265 protected:
266 
271  { m_eventForecast = 0; }
272 
277  { m_eventForecast = 1; }
278 
282  void setIdle()
284 
293  void setForecast( integer forecast )
294  { m_eventForecast = forecast; }
295 
301  bool isActive( real64 const time ) const
302  { return ( time >= m_beginTime ) && ( time < m_endTime ); }
303 
309  { return m_target; }
310 
315 
316 private:
317  string m_eventTarget;
318  real64 m_beginTime;
319  real64 m_endTime;
320  real64 m_forceDt;
321  real64 m_maxEventDt;
322  real64 m_finalDtStretch;
323  integer m_targetExactStartStop;
324  integer m_currentSubEvent;
325  integer m_targetExecFlag;
326  integer m_eventForecast;
327  integer m_exitFlag;
328  integer m_eventCount;
329  integer m_timeStepEventCount;
330  real64 m_eventProgress;
331  real64 m_currentEventDtRequest;
332 
334  ExecutableGroup * m_target;
335 };
336 
337 } /* namespace geosx */
338 
339 #endif /* GEOSX_MANAGERS_EVENTS_EVENTSBASE_HPP_ */
void SetExitFlag(integer flag)
Set this event objects exit flag.
Definition: EventBase.hpp:226
void setReadyForExec()
Define the event as ready for execution.
Definition: EventBase.hpp:270
integer getForecast() const
Get the forecast of the current event.
Definition: EventBase.hpp:241
void SetProgressIndicator(array1d< integer > &eventCounters)
Update the event progress for the event/sub-events.
virtual Group * CreateChild(string const &childKey, string const &childName) override
Creates a new sub-Group using the ObjectCatalog functionality.
bool isActive(real64 const time) const
Is the event active?
Definition: EventBase.hpp:301
void Step(real64 const time, real64 const dt, integer const cycle, dataRepository::Group *domain)
Call the execute method on the target and/or children if present.
real64 GetCurrentEventDtRequest() const
Get the current time increment request for this event.
Definition: EventBase.hpp:232
integer m_lastCycle
The last cycle the event occurred.
Definition: EventBase.hpp:314
virtual void EstimateEventTiming(real64 const time, real64 const dt, integer const cycle, dataRepository::Group *domain)=0
Perform the calculations to estimate the timing of the event.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
virtual void Execute(real64 const time_n, real64 const dt, integer const cycleNumber, integer const eventCounter, real64 const eventProgress, dataRepository::Group *domain) override
If the event forecast is equal to 0, then call the step function on its target and/or children...
static string CatalogName()
Catalog name interface.
Definition: EventBase.hpp:52
Group::wrapperMap::KeyIndex ViewKey
Type alias for KeyIndexT type used for wrapper lookups.
Definition: Group.hpp:1545
virtual void SignalToPrepareForExecution(real64 const time, real64 const dt, integer const cycle, dataRepository::Group *domain) override
If the event forecast is equal to 1, then signal the targets to prepare for execution during the next...
ExecutableGroup * GetEventTarget() const
Get the target of this event.
Definition: EventBase.hpp:308
static CatalogInterface::CatalogType & GetCatalog()
Get the singleton catalog for this class.
virtual void CheckEvents(real64 const time, real64 const dt, integer const cycle, dataRepository::Group *domain)
Events are triggered based upon their forecast values, which are defined as the expected number of co...
virtual real64 GetTimestepRequest(real64 const time) override
Collect time-step size requests from targets and/or children.
bool isIdle() const
Check if the event is idle.
Definition: EventBase.hpp:262
integer GetExitFlag()
Get the sum of the exit flags for the event/sub-events from the last execution.
bool isReadyForExec() const
Check if the event is ready for execution.
Definition: EventBase.hpp:248
void GetExecutionOrder(array1d< integer > &eventCounters)
Count the number of events/sub-events.
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:122
This class provides the base class/interface for the catalog value objects.
bool hasToPrepareForExec() const
Check if the event must be preparing for execution.
Definition: EventBase.hpp:255
virtual real64 GetEventTypeDtRequest(real64 const time)
Get event-specifit dt requests.
Definition: EventBase.hpp:158
void setForecast(integer forecast)
Sets the forecast.
Definition: EventBase.hpp:293
#define GEOSX_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:78
void setPrepareForExec()
Define that the event should prepare for execution.
Definition: EventBase.hpp:276
virtual void ExpandObjectCatalogs() override
Expand any catalogs in the data structure.
void setIdle()
Define the event as idle.
Definition: EventBase.hpp:282
void GetTargetReferences()
Process input data to retrieve targeted objects internally. The target object for an event may be spe...
std::string string
String type.
Definition: DataTypes.hpp:131
virtual ~EventBase() override
Destructor.
real64 m_lastTime
The last time the event occurred.
Definition: EventBase.hpp:312
constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > max(T const a, T const b)
Definition: math.hpp:46
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55
EventBase(std::string const &name, Group *const parent)
Main constructor.
std::unordered_map< std::string, std::unique_ptr< CatalogInterface< BASETYPE, ARGS... > > > CatalogType
This is the type that will be used for the catalog. The catalog is actually instantiated in the BASET...