All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FunctionVessel.h
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 #ifndef __PLUMED_vesselbase_FunctionVessel_h
23 #define __PLUMED_vesselbase_FunctionVessel_h
24 
25 #include <string>
26 #include <cstring>
27 #include <vector>
28 #include "Vessel.h"
29 #include "core/Value.h"
30 
31 namespace PLMD {
32 namespace vesselbase{
33 
34 /**
35 \ingroup TOOLBOX
36 Objects that inherit from FunctionVessel can be used (in tandem with PLMD::ActionWithVessel) to calculate
37 functions of the form \f$\prod_k H_k[ \sum_j \prod_i g_i(x) ]\f$. They should take in a series of values
38 and return one single value.
39 */
40 
41 class FunctionVessel : public Vessel {
42 private:
43 /// The number of derivatives
44  unsigned nderivatives;
45 /// This is the pointer to the value we are creating
47 protected:
48 /// Are the derivatives differentiable
49  bool diffweight;
50 /// Add some value to the accumulator if it is greater than tolerance
51  bool addValueUsingTolerance( const unsigned& jval, const double& val );
52 /// Add some value to the accumulator and ignore the tolerance
53  void addValueIgnoringTolerance( const unsigned& jval, const double& val );
54 /// Set the final value
55  void setOutputValue( const double& val );
56 /// Get the nth value in the distribution
57  double getFinalValue( const unsigned& j );
58 /// This does a combination of the product and chain rules
59  void mergeFinalDerivatives( const std::vector<double>& df );
60 public:
61  static void registerKeywords( Keywords& keys );
62  FunctionVessel( const VesselOptions& );
63 /// This does the resizing of the buffer
64  void resize();
65 /// This applies all the forces
66  bool applyForce( std::vector<double>& forces );
67 /// The description for the log
68  std::string description();
69 /// The rest of the description of what we are calculating
70  virtual std::string function_description()=0;
71 /// Return number of terms
72  virtual unsigned getNumberOfTerms(){ return 2; }
73 };
74 
75 inline
76 bool FunctionVessel::addValueUsingTolerance( const unsigned& jval, const double& val ){
77  if( fabs(val)<getTolerance() ) return false;
78  addToBufferElement( (nderivatives+1)*jval, val );
79  return true;
80 }
81 
82 inline
83 void FunctionVessel::addValueIgnoringTolerance( const unsigned& jval, const double& val ){
84  addToBufferElement( (nderivatives+1)*jval, val );
85 }
86 
87 inline
88 double FunctionVessel::getFinalValue(const unsigned& j){
89  plumed_dbg_assert( j<getNumberOfTerms() );
90  return getBufferElement( (nderivatives+1)*j );
91 }
92 
93 inline
94 void FunctionVessel::setOutputValue( const double& val ){
95  final_value->set( val );
96 }
97 
98 }
99 }
100 #endif
virtual unsigned getNumberOfTerms()
Return number of terms.
bool applyForce(std::vector< double > &forces)
This applies all the forces.
double getTolerance() const
Return the value of the tolerance.
Definition: Vessel.h:226
void addToBufferElement(const unsigned &i, const double &val)
Add something to the ith element in the buffer.
Definition: Vessel.h:252
double getFinalValue(const unsigned &j)
Get the nth value in the distribution.
bool diffweight
Are the derivatives differentiable.
std::string description()
The description for the log.
A class for holding the value of a function together with its derivatives.
Definition: Value.h:46
double getBufferElement(const unsigned &i) const
Get the value in the ith element of the buffer.
Definition: Vessel.h:258
void setOutputValue(const double &val)
Set the final value.
Objects that inherit from FunctionVessel can be used (in tandem with PLMD::ActionWithVessel) to calcu...
Value * final_value
This is the pointer to the value we are creating.
static void registerKeywords(Keywords &keys)
void mergeFinalDerivatives(const std::vector< double > &df)
This does a combination of the product and chain rules.
FunctionVessel(const VesselOptions &)
void set(double)
Set the value of the function.
Definition: Value.h:174
void resize()
This does the resizing of the buffer.
This class holds the keywords and their documentation.
Definition: Keywords.h:36
void addValueIgnoringTolerance(const unsigned &jval, const double &val)
Add some value to the accumulator and ignore the tolerance.
virtual std::string function_description()=0
The rest of the description of what we are calculating.
This class is used to pass the input to Vessels.
Definition: Vessel.h:53
unsigned nderivatives
The number of derivatives.
bool addValueUsingTolerance(const unsigned &jval, const double &val)
Add some value to the accumulator if it is greater than tolerance.