1
/***************************************************************************
2
* PSIMRCC : Copyright (C) 2007 by Francesco Evangelista and Andrew Simmonett
3
* frank@ccc.uga.edu andysim@ccc.uga.edu
4
* A multireference coupled cluster code
5
***************************************************************************/
9
#include <libmoinfo/libmoinfo.h>
12
#include "memory_manager.h"
14
extern FILE *infile, *outfile;
16
namespace psi{ namespace psimrcc{
20
int CCIndex::nirreps=-1;
22
CCIndex::CCIndex(std::string str):
23
nelements(0),ntuples(0), greater_than_or_equal(false), greater_than(false), memory(0.0), label(str),tuples(0),
24
one_index_to_tuple(0),one_index_to_irrep(0),
25
two_index_to_tuple(0),two_index_to_irrep(0),
26
three_index_to_tuple(0),three_index_to_irrep(0)
28
if(nirreps<0) nirreps = moinfo->get_nirreps();
39
// New orbital spaces must be added here
40
for(int i =0;i<label.size();i++)
41
if( label[i]=='o' || label[i]=='a' || label[i]=='v' || label[i]=='s' || label[i]=='n')
44
// Get the orbital spaces data pointers
45
for(int i=0;i<label.size();i++)
48
mospi.push_back(moinfo->get_occ());
49
indices_to_pitzer.push_back(moinfo->get_occ_to_pitzer());
50
}else if(label[i]=='v'){
51
mospi.push_back(moinfo->get_vir());
52
indices_to_pitzer.push_back(moinfo->get_vir_to_pitzer());
53
}else if(label[i]=='a'){
54
mospi.push_back(moinfo->get_actv());
55
indices_to_pitzer.push_back(moinfo->get_act_to_pitzer());
56
}else if(label[i]=='s'){
57
mospi.push_back(moinfo->get_sopi());
58
indices_to_pitzer.push_back(moinfo->get_so_to_pitzer());
59
}else if(label[i]=='n'){
60
mospi.push_back(moinfo->get_orbspi());
61
indices_to_pitzer.push_back(moinfo->get_orbs_to_pitzer());
64
for(int i=0;i<nelements;i++){
65
first_mos.push_back(vector<int>(nirreps,0));
66
dimension.push_back(0);
68
for(int i=0;i<nelements;i++){
69
for(int h=0;h<nirreps;h++){
70
first_mos[i][h]=dimension[i];
71
dimension[i]+=mospi[i][h];
89
fprintf(outfile,"\n\n\tThe CCIndex class cannot handle %s because there are more than three indices!!!\n\n",label.c_str());
94
mem->add_allocated_memory(memory);
97
void CCIndex::cleanup()
100
free_smatrix(tuples,ntuples,dimension.size());
101
if(one_index_to_tuple!=0)
102
delete[] one_index_to_tuple;
103
if(one_index_to_irrep!=0)
104
delete[] one_index_to_irrep;
105
if(two_index_to_tuple!=0)
106
release2(two_index_to_tuple);
107
if(two_index_to_irrep!=0)
108
release2(two_index_to_irrep);
109
if(three_index_to_tuple!=0)
110
release3(three_index_to_tuple);
111
if(three_index_to_irrep!=0)
112
release3(three_index_to_irrep);
115
void CCIndex::make_zero_index()
117
std::vector<std::vector<short> > pairs; // The pairs ordered as a vector
119
for(int h=0;h<nirreps;h++){
120
first.push_back(ntuples);
122
std::vector<short> pair;
123
pairs.push_back(pair);
126
last.push_back(ntuples);
127
pairpi.push_back(last[h]-first[h]);
129
// Allocate the memory for the tuples and store them
130
memory+=(double)init_smatrix(tuples,1,1)/1048576.0;
134
void CCIndex::make_one_index()
136
// The pairs ordered as a vector
137
std::vector<std::vector<short> > pairs;
139
// Allocate the 1->tuple mapping array and set them to -1
140
one_index_to_tuple = new size_t[dimension[0]];
141
one_index_to_irrep = new int[dimension[0]];
142
for(int i=0;i<dimension[0];i++){
143
one_index_to_tuple[i] = 0;
144
one_index_to_irrep[i] = -1;
146
memory+=(double)dimension[0]*2.0*sizeof(int)/1048576.0;
149
for(int h=0;h<nirreps;h++){
150
first.push_back(ntuples);
151
for(int p=0;p<mospi[0][h];p++){
152
one_index_to_tuple[ntuples]=p;
153
one_index_to_irrep[ntuples]=h;
154
std::vector<short> pair;
155
pair.push_back(ntuples);
156
pairs.push_back(pair);
159
last.push_back(ntuples);
160
pairpi.push_back(last[h]-first[h]);
163
// Allocate the memory for the tuples and store them
164
memory+=(double)init_smatrix(tuples,ntuples,1)/1048576.0;
165
for(int n=0;n<pairs.size();n++)
166
tuples[n][0] = pairs[n][0];
169
void CCIndex::make_two_index()
171
std::vector<std::vector<short> > pairs; // The pairs ordered as a vector
173
// Allocate the 2->tuple mapping array and set them to -1
174
allocate2(size_t,two_index_to_tuple,dimension[0],dimension[1]);
175
allocate2(int,two_index_to_irrep,dimension[0],dimension[1]);
177
for(int i=0;i<dimension[0];i++){
178
for(int j=0;j<dimension[1];j++){
179
two_index_to_tuple[i][j] = 0;
180
two_index_to_irrep[i][j] = -1;
185
if(label.find(">=")!=string::npos){
186
greater_than_or_equal = true;
188
for(int h=0;h<nirreps;h++){
189
first.push_back(ntuples);
190
for(int p_sym=0;p_sym<nirreps;p_sym++){
192
int p = first_mos[0][p_sym];
193
for(int p_rel=0;p_rel<mospi[0][p_sym];p_rel++){
194
int q = first_mos[1][q_sym];
195
for(int q_rel=0;q_rel<mospi[1][q_sym];q_rel++){
197
two_index_to_tuple[p][q]=ntuples-first[h];
198
two_index_to_irrep[p][q]=h;
199
std::vector<short> pair;
202
pairs.push_back(pair);
210
last.push_back(ntuples);
211
pairpi.push_back(last[h]-first[h]);
213
}else if(label.find(">")!=string::npos){
216
for(int h=0;h<nirreps;h++){
217
first.push_back(ntuples);
218
for(int p_sym=0;p_sym<nirreps;p_sym++){
220
int p = first_mos[0][p_sym];
221
for(int p_rel=0;p_rel<mospi[0][p_sym];p_rel++){
222
int q = first_mos[1][q_sym];
223
for(int q_rel=0;q_rel<mospi[1][q_sym];q_rel++){
225
two_index_to_tuple[p][q]=ntuples-first[h];
226
two_index_to_irrep[p][q]=h;
227
std::vector<short> pair;
230
pairs.push_back(pair);
238
last.push_back(ntuples);
239
pairpi.push_back(last[h]-first[h]);
243
for(int h=0;h<nirreps;h++){
244
first.push_back(ntuples);
245
for(int p_sym=0;p_sym<nirreps;p_sym++){
247
int p = first_mos[0][p_sym];
248
for(int p_rel=0;p_rel<mospi[0][p_sym];p_rel++){
249
int q = first_mos[1][q_sym];
250
for(int q_rel=0;q_rel<mospi[1][q_sym];q_rel++){
251
two_index_to_tuple[p][q]=ntuples-first[h];
252
two_index_to_irrep[p][q]=h;
253
std::vector<short> pair;
256
pairs.push_back(pair);
263
last.push_back(ntuples);
264
pairpi.push_back(last[h]-first[h]);
268
// Allocate the memory for the tuples and store them
269
memory+=(double)init_smatrix(tuples,ntuples,2)/1048576.0;
270
for(int n=0;n<pairs.size();n++){
271
tuples[n][0] = pairs[n][0];
272
tuples[n][1] = pairs[n][1];
277
void CCIndex::make_three_index()
279
if(label.find(">")!=string::npos){
280
fprintf(outfile,"\n\n\tThe CCIndex class cannot handle restricted loops for triplets!!!\n\n");
285
std::vector<std::vector<short> > pairs; // The pairs ordered as a vector
287
// Allocate the 3->tuple mapping array and set them to -1
288
allocate3(size_t,three_index_to_tuple,dimension[0],dimension[1],dimension[2]);
289
allocate3(int,three_index_to_irrep,dimension[0],dimension[1],dimension[2]);
290
for(int i=0;i<dimension[0];i++){
291
for(int j=0;j<dimension[1];j++){
292
for(int k=0;k<dimension[2];k++){
293
three_index_to_tuple[i][j][k] = 0;
294
three_index_to_irrep[i][j][k] = -1;
301
for(int h=0;h<nirreps;h++){
302
first.push_back(ntuples);
303
for(int p_sym=0;p_sym<nirreps;p_sym++){
304
for(int q_sym=0;q_sym<nirreps;q_sym++){
305
int r_sym = h^p_sym^q_sym;
306
int p = first_mos[0][p_sym];
307
for(int p_rel=0;p_rel<mospi[0][p_sym];p_rel++){
308
int q = first_mos[1][q_sym];
309
for(int q_rel=0;q_rel<mospi[1][q_sym];q_rel++){
310
int r = first_mos[2][r_sym];
311
for(int r_rel=0;r_rel<mospi[2][r_sym];r_rel++){
312
three_index_to_tuple[p][q][r]=ntuples-first[h];
313
three_index_to_irrep[p][q][r]=h;
314
std::vector<short> pair;
318
pairs.push_back(pair);
328
last.push_back(ntuples);
329
pairpi.push_back(last[h]-first[h]);
332
// Allocate the memory for the tuples and store them
333
memory+=(double)init_smatrix(tuples,ntuples,3)/1048576.0;
334
for(int n=0;n<pairs.size();n++){
335
tuples[n][0] = pairs[n][0];
336
tuples[n][1] = pairs[n][1];
337
tuples[n][2] = pairs[n][2];
341
void CCIndex::print()
343
fprintf(outfile,"\n\n---------------------------------");
344
fprintf(outfile,"\n\tPair Type %s has %d elements",label.c_str(),ntuples);
345
fprintf(outfile,"\n---------------------------------");
347
for(int h=0;h<nirreps;h++){
349
fprintf(outfile,"\n\t%s",moinfo->get_irr_labs(h));
350
for(int tuple=0;tuple<pairpi[h];tuple++){
351
fprintf(outfile,"\n\t\t( ");
352
for(int k=0;k<nelements;k++)
353
fprintf(outfile,"%d ",tuples[index][k]);
354
fprintf(outfile,")");
358
fprintf(outfile,"\n---------------------------------");
361
}} /* End Namespaces */