ergo
random_matrices.h
Go to the documentation of this file.
1 /* Ergo, version 3.7, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2018 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 
41 #include "matrix_typedefs.h" // definitions of matrix types and interval type (source)
42 #include "realtype.h" // definitions of types (utilities_basic)
43 #include "matrix_utilities.h"
45 #include "SizesAndBlocks.h"
46 #include "Matrix.h"
47 #include "Vector.h"
48 #include "MatrixSymmetric.h"
49 #include "MatrixTriangular.h"
50 #include "MatrixGeneral.h"
51 #include "VectorGeneral.h"
52 #include "output.h"
53 
54 #include "files_dense.h"
55 #include "files_sparse.h"
56 
57 #include <iostream>
58 #include <fstream>
59 #include <sstream>
60 #include <string.h>
61 
62 
63 using namespace std;
64 
65 
66 
71 
72 typedef std::vector<int> VectorTypeInt;
73 
74 #define MAX_DOUBLE std::numeric_limits<real>::max()
75 #define MIN_DOUBLE std::numeric_limits<real>::min()
76 
77 
78 #define PI 3.14159265 // needed for sprandsym
79 
80 
81 void print_matrix(std::vector<ergo_real> const &A);
82 template<typename Matrix>
83 void init_matrix(Matrix &X, const int N, int blockSizesMultuple = 4);
84 void get_random_matrix(int N, MatrixTypeInner &X);
85 void get_all_eigenvalues_of_matrix(std::vector<ergo_real> & eigvalList, const MatrixTypeInner & M);
86 void sprandsym(int N, MatrixTypeInner &X, MatrixGeneral &Q, vector<ergo_real> &D, const double MATRIX_SPARSITY);
87 int get_matrix_from_sparse(char *filename, MatrixTypeInner &X);
88 int get_matrix_from_sparse_vec(char *filename, std::vector<int> &I, std::vector<int> &J, std::vector<real> &val);
89 int get_matrix_from_binary(char *filename, MatrixTypeInner &X);
90 int get_matrix_from_binary_vec(char *filename, std::vector<int> &I, std::vector<int> &J, std::vector<real> &val, int &N);
91 int get_matrix_from_full(char * filename, MatrixTypeInner &X);
92 
93 
99 template<typename Matrix>
100 void init_matrix(Matrix &X, const int N, int blockSizesMultuple /*=4*/)
101 {
102  /********** Initialization of SizesAndBlocks */
103  int size = N;
104  int nlevels = 5;
105  std::vector<int> blockSizes(nlevels);
106  blockSizes[nlevels - 1] = 1; // should always be one
107  for (int ind = nlevels - 2; ind >= 0; ind--)
108  blockSizes[ind] = blockSizes[ind + 1] * blockSizesMultuple;
109  mat::SizesAndBlocks rows(blockSizes, size);
110  mat::SizesAndBlocks cols(blockSizes, size);
111  /********************************************/
112  X.resetSizesAndBlocks(rows,cols);
113 }
#define A
int get_matrix_from_sparse_vec(char *filename, std::vector< int > &I, std::vector< int > &J, std::vector< real > &val)
Definition: random_matrices.cc:406
int get_matrix_from_binary(char *filename, MatrixTypeInner &X)
Definition: random_matrices.cc:422
General vector class.
mat::SizesAndBlocks rows
Definition: test.cc:51
Functionality for writing output messages to a text file.
normalMatrix MatrixGeneral
Definition: random_matrices.h:70
mat::SizesAndBlocks cols
Definition: test.cc:52
intervalType IntervalType
Definition: random_matrices.h:67
Wrapper routines for different parts of the integral code, including conversion of matrices from/to t...
triangMatrix TriangMatrixType
Definition: random_matrices.h:69
std::vector< int > VectorTypeInt
Definition: random_matrices.h:72
void sprandsym(int N, MatrixTypeInner &X, MatrixGeneral &Q, vector< ergo_real > &D, const double MATRIX_SPARSITY)
Definition: random_matrices.cc:114
File containing declaration of functions for reading/writing dense matrices and vectors.
Utilities related to the hierarchical matrix library (HML), including functions for setting up permut...
Class used to keep track of the block sizes used at different levels in the hierarchical matrix data ...
MatrixSymmetric< real, matri > symmMatrix
Definition: test_LanczosSeveralLargestEig.cc:69
Describes dimensions of matrix and its blocks on all levels.
Definition: SizesAndBlocks.h:45
int get_matrix_from_full(char *filename, MatrixTypeInner &X)
Definition: random_matrices.cc:465
File containing declarations of functions for reading/writing sparse matrices from/to mtx (MatrixMark...
Triangular matrix class.
void get_all_eigenvalues_of_matrix(std::vector< ergo_real > &eigvalList, const MatrixTypeInner &M)
Definition: random_matrices.cc:90
MatrixGeneral< real, matri > normalMatrix
Definition: test_LanczosSeveralLargestEig.cc:71
Definition of the main floating-point datatype used; the ergo_real type.
MatrixTriangular< real, matri > triangMatrix
Definition: test_LanczosSeveralLargestEig.cc:70
Symmetric matrix class.
The heart of the matrix library.
General matrix class.
void init_matrix(Matrix &X, const int N, int blockSizesMultuple=4)
Create hierarchical matrix structure.
Definition: random_matrices.h:100
Copyright(c) Emanuel Rubensson 2006.
Header file with typedefs for matrix and vector types.
int get_matrix_from_binary_vec(char *filename, std::vector< int > &I, std::vector< int > &J, std::vector< real > &val, int &N)
Definition: random_matrices.cc:441
void get_random_matrix(int N, MatrixTypeInner &X)
Definition: random_matrices.cc:59
symmMatrix MatrixTypeInner
Definition: random_matrices.h:68
void print_matrix(std::vector< ergo_real > const &A)
Definition: random_matrices.cc:46
int get_matrix_from_sparse(char *filename, MatrixTypeInner &X)
Definition: random_matrices.cc:390