MADNESS 0.10.1
function_interface.h
Go to the documentation of this file.
1/*
2 This file is part of MADNESS.
3
4 Copyright (C) 2007,2010 Oak Ridge National Laboratory
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 For more information please contact:
21
22 Robert J. Harrison
23 Oak Ridge National Laboratory
24 One Bethel Valley Road
25 P.O. Box 2008, MS-6367
26
27 email: harrisonrj@ornl.gov
28 tel: 865-241-3937
29 fax: 865-572-0680
30
31 $Id: function_factory_and_interface.h 3422 2014-03-24 09:16:15Z 3ru6ruWu $
32*/
33
34
35#ifndef MADNESS_MRA_FUNCTION_INTERFACE_H__INCLUDED
36#define MADNESS_MRA_FUNCTION_INTERFACE_H__INCLUDED
37
40#include <madness/mra/key.h>
41
42// needed for the TwoElectronInterface
44#include <madness/mra/gfit.h>
47
48namespace madness {
49
50 // forward declaration needed for CompositeFunctorInterface
51 template<typename T, std::size_t NDIM>
52 class FunctionImpl;
53
54 template<typename T, std::size_t NDIM>
55 class Function;
56
57 template<typename T, std::size_t NDIM>
58 Tensor<T> fcube(const Key<NDIM>&, T (*f)(const Vector<double,NDIM>&), const Tensor<double>&);
59
60// template <typename T, std::size_t NDIM>
61// const std::vector<Function<T,NDIM>>& change_tree_state(const std::vector<Function<T,NDIM>>& v,
62// const TreeState finalstate,
63// const bool fence);
64
65
66 /// Abstract base class interface required for functors used as input to Functions
67 template<typename T, std::size_t NDIM>
69 public:
70
72 typedef Key<NDIM> keyT;
73 typedef T value_type;
74
76
78
79 /// adapt the special level to resolve the smallest length scale
80 void set_length_scale(double lo) {
82 double lo_sim=lo/Lmax; // lo in simulation coordinates;
84 }
85
86 /// Can we screen this function based on the bounding box information?
87 virtual bool screened(const Vector<double,NDIM>& c1, const Vector<double,NDIM>& c2) const {
88 return false;
89 }
90
91 /// Does the interface support a vectorized operator()?
92 virtual bool supports_vectorized() const {return false;}
93
95MADNESS_PRAGMA_GCC(diagnostic ignored "-Woverloaded-virtual")
97MADNESS_PRAGMA_CLANG(diagnostic ignored "-Woverloaded-virtual")
98
99 virtual void operator()(const Vector<double*,1>& xvals, T* fvals, int npts) const {
100 MADNESS_EXCEPTION("FunctionFunctorInterface: This function should not be called!", 0);
101 }
102
103 virtual void operator()(const Vector<double*,2>& xvals, T* fvals, int npts) const {
104 MADNESS_EXCEPTION("FunctionFunctorInterface: This function should not be called!", 0);
105 }
106
107 virtual void operator()(const Vector<double*,3>& xvals, T* fvals, int npts) const {
108 MADNESS_EXCEPTION("FunctionFunctorInterface: This function should not be called!", 0);
109 }
110
111 virtual void operator()(const Vector<double*,4>& xvals, T* fvals, int npts) const {
112 MADNESS_EXCEPTION("FunctionFunctorInterface: This function should not be called!", 0);
113 }
114
115 virtual void operator()(const Vector<double*,5>& xvals, T* fvals, int npts) const {
116 MADNESS_EXCEPTION("FunctionFunctorInterface: This function should not be called!", 0);
117 }
118
119 virtual void operator()(const Vector<double*,6>& xvals, T* fvals, int npts) const {
120 MADNESS_EXCEPTION("FunctionFunctorInterface: This function should not be called!", 0);
121 }
124
125 /// You should implement this to return \c f(x)
126 virtual T operator()(const Vector<double, NDIM>& x) const = 0;
127
128 /// Override this to return list of special points to be refined more deeply
129 virtual std::vector< Vector<double,NDIM> > special_points() const {
130 return std::vector< Vector<double,NDIM> >();
131 }
132
133 /// Override this to change the minimum level of refinement at special points (default is 6)
134 virtual Level special_level() const {return special_level_;}
135
137
138 virtual coeffT coeff(const keyT&) const {
139 MADNESS_EXCEPTION("implement coeff for FunctionFunctorInterface",0);
140 return coeffT();
141 }
142
143 virtual coeffT values(const keyT& key, const Tensor<double>& tensor) const {
144 MADNESS_EXCEPTION("implement values for FunctionFunctorInterface",0);
145 return coeffT();
146 }
147
148 /// does this functor directly provide sum coefficients? or only function values?
149 virtual bool provides_coeff() const {
150 return false;
151 }
152
153 };
154
155
156
157 ///forward declaration
158 template <typename T, std::size_t NDIM>
159 // void FunctionImpl<T,NDIM>::fcube(const keyT& key, const FunctionFunctorInterface<T,NDIM>& f, const Tensor<double>& qx, tensorT& fval) const {
160 void fcube(const Key<NDIM>& key, const FunctionFunctorInterface<T,NDIM>& f, const Tensor<double>& qx, Tensor<T>& fval);
161
162 /// CompositeFunctorInterface implements a wrapper of holding several functions and functors
163
164 /// Use this to "connect" several functions and/or functors and to return their coefficients
165 /// e.g. connect f1 and f2 with an addition, you can request the coefficients of any node
166 /// and they will be computed on the fly and returned. Mainly useful to connect a functor
167 /// with a function, if the functor is too large to be represented in MRA (e.g. 1/r12)
168 ///
169 /// as of now, the operation connecting the functions/functors is simply addition.
170 /// need to implement expression templates, if I only knew what that was...
171 template<typename T, std::size_t NDIM, std::size_t MDIM>
173
174 typedef Vector<double, NDIM> coordT; ///< Type of vector holding coordinates
177 typedef std::shared_ptr<implT> pimplT;
178 typedef std::shared_ptr<implL> pimplL;
179
181
182 public:
183 /// various MRA functions of NDIM dimensionality
184 std::vector<std::shared_ptr<implT>> impl_ket_vector; ///< supposedly the pair function
185 std::shared_ptr<implT> impl_eri; ///< supposedly 1/r12
186
187 /// various MRA functions of MDIM dimensionality (e.g. 3, if NDIM==6)
188 std::shared_ptr<implL> impl_m1; ///< supposedly 1/r1
189 std::shared_ptr<implL> impl_m2; ///< supposedly 1/r2
190 std::vector<std::shared_ptr<implL>> impl_p1_vector; ///< supposedly orbital 1
191 std::vector<std::shared_ptr<implL>> impl_p2_vector; ///< supposedly orbital 2
192
193 public:
194
195 /// constructor takes its Factory
196 CompositeFunctorInterface(World& world, std::vector<pimplT> ket, pimplT g12,
197 pimplL v1, pimplL v2, std::vector<pimplL> p1, std::vector<pimplL> p2)
198 : world(world), impl_ket_vector(ket), impl_eri(g12)
200 {
201
202 // some consistency checks
203 // either a pair ket is provided, or two particles (tba)
204 MADNESS_CHECK_THROW(impl_p1_vector.size()==impl_p2_vector.size(), "CompositeFunctorInterface: p1 and p2 must have the same size");
205 MADNESS_CHECK_THROW(impl_ket_vector.size()>0 or (impl_p1_vector.size()>0),"CompositeFunctorInterface: either ket or p1 must be provided");
206
207 }
208
209 /// replicate low-dimensional functions over all ranks of this world
210 void replicate_low_dim_functions(const bool fence) {
211 if (impl_m1 and (not impl_m1->is_on_demand())) impl_m1->replicate(false);
212 if (impl_m2 and (not impl_m2->is_on_demand())) impl_m2->replicate(false);
213
214 for (auto& p1 : impl_p1_vector) if (p1 and (not p1->is_on_demand())) p1->replicate(false);
215 for (auto& p2 : impl_p2_vector) if (p2 and (not p2->is_on_demand())) p2->replicate(false);
216 if (fence) world.gop.fence();
217 }
218
219 void make_redundant(const bool fence) {
220 // prepare base functions that make this function
221 for (auto& k : impl_ket_vector) if (k and (not k->is_on_demand())) k->change_tree_state(redundant,false);
222 if (impl_eri) {
223 if (not impl_eri->is_on_demand()) impl_eri->change_tree_state(redundant,false);
224 }
225 if (impl_m1 and (not impl_m1->is_on_demand())) impl_m1->change_tree_state(redundant,false);
226 if (impl_m2 and (not impl_m2->is_on_demand())) impl_m2->change_tree_state(redundant,false);
227
230// for (auto& k : impl_p1_vector) if (k and (not k->is_on_demand())) k->change_tree_state(redundant,false);
231// for (auto& k : impl_p2_vector) if (k and (not k->is_on_demand())) k->change_tree_state(redundant,false);
232// if (impl_p1 and (not impl_p1->is_on_demand())) impl_p1->change_tree_state(redundant,false);
233// if (impl_p2 and (not impl_p2->is_on_demand())) impl_p2->change_tree_state(redundant,false);
234 if (fence) world.gop.fence();
235 }
236
237 /// return true if all constituent functions are in redundant tree state
238 bool check_redundant() const {
239 for (auto& k : impl_ket_vector) if (k and (not k->is_redundant())) return false;
240// if (impl_ket and (not impl_ket->is_redundant())) return false;
241 if (impl_eri) MADNESS_ASSERT(impl_eri->is_on_demand());
242 if (impl_m1 and (not impl_m1->is_redundant())) return false;
243 if (impl_m2 and (not impl_m2->is_redundant())) return false;
244 for (auto& k : impl_p1_vector) if (k and (not k->is_redundant())) return false;
245 for (auto& k : impl_p2_vector) if (k and (not k->is_redundant())) return false;
246// if (impl_p1 and (not impl_p1->is_redundant())) return false;
247// if (impl_p2 and (not impl_p2->is_redundant())) return false;
248 return true;
249 }
250
251 /// return value at point x; fairly inefficient
252 T operator()(const coordT& x) const {
253 print("there is no operator()(coordT&) in CompositeFunctorInterface, for good reason");
255 return T(0);
256 };
257
258 bool provides_coeff() const {
259 return false;
260 }
261
262 };
263
264
265 /// ElementaryInterface (formerly FunctorInterfaceWrapper) interfaces a c-function
266
267 /// hard-code your favorite function and interface it with this; Does only
268 /// provide function values, no MRA coefficients. Care must be taken if the
269 /// function we refer to is a singular function, and a on-demand function
270 /// at the same time, since direct computation of coefficients via mraimpl::project
271 /// might suffer from inaccurate quadrature.
272 template<typename T, std::size_t NDIM>
274
275 public:
276 typedef Vector<double, NDIM> coordT; ///< Type of vector holding coordinates
278
279 T (*f)(const coordT&);
280
281 ElementaryInterface(T (*f)(const coordT&)) : f(f) {}
282
283 T operator()(const coordT& x) const {return f(x);}
284
285 coeffT values(const Key<NDIM>& key, const Tensor<double>& quad_x) const {
286 typedef Tensor<T> tensorT;
287 tensorT fval=madness::fcube(key,f,quad_x);
289 }
290 };
291
292 /// FunctorInterface interfaces a class or struct with an operator()()
293 template<typename T, std::size_t NDIM, typename opT>
295
296 public:
297 typedef Vector<double, NDIM> coordT; ///< Type of vector holding coordinates
299
300 opT op;
301
302 FunctorInterface(const opT& op) : op(op) {}
303
304 T operator()(const coordT& x) const {return op(x);}
305 };
306
307 /// FunctionInterface implements a wrapper around any class with the operator()()
308 template<typename T, size_t NDIM, typename opT>
310
312 typedef Vector<double, NDIM> coordT; ///< Type of vector holding coordinates
313
314 const opT op;
315
316 public:
317 FunctionInterface(const opT& op) : op(op) {}
318
319 T operator()(const coordT& coord) const {return op(coord);}
320
321 bool provides_coeff() const {return false;}
322
323 };
324
325 /// base class to compute the wavelet coefficients for an isotropic 2e-operator
326
327 /// all classes that derive from this base class use the Gaussian fitting
328 /// procedure that has been developed for the BSH operator. We simply
329 /// reuse the wavelet coefficients that we get from there to avoid
330 /// evaluating the functions themselves, since the quadrature of singular
331 /// functions is imprecise and slow.
332 template<typename T, std::size_t NDIM>
334 protected:
335 static constexpr std::size_t LDIM=NDIM/2;
336 public:
337
339
340 /// constructor: cf the Coulomb kernel
341
342 /// @param[in] lo the smallest length scale to be resolved
343 /// @param[in] eps the accuracy threshold
344 TwoElectronInterface(double lo, double eps,
347 :rank(), k(kk), lo(lo), hi(1.0) {
348
349 // Presently we must have periodic or non-periodic in all dimensions.
350 for (std::size_t d=1; d<NDIM; ++d) {MADNESS_ASSERT(bc(d,0)==bc(0,0));}
351
353 hi = width.normf(); // Diagonal width of cell
354 if (bc(0,0) == BC_PERIODIC) hi *= 100; // Extend range for periodic summation
355
356 }
357
358 bool provides_coeff() const {
359 return true;
360 }
361
362 /// return the coefficients of the function in 6D (x1,y1,z1, x2,y2,z2)
367
369 print("there is no operator()(coordT&) in TwoElectronInterface, for good reason");
371 return T(0);
372 }
373
374 protected:
375
376 /// make the coefficients from the 1d convolution
378 const Level n=key.level();
380
381 // get the displacements for all 3 dimensions: x12, y12, z12
383 if (NDIM==2) {
384 l0=l[0]-l[1];
385 } else if (NDIM==4) {
386 l0=(l[0]-l[2]);
387 l1=(l[1]-l[3]);
388 } else if (NDIM==6) {
389 l0=(l[0]-l[3]);
390 l1=(l[1]-l[4]);
391 l2=(l[2]-l[5]);
392 } else {
393 MADNESS_EXCEPTION("TwoElectronInterface: NDIM must be 2, 4, or 6",1);
394 }
395
397
398 // lump all the terms together
399 for (long mu=0; mu<rank; mu++) {
400 Tensor<double> r0, r1, r2;
401 if (NDIM>=2) r0=(ops[mu].getop(0)->rnlij(n,l0)).reshape(k*k);
402 if (NDIM>=4) r1=(ops[mu].getop(1)->rnlij(n,l1)).reshape(k*k);
403 if (NDIM>=6) r2=(ops[mu].getop(2)->rnlij(n,l2)).reshape(k*k);
404
405 // include weights in first vector
406 scr1(mu,Slice(_))=r0*ops[mu].getfac();
407
408 if (NDIM==2) {
409 ;
410 } else if (NDIM==4) {
411 scr3(mu,Slice(_))=r1;
412 } else if (NDIM==6) {
413 // merge second and third vector to scr(r,k1,k2)
414 scr2(mu,Slice(_),Slice(_))=outer(r1,r2);
415 } else {
416 MADNESS_EXCEPTION("TwoElectronInterface: NDIM must be 2, 4, or 6",1);
417 }
418 }
419
420 if (NDIM==2) {
421 // perform sum over the rank
422 Tensor<double> result(scr1.dim(1));
423 for (long mu=0; mu<rank; ++mu) result(_)+= scr1(mu,_);
424 return result;
425 }
426 else if (NDIM==4) return inner(scr1,scr3,0,0);
427 else if (NDIM==6) return inner(scr1,scr2,0,0);
428 else {
429 MADNESS_EXCEPTION("TwoElectronInterface: NDIM must be 2, 4, or 6",1);
430 return Tensor<double>();
431 }
432 }
433
434 /// the dimensions are a bit confused (x1,x2, y1,y2, z1,z2) -> (x1,y1,z1, x2,y2,z2)
436 std::vector<long> map(NDIM);
437 if (NDIM==2) {
438 map[0]=0; map[1]=1;
439 return copy(c.reshape(k,k));
440 } else if (NDIM==4) {
441 map[0]=0; map[1]=2;
442 map[2]=1; map[3]=3;
443 return copy(c.reshape(k,k,k,k).mapdim(map));
444 } else if (NDIM==6) {
445 map[0]=0; map[1]=3; map[2]=1;
446 map[3]=4; map[4]=2; map[5]=5;
447 return copy(c.reshape(k,k,k,k,k,k).mapdim(map));
448 }
449 return Tensor<double>();
450 }
451
452 /// initialize the Gaussian fit; uses the virtual function fit() to fit
453 void initialize(const double eps) {
454 GFit<double,LDIM> fit=this->fit(eps);
455 Tensor<double> coeff=fit.coeffs();
456 Tensor<double> expnt=fit.exponents();
457
458 // set some parameters
459 rank=coeff.dim(0);
460 ops.resize(rank);
462
463 // construct all the terms
464 for (int mu=0; mu<rank; ++mu) {
465 // double c = std::pow(sqrt(expnt(mu)/pi),static_cast<int>(NDIM)); // Normalization coeff
466 double c = std::pow(sqrt(expnt(mu)/constants::pi),LDIM); // Normalization coeff
467
468 // We cache the normalized operator so the factor is the value we must multiply
469 // by to recover the coeff we want.
470 ops[mu].setfac(coeff(mu)/c);
471
472 // only 3 dimensions here!
473 for (std::size_t d=0; d<LDIM; ++d) {
474 ops[mu].setop(d,GaussianConvolution1DCache<double>::get(k, expnt(mu)*width[d]*width[d], 0, false));
475 }
476 }
477 }
478
479 /// derived classes must implement this -- cf GFit.h
480 virtual GFit<double,LDIM> fit(const double eps) const = 0;
481
482 /// storing the coefficients
483 mutable std::vector< ConvolutionND<double,NDIM> > ops;
484
485 /// the number of terms in the Gaussian quadrature
486 int rank;
487
488 /// the wavelet order
489 int k;
490
491 /// the smallest length scale that needs to be represented
492 double lo;
493
494 /// the largest length scale that needs to be represented
495 double hi;
496
497 };
498
499
500 /// a function like f(x)=1/x
501 template<typename T, std::size_t NDIM>
503 public:
504
505 /// constructor: cf the Coulomb kernel
506
507 /// @param[in] lo the smallest length scale to be resolved
508 /// @param[in] eps the accuracy threshold
513
514 if (info.hi<0) {
516 if (bc(0,0) == BC_PERIODIC) hi *= 100; // Extend range for periodic summation
517 this->info.hi=hi;
518 }
519 this->initialize(info.thresh);
520 }
521
522 private:
524 static constexpr std::size_t LDIM=NDIM/2;
525
526 GFit<double,LDIM> fit(const double eps) const {
527 return GFit<double,LDIM>(info);
528 }
529 };
530
531 /// a function like f(x)=1/x
532 template<typename T, std::size_t NDIM>
534
535 public:
536
537 /// constructor: cf the Coulomb kernel
538
539 /// @param[in] lo the smallest length scale to be resolved
540 /// @param[in] eps the accuracy threshold
548
549 private:
550 static constexpr std::size_t LDIM=NDIM/2;
551
552 GFit<double,LDIM> fit(const double eps) const {
553 return GFit<double,LDIM>::CoulombFit(this->lo,this->hi,eps,false);
554 }
555 };
556
557 /// a function like f(x) = exp(-mu x)/x
559 public:
560
561 /// constructor: cf the Coulomb kernel
562
563 /// @param[in] mu the exponent of the BSH/inverse Laplacian
564 /// @param[in] lo the smallest length scale to be resolved
565 /// @param[in] eps the accuracy threshold
566 BSHFunctionInterface(double mu, double lo, double eps,
569 : TwoElectronInterface<double,6>(lo,eps,bc,kk), mu(mu) {
570
571 initialize(eps);
572 }
573
574 private:
575
576 double mu;
577
578 GFit<double,3> fit(const double eps) const {
579 return GFit<double,3>::BSHFit(mu,lo,hi,eps,false);
580 }
581 };
582
583 /// a function like f(x)=exp(-mu x)
585 public:
586
587 /// constructor: cf the Coulomb kernel
588
589 /// @param[in] mu the exponent of the Slater function
590 /// @param[in] lo the smallest length scale to be resolved
591 /// @param[in] eps the accuracy threshold
592 SlaterFunctionInterface(double mu, double lo, double eps,
595 : TwoElectronInterface<double,6>(lo,eps,bc,kk), mu(mu) {
596 initialize(eps);
597 }
598
599 private:
600
601 double mu;
602
603 GFit<double,3> fit(const double eps) const {
604 return GFit<double,3>::SlaterFit(mu,lo,hi,eps,false);
605 }
606 };
607
608 /// a function like f(x) = (1 - exp(-mu x))/(2 gamma)
609 class SlaterF12Interface : public TwoElectronInterface<double,6> {
610 public:
611
612 /// constructor: cf the Coulomb kernel
613
614 /// @param[in] mu the exponent of the Slater function
615 /// @param[in] lo the smallest length scale to be resolved
616 /// @param[in] eps the accuracy threshold
617 SlaterF12Interface(double mu, double lo, double eps,
620 : TwoElectronInterface<double,6>(lo,eps,bc,kk), mu(mu) {
621
622 initialize(eps);
623 }
624
625// /// overload the function of the base class
626// coeffT coeff(const Key<6>& key) const {
627//
628// Tensor<double> c=make_coeff(key);
629//
630// // subtract 1 from the (0,0,..,0) element of the tensor,
631// // which is the 0th order polynomial coefficient
632// double one_coeff1=1.0*sqrt(FunctionDefaults<6>::get_cell_volume())
633// *pow(0.5,0.5*6*key.level());
634// std::vector<long> v0(6,0L);
635// c(v0)-=one_coeff1;
636//
637// c.scale(-0.5/mu);
638// return coeffT(map_coeff(c),FunctionDefaults<6>::get_thresh(),TT_FULL);
639// }
640
641 private:
642
643 double mu;
644
645 GFit<double,3> fit(const double eps) const {
646 return GFit<double,3>::F12Fit(mu,lo,hi,eps,false);
647 }
648 };
649
650// Not right
651// /// a function like f(x) = (1 - exp(-mu x))/x
652// class FGInterface : public TwoElectronInterface<double,6> {
653// public:
654//
655// /// constructor: cf the Coulomb kernel
656//
657// /// @param[in] mu the exponent of the Slater function
658// /// @param[in] lo the smallest length scale to be resolved
659// /// @param[in] eps the accuracy threshold
660// FGInterface(double mu, double lo, double eps,
661// const BoundaryConditions<6>& bc=FunctionDefaults<6>::get_bc(),
662// int kk=FunctionDefaults<6>::get_k())
663// : TwoElectronInterface<double,6>(lo,eps,bc,kk), mu(mu) {
664//
665// initialize(eps);
666// }
667//
668// private:
669//
670// double mu;
671//
672// GFit<double,3> fit(const double eps) const {
673// return GFit<double,3>::SlaterFit(mu,lo,hi,eps,false);
674// }
675// };
676
677
678#if 0
679
680 /// ElectronRepulsionInterface implements the electron repulsion term 1/r12
681
682 /// this is essentially just a wrapper around ElectronRepulsion
683 template<typename T, std::size_t NDIM>
684 class ElectronRepulsionInterface : public FunctionFunctorInterface<T,NDIM> {
685
686 typedef GenTensor<T> coeffT;
687 typedef Vector<double, NDIM> coordT; ///< Type of vector holding coordinates
688
689 /// the class computing the coefficients
691
692 public:
693
694 /// constructor takes the same parameters as the Coulomb operator
695 /// which it uses to compute the coefficients
696 ElectronRepulsionInterface(World& world,double lo,double eps,
699 : eri(ElectronRepulsion(eps,eps,bc,k)) {
700 }
701
702
703 /// return value at point x; fairly inefficient
704 T operator()(const coordT& x) const {
705 print("there is no operator()(coordT&) in ElectronRepulsionInterface, for good reason");
707 return T(0);
708 };
709
710
711 /// return sum coefficients for imagined node at key
712 coeffT coeff(const Key<NDIM>& key) const {
713 return coeffT(this->eri.coeff(key),FunctionDefaults<NDIM>::get_thresh(),
714 TT_FULL);
715 }
716
717 };
718
719 /// FGIntegralInterface implements the two-electron integral (1-exp(-gamma*r12))/r12
720
721 /// this is essentially just a wrapper around ElectronRepulsion
722 /// The integral expressed as: 1/r12 - exp(-gamma*r12)/r12
723 /// which can be expressed with an eri and a bsh
724 template<typename T, std::size_t NDIM>
725 class FGIntegralInterface : public FunctionFunctorInterface<T,NDIM> {
726
727 typedef GenTensor<T> coeffT;
728 typedef Vector<double, NDIM> coordT; ///< Type of vector holding coordinates
729
730 /// the class computing the coefficients
733
734 public:
735
736 /// constructor takes the same parameters as the Coulomb operator
737 /// which it uses to compute the coefficients
738 FGIntegralInterface(World& world, double lo, double eps, double gamma,
741 : eri(ElectronRepulsion(eps,eps,0.0,bc,k))
742 , bsh(BSHFunction(eps,eps,gamma,bc,k)) {
743 }
744
745 bool provides_coeff() const {
746 return true;
747 }
748
749 /// return value at point x; fairly inefficient
750 T operator()(const coordT& x) const {
751 print("there is no operator()(coordT&) in FGIntegralInterface, for good reason");
753 return T(0);
754 };
755
756 /// return sum coefficients for imagined node at key
757 coeffT coeff(const Key<NDIM>& key) const {
758 typedef Tensor<T> tensorT;
759 tensorT e_b=eri.coeff(key)-bsh.coeff(key);
761 }
762
763 };
764
765#endif
766
767}
768
769#endif // MADNESS_MRA_FUNCTION_INTERFACE_H__INCLUDED
a function like f(x) = exp(-mu x)/x
Definition function_interface.h:558
GFit< double, 3 > fit(const double eps) const
derived classes must implement this – cf GFit.h
Definition function_interface.h:578
double mu
Definition function_interface.h:576
BSHFunctionInterface(double mu, double lo, double eps, const BoundaryConditions< 6 > &bc=FunctionDefaults< 6 >::get_bc(), int kk=FunctionDefaults< 6 >::get_k())
constructor: cf the Coulomb kernel
Definition function_interface.h:566
This class is used to specify boundary conditions for all operators.
Definition bc.h:72
CompositeFunctorInterface implements a wrapper of holding several functions and functors.
Definition function_interface.h:172
FunctionImpl< T, NDIM > implT
Definition function_interface.h:175
CompositeFunctorInterface(World &world, std::vector< pimplT > ket, pimplT g12, pimplL v1, pimplL v2, std::vector< pimplL > p1, std::vector< pimplL > p2)
constructor takes its Factory
Definition function_interface.h:196
std::vector< std::shared_ptr< implT > > impl_ket_vector
various MRA functions of NDIM dimensionality
Definition function_interface.h:184
std::shared_ptr< implT > pimplT
Definition function_interface.h:177
bool provides_coeff() const
does this functor directly provide sum coefficients? or only function values?
Definition function_interface.h:258
T operator()(const coordT &x) const
return value at point x; fairly inefficient
Definition function_interface.h:252
World & world
Definition function_interface.h:180
std::vector< std::shared_ptr< implL > > impl_p1_vector
supposedly orbital 1
Definition function_interface.h:190
std::shared_ptr< implL > pimplL
Definition function_interface.h:178
std::shared_ptr< implL > impl_m1
various MRA functions of MDIM dimensionality (e.g. 3, if NDIM==6)
Definition function_interface.h:188
FunctionImpl< T, MDIM > implL
Definition function_interface.h:176
std::shared_ptr< implT > impl_eri
supposedly 1/r12
Definition function_interface.h:185
std::shared_ptr< implL > impl_m2
supposedly 1/r2
Definition function_interface.h:189
void make_redundant(const bool fence)
Definition function_interface.h:219
bool check_redundant() const
return true if all constituent functions are in redundant tree state
Definition function_interface.h:238
std::vector< std::shared_ptr< implL > > impl_p2_vector
supposedly orbital 2
Definition function_interface.h:191
Vector< double, NDIM > coordT
Type of vector holding coordinates.
Definition function_interface.h:174
void replicate_low_dim_functions(const bool fence)
replicate low-dimensional functions over all ranks of this world
Definition function_interface.h:210
a function like f(x)=1/x
Definition function_interface.h:533
static constexpr std::size_t LDIM
Definition function_interface.h:550
GFit< double, LDIM > fit(const double eps) const
derived classes must implement this – cf GFit.h
Definition function_interface.h:552
ElectronRepulsionInterface(double lo, double eps, const BoundaryConditions< NDIM > &bc=FunctionDefaults< NDIM >::get_bc(), int kk=FunctionDefaults< NDIM >::get_k())
constructor: cf the Coulomb kernel
Definition function_interface.h:541
ElementaryInterface (formerly FunctorInterfaceWrapper) interfaces a c-function.
Definition function_interface.h:273
ElementaryInterface(T(*f)(const coordT &))
Definition function_interface.h:281
T operator()(const coordT &x) const
You should implement this to return f(x)
Definition function_interface.h:283
T(* f)(const coordT &)
Definition function_interface.h:279
coeffT values(const Key< NDIM > &key, const Tensor< double > &quad_x) const
Definition function_interface.h:285
GenTensor< T > coeffT
Definition function_interface.h:277
Vector< double, NDIM > coordT
Type of vector holding coordinates.
Definition function_interface.h:276
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:100
static int get_k()
Returns the default wavelet order.
Definition funcdefaults.h:164
static const double & get_thresh()
Returns the default threshold.
Definition funcdefaults.h:177
static const Tensor< double > & get_cell_width()
Returns the width of each user cell dimension.
Definition funcdefaults.h:370
static const BoundaryConditions< NDIM > & get_bc()
Returns the default boundary conditions.
Definition funcdefaults.h:311
Abstract base class interface required for functors used as input to Functions.
Definition function_interface.h:68
virtual ~FunctionFunctorInterface()
Definition function_interface.h:136
virtual bool provides_coeff() const
does this functor directly provide sum coefficients? or only function values?
Definition function_interface.h:149
virtual void operator()(const Vector< double *, 4 > &xvals, T *fvals, int npts) const
Definition function_interface.h:111
virtual bool supports_vectorized() const
Does the interface support a vectorized operator()?
Definition function_interface.h:92
GenTensor< T > coeffT
Definition function_interface.h:71
virtual coeffT coeff(const keyT &) const
Definition function_interface.h:138
virtual coeffT values(const keyT &key, const Tensor< double > &tensor) const
Definition function_interface.h:143
virtual bool screened(const Vector< double, NDIM > &c1, const Vector< double, NDIM > &c2) const
Can we screen this function based on the bounding box information?
Definition function_interface.h:87
T value_type
Definition function_interface.h:73
Level special_level_
Definition function_interface.h:75
void set_length_scale(double lo)
adapt the special level to resolve the smallest length scale
Definition function_interface.h:80
virtual void operator()(const Vector< double *, 2 > &xvals, T *fvals, int npts) const
Definition function_interface.h:103
virtual Level special_level() const
Override this to change the minimum level of refinement at special points (default is 6)
Definition function_interface.h:134
virtual void operator()(const Vector< double *, 5 > &xvals, T *fvals, int npts) const
Definition function_interface.h:115
virtual void operator()(const Vector< double *, 3 > &xvals, T *fvals, int npts) const
Definition function_interface.h:107
FunctionFunctorInterface()
Definition function_interface.h:77
Key< NDIM > keyT
Definition function_interface.h:72
virtual std::vector< Vector< double, NDIM > > special_points() const
Override this to return list of special points to be refined more deeply.
Definition function_interface.h:129
virtual void operator()(const Vector< double *, 6 > &xvals, T *fvals, int npts) const
Definition function_interface.h:119
FunctionImpl holds all Function state to facilitate shallow copy semantics.
Definition funcimpl.h:945
FunctionInterface implements a wrapper around any class with the operator()()
Definition function_interface.h:309
const opT op
Definition function_interface.h:314
bool provides_coeff() const
does this functor directly provide sum coefficients? or only function values?
Definition function_interface.h:321
Vector< double, NDIM > coordT
Type of vector holding coordinates.
Definition function_interface.h:312
GenTensor< T > coeffT
Definition function_interface.h:311
FunctionInterface(const opT &op)
Definition function_interface.h:317
T operator()(const coordT &coord) const
You should implement this to return f(x)
Definition function_interface.h:319
FunctorInterface interfaces a class or struct with an operator()()
Definition function_interface.h:294
GenTensor< T > coeffT
Definition function_interface.h:298
Vector< double, NDIM > coordT
Type of vector holding coordinates.
Definition function_interface.h:297
FunctorInterface(const opT &op)
Definition function_interface.h:302
opT op
Definition function_interface.h:300
T operator()(const coordT &x) const
You should implement this to return f(x)
Definition function_interface.h:304
Definition gfit.h:57
static GFit BSHFit(double mu, double lo, double hi, double eps, bool prnt=false)
return a fit for the bound-state Helmholtz function
Definition gfit.h:117
static GFit F12Fit(double gamma, double lo, double hi, double eps, bool prnt=false)
return a fit for the F12 correlation factor
Definition gfit.h:183
static GFit SlaterFit(double gamma, double lo, double hi, double eps, bool prnt=false)
return a fit for the Slater function
Definition gfit.h:140
static GFit CoulombFit(double lo, double hi, double eps, bool prnt=false)
return a fit for the Coulomb function
Definition gfit.h:102
Definition lowranktensor.h:59
long dim(const int i) const
return the number of entries in dimension i
Definition lowranktensor.h:391
a function like f(x)=1/x
Definition function_interface.h:502
static constexpr std::size_t LDIM
Definition function_interface.h:524
GeneralTwoElectronInterface(OperatorInfo info, const BoundaryConditions< NDIM > &bc=FunctionDefaults< NDIM >::get_bc(), int kk=FunctionDefaults< NDIM >::get_k())
constructor: cf the Coulomb kernel
Definition function_interface.h:509
GFit< double, LDIM > fit(const double eps) const
derived classes must implement this – cf GFit.h
Definition function_interface.h:526
OperatorInfo info
Definition function_interface.h:523
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:69
Level level() const
Definition key.h:168
const Vector< Translation, NDIM > & translation() const
Definition key.h:173
a function like f(x) = (1 - exp(-mu x))/(2 gamma)
Definition function_interface.h:609
GFit< double, 3 > fit(const double eps) const
derived classes must implement this – cf GFit.h
Definition function_interface.h:645
double mu
Definition function_interface.h:643
SlaterF12Interface(double mu, double lo, double eps, const BoundaryConditions< 6 > &bc=FunctionDefaults< 6 >::get_bc(), int kk=FunctionDefaults< 6 >::get_k())
constructor: cf the Coulomb kernel
Definition function_interface.h:617
a function like f(x)=exp(-mu x)
Definition function_interface.h:584
GFit< double, 3 > fit(const double eps) const
derived classes must implement this – cf GFit.h
Definition function_interface.h:603
SlaterFunctionInterface(double mu, double lo, double eps, const BoundaryConditions< 6 > &bc=FunctionDefaults< 6 >::get_bc(), int kk=FunctionDefaults< 6 >::get_k())
constructor: cf the Coulomb kernel
Definition function_interface.h:592
double mu
Definition function_interface.h:601
A slice defines a sub-range or patch of a dimension.
Definition slice.h:103
A tensor is a multidimensional array.
Definition tensor.h:317
float_scalar_type normf() const
Returns the Frobenius norm of the tensor.
Definition tensor.h:1726
T max(long *ind=0) const
Return the maximum value (and if ind is non-null, its index) in the Tensor.
Definition tensor.h:1703
base class to compute the wavelet coefficients for an isotropic 2e-operator
Definition function_interface.h:333
double hi
the largest length scale that needs to be represented
Definition function_interface.h:495
coeffT coeff(const Key< NDIM > &key) const
return the coefficients of the function in 6D (x1,y1,z1, x2,y2,z2)
Definition function_interface.h:363
TwoElectronInterface(double lo, double eps, const BoundaryConditions< NDIM > &bc=FunctionDefaults< NDIM >::get_bc(), int kk=FunctionDefaults< NDIM >::get_k())
constructor: cf the Coulomb kernel
Definition function_interface.h:344
int rank
the number of terms in the Gaussian quadrature
Definition function_interface.h:486
T operator()(const Vector< double, NDIM > &x) const
You should implement this to return f(x)
Definition function_interface.h:368
Tensor< double > map_coeff(const Tensor< double > &c) const
the dimensions are a bit confused (x1,x2, y1,y2, z1,z2) -> (x1,y1,z1, x2,y2,z2)
Definition function_interface.h:435
std::vector< ConvolutionND< double, NDIM > > ops
storing the coefficients
Definition function_interface.h:483
Tensor< double > make_coeff(const Key< NDIM > &key) const
make the coefficients from the 1d convolution
Definition function_interface.h:377
bool provides_coeff() const
does this functor directly provide sum coefficients? or only function values?
Definition function_interface.h:358
virtual GFit< double, LDIM > fit(const double eps) const =0
derived classes must implement this – cf GFit.h
double lo
the smallest length scale that needs to be represented
Definition function_interface.h:492
static constexpr std::size_t LDIM
Definition function_interface.h:335
void initialize(const double eps)
initialize the Gaussian fit; uses the virtual function fit() to fit
Definition function_interface.h:453
int k
the wavelet order
Definition function_interface.h:489
GenTensor< T > coeffT
Definition function_interface.h:338
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
A parallel world class.
Definition world.h:132
WorldGopInterface & gop
Global operations.
Definition world.h:207
Computes most matrix elements over 1D operators (including Gaussians)
static double lo
Definition dirac-hatom.cc:23
fit isotropic functions to a set of Gaussians with controlled precision
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:28
Multidimension Key for MRA tree and associated iterators.
#define MADNESS_PRAGMA_CLANG(x)
Definition madness_config.h:200
#define MADNESS_PRAGMA_GCC(x)
Definition madness_config.h:205
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
#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
Vector< double, 3 > coordT
Definition mcpfit.cc:48
constexpr double pi
Mathematical constant .
Definition constants.h:48
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
@ BC_PERIODIC
Definition bc.h:52
Vector< double, 3 > coordT
Definition corepotential.cc:54
@ redundant
s coeffs everywhere
Definition funcdefaults.h:65
static double r2(const coord_3d &x)
Definition smooth.h:45
Tensor< double > tensorT
Definition distpm.cc:21
std::vector< Function< T, NDIM > > impl2function(const std::vector< std::shared_ptr< FunctionImpl< T, NDIM > > > vimpl)
Definition vmra.h:694
int64_t Translation
Definition key.h:57
static const Slice _(0,-1, 1)
int Level
Definition key.h:58
std::enable_if< std::is_base_of< ProjectorBase, projT >::value, OuterProjector< projT, projQ > >::type outer(const projT &p0, const projQ &p1)
Definition projector.h:457
static double pop(std::vector< double > &v)
Definition SCF.cc:115
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:226
Tensor< T > fcube(const Key< NDIM > &, T(*f)(const Vector< double, NDIM > &), const Tensor< double > &)
Definition mraimpl.h:2133
@ TT_FULL
Definition gentensor.h:120
NDIM & f
Definition mra.h:2528
const Function< T, NDIM > & change_tree_state(const Function< T, NDIM > &f, const TreeState finalstate, bool fence=true)
change tree state of a function
Definition mra.h:2854
double inner(response_space &a, response_space &b)
Definition response_functions.h:639
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence.
Definition mra.h:2096
Definition mraimpl.h:51
const double mu
Definition navstokes_cosines.cc:95
static const double d
Definition nonlinschro.cc:121
static const double c
Definition relops.cc:10
static const double thresh
Definition rk.cc:45
static const long k
Definition rk.cc:44
Definition test_dc.cc:47
Definition convolution1d.h:992
Definition operatorinfo.h:58
double hi
Definition operatorinfo.h:67
double thresh
Definition operatorinfo.h:65
Defines and implements most of Tensor.
constexpr std::size_t NDIM
Definition testgconv.cc:54
const auto npts
Definition testgconv.cc:52