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