LCOV - code coverage report
Current view: top level - vesselbase - ValueVessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 34 34 100.0 %
Date: 2026-03-30 13:16:06 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-2023 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         355 : void ValueVessel::registerKeywords( Keywords& keys ) {
      28         355 :   Vessel::registerKeywords( keys );
      29         710 :   keys.add("compulsory","COMPONENT","1","the component of the vector for which to calculate this quantity");
      30         355 : }
      31             : 
      32         355 : ValueVessel::ValueVessel( const VesselOptions& da ):
      33         355 :   Vessel(da) {
      34         710 :   parse("COMPONENT",mycomp);
      35         355 :   ActionWithValue* a=dynamic_cast<ActionWithValue*>( getAction() );
      36         355 :   plumed_massert(a,"cannot create passable values as base action does not inherit from ActionWithValue");
      37             :   int numval = getNumericalLabel();
      38         355 :   if( numval<0 && a->getNumberOfComponents()==0 ) {  // This allows us to make multicolvars pretend to be colvars - this is used in AlphaRMSD etc
      39          36 :     a->addValueWithDerivatives();
      40          36 :     a->setNotPeriodic();
      41          36 :     final_value=a->copyOutput( a->getNumberOfComponents()-1 );
      42         319 :   } else if( numval<0 ) {
      43           4 :     final_value_ptr=Tools::make_unique<Value>();
      44           2 :     final_value=final_value_ptr.get();
      45           2 :     final_value->setNotPeriodic();
      46             :   } else {
      47         634 :     plumed_massert( !a->exists(getAction()->getLabel() + "." + getLabel() ), "you can't create the name multiple times");
      48         317 :     a->addComponentWithDerivatives( getLabel() );
      49         634 :     a->componentIsNotPeriodic( getLabel() );
      50         317 :     final_value=a->copyOutput( a->getNumberOfComponents()-1 );
      51             :   }
      52         355 : }
      53             : 
      54         355 : std::string ValueVessel::description() {
      55         355 :   if( final_value->getName()==getAction()->getLabel() ) {
      56          72 :     return "value " + getAction()->getLabel() + " contains " + value_descriptor();
      57             :   }
      58             :   std::string compstr;
      59         319 :   Tools::convert(mycomp,compstr);
      60         638 :   return "value " + getAction()->getLabel() + "." + getLabel() + " is obtained by taking the " + compstr + "th component and finding " + value_descriptor();
      61             : }
      62             : 
      63       11553 : bool ValueVessel::applyForce( std::vector<double>& forces ) {
      64       11553 :   std::vector<double> tmpforce( forces.size() );
      65       11553 :   forces.assign(forces.size(),0.0);
      66             :   bool wasforced=false;
      67       11553 :   if( final_value->applyForce( tmpforce ) ) {
      68             :     wasforced=true;
      69      758678 :     for(unsigned j=0; j<forces.size(); ++j) {
      70      758291 :       forces[j]+=tmpforce[j];
      71             :     }
      72             :   }
      73       11553 :   return wasforced;
      74             : }
      75             : 
      76             : }
      77             : }

Generated by: LCOV version 1.16