LCOV - code coverage report
Current view: top level - gridtools - GridCoordinatesObject.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 8 10 80.0 %
Date: 2024-10-18 13:59:31 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-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_gridtools_GridCoordinatesObject_h
      23             : #define __PLUMED_gridtools_GridCoordinatesObject_h
      24             : 
      25             : #include <string>
      26             : #include <cstring>
      27             : #include <vector>
      28             : #include "tools/Exception.h"
      29             : #include "tools/Tools.h"
      30             : 
      31             : namespace PLMD {
      32             : namespace gridtools {
      33             : 
      34             : class GridCoordinatesObject {
      35             : private:
      36             : /// Have the bounds been setup on the grid
      37             :   bool bounds_set;
      38             : /// The way that grid points are constructed
      39             :   enum {flat,fibonacci} gtype;
      40             : /// The number of points in the grid
      41             :   unsigned npoints;
      42             : /// Stuff for fibonacci grids
      43             :   double root5, golden, igolden, log_golden2;
      44             : /// Fib increment here is equal to 2*pi*(INVERSE GOLDEN RATIO)
      45             :   double fib_offset, fib_increment, fib_shift;
      46             :   std::vector<std::vector<unsigned> > fib_nlist;
      47             : /// The minimum and maximum of the grid stored as doubles
      48             :   std::vector<double> min, max;
      49             : /// The numerical distance between adjacent grid points
      50             :   std::vector<unsigned> stride;
      51             : /// The number of bins in each grid direction
      52             :   std::vector<unsigned> nbin;
      53             : /// Is this direction periodic
      54             :   std::vector<bool> pbc;
      55             : /// The minimum and maximum in the grid stored as strings
      56             :   std::vector<std::string> str_min, str_max;
      57             : /// The spacing between grid points
      58             :   std::vector<double> dx;
      59             : /// The dimensionality of the grid
      60             :   unsigned dimension;
      61             : /// Get the index of the closest point on the fibonacci sphere
      62             :   unsigned getFibonacciIndex( const std::vector<double>& p ) const ;
      63             : /// Get the flat grid coordinates
      64             :   void getFlatGridCoordinates( const unsigned& ipoint, std::vector<unsigned>& tindices, std::vector<double>& x ) const ;
      65             : /// Get the coordinates on the Fibonacci grid
      66             :   void getFibonacciCoordinates( const unsigned& ipoint, std::vector<double>& x ) const ;
      67             : public:
      68             : /// Setup the grid
      69             :   void setup( const std::string& geom, const std::vector<bool>& ipbc, const unsigned& np, const double& fib_cutoff );
      70             : /// Set the minimum and maximum of the grid
      71             :   void setBounds( const std::vector<std::string>& smin, const std::vector<std::string>& smax, const std::vector<unsigned>& nbins, std::vector<double>& spacing );
      72             : /// Convert an index into indices
      73             :   void convertIndexToIndices( const unsigned& index, const std::vector<unsigned>& nnbin, std::vector<unsigned>& indices ) const ;
      74             : /// Check if a point is within the grid boundaries
      75             :   bool inbounds( const std::vector<double>& point ) const ;
      76             : /// Convert a point in space the the correspoinding grid point
      77             :   unsigned getIndex( const std::vector<double>& p ) const ;
      78             : ///  Flatten the grid and get the grid index for a point
      79             :   unsigned getIndex( const std::vector<unsigned>& indices ) const ;
      80             : /// Get the indices fof a point
      81             :   void getIndices( const unsigned& index, std::vector<unsigned>& indices ) const ;
      82             : /// Get the indices of a particular point
      83             :   void getIndices( const std::vector<double>& point, std::vector<unsigned>& indices ) const ;
      84             : /// Get the number of points in the grid
      85             :   unsigned getNumberOfPoints() const;
      86             : /// Get the coordinates for a point in the grid
      87             :   void getGridPointCoordinates( const unsigned&, std::vector<double>& ) const ;
      88             :   void getGridPointCoordinates( const unsigned&, std::vector<unsigned>&, std::vector<double>& ) const ;
      89             : /// Create a coordinate that has this value of the grid
      90             :   void putCoordinateAtValue( const unsigned&, const double&, std::vector<double>& ) const ;
      91             : /// Get the dimensionality of the function
      92             :   unsigned getDimension() const ;
      93             : /// Is the grid periodic in the ith direction
      94             :   bool isPeriodic( const unsigned& i ) const ;
      95             : /// Get the number of grid points for each dimension
      96             :   std::vector<unsigned> getNbin( const bool& shape ) const ;
      97             : /// Get the vector containing the minimum value of the grid in each dimension
      98             :   std::vector<std::string> getMin() const ;
      99             : /// Get the vector containing the maximum value of the grid in each dimension
     100             :   std::vector<std::string> getMax() const ;
     101             : /// Return the volume of one of the grid cells
     102             :   double getCellVolume() const ;
     103             : /// Get the set of points neighouring a particular location in space
     104             :   void getNeighbors( const std::vector<double>& pp, const std::vector<unsigned>& nneigh,
     105             :                      unsigned& num_neighbours, std::vector<unsigned>& neighbors ) const ;
     106             : /// Get the neighbors for a set of indices of a point
     107             :   void getNeighbors( const std::vector<unsigned>& indices, const std::vector<unsigned>& nneigh,
     108             :                      unsigned& num_neighbors, std::vector<unsigned>& neighbors ) const ;
     109             : /// Get the points neighboring a particular spline point
     110             :   void getSplineNeighbors( const unsigned& mybox, unsigned& nneighbors, std::vector<unsigned>& mysneigh ) const ;
     111             : /// Get the spacing between grid points
     112             :   const std::vector<double>& getGridSpacing() const ;
     113             : /// Get the stride (the distance between the grid points of an index)
     114             :   const std::vector<unsigned>& getStride() const ;
     115             : /// Get the type of the grid
     116             :   std::string getGridType() const ;
     117             : };
     118             : 
     119             : inline
     120             : unsigned GridCoordinatesObject::getNumberOfPoints() const {
     121      544597 :   return npoints;
     122             : }
     123             : 
     124             : inline
     125     5000599 : const std::vector<double>& GridCoordinatesObject::getGridSpacing() const {
     126     5000599 :   if( gtype==flat ) return dx;
     127           0 :   plumed_merror("dont understand what spacing means for spherical grids");
     128             :   return dx;
     129             : }
     130             : 
     131             : inline
     132             : double GridCoordinatesObject::getCellVolume() const {
     133             :   if( gtype==flat ) {
     134             :     double myvol=1.0; for(unsigned i=0; i<dimension; ++i) myvol *= dx[i];
     135             :     return myvol;
     136             :   } else {
     137             :     return 4*pi / static_cast<double>( getNumberOfPoints() );
     138             :   }
     139             : }
     140             : 
     141             : inline
     142             : unsigned GridCoordinatesObject::getDimension() const {
     143     2506946 :   return dimension;
     144             : }
     145             : 
     146             : inline
     147             : bool GridCoordinatesObject::isPeriodic( const unsigned& i ) const {
     148             :   plumed_dbg_assert( gtype==flat );
     149       16844 :   return pbc[i];
     150             : }
     151             : 
     152             : inline
     153             : const std::vector<unsigned>& GridCoordinatesObject::getStride() const {
     154             :   plumed_dbg_assert( gtype==flat );
     155             :   return stride;
     156             : }
     157             : 
     158             : inline
     159      214508 : std::string GridCoordinatesObject::getGridType() const {
     160      214508 :   if( gtype==flat ) return "flat";
     161         656 :   else if( gtype==fibonacci ) return "fibonacci";
     162           0 :   return "";
     163             : }
     164             : 
     165             : }
     166             : }
     167             : #endif

Generated by: LCOV version 1.16