LCOV - code coverage report
Current view: top level - crystallization - VectorMultiColvar.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 39 48 81.2 %
Date: 2018-12-19 07:49:13 Functions: 8 11 72.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-2018 The plumed team
       3             :    (see the PEOPLE file at the root of the distribution for a list of names)
       4             : 
       5             :    See http://www.plumed.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       8             : 
       9             :    plumed is free software: you can redistribute it and/or modify
      10             :    it under the terms of the GNU Lesser General Public License as published by
      11             :    the Free Software Foundation, either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    plumed is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU Lesser General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU Lesser General Public License
      20             :    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : #include "VectorMultiColvar.h"
      23             : #include "multicolvar/MultiColvarFunction.h"
      24             : #include "multicolvar/BridgedMultiColvarFunction.h"
      25             : 
      26             : namespace PLMD {
      27             : namespace crystallization {
      28             : 
      29          26 : void VectorMultiColvar::registerKeywords( Keywords& keys ) {
      30          26 :   MultiColvar::registerKeywords( keys );
      31          26 : }
      32             : 
      33          21 : VectorMultiColvar::VectorMultiColvar(const ActionOptions& ao):
      34             :   PLUMED_MULTICOLVAR_INIT(ao),
      35          21 :   store_director(true)
      36             : {
      37          21 :   setLowMemOption(true);
      38          21 : }
      39             : 
      40          21 : void VectorMultiColvar::setVectorDimensionality( const unsigned& ncomp ) {
      41          21 :   ncomponents = ncomp; resizeFunctions(); // This resize needs to be here to ensure buffers are set to correct size in base
      42          21 : }
      43             : 
      44           0 : void VectorMultiColvar::doNotCalculateDirector() {
      45           0 :   store_director=false;    // Need a sanity check in here  so that you don't use the same instance of Q4 to calcualte vectors and directors
      46           0 : }
      47             : 
      48       95438 : double VectorMultiColvar::doCalculation( const unsigned& taskIndex, multicolvar::AtomValuePack& myatoms ) const {
      49             :   // Now calculate the vector
      50       95438 :   calculateVector( myatoms );
      51             :   // Sort out the active derivatives
      52       95460 :   updateActiveAtoms( myatoms );
      53             : 
      54             :   // Now calculate the norm of the vector (this is what we return here)
      55       95416 :   double norm=0;
      56       95416 :   for(unsigned i=0; i<ncomponents; ++i) norm += myatoms.getValue(2+i)*myatoms.getValue(2+i);
      57       95450 :   norm=sqrt(norm);
      58             : 
      59       95450 :   if( !doNotCalculateDerivatives() ) {
      60       66198 :     double inorm = 1.0 / norm; std::vector<double> dervec( ncomponents );
      61       66247 :     for(unsigned i=0; i<ncomponents; ++i) dervec[i] = inorm*myatoms.getValue(2+i);
      62             : 
      63       66202 :     MultiValue& myvals=myatoms.getUnderlyingMultiValue();
      64     7455103 :     for(unsigned j=0; j<myvals.getNumberActive(); ++j) {
      65     7388287 :       unsigned jder=myvals.getActiveIndex(j);
      66     7394659 :       for(unsigned i=0; i<ncomponents; ++i) myvals.addDerivative( 1, jder, dervec[i]*myvals.getDerivative( 2+i, jder ) );
      67       66173 :     }
      68             :   }
      69             : 
      70       95466 :   return norm;
      71             : }
      72             : 
      73       63312 : void VectorMultiColvar::normalizeVector( std::vector<double>& vals ) const {
      74       63312 :   double inorm = 1.0;
      75       63312 :   if( vals[1]>epsilon ) inorm = 1.0 / vals[1];
      76       63312 :   for(unsigned i=2; i<vals.size(); ++i) vals[i] = inorm*vals[i];
      77       63312 : }
      78             : 
      79       28441 : void VectorMultiColvar::normalizeVectorDerivatives( MultiValue& myvals ) const {
      80       28441 :   double v = myvals.get(1), weight = 1.0 / v,  wdf = 1.0 / ( v*v*v );
      81     3556933 :   for(unsigned j=0; j<myvals.getNumberActive(); ++j) {
      82     3528492 :     double comp2=0.0; unsigned jder=myvals.getActiveIndex(j);
      83     3528492 :     for(unsigned jcomp=2; jcomp<myvals.getNumberOfValues(); ++jcomp) comp2 += myvals.get(jcomp)*myvals.getDerivative( jcomp, jder );
      84    85772772 :     for(unsigned jcomp=2; jcomp<myvals.getNumberOfValues(); ++jcomp) {
      85    82244280 :       myvals.setDerivative( jcomp, jder, weight*myvals.getDerivative( jcomp, jder ) - wdf*comp2*myvals.get(jcomp) );
      86             :     }
      87             :   }
      88       28441 : }
      89             : 
      90           0 : void VectorMultiColvar::addForcesOnAtoms( const std::vector<double>& inforces ) {
      91             :   plumed_dbg_assert( inforces.size()==getNumberOfDerivatives() );
      92           0 :   std::vector<double> oldforces( getNumberOfDerivatives() );
      93           0 :   getForcesFromVessels( oldforces );
      94           0 :   for(unsigned i=0; i<getNumberOfDerivatives(); ++i) oldforces[i]+=inforces[i];
      95           0 :   setForcesOnAtoms( oldforces );
      96           0 : }
      97             : 
      98             : }
      99        2523 : }

Generated by: LCOV version 1.13