GEOS
EventBase.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 Total, S.A
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 
20 #ifndef GEOS_EVENTS_EVENTSBASE_HPP_
21 #define GEOS_EVENTS_EVENTSBASE_HPP_
22 
23 #include "dataRepository/Group.hpp"
25 
26 
27 namespace geos
28 {
29 
34 class EventBase : public ExecutableGroup
35 {
36 public:
42  explicit EventBase( string const & name,
43  Group * const parent );
44 
46  virtual ~EventBase() override;
47 
56  virtual void signalToPrepareForExecution( real64 const time,
57  real64 const dt,
58  integer const cycle,
59  DomainPartition & domain ) override;
64  virtual bool execute( real64 const time_n,
65  real64 const dt,
66  integer const cycleNumber,
67  integer const eventCounter,
68  real64 const eventProgress,
69  DomainPartition & domain ) override;
70 
78  void step( real64 const time,
79  real64 const dt,
80  integer const cycle,
81  dataRepository::Group * domain );
82 
97  virtual Group * createChild( string const & childKey, string const & childName ) override;
98 
102  virtual void expandObjectCatalogs() override;
103 
112 
123  virtual void checkEvents( real64 const time,
124  real64 const dt,
125  integer const cycle,
126  DomainPartition & domain );
127 
135  virtual void estimateEventTiming( real64 const time,
136  real64 const dt,
137  integer const cycle,
138  DomainPartition & domain ) = 0;
139 
145  virtual real64 getTimestepRequest( real64 const time ) override;
146 
152  virtual real64 getEventTypeDtRequest( real64 const time )
153  {
154  GEOS_UNUSED_VAR( time );
155  return std::numeric_limits< real64 >::max();
156  }
157 
162  virtual void validate() const {};
163 
168  void getExecutionOrder( array1d< integer > & eventCounters );
169 
178  void setProgressIndicator( array1d< integer > & eventCounters );
179 
181  struct viewKeyStruct
182  {
183  static constexpr char const * eventTargetString() { return "target"; }
184  static constexpr char const * beginTimeString() { return "beginTime"; }
185  static constexpr char const * endTimeString() { return "endTime"; }
186  static constexpr char const * forceDtString() { return "forceDt"; }
187  static constexpr char const * maxEventDtString() { return "maxEventDt"; }
188  static constexpr char const * lastTimeString() { return "lastTime"; }
189  static constexpr char const * lastCycleString() { return "lastCycle"; }
190  static constexpr char const * eventForecastString() { return "eventForecast"; }
191  static constexpr char const * targetExactStartStopString() { return "targetExactStartStop"; }
192  static constexpr char const * currentSubEventString() { return "currentSubEvent"; }
193  static constexpr char const * isTargetExecutingString() { return "isTargetExecuting"; }
194  static constexpr char const * finalDtStretchString() { return "finalDtStretch"; }
195 
196  dataRepository::ViewKey eventTarget = { eventTargetString() };
197  dataRepository::ViewKey beginTime = { beginTimeString() };
198  dataRepository::ViewKey endTime = { endTimeString() };
199  dataRepository::ViewKey forceDt = { forceDtString() };
200  dataRepository::ViewKey maxEventDt = { maxEventDtString() };
201  dataRepository::ViewKey lastTime = { lastTimeString() };
202  dataRepository::ViewKey lastCycle = { lastCycleString() };
203  dataRepository::ViewKey eventForecast = { eventForecastString() };
204  dataRepository::ViewKey targetExactStartStop = { targetExactStartStopString() };
205  dataRepository::ViewKey currentSubEvent = { currentSubEventString() };
206  dataRepository::ViewKey isTargetExecuting = { isTargetExecutingString() };
207  } viewKeys;
209 
214 
220 
225  void setExitFlag( integer flag ){ m_exitFlag = flag; }
226 
231  real64 getCurrentEventDtRequest() const { return m_currentEventDtRequest; }
232 
241  { return m_eventForecast; }
242 
247  bool isReadyForExec() const
248  { return m_eventForecast <= 0; }
249 
254  bool hasToPrepareForExec() const
255  { return m_eventForecast == 1; }
256 
261  bool isIdle() const
262  { return m_eventForecast > 1; }
263 
268  string getEventName() const
269  {
270  return m_eventTarget;
271  }
272 
273 protected:
274 
279  { m_eventForecast = 0; }
280 
285  { m_eventForecast = 1; }
286 
290  void setIdle()
291  { m_eventForecast = std::numeric_limits< decltype( m_eventForecast ) >::max(); }
292 
301  void setForecast( integer forecast )
302  { m_eventForecast = forecast; }
303 
309  { return m_target; }
310 
316  bool isActive( real64 const time ) const
317  { return ( time >= m_beginTime ) && ( time < m_endTime ); }
318 
324  bool isReadyForCleanup( real64 const time ) const
325  { return isActive( time ) || isZero( time - m_endTime ); }
326 
327 
332 
333 private:
334  string m_eventTarget;
335  real64 m_beginTime;
336  real64 m_endTime;
337  real64 m_forceDt;
338  real64 m_maxEventDt;
339  real64 m_finalDtStretch;
340  integer m_targetExactStartStop;
341  integer m_currentSubEvent;
342  integer m_targetExecFlag;
343  integer m_eventForecast;
344  integer m_exitFlag;
345  integer m_eventCount;
346  integer m_timeStepEventCount;
347  real64 m_eventProgress;
348  real64 m_currentEventDtRequest;
349 
351  ExecutableGroup * m_target;
352 };
353 
354 } /* namespace geos */
355 
356 #endif /* GEOS_EVENTS_EVENTSBASE_HPP_ */
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:84
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
real64 m_lastTime
The last time the event occurred.
Definition: EventBase.hpp:329
void setPrepareForExec()
Define that the event should prepare for execution.
Definition: EventBase.hpp:284
virtual Group * createChild(string const &childKey, string const &childName) override
Creates a new sub-Group using the ObjectCatalog functionality.
virtual void expandObjectCatalogs() override
Expand any catalogs in the data structure.
integer getForecast() const
Get the forecast of the current event.
Definition: EventBase.hpp:240
void setExitFlag(integer flag)
Set this event objects exit flag.
Definition: EventBase.hpp:225
EventBase(string const &name, Group *const parent)
Main constructor.
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.
virtual real64 getTimestepRequest(real64 const time) override
Collect time-step size requests from targets and/or children.
virtual void validate() const
Helper function to validate the consistency of the event input.
Definition: EventBase.hpp:162
real64 getCurrentEventDtRequest() const
Get the current time increment request for this event.
Definition: EventBase.hpp:231
bool isReadyForCleanup(real64 const time) const
Is the event ready for cleanup?
Definition: EventBase.hpp:324
bool isReadyForExec() const
Check if the event is ready for execution.
Definition: EventBase.hpp:247
integer getExitFlag()
Get the sum of the exit flags for the event/sub-events from the last execution.
virtual ~EventBase() override
Destructor.
virtual real64 getEventTypeDtRequest(real64 const time)
Get event-specifit dt requests.
Definition: EventBase.hpp:152
bool isActive(real64 const time) const
Is the event active?
Definition: EventBase.hpp:316
string getEventName() const
Get the string name of the target.
Definition: EventBase.hpp:268
void setReadyForExec()
Define the event as ready for execution.
Definition: EventBase.hpp:278
ExecutableGroup * getEventTarget() const
Get the target of this event.
Definition: EventBase.hpp:308
void getExecutionOrder(array1d< integer > &eventCounters)
Count the number of events/sub-events.
virtual void signalToPrepareForExecution(real64 const time, real64 const dt, integer const cycle, DomainPartition &domain) override
If the event forecast is equal to 1, then signal the targets to prepare for execution during the next...
virtual bool execute(real64 const time_n, real64 const dt, integer const cycleNumber, integer const eventCounter, real64 const eventProgress, DomainPartition &domain) override
If the event forecast is equal to 0, then call the step function on its target and/or children.
bool isIdle() const
Check if the event is idle.
Definition: EventBase.hpp:261
void setProgressIndicator(array1d< integer > &eventCounters)
Update the event progress for the event/sub-events.
virtual void checkEvents(real64 const time, real64 const dt, integer const cycle, DomainPartition &domain)
Events are triggered based upon their forecast values, which are defined as the expected number of co...
virtual void estimateEventTiming(real64 const time, real64 const dt, integer const cycle, DomainPartition &domain)=0
Perform the calculations to estimate the timing of the event.
void setForecast(integer forecast)
Sets the forecast.
Definition: EventBase.hpp:301
void getTargetReferences()
Process input data to retrieve targeted objects internally. The target object for an event may be spe...
void setIdle()
Define the event as idle.
Definition: EventBase.hpp:290
integer m_lastCycle
The last cycle the event occurred.
Definition: EventBase.hpp:331
static CatalogInterface::CatalogType & getCatalog()
Get the singleton catalog for this Group.
bool hasToPrepareForExec() const
Check if the event must be preparing for execution.
Definition: EventBase.hpp:254
This class provides the base class/interface for the catalog value objects.
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...
Group::wrapperMap::KeyIndex ViewKey
Type alias for KeyIndexT type used for wrapper lookups.
Definition: Group.hpp:1662
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
Array< T, 1 > array1d
Alias for 1D array.
Definition: DataTypes.hpp:176
Structure to hold scoped key names.
Definition: Group.hpp:1442