WSF
WsfEventStepSimulation Class Reference

A specialization of WsfSimulation that implements an event-stepped simulation. More...

#include <WsfEventStepSimulation.hpp>

Inheritance diagram for WsfEventStepSimulation:
Collaboration diagram for WsfEventStepSimulation:

Public Member Functions

 WsfEventStepSimulation (WsfScenario &aScenario, unsigned int aRunNumber)
 ~WsfEventStepSimulation () override
void Initialize () override
void Complete (double aSimTime) override
bool PlatformDeleted (double aSimTime, WsfPlatform *aOldPlatformPtr) override
void SetPartUpdateInterval (double aSimTime, WsfPlatformPart *aPartPtr, double aUpdateInterval) override
bool TurnPartOff (double aSimTime, WsfPlatformPart *aPartPtr) override
bool TurnPartOn (double aSimTime, WsfPlatformPart *aPartPtr) override
void SetRealtime (double aSimTime, bool aIsRealTime) override
 Set the optional real-time mode of the simulation.
void WaitForAdvanceTime () override
Public Member Functions inherited from WsfSimulation
 WsfSimulation (const WsfScenario &aScenario, unsigned int aRunNumber)
virtual ~WsfSimulation ()
 WsfSimulation (const WsfSimulation &aSrc)=delete
WsfSimulationoperator= (const WsfSimulation &aRhs)=delete
const WsfScenarioGetScenario () const
WsfApplicationGetApplication () const
virtual void PrepareSimulation ()
virtual void AddEvent (std::unique_ptr< WsfEvent > aEventPtr)
template<typename T, typename... Args>
T * AddEventT (Args &&... args)
virtual void AddWallEvent (std::unique_ptr< WsfEvent > aEventPtr)
template<typename T, typename... Args>
T * AddWallEventT (Args &&... args)
virtual double AdvanceTime ()
virtual double AdvanceTime (double aSimTime)
virtual bool ShouldExecute () const
virtual void Start ()
virtual void Pause ()
 Pause execution of the simulation.
void PauseAndRequestAdvance (double)
 Pause the execution of the simulation and request a time advance in scaled-and-stepped mode.
virtual void Resume ()
 Resume execution of the paused simulation.
virtual void RequestReset ()
bool IsActive () const
State GetState () const
 Return the simulation's current state.
const std::string & GetStateString () const
 Return the string representation of the simulation's current state.
CompletionReason GetCompletionReason () const
virtual std::string GetCompletionReasonString () const
virtual void RequestTermination ()
void SetEndTime (double aEndTime)
 Set the defined end time of the simulation.
double GetSimTime () const
 Get the last time to which the simulation was updated.
double GetEndTime () const
 Get the defined end time of the simulation.
virtual double GetNextEventTime () const
double GetRealTime () const
bool IsRealTime () const
 Return whether this simulation is running real-time, or a multiple of real-time.
double GetWallTime () const
 Get the current wall-clock time since simulation creation.
double GetTimeBehind () const
double GetTimestep () const
double GetSyncTimestep () const
void SetIsExternallyStarted (bool aIsExternallyStarted)
bool IsExternallyStarted () const
 Return whether the simulation is to be started by an external source.
bool MultiThreadingActive () const
 Return whether the simulation multi-threading is currently active.
void SetMultiThreadingActive (bool aMultiThreadingActive)
 Set whether multi-threading is currently active ('true') or not ('false').
bool IsEventStepSimulation () const
 Return event step simulation indicator.
void SetAmAnEventStepSimulation (bool aFlag)
void SetClockSource (std::unique_ptr< WsfClockSource > aClockSourcePtr)
const WsfClockSourceGetClockSource () const
virtual double GetClockRate () const
 Returns the clock rate of the simulation.
virtual void SetClockRate (double aClockRate)
 Changes the clock rate of the simulation.
virtual void SetTimeParameters (int aTimeScheme, double aSimTime, double aClockRate, double aTimeStep, bool aTimeAdvance=false)
 Change the time parameters of the simulation.
virtual bool AddPlatform (WsfPlatform *aPlatformPtr)
virtual bool AddPlatform (double aSimTime, WsfPlatform *aPlatformPtr)
virtual void DeletePlatform (double aSimTime, WsfPlatform *aPlatformPtr, bool aDeleteMemory=true)
WsfPlatformGetPlatformByIndex (size_t aIndex) const
WsfPlatformGetPlatformByName (WsfStringId aNameId) const
bool PlatformExists (size_t aIndex) const
 Returns 'true' if the platform with the specified index still exists.
WsfStringId GetPlatformNameId (size_t aIndex) const
 Return the name (ID) of a platform, even if the platform has been deleted from the simulation.
WsfStringId GetPlatformTypeId (size_t aIndex) const
 Return the type (ID) of a platform, even if the platform has been deleted from the simulation.
size_t GetPlatformCount () const
WsfPlatformGetPlatformEntry (size_t aEntry) const
virtual bool SetPartOperational (double aSimTime, WsfPlatformPart *aPartPtr, bool aOperational=true)
virtual void ProcessRemovePlatformEvent (double aSimTime, WsfPlatform *aPlatformPtr, bool aDeletePlatform)
 Called from RemovePlatformEvent to complete the processing of deleting a platform.
virtual void ProcessPlatformBrokenEvent (double aSimTime, WsfPlatform *aPlatformPtr)
 Call from PlatformBrokenEvent to complete the processing of the broken of a platform.
virtual void SimulationStarting ()
 Deprecated form of Start();.
virtual void SimulationComplete (double aSimTime)
 Deprecated form of Complete();.
bool IsFlexibleRealtime () const
 Return 'true' if the simulation's real-time constraint is flexible.
void SetFlexibleRealtime ()
WsfAdvancedBehaviorObserverGetAdvancedBehaviorObserver () const
WsfBehaviorObserverGetBehaviorObserver () const
WsfCommObserverGetCommObserver () const
WsfDisObserverGetDisObserver () const
WsfExchangeObserverGetExchangeObserver () const
WsfFuelObserverGetFuelObserver () const
WsfMoverObserverGetMoverObserver () const
WsfPlatformObserverGetPlatformObserver () const
WsfPlatformPartObserverGetPlatformPartObserver () const
WsfProcessorObserverGetProcessorObserver () const
WsfScriptStateMachineObserverGetScriptStateMachineObserver () const
WsfSensorObserverGetSensorObserver () const
WsfSimulationObserverGetSimulationObserver () const
WsfTaskObserverGetTaskObserver () const
WsfTrackObserverGetTrackObserver () const
WsfZoneObserverGetZoneObserver () const
WsfSimulationExtensionFindExtension (const std::string &aName) const
WsfSimulationExtensionGetExtension (const std::string &aName) const
const WsfExtensionListGetExtensions () const
void RegisterExtension (const std::string &aName, std::unique_ptr< WsfSimulationExtension > aExtensionPtr)
const std::vector< std::string > & GetExtensionNames () const
unsigned int AssignUniqueId ()
 Assign the next unique identifier for WsfUniqueId.
ut::Random & GetRandom ()
ut::Random & LockRandom ()
void UnlockRandom ()
ut::Random & GetScriptRandom ()
ut::Random & LockScriptRandom ()
void UnlockScriptRandom ()
wsf::TerrainInterfaceGetTerrainInterface () const
WsfDateTimeGetDateTime ()
const WsfDateTimeGetDateTime () const
WsfGroupManagerGetGroupManager ()
wsf::comm::NetworkManagerGetCommNetworkManager () const
WsfMultiThreadManagerGetMultiThreadManager ()
WsfPathFinderListGetPathFinderList () const
WsfScriptContextGetScriptContext ()
const WsfScriptContextGetScriptContext () const
WsfLOS_ManagerGetLOS_Manager () const
WsfZoneAttenuationGetZoneAttenuation ()
WsfEM_ManagerGetEM_Manager ()
UtScriptExecutor & GetScriptExecutor ()
UtAtmosphere & GetAtmosphere () const
 Return the UtAtmosphere object used by the simulation.
WsfEnvironmentGetEnvironment () const
WsfSystemLogGetSystemLog () const
WsfIFF_ManagerGetIFF_Manager () const
unsigned int NextMessageSerialNumber ()
unsigned int NextEngagementSerialNumber ()
unsigned int PreviousEngagementSerialNumber () const
void ReclaimPreviousEngagementSerialNumber ()
double CreateMessageDataTag ()
bool MultiThreaded () const
 Return whether the simulation should multi-thread were appropriate.
unsigned int GetRunNumber () const
 Get the current run number.
unsigned int GetFinalRunNumber () const
bool RandomizeFrequency () const
bool UseDefaultFrequency () const
double GetMinimumMoverTimestep () const
const WsfSimulationInputGetSimulationInput () const
std::string SubstituteOutputFileVariables (const std::string &aOutputFile)

Protected Member Functions

bool PlatformInitialized (double aSimTime, WsfPlatform *aNewPlatformPtr) override
bool PlatformIntroduced (double aSimTime, WsfPlatform *aNewPlatformPtr) override
void CreateClock () override
bool AddInputPlatforms ()
virtual bool TurnPartOffP (double aSimTime, WsfPlatformPart *aPartPtr)
virtual bool TurnPartOnP (double aSimTime, WsfPlatformPart *aPartPtr)
virtual bool SetPartOperationalP (double aSimTime, WsfPlatformPart *aPartPtr, bool aOperational)
virtual void DispatchWallEvents ()
 Dispatch any pending wall clock events up to and including the indicated time.
virtual void DispatchSimEvents (double aSimTime)
virtual void DispatchEvents (double aSimTime)
virtual bool SimulationInitialized ()
virtual bool PlatformIsAvailable (WsfPlatform *aPlatformPtr)
void AddToPlatformList (WsfPlatform *aPlatformPtr)
bool DeleteFromPlatformList (WsfPlatform *aPlatformPtr)
bool PlatformPointerExists (WsfPlatform *aPlatformPtr)
void ResetPlatformList ()
 Reset the list to its initial (empty) state.

Additional Inherited Members

Public Types inherited from WsfSimulation
enum  State {
  cPENDING_INITIALIZE , cINITIALIZING , cPENDING_START , cSTARTING ,
  cACTIVE , cPENDING_COMPLETE , cCOMPLETE
}
 An enumerated type specifying the state of the simulation. More...
enum  CompletionReason {
  cNONE , cEND_TIME_REACHED , cRESET , cTERMINATE ,
  cOTHER
}
 An enumerated type specifying the reason for completion of the simulation. More...
static const std::string & GetStateString (State aState)
 Return the string representation of the provided simulation state.
WsfEM_Manager mEM_Manager
 EM manager.
WsfEventManager mEventManager
 Simulation event manager object.
WsfEventManager mWallEventManager
 Wall clock-based event manager object.
std::unique_ptr< WsfClockSourcemClockSourcePtr {nullptr}
 Pointer to the simulation clock source object.
WsfRealTimeClockSourcemRealTimeClockSourcePtr {nullptr}
double mSimTime {0.0}
 The last time to which the simulation has been updated (seconds).
double mRealTime {false}
double mTimeBehind {0.0}
 The amount of time the simulation clock is behind the real-time clock.
double mTimestep {0.0}
double mSyncAccumulatedTime {0.0}
 The wall clock time taken to execute the current synchronized time step.
volatile State mState {cPENDING_INITIALIZE}
 The current state of the simulation.
volatile CompletionReason mCompletionReason {cNONE}
 The reason for simulation completion.
bool mExternalEventReady {false}
 True if an external event needs to be processed.
unsigned int mRunNumber
 The current run number being executed.
const WsfSimulationInputmSimulationInput
WsfDateTime mDateTime
bool mMultiThreaded
double mMinimumMoverTimestep
double mEndTime {std::numeric_limits<double>::max()}
 The end time of the simulation (seconds).
bool mIsRealTime {false}

Detailed Description

A specialization of WsfSimulation that implements an event-stepped simulation.

Constructor & Destructor Documentation

◆ WsfEventStepSimulation()

WsfEventStepSimulation::WsfEventStepSimulation ( WsfScenario & aScenario,
unsigned int aRunNumber )

◆ ~WsfEventStepSimulation()

WsfEventStepSimulation::~WsfEventStepSimulation ( )
override

Member Function Documentation

◆ Complete()

void WsfEventStepSimulation::Complete ( double aSimTime)
overridevirtual

Indicate that the application has completed its simulation loop.

This performs the following action (in the order specified):

  • Marks the simulation as complete.
  • Stops the clock.
  • Invokes SimulationComplete for each registered simulation observer.
  • Deletes all remaining platforms.
  • Deletes all remaining events in the event queue
  • Invokes the Complete method for each registered simulation extension.
  • Resets the clock back to 0.0
Parameters
aSimTimeThe current simulation time.

Reimplemented from WsfSimulation.

References WsfMultiThreadManager::Complete(), WsfSimulation::Complete(), WsfSimulation::GetMultiThreadManager(), and WsfSimulation::MultiThreaded().

Referenced by weapon_tools().

◆ CreateClock()

void WsfEventStepSimulation::CreateClock ( )
overrideprotectedvirtual

This is a method used to create the type of clock the simulation expects.

Note
See WsfEventStepSimulation for a non-trivial implementation.

Reimplemented from WsfSimulation.

References WsfSimulation::mIsRealTime, and WsfSimulation::SetClockSource().

Referenced by SetRealtime().

◆ Initialize()

void WsfEventStepSimulation::Initialize ( )
overridevirtual

Initialize the simulation.

This method initializes the simulation by performing the following actions:

  • Invokes the Initialize method for each registered simulation extension.
  • Invokes Initialize each registered simulation observer.
  • Adds the 'initial state' platforms to the simulation.
  • Invokes the derived class SimulationInitialized() method.
  • Marks the simulation as 'pending_start'

Upon completion of this call, the application should call WsfSimulation::Start, enter a loop to execute events and then call WsfSimulation::Complete.

Exceptions
WsfSimulation::InitializeErrorif an error is encountered.
Note
It is an error to call this method again without calling WsfSimulation::Complete.

Reimplemented from WsfSimulation.

References WsfSimulation::AddEvent(), WsfSimulation::GetMultiThreadManager(), WsfSimulation::GetSimTime(), WsfMultiThreadManager::Initialize(), WsfSimulation::Initialize(), WsfSimulation::mIsRealTime, WsfSimulation::mMinimumMoverTimestep, and WsfSimulation::MultiThreaded().

Referenced by weapon_tools().

◆ PlatformDeleted()

bool WsfEventStepSimulation::PlatformDeleted ( double aSimTime,
WsfPlatform * aOldPlatformPtr )
overridevirtual

Virtual method invoked by the base class used to notify other platforms and observers of the impending deletion of a platform. This is called immediately prior to deleting the platform object.

Parameters
aSimTimeThe current simulation time.
aOldPlatformPtrPointer to the platform to be deleted.
Returns
'true' if successful and 'false' otherwise.

Reimplemented from WsfSimulation.

References WsfSimulation::GetMultiThreadManager(), WsfSimulation::MultiThreaded(), WsfMultiThreadManager::PlatformDeleted(), and WsfSimulation::PlatformDeleted().

◆ PlatformInitialized()

bool WsfEventStepSimulation::PlatformInitialized ( double aSimTime,
WsfPlatform * aNewPlatformPtr )
overrideprotectedvirtual

Virtual method invoked by the base class just after it has called the a platforms Initialize() method.

It is provided so derived classes can perform their own unique platform initialization.

Parameters
aSimTimeThe current simulation time.
aNewPlatformPtrPointer to the platform just initialized.
Returns
'true' if successful and 'false' otherwise.

Reimplemented from WsfSimulation.

References WsfSimulation::AddEvent(), WsfPlatform::GetMover(), moverPtr, and WsfSimulation::MultiThreaded().

◆ PlatformIntroduced()

bool WsfEventStepSimulation::PlatformIntroduced ( double aSimTime,
WsfPlatform * aNewPlatformPtr )
overrideprotectedvirtual

Virtual method invoked by the base class after it has introduced a new platform to the simulation.

Parameters
aSimTimeThe current simulation time.
aNewPlatformPtrPointer to the platform just introduced.
Returns
'true' if successful and 'false' otherwise.

Reimplemented from WsfSimulation.

References WsfSimulation::GetMultiThreadManager(), WsfSimulation::MultiThreaded(), WsfMultiThreadManager::PlatformIntroduced(), and WsfSimulation::PlatformIntroduced().

◆ SetPartUpdateInterval()

void WsfEventStepSimulation::SetPartUpdateInterval ( double aSimTime,
WsfPlatformPart * aPartPtr,
double aUpdateInterval )
overridevirtual

Set the update interval for a platform part. This method defines how often the simulation executive will call the Update() method.

Parameters
aSimTimeThe current simulation time.
aPartPtrA pointer to the sensor whose update interval is to be changed.
aUpdateIntervalThe new update interval. If this value is less than or equal to zero, the periodic calls to Update() will be deactivated until another call is made to reactive the periodic calls.

Reimplemented from WsfSimulation.

References WsfSimulation::AddEvent(), WsfPlatformPartEvent::cUPDATE, WsfPlatformPart::GetPartType(), WsfPlatformPart::IncrementUpdateEventEpoch(), WsfSensor::IsSlave(), WsfPlatformPart::IsTurnedOn(), WsfPlatformPart::SetUpdateInterval(), and WsfPlatformPart::UpdateEventActive().

◆ SetRealtime()

void WsfEventStepSimulation::SetRealtime ( double aSimTime,
bool aIsRealTime )
overridevirtual

Set the optional real-time mode of the simulation.

Parameters
aSimTimeThe current simulation time.
aIsRealTimeWhether we desire real-time behavior.

Reimplemented from WsfSimulation.

References CreateClock(), WsfSimulation::IsExternallyStarted(), WsfSimulation::mClockSourcePtr, and WsfSimulation::mIsRealTime.

◆ TurnPartOff()

bool WsfEventStepSimulation::TurnPartOff ( double aSimTime,
WsfPlatformPart * aPartPtr )
overridevirtual

◆ TurnPartOn()

◆ WaitForAdvanceTime()

void WsfEventStepSimulation::WaitForAdvanceTime ( )
overridevirtual

Wait for the next event to occur. If running real-time and the real-time clock is running, impose a delay if the next event is too far in the future. The purpose of this routine is simply to avoid having a real-time application consume all the processor time while simply waiting for events. If the next event is 'too far' in the future, it delays a 'short' period of time and returns to the caller. It does not try to burn up all the time because external activities may cause new events to be inserted earlier in the queue.

Note
This routine does nothing unless the running real-time and the real-time clock is running.

Reimplemented from WsfSimulation.

References WsfSimulation::GetClockRate(), WsfSimulation::GetSimTime(), WsfEvent::GetTime(), WsfSimulation::mClockSourcePtr, WsfSimulation::mEventManager, WsfSimulation::mIsRealTime, WsfSimulation::mRealTime, WsfSimulation::mTimeBehind, and WsfObserver::SimulationTimeBehind().


The documentation for this class was generated from the following files:
Copyrights Multiple, All Rights Reserved