All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StoreCentralAtomsVessel.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/VesselRegister.h"
23 #include "vesselbase/ActionWithVessel.h"
24 #include "MultiColvar.h"
25 #include "MultiColvarFunction.h"
27 
28 #define CATOMS_MAXATOMS 2
29 
30 namespace PLMD {
31 namespace multicolvar {
32 
34 Vessel(da),
35 nspace(1 + 3*CATOMS_MAXATOMS)
36 {
37  mycolv=dynamic_cast<MultiColvar*>( getAction() );
38  plumed_assert( mycolv );
39  // Resize the active derivative lists
40  active_atoms.resize( mycolv->colvar_atoms.size() );
41 }
42 
44  unsigned nfunc=mycolv->colvar_atoms.size();
45  unsigned bsize=0; start.resize( nfunc +1 );
46  for(unsigned i=0;i<nfunc;++i){
47  start[i] = bsize;
48  bsize += 3*( 1 + 3*CATOMS_MAXATOMS );
49  }
50  start[nfunc]=bsize;
51  resizeBuffer( bsize );
52  // Update the active_derivative lists
53  for(unsigned i=0;i<active_atoms.size();++i){
54  active_atoms[i].clear(); active_atoms[i].setupMPICommunication( comm );
55  for(unsigned j=0;j<mycolv->getNumberOfAtoms();++j){
56  active_atoms[i].addIndexToList(j);
57  }
58  }
59 }
60 
63 
64  // Store the value
65  unsigned ibuf=start[mycolv->current];
66  for(unsigned i=0;i<3;++i){ addToBufferElement( ibuf, catom_pos[i] ); ibuf+=nspace; }
67  plumed_dbg_assert( ibuf==start[mycolv->current+1] );
68 
69  // Chect there is sufficent space for the derivatives
71  "increase CATOMS_MAXATOMS in StoreCentralAtomsVessel");
72 
73  // Store the derivatives
74  active_atoms[mycolv->current].deactivateAll();
75  for(unsigned j=0;j<mycolv->atomsWithCatomDer.getNumberActive();++j){
76  unsigned n=mycolv->atomsWithCatomDer[j];
77  active_atoms[mycolv->current].activate(n);
78  ibuf = start[mycolv->current] + 1 + 3*j;
79  for(unsigned i=0;i<3;++i){
80  for(unsigned k=0;k<3;++k) addToBufferElement( ibuf+k, mycolv->central_derivs[n](i,k) );
81  ibuf += nspace;
82  }
83  }
84 
85  return true;
86 }
87 
90 }
91 
92 Vector StoreCentralAtomsVessel::getPosition( const unsigned& ivec ) const {
93  plumed_dbg_assert( ivec<mycolv->colvar_atoms.size() );
94  unsigned pos=start[ivec]; Vector mypos;
95  for(unsigned i=0;i<3;++i){
96  mypos[i] = getBufferElement( pos );
97  pos+=nspace;
98  }
99  plumed_dbg_assert( pos==start[ivec+1] );
100  return mypos;
101 }
102 
103 void StoreCentralAtomsVessel::addAtomsDerivatives( const unsigned& iatom, const Vector& df, MultiColvarFunction* funcout ) const {
104  plumed_dbg_assert( iatom<mycolv->colvar_atoms.size() );
105 
106  Vector thisder;
107  for(unsigned ider=0;ider<active_atoms[iatom].getNumberActive();++ider){
108  unsigned ibuf=start[iatom] + 1 + 3*ider; thisder.zero();
109  for(unsigned jcomp=0;jcomp<3;++jcomp){
110  thisder[0]+=df[jcomp]*getBufferElement(ibuf);
111  thisder[1]+=df[jcomp]*getBufferElement(ibuf+1);
112  thisder[2]+=df[jcomp]*getBufferElement(ibuf+2);
113  ibuf+=nspace;
114  }
115  unsigned jatom = active_atoms[iatom][ider];
116  funcout->addAtomsDerivatives( jatom, thisder );
117  }
118 }
119 
120 void StoreCentralAtomsVessel::addAtomsDerivativeOfWeight( const unsigned& iatom, const Vector& df, MultiColvarFunction* funcout ) const {
121  plumed_dbg_assert( iatom<mycolv->colvar_atoms.size() );
122 
123  Vector thisder;
124  for(unsigned ider=0;ider<active_atoms[iatom].getNumberActive();++ider){
125  unsigned ibuf=start[iatom] + 1 + 3*ider; thisder.zero();
126  for(unsigned jcomp=0;jcomp<3;++jcomp){
127  thisder[0]+=df[jcomp]*getBufferElement(ibuf);
128  thisder[1]+=df[jcomp]*getBufferElement(ibuf+1);
129  thisder[2]+=df[jcomp]*getBufferElement(ibuf+2);
130  ibuf+=nspace;
131  }
132  unsigned jatom = active_atoms[iatom][ider];
133  funcout->addAtomsDerivativeOfWeight( jatom, thisder );
134  }
135 }
136 
137 void StoreCentralAtomsVessel::addDerivativeOfCentralAtomPos( const unsigned& iatom, const Tensor& df, MultiColvarFunction* funcout ) const {
138  plumed_dbg_assert( iatom<mycolv->colvar_atoms.size() );
139 
140  Tensor thisder;
141  for(unsigned ider=0;ider<active_atoms[iatom].getNumberActive();++ider){
142  unsigned ibuf=start[iatom] + 1 + 3*ider; thisder.zero();
143  for(unsigned jcomp=0;jcomp<3;++jcomp){
144  for(unsigned kcomp=0;kcomp<3;++kcomp){
145  for(unsigned k=0;k<3;++k) thisder(jcomp,kcomp)+=df(jcomp,k)*getBufferElement(ibuf+k*nspace+kcomp);
146  }
147  }
148  unsigned jatom = active_atoms[iatom][ider];
149  funcout->addCentralAtomDerivatives( jatom, thisder );
150  }
151 }
152 
153 
154 }
155 }
std::vector< Tensor > central_derivs
unsigned current
The numerical index of the task we are curently performing.
void addAtomsDerivatives(const int &, const Vector &)
Add some derivatives for an atom.
void addCentralAtomDerivatives(const unsigned &iatom, const Tensor &der)
Add derivative of central atom position wrt to position of iatom'th atom.
void addAtomsDerivativeOfWeight(const unsigned &iatom, const Vector &df, MultiColvarFunction *funcout) const
Add derivatives of the weight wrt to the central atom position.
bool calculate()
This makes sure all vectors are stored.
void resize()
This does the resizing of the buffer.
void mpi_gatherActiveMembers(Communicator &comm, std::vector< DynamicList< U > > &ll)
Definition: DynamicList.h:318
void addToBufferElement(const unsigned &i, const double &val)
Add something to the ith element in the buffer.
Definition: Vessel.h:252
Class implementing fixed size matrices of doubles.
Definition: Tensor.h:70
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
std::vector< DynamicList< unsigned > > active_atoms
void addAtomsDerivatives(const unsigned &iatom, const Vector &df, MultiColvarFunction *funcout) const
Add derivatives to central atom position.
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
void addDerivativeOfCentralAtomPos(const unsigned &iatom, const Tensor &df, MultiColvarFunction *funcout) const
Add derivative to the central atom position.
void const char const char int * n
Definition: Matrix.h:42
DynamicList< unsigned > atomsWithCatomDer
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...
void resizeBuffer(const unsigned &n)
Set the size of the data buffer.
Definition: Vessel.h:221
Vector retrieveCentralAtomPos()
Retrieve the position of the central atom.
This class is used to pass the input to Vessels.
Definition: Vessel.h:53
Vector getPosition(const unsigned &) const
Get the orientation of the ith vector.
StoreCentralAtomsVessel(const vesselbase::VesselOptions &)
Constructor.
This is the abstract base class to use for creating distributions of colvars and functions thereof...
Definition: MultiColvar.h:39
#define CATOMS_MAXATOMS
void int double * da
Definition: Matrix.h:47
void finish()
This should mpi gather the active atoms.
unsigned getNumberOfAtoms() const
Get number of available atoms.
unsigned getNumberActive() const
Return the number of elements that are currently active.
Definition: DynamicList.h:230
void addAtomsDerivativeOfWeight(const unsigned &i, const Vector &wder)
Set the derivative of the weight (used in MEAN and HISTOGRAM)
ActionWithVessel * getAction()
Return a pointer to the action we are working in.
Definition: Vessel.h:236