LCOV - code coverage report
Current view: top level - vesselbase - ValueVessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 33 33 100.0 %
Date: 2020-11-18 11:20:57 Functions: 7 8 87.5 %

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

Generated by: LCOV version 1.13