Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-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 "ActionWithIntegral.h" 23 : 24 : namespace PLMD { 25 : namespace gridtools { 26 : 27 8 : void ActionWithIntegral::registerKeywords( Keywords& keys ) { 28 8 : ActionWithInputGrid::registerKeywords( keys ); 29 8 : keys.remove("KERNEL"); 30 8 : keys.remove("BANDWIDTH"); 31 8 : keys.remove("CLEAR"); 32 16 : keys.add("compulsory","CLEAR","1","the frequency with which to clear all the accumulated data."); 33 8 : } 34 : 35 4 : ActionWithIntegral::ActionWithIntegral(const ActionOptions&ao): 36 : Action(ao), 37 4 : ActionWithInputGrid(ao) { 38 4 : plumed_assert( ingrid->getNumberOfComponents()==1 ); 39 : // Retrieve the volume of the grid (for integration) 40 4 : volume = ingrid->getCellVolume(); 41 : // Create something that is going to calculate the sum of all the values 42 : // at the various grid points - this is going to be the integral 43 : std::string fake_input; 44 4 : addVessel( "SUM", fake_input, -1 ); 45 4 : readVesselKeywords(); 46 : // Now create task list - number of tasks is equal to the number of grid points 47 : // as we have to evaluate the function at each grid points 48 1145 : for(unsigned i=0; i<ingrid->getNumberOfPoints(); ++i) { 49 1141 : addTaskToList(i); 50 : } 51 : // And activate all tasks 52 4 : deactivateAllTasks(); 53 1145 : for(unsigned i=0; i<ingrid->getNumberOfPoints(); ++i) { 54 1141 : taskFlags[i]=1; 55 : } 56 4 : lockContributors(); 57 4 : } 58 : 59 8 : void ActionWithIntegral::turnOnDerivatives() { 60 8 : ActionWithGrid::turnOnDerivatives(); 61 8 : forcesToApply.resize( ingrid->getNumberOfPoints() ); 62 8 : } 63 : 64 20 : void ActionWithIntegral::apply() { 65 20 : if( getForcesFromVessels( forcesToApply ) ) { 66 20 : ingrid->setForce( forcesToApply ); 67 : } 68 20 : } 69 : 70 : } 71 : }