LCOV - code coverage report
Current view: top level - analysis - AverageVessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 22 24 91.7 %
Date: 2020-11-18 11:20:57 Functions: 7 8 87.5 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-2019 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             : #include "AverageVessel.h"
      23             : 
      24             : namespace PLMD {
      25             : namespace analysis {
      26             : 
      27           2 : void AverageVessel::registerKeywords( Keywords& keys ) {
      28           2 :   vesselbase::AveragingVessel::registerKeywords( keys );
      29           8 :   keys.add("optional","PERIODIC","is the quantity being averaged periodic and what is its domain");
      30           2 : }
      31             : 
      32           2 : AverageVessel::AverageVessel( const vesselbase::VesselOptions& da):
      33           2 :   AveragingVessel(da)
      34             : {
      35           4 :   parseVector("PERIODIC",domain);
      36           2 :   plumed_assert( domain.size()==2 || domain.size()==0 );
      37           2 : }
      38             : 
      39           2 : void AverageVessel::resize() {
      40             :   resizeBuffer(0);
      41           2 :   if( domain.size()==2 ) setDataSize(2);
      42           1 :   else setDataSize(1);
      43           2 : }
      44             : 
      45          22 : void AverageVessel::accumulate( const double& weight, const double& val ) {
      46          22 :   if( domain.size()==2 ) {
      47             :     // Average with Berry Phase
      48          11 :     double tval = 2*pi*( val - domain[0] ) / ( domain[1] - domain[0] );
      49          22 :     addDataElement( 0, weight*sin(tval) ); addDataElement( 1, weight*cos(tval) );
      50          11 :   } else addDataElement( 0, weight*val );
      51          22 : }
      52             : 
      53          22 : double AverageVessel::getAverage() const {
      54          33 :   if( domain.size()==2 ) return domain[0] + (( domain[1] - domain[0] )*atan2( getDataElement(0), getDataElement(1) ) / (2*pi));
      55             :   return getDataElement(0);
      56             : }
      57             : 
      58           0 : void AverageVessel::calculate( const unsigned& current, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_list ) const {
      59           0 :   plumed_error();
      60             : }
      61             : 
      62             : }
      63        4839 : }

Generated by: LCOV version 1.13