LCOV - code coverage report
Current view: top level - tools - ColvarOutput.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 34 36 94.4 %
Date: 2025-12-04 11:19:34 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2025 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_tools_ColvarOutput_h
      23             : #define __PLUMED_tools_ColvarOutput_h
      24             : 
      25             : #include <vector>
      26             : 
      27             : #include "Pbc.h"
      28             : #include "View.h"
      29             : #include "View2D.h"
      30             : #include "Vector.h"
      31             : #include "Tensor.h"
      32             : 
      33             : namespace PLMD {
      34             : 
      35             : class Colvar;
      36             : 
      37             : class ColvarOutput {
      38             : private:
      39             :   class DerivHelper {
      40             :   private:
      41             :     std::size_t nderivPerComponent;
      42             :     double* derivatives;
      43             :   public:
      44     3591333 :     DerivHelper(double* d, std::size_t n ) : nderivPerComponent(n), derivatives(d) {}
      45             :     View2D<double, helpers::dynamic_extent, 3> operator[](std::size_t i) {
      46             :       //the -9 is to "exclude" the virial (even if tecnically is still accessible)
      47    20389523 :       return { derivatives + i*nderivPerComponent, nderivPerComponent-9 };
      48             :     }
      49             : 
      50     5468582 :     Vector getAtomDerivatives( std::size_t valueID, std::size_t atomID ) {
      51     5468582 :       std::size_t base = valueID*nderivPerComponent + 3*atomID;
      52     5468582 :       return Vector( derivatives[base], derivatives[base+1], derivatives[base+2] );
      53             :     }
      54             : 
      55             :     View<double,3> getView( std::size_t valueID, std::size_t atomID) {
      56           0 :       std::size_t base = valueID*nderivPerComponent + 3*atomID;
      57           0 :       return View<double,3> { derivatives +base};
      58             :     }
      59             :   };
      60             : public:
      61             :   class VirialHelper {
      62             :   private:
      63             :     std::size_t nderivPerComponent;
      64             :     double* derivatives;
      65             :   public:
      66     3591333 :     VirialHelper(double* d, std::size_t n ) : nderivPerComponent(n), derivatives(d) {}
      67    13870175 :     Tensor operator[](std::size_t i) const {
      68    13870175 :       std::size_t n=(i+1)*nderivPerComponent;
      69    13870175 :       return Tensor( derivatives[n-9],
      70    13870175 :                      derivatives[n-8],
      71    13870175 :                      derivatives[n-7],
      72    13870175 :                      derivatives[n-6],
      73    13870175 :                      derivatives[n-5],
      74    13870175 :                      derivatives[n-4],
      75    13870175 :                      derivatives[n-3],
      76    13870175 :                      derivatives[n-2],
      77    13870175 :                      derivatives[n-1] );
      78             :     }
      79             :     View<double,9> getView(std::size_t i) const {
      80       33739 :       std::size_t n=(i+1)*nderivPerComponent-9;
      81       33739 :       return View<double,9> {derivatives+n};
      82             :     }
      83    17830300 :     void set( std::size_t i, const Tensor& v ) {
      84    17830300 :       std::size_t n=(i+1)*nderivPerComponent;
      85    17830300 :       derivatives[n-9]=v[0][0];
      86    17830300 :       derivatives[n-8]=v[0][1];
      87    17830300 :       derivatives[n-7]=v[0][2];
      88    17830300 :       derivatives[n-6]=v[1][0];
      89    17830300 :       derivatives[n-5]=v[1][1];
      90    17830300 :       derivatives[n-4]=v[1][2];
      91    17830300 :       derivatives[n-3]=v[2][0];
      92    17830300 :       derivatives[n-2]=v[2][1];
      93    17830300 :       derivatives[n-1]=v[2][2];
      94    17830300 :     }
      95             :   };
      96             :   std::size_t ncomponents;
      97             :   View<double> values;
      98             :   DerivHelper derivs;
      99             :   VirialHelper virial;
     100             :   ColvarOutput( View<double> v, std::size_t nderivPerComponent, double *derivatives ):
     101     3591333 :     ncomponents(v.size()),
     102     3591333 :     values(v),
     103             :     derivs(derivatives,nderivPerComponent),
     104             :     virial(derivatives,nderivPerComponent)
     105             :   {}
     106             : 
     107             :   static ColvarOutput createColvarOutput( std::vector<double>& v,
     108             :                                           std::vector<double>& d,
     109             :                                           Colvar* action );
     110             : 
     111             :   Vector getAtomDerivatives( std::size_t i, std::size_t a ) {
     112      407259 :     return derivs.getAtomDerivatives(i,a);
     113             :   }
     114             : };
     115             : 
     116             : } //namespace PLMD
     117             : 
     118             : #endif // __PLUMED_tools_ColvarOutput_h

Generated by: LCOV version 1.16