All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FunctionVessel.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 #include "FunctionVessel.h"
23 #include "core/ActionWithValue.h"
24 
25 namespace PLMD{
26 namespace vesselbase{
27 
30  plumed_assert( keys.size()==0 );
31 }
32 
34 Vessel(da)
35 {
36  ActionWithValue* a=dynamic_cast<ActionWithValue*>( getAction() );
37  plumed_massert(a,"cannot create passable values as base action does not inherit from ActionWithValue");
38  int numval = getNumericalLabel();
39  if( numval<0 ){ // This allows us to make multicolvars pretend to be colvars - this is used in AlphaRMSD etc
40  plumed_massert( a->getNumberOfComponents()==0,"you can't multiple values with the action label");
42  } else {
43  plumed_massert( !a->exists(getAction()->getLabel() + "." + getLabel() ), "you can't create the name multiple times");
45  }
48 }
49 
51  return "value " + getAction()->getLabel() + "." + getLabel() + " contains " + function_description();
52 }
53 
58 }
59 
60 void FunctionVessel::mergeFinalDerivatives( const std::vector<double>& df ){
61  plumed_dbg_assert( df.size()==getNumberOfTerms() );
62  for(unsigned i=0;i<getNumberOfTerms();++i){
63  unsigned ider=i*( nderivatives + 1 ) + 1;
64  for(unsigned k=0;k<nderivatives;++k){
65  final_value->addDerivative( k, df[i]*getBufferElement( ider ) ); ider++;
66  }
67  }
68 }
69 
70 bool FunctionVessel::applyForce( std::vector<double>& forces ){
71  std::vector<double> tmpforce( forces.size() );
72  forces.assign(forces.size(),0.0); bool wasforced=false;
73  if( final_value->applyForce( tmpforce ) ){
74  wasforced=true;
75  for(unsigned j=0;j<forces.size();++j) forces[j]+=tmpforce[j];
76  }
77  return wasforced;
78 }
79 
80 }
81 }
82 
void setNotPeriodic()
Set your default value to have no periodicity.
virtual unsigned getNumberOfTerms()
Return number of terms.
bool applyForce(std::vector< double > &forces)
This applies all the forces.
bool applyForce(std::vector< double > &forces) const
Apply the forces to the derivatives using the chain rule (if there are no forces this routine returns...
Definition: Value.cpp:80
void componentIsNotPeriodic(const std::string &name)
Set your value component to have no periodicity.
bool diffweight
Are the derivatives differentiable.
std::string description()
The description for the log.
virtual unsigned getNumberOfDerivatives()=0
Get the number of derivatives for final calculated quantity.
static void registerKeywords(Keywords &keys)
Reserve any keywords for this particular vessel.
Definition: Vessel.cpp:53
double getBufferElement(const unsigned &i) const
Get the value in the ith element of the buffer.
Definition: Vessel.h:258
const std::string & getLabel() const
Returns the label.
Definition: Action.h:263
Value * final_value
This is the pointer to the value we are creating.
void addValueWithDerivatives()
Add a value with the name label that has derivatives.
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 &)
std::string getLabel() const
Return the label.
Definition: Vessel.cpp:80
bool weightHasDerivatives
Does the weight have derivatives.
void resize()
This does the resizing of the buffer.
Used to create a PLMD::Action that has some scalar or vectorial output that may or may not have some ...
This class holds the keywords and their documentation.
Definition: Keywords.h:36
bool exists(const std::string &name) const
Check if a value with a particular name is present.
void resizeBuffer(const unsigned &n)
Set the size of the data buffer.
Definition: Vessel.h:221
int getNumericalLabel() const
Return the numerical label.
Definition: Vessel.h:216
Value * copyOutput(const std::string &name) const
Return a pointer to the value with name (this is used to retrieve values in other PLMD::Actions) You ...
virtual std::string function_description()=0
The rest of the description of what we are calculating.
void resizeDerivatives(int n)
Set the number of derivatives.
Definition: Value.h:218
This class is used to pass the input to Vessels.
Definition: Vessel.h:53
unsigned nderivatives
The number of derivatives.
void int double * da
Definition: Matrix.h:47
void addComponentWithDerivatives(const std::string &name)
Add a value with a name like label.name that has derivatives.
int getNumberOfComponents() const
Returns the number of values defined.
void const char const char int double * a
Definition: Matrix.h:42
void addDerivative(unsigned i, double d)
Add some derivative to the ith component of the derivatives array.
Definition: Value.h:224
unsigned size() const
Return the number of defined keywords.
Definition: Keywords.cpp:230
ActionWithVessel * getAction()
Return a pointer to the action we are working in.
Definition: Vessel.h:236