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

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-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_gridtools_GridVessel_h
      23             : #define __PLUMED_gridtools_GridVessel_h
      24             : 
      25             : #include <string>
      26             : #include <cstring>
      27             : #include <vector>
      28             : #include "vesselbase/AveragingVessel.h"
      29             : 
      30             : namespace PLMD {
      31             : namespace gridtools {
      32             : 
      33          44 : class GridVessel : public vesselbase::AveragingVessel {
      34             :   friend class ActionWithInputGrid;
      35             :   friend class DumpGrid;
      36             : private:
      37             : /// Have the minimum and maximum for the grid been set
      38             :   bool bounds_set;
      39             : /// The number of points in the grid
      40             :   unsigned npoints;
      41             : /// Units for Gaussian Cube file
      42             :   double cube_units;
      43             : /// This flag is used to check if the user has created a valid input
      44             :   bool foundprint;
      45             : /// The minimum and maximum of the grid stored as doubles
      46             :   std::vector<double> min, max;
      47             : /// The numerical distance between adjacent grid points
      48             :   std::vector<unsigned> stride;
      49             : /// The number of bins in each grid direction
      50             :   std::vector<unsigned> nbin;
      51             : /// The grid point that was requested last by getGridPointCoordinates
      52             :   unsigned currentGridPoint;
      53             : protected:
      54             : /// Do we have derivatives
      55             :   bool noderiv;
      56             : /// The names of the various columns in the grid file
      57             :   std::vector<std::string> arg_names;
      58             : /// The number of pieces of information we are storing for each
      59             : /// point in the grid
      60             :   unsigned nper;
      61             : /// Is this direction periodic
      62             :   std::vector<bool> pbc;
      63             : /// The minimum and maximum in the grid stored as strings
      64             :   std::vector<std::string> str_min, str_max;
      65             : /// The spacing between grid points
      66             :   std::vector<double> dx;
      67             : /// The dimensionality of the grid
      68             :   unsigned dimension;
      69             : /// Which grid points are we actively accumulating
      70             :   std::vector<bool> active;
      71             : /// Convert a point in space the the correspoinding grid point
      72             :   unsigned getIndex( const std::vector<double>& p ) const ;
      73             : public:
      74             : /// keywords
      75             :   static void registerKeywords( Keywords& keys );
      76             : /// Constructor
      77             :   explicit GridVessel( const vesselbase::VesselOptions& );
      78             : /// Remove the derivatives
      79             :   void setNoDerivatives();
      80             : /// Set the minimum and maximum of the grid
      81             :   virtual void setBounds( const std::vector<std::string>& smin, const std::vector<std::string>& smax, const std::vector<unsigned>& nbins, const std::vector<double>& spacing );
      82             : /// Get a description of the grid to output to the log
      83             :   std::string description();
      84             : /// Convert an index into indices
      85             :   void convertIndexToIndices( const unsigned& index, const std::vector<unsigned>& nnbin, std::vector<unsigned>& indices ) const ;
      86             : ///  Flatten the grid and get the grid index for a point
      87             :   unsigned getIndex( const std::vector<unsigned>& indices ) const ;
      88             : /// Get the indices fof a point
      89             :   void getIndices( const unsigned& index, std::vector<unsigned>& indices ) const ;
      90             : /// Get the indices of a particular point
      91             :   void getIndices( const std::vector<double>& point, std::vector<unsigned>& indices ) const ;
      92             : /// Operations on one of the elements of grid point i
      93             :   void setGridElement( const unsigned&, const unsigned&, const double& );
      94             : /// Add data to an element of the grid
      95             :   void addToGridElement( const unsigned& ipoint, const unsigned& jelement, const double& value );
      96             : /// Operations on one of the elements of grid point specified by vector
      97             :   double getGridElement( const std::vector<unsigned>&, const unsigned& ) const ;
      98             :   void setGridElement( const std::vector<unsigned>&, const unsigned&, const double& );
      99             : /// Set the size of the buffer equal to nper*npoints
     100             :   virtual void resize();
     101             : /// Get the number of points in the grid
     102             :   unsigned getNumberOfPoints() const;
     103             : /// Get the coordinates for a point in the grid
     104             :   void getGridPointCoordinates( const unsigned&, std::vector<double>& ) const ;
     105             : /// Get the dimensionality of the function
     106             :   unsigned getDimension() const ;
     107             : /// Get the number of components in the vector stored on each grid point
     108             :   virtual unsigned getNumberOfComponents() const ;
     109             : /// Is the grid periodic in the ith direction
     110             :   bool isPeriodic( const unsigned& i ) const ;
     111             : /// Get the number of quantities we have stored at each grid point
     112             :   unsigned getNumberOfQuantities() const ;
     113             : /// Get the number of grid points for each dimension
     114             :   std::vector<unsigned> getNbin() const ;
     115             : /// Get the name of the ith component
     116             :   std::string getComponentName( const unsigned& i ) const ;
     117             : /// Get the vector containing the minimum value of the grid in each dimension
     118             :   std::vector<std::string> getMin() const ;
     119             : /// Get the vector containing the maximum value of the grid in each dimension
     120             :   std::vector<std::string> getMax() const ;
     121             : /// Get the number of points needed in the buffer
     122             :   virtual unsigned getNumberOfBufferPoints() const ;
     123             : /// Get the stride (the distance between the grid points of an index)
     124             :   const std::vector<unsigned>& getStride() const ;
     125             : /// Return the volume of one of the grid cells
     126             :   double getCellVolume() const ;
     127             : /// Get the value of the ith grid element
     128             :   virtual double getGridElement( const unsigned&, const unsigned& ) const ;
     129             : /// Get the set of points neighouring a particular location in space
     130             :   void getNeighbors( const std::vector<double>& pp, const std::vector<unsigned>& nneigh,
     131             :                      unsigned& num_neighbours, std::vector<unsigned>& neighbors ) const ;
     132             : /// Get the neighbors for a set of indices of a point
     133             :   void getNeighbors( const std::vector<unsigned>& indices, const std::vector<unsigned>& nneigh,
     134             :                      unsigned& num_neighbors, std::vector<unsigned>& neighbors ) const ;
     135             : /// Get the points neighboring a particular spline point
     136             :   void getSplineNeighbors( const unsigned& mybox, std::vector<unsigned>& mysneigh ) const ;
     137             : /// Get the spacing between grid points
     138             :   const std::vector<double>& getGridSpacing() const ;
     139             : /// Get the extent of the grid in one of the axis
     140             :   double getGridExtent( const unsigned& i ) const ;
     141             : /// Copy data from the action into the grid
     142             :   virtual void calculate( const unsigned& current, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_list ) const ;
     143             : /// This ensures that Gaussian cube fies are in correct units
     144             :   void setCubeUnits( const double& units );
     145             : /// This ensures that Gaussian cube files are in correct units
     146             :   double getCubeUnits() const ;
     147             : /// Return a string containing the input to the grid so we can clone it
     148             :   std::string getInputString() const ;
     149             : /// Does this have derivatives
     150             :   bool noDerivatives() const ;
     151             : /// Get the value and derivatives at a particular location using spline interpolation
     152             :   double getValueAndDerivatives( const std::vector<double>& x, const unsigned& ind, std::vector<double>& der ) const ;
     153             : /// Deactivate all the grid points
     154             :   void activateThesePoints( const std::vector<bool>& to_activate );
     155             : /// Is this point active
     156             :   bool inactive( const unsigned& ip ) const ;
     157             : };
     158             : 
     159             : inline
     160       13561 : unsigned GridVessel::getNumberOfQuantities() const {
     161       13561 :   return nper;
     162             : }
     163             : 
     164             : inline
     165      108208 : unsigned GridVessel::getNumberOfPoints() const {
     166      108208 :   return npoints;
     167             : }
     168             : 
     169             : inline
     170         596 : const std::vector<double>& GridVessel::getGridSpacing() const {
     171         596 :   return dx;
     172             : }
     173             : 
     174             : inline
     175             : double GridVessel::getCellVolume() const {
     176             :   double myvol=1.0; for(unsigned i=0; i<dimension; ++i) myvol *= dx[i];
     177             :   return myvol;
     178             : }
     179             : 
     180             : inline
     181      201913 : unsigned GridVessel::getDimension() const {
     182      201913 :   return dimension;
     183             : }
     184             : 
     185             : inline
     186       77389 : bool GridVessel::isPeriodic( const unsigned& i ) const {
     187       77389 :   return pbc[i];
     188             : }
     189             : 
     190             : inline
     191       24256 : std::string GridVessel::getComponentName( const unsigned& i ) const {
     192       24256 :   return arg_names[i];
     193             : }
     194             : 
     195             : inline
     196          16 : unsigned GridVessel::getNumberOfComponents() const {
     197          16 :   if( noderiv ) return nper;
     198          14 :   return nper / ( dimension + 1 );
     199             : }
     200             : 
     201             : inline
     202          45 : double GridVessel::getGridExtent( const unsigned& i ) const {
     203          45 :   return max[i] - min[i];
     204             : }
     205             : 
     206             : inline
     207        8750 : bool GridVessel::noDerivatives() const {
     208        8750 :   return noderiv;
     209             : }
     210             : 
     211             : inline
     212    15536664 : bool GridVessel::inactive( const unsigned& ip ) const {
     213             :   plumed_dbg_assert( ip<npoints );
     214    15536664 :   return !active[ip];
     215             : }
     216             : 
     217             : inline
     218       16696 : const std::vector<unsigned>& GridVessel::getStride() const {
     219       16696 :   return stride;
     220             : }
     221             : 
     222             : inline
     223          93 : unsigned GridVessel::getNumberOfBufferPoints() const {
     224          93 :   return npoints;
     225             : }
     226             : 
     227             : }
     228             : }
     229             : #endif

Generated by: LCOV version 1.13