SSAGES  0.1
A MetaDynamics Package
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.
 
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

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.

References AddListener(), NotifyObservers(), PostIntegrationHook(), PreSimulationHook(), SetCVManager(), and SetSnapshot().

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

Here is the call graph for this function:

Member Function Documentation

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.

References listeners_.

Referenced by Hook(), and SSAGES::ResourceHandler::ResourceHandler().

102  {
103  if(std::find(listeners_.begin(), listeners_.end(), listener) == listeners_.end())
104  listeners_.push_back(listener);
105  }
std::vector< EventListener * > listeners_
Vector of event listeners.
Definition: Hook.h:39

Here is the caller graph for this function:

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.

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

Referenced by Hook().

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  }
int GetIteration() const
Get the current iteration.
Definition: Snapshot.h:103
void Changed(bool state)
Set the "changed" flag of the Snapshot.
Definition: Snapshot.h:645
virtual void SyncToEngine()=0
Synchronization to the simulation engine.
bool HasChanged() const
Query if Snapshot was modified.
Definition: Snapshot.h:639
class Snapshot * snapshot_
Local snapshot.
Definition: Hook.h:46
std::vector< EventListener * > listeners_
Vector of event listeners.
Definition: Hook.h:39
std::vector< CollectiveVariable * > GetCVs(const std::vector< uint > &mask=std::vector< uint >()) const
Get CV iterator.
Definition: CVManager.h:80
class CVManager * cvmanager_
Collective variable manager.
Definition: Hook.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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

Referenced by PostStepHook().

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  }
void Changed(bool state)
Set the "changed" flag of the Snapshot.
Definition: Snapshot.h:645
virtual void SyncToEngine()=0
Synchronization to the simulation engine.
bool HasChanged() const
Query if Snapshot was modified.
Definition: Snapshot.h:639
class Snapshot * snapshot_
Local snapshot.
Definition: Hook.h:46
std::vector< EventListener * > listeners_
Vector of event listeners.
Definition: Hook.h:39
std::vector< CollectiveVariable * > GetCVs(const std::vector< uint > &mask=std::vector< uint >()) const
Get CV iterator.
Definition: CVManager.h:80
class CVManager * cvmanager_
Collective variable manager.
Definition: Hook.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

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 110 of file Hook.h.

References PostSimulationHook().

111  {
112  }

Here is the call graph for this function:

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.

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

Referenced by Hook().

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  }
void Changed(bool state)
Set the "changed" flag of the Snapshot.
Definition: Snapshot.h:645
virtual void SyncToEngine()=0
Synchronization to the simulation engine.
bool HasChanged() const
Query if Snapshot was modified.
Definition: Snapshot.h:639
class Snapshot * snapshot_
Local snapshot.
Definition: Hook.h:46
std::vector< EventListener * > listeners_
Vector of event listeners.
Definition: Hook.h:39
std::vector< CollectiveVariable * > GetCVs(const std::vector< uint > &mask=std::vector< uint >()) const
Get CV iterator.
Definition: CVManager.h:80
class CVManager * cvmanager_
Collective variable manager.
Definition: Hook.h:42

Here is the call graph for this function:

Here is the caller graph for this function:

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

Sets the current CV manager.

Sets the active CV manager.

Definition at line 90 of file Hook.cpp.

References cvmanager_.

Referenced by Hook(), and SSAGES::ResourceHandler::ResourceHandler().

91  {
92  cvmanager_ = cvmanager;
93  }
class CVManager * cvmanager_
Collective variable manager.
Definition: Hook.h:42

Here is the caller graph for this function:

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:

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: