QMCPACK
SPOSetInfo.cpp
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 #include "SPOSetInfo.h"
15 #include <limits>
16 
17 
18 namespace qmcplusplus
19 {
21 using namespace spoinfo;
22 
23 constexpr RealType no_energy_tol = std::numeric_limits<RealType>::max();
24 constexpr int no_index = -1;
25 
26 
27 // construction/destruction
28 SPOSetInfo::SPOSetInfo() { modify(); }
29 
30 SPOSetInfo::~SPOSetInfo() { delete_iter(states.begin(), states.end()); }
31 
32 
33 // initialization
34 void SPOSetInfo::add(SPOInfo& state) { states.push_back(state.copy()); }
35 
36 void SPOSetInfo::add(SPOInfo* state) { states.push_back(state->copy()); }
37 
38 void SPOSetInfo::add(std::vector<SPOInfo*>& state_vector)
39 {
40  for (int i = 0; i < state_vector.size(); ++i)
41  add(state_vector[i]);
42 }
43 
45 {
46  states_t::iterator so = other.states.begin(), so_end = other.states.end();
47  for (; so != so_end; ++so)
48  add((*so));
49 }
50 
52 {
53  if (!complete())
54  {
55  index_min = std::numeric_limits<int>::max();
56  index_max = std::numeric_limits<int>::min();
57  indices_present = true;
58  energies_present = true;
59  states_t::iterator i = states.begin(), i_end = states.end();
60  for (; i != i_end; ++i)
61  {
62  SPOInfo& s = **i;
63  index_min = std::min(s.index, index_min);
64  index_max = std::max(s.index, index_max);
65  indices_present &= s.has_index();
66  energies_present &= s.has_energy();
67  }
68  if (!has_indices())
69  APP_ABORT(
70  "SPOSetInfo::finish\n indices have not been assigned to states as required\n this is a developer error");
71  if (ord == spoinfo::index_ordered)
72  index_sort();
73  else if (ord == spoinfo::energy_ordered)
74  energy_sort(tol);
75  else
76  determine_order(tol);
77  is_complete = true;
78  }
79 }
80 
81 
82 // initialization queries
83 bool SPOSetInfo::complete() const { return is_complete; }
84 
85 bool SPOSetInfo::partial() const { return size() > 0 && !complete(); }
86 
87 bool SPOSetInfo::has_indices() const { return indices_present; }
88 
89 bool SPOSetInfo::has_energies() const { return energies_present; }
90 
91 
92 // array-like read-only access
93 int SPOSetInfo::size() const { return states.size(); }
94 
95 const SPOInfo* SPOSetInfo::operator[](int s) const { return states[s]; }
96 
97 const SPOInfo* SPOSetInfo::operator[](int s) { return states[s]; }
98 
99 
100 // data access
101 int SPOSetInfo::min_index() const { return index_min; }
102 
103 int SPOSetInfo::max_index() const { return index_max; }
104 
105 RealType SPOSetInfo::energy_tolerance() const { return energy_tol; }
106 
107 
108 // state properties
109 bool SPOSetInfo::contiguous() const { return index_max - index_min == size() - 1; }
110 
111 bool SPOSetInfo::unordered() const { return order == spoinfo::unordered; }
112 
113 bool SPOSetInfo::index_ordered() const { return order == spoinfo::index_ordered || order == energy_and_index_ordered; }
114 
116 {
117  return order == spoinfo::energy_ordered || order == energy_and_index_ordered;
118 }
119 
120 
121 // printing
122 void SPOSetInfo::report(const std::string& pad)
123 {
124  app_log() << pad << "complete = " << complete() << std::endl;
125  if (complete())
126  {
127  app_log() << pad << "min_index = " << min_index() << std::endl;
128  app_log() << pad << "max_index = " << max_index() << std::endl;
129  app_log() << pad << "contiguous = " << contiguous() << std::endl;
130  app_log() << pad << "has_energies = " << has_energies() << std::endl;
131  app_log() << pad << "energy_ordered = " << energy_ordered() << std::endl;
132  if (energy_ordered())
133  app_log() << pad << "energy_tolerance = " << energy_tolerance() << std::endl;
134  app_log() << pad << "# of states = " << size() << std::endl;
135  app_log() << pad << "state information:" << std::endl;
136  states_t::iterator s = states.begin(), s_end = states.end();
137  std::string pad2 = pad + " ";
138  int ns = 0;
139  for (; s != s_end; ++s, ++ns)
140  {
141  app_log() << pad << " state " << ns << std::endl;
142  (*s)->report(pad2);
143  }
144  }
145  app_log().flush();
146 }
147 
148 
150 {
151  sort(states.begin(), states.end(), index_order);
152  order = spoinfo::index_ordered;
153 }
154 
156 {
157  if (!has_energies())
158  APP_ABORT("SHOSetInfo::energy_sort not all states have an energy assigned");
159  energy_tol = tol;
160  EnergyOrder energy_order(energy_tol);
161  sort(states.begin(), states.end(), energy_order);
162  order = spoinfo::energy_ordered;
163  count_degeneracies();
164 }
165 
167 {
168  if (energy_ordered())
169  {
170  states_t::iterator stmp, s = states.begin(), s_end = states.end();
171  while (s != s_end)
172  {
173  int g = 1;
174  stmp = s;
175  ++stmp;
176  // look ahead to count
177  while (stmp != s_end && std::abs((*stmp)->energy - (*s)->energy) < energy_tol)
178  {
179  g++;
180  ++stmp;
181  }
182  (*s)->degeneracy = g;
183  //(*s)->degeneracy_index = g-1;
184  // run over degenerate states to assign
185  for (int n = 0; n < g; ++n)
186  {
187  (*s)->degeneracy = g;
188  //(*s)->degeneracy_index = g-1-n;
189  ++s;
190  }
191  }
192  }
193 }
194 
196 {
197  bool index_ord = false;
198  bool energy_ord = false;
199  states_t::iterator s_prev, s;
200  s = states.begin();
201  for (int i = 1; i < size(); ++i)
202  {
203  s_prev = s;
204  ++s;
205  index_ord &= index_order(*s_prev, *s);
206  }
207  if (has_energies())
208  {
209  energy_tol = tol;
210  EnergyOrder energy_order(energy_tol);
211  s = states.begin();
212  for (int i = 1; i < size(); ++i)
213  {
214  s_prev = s;
215  ++s;
216  energy_ord &= energy_order(*s_prev, *s);
217  }
218  }
219  if (index_ord && energy_ord)
220  order = energy_and_index_ordered;
221  else if (index_ord)
222  order = spoinfo::index_ordered;
223  else if (energy_ord)
224  order = spoinfo::energy_ordered;
225  else
226  order = spoinfo::unordered;
227  count_degeneracies();
228 }
229 
231 {
232  is_complete = false;
233  order = no_order;
234  indices_present = false;
235  energies_present = false;
236  energy_tol = no_energy_tol;
237  index_min = no_index;
238  index_max = no_index;
239 }
240 
242 {
243  delete_iter(states.begin(), states.end());
244  states.clear();
245  modify();
246 }
247 
248 } // namespace qmcplusplus
void index_sort()
sort states by index
Definition: SPOSetInfo.cpp:149
std::vector< SPOInfo * > states
collection of SPOInfo
Definition: SPOSetInfo.h:112
constexpr int no_index
Definition: SPOSetInfo.cpp:24
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
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
std::ostream & app_log()
Definition: OutputManager.h:65
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
T min(T a, T b)
void report(const std::string &pad="")
Definition: SPOSetInfo.cpp:122
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
SPOInfo * copy()
Definition: SPOInfo.h:58
collection of orbital info for SPOSet instance or builder
Definition: SPOSetInfo.h:25
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
const SPOInfo * operator[](int s) const
Definition: SPOSetInfo.cpp:95
void energy_sort(RealType tol)
sort states by energy
Definition: SPOSetInfo.cpp:155
bool has_energies() const
Definition: SPOSetInfo.cpp:89
RealType energy_tolerance() const
Definition: SPOSetInfo.cpp:105
QMCTraits::RealType RealType
void add(int n, const T *restrict in, T *restrict out)
Definition: vmath.hpp:95
QMCTraits::RealType RealType
Definition: SPOSetInfo.h:28
constexpr RealType no_energy_tol
Definition: SPOSetInfo.cpp:23
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