Psi4
points.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-2018 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 libfock_points_H
30 #define libfock_points_H
31 
32 #include "psi4/libmints/typedefs.h"
33 #include "psi4/pragma.h"
34 
35 #include <cstdio>
36 #include <map>
37 #include <unordered_map>
38 #include <tuple>
39 #include <vector>
40 #include <string>
41 
42 namespace psi {
43 
44 class BasisSet;
45 class Vector;
46 class BlockOPoints;
47 
49  protected:
51  std::shared_ptr<BasisSet> primary_;
53  bool puream_;
59  int deriv_;
61  std::map<std::string, SharedMatrix> basis_values_;
63  std::map<std::string, SharedMatrix> basis_temps_;
65  virtual void allocate();
66 
67  public:
68  // => Constructors <= //
69 
70  BasisFunctions(std::shared_ptr<BasisSet> primary, int max_points, int max_functions);
71  virtual ~BasisFunctions();
72 
73  // => Computers <= //
74 
75  void compute_functions(std::shared_ptr<BlockOPoints> block);
76 
77  // => Accessors <= //
78 
79  SharedMatrix basis_value(const std::string& key) { return basis_values_[key]; }
80  std::map<std::string, SharedMatrix>& basis_values() { return basis_values_; }
81 
82  int max_functions() const { return max_functions_; }
83  int max_points() const { return max_points_; }
84  int deriv() const { return deriv_; }
85 
86  virtual void print(std::string out_fname = "outfile", int print = 2) const;
87 
88  // => Setters <= //
89 
90  void set_deriv(int deriv) {
91  deriv_ = deriv;
92  allocate();
93  }
94  void set_max_functions(int max_functions) {
95  max_functions_ = max_functions;
96  allocate();
97  }
98  void set_max_points(int max_points) {
99  max_points_ = max_points;
100  allocate();
101  }
102 };
103 
105  protected:
106  // => Indices <= //
107 
109  size_t block_index_;
110 
111  // Contains a map to the cache the global basis_values
112  std::unordered_map<size_t, std::map<std::string, SharedMatrix>>* cache_map_ = nullptr;
113 
114  // Contains a pointer to the current map to use for basis_values
115  std::map<std::string, SharedMatrix>* current_basis_map_ = nullptr;
116 
118  int ansatz_;
120  std::map<std::string, std::shared_ptr<Vector>> point_values_;
121 
122  // => Orbital Collocation <= //
123 
125  std::map<std::string, std::shared_ptr<Matrix>> orbital_values_;
126 
127  public:
128  // => Constructors <= //
129 
130  PointFunctions(std::shared_ptr<BasisSet> primary, int max_points, int max_functions);
131  ~PointFunctions() override;
132 
133  // => Setters <= //
134  void set_cache_map(std::unordered_map<size_t, std::map<std::string, SharedMatrix>>* cache_map) {
135  cache_map_ = cache_map;
136  }
137 
138  // => Computers <= //
139 
140  virtual void compute_points(std::shared_ptr<BlockOPoints> block, bool force_compute = true) = 0;
141 
142  // => Accessors <= //
143 
144  std::shared_ptr<Vector> point_value(const std::string& key);
145  std::map<std::string, SharedVector>& point_values() { return point_values_; }
146 
147  SharedMatrix basis_value(const std::string& key) { return (*current_basis_map_)[key]; }
148  std::map<std::string, SharedMatrix>& basis_values() { return (*current_basis_map_); }
149 
150  virtual std::vector<SharedMatrix> scratch() = 0;
151  virtual std::vector<SharedMatrix> D_scratch() = 0;
152 
153  int ansatz() const { return ansatz_; }
154 
155  // => Setters <= //
156 
157  void set_ansatz(int ansatz) {
158  ansatz_ = ansatz;
159  deriv_ = ansatz;
160  allocate();
161  }
162  virtual void set_pointers(SharedMatrix Da_occ_AO) = 0;
163  virtual void set_pointers(SharedMatrix Da_occ_AO, SharedMatrix Db_occ_AO) = 0;
164 
165  // => Orbital Collocation <= //
166 
167  std::shared_ptr<Matrix> orbital_value(const std::string& key);
168  std::map<std::string, SharedMatrix>& orbital_values() { return orbital_values_; }
169 
170  virtual void compute_orbitals(std::shared_ptr<BlockOPoints> block, bool force_compute = true) = 0;
171  virtual void set_Cs(SharedMatrix Cocc) = 0;
172  virtual void set_Cs(SharedMatrix Caocc, SharedMatrix Cbocc) = 0;
173 };
174 
175 class RKSFunctions : public PointFunctions {
176  protected:
177  // => Pointers <= //
178 
181 
182  // => Temps <= //
183 
188 
190  void build_temps();
192  void allocate() override;
193 
194  // => Orbital Collocation <= //
195 
200 
201  public:
202  RKSFunctions(std::shared_ptr<BasisSet> primary, int max_points, int max_functions);
203  ~RKSFunctions() override;
204 
205  void set_pointers(SharedMatrix Da_occ_AO) override;
206  void set_pointers(SharedMatrix Da_occ_AO, SharedMatrix Db_occ_AO) override;
207 
208  void compute_points(std::shared_ptr<BlockOPoints> block, bool force_compute = true) override;
209 
210  std::vector<SharedMatrix> scratch() override;
211  std::vector<SharedMatrix> D_scratch() override;
212 
213  void print(std::string out_fname = "outfile", int print = 2) const override;
214 
215  void compute_orbitals(std::shared_ptr<BlockOPoints> block, bool force_compute = true) override;
216  void set_Cs(SharedMatrix Cocc) override;
217  void set_Cs(SharedMatrix Caocc, SharedMatrix Cbocc) override;
218  size_t block_index() { return block_index_; }
219 };
220 
221 class UKSFunctions : public PointFunctions {
222  protected:
223  // => Pointers <= //
224 
229 
230  // => Temps <= //
231 
240 
242  void build_temps();
244  void allocate() override;
245 
246  // => Orbital Collocation <= //
247 
256 
257  public:
258  UKSFunctions(std::shared_ptr<BasisSet> primary, int max_points, int max_functions);
259  ~UKSFunctions() override;
260 
261  void set_pointers(SharedMatrix Da_occ_AO) override;
262  void set_pointers(SharedMatrix Da_occ_AO, SharedMatrix Db_occ_AO) override;
263  void set_cache_map(std::unordered_map<size_t, std::map<std::string, SharedMatrix>>* cache_map) {
264  cache_map_ = cache_map;
265  }
266 
267  void compute_points(std::shared_ptr<BlockOPoints> block, bool force_compute = true) override;
268 
269  std::vector<SharedMatrix> scratch() override;
270  std::vector<SharedMatrix> D_scratch() override;
271 
272  void print(std::string out_fname = "outfile", int print = 2) const override;
273 
274  void compute_orbitals(std::shared_ptr<BlockOPoints> block, bool force_compute = true) override;
275  void set_Cs(SharedMatrix Cocc) override;
276  void set_Cs(SharedMatrix Caocc, SharedMatrix Cbocc) override;
277  size_t block_index() { return block_index_; }
278 };
279 }
280 #endif
SharedMatrix D_local_
Local D matrix.
Definition: points.h:187
void print(std::string out_fname="outfile", int print=2) const override
Definition: points.cc:556
std::map< std::string, SharedMatrix > & basis_values()
Definition: points.h:80
void set_Cs(SharedMatrix Cocc) override
Definition: points.cc:231
void compute_orbitals(std::shared_ptr< BlockOPoints > block, bool force_compute=true) override
Definition: points.cc:240
virtual void compute_points(std::shared_ptr< BlockOPoints > block, bool force_compute=true)=0
virtual void allocate()
Allocate registers.
Definition: points.cc:602
Definition: points.h:104
int max_functions_
Maximum number of functions in a block.
Definition: points.h:57
std::map< std::string, SharedVector > & point_values()
Definition: points.h:145
void compute_points(std::shared_ptr< BlockOPoints > block, bool force_compute=true) override
Definition: points.cc:93
void set_Cs(SharedMatrix Cocc) override
Definition: points.cc:499
SharedMatrix Cb_AO_
Orbital coefficients, AO.
Definition: points.h:251
SharedMatrix basis_value(const std::string &key)
Definition: points.h:79
SharedMatrix tempa_
Buffer for half-transform.
Definition: points.h:233
virtual std::vector< SharedMatrix > scratch()=0
void allocate() override
Allocate registers.
Definition: points.cc:65
int ansatz() const
Definition: points.h:153
void set_max_functions(int max_functions)
Definition: points.h:94
virtual void set_Cs(SharedMatrix Cocc)=0
std::shared_ptr< BasisSet > primary_
Basis set for this BasisFunctions.
Definition: points.h:51
std::unordered_map< size_t, std::map< std::string, SharedMatrix > > * cache_map_
Definition: points.h:112
~RKSFunctions() override
Definition: points.cc:50
SharedMatrix Db_AO_
Density matrix, AO.
Definition: points.h:228
~UKSFunctions() override
Definition: points.cc:308
void set_cache_map(std::unordered_map< size_t, std::map< std::string, SharedMatrix >> *cache_map)
Definition: points.h:263
virtual std::vector< SharedMatrix > D_scratch()=0
SharedMatrix Ca_AO_
Orbital coefficients, AO.
Definition: points.h:249
int ansatz_
Ansatz (0 - LSDA, 1 - GGA, 2 - Meta-GGA)
Definition: points.h:118
SharedMatrix C_AO_
Orbital coefficients, AO.
Definition: points.h:197
SharedMatrix Db_local_
Local D matrix.
Definition: points.h:239
SharedMatrix Cb_local_
Orbital coefficeints, local AO.
Definition: points.h:255
Definition: points.h:175
virtual void set_pointers(SharedMatrix Da_occ_AO)=0
int deriv_
Maximum derivative to compute.
Definition: points.h:59
SharedMatrix Ca_local_
Orbital coefficeints, local AO.
Definition: points.h:253
void compute_orbitals(std::shared_ptr< BlockOPoints > block, bool force_compute=true) override
Definition: points.cc:510
std::map< std::string, SharedMatrix > * current_basis_map_
Definition: points.h:115
void set_pointers(SharedMatrix Da_occ_AO) override
Definition: points.cc:89
std::vector< SharedMatrix > scratch() override
Definition: points.cc:309
SharedMatrix tempb_
Buffer for half-transform.
Definition: points.h:235
std::map< std::string, SharedMatrix > basis_values_
Map of value names to Matrices containing values.
Definition: points.h:61
PointFunctions(std::shared_ptr< BasisSet > primary, int max_points, int max_functions)
Definition: points.cc:582
bool puream_
Pure AM or not.
Definition: points.h:53
virtual void compute_orbitals(std::shared_ptr< BlockOPoints > block, bool force_compute=true)=0
std::map< std::string, SharedMatrix > basis_temps_
Map of temp names to Matrices containing temps.
Definition: points.h:63
size_t block_index()
Definition: points.h:218
SharedMatrix D_AO_
Density matrix, AO.
Definition: points.h:180
size_t block_index_
The index of the current referenced block.
Definition: points.h:109
RKSFunctions(std::shared_ptr< BasisSet > primary, int max_points, int max_functions)
Definition: points.cc:45
std::map< std::string, SharedMatrix > & orbital_values()
Definition: points.h:168
Definition: points.h:48
void build_temps()
Build temporary work arrays.
Definition: points.cc:61
void set_cache_map(std::unordered_map< size_t, std::map< std::string, SharedMatrix >> *cache_map)
Definition: points.h:134
Definition: points.h:221
void set_max_points(int max_points)
Definition: points.h:98
void set_deriv(int deriv)
Definition: points.h:90
UKSFunctions(std::shared_ptr< BasisSet > primary, int max_points, int max_functions)
Definition: points.cc:303
void allocate() override
Allocate registers.
Definition: points.cc:327
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
void compute_points(std::shared_ptr< BlockOPoints > block, bool force_compute=true) override
Definition: points.cc:362
int deriv() const
Definition: points.h:84
#define PSI_API
Definition: pragma.h:155
SharedMatrix basis_value(const std::string &key)
Definition: points.h:147
void set_pointers(SharedMatrix Da_occ_AO) override
Definition: points.cc:355
int max_functions() const
Definition: points.h:82
std::map< std::string, std::shared_ptr< Matrix > > orbital_values_
Map of value names to Matrices containing values.
Definition: points.h:125
std::vector< SharedMatrix > D_scratch() override
Definition: points.cc:315
std::vector< SharedMatrix > D_scratch() override
Definition: points.cc:56
SharedMatrix C_local_
Orbital coefficeints, local AO.
Definition: points.h:199
SharedMatrix temp_
Buffer for half-transform.
Definition: points.h:185
std::shared_ptr< Vector > point_value(const std::string &key)
Definition: points.cc:587
SharedMatrix Da_AO_
Density matrix, AO.
Definition: points.h:226
std::map< std::string, SharedMatrix > & basis_values()
Definition: points.h:148
std::map< std::string, std::shared_ptr< Vector > > point_values_
Map of value names to Vectors containing values.
Definition: points.h:120
int max_points() const
Definition: points.h:83
void set_ansatz(int ansatz)
Definition: points.h:157
std::shared_ptr< Matrix > orbital_value(const std::string &key)
Definition: points.cc:589
size_t block_index()
Definition: points.h:277
SharedMatrix Da_local_
Local D matrix.
Definition: points.h:237
void print(std::string out_fname="outfile", int print=2) const override
Definition: points.cc:277
int max_points_
Maximum number of points in a block.
Definition: points.h:55
~PointFunctions() override
Definition: points.cc:586
std::vector< SharedMatrix > scratch() override
Definition: points.cc:51
void build_temps()
Build temporary work arrays.
Definition: points.cc:321