LCOV - code coverage report
Current view: top level - multicolvar - AtomValuePack.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 51 51 100.0 %
Date: 2018-12-19 07:49:13 Functions: 17 17 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2014-2018 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.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       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_multicolvar_AtomValuePack_h
      23             : #define __PLUMED_multicolvar_AtomValuePack_h
      24             : 
      25             : #include "tools/MultiValue.h"
      26             : #include "MultiColvarBase.h"
      27             : 
      28             : namespace PLMD {
      29             : 
      30             : class LinkCells;
      31             : 
      32             : namespace multicolvar {
      33             : 
      34             : class CatomPack;
      35             : 
      36             : class AtomValuePack {
      37             :   friend class MultiColvarBase;
      38             :   friend class LocalAverage;
      39             : private:
      40             : /// Copy of the values that we are adding to
      41             :   MultiValue& myvals;
      42             : /// Copy of the underlying multicolvar
      43             :   MultiColvarBase const * mycolv;
      44             : /// Number of atoms at the moment
      45             :   unsigned natoms;
      46             : /// Atom indices
      47             :   std::vector<unsigned>& indices;
      48             : /// This is used to sort the atom indices
      49             :   std::vector<unsigned>& sort_vector;
      50             : /// This holds atom positions
      51             :   std::vector<Vector>& myatoms;
      52             : ///
      53             :   void addDerivative( const unsigned&, const unsigned&, const double& );
      54             : ///
      55             :   void addAtomsDerivatives( const unsigned&, const unsigned&, const Vector& );
      56             : ///
      57             :   void addTemporyAtomsDerivatives( const unsigned& jder, const Vector& der );
      58             : public:
      59             :   AtomValuePack( MultiValue& vals, MultiColvarBase const * mcolv );
      60             : /// Set the number of atoms
      61             :   void setNumberOfAtoms( const unsigned& );
      62             : /// Set the index for one of the atoms
      63             :   void setIndex( const unsigned&, const unsigned& );
      64             : ///
      65             :   void setAtomIndex( const unsigned& j, const unsigned& ind );
      66             : ///
      67             :   void setAtom( const unsigned& j, const unsigned& ind );
      68             : ///
      69             :   unsigned setupAtomsFromLinkCells( const std::vector<unsigned>& cind, const Vector& cpos, const LinkCells& linkcells );
      70             : ///
      71             :   unsigned getIndex( const unsigned& j ) const ;
      72             : ///
      73             :   unsigned getNumberOfAtoms() const ;
      74             : ///
      75             :   unsigned getNumberOfDerivatives() const ;
      76             : /// Get the position of the ith atom
      77             :   Vector& getPosition( const unsigned& );
      78             : ///
      79             :   void setValue( const unsigned&, const double& );
      80             : ///
      81             :   void addValue( const unsigned& ival, const double& vv );
      82             : ///
      83             :   double getValue( const unsigned& ) const ;
      84             : ///
      85             :   void addBoxDerivatives( const unsigned&, const Tensor& );
      86             : ///
      87             :   void addTemporyBoxDerivatives( const Tensor& vir );
      88             : ///
      89             :   void updateUsingIndices();
      90             : ///
      91             :   void updateDynamicList();
      92             : ///
      93             :   void addComDerivatives( const int&, const Vector&, CatomPack& );
      94             : ///
      95             :   MultiValue& getUnderlyingMultiValue();
      96             : };
      97             : 
      98             : inline
      99      232072 : void AtomValuePack::setNumberOfAtoms( const unsigned& nat ) {
     100      232072 :   natoms=nat;
     101      232072 : }
     102             : 
     103             : inline
     104    13120755 : unsigned AtomValuePack::getNumberOfAtoms() const {
     105    13120755 :   return natoms;
     106             : }
     107             : 
     108             : inline
     109         100 : unsigned AtomValuePack::getNumberOfDerivatives() const {
     110         100 :   return myvals.getNumberOfDerivatives();
     111             : }
     112             : 
     113             : inline
     114             : void AtomValuePack::setIndex( const unsigned& j, const unsigned& ind ) {
     115             :   plumed_dbg_assert( j<natoms ); indices[j]=ind;
     116             : }
     117             : 
     118             : inline
     119      580194 : void AtomValuePack::setAtomIndex( const unsigned& j, const unsigned& ind ) {
     120      580194 :   plumed_dbg_assert( j<natoms ); indices[j]=ind;
     121      580364 : }
     122             : 
     123             : inline
     124      554528 : void AtomValuePack::setAtom( const unsigned& j, const unsigned& ind ) {
     125      554528 :   setAtomIndex( j, ind ); myatoms[j]=mycolv->getPositionOfAtomForLinkCells( ind );
     126      554833 : }
     127             : 
     128             : inline
     129   125825812 : unsigned AtomValuePack::getIndex( const unsigned& j ) const {
     130   125825812 :   plumed_dbg_assert( j<natoms ); return indices[j];
     131             : }
     132             : 
     133             : inline
     134    15951473 : Vector& AtomValuePack::getPosition( const unsigned& iatom ) {
     135             :   plumed_dbg_assert( iatom<natoms );
     136    15951473 :   return myatoms[iatom];
     137             : }
     138             : 
     139             : inline
     140      642539 : void AtomValuePack::setValue( const unsigned& ival, const double& vv ) {
     141      642539 :   myvals.setValue( ival, vv );
     142      642689 : }
     143             : 
     144             : inline
     145    56323659 : void AtomValuePack::addValue( const unsigned& ival, const double& vv ) {
     146    56323659 :   myvals.addValue( ival, vv );
     147    56323065 : }
     148             : 
     149             : inline
     150     4642757 : double AtomValuePack::getValue( const unsigned& ival ) const {
     151     4642757 :   return myvals.get( ival );
     152             : }
     153             : 
     154             : inline
     155    60782592 : void AtomValuePack::addDerivative( const unsigned& ival, const unsigned& jder, const double& der ) {
     156    60782592 :   myvals.addDerivative( ival, jder, der );
     157    60782592 : }
     158             : 
     159             : inline
     160   101655360 : void AtomValuePack::addAtomsDerivatives( const unsigned& ival, const unsigned& jder, const Vector& der ) {
     161             :   plumed_dbg_assert( jder<natoms );
     162   101655360 :   myvals.addDerivative( ival, 3*indices[jder] + 0, der[0] );
     163   101658279 :   myvals.addDerivative( ival, 3*indices[jder] + 1, der[1] );
     164   101657005 :   myvals.addDerivative( ival, 3*indices[jder] + 2, der[2] );
     165   101656581 : }
     166             : 
     167             : inline
     168     4371940 : void AtomValuePack::addTemporyAtomsDerivatives( const unsigned& jder, const Vector& der ) {
     169             :   plumed_dbg_assert( jder<natoms );
     170     4371940 :   myvals.addTemporyDerivative( 3*indices[jder] + 0, der[0] );
     171     4371976 :   myvals.addTemporyDerivative( 3*indices[jder] + 1, der[1] );
     172     4371976 :   myvals.addTemporyDerivative( 3*indices[jder] + 2, der[2] );
     173     4371978 : }
     174             : 
     175             : inline
     176     2203667 : void AtomValuePack::addTemporyBoxDerivatives( const Tensor& vir ) {
     177     2203667 :   unsigned nvir=3*mycolv->getNumberOfAtoms();
     178     2203666 :   for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) myvals.addTemporyDerivative( nvir + 3*i+j, vir(i,j) );
     179     2203669 : }
     180             : 
     181             : inline
     182    50912166 : void AtomValuePack::addBoxDerivatives( const unsigned& ival, const Tensor& vir ) {
     183    50912166 :   unsigned nvir=3*mycolv->getNumberOfAtoms();
     184    50908210 :   for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) myvals.addDerivative( ival, nvir + 3*i+j, vir(i,j) );
     185    50911351 : }
     186             : 
     187             : inline
     188      137920 : void AtomValuePack::updateDynamicList() {
     189      275840 :   if( myvals.updateComplete() ) return;
     190      137483 :   myvals.updateDynamicList();
     191             : }
     192             : 
     193             : inline
     194     4453822 : MultiValue& AtomValuePack::getUnderlyingMultiValue() {
     195     4453822 :   return myvals;
     196             : }
     197             : 
     198             : }
     199             : }
     200             : #endif
     201             : 

Generated by: LCOV version 1.13