QMCPACK
ci_configuration.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef QMCPLUSPLUS_CI_CONFIGURATION_H
16 #define QMCPLUSPLUS_CI_CONFIGURATION_H
17 #include <vector>
18 #include <iostream>
19 
20 namespace qmcplusplus
21 {
22 // Defines a single CI ci_configuration, with respect to the hartree fock ci_configuration.
24 {
25  // vector of bits, each bit determines whether the corresponding state is occupied or not
26  std::vector<bool> occup;
27  bool taken;
28  int nExct; // with respect to base ci_configuration, which we assume is hf
29 
30  ci_configuration() : taken(false), nExct(0) {}
31 
32  ci_configuration(std::vector<bool>& v, int n) : occup(v), taken(false), nExct(n) {}
34 
36 
37  bool operator==(const ci_configuration& c) const
38  {
39  if (nExct != c.nExct)
40  {
41  return false;
42  }
43  if (occup.size() != c.occup.size())
44  {
45  APP_ABORT("ci_configuration::operator==() - ci_configurations are not compatible.");
46  }
47  if (count() != c.count())
48  {
49  app_log() << "c0: ";
50  for (int i = 0; i < occup.size(); i++)
51  app_log() << occup[i];
52  app_log() << std::endl << "c1: ";
53  for (int i = 0; i < c.occup.size(); i++)
54  app_log() << c.occup[i];
55  app_log() << std::endl;
56  APP_ABORT(
57  "ci_configuration::operator==() - ci_configurations are not compatible. Unequal number of occupied states. ");
58  }
59  for (int i = 0; i < occup.size(); i++)
60  {
61  if (occup[i] ^ c.occup[i])
62  {
63  return false;
64  }
65  }
66  return true;
67  }
68 
69  // this has a very specific use below
70  bool isSingle(const ci_configuration& c, int& rem, int& add) const
71  {
72  if (c.nExct - nExct != 1)
73  return false;
74  if (occup.size() != c.occup.size())
75  {
76  APP_ABORT("ci_configuration::isSingle() - ci_configurations are not compatible.");
77  }
78  if (count() != c.count())
79  {
80  APP_ABORT(
81  "ci_configuration::isSingle() - ci_configurations are not compatible. Unequal number of occupied states. ");
82  }
83  int nr = 0, na = 0, r = -1, a = -1;
84  for (int i = 0; i < occup.size(); i++)
85  {
86  if (occup[i] ^ c.occup[i])
87  {
88  if (occup[i])
89  {
90  nr++;
91  r = i;
92  }
93  else
94  {
95  na++;
96  a = i;
97  }
98  }
99  }
100  if (na == 1 && nr == 1)
101  {
102  rem = r;
103  add = a;
104  return true;
105  }
106  else
107  return false;
108  }
109 
110  int count() const
111  {
112  int res = 0;
113  for (int i = 0; i < occup.size(); i++)
114  if (occup[i])
115  res++;
116  return res;
117  }
118 
119  void add_occupation(std::string& str)
120  {
121  int str_size = str.size();
122  occup.resize(str_size);
123  for (int i = 0; i < str_size; i++)
124  occup[i] = str[i] - '0';
125  }
126 };
127 
128 inline std::ostream& operator<<(std::ostream& out, const ci_configuration& c)
129 {
130  out << "ci ci_configuration: ";
131  for (int i = 0; i < c.occup.size(); i++)
132  out << c.occup[i];
133  out << std::endl;
134  return out;
135 };
136 } // namespace qmcplusplus
137 #endif
void add_occupation(std::string &str)
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::ostream & app_log()
Definition: OutputManager.h:65
bool operator==(const ci_configuration &c) const
std::ostream & operator<<(std::ostream &out, const AntiSymTensor< T, D > &rhs)
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void add(int n, const T *restrict in, T *restrict out)
Definition: vmath.hpp:95
ci_configuration(const ci_configuration &c)
bool isSingle(const ci_configuration &c, int &rem, int &add) const
ci_configuration(std::vector< bool > &v, int n)