Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2016-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 "ActionWithGrid.h"
23 : #include "core/PlumedMain.h"
24 : #include "core/ActionSet.h"
25 :
26 : namespace PLMD {
27 : namespace gridtools {
28 :
29 57 : void ActionWithGrid::registerKeywords( Keywords& keys ) {
30 57 : vesselbase::ActionWithAveraging::registerKeywords( keys );
31 57 : keys.add("compulsory","BANDWIDTH","the bandwidths for kernel density esimtation");
32 : keys.add("compulsory","KERNEL","gaussian","the kernel function you are using. More details on the kernels available "
33 57 : "in plumed plumed can be found in \\ref kernelfunctions.");
34 57 : keys.add("optional","CONCENTRATION","the concentration parameter for Von Mises-Fisher distributions");
35 57 : }
36 :
37 48 : ActionWithGrid::ActionWithGrid( const ActionOptions& ao):
38 : Action(ao),
39 : ActionWithAveraging(ao),
40 48 : mygrid(NULL)
41 : {
42 48 : }
43 :
44 43 : void ActionWithGrid::createGrid( const std::string& type, const std::string& inputstr ) {
45 : // Start creating the input for the grid
46 43 : std::string vstring = inputstr;
47 43 : if( keywords.exists("KERNEL") ) {
48 34 : std::string vconc; parse("CONCENTRATION",vconc);
49 34 : if( vconc.length()>0 ) {
50 2 : vstring += " TYPE=fibonacci CONCENTRATION=" + vconc;
51 : } else {
52 32 : std::string kstring; parse("KERNEL",kstring);
53 32 : if( kstring=="DISCRETE" ) vstring += " KERNEL=" + kstring;
54 28 : else vstring += " KERNEL=" + kstring + " " + getKeyword("BANDWIDTH");
55 34 : }
56 : }
57 86 : vesselbase::VesselOptions da("mygrid","",-1,vstring,this);
58 86 : Keywords keys; gridtools::AverageOnGrid::registerKeywords( keys );
59 86 : vesselbase::VesselOptions dar( da, keys );
60 43 : if( type=="histogram" ) {
61 26 : mygrid = new HistogramOnGrid(dar);
62 17 : } else if( type=="average" ) {
63 8 : mygrid = new AverageOnGrid(dar);
64 9 : } else if( type=="grid" ) {
65 9 : mygrid = new GridVessel(dar);
66 : } else {
67 0 : plumed_merror("no way to create grid of type " + type );
68 43 : }
69 43 : }
70 :
71 16 : void ActionWithGrid::turnOnDerivatives() {
72 16 : needsDerivatives(); ActionWithValue::turnOnDerivatives();
73 16 : if( getStride()==1 ) setStride(0);
74 8 : else if( getStride()!=0 ) error("conflicting instructions for grid - stride was set but must be evaluated on every step for derivatives - remove STRIDE keyword");
75 16 : if( clearstride>1 ) error("conflicting instructions for grid - CLEAR was set but grid must be reset on every step for derivatives - remove CLEAR keyword" );
76 16 : if( weights.size()>0 ) error("conflicting instructions for grid - LOGWEIGHTS was set but weights are not considered when derivatives of grid are evaluated - remove LOGWEIGHTS keyword");
77 16 : }
78 :
79 160 : void ActionWithGrid::calculate() {
80 : // Do nothing if derivatives are not required
81 320 : if( doNotCalculateDerivatives() ) return;
82 : // Clear on every step
83 40 : if( mygrid ) clearAverage();
84 : // Should not be any reweighting so just set these accordingly
85 40 : lweight=0; cweight=1.0;
86 : // Prepare to do the averaging
87 40 : prepareForAveraging();
88 : // Run all the tasks (if required
89 40 : if( useRunAllTasks ) runAllTasks();
90 : // This the averaging if it is not done using task list
91 20 : else performOperations( true );
92 : // Update the norm
93 40 : if( mygrid ) mygrid->setNorm( cweight );
94 : // Finish the averaging
95 40 : finishAveraging();
96 : // And reset for next step
97 40 : if( mygrid ) mygrid->reset();
98 : }
99 :
100 48505 : void ActionWithGrid::performTask( const unsigned& task_index, const unsigned& current, MultiValue& myvals ) const {
101 : // Set the weight of this point
102 48505 : myvals.setValue( 0, cweight ); compute( current, myvals );
103 48502 : }
104 :
105 : }
106 4821 : }
|