Skip to content

Commit aa15e09

Browse files
committed
Trying to generalize the number of orbital spaces.
1 parent 2ed6a41 commit aa15e09

File tree

10 files changed

+138
-109
lines changed

10 files changed

+138
-109
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ AC_CONFIG_SRCDIR([src/main.cc])
88
AC_CONFIG_HEADER([config.h])
99

1010
# Checks for programs.
11-
CXXFLAGS="$CXXFLAGS -std=c++0x -O3"
11+
CXXFLAGS="$CXXFLAGS -std=c++0x"
1212
AC_PROG_CXX
1313
AC_PROG_CC
1414
AC_PROG_RANLIB

src/binarycontraction.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//
2-
// Author:: Toru Shiozaki
3-
// Date :: Feb 2009
2+
// Author : Toru Shiozaki
3+
// Date : Feb 2009
44
//
5+
56
#include <src/binarycontraction.h>
67
#include <src/smartindex.h>
78
#include <iostream>
@@ -25,8 +26,8 @@ BinaryContraction::~BinaryContraction(){
2526

2627

2728
pair<PCost, PCost> BinaryContraction::cost_evaluater(const vector<shared_ptr<Tensor> >& tensors) {
28-
PCost pcop(0,0,0);
29-
PCost pcmem(0,0,0);
29+
PCost pcop;
30+
PCost pcmem;
3031

3132
if (one())
3233
return make_pair(pcop, pcmem);

src/cost.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
using namespace std;
1111

1212

13-
void PCost::add(int i, int j, int k) {
14-
get<0>(pcost_) += i;
15-
get<1>(pcost_) += j;
16-
get<2>(pcost_) += k;
17-
}
18-
19-
2013
const string PCost::show() const {
21-
stringstream out; out << "h" << get<0>(pcost()) << "p" << get<1>(pcost()) << "P" << get<2>(pcost());
14+
stringstream out;
15+
auto j = pcost_.begin();
16+
for (auto i = indmap_.begin(); i != indmap_.end(); ++i, ++j)
17+
out << i->first << *j;
2218
return out.str();
2319
}
2420

src/cost.h

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,50 @@
1111
#include <algorithm>
1212
#include <functional>
1313
#include <tuple>
14-
14+
#include <cassert>
1515
#include <iostream>
16+
#include <src/index.h>
1617

17-
// may be substituted by the actual numbers...
18-
#define NUM_COMP_PARTICLE 888
19-
#define NUM_PARTICLE 232
20-
#define NUM_HOLE 28
18+
class PCost {
2119

20+
protected:
21+
// a vector of integers with length cat
22+
std::vector<int> pcost_;
23+
// mapping information. Maybe this is not the most beautiful way..
24+
Index_map indmap_;
2225

23-
class PCost {
24-
25-
protected:
26-
std::tuple<int,int,int> pcost_;// hole, particle, complete particle
27-
2826
public:
29-
PCost(const std::tuple<int,int,int>& pcst): pcost_(pcst) { };
30-
PCost(int i, int j, int k): pcost_(std::make_tuple(i,j,k)) {};
31-
PCost() { };
27+
PCost(const std::vector<int>& pcst): pcost_(pcst) { };
28+
PCost() { pcost_.resize(indmap_.size()); };
3229
~PCost() { };
3330

34-
bool operator<(const PCost& other) const { return pcost_total() < other.pcost_total(); };
35-
bool operator>(const PCost& other) const { return pcost_total() > other.pcost_total(); };
31+
bool operator<(const PCost& other) const { return pcost_total() < other.pcost_total(); };
32+
bool operator>(const PCost& other) const { return pcost_total() > other.pcost_total(); };
3633
bool operator==(const PCost& other) const { return pcost() == other.pcost(); };
3734
bool operator!=(const PCost& other) const { return !(*this == other);};
3835

39-
const double pcost_total() const { return
40-
::log(static_cast<double>(NUM_HOLE ))*std::get<0>(pcost_)
41-
+ ::log(static_cast<double>(NUM_PARTICLE ))*std::get<1>(pcost_)
42-
+ ::log(static_cast<double>(NUM_COMP_PARTICLE))*std::get<2>(pcost_);
36+
const double pcost_total() const {
37+
double out = 0.0;
38+
auto j = indmap_.begin();
39+
for (auto i = pcost_.begin(); i != pcost_.end(); ++i, ++j)
40+
out += ::log(static_cast<double>(j->second.second))* *i;
41+
return out;
4342
}
44-
const std::tuple<int,int,int> pcost() const { return pcost_;};
43+
const std::vector<int> pcost() const { return pcost_;};
44+
45+
void add(std::vector<int>& o) {
46+
for (auto i = pcost_.begin(), j = o.begin(); i != pcost_.end(); ++i, ++j) *i += *j;
47+
};
48+
#if 0
49+
void add(int i, int j, int k) {
50+
assert(ORB_CLASS == 3);
51+
pcost_[0] += i;
52+
pcost_[1] += j;
53+
pcost_[2] += k;
54+
};
55+
#endif
4556

46-
void add(int, int, int);
57+
int pcost(const int i) const { return pcost_[i]; };
4758

4859
const std::string show() const;
4960

@@ -52,8 +63,8 @@ class PCost {
5263

5364
class Cost {
5465

55-
protected:
56-
std::vector<PCost> cost_;
66+
protected:
67+
std::vector<PCost> cost_;
5768

5869
public:
5970
Cost(const std::vector<PCost>& cst) : cost_(cst) { };
@@ -65,33 +76,20 @@ class Cost {
6576
std::vector<PCost> myc = cost();
6677
for (auto i = myc.begin(), j = otherc.begin(); i != myc.end(); ++i, ++j) {
6778
if (j == otherc.end()) return false;
68-
if (*i < *j) return true;
79+
if (*i < *j) return true;
6980
else if (*i > *j) return false;
7081
}
71-
return true;
82+
return true;
7283
};
7384

74-
#define use_old_code_cost 0
75-
#if use_old_code_cost
76-
bool operator==(const Cost& other) const {
77-
std::vector<PCost> otherc = other.cost();
78-
std::vector<PCost> myc = cost();
79-
if (myc.size() != otherc.size()) return false;
80-
for (auto i = myc.begin(), j = otherc.begin(); i != myc.end(); ++i, ++j) {
81-
if (*i != *j ) return false;
82-
}
83-
return true;
84-
}
85-
#else
8685
bool operator==(const Cost& other) const { return cost()==other.cost(); };
87-
#endif
8886
bool operator!=(const Cost& other) const { return !(*this == other);};
8987
bool operator>(const Cost& other) const { return !(*this < other);};
9088

9189
const std::vector<PCost> cost() const {return cost_;};
9290

9391
void add_pcost(const PCost& p) { cost_.push_back(p); };
94-
void add_pcost(int i, int j, int k) { PCost a(i, j, k); cost_.push_back(a); };
92+
// void add_pcost(int i, int j, int k) { PCost a(i, j, k); cost_.push_back(a); };
9593

9694
const std::string show() const;
9795

src/index.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Index::~Index() {
4444
const string Index::show() const {
4545

4646
ostringstream buffer;
47-
buffer << type() << num() << (dagger() ? "+" : "");
47+
buffer << type_str() << num() << (dagger() ? "+" : "");
4848

4949
return buffer.str();
5050
}

src/index.h

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,52 @@
22
// Author : Toru Shiozaki
33
// Date : Feb 2009
44
//
5+
56
#ifndef _smith_index_h
67
#define _smith_index_h
78

89
#include <string>
910
#include <iostream>
1011
#include <vector>
1112
#include <memory>
13+
#include <list>
14+
#include <stdexcept>
15+
16+
// This defines the index classes. If you want to generalize this generator
17+
// to more general cases (RASPT2, for instance), then just add some entry.
18+
// Indices will be sorted using these numbers when tensors are canonicalized.
19+
class Index_map {
20+
protected:
21+
std::list<std::pair<std::string, std::pair<int,int> > > map_;
22+
public:
23+
Index_map() {
24+
map_.push_back(std::make_pair("h", std::make_pair(0, 28)));
25+
map_.push_back(std::make_pair("a", std::make_pair(1, 6)));
26+
map_.push_back(std::make_pair("p", std::make_pair(2, 232)));
27+
map_.push_back(std::make_pair("P", std::make_pair(3, 888)));
28+
};
29+
~Index_map() {};
30+
int num_orb_class() const { return map_.size(); };
31+
int size() const { return num_orb_class(); };
32+
33+
const int type(const std::string& type_) const {
34+
auto iter = map_.begin();
35+
for (; iter != map_.end(); ++iter) if (iter->first == type_) break;
36+
if (iter == map_.end()) throw std::runtime_error("key is no valid in Index::type()");
37+
return iter->second.first;
38+
};
39+
std::list<std::pair<std::string, std::pair<int,int> > >::const_iterator begin() const { return map_.begin(); };
40+
std::list<std::pair<std::string, std::pair<int,int> > >::const_iterator end() const { return map_.end(); };
41+
};
1242

1343
class Index {
1444

1545
protected:
1646
// basic info for deriving equations.
1747
bool dagger_;
1848
std::string type_;
19-
std::shared_ptr<int> num_;
49+
std::shared_ptr<int> num_;
50+
Index_map indmap_;
2051

2152
public:
2253
Index(const std::string);
@@ -25,11 +56,14 @@ class Index {
2556
// returns dagger_
2657
bool dagger() const { return dagger_; };
2758
// reutrns type_
28-
const std::string type() const { return type_; };
59+
const std::string type_str() const { return type_; };
60+
const int type() const { indmap_.type(type_); };
2961
// returns num_
3062
int num() const { return *num_; };
3163
// pointer to num_, which is used for updating num_ in Wick's theorem
3264
std::shared_ptr<int> num_pointer() { return num_; };
65+
// returns indmap_
66+
Index_map indmap() const { return indmap_; };
3367

3468
// show function
3569
const std::string show() const;

0 commit comments

Comments
 (0)