Skip to content
Snippets Groups Projects
Commit c7de80a0 authored by Gareth Tribello's avatar Gareth Tribello
Browse files

Added functionality to stop plumed and the MD code from an action

parent 349a6db5
No related branches found
No related tags found
No related merge requests found
......@@ -62,7 +62,9 @@ PlumedMain::PlumedMain():
bias(0.0),
exchangePatterns(*new(ExchangePatterns)),
novirial(false),
restart(false)
restart(false),
stopFlag(NULL),
stopNow(false)
{
log.link(comm);
log.setLinePrefix("PLUMED: ");
......@@ -271,6 +273,10 @@ void PlumedMain::cmd(const std::string & word,void*val){
CHECK_NOTINIT(initialized,word);
CHECK_NULL(val,word);
log.open(static_cast<char*>(val),"w");
} else if(word=="setStopFlag"){
CHECK_NOTINIT(initialized,word);
CHECK_NULL(val,word);
stopFlag=static_cast<int*>(val);
} else if(word=="getExchangesFlag"){
CHECK_INIT(initialized,word);
CHECK_NULL(val,word);
......@@ -535,6 +541,11 @@ void PlumedMain::justApply(){
for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){
if((*p)->isActive()) (*p)->update();
}
// Check that no action has told the calculation to stop
if(stopNow){
if(stopFlag) (*stopFlag)=1;
else plumed_merror("your md code cannot handle plumed stop events - add a call to plumed.comm(stopFlag,stopCondition)");
}
stopwatch.stop("5 Applying (backward loop)");
}
......@@ -608,6 +619,9 @@ void PlumedMain::eraseFile(PlumedFileBase&f){
files.erase(&f);
}
void PlumedMain::stop(){
stopNow=true;
}
......
......@@ -129,6 +129,10 @@ private:
std::set<PlumedFileBase*> files;
typedef std::set<PlumedFileBase*>::iterator files_iterator;
/// Stuff to make plumed stop the MD code cleanly
int* stopFlag;
bool stopNow;
public:
/// Flag to switch off virial calculation (for debug)
bool novirial;
......@@ -237,6 +241,8 @@ public:
void fflush();
/// Check if restarting
bool getRestart()const;
/// Stop the calculation cleanly (both the MD code and plumed)
void stop();
};
/////
......
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