LCOV - code coverage report
Current view: top level - multicolvar - BridgedMultiColvarFunction.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 53 57 93.0 %
Date: 2020-11-18 11:20:57 Functions: 11 13 84.6 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2014-2019 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 "BridgedMultiColvarFunction.h"
      23             : #include "core/PlumedMain.h"
      24             : #include "core/ActionSet.h"
      25             : #include "CatomPack.h"
      26             : 
      27             : namespace PLMD {
      28             : namespace multicolvar {
      29             : 
      30          57 : void BridgedMultiColvarFunction::registerKeywords( Keywords& keys ) {
      31          57 :   MultiColvarBase::registerKeywords( keys );
      32         228 :   keys.add("compulsory","DATA","The multicolvar that calculates the set of base quantities that we are interested in");
      33          57 : }
      34             : 
      35          44 : BridgedMultiColvarFunction::BridgedMultiColvarFunction(const ActionOptions&ao):
      36             :   Action(ao),
      37          44 :   MultiColvarBase(ao)
      38             : {
      39          88 :   std::string mlab; parse("DATA",mlab);
      40          88 :   mycolv = plumed.getActionSet().selectWithLabel<MultiColvarBase*>(mlab);
      41          44 :   if(!mycolv) error("action labeled " + mlab + " does not exist or is not a multicolvar");
      42             : 
      43             :   // When using numerical derivatives here we must use numerical derivatives
      44             :   // in base multicolvar
      45          44 :   if( checkNumericalDerivatives() ) mycolv->useNumericalDerivatives();
      46             : 
      47          44 :   myBridgeVessel = mycolv->addBridgingVessel( this ); addDependency(mycolv);
      48          44 :   weightHasDerivatives=true; usespecies=mycolv->usespecies;
      49             :   // Number of tasks is the same as the number in the underlying MultiColvar
      50       60136 :   for(unsigned i=0; i<mycolv->getFullNumberOfTasks(); ++i) addTaskToList( mycolv->getTaskCode(i) );
      51          44 : }
      52             : 
      53          45 : void BridgedMultiColvarFunction::turnOnDerivatives() {
      54          45 :   BridgedMultiColvarFunction* check = dynamic_cast<BridgedMultiColvarFunction*>( mycolv );
      55          45 :   if( check ) {
      56           0 :     if( check->getNumberOfAtoms()>0 ) error("cannot calculate required derivatives of this quantity");
      57             :   }
      58          45 :   MultiColvarBase::turnOnDerivatives();
      59          45 : }
      60             : 
      61      100985 : void BridgedMultiColvarFunction::transformBridgedDerivatives( const unsigned& current, MultiValue& invals, MultiValue& outvals ) const {
      62      100985 :   completeTask( current, invals, outvals );
      63             : 
      64             :   // Now update the outvals derivatives lists
      65      100985 :   if( derivativesAreRequired() ) {
      66             :     outvals.emptyActiveMembers();
      67       94076 :     if( mycolv->isDensity() ) {
      68      303940 :       for(unsigned j=0; j<3; ++j) outvals.putIndexInActiveArray( 3*current+j );
      69      868400 :       for(unsigned j=invals.getNumberOfDerivatives()-9; j<invals.getNumberOfDerivatives(); ++j) outvals.putIndexInActiveArray(j);
      70             :     } else {
      71    11198443 :       for(unsigned j=0; j<invals.getNumberActive(); ++j) outvals.putIndexInActiveArray( invals.getActiveIndex(j) );
      72             :     }
      73      684862 :     for(unsigned j=invals.getNumberOfDerivatives(); j<outvals.getNumberOfDerivatives(); ++j) outvals.putIndexInActiveArray( j );
      74             :     outvals.completeUpdate();
      75             :   }
      76      100985 : }
      77             : 
      78       13042 : void BridgedMultiColvarFunction::performTask( const unsigned& taskIndex, const unsigned& current, MultiValue& myvals ) const {
      79             :   // This allows us to speed up the code as we don't need to reallocate memory on every call of perform task
      80       13042 :   MultiValue& invals=myBridgeVessel->getTemporyMultiValue();
      81       26080 :   if( invals.getNumberOfValues()!=mycolv->getNumberOfQuantities() ||
      82       13038 :       invals.getNumberOfDerivatives()!=mycolv->getNumberOfDerivatives() ) {
      83           4 :     invals.resize( mycolv->getNumberOfQuantities(), mycolv->getNumberOfDerivatives() );
      84             :   }
      85       13042 :   invals.clearAll(); mycolv->performTask( taskIndex, current, invals );
      86       13042 :   transformBridgedDerivatives( taskIndex, invals, myvals );
      87       13042 : }
      88             : 
      89          60 : void BridgedMultiColvarFunction::calculateNumericalDerivatives( ActionWithValue* a ) {
      90          60 :   if(!a) {
      91          60 :     a=dynamic_cast<ActionWithValue*>(this);
      92          60 :     plumed_massert(a,"cannot compute numerical derivatives for an action without values");
      93             :   }
      94          60 :   if( myBridgeVessel ) {
      95          60 :     myBridgeVessel->completeNumericalDerivatives();
      96             :   } else {
      97           0 :     error("numerical derivatives are not implemented");
      98             :   }
      99          60 : }
     100             : 
     101          21 : void BridgedMultiColvarFunction::applyBridgeForces( const std::vector<double>& bb ) {
     102          21 :   if( getNumberOfAtoms()==0 ) return ;
     103             : 
     104             :   std::vector<Vector>& f( modifyForces() );
     105          63 :   for(unsigned i=0; i<getNumberOfAtoms(); ++i) {
     106         147 :     f[i][0]+=bb[3*i+0]; f[i][1]+=bb[3*i+1]; f[i][2]+=bb[3*i+2];
     107             :   }
     108          21 :   applyForces();
     109             : }
     110             : 
     111          34 : bool BridgedMultiColvarFunction::isPeriodic() {
     112          34 :   return mycolv->isPeriodic();
     113             : }
     114             : 
     115           0 : void BridgedMultiColvarFunction::deactivate_task( const unsigned& taskno ) {
     116           0 :   plumed_merror("This should never be called");
     117             : }
     118             : 
     119       11462 : void BridgedMultiColvarFunction::getCentralAtomPack( const unsigned& basn, const unsigned& curr, CatomPack& mypack ) {
     120       11462 :   return mycolv->getCentralAtomPack( basn, curr, mypack );
     121             : }
     122             : 
     123             : }
     124        4839 : }

Generated by: LCOV version 1.13