SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
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  // 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  }
49 
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  }
66 
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  }
82 
84  void Hook::SetSnapshot(Snapshot* snapshot)
85  {
86  snapshot_ = snapshot;
87  }
88 
90  void Hook::SetCVManager(CVManager* cvmanager)
91  {
92  cvmanager_ = cvmanager;
93  }
94 
96 
102  {
103  if(std::find(listeners_.begin(), listeners_.end(), listener) == listeners_.end())
104  listeners_.push_back(listener);
105  }
106 }
Collective variable manager.
Definition: CVManager.h:43
CVList GetCVs(const std::vector< unsigned int > &mask=std::vector< unsigned int >()) const
Get CV iterator.
Definition: CVManager.h:81
Base abstract class for listening in to events fired by "Hook".
Definition: EventListener.h:36
virtual void SyncToEngine()=0
Synchronization to the simulation engine.
void SetCVManager(class CVManager *cvmanager)
Sets the current CV manager.
Definition: Hook.cpp:90
std::vector< EventListener * > listeners_
Vector of event listeners.
Definition: Hook.h:39
class Snapshot * snapshot_
Local snapshot.
Definition: Hook.h:46
void PostSimulationHook()
Post-simulation hook.
Definition: Hook.cpp:67
class CVManager * cvmanager_
Collective variable manager.
Definition: Hook.h:42
void AddListener(EventListener *listener)
Add a listener to the hook.
Definition: Hook.cpp:101
void SetSnapshot(class Snapshot *snapshot)
Sets the active snapshot.
Definition: Hook.cpp:84
void PostIntegrationHook()
Post-integration hook.
Definition: Hook.cpp:50
void PreSimulationHook()
Pre-simulation hook.
Definition: Hook.cpp:30
Class containing a snapshot of the current simulation in time.
Definition: Snapshot.h:48
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