Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2014-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 "MultiColvarFilter.h"
23 :
24 : namespace PLMD {
25 : namespace multicolvar {
26 :
27 20 : void MultiColvarFilter::registerKeywords( Keywords& keys ) {
28 20 : BridgedMultiColvarFunction::registerKeywords( keys );
29 60 : if( keys.reserved("VMEAN") ) keys.use("VMEAN");
30 100 : keys.use("MEAN"); keys.use("MOMENTS"); keys.use("MIN"); keys.use("MAX");
31 80 : keys.use("ALT_MIN"); keys.use("LOWEST"); keys.use("HIGHEST");
32 20 : }
33 :
34 14 : MultiColvarFilter::MultiColvarFilter(const ActionOptions&ao):
35 : Action(ao),
36 14 : BridgedMultiColvarFunction(ao)
37 : {
38 14 : if( getPntrToMultiColvar()->isDensity() ) error("filtering/transforming density makes no sense");
39 :
40 28 : if( getName().find("MFILTER")!=std::string::npos ) filter=true;
41 : else {
42 2 : plumed_assert( getName().find("MTRANSFORM")!=std::string::npos );
43 1 : filter=false;
44 : }
45 :
46 14 : readVesselKeywords();
47 14 : }
48 :
49 46 : void MultiColvarFilter::doJobsRequiredBeforeTaskList() {
50 46 : ActionWithValue::clearDerivatives();
51 46 : ActionWithVessel::doJobsRequiredBeforeTaskList();
52 46 : }
53 :
54 20027 : void MultiColvarFilter::completeTask( const unsigned& curr, MultiValue& invals, MultiValue& outvals ) const {
55 20027 : invals.copyValues( outvals );
56 20027 : if( derivativesAreRequired() ) invals.copyDerivatives( outvals );
57 :
58 : // Retrive the value of the multicolvar and apply filter
59 20027 : double val=invals.get(1), df, weight=applyFilter( val, df );
60 :
61 : // Now propegate derivatives
62 38474 : if( filter && !getPntrToMultiColvar()->weightHasDerivatives ) {
63 : outvals.setValue( 0, weight );
64 18447 : if( derivativesAreRequired() ) {
65 4521573 : for(unsigned i=0; i<invals.getNumberActive(); ++i) {
66 2253501 : unsigned jder=invals.getActiveIndex(i);
67 2253501 : outvals.addDerivative( 0, jder, df*invals.getDerivative(1, jder ) );
68 : }
69 : }
70 1580 : } else if( filter ) {
71 0 : double ww=outvals.get(0); outvals.setValue( 0, ww*weight );
72 0 : if( derivativesAreRequired() ) {
73 0 : for(unsigned i=0; i<outvals.getNumberActive(); ++i) {
74 : unsigned ider=outvals.getActiveIndex(i);
75 0 : outvals.setDerivative( 0, ider, weight*outvals.getDerivative(1,ider) + ww*df*outvals.getDerivative(0,ider) );
76 : }
77 : }
78 : } else {
79 : outvals.setValue( 1, weight );
80 1580 : if( derivativesAreRequired() ) {
81 160244 : for(unsigned i=0; i<invals.getNumberActive(); ++i) {
82 : unsigned jder=invals.getActiveIndex(i);
83 79332 : outvals.setDerivative( 1, jder, df*invals.getDerivative(1, jder ) );
84 : }
85 : }
86 : }
87 20027 : }
88 :
89 0 : void MultiColvarFilter::addBridgeForces( const std::vector<double>& bb ) {
90 : plumed_dbg_assert( bb.size()==0 );
91 0 : }
92 :
93 : }
94 4839 : }
|