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(); } }
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(); }