LCOV - code coverage report
Current view: top level - ves - CoeffsMatrix.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 0 1 0.0 %
Date: 2025-03-25 09:33:27 Functions: 0 0 -

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-2021 The VES code team
       3             :    (see the PEOPLE-VES file at the root of this folder for a list of names)
       4             : 
       5             :    See http://www.ves-code.org for more information.
       6             : 
       7             :    This file is part of VES code module.
       8             : 
       9             :    The VES code module 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             :    The VES code module 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 the VES code module.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : #ifndef __PLUMED_ves_CoeffsMatrix_h
      23             : #define __PLUMED_ves_CoeffsMatrix_h
      24             : 
      25             : #include "CoeffsBase.h"
      26             : 
      27             : #include <vector>
      28             : #include <string>
      29             : #include <cmath>
      30             : 
      31             : 
      32             : namespace PLMD {
      33             : 
      34             : class Action;
      35             : class Value;
      36             : class IFile;
      37             : class OFile;
      38             : class Communicator;
      39             : 
      40             : namespace ves {
      41             : 
      42             : class BasisFunctions;
      43             : class CoeffsVector;
      44             : 
      45             : 
      46             : class CoeffsMatrix:
      47             :   public CoeffsBase {
      48             : public:
      49             : private:
      50             :   std::vector<double> data;
      51             :   //
      52             :   size_t size_;
      53             :   size_t nrows_;
      54             :   size_t ncolumns_;
      55             :   //
      56             :   bool diagonal_;
      57             :   //
      58             :   unsigned int averaging_counter;
      59             :   unsigned int averaging_exp_decay_;
      60             :   //
      61             :   Communicator& mycomm;
      62             :   //
      63             :   void setupMatrix();
      64             :   //
      65             :   CoeffsMatrix& operator=(const CoeffsMatrix&);
      66             : public:
      67             :   explicit CoeffsMatrix(
      68             :     const std::string&,
      69             :     const std::vector<std::string>&,
      70             :     const std::vector<unsigned int>&,
      71             :     Communicator& cc,
      72             :     const bool diagonal=true,
      73             :     const bool use_iteration_counter=false);
      74             :   //
      75             :   explicit CoeffsMatrix(
      76             :     const std::string&,
      77             :     std::vector<Value*>&,
      78             :     std::vector<BasisFunctions*>&,
      79             :     Communicator& cc,
      80             :     const bool diagonal=true,
      81             :     const bool use_iteration_counter=false);
      82             :   //
      83             :   explicit CoeffsMatrix(
      84             :     const std::string&,
      85             :     std::vector<std::vector<Value*> >& argsv,
      86             :     std::vector<std::vector<BasisFunctions*> >& basisfv,
      87             :     Communicator& cc,
      88             :     const bool diagonal=true,
      89             :     const bool use_iteration_counter=false,
      90             :     const std::string& multicoeffs_label="bias");
      91             :   //
      92             :   explicit CoeffsMatrix(
      93             :     const std::string&,
      94             :     CoeffsVector*,
      95             :     Communicator& cc,
      96             :     const bool diagonal=true);
      97             :   //
      98             :   ~CoeffsMatrix();
      99             :   //
     100             :   size_t getSize() const;
     101             :   //
     102             :   bool isSymmetric() const;
     103             :   bool isDiagonal() const;
     104             :   //
     105             :   bool sameShape(CoeffsVector&) const;
     106             :   bool sameShape(CoeffsMatrix&) const;
     107             :   static bool sameShape(CoeffsMatrix&, CoeffsMatrix&);
     108             :   static bool sameShape(CoeffsVector&, CoeffsMatrix&);
     109             :   static bool sameShape(CoeffsMatrix&, CoeffsVector&);
     110             :   //
     111             :   void sumCommMPI();
     112             :   void sumCommMPI(Communicator&);
     113             :   //
     114             :   void sumMultiSimCommMPI(Communicator&);
     115             :   //
     116             :   size_t getMatrixIndex(const size_t, const size_t) const;
     117             :   //
     118             :   // clear coeffs
     119             :   void clear();
     120             :   void setAllValuesToZero();
     121             :   //
     122             :   std::vector<double> getDataAsVector() const {
     123             :     return data;
     124             :   }
     125             :   // get value
     126             :   double getValue(const size_t, const size_t) const;
     127             :   double getValue(const std::vector<unsigned int>&, const std::vector<unsigned int>&) const;
     128             :   // set value
     129             :   void setValue(const size_t, const size_t, const double);
     130             :   void setValue(const std::vector<unsigned int>&, const std::vector<unsigned int>&, const double);
     131             :   double& operator()(const size_t, const size_t);
     132             :   const double& operator()(const size_t, const size_t) const;
     133             :   double& operator()(const std::vector<unsigned int>&, const std::vector<unsigned int>&);
     134             :   const double& operator()(const std::vector<unsigned int>&, const std::vector<unsigned int>&) const;
     135             :   //
     136             :   friend CoeffsVector operator*(const CoeffsMatrix&, const CoeffsVector&);
     137             :   // add to value
     138             :   void addToValue(const size_t, const size_t, const double);
     139             :   void addToValue(const std::vector<unsigned int>&, const std::vector<unsigned int>&, const double);
     140             :   // scale all values
     141             :   void scaleAllValues(const double);
     142             :   CoeffsMatrix& operator*=(const double);
     143             :   friend CoeffsMatrix operator*(const double, const CoeffsMatrix&);
     144             :   friend CoeffsMatrix operator*(const CoeffsMatrix&, const double);
     145             :   CoeffsMatrix& operator*=(const CoeffsMatrix&);
     146             :   CoeffsMatrix operator*(const CoeffsMatrix&) const;
     147             :   // set all values
     148             :   void setValues(const double);
     149             :   void setValues(const std::vector<double>&);
     150             :   void setValues(const CoeffsMatrix&);
     151             :   CoeffsMatrix& operator=(const double);
     152             :   CoeffsMatrix& operator=(const std::vector<double>&);
     153             :   // CoeffsMatrix& operator=(const CoeffsMatrix&);
     154             :   // add to all values
     155             :   CoeffsMatrix operator+() const;
     156             :   CoeffsMatrix operator-() const;
     157             :   void addToValues(const double);
     158             :   void addToValues(const std::vector<double>&);
     159             :   void addToValues(const CoeffsMatrix&);
     160             :   void subtractFromValues(const double);
     161             :   void subtractFromValues(const std::vector<double>&);
     162             :   void subtractFromValues(const CoeffsMatrix&);
     163             :   CoeffsMatrix& operator+=(const double);
     164             :   friend CoeffsMatrix operator+(const double, const CoeffsMatrix&);
     165             :   friend CoeffsMatrix operator+(const CoeffsMatrix&, const double);
     166             :   CoeffsMatrix& operator+=(const std::vector<double>&);
     167             :   friend CoeffsMatrix operator+(const std::vector<double>&, const CoeffsMatrix&);
     168             :   friend CoeffsMatrix operator+(const CoeffsMatrix&, const std::vector<double>&);
     169             :   CoeffsMatrix& operator-=(const double);
     170             :   friend CoeffsMatrix operator-(const double, const CoeffsMatrix&);
     171             :   friend CoeffsMatrix operator-(const CoeffsMatrix&, const double);
     172             :   CoeffsMatrix& operator-=(const std::vector<double>&);
     173             :   friend CoeffsMatrix operator-(const std::vector<double>&, const CoeffsMatrix&);
     174             :   friend CoeffsMatrix operator-(const CoeffsMatrix&, const std::vector<double>&);
     175             :   CoeffsMatrix& operator+=(const CoeffsMatrix&);
     176             :   CoeffsMatrix operator+(const CoeffsMatrix&) const;
     177             :   CoeffsMatrix& operator-=(const CoeffsMatrix&);
     178             :   CoeffsMatrix operator-(const CoeffsMatrix&) const;
     179             :   //
     180             :   static void averageMatrices(CoeffsMatrix&, CoeffsMatrix&);
     181             :   static void averageMatrices(const std::vector<CoeffsMatrix*>&);
     182             :   //
     183             :   double getMinValue() const;
     184             :   double getMaxValue() const;
     185             :   //
     186             :   void randomizeValuesGaussian(int);
     187             :   //
     188             :   void resetAveragingCounter() {
     189           0 :     averaging_counter=0;
     190             :   }
     191             :   void setupExponentiallyDecayingAveraging(const unsigned int averaging_exp_decay_in) {
     192             :     averaging_exp_decay_=averaging_exp_decay_in;
     193             :   }
     194             :   void turnOffExponentiallyDecayingAveraging() {
     195             :     averaging_exp_decay_=0;
     196             :   }
     197             :   void resetAveraging();
     198             :   void addToAverage(const CoeffsMatrix&);
     199             :   void addToAverage(const CoeffsMatrix&, const unsigned int);
     200             :   //
     201             :   // file input/output stuff
     202             :   void writeToFile(OFile&);
     203             :   void writeToFile(const std::string&, const bool append_file=false, Action* action_pntr=NULL);
     204             : private:
     205             :   void writeDataToFile(OFile&);
     206             :   void writeMatrixInfoToFile(OFile&);
     207             :   void writeHeaderToFile(OFile&);
     208             :   void writeDataDiagonalToFile(OFile&);
     209             :   void writeDataFullToFile(OFile&);
     210             : public:
     211             :   Communicator& getCommunicator() const {
     212             :     return mycomm;
     213             :   }
     214             : 
     215             : };
     216             : }
     217             : }
     218             : 
     219             : 
     220             : #endif

Generated by: LCOV version 1.16