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