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