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>
21
22#include "lowrankfunction.h"
23
24namespace madness {
25
26/// Calculation Types used by CC2
30/// Type of Pairs used by CC_Pair2 class
34
35/// CC2 Singles Potentials
55
56/// Assigns strings to enums for formated output
57std::string
58assign_name(const CCState& input);
59
60/// Assigns enum to string
62assign_calctype(const std::string name);
63
64/// Assigns strings to enums for formated output
65std::string
67
68/// Assigns strings to enums for formated output
69std::string
71
72/// Assigns strings to enums for formated output
73std::string
75
76/// check memory usage using getrusage
77inline void print_memory_usage(const World& world) {
78 long mem=get_memory_usage();
79 std::string hostname=get_hostname();
80 std::stringstream ss;
81 ss << "memory usage of process "<< world.rank()<< " on "<< hostname<< ": "<< mem/1024/1024<<"MB";
82 std::string msg=ss.str();
83 auto memusage=world.gop.concat0(std::vector<std::string>(1,msg));
84 std::sort(memusage.begin(),memusage.end());
85 if (world.rank()==0) for (const auto& msg : memusage) print(msg);
86}
87
88// Little structure for formated output and to collect warnings
89// much room to improve
92
96 bool debug;
97
98 void operator()(const std::string& msg) const { output(msg); }
99
100 void debug_output(const std::string& msg) const {
101 if (debug) output(msg);
102 }
103
104 void
105 output(const std::string& msg) const;
106
107 void
108 section(const std::string& msg) const;
109
110 void
111 subsection(const std::string& msg) const;
112
113 void
114 warning(const std::string& msg) const;
115
116 void print_warnings() const {
117 for (const auto& x:warnings) if (world.rank() == 0) std::cout << x << "\n";
118 }
119
120 template<class T>
121 CCMessenger operator<<(const T& t) const {
122 using madness::operators::operator<<;
123 if (world.rank() == 0) os << t;
124 return *this;
125 }
126
127 /// collect all warnings that occur to print out at the end of the job
128 mutable std::vector<std::string> warnings;
129 /// output stream
130 std::ostream& os;
131};
132
133
134/// Timer Structure
135struct CCTimer {
136 /// TDA_TIMER constructor
137 /// @param[in] world the world
138 /// @param[in] msg a string that contains the desired printout when info function is called
140 operation(msg), end_wall(0.0), end_cpu(0.0), time_wall(-1.0),
141 time_cpu(-1.0) {}
142
145 double start_cpu;
146 std::string operation;
147 double end_wall;
148 double end_cpu;
149 double time_wall;
150 double time_cpu;
151
156
157public:
158 /// print out information about the passed time since the CC_TIMER object was created
159 void
160 info(const bool debug = true, const double norm = 12345.6789);
161
165 return *this;
166 }
167
170 end_cpu = cpu_time();
173 return *this;
174 }
175
176 double reset() {
177 stop();
178 double wtime=time_wall;
179 start();
180 return wtime;
181 }
182
183
184 double get_wall_time_diff() const { return end_wall; }
185
186 double get_cpu_time_diff() const { return end_cpu; }
187
188 std::pair<double, double> current_time(bool printout = false) {
189 if (time_wall < 0.0 or time_cpu < 0.0) stop();
190 return std::make_pair(time_wall, time_cpu);
191 }
192
193 void print() {
195 }
196
197 void print() const {
198 print(std::make_pair(time_wall, time_cpu));
199 }
200
201 void print(const std::pair<double, double>& times) const {
202 if (world.rank() == 0) {
203 std::cout << std::setfill(' ') << std::scientific << std::setprecision(2)
204 << "Timer: " << times.first << " (Wall), " << times.second << " (CPU)" << ", (" + operation + ")"
205 << "\n";
206 }
207 }
208};
209
210
211/// Calculation TDHFParameters for CC2 and TDA calculations
212/// Maybe merge this with calculation_parameters of SCF at some point, or split into TDA and CC
214
218
219 /// copy constructor
220 CCParameters(const CCParameters& other) =default;
221
222 /// ctor reading out the input file
223 CCParameters(World& world, const commandlineparser& parser) {
225 read_input_and_commandline_options(world,parser,"cc2");
227 };
228
229
231 double thresh=1.e-3;
232 double thresh_operators=1.e-6;
233 initialize < std::string > ("calc_type", "mp2", "the calculation type", {"mp2", "mp3", "cc2", "cis", "lrcc2", "cispd", "adc2", "test"});
234 initialize < double > ("lo", 1.e-7, "the finest length scale to be resolved by 6D operators");
235 initialize < double > ("dmin", 1.0, "defines the depth of the special level");
236 initialize < double > ("thresh_6d", thresh, "threshold for the 6D wave function");
237 initialize < double > ("tight_thresh_6d", 0.1*thresh, "tight threshold for the 6D wave function");
238 initialize < double > ("thresh_3d", 0.01*thresh, "threshold for the 3D reference wave function");
239 initialize < double > ("tight_thresh_3d", 0.001*thresh, "tight threshold for the 3D reference wave function");
240 initialize < double > ("thresh_bsh_3d", thresh_operators, "threshold for BSH operators");
241 initialize < double > ("thresh_bsh_6d", thresh_operators, "threshold for BSH operators");
242 initialize < double > ("thresh_poisson", thresh_operators, "threshold for Poisson operators");
243 initialize < double > ("thresh_f12", thresh_operators, "threshold for Poisson operators");
244 initialize < double > ("thresh_Ue", thresh_operators, "ue threshold");
245 initialize < double > ("econv", thresh, "overal convergence threshold ");
246 initialize < double > ("econv_pairs", 0.1*thresh, "convergence threshold for pairs");
247 initialize < double > ("dconv_3d", 0.3*thresh, "convergence for cc singles");
248 initialize < double > ("dconv_6d", 3.0*thresh, "convergence for cc doubles");
249 initialize < std::size_t > ("iter_max", 10, "max iterations");
250 initialize < std::size_t > ("iter_max_3d", 10, "max iterations for singles");
251 initialize < std::size_t > ("iter_max_6d", 10, "max iterations for doubles");
252 initialize < std::pair<int, int>> ("only_pair", {-1, -1}, "compute only a single pair");
253 initialize < bool > ("restart", false, "restart");
254 initialize < bool > ("no_compute", false, "no compute");
255 initialize < bool > ("no_compute_gs", false, "no compute");
256 initialize < bool > ("no_compute_mp2_constantpart", false, "no compute");
257 initialize < bool > ("no_compute_response", false, "no compute");
258 initialize < bool > ("no_compute_mp2", false, "no compute");
259 initialize < bool > ("no_compute_cc2", false, "no compute");
260 initialize < bool > ("no_compute_cispd", false, "no compute");
261 initialize < bool > ("no_compute_lrcc2", false, "no compute");
262 initialize < double > ("corrfac_gamma", 1.0, "exponent for the correlation factor");
263 initialize < std::size_t > ("output_prec", 8, "for formatted output");
264 initialize < bool > ("debug", false, "");
265 initialize < bool > ("plot", false, "");
266 initialize < bool > ("kain", true, "");
267 initialize < std::size_t > ("kain_subspace", 3, "");
268 initialize < long > ("freeze", -1, "number of frozen orbitals: -1: automatic");
269 initialize < bool > ("test", false, "");
270 // choose if Q for the constant part of MP2 and related calculations should be decomposed: GQV or GV - GO12V
271 initialize < bool > ("decompose_Q", true, "always true",{true});
272 // if true the ansatz for the CC2 ground state pairs is |tau_ij> = |u_ij> + Qtf12|titj>, with Qt = Q - |tau><phi|
273 // if false the ansatz is the same with normal Q projector
274 // the response ansatz is the corresponding response of the gs ansatz
275 initialize < bool > ("QtAnsatz", true, "always true",{true});
276 // a vector containing the excitations which shall be optizmized later (with CIS(D) or CC2)
278 ("excitations", {}, "vector containing the excitations");
279 }
280
281 void set_derived_values();
282
284 std::string value = get<std::string>("calc_type");
285 if (value == "mp2") return CT_MP2;
286 if (value == "mp3") return CT_MP3;
287 if (value == "cc2") return CT_CC2;
288 if (value == "cis") return CT_LRCCS;
289 if (value == "lrcc2") return CT_LRCC2;
290 if (value == "cispd") return CT_CISPD;
291 if (value == "adc2") return CT_ADC2;
292 if (value == "test") return CT_TEST;
293 MADNESS_EXCEPTION("faulty CalcType", 1);
294 }
295
297 double lo() const { return get<double>("lo"); }
298
299 double dmin() const { return get<double>("dmin"); }
300
301 double thresh_3D() const { return get<double>("thresh_3d"); }
302
303 double tight_thresh_3D() const { return get<double>("tight_thresh_3d"); }
304
305 double thresh_6D() const { return get<double>("thresh_6d"); }
306
307 double tight_thresh_6D() const { return get<double>("tight_thresh_6d"); }
308
309 double thresh_bsh_3D() const { return get<double>("thresh_bsh_3d"); }
310
311 double thresh_bsh_6D() const { return get<double>("thresh_bsh_6d"); }
312
313 double thresh_poisson() const { return get<double>("thresh_poisson"); }
314
315 double thresh_f12() const { return get<double>("thresh_f12"); }
316
317 double thresh_Ue() const { return get<double>("thresh_ue"); }
318
319 double econv() const { return get<double>("econv"); }
320
321 double econv_pairs() const { return get<double>("econv_pairs"); }
322
323 double dconv_3D() const { return get<double>("dconv_3d"); }
324
325 double dconv_6D() const { return get<double>("dconv_6d"); }
326
327 std::size_t iter_max() const { return get<std::size_t>("iter_max"); }
328
329 std::size_t iter_max_3D() const { return get<std::size_t>("iter_max_3d"); }
330
331 std::size_t iter_max_6D() const { return get<std::size_t>("iter_max_6d"); }
332
333 std::pair<int, int> only_pair() const { return get<std::pair<int, int>>("only_pair"); }
334
335 bool restart() const { return get<bool>("restart"); }
336
337 bool no_compute() const { return get<bool>("no_compute"); }
338
339 bool no_compute_gs() const { return get<bool>("no_compute_gs"); }
340
341 bool no_compute_mp2_constantpart() const { return get<bool>("no_compute_mp2_constantpart"); }
342
343 bool no_compute_response() const { return get<bool>("no_compute_response"); }
344
345 bool no_compute_mp2() const { return get<bool>("no_compute_mp2"); }
346
347 bool no_compute_cc2() const { return get<bool>("no_compute_cc2"); }
348
349 bool no_compute_cispd() const { return get<bool>("no_compute_cispd"); }
350
351 bool no_compute_lrcc2() const { return get<bool>("no_compute_lrcc2"); }
352
353 bool debug() const { return get<bool>("debug"); }
354
355 bool plot() const { return get<bool>("plot"); }
356
357 bool kain() const { return get<bool>("kain"); }
358
359 bool test() const { return get<bool>("test"); }
360
361 bool decompose_Q() const { return get<bool>("decompose_q"); }
362
363 bool QtAnsatz() const { return get<bool>("qtansatz"); }
364
365 std::size_t output_prec() const { return get<std::size_t>("output_prec"); }
366
367 std::size_t kain_subspace() const { return get<std::size_t>("kain_subspace"); }
368
369 long freeze() const { return get<long>("freeze"); }
370
371 std::vector<std::size_t> excitations() const { return get<std::vector<std::size_t>>("excitations"); }
372
373 double gamma() const {return get<double>("corrfac_gamma");}
374
375 /// print out the parameters
376 void information(World& world) const;
377
378 /// check if parameters are set correct
379 void sanity_check(World& world) const;
380
381 void error(World& world, const std::string& msg) const {
382 if (world.rank() == 0)
383 std::cout << "\n\n\n\n\n!!!!!!!!!\n\nERROR IN CC_PARAMETERS:\n ERROR MESSAGE IS: " << msg
384 << "\n\n\n!!!!!!!!" << std::endl;
385 MADNESS_EXCEPTION("ERROR IN CC_PARAMETERS", 1);
386 }
387
388 size_t warning(World& world, const std::string& msg) const {
389 if (world.rank() == 0) std::cout << "WARNING IN CC_PARAMETERS!: " << msg << std::endl;
390 return 1;
391 }
392
393};
394
396
397 std::vector<std::pair<int, int>> map; ///< maps pair index (i,j) to vector index k
398 PairVectorMap() = default;
399 PairVectorMap(const std::vector<std::pair<int, int>> map1) : map(map1) {}
400
401 static PairVectorMap triangular_map(const int nfreeze, const int nocc) {
402 std::vector<std::pair<int, int>> map; ///< maps pair index (i,j) to vector index k
403 for (int i=nfreeze; i<nocc; ++i) {
404 for (int j=i; j<nocc; ++j) {
405 map.push_back(std::make_pair(i,j));
406 }
407 }
408 return PairVectorMap(map);
409 }
410
411 static PairVectorMap quadratic_map(const int nfreeze, const int nocc) {
412 std::vector<std::pair<int, int>> map; ///< maps pair index (i,j) to vector index k
413 for (int i=nfreeze; i<nocc; ++i) {
414 for (int j=nfreeze; j<nocc; ++j) {
415 map.push_back(std::make_pair(i,j));
416 }
417 }
418 return PairVectorMap(map);
419 }
420
421 void print(const std::string msg="PairVectorMap") const {
422 madness::print(msg);
423 madness::print("vector element <-> pair index");
424 for (size_t i=0; i<map.size(); ++i) {
425 madness::print(i, " <-> ",map[i]);
426 }
427 }
428
429};
430
431/// POD holding all electron pairs with easy access
432/// Similar strucutre than the Pair structure from MP2 but with some additional features (merge at some point)
433/// This structure will also be used for intermediates
434template<typename T>
435struct Pairs {
436
437 typedef std::map<std::pair<int, int>, T> pairmapT;
439
440 /// convert Pairs<T> to another type
441
442 /// opT op takes an object of T and returns the result type
443 template<typename R, typename opT>
444 Pairs<R> convert(const Pairs<T> arg, const opT op) const {
445 Pairs<R> result;
446 for (auto& p : arg.allpairs) {
447 int i=p.first.first;
448 int j=p.first.second;
449 result.insert(i,j,op(p.second));
450 }
451 return result;
452 }
453
454 static Pairs vector2pairs(const std::vector<T>& argument, const PairVectorMap map) {
455 Pairs<T> pairs;
456 for (int i=0; i<argument.size(); ++i) {
457 pairs.insert(map.map[i].first,map.map[i].second,argument[i]);
458 }
459 return pairs;
460 }
461
462 static std::vector<T> pairs2vector(const Pairs<T>& argument, const PairVectorMap map) {
463 std::vector<T> vector;
464 for (size_t i=0; i<argument.allpairs.size(); ++i) {
465 vector.push_back(argument(map.map[i].first,map.map[i].second));
466 }
467 return vector;
468 }
469
470 /// getter
471 const T& operator()(int i, int j) const {
472 return allpairs.at(std::make_pair(i, j));
473 }
474
475 /// getter
476 // at instead of [] operator bc [] inserts new element if nothing is found while at throws out of range error
477 // back to before
478 T& operator()(int i, int j) {
479 // return allpairs.at(std::make_pair(i, j));
480 return allpairs[std::make_pair(i, j)];
481 }
482
483 /// setter
484 /// can NOT replace elements (for this construct new pair map and swap the content)
485 void insert(int i, int j, const T& pair) {
486 std::pair<int, int> key = std::make_pair(i, j);
487 allpairs.insert(std::make_pair(key, pair));
488 }
489
490 /// swap the contant of the pairmap
491 void swap(Pairs<T>& other) {
492 allpairs.swap(other.allpairs);
493 }
494
495 bool empty() const {
496 if (allpairs.size() == 0) return true;
497 else return false;
498 }
499};
500
501/// f12 and g12 intermediates of the form <f1|op|f2> (with op=f12 or op=g12) will be saved using the pair structure
502template <typename T, std::size_t NDIM>
504
505/// Returns the size of an intermediate
506//double
507//size_of(const intermediateT& im);
508/// Returns the size of an intermediate
509template<typename T, std::size_t NDIM>
510double
512 double size = 0.0;
513 for (const auto& tmp : im.allpairs) {
514 size += get_size<T, NDIM>(tmp.second);
515 }
516 return size;
517}
518
519
520
521// structure for CC Vectorfunction
522/// A helper structure which holds a map of functions
524
526
527 CC_vecfunction(const FuncType type_) : type(type_), omega(0.0), current_error(99.9), delta(0.0) {}
528
530 for (size_t i = 0; i < v.size(); i++) {
532 functions.insert(std::make_pair(i, tmp));
533 }
534 }
535
536 CC_vecfunction(const std::vector<CCFunction<double,3>>& v) : type(UNDEFINED), omega(0.0), current_error(99.9), delta(0.0) {
537 for (size_t i = 0; i < v.size(); i++) {
538 functions.insert(std::make_pair(v[i].i, v[i]));
539 }
540 }
541
543 current_error(99.9), delta(0.0) {
544 for (size_t i = 0; i < v.size(); i++) {
546 functions.insert(std::make_pair(i, tmp));
547 }
548 }
549
550 CC_vecfunction(const vector_real_function_3d& v, const FuncType& type, const size_t& freeze) : type(type),
551 omega(0.0),
552 current_error(99.9),
553 delta(0.0) {
554 for (size_t i = 0; i < v.size(); i++) {
555 CCFunction<double,3> tmp(v[i], freeze + i, type);
556 functions.insert(std::make_pair(freeze + i, tmp));
557 }
558 }
559
560 CC_vecfunction(const std::vector<CCFunction<double,3>>& v, const FuncType type_)
561 : type(type_), omega(0.0), current_error(99.9), delta(0.0) {
562 for (auto x:v) functions.insert(std::make_pair(x.i, x));
563 }
564
565 /// copy ctor (shallow)
567 : functions(other.functions), type(other.type), omega(other.omega),
569 delta(other.delta), irrep(other.irrep) {
570 }
571
572 /// assignment operator, shallow wrt the functions
573// CC_vecfunction& operator=(const CC_vecfunction& other) = default;
575 if (this == &other) return *this;
576 functions = other.functions;
577 type = other.type;
578 omega = other.omega;
580 delta = other.delta;
581 irrep = other.irrep;
582 return *this;
583 }
584
585
586 /// returns a deep copy (void shallow copy errors)
587 friend CC_vecfunction
588 copy(const CC_vecfunction& other) {
589 CC_vecfunction tmp=other;
590 tmp.functions.clear();
591 for (const auto& x : other.functions) {
592 tmp.functions.insert(std::make_pair(x.first, copy(x.second)));
593 }
594 return tmp;
595 }
596
597 void reconstruct() const {
598 for (auto& x : functions) x.second.function.reconstruct();
599 }
600
601//madness::CC_vecfunction
602//CC_vecfunction::copy() const {
603// std::vector<CCFunction<double,3>> vn;
604// for (auto x : functions) {
605// const CCFunction<double,3> fn(madness::copy(x.second.function), x.second.i, x.second.type);
606// vn.push_back(fn);
607// }
608// CC_vecfunction result(vn, type);
609// result.irrep = irrep;
610// return result;
611//}
612//
613
614 static CC_vecfunction load_restartdata(World& world, std::string filename) {
617 ar & tmp;
618 return tmp;
619 }
620
621 void save_restartdata(World& world, std::string filename) const {
623 ar & *this;
624 }
625
626 template<typename Archive>
627 void serialize(const Archive& ar) {
628 typedef std::vector<std::pair<std::size_t, CCFunction<double,3>>> CC_functionvec;
629
630 auto map2vector = [] (const CC_functionmap& map) {
631 return CC_functionvec(map.begin(), map.end());
632 };
633 auto vector2map = [] (const CC_functionvec& vec) {
634 return CC_functionmap(vec.begin(), vec.end());
635 };
636
637 ar & type & omega & current_error & delta & irrep ;
638 if (ar.is_input_archive) {
639 std::size_t size=0; // set to zero to silence compiler warning
640 ar & size;
642
643 for (auto& t : tmp) ar & t.first & t.second;
645 } else if (ar.is_output_archive) {
647 ar & tmp.size();
648 for (auto& t : tmp) ar & t.first & t.second;
649 }
650 }
651
652 hashT hash() const {
653 hashT hashval = std::hash<FuncType>{}(type);
654 for (const auto& f : functions) hash_combine(hashval, hash_value(f.second.f().get_impl()->id()));
655
656 return hashval;
657 }
658
659 typedef std::map<std::size_t, CCFunction<double,3>> CC_functionmap;
661
663 double omega; /// excitation energy
665 double delta; // Last difference in Energy
666 std::string irrep = "null"; /// excitation irrep (direct product of x function and corresponding orbital)
667
668 std::string
669 name(const int ex) const {
670 return madness::name(type,ex);
671 };
672
673 bool is_converged(const double econv, const double dconv) const {
674 return (current_error<dconv) and (std::fabs(delta)<econv);
675 }
676
677 /// getter
679 return functions.find(i.i)->second;
680 }
681
682 /// getter
683 const CCFunction<double,3>& operator()(const size_t& i) const {
684 return functions.find(i)->second;
685 }
686
687 /// getter
691
692 /// getter
694 return functions[i];
695 }
696
697 /// setter
698 void insert(const size_t& i, const CCFunction<double,3>& f) {
699 functions.insert(std::make_pair(i, f));
700 }
701
702 /// setter
703 void set_functions(const vector_real_function_3d& v, const FuncType& type, const size_t& freeze) {
704 functions.clear();
705 for (size_t i = 0; i < v.size(); i++) {
706 CCFunction<double,3> tmp(v[i], freeze + i, type);
707 functions.insert(std::make_pair(freeze + i, tmp));
708 }
709 }
710
711 /// Returns all the functions of the map as vector
714 for (auto x:functions) tmp.push_back(x.second.function);
715 return tmp;
716 }
717
718 /// Get the size vector (number of functions in the map)
719 size_t size() const {
720 return functions.size();
721 }
722
723 /// Print the memory of which is used by all the functions in the map
724 void
725 print_size(const std::string& msg = "!?not assigned!?") const;
726
727 /// scalar multiplication
728 CC_vecfunction operator*(const double& fac) const {
730 const size_t freeze = functions.cbegin()->first;
731 return CC_vecfunction(vnew, type, freeze);
732 }
733
734 /// scaling (inplace)
735 void scale(const double& factor) {
736 for (auto& ktmp:functions) {
737 ktmp.second.function.scale(factor);
738 }
739 }
740
741 /// operator needed for sort operation (sorted by omega values)
742 bool operator<(const CC_vecfunction& b) const { return omega < b.omega; }
743
744 // plotting
745 void plot(const std::string& msg = "") const {
746 for (auto& ktmp:functions) {
747 ktmp.second.plot(msg);
748 }
749 }
750public:
752
753};
754
755/// Helper Structure that carries out operations on CC_functions
756/// The structure can hold intermediates for g12 and f12 of type : <mo_bra_k|op|type> with type=HOLE,PARTICLE or RESPONSE
757/// some 6D operations are also included
758/// The structure does not know if nuclear correlation facors are used, so the corresponding bra states have to be prepared beforehand
759template<typename T=double, std::size_t NDIM=3>
761public:
762
763 /// parameter class
764 struct Parameters {
766
767 Parameters(const Parameters& other) :
768 thresh_op(other.thresh_op),
769 lo(other.lo),
770 freeze(other.freeze),
771 gamma(other.gamma) {
772 }
773
774 Parameters(const CCParameters& param) : thresh_op(param.thresh_poisson()), lo(param.lo()),
776 gamma(param.gamma()) {};
778 double lo = 1.e-6;
779 int freeze = 0;
780 double gamma = 1.0; /// f12 exponent
781
782 template<typename archiveT>
783 void serialize(archiveT& ar) {
784 ar & thresh_op & lo & freeze & gamma;
785 }
786 };
787
788
789 /// @param[in] world
790 /// @param[in] optype: the operatortype (can be g12_ or f12_)
791 /// @param[in] param: the parameters of the current CC-Calculation (including function and operator thresholds and the exponent for f12)
795
797
798 static inline
799 std::shared_ptr<CCConvolutionOperator> CCConvolutionOperatorPtr(World& world, const OpType type, Parameters param) {
800 return std::shared_ptr<CCConvolutionOperator>(new CCConvolutionOperator(world, type, param));
801 }
802
803protected:
804
806 auto info= SeparatedConvolution<T,NDIM>::combine_OT((*a.get_op()),(*b.get_op()));
808 param.gamma=info.mu;
809 param.thresh_op=info.thresh;
810 param.lo=info.lo;
811 param.freeze=a.parameters.freeze;
812 return CCConvolutionOperator(a.world, info.type, param);
813 }
814
815 friend std::shared_ptr<CCConvolutionOperator> combine(const std::shared_ptr<CCConvolutionOperator>& a,
816 const std::shared_ptr<CCConvolutionOperator>& b) {
817 if (a and (not b)) return a;
818 if ((not a) and b) return b;
819 if ((not a) and (not b)) return nullptr;
820 return std::shared_ptr<CCConvolutionOperator>(new CCConvolutionOperator(combine(*a,*b)));
821 }
822
823public:
824 /// @param[in] f: a 3D function
825 /// @param[out] the convolution op(f), no intermediates are used
827 if (op) return ((*op)(f)).truncate();
828 return f;
829 }
830
831 /// @param[in] bra a CC_vecfunction
832 /// @param[in] ket a CC_function
833 /// @param[out] vector[i] = <bra[i]|op|ket>
834 std::vector<Function<T,NDIM>> operator()(const CC_vecfunction& bra, const CCFunction<T,NDIM>& ket) const {
836 std::vector<Function<T, NDIM>> result;
837 if constexpr (NDIM == 3) {
838 if (bra.type == HOLE) {
839 for (const auto& ktmp: bra.functions) {
840 const CCFunction<T, NDIM>& brai = ktmp.second;
841 const Function<T, NDIM> tmpi = this->operator()(brai, ket);
842 result.push_back(tmpi);
843 }
844 } else {
845 std::vector<Function<T, NDIM>> tmp = mul(world, ket.function, bra.get_vecfunction());
846 result = apply(world, (*op), tmp);
847 truncate(world, result);
848 }
849 } else {
850 MADNESS_EXCEPTION("not implemented", 1);
851 }
852
853 return result;
854 }
855
856 // @param[in] f: a vector of 3D functions
857 // @param[out] the convolution of op with each function, no intermeditates are used
858 std::vector<Function<T,NDIM>> operator()(const std::vector<Function<T,NDIM>>& f) const {
860 return apply<T,T,NDIM,NDIM>(world, (*op), f);
861 }
862
863 // @param[in] bra: a 3D CC_function, if nuclear-correlation factors are used they have to be applied before
864 // @param[in] ket: a 3D CC_function,
865 // @param[in] use_im: default is true, if false then no intermediates are used
866 // @param[out] the convolution <bra|op|ket> = op(bra*ket), if intermediates were calculated before the operator uses them
867 Function<T,NDIM> operator()(const CCFunction<T,NDIM>& bra, const CCFunction<T,NDIM>& ket, const bool use_im = true) const;
868
869 // @param[in] u: a 6D-function
870 // @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)
871 // @param[in] particle: specifies on which particle of u the operator will act (particle ==1 or particle==2)
872 Function<T,2*NDIM> operator()(const Function<T,2*NDIM>& u, const size_t particle) const;
873
874 // @param[in] bra: a 3D-CC_function, if nuclear-correlation factors are used they have to be applied before
875 // @param[in] u: a 6D-function
876 // @param[in] particle: specifies on which particle of u the operator will act (particle ==1 or particle==2)
877 // @param[out] the convolution <bra|g12|u>_particle
878 Function<T,NDIM> operator()(const CCFunction<T,NDIM>& bra, const Function<T,2*NDIM>& u, const size_t particle) const;
879
880 /// @param[in] bra: a vector of CC_functions, the type has to be HOLE
881 /// @param[in] ket: a vector of CC_functions, the type can be HOLE,PARTICLE,RESPONSE
882 /// updates intermediates of the type <bra|op|ket>
883 void update_elements(const CC_vecfunction& bra, const CC_vecfunction& ket);
884
885 /// @param[out] prints the name of the operator (convenience) which is g12 or f12 or maybe other things like gf in the future
886 std::string name() const {
887 std::stringstream ss;
888 ss << type();
889 return ss.str();
890 }
891
892 /// @param[in] the type of which intermediates will be deleted
893 /// e.g if(type==HOLE) then all intermediates of type <mo_bra_k|op|HOLE> will be deleted
894 void clear_intermediates(const FuncType& type);
895
896 /// prints out information (operatorname, number of stored intermediates ...)
897 size_t info() const;
898
900 hashT h;
901 hash_combine(h, op.parameters.thresh_op);
902 hash_combine(h, op.parameters.lo);
903 hash_combine(h, op.parameters.freeze);
904 hash_combine(h, op.parameters.gamma);
905 hash_combine(h, int(op.type()));
906 return h;
907 }
908
909 /// sanity check .. doens not do so much
910 void sanity() const { print_intermediate(HOLE); }
911
912 /// @param[in] type: the type of intermediates which will be printed, can be HOLE,PARTICLE or RESPONSE
913 void print_intermediate(const FuncType type) const {
914 if (type == HOLE)
915 for (const auto& tmp:imH.allpairs)
916 tmp.second.print_size("<H" + std::to_string(tmp.first.first) + "|" + name() + "|H" +
917 std::to_string(tmp.first.second) + "> intermediate");
918 else if (type == PARTICLE)
919 for (const auto& tmp:imP.allpairs)
920 tmp.second.print_size("<H" + std::to_string(tmp.first.first) + "|" + name() + "|P" +
921 std::to_string(tmp.first.second) + "> intermediate");
922 else if (type == RESPONSE)
923 for (const auto& tmp:imR.allpairs)
924 tmp.second.print_size("<H" + std::to_string(tmp.first.first) + "|" + name() + "|R" +
925 std::to_string(tmp.first.second) + "> intermediate");
926 }
927
928 /// create a TwoElectronFactory with the operatorkernel
931 factory.set_info(op->info);
932 return factory;
933 }
934
935 OpType type() const { return get_op()->info.type; }
936
938
939 std::shared_ptr<SeparatedConvolution<T,NDIM>> get_op() const {return op;};
940
941private:
942 /// the world
944
945 /// @param[in] optype: can be f12_ or g12_ depending on which operator shall be intitialzied
946 /// @param[in] parameters: parameters (thresholds etc)
947 /// initializes the operators
949
950 std::shared_ptr<SeparatedConvolution<T,NDIM>> op;
954
955 /// @param[in] msg: output message
956 /// the function will throw an MADNESS_EXCEPTION
957 void error(const std::string& msg) const {
958 if (world.rank() == 0)
959 std::cout << "\n\n!!!!ERROR in CCConvolutionOperator " << name() << ": " << msg
960 << "!!!!!\n\n" << std::endl;
961 MADNESS_EXCEPTION(msg.c_str(), 1);
962 }
963public:
964};
965
966template<typename T, std::size_t NDIM>
967std::shared_ptr<CCConvolutionOperator<T,NDIM>> CCConvolutionOperatorPtr(World& world, const OpType type,
969 return std::shared_ptr<CCConvolutionOperator<T,NDIM>>(new CCConvolutionOperator<T,NDIM>(world,type,param));
970}
971
972/// little helper structure which manages the stored singles potentials
978
979 /// check if the intermediate potential exists
981 return potential_exists(type,f.type);
982 }
983
984 /// check if the intermediate potential exists
986 bool exists=get_potential(type,ftype,false).size()>0;
987 return exists;
988 }
989
990 /// return a vector of the intermediate potentials
991
992 /// @param[in] ptype: the potential type (POT_SINGLES, POT_S2B, ..)
993 /// @param[in] ftype: the function type (HOLE, PARTICLE, RESPONSE)
995 get_potential(const PotentialType& ptype, const FuncType& ftype, const bool throw_if_empty) const;
996
997 /// fetches the correct stored potential or throws an exception
999 operator()(const CC_vecfunction& f, const PotentialType& type, const bool throw_if_empty) const;
1000
1001 /// fetch the potential for a single function
1003 operator()(const CCFunction<double,3>& f, const PotentialType& type, const bool throw_if_empty) const;
1004
1014
1015 /// deltes all stored potentials
1024
1025 /// clears only potentials of the response
1031
1032 /// insert potential
1033 void
1035
1048
1059
1062 hashT h;
1063 for (const auto& f : v) {
1064 hash_combine(h, hash_value(f.get_impl()->id()));
1065 }
1066 return h;
1067 };
1068 hashT h;
1069 hash_combine(h, hash_vector_of_functions(ip.current_s2b_potential_ex_));
1070 hash_combine(h, hash_vector_of_functions(ip.current_s2b_potential_gs_));
1071 hash_combine(h, hash_vector_of_functions(ip.current_s2c_potential_ex_));
1072 hash_combine(h, hash_vector_of_functions(ip.current_s2c_potential_gs_));
1073 hash_combine(h, hash_vector_of_functions(ip.current_singles_potential_ex_));
1074 hash_combine(h, hash_vector_of_functions(ip.current_singles_potential_gs_));
1075 hash_combine(h, hash_vector_of_functions(ip.unprojected_cc2_projector_response_));
1076 return h;
1077 }
1078
1080private:
1081 // World& world;
1082 /// whole ground state singles potential without fock-residue
1084 /// whole excited state singles potential without fock-residue
1086 /// s2b_potential for the pure 6D-part of the ground-state (expensive and constant during singles iterations)
1088 /// s2b_potential for the pure 6D-part of the excited-state (expensive and constant during singles iterations)
1090 /// s2c_potential for the pure 6D-part of the ground-state (expensive and constant during singles iterations)
1092 /// s2c_potential for the pure 6D-part of the excited_state (expensive and constant during singles iterations)
1094 /// unprojected S3c + S5c + S2b + S2c potential of CC2 singles
1095 /// for the projector response of the CC2 singles potential
1097
1098 /// structured output
1099 void output(const std::string& msg) const {
1100 if (parameters.debug())
1101 std::cout << "Intermediate Potential Manager: " << msg << "\n";
1102 }
1103};
1104
1105/// POD holding some basic functions and some intermediates for the CC2 calculation
1106
1107/// the class is cloud-serializable and can be used in MacroTasks
1108struct Info {
1109 std::vector<Function<double,3>> mo_ket;
1110 std::vector<Function<double,3>> mo_bra;
1111 std::vector<madness::Vector<double,3>> molecular_coordinates;
1113 std::vector<double> orbital_energies;
1117 std::vector<Function<double,3>> U1;
1118
1121 for (size_t i = parameters.freeze(); i < mo_ket.size(); i++) result.push_back(mo_ket[i]);
1122 return result;
1123 }
1124
1127 for (size_t i = parameters.freeze(); i < mo_bra.size(); i++) result.push_back(mo_bra[i]);
1128 return result;
1129 }
1130
1140
1141 /// customized function to store this to the cloud
1142
1143 /// functions and constant_part can be very large and we want to split them and store them in different records
1146 records+=cloud.store(world,mo_bra);
1147 records+=cloud.store(world,mo_ket);
1148 records+=cloud.store(world,parameters);
1149 records+=cloud.store(world,orbital_energies);
1150 records+=cloud.store(world,fock);
1152 records+=cloud.store(world,R_square);
1153 records+=cloud.store(world,molecular_coordinates);
1154 records+=cloud.store(world,U2);
1155 records+=cloud.store(world,U1);
1156 return records;
1157 }
1158
1159 /// customized function to load this from the cloud
1160
1161 /// functions and constant_part can be very large and we want to split them and store them in different records
1162 /// @param[inout] recordlist: containing the keys of the member variables -> will be reduced by the keys which are used
1164 // load bookkeeping stuff in a vector
1165 mo_bra=cloud.forward_load<std::vector<Function<double,3>>>(world,recordlist);
1166 mo_ket=cloud.forward_load<std::vector<Function<double,3>>>(world,recordlist);
1168 orbital_energies=cloud.forward_load<std::vector<double>>(world,recordlist);
1172 molecular_coordinates=cloud.forward_load<std::vector<madness::Vector<double,3>>>(world,recordlist);
1174 U1=cloud.forward_load<std::vector<Function<double,3>>>(world,recordlist);
1175 }
1176
1177};
1178
1179
1181public:
1182 CCPair() = default;
1183
1184 CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c)
1185 : type(t), ctype(c), i(ii), j(jj), bsh_eps(12345.6789) {};
1186
1187 CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c,
1188 const std::vector<CCPairFunction<double,6>>& f)
1189 : type(t), ctype(c), i(ii), j(jj), functions(f), bsh_eps(12345.6789) {};
1190
1191 CCPair(const CCPair& other) : type(other.type), ctype(other.ctype), i(other.i), j(other.j),
1193 bsh_eps(other.bsh_eps) {};
1194
1197 size_t i;
1198 size_t j;
1199
1200 /// customized function to store this to the cloud
1201
1202 /// functions and constant_part can be very large and we want to split them and store them in different records
1203 /// *NOTE* only the 6d function and the constant part are stored in the cloud, not the 3d functions *NOTE*
1205 // save bookkeeping stuff in a vector
1206 std::vector<unsigned char> v;
1208 bool function_is_assigned=(functions.size()>0 && functions[0].is_assigned());
1210
1212 records+=cloud.store(world,v);
1213 if (function_is_assigned) records+=cloud.store(world,functions[0]);
1215 return records;
1216 }
1217
1218 /// customized function to load this from the cloud
1219
1220 /// functions and constant_part can be very large and we want to split them and store them in different records
1221 /// @param[inout] recordlist: containing the keys of the member variables -> will be reduced by the keys which are used
1223 // load bookkeeping stuff in a vector
1224 std::vector<unsigned char> v=cloud.forward_load<std::vector<unsigned char>>(world,recordlist);
1228 functions.clear();
1230
1233 }
1234
1235 bool function_exists() const {
1236 return (functions.size()>0 and functions[0].is_assigned() and functions[0].is_pure());
1237 }
1238
1239 /// gives back the pure 6D part of the pair function
1241 MADNESS_CHECK_THROW(not functions.empty(), "no function assigned in CCPair::function()");
1242 MADNESS_CHECK_THROW(functions[0].is_pure(),"function is not pure in CCPair::function()");
1243 return functions[0].get_function();
1244 }
1245
1246 /// updates the pure 6D part of the pair function
1248 // print("updating u(",i,j,")");
1250 if (functions.size() == 0) functions.push_back(tmp);
1251 else { //(functions.size() > 1) {
1252 MADNESS_CHECK_THROW(functions[0].is_pure(),"function is not pure in CCPair::update_u()");
1253 functions[0]=tmp;
1254 }
1255 }
1256
1257 template<typename Archive>
1258 void serialize(const Archive& ar) {
1259 size_t f_size = functions.size();
1260 bool fexist = (f_size > 0) && (functions[0].get_function().is_initialized());
1262 ar & type & ctype & i & j & bsh_eps & fexist & cexist & f_size;
1263 if constexpr (Archive::is_input_archive) {
1264 if (fexist) {
1266 ar & func;
1268 functions.push_back(f1);
1269 }
1270 } else {
1271 if (fexist) ar & functions[0].get_function();
1272 }
1273 if (cexist) ar & constant_part;
1274 }
1275
1276 /// reconstruct constant part and all functions
1277 void reconstruct() const {
1279 for (auto& f : functions) {
1280 if (f.is_assigned() and f.is_pure()) f.get_function().reconstruct();
1281 }
1282 }
1283
1284 bool load_pair(World& world, const bool verbose=false) {
1285 std::string fname=this->name();
1286 if (verbose and world.rank()==0) print("loading pair from file", fname);
1288 if (exists) {
1290 ar & *this;
1291 if (functions[0].get_function().is_initialized()) functions[0].get_function().set_thresh(FunctionDefaults<6>::get_thresh());
1293 }
1294 return exists;
1295 }
1296
1297 void store_pair(World& world, const bool verbose=false) {
1298 std::string fname =this->name();
1299 if (verbose and world.rank()==0) print("loading pair from file", fname);
1300 this->reconstruct();
1302 ar & *this;
1303 }
1304
1305 hashT hash() const {
1306 hashT hash_i = std::hash<std::size_t>{}(i);
1307 hash_combine(hash_i, std::hash<std::size_t>{}(j));
1310 }
1311 return hash_i;
1312 }
1313
1314 /// the functions which belong to the pair
1315 std::vector<CCPairFunction<double,6>> functions;
1316
1317 /// the constant part
1319
1320 /// Energy for the BSH Operator
1321 /// Ground State: e_i + e_j
1322 /// Excited State: e_i + e_j + omega
1323 /// default to positive value to make sure this is set somewhere
1324 double bsh_eps=1.0;
1325
1326 /// return the base name like "MP2_pair_u" or "CC2_pair_x"
1327 std::string basename() const {
1328 std::string name = "???";
1329 if (type == GROUND_STATE) name = assign_name(ctype) + "_pair_u";
1330 if (type == EXCITED_STATE) name = assign_name(ctype) + "_pair_x";
1331 return name;
1332
1333 }
1334 std::string name() const {
1335 return basename() +"_" + stringify(i) + stringify(j);
1336 }
1337
1338 void
1339 info() const;
1340
1341};
1342
1343/// build an MP2 or CC2 or LRCC2 etc pair, possibly including the lo-rank parts
1345public:
1347
1348 /// provide ground-state singles, needed for CC2 and LRCC2 wave function ansatz
1350 gs_singles = gs;
1351 return *this;
1352 }
1353
1354 /// provide excited state singles, needed for CC2 and LRCC2 wave function ansatz
1356 ex_singles = ex;
1357 return *this;
1358 }
1359
1361 ctype = type;
1362 return *this;
1363 }
1364
1365 /// make a CCPair without the 6d function and some bookkeeping information
1366 CCPair make_bare_pair(const int i, const int j) const;
1367
1368 /// make a CCPair with the 6d function only and some bookkeeping information
1369 CCPair make_bare_pair_from_file(const int i, const int j) const;
1370
1371 /// make a CCPair
1372 CCPair make_pair(const int i, const int j, const std::vector<CCPairFunction<double,6>>& u) const;
1373
1374 inline static CCState cc_state(const CalcType& type) {
1376 else if (type==CT_LRCC2 or type==CT_ADC2 or type==CT_CISPD) return EXCITED_STATE;
1377 else {
1378 MADNESS_EXCEPTION("unknown cc-state",1);
1379 }
1380 }
1381
1382 /// make a CCPair with the 6d function only and some bookkeeping information
1384 Pairs<CCPair> pairs;
1385 for (size_t i = info.parameters.freeze(); i < info.mo_bra.size(); i++) {
1386 for (size_t j = info.parameters.freeze(); j < info.mo_ket.size(); j++) {
1387 pairs.insert(i,j,make_bare_pair(i, j));
1388 }
1389 }
1390 return pairs;
1391 }
1392
1393 /// complete the given pair with the low-rank parts
1394
1395 /// will use pair's ctype, while builder's ctype is ignored
1397
1398
1399 /// Function to load a function from disk
1400
1401 /// @param[in] name of the file in which the function was stored
1402 /// @param do_print
1403 /// @return the function, possibly not initialized if not found on disk
1404 template <typename T, size_t NDIM>
1405 Function<T,NDIM> load_function(const std::string name, bool do_print) const {
1407 bool exists = archive::ParallelInputArchive<
1409 if (exists) {
1410 if ((world.rank() == 0) and do_print) print("loading function", name);
1412 ar & f;
1413 if (do_print) f.print_size(name);
1414 if (f.is_compressed()) {
1415 if (world.rank()==0 and do_print) print("function is compressed -- reconstructing");
1416 f.change_tree_state(reconstructed);
1417 if (do_print) f.print_size(name+" reconstructed");
1418 save(f, name);
1419 }
1421 f.truncate();
1422 f.print_size(name);
1423 } else {
1424 if ((world.rank()==0) and do_print) print("could not find function",name);
1425 }
1426 return f;
1427 }
1428
1430 const Info& info;
1433
1434};
1435
1436
1437/// print accumulated size of all functions
1438struct CCSize {
1439 double size_local=0;
1440
1441 CCSize() = default;
1442
1443 template<typename T, std::size_t NDIM>
1444 void add_helper(const std::vector<Function<T,NDIM>>& v) {
1445 if (v.size()>0) size_local+=get_size_local(v.front().world(),v);
1446 }
1447
1448 void add_helper(const std::vector<CCPair>& vp) {
1449 if (vp.empty()) return;
1450 for (const auto& p : vp) {
1451 size_local+=get_size(p.constant_part);
1452 if (p.function_exists()) size_local+=get_size_local(p.function());
1453 }
1454 }
1455
1456 /// variadic template parameters to add the size of all functions and pairs
1457 template<typename... Args>
1458 void add(const Args&... args) {
1459 (add_helper(args), ...);
1460 }
1461
1462 void print(World& world, const std::string msg="") const {
1463 double size_global=size_local;
1464 world.gop.sum(size_global);
1465 if (msg.size()>0 and world.rank()==0) madness::print(msg);
1466 world.gop.fence();
1467 madness::print("size of all functions on rank",world.rank(),size_local);
1468 world.gop.fence();
1469 if (world.rank()==0) madness::print("total size of all functions",size_global);
1470
1471 }
1472};
1473
1474
1476
1478 public:
1480
1481 partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1482 const std::string policy) const override {
1483 partitionT p;
1484 for (size_t i = 0; i < vsize1; i++) {
1485 Batch batch(Batch_1D(i,i+1), Batch_1D(i,i+1));
1486 p.push_back(std::make_pair(batch,1.0));
1487 }
1488 return p;
1489 }
1490 };
1491
1492public:
1494
1495 // typedef std::tuple<const std::vector<CCPair>&, const std::vector<Function<double,3>>&,
1496 // const std::vector<Function<double,3>>&, const CCParameters&, const Function<double,3>&,
1497 // const std::vector<Function<double,3>>&, const std::vector<std::string>& > argtupleT;
1498 typedef std::tuple<const std::vector<CCPair>&, const madness::Info&, const std::vector<std::string>& > argtupleT;
1499
1500 using resultT = std::vector<real_function_6d>;
1501
1502 resultT allocator(World& world, const argtupleT& argtuple) const {
1503 std::size_t n = std::get<0>(argtuple).size();
1505 return result;
1506 }
1507
1508// resultT operator() (const std::vector<CCPair>& pair, const std::vector<Function<double,3>>& mo_ket,
1509// const std::vector<Function<double,3>>& mo_bra, const CCParameters& parameters,
1510// const Function<double,3>& Rsquare, const std::vector<Function<double,3>>& U1,
1511// const std::vector<std::string>& argument) const;
1512 resultT operator() (const std::vector<CCPair>& pair, const Info& info, const std::vector<std::string>& argument) const;
1513};
1514
1515/// compute the "constant" part of MP2, CC2, or LR-CC2
1516///
1517/// the constant part is
1518/// result = G [F,f] |ij> for MP2
1519/// result = G [F,f] |t_i t_j> for CC2
1520/// result = G [F,f] |t_i x_j> + |x_i t_j> for LR-CC2
1522
1524 public:
1526
1527 partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1528 const std::string policy) const override {
1529 partitionT p;
1530 for (size_t i = 0; i < vsize1; i++) {
1531 Batch batch(Batch_1D(i,i+1), Batch_1D(i,i+1));
1532 p.push_back(std::make_pair(batch,1.0));
1533 }
1534 return p;
1535 }
1536 };
1537
1538public:
1541 name="ConstantPart";
1542 }
1543
1544 // typedef std::tuple<const std::vector<CCPair>&, const std::vector<Function<double,3>>&,
1545 // const std::vector<Function<double,3>>&, const CCParameters&, const Function<double,3>&,
1546 // const std::vector<Function<double,3>>&, const std::vector<std::string>& > argtupleT;
1547 typedef std::tuple<const std::vector<CCPair>&,
1548 const std::vector<Function<double,3>>&, const std::vector<Function<double,3>>&,
1550
1551 using resultT = std::vector<real_function_6d>;
1552
1553 resultT allocator(World& world, const argtupleT& argtuple) const {
1554 std::size_t n = std::get<0>(argtuple).size();
1556 return result;
1557 }
1558 resultT operator() (const std::vector<CCPair>& pair,
1559 const std::vector<Function<double,3>>& gs_singles,
1560 const std::vector<Function<double,3>>& ex_singles,
1561 const Info& info) const;
1562};
1563
1565
1567 public :
1571
1572 partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1573 const std::string policy) const override {
1574 partitionT p;
1575 for (size_t i = 0; i < vsize1; i++) {
1576 Batch batch(Batch_1D(i, i+1), Batch_1D(i, i+1), Batch_1D(i,i+1));
1577 p.push_back(std::make_pair(batch, 1.0));
1578 }
1579 return p;
1580 }
1581 };
1582public:
1585 name="MP2UpdatePair";
1586 }
1587
1588 // typedef std::tuple<const std::vector<CCPair>&, const std::vector<real_function_6d>&, const CCParameters&,
1589 // const std::vector< madness::Vector<double,3> >&,
1590 // const std::vector<Function<double,3>>&, const std::vector<Function<double,3>>&,
1591 // const std::vector<Function<double,3>>&, const Function<double,3>&> argtupleT;
1592 typedef std::tuple<const std::vector<CCPair>&, const std::vector<real_function_6d>&,
1593 const std::vector<madness::Vector<double,3>>&, const Info& > argtupleT;
1594
1595 using resultT = std::vector<real_function_6d>;
1596
1597 resultT allocator(World& world, const argtupleT& argtuple) const {
1598 std::size_t n = std::get<0>(argtuple).size();
1600 return result;
1601 }
1602
1603// resultT operator() (const std::vector<CCPair>& pair, const std::vector<real_function_6d>& mp2_coupling, const CCParameters& parameters,
1604// const std::vector< madness::Vector<double,3> >& all_coords_vec,
1605// const std::vector<Function<double,3>>& mo_ket, const std::vector<Function<double,3>>& mo_bra,
1606// const std::vector<Function<double,3>>& U1, const Function<double,3>& U2) const;
1607 resultT operator() (const std::vector<CCPair>& pair, const std::vector<real_function_6d>& mp2_coupling,
1608 const std::vector< madness::Vector<double,3> >& all_coords_vec, const Info& info) const;
1609};
1610
1611
1613
1615 public :
1617
1618 partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1619 const std::string policy) const override {
1620 partitionT p;
1621 for (size_t i = 0; i < vsize1; i++) {
1622 Batch batch(Batch_1D(i, i+1), Batch_1D(i, i+1), Batch_1D(i,i+1));
1623 p.push_back(std::make_pair(batch,1.0));
1624 }
1625 return p;
1626 }
1627 };
1628public:
1631 name="IteratePair";
1632 }
1633
1634 typedef std::tuple<
1635 const std::vector<CCPair>&, // pair
1636 const std::vector<real_function_6d>&, // local coupling
1637 const CC_vecfunction&, // gs singles
1638 const CC_vecfunction&, // ex singles
1639 const Info&,
1640 const std::size_t&
1642
1643 using resultT = std::vector<real_function_6d>;
1644
1645 resultT allocator(World& world, const argtupleT& argtuple) const {
1646 std::size_t n = std::get<0>(argtuple).size();
1648 return result;
1649 }
1650
1651 /// iterate a given pair of the MP2, CC2 or LRCC2 calculation
1652
1653 /// will *NOT* compute the local coupling,
1654 /// will apply the Fock operators (J-K+V)|pair> and use
1655 /// the (excited) singles vectors to update the pair
1656 /// @param[in] pair: the pair which will be updated
1657 /// @param[in] gs_singles: the ground state singles, may be dummy for MP2
1658 /// @param[in] ex_singles: the excited state singles, may be dummy for MP2, CC2
1659 /// @param[in] all_coords_vec: the coordinates of the atoms
1660 /// @param[in] info: the info structure
1661 /// @param[in] maxiter: the maximal number of iterations
1662 resultT operator() (const std::vector<CCPair>& pair,
1663 const std::vector<real_function_6d>& local_coupling,
1664 const CC_vecfunction& gs_singles,
1665 const CC_vecfunction& ex_singles,
1666 const Info& info,
1667 const std::size_t& maxiter) const;
1668};
1669
1670
1672public:
1673 std::string basename="SinglesPotentialEx";
1675 name="SinglesPotentialEx";
1676 partitioner->max_batch_size=2;
1677 partitioner->min_batch_size=2;
1678 }
1679
1680 typedef std::tuple<
1681 const std::vector<int>&, // result_index,
1682 const CC_vecfunction&, // singles_gs,
1683 const std::vector<CCPair>&, // doubles_gs,
1684 const CC_vecfunction&, // singles_ex,
1685 const std::vector<CCPair>&, // doubles_ex,
1686 const int&, // name,
1687 const Info& // info
1689
1690 using resultT = std::tuple<std::vector<real_function_3d>,std::vector<real_function_3d>>;
1691
1692 resultT allocator(World& world, const argtupleT& argtuple) const {
1693 std::size_t n = std::get<0>(argtuple).size();
1694 std::vector<real_function_3d> result = zero_functions_compressed<double, 3>(world, n);
1695 std::vector<real_function_3d> intermediate = zero_functions_compressed<double, 3>(world, n);
1696 const_cast<std::string&>(name) =basename+"_"+assign_name(PotentialType(std::get<5>(argtuple)));
1697 return std::make_tuple(result,intermediate);
1698 }
1699
1700 resultT operator() (const std::vector<int>& result_index,
1702 const std::vector<CCPair>& doubles_gs,
1704 const std::vector<CCPair>& doubles_ex,
1705 const int& name,
1706 const Info& info);
1707};
1708
1710public:
1711 std::string basename="SinglesPotentialGs";
1713 name="SinglesPotentialGs";
1714 }
1715
1716 typedef std::tuple<
1717 const std::vector<int>&, // result_index,
1718 const CC_vecfunction&, // singles_gs,
1719 const std::vector<CCPair>&, // doubles_gs,
1720 const int&, // name,
1721 const Info& // info
1723
1724 /// first vector is the potential, second is an intermediate (if applicable, e.g. for s2b and s2c potentials)
1725 using resultT = std::tuple<std::vector<real_function_3d>,std::vector<real_function_3d>>;
1726
1727 /// allocate the result and set the name of this task
1728 resultT allocator(World& world, const argtupleT& argtuple) const {
1729 std::size_t n = std::get<0>(argtuple).size();
1730 std::vector<real_function_3d> result = zero_functions_compressed<double, 3>(world, n);
1731 std::vector<real_function_3d> intermediate = zero_functions_compressed<double, 3>(world, n);
1732 const_cast<std::string&>(name) =basename+"_"+assign_name(PotentialType(std::get<3>(argtuple)));
1733 return std::make_tuple(result,intermediate);
1734 }
1735
1736 resultT operator() (const std::vector<int>& result_index,
1738 const std::vector<CCPair>& doubles_gs,
1739 const int& name,
1740 const Info& info);
1741};
1742
1743
1745public:
1746 std::string basename="CorrelationEnergy";
1748 name="CorrelationEnergy";
1749 }
1750
1751 typedef std::tuple<
1752 const std::vector<CCPair>&,
1753 const CC_vecfunction&,
1754 const Info&
1756
1757 /// first vector is the potential, second is an intermediate (if applicable, e.g. for s2b and s2c potentials)
1758 typedef std::vector<ScalarResult<double>> resultT;
1759
1760
1761 /// allocate the result and set the name of this task
1762 resultT allocator(World &world, const argtupleT &argtuple) const {
1763 std::size_t n = std::get<0>(argtuple).size();
1764 return scalar_result_vector<double>(world,n);
1765 }
1766
1767 resultT operator() (const std::vector<CCPair>& pairs,
1769 const Info& info) const;
1770};
1771
1772}//namespace madness
1773
1774#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:139
Definition CCStructures.h:760
intermediateT< T, NDIM > imH
Definition CCStructures.h:951
CCConvolutionOperator(const CCConvolutionOperator &other)=default
friend hashT hash_value(CCConvolutionOperator< T, NDIM > &op)
Definition CCStructures.h:899
static std::shared_ptr< CCConvolutionOperator > CCConvolutionOperatorPtr(World &world, const OpType type, Parameters param)
Definition CCStructures.h:799
Function< T, NDIM > operator()(const Function< T, NDIM > &f) const
Definition CCStructures.h:826
SeparatedConvolution< T, NDIM > * init_op(const OpType &type, const Parameters &parameters) const
Definition CCStructures.cc:370
size_t info() const
prints out information (operatorname, number of stored intermediates ...)
Definition CCStructures.cc:352
std::shared_ptr< SeparatedConvolution< T, NDIM > > op
Definition CCStructures.h:950
std::vector< Function< T, NDIM > > operator()(const std::vector< Function< T, NDIM > > &f) const
Definition CCStructures.h:858
OpType type() const
Definition CCStructures.h:935
void clear_intermediates(const FuncType &type)
Definition CCStructures.cc:330
World & world
the world
Definition CCStructures.h:943
void sanity() const
sanity check .. doens not do so much
Definition CCStructures.h:910
std::string name() const
Definition CCStructures.h:886
friend std::shared_ptr< CCConvolutionOperator > combine(const std::shared_ptr< CCConvolutionOperator > &a, const std::shared_ptr< CCConvolutionOperator > &b)
Definition CCStructures.h:815
void update_elements(const CC_vecfunction &bra, const CC_vecfunction &ket)
Definition CCStructures.cc:298
intermediateT< T, NDIM > imP
Definition CCStructures.h:952
void error(const std::string &msg) const
Definition CCStructures.h:957
const Parameters parameters
Definition CCStructures.h:937
CCConvolutionOperator(World &world, const OpType type, Parameters param)
Definition CCStructures.h:792
std::vector< Function< T, NDIM > > operator()(const CC_vecfunction &bra, const CCFunction< T, NDIM > &ket) const
Definition CCStructures.h:834
std::shared_ptr< SeparatedConvolution< T, NDIM > > get_op() const
Definition CCStructures.h:939
void print_intermediate(const FuncType type) const
Definition CCStructures.h:913
intermediateT< T, NDIM > imR
Definition CCStructures.h:953
TwoElectronFactory< T, 2 *NDIM > get_kernel() const
create a TwoElectronFactory with the operatorkernel
Definition CCStructures.h:929
friend CCConvolutionOperator combine(const CCConvolutionOperator &a, const CCConvolutionOperator &b)
Definition CCStructures.h:805
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
build an MP2 or CC2 or LRCC2 etc pair, possibly including the lo-rank parts
Definition CCStructures.h:1344
CCPairBuilder & set_ex_singles(const CC_vecfunction &ex)
provide excited state singles, needed for CC2 and LRCC2 wave function ansatz
Definition CCStructures.h:1355
CCPairBuilder(World &world, const Info &info)
Definition CCStructures.h:1346
CC_vecfunction gs_singles
Definition CCStructures.h:1431
const Info & info
Definition CCStructures.h:1430
CCPair make_bare_pair(const int i, const int j) const
make a CCPair without the 6d function and some bookkeeping information
Definition CCStructures.cc:506
CCPairBuilder & set_gs_singles(const CC_vecfunction &gs)
provide ground-state singles, needed for CC2 and LRCC2 wave function ansatz
Definition CCStructures.h:1349
static CCState cc_state(const CalcType &type)
Definition CCStructures.h:1374
CCPair make_bare_pair_from_file(const int i, const int j) const
make a CCPair with the 6d function only and some bookkeeping information
Definition CCStructures.cc:529
World & world
Definition CCStructures.h:1429
Function< T, NDIM > load_function(const std::string name, bool do_print) const
Function to load a function from disk.
Definition CCStructures.h:1405
CCPair make_pair(const int i, const int j, const std::vector< CCPairFunction< double, 6 > > &u) const
make a CCPair
Definition CCStructures.cc:520
CalcType ctype
Definition CCStructures.h:1432
CC_vecfunction ex_singles
Definition CCStructures.h:1431
CCPairBuilder & set_ctype(const CalcType &type)
Definition CCStructures.h:1360
CCPair complete_pair_with_low_rank_parts(const CCPair &pair) const
complete the given pair with the low-rank parts
Definition CCStructures.cc:545
Pairs< CCPair > make_all_bare_pairs() const
make a CCPair with the 6d function only and some bookkeeping information
Definition CCStructures.h:1383
a 6D function, either in full or low rank form, possibly including an 2-particle function
Definition ccpairfunction.h:373
Definition CCStructures.h:1180
void reconstruct() const
reconstruct constant part and all functions
Definition CCStructures.h:1277
hashT hash() const
Definition CCStructures.h:1305
void info() const
Definition CCStructures.cc:84
std::string basename() const
return the base name like "MP2_pair_u" or "CC2_pair_x"
Definition CCStructures.h:1327
CCPair(const CCPair &other)
Definition CCStructures.h:1191
void store_pair(World &world, const bool verbose=false)
Definition CCStructures.h:1297
Recordlist< Cloud::keyT > cloud_store(World &world, Cloud &cloud) const
customized function to store this to the cloud
Definition CCStructures.h:1204
bool function_exists() const
Definition CCStructures.h:1235
std::string name() const
Definition CCStructures.h:1334
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:1187
size_t i
Definition CCStructures.h:1197
bool load_pair(World &world, const bool verbose=false)
Definition CCStructures.h:1284
real_function_6d function() const
gives back the pure 6D part of the pair function
Definition CCStructures.h:1240
real_function_6d constant_part
the constant part
Definition CCStructures.h:1318
std::vector< CCPairFunction< double, 6 > > functions
the functions which belong to the pair
Definition CCStructures.h:1315
CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c)
Definition CCStructures.h:1184
void update_u(const real_function_6d &u)
updates the pure 6D part of the pair function
Definition CCStructures.h:1247
size_t j
Definition CCStructures.h:1198
CCState type
Definition CCStructures.h:1195
CCPair()=default
double bsh_eps
Definition CCStructures.h:1324
void serialize(const Archive &ar)
Definition CCStructures.h:1258
CalcType ctype
Definition CCStructures.h:1196
void cloud_load(World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
customized function to load this from the cloud
Definition CCStructures.h:1222
cloud class
Definition cloud.h:147
recordlistT store(madness::World &world, const T &source)
Definition cloud.h:314
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:296
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:100
static const double & get_thresh()
Returns the default threshold.
Definition funcdefaults.h:176
A multiresolution adaptive numerical function.
Definition mra.h:139
void set_thresh(double value, bool fence=true)
Sets the value of the truncation threshold. Optional global fence.
Definition mra.h:602
const std::shared_ptr< FunctionImpl< T, NDIM > > & get_impl() const
Returns a shared-pointer to the implementation.
Definition mra.h:639
const Function< T, NDIM > & reconstruct(bool fence=true) const
Reconstructs the function, transforming into scaling function basis. Possible non-blocking comm.
Definition mra.h:800
void clear(bool fence=true)
Clears the function as if constructed uninitialized. Optional fence.
Definition mra.h:872
bool is_initialized() const
Returns true if the function is initialized.
Definition mra.h:167
Definition CCStructures.h:1744
resultT operator()(const std::vector< CCPair > &pairs, const CC_vecfunction &singles_gs, const Info &info) const
Definition CCStructures.cc:746
std::tuple< const std::vector< CCPair > &, const CC_vecfunction &, const Info & > argtupleT
Definition CCStructures.h:1755
MacroTaskComputeCorrelationEnergy()
Definition CCStructures.h:1747
resultT allocator(World &world, const argtupleT &argtuple) const
allocate the result and set the name of this task
Definition CCStructures.h:1762
std::vector< ScalarResult< double > > resultT
first vector is the potential, second is an intermediate (if applicable, e.g. for s2b and s2c potenti...
Definition CCStructures.h:1758
std::string basename
Definition CCStructures.h:1746
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:1527
ConstantPartPartitioner()
Definition CCStructures.h:1525
Definition CCStructures.h:1521
std::vector< real_function_6d > resultT
Definition CCStructures.h:1551
MacroTaskConstantPart()
Definition CCStructures.h:1539
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:1549
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1553
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:616
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:1618
Definition CCStructures.h:1612
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:1641
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:651
MacroTaskIteratePair()
Definition CCStructures.h:1629
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1645
std::vector< real_function_6d > resultT
Definition CCStructures.h:1643
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:1481
Definition CCStructures.h:1475
resultT operator()(const std::vector< CCPair > &pair, const Info &info, const std::vector< std::string > &argument) const
Definition CCStructures.cc:604
MacroTaskMp2ConstantPart()
Definition CCStructures.h:1493
std::tuple< const std::vector< CCPair > &, const madness::Info &, const std::vector< std::string > & > argtupleT
Definition CCStructures.h:1498
std::vector< real_function_6d > resultT
Definition CCStructures.h:1500
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1502
UpdatePairPartitioner()
Definition CCStructures.h:1568
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:1572
Definition CCStructures.h:1564
MacroTaskMp2UpdatePair()
Definition CCStructures.h:1583
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1597
std::vector< real_function_6d > resultT
Definition CCStructures.h:1595
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:1593
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:635
Definition macrotaskq.h:969
Batch batch
Definition macrotaskq.h:971
std::shared_ptr< MacroTaskPartitioner > partitioner
Definition macrotaskq.h:973
std::string name
Definition macrotaskq.h:972
partition one (two) vectors into 1D (2D) batches.
Definition macrotaskpartitioner.h:197
std::string policy
how to partition the batches
Definition macrotaskpartitioner.h:205
std::list< std::pair< Batch, double > > partitionT
Definition macrotaskpartitioner.h:201
MacroTaskPartitioner & set_dimension(const std::size_t &n)
Definition macrotaskpartitioner.h:220
Definition CCStructures.h:1671
std::tuple< std::vector< real_function_3d >, std::vector< real_function_3d > > resultT
Definition CCStructures.h:1690
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1692
std::tuple< const std::vector< int > &, const CC_vecfunction &, const std::vector< CCPair > &, const CC_vecfunction &, const std::vector< CCPair > &, const int &, const Info & > argtupleT
Definition CCStructures.h:1688
std::string basename
Definition CCStructures.h:1673
MacroTaskSinglesPotentialEx()
Definition CCStructures.h:1674
resultT operator()(const std::vector< int > &result_index, const CC_vecfunction &singles_gs, const std::vector< CCPair > &doubles_gs, const CC_vecfunction &singles_ex, const std::vector< CCPair > &doubles_ex, const int &name, const Info &info)
convenience function
Definition CCStructures.cc:672
Definition CCStructures.h:1709
std::string basename
Definition CCStructures.h:1711
std::tuple< const std::vector< int > &, const CC_vecfunction &, const std::vector< CCPair > &, const int &, const Info & > argtupleT
Definition CCStructures.h:1722
std::tuple< std::vector< real_function_3d >, std::vector< real_function_3d > > resultT
first vector is the potential, second is an intermediate (if applicable, e.g. for s2b and s2c potenti...
Definition CCStructures.h:1725
resultT operator()(const std::vector< int > &result_index, const CC_vecfunction &singles_gs, const std::vector< CCPair > &doubles_gs, const int &name, const Info &info)
Definition CCStructures.cc:714
MacroTaskSinglesPotentialGs()
Definition CCStructures.h:1712
resultT allocator(World &world, const argtupleT &argtuple) const
allocate the result and set the name of this task
Definition CCStructures.h:1728
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
Convolutions in separated form (including Gaussian)
Definition operator.h:139
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:1706
A tensor is a multidimensional array.
Definition tensor.h:317
factory for generating TwoElectronInterfaces
Definition function_factory.h:436
A simple, fixed dimension vector.
Definition vector.h:64
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:161
std::vector< T > concat0(const std::vector< T > &v, size_t bufsz=1024 *1024)
Concatenate an STL vector of serializable stuff onto node 0.
Definition worldgop.h:953
void sum(T *buf, size_t nelem)
Inplace global sum while still processing AM & tasks.
Definition worldgop.h:870
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:320
WorldGopInterface & gop
Global operations.
Definition world.h:207
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
Wraps an archive around a binary filestream for input.
Definition binary_fstream_archive.h:104
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
static double u(double r, double c)
Definition he.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:182
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
long get_memory_usage()
Definition unique_filename.cc:29
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
void print_memory_usage(const World &world)
check memory usage using getrusage
Definition CCStructures.h:77
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:1733
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
@ reconstructed
s coeffs at the leaves only
Definition funcdefaults.h:60
CalcType assign_calctype(const std::string name)
Assigns enum to string.
Definition CCStructures.cc:396
const std::vector< Function< T, NDIM > > & reconstruct(const std::vector< Function< T, NDIM > > &v)
reconstruct a vector of functions
Definition vmra.h:156
std::shared_ptr< CCConvolutionOperator< T, NDIM > > CCConvolutionOperatorPtr(World &world, const OpType type, typename CCConvolutionOperator< T, NDIM >::Parameters param)
Definition CCStructures.h:967
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:511
std::vector< real_function_3d > vector_real_function_3d
Definition functypedefs.h:94
std::shared_ptr< FunctionFunctorInterface< double, 3 > > func(new opT(g))
OpType
operator types
Definition operatorinfo.h:11
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
response_space apply(World &world, std::vector< std::vector< std::shared_ptr< real_convolution_3d > > > &op, response_space &f)
Definition basic_operators.cc:39
std::string get_hostname()
Definition unique_filename.cc:40
NDIM & f
Definition mra.h:2448
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
constexpr Vector< T, sizeof...(Ts)+1 > vec(T t, Ts... ts)
Factory function for creating a madness::Vector.
Definition vector.h:750
PotentialType
CC2 Singles Potentials.
Definition CCStructures.h:36
@ POT_singles_
Definition CCStructures.h:53
@ POT_s2b_
Definition CCStructures.h:45
@ POT_F3D_
Definition CCStructures.h:38
@ POT_s5b_
Definition CCStructures.h:43
@ POT_s4c_
Definition CCStructures.h:49
@ POT_s5c_
Definition CCStructures.h:44
@ POT_s6_
Definition CCStructures.h:50
@ POT_s4b_
Definition CCStructures.h:48
@ POT_ccs_
Definition CCStructures.h:51
@ POT_s3c_
Definition CCStructures.h:41
@ POT_s4a_
Definition CCStructures.h:47
@ POT_s5a_
Definition CCStructures.h:42
@ POT_s3b_
Definition CCStructures.h:40
@ POT_s2c_
Definition CCStructures.h:46
@ POT_cis_
Definition CCStructures.h:52
@ POT_UNDEFINED
Definition CCStructures.h:37
@ POT_s3a_
Definition CCStructures.h:39
std::string assign_name(const CCState &input)
Assigns strings to enums for formated output.
Definition CCStructures.cc:379
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:284
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
void save(const Function< T, NDIM > &f, const std::string name)
Definition mra.h:2777
double get_size(World &world, const std::vector< Function< T, NDIM > > &v)
Definition vmra.h:1721
double get_size_local(World &world, const std::vector< Function< T, NDIM > > &v)
return the size of a vector of functions for each rank
Definition vmra.h:1702
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
double thresh
Definition tdse.cc:67
parameter class
Definition CCStructures.h:764
int freeze
Definition CCStructures.h:779
Parameters()
Definition CCStructures.h:765
void serialize(archiveT &ar)
f12 exponent
Definition CCStructures.h:783
double lo
Definition CCStructures.h:778
double gamma
Definition CCStructures.h:780
Parameters(const CCParameters &param)
Definition CCStructures.h:774
double thresh_op
Definition CCStructures.h:777
Parameters(const Parameters &other)
Definition CCStructures.h:767
little helper structure which manages the stored singles potentials
Definition CCStructures.h:973
CCParameters parameters
Definition CCStructures.h:1079
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:1093
bool potential_exists(const CC_vecfunction &f, const PotentialType &type) const
check if the intermediate potential exists
Definition CCStructures.h:980
Recordlist< Cloud::keyT > cloud_store(World &world, Cloud &cloud) const
Definition CCStructures.h:1036
void reconstruct() const
Definition CCStructures.h:1005
vector_real_function_3d operator()(const CC_vecfunction &f, const PotentialType &type, const bool throw_if_empty) const
fetches the correct stored potential or throws an exception
Definition CCStructures.cc:125
vector_real_function_3d current_singles_potential_gs_
whole ground state singles potential without fock-residue
Definition CCStructures.h:1083
CCIntermediatePotentials & operator=(const CCIntermediatePotentials &other)=default
void clear_response()
clears only potentials of the response
Definition CCStructures.h:1026
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:1091
vector_real_function_3d current_singles_potential_ex_
whole excited state singles potential without fock-residue
Definition CCStructures.h:1085
bool potential_exists(const PotentialType &type, const FuncType &ftype) const
check if the intermediate potential exists
Definition CCStructures.h:985
void cloud_load(World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
Definition CCStructures.h:1049
CCIntermediatePotentials(const CCIntermediatePotentials &other)=default
CCIntermediatePotentials(const CCParameters &p)
Definition CCStructures.h:975
vector_real_function_3d unprojected_cc2_projector_response_
Definition CCStructures.h:1096
friend hashT hash_value(const CCIntermediatePotentials &ip)
Definition CCStructures.h:1060
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:1087
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:1089
void insert(const vector_real_function_3d &potential, const CC_vecfunction &f, const PotentialType &type)
insert potential
Definition CCStructures.cc:140
void clear_all()
deltes all stored potentials
Definition CCStructures.h:1016
vector_real_function_3d get_potential(const PotentialType &ptype, const FuncType &ftype, const bool throw_if_empty) const
return a vector of the intermediate potentials
Definition CCStructures.cc:97
void output(const std::string &msg) const
structured output
Definition CCStructures.h:1099
Definition CCStructures.h:90
void print_warnings() const
Definition CCStructures.h:116
void warning(const std::string &msg) const
Definition CCStructures.cc:45
void debug_output(const std::string &msg) const
Definition CCStructures.h:100
bool debug
Definition CCStructures.h:96
void subsection(const std::string &msg) const
Definition CCStructures.cc:34
CCMessenger operator<<(const T &t) const
Definition CCStructures.h:121
World & world
Definition CCStructures.h:93
bool scientific
Definition CCStructures.h:95
std::vector< std::string > warnings
collect all warnings that occur to print out at the end of the job
Definition CCStructures.h:128
std::ostream & os
output stream
Definition CCStructures.h:130
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:91
size_t output_prec
Definition CCStructures.h:94
void operator()(const std::string &msg) const
Definition CCStructures.h:98
Definition CCStructures.h:213
double thresh_Ue() const
Definition CCStructures.h:317
double thresh_f12() const
Definition CCStructures.h:315
std::size_t kain_subspace() const
Definition CCStructures.h:367
double tight_thresh_6D() const
Definition CCStructures.h:307
std::size_t iter_max_3D() const
Definition CCStructures.h:329
bool no_compute_cispd() const
Definition CCStructures.h:349
CCParameters(World &world, const commandlineparser &parser)
ctor reading out the input file
Definition CCStructures.h:223
bool no_compute_mp2_constantpart() const
Definition CCStructures.h:341
std::pair< int, int > only_pair() const
Definition CCStructures.h:333
bool kain() const
Definition CCStructures.h:357
bool plot() const
Definition CCStructures.h:355
bool no_compute_response() const
Definition CCStructures.h:343
double thresh_poisson() const
Definition CCStructures.h:313
CCParameters()
Definition CCStructures.h:215
double thresh_bsh_3D() const
Definition CCStructures.h:309
bool no_compute_mp2() const
Definition CCStructures.h:345
double dconv_6D() const
Definition CCStructures.h:325
double econv_pairs() const
Definition CCStructures.h:321
void initialize_parameters()
Definition CCStructures.h:230
bool response() const
Definition CCStructures.h:296
bool decompose_Q() const
Definition CCStructures.h:361
double thresh_bsh_6D() const
Definition CCStructures.h:311
void error(World &world, const std::string &msg) const
Definition CCStructures.h:381
CCParameters(const CCParameters &other)=default
copy constructor
double gamma() const
Definition CCStructures.h:373
double thresh_3D() const
Definition CCStructures.h:301
double tight_thresh_3D() const
Definition CCStructures.h:303
bool no_compute() const
Definition CCStructures.h:337
double dconv_3D() const
Definition CCStructures.h:323
std::size_t iter_max() const
Definition CCStructures.h:327
double lo() const
Definition CCStructures.h:297
long freeze() const
Definition CCStructures.h:369
double thresh_6D() const
Definition CCStructures.h:305
bool no_compute_cc2() const
Definition CCStructures.h:347
std::vector< std::size_t > excitations() const
Definition CCStructures.h:371
void set_derived_values()
Definition CCStructures.cc:159
bool QtAnsatz() const
Definition CCStructures.h:363
bool test() const
Definition CCStructures.h:359
double dmin() const
Definition CCStructures.h:299
std::size_t output_prec() const
Definition CCStructures.h:365
bool restart() const
Definition CCStructures.h:335
double econv() const
Definition CCStructures.h:319
std::size_t iter_max_6D() const
Definition CCStructures.h:331
CalcType calc_type() const
Definition CCStructures.h:283
bool no_compute_gs() const
Definition CCStructures.h:339
bool debug() const
Definition CCStructures.h:353
void information(World &world) const
print out the parameters
Definition CCStructures.cc:191
bool no_compute_lrcc2() const
Definition CCStructures.h:351
size_t warning(World &world, const std::string &msg) const
Definition CCStructures.h:388
void sanity_check(World &world) const
check if parameters are set correct
Definition CCStructures.cc:202
print accumulated size of all functions
Definition CCStructures.h:1438
void print(World &world, const std::string msg="") const
Definition CCStructures.h:1462
CCSize()=default
double size_local
Definition CCStructures.h:1439
void add_helper(const std::vector< CCPair > &vp)
Definition CCStructures.h:1448
void add(const Args &... args)
variadic template parameters to add the size of all functions and pairs
Definition CCStructures.h:1458
void add_helper(const std::vector< Function< T, NDIM > > &v)
Definition CCStructures.h:1444
Timer Structure.
Definition CCStructures.h:135
std::pair< double, double > current_time(bool printout=false)
Definition CCStructures.h:188
CCTimer(World &world, std::string msg)
Definition CCStructures.h:139
void print() const
Definition CCStructures.h:197
std::string operation
Definition CCStructures.h:146
double start_cpu
Definition CCStructures.h:145
double time_wall
Definition CCStructures.h:149
double get_wall_time_diff() const
Definition CCStructures.h:184
void update_time()
Definition CCStructures.h:152
CCTimer stop()
Definition CCStructures.h:168
CCTimer start()
Definition CCStructures.h:162
void print()
Definition CCStructures.h:193
double time_cpu
Definition CCStructures.h:150
double start_wall
Definition CCStructures.h:144
double get_cpu_time_diff() const
Definition CCStructures.h:186
void print(const std::pair< double, double > &times) const
Definition CCStructures.h:201
double reset()
Definition CCStructures.h:176
World & world
Definition CCStructures.h:143
double end_wall
Definition CCStructures.h:147
double end_cpu
Definition CCStructures.h:148
A helper structure which holds a map of functions.
Definition CCStructures.h:523
std::string irrep
Definition CCStructures.h:666
hashT hash() const
Definition CCStructures.h:652
CC_vecfunction(const vector_real_function_3d &v, const FuncType &type, const size_t &freeze)
Definition CCStructures.h:550
std::map< std::size_t, CCFunction< double, 3 > > CC_functionmap
Definition CCStructures.h:659
CC_vecfunction(const CC_vecfunction &other)
copy ctor (shallow)
Definition CCStructures.h:566
const CCFunction< double, 3 > & operator()(const CCFunction< double, 3 > &i) const
getter
Definition CCStructures.h:678
void insert(const size_t &i, const CCFunction< double, 3 > &f)
setter
Definition CCStructures.h:698
CC_vecfunction(const vector_real_function_3d &v, const FuncType &type)
Definition CCStructures.h:542
static CC_vecfunction load_restartdata(World &world, std::string filename)
Definition CCStructures.h:614
const CCFunction< double, 3 > & operator()(const size_t &i) const
getter
Definition CCStructures.h:683
CC_vecfunction operator*(const double &fac) const
scalar multiplication
Definition CCStructures.h:728
double delta
Definition CCStructures.h:665
CCFunction< double, 3 > & operator()(const size_t &i)
getter
Definition CCStructures.h:693
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
CC_vecfunction(const std::vector< CCFunction< double, 3 > > &v)
Definition CCStructures.h:536
bool operator<(const CC_vecfunction &b) const
operator needed for sort operation (sorted by omega values)
Definition CCStructures.h:742
CC_vecfunction(const FuncType type_)
Definition CCStructures.h:527
void serialize(const Archive &ar)
Definition CCStructures.h:627
CC_vecfunction(const std::vector< CCFunction< double, 3 > > &v, const FuncType type_)
Definition CCStructures.h:560
CC_vecfunction(const vector_real_function_3d &v)
Definition CCStructures.h:529
CC_vecfunction()
Definition CCStructures.h:525
void set_functions(const vector_real_function_3d &v, const FuncType &type, const size_t &freeze)
setter
Definition CCStructures.h:703
CCFunction< double, 3 > & operator()(const CCFunction< double, 3 > &i)
getter
Definition CCStructures.h:688
void scale(const double &factor)
scaling (inplace)
Definition CCStructures.h:735
void plot(const std::string &msg="") const
Definition CCStructures.h:745
FuncType type
Definition CCStructures.h:662
double current_error
excitation energy
Definition CCStructures.h:664
friend CC_vecfunction copy(const CC_vecfunction &other)
returns a deep copy (void shallow copy errors)
Definition CCStructures.h:588
size_t size() const
Get the size vector (number of functions in the map)
Definition CCStructures.h:719
CC_vecfunction & operator=(const CC_vecfunction &other)
assignment operator, shallow wrt the functions
Definition CCStructures.h:574
double omega
Definition CCStructures.h:663
bool is_converged(const double econv, const double dconv) const
Definition CCStructures.h:673
vector_real_function_3d get_vecfunction() const
Returns all the functions of the map as vector.
Definition CCStructures.h:712
void save_restartdata(World &world, std::string filename) const
Definition CCStructures.h:621
CC_functionmap functions
Definition CCStructures.h:660
std::string name(const int ex) const
excitation irrep (direct product of x function and corresponding orbital)
Definition CCStructures.h:669
void reconstruct() const
Definition CCStructures.h:597
POD holding some basic functions and some intermediates for the CC2 calculation.
Definition CCStructures.h:1108
void reconstruct() const
Definition CCStructures.h:1131
std::vector< Function< double, 3 > > mo_ket
Definition CCStructures.h:1109
Recordlist< Cloud::keyT > cloud_store(World &world, Cloud &cloud) const
customized function to store this to the cloud
Definition CCStructures.h:1144
Tensor< double > fock
Definition CCStructures.h:1114
Function< double, 3 > R
Definition CCStructures.h:1116
std::vector< Function< double, 3 > > U1
Definition CCStructures.h:1117
CCIntermediatePotentials intermediate_potentials
Definition CCStructures.h:1115
Function< double, 3 > U2
Definition CCStructures.h:1116
std::vector< madness::Vector< double, 3 > > molecular_coordinates
Definition CCStructures.h:1111
std::vector< double > orbital_energies
Definition CCStructures.h:1113
std::vector< Function< double, 3 > > mo_bra
Definition CCStructures.h:1110
CCParameters parameters
Definition CCStructures.h:1112
vector_real_function_3d get_active_mo_bra() const
Definition CCStructures.h:1125
void cloud_load(World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
customized function to load this from the cloud
Definition CCStructures.h:1163
Function< double, 3 > R_square
Definition CCStructures.h:1116
vector_real_function_3d get_active_mo_ket() const
Definition CCStructures.h:1119
Definition CCStructures.h:395
static PairVectorMap triangular_map(const int nfreeze, const int nocc)
Definition CCStructures.h:401
void print(const std::string msg="PairVectorMap") const
Definition CCStructures.h:421
std::vector< std::pair< int, int > > map
maps pair index (i,j) to vector index k
Definition CCStructures.h:397
static PairVectorMap quadratic_map(const int nfreeze, const int nocc)
Definition CCStructures.h:411
PairVectorMap(const std::vector< std::pair< int, int > > map1)
Definition CCStructures.h:399
Definition CCStructures.h:435
void swap(Pairs< T > &other)
swap the contant of the pairmap
Definition CCStructures.h:491
pairmapT allpairs
Definition CCStructures.h:438
static Pairs vector2pairs(const std::vector< T > &argument, const PairVectorMap map)
Definition CCStructures.h:454
Pairs< R > convert(const Pairs< T > arg, const opT op) const
convert Pairs<T> to another type
Definition CCStructures.h:444
std::map< std::pair< int, int >, T > pairmapT
Definition CCStructures.h:437
bool empty() const
Definition CCStructures.h:495
T & operator()(int i, int j)
getter
Definition CCStructures.h:478
void insert(int i, int j, const T &pair)
Definition CCStructures.h:485
const T & operator()(int i, int j) const
getter
Definition CCStructures.h:471
static std::vector< T > pairs2vector(const Pairs< T > &argument, const PairVectorMap map)
Definition CCStructures.h:462
Definition cloud.h:34
very simple command line parser
Definition commandlineparser.h:15
Definition lowrankfunction.h:332
static double current_time
Definition tdse1d.cc:160
InputParameters param
Definition tdse.cc:203
double norm(const T i1)
Definition test_cloud.cc:72
constexpr std::size_t NDIM
Definition testgconv.cc:54
double h(const coord_1d &r)
Definition testgconv.cc:175