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-2019 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 using namespace psi;
36 
37 namespace psi {
38 namespace occwave {
39 
40 class Array1d;
41 class Array2d;
42 class Array3d;
43 class Array1i;
44 class Array3i;
45 
46 class Array1d {
47  private:
48  double* A1d_;
49  int dim1_;
50  std::string name_; // Name of the array
51 
52  public:
53  Array1d(int d1);
54  Array1d(std::string name, int d1);
55  Array1d(); // default constructer
56  ~Array1d(); // destructer
57 
58  Array1d* generate(int d1);
59  Array1d* generate(std::string name, int d1);
60  void init(std::string name, int d1);
61  void init(int d1);
62  void memalloc();
63  void zero();
64  void print();
65  void print(std::string out_fname);
66  void release();
67  void set(int i, double value);
68  void set(double* vec);
69  void set(const Array1d* vec);
70  void add(const Array1d* Adum);
71  void add(int i, double value); // add value to ith element of the vector
72  void subtract(const Array1d* Adum);
73  void subtract(int i, double value);
74  double get(int i);
75  // rms: rms of A1d_
76  double rms();
77  // rms: rms of (A1d_ - Atemp)
78  double rms(const Array1d* Atemp);
79  // dot: return result of A1d_' * y
80  double dot(const Array1d* y);
81  // gemv: A1d_ = alpha * A * b + beta, where A is a general matrix
82  void gemv(bool transa, double alpha, const Array2d* a, const Array1d* b, double beta);
83  // gbmv: This function may NOT working correctly!!!!
84  void gbmv(bool transa, double alpha, const Array2d* a, const Array1d* b, double beta);
85  // xay: return result of A1d_' * A * y
86  double xay(const Array2d* a, const Array1d* y);
87  void scale(double a);
88  void copy(double* x);
89  void copy(const Array1d* x);
90  // row_vector: set A1d to nth row of A, dim1_ = A->dim2
91  void row_vector(Array2d* A, int n);
92  // column_vector: set A1d to nth column of A, dim1_ = A->dim1
93  void column_vector(Array2d* A, int n);
94  int dim1() const { return dim1_; }
95  // dirprd: A1d_[i] = a[i] * b[i]
96  void dirprd(Array1d* a, Array1d* b);
97 
98  friend class Array2d;
99  friend class Array3d;
100 };
101 
102 class Array2d {
103  private:
104  double** A2d_;
105  int dim1_, dim2_;
106  std::string name_; // Name of the array
107 
108  public:
109  Array2d(int d1, int d2);
110  Array2d(std::string name, int d1, int d2);
111  Array2d(); // default constructer
112  ~Array2d(); // destructer
113 
114  Array2d* generate(int d1, int d2);
115  Array2d* generate(std::string name, int d1, int d2);
116  void init(std::string name, int d1, int d2);
117  void init(int d1, int d2);
118  void memalloc();
119  void zero();
120  void zero_diagonal();
121  void print();
122  void print(std::string out_fname);
123  void release();
124  void set(int i, int j, double value);
125  void set(double** A);
126  double get(int i, int j);
127  void add(const Array2d* Adum);
128  void add(int i, int j, double value);
129  void subtract(const Array2d* Adum);
130  void subtract(int i, int j, double value);
131  Array2d* transpose();
132  void copy(const Array2d* Adum);
133  void copy(double** a);
134  // diagonalize: diagonalize via rsp
135  void diagonalize(Array2d* eigvectors, Array1d* eigvalues, double cutoff);
136  // cdsyev: diagonalize via lapack
137  void cdsyev(char jobz, char uplo, Array2d* eigvectors, Array1d* eigvalues);
138  // davidson: diagonalize via davidson algorithm
139  void davidson(int n_eigval, Array2d* eigvectors, Array1d* eigvalues, double cutoff, int print);
140  // cdgesv: solve a linear equation via lapack
141  void cdgesv(Array1d* Xvec);
142  void cdgesv(double* Xvec);
143  void cdgesv(Array1d* Xvec, int errcod);
144  void cdgesv(double* Xvec, int errcod);
145  // lineq_flin: solve a linear equation via FLIN
146  void lineq_flin(Array1d* Xvec, double* det);
147  void lineq_flin(double* Xvec, double* det);
148  // lineq_pople: solve a linear equation via Pople's algorithm
149  void lineq_pople(Array1d* Xvec, int num_vecs, double cutoff);
150  void lineq_pople(double* Xvec, int num_vecs, double cutoff);
151  // gemm: matrix multiplication
152  void gemm(bool transa, bool transb, double alpha, const Array2d* a, const Array2d* b, double beta);
153  // level_shift: A[i][i] = A[i][i] - value
154  void level_shift(double value);
155  // outer_product: A = x * y'
156  void outer_product(const Array1d* x, const Array1d* y);
157  void scale(double a);
158  // scale_row: scales mth row with a
159  void scale_row(int m, double a);
160  // scale_column: scales nth column with a
161  void scale_column(int n, double a);
162  // identity: A = I
163  void identity();
164  double trace();
165  // transform: A = L' * B * L
166  void transform(const Array2d* a, const Array2d* transformer);
167  // back_transform: A = L * B * L'
168  void back_transform(const Array2d* a, const Array2d* transformer);
169  // pseudo_transform: A = L * B * L
170  void pseudo_transform(const Array2d* a, const Array2d* transformer);
171  // triple_gemm: A2d_ = a * b * c
172  void triple_gemm(const Array2d* a, const Array2d* b, const Array2d* c);
173  // vector_dot: value = Tr(A' * B)
174  double vector_dot(Array2d* rhs);
175  double vector_dot(double** rhs);
176  double** to_block_matrix();
177  double* to_lower_triangle();
178  // mgs: orthogonalize with a Modified Gram-Schmid algorithm
179  void mgs();
180  // gs: orthogonalize with a Classical Gram-Schmid algorithm
181  void gs();
182  // row_vector: return nth row as a vector
183  double* row_vector(int n);
184  // column_vector: return nth column as a vector
185  double* column_vector(int n);
186  int dim1() const { return dim1_; }
187  int dim2() const { return dim2_; }
188  /*
189  void write(psi::PSIO* psio, size_t fileno);
190  void write(shared_ptr<psi::PSIO> psio, size_t fileno);
191  void write(psi::PSIO& psio, size_t fileno);
192  void read(psi::PSIO* psio, size_t fileno);
193  void read(psi::PSIO& psio, size_t fileno);
194  bool read(PSIO* psio, int itap, const char *label, int dim);
195  bool read(shared_ptr<psi::PSIO> psio, int itap, const char *label, int dim);
196  */
197 
198  friend class Array1d;
199  friend class Array3d;
200 };
201 
202 class Array3d {
203  private:
204  double*** A3d_;
205  int dim1_, dim2_, dim3_;
206  std::string name_; // Name of the array
207 
208  public:
209  Array3d(int d1, int d2, int d3);
210  Array3d(std::string name, int d1, int d2, int d3);
211  Array3d(); // default constructer
212  ~Array3d(); // destructer
213 
214  Array3d* generate(int d1, int d2, int d3);
215  Array3d* generate(std::string name, int d1, int d2, int d3);
216  void init(std::string name, int d1, int d2, int d3);
217  void init(int d1, int d2, int d3);
218  void memalloc();
219  void zero();
220  void print();
221  void release();
222  void set(int h, int i, int j, double value);
223  double get(int h, int i, int j);
224 
225  friend class Array1d;
226  friend class Array2d;
227 };
228 
229 class Array1i {
230  private:
231  int* A1i_;
232  int dim1_;
233  std::string name_; // Name of the array
234 
235  public:
236  Array1i(int d1);
237  Array1i(std::string name, int d1);
238  Array1i(); // default constructer
239  ~Array1i(); // destructer
240 
241  Array1i* generate(int d1);
242  Array1i* generate(std::string name, int d1);
243  void init(std::string name, int d1);
244  void init(int d1);
245  void memalloc();
246  void zero();
247  void print();
248  void release();
249  void set(int i, int value);
250  int get(int i);
251  void add(const Array1i* Adum);
252  void add(int i, int value);
253  void subtract(const Array1i* Adum);
254  void subtract(int i, int value);
255 };
256 
257 class Array3i {
258  private:
259  int*** A3i_;
260  int dim1_, dim2_, dim3_;
261  std::string name_; // Name of the array
262 
263  public:
264  Array3i(int d1, int d2, int d3);
265  Array3i(std::string name, int d1, int d2, int d3);
266  Array3i(); // default constructer
267  ~Array3i(); // destructer
268 
269  Array3i* generate(int d1, int d2, int d3);
270  Array3i* generate(std::string name, int d1, int d2, int d3);
271  void init(std::string name, int d1, int d2, int d3);
272  void init(int d1, int d2, int d3);
273  void memalloc();
274  void zero();
275  void print();
276  void release();
277  void set(int h, int i, int j, int value);
278  int get(int h, int i, int j);
279 };
280 }
281 } // End Namespaces
282 #endif // _psi_src_bin_occ_arrays_h_
int *** A3i_
Definition: occ/arrays.h:259
int dim1() const
Definition: occ/arrays.h:186
std::string name_
Definition: occ/arrays.h:206
int dim1_
Definition: occ/arrays.h:49
double dot(BlockMatrix *A, BlockMatrix *B)
Definition: mcscf/block_matrix.cc:199
std::string name_
Definition: occ/arrays.h:50
double ** A2d_
Definition: occ/arrays.h:104
int dim3_
Definition: occ/arrays.h:260
Definition: occ/arrays.h:229
Definition: matrixtmp.h:42
Definition: pointgrp.h:104
int dim3_
Definition: occ/arrays.h:205
std::string name_
Definition: occ/arrays.h:261
int dim1() const
Definition: occ/arrays.h:94
Definition: occ/arrays.h:202
SharedWavefunction occwave(SharedWavefunction, Options &)
Definition: occ/main.cc:34
std::string name_
Definition: occ/arrays.h:106
int dim2_
Definition: occ/arrays.h:105
double *** A3d_
Definition: occ/arrays.h:204
Definition: occ/arrays.h:257
int * A1i_
Definition: occ/arrays.h:231
std::string name_
Definition: occ/arrays.h:233
int dim1_
Definition: occ/arrays.h:232
Definition: occ/arrays.h:46
int dim2() const
Definition: occ/arrays.h:187
Definition: occ/arrays.h:102
double * A1d_
Definition: occ/arrays.h:48