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 : { 35 6 : parseVector("PERIODIC",domain); 36 3 : plumed_assert( domain.size()==2 || domain.size()==0 ); 37 3 : } 38 : 39 3 : void AverageVessel::resize() { 40 : resizeBuffer(0); 41 3 : if( domain.size()==2 ) setDataSize(2); 42 2 : else setDataSize(1); 43 3 : } 44 : 45 1022 : void AverageVessel::accumulate( const double& weight, const double& val ) { 46 1022 : if( domain.size()==2 ) { 47 : // Average with Berry Phase 48 11 : double tval = 2*pi*( val - domain[0] ) / ( domain[1] - domain[0] ); 49 11 : addDataElement( 0, weight*std::sin(tval) ); addDataElement( 1, weight*std::cos(tval) ); 50 1011 : } else addDataElement( 0, weight*val ); 51 1022 : } 52 : 53 1022 : double AverageVessel::getAverage() const { 54 1022 : if( domain.size()==2 ) return domain[0] + (( domain[1] - domain[0] )*std::atan2( getDataElement(0), getDataElement(1) ) / (2*pi)); 55 1011 : 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 : }