33 #ifndef MADNESS_MRA_CONVOLUTION1D_H__INCLUDED
34 #define MADNESS_MRA_CONVOLUTION1D_H__INCLUDED
61 static void copy_2d_patch(
T*
restrict out,
long ldout,
const T*
restrict in,
long ldin,
long n,
long m) {
62 for (
long i=0; i<n; ++i, out+=ldout, in+=ldin) {
63 for (
long j=0; j<
m; ++j) {
82 for (
long i=0; i<nm; ++i) b[i] = a[i];
89 for (
long i=0; i<n4; i+=4, a0+=m4) {
94 for (
long j=0; j<
m; ++j, bi+=n) {
107 for (
long i=n4; i<n; ++i)
108 for (
long j=0; j<
m; ++j)
116 template <
typename T>
120 for (
long i=0; i<n; ++i, a+=
m, b+=r) {
126 for (
long i=0; i<n; ++i, a+=
m, b+=r) {
134 MADNESS_ASSERT((r&0x1L)==0);
135 for (
long i=0; i<n; ++i, a+=
m, b+=r) {
136 for (
long j=0; j<r; j+=2) {
149 template <
typename Q>
155 Tensor<typename Tensor<Q>::scalar_type>
Rs,
Ts;
173 if (Rnormf > 1e-20) {
179 Tensor<Q> NS =
copy(R);
180 for (
int i=0; i<k; ++i)
181 for (
int j=0; j<k; ++j)
183 NSnormf = NS.normf();
187 Rnorm = Tnorm = Rnormf = Tnormf = NSnormf = 0.0;
188 N_F = N_up = N_diff = 0.0;
205 if (Rnormf > 1e-20)
make_approx(R, RU, Rs, RVT, Rnorm);
206 if (Tnormf > 1e-20)
make_approx(T, TU, Ts, TVT, Tnorm);
211 N_diff=(R-
T).normf();
219 Tensor<Q>& RU, Tensor<
typename Tensor<Q>::scalar_type>& Rs, Tensor<Q>& RVT,
double&
norm) {
222 for (
int i=0; i<n; ++i) {
223 for (
int j=0; j<n; ++j) {
227 for (
int i=n-1; i>1; --i) {
233 double rnorm = 1.0/
norm;
234 for (
int i=0; i<n; ++i) {
246 template <
typename Q>
276 MADNESS_ASSERT(
autoc(k,&c));
302 for (
int R=-maxR;
R<=
maxR; ++
R) {
303 if (!
issmall(n,
R*twon+lx))
return false;
325 const Tensor<Q>* p=rnlij_cache.
getptr(n,lx);
335 R.scale(pow(0.5,0.5*n));
338 rnlij_cache.
set(n,lx,R);
339 return *rnlij_cache.
getptr(n,lx);
362 MADNESS_ASSERT(sx>=0 and tx>=0);
370 const Slice s0(0,k-1), s1(k,2*k-1);
377 Rm = Tensor<Q>(2*
k,2*
k);
378 if (n>0) Rm(s0,s0)=
rnlij(n-1,lx_half);
387 if (t_off==0 and s_off==0) T=
copy(Rm(s0,s0));
388 if (t_off==0 and s_off==1) T=
copy(Rm(s0,s1));
389 if (t_off==1 and s_off==0) T=
copy(Rm(s1,s0));
390 if (t_off==1 and s_off==1) T=
copy(Rm(s1,s1));
400 Tensor<Q> RT(k,k), TT(k,k);
410 return mod_ns_cache.
getptr(cache_key);
423 #if 0 // UNUSED VARIABLES
424 Slice s0(0,k-1), s1(k,2*k-1);
426 const Tensor<Q> r0 =
rnlij(n+1,lx2);
427 const Tensor<Q> rp =
rnlij(n+1,lx2+1);
428 const Tensor<Q> rm =
rnlij(n+1,lx2-1);
430 R = Tensor<Q>(2*
k,2*
k);
439 copy_2d_patch(R.ptr(), 2*
k, r0.ptr(),
k,
k,
k);
440 copy_2d_patch(R.ptr()+2*k*k +
k, 2*
k, r0.ptr(),
k,
k,
k);
441 copy_2d_patch(R.ptr()+2*k*
k, 2*
k, rp.ptr(),
k,
k,
k);
442 copy_2d_patch(R.ptr() +
k, 2*
k, rm.ptr(),
k,
k,
k);
458 Tensor<Q> RT(2*k,2*k);
466 copy_2d_patch(T.ptr(),
k, R.ptr(), 2*
k,
k,
k);
474 return ns_cache.
getptr(n,lx);
487 const Tensor<Q>* p=rnlp_cache.
getptr(n,lx);
512 for (
int R=-maxR;
R<=
maxR; ++
R) {
521 rnlp_cache.
set(n, lx, r);
523 return *rnlp_cache.
getptr(n,lx);
530 template <
typename Q,
int NDIM>
566 template <
typename Q>
577 : coeff(coeff), exponent(exponent), m(m),
581 Q ee = coeff*
exp(-exponent*x*x);
582 for (
int mm=0; mm<m; ++mm) ee *= x;
592 template <
typename Q,
typename opT>
613 const Tensor<Q>& rp = this->
get_rnlp(natl, lx);
614 const Tensor<Q>& rm = this->
get_rnlp(natl,-lx);
615 if (rp.normf()<1e-12 && rm.normf()<1e-12) ++nzero;
632 : n(n), lx(lx), q(*q) {}
636 double fac = std::pow(0.5,n);
639 Q
f = q.op(fac*x)*
sqrt(fac);
641 for (
long p=0; p<twok; ++p) v(p) += f*phix[p];
647 return adq1(lx, lx+1,
Shmoo(n, lx,
this), 1e-12,
652 if (lx < 0) lx = 1 - lx;
655 if (lx <= 7)
return false;
658 if (n >= 0) lx = lx << n;
670 template <
typename Q>
673 static int maxR(
bool periodic,
double expnt) {
688 int m,
bool periodic,
double arg = 0.0)
695 MADNESS_ASSERT(m>=0 && m<=2);
729 int twok = 2*this->
k;
733 if (lx<0) lx = -lx-1;
748 Q scaledcoeff = coeff*pow(0.5,0.5*n*(2*m+1));
767 double fourn = std::pow(4.0,
double(n));
768 double beta = expnt * pow(0.25,
double(n));
769 double h = 1.0/
sqrt(beta);
770 long nbox = long(1.0/h);
771 if (nbox < 1) nbox = 1;
780 double sch = std::abs(scaledcoeff*h);
781 if (m == 1) sch *=
expnt;
782 else if (m == 2) sch *= expnt*
expnt;
783 double argmax = std::abs(
log(1e-22/sch));
785 for (
long box=0; box<nbox; ++box) {
786 double xlo = box*h + lx;
787 if (beta*xlo*xlo > argmax)
break;
788 for (
long i=0; i<this->
npt; ++i) {
794 double xx = xlo + h*this->
quad_x(i);
795 Q ee = scaledcoeff*
exp(-beta*xx*xx)*this->
quad_w(i)*h;
802 ee *= (4.0*xx*xx*expnt*expnt - 2.0*expnt*fourn);
806 for (
long p=0; p<twok; ++p) v(p) += ee*phix[p];
813 for (
long p=0; p<twok; ++p) v(p) = -v(p);
814 for (
long p=1; p<twok; p+=2) v(p) = -v(p);
822 double beta = expnt * pow(0.25,
double(n));
831 return (beta*ll*ll > 49.0);
836 template <
typename Q>
847 iterator it = map.
find(key);
848 if (it == map.
end()) {
866 #endif // MADNESS_MRA_CONVOLUTION1D_H__INCLUDED
Tensor< double > hgT
Definition: convolution1d.h:256
bool get_issmall(Level n, Translation lx) const
Returns true if the block of rnlp is expected to be small including periodicity.
Definition: convolution1d.h:296
int maxR
Number of lattice translations for sum.
Definition: convolution1d.h:252
Definition: shared_ptr_bits.h:38
Tensor< Q > rnlp(Level n, Translation lx) const
Compute the projection of the operator onto the double order polynomials.
Definition: convolution1d.h:728
const mpreal exp(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2234
Tensor< typename Tensor< Q >::scalar_type > Ts
hold relative errors, NOT the singular values..
Definition: convolution1d.h:155
static ConcurrentHashMap< hashT, std::shared_ptr< GaussianConvolution1D< Q > > > map
Definition: convolution1d.h:838
const double pi
Mathematical constant pi.
Definition: constants.h:44
GenericConvolution1D()
Definition: convolution1d.h:599
Level n
Definition: convolution1d.h:627
T norm(Vector< T, N > v)
Compute norm of a Vector.
Definition: array.h:447
const double R
Definition: dielectric.cc:191
std::complex< double > double_complex
Definition: lineplot.cc:16
iterator for hash
Definition: worldhashmap.h:190
1D convolution with (derivative) Gaussian; coeff and expnt given in simulation coordinates [0...
Definition: convolution1d.h:671
GaussianGenericFunctor(Q coeff, double exponent, int m=0)
Definition: convolution1d.h:576
const Level natlev
Level to evaluate.
Definition: convolution1d.h:684
const mpreal log(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2213
SimpleCache< Tensor< Q >, 1 > rnlp_cache
Definition: convolution1d.h:260
const Vector< Translation, NDIM > & translation() const
Definition: key.h:225
const int NDIM
Definition: tdse1.cc:44
bool issmall(Level n, Translation lx) const
Returns true if the block of rnlp is expected to be small.
Definition: convolution1d.h:651
iterator end()
Definition: worldhashmap.h:579
Tensor< Q > RVT
Definition: convolution1d.h:154
A simple, fixed dimension Coordinate.
Definition: array.h:99
Tensor< typename Tensor< Q >::scalar_type > Rs
Definition: convolution1d.h:155
const Tensor< Q > & get_rnlp(Level n, Translation lx) const
Definition: convolution1d.h:486
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t rnd_mode)
Definition: mpreal.h:2201
Level natural_level() const
Definition: convolution1d.h:585
const double L
Definition: 3dharmonic.cc:123
double N_up
Definition: convolution1d.h:161
Defines common mathematical and physical constants.
Tensor< double > quad_x
Definition: convolution1d.h:253
Generic 1D convolution using brute force (i.e., slow) adaptive quadrature for rnlp.
Definition: convolution1d.h:593
void make_approx(const Tensor< Q > &R, Tensor< Q > &RU, Tensor< typename Tensor< Q >::scalar_type > &Rs, Tensor< Q > &RVT, double &norm)
Definition: convolution1d.h:218
void aligned_add(long n, double *restrict a, const double *restrict b)
Tensor< Q > rnlp(Level n, Translation lx) const
Compute the projection of the operator onto the double order polynomials.
Definition: convolution1d.h:646
Tensor< double > quad_w
Definition: convolution1d.h:254
SimpleCache< Tensor< Q >, 1 > rnlij_cache
Definition: convolution1d.h:261
Provides the common functionality/interface of all 1D convolutions.
Definition: convolution1d.h:247
Definition: convolution1d.h:567
ConvolutionData1D(const Tensor< Q > &R, const Tensor< Q > &T)
Definition: convolution1d.h:169
void setfac(Q value)
Definition: convolution1d.h:556
void legendre_scaling_functions(double x, long k, double *p)
Evaluate the first k Legendre scaling functions.
Definition: legendre.cc:90
Provides routines for internal use optimized for aligned data.
NDIM & f
Definition: mra.h:2179
Q opT
The apply function uses this to infer resultT=opT*inputT.
Definition: convolution1d.h:249
returnT operator()(double x) const
Definition: convolution1d.h:634
ConvolutionND(const ConvolutionND &other)
Definition: convolution1d.h:538
int npt
Number of quadrature points (is this used?)
Definition: convolution1d.h:251
Tensor< Q > R
Definition: convolution1d.h:153
Tensor< Q > T
if NS: R=ns, T=T part of ns; if modified NS: T= r^(n-1)
Definition: convolution1d.h:153
double Tnorm
Definition: convolution1d.h:158
funcT::returnT adq1(double lo, double hi, const funcT &func, double thresh, int n, const double *x, const double *w, int level)
Definition: adquad.h:64
Tensor< double > c
Definition: convolution1d.h:255
Definition: worldhashmap.h:57
int k
Wavelet order.
Definition: convolution1d.h:250
const double beta
Definition: gygi_soltion.cc:63
T inner(const vecfunc< T, NDIM > &a, const vecfunc< T, NDIM > &b)
the non-linear solver requires an inner product
Definition: nemo.h:112
#define PROFILE_MEMBER_FUNC(classname)
Definition: worldprofile.h:199
Array idential to C++0X arrays.
Definition: stdarray_bits.h:11
!!! Note that if Rnormf is zero then ***ALL*** of the tensors are empty
Definition: convolution1d.h:150
ConcurrentHashMap< hashT, std::shared_ptr< GaussianConvolution1D< Q > > >::datumT datumT
Definition: convolution1d.h:840
virtual bool issmall(Level n, Translation lx) const =0
Returns true if the block of rnlp is expected to be small.
const GenericConvolution1D< Q, opT > & q
Definition: convolution1d.h:629
Tensor< double > hgT2k
Definition: convolution1d.h:257
virtual Tensor< Q > rnlp(Level n, Translation lx) const =0
Compute the projection of the operator onto the double order polynomials.
Defines and implements most of Tensor.
virtual Level natural_level() const
Returns the level for projection.
Definition: convolution1d.h:707
const ConvolutionData1D< Q > * mod_nonstandard(const Key< 2 > &op_key) const
Returns a pointer to the cached modified nonstandard form of the operator.
Definition: convolution1d.h:347
Convolution1D(int k, int npt, int maxR, double arg=0.0)
Definition: convolution1d.h:267
const double a2
Definition: vnucso.cc:91
double arg
Definition: convolution1d.h:258
#define PROFILE_BLOCK(name)
Definition: worldprofile.h:197
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
const Tensor< Q > & rnlij(Level n, Translation lx, bool do_transpose=false) const
Computes the transition matrix elements for the convolution for n,l.
Definition: convolution1d.h:324
#define max(a, b)
Definition: lda.h:53
Vector< T, 1 > vec(T x)
Your friendly neighborhood factory function.
Definition: array.h:456
double Rnormf
Definition: convolution1d.h:158
const Q coeff
Coefficient.
Definition: convolution1d.h:682
const int k
Definition: dielectric.cc:184
Simplified interface around hash_map to cache stuff for 1D.
Definition: simplecache.h:45
const Q * getptr(const Key< NDIM > &key) const
If key is present return pointer to cached value, otherwise return NULL.
Definition: simplecache.h:65
std::shared_ptr< Convolution1D< Q > > getop(int dim) const
Definition: convolution1d.h:552
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:1835
SimpleCache< ConvolutionData1D< Q >, 2 > mod_ns_cache
Definition: convolution1d.h:263
void fast_transpose(long n, long m, const T *a, T *restrict b)
a(n,m) –> b(m,n) ... optimized for smallish matrices
Definition: convolution1d.h:71
Prototypes for a partial interface from Tensor to LAPACK.
GaussianConvolution1D(int k, Q coeff, double expnt, int m, bool periodic, double arg=0.0)
Definition: convolution1d.h:687
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
ConvolutionND()
Definition: convolution1d.h:536
bool gauss_legendre(int n, double xlo, double xhi, double *x, double *w)
Definition: legendre.cc:231
Level level() const
Definition: key.h:220
std::pair< iterator, bool > insert(const datumT &datum)
Definition: worldhashmap.h:469
Tensor< Q > TU
Definition: convolution1d.h:154
Q getfac() const
Definition: convolution1d.h:560
Array of 1D convolutions (one / dimension)
Definition: convolution1d.h:531
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness::Hash.
Definition: array.h:62
const ConvolutionData1D< Q > * nonstandard(Level n, Translation lx) const
Returns a pointer to the cached nonstandard form of the operator.
Definition: convolution1d.h:414
ConcurrentHashMap< hashT, std::shared_ptr< GaussianConvolution1D< Q > > >::iterator iterator
Definition: convolution1d.h:839
void hash_combine(hashT &seed, const T &v)
Combine hash values.
Definition: worldhash.h:259
double NSnormf
Definition: convolution1d.h:158
void svd(const Tensor< T > &a, Tensor< T > &U, Tensor< typename Tensor< T >::scalar_type > &s, Tensor< T > &VT)
Compute the singluar value decomposition of an n-by-m matrix using *gesvd.
Definition: lapack.cc:273
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
std::size_t hashT
The hash value type.
Definition: worldhash.h:148
GenericConvolution1D(int k, const opT &op, int maxR, double arg=0.0)
Definition: convolution1d.h:601
int Level
Definition: key.h:58
ConvolutionData1D(const Tensor< Q > &R, const Tensor< Q > &T, const bool modified)
Definition: convolution1d.h:197
virtual ~Convolution1D()
Definition: convolution1d.h:265
void aligned_sub(long n, double *restrict a, const double *restrict b)
const double m
Definition: gfit.cc:199
iterator begin()
Definition: stdarray_bits.h:26
double Tnormf
Definition: convolution1d.h:158
Translation lx
Definition: convolution1d.h:628
Shmoo(Level n, Translation lx, const GenericConvolution1D< Q, opT > *q)
Definition: convolution1d.h:631
Tensor< Q > TVT
SVD approximations to R and T.
Definition: convolution1d.h:154
double N_F
the norms according to Beylkin 2008, Eq. (21) ff
Definition: convolution1d.h:161
double N_diff
Definition: convolution1d.h:161
const double a1
Definition: vnucso.cc:90
Definition: convolution1d.h:837
Q phase(double_complex R) const
Definition: convolution1d.h:481
void set(const Key< NDIM > &key, const Q &val)
Set value associated with key ... gives ownership of a new copy to the container. ...
Definition: simplecache.h:91
virtual ~GaussianConvolution1D()
Definition: convolution1d.h:705
const int m
Order of derivative (0, 1, or 2 only)
Definition: convolution1d.h:685
T * shrink(long n, long m, long r, const T *a, T *restrict b)
a(i,j) –> b(i,j) for i=0..n-1 and j=0..r-1 noting dimensions are a(n,m) and b(n,r).
Definition: convolution1d.h:117
Tensor< Q > returnT
Definition: convolution1d.h:626
double Rnorm
Definition: convolution1d.h:158
bool autoc(int k, Tensor< double > *c)
Return the autocorrelation coefficients for scaling functions of given order.
Definition: twoscale.cc:239
Tensor< T > transpose(const Tensor< T > &t)
Returns a new deep copy of the transpose of the input tensor.
Definition: tensor.h:1945
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
Q operator()(double x) const
Definition: convolution1d.h:580
virtual Level natural_level() const
Returns the level for projection.
Definition: convolution1d.h:313
A slice defines a sub-range or patch of a dimension.
Definition: slice.h:103
void setop(int dim, const std::shared_ptr< Convolution1D< Q > > &op)
Definition: convolution1d.h:548
Definition: convolution1d.h:625
SimpleCache< ConvolutionData1D< Q >, 1 > ns_cache
Definition: convolution1d.h:262
#define restrict
Definition: config.h:403
int64_t Translation
Definition: key.h:57
iterator find(const keyT &key)
Definition: worldhashmap.h:524
bool two_scale_hg(int k, Tensor< double > *hg)
Definition: twoscale.cc:156
Tensor< Q > RU
Definition: convolution1d.h:154
Tensor< double > hg
Definition: convolution1d.h:256
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform(World &world, const std::vector< Function< T, NDIM > > &v, const DistributedMatrix< R > &c, bool fence=true)
Definition: chem/SCF.cc:86
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
const double expnt
Exponent.
Definition: convolution1d.h:683
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
Q phase(double R) const
Definition: convolution1d.h:477
bool issmall(Level n, Translation lx) const
Returns true if the block is expected to be small.
Definition: convolution1d.h:821
iterator end()
Definition: stdarray_bits.h:28
ConvolutionND(std::shared_ptr< Convolution1D< Q > > op, Q fac=1.0)
Definition: convolution1d.h:543
virtual Level natural_level() const
Returns the level for projection.
Definition: convolution1d.h:623