LCOV - code coverage report
Current view: top level - analysis - AverageVessel.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 25 27 92.6 %
Date: 2026-03-30 13:16:06 Functions: 5 6 83.3 %

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

Generated by: LCOV version 1.16