SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
SSAGES::Hook Class Referenceabstract

Base class for hooks into the simultion engines. More...

#include <Hook.h>

Public Member Functions

 Hook ()
 Constructor. More...
 
void SetSnapshot (class Snapshot *snapshot)
 Sets the active snapshot. More...
 
void SetCVManager (class CVManager *cvmanager)
 Sets the current CV manager. More...
 
void AddListener (EventListener *listener)
 Add a listener to the hook. More...
 
void NotifyObservers ()
 Notify observers of changes in the simulation.
 
void PreSimulationHook ()
 Pre-simulation hook. More...
 
void PostIntegrationHook ()
 Post-integration hook. More...
 
void PostStepHook ()
 Post-step hook. More...
 
void PostSimulationHook ()
 Post-simulation hook. More...
 
virtual ~Hook ()
 Destructor.
 

Protected Member Functions

virtual void SyncToEngine ()=0
 Synchronization to the simulation engine. More...
 
virtual void SyncToSnapshot ()=0
 Synchronization to the snapshot. More...
 

Protected Attributes

class Snapshotsnapshot_
 Local snapshot.
 

Private Attributes

std::vector< EventListener * > listeners_
 Vector of event listeners.
 
class CVManagercvmanager_
 Collective variable manager.
 

Detailed Description

Base class for hooks into the simultion engines.

Abstract base class responsible for hooking into simulation engine and calling appropriate events.

Definition at line 35 of file Hook.h.

Constructor & Destructor Documentation

◆ Hook()

SSAGES::Hook::Hook ( )
inline

Constructor.

Initialize a hook with world and walker communicators and corresponding walker ID.

Definition at line 68 of file Hook.h.

68  :
69  listeners_(0), snapshot_(nullptr)
70  {}
std::vector< EventListener * > listeners_
Vector of event listeners.
Definition: Hook.h:39
class Snapshot * snapshot_
Local snapshot.
Definition: Hook.h:46

Member Function Documentation

◆ AddListener()

void SSAGES::Hook::AddListener ( EventListener listener)

Add a listener to the hook.

Parameters
listenerPointer to the EventListener to be added to the Hook.

Does nothing if the listener is already added.

Definition at line 101 of file Hook.cpp.

102  {
103  if(std::find(listeners_.begin(), listeners_.end(), listener) == listeners_.end())
104  listeners_.push_back(listener);
105  }

References listeners_.

Referenced by SSAGES::ResourceHandler::ConfigureHook().

Here is the caller graph for this function:

◆ PostIntegrationHook()

void SSAGES::Hook::PostIntegrationHook ( )

Post-integration hook.

This function should be called by the Hook implementation within the integration routine such that the forces, position, velocities, etc.. will be updated.

Definition at line 50 of file Hook.cpp.

51  {
52  snapshot_->Changed(false);
53 
54  for(auto& cv : cvmanager_->GetCVs())
55  cv->Evaluate(*snapshot_);
56 
57  for(auto& listener : listeners_)
58  if(snapshot_->GetIteration() % listener->GetFrequency() == 0)
59  listener->PostIntegration(snapshot_, *cvmanager_);
60 
61  if(snapshot_->HasChanged())
62  SyncToEngine();
63 
64  snapshot_->Changed(false);
65  }
CVList GetCVs(const std::vector< unsigned int > &mask=std::vector< unsigned int >()) const
Get CV iterator.
Definition: CVManager.h:81
virtual void SyncToEngine()=0
Synchronization to the simulation engine.
class CVManager * cvmanager_
Collective variable manager.
Definition: Hook.h:42
bool HasChanged() const
Query if Snapshot was modified.
Definition: Snapshot.h:590
void Changed(bool state)
Set the "changed" flag of the Snapshot.
Definition: Snapshot.h:596
size_t GetIteration() const
Get the current iteration.
Definition: Snapshot.h:105

References SSAGES::Snapshot::Changed(), cvmanager_, SSAGES::CVManager::GetCVs(), SSAGES::Snapshot::GetIteration(), SSAGES::Snapshot::HasChanged(), listeners_, snapshot_, and SyncToEngine().

Here is the call graph for this function:

◆ PostSimulationHook()

void SSAGES::Hook::PostSimulationHook ( )

Post-simulation hook.

This method should be called by the Hook implementation at the end of the simulation.

Definition at line 67 of file Hook.cpp.

68  {
69  snapshot_->Changed(false);
70 
71  for(auto& cv : cvmanager_->GetCVs())
72  cv->Evaluate(*snapshot_);
73 
74  for(auto& listener : listeners_)
75  listener->PostSimulation(snapshot_, *cvmanager_);
76 
77  if(snapshot_->HasChanged())
78  SyncToEngine();
79 
80  snapshot_->Changed(false);
81  }

References SSAGES::Snapshot::Changed(), cvmanager_, SSAGES::CVManager::GetCVs(), SSAGES::Snapshot::HasChanged(), listeners_, snapshot_, and SyncToEngine().

Here is the call graph for this function:

◆ PostStepHook()

void SSAGES::Hook::PostStepHook ( )
inline

Post-step hook.

This function should be called by the Hook implementation after the integration routine such that the forces, position, velocities, etc.. are done being updated.

Definition at line 116 of file Hook.h.

117  {
118  }

◆ PreSimulationHook()

void SSAGES::Hook::PreSimulationHook ( )

Pre-simulation hook.

This should be called at the appropriate time by the Hook implementation.

Definition at line 30 of file Hook.cpp.

31  {
32  snapshot_->Changed(false);
33  // Initialize/evaluate CVs.
34  for(auto& cv : cvmanager_->GetCVs())
35  {
36  cv->Initialize(*snapshot_);
37  cv->Evaluate(*snapshot_);
38  }
39  // Call presimulation method on listeners.
40  for(auto& listener : listeners_)
41  listener->PreSimulation(snapshot_, *cvmanager_);
42 
43  // Sync snapshot to engine.
44  if(snapshot_->HasChanged())
45  SyncToEngine();
46 
47  snapshot_->Changed(false);
48  }

References SSAGES::Snapshot::Changed(), cvmanager_, SSAGES::CVManager::GetCVs(), SSAGES::Snapshot::HasChanged(), listeners_, snapshot_, and SyncToEngine().

Here is the call graph for this function:

◆ SetCVManager()

void SSAGES::Hook::SetCVManager ( class CVManager cvmanager)

Sets the current CV manager.

Sets the active CV manager.

Parameters
cvmanagerCollective variable manager.

Definition at line 90 of file Hook.cpp.

91  {
92  cvmanager_ = cvmanager;
93  }

References cvmanager_.

Referenced by SSAGES::ResourceHandler::ConfigureHook().

Here is the caller graph for this function:

◆ SetSnapshot()

void SSAGES::Hook::SetSnapshot ( class Snapshot snapshot)

Sets the active snapshot.

Parameters
snapshotCurrent snapshot.

Definition at line 84 of file Hook.cpp.

85  {
86  snapshot_ = snapshot;
87  }

References snapshot_.

Referenced by SSAGES::ResourceHandler::ConfigureHook().

Here is the caller graph for this function:

◆ SyncToEngine()

virtual void SSAGES::Hook::SyncToEngine ( )
protectedpure virtual

Synchronization to the simulation engine.

A Hook must implement this method. It takes data from the snapshot and updates the simulation engine with it.

Referenced by PostIntegrationHook(), PostSimulationHook(), and PreSimulationHook().

Here is the caller graph for this function:

◆ SyncToSnapshot()

virtual void SSAGES::Hook::SyncToSnapshot ( )
protectedpure virtual

Synchronization to the snapshot.

A Hook must implement this method. It takes data from the simulation eingine and updates the snapshot with it.


The documentation for this class was generated from the following files: