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_DataPassingObject_h 23 : #define __PLUMED_core_DataPassingObject_h 24 : 25 : #include <vector> 26 : #include <memory> 27 : #include <set> 28 : #include "tools/AtomNumber.h" 29 : #include "tools/TypesafePtr.h" 30 : #include "Value.h" 31 : 32 : namespace PLMD { 33 : 34 : class DataPassingObject { 35 : protected: 36 : /// The start of the data in the input pointer 37 : unsigned start; 38 : /// The spacing between values in the input arrays 39 : unsigned stride; 40 : /// The units of the quantity 41 : double unit; 42 : /// The units of the force on this quantity 43 : double funit; 44 : /// The backup value of the quantity (used if the value is passed directly) 45 : bool hasbackup; 46 : double bvalue; 47 : public: 48 : static std::unique_ptr<DataPassingObject> create(unsigned n); 49 : explicit DataPassingObject() : start(0), stride(1), unit(1), funit(1), hasbackup(false), bvalue(0) {} 50 : /// Virtual destructor, just to allow inheritance. 51 : virtual ~DataPassingObject() {} 52 : /// Convert what comes from the MD code to a double 53 : virtual double MD2double(const TypesafePtr & m) const=0; 54 : /// 55 451096 : void setStart( const unsigned& s ) { start=s; } 56 : /// Set the stride to use when getting data from the input array 57 451096 : void setStride( const unsigned& s ) { stride=s; } 58 : /// Set the unit for the value 59 9612 : void setUnit( const double& u ) { unit=u; } 60 : /// Set the unit for the force 61 9612 : void setForceUnit( const double& u ) { funit=u; } 62 : /// This is used when you want to save the passed object to a double variable in PLUMED rather than the pointer 63 : /// this can be used even when you don't pass a pointer from the MD code 64 : virtual void saveValueAsDouble( const TypesafePtr & val )=0; 65 : /// Set the pointer to the value 66 : virtual void setValuePointer( const TypesafePtr & val, const std::vector<unsigned>& shape, const bool& isconst )=0; 67 : /// Set the pointer to the force 68 : virtual void setForcePointer( const TypesafePtr & val, const std::vector<unsigned>& shape )=0; 69 : /// This gets the data in the pointer and passes it to the output value 70 : virtual void share_data( std::vector<double>& values ) const = 0; 71 : /// Share the data and put it in the value from sequential data 72 : virtual void share_data( const unsigned& j, const unsigned& k, Value* value )=0; 73 : /// Share the data and put it in the value from a scattered data 74 : virtual void share_data( const std::vector<AtomNumber>&index, const std::vector<unsigned>& i, Value* value )=0; 75 : /// Pass the force from the value to the output value 76 : virtual void add_force( Value* vv )=0; 77 : virtual void add_force( const std::vector<int>& index, Value* value )=0; 78 : virtual void add_force( const std::vector<AtomNumber>& index, const std::vector<unsigned>& i, Value* value )=0; 79 : /// Rescale the forces that were passed 80 : virtual void rescale_force( const unsigned& n, const double& factor, Value* value )=0; 81 : /// This transfers everything to the output 82 : virtual void setData( Value* value )=0; 83 : }; 84 : 85 : } 86 : #endif