Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2012-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 "core/ActionWithValue.h" 23 : #include "core/ActionRegister.h" 24 : #include <string> 25 : #include <cmath> 26 : 27 : namespace PLMD { 28 : namespace generic { 29 : 30 : //+PLUMEDOC GENERIC TIME 31 : /* 32 : retrieve the time of the simulation to be used elsewhere 33 : 34 : \par Examples 35 : 36 : \plumedfile 37 : TIME LABEL=t1 38 : PRINT ARG=t1 39 : \endplumedfile 40 : 41 : */ 42 : //+ENDPLUMEDOC 43 : 44 : class Time : public ActionWithValue { 45 : public: 46 : static void registerKeywords( Keywords& keys ); 47 : explicit Time(const ActionOptions&); 48 : // active methods: 49 : void calculate() override; 50 0 : void apply() override {} 51 0 : unsigned getNumberOfDerivatives() override { return 0; } 52 : }; 53 : 54 : PLUMED_REGISTER_ACTION(Time,"TIME") 55 : 56 2 : void Time::registerKeywords( Keywords& keys ) { 57 2 : Action::registerKeywords( keys ); 58 2 : ActionWithValue::registerKeywords( keys ); 59 4 : keys.setValueDescription("scalar","the time since the start of the trajectory"); 60 2 : } 61 : 62 0 : Time::Time(const ActionOptions&ao): 63 0 : Action(ao),ActionWithValue(ao) 64 : { 65 0 : addValueWithDerivatives(); setNotPeriodic(); 66 : // resize derivative by hand to a nonzero value 67 0 : getPntrToValue()->resizeDerivatives(1); 68 0 : } 69 : 70 0 : void Time::calculate() { 71 0 : setValue (getTime()); 72 0 : } 73 : 74 : } 75 : 76 : 77 : 78 : 79 : 80 : }