LCOV - code coverage report
Current view: top level - gridtools - ActionWithInputGrid.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 31 34 91.2 %
Date: 2024-10-11 08:09:47 Functions: 5 6 83.3 %

          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 "ActionWithInputGrid.h"
      23             : #include "core/PlumedMain.h"
      24             : #include "core/ActionSet.h"
      25             : 
      26             : namespace PLMD {
      27             : namespace gridtools {
      28             : 
      29          32 : void ActionWithInputGrid::registerKeywords( Keywords& keys ) {
      30          32 :   ActionWithGrid::registerKeywords( keys );
      31          64 :   keys.add("compulsory","GRID","the action that creates the input grid you would like to use");
      32          64 :   keys.add("optional","COMPONENT","if your input is a vector field use this to specify the component of the input vector field for which you wish to use");
      33          32 : }
      34             : 
      35          25 : ActionWithInputGrid::ActionWithInputGrid(const ActionOptions&ao):
      36             :   Action(ao),
      37             :   ActionWithGrid(ao),
      38          25 :   ingrid(NULL)
      39             : {
      40          25 :   std::string mlab; parse("GRID",mlab);
      41          25 :   vesselbase::ActionWithVessel* mves= plumed.getActionSet().selectWithLabel<vesselbase::ActionWithVessel*>(mlab);
      42          25 :   if(!mves) error("action labelled " +  mlab + " does not exist or does not have vessels");
      43          25 :   addDependency(mves);
      44             : 
      45          25 :   for(unsigned i=0; i<mves->getNumberOfVessels(); ++i) {
      46          25 :     ingrid=dynamic_cast<GridVessel*>( mves->getPntrToVessel(i) );
      47          25 :     if( ingrid ) break;
      48             :   }
      49          25 :   if( !ingrid ) error("input action does not calculate a grid");
      50             : 
      51          25 :   if( ingrid->getNumberOfComponents()==1 ) {
      52          25 :     mycomp=0;
      53             :   } else {
      54           0 :     int tcomp=-1; parse("COMPONENT",tcomp);
      55           0 :     if( tcomp<0 ) error("component of vector field was not specified - use COMPONENT keyword");
      56           0 :     mycomp=tcomp;
      57             :   }
      58          25 :   log.printf("  using %uth component of grid calculated by action %s \n",mycomp,mves->getLabel().c_str() );
      59          25 : }
      60             : 
      61          26 : void ActionWithInputGrid::clearAverage() {
      62          77 :   if( mygrid->getType()=="flat" ) mygrid->setBounds( ingrid->getMin(), ingrid->getMax(), mygrid->getNbin(), mygrid->getGridSpacing() );
      63          26 :   ActionWithAveraging::clearAverage();
      64          26 : }
      65             : 
      66          70 : void ActionWithInputGrid::prepareForAveraging() {
      67          70 :   if( checkAllActive() ) {
      68       93583 :     for(unsigned i=0; i<ingrid->getNumberOfPoints(); ++i) {
      69       93513 :       if( ingrid->inactive(i) ) error("if FIND_CONTOUR is used with BUFFER option then other actions cannot be performed with grid");
      70             :     }
      71             :   }
      72          70 : }
      73             : 
      74          21 : void ActionWithInputGrid::performOperations( const bool& from_update ) {
      75          21 :   prepareForAveraging(); runAllTasks();
      76          21 : }
      77             : 
      78             : }
      79             : }
      80             : 

Generated by: LCOV version 1.15