LCOV - code coverage report
Current view: top level - core - DataPassingTools.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 19 23 82.6 %
Date: 2024-10-18 13:59:31 Functions: 6 8 75.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             : #include "DataPassingTools.h"
      23             : #include "PlumedMain.h"
      24             : #include "tools/Tools.h"
      25             : 
      26             : namespace PLMD {
      27             : 
      28       26446 : double DataPassingTools::getUnitConversion( const std::string& unit ) const {
      29       26446 :   if( unit=="energy" ) return MDUnits.getEnergy()/units.getEnergy();
      30        9447 :   if( unit=="length" ) return MDUnits.getLength()/units.getLength();
      31        4535 :   if( unit=="mass" ) return  MDUnits.getMass()/units.getMass();
      32        3307 :   if( unit=="charge" ) return MDUnits.getCharge()/units.getCharge();
      33        2079 :   if( unit=="time" ) return MDUnits.getTime()/units.getTime();
      34           0 :   if( unit=="number" ) return 1;
      35           0 :   plumed_error();
      36             : }
      37             : 
      38             : template <class T>
      39      807741 : class DataPassingToolsTyped : public DataPassingTools {
      40             : public:
      41             :   int getRealPrecision() const override;
      42             :   double MD2double(const TypesafePtr & m)const override;
      43             :   void double2MD(const double&d,const TypesafePtr & m) const override;
      44             : };
      45             : 
      46      807741 : std::unique_ptr<DataPassingTools> DataPassingTools::create(unsigned n) {
      47      807741 :   if(n==sizeof(double)) {
      48      807740 :     return std::make_unique<DataPassingToolsTyped<double>>();
      49           1 :   } else  if(n==sizeof(float)) {
      50           1 :     return std::make_unique<DataPassingToolsTyped<float>>();
      51             :   }
      52           0 :   std::string pp; Tools::convert(n,pp);
      53           0 :   plumed_merror("cannot create an MD interface with sizeof(real)=="+ pp);
      54             :   return NULL;
      55             : }
      56             : 
      57             : template <class T>
      58       10746 : int DataPassingToolsTyped<T>::getRealPrecision() const {
      59       10746 :   return sizeof(T);
      60             : }
      61             : 
      62             : template <class T>
      63        2919 : double DataPassingToolsTyped<T>::MD2double(const TypesafePtr & m) const {
      64        2919 :   return double(m.template get<T>());
      65             : }
      66             : 
      67             : template <class T>
      68        7269 : void DataPassingToolsTyped<T>::double2MD(const double&d,const TypesafePtr & m) const {
      69        7269 :   m.set(T(d));
      70        7269 : }
      71             : 
      72             : }

Generated by: LCOV version 1.16