32#ifndef MADNESS_MRA_CONVOLUTION1D_H__INCLUDED
33#define MADNESS_MRA_CONVOLUTION1D_H__INCLUDED
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)
162 template <
typename Q>
192 for (
int i=0; i<
k; ++i)
193 for (
int j=0; j<
k; ++j)
234 for (
int i=0; i<n; ++i) {
235 for (
int j=0; j<n; ++j) {
239 for (
int i=n-1; i>1; --i) {
245 double rnorm = 1.0/
norm;
246 for (
int i=0; i<n; ++i) {
258 template <
typename Q>
326 const auto closest_l = l<=0 ? l : l-1;
388 R.scale(
pow(0.5,0.5*n));
440 if (t_off==0 and s_off==0) T=
copy(Rm(
s0,
s0));
441 if (t_off==0 and s_off==1) T=
copy(Rm(
s0,s1));
442 if (t_off==1 and s_off==0) T=
copy(Rm(s1,
s0));
443 if (t_off==1 and s_off==1) T=
copy(Rm(s1,s1));
530 if constexpr (std::is_arithmetic_v<Q>)
580 template <
typename Q,
int NDIM>
582 std::array<std::shared_ptr<Convolution1D<Q> >,
NDIM>
ops;
595 std::fill(
ops.begin(),
ops.end(),
op);
602 std::shared_ptr<Convolution1D<Q> >
getop(
int dim)
const {
617 for (
int d = 0;
d !=
NDIM; ++
d) {
619 result[
d] =
ops[
d]->lattice_summed();
626 template <
typename Q>
642 for (
int mm=0; mm<
m; ++mm) ee *= x;
652 template <
typename Q,
typename opT>
696 double fac = std::pow(0.5,
n);
699 Q f =
q.op(fac*x)*sqrt(fac);
701 for (
long p=0;
p<twok; ++
p)
v(
p) +=
f*phix[
p];
707 return adq1(lx, lx+1,
Shmoo(n, lx,
this), 1
e-12,
712 if (lx < 0) lx = 1 - lx;
715 if (lx <= 7)
return false;
718 if (n >= 0) lx = lx << n;
730 template <
typename Q>
735 const int maxR_lattice = lattice_range.
get_range();
736 if (!maxR_lattice) {
return 0; }
738 const int maxR_rng = rng.finite() ? (rng.iextent_x2(1
e-16) + 1)/2 :
std::numeric_limits<int>::
max();
740 const int maxR_G = std::max(1,
int(sqrt(16.0 * 2.3 /
expnt) + 1));
741 return std::min({maxR_lattice, maxR_rng,maxR_G});
792 int twok = 2*this->
k;
795 std::vector<KahanAccumulator<Q>> v_accumulator(twok);
796 constexpr bool use_kahan =
false;
799 std::pair<double, double> integration_limits{0,1};
802 const auto two_to_nm1 = (1ul << n) * 0.5;
804 integration_limits = std::make_pair(
805 std::min(std::max(-two_to_nm1 * this->
range.
iextent_x2() - lx, 0.), 1.), 1.);
807 integration_limits = std::make_pair(
808 0., std::max(std::min(two_to_nm1 * this->
range.
iextent_x2() - lx, 1.), 0.));
812 if (integration_limits.first == integration_limits.second) {
821 const auto x0 = integration_limits.first;
822 const auto x1 = integration_limits.second;
823 const auto L = x1 -
x0;
857 double fourn = std::pow(4.0,
double(n));
859 double h = 1.0/sqrt(
beta);
860 long nbox = long(1.0/
h);
861 if (nbox < 1) nbox = 1;
870 const auto range_edge_in_interval = [&]() {
871 const auto two_to_nm1 = (1ul << n) * 0.5;
872 const auto range_boundary = two_to_nm1 * this->
range.
N();
874 return range_boundary >= lx && range_boundary <= lx+1;
877 return range_boundary <= -lx && range_boundary >= -lx-1;
882 if (range_edge_in_interval()) {
883 nbox = std::max(nbox,
static_cast<long>(ceil(1./((1ul << n) * this->
range.
sigma()))));
898 double argmax =
std::abs(log(1
e-22/sch));
901 const bool left_to_right = lx >= 0;
903 const double xstartedge = left_to_right ?
x0+lx : lx + 1;
909 const long first_pt = left_to_right ? this->
npt-1: 0;
910 const long sentinel_pt = left_to_right ? -1 : this->
npt;
911 const auto next_pt = [left_to_right](
auto i) {
return left_to_right ? i-1 : i+1; };
913 double xlo = left_to_right ? xstartedge : xstartedge-
h;
915 for (
long box=0; box!=nbox; ++box, xlo = (left_to_right ? xhi : xlo-
h)) {
920 if (
beta*xabs_min*xabs_min > argmax)
break;
922 for (
long i=first_pt; i!=sentinel_pt; i=next_pt(i)) {
928 double xx = xlo +
h*this->
quad_x(i);
931 const auto x = xx *
pow(0.5,
double(n));
944 for (
long p=0;
p<twok; ++
p) {
945 if constexpr (use_kahan)
946 v_accumulator[
p] += ee * phix[
p];
948 v(
p) += ee * phix[
p];
953 if constexpr (use_kahan) {
954 for (
long p = 0;
p < twok; ++
p)
955 v(
p) =
static_cast<Q>(v_accumulator[
p]);
971 const double overly_large_beta_r2 = 49.0;
973 const auto ll = lx - 1;
974 return beta * ll * ll > overly_large_beta_r2;
976 const auto ll = lx + 1;
977 return beta * ll * ll > overly_large_beta_r2;
984 template <
typename Q>
990 static std::shared_ptr< GaussianConvolution1D<Q> >
get(
int k,
double expnt,
int m,
const LatticeRange& lattice_range,
991 double bloch_k = 0.0,
1004 if (it ==
map.end()) {
1020 auto& result = it->second;
1024 result->lattice_summed() ==
static_cast<bool>(lattice_range) &&
1025 result->range == range &&
1026 result->bloch_k == bloch_k);
1036 ConcurrentHashMap< hashT, std::shared_ptr< GaussianConvolution1D<double> > >
Provides routines for internal use optimized for aligned data.
std::complex< double > double_complex
Definition cfft.h:14
long dim(int i) const
Returns the size of dimension i.
Definition basetensor.h:147
Definition worldhashmap.h:396
Provides the common functionality/interface of all 1D convolutions.
Definition convolution1d.h:259
SimpleCache< Tensor< Q >, 1 > rnlp_cache
Definition convolution1d.h:273
Tensor< double > hgT2k
Definition convolution1d.h:271
virtual Level natural_level() const
Returns the level for projection.
Definition convolution1d.h:365
bool lattice_summed() const
Definition convolution1d.h:278
int maxR
Number of lattice translations for sum.
Definition convolution1d.h:264
Tensor< double > hg
Definition convolution1d.h:270
int k
Wavelet order.
Definition convolution1d.h:262
SimpleCache< ConvolutionData1D< Q >, 1 > ns_cache
Definition convolution1d.h:275
Tensor< double > hgT
Definition convolution1d.h:270
Tensor< double > c
Definition convolution1d.h:269
double bloch_k
k in exp(i k R) Bloch phase factor folded into lattice sum
Definition convolution1d.h:265
const Tensor< Q > & get_rnlp(Level n, Translation lx) const
Definition convolution1d.h:537
bool rnlp_is_zero(Level n, Translation l) const
Definition convolution1d.h:345
SimpleCache< Tensor< Q >, 1 > rnlij_cache
Definition convolution1d.h:274
virtual Tensor< Q > rnlp(Level n, Translation lx) const =0
Compute the projection of the operator onto the double order polynomials.
Convolution1D(int k, int npt, int maxR, double bloch_k=0.0, KernelRange rng={})
Definition convolution1d.h:283
bool range_restricted() const
Definition convolution1d.h:279
int npt
Number of quadrature points (is this used?)
Definition convolution1d.h:263
KernelRange range
if range is nonnull, kernel range limited to to range (in simulation cell units), useful for finite-r...
Definition convolution1d.h:266
virtual ~Convolution1D()
Definition convolution1d.h:281
Tensor< double > quad_w
Definition convolution1d.h:268
Q phase(double R) const
Definition convolution1d.h:529
SimpleCache< ConvolutionData1D< Q >, 2 > mod_ns_cache
Definition convolution1d.h:276
bool get_issmall(Level n, Translation lx) const
Definition convolution1d.h:318
Tensor< double > quad_x
Definition convolution1d.h:267
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:377
virtual bool issmall(Level n, Translation lx) const =0
const ConvolutionData1D< Q > * mod_nonstandard(const Key< 2 > &op_key) const
Returns a pointer to the cached modified make_nonstandard form of the operator.
Definition convolution1d.h:400
Q opT
The apply function uses this to infer resultT=opT*inputT.
Definition convolution1d.h:261
const ConvolutionData1D< Q > * nonstandard(Level n, Translation lx) const
Returns a pointer to the cached make_nonstandard form of the operator.
Definition convolution1d.h:466
Array of 1D convolutions (one / dimension)
Definition convolution1d.h:581
std::shared_ptr< Convolution1D< Q > > getop(int dim) const
Definition convolution1d.h:602
void setop(int dim, const std::shared_ptr< Convolution1D< Q > > &op)
Definition convolution1d.h:598
ConvolutionND(const ConvolutionND &other)
Definition convolution1d.h:588
ConvolutionND()
Definition convolution1d.h:586
std::array< std::shared_ptr< Convolution1D< Q > >, NDIM > ops
Definition convolution1d.h:582
Q fac
Definition convolution1d.h:583
ConvolutionND(std::shared_ptr< Convolution1D< Q > > op, Q fac=1.0)
Definition convolution1d.h:593
Q getfac() const
Definition convolution1d.h:610
array_of_bools< NDIM > lattice_summed() const
Definition convolution1d.h:615
void setfac(Q value)
Definition convolution1d.h:606
1D convolution with (derivative) Gaussian; coeff and expnt given in simulation coordinates [0,...
Definition convolution1d.h:731
const int m
Order of derivative (0, 1, or 2 only)
Definition convolution1d.h:747
Tensor< Q > rnlp(Level n, const Translation lx) const final
Compute the projection of the operator onto the double order polynomials.
Definition convolution1d.h:791
virtual ~GaussianConvolution1D()
Definition convolution1d.h:768
const double expnt
Exponent.
Definition convolution1d.h:745
const Level natlev
Level to evaluate.
Definition convolution1d.h:746
GaussianConvolution1D(int k, Q coeff, double expnt, int m, const LatticeRange &lattice_range, double bloch_k=0.0, KernelRange rng={})
Definition convolution1d.h:749
const Q coeff
Coefficient.
Definition convolution1d.h:744
bool issmall(Level n, Translation lx) const final
Definition convolution1d.h:962
static int maxR(const LatticeRange &lattice_range, double expnt, const KernelRange &rng={})
Definition convolution1d.h:734
virtual Level natural_level() const final
Returns the level for projection.
Definition convolution1d.h:770
Definition convolution1d.h:627
Q coeff
Definition convolution1d.h:629
int m
Definition convolution1d.h:631
Level natural_level() const
Definition convolution1d.h:645
Level natlev
Definition convolution1d.h:632
GaussianGenericFunctor(Q coeff, double exponent, int m=0)
Definition convolution1d.h:636
Q operator()(double x) const
Definition convolution1d.h:640
double exponent
Definition convolution1d.h:630
Generic 1D convolution using brute force (i.e., slow) adaptive quadrature for rnlp.
Definition convolution1d.h:653
bool issmall(Level n, Translation lx) const final
Definition convolution1d.h:711
GenericConvolution1D(int k, const opT &op, int maxR, double bloch_k=0.0)
Definition convolution1d.h:661
opT op
Definition convolution1d.h:655
Tensor< Q > rnlp(Level n, Translation lx) const final
Compute the projection of the operator onto the double order polynomials.
Definition convolution1d.h:706
virtual Level natural_level() const final
Returns the level for projection.
Definition convolution1d.h:683
long maxl
At natural level is l beyond which operator is zero.
Definition convolution1d.h:656
GenericConvolution1D()
Definition convolution1d.h:659
Definition kernelrange.h:60
bool finite_soft() const
Definition kernelrange.h:159
double sigma() const
Definition kernelrange.h:152
int iextent_x2(double epsilon=extent_default_epsilon) const
Definition kernelrange.h:198
bool finite() const
Definition kernelrange.h:155
unsigned int N() const
Definition kernelrange.h:150
double value(double r) const
Definition kernelrange.h:176
bool finite_hard() const
Definition kernelrange.h:157
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:70
Level level() const
Definition key.h:169
const Vector< Translation, NDIM > & translation() const
Definition key.h:174
Denotes lattice summation over range [-N, N]; N=0 is equivalent to including the simulation cell only...
Definition kernelrange.h:17
int get_range() const
Definition kernelrange.h:41
Simplified interface around hash_map to cache stuff for 1D.
Definition simplecache.h:46
A slice defines a sub-range or patch of a dimension.
Definition slice.h:103
A tensor is a multidimensional array.
Definition tensor.h:318
float_scalar_type normf() const
Returns the Frobenius norm of the tensor.
Definition tensor.h:1727
Tensor< T > & gaxpy(T alpha, const Tensor< T > &other, T beta)
Inplace generalized saxpy ... this = this*alpha + other*beta.
Definition tensor.h:1806
TensorTypeData< T >::scalar_type scalar_type
C++ typename of the real type associated with a complex type.
Definition tensor.h:410
T * ptr()
Returns a pointer to the internal data.
Definition tensor.h:1841
A simple, fixed dimension vector.
Definition vector.h:64
syntactic sugar for std::array<bool, N>
Definition array_of_bools.h:19
Defines common mathematical and physical constants.
static const double R
Definition csqrt.cc:46
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
Provides FunctionDefaults and utilities for coordinate transformation.
Tensor< T > transpose(const Tensor< T > &t)
Returns a new deep copy of the transpose of the input tensor.
Definition tensor.h:2035
const double beta
Definition gygi_soltion.cc:62
static const double v
Definition hatom_sf_dirac.cc:20
Tensor< double > op(const Tensor< double > &x)
Definition kain.cc:508
static double pow(const double *a, const double *b)
Definition lda.h:74
#define max(a, b)
Definition lda.h:51
#define final(a, b, c)
Definition lookup3.c:165
#define MADNESS_RESTRICT
Definition mTxmq.h:37
#define MADNESS_PRAGMA_CLANG(x)
Definition madness_config.h:200
#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_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
constexpr double pi
Mathematical constant .
Definition constants.h:48
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
bool two_scale_hg(int k, Tensor< double > *hg)
Definition twoscale.cc:151
void aligned_add(long n, double *MADNESS_RESTRICT a, const double *MADNESS_RESTRICT b)
void fast_transpose(long n, long m, const T *a, T *MADNESS_RESTRICT b)
a(n,m) --> b(m,n) ... optimized for smallish matrices
Definition convolution1d.h:71
void legendre_scaling_functions(double x, long k, double *p)
Evaluate the first k Legendre scaling functions.
Definition legendre.cc:85
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform(World &world, const std::vector< Function< T, NDIM > > &v, const Tensor< R > &c, bool fence=true)
Transforms a vector of functions according to new[i] = sum[j] old[j]*c[j,i].
Definition vmra.h:758
void hash_combine(hashT &seed, const T &v)
Combine hash values.
Definition worldhash.h:261
int64_t Translation
Definition key.h:58
int Level
Definition key.h:59
static void copy_2d_patch(T *MADNESS_RESTRICT out, long ldout, const T *MADNESS_RESTRICT in, long ldin, long n, long m)
Definition convolution1d.h:61
bool autoc(int k, Tensor< double > *c)
Return the autocorrelation coefficients for scaling functions of given order.
Definition twoscale.cc:234
bool gauss_legendre(int n, double xlo, double xhi, double *x, double *w)
Definition legendre.cc:226
static double pop(std::vector< double > &v)
Definition SCF.cc:117
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:739
NDIM & f
Definition mra.h:2668
std::size_t hashT
The hash value type.
Definition worldhash.h:146
void aligned_sub(long n, double *MADNESS_RESTRICT a, const double *MADNESS_RESTRICT b)
Function< T, CCPairFunction< T, NDIM >::LDIM > inner(const CCPairFunction< T, NDIM > &c, const Function< T, CCPairFunction< T, NDIM >::LDIM > &f, const std::tuple< int, int, int > v1, const std::tuple< int, int, int > v2)
Definition ccpairfunction.h:993
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
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness hash.
Definition array_addons.h:78
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:2233
static const int MAXK
The maximum wavelet order presently supported.
Definition funcdefaults.h:55
static long abs(long a)
Definition tensor.h:219
static const double b
Definition nonlinschro.cc:119
static const double d
Definition nonlinschro.cc:121
static const double a
Definition nonlinschro.cc:118
double Q(double a)
Definition relops.cc:20
static const double m
Definition relops.cc:9
static const double L
Definition rk.cc:46
static const long k
Definition rk.cc:44
!!! Note that if Rnormf is zero then ALL of the tensors are empty
Definition convolution1d.h:163
Tensor< Q > T
if NS: R=ns, T=T part of ns; if modified NS: T=\uparrow r^(n-1)
Definition convolution1d.h:166
double Rnorm
Definition convolution1d.h:171
Tensor< typename Tensor< Q >::scalar_type > Rs
Definition convolution1d.h:168
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:230
double N_up
Definition convolution1d.h:174
double NSnormf
Definition convolution1d.h:171
double Rnormf
Definition convolution1d.h:171
Tensor< Q > TU
Definition convolution1d.h:167
ConvolutionData1D(const Tensor< Q > &R, const Tensor< Q > &T)
Definition convolution1d.h:181
double N_F
the norms according to Beylkin 2008, Eq. (21) ff
Definition convolution1d.h:174
double N_diff
Definition convolution1d.h:174
Tensor< Q > RU
Definition convolution1d.h:167
double Tnorm
Definition convolution1d.h:171
Tensor< typename Tensor< Q >::scalar_type > Ts
hold relative errors, NOT the singular values..
Definition convolution1d.h:168
ConvolutionData1D(const Tensor< Q > &R, const Tensor< Q > &T, const bool modified)
Definition convolution1d.h:209
double Tnormf
Definition convolution1d.h:171
Tensor< Q > R
Definition convolution1d.h:166
Tensor< Q > TVT
SVD approximations to R and T.
Definition convolution1d.h:167
Tensor< Q > RVT
Definition convolution1d.h:167
Definition convolution1d.h:985
ConcurrentHashMap< hashT, std::shared_ptr< GaussianConvolution1D< Q > > >::iterator iterator
Definition convolution1d.h:987
static ConcurrentHashMap< hashT, std::shared_ptr< GaussianConvolution1D< Q > > > map
Definition convolution1d.h:986
ConcurrentHashMap< hashT, std::shared_ptr< GaussianConvolution1D< Q > > >::datumT datumT
Definition convolution1d.h:988
static std::shared_ptr< GaussianConvolution1D< Q > > get(int k, double expnt, int m, const LatticeRange &lattice_range, double bloch_k=0.0, const KernelRange &range={})
Definition convolution1d.h:990
Definition convolution1d.h:685
returnT operator()(double x) const
Definition convolution1d.h:694
Tensor< Q > returnT
Definition convolution1d.h:686
Translation lx
Definition convolution1d.h:688
Level n
Definition convolution1d.h:687
Shmoo(Level n, Translation lx, const GenericConvolution1D< Q, opT > *q)
Definition convolution1d.h:691
const GenericConvolution1D< Q, opT > & q
Definition convolution1d.h:689
static const double x0
Definition tdse1d.cc:145
static const double s0
Definition tdse4.cc:83
Defines and implements most of Tensor.
Prototypes for a partial interface from Tensor to LAPACK.
bool is_small(const double &val, const double &eps)
Definition test6.cc:56
double norm(const T i1)
Definition test_cloud.cc:85
void e()
Definition test_sig.cc:75
constexpr std::size_t NDIM
Definition testgconv.cc:54
double h(const coord_1d &r)
Definition testgconv.cc:175
Implement the madness:Vector class, an extension of std::array that supports some mathematical operat...
const double a2
Definition vnucso.cc:86
const double a1
Definition vnucso.cc:85