MADNESS  0.10.1
CCStructures.h
Go to the documentation of this file.
1 /*
2  * CCStructures.h
3  *
4  * Created on: Sep 3, 2015
5  * Author: kottmanj
6  */
7 
8 
9 /// File holds all helper structures necessary for the CC_Operator and CC2 class
10 #ifndef CCSTRUCTURES_H_
11 #define CCSTRUCTURES_H_
12 
13 #include <madness/mra/mra.h>
17 #include <algorithm>
18 #include <iomanip>
19 #include <iostream>
20 #include <madness/mra/macrotaskq.h>
21 
22 #include "lowrankfunction.h"
23 
24 namespace madness {
25 
26 /// Calculation Types used by CC2
27 enum CalcType {
29 };
30 /// Type of Pairs used by CC_Pair2 class
31 enum CCState {
33 };
34 /// CC2 Singles Potentials
53 };
54 
55 /// Assigns strings to enums for formated output
56 std::string
57 assign_name(const CCState& input);
58 
59 /// Assigns enum to string
61 assign_calctype(const std::string name);
62 
63 /// Assigns strings to enums for formated output
64 std::string
65 assign_name(const CalcType& inp);
66 
67 /// Assigns strings to enums for formated output
68 std::string
69 assign_name(const PotentialType& inp);
70 
71 /// Assigns strings to enums for formated output
72 std::string
73 assign_name(const FuncType& inp);
74 
75 // Little structure for formated output and to collect warnings
76 // much room to improve
77 struct CCMessenger {
78  CCMessenger(World& world) : world(world), output_prec(10), scientific(true), debug(false), os(std::cout) {}
79 
81  size_t output_prec;
82  bool scientific;
83  bool debug;
84 
85  void operator()(const std::string& msg) const { output(msg); }
86 
87  void debug_output(const std::string& msg) const {
88  if (debug) output(msg);
89  }
90 
91  void
92  output(const std::string& msg) const;
93 
94  void
95  section(const std::string& msg) const;
96 
97  void
98  subsection(const std::string& msg) const;
99 
100  void
101  warning(const std::string& msg) const;
102 
103  void print_warnings() const {
104  for (const auto& x:warnings) if (world.rank() == 0) std::cout << x << "\n";
105  }
106 
107  template<class T>
108  CCMessenger operator<<(const T& t) const {
109  using madness::operators::operator<<;
110  if (world.rank() == 0) os << t;
111  return *this;
112  }
113 
114  /// collect all warnings that occur to print out at the end of the job
115  mutable std::vector<std::string> warnings;
116  /// output stream
117  std::ostream& os;
118 };
119 
120 
121 /// Timer Structure
122 struct CCTimer {
123  /// TDA_TIMER constructor
124  /// @param[in] world the world
125  /// @param[in] msg a string that contains the desired printout when info function is called
127  operation(msg), end_wall(0.0), end_cpu(0.0), time_wall(-1.0),
128  time_cpu(-1.0) {}
129 
131  double start_wall;
132  double start_cpu;
133  std::string operation;
134  double end_wall;
135  double end_cpu;
136  double time_wall;
137  double time_cpu;
138 
139  void update_time() {
142  }
143 
144 public:
145  /// print out information about the passed time since the CC_TIMER object was created
146  void
147  info(const bool debug = true, const double norm = 12345.6789);
148 
150  start_wall = wall_time();
151  start_cpu = cpu_time();
152  return *this;
153  }
154 
156  end_wall = wall_time();
157  end_cpu = cpu_time();
160  return *this;
161  }
162 
163  double reset() {
164  stop();
165  double wtime=time_wall;
166  start();
167  return wtime;
168  }
169 
170 
171  double get_wall_time_diff() const { return end_wall; }
172 
173  double get_cpu_time_diff() const { return end_cpu; }
174 
175  std::pair<double, double> current_time(bool printout = false) {
176  if (time_wall < 0.0 or time_cpu < 0.0) stop();
177  return std::make_pair(time_wall, time_cpu);
178  }
179 
180  void print() {
181  print(current_time());
182  }
183 
184  void print() const {
185  print(std::make_pair(time_wall, time_cpu));
186  }
187 
188  void print(const std::pair<double, double>& times) const {
189  if (world.rank() == 0) {
190  std::cout << std::setfill(' ') << std::scientific << std::setprecision(2)
191  << "Timer: " << times.first << " (Wall), " << times.second << " (CPU)" << ", (" + operation + ")"
192  << "\n";
193  }
194  }
195 };
196 
197 /// Calculation TDHFParameters for CC2 and TDA calculations
198 /// Maybe merge this with calculation_parameters of SCF at some point, or split into TDA and CC
200 
203  };
204 
205  /// copy constructor
206  CCParameters(const CCParameters& other) =default;
207 
208  /// ctor reading out the input file
209  CCParameters(World& world, const commandlineparser& parser) {
211  read_input_and_commandline_options(world,parser,"cc2");
213  };
214 
215 
217  double thresh=1.e-3;
218  double thresh_operators=1.e-6;
219  initialize < std::string > ("calc_type", "mp2", "the calculation type", {"mp2", "mp3", "cc2", "cis", "lrcc2", "cispd", "adc2", "test"});
220  initialize < double > ("lo", 1.e-7, "the finest length scale to be resolved by 6D operators");
221  initialize < double > ("dmin", 1.0, "defines the depth of the special level");
222  initialize < double > ("thresh_6d", thresh, "threshold for the 6D wave function");
223  initialize < double > ("tight_thresh_6d", 0.1*thresh, "tight threshold for the 6D wave function");
224  initialize < double > ("thresh_3d", 0.01*thresh, "threshold for the 3D reference wave function");
225  initialize < double > ("tight_thresh_3d", 0.001*thresh, "tight threshold for the 3D reference wave function");
226  initialize < double > ("thresh_bsh_3d", thresh_operators, "threshold for BSH operators");
227  initialize < double > ("thresh_bsh_6d", thresh_operators, "threshold for BSH operators");
228  initialize < double > ("thresh_poisson", thresh_operators, "threshold for Poisson operators");
229  initialize < double > ("thresh_f12", thresh_operators, "threshold for Poisson operators");
230  initialize < double > ("thresh_Ue", thresh_operators, "ue threshold");
231  initialize < double > ("econv", thresh, "overal convergence threshold ");
232  initialize < double > ("econv_pairs", 0.1*thresh, "convergence threshold for pairs");
233  initialize < double > ("dconv_3d", 0.3*thresh, "convergence for cc singles");
234  initialize < double > ("dconv_6d", 3.0*thresh, "convergence for cc doubles");
235  initialize < std::size_t > ("iter_max", 10, "max iterations");
236  initialize < std::size_t > ("iter_max_3d", 10, "max iterations for singles");
237  initialize < std::size_t > ("iter_max_6d", 10, "max iterations for doubles");
238  initialize < std::pair<int, int>> ("only_pair", {-1, -1}, "compute only a single pair");
239  initialize < bool > ("restart", false, "restart");
240  initialize < bool > ("no_compute", false, "no compute");
241  initialize < bool > ("no_compute_gs", false, "no compute");
242  initialize < bool > ("no_compute_mp2_constantpart", false, "no compute");
243  initialize < bool > ("no_compute_response", false, "no compute");
244  initialize < bool > ("no_compute_mp2", false, "no compute");
245  initialize < bool > ("no_compute_cc2", false, "no compute");
246  initialize < bool > ("no_compute_cispd", false, "no compute");
247  initialize < bool > ("no_compute_lrcc2", false, "no compute");
248  initialize < double > ("corrfac_gamma", 1.0, "exponent for the correlation factor");
249  initialize < std::size_t > ("output_prec", 8, "for formatted output");
250  initialize < bool > ("debug", false, "");
251  initialize < bool > ("plot", false, "");
252  initialize < bool > ("kain", true, "");
253  initialize < std::size_t > ("kain_subspace", 3, "");
254  initialize < long > ("freeze", -1, "number of frozen orbitals: -1: automatic");
255  initialize < bool > ("test", false, "");
256  // choose if Q for the constant part of MP2 and related calculations should be decomposed: GQV or GV - GO12V
257  initialize < bool > ("decompose_Q", true, "always true",{true});
258  // if true the ansatz for the CC2 ground state pairs is |tau_ij> = |u_ij> + Qtf12|titj>, with Qt = Q - |tau><phi|
259  // if false the ansatz is the same with normal Q projector
260  // the response ansatz is the corresponding response of the gs ansatz
261  initialize < bool > ("QtAnsatz", true, "always true",{true});
262  // a vector containing the excitations which shall be optizmized later (with CIS(D) or CC2)
263  initialize < std::vector<size_t>>
264  ("excitations", {}, "vector containing the excitations");
265  }
266 
267  void set_derived_values();
268 
269  CalcType calc_type() const {
270  std::string value = get<std::string>("calc_type");
271  if (value == "mp2") return CT_MP2;
272  if (value == "mp3") return CT_MP3;
273  if (value == "cc2") return CT_CC2;
274  if (value == "cis") return CT_LRCCS;
275  if (value == "lrcc2") return CT_LRCC2;
276  if (value == "cispd") return CT_CISPD;
277  if (value == "adc2") return CT_ADC2;
278  if (value == "test") return CT_TEST;
279  MADNESS_EXCEPTION("faulty CalcType", 1);
280  }
281 
282  bool response() const {return calc_type()==CT_ADC2 or calc_type()==CT_CISPD or calc_type()==CT_LRCC2 or calc_type()==CT_LRCCS;}
283  double lo() const { return get<double>("lo"); }
284 
285  double dmin() const { return get<double>("dmin"); }
286 
287  double thresh_3D() const { return get<double>("thresh_3d"); }
288 
289  double tight_thresh_3D() const { return get<double>("tight_thresh_3d"); }
290 
291  double thresh_6D() const { return get<double>("thresh_6d"); }
292 
293  double tight_thresh_6D() const { return get<double>("tight_thresh_6d"); }
294 
295  double thresh_bsh_3D() const { return get<double>("thresh_bsh_3d"); }
296 
297  double thresh_bsh_6D() const { return get<double>("thresh_bsh_6d"); }
298 
299  double thresh_poisson() const { return get<double>("thresh_poisson"); }
300 
301  double thresh_f12() const { return get<double>("thresh_f12"); }
302 
303  double thresh_Ue() const { return get<double>("thresh_ue"); }
304 
305  double econv() const { return get<double>("econv"); }
306 
307  double econv_pairs() const { return get<double>("econv_pairs"); }
308 
309  double dconv_3D() const { return get<double>("dconv_3d"); }
310 
311  double dconv_6D() const { return get<double>("dconv_6d"); }
312 
313  std::size_t iter_max() const { return get<std::size_t>("iter_max"); }
314 
315  std::size_t iter_max_3D() const { return get<std::size_t>("iter_max_3d"); }
316 
317  std::size_t iter_max_6D() const { return get<std::size_t>("iter_max_6d"); }
318 
319  std::pair<int, int> only_pair() const { return get<std::pair<int, int>>("only_pair"); }
320 
321  bool restart() const { return get<bool>("restart"); }
322 
323  bool no_compute() const { return get<bool>("no_compute"); }
324 
325  bool no_compute_gs() const { return get<bool>("no_compute_gs"); }
326 
327  bool no_compute_mp2_constantpart() const { return get<bool>("no_compute_mp2_constantpart"); }
328 
329  bool no_compute_response() const { return get<bool>("no_compute_response"); }
330 
331  bool no_compute_mp2() const { return get<bool>("no_compute_mp2"); }
332 
333  bool no_compute_cc2() const { return get<bool>("no_compute_cc2"); }
334 
335  bool no_compute_cispd() const { return get<bool>("no_compute_cispd"); }
336 
337  bool no_compute_lrcc2() const { return get<bool>("no_compute_lrcc2"); }
338 
339  bool debug() const { return get<bool>("debug"); }
340 
341  bool plot() const { return get<bool>("plot"); }
342 
343  bool kain() const { return get<bool>("kain"); }
344 
345  bool test() const { return get<bool>("test"); }
346 
347  bool decompose_Q() const { return get<bool>("decompose_q"); }
348 
349  bool QtAnsatz() const { return get<bool>("qtansatz"); }
350 
351  std::size_t output_prec() const { return get<std::size_t>("output_prec"); }
352 
353  std::size_t kain_subspace() const { return get<std::size_t>("kain_subspace"); }
354 
355  long freeze() const { return get<long>("freeze"); }
356 
357  std::vector<std::size_t> excitations() const { return get<std::vector<std::size_t>>("excitations"); }
358 
359  double gamma() const {return get<double>("corrfac_gamma");}
360 
361  /// print out the parameters
362  void information(World& world) const;
363 
364  /// check if parameters are set correct
365  void sanity_check(World& world) const;
366 
367  void error(World& world, const std::string& msg) const {
368  if (world.rank() == 0)
369  std::cout << "\n\n\n\n\n!!!!!!!!!\n\nERROR IN CC_PARAMETERS:\n ERROR MESSAGE IS: " << msg
370  << "\n\n\n!!!!!!!!" << std::endl;
371  MADNESS_EXCEPTION("ERROR IN CC_PARAMETERS", 1);
372  }
373 
374  size_t warning(World& world, const std::string& msg) const {
375  if (world.rank() == 0) std::cout << "WARNING IN CC_PARAMETERS!: " << msg << std::endl;
376  return 1;
377  }
378 
379 };
380 
382 
383  std::vector<std::pair<int, int>> map; ///< maps pair index (i,j) to vector index k
384  PairVectorMap() = default;
385  PairVectorMap(const std::vector<std::pair<int, int>> map1) : map(map1) {}
386 
387  static PairVectorMap triangular_map(const int nfreeze, const int nocc) {
388  std::vector<std::pair<int, int>> map; ///< maps pair index (i,j) to vector index k
389  for (int i=nfreeze; i<nocc; ++i) {
390  for (int j=i; j<nocc; ++j) {
391  map.push_back(std::make_pair(i,j));
392  }
393  }
394  return PairVectorMap(map);
395  }
396 
397  static PairVectorMap quadratic_map(const int nfreeze, const int nocc) {
398  std::vector<std::pair<int, int>> map; ///< maps pair index (i,j) to vector index k
399  for (int i=nfreeze; i<nocc; ++i) {
400  for (int j=nfreeze; j<nocc; ++j) {
401  map.push_back(std::make_pair(i,j));
402  }
403  }
404  return PairVectorMap(map);
405  }
406 
407  void print(const std::string msg="PairVectorMap") const {
408  madness::print(msg);
409  madness::print("vector element <-> pair index");
410  for (size_t i=0; i<map.size(); ++i) {
411  madness::print(i, " <-> ",map[i]);
412  }
413  }
414 
415 };
416 
417 /// POD holding all electron pairs with easy access
418 /// Similar strucutre than the Pair structure from MP2 but with some additional features (merge at some point)
419 /// This structure will also be used for intermediates
420 template<typename T>
421 struct Pairs {
422 
423  typedef std::map<std::pair<int, int>, T> pairmapT;
425 
426  /// convert Pairs<T> to another type
427 
428  /// opT op takes an object of T and returns the result type
429  template<typename R, typename opT>
430  Pairs<R> convert(const Pairs<T> arg, const opT op) const {
431  Pairs<R> result;
432  for (auto& p : arg.allpairs) {
433  int i=p.first.first;
434  int j=p.first.second;
435  result.insert(i,j,op(p.second));
436  }
437  return result;
438  }
439 
440  static Pairs vector2pairs(const std::vector<T>& argument, const PairVectorMap map) {
441  Pairs<T> pairs;
442  for (int i=0; i<argument.size(); ++i) {
443  pairs.insert(map.map[i].first,map.map[i].second,argument[i]);
444  }
445  return pairs;
446  }
447 
448  static std::vector<T> pairs2vector(const Pairs<T>& argument, const PairVectorMap map) {
449  std::vector<T> vector;
450  for (size_t i=0; i<argument.allpairs.size(); ++i) {
451  vector.push_back(argument(map.map[i].first,map.map[i].second));
452  }
453  return vector;
454  }
455 
456  /// getter
457  const T& operator()(int i, int j) const {
458  return allpairs.at(std::make_pair(i, j));
459  }
460 
461  /// getter
462  // at instead of [] operator bc [] inserts new element if nothing is found while at throws out of range error
463  // back to before
464  T& operator()(int i, int j) {
465  // return allpairs.at(std::make_pair(i, j));
466  return allpairs[std::make_pair(i, j)];
467  }
468 
469  /// setter
470  /// can NOT replace elements (for this construct new pair map and swap the content)
471  void insert(int i, int j, const T& pair) {
472  std::pair<int, int> key = std::make_pair(i, j);
473  allpairs.insert(std::make_pair(key, pair));
474  }
475 
476  /// swap the contant of the pairmap
477  void swap(Pairs<T>& other) {
478  allpairs.swap(other.allpairs);
479  }
480 
481  bool empty() const {
482  if (allpairs.size() == 0) return true;
483  else return false;
484  }
485 };
486 
487 /// f12 and g12 intermediates of the form <f1|op|f2> (with op=f12 or op=g12) will be saved using the pair structure
488 template <typename T, std::size_t NDIM>
490 
491 /// Returns the size of an intermediate
492 //double
493 //size_of(const intermediateT& im);
494 /// Returns the size of an intermediate
495 template<typename T, std::size_t NDIM>
496 double
498  double size = 0.0;
499  for (const auto& tmp : im.allpairs) {
500  size += get_size<T, NDIM>(tmp.second);
501  }
502  return size;
503 }
504 
505 
506 
507 // structure for CC Vectorfunction
508 /// A helper structure which holds a map of functions
510 
512 
513  CC_vecfunction(const FuncType type_) : type(type_), omega(0.0), current_error(99.9), delta(0.0) {}
514 
516  for (size_t i = 0; i < v.size(); i++) {
517  CCFunction<double,3> tmp(v[i], i, type);
518  functions.insert(std::make_pair(i, tmp));
519  }
520  }
521 
522  CC_vecfunction(const std::vector<CCFunction<double,3>>& v) : type(UNDEFINED), omega(0.0), current_error(99.9), delta(0.0) {
523  for (size_t i = 0; i < v.size(); i++) {
524  functions.insert(std::make_pair(v[i].i, v[i]));
525  }
526  }
527 
529  current_error(99.9), delta(0.0) {
530  for (size_t i = 0; i < v.size(); i++) {
531  CCFunction<double,3> tmp(v[i], i, type);
532  functions.insert(std::make_pair(i, tmp));
533  }
534  }
535 
536  CC_vecfunction(const vector_real_function_3d& v, const FuncType& type, const size_t& freeze) : type(type),
537  omega(0.0),
538  current_error(99.9),
539  delta(0.0) {
540  for (size_t i = 0; i < v.size(); i++) {
541  CCFunction<double,3> tmp(v[i], freeze + i, type);
542  functions.insert(std::make_pair(freeze + i, tmp));
543  }
544  }
545 
546  CC_vecfunction(const std::vector<CCFunction<double,3>>& v, const FuncType type_)
547  : type(type_), omega(0.0), current_error(99.9), delta(0.0) {
548  for (auto x:v) functions.insert(std::make_pair(x.i, x));
549  }
550 
551  /// copy ctor (shallow)
553  : functions(other.functions), type(other.type), omega(other.omega),
555  delta(other.delta), irrep(other.irrep) {
556  }
557 
558  /// assignment operator, shallow wrt the functions
559 // CC_vecfunction& operator=(const CC_vecfunction& other) = default;
561  if (this == &other) return *this;
562  functions = other.functions;
563  type = other.type;
564  omega = other.omega;
566  delta = other.delta;
567  irrep = other.irrep;
568  return *this;
569  }
570 
571 
572  /// returns a deep copy (void shallow copy errors)
573  friend CC_vecfunction
574  copy(const CC_vecfunction& other) {
575  CC_vecfunction tmp=other;
576  tmp.functions.clear();
577  for (const auto& x : other.functions) {
578  tmp.functions.insert(std::make_pair(x.first, copy(x.second)));
579  }
580  return tmp;
581  }
582 
583 
584 //madness::CC_vecfunction
585 //CC_vecfunction::copy() const {
586 // std::vector<CCFunction<double,3>> vn;
587 // for (auto x : functions) {
588 // const CCFunction<double,3> fn(madness::copy(x.second.function), x.second.i, x.second.type);
589 // vn.push_back(fn);
590 // }
591 // CC_vecfunction result(vn, type);
592 // result.irrep = irrep;
593 // return result;
594 //}
595 //
596 
597  static CC_vecfunction load_restartdata(World& world, std::string filename) {
599  CC_vecfunction tmp;
600  ar & tmp;
601  return tmp;
602  }
603 
604  void save_restartdata(World& world, std::string filename) const {
606  ar & *this;
607  }
608 
609  template<typename Archive>
610  void serialize(const Archive& ar) {
611  typedef std::vector<std::pair<std::size_t, CCFunction<double,3>>> CC_functionvec;
612 
613  auto map2vector = [] (const CC_functionmap& map) {
614  return CC_functionvec(map.begin(), map.end());
615  };
616  auto vector2map = [] (const CC_functionvec& vec) {
617  return CC_functionmap(vec.begin(), vec.end());
618  };
619 
620  ar & type & omega & current_error & delta & irrep ;
621  if (ar.is_input_archive) {
622  std::size_t size=0; // set to zero to silence compiler warning
623  ar & size;
624  CC_functionvec tmp(size);
625 
626  for (auto& t : tmp) ar & t.first & t.second;
627  functions=vector2map(tmp);
628  } else if (ar.is_output_archive) {
629  auto tmp=map2vector(functions);
630  ar & tmp.size();
631  for (auto& t : tmp) ar & t.first & t.second;
632  }
633  }
634 
635  hashT hash() const {
636  hashT hashval = std::hash<FuncType>{}(type);
637  for (const auto& f : functions) hash_combine(hashval, hash_value(f.second.f().get_impl()->id()));
638 
639  return hashval;
640  }
641 
642  typedef std::map<std::size_t, CCFunction<double,3>> CC_functionmap;
644 
646  double omega; /// excitation energy
648  double delta; // Last difference in Energy
649  std::string irrep = "null"; /// excitation irrep (direct product of x function and corresponding orbital)
650 
651  std::string
652  name(const int ex) const {
653  return madness::name(type,ex);
654  };
655 
656  bool is_converged(const double econv, const double dconv) const {
657  return (current_error<dconv) and (std::fabs(delta)<econv);
658  }
659 
660  /// getter
662  return functions.find(i.i)->second;
663  }
664 
665  /// getter
666  const CCFunction<double,3>& operator()(const size_t& i) const {
667  return functions.find(i)->second;
668  }
669 
670  /// getter
672  return functions[i.i];
673  }
674 
675  /// getter
676  CCFunction<double,3>& operator()(const size_t& i) {
677  return functions[i];
678  }
679 
680  /// setter
681  void insert(const size_t& i, const CCFunction<double,3>& f) {
682  functions.insert(std::make_pair(i, f));
683  }
684 
685  /// setter
686  void set_functions(const vector_real_function_3d& v, const FuncType& type, const size_t& freeze) {
687  functions.clear();
688  for (size_t i = 0; i < v.size(); i++) {
689  CCFunction<double,3> tmp(v[i], freeze + i, type);
690  functions.insert(std::make_pair(freeze + i, tmp));
691  }
692  }
693 
694  /// Returns all the functions of the map as vector
697  for (auto x:functions) tmp.push_back(x.second.function);
698  return tmp;
699  }
700 
701  /// Get the size vector (number of functions in the map)
702  size_t size() const {
703  return functions.size();
704  }
705 
706  /// Print the memory of which is used by all the functions in the map
707  void
708  print_size(const std::string& msg = "!?not assigned!?") const;
709 
710  /// scalar multiplication
711  CC_vecfunction operator*(const double& fac) const {
713  const size_t freeze = functions.cbegin()->first;
714  return CC_vecfunction(vnew, type, freeze);
715  }
716 
717  /// scaling (inplace)
718  void scale(const double& factor) {
719  for (auto& ktmp:functions) {
720  ktmp.second.function.scale(factor);
721  }
722  }
723 
724  /// operator needed for sort operation (sorted by omega values)
725  bool operator<(const CC_vecfunction& b) const { return omega < b.omega; }
726 
727  // plotting
728  void plot(const std::string& msg = "") const {
729  for (auto& ktmp:functions) {
730  ktmp.second.plot(msg);
731  }
732  }
733 public:
734  NLOHMANN_DEFINE_TYPE_INTRUSIVE(CC_vecfunction, omega, irrep, current_error)
735 
736 };
737 
738 /// Helper Structure that carries out operations on CC_functions
739 /// The structure can hold intermediates for g12 and f12 of type : <mo_bra_k|op|type> with type=HOLE,PARTICLE or RESPONSE
740 /// some 6D operations are also included
741 /// The structure does not know if nuclear correlation facors are used, so the corresponding bra states have to be prepared beforehand
742 template<typename T=double, std::size_t NDIM=3>
744 public:
745 
746  /// parameter class
747  struct Parameters {
749 
750  Parameters(const Parameters& other) :
751  thresh_op(other.thresh_op),
752  lo(other.lo),
753  freeze(other.freeze),
754  gamma(other.gamma) {
755  }
756 
757  Parameters(const CCParameters& param) : thresh_op(param.thresh_poisson()), lo(param.lo()),
758  freeze(param.freeze()),
759  gamma(param.gamma()) {};
761  double lo = 1.e-6;
762  int freeze = 0;
763  double gamma = 1.0; /// f12 exponent
764 
765  template<typename archiveT>
766  void serialize(archiveT& ar) {
767  ar & thresh_op & lo & freeze & gamma;
768  }
769  };
770 
771 
772  /// @param[in] world
773  /// @param[in] optype: the operatortype (can be g12_ or f12_)
774  /// @param[in] param: the parameters of the current CC-Calculation (including function and operator thresholds and the exponent for f12)
777  }
778 
780 
781  static inline
782  std::shared_ptr<CCConvolutionOperator> CCConvolutionOperatorPtr(World& world, const OpType type, Parameters param) {
783  return std::shared_ptr<CCConvolutionOperator>(new CCConvolutionOperator(world, type, param));
784  }
785 
786 protected:
787 
789  auto info= SeparatedConvolution<T,NDIM>::combine_OT((*a.get_op()),(*b.get_op()));
791  param.gamma=info.mu;
792  param.thresh_op=info.thresh;
793  param.lo=info.lo;
794  param.freeze=a.parameters.freeze;
795  return CCConvolutionOperator(a.world, info.type, param);
796  }
797 
798  friend std::shared_ptr<CCConvolutionOperator> combine(const std::shared_ptr<CCConvolutionOperator>& a,
799  const std::shared_ptr<CCConvolutionOperator>& b) {
800  if (a and (not b)) return a;
801  if ((not a) and b) return b;
802  if ((not a) and (not b)) return nullptr;
803  return std::shared_ptr<CCConvolutionOperator>(new CCConvolutionOperator(combine(*a,*b)));
804  }
805 
806 public:
807  /// @param[in] f: a 3D function
808  /// @param[out] the convolution op(f), no intermediates are used
810  if (op) return ((*op)(f)).truncate();
811  return f;
812  }
813 
814  /// @param[in] bra a CC_vecfunction
815  /// @param[in] ket a CC_function
816  /// @param[out] vector[i] = <bra[i]|op|ket>
817  std::vector<Function<T,NDIM>> operator()(const CC_vecfunction& bra, const CCFunction<T,NDIM>& ket) const {
818  MADNESS_CHECK(op);
819  std::vector<Function<T, NDIM>> result;
820  if constexpr (NDIM == 3) {
821  if (bra.type == HOLE) {
822  for (const auto& ktmp: bra.functions) {
823  const CCFunction<T, NDIM>& brai = ktmp.second;
824  const Function<T, NDIM> tmpi = this->operator()(brai, ket);
825  result.push_back(tmpi);
826  }
827  } else {
828  std::vector<Function<T, NDIM>> tmp = mul(world, ket.function, bra.get_vecfunction());
829  result = apply(world, (*op), tmp);
830  truncate(world, result);
831  }
832  } else {
833  MADNESS_EXCEPTION("not implemented", 1);
834  }
835 
836  return result;
837  }
838 
839  // @param[in] f: a vector of 3D functions
840  // @param[out] the convolution of op with each function, no intermeditates are used
841  std::vector<Function<T,NDIM>> operator()(const std::vector<Function<T,NDIM>>& f) const {
842  MADNESS_CHECK(op);
843  return apply<T,T,NDIM,NDIM>(world, (*op), f);
844  }
845 
846  // @param[in] bra: a 3D CC_function, if nuclear-correlation factors are used they have to be applied before
847  // @param[in] ket: a 3D CC_function,
848  // @param[in] use_im: default is true, if false then no intermediates are used
849  // @param[out] the convolution <bra|op|ket> = op(bra*ket), if intermediates were calculated before the operator uses them
850  Function<T,NDIM> operator()(const CCFunction<T,NDIM>& bra, const CCFunction<T,NDIM>& ket, const bool use_im = true) const;
851 
852  // @param[in] u: a 6D-function
853  // @param[out] the convolution \int g(r,r') u(r,r') dr' (if particle==2) and g(r,r') u(r',r) dr' (if particle==1)
854  // @param[in] particle: specifies on which particle of u the operator will act (particle ==1 or particle==2)
855  Function<T,2*NDIM> operator()(const Function<T,2*NDIM>& u, const size_t particle) const;
856 
857  // @param[in] bra: a 3D-CC_function, if nuclear-correlation factors are used they have to be applied before
858  // @param[in] u: a 6D-function
859  // @param[in] particle: specifies on which particle of u the operator will act (particle ==1 or particle==2)
860  // @param[out] the convolution <bra|g12|u>_particle
861  Function<T,NDIM> operator()(const CCFunction<T,NDIM>& bra, const Function<T,2*NDIM>& u, const size_t particle) const;
862 
863  /// @param[in] bra: a vector of CC_functions, the type has to be HOLE
864  /// @param[in] ket: a vector of CC_functions, the type can be HOLE,PARTICLE,RESPONSE
865  /// updates intermediates of the type <bra|op|ket>
866  void update_elements(const CC_vecfunction& bra, const CC_vecfunction& ket);
867 
868  /// @param[out] prints the name of the operator (convenience) which is g12 or f12 or maybe other things like gf in the future
869  std::string name() const {
870  std::stringstream ss;
871  ss << type();
872  return ss.str();
873  }
874 
875  /// @param[in] the type of which intermediates will be deleted
876  /// e.g if(type==HOLE) then all intermediates of type <mo_bra_k|op|HOLE> will be deleted
877  void clear_intermediates(const FuncType& type);
878 
879  /// prints out information (operatorname, number of stored intermediates ...)
880  size_t info() const;
881 
883  hashT h;
884  hash_combine(h, op.parameters.thresh_op);
885  hash_combine(h, op.parameters.lo);
886  hash_combine(h, op.parameters.freeze);
887  hash_combine(h, op.parameters.gamma);
888  hash_combine(h, int(op.type()));
889  return h;
890  }
891 
892  /// sanity check .. doens not do so much
893  void sanity() const { print_intermediate(HOLE); }
894 
895  /// @param[in] type: the type of intermediates which will be printed, can be HOLE,PARTICLE or RESPONSE
896  void print_intermediate(const FuncType type) const {
897  if (type == HOLE)
898  for (const auto& tmp:imH.allpairs)
899  tmp.second.print_size("<H" + std::to_string(tmp.first.first) + "|" + name() + "|H" +
900  std::to_string(tmp.first.second) + "> intermediate");
901  else if (type == PARTICLE)
902  for (const auto& tmp:imP.allpairs)
903  tmp.second.print_size("<H" + std::to_string(tmp.first.first) + "|" + name() + "|P" +
904  std::to_string(tmp.first.second) + "> intermediate");
905  else if (type == RESPONSE)
906  for (const auto& tmp:imR.allpairs)
907  tmp.second.print_size("<H" + std::to_string(tmp.first.first) + "|" + name() + "|R" +
908  std::to_string(tmp.first.second) + "> intermediate");
909  }
910 
911  /// create a TwoElectronFactory with the operatorkernel
913  auto factory=TwoElectronFactory<T,2*NDIM>(world);
914  factory.set_info(op->info);
915  return factory;
916  }
917 
918  OpType type() const { return get_op()->info.type; }
919 
921 
922  std::shared_ptr<SeparatedConvolution<T,NDIM>> get_op() const {return op;};
923 
924 private:
925  /// the world
927 
928  /// @param[in] optype: can be f12_ or g12_ depending on which operator shall be intitialzied
929  /// @param[in] parameters: parameters (thresholds etc)
930  /// initializes the operators
932 
933  std::shared_ptr<SeparatedConvolution<T,NDIM>> op;
937 
938  /// @param[in] msg: output message
939  /// the function will throw an MADNESS_EXCEPTION
940  void error(const std::string& msg) const {
941  if (world.rank() == 0)
942  std::cout << "\n\n!!!!ERROR in CCConvolutionOperator " << name() << ": " << msg
943  << "!!!!!\n\n" << std::endl;
944  MADNESS_EXCEPTION(msg.c_str(), 1);
945  }
946 public:
947 };
948 
949 template<typename T, std::size_t NDIM>
950 std::shared_ptr<CCConvolutionOperator<T,NDIM>> CCConvolutionOperatorPtr(World& world, const OpType type,
952  return std::shared_ptr<CCConvolutionOperator<T,NDIM>>(new CCConvolutionOperator<T,NDIM>(world,type,param));
953 }
954 
955 
957 public:
958  CCPair(){};
959 
960  CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c) : type(t), ctype(c), i(ii), j(jj),
961  bsh_eps(12345.6789) {};
962 
963  CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c, const std::vector<CCPairFunction<double,6>>& f)
964  : type(t), ctype(c), i(ii), j(jj), functions(f), bsh_eps(12345.6789) {};
965 
966  CCPair(const CCPair& other) : type(other.type), ctype(other.ctype), i(other.i), j(other.j),
968  bsh_eps(other.bsh_eps) {};
969 
972  size_t i;
973  size_t j;
974 
975  /// customized function to store this to the cloud
976 
977  /// functions and constant_part can be very large and we want to split them and store them in different records
979  // save bookkeeping stuff in a vector
980  std::vector<unsigned char> v;
982  bool function_is_assigned=(functions.size()>0 && functions[0].is_assigned());
983  arout & type & ctype & i & j & bsh_eps & function_is_assigned & constant_part.is_initialized();
984 
985  Recordlist<Cloud::keyT> records;
986  records+=cloud.store(world,v);
987  if (function_is_assigned) records+=cloud.store(world,functions[0]);
988  if (constant_part.is_initialized()) records+=cloud.store(world,constant_part);
989  return records;
990  }
991 
992  /// customized function to load this from the cloud
993 
994  /// functions and constant_part can be very large and we want to split them and store them in different records
995  /// @param[inout] recordlist: containing the keys of the member variables -> will be reduced by the keys which are used
996  void cloud_load(World& world, const Cloud& cloud, Recordlist<Cloud::keyT>& recordlist) {
997  // load bookkeeping stuff in a vector
998  std::vector<unsigned char> v=cloud.forward_load<std::vector<unsigned char>>(world,recordlist);
1000  bool function_is_assigned = false, constant_part_is_initialized=false;
1001  arin & type & ctype & i & j & bsh_eps & function_is_assigned & constant_part_is_initialized;
1002  functions.clear();
1003  constant_part.clear();
1004 
1005  if (function_is_assigned) functions.emplace_back(cloud.forward_load<CCPairFunction<double,6>>(world,recordlist));
1006  if (constant_part_is_initialized) constant_part=cloud.forward_load<real_function_6d>(world,recordlist);
1007  }
1008 
1009  /// gives back the pure 6D part of the pair function
1010  real_function_6d function() const {
1011  MADNESS_ASSERT(not functions.empty());
1012  MADNESS_ASSERT(functions[0].is_pure());
1013  return functions[0].get_function();
1014  }
1015 
1016  /// updates the pure 6D part of the pair function
1017  void update_u(const real_function_6d& u) {
1018  MADNESS_ASSERT(not functions.empty());
1019  MADNESS_ASSERT(functions[0].is_pure());
1020  CCPairFunction tmp(u);
1021  functions[0] = tmp;
1022  }
1023 
1024  template<typename Archive>
1025  void serialize(const Archive& ar) {
1026  size_t f_size = functions.size();
1027  bool fexist = (f_size > 0) && (functions[0].get_function().is_initialized());
1028  bool cexist = constant_part.is_initialized();
1029  ar & type & ctype & i & j & bsh_eps & fexist & cexist & f_size;
1030  if constexpr (Archive::is_input_archive) {
1031  if (fexist) {
1033  ar & func;
1035  functions.push_back(f1);
1036  }
1037  } else {
1038  if (fexist) ar & functions[0].get_function();
1039  }
1040  if (cexist) ar & constant_part;
1041  }
1042 
1043  bool load_pair(World& world) {
1044  std::string name = "pair_" + stringify(i) + stringify(j);
1046  if (exists) {
1047  if (world.rank() == 0) printf("loading matrix elements %s\n", name.c_str());
1049  ar & *this;
1050  //if (world.rank() == 0) printf(" %s\n", (converged) ? " converged" : " not converged");
1051  if (functions[0].get_function().is_initialized()) functions[0].get_function().set_thresh(FunctionDefaults<6>::get_thresh());
1053  } else {
1054  if (world.rank() == 0) print("could not find pair ", i, j, " on disk");
1055  }
1056  return exists;
1057  }
1058 
1059  void store_pair(World& world) {
1060  std::string name = "pair_" + stringify(i) + stringify(j);
1061  if (world.rank() == 0) printf("storing matrix elements %s\n", name.c_str());
1063  ar & *this;
1064  }
1065 
1066  hashT hash() const {
1067  hashT hash_i = std::hash<std::size_t>{}(i);
1068  hash_combine(hash_i, std::hash<std::size_t>{}(j));
1069  if (constant_part.is_initialized()) {
1070  hash_combine(hash_i, hash_value(constant_part.get_impl()->id()));
1071  }
1072  return hash_i;
1073  }
1074 
1075  /// the functions which belong to the pair
1076  std::vector<CCPairFunction<double,6>> functions;
1077 
1078  /// the constant part
1080 
1081  /// Energy for the BSH Operator
1082  /// Ground State: e_i + e_j
1083  /// Excited State: e_i + e_j + omega
1084  double bsh_eps;
1085 
1086  std::string name() const {
1087  std::string name = "???";
1088  if (type == GROUND_STATE) name = assign_name(ctype) + "_pair_u_";
1089  if (type == EXCITED_STATE) name = assign_name(ctype) + "_pair_x_";
1090  return name + stringify(i) + stringify(j);
1091  }
1092 
1093  void
1094  info() const;
1095 
1096 };
1097 
1098 /// little helper structure which manages the stored singles potentials
1102 
1105 
1106  /// fetches the correct stored potential or throws an exception
1108  operator()(const CC_vecfunction& f, const PotentialType& type) const;
1109 
1110  /// fetch the potential for a single function
1112  operator()(const CCFunction<double,3>& f, const PotentialType& type) const;
1113 
1114  /// deltes all stored potentials
1115  void clear_all() {
1118  current_s2b_potential_gs_.clear();
1119  current_s2b_potential_ex_.clear();
1120  current_s2c_potential_gs_.clear();
1121  current_s2c_potential_ex_.clear();
1122  }
1123 
1124  /// clears only potentials of the response
1127  current_s2b_potential_ex_.clear();
1128  current_s2c_potential_ex_.clear();
1129  }
1130 
1131  /// insert potential
1132  void
1134 
1136  Recordlist<Cloud::keyT> records;
1137  records+=cloud.store(world,parameters);
1138  records+=cloud.store(world,current_s2b_potential_ex_);
1139  records+=cloud.store(world,current_s2b_potential_gs_);
1140  records+=cloud.store(world,current_s2c_potential_ex_);
1141  records+=cloud.store(world,current_s2c_potential_gs_);
1142  records+=cloud.store(world,current_singles_potential_ex_);
1143  records+=cloud.store(world,current_singles_potential_gs_);
1144  records+=cloud.store(world,unprojected_cc2_projector_response_);
1145  return records;
1146  }
1147 
1148  void cloud_load(World& world, const Cloud& cloud, Recordlist<Cloud::keyT>& recordlist) {
1149  parameters=cloud.forward_load<CCParameters>(world,recordlist);
1157  }
1158 
1160  auto hash_vector_of_functions =[](const vector_real_function_3d& v) {
1161  hashT h;
1162  for (const auto& f : v) {
1163  hash_combine(h, hash_value(f.get_impl()->id()));
1164  }
1165  return h;
1166  };
1167  hashT h;
1168  hash_combine(h, hash_vector_of_functions(ip.current_s2b_potential_ex_));
1169  hash_combine(h, hash_vector_of_functions(ip.current_s2b_potential_gs_));
1170  hash_combine(h, hash_vector_of_functions(ip.current_s2c_potential_ex_));
1171  hash_combine(h, hash_vector_of_functions(ip.current_s2c_potential_gs_));
1172  hash_combine(h, hash_vector_of_functions(ip.current_singles_potential_ex_));
1173  hash_combine(h, hash_vector_of_functions(ip.current_singles_potential_gs_));
1174  hash_combine(h, hash_vector_of_functions(ip.unprojected_cc2_projector_response_));
1175  return h;
1176  }
1177 
1179 private:
1180  // World& world;
1181  /// whole ground state singles potential without fock-residue
1183  /// whole excited state singles potential without fock-residue
1185  /// s2b_potential for the pure 6D-part of the ground-state (expensive and constant during singles iterations)
1187  /// s2b_potential for the pure 6D-part of the excited-state (expensive and constant during singles iterations)
1189  /// s2c_potential for the pure 6D-part of the ground-state (expensive and constant during singles iterations)
1191  /// s2c_potential for the pure 6D-part of the excited_state (expensive and constant during singles iterations)
1193  /// unprojected S3c + S5c + S2b + S2c potential of CC2 singles
1194  /// for the projector response of the CC2 singles potential
1196 
1197  /// structured output
1198  void output(const std::string& msg) const {
1199  if (parameters.debug())
1200  std::cout << "Intermediate Potential Manager: " << msg << "\n";
1201  }
1202 };
1203 
1204 /// POD holding some basic functions and some intermediates for the CC2 calculation
1205 
1206 /// the class is cloud-serializable and can be used in MacroTasks
1207 struct Info {
1208  std::vector<Function<double,3>> mo_ket;
1209  std::vector<Function<double,3>> mo_bra;
1210  std::vector<madness::Vector<double,3>> molecular_coordinates;
1212  std::vector<double> orbital_energies;
1216  std::vector<Function<double,3>> U1;
1217 
1219  vector_real_function_3d result;
1220  for (size_t i = parameters.freeze(); i < mo_ket.size(); i++) result.push_back(mo_ket[i]);
1221  return result;
1222  }
1223 
1225  vector_real_function_3d result;
1226  for (size_t i = parameters.freeze(); i < mo_bra.size(); i++) result.push_back(mo_bra[i]);
1227  return result;
1228  }
1229 
1230  /// customized function to store this to the cloud
1231 
1232  /// functions and constant_part can be very large and we want to split them and store them in different records
1234  Recordlist<Cloud::keyT> records;
1235  records+=cloud.store(world,mo_bra);
1236  records+=cloud.store(world,mo_ket);
1237  records+=cloud.store(world,parameters);
1238  records+=cloud.store(world,orbital_energies);
1239  records+=cloud.store(world,fock);
1240  records+=cloud.store(world,intermediate_potentials);
1241  records+=cloud.store(world,R_square);
1242  records+=cloud.store(world,molecular_coordinates);
1243  records+=cloud.store(world,U2);
1244  records+=cloud.store(world,U1);
1245  return records;
1246  }
1247 
1248  /// customized function to load this from the cloud
1249 
1250  /// functions and constant_part can be very large and we want to split them and store them in different records
1251  /// @param[inout] recordlist: containing the keys of the member variables -> will be reduced by the keys which are used
1252  void cloud_load(World& world, const Cloud& cloud, Recordlist<Cloud::keyT>& recordlist) {
1253  // load bookkeeping stuff in a vector
1254  mo_bra=cloud.forward_load<std::vector<Function<double,3>>>(world,recordlist);
1255  mo_ket=cloud.forward_load<std::vector<Function<double,3>>>(world,recordlist);
1256  parameters=cloud.forward_load<CCParameters>(world,recordlist);
1257  orbital_energies=cloud.forward_load<std::vector<double>>(world,recordlist);
1258  fock=cloud.forward_load<Tensor<double>>(world,recordlist);
1260  R_square=cloud.forward_load<Function<double,3>>(world,recordlist);
1261  molecular_coordinates=cloud.forward_load<std::vector<madness::Vector<double,3>>>(world,recordlist);
1262  U2=cloud.forward_load<Function<double,3>>(world,recordlist);
1263  U1=cloud.forward_load<std::vector<Function<double,3>>>(world,recordlist);
1264  }
1265 
1266 };
1267 
1269 
1271  public:
1273 
1274  partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1275  const std::string policy) const override {
1276  partitionT p;
1277  for (size_t i = 0; i < vsize1; i++) {
1278  Batch batch(Batch_1D(i,i+1), Batch_1D(i,i+1));
1279  p.push_back(std::make_pair(batch,1.0));
1280  }
1281  return p;
1282  }
1283  };
1284 
1285 public:
1287 
1288  // typedef std::tuple<const std::vector<CCPair>&, const std::vector<Function<double,3>>&,
1289  // const std::vector<Function<double,3>>&, const CCParameters&, const Function<double,3>&,
1290  // const std::vector<Function<double,3>>&, const std::vector<std::string>& > argtupleT;
1291  typedef std::tuple<const std::vector<CCPair>&, const madness::Info&, const std::vector<std::string>& > argtupleT;
1292 
1293  using resultT = std::vector<real_function_6d>;
1294 
1295  resultT allocator(World& world, const argtupleT& argtuple) const {
1296  std::size_t n = std::get<0>(argtuple).size();
1297  resultT result = zero_functions_compressed<double, 6>(world, n);
1298  return result;
1299  }
1300 
1301 // resultT operator() (const std::vector<CCPair>& pair, const std::vector<Function<double,3>>& mo_ket,
1302 // const std::vector<Function<double,3>>& mo_bra, const CCParameters& parameters,
1303 // const Function<double,3>& Rsquare, const std::vector<Function<double,3>>& U1,
1304 // const std::vector<std::string>& argument) const;
1305  resultT operator() (const std::vector<CCPair>& pair, const Info& info, const std::vector<std::string>& argument) const;
1306 };
1307 
1308 /// compute the "constant" part of MP2, CC2, or LR-CC2
1309 ///
1310 /// the constant part is
1311 /// result = G [F,f] |ij> for MP2
1312 /// result = G [F,f] |t_i t_j> for CC2
1313 /// result = G [F,f] |t_i x_j> + |x_i t_j> for LR-CC2
1315 
1317  public:
1319 
1320  partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1321  const std::string policy) const override {
1322  partitionT p;
1323  for (size_t i = 0; i < vsize1; i++) {
1324  Batch batch(Batch_1D(i,i+1), Batch_1D(i,i+1));
1325  p.push_back(std::make_pair(batch,1.0));
1326  }
1327  return p;
1328  }
1329  };
1330 
1331 public:
1333  partitioner.reset(new ConstantPartPartitioner());
1334  name="ConstantPart";
1335  }
1336 
1337  // typedef std::tuple<const std::vector<CCPair>&, const std::vector<Function<double,3>>&,
1338  // const std::vector<Function<double,3>>&, const CCParameters&, const Function<double,3>&,
1339  // const std::vector<Function<double,3>>&, const std::vector<std::string>& > argtupleT;
1340  typedef std::tuple<const std::vector<CCPair>&,
1341  const std::vector<Function<double,3>>&, const std::vector<Function<double,3>>&,
1343 
1344  using resultT = std::vector<real_function_6d>;
1345 
1346  resultT allocator(World& world, const argtupleT& argtuple) const {
1347  std::size_t n = std::get<0>(argtuple).size();
1348  resultT result = zero_functions_compressed<double, 6>(world, n);
1349  return result;
1350  }
1351  resultT operator() (const std::vector<CCPair>& pair,
1352  const std::vector<Function<double,3>>& gs_singles,
1353  const std::vector<Function<double,3>>& ex_singles,
1354  const Info& info) const;
1355 };
1356 
1358 
1360  public :
1362  set_dimension(2);
1363  }
1364 
1365  partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1366  const std::string policy) const override {
1367  partitionT p;
1368  for (size_t i = 0; i < vsize1; i++) {
1369  Batch batch(Batch_1D(i, i+1), Batch_1D(i, i+1), Batch_1D(i,i+1));
1370  p.push_back(std::make_pair(batch, 1.0));
1371  }
1372  return p;
1373  }
1374  };
1375 public:
1377  partitioner.reset(new UpdatePairPartitioner());
1378  name="MP2UpdatePair";
1379  }
1380 
1381  // typedef std::tuple<const std::vector<CCPair>&, const std::vector<real_function_6d>&, const CCParameters&,
1382  // const std::vector< madness::Vector<double,3> >&,
1383  // const std::vector<Function<double,3>>&, const std::vector<Function<double,3>>&,
1384  // const std::vector<Function<double,3>>&, const Function<double,3>&> argtupleT;
1385  typedef std::tuple<const std::vector<CCPair>&, const std::vector<real_function_6d>&,
1386  const std::vector<madness::Vector<double,3>>&, const Info& > argtupleT;
1387 
1388  using resultT = std::vector<real_function_6d>;
1389 
1390  resultT allocator(World& world, const argtupleT& argtuple) const {
1391  std::size_t n = std::get<0>(argtuple).size();
1392  resultT result = zero_functions_compressed<double, 6>(world, n);
1393  return result;
1394  }
1395 
1396 // resultT operator() (const std::vector<CCPair>& pair, const std::vector<real_function_6d>& mp2_coupling, const CCParameters& parameters,
1397 // const std::vector< madness::Vector<double,3> >& all_coords_vec,
1398 // const std::vector<Function<double,3>>& mo_ket, const std::vector<Function<double,3>>& mo_bra,
1399 // const std::vector<Function<double,3>>& U1, const Function<double,3>& U2) const;
1400  resultT operator() (const std::vector<CCPair>& pair, const std::vector<real_function_6d>& mp2_coupling,
1401  const std::vector< madness::Vector<double,3> >& all_coords_vec, const Info& info) const;
1402 };
1403 
1404 
1406 
1408  public :
1410 
1411  partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1412  const std::string policy) const override {
1413  partitionT p;
1414  for (size_t i = 0; i < vsize1; i++) {
1415  Batch batch(Batch_1D(i, i+1), Batch_1D(i, i+1), Batch_1D(i,i+1));
1416  p.push_back(std::make_pair(batch,1.0));
1417  }
1418  return p;
1419  }
1420  };
1421 public:
1423  partitioner.reset(new IteratePairPartitioner());
1424  name="IteratePair";
1425  }
1426 
1427  typedef std::tuple<
1428  const std::vector<CCPair>&, // pair
1429  const std::vector<real_function_6d>&, // local coupling
1430  const CC_vecfunction&, // gs singles
1431  const CC_vecfunction&, // ex singles
1432  const Info&,
1433  const std::size_t&
1435 
1436  using resultT = std::vector<real_function_6d>;
1437 
1438  resultT allocator(World& world, const argtupleT& argtuple) const {
1439  std::size_t n = std::get<0>(argtuple).size();
1440  resultT result = zero_functions_compressed<double, 6>(world, n);
1441  return result;
1442  }
1443 
1444  /// iterate a given pair of the MP2, CC2 or LRCC2 calculation
1445 
1446  /// will *NOT* compute the local coupling,
1447  /// will apply the Fock operators (J-K+V)|pair> and use
1448  /// the (excited) singles vectors to update the pair
1449  /// @param[in] pair: the pair which will be updated
1450  /// @param[in] gs_singles: the ground state singles, may be dummy for MP2
1451  /// @param[in] ex_singles: the excited state singles, may be dummy for MP2, CC2
1452  /// @param[in] all_coords_vec: the coordinates of the atoms
1453  /// @param[in] info: the info structure
1454  /// @param[in] maxiter: the maximal number of iterations
1455  resultT operator() (const std::vector<CCPair>& pair,
1456  const std::vector<real_function_6d>& local_coupling,
1457  const CC_vecfunction& gs_singles,
1458  const CC_vecfunction& ex_singles,
1459  const Info& info,
1460  const std::size_t& maxiter) const;
1461 };
1462 
1463 }//namespace madness
1464 
1465 #endif /* CCSTRUCTURES_H_ */
double potential(const coord_3d &r)
Definition: 3dharmonic.cc:132
Definition: macrotaskpartitioner.h:63
a batch consists of a 2D-input batch and a 1D-output batch: K-batch <- (I-batch, J-batch)
Definition: macrotaskpartitioner.h:132
Definition: CCStructures.h:743
intermediateT< T, NDIM > imH
Definition: CCStructures.h:934
std::shared_ptr< SeparatedConvolution< T, NDIM > > get_op() const
Definition: CCStructures.h:922
std::vector< Function< T, NDIM > > operator()(const std::vector< Function< T, NDIM >> &f) const
Definition: CCStructures.h:841
CCConvolutionOperator(const CCConvolutionOperator &other)=default
friend hashT hash_value(CCConvolutionOperator< T, NDIM > &op)
Definition: CCStructures.h:882
std::vector< Function< T, NDIM > > operator()(const CC_vecfunction &bra, const CCFunction< T, NDIM > &ket) const
Definition: CCStructures.h:817
SeparatedConvolution< T, NDIM > * init_op(const OpType &type, const Parameters &parameters) const
Definition: CCStructures.cc:374
TwoElectronFactory< T, 2 *NDIM > get_kernel() const
create a TwoElectronFactory with the operatorkernel
Definition: CCStructures.h:912
Function< T, NDIM > operator()(const Function< T, NDIM > &f) const
Definition: CCStructures.h:809
size_t info() const
prints out information (operatorname, number of stored intermediates ...)
Definition: CCStructures.cc:356
std::shared_ptr< SeparatedConvolution< T, NDIM > > op
Definition: CCStructures.h:933
OpType type() const
Definition: CCStructures.h:918
void clear_intermediates(const FuncType &type)
Definition: CCStructures.cc:334
World & world
the world
Definition: CCStructures.h:922
void sanity() const
sanity check .. doens not do so much
Definition: CCStructures.h:893
std::string name() const
Definition: CCStructures.h:869
void update_elements(const CC_vecfunction &bra, const CC_vecfunction &ket)
Definition: CCStructures.cc:302
intermediateT< T, NDIM > imP
Definition: CCStructures.h:935
void error(const std::string &msg) const
Definition: CCStructures.h:940
const Parameters parameters
Definition: CCStructures.h:920
CCConvolutionOperator(World &world, const OpType type, Parameters param)
Definition: CCStructures.h:775
friend std::shared_ptr< CCConvolutionOperator > combine(const std::shared_ptr< CCConvolutionOperator > &a, const std::shared_ptr< CCConvolutionOperator > &b)
Definition: CCStructures.h:798
static std::shared_ptr< CCConvolutionOperator > CCConvolutionOperatorPtr(World &world, const OpType type, Parameters param)
Definition: CCStructures.h:782
void print_intermediate(const FuncType type) const
Definition: CCStructures.h:896
intermediateT< T, NDIM > imR
Definition: CCStructures.h:936
friend CCConvolutionOperator combine(const CCConvolutionOperator &a, const CCConvolutionOperator &b)
Definition: CCStructures.h:788
structure for a CC Function 3D which holds an index and a type
Definition: ccpairfunction.h:45
Function< T, NDIM > function
Definition: ccpairfunction.h:70
size_t i
Definition: ccpairfunction.h:78
a 6D function, either in full or low rank form, possibly including an 2-particle function
Definition: ccpairfunction.h:373
Definition: CCStructures.h:956
CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c, const std::vector< CCPairFunction< double, 6 >> &f)
Definition: CCStructures.h:963
hashT hash() const
Definition: CCStructures.h:1066
void info() const
Definition: CCStructures.cc:84
void store_pair(World &world)
Definition: CCStructures.h:1059
CCPair(const CCPair &other)
Definition: CCStructures.h:966
std::string name() const
Definition: CCStructures.h:1086
size_t i
Definition: CCStructures.h:972
CCPair()
Definition: CCStructures.h:958
real_function_6d constant_part
the constant part
Definition: CCStructures.h:1079
std::vector< CCPairFunction< double, 6 > > functions
the functions which belong to the pair
Definition: CCStructures.h:1076
CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c)
Definition: CCStructures.h:960
void update_u(const real_function_6d &u)
updates the pure 6D part of the pair function
Definition: CCStructures.h:1017
size_t j
Definition: CCStructures.h:973
CCState type
Definition: CCStructures.h:968
bool load_pair(World &world)
Definition: CCStructures.h:1043
double bsh_eps
Definition: CCStructures.h:1084
void serialize(const Archive &ar)
Definition: CCStructures.h:1025
Recordlist< Cloud::keyT > cloud_store(World &world, Cloud &cloud) const
customized function to store this to the cloud
Definition: CCStructures.h:978
CalcType ctype
Definition: CCStructures.h:971
void cloud_load(World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
customized function to load this from the cloud
Definition: CCStructures.h:996
cloud class
Definition: cloud.h:147
recordlistT store(madness::World &world, const T &source)
Definition: cloud.h:302
T forward_load(madness::World &world, recordlistT &recordlist) const
load a single object from the cloud, recordlist is consumed while loading elements
Definition: cloud.h:284
FunctionDefaults holds default paramaters as static class members.
Definition: funcdefaults.h:204
static const double & get_thresh()
Returns the default threshold.
Definition: funcdefaults.h:279
A multiresolution adaptive numerical function.
Definition: mra.h:122
void set_thresh(double value, bool fence=true)
Sets the value of the truncation threshold. Optional global fence.
Definition: mra.h:577
void clear(bool fence=true)
Clears the function as if constructed uninitialized. Optional fence.
Definition: mra.h:847
const std::shared_ptr< FunctionImpl< T, NDIM > > & get_impl() const
Returns a shared-pointer to the implementation.
Definition: mra.h:614
bool is_initialized() const
Returns true if the function is initialized.
Definition: mra.h:147
partitionT do_partitioning(const std::size_t &vsize1, const std::size_t &vsize2, const std::string policy) const override
override this if you want your own partitioning
Definition: CCStructures.h:1320
ConstantPartPartitioner()
Definition: CCStructures.h:1318
Definition: CCStructures.h:1314
std::vector< real_function_6d > resultT
Definition: CCStructures.h:1344
resultT operator()(const std::vector< CCPair > &pair, const std::vector< Function< double, 3 >> &gs_singles, const std::vector< Function< double, 3 >> &ex_singles, const Info &info) const
Definition: CCStructures.cc:527
MacroTaskConstantPart()
Definition: CCStructures.h:1332
std::tuple< const std::vector< CCPair > &, const std::vector< Function< double, 3 > > &, const std::vector< Function< double, 3 > > &, const madness::Info & > argtupleT
Definition: CCStructures.h:1342
resultT allocator(World &world, const argtupleT &argtuple) const
Definition: CCStructures.h:1346
partitionT do_partitioning(const std::size_t &vsize1, const std::size_t &vsize2, const std::string policy) const override
override this if you want your own partitioning
Definition: CCStructures.h:1411
Definition: CCStructures.h:1405
std::tuple< const std::vector< CCPair > &, const std::vector< real_function_6d > &, const CC_vecfunction &, const CC_vecfunction &, const Info &, const std::size_t & > argtupleT
Definition: CCStructures.h:1434
resultT operator()(const std::vector< CCPair > &pair, const std::vector< real_function_6d > &local_coupling, const CC_vecfunction &gs_singles, const CC_vecfunction &ex_singles, const Info &info, const std::size_t &maxiter) const
iterate a given pair of the MP2, CC2 or LRCC2 calculation
Definition: CCStructures.cc:569
MacroTaskIteratePair()
Definition: CCStructures.h:1422
resultT allocator(World &world, const argtupleT &argtuple) const
Definition: CCStructures.h:1438
std::vector< real_function_6d > resultT
Definition: CCStructures.h:1436
ConstantPartPartitioner()
Definition: CCStructures.h:1272
partitionT do_partitioning(const std::size_t &vsize1, const std::size_t &vsize2, const std::string policy) const override
override this if you want your own partitioning
Definition: CCStructures.h:1274
Definition: CCStructures.h:1268
resultT operator()(const std::vector< CCPair > &pair, const Info &info, const std::vector< std::string > &argument) const
Definition: CCStructures.cc:515
MacroTaskMp2ConstantPart()
Definition: CCStructures.h:1286
std::tuple< const std::vector< CCPair > &, const madness::Info &, const std::vector< std::string > & > argtupleT
Definition: CCStructures.h:1291
std::vector< real_function_6d > resultT
Definition: CCStructures.h:1293
resultT allocator(World &world, const argtupleT &argtuple) const
Definition: CCStructures.h:1295
UpdatePairPartitioner()
Definition: CCStructures.h:1361
partitionT do_partitioning(const std::size_t &vsize1, const std::size_t &vsize2, const std::string policy) const override
override this if you want your own partitioning
Definition: CCStructures.h:1365
Definition: CCStructures.h:1357
MacroTaskMp2UpdatePair()
Definition: CCStructures.h:1376
resultT allocator(World &world, const argtupleT &argtuple) const
Definition: CCStructures.h:1390
std::vector< real_function_6d > resultT
Definition: CCStructures.h:1388
std::tuple< const std::vector< CCPair > &, const std::vector< real_function_6d > &, const std::vector< madness::Vector< double, 3 > > &, const Info & > argtupleT
Definition: CCStructures.h:1386
resultT operator()(const std::vector< CCPair > &pair, const std::vector< real_function_6d > &mp2_coupling, const std::vector< madness::Vector< double, 3 > > &all_coords_vec, const Info &info) const
Definition: CCStructures.cc:553
Definition: macrotaskq.h:716
Batch batch
Definition: macrotaskq.h:718
std::shared_ptr< MacroTaskPartitioner > partitioner
Definition: macrotaskq.h:720
std::string name
Definition: macrotaskq.h:719
partition one (two) vectors into 1D (2D) batches.
Definition: macrotaskpartitioner.h:190
std::string policy
how to partition the batches
Definition: macrotaskpartitioner.h:198
MacroTaskPartitioner & set_dimension(const std::size_t &n)
Definition: macrotaskpartitioner.h:213
std::list< std::pair< Batch, double > > partitionT
Definition: macrotaskpartitioner.h:194
class for holding the parameters for calculation
Definition: QCCalculationParametersBase.h:290
virtual void read_input_and_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
Definition: QCCalculationParametersBase.h:325
static OperatorInfo combine_OT(const SeparatedConvolution< Q, NDIM > &left, const SeparatedConvolution< Q, NDIM > &right)
return operator type and other info of the combined operator (e.g. fg = f(1,2)* g(1,...
Definition: operator.h:1653
factory for generating TwoElectronInterfaces
Definition: function_factory.h:436
A parallel world class.
Definition: world.h:132
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition: world.h:318
static std::enable_if_t< std::is_same< X, BinaryFstreamInputArchive >::value||std::is_same< X, BinaryFstreamOutputArchive >::value, bool > exists(World &world, const char *filename)
Returns true if the named, unopened archive exists on disk with read access.
Definition: parallel_archive.h:224
An archive for storing local or parallel data, wrapping a BinaryFstreamInputArchive.
Definition: parallel_archive.h:366
An archive for storing local or parallel data wrapping a BinaryFstreamOutputArchive.
Definition: parallel_archive.h:321
Objects that implement their own parallel archive interface should derive from this class.
Definition: parallel_archive.h:58
Wraps an archive around an STL vector for input.
Definition: vector_archive.h:101
Wraps an archive around an STL vector for output.
Definition: vector_archive.h:55
double(* f1)(const coord_3d &)
Definition: derivatives.cc:55
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition: derivatives.cc:72
static bool debug
Definition: dirac-hatom.cc:16
auto T(World &world, response_space &f) -> response_space
Definition: global_functions.cc:34
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only)
Definition: tensor.h:2502
const int maxiter
Definition: gygi_soltion.cc:68
static const double v
Definition: hatom_sf_dirac.cc:20
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
Declares the macrotaskq and MacroTaskBase classes.
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition: madness_exception.h:190
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition: madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition: madness_exception.h:134
Main include file for MADNESS and defines Function interface.
double norm(const T &t)
Definition: adquad.h:42
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
static const char * filename
Definition: legendre.cc:96
CalcType
Calculation Types used by CC2.
Definition: CCStructures.h:27
@ CT_CC2
Definition: CCStructures.h:28
@ CT_LRCC2
Definition: CCStructures.h:28
@ CT_MP3
Definition: CCStructures.h:28
@ CT_UNDEFINED
Definition: CCStructures.h:28
@ CT_LRCCS
Definition: CCStructures.h:28
@ CT_CISPD
Definition: CCStructures.h:28
@ CT_TEST
Definition: CCStructures.h:28
@ CT_MP2
Definition: CCStructures.h:28
@ CT_ADC2
Definition: CCStructures.h:28
@ CT_TDHF
Definition: CCStructures.h:28
static std::string stringify(T arg)
Definition: funcplot.h:1034
static double cpu_time()
Returns the cpu time in seconds relative to an arbitrary origin.
Definition: timers.h:127
Function< TENSOR_RESULT_TYPE(Q, T), NDIM > mul(const Q alpha, const Function< T, NDIM > &f, bool fence=true)
Returns new function equal to alpha*f(x) with optional fence.
Definition: mra.h:1701
std::shared_ptr< CCConvolutionOperator< T, NDIM > > CCConvolutionOperatorPtr(World &world, const OpType type, typename CCConvolutionOperator< T, NDIM >::Parameters param)
Definition: CCStructures.h:950
response_space apply(World &world, std::vector< std::vector< std::shared_ptr< real_convolution_3d >>> &op, response_space &f)
Definition: basic_operators.cc:39
void truncate(World &world, response_space &v, double tol, bool fence)
Definition: basic_operators.cc:30
CCState
Type of Pairs used by CC_Pair2 class.
Definition: CCStructures.h:31
@ CCSTATE_UNDEFINED
Definition: CCStructures.h:32
@ GROUND_STATE
Definition: CCStructures.h:32
@ EXCITED_STATE
Definition: CCStructures.h:32
FuncType
Definition: ccpairfunction.h:26
@ RESPONSE
Definition: ccpairfunction.h:26
@ HOLE
Definition: ccpairfunction.h:26
@ UNDEFINED
Definition: ccpairfunction.h:26
@ PARTICLE
Definition: ccpairfunction.h:26
CalcType assign_calctype(const std::string name)
Assigns enum to string.
Definition: CCStructures.cc:400
void hash_combine(hashT &seed, const T &v)
Combine hash values.
Definition: worldhash.h:260
double size_of(const intermediateT< T, NDIM > &im)
Returns the size of an intermediate.
Definition: CCStructures.h:497
std::vector< real_function_3d > vector_real_function_3d
Definition: functypedefs.h:79
OpType
operator types
Definition: operatorinfo.h:11
std::shared_ptr< FunctionFunctorInterface< double, 3 > > func(new opT(g))
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition: print.h:225
NDIM & f
Definition: mra.h:2416
std::size_t hashT
The hash value type.
Definition: worldhash.h:145
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition: timers.cc:48
std::string type(const PairType &n)
Definition: PNOParameters.h:18
PotentialType
CC2 Singles Potentials.
Definition: CCStructures.h:35
@ POT_singles_
Definition: CCStructures.h:52
@ POT_s2b_
Definition: CCStructures.h:44
@ POT_F3D_
Definition: CCStructures.h:37
@ POT_s5b_
Definition: CCStructures.h:42
@ POT_s4c_
Definition: CCStructures.h:48
@ POT_s5c_
Definition: CCStructures.h:43
@ POT_s6_
Definition: CCStructures.h:49
@ POT_s4b_
Definition: CCStructures.h:47
@ POT_ccs_
Definition: CCStructures.h:50
@ POT_s3c_
Definition: CCStructures.h:40
@ POT_s4a_
Definition: CCStructures.h:46
@ POT_s5a_
Definition: CCStructures.h:41
@ POT_s3b_
Definition: CCStructures.h:39
@ POT_s2c_
Definition: CCStructures.h:45
@ POT_cis_
Definition: CCStructures.h:51
@ POT_UNDEFINED
Definition: CCStructures.h:36
@ POT_s3a_
Definition: CCStructures.h:38
std::string assign_name(const CCState &input)
Assigns strings to enums for formated output.
Definition: CCStructures.cc:383
std::string name(const FuncType &type, const int ex=-1)
Definition: ccpairfunction.h:28
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness hash.
Definition: array_addons.h:78
Vector< T, sizeof...(Ts)+1 > vec(T t, Ts... ts)
Factory function for creating a madness::Vector.
Definition: vector.h:711
Definition: mraimpl.h:50
static const double b
Definition: nonlinschro.cc:119
static const double a
Definition: nonlinschro.cc:118
static const double c
Definition: relops.cc:10
static const double thresh
Definition: rk.cc:45
parameter class
Definition: CCStructures.h:747
int freeze
Definition: CCStructures.h:762
Parameters()
Definition: CCStructures.h:748
void serialize(archiveT &ar)
f12 exponent
Definition: CCStructures.h:766
double lo
Definition: CCStructures.h:761
double gamma
Definition: CCStructures.h:763
Parameters(const CCParameters &param)
Definition: CCStructures.h:757
double thresh_op
Definition: CCStructures.h:760
Parameters(const Parameters &other)
Definition: CCStructures.h:750
little helper structure which manages the stored singles potentials
Definition: CCStructures.h:1099
Recordlist< Cloud::keyT > cloud_store(World &world, Cloud &cloud) const
Definition: CCStructures.h:1135
CCParameters parameters
Definition: CCStructures.h:1178
vector_real_function_3d current_s2c_potential_ex_
s2c_potential for the pure 6D-part of the excited_state (expensive and constant during singles iterat...
Definition: CCStructures.h:1192
vector_real_function_3d current_singles_potential_gs_
whole ground state singles potential without fock-residue
Definition: CCStructures.h:1182
vector_real_function_3d operator()(const CC_vecfunction &f, const PotentialType &type) const
fetches the correct stored potential or throws an exception
Definition: CCStructures.cc:97
void clear_response()
clears only potentials of the response
Definition: CCStructures.h:1125
vector_real_function_3d current_s2c_potential_gs_
s2c_potential for the pure 6D-part of the ground-state (expensive and constant during singles iterati...
Definition: CCStructures.h:1190
vector_real_function_3d current_singles_potential_ex_
whole excited state singles potential without fock-residue
Definition: CCStructures.h:1184
void cloud_load(World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
Definition: CCStructures.h:1148
CCIntermediatePotentials(const CCIntermediatePotentials &other)=default
CCIntermediatePotentials(const CCParameters &p)
Definition: CCStructures.h:1101
vector_real_function_3d unprojected_cc2_projector_response_
Definition: CCStructures.h:1195
friend hashT hash_value(const CCIntermediatePotentials &ip)
Definition: CCStructures.h:1159
vector_real_function_3d current_s2b_potential_gs_
s2b_potential for the pure 6D-part of the ground-state (expensive and constant during singles iterati...
Definition: CCStructures.h:1186
vector_real_function_3d current_s2b_potential_ex_
s2b_potential for the pure 6D-part of the excited-state (expensive and constant during singles iterat...
Definition: CCStructures.h:1188
void insert(const vector_real_function_3d &potential, const CC_vecfunction &f, const PotentialType &type)
insert potential
Definition: CCStructures.cc:144
void clear_all()
deltes all stored potentials
Definition: CCStructures.h:1115
void output(const std::string &msg) const
structured output
Definition: CCStructures.h:1198
CCIntermediatePotentials & operator=(const CCIntermediatePotentials &other)=default
Definition: CCStructures.h:77
void print_warnings() const
Definition: CCStructures.h:103
void warning(const std::string &msg) const
Definition: CCStructures.cc:45
void debug_output(const std::string &msg) const
Definition: CCStructures.h:87
bool debug
Definition: CCStructures.h:83
void subsection(const std::string &msg) const
Definition: CCStructures.cc:34
CCMessenger operator<<(const T &t) const
Definition: CCStructures.h:108
World & world
Definition: CCStructures.h:80
bool scientific
Definition: CCStructures.h:82
std::vector< std::string > warnings
collect all warnings that occur to print out at the end of the job
Definition: CCStructures.h:115
std::ostream & os
output stream
Definition: CCStructures.h:117
void section(const std::string &msg) const
Definition: CCStructures.cc:23
void output(const std::string &msg) const
Definition: CCStructures.cc:14
CCMessenger(World &world)
Definition: CCStructures.h:78
size_t output_prec
Definition: CCStructures.h:81
void operator()(const std::string &msg) const
Definition: CCStructures.h:85
Definition: CCStructures.h:199
double thresh_Ue() const
Definition: CCStructures.h:303
double thresh_f12() const
Definition: CCStructures.h:301
std::size_t kain_subspace() const
Definition: CCStructures.h:353
double tight_thresh_6D() const
Definition: CCStructures.h:293
std::size_t iter_max_3D() const
Definition: CCStructures.h:315
bool no_compute_cispd() const
Definition: CCStructures.h:335
CCParameters(World &world, const commandlineparser &parser)
ctor reading out the input file
Definition: CCStructures.h:209
bool no_compute_mp2_constantpart() const
Definition: CCStructures.h:327
std::vector< std::size_t > excitations() const
Definition: CCStructures.h:357
bool kain() const
Definition: CCStructures.h:343
bool plot() const
Definition: CCStructures.h:341
bool no_compute_response() const
Definition: CCStructures.h:329
double thresh_poisson() const
Definition: CCStructures.h:299
CCParameters()
Definition: CCStructures.h:201
double thresh_bsh_3D() const
Definition: CCStructures.h:295
bool no_compute_mp2() const
Definition: CCStructures.h:331
double dconv_6D() const
Definition: CCStructures.h:311
double econv_pairs() const
Definition: CCStructures.h:307
void initialize_parameters()
Definition: CCStructures.h:216
bool response() const
Definition: CCStructures.h:282
bool decompose_Q() const
Definition: CCStructures.h:347
double thresh_bsh_6D() const
Definition: CCStructures.h:297
void error(World &world, const std::string &msg) const
Definition: CCStructures.h:367
CCParameters(const CCParameters &other)=default
copy constructor
double gamma() const
Definition: CCStructures.h:359
double thresh_3D() const
Definition: CCStructures.h:287
double tight_thresh_3D() const
Definition: CCStructures.h:289
bool no_compute() const
Definition: CCStructures.h:323
double dconv_3D() const
Definition: CCStructures.h:309
std::size_t iter_max() const
Definition: CCStructures.h:313
double lo() const
Definition: CCStructures.h:283
long freeze() const
Definition: CCStructures.h:355
double thresh_6D() const
Definition: CCStructures.h:291
bool no_compute_cc2() const
Definition: CCStructures.h:333
void set_derived_values()
Definition: CCStructures.cc:163
bool QtAnsatz() const
Definition: CCStructures.h:349
bool test() const
Definition: CCStructures.h:345
double dmin() const
Definition: CCStructures.h:285
std::size_t output_prec() const
Definition: CCStructures.h:351
bool restart() const
Definition: CCStructures.h:321
double econv() const
Definition: CCStructures.h:305
std::size_t iter_max_6D() const
Definition: CCStructures.h:317
CalcType calc_type() const
Definition: CCStructures.h:269
bool no_compute_gs() const
Definition: CCStructures.h:325
bool debug() const
Definition: CCStructures.h:339
void information(World &world) const
print out the parameters
Definition: CCStructures.cc:195
bool no_compute_lrcc2() const
Definition: CCStructures.h:337
std::pair< int, int > only_pair() const
Definition: CCStructures.h:319
size_t warning(World &world, const std::string &msg) const
Definition: CCStructures.h:374
void sanity_check(World &world) const
check if parameters are set correct
Definition: CCStructures.cc:206
Timer Structure.
Definition: CCStructures.h:122
CCTimer(World &world, std::string msg)
Definition: CCStructures.h:126
void print() const
Definition: CCStructures.h:184
std::pair< double, double > current_time(bool printout=false)
Definition: CCStructures.h:175
std::string operation
Definition: CCStructures.h:133
double start_cpu
Definition: CCStructures.h:132
double time_wall
Definition: CCStructures.h:136
double get_wall_time_diff() const
Definition: CCStructures.h:171
void update_time()
Definition: CCStructures.h:139
CCTimer stop()
Definition: CCStructures.h:155
CCTimer start()
Definition: CCStructures.h:149
void print()
Definition: CCStructures.h:180
double time_cpu
Definition: CCStructures.h:137
double start_wall
Definition: CCStructures.h:131
double get_cpu_time_diff() const
Definition: CCStructures.h:173
void print(const std::pair< double, double > &times) const
Definition: CCStructures.h:188
double reset()
Definition: CCStructures.h:163
void info(const bool debug=true, const double norm=12345.6789)
print out information about the passed time since the CC_TIMER object was created
Definition: CCStructures.cc:52
World & world
Definition: CCStructures.h:130
double end_wall
Definition: CCStructures.h:134
double end_cpu
Definition: CCStructures.h:135
A helper structure which holds a map of functions.
Definition: CCStructures.h:509
std::string irrep
Definition: CCStructures.h:649
CCFunction< double, 3 > & operator()(const CCFunction< double, 3 > &i)
getter
Definition: CCStructures.h:671
hashT hash() const
Definition: CCStructures.h:635
CC_vecfunction(const vector_real_function_3d &v, const FuncType &type, const size_t &freeze)
Definition: CCStructures.h:536
std::map< std::size_t, CCFunction< double, 3 > > CC_functionmap
Definition: CCStructures.h:642
CC_vecfunction(const CC_vecfunction &other)
copy ctor (shallow)
Definition: CCStructures.h:552
void insert(const size_t &i, const CCFunction< double, 3 > &f)
setter
Definition: CCStructures.h:681
CC_vecfunction(const vector_real_function_3d &v, const FuncType &type)
Definition: CCStructures.h:528
static CC_vecfunction load_restartdata(World &world, std::string filename)
Definition: CCStructures.h:597
CC_vecfunction operator*(const double &fac) const
scalar multiplication
Definition: CCStructures.h:711
double delta
Definition: CCStructures.h:648
const CCFunction< double, 3 > & operator()(const CCFunction< double, 3 > &i) const
getter
Definition: CCStructures.h:661
void print_size(const std::string &msg="!?not assigned!?") const
Print the memory of which is used by all the functions in the map.
Definition: CCStructures.cc:69
bool operator<(const CC_vecfunction &b) const
operator needed for sort operation (sorted by omega values)
Definition: CCStructures.h:725
CC_vecfunction(const FuncType type_)
Definition: CCStructures.h:513
void serialize(const Archive &ar)
Definition: CCStructures.h:610
CC_vecfunction(const vector_real_function_3d &v)
Definition: CCStructures.h:515
CC_vecfunction(const std::vector< CCFunction< double, 3 >> &v, const FuncType type_)
Definition: CCStructures.h:546
CC_vecfunction()
Definition: CCStructures.h:511
void set_functions(const vector_real_function_3d &v, const FuncType &type, const size_t &freeze)
setter
Definition: CCStructures.h:686
CC_vecfunction(const std::vector< CCFunction< double, 3 >> &v)
Definition: CCStructures.h:522
void scale(const double &factor)
scaling (inplace)
Definition: CCStructures.h:718
void plot(const std::string &msg="") const
Definition: CCStructures.h:728
CCFunction< double, 3 > & operator()(const size_t &i)
getter
Definition: CCStructures.h:676
FuncType type
Definition: CCStructures.h:645
double current_error
excitation energy
Definition: CCStructures.h:647
friend CC_vecfunction copy(const CC_vecfunction &other)
returns a deep copy (void shallow copy errors)
Definition: CCStructures.h:574
size_t size() const
Get the size vector (number of functions in the map)
Definition: CCStructures.h:702
double omega
Definition: CCStructures.h:646
bool is_converged(const double econv, const double dconv) const
Definition: CCStructures.h:656
vector_real_function_3d get_vecfunction() const
Returns all the functions of the map as vector.
Definition: CCStructures.h:695
CC_vecfunction & operator=(const CC_vecfunction &other)
assignment operator, shallow wrt the functions
Definition: CCStructures.h:560
void save_restartdata(World &world, std::string filename) const
Definition: CCStructures.h:604
CC_functionmap functions
Definition: CCStructures.h:643
std::string name(const int ex) const
excitation irrep (direct product of x function and corresponding orbital)
Definition: CCStructures.h:652
const CCFunction< double, 3 > & operator()(const size_t &i) const
getter
Definition: CCStructures.h:666
POD holding some basic functions and some intermediates for the CC2 calculation.
Definition: CCStructures.h:1207
std::vector< Function< double, 3 > > mo_ket
Definition: CCStructures.h:1208
Tensor< double > fock
Definition: CCStructures.h:1213
Function< double, 3 > R
Definition: CCStructures.h:1215
std::vector< Function< double, 3 > > U1
Definition: CCStructures.h:1215
CCIntermediatePotentials intermediate_potentials
Definition: CCStructures.h:1214
Function< double, 3 > U2
Definition: CCStructures.h:1215
std::vector< madness::Vector< double, 3 > > molecular_coordinates
Definition: CCStructures.h:1210
std::vector< double > orbital_energies
Definition: CCStructures.h:1212
std::vector< Function< double, 3 > > mo_bra
Definition: CCStructures.h:1209
CCParameters parameters
Definition: CCStructures.h:1211
Recordlist< Cloud::keyT > cloud_store(World &world, Cloud &cloud) const
customized function to store this to the cloud
Definition: CCStructures.h:1233
vector_real_function_3d get_active_mo_bra() const
Definition: CCStructures.h:1224
void cloud_load(World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
customized function to load this from the cloud
Definition: CCStructures.h:1252
Function< double, 3 > R_square
Definition: CCStructures.h:1215
vector_real_function_3d get_active_mo_ket() const
Definition: CCStructures.h:1218
Definition: CCStructures.h:381
static PairVectorMap triangular_map(const int nfreeze, const int nocc)
Definition: CCStructures.h:387
void print(const std::string msg="PairVectorMap") const
Definition: CCStructures.h:407
std::vector< std::pair< int, int > > map
maps pair index (i,j) to vector index k
Definition: CCStructures.h:383
PairVectorMap(const std::vector< std::pair< int, int >> map1)
Definition: CCStructures.h:385
static PairVectorMap quadratic_map(const int nfreeze, const int nocc)
Definition: CCStructures.h:397
Definition: CCStructures.h:421
void swap(Pairs< T > &other)
swap the contant of the pairmap
Definition: CCStructures.h:477
pairmapT allpairs
Definition: CCStructures.h:424
static Pairs vector2pairs(const std::vector< T > &argument, const PairVectorMap map)
Definition: CCStructures.h:440
const T & operator()(int i, int j) const
getter
Definition: CCStructures.h:457
static std::vector< T > pairs2vector(const Pairs< T > &argument, const PairVectorMap map)
Definition: CCStructures.h:448
std::map< std::pair< int, int >, T > pairmapT
Definition: CCStructures.h:423
bool empty() const
Definition: CCStructures.h:481
void insert(int i, int j, const T &pair)
Definition: CCStructures.h:471
T & operator()(int i, int j)
getter
Definition: CCStructures.h:464
Pairs< R > convert(const Pairs< T > arg, const opT op) const
convert Pairs<T> to another type
Definition: CCStructures.h:430
Definition: cloud.h:34
very simple command line parser
Definition: commandlineparser.h:15
Definition: lowrankfunction.h:332
InputParameters param
Definition: tdse.cc:203
double h(const coord_1d &r)
Definition: testgconv.cc:68
static const std::size_t NDIM
Definition: testpdiff.cc:42
double u(const double x, const double expnt)
Definition: testperiodic.cc:56