LCOV - code coverage report
Current view: top level - reference - ReferenceValuePack.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 38 38 100.0 %
Date: 2024-10-11 08:09:47 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2014-2023 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             : 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             : unsigned ReferenceValuePack::getNumberOfDerivatives() const {
     112          44 :   return myvals.getNumberOfDerivatives();
     113             : }
     114             : 
     115             : inline
     116             : unsigned ReferenceValuePack::getNumberOfArguments() const {
     117      172372 :   return numberOfArgs;
     118             : }
     119             : 
     120             : inline
     121             : unsigned ReferenceValuePack::getNumberOfAtoms() const {
     122     2098660 :   return atom_indices.size();
     123             : }
     124             : 
     125             : inline
     126             : void ReferenceValuePack::setAtomIndex( const unsigned& iatom, const unsigned& jindex ) {
     127     2966862 :   plumed_dbg_assert( iatom<atom_indices.size() ); atom_indices[iatom]=jindex;
     128             : }
     129             : 
     130             : inline
     131             : unsigned ReferenceValuePack::getAtomIndex( const unsigned& iatom ) const {
     132             :   plumed_dbg_assert( iatom<atom_indices.size() );
     133     1788696 :   return atom_indices[iatom];
     134             : }
     135             : 
     136             : inline
     137             : void ReferenceValuePack::addArgumentDerivatives( const unsigned& iarg, const double& der ) {
     138             :   plumed_dbg_assert( iarg<numberOfArgs && oind_set ); myvals.addDerivative( oind, iarg, der );
     139             : }
     140             : 
     141             : inline
     142             : void ReferenceValuePack::setArgumentDerivatives( const unsigned& iarg, const double& der ) {
     143      833432 :   plumed_dbg_assert( iarg<numberOfArgs && oind_set ); myvals.setDerivative( oind, iarg, der );
     144             : }
     145             : 
     146             : inline
     147             : bool ReferenceValuePack::updateComplete() const {
     148      520180 :   return myvals.updateComplete();
     149             : }
     150             : 
     151             : inline
     152    17546439 : void ReferenceValuePack::setAtomDerivatives( const unsigned& jder, const Vector& der ) {
     153             :   plumed_dbg_assert( oind_set && jder<atom_indices.size() );
     154    17546439 :   myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 0, der[0] );
     155    17546439 :   myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 1, der[1] );
     156    17546439 :   myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 2, der[2] );
     157    17546439 : }
     158             : 
     159             : inline
     160    16356460 : void ReferenceValuePack::addAtomDerivatives( const unsigned& jder, const Vector& der ) {
     161             :   plumed_dbg_assert( oind_set && jder<atom_indices.size() );
     162    16356460 :   myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 0, der[0] );
     163    16356460 :   myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 1, der[1] );
     164    16356460 :   myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 2, der[2] );
     165    16356460 : }
     166             : 
     167             : inline
     168     8268786 : void ReferenceValuePack::addBoxDerivatives( const Tensor& vir ) {
     169             :   plumed_dbg_assert( oind_set && atom_indices.size()>0 );
     170     8268786 :   boxWasSet=true; unsigned nbase = myvals.getNumberOfDerivatives() - 9;
     171   107494218 :   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     8268786 : }
     173             : 
     174             : inline
     175             : void ReferenceValuePack::setValIndex( const unsigned& ind ) {
     176      255233 :   oind=ind; oind_set=true;
     177             : }
     178             : 
     179             : inline
     180             : bool ReferenceValuePack::virialWasSet() const {
     181      176799 :   return boxWasSet;
     182             : }
     183             : 
     184             : inline
     185    17174456 : Vector ReferenceValuePack::getAtomDerivative( const unsigned& iatom ) const {
     186    17174456 :   Vector tmp; plumed_dbg_assert( oind_set && iatom<atom_indices.size() );
     187    17174456 :   tmp[0]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 0 );
     188    17174456 :   tmp[1]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 1 );
     189    17174456 :   tmp[2]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 2 );
     190    17174456 :   return tmp;
     191             : }
     192             : 
     193             : inline
     194             : double ReferenceValuePack::getArgumentDerivative( const unsigned& ival ) const {
     195             :   plumed_dbg_assert( oind_set && ival<numberOfArgs );
     196       12614 :   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        7800 :   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             : bool ReferenceValuePack::calcUsingPCAOption() const {
     208      219081 :   return pca;
     209             : }
     210             : 
     211             : inline
     212             : void ReferenceValuePack::switchOnPCAOption() {
     213         698 :   pca=true;
     214             : }
     215             : 
     216             : inline
     217             : std::vector<Vector>& ReferenceValuePack::getAtomVector() {
     218    17764910 :   return myvals.getAtomVector();
     219             : }
     220             : 
     221             : inline
     222             : std::vector<Vector>& ReferenceValuePack::getAtomsDisplacementVector() {
     223        3014 :   return displacement;
     224             : }
     225             : 
     226             : }
     227             : 
     228             : #endif

Generated by: LCOV version 1.15