Skip to content
Snippets Groups Projects
Commit a67412c2 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Added preparation step for Actions

New virtual method for Actions which is called at steps when action is
active just before atoms sharing. This is the right place where Actions
can change their atom requirements. E.g., you can do

class ColvarSomething{
...
void prepare();
}

void ColvarSomething::prepare(){
// take here your decision and eventually change the requested atoms
}
parent 451af3c9
No related branches found
No related tags found
No related merge requests found
......@@ -109,6 +109,11 @@ void Action::calculateNumericalDerivatives(){
assert(0);
}
void Action::prepare(){
return;
}
......@@ -107,6 +107,13 @@ public:
PlumedCommunicator& comm;
/// Prepare an Action for calculation
/// This can be used by Action if they need some special preparation
/// before calculation. Typical case is for collective variables
/// which would like to change their list of requested atoms.
/// By default (if not overridden) does nothing.
virtual void prepare();
/// Calculate an Action.
/// This method is called one or more times per step.
/// The set of all Actions is calculated in forward order.
......@@ -114,7 +121,7 @@ public:
/// Apply an Action.
/// This method is called one time per step.
/// The set of all Actions is applied in backword order.
/// The set of all Actions is applied in backward order.
virtual void apply()=0;
/// Tell to the Action to flush open files
......
......@@ -373,8 +373,6 @@ void PlumedMain::prepareDependencies(){
atoms.setCollectEnergy(false);
// activate all the actions which are on step
// activation is recursive and enables also the dependencies
for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();p++){
(*p)->deactivate();
if(Colvar *c=dynamic_cast<Colvar*>(*p)) {
......@@ -382,13 +380,19 @@ void PlumedMain::prepareDependencies(){
}
}
// activate all the actions which are on step
// activation is recursive and enables also the dependencies
for(unsigned i=0;i<pilots.size();++i){
if(pilots[i]->onStep()){
pilots[i]->activate();
active=true;
}
};
}
// allow actions to update their request list before atoms are shared
for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();p++)
if((*p)->isActive()) (*p)->prepare();
}
void PlumedMain::shareData(){
if(active)atoms.share();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment