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