LCOV - code coverage report
Current view: top level - mapping - SpathVessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 29 100.0 %
Date: 2024-10-11 08:09:47 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       10429 : PLUMED_REGISTER_VESSEL(SpathVessel,"SPATH")
      43             : 
      44          10 : void SpathVessel::registerKeywords( Keywords& keys ) {
      45          10 :   FunctionVessel::registerKeywords(keys);
      46          10 : }
      47             : 
      48        3473 : void SpathVessel::reserveKeyword( Keywords& keys ) {
      49        6946 :   keys.reserve("vessel","SPATH","docs should not appear");
      50        6946 :   keys.addOutputComponent("spath","SPATH","the position on the path");
      51        3473 : }
      52             : 
      53          10 : SpathVessel::SpathVessel( const vesselbase::VesselOptions& da ):
      54             :   FunctionVessel(da),
      55          10 :   foundoneclose(false)
      56             : {
      57          10 :   mymap=dynamic_cast<Mapping*>( getAction() );
      58          10 :   plumed_massert( mymap, "SpathVessel can only be used with mappings");
      59             :   // Retrieve the index of the property in the underlying mapping
      60          10 :   usetol=true; norm=true;
      61             : 
      62         430 :   for(unsigned i=0; i<mymap->getFullNumberOfTasks(); ++i) {
      63         420 :     if( mymap->getTaskCode(i)!=mymap->getPositionInFullTaskList(i) ) error("mismatched tasks and codes");
      64             :   }
      65          10 : }
      66             : 
      67          10 : std::string SpathVessel::value_descriptor() {
      68          10 :   return "the position on the path";
      69             : }
      70             : 
      71        5460 : void SpathVessel::prepare() {
      72        5460 :   foundoneclose=false;
      73        5460 : }
      74             : 
      75       27391 : void SpathVessel::calculate( const unsigned& current, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_index ) const {
      76       27391 :   double pp=mymap->getPropertyValue( current, getLabel() ), weight=myvals.get(0);
      77       27391 :   if( weight<getTolerance() ) return;
      78       27391 :   unsigned nderivatives=getFinalValue()->getNumberOfDerivatives();
      79       27391 :   buffer[bufstart] += weight*pp; buffer[bufstart+1+nderivatives] += weight;
      80       27391 :   if( getAction()->derivativesAreRequired() ) {
      81       23478 :     myvals.chainRule( 0, 0, 1, 0, pp, bufstart, buffer );
      82       23478 :     myvals.chainRule( 0, 1, 1, 0, 1.0, bufstart, buffer );
      83             :   }
      84             : }
      85             : 
      86             : }
      87             : }

Generated by: LCOV version 1.15