1 /* Ergo, version 3.8, a program for linear scaling electronic structure 2 * calculations. 3 * Copyright (C) 2019 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, 4 * and Anastasia Kruchinina. 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * 19 * Primary academic reference: 20 * Ergo: An open-source program for linear-scaling electronic structure 21 * calculations, 22 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia 23 * Kruchinina, 24 * SoftwareX 7, 107 (2018), 25 * <http://dx.doi.org/10.1016/j.softx.2018.03.005> 26 * 27 * For further information about Ergo, see <http://www.ergoscf.org>. 28 */ 29 30 /** @file grid_matrix.h 31 32 @brief Generic matrix interface. It is not optimized for speed. 33 34 @author: Pawel Salek <em>responsible</em> 35 */ 36 37 #if !defined(_GRID_MATRIX_H_) 38 #define _GRID_MATRIX_H_ 1 39 40 #include "sparse_matrix.h" 41 42 namespace Dft { 43 44 class Matrix { 45 public: 46 virtual ergo_real at(int row, int col) const = 0; 47 virtual bool isSparse() const = 0; 48 virtual const SparseMatrix* asSparse() const = 0; 49 virtual const ergo_real* asFull() const = 0; ~Matrix()50 virtual ~Matrix() {} 51 }; 52 53 class FullMatrix { 54 public: 55 ergo_real* mat; 56 int nbast; 57 bool owned; FullMatrix(int nbast_)58 explicit FullMatrix(int nbast_) 59 : mat(new ergo_real[nbast_*nbast_]), nbast(nbast_), owned(true) 60 { 61 for(int i= nbast*nbast-1; i >=0; --i) mat[i] = 0.0; 62 } FullMatrix(ergo_real * m,int nbast_)63 FullMatrix(ergo_real *m, int nbast_) 64 : mat(m), nbast(nbast_), owned(false) 65 { 66 } 67 /** ugly-hack constructor. Remove it! */ FullMatrix(const ergo_real * m,int nbast_)68 FullMatrix(const ergo_real *m, int nbast_) 69 : mat( (ergo_real*)(m)), nbast(nbast_), owned(false) 70 { 71 } 72 ~FullMatrix()73 ~FullMatrix() { if (owned && mat) delete []mat; } add(int row,int col,ergo_real val)74 void add(int row, int col, ergo_real val) 75 { 76 mat[row + col*nbast] += val; 77 } at(int row,int col)78 ergo_real at(int row, int col) const 79 { 80 return mat[row + col*nbast]; 81 } 82 }; 83 84 } 85 86 #endif /* _GRID_MATRIX_H_ */ 87