LCOV - code coverage report
Current view: top level - vesselbase - ValueVessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 35 35 100.0 %
Date: 2018-12-19 07:49:13 Functions: 7 8 87.5 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-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 "ValueVessel.h"
      23             : 
      24             : namespace PLMD {
      25             : namespace vesselbase {
      26             : 
      27         286 : void ValueVessel::registerKeywords( Keywords& keys ) {
      28         286 :   Vessel::registerKeywords( keys );
      29         286 :   keys.add("compulsory","COMPONENT","1","The component we are using in the functions");
      30         286 : }
      31             : 
      32         286 : ValueVessel::ValueVessel( const VesselOptions& da ):
      33             :   Vessel(da),
      34         286 :   no_output_value(false)
      35             : {
      36         286 :   parse("COMPONENT",mycomp);
      37         286 :   ActionWithValue* a=dynamic_cast<ActionWithValue*>( getAction() );
      38         286 :   plumed_massert(a,"cannot create passable values as base action does not inherit from ActionWithValue");
      39         286 :   int numval = getNumericalLabel();
      40         286 :   if( numval<0 && a->getNumberOfComponents()==0 ) {  // This allows us to make multicolvars pretend to be colvars - this is used in AlphaRMSD etc
      41          34 :     a->addValueWithDerivatives();
      42          34 :     a->setNotPeriodic();
      43          34 :     final_value=a->copyOutput( a->getNumberOfComponents()-1 );
      44         252 :   } else if( numval<0 ) {
      45           2 :     no_output_value=true; final_value=new Value(); final_value->setNotPeriodic();
      46             :   } else {
      47         250 :     plumed_massert( !a->exists(getAction()->getLabel() + "." + getLabel() ), "you can't create the name multiple times");
      48         250 :     a->addComponentWithDerivatives( getLabel() );
      49         250 :     a->componentIsNotPeriodic( getLabel() );
      50         250 :     final_value=a->copyOutput( a->getNumberOfComponents()-1 );
      51             :   }
      52         286 : }
      53             : 
      54         572 : ValueVessel::~ValueVessel() {
      55         286 :   if( no_output_value ) delete final_value;
      56         286 : }
      57             : 
      58         286 : std::string ValueVessel::description() {
      59         286 :   if( final_value->getName()==getAction()->getLabel() ) return "value " + getAction()->getLabel() + " contains " + value_descriptor();
      60         252 :   return "value " + getAction()->getLabel() + "." + getLabel() + " contains " + value_descriptor();
      61             : }
      62             : 
      63       11275 : bool ValueVessel::applyForce( std::vector<double>& forces ) {
      64       11275 :   std::vector<double> tmpforce( forces.size() );
      65       11275 :   forces.assign(forces.size(),0.0); bool wasforced=false;
      66       11275 :   if( final_value->applyForce( tmpforce ) ) {
      67         145 :     wasforced=true;
      68         145 :     for(unsigned j=0; j<forces.size(); ++j) forces[j]+=tmpforce[j];
      69             :   }
      70       11275 :   return wasforced;
      71             : }
      72             : 
      73             : }
      74        2523 : }

Generated by: LCOV version 1.13