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