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 : #include "OrderingVessel.h" 23 : #include "core/ActionWithValue.h" 24 : 25 : namespace PLMD { 26 : namespace vesselbase { 27 : 28 : 29 8 : void OrderingVessel::registerKeywords( Keywords& keys ) { 30 8 : ValueVessel::registerKeywords( keys ); 31 8 : } 32 : 33 8 : OrderingVessel::OrderingVessel( const VesselOptions& da ) : 34 8 : ValueVessel(da) 35 : { 36 8 : mydata = getAction()->buildDataStashes( NULL ); 37 26 : for(unsigned i=0; i<getAction()->getNumberOfVessels(); ++i) { 38 18 : if( getAction()->getPntrToVessel(i)->getName()==getName() ) 39 0 : error("calculating lowest/highest value multiple times serves no purpose"); 40 : } 41 8 : } 42 : 43 34 : void OrderingVessel::resize() { 44 : resizeBuffer( 0 ); 45 34 : if( getAction()->derivativesAreRequired() ) getFinalValue()->resizeDerivatives( getAction()->getNumberOfDerivatives() ); 46 34 : } 47 : 48 19 : void OrderingVessel::finish( const std::vector<double>& buffer ) { 49 19 : std::vector<double> values( getAction()->getNumberOfQuantities() ); 50 19 : mydata->retrieveSequentialValue( 0, false, values ); 51 : 52 19 : double min=values[mycomp]; unsigned mini=getAction()->getPositionInFullTaskList(0); 53 4134 : for(unsigned i=1; i<mydata->getNumberOfStoredValues(); ++i) { 54 4115 : mydata->retrieveSequentialValue( i, false, values ); 55 4115 : double newval = values[mycomp]; 56 4115 : if( compare( newval, min ) ) { min=newval; mini=getAction()->getPositionInFullTaskList(i); } 57 : } 58 : setOutputValue( min ); 59 : 60 19 : if( getAction()->derivativesAreRequired() ) { 61 17 : MultiValue myvals( getAction()->getNumberOfQuantities(), getAction()->getNumberOfDerivatives() ); 62 17 : mydata->retrieveDerivatives( mini, false, myvals ); Value* fval=getFinalValue(); 63 551 : for(unsigned i=0; i<myvals.getNumberActive(); ++i) { 64 : unsigned ider=myvals.getActiveIndex(i); 65 : fval->setDerivative( ider, myvals.getDerivative(mycomp,ider) ); 66 : } 67 17 : } 68 19 : } 69 : 70 : } 71 : }