LCOV - code coverage report
Current view: top level - multicolvar - VolumeGradientBase.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 44 56 78.6 %
Date: 2018-12-19 07:49:13 Functions: 8 10 80.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2014-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 "VolumeGradientBase.h"
      23             : #include "CatomPack.h"
      24             : 
      25             : namespace PLMD {
      26             : namespace multicolvar {
      27             : 
      28          35 : void VolumeGradientBase::registerKeywords( Keywords& keys ) {
      29          35 :   BridgedMultiColvarFunction::registerKeywords( keys );
      30          35 : }
      31             : 
      32          29 : VolumeGradientBase::VolumeGradientBase(const ActionOptions&ao):
      33             :   Action(ao),
      34          29 :   BridgedMultiColvarFunction(ao)
      35             : {
      36          29 : }
      37             : 
      38          29 : void VolumeGradientBase::requestAtoms( const std::vector<AtomNumber>& atoms ) {
      39          29 :   ActionAtomistic::requestAtoms(atoms); bridgeVariable=3*atoms.size();
      40          29 :   addDependency( getPntrToMultiColvar() );
      41          29 :   tmpforces.resize( 3*atoms.size()+9 );
      42          29 : }
      43             : 
      44        2218 : void VolumeGradientBase::doJobsRequiredBeforeTaskList() {
      45        2218 :   ActionWithValue::clearDerivatives();
      46        2218 :   retrieveAtoms(); setupRegions();
      47        2218 :   ActionWithVessel::doJobsRequiredBeforeTaskList();
      48        2218 : }
      49             : 
      50       80527 : void VolumeGradientBase::completeTask( const unsigned& curr, MultiValue& invals, MultiValue& outvals ) const {
      51       80527 :   if( getPntrToMultiColvar()->isDensity() ) {
      52       43404 :     outvals.setValue(0, 1.0); outvals.setValue(1, 1.0);
      53             :   } else {
      54             :     // Copy derivatives of the colvar and the value of the colvar
      55       37158 :     invals.copyValues( outvals );
      56       37162 :     if( derivativesAreRequired() ) invals.copyDerivatives( outvals );
      57             :   }
      58       80562 :   calculateAllVolumes( curr, outvals );
      59       80553 : }
      60             : 
      61      115292 : void VolumeGradientBase::setNumberInVolume( const unsigned& ivol, const unsigned& curr, const double& weight,
      62             :     const Vector& wdf, const Tensor& virial, const std::vector<Vector>& refders,
      63             :     MultiValue& outvals ) const {
      64      115292 :   MultiColvarBase* mcolv=getPntrToMultiColvar();
      65      115355 :   if( !mcolv->weightHasDerivatives ) {
      66      115355 :     outvals.setValue(ivol, weight );
      67      115356 :     if( derivativesAreRequired() ) {
      68      112284 :       CatomPack catom( mcolv->getCentralAtomPack( 0, curr ) );
      69      252569 :       for(unsigned i=0; i<catom.getNumberOfAtomsWithDerivatives(); ++i) {
      70      140233 :         unsigned jatom=3*catom.getIndex(i);
      71      140294 :         outvals.addDerivative( ivol, jatom+0, catom.getDerivative(i,0,wdf) );
      72      140278 :         outvals.addDerivative( ivol, jatom+1, catom.getDerivative(i,1,wdf) );
      73      140324 :         outvals.addDerivative( ivol, jatom+2, catom.getDerivative(i,2,wdf) );
      74             :       }
      75      112339 :       unsigned nmder=getPntrToMultiColvar()->getNumberOfDerivatives();
      76      112381 :       for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) outvals.addDerivative( ivol, nmder-9+3*i+j, virial(i,j) );
      77      229486 :       for(unsigned i=0; i<refders.size(); ++i) {
      78      117108 :         unsigned iatom=nmder+3*i;
      79             : 
      80      117108 :         outvals.addDerivative( ivol, iatom+0, refders[i][0] );
      81      117166 :         outvals.addDerivative( ivol, iatom+1, refders[i][1] );
      82      117186 :         outvals.addDerivative( ivol, iatom+2, refders[i][2] );
      83      112329 :       }
      84             :     }
      85           0 :   } else if(ivol==0) {
      86           0 :     double ww=outvals.get(0); outvals.setValue(ivol,ww*weight);
      87           0 :     if( derivativesAreRequired() ) {
      88           0 :       plumed_merror("This needs testing");
      89             :       CatomPack catom( mcolv->getCentralAtomPack( 0, curr ) );
      90             :       for(unsigned i=0; i<catom.getNumberOfAtomsWithDerivatives(); ++i) {
      91             :         unsigned jatom=3*catom.getIndex(i);
      92             :         outvals.addDerivative( ivol, jatom+0, weight*outvals.getDerivative(ivol,jatom+0) + ww*catom.getDerivative(i,0,wdf) );
      93             :         outvals.addDerivative( ivol, jatom+1, weight*outvals.getDerivative(ivol,jatom+1) + ww*catom.getDerivative(i,1,wdf) );
      94             :         outvals.addDerivative( ivol, jatom+2, weight*outvals.getDerivative(ivol,jatom+2) + ww*catom.getDerivative(i,2,wdf) );
      95             :       }
      96             :       unsigned nmder=getPntrToMultiColvar()->getNumberOfDerivatives();
      97             :       for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) outvals.addDerivative( ivol, nmder-9+3*i+j, ww*virial(i,j) );
      98             :       for(unsigned i=0; i<refders.size(); ++i) {
      99             :         unsigned iatom=nmder+3*i;
     100             :         outvals.addDerivative( ivol, iatom+0, ww*refders[i][0] );
     101             :         outvals.addDerivative( ivol, iatom+1, ww*refders[i][1] );
     102             :         outvals.addDerivative( ivol, iatom+2, ww*refders[i][2] );
     103             :       }
     104             :     }
     105             :   } else {
     106           0 :     double ww=outvals.get(0); outvals.setValue(ivol,ww*weight);
     107           0 :     if( derivativesAreRequired() ) {
     108           0 :       plumed_merror("This needs testing");
     109             :       CatomPack catom( mcolv->getCentralAtomPack( 0, curr ) );
     110             :       for(unsigned i=0; i<catom.getNumberOfAtomsWithDerivatives(); ++i) {
     111             :         unsigned jatom=3*catom.getIndex(i);
     112             :         outvals.addDerivative( ivol, jatom+0, ww*catom.getDerivative(i,0,wdf) );
     113             :         outvals.addDerivative( ivol, jatom+1, ww*catom.getDerivative(i,1,wdf) );
     114             :         outvals.addDerivative( ivol, jatom+2, ww*catom.getDerivative(i,2,wdf) );
     115             :       }
     116             :       unsigned nmder=getPntrToMultiColvar()->getNumberOfDerivatives();
     117             :       for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) outvals.addDerivative( ivol, nmder-9+3*i+j, ww*virial(i,j) );
     118             :       for(unsigned i=0; i<refders.size(); ++i) {
     119             :         unsigned iatom=nmder+3*i;
     120             :         outvals.addDerivative( ivol, iatom+0, ww*refders[i][0] );
     121             :         outvals.addDerivative( ivol, iatom+1, ww*refders[i][1] );
     122             :         outvals.addDerivative( ivol, iatom+2, ww*refders[i][2] );
     123             :       }
     124             :     }
     125             :   }
     126      115353 : }
     127             : 
     128           0 : void VolumeGradientBase::addBridgeForces( const std::vector<double>& bb ) {
     129             :   plumed_dbg_assert( bb.size()==tmpforces.size()-9 );
     130             :   // Forces on local atoms
     131           0 :   for(unsigned i=0; i<bb.size(); ++i) tmpforces[i]=bb[i];
     132             :   // Virial contribution is zero
     133           0 :   for(unsigned i=bb.size(); i<bb.size()+9; ++i) tmpforces[i]=0.0;
     134           0 :   setForcesOnAtoms( tmpforces, 0 );
     135           0 : }
     136             : 
     137             : }
     138        2523 : }

Generated by: LCOV version 1.13