QMCPACK
SPOSetInfo.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: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #ifndef QMCPLUSPLUS_SPOSET_INFO_H
15 #define QMCPLUSPLUS_SPOSET_INFO_H
16 
19 
20 
21 namespace qmcplusplus
22 {
23 /** collection of orbital info for SPOSet instance or builder
24  */
26 {
27 public:
29  using states_t = std::vector<SPOInfo*>;
31 
32  // construction/destruction
33  SPOSetInfo();
34  ~SPOSetInfo();
35 
36  // initialization
37  void add(SPOInfo& state);
38  void add(SPOInfo* state);
39  void add(std::vector<SPOInfo*>& state_vector);
40  void add(SPOSetInfo& other);
41  /// renders collection immutable, must be called at end of initialization
42  void finish(orderings ord = spoinfo::no_order, RealType tol = 1e-6);
43 
44  // initialization queries
45  bool complete() const;
46  bool partial() const;
47  bool has_indices() const;
48  bool has_energies() const;
49 
50  // array-like read-only access
51  int size() const;
52  const SPOInfo* operator[](int s) const;
53  const SPOInfo* operator[](int s);
54 
55  // data access
56  int min_index() const;
57  int max_index() const;
58  RealType energy_tolerance() const;
59 
60  // state properties
61  bool contiguous() const;
62  bool unordered() const;
63  bool index_ordered() const;
64  bool energy_ordered() const;
65 
66  // printing
67  void report(const std::string& pad = "");
68 
69  // templated versions of finish to work with arbitrary vectors
70  template<typename SPOI>
71  inline void finish(std::vector<SPOI*>& state_vector, orderings ord = spoinfo::no_order, RealType tol = 1e-6)
72  {
73  for (int i = 0; i < state_vector.size(); ++i)
74  add(state_vector[i]);
75  finish(ord, tol);
76  }
77 
78  template<typename SPOI>
79  inline void finish(std::vector<int>& subset,
80  std::vector<SPOI*>& state_vector,
82  RealType tol = 1e-6)
83  {
84  for (int i = 0; i < subset.size(); ++i)
85  add(state_vector[subset[i]]);
86  finish(ord, tol);
87  }
88 
89 private:
90  /// whether initialization is complete and SPOSetInfo is ready for use
92 
93  /// whether all states have an index assigned
95 
96  /// whether all states have an energy assigned
98 
99  /// enum for how states are ordered
101 
102  /// tolerance used to sort energies
104 
105  /// minimum orbital index in the set (w.r.t the full set)
107 
108  /// maximum orbital index in the set (w.r.t the full set)
110 
111  /// collection of SPOInfo
112  std::vector<SPOInfo*> states;
113 
114  /// sort states by index
115  void index_sort();
116 
117  /// sort states by energy
118  void energy_sort(RealType tol);
119 
120  /// count energetic degeneracy of states
121  void count_degeneracies();
122 
123  /// determine the ordering of the states, if any
124  void determine_order(RealType tol);
125 
126  /// render collection mutable
127  void modify();
128 
129  /// empty collection and render mutable
130  void clear();
131 
132  friend class SPOSetBuilder;
133 };
134 
135 
136 template<typename SPOI>
138 {
140  std::vector<SPOI*> states; //SPOI should derive from SPOInfo
141 
143 
145 
146  inline void add(SPOI* state)
147  {
148  states.push_back(state);
149  state = 0;
150  }
151 
152  inline void clear()
153  {
154  delete_iter(states.begin(), states.end());
155  states.clear();
156  }
157 
158  int size() const { return states.size(); }
159 
160  SPOI* operator[](int s) const { return states[s]; }
161 
162  SPOI*& operator[](int s) { return states[s]; }
163 
164  void index_sort() { sort(states.begin(), states.end(), spoinfo::index_order); }
165 
166  void energy_sort(RealType tol = 1e-6, bool assign_indices = false)
167  {
168  spoinfo::EnergyOrder energy_order(tol);
169  sort(states.begin(), states.end(), energy_order);
170  if (assign_indices)
171  for (int i = 0; i < size(); ++i)
172  states[i]->index = i;
173  }
174 };
175 
176 } // namespace qmcplusplus
177 
178 #endif
void index_sort()
sort states by index
Definition: SPOSetInfo.cpp:149
std::vector< SPOInfo * > states
collection of SPOInfo
Definition: SPOSetInfo.h:112
bool has_indices() const
Definition: SPOSetInfo.cpp:87
bool index_order(const SPOInfo *left, const SPOInfo *right)
comparison function for sorting SPOInfo based on orbital index
Definition: SPOInfo.h:78
void delete_iter(IT first, IT last)
delete the pointers in [first,last)
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
void finish(std::vector< SPOI *> &state_vector, orderings ord=spoinfo::no_order, RealType tol=1e-6)
Definition: SPOSetInfo.h:71
void clear()
empty collection and render mutable
Definition: SPOSetInfo.cpp:241
void determine_order(RealType tol)
determine the ordering of the states, if any
Definition: SPOSetInfo.cpp:195
comparison functor for sorting SPOInfo based on energy
Definition: SPOInfo.h:81
bool energies_present
whether all states have an energy assigned
Definition: SPOSetInfo.h:97
base class for the real SPOSet builder
Definition: SPOSetBuilder.h:47
void report(const std::string &pad="")
Definition: SPOSetInfo.cpp:122
SPOI * operator[](int s) const
Definition: SPOSetInfo.h:160
base class to describe a single orbital in an SPOSet
Definition: SPOInfo.h:23
void add(SPOInfo &state)
Definition: SPOSetInfo.cpp:34
void count_degeneracies()
count energetic degeneracy of states
Definition: SPOSetInfo.cpp:166
bool energy_ordered() const
Definition: SPOSetInfo.cpp:115
void modify()
render collection mutable
Definition: SPOSetInfo.cpp:230
collection of orbital info for SPOSet instance or builder
Definition: SPOSetInfo.h:25
int index_min
minimum orbital index in the set (w.r.t the full set)
Definition: SPOSetInfo.h:106
const SPOInfo * operator[](int s) const
Definition: SPOSetInfo.cpp:95
std::vector< SPOInfo * > states_t
Definition: SPOSetInfo.h:29
int index_max
maximum orbital index in the set (w.r.t the full set)
Definition: SPOSetInfo.h:109
void energy_sort(RealType tol)
sort states by energy
Definition: SPOSetInfo.cpp:155
bool has_energies() const
Definition: SPOSetInfo.cpp:89
bool is_complete
whether initialization is complete and SPOSetInfo is ready for use
Definition: SPOSetInfo.h:91
RealType energy_tolerance() const
Definition: SPOSetInfo.cpp:105
bool indices_present
whether all states have an index assigned
Definition: SPOSetInfo.h:94
std::vector< SPOI * > states
Definition: SPOSetInfo.h:140
RealType energy_tol
tolerance used to sort energies
Definition: SPOSetInfo.h:103
void energy_sort(RealType tol=1e-6, bool assign_indices=false)
Definition: SPOSetInfo.h:166
void finish(std::vector< int > &subset, std::vector< SPOI *> &state_vector, orderings ord=spoinfo::no_order, RealType tol=1e-6)
Definition: SPOSetInfo.h:79
QMCTraits::RealType RealType
Definition: SPOSetInfo.h:28
orderings order
enum for how states are ordered
Definition: SPOSetInfo.h:100
orderings
enumeration of possible orbital info orderings
Definition: SPOInfo.h:68
void finish(orderings ord=spoinfo::no_order, RealType tol=1e-6)
renders collection immutable, must be called at end of initialization
Definition: SPOSetInfo.cpp:51
bool index_ordered() const
Definition: SPOSetInfo.cpp:113