ergo
grid_matrix.h
Go to the documentation of this file.
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
37#if !defined(_GRID_MATRIX_H_)
38#define _GRID_MATRIX_H_ 1
39
40#include "sparse_matrix.h"
41
42namespace 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;
50 virtual ~Matrix() {}
51 };
52
53 class FullMatrix {
54 public:
56 int nbast;
57 bool owned;
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 }
63 FullMatrix(ergo_real *m, int nbast_)
64 : mat(m), nbast(nbast_), owned(false)
65 {
66 }
68 FullMatrix(const ergo_real *m, int nbast_)
69 : mat( (ergo_real*)(m)), nbast(nbast_), owned(false)
70 {
71 }
72
73 ~FullMatrix() { if (owned && mat) delete []mat; }
74 void add(int row, int col, ergo_real val)
75 {
76 mat[row + col*nbast] += val;
77 }
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_ */
Definition: grid_matrix.h:53
int nbast
Definition: grid_matrix.h:56
ergo_real at(int row, int col) const
Definition: grid_matrix.h:78
bool owned
Definition: grid_matrix.h:57
ergo_real * mat
Definition: grid_matrix.h:55
FullMatrix(ergo_real *m, int nbast_)
Definition: grid_matrix.h:63
void add(int row, int col, ergo_real val)
Definition: grid_matrix.h:74
FullMatrix(int nbast_)
Definition: grid_matrix.h:58
FullMatrix(const ergo_real *m, int nbast_)
ugly-hack constructor.
Definition: grid_matrix.h:68
~FullMatrix()
Definition: grid_matrix.h:73
Definition: grid_matrix.h:44
virtual ergo_real at(int row, int col) const =0
virtual bool isSparse() const =0
virtual const ergo_real * asFull() const =0
virtual ~Matrix()
Definition: grid_matrix.h:50
virtual const SparseMatrix * asSparse() const =0
Sparse matrix structure optimized for XC data access pattern.
Definition: sparse_matrix.h:56
Definition: grid_matrix.h:42
Definition: allocate.cc:39
double ergo_real
Definition: realtype.h:69
Declares a sparse matrix optimized for the XC code.