LCOV - code coverage report
Current view: top level - reference - ReferenceValuePack.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 57 60 95.0 %
Date: 2018-12-19 07:49:13 Functions: 20 21 95.2 %

          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_reference_ReferenceValuePack_h
      23             : #define __PLUMED_reference_ReferenceValuePack_h
      24             : 
      25             : #include "tools/MultiValue.h"
      26             : 
      27             : namespace PLMD {
      28             : 
      29      162838 : class ReferenceValuePack {
      30             :   friend class MultiDomainRMSD;
      31             :   friend class OptimalRMSD;
      32             : private:
      33             : /// Was the virial set
      34             :   bool boxWasSet;
      35             : ///
      36             :   unsigned numberOfArgs;
      37             : ///
      38             :   bool oind_set;
      39             :   unsigned oind;
      40             : /// Copy of the values that we are adding to
      41             :   MultiValue& myvals;
      42             : /// Ths list of atom indices
      43             :   std::vector<unsigned>& atom_indices;
      44             : /// Are we using pca
      45             :   bool pca;
      46             : /// A vector of vectors to save us some overhead for vector resizes
      47             :   std::vector<Vector> centeredpos;
      48             : ///
      49             :   std::vector<Vector> displacement;
      50             : ///
      51             :   std::vector<Tensor> rot;
      52             : ///
      53             :   Matrix< std::vector<Vector> >  DRotDPos;
      54             : public:
      55             :   ReferenceValuePack( const unsigned& nargs, const unsigned& natoms, MultiValue& vals );
      56             : ///
      57             :   void resize( const unsigned& nargs, const unsigned& natoms );
      58             : ///
      59             :   void clear();
      60             : ///
      61             :   unsigned getNumberOfDerivatives() const ;
      62             : ///
      63             :   unsigned getNumberOfArguments() const ;
      64             : ///
      65             :   unsigned getNumberOfAtoms() const ;
      66             : ///
      67             :   void setAtomIndex( const unsigned& iatom, const unsigned& jindex );
      68             : ///
      69             :   unsigned getAtomIndex( const unsigned& iatom ) const ;
      70             : ///
      71             :   void copyScaledDerivatives( const unsigned& from, const double& scalef, const MultiValue& tvals );
      72             : ///
      73             :   void addArgumentDerivatives( const unsigned& iarg, const double& der );
      74             : ///
      75             :   void setArgumentDerivatives( const unsigned& iarg, const double& der );
      76             : ///
      77             :   void setAtomDerivatives( const unsigned& jder, const Vector& der );
      78             : ///
      79             :   void addAtomDerivatives( const unsigned& iatom, const Vector& der );
      80             : ///
      81             :   void addBoxDerivatives( const Tensor& vir );
      82             : ///
      83             :   bool updateComplete() const ;
      84             : ///
      85             :   void updateDynamicLists();
      86             : ///
      87             :   void scaleAllDerivatives( const double& scalef );
      88             : ///
      89             :   void setValIndex( const unsigned& ind );
      90             : ///
      91             :   void moveDerivatives( const unsigned& from, const unsigned& to );
      92             : ///
      93             :   bool virialWasSet() const ;
      94             : ///
      95             :   Vector getAtomDerivative( const unsigned& iatom ) const ;
      96             : ///
      97             :   double getArgumentDerivative( const unsigned& ival ) const ;
      98             : ///
      99             :   Tensor getBoxDerivatives() const ;
     100             : ///
     101             :   bool calcUsingPCAOption() const ;
     102             : ///
     103             :   void switchOnPCAOption();
     104             : ///
     105             :   std::vector<Vector>& getAtomVector();
     106             : ///
     107             :   std::vector<Vector>& getAtomsDisplacementVector();
     108             : };
     109             : 
     110             : inline
     111          44 : unsigned ReferenceValuePack::getNumberOfDerivatives() const {
     112          44 :   return myvals.getNumberOfDerivatives();
     113             : }
     114             : 
     115             : inline
     116      114304 : unsigned ReferenceValuePack::getNumberOfArguments() const {
     117      114304 :   return numberOfArgs;
     118             : }
     119             : 
     120             : inline
     121     1718712 : unsigned ReferenceValuePack::getNumberOfAtoms() const {
     122     1718712 :   return atom_indices.size();
     123             : }
     124             : 
     125             : inline
     126     2660399 : void ReferenceValuePack::setAtomIndex( const unsigned& iatom, const unsigned& jindex ) {
     127     2660399 :   plumed_dbg_assert( iatom<atom_indices.size() ); atom_indices[iatom]=jindex;
     128     2665401 : }
     129             : 
     130             : inline
     131     1489979 : unsigned ReferenceValuePack::getAtomIndex( const unsigned& iatom ) const {
     132             :   plumed_dbg_assert( iatom<atom_indices.size() );
     133     1489979 :   return atom_indices[iatom];
     134             : }
     135             : 
     136             : inline
     137           0 : void ReferenceValuePack::addArgumentDerivatives( const unsigned& iarg, const double& der ) {
     138           0 :   plumed_dbg_assert( iarg<numberOfArgs && oind_set ); myvals.addDerivative( oind, iarg, der );
     139           0 : }
     140             : 
     141             : inline
     142       21982 : void ReferenceValuePack::setArgumentDerivatives( const unsigned& iarg, const double& der ) {
     143       21982 :   plumed_dbg_assert( iarg<numberOfArgs && oind_set ); myvals.setDerivative( oind, iarg, der );
     144       21982 : }
     145             : 
     146             : inline
     147      203854 : bool ReferenceValuePack::updateComplete() const {
     148      203854 :   return myvals.updateComplete();
     149             : }
     150             : 
     151             : inline
     152    17216910 : void ReferenceValuePack::setAtomDerivatives( const unsigned& jder, const Vector& der ) {
     153             :   plumed_dbg_assert( oind_set && jder<atom_indices.size() );
     154    17216910 :   myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 0, der[0] );
     155    17218019 :   myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 1, der[1] );
     156    17217634 :   myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 2, der[2] );
     157    17217562 : }
     158             : 
     159             : inline
     160    16205326 : void ReferenceValuePack::addAtomDerivatives( const unsigned& jder, const Vector& der ) {
     161             :   plumed_dbg_assert( oind_set && jder<atom_indices.size() );
     162    16205326 :   myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 0, der[0] );
     163    16211580 :   myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 1, der[1] );
     164    16209176 :   myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 2, der[2] );
     165    16206994 : }
     166             : 
     167             : inline
     168     8245641 : void ReferenceValuePack::addBoxDerivatives( const Tensor& vir ) {
     169             :   plumed_dbg_assert( oind_set && atom_indices.size()>0 );
     170     8245641 :   boxWasSet=true; unsigned nbase = myvals.getNumberOfDerivatives() - 9;
     171     8260851 :   for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) myvals.addDerivative( oind, nbase + 3*i + j, vir(i,j) );
     172     8243666 : }
     173             : 
     174             : inline
     175      195894 : void ReferenceValuePack::setValIndex( const unsigned& ind ) {
     176      195894 :   oind=ind; oind_set=true;
     177      195894 : }
     178             : 
     179             : inline
     180      153388 : bool ReferenceValuePack::virialWasSet() const {
     181      153388 :   return boxWasSet;
     182             : }
     183             : 
     184             : inline
     185    16839807 : Vector ReferenceValuePack::getAtomDerivative( const unsigned& iatom ) const {
     186    16839807 :   Vector tmp; plumed_dbg_assert( oind_set && iatom<atom_indices.size() );
     187    16839702 :   tmp[0]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 0 );
     188    16840161 :   tmp[1]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 1 );
     189    16840212 :   tmp[2]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 2 );
     190    16840561 :   return tmp;
     191             : }
     192             : 
     193             : inline
     194        4366 : double ReferenceValuePack::getArgumentDerivative( const unsigned& ival ) const {
     195             :   plumed_dbg_assert( oind_set && ival<numberOfArgs );
     196        4366 :   return myvals.getDerivative( oind, ival );
     197             : }
     198             : 
     199             : inline
     200         600 : Tensor ReferenceValuePack::getBoxDerivatives() const {
     201         600 :   plumed_dbg_assert( oind_set && boxWasSet ); Tensor tvir; unsigned nbase = myvals.getNumberOfDerivatives() - 9;
     202         600 :   for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) tvir(i,j)=myvals.getDerivative( oind, nbase + 3*i + j );
     203         600 :   return tvir;
     204             : }
     205             : 
     206             : inline
     207      191767 : bool ReferenceValuePack::calcUsingPCAOption() const {
     208      191767 :   return pca;
     209             : }
     210             : 
     211             : inline
     212         138 : void ReferenceValuePack::switchOnPCAOption() {
     213         138 :   pca=true;
     214         138 : }
     215             : 
     216             : inline
     217    17409774 : std::vector<Vector>& ReferenceValuePack::getAtomVector() {
     218    17409774 :   return myvals.getAtomVector();
     219             : }
     220             : 
     221             : inline
     222     2453588 : std::vector<Vector>& ReferenceValuePack::getAtomsDisplacementVector() {
     223     2453588 :   return displacement;
     224             : }
     225             : 
     226             : }
     227             : 
     228             : #endif

Generated by: LCOV version 1.13