v2DM-DOCI  1.0
UnitaryMatrix.h
Go to the documentation of this file.
1 // CIFlow is a very flexible configuration interaction program
2 // Copyright (C) 2014 Mario Van Raemdonck <mario.vanraemdonck@UGent.be>
3 //
4 // This file is part of CIFlow.
5 //
6 // CIFlow is private software; developed by Mario Van Raemdonck
7 // a member of the Ghent Quantum Chemistry Group (Ghent University).
8 // See also : http://www.quantum.ugent.be
9 //
10 // At this moment CIFlow is not yet distributed.
11 // However this might change in the future in the hope that
12 // it will be useful to someone.
13 //
14 // For now you have to ask the main author for permission.
15 //
16 //--
17 #ifndef _UnitaryMatrix_H
18 #define _UnitaryMatrix_H
19 
20 #include <memory>
21 #include <vector>
22 #include "OptIndex.h" //For optindex (should put this in a separate file)
23 
24 namespace simanneal {
25 
31 {
32  public:
33 
35 
36  UnitaryMatrix(const OptIndex&);
37 
39  UnitaryMatrix(const UnitaryMatrix & unit);
40 
42 
44  virtual ~UnitaryMatrix() = default;
45 
47 
49 
51 
52  unsigned int getNumVariablesX() const;
53 
55 
57  int getFirstIndex(const int linearindex) const;
58 
60 
62  int getSecondIndex(const int linearindex) const;
63 
65 
67  double * getBlock(const int irrep) const;
68 
70 
71  void copyXsolutionBack(double * vector);
72 
74 
76  void updateUnitary(double * workmem1, double * workmem2, double * vector , const bool multiply);
77 
79 
81  void rotate_active_space_vectors(double * eigenvecs, double * work);
82 
84 
85  void CheckDeviationFromUnitary(double * work) const;
86 
88  void saveU(std::string savename) const;
89 
91  void loadU(std::string loadname);
92 
94  void deleteStoredUnitary(std::string name) const;
95 
97  void jacobi_rotation(int irrep, int i, int j, double angle);
98 
100  void reset_unitary();
101 
102  void print_unitary() const;
103 
104  void build_skew_symm_x(const int irrep, double * xblock , const double * Xelem) const;
105 
106  void sendreceive(int);
107 
108  int get_Nirrep() const;
109 
110  void updateUnitary(double *, double *, const UnitaryMatrix &, bool);
111 
112  void fill_random();
113 
114  void make_skew_symmetric();
115 
116  private:
117 
118  //Externally created and destroyed index handler
119  std::unique_ptr<OptIndex> _index;
120 
121  //Number of variables in the x-matrix
122  unsigned int x_linearlength;
123 
124  //The unitary matrix (e^x * previous unitary): unitary[irrep][row + size_irrep * col]
125  std::vector< std::unique_ptr<double []> > unitary;
126 
127  // Find the linear index corresponding to p and q
132  };
133 
134 }
135 #endif
136 
137 /* vim: set ts=4 sw=4 expandtab :*/
void build_skew_symm_x(const int irrep, double *xblock, const double *Xelem) const
UnitaryMatrix & operator=(const UnitaryMatrix &unit)
void rotate_active_space_vectors(double *eigenvecs, double *work)
Rotate the unitary matrix to the NO eigenbasis.
void copyXsolutionBack(double *vector)
Copy the x solution back (NR, augmented NR, ...)
void jacobi_rotation(int irrep, int i, int j, double angle)
Implements a simple jacobi rotation of the i, and j th orbital.
virtual ~UnitaryMatrix()=default
Destructor.
int getSecondIndex(const int linearindex) const
Get the second Hamiltonian index corresponding to linearindex.
int getFirstIndex(const int linearindex) const
Get the first Hamiltonian index corresponding to linearindex.
unsigned int getNumVariablesX() const
Get the number of variables in the x-parametrization of the unitary update.
void CheckDeviationFromUnitary(double *work) const
Calculate the two-norm of U^T*U - I.
std::unique_ptr< OptIndex > _index
UnitaryMatrix(const OptIndex &)
Constructor.
std::vector< std::unique_ptr< double[]> > unitary
void deleteStoredUnitary(std::string name) const
Delete the stored unitary (on disk)
void saveU(std::string savename) const
Save the unitary to disk.
void loadU(std::string loadname)
Load the unitary from disk.
double * getBlock(const int irrep) const
Get the unitary rotation for block irrep.
void updateUnitary(double *workmem1, double *workmem2, double *vector, const bool multiply)
Update the unitary transformation based on the new vector and the previous unitary.
void reset_unitary()
Resets the unitary matrix.