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/// Type of Pairs used by CC_Pair2 class
30
31/// CC2 Singles Potentials
51
52/// Assigns strings to enums for formated output
53std::string
54assign_name(const CCState& input);
55
56/// Assigns enum to string
58assign_calctype(const std::string name);
59
60/// Assigns strings to enums for formated output
61std::string
62assign_name(const CalcType& inp);
63
64/// Assigns strings to enums for formated output
65std::string
66assign_name(const PotentialType& inp);
67
68/// Assigns strings to enums for formated output
69std::string
70assign_name(const FuncType& inp);
71
72/// check memory usage using getrusage
73inline void print_memory_usage(const World& world) {
74 long mem=get_memory_usage();
75 std::string hostname=get_hostname();
76 std::stringstream ss;
77 ss << "memory usage of process "<< world.rank()<< " on "<< hostname<< ": "<< mem/1024/1024<<"MB";
78 std::string msg=ss.str();
79 auto memusage=world.gop.concat0(std::vector<std::string>(1,msg));
80 std::sort(memusage.begin(),memusage.end());
81 if (world.rank()==0) for (const auto& msg : memusage) print(msg);
82}
83
84// Little structure for formated output and to collect warnings
85// much room to improve
87 CCMessenger(World& world) : world(world), output_prec(10), scientific(true), debug(false), os(std::cout) {}
88
92 bool debug;
93
94 void operator()(const std::string& msg) const { output(msg); }
95
96 void debug_output(const std::string& msg) const {
97 if (debug) output(msg);
98 }
99
100 void
101 output(const std::string& msg) const;
102
103 void
104 section(const std::string& msg) const;
105
106 void
107 subsection(const std::string& msg) const;
108
109 void
110 warning(const std::string& msg) const;
111
112 void print_warnings() const {
113 for (const auto& x:warnings) if (world.rank() == 0) std::cout << x << "\n";
114 }
115
116 template<class T>
117 CCMessenger operator<<(const T& t) const {
118 using madness::operators::operator<<;
119 if (world.rank() == 0) os << t;
120 return *this;
121 }
122
123 /// collect all warnings that occur to print out at the end of the job
124 mutable std::vector<std::string> warnings;
125 /// output stream
126 std::ostream& os;
127};
128
129
130/// Timer Structure
131struct CCTimer {
132 /// TDA_TIMER constructor
133 /// @param[in] world the world
134 /// @param[in] msg a string that contains the desired printout when info function is called
136 operation(msg), end_wall(0.0), end_cpu(0.0), time_wall(-1.0),
137 time_cpu(-1.0) {}
138
141 double start_cpu;
142 std::string operation;
143 double end_wall;
144 double end_cpu;
145 double time_wall;
146 double time_cpu;
147
152
153public:
154 /// print out information about the passed time since the CC_TIMER object was created
155 void
156 info(const bool debug = true, const double norm = 12345.6789);
157
161 return *this;
162 }
163
166 end_cpu = cpu_time();
169 return *this;
170 }
171
172 double reset() {
173 stop();
174 double wtime=time_wall;
175 start();
176 return wtime;
177 }
178
179
180 double get_wall_time_diff() const { return end_wall; }
181
182 double get_cpu_time_diff() const { return end_cpu; }
183
184 std::pair<double, double> current_time(bool printout = false) {
185 if (time_wall < 0.0 or time_cpu < 0.0) stop();
186 return std::make_pair(time_wall, time_cpu);
187 }
188
189 void print() {
191 }
192
193 void print() const {
194 print(std::make_pair(time_wall, time_cpu));
195 }
196
197 void print(const std::pair<double, double>& times) const {
198 if (world.rank() == 0) {
199 std::cout << std::setfill(' ') << std::scientific << std::setprecision(2)
200 << "Timer: " << times.first << " (Wall), " << times.second << " (CPU)" << ", (" + operation + ")"
201 << "\n";
202 }
203 }
204};
205
207
208 std::vector<std::pair<int, int>> map; ///< maps pair index (i,j) to vector index k
209 PairVectorMap() = default;
210 PairVectorMap(const std::vector<std::pair<int, int>> map1) : map(map1) {}
211
212 static PairVectorMap triangular_map(const int nfreeze, const int nocc) {
213 std::vector<std::pair<int, int>> map; ///< maps pair index (i,j) to vector index k
214 for (int i=nfreeze; i<nocc; ++i) {
215 for (int j=i; j<nocc; ++j) {
216 map.push_back(std::make_pair(i,j));
217 }
218 }
219 return PairVectorMap(map);
220 }
221
222 static PairVectorMap quadratic_map(const int nfreeze, const int nocc) {
223 std::vector<std::pair<int, int>> map; ///< maps pair index (i,j) to vector index k
224 for (int i=nfreeze; i<nocc; ++i) {
225 for (int j=nfreeze; j<nocc; ++j) {
226 map.push_back(std::make_pair(i,j));
227 }
228 }
229 return PairVectorMap(map);
230 }
231
232 void print(const std::string msg="PairVectorMap") const {
233 madness::print(msg);
234 madness::print("vector element <-> pair index");
235 for (size_t i=0; i<map.size(); ++i) {
236 madness::print(i, " <-> ",map[i]);
237 }
238 }
239
240};
241
242/// POD holding all electron pairs with easy access
243/// Similar strucutre than the Pair structure from MP2 but with some additional features (merge at some point)
244/// This structure will also be used for intermediates
245template<typename T>
246struct Pairs {
247
248 typedef std::map<std::pair<int, int>, T> pairmapT;
250
251 /// convert Pairs<T> to another type
252
253 /// opT op takes an object of T and returns the result type
254 template<typename R, typename opT>
255 Pairs<R> convert(const Pairs<T> arg, const opT op) const {
256 Pairs<R> result;
257 for (auto& p : arg.allpairs) {
258 int i=p.first.first;
259 int j=p.first.second;
260 result.insert(i,j,op(p.second));
261 }
262 return result;
263 }
264
265 static Pairs vector2pairs(const std::vector<T>& argument, const PairVectorMap map) {
266 Pairs<T> pairs;
267 for (int i=0; i<argument.size(); ++i) {
268 pairs.insert(map.map[i].first,map.map[i].second,argument[i]);
269 }
270 return pairs;
271 }
272
273 static std::vector<T> pairs2vector(const Pairs<T>& argument, const PairVectorMap map) {
274 std::vector<T> vector;
275 for (size_t i=0; i<argument.allpairs.size(); ++i) {
276 vector.push_back(argument(map.map[i].first,map.map[i].second));
277 }
278 return vector;
279 }
280
281 /// getter
282 const T& operator()(int i, int j) const {
283 return allpairs.at(std::make_pair(i, j));
284 }
285
286 /// getter
287 // at instead of [] operator bc [] inserts new element if nothing is found while at throws out of range error
288 // back to before
289 T& operator()(int i, int j) {
290 // return allpairs.at(std::make_pair(i, j));
291 return allpairs[std::make_pair(i, j)];
292 }
293
294 /// setter
295 /// can NOT replace elements (for this construct new pair map and swap the content)
296 void insert(int i, int j, const T& pair) {
297 std::pair<int, int> key = std::make_pair(i, j);
298 allpairs.insert(std::make_pair(key, pair));
299 }
300
301 /// swap the contant of the pairmap
302 void swap(Pairs<T>& other) {
303 allpairs.swap(other.allpairs);
304 }
305
306 bool empty() const {
307 if (allpairs.size() == 0) return true;
308 else return false;
309 }
310};
311
312/// f12 and g12 intermediates of the form <f1|op|f2> (with op=f12 or op=g12) will be saved using the pair structure
313template <typename T, std::size_t NDIM>
315
316/// Returns the size of an intermediate
317//double
318//size_of(const intermediateT& im);
319/// Returns the size of an intermediate
320template<typename T, std::size_t NDIM>
321double
323 double size = 0.0;
324 for (const auto& tmp : im.allpairs) {
325 size += get_size<T, NDIM>(tmp.second);
326 }
327 return size;
328}
329
330
331
332// structure for CC Vectorfunction
333/// A helper structure which holds a map of functions
335
337
338 CC_vecfunction(const FuncType type_) : type(type_), omega(0.0), current_error(99.9), delta(0.0) {}
339
341 for (size_t i = 0; i < v.size(); i++) {
342 CCFunction<double,3> tmp(v[i], i, type);
343 functions.insert(std::make_pair(i, tmp));
344 }
345 }
346
347 CC_vecfunction(const std::vector<CCFunction<double,3>>& v) : type(UNDEFINED), omega(0.0), current_error(99.9), delta(0.0) {
348 for (size_t i = 0; i < v.size(); i++) {
349 functions.insert(std::make_pair(v[i].i, v[i]));
350 }
351 }
352
354 current_error(99.9), delta(0.0) {
355 for (size_t i = 0; i < v.size(); i++) {
356 CCFunction<double,3> tmp(v[i], i, type);
357 functions.insert(std::make_pair(i, tmp));
358 }
359 }
360
361 CC_vecfunction(const vector_real_function_3d& v, const FuncType& type, const size_t& freeze) : type(type),
362 omega(0.0),
363 current_error(99.9),
364 delta(0.0) {
365 for (size_t i = 0; i < v.size(); i++) {
366 CCFunction<double,3> tmp(v[i], freeze + i, type);
367 functions.insert(std::make_pair(freeze + i, tmp));
368 }
369 }
370
371 CC_vecfunction(const std::vector<CCFunction<double,3>>& v, const FuncType type_)
372 : type(type_), omega(0.0), current_error(99.9), delta(0.0) {
373 for (auto x:v) functions.insert(std::make_pair(x.i, x));
374 }
375
376 /// copy ctor (shallow)
378 : functions(other.functions), type(other.type), omega(other.omega),
380 delta(other.delta), irrep(other.irrep) {
381 }
382
383 /// assignment operator, shallow wrt the functions
384// CC_vecfunction& operator=(const CC_vecfunction& other) = default;
386 if (this == &other) return *this;
387 functions = other.functions;
388 type = other.type;
389 omega = other.omega;
391 delta = other.delta;
392 irrep = other.irrep;
393 return *this;
394 }
395
396
397 /// returns a deep copy (void shallow copy errors)
398 friend CC_vecfunction
399 copy(const CC_vecfunction& other) {
400 CC_vecfunction tmp=other;
401 tmp.functions.clear();
402 for (const auto& x : other.functions) {
403 tmp.functions.insert(std::make_pair(x.first, copy(x.second)));
404 }
405 return tmp;
406 }
407
408 void reconstruct() const {
409 for (auto& x : functions) x.second.function.reconstruct();
410 }
411
412//madness::CC_vecfunction
413//CC_vecfunction::copy() const {
414// std::vector<CCFunction<double,3>> vn;
415// for (auto x : functions) {
416// const CCFunction<double,3> fn(madness::copy(x.second.function), x.second.i, x.second.type);
417// vn.push_back(fn);
418// }
419// CC_vecfunction result(vn, type);
420// result.irrep = irrep;
421// return result;
422//}
423//
424
425 static CC_vecfunction load_restartdata(World& world, std::string filename) {
427 CC_vecfunction tmp;
428 ar & tmp;
429 return tmp;
430 }
431
432 void save_restartdata(World& world, std::string filename) const {
434 ar & *this;
435 }
436
437 template<typename Archive>
438 void serialize(const Archive& ar) {
439 typedef std::vector<std::pair<std::size_t, CCFunction<double,3>>> CC_functionvec;
440
441 auto map2vector = [] (const CC_functionmap& map) {
442 return CC_functionvec(map.begin(), map.end());
443 };
444 auto vector2map = [] (const CC_functionvec& vec) {
445 return CC_functionmap(vec.begin(), vec.end());
446 };
447
448 ar & type & omega & current_error & delta & irrep ;
449 if (ar.is_input_archive) {
450 std::size_t size=0; // set to zero to silence compiler warning
451 ar & size;
452 CC_functionvec tmp(size);
453
454 for (auto& t : tmp) ar & t.first & t.second;
455 functions=vector2map(tmp);
456 } else if (ar.is_output_archive) {
457 auto tmp=map2vector(functions);
458 ar & tmp.size();
459 for (auto& t : tmp) ar & t.first & t.second;
460 }
461 }
462
463 hashT hash() const {
464 hashT hashval = std::hash<FuncType>{}(type);
465 for (const auto& f : functions) hash_combine(hashval, hash_value(f.second.f().get_impl()->id()));
466
467 return hashval;
468 }
469
470 typedef std::map<std::size_t, CCFunction<double,3>> CC_functionmap;
472
474 double omega; /// excitation energy
476 double delta; // Last difference in Energy
477 std::string irrep = "null"; /// excitation irrep (direct product of x function and corresponding orbital)
478
479 std::string
480 name(const int ex) const {
481 return madness::name(type,ex);
482 };
483
484 bool is_converged(const double econv, const double dconv) const {
485 return (current_error<dconv) and (std::fabs(delta)<econv);
486 }
487
488 /// getter
490 return functions.find(i.i)->second;
491 }
492
493 /// getter
494 const CCFunction<double,3>& operator()(const size_t& i) const {
495 return functions.find(i)->second;
496 }
497
498 /// getter
502
503 /// getter
505 return functions[i];
506 }
507
508 /// setter
509 void insert(const size_t& i, const CCFunction<double,3>& f) {
510 functions.insert(std::make_pair(i, f));
511 }
512
513 /// setter
514 void set_functions(const vector_real_function_3d& v, const FuncType& type, const size_t& freeze) {
515 functions.clear();
516 for (size_t i = 0; i < v.size(); i++) {
517 CCFunction<double,3> tmp(v[i], freeze + i, type);
518 functions.insert(std::make_pair(freeze + i, tmp));
519 }
520 }
521
522 /// Returns all the functions of the map as vector
525 for (auto x:functions) tmp.push_back(x.second.function);
526 return tmp;
527 }
528
529 /// Get the size vector (number of functions in the map)
530 size_t size() const {
531 return functions.size();
532 }
533
534 /// Print the memory of which is used by all the functions in the map
535 void
536 print_size(const std::string& msg = "!?not assigned!?") const;
537
538 /// scalar multiplication
539 CC_vecfunction operator*(const double& fac) const {
541 const size_t freeze = functions.cbegin()->first;
542 return CC_vecfunction(vnew, type, freeze);
543 }
544
545 /// scaling (inplace)
546 void scale(const double& factor) {
547 for (auto& ktmp:functions) {
548 ktmp.second.function.scale(factor);
549 }
550 }
551
552 /// operator needed for sort operation (sorted by omega values)
553 bool operator<(const CC_vecfunction& b) const { return omega < b.omega; }
554
555 // plotting
556 void plot(const std::string& msg = "") const {
557 for (auto& ktmp:functions) {
558 ktmp.second.plot(msg);
559 }
560 }
561public:
562 NLOHMANN_DEFINE_TYPE_INTRUSIVE(CC_vecfunction, omega, irrep, current_error)
563
564};
565
566/// Helper Structure that carries out operations on CC_functions
567/// The structure can hold intermediates for g12 and f12 of type : <mo_bra_k|op|type> with type=HOLE,PARTICLE or RESPONSE
568/// some 6D operations are also included
569/// The structure does not know if nuclear correlation facors are used, so the corresponding bra states have to be prepared beforehand
570template<typename T=double, std::size_t NDIM=3>
572public:
573
574 /// parameter class
575 struct Parameters {
577
578 Parameters(const Parameters& other) :
579 thresh_op(other.thresh_op),
580 lo(other.lo),
581 freeze(other.freeze),
582 gamma(other.gamma) {
583 }
584
585 Parameters(const CCParameters& param) : thresh_op(param.thresh_poisson()), lo(param.lo()),
587 gamma(param.gamma()) {};
589 double lo = 1.e-6;
590 int freeze = 0;
591 double gamma = 1.0; /// f12 exponent
592
593 template<typename archiveT>
594 void serialize(archiveT& ar) {
595 ar & thresh_op & lo & freeze & gamma;
596 }
597 };
598
599
600 /// @param[in] world
601 /// @param[in] optype: the operatortype (can be g12_ or f12_)
602 /// @param[in] param: the parameters of the current CC-Calculation (including function and operator thresholds and the exponent for f12)
606
608
609 static inline
610 std::shared_ptr<CCConvolutionOperator> CCConvolutionOperatorPtr(World& world, const OpType type, Parameters param) {
611 return std::shared_ptr<CCConvolutionOperator>(new CCConvolutionOperator(world, type, param));
612 }
613
614protected:
615
617 auto info= SeparatedConvolution<T,NDIM>::combine_OT((*a.get_op()),(*b.get_op()));
619 param.gamma=info.mu;
620 param.thresh_op=info.thresh;
621 param.lo=info.lo;
622 param.freeze=a.parameters.freeze;
623 return CCConvolutionOperator(a.world, info.type, param);
624 }
625
626 friend std::shared_ptr<CCConvolutionOperator> combine(const std::shared_ptr<CCConvolutionOperator>& a,
627 const std::shared_ptr<CCConvolutionOperator>& b) {
628 if (a and (not b)) return a;
629 if ((not a) and b) return b;
630 if ((not a) and (not b)) return nullptr;
631 return std::shared_ptr<CCConvolutionOperator>(new CCConvolutionOperator(combine(*a,*b)));
632 }
633
634public:
635 /// @param[in] f: a 3D function
636 /// @param[out] the convolution op(f), no intermediates are used
638 if (op) return ((*op)(f)).truncate();
639 return f;
640 }
641
642 /// @param[in] bra a CC_vecfunction
643 /// @param[in] ket a CC_function
644 /// @param[out] vector[i] = <bra[i]|op|ket>
645 std::vector<Function<T,NDIM>> operator()(const CC_vecfunction& bra, const CCFunction<T,NDIM>& ket) const {
647 std::vector<Function<T, NDIM>> result;
648 if constexpr (NDIM == 3) {
649 if (bra.type == HOLE) {
650 for (const auto& ktmp: bra.functions) {
651 const CCFunction<T, NDIM>& brai = ktmp.second;
652 const Function<T, NDIM> tmpi = this->operator()(brai, ket);
653 result.push_back(tmpi);
654 }
655 } else {
656 std::vector<Function<T, NDIM>> tmp = mul(world, ket.function, bra.get_vecfunction());
657 result = apply(world, (*op), tmp);
658 truncate(world, result);
659 }
660 } else {
661 MADNESS_EXCEPTION("not implemented", 1);
662 }
663
664 return result;
665 }
666
667 // @param[in] f: a vector of 3D functions
668 // @param[out] the convolution of op with each function, no intermeditates are used
669 std::vector<Function<T,NDIM>> operator()(const std::vector<Function<T,NDIM>>& f) const {
671 return apply<T,T,NDIM,NDIM>(world, (*op), f);
672 }
673
674 // @param[in] bra: a 3D CC_function, if nuclear-correlation factors are used they have to be applied before
675 // @param[in] ket: a 3D CC_function,
676 // @param[in] use_im: default is true, if false then no intermediates are used
677 // @param[out] the convolution <bra|op|ket> = op(bra*ket), if intermediates were calculated before the operator uses them
678 Function<T,NDIM> operator()(const CCFunction<T,NDIM>& bra, const CCFunction<T,NDIM>& ket, const bool use_im = true) const;
679
680 // @param[in] u: a 6D-function
681 // @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)
682 // @param[in] particle: specifies on which particle of u the operator will act (particle ==1 or particle==2)
683 Function<T,2*NDIM> operator()(const Function<T,2*NDIM>& u, const size_t particle) const;
684
685 // @param[in] bra: a 3D-CC_function, if nuclear-correlation factors are used they have to be applied before
686 // @param[in] u: a 6D-function
687 // @param[in] particle: specifies on which particle of u the operator will act (particle ==1 or particle==2)
688 // @param[out] the convolution <bra|g12|u>_particle
689 Function<T,NDIM> operator()(const CCFunction<T,NDIM>& bra, const Function<T,2*NDIM>& u, const size_t particle) const;
690
691 /// @param[in] bra: a vector of CC_functions, the type has to be HOLE
692 /// @param[in] ket: a vector of CC_functions, the type can be HOLE,PARTICLE,RESPONSE
693 /// updates intermediates of the type <bra|op|ket>
694 void update_elements(const CC_vecfunction& bra, const CC_vecfunction& ket);
695
696 /// @param[out] prints the name of the operator (convenience) which is g12 or f12 or maybe other things like gf in the future
697 std::string name() const {
698 std::stringstream ss;
699 ss << type();
700 return ss.str();
701 }
702
703 /// @param[in] the type of which intermediates will be deleted
704 /// e.g if(type==HOLE) then all intermediates of type <mo_bra_k|op|HOLE> will be deleted
705 void clear_intermediates(const FuncType& type);
706
707 /// prints out information (operatorname, number of stored intermediates ...)
708 size_t info() const;
709
711 hashT h;
712 hash_combine(h, op.parameters.thresh_op);
713 hash_combine(h, op.parameters.lo);
714 hash_combine(h, op.parameters.freeze);
715 hash_combine(h, op.parameters.gamma);
716 hash_combine(h, int(op.type()));
717 return h;
718 }
719
720 /// sanity check .. doens not do so much
721 void sanity() const { print_intermediate(HOLE); }
722
723 /// @param[in] type: the type of intermediates which will be printed, can be HOLE,PARTICLE or RESPONSE
724 void print_intermediate(const FuncType type) const {
725 if (type == HOLE)
726 for (const auto& tmp:imH.allpairs)
727 tmp.second.print_size("<H" + std::to_string(tmp.first.first) + "|" + name() + "|H" +
728 std::to_string(tmp.first.second) + "> intermediate");
729 else if (type == PARTICLE)
730 for (const auto& tmp:imP.allpairs)
731 tmp.second.print_size("<H" + std::to_string(tmp.first.first) + "|" + name() + "|P" +
732 std::to_string(tmp.first.second) + "> intermediate");
733 else if (type == RESPONSE)
734 for (const auto& tmp:imR.allpairs)
735 tmp.second.print_size("<H" + std::to_string(tmp.first.first) + "|" + name() + "|R" +
736 std::to_string(tmp.first.second) + "> intermediate");
737 }
738
739 /// create a TwoElectronFactory with the operatorkernel
742 factory.set_info(op->info);
743 return factory;
744 }
745
746 OpType type() const { return get_op()->info.type; }
747
749
750 std::shared_ptr<SeparatedConvolution<T,NDIM>> get_op() const {return op;};
751
752private:
753 /// the world
755
756 /// @param[in] optype: can be f12_ or g12_ depending on which operator shall be intitialzied
757 /// @param[in] parameters: parameters (thresholds etc)
758 /// initializes the operators
760
761 std::shared_ptr<SeparatedConvolution<T,NDIM>> op;
765
766 /// @param[in] msg: output message
767 /// the function will throw an MADNESS_EXCEPTION
768 void error(const std::string& msg) const {
769 if (world.rank() == 0)
770 std::cout << "\n\n!!!!ERROR in CCConvolutionOperator " << name() << ": " << msg
771 << "!!!!!\n\n" << std::endl;
772 MADNESS_EXCEPTION(msg.c_str(), 1);
773 }
774public:
775};
776
777template<typename T, std::size_t NDIM>
778std::shared_ptr<CCConvolutionOperator<T,NDIM>> CCConvolutionOperatorPtr(World& world, const OpType type,
780 return std::shared_ptr<CCConvolutionOperator<T,NDIM>>(new CCConvolutionOperator<T,NDIM>(world,type,param));
781}
782
783/// little helper structure which manages the stored singles potentials
789
790 /// check if the intermediate potential exists
792 return potential_exists(type,f.type);
793 }
794
795 /// check if the intermediate potential exists
796 bool potential_exists(const PotentialType& type,const FuncType& ftype) const {
797 bool exists=get_potential(type,ftype,false).size()>0;
798 return exists;
799 }
800
801 /// return a vector of the intermediate potentials
802
803 /// @param[in] ptype: the potential type (POT_SINGLES, POT_S2B, ..)
804 /// @param[in] ftype: the function type (HOLE, PARTICLE, RESPONSE)
806 get_potential(const PotentialType& ptype, const FuncType& ftype, const bool throw_if_empty) const;
807
808 /// fetches the correct stored potential or throws an exception
810 operator()(const CC_vecfunction& f, const PotentialType& type, const bool throw_if_empty) const;
811
812 /// fetch the potential for a single function
814 operator()(const CCFunction<double,3>& f, const PotentialType& type, const bool throw_if_empty) const;
815
825
826 /// deltes all stored potentials
835
836 /// clears only potentials of the response
842
843 /// insert potential
844 void
846
849 records+=cloud.store(world,parameters);
850 records+=cloud.store(world,current_s2b_potential_ex_);
851 records+=cloud.store(world,current_s2b_potential_gs_);
852 records+=cloud.store(world,current_s2c_potential_ex_);
853 records+=cloud.store(world,current_s2c_potential_gs_);
854 records+=cloud.store(world,current_singles_potential_ex_);
855 records+=cloud.store(world,current_singles_potential_gs_);
856 records+=cloud.store(world,unprojected_cc2_projector_response_);
857 return records;
858 }
859
870
872 auto hash_vector_of_functions =[](const vector_real_function_3d& v) {
873 hashT h;
874 for (const auto& f : v) {
875 hash_combine(h, hash_value(f.get_impl()->id()));
876 }
877 return h;
878 };
879 hashT h;
880 hash_combine(h, hash_vector_of_functions(ip.current_s2b_potential_ex_));
881 hash_combine(h, hash_vector_of_functions(ip.current_s2b_potential_gs_));
882 hash_combine(h, hash_vector_of_functions(ip.current_s2c_potential_ex_));
883 hash_combine(h, hash_vector_of_functions(ip.current_s2c_potential_gs_));
884 hash_combine(h, hash_vector_of_functions(ip.current_singles_potential_ex_));
885 hash_combine(h, hash_vector_of_functions(ip.current_singles_potential_gs_));
886 hash_combine(h, hash_vector_of_functions(ip.unprojected_cc2_projector_response_));
887 return h;
888 }
889
891private:
892 // World& world;
893 /// whole ground state singles potential without fock-residue
895 /// whole excited state singles potential without fock-residue
897 /// s2b_potential for the pure 6D-part of the ground-state (expensive and constant during singles iterations)
899 /// s2b_potential for the pure 6D-part of the excited-state (expensive and constant during singles iterations)
901 /// s2c_potential for the pure 6D-part of the ground-state (expensive and constant during singles iterations)
903 /// s2c_potential for the pure 6D-part of the excited_state (expensive and constant during singles iterations)
905 /// unprojected S3c + S5c + S2b + S2c potential of CC2 singles
906 /// for the projector response of the CC2 singles potential
908
909 /// structured output
910 void output(const std::string& msg) const {
911 if (parameters.debug())
912 std::cout << "Intermediate Potential Manager: " << msg << "\n";
913 }
914};
915
916/// POD holding some basic functions and some intermediates for the CC2 calculation
917
918/// the class is cloud-serializable and can be used in MacroTasks
919struct Info {
920 std::vector<Function<double,3>> mo_ket;
921 std::vector<Function<double,3>> mo_bra;
922 std::vector<madness::Vector<double,3>> molecular_coordinates;
924 std::vector<double> orbital_energies;
928 std::vector<Function<double,3>> U1;
929
932 for (size_t i = parameters.freeze(); i < mo_ket.size(); i++) result.push_back(mo_ket[i]);
933 return result;
934 }
935
938 for (size_t i = parameters.freeze(); i < mo_bra.size(); i++) result.push_back(mo_bra[i]);
939 return result;
940 }
941
951
952 /// customized function to store this to the cloud
953
954 /// functions and constant_part can be very large and we want to split them and store them in different records
957 records+=cloud.store(world,mo_bra);
958 records+=cloud.store(world,mo_ket);
959 records+=cloud.store(world,parameters);
960 records+=cloud.store(world,orbital_energies);
961 records+=cloud.store(world,fock);
962 records+=cloud.store(world,intermediate_potentials);
963 records+=cloud.store(world,R_square);
964 records+=cloud.store(world,molecular_coordinates);
965 records+=cloud.store(world,U2);
966 records+=cloud.store(world,U1);
967 return records;
968 }
969
970 /// customized function to load this from the cloud
971
972 /// functions and constant_part can be very large and we want to split them and store them in different records
973 /// @param[inout] recordlist: containing the keys of the member variables -> will be reduced by the keys which are used
974 void cloud_load(World& world, const Cloud& cloud, Recordlist<Cloud::keyT>& recordlist) {
975 // load bookkeeping stuff in a vector
976 mo_bra=cloud.forward_load<std::vector<Function<double,3>>>(world,recordlist);
977 mo_ket=cloud.forward_load<std::vector<Function<double,3>>>(world,recordlist);
978 parameters=cloud.forward_load<CCParameters>(world,recordlist);
979 orbital_energies=cloud.forward_load<std::vector<double>>(world,recordlist);
980 fock=cloud.forward_load<Tensor<double>>(world,recordlist);
982 R_square=cloud.forward_load<Function<double,3>>(world,recordlist);
983 molecular_coordinates=cloud.forward_load<std::vector<madness::Vector<double,3>>>(world,recordlist);
984 U2=cloud.forward_load<Function<double,3>>(world,recordlist);
985 U1=cloud.forward_load<std::vector<Function<double,3>>>(world,recordlist);
986 }
987
988};
989
990
992public:
993 CCPair() = default;
994
995 CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c)
996 : type(t), ctype(c), i(ii), j(jj), bsh_eps(12345.6789) {};
997
998 CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c,
999 const std::vector<CCPairFunction<double,6>>& f)
1000 : type(t), ctype(c), i(ii), j(jj), functions(f), bsh_eps(12345.6789) {};
1001
1002 CCPair(const CCPair& other) : type(other.type), ctype(other.ctype), i(other.i), j(other.j),
1004 bsh_eps(other.bsh_eps) {};
1005
1008 size_t i;
1009 size_t j;
1010
1011 /// customized function to store this to the cloud
1012
1013 /// functions and constant_part can be very large and we want to split them and store them in different records
1014 /// *NOTE* only the 6d function and the constant part are stored in the cloud, not the 3d functions *NOTE*
1016 // save bookkeeping stuff in a vector
1017 std::vector<unsigned char> v;
1019 bool function_is_assigned=(functions.size()>0 && functions[0].is_assigned());
1020 arout & type & ctype & i & j & bsh_eps & function_is_assigned & constant_part.is_initialized();
1021
1023 records+=cloud.store(world,v);
1024 if (function_is_assigned) records+=cloud.store(world,functions[0]);
1025 if (constant_part.is_initialized()) records+=cloud.store(world,constant_part);
1026 return records;
1027 }
1028
1029 /// customized function to load this from the cloud
1030
1031 /// functions and constant_part can be very large and we want to split them and store them in different records
1032 /// @param[inout] recordlist: containing the keys of the member variables -> will be reduced by the keys which are used
1033 void cloud_load(World& world, const Cloud& cloud, Recordlist<Cloud::keyT>& recordlist) {
1034 // load bookkeeping stuff in a vector
1035 std::vector<unsigned char> v=cloud.forward_load<std::vector<unsigned char>>(world,recordlist);
1037 bool function_is_assigned = false, constant_part_is_initialized=false;
1038 arin & type & ctype & i & j & bsh_eps & function_is_assigned & constant_part_is_initialized;
1039 functions.clear();
1041
1042 if (function_is_assigned) functions.emplace_back(cloud.forward_load<CCPairFunction<double,6>>(world,recordlist));
1043 if (constant_part_is_initialized) constant_part=cloud.forward_load<real_function_6d>(world,recordlist);
1044 }
1045
1046 /// return the world of the function
1047 World& world() const {
1048 MADNESS_CHECK_THROW(function_exists(), "no function assigned in CCPair::world()");
1049 return function().world();
1050 }
1051
1052 /// check if the pair has a function assigned
1053 bool function_exists() const {
1054 return (functions.size()>0 and functions[0].is_assigned() and functions[0].is_pure());
1055 }
1056
1057 /// gives back the pure 6D part of the pair function
1059 MADNESS_CHECK_THROW(not functions.empty(), "no function assigned in CCPair::function()");
1060 MADNESS_CHECK_THROW(functions[0].is_pure(),"function is not pure in CCPair::function()");
1061 return functions[0].get_function();
1062 }
1063
1064 /// updates the pure 6D part of the pair function
1066 // print("updating u(",i,j,")");
1067 CCPairFunction tmp(u);
1068 if (functions.size() == 0) functions.push_back(tmp);
1069 else { //(functions.size() > 1) {
1070 MADNESS_CHECK_THROW(functions[0].is_pure(),"function is not pure in CCPair::update_u()");
1071 functions[0]=tmp;
1072 }
1073 }
1074
1075 template<typename Archive>
1076 void serialize(const Archive& ar) {
1077 size_t f_size = functions.size();
1078 bool fexist = (f_size > 0) && (functions[0].get_function().is_initialized());
1079 bool cexist = constant_part.is_initialized();
1080 ar & type & ctype & i & j & bsh_eps & fexist & cexist & f_size;
1081 if constexpr (Archive::is_input_archive) {
1082 if (fexist) {
1084 ar & func;
1086 functions.push_back(f1);
1087 }
1088 } else {
1089 if (fexist) ar & functions[0].get_function();
1090 }
1091 if (cexist) ar & constant_part;
1092 }
1093
1094 /// reconstruct constant part and all functions
1095 void reconstruct() const {
1097 for (auto& f : functions) {
1098 if (f.is_assigned() and f.is_pure()) f.get_function().reconstruct();
1099 }
1100 }
1101
1102 bool load_pair(World& world, const bool verbose=false) {
1103 std::string fname=this->name();
1104 if (verbose and world.rank()==0) print("loading pair from file", fname);
1106 if (exists) {
1108 ar & *this;
1109 if (functions[0].get_function().is_initialized()) functions[0].get_function().set_thresh(FunctionDefaults<6>::get_thresh());
1111 }
1112 return exists;
1113 }
1114
1115 void store_pair(World& world, const bool verbose=false) {
1116 std::string fname =this->name();
1117 if (verbose and world.rank()==0) print("loading pair from file", fname);
1118 this->reconstruct();
1120 ar & *this;
1121 }
1122
1123 hashT hash() const {
1124 hashT hash_i = std::hash<std::size_t>{}(i);
1125 hash_combine(hash_i, std::hash<std::size_t>{}(j));
1128 }
1129 return hash_i;
1130 }
1131
1132 /// the functions which belong to the pair
1133 std::vector<CCPairFunction<double,6>> functions;
1134
1135 /// the constant part
1137
1138 /// Energy for the BSH Operator
1139 /// Ground State: e_i + e_j
1140 /// Excited State: e_i + e_j + omega
1141 /// default to positive value to make sure this is set somewhere
1142 double bsh_eps=1.0;
1143
1144 /// return the base name like "MP2_pair_u" or "CC2_pair_x"
1145 std::string basename() const {
1146 std::string name = "???";
1147 if (type == GROUND_STATE) name = assign_name(ctype) + "_pair_u";
1148 if (type == EXCITED_STATE) name = assign_name(ctype) + "_pair_x";
1149 return name;
1150
1151 }
1152 std::string name() const {
1153 return basename() +"_" + stringify(i) + stringify(j);
1154 }
1155
1156 void
1157 info() const;
1158
1159};
1160
1161/// build an MP2 or CC2 or LRCC2 etc pair, possibly including the lo-rank parts
1163public:
1165
1166 /// provide ground-state singles, needed for CC2 and LRCC2 wave function ansatz
1168 gs_singles = gs;
1169 return *this;
1170 }
1171
1172 /// provide excited state singles, needed for CC2 and LRCC2 wave function ansatz
1174 ex_singles = ex;
1175 return *this;
1176 }
1177
1179 ctype = type;
1180 return *this;
1181 }
1182
1183 /// make a CCPair without the 6d function and some bookkeeping information
1184 CCPair make_bare_pair(const int i, const int j) const;
1185
1186 /// make a CCPair with the 6d function only and some bookkeeping information
1187 CCPair make_bare_pair_from_file(const int i, const int j) const;
1188
1189 /// make a CCPair
1190 CCPair make_pair(const int i, const int j, const std::vector<CCPairFunction<double,6>>& u) const;
1191
1192 inline static CCState cc_state(const CalcType& type) {
1193 if (type==CT_MP2 or type==CT_CC2 or type==CT_MP3) return GROUND_STATE;
1194 else if (type==CT_LRCC2 or type==CT_ADC2 or type==CT_CISPD) return EXCITED_STATE;
1195 else {
1196 MADNESS_EXCEPTION("unknown cc-state",1);
1197 }
1198 }
1199
1200 /// make a CCPair with the 6d function only and some bookkeeping information
1202 Pairs<CCPair> pairs;
1203 for (size_t i = info.parameters.freeze(); i < info.mo_bra.size(); i++) {
1204 for (size_t j = info.parameters.freeze(); j < info.mo_ket.size(); j++) {
1205 pairs.insert(i,j,make_bare_pair(i, j));
1206 }
1207 }
1208 return pairs;
1209 }
1210
1211 /// complete the given pair with the low-rank parts
1212
1213 /// will use pair's ctype, while builder's ctype is ignored
1215
1216
1217 /// Function to load a function from disk
1218
1219 /// @param[in] name of the file in which the function was stored
1220 /// @param do_print
1221 /// @return the function, possibly not initialized if not found on disk
1222 template <typename T, size_t NDIM>
1223 Function<T,NDIM> load_function(const std::string name, bool do_print) const {
1225 bool exists = archive::ParallelInputArchive<
1227 if (exists) {
1228 if ((world.rank() == 0) and do_print) print("loading function", name);
1230 ar & f;
1231 if (do_print) f.print_size(name);
1232 if (f.is_compressed()) {
1233 if (world.rank()==0 and do_print) print("function is compressed -- reconstructing");
1234 f.change_tree_state(reconstructed);
1235 if (do_print) f.print_size(name+" reconstructed");
1236 save(f, name);
1237 }
1239 f.truncate();
1240 f.print_size(name);
1241 } else {
1242 if ((world.rank()==0) and do_print) print("could not find function",name);
1243 }
1244 return f;
1245 }
1246
1248 const Info& info;
1251
1252};
1253
1254
1255/// print accumulated size of all functions
1256struct CCSize {
1257 double size_local=0;
1258
1259 CCSize() = default;
1260
1261 template<typename T, std::size_t NDIM>
1262 void add_helper(const std::vector<Function<T,NDIM>>& v) {
1263 if (v.size()>0) size_local+=get_size_local(v.front().world(),v);
1264 }
1265
1266 void add_helper(const std::vector<CCPair>& vp) {
1267 if (vp.empty()) return;
1268 for (const auto& p : vp) {
1269 size_local+=get_size(p.constant_part);
1270 if (p.function_exists()) size_local+=get_size_local(p.function());
1271 }
1272 }
1273
1274 /// variadic template parameters to add the size of all functions and pairs
1275 template<typename... Args>
1276 void add(const Args&... args) {
1277 (add_helper(args), ...);
1278 }
1279
1280 void print(World& world, const std::string msg="") const {
1281 double size_global=size_local;
1282 world.gop.sum(size_global);
1283 if (msg.size()>0 and world.rank()==0) madness::print(msg);
1284 world.gop.fence();
1285 madness::print("size of all functions on rank",world.rank(),size_local);
1286 world.gop.fence();
1287 if (world.rank()==0) madness::print("total size of all functions",size_global);
1288
1289 }
1290};
1291
1292
1294
1296 public:
1298
1299 partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1300 const std::string policy) const override {
1301 partitionT p;
1302 for (size_t i = 0; i < vsize1; i++) {
1303 Batch batch(Batch_1D(i,i+1), Batch_1D(i,i+1));
1304 p.push_back(std::make_pair(batch,1.0));
1305 }
1306 return p;
1307 }
1308 };
1309
1310public:
1312
1313 // typedef std::tuple<const std::vector<CCPair>&, const std::vector<Function<double,3>>&,
1314 // const std::vector<Function<double,3>>&, const CCParameters&, const Function<double,3>&,
1315 // const std::vector<Function<double,3>>&, const std::vector<std::string>& > argtupleT;
1316 typedef std::tuple<const std::vector<CCPair>&, const madness::Info&, const std::vector<std::string>& > argtupleT;
1317
1318 using resultT = std::vector<real_function_6d>;
1319
1320 resultT allocator(World& world, const argtupleT& argtuple) const {
1321 std::size_t n = std::get<0>(argtuple).size();
1322 resultT result = zero_functions_auto_tree_state<double, 6>(world, n);
1323 return result;
1324 }
1325
1326// resultT operator() (const std::vector<CCPair>& pair, const std::vector<Function<double,3>>& mo_ket,
1327// const std::vector<Function<double,3>>& mo_bra, const CCParameters& parameters,
1328// const Function<double,3>& Rsquare, const std::vector<Function<double,3>>& U1,
1329// const std::vector<std::string>& argument) const;
1330 resultT operator() (const std::vector<CCPair>& pair, const Info& info, const std::vector<std::string>& argument) const;
1331};
1332
1333/// compute the "constant" part of MP2, CC2, or LR-CC2
1334///
1335/// the constant part is
1336/// result = G [F,f] |ij> for MP2
1337/// result = G [F,f] |t_i t_j> for CC2
1338/// result = G [F,f] |t_i x_j> + |x_i t_j> for LR-CC2
1340
1342 public:
1344
1345 partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1346 const std::string policy) const override {
1347 partitionT p;
1348 for (size_t i = 0; i < vsize1; i++) {
1349 Batch batch(Batch_1D(i,i+1), Batch_1D(i,i+1));
1350 p.push_back(std::make_pair(batch,1.0));
1351 }
1352 return p;
1353 }
1354 };
1355
1356public:
1359 name="ConstantPart";
1360 }
1361
1362 // typedef std::tuple<const std::vector<CCPair>&, const std::vector<Function<double,3>>&,
1363 // const std::vector<Function<double,3>>&, const CCParameters&, const Function<double,3>&,
1364 // const std::vector<Function<double,3>>&, const std::vector<std::string>& > argtupleT;
1365 typedef std::tuple<const std::vector<CCPair>&,
1366 const std::vector<Function<double,3>>&, const std::vector<Function<double,3>>&,
1368
1369 using resultT = std::vector<real_function_6d>;
1370
1371 resultT allocator(World& world, const argtupleT& argtuple) const {
1372 std::size_t n = std::get<0>(argtuple).size();
1373 resultT result = zero_functions_auto_tree_state<double, 6>(world, n);
1374 return result;
1375 }
1376 resultT operator() (const std::vector<CCPair>& pair,
1377 const std::vector<Function<double,3>>& gs_singles,
1378 const std::vector<Function<double,3>>& ex_singles,
1379 const Info& info) const;
1380};
1381
1383
1385 public :
1389
1390 partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1391 const std::string policy) const override {
1392 partitionT p;
1393 for (size_t i = 0; i < vsize1; i++) {
1394 Batch batch(Batch_1D(i, i+1), Batch_1D(i, i+1), Batch_1D(i,i+1));
1395 p.push_back(std::make_pair(batch, 1.0));
1396 }
1397 return p;
1398 }
1399 };
1400public:
1403 name="MP2UpdatePair";
1404 }
1405
1406 // typedef std::tuple<const std::vector<CCPair>&, const std::vector<real_function_6d>&, const CCParameters&,
1407 // const std::vector< madness::Vector<double,3> >&,
1408 // const std::vector<Function<double,3>>&, const std::vector<Function<double,3>>&,
1409 // const std::vector<Function<double,3>>&, const Function<double,3>&> argtupleT;
1410 typedef std::tuple<const std::vector<CCPair>&, const std::vector<real_function_6d>&,
1411 const std::vector<madness::Vector<double,3>>&, const Info& > argtupleT;
1412
1413 using resultT = std::vector<real_function_6d>;
1414
1415 resultT allocator(World& world, const argtupleT& argtuple) const {
1416 std::size_t n = std::get<0>(argtuple).size();
1417 resultT result = zero_functions_auto_tree_state<double, 6>(world, n);
1418 return result;
1419 }
1420
1421// resultT operator() (const std::vector<CCPair>& pair, const std::vector<real_function_6d>& mp2_coupling, const CCParameters& parameters,
1422// const std::vector< madness::Vector<double,3> >& all_coords_vec,
1423// const std::vector<Function<double,3>>& mo_ket, const std::vector<Function<double,3>>& mo_bra,
1424// const std::vector<Function<double,3>>& U1, const Function<double,3>& U2) const;
1425 resultT operator() (const std::vector<CCPair>& pair, const std::vector<real_function_6d>& mp2_coupling,
1426 const std::vector< madness::Vector<double,3> >& all_coords_vec, const Info& info) const;
1427};
1428
1429
1431
1433 public :
1435
1436 partitionT do_partitioning(const std::size_t& vsize1, const std::size_t& vsize2,
1437 const std::string policy) const override {
1438 partitionT p;
1439 for (size_t i = 0; i < vsize1; i++) {
1440 Batch batch(Batch_1D(i, i+1), Batch_1D(i, i+1), Batch_1D(i,i+1));
1441 p.push_back(std::make_pair(batch,1.0));
1442 }
1443 return p;
1444 }
1445 };
1446public:
1449 name="IteratePair";
1450 }
1451
1452 typedef std::tuple<
1453 const std::vector<CCPair>&, // pair
1454 const std::vector<real_function_6d>&, // local coupling
1455 const CC_vecfunction&, // gs singles
1456 const CC_vecfunction&, // ex singles
1457 const Info&,
1458 const std::size_t&
1460
1461 using resultT = std::vector<real_function_6d>;
1462
1463 resultT allocator(World& world, const argtupleT& argtuple) const {
1464 std::size_t n = std::get<0>(argtuple).size();
1465 resultT result = zero_functions_auto_tree_state<double, 6>(world, n);
1466 return result;
1467 }
1468
1469 /// iterate a given pair of the MP2, CC2 or LRCC2 calculation
1470
1471 /// will *NOT* compute the local coupling,
1472 /// will apply the Fock operators (J-K+V)|pair> and use
1473 /// the (excited) singles vectors to update the pair
1474 /// @param[in] pair: the pair which will be updated
1475 /// @param[in] gs_singles: the ground state singles, may be dummy for MP2
1476 /// @param[in] ex_singles: the excited state singles, may be dummy for MP2, CC2
1477 /// @param[in] all_coords_vec: the coordinates of the atoms
1478 /// @param[in] info: the info structure
1479 /// @param[in] maxiter: the maximal number of iterations
1480 resultT operator() (const std::vector<CCPair>& pair,
1481 const std::vector<real_function_6d>& local_coupling,
1482 const CC_vecfunction& gs_singles,
1483 const CC_vecfunction& ex_singles,
1484 const Info& info,
1485 const std::size_t& maxiter) const;
1486};
1487
1488
1490public:
1491 std::string basename="SinglesPotentialEx";
1493 name="SinglesPotentialEx";
1494 partitioner->max_batch_size=2;
1495 partitioner->min_batch_size=2;
1496 }
1497
1498 typedef std::tuple<
1499 const std::vector<int>&, // result_index,
1500 const CC_vecfunction&, // singles_gs,
1501 const std::vector<CCPair>&, // doubles_gs,
1502 const CC_vecfunction&, // singles_ex,
1503 const std::vector<CCPair>&, // doubles_ex,
1504 const int&, // name,
1505 const Info& // info
1507
1508 using resultT = std::tuple<std::vector<real_function_3d>,std::vector<real_function_3d>>;
1509
1510 resultT allocator(World& world, const argtupleT& argtuple) const {
1511 std::size_t n = std::get<0>(argtuple).size();
1512 std::vector<real_function_3d> result = zero_functions_auto_tree_state<double, 3>(world, n);
1513 std::vector<real_function_3d> intermediate = zero_functions_auto_tree_state<double, 3>(world, n);
1514 const_cast<std::string&>(name) =basename+"_"+assign_name(PotentialType(std::get<5>(argtuple)));
1515 return std::make_tuple(result,intermediate);
1516 }
1517
1518 resultT operator() (const std::vector<int>& result_index,
1519 const CC_vecfunction& singles_gs,
1520 const std::vector<CCPair>& doubles_gs,
1521 const CC_vecfunction& singles_ex,
1522 const std::vector<CCPair>& doubles_ex,
1523 const int& name,
1524 const Info& info);
1525};
1526
1528public:
1529 std::string basename="SinglesPotentialGs";
1531 name="SinglesPotentialGs";
1532 }
1533
1534 typedef std::tuple<
1535 const std::vector<int>&, // result_index,
1536 const CC_vecfunction&, // singles_gs,
1537 const std::vector<CCPair>&, // doubles_gs,
1538 const int&, // name,
1539 const Info& // info
1541
1542 /// first vector is the potential, second is an intermediate (if applicable, e.g. for s2b and s2c potentials)
1543 using resultT = std::tuple<std::vector<real_function_3d>,std::vector<real_function_3d>>;
1544
1545 /// allocate the result and set the name of this task
1546 resultT allocator(World& world, const argtupleT& argtuple) const {
1547 std::size_t n = std::get<0>(argtuple).size();
1548 std::vector<real_function_3d> result = zero_functions_auto_tree_state<double, 3>(world, n);
1549 std::vector<real_function_3d> intermediate = zero_functions_auto_tree_state<double, 3>(world, n);
1550 const_cast<std::string&>(name) =basename+"_"+assign_name(PotentialType(std::get<3>(argtuple)));
1551 return std::make_tuple(result,intermediate);
1552 }
1553
1554 resultT operator() (const std::vector<int>& result_index,
1555 const CC_vecfunction& singles_gs,
1556 const std::vector<CCPair>& doubles_gs,
1557 const int& name,
1558 const Info& info);
1559};
1560
1561
1563public:
1564 std::string basename="CorrelationEnergy";
1566 name="CorrelationEnergy";
1567 }
1568
1569 typedef std::tuple<
1570 const std::vector<CCPair>&,
1571 const CC_vecfunction&,
1572 const Info&
1574
1575 /// first vector is the potential, second is an intermediate (if applicable, e.g. for s2b and s2c potentials)
1576 typedef std::vector<ScalarResult<double>> resultT;
1577
1578
1579 /// allocate the result and set the name of this task
1580 resultT allocator(World &world, const argtupleT &argtuple) const {
1581 std::size_t n = std::get<0>(argtuple).size();
1582 return scalar_result_vector<double>(world,n);
1583 }
1584
1585 resultT operator() (const std::vector<CCPair>& pairs,
1586 const CC_vecfunction& singles_gs,
1587 const Info& info) const;
1588};
1589
1590}//namespace madness
1591
1592#endif /* CCSTRUCTURES_H_ */
double potential(const coord_3d &r)
Definition 3dharmonic.cc:132
Definition macrotaskpartitioner.h:55
a batch consists of a 2D-input batch and a 1D-output batch: K-batch <- (I-batch, J-batch)
Definition macrotaskpartitioner.h:124
Definition CCStructures.h:571
intermediateT< T, NDIM > imH
Definition CCStructures.h:762
CCConvolutionOperator(const CCConvolutionOperator &other)=default
friend hashT hash_value(CCConvolutionOperator< T, NDIM > &op)
Definition CCStructures.h:710
static std::shared_ptr< CCConvolutionOperator > CCConvolutionOperatorPtr(World &world, const OpType type, Parameters param)
Definition CCStructures.h:610
Function< T, NDIM > operator()(const Function< T, NDIM > &f) const
Definition CCStructures.h:637
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:761
std::vector< Function< T, NDIM > > operator()(const std::vector< Function< T, NDIM > > &f) const
Definition CCStructures.h:669
OpType type() const
Definition CCStructures.h:746
void clear_intermediates(const FuncType &type)
Definition CCStructures.cc:330
World & world
the world
Definition CCStructures.h:754
void sanity() const
sanity check .. doens not do so much
Definition CCStructures.h:721
std::string name() const
Definition CCStructures.h:697
friend std::shared_ptr< CCConvolutionOperator > combine(const std::shared_ptr< CCConvolutionOperator > &a, const std::shared_ptr< CCConvolutionOperator > &b)
Definition CCStructures.h:626
void update_elements(const CC_vecfunction &bra, const CC_vecfunction &ket)
Definition CCStructures.cc:298
intermediateT< T, NDIM > imP
Definition CCStructures.h:763
void error(const std::string &msg) const
Definition CCStructures.h:768
const Parameters parameters
Definition CCStructures.h:748
CCConvolutionOperator(World &world, const OpType type, Parameters param)
Definition CCStructures.h:603
std::vector< Function< T, NDIM > > operator()(const CC_vecfunction &bra, const CCFunction< T, NDIM > &ket) const
Definition CCStructures.h:645
std::shared_ptr< SeparatedConvolution< T, NDIM > > get_op() const
Definition CCStructures.h:750
void print_intermediate(const FuncType type) const
Definition CCStructures.h:724
intermediateT< T, NDIM > imR
Definition CCStructures.h:764
TwoElectronFactory< T, 2 *NDIM > get_kernel() const
create a TwoElectronFactory with the operatorkernel
Definition CCStructures.h:740
friend CCConvolutionOperator combine(const CCConvolutionOperator &a, const CCConvolutionOperator &b)
Definition CCStructures.h:616
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:1162
CCPairBuilder & set_ex_singles(const CC_vecfunction &ex)
provide excited state singles, needed for CC2 and LRCC2 wave function ansatz
Definition CCStructures.h:1173
CCPairBuilder(World &world, const Info &info)
Definition CCStructures.h:1164
CC_vecfunction gs_singles
Definition CCStructures.h:1249
const Info & info
Definition CCStructures.h:1248
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:1167
static CCState cc_state(const CalcType &type)
Definition CCStructures.h:1192
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:1247
Function< T, NDIM > load_function(const std::string name, bool do_print) const
Function to load a function from disk.
Definition CCStructures.h:1223
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:1250
CC_vecfunction ex_singles
Definition CCStructures.h:1249
CCPairBuilder & set_ctype(const CalcType &type)
Definition CCStructures.h:1178
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:1201
a 6D function, either in full or low rank form, possibly including an 2-particle function
Definition ccpairfunction.h:373
Definition CCStructures.h:991
void reconstruct() const
reconstruct constant part and all functions
Definition CCStructures.h:1095
hashT hash() const
Definition CCStructures.h:1123
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:1145
CCPair(const CCPair &other)
Definition CCStructures.h:1002
World & world() const
return the world of the function
Definition CCStructures.h:1047
void store_pair(World &world, const bool verbose=false)
Definition CCStructures.h:1115
Recordlist< Cloud::keyT > cloud_store(World &world, Cloud &cloud) const
customized function to store this to the cloud
Definition CCStructures.h:1015
bool function_exists() const
check if the pair has a function assigned
Definition CCStructures.h:1053
std::string name() const
Definition CCStructures.h:1152
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:998
size_t i
Definition CCStructures.h:1008
bool load_pair(World &world, const bool verbose=false)
Definition CCStructures.h:1102
real_function_6d function() const
gives back the pure 6D part of the pair function
Definition CCStructures.h:1058
real_function_6d constant_part
the constant part
Definition CCStructures.h:1136
std::vector< CCPairFunction< double, 6 > > functions
the functions which belong to the pair
Definition CCStructures.h:1133
CCPair(const size_t ii, const size_t jj, const CCState t, const CalcType c)
Definition CCStructures.h:995
void update_u(const real_function_6d &u)
updates the pure 6D part of the pair function
Definition CCStructures.h:1065
size_t j
Definition CCStructures.h:1009
CCState type
Definition CCStructures.h:1006
CCPair()=default
double bsh_eps
Definition CCStructures.h:1142
void serialize(const Archive &ar)
Definition CCStructures.h:1076
CalcType ctype
Definition CCStructures.h:1007
void cloud_load(World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
customized function to load this from the cloud
Definition CCStructures.h:1033
cloud class
Definition cloud.h:147
recordlistT store(madness::World &world, const T &source)
Definition cloud.h:316
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:298
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
World & world() const
Returns the world.
Definition mra.h:688
void set_thresh(double value, bool fence=true)
Sets the value of the truncation threshold. Optional global fence.
Definition mra.h:617
const std::shared_ptr< FunctionImpl< T, NDIM > > & get_impl() const
Returns a shared-pointer to the implementation.
Definition mra.h:654
const Function< T, NDIM > & reconstruct(bool fence=true) const
Reconstructs the function, transforming into scaling function basis. Possible non-blocking comm.
Definition mra.h:817
void clear(bool fence=true)
Clears the function as if constructed uninitialized. Optional fence.
Definition mra.h:889
bool is_initialized() const
Returns true if the function is initialized.
Definition mra.h:167
Definition CCStructures.h:1562
resultT operator()(const std::vector< CCPair > &pairs, const CC_vecfunction &singles_gs, const Info &info) const
Definition CCStructures.cc:748
std::tuple< const std::vector< CCPair > &, const CC_vecfunction &, const Info & > argtupleT
Definition CCStructures.h:1573
MacroTaskComputeCorrelationEnergy()
Definition CCStructures.h:1565
resultT allocator(World &world, const argtupleT &argtuple) const
allocate the result and set the name of this task
Definition CCStructures.h:1580
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:1576
std::string basename
Definition CCStructures.h:1564
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:1345
ConstantPartPartitioner()
Definition CCStructures.h:1343
Definition CCStructures.h:1339
std::vector< real_function_6d > resultT
Definition CCStructures.h:1369
MacroTaskConstantPart()
Definition CCStructures.h:1357
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:1367
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1371
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:1436
Definition CCStructures.h:1430
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:1459
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:653
MacroTaskIteratePair()
Definition CCStructures.h:1447
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1463
std::vector< real_function_6d > resultT
Definition CCStructures.h:1461
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:1299
Definition CCStructures.h:1293
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:1311
std::tuple< const std::vector< CCPair > &, const madness::Info &, const std::vector< std::string > & > argtupleT
Definition CCStructures.h:1316
std::vector< real_function_6d > resultT
Definition CCStructures.h:1318
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1320
UpdatePairPartitioner()
Definition CCStructures.h:1386
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:1390
Definition CCStructures.h:1382
MacroTaskMp2UpdatePair()
Definition CCStructures.h:1401
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1415
std::vector< real_function_6d > resultT
Definition CCStructures.h:1413
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:1411
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:978
Batch batch
Definition macrotaskq.h:980
std::shared_ptr< MacroTaskPartitioner > partitioner
Definition macrotaskq.h:982
std::string name
Definition macrotaskq.h:981
partition one (two) vectors into 1D (2D) batches.
Definition macrotaskpartitioner.h:182
std::string policy
how to partition the batches
Definition macrotaskpartitioner.h:190
std::list< std::pair< Batch, double > > partitionT
Definition macrotaskpartitioner.h:186
MacroTaskPartitioner & set_dimension(const std::size_t &n)
Definition macrotaskpartitioner.h:205
Definition CCStructures.h:1489
std::tuple< std::vector< real_function_3d >, std::vector< real_function_3d > > resultT
Definition CCStructures.h:1508
resultT allocator(World &world, const argtupleT &argtuple) const
Definition CCStructures.h:1510
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:1506
std::string basename
Definition CCStructures.h:1491
MacroTaskSinglesPotentialEx()
Definition CCStructures.h:1492
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:674
Definition CCStructures.h:1527
std::string basename
Definition CCStructures.h:1529
std::tuple< const std::vector< int > &, const CC_vecfunction &, const std::vector< CCPair > &, const int &, const Info & > argtupleT
Definition CCStructures.h:1540
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:1543
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:716
MacroTaskSinglesPotentialGs()
Definition CCStructures.h:1530
resultT allocator(World &world, const argtupleT &argtuple) const
allocate the result and set the name of this task
Definition CCStructures.h:1546
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:443
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:955
void sum(T *buf, size_t nelem)
Inplace global sum while still processing AM & tasks.
Definition worldgop.h:872
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:28
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:2503
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 CCParameters.h:14
@ CT_CC2
Definition CCParameters.h:15
@ CT_LRCC2
Definition CCParameters.h:15
@ CT_MP3
Definition CCParameters.h:15
@ CT_UNDEFINED
Definition CCParameters.h:15
@ CT_CISPD
Definition CCParameters.h:15
@ CT_MP2
Definition CCParameters.h:15
@ CT_ADC2
Definition CCParameters.h:15
static std::string stringify(T arg)
Definition funcplot.h:1039
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:73
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:1765
void truncate(World &world, response_space &v, double tol, bool fence)
Definition basic_operators.cc:31
CCState
Type of Pairs used by CC_Pair2 class.
Definition CCStructures.h:27
@ CCSTATE_UNDEFINED
Definition CCStructures.h:28
@ GROUND_STATE
Definition CCStructures.h:28
@ EXCITED_STATE
Definition CCStructures.h:28
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:162
std::shared_ptr< CCConvolutionOperator< T, NDIM > > CCConvolutionOperatorPtr(World &world, const OpType type, typename CCConvolutionOperator< T, NDIM >::Parameters param)
Definition CCStructures.h:778
void hash_combine(hashT &seed, const T &v)
Combine hash values.
Definition worldhash.h:260
Pairs< Function< T, NDIM > > intermediateT
f12 and g12 intermediates of the form <f1|op|f2> (with op=f12 or op=g12) will be saved using the pair...
Definition CCStructures.h:314
double size_of(const intermediateT< T, NDIM > &im)
Returns the size of an intermediate.
Definition CCStructures.h:322
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:43
std::string get_hostname()
Definition unique_filename.cc:40
NDIM & f
Definition mra.h:2481
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:32
@ POT_singles_
Definition CCStructures.h:49
@ POT_s2b_
Definition CCStructures.h:41
@ POT_F3D_
Definition CCStructures.h:34
@ POT_s5b_
Definition CCStructures.h:39
@ POT_s4c_
Definition CCStructures.h:45
@ POT_s5c_
Definition CCStructures.h:40
@ POT_s6_
Definition CCStructures.h:46
@ POT_s4b_
Definition CCStructures.h:44
@ POT_ccs_
Definition CCStructures.h:47
@ POT_s3c_
Definition CCStructures.h:37
@ POT_s4a_
Definition CCStructures.h:43
@ POT_s5a_
Definition CCStructures.h:38
@ POT_s3b_
Definition CCStructures.h:36
@ POT_s2c_
Definition CCStructures.h:42
@ POT_cis_
Definition CCStructures.h:48
@ POT_UNDEFINED
Definition CCStructures.h:33
@ POT_s3a_
Definition CCStructures.h:35
std::string assign_name(const CCState &input)
Assigns strings to enums for formated output.
Definition CCStructures.cc:379
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:2835
double get_size(World &world, const std::vector< Function< T, NDIM > > &v)
Definition vmra.h:1851
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:1832
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
double thresh
Definition tdse.cc:67
parameter class
Definition CCStructures.h:575
int freeze
Definition CCStructures.h:590
Parameters()
Definition CCStructures.h:576
void serialize(archiveT &ar)
f12 exponent
Definition CCStructures.h:594
double lo
Definition CCStructures.h:589
double gamma
Definition CCStructures.h:591
Parameters(const CCParameters &param)
Definition CCStructures.h:585
double thresh_op
Definition CCStructures.h:588
Parameters(const Parameters &other)
Definition CCStructures.h:578
little helper structure which manages the stored singles potentials
Definition CCStructures.h:784
CCParameters parameters
Definition CCStructures.h:890
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:904
bool potential_exists(const CC_vecfunction &f, const PotentialType &type) const
check if the intermediate potential exists
Definition CCStructures.h:791
Recordlist< Cloud::keyT > cloud_store(World &world, Cloud &cloud) const
Definition CCStructures.h:847
void reconstruct() const
Definition CCStructures.h:816
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:894
CCIntermediatePotentials & operator=(const CCIntermediatePotentials &other)=default
void clear_response()
clears only potentials of the response
Definition CCStructures.h:837
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:902
vector_real_function_3d current_singles_potential_ex_
whole excited state singles potential without fock-residue
Definition CCStructures.h:896
bool potential_exists(const PotentialType &type, const FuncType &ftype) const
check if the intermediate potential exists
Definition CCStructures.h:796
void cloud_load(World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
Definition CCStructures.h:860
CCIntermediatePotentials(const CCIntermediatePotentials &other)=default
CCIntermediatePotentials(const CCParameters &p)
Definition CCStructures.h:786
vector_real_function_3d unprojected_cc2_projector_response_
Definition CCStructures.h:907
friend hashT hash_value(const CCIntermediatePotentials &ip)
Definition CCStructures.h:871
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:898
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:900
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:827
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:910
Definition CCStructures.h:86
void print_warnings() const
Definition CCStructures.h:112
void warning(const std::string &msg) const
Definition CCStructures.cc:45
void debug_output(const std::string &msg) const
Definition CCStructures.h:96
bool debug
Definition CCStructures.h:92
void subsection(const std::string &msg) const
Definition CCStructures.cc:34
CCMessenger operator<<(const T &t) const
Definition CCStructures.h:117
World & world
Definition CCStructures.h:89
bool scientific
Definition CCStructures.h:91
std::vector< std::string > warnings
collect all warnings that occur to print out at the end of the job
Definition CCStructures.h:124
std::ostream & os
output stream
Definition CCStructures.h:126
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:87
size_t output_prec
Definition CCStructures.h:90
void operator()(const std::string &msg) const
Definition CCStructures.h:94
Definition CCParameters.h:20
long freeze() const
Definition CCParameters.h:181
bool debug() const
Definition CCParameters.h:165
print accumulated size of all functions
Definition CCStructures.h:1256
void print(World &world, const std::string msg="") const
Definition CCStructures.h:1280
CCSize()=default
double size_local
Definition CCStructures.h:1257
void add_helper(const std::vector< CCPair > &vp)
Definition CCStructures.h:1266
void add(const Args &... args)
variadic template parameters to add the size of all functions and pairs
Definition CCStructures.h:1276
void add_helper(const std::vector< Function< T, NDIM > > &v)
Definition CCStructures.h:1262
Timer Structure.
Definition CCStructures.h:131
std::pair< double, double > current_time(bool printout=false)
Definition CCStructures.h:184
CCTimer(World &world, std::string msg)
Definition CCStructures.h:135
void print() const
Definition CCStructures.h:193
std::string operation
Definition CCStructures.h:142
double start_cpu
Definition CCStructures.h:141
double time_wall
Definition CCStructures.h:145
double get_wall_time_diff() const
Definition CCStructures.h:180
void update_time()
Definition CCStructures.h:148
CCTimer stop()
Definition CCStructures.h:164
CCTimer start()
Definition CCStructures.h:158
void print()
Definition CCStructures.h:189
double time_cpu
Definition CCStructures.h:146
double start_wall
Definition CCStructures.h:140
double get_cpu_time_diff() const
Definition CCStructures.h:182
void print(const std::pair< double, double > &times) const
Definition CCStructures.h:197
double reset()
Definition CCStructures.h:172
World & world
Definition CCStructures.h:139
double end_wall
Definition CCStructures.h:143
double end_cpu
Definition CCStructures.h:144
A helper structure which holds a map of functions.
Definition CCStructures.h:334
std::string irrep
Definition CCStructures.h:477
hashT hash() const
Definition CCStructures.h:463
CC_vecfunction(const vector_real_function_3d &v, const FuncType &type, const size_t &freeze)
Definition CCStructures.h:361
std::map< std::size_t, CCFunction< double, 3 > > CC_functionmap
Definition CCStructures.h:470
CC_vecfunction(const CC_vecfunction &other)
copy ctor (shallow)
Definition CCStructures.h:377
const CCFunction< double, 3 > & operator()(const CCFunction< double, 3 > &i) const
getter
Definition CCStructures.h:489
void insert(const size_t &i, const CCFunction< double, 3 > &f)
setter
Definition CCStructures.h:509
CC_vecfunction(const vector_real_function_3d &v, const FuncType &type)
Definition CCStructures.h:353
static CC_vecfunction load_restartdata(World &world, std::string filename)
Definition CCStructures.h:425
const CCFunction< double, 3 > & operator()(const size_t &i) const
getter
Definition CCStructures.h:494
CC_vecfunction operator*(const double &fac) const
scalar multiplication
Definition CCStructures.h:539
double delta
Definition CCStructures.h:476
CCFunction< double, 3 > & operator()(const size_t &i)
getter
Definition CCStructures.h:504
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:347
bool operator<(const CC_vecfunction &b) const
operator needed for sort operation (sorted by omega values)
Definition CCStructures.h:553
CC_vecfunction(const FuncType type_)
Definition CCStructures.h:338
void serialize(const Archive &ar)
Definition CCStructures.h:438
CC_vecfunction(const std::vector< CCFunction< double, 3 > > &v, const FuncType type_)
Definition CCStructures.h:371
CC_vecfunction(const vector_real_function_3d &v)
Definition CCStructures.h:340
CC_vecfunction()
Definition CCStructures.h:336
void set_functions(const vector_real_function_3d &v, const FuncType &type, const size_t &freeze)
setter
Definition CCStructures.h:514
CCFunction< double, 3 > & operator()(const CCFunction< double, 3 > &i)
getter
Definition CCStructures.h:499
void scale(const double &factor)
scaling (inplace)
Definition CCStructures.h:546
void plot(const std::string &msg="") const
Definition CCStructures.h:556
FuncType type
Definition CCStructures.h:473
double current_error
excitation energy
Definition CCStructures.h:475
friend CC_vecfunction copy(const CC_vecfunction &other)
returns a deep copy (void shallow copy errors)
Definition CCStructures.h:399
size_t size() const
Get the size vector (number of functions in the map)
Definition CCStructures.h:530
CC_vecfunction & operator=(const CC_vecfunction &other)
assignment operator, shallow wrt the functions
Definition CCStructures.h:385
double omega
Definition CCStructures.h:474
bool is_converged(const double econv, const double dconv) const
Definition CCStructures.h:484
vector_real_function_3d get_vecfunction() const
Returns all the functions of the map as vector.
Definition CCStructures.h:523
void save_restartdata(World &world, std::string filename) const
Definition CCStructures.h:432
CC_functionmap functions
Definition CCStructures.h:471
std::string name(const int ex) const
excitation irrep (direct product of x function and corresponding orbital)
Definition CCStructures.h:480
void reconstruct() const
Definition CCStructures.h:408
POD holding some basic functions and some intermediates for the CC2 calculation.
Definition CCStructures.h:919
void reconstruct() const
Definition CCStructures.h:942
std::vector< Function< double, 3 > > mo_ket
Definition CCStructures.h:920
Recordlist< Cloud::keyT > cloud_store(World &world, Cloud &cloud) const
customized function to store this to the cloud
Definition CCStructures.h:955
Tensor< double > fock
Definition CCStructures.h:925
Function< double, 3 > R
Definition CCStructures.h:927
std::vector< Function< double, 3 > > U1
Definition CCStructures.h:928
CCIntermediatePotentials intermediate_potentials
Definition CCStructures.h:926
Function< double, 3 > U2
Definition CCStructures.h:927
std::vector< madness::Vector< double, 3 > > molecular_coordinates
Definition CCStructures.h:922
std::vector< double > orbital_energies
Definition CCStructures.h:924
std::vector< Function< double, 3 > > mo_bra
Definition CCStructures.h:921
CCParameters parameters
Definition CCStructures.h:923
vector_real_function_3d get_active_mo_bra() const
Definition CCStructures.h:936
void cloud_load(World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
customized function to load this from the cloud
Definition CCStructures.h:974
Function< double, 3 > R_square
Definition CCStructures.h:927
vector_real_function_3d get_active_mo_ket() const
Definition CCStructures.h:930
Definition CCStructures.h:206
static PairVectorMap triangular_map(const int nfreeze, const int nocc)
Definition CCStructures.h:212
void print(const std::string msg="PairVectorMap") const
Definition CCStructures.h:232
std::vector< std::pair< int, int > > map
maps pair index (i,j) to vector index k
Definition CCStructures.h:208
static PairVectorMap quadratic_map(const int nfreeze, const int nocc)
Definition CCStructures.h:222
PairVectorMap(const std::vector< std::pair< int, int > > map1)
Definition CCStructures.h:210
Definition CCStructures.h:246
void swap(Pairs< T > &other)
swap the contant of the pairmap
Definition CCStructures.h:302
pairmapT allpairs
Definition CCStructures.h:249
static Pairs vector2pairs(const std::vector< T > &argument, const PairVectorMap map)
Definition CCStructures.h:265
Pairs< R > convert(const Pairs< T > arg, const opT op) const
convert Pairs<T> to another type
Definition CCStructures.h:255
std::map< std::pair< int, int >, T > pairmapT
Definition CCStructures.h:248
bool empty() const
Definition CCStructures.h:306
T & operator()(int i, int j)
getter
Definition CCStructures.h:289
void insert(int i, int j, const T &pair)
Definition CCStructures.h:296
const T & operator()(int i, int j) const
getter
Definition CCStructures.h:282
static std::vector< T > pairs2vector(const Pairs< T > &argument, const PairVectorMap map)
Definition CCStructures.h:273
Definition cloud.h:34
Definition lowrankfunction.h:336
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