LCOV - code coverage report
Current view: top level - tools - Pbc.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 3 5 60.0 %
Date: 2018-12-19 07:49:13 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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_tools_Pbc_h
      23             : #define __PLUMED_tools_Pbc_h
      24             : 
      25             : #include "Vector.h"
      26             : #include "Tensor.h"
      27             : #include <vector>
      28             : #include <cstddef>
      29             : 
      30             : namespace PLMD {
      31             : 
      32             : /*
      33             : Tool to deal with periodic boundary conditions.
      34             : 
      35             : This class is useful to apply periodic boundary conditions on interatomic
      36             : distances. It stores privately information about reduced lattice vectors
      37             : */
      38       59204 : class Pbc {
      39             : /// Type of box
      40             :   enum {unset,orthorombic,generic} type;
      41             : /// Box
      42             :   Tensor box;
      43             : /// Inverse box
      44             :   Tensor invBox;
      45             : /// Reduced box.
      46             : /// This is a set of lattice vectors generating the same lattice
      47             : /// but "minimally skewed". Useful to optimize image search.
      48             :   Tensor reduced;
      49             : /// Inverse of the reduced box
      50             :   Tensor invReduced;
      51             : /// List of shifts that should be attempted.
      52             : /// Depending on the sign of the scaled coordinates representing
      53             : /// a distance vector, a different set of shifts must be tried.
      54             :   std::vector<Vector> shifts[2][2][2];
      55             : /// Alternative representation for orthorombic cells.
      56             : /// Not really used, but could be used to optimize search in
      57             : /// orthorombic cells.
      58             :   Vector diag,hdiag,mdiag;
      59             : /// Build list of shifts.
      60             : /// This is expensive, and must be called only when box is
      61             : /// reset. It allows building a minimal set of shifts
      62             : /// depending on the sign of the scaled coordinates representing
      63             : /// a distance vector.
      64             :   void buildShifts(std::vector<Vector> shifts[2][2][2])const;
      65             : public:
      66             : /// Perform some check. Useful for debugging.
      67             :   static void test();
      68             : /// Constructor
      69             :   Pbc();
      70             : /// Compute modulo of (v2-v1), using or not pbc depending on bool pbc.
      71             :   double distance( const bool pbc, const Vector& v1, const Vector& v2 ) const;
      72             : /// Computes v2-v1, using minimal image convention
      73             :   Vector distance(const Vector& v1,const Vector& v2)const;
      74             : /// version of distance which also returns the number
      75             : /// of attempted shifts
      76             :   Vector distance(const Vector&,const Vector&,int*nshifts)const;
      77             : /// Apply PBC to a set of positions or distance vectors
      78             :   void apply(std::vector<Vector>&dlist, unsigned max_index=0) const;
      79             : /// Set the lattice vectors.
      80             : /// b[i][j] is the j-th component of the i-th vector
      81             :   void setBox(const Tensor&b);
      82             : /// Returns the box
      83             :   const Tensor& getBox()const;
      84             : /// Returns the inverse matrix of box.
      85             : /// Thus: pbc.getInvBox() == inverse(pbc.getBox()).
      86             :   const Tensor& getInvBox()const;
      87             : /// Transform a vector in real space to a vector in scaled coordinates.
      88             : /// Thus:pbc.realToScaled(v) == matmul(transpose(inverse(pbc.getBox(),v)));
      89             :   Vector realToScaled(const Vector&)const;
      90             : /// Transform a vector in scaled coordinates to a vector in real space.
      91             : /// Thus:pbc.scaledToRead(v) == matmul(transpose(pbc.getBox()),v);
      92             :   Vector scaledToReal(const Vector&)const;
      93             : /// Returns true if the box vectors are orthogonal
      94             :   bool isOrthorombic()const;
      95             : /// Full search (for testing).
      96             : /// Perform a full search on vector
      97             :   void fullSearch(Vector&)const;
      98             : /// Returns true if box is set and non zero
      99             :   bool isSet()const;
     100             : };
     101             : 
     102             : inline
     103    16697358 : Vector Pbc::distance(const Vector& v1,const Vector& v2)const {
     104    16697358 :   return distance(v1,v2,NULL);
     105             : }
     106             : 
     107             : inline
     108           0 : bool Pbc::isSet()const {
     109           0 :   return type!=unset;
     110             : }
     111             : 
     112             : }
     113             : 
     114             : #endif

Generated by: LCOV version 1.13