LCOV - code coverage report
Current view: top level - reference - ReferenceValuePack.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 45 45 100.0 %
Date: 2026-03-30 13:16:06 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             :   plumed_dbg_assert( iatom<atom_indices.size() );
     128     4424160 :   atom_indices[iatom]=jindex;
     129             : }
     130             : 
     131             : inline
     132             : unsigned ReferenceValuePack::getAtomIndex( const unsigned& iatom ) const {
     133             :   plumed_dbg_assert( iatom<atom_indices.size() );
     134     1788696 :   return atom_indices[iatom];
     135             : }
     136             : 
     137             : inline
     138             : void ReferenceValuePack::addArgumentDerivatives( const unsigned& iarg, const double& der ) {
     139             :   plumed_dbg_assert( iarg<numberOfArgs && oind_set );
     140             :   myvals.addDerivative( oind, iarg, der );
     141             : }
     142             : 
     143             : inline
     144             : void ReferenceValuePack::setArgumentDerivatives( const unsigned& iarg, const double& der ) {
     145             :   plumed_dbg_assert( iarg<numberOfArgs && oind_set );
     146      833432 :   myvals.setDerivative( oind, iarg, der );
     147             : }
     148             : 
     149             : inline
     150             : bool ReferenceValuePack::updateComplete() const {
     151      574780 :   return myvals.updateComplete();
     152             : }
     153             : 
     154             : inline
     155    19185555 : void ReferenceValuePack::setAtomDerivatives( const unsigned& jder, const Vector& der ) {
     156             :   plumed_dbg_assert( oind_set && jder<atom_indices.size() );
     157    19185555 :   myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 0, der[0] );
     158    19185555 :   myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 1, der[1] );
     159    19185555 :   myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 2, der[2] );
     160    19185555 : }
     161             : 
     162             : inline
     163    31174516 : void ReferenceValuePack::addAtomDerivatives( const unsigned& jder, const Vector& der ) {
     164             :   plumed_dbg_assert( oind_set && jder<atom_indices.size() );
     165    31174516 :   myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 0, der[0] );
     166    31174516 :   myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 1, der[1] );
     167    31174516 :   myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 2, der[2] );
     168    31174516 : }
     169             : 
     170             : inline
     171    15714222 : void ReferenceValuePack::addBoxDerivatives( const Tensor& vir ) {
     172             :   plumed_dbg_assert( oind_set && atom_indices.size()>0 );
     173    15714222 :   boxWasSet=true;
     174    15714222 :   unsigned nbase = myvals.getNumberOfDerivatives() - 9;
     175    62856888 :   for(unsigned i=0; i<3; ++i)
     176   188570664 :     for(unsigned j=0; j<3; ++j) {
     177   141427998 :       myvals.addDerivative( oind, nbase + 3*i + j, vir(i,j) );
     178             :     }
     179    15714222 : }
     180             : 
     181             : inline
     182             : void ReferenceValuePack::setValIndex( const unsigned& ind ) {
     183      364433 :   oind=ind;
     184      364433 :   oind_set=true;
     185             : }
     186             : 
     187             : inline
     188             : bool ReferenceValuePack::virialWasSet() const {
     189      225351 :   return boxWasSet;
     190             : }
     191             : 
     192             : inline
     193    18268172 : Vector ReferenceValuePack::getAtomDerivative( const unsigned& iatom ) const {
     194    18268172 :   Vector tmp;
     195             :   plumed_dbg_assert( oind_set && iatom<atom_indices.size() );
     196    18268172 :   tmp[0]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 0 );
     197    18268172 :   tmp[1]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 1 );
     198    18268172 :   tmp[2]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 2 );
     199    18268172 :   return tmp;
     200             : }
     201             : 
     202             : inline
     203             : double ReferenceValuePack::getArgumentDerivative( const unsigned& ival ) const {
     204             :   plumed_dbg_assert( oind_set && ival<numberOfArgs );
     205       12614 :   return myvals.getDerivative( oind, ival );
     206             : }
     207             : 
     208             : inline
     209         600 : Tensor ReferenceValuePack::getBoxDerivatives() const {
     210             :   plumed_dbg_assert( oind_set && boxWasSet );
     211         600 :   Tensor tvir;
     212         600 :   unsigned nbase = myvals.getNumberOfDerivatives() - 9;
     213        2400 :   for(unsigned i=0; i<3; ++i)
     214        7200 :     for(unsigned j=0; j<3; ++j) {
     215        5400 :       tvir(i,j)=myvals.getDerivative( oind, nbase + 3*i + j );
     216             :     }
     217         600 :   return tvir;
     218             : }
     219             : 
     220             : inline
     221             : bool ReferenceValuePack::calcUsingPCAOption() const {
     222      273669 :   return pca;
     223             : }
     224             : 
     225             : inline
     226             : void ReferenceValuePack::switchOnPCAOption() {
     227         698 :   pca=true;
     228             : }
     229             : 
     230             : inline
     231             : std::vector<Vector>& ReferenceValuePack::getAtomVector() {
     232    19458614 :   return myvals.getAtomVector();
     233             : }
     234             : 
     235             : inline
     236             : std::vector<Vector>& ReferenceValuePack::getAtomsDisplacementVector() {
     237        3026 :   return displacement;
     238             : }
     239             : 
     240             : }
     241             : 
     242             : #endif

Generated by: LCOV version 1.16