Psi4
occ/arrays.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef _psi_src_bin_occ_arrays_h_
30 #define _psi_src_bin_occ_arrays_h_
31 
32 #include "psi4/libciomr/libciomr.h"
33 #include "psi4/libiwl/iwl.h"
34 
35 
36 
37 
38 using namespace psi;
39 using namespace std;
40 
41 namespace psi{ namespace occwave{
42 
43 class Array1d;
44 class Array2d;
45 class Array3d;
46 class Array1i;
47 class Array3i;
48 
49 class Array1d
50 {
51 
52  private:
53  double *A1d_;
54  int dim1_;
55  string name_; // Name of the array
56 
57  public:
58  Array1d(int d1);
59  Array1d(string name, int d1);
60  Array1d(); //default constructer
61  ~Array1d(); //destructer
62 
63  Array1d* generate(int d1);
64  Array1d* generate(string name, int d1);
65  void init(string name, int d1);
66  void init(int d1);
67  void memalloc();
68  void zero();
69  void print();
70  void print(std::string OutFileRMR);
71  void release();
72  void set(int i, double value);
73  void set(double *vec);
74  void set(const Array1d *vec);
75  void add(const Array1d* Adum);
76  void add(int i, double value);// add value to ith element of the vector
77  void subtract(const Array1d* Adum);
78  void subtract(int i, double value);
79  double get(int i);
80  // rms: rms of A1d_
81  double rms();
82  // rms: rms of (A1d_ - Atemp)
83  double rms(const Array1d* Atemp);
84  // dot: return result of A1d_' * y
85  double dot(const Array1d *y);
86  // gemv: A1d_ = alpha * A * b + beta, where A is a general matrix
87  void gemv(bool transa, double alpha, const Array2d* a, const Array1d* b, double beta);
88  // gbmv: This function may NOT working correctly!!!!
89  void gbmv(bool transa, double alpha, const Array2d* a, const Array1d* b, double beta);
90  // xay: return result of A1d_' * A * y
91  double xay(const Array2d *a, const Array1d *y);
92  void scale(double a);
93  void copy(double *x);
94  void copy(const Array1d *x);
95  // row_vector: set A1d to nth row of A, dim1_ = A->dim2
96  void row_vector(Array2d *A, int n);
97  // column_vector: set A1d to nth column of A, dim1_ = A->dim1
98  void column_vector(Array2d *A, int n);
99  int dim1() const { return dim1_; }
100  // dirprd: A1d_[i] = a[i] * b[i]
101  void dirprd(Array1d *a, Array1d *b);
102 
103  friend class Array2d;
104  friend class Array3d;
105 };
106 
107 
108 class Array2d
109 {
110 
111  private:
112  double **A2d_;
113  int dim1_,dim2_;
114  string name_; // Name of the array
115 
116  public:
117  Array2d(int d1,int d2);
118  Array2d(string name, int d1,int d2);
119  Array2d(); //default constructer
120  ~Array2d(); //destructer
121 
122  Array2d* generate(int d1,int d2);
123  Array2d* generate(string name, int d1,int d2);
124  void init(string name, int d1,int d2);
125  void init(int d1,int d2);
126  void memalloc();
127  void zero();
128  void zero_diagonal();
129  void print();
130  void print(std::string OutFileRMR);
131  void release();
132  void set(int i, int j, double value);
133  void set(double **A);
134  double get(int i, int j);
135  void add(const Array2d* Adum);
136  void add(int i, int j, double value);
137  void subtract(const Array2d* Adum);
138  void subtract(int i, int j, double value);
139  Array2d* transpose();
140  void copy(const Array2d* Adum);
141  void copy(double **a);
142  // diagonalize: diagonalize via rsp
143  void diagonalize(Array2d* eigvectors, Array1d* eigvalues, double cutoff);
144  // cdsyev: diagonalize via lapack
145  void cdsyev(char jobz, char uplo, Array2d* eigvectors, Array1d* eigvalues);
146  // davidson: diagonalize via davidson algorithm
147  void davidson(int n_eigval, Array2d* eigvectors, Array1d* eigvalues, double cutoff, int print);
148  // cdgesv: solve a linear equation via lapack
149  void cdgesv(Array1d* Xvec);
150  void cdgesv(double* Xvec);
151  void cdgesv(Array1d* Xvec, int errcod);
152  void cdgesv(double* Xvec, int errcod);
153  // lineq_flin: solve a linear equation via FLIN
154  void lineq_flin(Array1d* Xvec, double *det);
155  void lineq_flin(double* Xvec, double *det);
156  // lineq_pople: solve a linear equation via Pople's algorithm
157  void lineq_pople(Array1d* Xvec, int num_vecs, double cutoff);
158  void lineq_pople(double* Xvec, int num_vecs, double cutoff);
159  // gemm: matrix multiplication
160  void gemm(bool transa, bool transb, double alpha, const Array2d* a, const Array2d* b, double beta);
161  // level_shift: A[i][i] = A[i][i] - value
162  void level_shift(double value);
163  // outer_product: A = x * y'
164  void outer_product(const Array1d *x, const Array1d *y);
165  void scale(double a);
166  // scale_row: scales mth row with a
167  void scale_row(int m, double a);
168  // scale_column: scales nth column with a
169  void scale_column(int n, double a);
170  // identity: A = I
171  void identity();
172  double trace();
173  // transform: A = L' * B * L
174  void transform(const Array2d* a, const Array2d* transformer);
175  // back_transform: A = L * B * L'
176  void back_transform(const Array2d* a, const Array2d* transformer);
177  // pseudo_transform: A = L * B * L
178  void pseudo_transform(const Array2d* a, const Array2d* transformer);
179  // triple_gemm: A2d_ = a * b * c
180  void triple_gemm(const Array2d* a, const Array2d* b, const Array2d* c);
181  // vector_dot: value = Tr(A' * B)
182  double vector_dot(Array2d *rhs);
183  double vector_dot(double **rhs);
184  double **to_block_matrix();
185  double *to_lower_triangle();
186  // mgs: orthogonalize with a Modified Gram-Schmid algorithm
187  void mgs();
188  // gs: orthogonalize with a Classical Gram-Schmid algorithm
189  void gs();
190  // row_vector: return nth row as a vector
191  double *row_vector(int n);
192  // column_vector: return nth column as a vector
193  double *column_vector(int n);
194  int dim1() const { return dim1_; }
195  int dim2() const { return dim2_; }
196  /*
197  void write(psi::PSIO* psio, unsigned int fileno);
198  void write(shared_ptr<psi::PSIO> psio, unsigned int fileno);
199  void write(psi::PSIO& psio, unsigned int fileno);
200  void read(psi::PSIO* psio, unsigned int fileno);
201  void read(psi::PSIO& psio, unsigned int fileno);
202  bool read(PSIO* psio, int itap, const char *label, int dim);
203  bool read(shared_ptr<psi::PSIO> psio, int itap, const char *label, int dim);
204  */
205 
206  friend class Array1d;
207  friend class Array3d;
208 };
209 
210 class Array3d
211 {
212 
213  private:
214  double ***A3d_;
215  int dim1_,dim2_,dim3_;
216  string name_; // Name of the array
217 
218  public:
219  Array3d(int d1,int d2, int d3);
220  Array3d(string name, int d1,int d2, int d3);
221  Array3d(); //default constructer
222  ~Array3d(); //destructer
223 
224  Array3d* generate(int d1,int d2, int d3);
225  Array3d* generate(string name, int d1,int d2, int d3);
226  void init(string name, int d1,int d2, int d3);
227  void init(int d1,int d2, int d3);
228  void memalloc();
229  void zero();
230  void print();
231  void release();
232  void set(int h, int i, int j, double value);
233  double get(int h, int i, int j);
234 
235  friend class Array1d;
236  friend class Array2d;
237 };
238 
239 class Array1i
240 {
241 
242  private:
243  int *A1i_;
244  int dim1_;
245  string name_; // Name of the array
246 
247  public:
248  Array1i(int d1);
249  Array1i(string name, int d1);
250  Array1i(); //default constructer
251  ~Array1i(); //destructer
252 
253  Array1i* generate(int d1);
254  Array1i* generate(string name, int d1);
255  void init(string name, int d1);
256  void init(int d1);
257  void memalloc();
258  void zero();
259  void print();
260  void release();
261  void set(int i, int value);
262  int get(int i);
263  void add(const Array1i* Adum);
264  void add(int i, int value);
265  void subtract(const Array1i* Adum);
266  void subtract(int i, int value);
267 
268 };
269 
270 class Array3i
271 {
272 
273  private:
274  int ***A3i_;
275  int dim1_,dim2_,dim3_;
276  string name_; // Name of the array
277 
278  public:
279  Array3i(int d1,int d2, int d3);
280  Array3i(string name, int d1,int d2, int d3);
281  Array3i(); //default constructer
282  ~Array3i(); //destructer
283 
284  Array3i* generate(int d1,int d2, int d3);
285  Array3i* generate(string name, int d1,int d2, int d3);
286  void init(string name, int d1,int d2, int d3);
287  void init(int d1,int d2, int d3);
288  void memalloc();
289  void zero();
290  void print();
291  void release();
292  void set(int h, int i, int j, int value);
293  int get(int h, int i, int j);
294 };
295 }} // End Namespaces
296 #endif // _psi_src_bin_occ_arrays_h_
int *** A3i_
Definition: occ/arrays.h:274
int dim1() const
Definition: occ/arrays.h:194
int dim1_
Definition: occ/arrays.h:54
double dot(BlockMatrix *A, BlockMatrix *B)
Definition: mcscf/block_matrix.cc:224
string name_
Definition: occ/arrays.h:114
string name_
Definition: occ/arrays.h:216
double ** A2d_
Definition: occ/arrays.h:112
int dim3_
Definition: occ/arrays.h:275
Definition: occ/arrays.h:239
string name_
Definition: occ/arrays.h:276
Definition: matrixtmp.h:42
Definition: pointgrp.h:106
int dim3_
Definition: occ/arrays.h:215
int dim1() const
Definition: occ/arrays.h:99
Definition: occ/arrays.h:210
SharedWavefunction occwave(SharedWavefunction, Options &)
Definition: occ/main.cc:35
int dim2_
Definition: occ/arrays.h:113
string name_
Definition: occ/arrays.h:245
double *** A3d_
Definition: occ/arrays.h:214
string name_
Definition: occ/arrays.h:55
Definition: occ/arrays.h:270
int * A1i_
Definition: occ/arrays.h:243
int dim1_
Definition: occ/arrays.h:244
Definition: occ/arrays.h:49
int dim2() const
Definition: occ/arrays.h:195
Definition: PsiFileImpl.h:39
Definition: occ/arrays.h:108
double * A1d_
Definition: occ/arrays.h:53