All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LessThan.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 LessThan : public FunctionVessel {
32 private:
34 public:
35  static void registerKeywords( Keywords& keys );
36  static void reserveKeyword( Keywords& keys );
37  LessThan( const VesselOptions& da );
38  std::string function_description();
39  bool calculate();
40  void finish();
41 };
42 
44 
45 void LessThan::registerKeywords( Keywords& keys ){
48 }
49 
51  keys.reserve("numbered","LESS_THAN","calculate the number of variables less than a certain target value. "
52  "This quantity is calculated using \\f$\\sum_i \\sigma(s_i)\\f$, where \\f$\\sigma(s)\\f$ "
53  "is a \\ref switchingfunction.",true);
54  keys.addOutputComponent("less_than","LESS_THAN","the number of values less than a target value. This is calculated using one of the "
55  "formula described in the description of the keyword so as to make it continuous. "
56  "You can calculate this quantity multiple times using different parameters.");
57 }
58 
61 {
62  if( getAction()->isPeriodic() ) error("LESS_THAN is not a meaningful option for periodic variables");
63  std::string errormsg; sf.set( getAllInput(), errormsg );
64  if( errormsg.size()!=0 ) error( errormsg );
65 }
66 
68  return "the number of values less than " + sf.description();
69 }
70 
72  double weight=getAction()->getElementValue(1);
73  plumed_dbg_assert( weight>=getTolerance() );
74 
75  double val=getAction()->getElementValue(0);
76  double dval, f = sf.calculate(val, dval); dval*=val;
77  double contr=weight*f;
78  bool addval=addValueUsingTolerance(0,contr);
79  if(addval){
80  getAction()->chainRuleForElementDerivatives(0, 0, weight*dval, this);
82  }
83  return ( contr>getNLTolerance() );
84 }
85 
88  std::vector<double> df(2); df[0]=1.0; df[1]=0.0;
90 }
91 
92 }
93 }
double calculate(double x, double &df) const
static void registerKeywords(Keywords &keys)
Definition: LessThan.cpp:45
bool calculate()
Calculate the part of the vessel that is done in the loop.
Definition: LessThan.cpp:71
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.
void set(int nn, int mm, double r_0, double d_0)
void setOutputValue(const double &val)
Set the final value.
Objects that inherit from FunctionVessel can be used (in tandem with PLMD::ActionWithVessel) to calcu...
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...
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)
static void reserveKeyword(Keywords &keys)
Definition: LessThan.cpp:50
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
std::string function_description()
The rest of the description of what we are calculating.
Definition: LessThan.cpp:67
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 int double * da
Definition: Matrix.h:47
std::string description() const
bool addValueUsingTolerance(const unsigned &jval, const double &val)
Add some value to the accumulator if it is greater than tolerance.
LessThan(const VesselOptions &da)
Definition: LessThan.cpp:59
static void registerKeywords(Keywords &keys)
double getNLTolerance() const
Return the value of the neighbor list tolerance.
Definition: Vessel.h:231
void finish()
Complete the calculation once the loop is finished.
Definition: LessThan.cpp:86
std::string getAllInput()
This returns the whole input line (it is used for less_than/more_than/between)
Definition: Vessel.cpp:84
SwitchingFunction sf
Definition: LessThan.cpp:33
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