Exemplo n.º 1
0
void Histogram::apply() {
  if( !myhist->wasForced() ) return ;
  in_apply=true;
  // Run the loop to calculate the forces
  runAllTasks(); finishAveraging();
  // We now need to retrieve the buffer and set the forces on the atoms
  myhist->applyForce( forcesToApply );
  // Now make the forces make sense for the virial
  unsigned fbase=0, tbase=0, vbase = getNumberOfDerivatives() - myvessels.size()*9;
  for(unsigned i=vbase; i<vbase+9; ++i) finalForces[i]=0.0;
  for(unsigned i=0; i<myvessels.size(); ++i) {
    for(unsigned j=0; j<myvessels[i]->getNumberOfDerivatives()-9; ++j) {
      finalForces[fbase + j] = forcesToApply[tbase + j];
    }
    unsigned k=0;
    for(unsigned j=myvessels[i]->getNumberOfDerivatives()-9; j<myvessels[i]->getNumberOfDerivatives(); ++j) {
      finalForces[vbase + k] += forcesToApply[tbase + j]; k++;
    }
    fbase += myvessels[i]->getNumberOfDerivatives() - 9;
    tbase += myvessels[i]->getNumberOfDerivatives();
  }
  // And set the final forces on the atoms
  setForcesOnAtoms( finalForces );
  // Reset everything for next regular loop
  in_apply=false;
}
Exemplo n.º 2
0
void ActionWithAveraging::update() {
  if( (clearstride!=1 && getStep()==0) || !onStep() ) return;
  // Clear if it is time to reset
  if( myaverage ) {
    if( myaverage->wasreset() ) clearAverage();
  }
  // Calculate the weight for all reweighting
  if ( weights.size()>0 ) {
    double sum=0; for(unsigned i=0; i<weights.size(); ++i) sum+=weights[i]->get();
    lweight=sum; cweight = exp( sum );
  } else {
    lweight=0; cweight=1.0;
  }
  // Prepare to do the averaging
  prepareForAveraging();
  // Run all the tasks (if required
  if( useRunAllTasks ) runAllTasks();
  // This the averaging if it is not done using task list
  else performOperations( true );
  // Update the norm
  if( myaverage ) myaverage->setNorm( cweight + myaverage->getNorm() );
  // Finish the averaging
  finishAveraging();
  // By resetting here we are ensuring that the grid will be cleared at the start of the next step
  if( myaverage ) {
    if( getStride()==0 || (clearstride>0 && getStep()%clearstride==0) ) myaverage->reset();
  }
}
Exemplo n.º 3
0
void ActionWithGrid::calculate(){
  // Do nothing if derivatives are not required
  if( doNotCalculateDerivatives() ) return;
  // Clear on every step
  if( mygrid ) clearAverage();
  // Should not be any reweighting so just set these accordingly
  lweight=0; cweight=1.0;
  // Prepare to do the averaging
  prepareForAveraging();
  // Run all the tasks (if required
  if( useRunAllTasks ) runAllTasks();
  // This the averaging if it is not done using task list
  else performOperations( true );
  // Update the norm
  if( mygrid ) mygrid->setNorm( cweight );
  // Finish the averaging
  finishAveraging();
  // And reset for next step
  if( mygrid ) mygrid->reset();
}