From 8ab10ab847dfdf02205d269e46be82a55da141ac Mon Sep 17 00:00:00 2001 From: Gareth Tribello <gareth.tribello@gmail.com> Date: Fri, 29 Jan 2016 15:49:36 +0000 Subject: [PATCH] Small fix to ensure that you can perform multiple actions on a calculated grid --- src/analysis/Histogram.cpp | 1 + src/gridtools/ConvertToFES.cpp | 2 +- src/gridtools/FindContour.cpp | 4 ++-- src/gridtools/GridVessel.cpp | 6 +++++- src/gridtools/GridVessel.h | 2 ++ src/gridtools/PrintCube.cpp | 2 +- src/gridtools/PrintGrid.cpp | 2 +- src/multicolvar/MultiColvarDensity.cpp | 7 +------ 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/analysis/Histogram.cpp b/src/analysis/Histogram.cpp index d2519e7f9..73fde2065 100644 --- a/src/analysis/Histogram.cpp +++ b/src/analysis/Histogram.cpp @@ -208,6 +208,7 @@ void Histogram::performTask( const unsigned& task_index, const unsigned& current } void Histogram::performAnalysis(){ + if( mygrid->wasreset() ) mygrid->clear(); runAllTasks(); mygrid->setNorm( getNormalization() ); } diff --git a/src/gridtools/ConvertToFES.cpp b/src/gridtools/ConvertToFES.cpp index eef7fd498..0d7ce6d8b 100644 --- a/src/gridtools/ConvertToFES.cpp +++ b/src/gridtools/ConvertToFES.cpp @@ -81,7 +81,7 @@ unsigned ConvertToFES::getNumberOfQuantities() const { } void ConvertToFES::performOperationsWithGrid( const bool& from_update ){ - outgrid->clear(); runAllTasks(); + outgrid->clear(); runAllTasks(); outgrid->reset(); } void ConvertToFES::performTask( const unsigned& task_index, const unsigned& current, MultiValue& myvals ) const { diff --git a/src/gridtools/FindContour.cpp b/src/gridtools/FindContour.cpp index ba1238444..889f757e5 100644 --- a/src/gridtools/FindContour.cpp +++ b/src/gridtools/FindContour.cpp @@ -143,7 +143,7 @@ void FindContour::performOperationsWithGrid( const bool& from_update ){ contour_points[npoints].resize( mygrid->getDimension() ); mygrid->getGridPointCoordinates( i, contour_points[npoints] ); // Setup direction vector - direction[j]=0.9999*dx[j]; + direction[j]=0.999999999*dx[j]; // And do proper search for contour point mymin.linesearch( direction, contour_points[npoints], &FindContour::getDifferenceFromContour ); direction[j]=0.0; npoints++; @@ -154,7 +154,7 @@ void FindContour::performOperationsWithGrid( const bool& from_update ){ } // Clear the grid ready for next time - if( from_update ) mygrid->clear(); + if( from_update ) mygrid->reset(); of.printf("%u\n",npoints); of.printf("Points found on isocontour\n"); diff --git a/src/gridtools/GridVessel.cpp b/src/gridtools/GridVessel.cpp index 2b3fb4354..6c3b498b0 100644 --- a/src/gridtools/GridVessel.cpp +++ b/src/gridtools/GridVessel.cpp @@ -266,9 +266,13 @@ void GridVessel::getNeighbors( const std::vector<double>& pp, const std::vector< } } -void GridVessel::clear(){ +void GridVessel::reset(){ if( !nomemory ) return ; wascleared=true; +} + +void GridVessel::clear(){ + plumed_assert( wascleared ); data.assign( data.size(), 0.0 ); } diff --git a/src/gridtools/GridVessel.h b/src/gridtools/GridVessel.h index f18680b18..cdc74eac6 100644 --- a/src/gridtools/GridVessel.h +++ b/src/gridtools/GridVessel.h @@ -135,6 +135,8 @@ public: double getGridExtent( const unsigned& i ) const ; /// Clear all the data stored on the grid virtual void clear(); +/// Reset the grid so that it is cleared at start of next time it is calculated + void reset(); /// This ensures that Gaussian cube fies are in correct units void setCubeUnits( const double& units ); /// This ensures that Gaussian cube files are in correct units diff --git a/src/gridtools/PrintCube.cpp b/src/gridtools/PrintCube.cpp index f4955a9f5..09b216818 100644 --- a/src/gridtools/PrintCube.cpp +++ b/src/gridtools/PrintCube.cpp @@ -90,7 +90,7 @@ void PrintCube::performOperationsWithGrid( const bool& from_update ){ ofile.close(); // Clear the grid ready for next time - if( from_update ) mygrid->clear(); + if( from_update ) mygrid->reset(); } } diff --git a/src/gridtools/PrintGrid.cpp b/src/gridtools/PrintGrid.cpp index a1ab19260..fde163336 100644 --- a/src/gridtools/PrintGrid.cpp +++ b/src/gridtools/PrintGrid.cpp @@ -98,7 +98,7 @@ void PrintGrid::performOperationsWithGrid( const bool& from_update ){ ofile.close(); // Clear the grid ready for next time - if( from_update ) mygrid->clear(); + if( from_update ) mygrid->reset(); } } diff --git a/src/multicolvar/MultiColvarDensity.cpp b/src/multicolvar/MultiColvarDensity.cpp index 9d731faf6..d76188970 100644 --- a/src/multicolvar/MultiColvarDensity.cpp +++ b/src/multicolvar/MultiColvarDensity.cpp @@ -202,12 +202,7 @@ void MultiColvarDensity::update(){ } } for(unsigned i=0;i<directions.size();++i){ Tools::convert(min[i],gmin[i]); Tools::convert(max[i],gmax[i]); } - - if( plumed.getRestart() ){ - error("restarting of MultiColvarDensity is not yet implemented"); - } else { - mygrid->setBounds( gmin, gmax, nbins, gspacing ); resizeFunctions(); - } + mygrid->clear(); mygrid->setBounds( gmin, gmax, nbins, gspacing ); resizeFunctions(); } else { for(unsigned i=0;i<directions.size();++i){ double max; Tools::convert( mygrid->getMax()[i], max ); -- GitLab