From 29eb66052f7a70998217c8fe99b2afdabcd125e1 Mon Sep 17 00:00:00 2001
From: Gareth Tribello <gareth.tribello@gmail.com>
Date: Fri, 15 Mar 2013 12:14:46 +0100
Subject: [PATCH] Made StoreCentralAtoms class slightly faster.  Only slightly
 though

---
 src/multicolvar/StoreCentralAtomsVessel.cpp | 10 +++++++---
 src/multicolvar/StoreCentralAtomsVessel.h   |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/multicolvar/StoreCentralAtomsVessel.cpp b/src/multicolvar/StoreCentralAtomsVessel.cpp
index 1223fa950..0581240e1 100644
--- a/src/multicolvar/StoreCentralAtomsVessel.cpp
+++ b/src/multicolvar/StoreCentralAtomsVessel.cpp
@@ -99,11 +99,15 @@ void StoreCentralAtomsVessel::chainRuleForCentralAtom( const unsigned& iatom, co
   unsigned nder=3*mycolv->colvar_atoms[iatom].getNumberActive();
   unsigned nder2=mycolv->getNumberOfDerivatives();
   for(unsigned ider=0;ider<nder;++ider){
-      unsigned jder = iderno*nder2 + mycolv->getOutputDerivativeIndex( iatom, ider );
+      unsigned ibuf=start[iatom] + 1 + ider; double thisder=0.0;
       for(unsigned jcomp=0;jcomp<3;++jcomp){
-          unsigned ibuf=start[iatom] + jcomp*(nder+1) + 1 + ider;
-          act->addElementDerivative( jder, df[jcomp]*getBufferElement(ibuf) );
+          thisder+=df[jcomp]*getBufferElement(ibuf);
+          ibuf+=(nder+1);
+          //unsigned ibuf=start[iatom] + jcomp*(nder+1) + 1 + ider;
+          //act->addElementDerivative( jder, df[jcomp]*getBufferElement(ibuf) );
       }
+      unsigned jder = iderno*nder2 + mycolv->getOutputDerivativeIndex( iatom, ider );
+      act->addElementDerivative( jder, thisder );
   }
 }
  
diff --git a/src/multicolvar/StoreCentralAtomsVessel.h b/src/multicolvar/StoreCentralAtomsVessel.h
index a729c431d..c7651b913 100644
--- a/src/multicolvar/StoreCentralAtomsVessel.h
+++ b/src/multicolvar/StoreCentralAtomsVessel.h
@@ -44,7 +44,7 @@ public:
 /// This does the resizing of the buffer
   void resize();
 /// This does nothing
-  std::string description(){ return""; }
+  std::string description(){ return ""; }
 /// This does nothing
   void finish(){}
 /// Add some force to the atoms
-- 
GitLab