8 #ifndef SRC_APPS_CHEM_CCPOTENTIALS_H_
9 #define SRC_APPS_CHEM_CCPOTENTIALS_H_
22 CCPotentials(World& world_,
const std::shared_ptr<Nemo> nemo,
const CCParameters&
param);
24 void reset_nemo(
const std::shared_ptr<Nemo> nemo) {
26 mo_ket_ = (make_mo_ket(*nemo));
27 mo_bra_ = (make_mo_bra(*nemo));
28 orbital_energies_ = init_orbital_energies(*nemo);
31 Info update_info(
const CCParameters& parameters,
const std::shared_ptr<Nemo> nemo)
const {
33 info.mo_bra = mo_bra().get_vecfunction();
34 info.mo_ket = mo_ket().get_vecfunction();
35 info.molecular_coordinates = nemo->get_calc()->molecule.get_all_coords_vec();
36 info.parameters = parameters;
37 info.R_square = nemo->R_square;
39 info.U1 = nemo->ncf->U1vec();
40 info.U2 = nemo->ncf->U2();
41 info.intermediate_potentials = get_potentials;
42 info.orbital_energies = orbital_energies_;
43 info.fock=nemo->compute_fock_matrix(nemo->get_calc()->amo, nemo->get_calc()->aocc);
51 void test_pair_consistency(
const CCPairFunction<double, 6>&
u,
const size_t i,
const size_t j,
52 const CC_vecfunction& x)
const;
54 bool test_compare_pairs(
const CCPair& pair1,
const CCPair& pair2)
const;
58 void test_singles_potential(Info& info)
const;
69 template <
typename T,
size_t NDIM>
71 bool exists = archive::ParallelInputArchive<
72 archive::BinaryFstreamInputArchive>::exists(world,
name.c_str());
74 if (world.rank() == 0)
print(
"loading function",
name);
75 archive::ParallelInputArchive<archive::BinaryFstreamInputArchive> ar(world,
name.c_str());
83 if (world.rank()==0)
print(
"could not find function",
name);
95 template <
size_t NDIM>
96 void print_size(
const Function<double, NDIM>&
f,
const std::string& msg,
const bool print =
true)
const {
97 if (
print)
f.print_size(msg);
101 std::vector<double> get_orbital_energies()
const {
return orbital_energies_; }
104 double get_epsilon(
const size_t i,
const size_t j)
const {
105 return orbital_energies_[i] + orbital_energies_[j];
109 static double get_epsilon(
const size_t i,
const size_t j,
const Info& info) {
110 return info.orbital_energies[i] + info.orbital_energies[j];
116 for (
size_t i = parameters.freeze(); i < mo_ket_.size(); i++) result.push_back(mo_ket_(i).
function);
123 for (
size_t i = parameters.freeze(); i < mo_bra_.size(); i++) result.push_back(mo_bra_(i).
function);
130 for (
const auto& ktmp : ket.functions) {
131 result.push_back(mo_bra_(ktmp.first).function);
137 CCFunction<double, 3> mo_ket(
const size_t& i)
const {
142 CC_vecfunction mo_ket()
const {
147 CCFunction<double, 3> mo_bra(
const size_t& i)
const {
152 CC_vecfunction mo_bra()
const {
158 return make_bra(t.get_vecfunction());
170 CC_vecfunction make_t_intermediate(
const CC_vecfunction& tau,
const CCParameters& parameters)
const;
175 CC_vecfunction make_full_t_intermediate(
const CC_vecfunction& tau)
const;
180 static CC_vecfunction make_full_t_intermediate(
const CC_vecfunction& tau,
const Info& info);
186 static CC_vecfunction make_active_t_intermediate(
const CC_vecfunction& tau,
const Info& info);
191 CCFunction<double, 3> make_t_intermediate(
const CCFunction<double, 3>& tau)
const;
196 make_mo_bra(
const Nemo& nemo)
const;
200 make_mo_ket(
const Nemo& nemo)
const;
204 init_orbital_energies(
const Nemo& nemo)
const;
208 static CCPair make_pair_mp2(
const real_function_6d&
u,
const size_t i,
const size_t j,
const Info& info);
211 static CCPair make_pair_cc2(
const real_function_6d&
u,
const CC_vecfunction& gs_singles,
212 const size_t i,
const size_t j,
const Info& info);
216 const CC_vecfunction& gs_singles,
const CC_vecfunction& ex_singles,
217 const size_t i,
const size_t j,
const Info& info);
232 make_pair_gs(
const real_function_6d&
u,
const CC_vecfunction& tau,
const size_t i,
const size_t j)
const;
250 make_pair_ex(
const real_function_6d&
u,
const CC_vecfunction& tau,
const CC_vecfunction& x,
const size_t i,
251 const size_t j,
const CalcType ctype)
const;
261 compute_pair_correlation_energy(World& world,
264 const CC_vecfunction& singles = CC_vecfunction(
PARTICLE));
274 compute_cc2_correlation_energy(World& world,
const CC_vecfunction& singles,
const Pairs<CCPair>& doubles,
283 compute_cis_expectation_value(World& world,
const CC_vecfunction& x,
289 compute_excited_pair_energy(World& world,
const CCPair&
d,
const CC_vecfunction& x,
const Info& info);
293 compute_cispd_energy(
const CC_vecfunction& x,
const Pairs<CCPair> mp2,
const Pairs<CCPair> cispd)
const;
297 compute_cc2_excitation_energy(
const CC_vecfunction& stau,
const CC_vecfunction& sx,
const Pairs<CCPair> dtau,
298 const Pairs<CCPair> dx)
const;
304 fock_residue_6d(
const CCPair&
u)
const;
308 fock_residue_6d_macrotask(World& world,
const CCPair&
u,
const CCParameters& parameters,
310 const std::vector<real_function_3d>& mo_ket,
311 const std::vector<real_function_3d>& mo_bra,
312 const std::vector<real_function_3d>& U1,
317 make_constant_part_mp2_macrotask(World& world,
const CCPair& pair,
const std::vector<real_function_3d>& mo_ket,
318 const std::vector<real_function_3d>& mo_bra,
320 const std::vector<real_function_3d>& U1,
321 const std::vector<std::string> argument);
332 make_constant_part_macrotask(World& world,
const CCPair& pair,
333 const CC_vecfunction& gs_singles,
const CC_vecfunction& ex_singles,
339 update_pair_mp2_macrotask(World& world,
const CCPair& pair,
const CCParameters& parameters,
341 const std::vector<real_function_3d>& mo_ket,
342 const std::vector<real_function_3d>& mo_bra,
343 const std::vector<real_function_3d>& U1,
348 static CCPair iterate_pair_macrotask(World& world,
349 const CCPair& pair,
const CC_vecfunction& gs_singles,
350 const CC_vecfunction& ex_singles,
364 make_constant_part_cc2_gs(
const CCPair&
u,
const CC_vecfunction& tau,
377 make_constant_part_cc2_Qt_gs(
const CCPair&
u,
const CC_vecfunction& tau,
382 make_constant_part_cispd(
const CCPair&
u,
const CC_vecfunction& x,
387 make_constant_part_cispd_Qt(
const CCPair&
u,
const CC_vecfunction& x,
392 make_constant_part_cc2_ex(
const CCPair&
u,
const CC_vecfunction& tau,
const CC_vecfunction& x,
397 make_constant_part_cc2_Qt_ex(
const CCPair&
u,
const CC_vecfunction& tau,
const CC_vecfunction& x,
407 apply_Vreg(
const CCFunction<double, 3>& ti,
const CCFunction<double, 3>& tj,
416 std::vector<CCPairFunction<double, 6>>
417 static apply_Vreg(World& world,
const CCFunction<double, 3>& ti,
const CCFunction<double, 3>& tj,
418 const CC_vecfunction& gs_singles,
const CC_vecfunction& ex_singles,
419 const Info& info,
const std::vector<std::string>& argument,
const double bsh_eps);
424 apply_Vreg_macrotask(World& world,
const std::vector<real_function_3d>& mo_ket,
425 const std::vector<real_function_3d>& mo_bra,
427 const std::vector<real_function_3d>& U1,
const size_t& i,
const size_t& j,
429 const std::vector<std::string> argument,
441 apply_reduced_F1(
const CCFunction<double, 3>& ti,
const CCFunction<double, 3>& tj,
453 static apply_reduced_F(World& world,
const CCFunction<double, 3>& ti,
const CCFunction<double, 3>& tj,
467 apply_transformed_Ue(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
473 static apply_transformed_Ue_macrotask(World& world,
const std::vector<real_function_3d>& mo_ket,
475 const std::vector<real_function_3d>& U1,
const size_t& i,
const size_t& j,
480 static apply_Ue(World& world,
const CCFunction<double, 3>& phi_i,
const CCFunction<double, 3>& phi_j,
485 apply_KffK(World& world,
const CCFunction<double, 3>& phi_i,
const CCFunction<double, 3>& phi_j,
487 static CCPairFunction<double, 6>
488 apply_commutator_F_Qt_f12(World& world,
const CCFunction<double, 3>& phi_i,
const CCFunction<double, 3>& phi_j,
489 const CC_vecfunction& gs_singles,
const CC_vecfunction& ex_singles,
492 static CCPairFunction<double, 6>
493 apply_commutator_F_dQt_f12(World& world,
const CCFunction<double, 3>& phi_i,
const CCFunction<double, 3>& phi_j,
494 const CC_vecfunction& gs_singles,
const CC_vecfunction& ex_singles,
509 apply_exchange_commutator(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
513 static apply_exchange_commutator_macrotask(World& world,
const std::vector<real_function_3d>& mo_ket,
514 const std::vector<real_function_3d>& mo_bra,
516 const size_t& i,
const size_t& j,
const CCParameters& parameters,
522 apply_exchange_commutator1(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
531 make_xy_gf_ab(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
const CCFunction<double, 3>&
a,
532 const CCFunction<double, 3>&
b)
const;
534 double make_xy_ff_ab(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
535 const CCFunction<double, 3>&
a,
const CCFunction<double, 3>&
b)
const {
536 error(
"xy_ff_ab not yet implemented");
549 make_xy_op_u(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
550 const CCConvolutionOperator<double, 3>&
op,
551 const std::vector<CCPairFunction<double, 6>>&
u);
557 make_xy_u(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
558 const std::vector<CCPairFunction<double, 6>>&
u);
565 make_xy_op_u(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
566 const CCConvolutionOperator<double, 3>&
op,
567 const CCPairFunction<double, 6>&
u);
576 make_xy_op_ab(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
577 const CCConvolutionOperator<double, 3>&
op,
const CCFunction<double, 3>&
a,
578 const CCFunction<double, 3>&
b)
const;
583 static std::vector<CCPairFunction<double, 6>>
584 get_pair_function(
const Pairs<CCPair>& pairs,
const size_t i,
const size_t j);
589 apply_s2b_operation(World& world,
const CCFunction<double, 3>& bra,
const CCPairFunction<double, 6>&
u,
590 const size_t particle,
const Info& info);
594 return madness::swap_particles<double>(
f);
598 static std::vector<CCPairFunction<double, 6>>
swap_particles(
const std::vector<CCPairFunction<double, 6>>&
f) {
599 std::vector<CCPairFunction<double, 6>> swapped;
600 for (
size_t i = 0; i <
f.size(); i++) swapped.push_back(
f[i].swap_particles());
608 overlap(
const CCPairFunction<double, 6>&
f1,
const CCPairFunction<double, 6>&
f2)
const {
609 return inner(
f1,
f2, nemo_->ncf->square());
616 overlap(
const CCPair& x)
const;
625 apply_projector(
const CC_vecfunction&
f,
const CC_vecfunction& ket_)
const;
638 apply_Qt(
const CC_vecfunction&
f,
const CC_vecfunction& ket_,
const double c = 1.0)
const;
642 CCPairFunction<double, 6>
643 apply_Qt(
const CCPairFunction<double, 6>&
f,
const CC_vecfunction& t,
const size_t particle,
644 const double c = 1.0)
const;
655 CCPairFunction<double, 6>
656 apply_Ot(
const CCPairFunction<double, 6>&
f,
const CC_vecfunction& t,
const size_t particle)
const;
666 CCTimer time(world,
"Apply Greens Operator");
668 time.info(
true, result.norm2());
679 get_CC2_singles_potential_gs(World& world,
const CC_vecfunction& singles,
const Pairs<CCPair>& doubles,
686 get_CCS_potential_ex(World& world,
const CC_vecfunction& x,
const bool print, Info& info);
691 get_CC2_singles_potential_ex(World& world,
const CC_vecfunction& gs_singles,
692 const Pairs<CCPair>& gs_doubles,
const CC_vecfunction& ex_singles,
693 const Pairs<CCPair>& response_doubles, Info& info);
698 get_ADC2_singles_potential(World& world,
const Pairs<CCPair>& gs_doubles,
699 CC_vecfunction& ex_singles,
const Pairs<CCPair>& response_doubles, Info& info)
const;
711 potential_energy_gs(World& world,
const CC_vecfunction& bra,
const CC_vecfunction& singles,
723 potential_singles_gs(World& world,
const CC_vecfunction& singles,
const Pairs<CCPair>& doubles,
738 potential_energy_ex(World& world,
const CC_vecfunction& bra,
const CC_vecfunction& singles_gs,
739 const Pairs<CCPair>& doubles_gs,
const CC_vecfunction& singles_ex,
753 potential_singles_ex(World& world,
const CC_vecfunction& singles_gs,
754 const Pairs<CCPair>& doubles_gs,
const CC_vecfunction& singles_ex,
762 fock_residue_closed_shell(World& world,
const CC_vecfunction& singles,
const Info& info);
766 K(World& world,
const CCFunction<double, 3>&
f,
const Info& info);
770 static K_macrotask(World& world,
const std::vector<real_function_3d>& mo_ket,
772 const CCParameters& parameters);
782 static K_macrotask(World& world,
const std::vector<real_function_3d>& mo_ket,
783 const std::vector<real_function_3d>& mo_bra,
784 const real_function_6d&
u,
const bool symmetric,
const CCParameters& parameters);
797 static apply_K_macrotask(World& world,
const std::vector<real_function_3d>& mo_ket,
798 const std::vector<real_function_3d>& mo_bra,
799 const real_function_6d&
u,
const size_t& particle,
const CCParameters& parameters);
804 apply_Kf(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y)
const;
812 apply_fK(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
817 make_f_xy(
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
822 static make_f_xy(World& world,
const CCFunction<double, 3>& x,
const CCFunction<double, 3>& y,
828 const size_t& i,
const size_t& j,
const CCParameters& parameters,
836 ccs_unprojected(World& world,
const CC_vecfunction& ti,
const CC_vecfunction& tk,
const Info& info);
839 template <
typename T, std::
size_t NDIM>
840 static std::pair<double, double> residual_stats(
const std::vector<Function<T, NDIM>>&
residual) {
841 if (
residual.size() == 0)
return std::make_pair(0.0, 0.0);
842 World& world =
residual.front().world();
844 double rnorm = 0.0, maxrnorm = 0.0;
845 for (
double&
e : errors) {
849 rnorm = sqrt(rnorm / errors.size());
850 return std::make_pair(rnorm, maxrnorm);
853 static void print_convergence(
const std::string
name,
const double rmsresidual,
const double maxresidual,
854 const double energy_diff,
const int iteration) {
855 const std::size_t
bufsize = 255;
858 "convergence of %s in iteration %2d at time %8.1fs: rms/max residual, energy change %.1e %.1e %.1e",
859 name.c_str(), iteration,
wall_time(), rmsresidual, maxresidual,energy_diff);
867 x_s3a(
const CC_vecfunction& x,
const CC_vecfunction& t)
const;
871 x_s3b(
const CC_vecfunction& x,
const CC_vecfunction& t)
const;
875 x_s3c(
const CC_vecfunction& x,
const CC_vecfunction& t)
const;
879 x_s5b(
const CC_vecfunction& x,
const CC_vecfunction& t1,
const CC_vecfunction& t2)
const;
883 x_s5c(
const CC_vecfunction& x,
const CC_vecfunction& t1,
const CC_vecfunction& t2)
const;
887 x_s6(
const CC_vecfunction& x,
const CC_vecfunction& t1,
const CC_vecfunction& t2,
888 const CC_vecfunction& t3)
const;
892 x_s2b(
const CC_vecfunction& x,
const Pairs<CCPair>&
u)
const;
896 x_s2c(
const CC_vecfunction& x,
const Pairs<CCPair>&
u)
const;
900 x_s4a(
const CC_vecfunction& x,
const CC_vecfunction& t,
const Pairs<CCPair>&
u)
const;
904 x_s4b(
const CC_vecfunction& x,
const CC_vecfunction& t,
const Pairs<CCPair>&
u)
const;
908 x_s4c(
const CC_vecfunction& x,
const CC_vecfunction& t,
const Pairs<CCPair>&
u)
const;
920 s2b(World& world,
const CC_vecfunction& singles,
const Pairs<CCPair>& doubles, Info& info);
931 s2c(World& world,
const CC_vecfunction& singles,
const Pairs<CCPair>& doubles, Info& info);
946 s4b(World& world,
const CC_vecfunction& singles,
const Pairs<CCPair>& doubles,
const Info& info);
956 s4c(World& world,
const CC_vecfunction& singles,
const Pairs<CCPair>& doubles,
const Info& info);
959 void update_intermediates(
const CC_vecfunction& t) {
960 g12->update_elements(mo_bra_, t);
962 f12->update_elements(mo_bra_, t);
968 void clear_potentials(
const CC_vecfunction& t)
const {
970 output(
"Clearing Response Singles-Potentials");
971 get_potentials.clear_response();
974 output(
"Clearing all stored Singles-Potentials");
975 get_potentials.clear_all();
984 std::shared_ptr<Nemo> nemo_;
986 const CCParameters& parameters;
988 CC_vecfunction mo_ket_;
990 CC_vecfunction mo_bra_;
992 std::vector<double> orbital_energies_;
995 std::shared_ptr<CCConvolutionOperator<double, 3>> g12;
997 std::shared_ptr<CCConvolutionOperator<double, 3>> f12;
999 CorrelationFactor corrfac;
1001 mutable CCIntermediatePotentials get_potentials;
Operators for the molecular HF and DFT code.
Definition: test_derivative.cc:24
static const double & get_thresh()
Returns the default threshold.
Definition: funcdefaults.h:279
void test(World &world, bool doloadbal=false)
Definition: dataloadbal.cc:224
double(* f1)(const coord_3d &)
Definition: derivatives.cc:55
double(* f2)(const coord_3d &)
Definition: derivatives.cc:56
const std::size_t bufsize
Definition: derivatives.cc:16
vecfuncT K(vecfuncT &ket, vecfuncT &bra, vecfuncT &vf)
const int maxiter
Definition: gygi_soltion.cc:68
static double bsh_eps
Definition: helium_exact.cc:62
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
#define max(a, b)
Definition: lda.h:51
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
CalcType
Calculation Types used by CC2.
Definition: CCStructures.h:27
std::enable_if_t< NDIM%2==0, Function< T, NDIM > > swap_particles(const Function< T, NDIM > &f)
swap particles 1 and 2
Definition: mra.h:2302
Function< TENSOR_RESULT_TYPE(Q, T), NDIM > mul(const Q alpha, const Function< T, NDIM > &f, bool fence=true)
Returns new function equal to alpha*f(x) with optional fence.
Definition: mra.h:1701
void truncate(World &world, response_space &v, double tol, bool fence)
Definition: basic_operators.cc:30
FuncType
Definition: ccpairfunction.h:26
@ RESPONSE
Definition: ccpairfunction.h:26
@ PARTICLE
Definition: ccpairfunction.h:26
void plot(const std::vector< Function< double, NDIM > > &vf, const std::string &name, const std::vector< std::string > &header)
convenience to get plot_plane and plot_cubefile
Definition: funcplot.h:1022
std::vector< real_function_3d > vector_real_function_3d
Definition: functypedefs.h:79
Function< double, 6 > real_function_6d
Definition: functypedefs.h:68
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
void print_size(World &world, const std::vector< Function< T, NDIM > > &v, const std::string &msg="vectorfunction")
Definition: vmra.h:1622
NDIM & f
Definition: mra.h:2416
void error(const char *msg)
Definition: world.cc:139
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition: timers.cc:48
Function< double, 3 > real_function_3d
Definition: functypedefs.h:65
double inner(response_space &a, response_space &b)
Definition: response_functions.h:442
void load_function(World &world, std::vector< Function< T, NDIM > > &f, const std::string name)
load a vector of functions
Definition: vmra.h:2048
PotentialType
CC2 Singles Potentials.
Definition: CCStructures.h:35
SeparatedConvolution< double, 6 > real_convolution_6d
Definition: functypedefs.h:124
std::string name(const FuncType &type, const int ex=-1)
Definition: ccpairfunction.h:28
std::vector< double > norm2s(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norms of a vector of functions.
Definition: vmra.h:827
static const double b
Definition: nonlinschro.cc:119
static const double a
Definition: nonlinschro.cc:118
static const double c
Definition: relops.cc:10
pcomplex_operatorT G
Definition: tdse1d.cc:167
static double V(const coordT &r)
Definition: tdse.cc:288
InputParameters param
Definition: tdse.cc:203
void d()
Definition: test_sig.cc:79
void e()
Definition: test_sig.cc:75
F residual(const F &f)
Definition: testcomplexfunctionsolver.cc:69
double u(const double x, const double expnt)
Definition: testperiodic.cc:56