All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StoreColvarVessel.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 "vesselbase/ActionWithVessel.h"
23 #include "StoreColvarVessel.h"
24 #include "MultiColvarBase.h"
25 
26 #define MAXDERIVATIVES 300
27 
28 namespace PLMD {
29 namespace multicolvar{
30 
32  Vessel::registerKeywords( keys );
33  plumed_assert( keys.size()==0 );
34 }
35 
37 Vessel(da)
38 {
39  mycolv=dynamic_cast<MultiColvarBase*>( getAction() );
40  plumed_assert( mycolv );
42  // Resize the active derivative lists
43  active_atoms.resize( mycolv->colvar_atoms.size() );
44 }
45 
47  unsigned nfunc=mycolv->colvar_atoms.size();
48  bufsize=0; start.resize( nfunc +1 );
49  for(unsigned i=0;i<nfunc;++i){
50  start[i] = bufsize;
51  bufsize += 1 + MAXDERIVATIVES;
52  }
53  start[nfunc]=bufsize;
55  // Build the arrays of indexes
56  for(unsigned i=0;i<active_atoms.size();++i){
57  active_atoms[i].clear(); active_atoms[i].setupMPICommunication( comm );
58  for(unsigned j=0;j<mycolv->getNumberOfAtoms();++j) active_atoms[i].addIndexToList(j);
59  }
60 }
61 
64  "Error increase MAXDERIVATIVES in StoreColvarVessel");
65 
66  unsigned ibuf=start[mycolv->current];
67  setBufferElement( ibuf, mycolv->getElementValue(0) ); ibuf++;
68  for(unsigned j=0;j<mycolv->atoms_with_derivatives.getNumberActive();++j){
69  unsigned iatom=mycolv->atoms_with_derivatives[j];
70  active_atoms[mycolv->current].activate(iatom);
71  unsigned ider=3*iatom;
72  setBufferElement( ibuf, mycolv->getElementDerivative(ider) ); ider++; ibuf++;
73  setBufferElement( ibuf, mycolv->getElementDerivative(ider) ); ider++; ibuf++;
74  setBufferElement( ibuf, mycolv->getElementDerivative(ider) ); ibuf++;
75  }
76  unsigned ivir=3*mycolv->getNumberOfAtoms();
77  for(unsigned j=0;j<9;++j){
78  setBufferElement( ibuf, mycolv->getElementDerivative(ivir) ); ivir++; ibuf++;
79  }
80  ibuf=bufsize+start[mycolv->current];
81  setBufferElement( ibuf, mycolv->getElementValue(1) ); ibuf++;
82  if(diffweight){
83  unsigned nder=mycolv->getNumberOfDerivatives();
84  for(unsigned j=0;j<mycolv->atoms_with_derivatives.getNumberActive();++j){
85  unsigned ider=nder+3*mycolv->atoms_with_derivatives[j];
86  setBufferElement( ibuf, mycolv->getElementDerivative(ider) ); ider++; ibuf++;
87  setBufferElement( ibuf, mycolv->getElementDerivative(ider) ); ider++; ibuf++;
88  setBufferElement( ibuf, mycolv->getElementDerivative(ider) ); ibuf++;
89  }
90  unsigned ivir=nder + 3*mycolv->getNumberOfAtoms();
91  for(unsigned j=0;j<9;++j){
92  setBufferElement( ibuf, mycolv->getElementDerivative(ivir) ); ivir++; ibuf++;
93  }
94  }
95  return true;
96 }
97 
101 }
102 
103 void StoreColvarVessel::addDerivatives( const unsigned& ival, double& pref, Value* value_out ){
104  for(unsigned i=0;i<active_atoms[ival].getNumberActive();++i){
105  unsigned jbuf=start[ival] + 1 + 3*i;
106  value_out->addDerivative( 3*active_atoms[ival][i] + 0, pref*getBufferElement(jbuf) ); jbuf++;
107  value_out->addDerivative( 3*active_atoms[ival][i] + 1, pref*getBufferElement(jbuf) ); jbuf++;
108  value_out->addDerivative( 3*active_atoms[ival][i] + 2, pref*getBufferElement(jbuf) );
109  }
110  unsigned jbuf=start[ival] + 1 + 3*active_atoms[ival].getNumberActive();
111  unsigned nder=3*mycolv->getNumberOfAtoms();
112  for(unsigned i=0;i<9;++i){
113  value_out->addDerivative( nder, pref*getBufferElement(jbuf) ); nder++; jbuf++;
114  }
115 }
116 
117 void StoreColvarVessel::addWeightDerivatives( const unsigned& ival, double& pref, Value* value_out ){
118  if(!diffweight) return;
119 
120  unsigned jbuf=bufsize+start[ival]+1;
121  for(unsigned i=0;i<active_atoms[ival].getNumberActive();++i){
122  value_out->addDerivative( 3*active_atoms[ival][i] + 0, pref*getBufferElement(jbuf) ); jbuf++;
123  value_out->addDerivative( 3*active_atoms[ival][i] + 1, pref*getBufferElement(jbuf) ); jbuf++;
124  value_out->addDerivative( 3*active_atoms[ival][i] + 2, pref*getBufferElement(jbuf) ); jbuf++;
125  }
126  jbuf=bufsize+start[ival] + 1 + 3*active_atoms[ival].getNumberActive();
127  unsigned nder=3*mycolv->getNumberOfAtoms();
128  for(unsigned i=0;i<9;++i){
129  value_out->addDerivative( nder, pref*getBufferElement(jbuf) ); nder++; jbuf++;
130  }
131 }
132 
133 
134 }
135 }
136 
virtual void performCalculationUsingAllValues()=0
Do the calculation.
unsigned current
The numerical index of the task we are curently performing.
void mpi_gatherActiveMembers(Communicator &comm, std::vector< DynamicList< U > > &ll)
Definition: DynamicList.h:318
#define MAXDERIVATIVES
A class for holding the value of a function together with its derivatives.
Definition: Value.h:46
Communicator & comm
A copy of the communicator.
Definition: Vessel.h:102
double getBufferElement(const unsigned &i) const
Get the value in the ith element of the buffer.
Definition: Vessel.h:258
double getElementDerivative(const unsigned &) const
Retrieve the derivative of the quantity in the sum wrt to a numbered element.
bool calculate()
This makes sure all values are stored.
virtual void local_resizing()=0
This makes sure things further down the chain are resized.
void resize()
This does the resizing of the buffer.
std::vector< DynamicList< unsigned > > active_atoms
void addDerivatives(const unsigned &ival, double &pref, Value *value_out)
Add the derivatives from the value.
bool weightHasDerivatives
Does the weight have derivatives.
This class holds the keywords and their documentation.
Definition: Keywords.h:36
std::vector< DynamicList< unsigned > > colvar_atoms
The lists of the atoms involved in each of the individual colvars note these refer to the atoms in al...
static void registerKeywords(Keywords &keys)
void resizeBuffer(const unsigned &n)
Set the size of the data buffer.
Definition: Vessel.h:221
void setBufferElement(const unsigned &i, const double &val)
Set the value of the ith element in the buffer.
Definition: Vessel.h:246
void addWeightDerivatives(const unsigned &ival, double &pref, Value *value_out)
Add the derivatives from the weight of the value.
StoreColvarVessel(const vesselbase::VesselOptions &)
Constructor.
This class is used to pass the input to Vessels.
Definition: Vessel.h:53
void int double * da
Definition: Matrix.h:47
DynamicList< unsigned > atoms_with_derivatives
A dynamic list containing those atoms with derivatives.
unsigned getNumberOfDerivatives()
Get the number of derivatives for this action.
void finish()
Makes sure the dynamic lists are gathered.
unsigned getNumberOfAtoms() const
Get number of available atoms.
bool diffweight
Are the weights differentiable.
void addDerivative(unsigned i, double d)
Add some derivative to the ith component of the derivatives array.
Definition: Value.h:224
unsigned getNumberActive() const
Return the number of elements that are currently active.
Definition: DynamicList.h:230
unsigned size() const
Return the number of defined keywords.
Definition: Keywords.cpp:230
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