All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MoreThan.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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 
23 #include "VesselRegister.h"
24 #include "FunctionVessel.h"
25 #include "tools/SwitchingFunction.h"
26 #include "ActionWithVessel.h"
27 
28 namespace PLMD {
29 namespace vesselbase{
30 
31 class MoreThan : public FunctionVessel {
32 private:
33  std::vector<double> df;
35 public:
36  static void registerKeywords( Keywords& keys );
37  static void reserveKeyword( Keywords& keys );
38  MoreThan( const VesselOptions& da );
39  std::string function_description();
40  bool calculate();
41  void finish();
42 };
43 
45 
46 void MoreThan::registerKeywords( Keywords& keys ){
49 }
50 
52  keys.reserve("numbered","MORE_THAN","calculate the number of variables more than a certain target value. "
53  "This quantity is calculated using \\f$\\sum_i 1.0 - \\sigma(s_i)\\f$, where \\f$\\sigma(s)\\f$ "
54  "is a \\ref switchingfunction.",true);
55  keys.addOutputComponent("more_than","MORE_THAN","the number of values more than a target value. This is calculated using one of the "
56  "formula described in the description of the keyword so as to make it continuous. "
57  "You can calculate this quantity multiple times using different parameters.");
58 }
59 
61 FunctionVessel(da),
62 df(2)
63 {
64  if( getAction()->isPeriodic() ) error("more than is not a meaningful option for periodic variables");
65  std::string errormsg; sf.set( getAllInput(), errormsg );
66  if( errormsg.size()!=0 ) error( errormsg );
67 }
68 
70  return "the number of values more than " + sf.description();
71 }
72 
74  double weight=getAction()->getElementValue(1);
75  plumed_dbg_assert( weight>=getTolerance() );
76 
77  double val=getAction()->getElementValue(0);
78  double dval, f = 1.0 - sf.calculate(val, dval); dval*=-val;
79  double contr=weight*f;
80  bool addval=addValueUsingTolerance(0,contr);
81  if(addval){
82  getAction()->chainRuleForElementDerivatives( 0, 0, weight*dval, this );
84  }
85  return ( contr>getNLTolerance() );
86 }
87 
90  df[0]=1.0; df[1]=0.0;
92 }
93 
94 }
95 }
double calculate(double x, double &df) const
double getTolerance() const
Return the value of the tolerance.
Definition: Vessel.h:226
double getFinalValue(const unsigned &j)
Get the nth value in the distribution.
bool diffweight
Are the derivatives differentiable.
void chainRuleForElementDerivatives(const unsigned &, const unsigned &, const double &, Vessel *)
Merge the derivatives.
static void reserveKeyword(Keywords &keys)
Definition: MoreThan.cpp:51
void set(int nn, int mm, double r_0, double d_0)
bool calculate()
Calculate the part of the vessel that is done in the loop.
Definition: MoreThan.cpp:73
std::vector< double > df
Definition: MoreThan.cpp:33
void setOutputValue(const double &val)
Set the final value.
Objects that inherit from FunctionVessel can be used (in tandem with PLMD::ActionWithVessel) to calcu...
std::string function_description()
The rest of the description of what we are calculating.
Definition: MoreThan.cpp:69
static void registerKeywords(Keywords &keys)
void mergeFinalDerivatives(const std::vector< double > &df)
This does a combination of the product and chain rules.
Small class to compure switching functions in the form In the future we might extend it so as to be s...
static void registerKeywords(Keywords &keys)
Definition: MoreThan.cpp:46
void addOutputComponent(const std::string &name, const std::string &key, const std::string &descr)
Add a potential component which can be output by this particular action.
Definition: Keywords.cpp:565
This class holds the keywords and their documentation.
Definition: Keywords.h:36
#define PLUMED_REGISTER_VESSEL(classname, keyword)
MoreThan(const VesselOptions &da)
Definition: MoreThan.cpp:60
void reserve(const std::string &t, const std::string &k, const std::string &d, const bool isvessel=false)
Reserve a keyword.
Definition: Keywords.cpp:110
void error(const std::string &errmsg)
Report an error.
Definition: Vessel.cpp:122
This class is used to pass the input to Vessels.
Definition: Vessel.h:53
void finish()
Complete the calculation once the loop is finished.
Definition: MoreThan.cpp:88
void int double * da
Definition: Matrix.h:47
SwitchingFunction sf
Definition: MoreThan.cpp:34
std::string description() const
bool addValueUsingTolerance(const unsigned &jval, const double &val)
Add some value to the accumulator if it is greater than tolerance.
static void registerKeywords(Keywords &keys)
double getNLTolerance() const
Return the value of the neighbor list tolerance.
Definition: Vessel.h:231
std::string getAllInput()
This returns the whole input line (it is used for less_than/more_than/between)
Definition: Vessel.cpp:84
double getElementValue(const unsigned &ival) const
Get the value of this element.
ActionWithVessel * getAction()
Return a pointer to the action we are working in.
Definition: Vessel.h:236