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