Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2017-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 : #ifndef __PLUMED_core_ActionToPutData_h 23 : #define __PLUMED_core_ActionToPutData_h 24 : 25 : #include "ActionForInterface.h" 26 : #include "DataPassingObject.h" 27 : #include "tools/Units.h" 28 : #include "DataPassingTools.h" 29 : 30 : namespace PLMD { 31 : 32 : class ActionToPutData : 33 : public ActionForInterface { 34 : friend class PlumedMain; 35 : friend class TimeStep; 36 : friend class DomainDecomposition; 37 : private: 38 : /// Are we not applying forces on this values 39 : bool noforce; 40 : /// Are the forces on this value added by another rank? The forces that the MD code 41 : /// holds in this value are still rescaled on this rank (e.g. its share of the virial) 42 : bool forces_added_elsewhere; 43 : /// Is this quantity fixed 44 : bool fixed; 45 : /// Is this quantity passed from the domains 46 : bool from_domains; 47 : /// Is PLUMED allowed to change the value of this pointer 48 : bool resetable; 49 : /// Are we allowed to set data at this time 50 : bool dataCanBeSet; 51 : /// The unit of the value that has been passed to plumed 52 : enum {n,e,l,m,q,t} unit; 53 : /// The unit to to use for the force 54 : enum {d,eng} funit; 55 : /// This holds the pointer that we getting data from 56 : std::unique_ptr<DataPassingObject> mydata; 57 : /// Convert the enum contaning the unit into the name of the unit 58 : std::string getUnitName() const ; 59 : protected: 60 : /// Setup the units of the input value 61 : void setUnit( const std::string& unitstr, const std::string& funitstr ); 62 : public: 63 : static void registerKeywords(Keywords& keys); 64 : explicit ActionToPutData(const ActionOptions&ao); 65 : /// Set the start point for the memory if needed 66 : void setStart( const std::string& name, const unsigned& sss) override; 67 : /// This resets the stride in the collection object 68 : void setStride( const std::string& name, const unsigned& sss ) override; 69 : /// Update the units on the input data 70 : void updateUnits( DataPassingTools* passtools ); 71 : /// This is called at the start of the step 72 1333023 : void resetForStepStart() override { 73 1333023 : dataCanBeSet = true; 74 1333023 : } 75 : /// These are the actions that set the pointers to the approrpiate values 76 : virtual bool setValuePointer( const std::string& name, const TypesafePtr & val ) override ; 77 : bool setForcePointer( const std::string& name, const TypesafePtr & val ) override ; 78 : /// 79 1 : void Set_comm(Communicator& comm) override {} 80 : /// And this gets the number of forces that need to be rescaled 81 : unsigned getNumberOfForcesToRescale() const override ; 82 : /// Share the data 83 1321362 : void share() override {} 84 228 : void shareAll() override {} 85 : /// 86 : void getLocalValues( std::vector<double>& vals ) const ; 87 : /// Get the data to share 88 : virtual void wait() override ; 89 : /// Actually set the values for the output 90 : virtual void apply() override ; 91 : void rescaleForces( const double& alpha ); 92 : /// For replica exchange 93 : void writeBinary(std::ostream&o) override; 94 : virtual void readBinary(std::istream&i) override; 95 3460 : bool onStep() const override { 96 3460 : return false; 97 : } 98 846808 : ActionToPutData* castToActionToPutData() noexcept final { 99 846808 : return this; 100 : } 101 : }; 102 : 103 : } 104 : #endif