v2DM-DOCI  1.0
SUP.cpp
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Copyright (C) 2014-2015 Ward Poelmans
5  *
6  * This file is part of v2DM-DOCI.
7  *
8  * v2DM-DOCI is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Foobar is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * @END LICENSE
22  */
23 
24 #include "SUP.h"
25 
26 using namespace doci2DM;
27 
28 SUP::SUP(int L, int N)
29 {
30  this->L = L;
31  this->N = N;
32 
33  I.reset(new TPM(L,N));
34 #ifdef __Q_CON
35  Q.reset(new TPM(L,N));
36 #endif
37 
38 #ifdef __G_CON
39  G.reset(new PHM(L,N));
40 #endif
41 }
42 
43 SUP::SUP(const SUP &orig)
44 {
45  this->L = orig.L;
46  this->N = orig.N;
47 
48  I.reset(new TPM(*orig.I));
49 #ifdef __Q_CON
50  Q.reset(new TPM(*orig.Q));
51 #endif
52 
53 #ifdef __G_CON
54  G.reset(new PHM(*orig.G));
55 #endif
56 }
57 
58 SUP::SUP(SUP &&orig)
59 {
60  this->L = orig.L;
61  this->N = orig.N;
62 
63  I = std::move(orig.I);
64  Q = std::move(orig.Q);
65  G = std::move(orig.G);
66 }
67 
68 SUP& SUP::operator=(const SUP &orig)
69 {
70  I.reset(new TPM(*orig.I));
71 #ifdef __Q_CON
72  Q.reset(new TPM(*orig.Q));
73 #endif
74 
75 #ifdef __G_CON
76  G.reset(new PHM(*orig.G));
77 #endif
78 
79  return *this;
80 }
81 
83 {
84  I = std::move(orig.I);
85  Q = std::move(orig.Q);
86  G = std::move(orig.G);
87 
88  return *this;
89 }
90 
91 SUP& SUP::operator=(double a)
92 {
93  (*I) = a;
94 #ifdef __Q_CON
95  (*Q) = a;
96 #endif
97 
98 #ifdef __G_CON
99  (*G) = a;
100 #endif
101 
102  return *this;
103 }
104 
105 SUP& SUP::operator+=(const SUP &orig)
106 {
107  (*I) += (*orig.I);
108 #ifdef __Q_CON
109  (*Q) += (*orig.Q);
110 #endif
111 
112 #ifdef __G_CON
113  (*G) += (*orig.G);
114 #endif
115 
116  return *this;
117 }
118 
119 SUP& SUP::operator-=(const SUP &orig)
120 {
121  (*I) -= (*orig.I);
122 #ifdef __Q_CON
123  (*Q) -= (*orig.Q);
124 #endif
125 
126 #ifdef __G_CON
127  (*G) -= (*orig.G);
128 #endif
129 
130  return *this;
131 }
132 
133 SUP& SUP::operator*=(double alpha)
134 {
135  (*I) *= alpha;
136 #ifdef __Q_CON
137  (*Q) *= alpha;
138 #endif
139 
140 #ifdef __G_CON
141  (*G) *= alpha;
142 #endif
143 
144  return *this;
145 }
146 
147 SUP& SUP::operator/=(double alpha)
148 {
149  (*I) /= alpha;
150 #ifdef __Q_CON
151  (*Q) /= alpha;
152 #endif
153 
154 #ifdef __G_CON
155  (*G) /= alpha;
156 #endif
157 
158  return *this;
159 }
160 
161 void SUP::dscal(double alpha)
162 {
163  I->dscal(alpha);
164 
165 #ifdef __Q_CON
166  Q->dscal(alpha);
167 #endif
168 
169 #ifdef __G_CON
170  G->dscal(alpha);
171 #endif
172 }
173 
174 int SUP::gN() const
175 {
176  return N;
177 }
178 
179 int SUP::gL() const
180 {
181  return L;
182 }
183 
184 TPM const & SUP::getI() const
185 {
186  return *I;
187 }
188 
190 {
191  return *I;
192 }
193 
194 TPM const & SUP::getQ() const
195 {
196  return *Q;
197 }
198 
200 {
201  return *Q;
202 }
203 
204 PHM const & SUP::getG() const
205 {
206  return *G;
207 }
208 
210 {
211  return *G;
212 }
213 
215 {
216  I->invert();
217 
218 #ifdef __Q_CON
219  Q->invert();
220 #endif
221 
222 #ifdef __G_CON
223  G->invert();
224 #endif
225 }
226 
231 void SUP::fill(const TPM &tpm)
232 {
233  (*I) = tpm;
234 
235 #ifdef __Q_CON
236  Q->Q(tpm);
237 #endif
238 
239 #ifdef __G_CON
240  G->G(tpm);
241 #endif
242 }
243 
244 void SUP::sqrt(int option)
245 {
246  I->sqrt(option);
247 
248 #ifdef __Q_CON
249  Q->sqrt(option);
250 #endif
251 
252 #ifdef __G_CON
253  G->sqrt(option);
254 #endif
255 }
256 
257 void SUP::L_map(const SUP &A, const SUP &B)
258 {
259  I->L_map(*A.I,*B.I);
260 
261 #ifdef __Q_CON
262  Q->L_map(*A.Q,*B.Q);
263 #endif
264 
265 #ifdef __G_CON
266  G->L_map(*A.G,*B.G);
267 #endif
268 }
269 
270 int SUP::gnr() const
271 {
272  int res = I->gnr();
273 
274 #ifdef __Q_CON
275  res += Q->gnr();
276 #endif
277 
278 #ifdef __G_CON
279  res += G->gnr();
280 #endif
281 
282  return res;
283 }
284 
285 namespace doci2DM
286 {
287  std::ostream &operator<<(std::ostream &output,doci2DM::SUP &sup)
288  {
289  output << "I block:" << std::endl;
290  output << *sup.I << std::endl;
291 
292 #ifdef __Q_CON
293  output << "Q block:" << std::endl;
294  output << *sup.Q << std::endl;
295 #endif
296 
297 #ifdef __G_CON
298  output << "G block:" << std::endl;
299  output << *sup.G << std::endl;
300 #endif
301 
302  return output;
303  }
304 }
305 
306 double SUP::ddot(const SUP &x) const
307 {
308  double result;
309 
310  result = I->ddot(*x.I);
311 
312 #ifdef __Q_CON
313  result += Q->ddot(*x.Q);
314 #endif
315 
316 #ifdef __G_CON
317  result += G->ddot(*x.G);
318 #endif
319 
320  return result;
321 }
322 
323 void SUP::daxpy(double alpha, const SUP &y)
324 {
325  I->daxpy(alpha, *y.I);
326 
327 #ifdef __Q_CON
328  Q->daxpy(alpha, *y.Q);
329 #endif
330 
331 #ifdef __G_CON
332  G->daxpy(alpha, *y.G);
333 #endif
334 }
335 
336 void SUP::sep_pm(SUP &pos, SUP &neg)
337 {
338  I->sep_pm(*pos.I, *neg.I);
339 
340 #ifdef __Q_CON
341  Q->sep_pm(*pos.Q, *neg.Q);
342 #endif
343 
344 #ifdef __G_CON
345  G->sep_pm(*pos.G, *neg.G);
346 #endif
347 }
348 
352 void SUP::init_S(const Lineq &lineq)
353 {
354  *this = lineq.gu_0(0);
355 
356  this->dscal(lineq.ge_ortho(0));
357 
358  for(int i = 1;i < lineq.gnr();++i)
359  this->daxpy(lineq.ge_ortho(i),lineq.gu_0(i));
360 }
361 
366 void SUP::WriteToFile(std::string filename) const
367 {
368  hid_t file_id, main_group_id, group_id;
369  herr_t status;
370 
371  file_id = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
372 
373  main_group_id = H5Gcreate(file_id, "SUP", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
374 
375  group_id = H5Gcreate(main_group_id, "I", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
376 
377  I->WriteToFile(group_id);
378 
379  status = H5Gclose(group_id);
380  HDF5_STATUS_CHECK(status);
381 
382 #ifdef __Q_CON
383  group_id = H5Gcreate(main_group_id, "Q", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
384 
385  Q->WriteToFile(group_id);
386 
387  status = H5Gclose(group_id);
388  HDF5_STATUS_CHECK(status);
389 #endif
390 
391 #ifdef __G_CON
392  group_id = H5Gcreate(main_group_id, "G", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
393 
394  G->WriteToFile(group_id);
395 
396  status = H5Gclose(group_id);
397  HDF5_STATUS_CHECK(status);
398 #endif
399 
400  status = H5Gclose(main_group_id);
401  HDF5_STATUS_CHECK(status);
402 
403  status = H5Fclose(file_id);
404  HDF5_STATUS_CHECK(status);
405 }
406 
412 void SUP::ReadFromFile(std::string filename)
413 {
414  hid_t file_id, main_group_id, group_id;
415  herr_t status;
416 
417  file_id = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
418  HDF5_STATUS_CHECK(file_id);
419 
420  main_group_id = H5Gopen(file_id, "/SUP", H5P_DEFAULT);
421  HDF5_STATUS_CHECK(group_id);
422 
423  group_id = H5Gopen(main_group_id, "I", H5P_DEFAULT);
424  HDF5_STATUS_CHECK(group_id);
425 
426  I->ReadFromFile(group_id);
427 
428  status = H5Gclose(group_id);
429  HDF5_STATUS_CHECK(status);
430 
431 #ifdef __Q_CON
432  group_id = H5Gopen(main_group_id, "Q", H5P_DEFAULT);
433  HDF5_STATUS_CHECK(group_id);
434 
435  Q->ReadFromFile(group_id);
436 
437  status = H5Gclose(group_id);
438  HDF5_STATUS_CHECK(status);
439 #endif
440 
441 #ifdef __G_CON
442  group_id = H5Gopen(main_group_id, "G", H5P_DEFAULT);
443  HDF5_STATUS_CHECK(group_id);
444 
445  G->ReadFromFile(group_id);
446 
447  status = H5Gclose(group_id);
448  HDF5_STATUS_CHECK(status);
449 #endif
450 
451  status = H5Gclose(main_group_id);
452  HDF5_STATUS_CHECK(status);
453 
454  status = H5Fclose(file_id);
455  HDF5_STATUS_CHECK(status);
456 }
457 
458 /* vim: set ts=3 sw=3 expandtab :*/
void daxpy(double, const SUP &)
Definition: SUP.cpp:323
double ddot(const SUP &) const
Definition: SUP.cpp:306
SUP(int L, int N)
Definition: SUP.cpp:28
SUP & operator/=(double)
Definition: SUP.cpp:147
SUP & operator+=(const SUP &)
Definition: SUP.cpp:105
int gnr() const
Definition: SUP.cpp:270
void invert()
Definition: SUP.cpp:214
double ge_ortho(int) const
Definition: Lineq.cpp:143
int gnr() const
Definition: Lineq.cpp:95
void WriteToFile(std::string filename) const
Definition: SUP.cpp:366
PHM const & getG() const
Definition: SUP.cpp:204
void L_map(const SUP &, const SUP &)
Definition: SUP.cpp:257
TPM const & getI() const
Definition: SUP.cpp:184
void sqrt(int)
Definition: SUP.cpp:244
std::ostream & operator<<(std::ostream &output, const doci2DM::BlockStructure< MyBlockType > &blocks_p)
void init_S(const Lineq &)
Definition: SUP.cpp:352
int L
the size of the sp DOCI space (there are 2*L sp states)
Definition: SUP.h:109
SUP & operator=(const SUP &)
Definition: SUP.cpp:68
int gL() const
Definition: SUP.cpp:179
void dscal(double)
Definition: SUP.cpp:161
void sep_pm(SUP &, SUP &)
Definition: SUP.cpp:336
#define HDF5_STATUS_CHECK(status)
Definition: helpers.cpp:30
std::unique_ptr< TPM > I
the RDM matrix
Definition: SUP.h:112
const SUP & gu_0(int) const
Definition: Lineq.cpp:224
std::unique_ptr< PHM > G
the G matrix
Definition: SUP.h:118
int N
number of particles
Definition: SUP.h:106
void fill(const TPM &)
Definition: SUP.cpp:231
SUP & operator*=(double)
Definition: SUP.cpp:133
std::unique_ptr< TPM > Q
the Q matrix
Definition: SUP.h:115
TPM const & getQ() const
Definition: SUP.cpp:194
void ReadFromFile(std::string filename)
Definition: SUP.cpp:412
int gN() const
Definition: SUP.cpp:174
SUP & operator-=(const SUP &)
Definition: SUP.cpp:119