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 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 : /// Raise an error if forces have to be applied but the MD code did not pass the array to store them 60 : void checkForcePointer() const ; 61 : protected: 62 : /// Setup the units of the input value 63 : void setUnit( const std::string& unitstr, const std::string& funitstr ); 64 : public: 65 : static void registerKeywords(Keywords& keys); 66 : explicit ActionToPutData(const ActionOptions&ao); 67 : /// Set the start point for the memory if needed 68 : void setStart( const std::string& actname, const unsigned& sss) override; 69 : /// This resets the stride in the collection object 70 : void setStride( const std::string& actname, const unsigned& sss ) override; 71 : /// Update the units on the input data 72 : void updateUnits( DataPassingTools* passtools ); 73 : /// This is called at the start of the step 74 1522411 : void resetForStepStart() override { 75 1522411 : dataCanBeSet = true; 76 1522411 : } 77 : /// These are the actions that set the pointers to the approrpiate values 78 : virtual bool setValuePointer( const std::string& actname, const TypesafePtr & val ) override ; 79 : bool setForcePointer( const std::string& actname, const TypesafePtr & val ) override ; 80 : /// 81 1 : void Set_comm(Communicator& newcomm) override {} 82 : /// And this gets the number of forces that need to be rescaled 83 : unsigned getNumberOfForcesToRescale() const override ; 84 : /// Share the data 85 1510387 : void share() override {} 86 252 : void shareAll() override {} 87 : /// 88 : void getLocalValues( std::vector<double>& vals ) const ; 89 : /// Get the data to share 90 : virtual void wait() override ; 91 : /// Actually set the values for the output 92 : virtual void apply() override ; 93 : void rescaleForces( const double& alpha ); 94 : /// For replica exchange 95 : void writeBinary(std::ostream&o) override; 96 : virtual void readBinary(std::istream&i) override; 97 3583 : bool onStep() const override { 98 3583 : return false; 99 : } 100 830936 : ActionToPutData* castToActionToPutData() noexcept final { 101 830936 : return this; 102 : } 103 : }; 104 : 105 : } 106 : #endif