LCOV - code coverage report
Current view: top level - core - DataPassingObject.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 5 5 100.0 %
Date: 2026-11-05 10:19:04 Functions: 0 0 -

          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             : /// Whether the quantity is one that the user specifies in base ten, such as the timestep
      48             :   bool roundToBaseTen;
      49             : public:
      50             :   static std::unique_ptr<DataPassingObject> create(unsigned n);
      51             :   explicit DataPassingObject() : start(0), stride(1), unit(1), funit(1), hasbackup(false), bvalue(0), roundToBaseTen(false) {}
      52             :   /// Virtual destructor, just to allow inheritance.
      53             :   virtual ~DataPassingObject() {}
      54             : /// Convert what comes from the MD code to a double
      55             :   virtual double MD2double(const TypesafePtr & m) const=0;
      56             : ///
      57             :   void setStart( const unsigned& s ) {
      58      973768 :     start=s;
      59             :   }
      60             : /// Set the stride to use when getting data from the input array
      61             :   void setStride( const unsigned& s ) {
      62      973768 :     stride=s;
      63             :   }
      64             : /// Set the unit for the value
      65             :   void setUnit( const double& u ) {
      66       17580 :     unit=u;
      67             :   }
      68             : /// Set the unit for the force
      69             :   void setForceUnit( const double& u ) {
      70       17580 :     funit=u;
      71             :   }
      72             : /// Only set this for quantities that the user specifies in base ten, see saveValueAsDouble
      73             :   void setRoundToBaseTen( const bool& r ) {
      74       13245 :     roundToBaseTen=r;
      75             :   }
      76             : /// This is used when you want to save the passed object to a double variable in PLUMED rather than the pointer
      77             : /// this can be used even when you don't pass a pointer from the MD code
      78             :   virtual void saveValueAsDouble( const TypesafePtr & val )=0;
      79             : /// Set the pointer to the value
      80             :   virtual void setValuePointer( const TypesafePtr & val, const std::vector<std::size_t>& shape, const bool& isconst )=0;
      81             : /// Set the pointer to the force
      82             :   virtual void setForcePointer( const TypesafePtr & val, const std::vector<std::size_t>& shape )=0;
      83             : /// This gets the data in the pointer and passes it to the output value
      84             :   virtual void share_data( std::vector<double>& values ) const = 0;
      85             : /// Share the data and put it in the value from sequential data
      86             :   virtual void share_data( const unsigned& j, const unsigned& k, Value* value )=0;
      87             : /// Share the data and put it in the value from a scattered data.
      88             : /// index holds the positions in the value, i the positions in the MD array and
      89             : /// nlocal is the number of elements in the MD array, which is used to check its size
      90             :   virtual void share_data( const std::vector<AtomNumber>&index, const std::vector<unsigned>& i, const std::size_t& nlocal, Value* value )=0;
      91             : /// Check if the MD code passed an array to store the forces on this quantity
      92             :   virtual bool hasForcePointer() const = 0;
      93             : /// Pass the force from the value to the output value
      94             :   virtual void add_force( Value* vv )=0;
      95             :   virtual void add_force( const std::vector<int>& index, Value* value )=0;
      96             : /// Pass the forces on the elements index of the value to the elements i of the MD array, which has nlocal elements
      97             :   virtual void add_force( const std::vector<AtomNumber>& index, const std::vector<unsigned>& i, const std::size_t& nlocal, Value* value )=0;
      98             : /// Rescale the forces that were passed
      99             :   virtual void rescale_force( const unsigned& n, const double& factor, Value* value )=0;
     100             : /// This transfers everything to the output
     101             :   virtual void setData( Value* value )=0;
     102             : };
     103             : 
     104             : }
     105             : #endif

Generated by: LCOV version 1.16