LCOV - code coverage report
Current view: top level - vesselbase - ValueVessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 32 32 100.0 %
Date: 2024-10-11 08:09:47 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         335 : void ValueVessel::registerKeywords( Keywords& keys ) {
      28         335 :   Vessel::registerKeywords( keys );
      29         670 :   keys.add("compulsory","COMPONENT","1","the component of the vector for which to calculate this quantity");
      30         335 : }
      31             : 
      32         335 : ValueVessel::ValueVessel( const VesselOptions& da ):
      33         335 :   Vessel(da)
      34             : {
      35         670 :   parse("COMPONENT",mycomp);
      36         335 :   ActionWithValue* a=dynamic_cast<ActionWithValue*>( getAction() );
      37         335 :   plumed_massert(a,"cannot create passable values as base action does not inherit from ActionWithValue");
      38             :   int numval = getNumericalLabel();
      39         335 :   if( numval<0 && a->getNumberOfComponents()==0 ) {  // This allows us to make multicolvars pretend to be colvars - this is used in AlphaRMSD etc
      40          36 :     a->addValueWithDerivatives();
      41          36 :     a->setNotPeriodic();
      42          36 :     final_value=a->copyOutput( a->getNumberOfComponents()-1 );
      43         299 :   } else if( numval<0 ) {
      44           4 :     final_value_ptr=Tools::make_unique<Value>();
      45           2 :     final_value=final_value_ptr.get();
      46           2 :     final_value->setNotPeriodic();
      47             :   } else {
      48         594 :     plumed_massert( !a->exists(getAction()->getLabel() + "." + getLabel() ), "you can't create the name multiple times");
      49         297 :     a->addComponentWithDerivatives( getLabel() );
      50         594 :     a->componentIsNotPeriodic( getLabel() );
      51         297 :     final_value=a->copyOutput( a->getNumberOfComponents()-1 );
      52             :   }
      53         335 : }
      54             : 
      55         335 : std::string ValueVessel::description() {
      56         403 :   if( final_value->getName()==getAction()->getLabel() ) return "value " + getAction()->getLabel() + " contains " + value_descriptor();
      57         299 :   std::string compstr; Tools::convert(mycomp,compstr);
      58         814 :   return "value " + getAction()->getLabel() + "." + getLabel() + " is obtained by taking the " + compstr + "th component and finding " + value_descriptor();
      59             : }
      60             : 
      61       11443 : bool ValueVessel::applyForce( std::vector<double>& forces ) {
      62       11443 :   std::vector<double> tmpforce( forces.size() );
      63       11443 :   forces.assign(forces.size(),0.0); bool wasforced=false;
      64       11443 :   if( final_value->applyForce( tmpforce ) ) {
      65             :     wasforced=true;
      66      524318 :     for(unsigned j=0; j<forces.size(); ++j) forces[j]+=tmpforce[j];
      67             :   }
      68       11443 :   return wasforced;
      69             : }
      70             : 
      71             : }
      72             : }

Generated by: LCOV version 1.15