SSAGES  0.1
A MetaDynamics Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
Hook.cpp
1 
22 #include "Hook.h"
23 #include "Snapshot.h"
24 #include "ResourceHandler.h"
25 #include "CVs/CVManager.h"
26 #include <algorithm>
27 
28 namespace SSAGES
29 {
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  }
51 
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  }
68 
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  }
84 
86  void Hook::SetSnapshot(Snapshot* snapshot)
87  {
88  snapshot_ = snapshot;
89  }
90 
92  void Hook::SetCVManager(CVManager* cvmanager)
93  {
94  cvmanager_ = cvmanager;
95  }
96 
98 
104  {
105  if(std::find(listeners_.begin(), listeners_.end(), listener) == listeners_.end())
106  listeners_.push_back(listener);
107  }
108 }
Base abstract class for listening in to events fired by "Hook".
Definition: EventListener.h:34
Collective variable manager.
Definition: CVManager.h:40
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
Class containing a snapshot of the current simulation in time.
Definition: Snapshot.h:43
virtual void SyncToEngine()=0
Synchronization to the simulation engine.
void PostIntegrationHook()
Post-integration hook.
Definition: Hook.cpp:52
void SetSnapshot(class Snapshot *snapshot)
Sets the active snapshot.
Definition: Hook.cpp:86
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
void PreSimulationHook()
Pre-simulation hook.
Definition: Hook.cpp:30
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
void AddListener(EventListener *listener)
Add a listener to the hook.
Definition: Hook.cpp:103
void SetCVManager(class CVManager *cvmanager)
Sets the current CV manager.
Definition: Hook.cpp:92
void PostSimulationHook()
Post-simulation hook.
Definition: Hook.cpp:69