SSAGES  0.1
A MetaDynamics Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
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.

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

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 103 of file Hook.cpp.

References listeners_.

104  {
105  if(std::find(listeners_.begin(), listeners_.end(), listener) == listeners_.end())
106  listeners_.push_back(listener);
107  }
std::vector< EventListener * > listeners_
Vector of event listeners.
Definition: Hook.h:39
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 52 of file Hook.cpp.

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

53  {
54  snapshot_->Changed(false);
55 
56  for(auto& cv : cvmanager_->GetCVs())
57  cv->Evaluate(*snapshot_);
58 
59  for(auto& listener : listeners_)
60  if(snapshot_->GetIteration() % listener->GetFrequency() == 0)
61  listener->PostIntegration(snapshot_, *cvmanager_);
62 
63  if(snapshot_->HasChanged())
64  SyncToEngine();
65 
66  snapshot_->Changed(false);
67  }
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:

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 69 of file Hook.cpp.

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

70  {
71  snapshot_->Changed(false);
72 
73  for(auto& cv : cvmanager_->GetCVs())
74  cv->Evaluate(*snapshot_);
75 
76  for(auto& listener : listeners_)
77  listener->PostSimulation(snapshot_, *cvmanager_);
78 
79  if(snapshot_->HasChanged())
80  SyncToEngine();
81 
82  snapshot_->Changed(false);
83  }
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:

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.

111  {
112  }
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().

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

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

Sets the current CV manager.

Sets the active CV manager.

Definition at line 92 of file Hook.cpp.

References cvmanager_.

93  {
94  cvmanager_ = cvmanager;
95  }
class CVManager * cvmanager_
Collective variable manager.
Definition: Hook.h:42
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: