LCOV - code coverage report
Current view: top level - gridtools - ActionWithGrid.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 50 51 98.0 %
Date: 2021-11-18 15:22:58 Functions: 8 9 88.9 %

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

Generated by: LCOV version 1.14