LCOV - code coverage report
Current view: top level - mapping - SpathVessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 31 33 93.9 %
Date: 2026-03-30 13:16:06 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-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 "vesselbase/VesselRegister.h"
      23             : #include "vesselbase/FunctionVessel.h"
      24             : #include "Mapping.h"
      25             : 
      26             : namespace PLMD {
      27             : namespace mapping {
      28             : 
      29             : class SpathVessel : public vesselbase::FunctionVessel {
      30             : private:
      31             :   bool foundoneclose;
      32             :   Mapping* mymap;
      33             : public:
      34             :   static void registerKeywords( Keywords& keys );
      35             :   static void reserveKeyword( Keywords& keys );
      36             :   explicit SpathVessel( const vesselbase::VesselOptions& da );
      37             :   std::string value_descriptor() override;
      38             :   void prepare() override;
      39             :   void calculate( const unsigned& current, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_index ) const override;
      40             : };
      41             : 
      42       13795 : PLUMED_REGISTER_VESSEL(SpathVessel,"SPATH")
      43             : 
      44          10 : void SpathVessel::registerKeywords( Keywords& keys ) {
      45          10 :   FunctionVessel::registerKeywords(keys);
      46          10 : }
      47             : 
      48        4595 : void SpathVessel::reserveKeyword( Keywords& keys ) {
      49        9190 :   keys.reserve("vessel","SPATH","docs should not appear");
      50        9190 :   keys.addOutputComponent("spath","SPATH","the position on the path");
      51        4595 : }
      52             : 
      53          10 : SpathVessel::SpathVessel( const vesselbase::VesselOptions& da ):
      54             :   FunctionVessel(da),
      55          10 :   foundoneclose(false) {
      56          10 :   mymap=dynamic_cast<Mapping*>( getAction() );
      57          10 :   plumed_massert( mymap, "SpathVessel can only be used with mappings");
      58             :   // Retrieve the index of the property in the underlying mapping
      59          10 :   usetol=true;
      60          10 :   norm=true;
      61             : 
      62         430 :   for(unsigned i=0; i<mymap->getFullNumberOfTasks(); ++i) {
      63         420 :     if( mymap->getTaskCode(i)!=mymap->getPositionInFullTaskList(i) ) {
      64           0 :       error("mismatched tasks and codes");
      65             :     }
      66             :   }
      67          10 : }
      68             : 
      69          10 : std::string SpathVessel::value_descriptor() {
      70          10 :   return "the position on the path";
      71             : }
      72             : 
      73        5460 : void SpathVessel::prepare() {
      74        5460 :   foundoneclose=false;
      75        5460 : }
      76             : 
      77       27391 : void SpathVessel::calculate( const unsigned& current, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_index ) const {
      78       27391 :   double pp=mymap->getPropertyValue( current, getLabel() ), weight=myvals.get(0);
      79       27391 :   if( weight<getTolerance() ) {
      80           0 :     return;
      81             :   }
      82       27391 :   unsigned nderivatives=getFinalValue()->getNumberOfDerivatives();
      83       27391 :   buffer[bufstart] += weight*pp;
      84       27391 :   buffer[bufstart+1+nderivatives] += weight;
      85       27391 :   if( getAction()->derivativesAreRequired() ) {
      86       23478 :     myvals.chainRule( 0, 0, 1, 0, pp, bufstart, buffer );
      87       23478 :     myvals.chainRule( 0, 1, 1, 0, 1.0, bufstart, buffer );
      88             :   }
      89             : }
      90             : 
      91             : }
      92             : }

Generated by: LCOV version 1.16