Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2014-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 "ActionWithInputVessel.h" 23 : #include "StoreDataVessel.h" 24 : #include "BridgeVessel.h" 25 : #include "core/PlumedMain.h" 26 : #include "core/ActionSet.h" 27 : 28 : namespace PLMD { 29 : namespace vesselbase { 30 : 31 36 : void ActionWithInputVessel::registerKeywords(Keywords& keys) { 32 72 : keys.add("compulsory","DATA","certain actions in plumed work by calculating a list of variables and summing over them. " 33 : "This particular action can be used to calculate functions of these base variables or prints " 34 : "them to a file. This keyword thus takes the label of one of those such variables as input."); 35 72 : keys.reserve("compulsory","GRID","the action that creates the input grid you would like to use"); 36 36 : } 37 : 38 24 : ActionWithInputVessel::ActionWithInputVessel(const ActionOptions&ao): 39 : Action(ao), 40 24 : arguments(NULL), 41 24 : myBridgeVessel(NULL) { 42 24 : } 43 : 44 24 : void ActionWithInputVessel::readArgument( const std::string& type ) { 45 : std::string mlab; 46 72 : if( keywords.exists("DATA") && type!="grid" ) { 47 48 : parse("DATA",mlab); 48 : } 49 24 : ActionWithVessel* mves= plumed.getActionSet().selectWithLabel<ActionWithVessel*>(mlab); 50 24 : if(!mves) { 51 0 : error("action labelled " + mlab + " does not exist or does not have vessels"); 52 : } 53 24 : addDependency(mves); 54 : 55 24 : ActionWithValue* aval=dynamic_cast<ActionWithValue*>( this ); 56 24 : if(aval) { 57 2 : if( aval->checkNumericalDerivatives() ) { 58 1 : ActionWithValue* aval2=dynamic_cast<ActionWithValue*>( mves ); 59 1 : plumed_assert( aval2 ); 60 1 : aval2->useNumericalDerivatives(); 61 : } 62 : } 63 : 64 24 : if( type=="bridge" ) { 65 2 : ActionWithVessel* aves=dynamic_cast<ActionWithVessel*>( this ); 66 2 : plumed_assert(aves); 67 2 : myBridgeVessel = mves->addBridgingVessel( aves ); 68 2 : arguments = dynamic_cast<Vessel*>( myBridgeVessel ); 69 22 : } else if( type=="store" ) { 70 22 : arguments = dynamic_cast<Vessel*>( mves->buildDataStashes( NULL ) ); 71 : } else { 72 0 : plumed_error(); 73 : } 74 24 : } 75 : 76 5 : void ActionWithInputVessel::calculateNumericalDerivatives( ActionWithValue* a ) { 77 5 : if(!a) { 78 5 : a=dynamic_cast<ActionWithValue*>(this); 79 5 : plumed_massert(a,"cannot compute numerical derivatives for an action without values"); 80 : } 81 5 : if( myBridgeVessel ) { 82 5 : myBridgeVessel->completeNumericalDerivatives(); 83 : } else { 84 0 : error("numerical derivatives are not implemented"); 85 : } 86 5 : } 87 : 88 0 : void ActionWithInputVessel::applyBridgeForces( const std::vector<double>& bb ) { 89 : plumed_dbg_assert( myBridgeVessel ); 90 0 : addBridgeForces( bb ); 91 0 : } 92 : 93 : } 94 : }