35 #ifndef MADNESS_MRA_MRAIMPL_H__INCLUDED
36 #define MADNESS_MRA_MRAIMPL_H__INCLUDED
39 #error "mraimpl.h should ONLY be included in one of the mraX.cc files (x=1..6)"
61 template <
typename T, std::
size_t NDIM>
62 void FunctionCommonData<T,NDIM>::_init_twoscale() {
63 if (!
two_scale_hg(k, &hg))
throw "failed to get twoscale coefficients";
66 Slice sk(0,k-1), sk2(k,-1);
67 hgsonly =
copy(hg(Slice(0,k-1),_));
70 h1 =
copy(hg(sk,sk2));
71 g0 =
copy(hg(sk2,sk));
72 g1 =
copy(hg(sk2,sk2));
81 template <
typename T, std::
size_t NDIM>
83 (
int k,
int npt, Tensor<double>& quad_x, Tensor<double>& quad_w,
84 Tensor<double>& quad_phi, Tensor<double>& quad_phiw, Tensor<double>& quad_phit) {
85 quad_x = Tensor<double>(npt);
86 quad_w = Tensor<double>(npt);
87 quad_phi = Tensor<double>(npt,k);
88 quad_phiw = Tensor<double>(npt,k);
91 for (
int mu=0;
mu<npt; ++
mu) {
94 for (
int j=0; j<k; ++j) {
95 quad_phi(
mu,j) = phi[j];
96 quad_phiw(
mu,j) = quad_w(
mu)*phi[j];
103 template <
typename T, std::
size_t NDIM>
111 const keyT& key = it->first;
112 const nodeT& node = it->second;
115 if (is_compressed()) {
135 print(world.rank(),
"FunctionImpl: verify: INCONSISTENT TREE NODE, key =", key,
", node =", node,
136 ", dim[0] =",node.
coeff().
dim(0),
", compressed =",is_compressed());
144 const keyT& key = it->first;
145 const nodeT& node = it->second;
147 if (key.
level() > 0) {
150 if (pit == coeffs.end()) {
151 print(world.rank(),
"FunctionImpl: verify: MISSING PARENT",key,parent);
155 const nodeT& pnode = pit->second;
157 print(world.rank(),
"FunctionImpl: verify: PARENT THINKS IT HAS NO CHILDREN",key,parent);
165 if (cit == coeffs.end()) {
167 print(world.rank(),
"FunctionImpl: verify: MISSING CHILD",key,kit.key());
174 print(world.rank(),
"FunctionImpl: verify: UNEXPECTED CHILD",key,kit.key());
186 template <
typename T, std::
size_t NDIM>
188 return coeffs.get_pmap();
202 template <
typename T, std::
size_t NDIM>
204 const double beta,
const implT&
g,
const bool fence) {
209 ProcessID owner = coeffs.owner(cdata.key0);
210 if (world.rank() == owner) {
216 coeff_opT coeff_op(ff,gg,alpha,beta);
218 apply_opT apply_op(
this);
220 woT::task(world.rank(), &implT:: template forward_traverse<coeff_opT,apply_opT>,
221 coeff_op, apply_op, cdata.key0);
225 this->compressed=
false;
226 if (fence) world.gop.fence();
230 template <
typename T, std::
size_t NDIM>
236 template <
typename T, std::
size_t NDIM>
241 template <
typename T, std::
size_t NDIM>
244 template <
typename T, std::
size_t NDIM>
246 this->on_demand=
true;
250 template <
typename T, std::
size_t NDIM>
252 MADNESS_ASSERT(this->functor);
256 template <
typename T, std::
size_t NDIM>
258 MADNESS_ASSERT(this->functor);
262 template <
typename T, std::
size_t NDIM>
264 this->on_demand=
false;
268 template <
typename T, std::
size_t NDIM>
271 template <
typename T, std::
size_t NDIM>
274 template <
typename T, std::
size_t NDIM>
277 template <
typename T, std::
size_t NDIM>
280 template <
typename T, std::
size_t NDIM>
283 template <
typename T, std::
size_t NDIM>
286 template <
typename T, std::
size_t NDIM>
289 template <
typename T, std::
size_t NDIM>
292 template <
typename T, std::
size_t NDIM>
295 template <
typename T, std::
size_t NDIM>
298 template <
typename T, std::
size_t NDIM>
301 template <
typename T, std::
size_t NDIM>
304 template <
typename T, std::
size_t NDIM>
306 timer_accumulate.accumulate(time);
310 template <
typename T, std::
size_t NDIM>
312 if (world.rank()==0) {
313 timer_accumulate.print(
"accumulate");
314 timer_target_driven.print(
"target_driven");
315 timer_lr_result.print(
"result2low_rank");
319 template <
typename T, std::
size_t NDIM>
321 if (world.rank()==0) {
322 timer_accumulate.reset();
323 timer_target_driven.reset();
324 timer_lr_result.reset();
331 template <
typename T, std::
size_t NDIM>
336 if (world.rank() == coeffs.owner(cdata.key0)) {
337 if (is_compressed()) {
338 truncate_spawn(cdata.key0,tol);
340 truncate_reconstructed_spawn(cdata.key0,tol);
347 template <
typename T, std::
size_t NDIM>
356 template <
typename T, std::
size_t NDIM>
360 Tensor<double> localinfo=print_plane_local(xaxis,yaxis,el2);
363 std::vector<Tensor<double> > localinfo_vec(1,localinfo);
364 std::vector<Tensor<double> > printinfo=world.gop.concat0(localinfo_vec);
368 if (world.rank()==0) do_print_plane(filename,printinfo,xaxis,yaxis,el2);
377 template <
typename T, std::
size_t NDIM>
380 user_to_sim<NDIM>(el2,x_sim);
384 Tensor<double> plotinfo(coeffs.size(),5);
390 const keyT& key = it->first;
391 const nodeT& node = it->second;
399 double scale=std::pow(0.5,
double(n));
400 double xloleft = scale*l[xaxis];
401 double yloleft = scale*l[yaxis];
402 double xhiright = scale*(l[xaxis]+1);
403 double yhiright = scale*(l[yaxis]+1);
414 if ((user[0]<-5.0) or (user[1]<-5.0) or (user[2]>5.0) or (user[3]>5.0))
continue;
420 const double maxrank=40;
426 const int npt = cdata.npt + 1;
427 Tensor<double> qx, qw, quad_phi, quad_phiw, quad_phit;
437 plotinfo(counter,0)=color;
438 plotinfo(counter,1)=user[0];
439 plotinfo(counter,2)=user[1];
440 plotinfo(counter,3)=user[2];
441 plotinfo(counter,4)=user[3];
447 if (counter==0) plotinfo=Tensor<double>();
448 else plotinfo=plotinfo(
Slice(0,counter-1),
Slice(_));
453 template <
typename T, std::
size_t NDIM>
455 const int xaxis,
const int yaxis,
const coordT el2) {
458 MADNESS_ASSERT(world.rank()==0);
462 pFile = fopen(filename.c_str(),
"w");
466 fprintf(pFile,
"\\psset{unit=1cm}\n");
467 fprintf(pFile,
"\\begin{pspicture}(%4.2f,%4.2f)(%4.2f,%4.2f)\n",
470 fprintf(pFile,
"\\pslinewidth=0.1pt\n");
472 for (std::vector<Tensor<double> >::const_iterator it=plotinfo.begin(); it!=plotinfo.end(); ++it) {
474 Tensor<double> localinfo=*it;
475 if (localinfo.has_data()) {
477 for (
long i=0; i<localinfo.dim(0); ++i) {
479 fprintf(pFile,
"\\newhsbcolor{mycolor}{%8.4f 1.0 0.7}\n",localinfo(i,0));
480 fprintf(pFile,
"\\psframe["
483 "(%12.8f,%12.8f)(%12.8f,%12.8f)\n",
484 localinfo(i,1),localinfo(i,2),localinfo(i,3),localinfo(i,4));
490 fprintf(pFile,
"\\end{pspicture}\n");
498 template <
typename T, std::
size_t NDIM>
502 std::vector<keyT> local_keys=local_leaf_keys();
505 std::vector<keyT> all_keys=world.gop.concat0(local_keys);
509 if (world.rank()==0) do_print_grid(filename,all_keys);
514 template <
typename T, std::
size_t NDIM>
518 std::vector<keyT> keys(coeffs.size());
525 const keyT& key = it->first;
526 const nodeT& node = it->second;
527 if (node.
is_leaf()) keys[i++]=key;
540 template <
typename T, std::
size_t NDIM>
543 MADNESS_ASSERT(world.rank()==0);
546 const Tensor<double> qx=cdata.quad_x;
547 const size_t npt = qx.dim(0);
550 long npoints=power<NDIM>(npt);
552 long nboxes=keys.size();
556 pFile = fopen(filename.c_str(),
"w");
558 fprintf(pFile,
"%ld\n",npoints*nboxes);
559 fprintf(pFile,
"%ld points per box and %ld boxes \n",npoints,nboxes);
562 typename std::vector<keyT>::const_iterator key_it=keys.begin();
563 for (key_it=keys.begin(); key_it!=keys.end(); ++key_it) {
565 const keyT& key=*key_it;
566 fprintf(pFile,
"# key: %8d",key.
level());
567 for (
size_t d=0; d<
NDIM; d++) fprintf(pFile,
"%8d",
int(key.
translation()[d]));
573 const double h = std::pow(0.5,
double(n));
580 for (
size_t i=0; i<npt; ++i) {
581 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
582 for (
size_t j=0; j<npt; ++j) {
583 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
584 for (
size_t k=0; k<npt; ++k) {
585 c[2] = cell(2,0) + h*cell_width[2]*(l[2] + qx(k));
591 fprintf(pFile,
"%18.12f %18.12f %18.12f\n",c[0],c[1],c[2]);
612 template <
typename T, std::
size_t NDIM>
614 const static double fac=1.0/std::pow(2,
NDIM*0.5);
620 const int MAXLEVEL1 = 20;
621 const int MAXLEVEL2 = 10;
623 if (truncate_mode == 0) {
626 else if (truncate_mode == 1) {
630 else if (truncate_mode == 2) {
640 template <
typename T, std::
size_t NDIM>
642 std::vector<Slice> s(
NDIM);
644 for (std::size_t i=0; i<
NDIM; ++i)
645 s[i] = cdata.s[l[i]&1];
657 template <
typename T, std::
size_t NDIM>
659 const coeffT& coeff)
const {
669 if (coeff.
dim(0)==2*f->
get_k()) result=coeff;
670 else if (coeff.
dim(0)==f->
get_k()) {
681 MADNESS_ASSERT(coeff.
dim(0)==f->
get_k());
684 t(f->cdata.s0)=coeff1.full_tensor_copy();
693 template <
typename T, std::
size_t NDIM>
696 double twon = std::pow(2.0,
double(n));
697 for (std::size_t i=0; i<
NDIM; ++i) {
707 template <
typename T, std::
size_t NDIM>
712 long M = (q ? N/q:
N);
716 for (std::size_t d=0; d<
NDIM; ++d) {
718 dim[d+
NDIM] = cdata.k;
726 for (std::size_t d=0; d<
NDIM; ++d) {
750 r=rr.cycledim(NDIM,0,-1);
752 print(
"faking done M q r(fake) r0(real)",M,q,
"\n", std::vector<long> (r.dims(),r.dims()+6),std::vector<long> (r0.dims(),r0.dims()+6));
758 powM[NDIM1]=powq[NDIM1]=powN[NDIM1]=1;
759 for (
int d=NDIM1-1; d>=0; --d) {
760 powM[d] = powM[d+1]*M;
761 powq[d] = powq[d+1]*q;
762 powN[d] = powN[d+1]*
N;
764 long powMNDIM = powM[0]*M;
768 if (coeffs.owner(key) == me) {
772 if (it == coeffs.end()) {
774 typedef std::pair< keyT,coeffT > pairT;
777 const keyT& parent = result.
get().first;
781 qq = (parent_to_child(t, parent, key));
783 qq =
copy(it->second.coeff());
785 std::vector<Slice> s(
NDIM*2);
787 for (std::size_t d=0; d<
NDIM; ++d) {
789 long dum = long(
float(l)/q);
790 ll += (l - dum*q)*powMNDIM*powq[d] + dum*powM[d];
799 for (std::size_t d=0; d<
NDIM; ++d) {
802 s[d ] =
Slice(l,l,0);
822 template <
typename T, std::
size_t NDIM>
824 this->make_redundant(
true);
827 for (
typename dcT::iterator it= coeffs.begin(); it!=end; ++it) {
829 nodeT& node=it->second;
830 if (key.
level()>max_level) coeffs.erase(key);
833 this->undo_redundant(
true);
839 template <
typename T, std::
size_t NDIM>
853 template <
typename T, std::
size_t NDIM>
855 const std::vector<tensorT>&
c,
857 if (key == cdata.key0 && coeffs.owner(key)!=world.rank())
return None;
861 for (
unsigned int i=0; i<c.size(); i++) {
862 MADNESS_ASSERT(v[i]->coeffs.get_pmap() == coeffs.get_pmap());
863 MADNESS_ASSERT(v[i]->coeffs.owner(key) == world.rank());
864 bool exists = ! v[i]->coeffs.insert(acc[i],key);
866 MADNESS_ASSERT(!exists);
870 MADNESS_ASSERT(exists);
876 for (
unsigned int i=0; i<v.size(); i++) {
877 done &= acc[i]->second.has_coeff();
882 std::vector<tensorT> d(v.size());
883 for (
unsigned int i=0; i<v.size(); i++) {
884 if (acc[i]->second.has_coeff()) {
887 s(cdata.s0) = acc[i]->second.coeff().full_tensor_copy();
888 acc[i]->second.clear_coeff();
890 acc[i]->second.set_has_children(
true);
896 const keyT& child = kit.key();
897 std::vector<Slice> cp = child_patch(child);
898 std::vector<tensorT> childc(v.size());
899 for (
unsigned int i=0; i<v.size(); i++) {
900 if (d[i].size()) childc[i] =
copy(d[i](cp));
902 woT::task(coeffs.owner(child), &implT::refine_to_common_level, v, childc, child);
910 template <
typename T, std::
size_t NDIM>
912 if (world.size()> 1000)
915 box_interior[from] = ni;
920 template <
typename T, std::
size_t NDIM>
922 if (world.size() >= 1000)
924 for (
int i=0; i<world.size(); ++i)
925 box_leaf[i] = box_interior[i] == 0;
927 long nleaf=0, ninterior=0;
930 const nodeT& node = it->second;
936 this->send(0, &implT::put_in_box, world.rank(), nleaf, ninterior);
938 if (world.rank() == 0) {
939 for (
int i=0; i<world.size(); ++i) {
940 printf(
"load: %5d %8ld %8ld\n", i, box_leaf[i], box_interior[i]);
946 template <
typename T, std::
size_t NDIM>
952 template <
typename T, std::
size_t NDIM>
956 double test = 2*lo*hi + hi*hi;
958 return test> truncate_tol(
thresh, key);
963 template <
typename T, std::
size_t NDIM>
966 coeffs.insert(acc,key);
967 nodeT& node = acc->second;
982 d =
coeffT(cdata.v2k,targs);
989 const keyT& child = kit.key();
990 if (d.
size() > 0) ss =
copy(d(child_patch(child)));
992 woT::task(coeffs.owner(child), &implT::sum_down_spawn, child, ss);
997 if (c.
size() <= 0) c =
coeffT(cdata.vk,targs);
1003 template <
typename T, std::
size_t NDIM>
1005 if (world.rank() == coeffs.owner(cdata.key0)) sum_down_spawn(cdata.key0,
coeffT());
1007 if (fence) world.gop.fence();
1011 template <
typename T, std::
size_t NDIM>
1015 const std::pair<keyT,coeffT>& left,
1016 const std::pair<keyT,coeffT>& center,
1017 const std::pair<keyT,coeffT>& right) {
1022 template <
typename T, std::
size_t NDIM>
1026 const std::pair<keyT,coeffT>& left,
1027 const std::pair<keyT,coeffT>& center,
1028 const std::pair<keyT,coeffT>& right) {
1029 return D->
do_diff1(f,
this,key,left,center,right);
1034 template <
typename T, std::
size_t NDIM>
1036 typedef std::pair<keyT,coeffT> argT;
1039 const keyT& key = it->first;
1040 const nodeT& node = it->second;
1043 argT center(key,node.
coeff());
1051 if (fence) world.gop.fence();
1056 template <
typename T, std::
size_t NDIM>
1058 MADNESS_ASSERT(coeffs.probe(key));
1069 template <
typename T, std::
size_t NDIM>
1073 MADNESS_ASSERT(particle==0 or particle==1);
1077 std::vector<Slice> s(rr.
config().dim_per_vector()+1,_);
1078 for (
int r=0; r<rr.
rank(); ++r) {
1098 template <
typename T, std::
size_t NDIM>
1104 bool ket_only=(not (vpotential1.
has_data() or vpotential2.
has_data() or veri.has_data()));
1105 if (ket_only)
return coeff_ket;
1108 coeffT val_ket=coeffs2values(key,coeff_ket);
1119 if (veri.has_data()) {
1123 coeff_result=
coeffT(values2coeffs(key,val_ket2),this->get_tensor_args());
1127 MADNESS_ASSERT(val_result.
has_data());
1128 coeff_result=values2coeffs(key,val_result);
1129 coeff_result.reduce_rank(this->get_tensor_args().
thresh);
1132 return coeff_result;
1137 template <
typename T, std::
size_t NDIM>
1141 const_cast<implT*
>(&
f)->flo_unary_op_node_inplace(
do_mapdim(map,*
this),fence);
1149 template <
typename T, std::
size_t NDIM>
1153 this->scale_inplace(0.5,
true);
1160 template <
typename T, std::
size_t NDIM>
1168 template <
typename T, std::
size_t NDIM>
1187 template <
typename T, std::
size_t NDIM>
1195 template <
typename T, std::
size_t NDIM>
1216 template <
typename T, std::
size_t NDIM>
1224 template <
typename T, std::
size_t NDIM>
1236 template <
typename T, std::
size_t NDIM>
1242 const tensorT h[2] = {cdata.h0T, cdata.h1T};
1250 for (
size_t ii=0; ii<
NDIM; ++ii) matrices[ii]=h[kit.key().translation()[ii]%2];
1266 template <
typename T, std::
size_t NDIM>
1271 const tensorT h[2] = {cdata.h0, cdata.h1};
1275 for (
size_t ii=0; ii<
NDIM; ++ii) matrices[ii]=h[key.
translation()[ii]%2];
1284 template <
typename T, std::
size_t NDIM>
1286 long kmin =
std::min(cdata.k,old.cdata.k);
1287 std::vector<Slice> s(
NDIM,
Slice(0,kmin-1));
1290 const keyT& key = it->first;
1291 const nodeT& node = it->second;
1295 coeffs.replace(key,
nodeT(c,
false));
1305 template <
typename T, std::
size_t NDIM>
1307 return coeffs.probe(key) && coeffs.find(key).get()->second.has_children();
1310 template <
typename T, std::
size_t NDIM>
1312 return coeffs.probe(key) && (not coeffs.find(key).get()->second.has_children());
1316 template <
typename T, std::
size_t NDIM>
1318 for (
unsigned int i=0; i<v.size(); ++i) {
1328 template <
typename T, std::
size_t NDIM>
1331 for (
typename dcT::iterator it=coeffs.begin(); it!=end; ++it) {
1332 it->second.set_norm_tree(0.0);
1337 template <
typename T, std::
size_t NDIM>
1340 for (
typename dcT::iterator it=coeffs.begin(); it!=end; ++it) {
1341 const keyT& key = it->first;
1343 MADNESS_ASSERT(coeffs.find(acc,key));
1344 nodeT& node = acc->second;
1345 if (node.has_coeff() &&
1346 node.get_norm_tree() != -1.0 &&
1347 node.coeff().normf() >= truncate_tol(
thresh,key)) {
1349 node.set_norm_tree(-1.0);
1352 int ndir =
static_cast<int>(std::pow(static_cast<double>(3), static_cast<int>(
NDIM)));
1353 std::vector< Future <bool> > v = future_vector_factory<bool>(ndir);
1358 for (std::size_t d=0; d<
NDIM; ++d) {
1366 keyT neigh = neighbor(key,
keyT(key.
level(),l), is_periodic);
1369 v[i++] = this->send(coeffs.owner(neigh), &implT::exists_and_has_children, neigh);
1375 woT::task(world.rank(), &implT::broaden_op, key, v);
1387 template <
typename T, std::
size_t NDIM>
1392 if (world.rank() == coeffs.owner(cdata.key0))
1393 woT::task(world.rank(), &implT::trickle_down_op, cdata.key0,
coeffT());
1401 template <
typename T, std::
size_t NDIM>
1412 if (it == coeffs.end()) {
1414 it = coeffs.find(key).get();
1416 nodeT& node = it->second;
1426 if (key.
level() > 0) d += s;
1429 const keyT& child = kit.key();
1430 coeffT ss= upsample(child,d);
1433 woT::task(coeffs.owner(child), &implT::trickle_down_op, child, ss);
1443 template <
typename T, std::
size_t NDIM>
1446 MADNESS_ASSERT(not is_redundant());
1448 if (world.rank() == coeffs.owner(cdata.key0))
1449 woT::task(world.rank(), &implT::reconstruct_op, cdata.key0,
coeffT());
1461 template <
typename T, std::
size_t NDIM>
1463 MADNESS_ASSERT(not is_redundant());
1465 this->compressed =
true;
1467 this->redundant = redundant;
1470 MADNESS_ASSERT(not (redundant and nonstandard));
1472 if (redundant) {MADNESS_ASSERT(keepleaves);}
1475 if (world.rank() == coeffs.owner(cdata.key0)) {
1477 compress_spawn(cdata.key0, nonstandard, keepleaves, redundant);
1484 template <
typename T, std::
size_t NDIM>
1488 if (is_redundant())
return;
1492 if (is_nonstandard()) this->
standard(
true);
1503 template <
typename T, std::
size_t NDIM>
1506 if (!is_redundant())
return;
1513 template <
typename T, std::
size_t NDIM>
1515 if (world.rank() == coeffs.owner(cdata.key0))
1516 norm_tree_spawn(cdata.key0);
1521 template <
typename T, std::
size_t NDIM>
1527 double value = v[i].get();
1531 coeffs.task(key, &nodeT::set_norm_tree, sum);
1536 template <
typename T, std::
size_t NDIM>
1538 nodeT& node = coeffs.find(key).get()->second;
1540 std::vector< Future<double> > v = future_vector_factory<double>(1<<
NDIM);
1543 v[i] = woT::task(coeffs.owner(kit.key()), &implT::norm_tree_spawn, kit.key());
1545 return woT::task(world.rank(),&implT::norm_tree_op, key, v);
1559 template <
typename T, std::
size_t NDIM>
1561 MADNESS_ASSERT(coeffs.probe(key));
1562 nodeT& node = coeffs.find(key).get()->second;
1565 if (not node.has_children())
return Future<coeffT>(node.coeff());
1569 std::vector<Future<coeffT> > v = future_vector_factory<coeffT>(1<<
NDIM);
1572 v[i] = woT::task(coeffs.owner(kit.key()), &implT::truncate_reconstructed_spawn, kit.key(),tol,
TaskAttributes::hipri());
1583 template <
typename T, std::
size_t NDIM>
1586 MADNESS_ASSERT(coeffs.probe(key));
1590 for (
size_t i=0; i<v.size(); ++i)
if (v[i].
get().has_no_data())
return coeffT();
1593 MADNESS_ASSERT(coeffs.find(acc, key));
1600 const tensorT s=downsample(key,v);
1601 const double snorm=s.normf();
1605 for (
size_t i=0; i<v.size(); ++i) {
1606 const double d=v[i].get().normf();
1611 const double error=
sqrt(dnorm-snorm*snorm);
1617 d(child_patch(kit.key())) += v[i].get().full_tensor_copy();
1623 const double error=d.normf();
1626 nodeT& node = coeffs.find(key).get()->second;
1628 if (error < truncate_tol(tol,key)) {
1631 coeffs.erase(kit.key());
1635 acc->second.set_coeff(ss);
1649 template <
typename T, std::
size_t NDIM>
1653 MADNESS_ASSERT(not redundant);
1654 double cpu0=cpu_time();
1661 d(child_patch(kit.key())) += v[i].get().full_tensor_copy();
1665 double cpu1=cpu_time();
1666 timer_filter.accumulate(cpu1-cpu0);
1670 MADNESS_ASSERT(coeffs.find(acc, key));
1672 if (acc->second.has_coeff()) {
1673 print(
" stuff in compress_op");
1675 const tensorT c = acc->second.coeff().full_tensor_copy();
1676 if (c.dim(0) == k) {
1696 acc->second.set_coeff(ss);
1699 acc->second.set_coeff(dd);
1702 timer_compress_svd.accumulate(cpu1-cpu0);
1713 template <
typename T, std::
size_t NDIM>
1719 coeffT s(this->downsample(key,v),targs2);
1723 MADNESS_ASSERT(coeffs.find(acc, key));
1724 MADNESS_ASSERT(not (acc->second.has_coeff()));
1725 acc->second.set_coeff(s);
1731 template <
typename T, std::
size_t NDIM>
1734 flo_unary_op_node_inplace(
do_standard(
this),fence);
1740 template <
typename T, std::
size_t NDIM>
1758 double elapsed=end-begin;
1759 this->compressed=
true;
1761 this->redundant=
false;
1762 if (fence) world.gop.fence();
1767 template <
typename T, std::
size_t NDIM>
1771 return world.taskq.reduce<double,rangeT,
do_norm2sq_local>(rangeT(coeffs.begin(),coeffs.end()),
1779 template <
typename T, std::
size_t NDIM>
1781 std::size_t maxdepth = 0;
1784 std::size_t
N = (std::size_t) it->first.level();
1793 template <
typename T, std::
size_t NDIM>
1795 std::size_t maxdepth = max_local_depth();
1796 world.gop.max(maxdepth);
1801 template <
typename T, std::
size_t NDIM>
1803 std::size_t maxsize = 0;
1804 maxsize = coeffs.size();
1805 world.gop.max(maxsize);
1810 template <
typename T, std::
size_t NDIM>
1812 std::size_t minsize = 0;
1813 minsize = coeffs.size();
1814 world.gop.min(minsize);
1819 template <
typename T, std::
size_t NDIM>
1821 std::size_t
sum = 0;
1822 sum = coeffs.size();
1828 template <
typename T, std::
size_t NDIM>
1830 std::size_t
sum = 0;
1834 const nodeT& node = it->second;
1842 const nodeT& node = it->second;
1846 if (is_compressed())
1847 for (std::size_t i=0; i<
NDIM; ++i)
1850 for (std::size_t i=0; i<
NDIM; ++i)
1859 template <
typename T, std::
size_t NDIM>
1861 std::size_t
sum = coeffs.size() * (
sizeof(
keyT) +
sizeof(
nodeT));
1864 const nodeT& node = it->second;
1873 template <
typename T, std::
size_t NDIM>
1875 const size_t tsize=this->tree_size();
1876 const size_t size=this->size();
1877 const size_t rsize=this->real_size();
1879 const double d=
sizeof(
T);
1880 const double fac=1024*1024*1024;
1884 double local = norm2sq_local();
1885 this->world.gop.sum(local);
1886 this->world.gop.fence();
1890 if (this->world.rank()==0) {
1891 printf(
"%s at time %.1fs: norm/tree/real/size: %7.5f %zu, %6.3f, %6.3f GByte\n",
1892 (name.c_str()), wall, norm, tsize,
double(rsize)/fac,double(size)/fac*d);
1897 template <
typename T, std::
size_t NDIM>
1899 if (this->targs.tt==
TT_FULL)
return;
1902 if (is_compressed()) k0=2*k;
1903 Tensor<long> n(
int(std::pow(
double(k0),
double(dim))+1));
1907 if (world.rank()==0)
print(
"n.size(),k0,dim",n.size(),k0,
dim);
1910 const nodeT& node = it->second;
1912 if (node.
coeff().
rank()>long(n.size())) {
1924 world.gop.sum(n.ptr(), n.size());
1926 if (world.rank()==0) {
1927 print(
"configurations number of nodes");
1928 if (world.rank()==0)
print(
" full rank ",n_full);
1929 for (
unsigned int i=0; i<n.size(); i++) {
1931 if (world.rank()==0)
print(
" ",i,
" ",m);
1933 if (world.rank()==0)
print(
" large rank ",n_large);
1937 template <
typename T, std::
size_t NDIM>
1940 const int k = cdata.k;
1947 for (
int p=0; p<k; ++p)
1948 sum +=
c(p)*px[0][p];
1950 else if (NDIM == 2) {
1951 for (
int p=0; p<k; ++p)
1952 for (
int q=0; q<k; ++q)
1953 sum +=
c(p,q)*px[0][p]*px[1][q];
1955 else if (NDIM == 3) {
1956 for (
int p=0; p<k; ++p)
1957 for (
int q=0; q<k; ++q)
1958 for (
int r=0; r<k; ++r)
1959 sum +=
c(p,q,r)*px[0][p]*px[1][q]*px[2][r];
1961 else if (NDIM == 4) {
1962 for (
int p=0; p<k; ++p)
1963 for (
int q=0; q<k; ++q)
1964 for (
int r=0; r<k; ++r)
1965 for (
int s=0; s<k; ++s)
1966 sum +=
c(p,q,r,s)*px[0][p]*px[1][q]*px[2][r]*px[3][s];
1968 else if (NDIM == 5) {
1969 for (
int p=0; p<k; ++p)
1970 for (
int q=0; q<k; ++q)
1971 for (
int r=0; r<k; ++r)
1972 for (
int s=0; s<k; ++s)
1973 for (
int t=0; t<k; ++t)
1974 sum +=
c(p,q,r,s,t)*px[0][p]*px[1][q]*px[2][r]*px[3][s]*px[4][t];
1976 else if (NDIM == 6) {
1977 for (
int p=0; p<k; ++p)
1978 for (
int q=0; q<k; ++q)
1979 for (
int r=0; r<k; ++r)
1980 for (
int s=0; s<k; ++s)
1981 for (
int t=0; t<k; ++t)
1982 for (
int u=0; u<k; ++u)
1983 sum +=
c(p,q,r,s,t,u)*px[0][p]*px[1][q]*px[2][r]*px[3][s]*px[4][t]*px[5][u];
1991 template <
typename T, std::
size_t NDIM>
2003 if (it == coeffs.end()) {
2005 it = coeffs.find(key).get();
2007 nodeT& node = it->second;
2019 if (key.
level() > 0) d(cdata.s0) += s;
2020 if (d.
dim(0)==2*get_k()) {
2025 const keyT& child = kit.key();
2029 woT::task(coeffs.owner(child), &implT::reconstruct_op, child, ss);
2032 MADNESS_ASSERT(node.
is_leaf());
2046 template <
typename T, std::
size_t NDIM>
2049 std::vector<long> npt(
NDIM,qx.dim(0));
2050 Tensor<T> fval(npt);
2055 template <
typename T, std::
size_t NDIM>
2058 std::vector<long> npt(
NDIM,qx.dim(0));
2059 Tensor<T> fval(npt);
2060 fcube(key, f, qx, fval);
2070 template <
typename T, std::
size_t NDIM>
2079 const double h = std::pow(0.5,
double(n));
2081 const int npt = qx.dim(0);
2088 for (
int i = 0; i <
NDIM; i++) {
2089 c1[i] = cell(i,0) + h*cell_width[i]*(l[i] + qx((
long)0));
2090 c2[i] = cell(i,0) + h*cell_width[i]*(l[i] + qx(npt-1));
2100 T* fvptr = fval.ptr();
2102 double* x1 =
new double[npt];
2104 for (
int i=0; i<npt; ++i, ++idx) {
2105 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2109 f(xvals, fvptr, npt);
2112 else if (NDIM == 2) {
2113 double* x1 =
new double[npt*npt];
2114 double* x2 =
new double[npt*npt];
2116 for (
int i=0; i<npt; ++i) {
2117 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2118 for (
int j=0; j<npt; ++j, ++idx) {
2119 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2125 f(xvals, fvptr, npt*npt);
2129 else if (NDIM == 3) {
2130 double* x1 =
new double[npt*npt*npt];
2131 double* x2 =
new double[npt*npt*npt];
2132 double* x3 =
new double[npt*npt*npt];
2134 for (
int i=0; i<npt; ++i) {
2135 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2136 for (
int j=0; j<npt; ++j) {
2137 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2138 for (
int k=0; k<npt; ++k, ++idx) {
2139 c[2] = cell(2,0) + h*cell_width[2]*(l[2] + qx(k));
2147 f(xvals, fvptr, npt*npt*npt);
2152 else if (NDIM == 4) {
2153 double* x1 =
new double[npt*npt*npt*npt];
2154 double* x2 =
new double[npt*npt*npt*npt];
2155 double* x3 =
new double[npt*npt*npt*npt];
2156 double* x4 =
new double[npt*npt*npt*npt];
2158 for (
int i=0; i<npt; ++i) {
2159 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2160 for (
int j=0; j<npt; ++j) {
2161 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2162 for (
int k=0; k<npt; ++k) {
2163 c[2] = cell(2,0) + h*cell_width[2]*(l[2] + qx(k));
2164 for (
int m=0;
m<npt; ++
m, ++idx) {
2165 c[3] = cell(3,0) + h*cell_width[3]*(l[3] + qx(
m));
2175 f(xvals, fvptr, npt*npt*npt*npt);
2181 else if (NDIM == 5) {
2182 double* x1 =
new double[npt*npt*npt*npt*npt];
2183 double* x2 =
new double[npt*npt*npt*npt*npt];
2184 double* x3 =
new double[npt*npt*npt*npt*npt];
2185 double* x4 =
new double[npt*npt*npt*npt*npt];
2186 double* x5 =
new double[npt*npt*npt*npt*npt];
2188 for (
int i=0; i<npt; ++i) {
2189 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2190 for (
int j=0; j<npt; ++j) {
2191 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2192 for (
int k=0; k<npt; ++k) {
2193 c[2] = cell(2,0) + h*cell_width[2]*(l[2] + qx(k));
2194 for (
int m=0;
m<npt; ++
m) {
2195 c[3] = cell(3,0) + h*cell_width[3]*(l[3] + qx(
m));
2196 for (
int n=0; n<npt; ++n, ++idx) {
2197 c[4] = cell(4,0) + h*cell_width[4]*(l[4] + qx(n));
2209 f(xvals, fvptr, npt*npt*npt*npt*npt);
2216 else if (NDIM == 6) {
2217 double* x1 =
new double[npt*npt*npt*npt*npt*npt];
2218 double* x2 =
new double[npt*npt*npt*npt*npt*npt];
2219 double* x3 =
new double[npt*npt*npt*npt*npt*npt];
2220 double* x4 =
new double[npt*npt*npt*npt*npt*npt];
2221 double* x5 =
new double[npt*npt*npt*npt*npt*npt];
2222 double* x6 =
new double[npt*npt*npt*npt*npt*npt];
2224 for (
int i=0; i<npt; ++i) {
2225 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2226 for (
int j=0; j<npt; ++j) {
2227 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2228 for (
int k=0; k<npt; ++k) {
2229 c[2] = cell(2,0) + h*cell_width[2]*(l[2] + qx(k));
2230 for (
int m=0;
m<npt; ++
m) {
2231 c[3] = cell(3,0) + h*cell_width[3]*(l[3] + qx(
m));
2232 for (
int n=0; n<npt; ++n) {
2233 c[4] = cell(4,0) + h*cell_width[4]*(l[4] + qx(n));
2234 for (
int p=0; p<npt; ++p, ++idx) {
2235 c[5] = cell(5,0) + h*cell_width[5]*(l[5] + qx(p));
2249 f(xvals, fvptr, npt*npt*npt*npt*npt*npt);
2263 for (
int i=0; i<npt; ++i) {
2264 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2268 else if (NDIM == 2) {
2269 for (
int i=0; i<npt; ++i) {
2270 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2271 for (
int j=0; j<npt; ++j) {
2272 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2277 else if (NDIM == 3) {
2278 for (
int i=0; i<npt; ++i) {
2279 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2280 for (
int j=0; j<npt; ++j) {
2281 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2282 for (
int k=0; k<npt; ++k) {
2283 c[2] = cell(2,0) + h*cell_width[2]*(l[2] + qx(k));
2289 else if (NDIM == 4) {
2290 for (
int i=0; i<npt; ++i) {
2291 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2292 for (
int j=0; j<npt; ++j) {
2293 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2294 for (
int k=0; k<npt; ++k) {
2295 c[2] = cell(2,0) + h*cell_width[2]*(l[2] + qx(k));
2296 for (
int m=0;
m<npt; ++
m) {
2297 c[3] = cell(3,0) + h*cell_width[3]*(l[3] + qx(
m));
2298 fval(i,j,k,
m) =
f(c);
2304 else if (NDIM == 5) {
2305 for (
int i=0; i<npt; ++i) {
2306 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2307 for (
int j=0; j<npt; ++j) {
2308 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2309 for (
int k=0; k<npt; ++k) {
2310 c[2] = cell(2,0) + h*cell_width[2]*(l[2] + qx(k));
2311 for (
int m=0;
m<npt; ++
m) {
2312 c[3] = cell(3,0) + h*cell_width[3]*(l[3] + qx(
m));
2313 for (
int n=0; n<npt; ++n) {
2314 c[4] = cell(4,0) + h*cell_width[4]*(l[4] + qx(n));
2315 fval(i,j,k,
m,n) =
f(c);
2322 else if (NDIM == 6) {
2323 for (
int i=0; i<npt; ++i) {
2324 c[0] = cell(0,0) + h*cell_width[0]*(l[0] + qx(i));
2325 for (
int j=0; j<npt; ++j) {
2326 c[1] = cell(1,0) + h*cell_width[1]*(l[1] + qx(j));
2327 for (
int k=0; k<npt; ++k) {
2328 c[2] = cell(2,0) + h*cell_width[2]*(l[2] + qx(k));
2329 for (
int m=0;
m<npt; ++
m) {
2330 c[3] = cell(3,0) + h*cell_width[3]*(l[3] + qx(
m));
2331 for (
int n=0; n<npt; ++n) {
2332 c[4] = cell(4,0) + h*cell_width[4]*(l[4] + qx(n));
2333 for (
int p=0; p<npt; ++p) {
2334 c[5] = cell(5,0) + h*cell_width[5]*(l[5] + qx(p));
2335 fval(i,j,k,
m,n,p) =
f(c);
2349 template <
typename T, std::
size_t NDIM>
2355 template <
typename T, std::
size_t NDIM>
2367 template <
typename T, std::
size_t NDIM>
2372 if (do_refine && key.
level() < max_refine_level) {
2375 std::vector<Vector<double,NDIM> > newspecialpts;
2376 if (key.
level() < functor->special_level() && specialpts.size() > 0) {
2379 for (
unsigned int i = 0; i < specialpts.size(); ++i) {
2381 user_to_sim(specialpts[i], simpt);
2384 newspecialpts.push_back(specialpts[i]);
2398 const keyT& child = it.key();
2399 r(child_patch(child)) =
project(child);
2403 if (truncate_on_project) s0 =
copy(d(cdata.s0));
2410 if (newspecialpts.size() > 0 || dnorm >=truncate_tol(
thresh,key.
level())) {
2413 const keyT& child = it.key();
2416 p = world.random_proc();
2419 p = coeffs.owner(child);
2422 woT::task(p, &implT::project_refine_op, child, do_refine, newspecialpts);
2426 if (truncate_on_project) {
2428 coeffs.replace(key,
nodeT(s,
false));
2433 const keyT& child = it.key();
2435 coeffs.replace(child,
nodeT(s,
false));
2446 template <
typename T, std::
size_t NDIM>
2448 std::vector<long> v0(
NDIM,0
L);
2449 std::vector<long> v1(
NDIM,1
L);
2452 if (is_compressed()) {
2453 if (world.rank() == coeffs.owner(cdata.key0)) {
2455 MADNESS_ASSERT(it != coeffs.end());
2456 nodeT& node = it->second;
2457 MADNESS_ASSERT(node.has_coeff());
2467 for (
typename dcT::iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
2468 Level n = it->first.level();
2469 nodeT& node = it->second;
2476 coeffT tt(ttt,get_tensor_args());
2477 node.
coeff()(s) += tt;
2484 if (fence) world.gop.fence();
2487 template <
typename T, std::
size_t NDIM>
2490 if (compressed) initial_level =
std::max(initial_level,1);
2491 if (coeffs.is_local(key)) {
2493 if (key.
level() == initial_level) {
2497 coeffs.replace(key,
nodeT(
coeffT(cdata.v2k,targs),
true));
2501 if (key.
level()<initial_level) {
2505 coeffs.replace(key,
nodeT(
coeffT(cdata.vk,targs),
false));
2509 if (key.
level() < initial_level) {
2511 insert_zero_down_to_initial_level(kit.key());
2518 template <
typename T, std::
size_t NDIM>
2522 if (it == coeffs.end()) {
2526 coeffs.replace(key,
nodeT());
2527 it = coeffs.find(key).get();
2529 nodeT& node = it->second;
2531 std::vector< Future<bool> > v = future_vector_factory<bool>(1<<
NDIM);
2536 return woT::task(world.rank(),&implT::truncate_op, key, tol, v);
2544 double dnorm = node.
coeff().normf();
2545 if (dnorm < truncate_tol(tol,key)) {
2554 template <
typename T, std::
size_t NDIM>
2558 for (
int i=0; i<(1<<
NDIM); ++i)
if (v[i].
get())
return true;
2559 nodeT& node = coeffs.find(key).get()->second;
2566 if (key.
level() > 1) {
2567 double dnorm = node.
coeff().normf();
2568 if (dnorm < truncate_tol(tol,key)) {
2573 coeffs.erase(kit.key());
2582 template <
typename T, std::
size_t NDIM>
2584 if (world.rank() == 0) do_print_tree(cdata.key0, os, maxlevel);
2586 if (world.rank() == 0) os.flush();
2591 template <
typename T, std::
size_t NDIM>
2594 if (it == coeffs.end()) {
2596 for (
int i=0; i<key.
level(); ++i) os <<
" ";
2597 os << key <<
" missing --> " << coeffs.owner(key) <<
"\n";
2600 const nodeT& node = it->second;
2601 for (
int i=0; i<key.
level(); ++i) os <<
" ";
2602 os << key <<
" " << node <<
" --> " << coeffs.owner(key) <<
"\n";
2605 do_print_tree(kit.key(),os,maxlevel);
2611 template <
typename T, std::
size_t NDIM>
2613 if (world.rank() == 0) do_print_tree_graphviz(cdata.key0, os, maxlevel);
2615 if (world.rank() == 0) os.flush();
2619 template <
typename T, std::
size_t NDIM>
2623 static int64_t value(
const keyT& key) {
2625 for (int64_t j = 0; j <= key.
level()-1; ++j) {
2626 result += (1 << j*
NDIM);
2634 if (it != coeffs.end()) {
2635 const nodeT& node = it->second;
2638 os << uniqhash::value(key) <<
" -> " << uniqhash::value(kit.key()) <<
"\n";
2639 do_print_tree_graphviz(kit.key(),os,maxlevel);
2645 template <
typename T, std::
size_t NDIM>
2649 if (not functor)
MADNESS_EXCEPTION(
"FunctionImpl: project: confusion about function?",0);
2652 if (functor->provides_coeff())
return functor->coeff(key).full_tensor_copy();
2654 MADNESS_ASSERT(cdata.npt == cdata.k);
2657 tensorT workq(cdata.vq,
false);
2666 template <
typename T, std::
size_t NDIM>
2668 if (coeffs.probe(key)) {
2669 return Future<double>(coeffs.find(key).get()->second.get_norm_tree());
2671 MADNESS_ASSERT(key.
level());
2673 return woT::task(coeffs.owner(parent), &implT::get_norm_tree_recursive, parent,
TaskAttributes::hipri());
2677 template <
typename T, std::
size_t NDIM>
2681 if (coeffs.probe(key)) {
2682 const nodeT& node = coeffs.find(key).get()->second;
2686 result.
set(std::pair<keyT,coeffT>(key,node.
coeff()));
2690 result.
set(std::pair<keyT,coeffT>(key,
coeffT()));
2703 template <
typename T, std::
size_t NDIM>
2707 if (coeffs.probe(key)) {
2708 const nodeT& node = coeffs.find(key).get()->second;
2711 result.
set(std::pair<keyT,coeffT>(key,node.
coeff()));
2726 template <
typename T, std::
size_t NDIM>
2748 nodeT& node = it->second;
2754 for (std::size_t i=0; i<
NDIM; ++i) {
2755 double xi = x[i]*2.0;
2757 if (li == 2) li = 1;
2769 template <
typename T, std::
size_t NDIM>
2776 while (key.
level() <= maxlevel) {
2777 if (coeffs.owner(key) == me) {
2780 if (it != coeffs.end()) {
2781 nodeT& node = it->second;
2787 for (std::size_t i=0; i<
NDIM; ++i) {
2788 double xi = x[i]*2.0;
2790 if (li == 2) li = 1;
2796 return std::pair<bool,T>(
false,0.0);
2799 template <
typename T, std::
size_t NDIM>
2821 nodeT& node = it->second;
2827 for (std::size_t i=0; i<
NDIM; ++i) {
2828 double xi = x[i]*2.0;
2830 if (li == 2) li = 1;
2841 template <
typename T, std::
size_t NDIM>
2863 nodeT& node = it->second;
2869 for (std::size_t i=0; i<
NDIM; ++i) {
2870 double xi = x[i]*2.0;
2872 if (li == 2) li = 1;
2884 template <
typename T, std::
size_t NDIM>
2900 template <
typename A,
typename B>
2907 template <
typename T, std::
size_t NDIM>
2917 node.
coeff().scale(q);
2924 template <
typename T, std::
size_t NDIM>
2932 template <
typename T, std::
size_t NDIM>
2938 template <
typename T, std::
size_t NDIM>
2945 template <
typename T, std::
size_t NDIM>
2951 template <
typename T, std::
size_t NDIM>
2957 template <
typename T, std::
size_t NDIM>
2962 template <
typename T, std::
size_t NDIM>
2967 template <
typename T, std::
size_t NDIM>
2971 double scale = pow(2.0,
double(np-nc));
2972 for (
int mu=0;
mu<cdata.npt; ++
mu) {
2973 double xmu = scale*(cdata.quad_x(
mu)+lc) - lp;
2974 MADNESS_ASSERT(xmu>-1e-15 && xmu<(1+1e-15));
2976 for (
int i=0; i<k; ++i) phi(i,
mu) = p[i];
2978 phi.scale(pow(2.0,0.5*np));
2981 template <
typename T, std::
size_t NDIM>
2991 coeffT result = fcube_for_mul<T>(child, parent, s);
2993 result =
transform(result,cdata.quad_phiw);
2999 template <
typename T, std::
size_t NDIM>
3002 std::vector<long> v0(
NDIM,0);
3005 if (world.rank() == coeffs.owner(cdata.key0)) {
3007 if (it != coeffs.end()) {
3008 const nodeT& node = it->second;
3015 const keyT& key = it->first;
3016 const nodeT& node = it->second;
3032 else if (l >= two2n) {
3041 template <
typename T, std::
size_t NDIM>
3045 for (std::size_t axis=0; axis<
NDIM; ++axis) {
3049 if (!enforce_bc(is_periodic[axis], key.
level(), l[axis])) {
3050 return keyT::invalid();
3057 template <
typename T, std::
size_t NDIM>
3061 typedef std::pair< Key<NDIM>,
coeffT > argT;
3069 template <
typename T, std::
size_t NDIM>
3071 bool nonstandard,
bool keepleaves,
bool redundant) {
3072 if (!coeffs.probe(key))
print(
"missing node",key);
3073 MADNESS_ASSERT(coeffs.probe(key));
3076 nodeT& node = coeffs.find(key).get()->second;
3077 if (node.has_children()) {
3078 std::vector< Future<coeffT > > v = future_vector_factory<coeffT >(1<<
NDIM);
3083 v[i] = woT::task(coeffs.owner(kit.key()), &implT::compress_spawn, kit.key(),
3086 if (redundant)
return woT::task(world.rank(),&implT::make_redundant_op, key, v);
3087 return woT::task(world.rank(),&implT::compress_op, key, v,
nonstandard, redundant);
3091 if (!keepleaves) node.clear_coeff();
3096 template <
typename T, std::
size_t NDIM>
3099 const coordT& plotlo,
const coordT& plothi,
const std::vector<long>& npt,
3100 bool eval_refine)
const {
3102 Tensor<T>& r = *ptr;
3105 for (std::size_t i=0; i<
NDIM; ++i) {
3107 h[i] = (plothi[i]-plotlo[i])/(npt[i]-1);
3110 MADNESS_ASSERT(plotlo[i] == plothi[i]);
3117 const double twon = pow(2.0,
double(n));
3118 const tensorT& coeff = coeffs.find(key).get()->second.coeff().full_tensor_copy();
3125 double fac = pow(0.5,
double(key.
level()));
3127 for (std::size_t d=0; d<
NDIM; ++d) {
3130 boxhi[d] = boxlo[d]+fac;
3132 if (boxlo[d] > plothi[d] || boxhi[d] < plotlo[d]) {
3134 npttotal = boxnpt[d] = 0;
3138 else if (npt[d] == 1) {
3140 boxlo[d] = boxhi[d] = plotlo[d];
3145 boxlo[d] =
std::max(boxlo[d],plotlo[d]);
3146 boxhi[d] =
std::min(boxhi[d],plothi[d]);
3149 double xlo = long((boxlo[d]-plotlo[d])/h[d])*h[d] + plotlo[d];
3150 if (xlo < boxlo[d]) xlo += h[d];
3152 double xhi = long((boxhi[d]-plotlo[d])/h[d])*h[d] + plotlo[d];
3153 if (xhi > boxhi[d]) xhi -= h[d];
3156 boxnpt[d] = long(
round((boxhi[d] - boxlo[d])/h[d])) + 1;
3158 npttotal *= boxnpt[d];
3163 for (std::size_t d=0; d<
NDIM; ++d) {
3164 double xd = boxlo[d] + it[d]*h[d];
3165 x[d] = twon*xd - l[d];
3166 MADNESS_ASSERT(x[d]>=0.0 && x[d] <=1.0);
3168 ind[d] = long(
round((xd-plotlo[d])/h[d]));
3173 MADNESS_ASSERT(ind[d]>=0 && ind[d]<npt[d]);
3179 T tmp = eval_cube(n, x, coeff);
3191 template <
typename T, std::
size_t NDIM>
3194 const std::vector<long>& npt,
3195 const bool eval_refine)
const {
3197 Tensor<T> r(
NDIM, &npt[0]);
3199 MADNESS_ASSERT(!compressed);
3202 const keyT& key = it->first;
3203 const nodeT& node = it->second;
3205 woT::task(world.rank(), &implT::plot_cube_kernel,
3212 world.taskq.fence();
3213 world.gop.sum(r.ptr(), r.size());
3219 static inline void dxprintvalue(FILE*
f,
const double t) {
3220 fprintf(f,
"%.6e\n",t);
3224 fprintf(f,
"%.6e %.6e\n", t.real(), t.imag());
3227 template <
typename T, std::
size_t NDIM>
3229 const char* filename,
3230 const Tensor<double>& cell,
3231 const std::vector<long>& npt,
3234 MADNESS_ASSERT(
NDIM<=6);
3235 const char* element[6] = {
"lines",
"quads",
"cubes",
"cubes4D",
"cubes5D",
"cubes6D"};
3240 if (world.
rank() == 0) {
3241 f = fopen(filename,
"w");
3244 fprintf(f,
"object 1 class gridpositions counts ");
3245 for (std::size_t d=0; d<
NDIM; ++d) fprintf(f,
" %ld",npt[d]);
3248 fprintf(f,
"origin ");
3249 for (std::size_t d=0; d<
NDIM; ++d) fprintf(f,
" %.6e", cell(d,0));
3252 for (std::size_t d=0; d<
NDIM; ++d) {
3253 fprintf(f,
"delta ");
3254 for (std::size_t
c=0;
c<d; ++
c) fprintf(f,
" 0");
3256 if (npt[d]>1) h = (cell(d,1)-cell(d,0))/(npt[d]-1);
3257 fprintf(f,
" %.6e", h);
3258 for (std::size_t
c=d+1;
c<
NDIM; ++
c) fprintf(f,
" 0");
3263 fprintf(f,
"object 2 class gridconnections counts ");
3264 for (std::size_t d=0; d<
NDIM; ++d) fprintf(f,
" %ld",npt[d]);
3266 fprintf(f,
"attribute \"element type\" string \"%s\"\n", element[NDIM-1]);
3267 fprintf(f,
"attribute \"ref\" string \"positions\"\n");
3271 for (std::size_t d=0; d<
NDIM; ++d) npoint *= npt[d];
3272 const char* iscomplex =
"";
3274 const char* isbinary =
"";
3275 if (binary) isbinary =
"binary";
3276 fprintf(f,
"object 3 class array type double %s rank 0 items %d %s data follows\n",
3277 iscomplex, npoint, isbinary);
3281 Tensor<T> r =
function.eval_cube(cell, npt);
3283 if (world.
rank() == 0) {
3287 fwrite((
void *) r.ptr(),
sizeof(
T), r.size(),
f);
3293 dxprintvalue(f,r(*it));
3298 fprintf(f,
"object \"%s\" class field\n",filename);
3299 fprintf(f,
"component \"positions\" value 1\n");
3300 fprintf(f,
"component \"connections\" value 2\n");
3301 fprintf(f,
"component \"data\" value 3\n");
3302 fprintf(f,
"\nend\n");
3308 template <std::
size_t NDIM>
3313 max_refine_level = 30;
3318 truncate_on_project =
true;
3319 apply_randomize =
false;
3320 project_randomize =
false;
3323 cell = Tensor<double>(
NDIM,2);
3325 recompute_cell_info();
3332 template <
typename T, std::
size_t NDIM>
3333 const FunctionCommonData<T,NDIM>*
FunctionCommonData<T,NDIM>::data[MAXK] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
3335 template <std::
size_t NDIM>
int FunctionDefaults<NDIM>::k;
3336 template <std::
size_t NDIM>
double FunctionDefaults<NDIM>::thresh;
3337 template <std::
size_t NDIM>
int FunctionDefaults<NDIM>::initial_level;
3338 template <std::
size_t NDIM>
int FunctionDefaults<NDIM>::max_refine_level;
3339 template <std::
size_t NDIM>
int FunctionDefaults<NDIM>::truncate_mode;
3340 template <std::
size_t NDIM>
bool FunctionDefaults<NDIM>::refine;
3341 template <std::
size_t NDIM>
bool FunctionDefaults<NDIM>::autorefine;
3343 template <std::
size_t NDIM>
bool FunctionDefaults<NDIM>::truncate_on_project;
3344 template <std::
size_t NDIM>
bool FunctionDefaults<NDIM>::apply_randomize;
3345 template <std::
size_t NDIM>
bool FunctionDefaults<NDIM>::project_randomize;
3346 template <std::
size_t NDIM> BoundaryConditions<NDIM> FunctionDefaults<NDIM>::bc;
3347 template <std::
size_t NDIM>
TensorType FunctionDefaults<NDIM>::tt;
3348 template <std::
size_t NDIM> Tensor<double> FunctionDefaults<NDIM>::cell;
3349 template <std::
size_t NDIM> Tensor<double> FunctionDefaults<NDIM>::cell_width;
3350 template <std::
size_t NDIM> Tensor<double> FunctionDefaults<NDIM>::rcell_width;
3351 template <std::
size_t NDIM>
double FunctionDefaults<NDIM>::cell_volume;
3352 template <std::
size_t NDIM>
double FunctionDefaults<NDIM>::cell_min_width;
3355 template <std::
size_t NDIM> std::vector< Key<NDIM> > Displacements<NDIM>::disp;
3356 template <std::
size_t NDIM> std::vector< Key<NDIM> > Displacements<NDIM>::disp_periodicsum[64];
3360 #endif // MADNESS_MRA_MRAIMPL_H__INCLUDED
int np
Definition: tdse1d.cc:166
bool is_leaf() const
Returns true if this does not have children.
Definition: funcimpl.h:202
const double thresh
Definition: dielectric.cc:185
void error(const char *msg)
Definition: world.cc:128
WorldGopInterface & gop
Global operations.
Definition: worldfwd.h:462
SRConf< T > config() const
Definition: gentensor.h:201
void operator()(const A &a, const B &b) const
Definition: mraimpl.h:2902
double ttt
Definition: eigen_solver.cc:182
Tensor< double > B
Definition: tdse1d.cc:167
Void sum_down_spawn(const keyT &key, const coeffT &s)
is this the same as trickle_down() ?
Definition: mraimpl.h:964
Definition: shared_ptr_bits.h:38
size_t size() const
Returns the number of coefficients in this node.
Definition: funcimpl.h:231
void reconstruct(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Reconstruct a vector of functions.
Definition: vmra.h:149
NDIM const Function< R, NDIM > & g
Definition: mra.h:2179
void set_coeff(const coeffT &coeffs)
Takes a shallow copy of the coeff — same as this->coeff()=coeff.
Definition: funcimpl.h:274
Void sock_it_to_me_too(const keyT &key, const RemoteReference< FutureImpl< std::pair< keyT, coeffT > > > &ref) const
Definition: mraimpl.h:2704
T norm(Vector< T, N > v)
Compute norm of a Vector.
Definition: array.h:447
static void _init_quadrature(int k, int npt, Tensor< double > &quad_x, Tensor< double > &quad_w, Tensor< double > &quad_phi, Tensor< double > &quad_phiw, Tensor< double > &quad_phit)
Initialize the quadrature information.
Definition: mraimpl.h:83
Future< argT > find_neighbor(const implT *f, const Key< NDIM > &key, int step) const
Definition: derivative.h:250
std::complex< double > double_complex
Definition: lineplot.cc:16
A pmap that locates children on odd levels with their even level parents.
Definition: funcimpl.h:104
GenTensor< T > full_tensor_copy() const
Definition: gentensor.h:184
double get_thresh() const
Definition: mraimpl.h:281
void print_plane(const std::string filename, const int xaxis, const int yaxis, const coordT &el2)
Print a plane ("xy", "xz", or "yz") containing the point x to file.
Definition: mraimpl.h:357
void do_print_tree(const keyT &key, std::ostream &os, Level maxlevel) const
Definition: mraimpl.h:2592
static TaskAttributes hipri()
Definition: worldthread.h:277
FunctionDefaults holds default paramaters as static class members.
Definition: funcdefaults.h:175
coeffT compress_op(const keyT &key, const std::vector< Future< coeffT > > &v, bool nonstandard, bool redundant)
calculate the wavelet coefficients using the sum coefficients of all child nodes
Definition: mraimpl.h:1650
Void plot_cube_kernel(archive::archive_ptr< Tensor< T > > ptr, const keyT &key, const coordT &plotlo, const coordT &plothi, const std::vector< long > &npt, bool eval_refine) const
Definition: mraimpl.h:3097
Void multiply(const implT *f, const FunctionImpl< T, LDIM > *g, const int particle)
multiply f (a pair function of NDIM) with an orbital g (LDIM=NDIM/2)
Definition: funcimpl.h:3018
TensorType
low rank representations of tensors (see gentensor.h)
Definition: tensor.h:275
void insert_zero_down_to_initial_level(const keyT &key)
Initialize nodes to zero function at initial_level of refinement.
Definition: mraimpl.h:2488
static double get_cell_min_width()
Returns the minimum width of any user cell dimension.
Definition: funcdefaults.h:401
bool has_children() const
Returns true if this node has children.
Definition: funcimpl.h:196
std::size_t size() const
Returns the number of coefficients in the function ... collective global sum.
Definition: mraimpl.h:1829
const Vector< Translation, NDIM > & translation() const
Definition: key.h:225
void abs_inplace(bool fence)
Definition: mraimpl.h:2958
Definition: worldhashmap.h:332
const int NDIM
Definition: tdse1.cc:44
friend const mpreal sum(const mpreal tab[], unsigned long int n, mp_rnd_t rnd_mode=mpreal::default_rnd)
Definition: mpreal.cc:241
Definition: funcimpl.h:4544
bool has_no_data() const
Definition: gentensor.h:188
const bool debug
Definition: tdse1.cc:45
void square_inplace(bool fence)
Pointwise squaring of function with optional global fence.
Definition: mraimpl.h:2952
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t rnd_mode)
Definition: mpreal.h:2201
coeffT & coeff()
Returns a non-const reference to the tensor containing the coeffs.
Definition: funcimpl.h:216
static void set_defaults(World &world)
Used to set defaults to k=7, thresh=1-5, for a unit cube [0,1].
Definition: mraimpl.h:3309
coeffT parent_to_child_NS(const keyT &child, const keyT &parent, const coeffT &coeff) const
Directly project parent NS coeffs to child NS coeffs.
Definition: mraimpl.h:658
bool is_compressed() const
Returns true if the function is compressed.
Definition: mraimpl.h:231
const double L
Definition: 3dharmonic.cc:123
void phi_for_mul(Level np, Translation lp, Level nc, Translation lc, Tensor< double > &phi) const
Compute the Legendre scaling functions for multiplication.
Definition: mraimpl.h:2968
std::size_t max_nodes() const
Returns the max number of nodes on a processor.
Definition: mraimpl.h:1802
detail::ReferenceWrapper< T > const ref(T &t)
Reference wrapper factory function.
Definition: ref.h:132
void plotdx(const Function< T, NDIM > &f, const char *filename, const Tensor< double > &cell=FunctionDefaults< NDIM >::get_cell(), const std::vector< long > &npt=std::vector< long >(NDIM, 201L), bool binary=true)
Writes an OpenDX format file with a cube/slice of points on a uniform grid.
Definition: mraimpl.h:3228
Definition: mraimpl.h:2925
std::size_t max_depth() const
Returns the maximum depth of the tree ... collective ... global sum/broadcast.
Definition: mraimpl.h:1794
::std::string string
Definition: gtest-port.h:872
Definition: funcimpl.h:1948
void operator()(const Key< NDIM > &key, FunctionNode< T, NDIM > &node) const
Definition: mraimpl.h:2916
Iterator for distributed container wraps the local iterator.
Definition: worlddc.h:159
void abs_square_inplace(bool fence)
Definition: mraimpl.h:2963
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition: mraimpl.h:2940
Void do_diff1(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const
Definition: derivative.h:146
Void do_diff1(const DerivativeBase< T, NDIM > *D, const implT *f, const keyT &key, const std::pair< keyT, coeffT > &left, const std::pair< keyT, coeffT > ¢er, const std::pair< keyT, coeffT > &right)
Definition: mraimpl.h:1023
void compress(bool nonstandard, bool keepleaves, bool redundant, bool fence)
compress the wave function
Definition: mraimpl.h:1462
bool has_coeff() const
Returns true if there are coefficients in this node.
Definition: funcimpl.h:188
tensorT downsample(const keyT &key, const std::vector< Future< coeffT > > &v) const
downsample the sum coefficients of level n+1 to sum coeffs on level n
Definition: mraimpl.h:1237
void set_functor(const std::shared_ptr< FunctionFunctorInterface< T, NDIM > > functor1)
Definition: mraimpl.h:245
coeffT truncate_reconstructed_op(const keyT &key, const std::vector< Future< coeffT > > &v, const double tol)
given the sum coefficients of all children, truncate or not
Definition: mraimpl.h:1584
void add_scalar_inplace(T t, bool fence)
Adds a constant to the function. Local operation, optional fence.
Definition: mraimpl.h:2447
double norm_tree_op(const keyT &key, const std::vector< Future< double > > &v)
Definition: mraimpl.h:1522
void nonstandard(World &world, std::vector< Function< T, NDIM > > &v, bool fence=true)
Generates non-standard form of a vector of functions.
Definition: vmra.h:167
std::size_t real_size() const
Returns the number of coefficients in the function ... collective global sum.
Definition: mraimpl.h:1860
Future< double > get_norm_tree_recursive(const keyT &key) const
Definition: mraimpl.h:2667
std::vector< keyT > local_leaf_keys() const
return the keys of the local leaf boxes
Definition: mraimpl.h:515
Definition: funcimpl.h:684
void legendre_scaling_functions(double x, long k, double *p)
Evaluate the first k Legendre scaling functions.
Definition: legendre.cc:90
Definition: mraimpl.h:2939
void trickle_down(bool fence)
sum all the contributions from all scales after applying an operator in mod-NS form ...
Definition: mraimpl.h:1388
NDIM & f
Definition: mra.h:2179
long dim(int i) const
Returns the size of dmension i.
Definition: basetensor.h:147
std::size_t min_nodes() const
Returns the min number of nodes on a processor.
Definition: mraimpl.h:1811
bool has_data() const
Definition: gentensor.h:187
iterator end()
Returns an iterator past the end of the local data (no communication)
Definition: worlddc.h:835
Key< 6 > simpt2key(const Vector< double, 6 > &pt, Level n)
Returns the box at level n that contains the given point in simulation coordinates.
Definition: helium_mp2.cc:475
Tensor< T > fcube(const Key< NDIM > &, T(*f)(const Vector< double, NDIM > &), const Tensor< double > &)
Definition: mraimpl.h:2047
"put" this on g
Definition: funcimpl.h:2152
Wrapper for opaque pointer ... bitwise copy of the pointer ... no remapping performed.
Definition: archive.h:788
const FunctionCommonData< T, NDIM > & get_cdata() const
Definition: mraimpl.h:302
Vector< double, 3 > coordT
Definition: chem/corepotential.cc:57
void average(const implT &rhs)
take the average of two functions, similar to: this=0.5*(this+rhs)
Definition: mraimpl.h:1150
Tensor< T > tensorT
Type of tensor for anything but to hold coeffs.
Definition: funcimpl.h:904
int get_k() const
Definition: mraimpl.h:293
std::vector< Slice > child_patch(const keyT &child) const
Returns patch referring to coeffs of child in parent box.
Definition: mraimpl.h:641
void change_tensor_type1(const TensorArgs &targs, bool fence)
change the tensor type of the coefficients in the FunctionNode
Definition: mraimpl.h:1161
const coeffT parent_to_child(const coeffT &s, const keyT &parent, const keyT &child) const
Directly project parent coeffs to child coeffs.
Definition: mraimpl.h:2983
const double beta
Definition: gygi_soltion.cc:63
FunctionImpl holds all Function state to facilitate shallow copy semantics.
Definition: funcdefaults.h:48
static const Tensor< double > & get_cell()
Gets the user cell for the simulation.
Definition: funcdefaults.h:369
bool is_invalid() const
Checks if a key is invalid.
Definition: key.h:152
void serialize(Archive &ar)
Definition: mraimpl.h:2929
#define PROFILE_MEMBER_FUNC(classname)
Definition: worldprofile.h:199
iterator begin()
Returns an iterator to the beginning of the local data (no communication)
Definition: worlddc.h:822
scaleinplace()
Definition: mraimpl.h:2910
Changes non-standard compressed form to standard compressed form.
Definition: funcimpl.h:3895
Future< std::pair< keyT, coeffT > > find_me(const keyT &key) const
find_me. Called by diff_bdry to get coefficients of boundary function
Definition: mraimpl.h:3059
Void trickle_down_op(const keyT &key, const coeffT &s)
sum all the contributions from all scales after applying an operator in mod-NS form ...
Definition: mraimpl.h:1402
Provides FunctionCommonData, FunctionImpl and FunctionFactory.
T q
Definition: mraimpl.h:2909
Void set_norm_tree(double norm_tree)
Sets the value of norm_tree.
Definition: funcimpl.h:295
static const BoundaryConditions< NDIM > & get_bc()
Returns the default boundary conditions.
Definition: funcdefaults.h:345
TensorType get_tensor_type() const
Definition: mraimpl.h:275
void scale_inplace(const T q, bool fence)
In-place scale by a constant.
Definition: mraimpl.h:2946
bool is_valid() const
Checks if a key is valid.
Definition: key.h:158
bool noautorefine(const keyT &key, const tensorT &t) const
Always returns false (for when autorefine is not wanted)
Definition: mraimpl.h:947
void set_autorefine(bool value)
Definition: mraimpl.h:290
a class to track where relevant (parent) coeffs are
Definition: funcimpl.h:756
std::size_t max_local_depth() const
Returns the maximum local depth of the tree ... no communications.
Definition: mraimpl.h:1780
bool thisKeyContains(const Vector< double, NDIM > &x, const unsigned int &dim0, const unsigned int &dim1) const
check if this MultiIndex contains point x, disregarding these two dimensions
Definition: key.h:306
Void erase(const Level &max_level)
truncate tree at a certain level
Definition: mraimpl.h:823
void do_print_tree_graphviz(const keyT &key, std::ostream &os, Level maxlevel) const
Definition: mraimpl.h:2620
double thresh
Definition: gentensor.h:128
Simple structure used to manage references/pointers to remote instances.
Definition: worldref.h:59
#define PROFILE_BLOCK(name)
Definition: worldprofile.h:197
Definition: funcimpl.h:2206
given an NS tree resulting from a convolution, truncate leafs if appropriate
Definition: funcimpl.h:1922
Void sock_it_to_me(const keyT &key, const RemoteReference< FutureImpl< std::pair< keyT, coeffT > > > &ref) const
Walk up the tree returning pair(key,node) for first node with coefficients.
Definition: mraimpl.h:2678
Void evaldepthpt(const Vector< double, NDIM > &xin, const keyT &keyin, const typename Future< Level >::remote_refT &ref)
Get the depth of the tree at a point in simulation coordinates.
Definition: mraimpl.h:2800
void zero_norm_tree()
Definition: mraimpl.h:1329
Future< coeffT > truncate_reconstructed_spawn(const keyT &key, const double tol)
truncate using a tree in reconstructed form
Definition: mraimpl.h:1560
void print_tree_graphviz(std::ostream &os=std::cout, Level maxlevel=10000) const
Definition: mraimpl.h:2612
T & get()
Gets the value, waiting if necessary (error if not a local future)
Definition: worldfut.h:513
void do_print_grid(const std::string filename, const std::vector< keyT > &keys) const
print the grid in xyz format
Definition: mraimpl.h:541
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
std::pair< Key< NDIM >, ShallowNode< T, NDIM > > find_datum(keyT key) const
return the a std::pair, which MUST exist
Definition: mraimpl.h:1057
void verify_tree() const
Verify tree is properly constructed ... global synchronization involved.
Definition: mraimpl.h:104
#define max(a, b)
Definition: lda.h:53
Vector< T, 1 > vec(T x)
Your friendly neighborhood factory function.
Definition: array.h:456
Tensor< double > print_plane_local(const int xaxis, const int yaxis, const coordT &el2)
collect the data for a plot of the MRA structure locally on each node
Definition: mraimpl.h:378
Key parent(int generation=1) const
Returns the key of the parent.
Definition: key.h:248
void scale(World &world, std::vector< Function< T, NDIM > > &v, const std::vector< Q > &factors, bool fence=true)
Scales inplace a vector of functions by distinct values.
Definition: vmra.h:290
void serialize(Archive &ar)
Definition: mraimpl.h:2935
Void forward_do_diff1(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const
Definition: derivative.h:109
void change_tensor_type(GenTensor< T > &t, const TensorArgs &targs)
change representation to targ.tt
Definition: gentensor.h:1309
std::vector< bool > is_periodic() const
Convenience for application of integral operators.
Definition: funcdefaults.h:137
std::pair< bool, T > eval_local_only(const Vector< double, NDIM > &xin, Level maxlevel)
Evaluate function only if point is local returning (true,value); otherwise return (false...
Definition: mraimpl.h:2771
const keyT & key0() const
Definition: mraimpl.h:348
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
void gaxpy_oop_reconstructed(const double alpha, const implT &f, const double beta, const implT &g, const bool fence)
perform: this= alpha*f + beta*g, invoked by result
Definition: mraimpl.h:203
const mpreal min(const mpreal &x, const mpreal &y)
Definition: mpreal.h:2675
const double N
Definition: navstokes_cosines.cc:94
change representation of nodes' coeffs to low rank, optional fence
Definition: funcimpl.h:2185
coeffT make_redundant_op(const keyT &key, const std::vector< Future< coeffT > > &v)
similar to compress_op, but insert only the sum coefficients in the tree
Definition: mraimpl.h:1714
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
void reset_timer()
Definition: mraimpl.h:320
void print_grid(const std::string filename) const
Definition: mraimpl.h:499
This class is used to specify boundary conditions for all operatorsExterior boundary conditions (i...
Definition: funcdefaults.h:72
bool gauss_legendre(int n, double xlo, double xhi, double *x, double *w)
Definition: legendre.cc:231
Level level() const
Definition: key.h:220
void reduce_rank(const double &eps)
Definition: gentensor.h:193
const double mu
Definition: navstokes_cosines.cc:96
coeffT upsample(const keyT &key, const coeffT &coeff) const
upsample the sum coefficients of level 1 to sum coeffs on level n+1
Definition: mraimpl.h:1267
void print_tree(std::ostream &os=std::cout, Level maxlevel=10000) const
Definition: mraimpl.h:2583
Tensor< double > tensorT
Definition: chem/distpm.cc:13
void truncate(double tol, bool fence)
Truncate according to the threshold with optional global fence.
Definition: mraimpl.h:332
TensorArgs holds the arguments for creating a LowRankTensor.
Definition: gentensor.h:127
Void reconstruct_op(const keyT &key, const coeffT &s)
Definition: mraimpl.h:1992
double check_symmetry_local() const
Returns some asymmetry measure ... no comms.
Definition: mraimpl.h:840
Definition: mraimpl.h:2908
Void evalR(const Vector< double, NDIM > &xin, const keyT &keyin, const typename Future< long >::remote_refT &ref)
Get the rank of leaf box of the tree at a point in simulation coordinates.
Definition: mraimpl.h:2842
Namespace for mathematical applications.
Definition: muParser.cpp:47
shallow-copy, pared-down version of FunctionNode, for special purpose only
Definition: funcimpl.h:717
void broaden(std::vector< bool > is_periodic, bool fence)
Definition: mraimpl.h:1338
Implements the functionality of Futures.
Definition: worldfut.h:157
void flo_unary_op_node_inplace(const opT &op, bool fence)
Unary operation applied inplace to the coefficients WITHOUT refinement, optional fence.
Definition: funcimpl.h:1897
map this on f
Definition: funcimpl.h:2122
static TaskAttributes generator()
Definition: worldthread.h:273
bool truncate_op(const keyT &key, double tol, const std::vector< Future< bool > > &v)
Actually do the truncate operation.
Definition: mraimpl.h:2555
ElementaryInterface (formerly FunctorInterfaceWrapper) interfaces a c-function.
Definition: function_interface.h:207
bool & is_on_demand()
Definition: mraimpl.h:269
Defines and implements WorldObject.
void standard(World &world, std::vector< Function< T, NDIM > > &v, bool fence=true)
Generates standard form of a vector of functions.
Definition: vmra.h:181
void set_thresh(double value)
Definition: mraimpl.h:284
bool is_nonstandard() const
Definition: mraimpl.h:242
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
void fence()
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition: worldgop.cc:52
TensorType tensor_type() const
Definition: gentensor.h:197
std::shared_ptr< FunctionFunctorInterface< T, NDIM > > get_functor()
Definition: mraimpl.h:251
void reduce_rank(const TensorArgs &targs, bool fence)
reduce the rank of the coefficients tensors
Definition: mraimpl.h:1169
const mpreal round(const mpreal &v)
Definition: mpreal.h:2611
void reconstruct(bool fence)
Definition: mraimpl.h:1444
Void project_refine_op(const keyT &key, bool do_refine, const std::vector< Vector< double, NDIM > > &specialpts)
Projection with optional refinement.
Definition: mraimpl.h:2368
A multiresolution adaptive numerical function.
Definition: derivative.h:61
int Level
Definition: key.h:58
void serialize(Archive &ar)
Definition: mraimpl.h:2919
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:37
Scoped array.
Definition: scopedptr.h:85
T trace_local() const
Returns int(f(x),x) in local volume.
Definition: mraimpl.h:3000
Definition: funcimpl.h:3757
void print_size(const std::string name) const
print tree size and size
Definition: mraimpl.h:1874
const mpreal sum(const mpreal tab[], unsigned long int n, mp_rnd_t rnd_mode)
Definition: mpreal.cc:241
void serialize(Archive &ar)
Definition: mraimpl.h:2904
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition: derivative.h:58
Tri-diagonal operator traversing tree primarily for derivative operator.
Definition: derivative.h:73
Abstract base class interface required for functors used as input to Functions.
Definition: function_interface.h:58
const double m
Definition: gfit.cc:199
Tensor< T > eval_plot_cube(const coordT &plotlo, const coordT &plothi, const std::vector< long > &npt, const bool eval_refine=false) const
Evaluate a cube/slice of points ... plotlo and plothi are already in simulation coordinates.
Definition: mraimpl.h:3192
ProcessID rank() const
Returns the process rank in this world (same as MPI_Comm_rank()))
Definition: worldfwd.h:526
Void accumulate_timer(const double time) const
Definition: mraimpl.h:305
check symmetry wrt particle exchange
Definition: funcimpl.h:2012
double finalize_apply(const bool fence=true)
after apply we need to do some cleanup;
Definition: mraimpl.h:1741
void norm_tree(bool fence)
compute for each FunctionNode the norm of the function inside that node
Definition: mraimpl.h:1514
Void set_has_children(bool flag)
Sets has_children attribute to value of flag.
Definition: funcimpl.h:244
void print_stats() const
print the number of configurations per node
Definition: mraimpl.h:1898
GenTensor< T > full_tensor() const
Definition: gentensor.h:182
void test(World &world, bool doloadbal=false)
Definition: dataloadbal.cc:225
Void broaden_op(const keyT &key, const std::vector< Future< bool > > &v)
Definition: mraimpl.h:1317
bool is_redundant() const
Returns true if the function is redundant.
Definition: mraimpl.h:237
GenTensor< TENSOR_RESULT_TYPE(T, Q)> general_transform(const GenTensor< T > &t, const Tensor< Q > c[])
Transform all dimensions of the tensor t by distinct matrices c.
Definition: gentensor.h:1342
Definition: funcimpl.h:1250
double abs(double x)
Definition: complexfun.h:48
bool is_neighbor_of(const Key &key, const std::vector< bool > &bperiodic) const
Assuming keys are at the same level, returns true if displaced by no more than 1 in any direction...
Definition: key.h:283
std::size_t tree_size() const
Returns the size of the tree structure of the function ... collective global sum. ...
Definition: mraimpl.h:1820
remote_refT remote_ref(World &world) const
Returns a structure used to pass references to another process.
Definition: worldfut.h:552
Range vaguely a la Intel TBB encapsulates random-access STL-like start and end iterators with chunksi...
Definition: worldrange.h:49
const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > & get_pmap() const
Definition: mraimpl.h:187
void clear_coeff()
Clears the coefficients (has_coeff() will subsequently return false)
Definition: funcimpl.h:284
long size() const
Returns the number of elements in the tensor.
Definition: basetensor.h:138
void diff(const DerivativeBase< T, NDIM > *D, const implT *f, bool fence)
Definition: mraimpl.h:1035
Future< bool > truncate_spawn(const keyT &key, double tol)
Returns true if after truncation this node has coefficients.
Definition: mraimpl.h:2519
static const Tensor< double > & get_cell_width()
Returns the width of each user cell dimension.
Definition: funcdefaults.h:391
void standard(bool fence)
Changes non-standard compressed form to standard compressed form.
Definition: mraimpl.h:1732
Implements WorldContainer.
Key< NDIM > simpt2key(const coordT &pt, Level n) const
Returns the box at level n that contains the given point in simulation coordinates.
Definition: mraimpl.h:694
size_t real_size() const
Definition: gentensor.h:191
A future is a possibly yet unevaluated value.
Definition: ref.h:210
A type you can return when you want to return void ... use "return None".
Definition: typestuff.h:154
void fcube(const keyT &key, const FunctionFunctorInterface< T, NDIM > &f, const Tensor< double > &qx, tensorT &fval) const
Evaluate function at quadrature points in the specified box.
Definition: mraimpl.h:2356
bool exists_and_has_children(const keyT &key) const
Definition: mraimpl.h:1306
tensorT coeffs_for_jun(Level n, long q=0)
Get the scaling function coeffs at level n starting from NS form.
Definition: mraimpl.h:708
Tensor< TENSOR_RESULT_TYPE(T, Q) > & fast_transform(const Tensor< T > &t, const Tensor< Q > &c, Tensor< TENSOR_RESULT_TYPE(T, Q) > &result, Tensor< TENSOR_RESULT_TYPE(T, Q) > &workspace)
Restricted but heavily optimized form of transform()
Definition: tensor.h:2351
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
Definition: funcdefaults.h:56
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
FunctionCommonData holds all Function data common for given k.
Definition: function_common_data.h:52
Function< T, NDIM > project(const Function< T, NDIM > &other, int k=FunctionDefaults< NDIM >::get_k(), double thresh=FunctionDefaults< NDIM >::get_thresh(), bool fence=true)
Definition: mra.h:2162
coeffT assemble_coefficients(const keyT &key, const coeffT &coeff_ket, const coeffT &vpotential1, const coeffT &vpotential2, const tensorT &veri) const
given several coefficient tensors, assemble a result tensor
Definition: mraimpl.h:1099
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
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:65
tensorT filter(const tensorT &s) const
Transform sum coefficients at level n to sums+differences at level n-1.
Definition: mraimpl.h:1188
void print_info() const
Prints summary of data distribution.
Definition: mraimpl.h:921
A slice defines a sub-range or patch of a dimension.
Definition: slice.h:103
Future< coeffT > compress_spawn(const keyT &key, bool nonstandard, bool keepleaves, bool redundant)
Definition: mraimpl.h:3070
bool exists_and_is_leaf(const keyT &key) const
Definition: mraimpl.h:1311
Void do_print_plane(const std::string filename, std::vector< Tensor< double > > plotinfo, const int xaxis, const int yaxis, const coordT el2)
print the MRA structure
Definition: mraimpl.h:454
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition: mraimpl.h:2926
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition: mraimpl.h:2934
Definition: mraimpl.h:2933
Definition: gentensor.h:123
Future< double > norm_tree_spawn(const keyT &key)
Definition: mraimpl.h:1537
bool get_autorefine() const
Definition: mraimpl.h:287
bool autorefine_square_test(const keyT &key, const nodeT &t) const
Returns true if this block of coeffs needs autorefining.
Definition: mraimpl.h:953
void set(const Future< T > &other)
A.set(B) where A & B are futures ensures A has/will have the same value as B.
Definition: worldfut.h:473
void undo_redundant(const bool fence)
convert this from redundant to standard reconstructed form
Definition: mraimpl.h:1504
Void eval(const Vector< double, NDIM > &xin, const keyT &keyin, const typename Future< T >::remote_refT &ref)
Evaluate the function at a point in simulation coordinates.
Definition: mraimpl.h:2727
double norm2sq_local() const
Returns the square of the local norm ... no comms.
Definition: mraimpl.h:1768
Function< T, NDIM > multiply(const Function< T, NDIM > f, const Function< T, LDIM > g, const int particle, const bool fence=true)
multiply a high-dimensional function with a low-dimensional function
Definition: mra.h:2116
int64_t Translation
Definition: key.h:57
bool two_scale_hg(int k, Tensor< double > *hg)
Definition: twoscale.cc:156
Definition: mraimpl.h:2901
reduce the rank of the nodes, optional fence
Definition: funcimpl.h:1986
add two functions f and g: result=alpha * f + beta * g
Definition: funcimpl.h:2956
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition: mraimpl.h:2913
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const dcT & get_coeffs() const
Definition: mraimpl.h:296
const double c
Definition: gfit.cc:200
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
void print_timer() const
Definition: mraimpl.h:311
double wall_time()
Returns the wall time in seconds relative to arbitrary origin.
Definition: world.cc:248
Definition: funcimpl.h:4598
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
tensorT unfilter(const tensorT &s) const
Transform sums+differences at level n to sum coefficients at level n+1.
Definition: mraimpl.h:1217
tensorT project(const keyT &key) const
Compute by projection the scaling function coeffs in specified box.
Definition: mraimpl.h:2646
double truncate_tol(double tol, const keyT &key) const
Returns the truncation threshold according to truncate_method.
Definition: mraimpl.h:613
void unset_functor()
Definition: mraimpl.h:263
TensorArgs get_tensor_args() const
Definition: mraimpl.h:278
keyT neighbor(const keyT &key, const keyT &disp, const std::vector< bool > &is_periodic) const
Returns key of general neighbor enforcing BC.
Definition: mraimpl.h:3042
Definition: indexit.h:141
T eval_cube(Level n, coordT &x, const tensorT &c) const
Definition: mraimpl.h:1938
virtual bool supports_vectorized() const
Does the interface support a vectorized operator()?
Definition: function_interface.h:70
#define PROFILE_FUNC
Definition: worldprofile.h:198
Void forward_do_diff1(const DerivativeBase< T, NDIM > *D, const implT *f, const keyT &key, const std::pair< keyT, coeffT > &left, const std::pair< keyT, coeffT > ¢er, const std::pair< keyT, coeffT > &right)
Definition: mraimpl.h:1012
Traits class to specify support of numeric types.
Definition: type_data.h:56
void tnorm(const tensorT &t, double *lo, double *hi) const
Computes norm of low/high-order polyn. coeffs for autorefinement test.
Definition: mraimpl.h:2885
void sum_down(bool fence)
After 1d push operator must sum coeffs down the tree to restore correct scaling function coefficients...
Definition: mraimpl.h:1004
Defines and implements a concurrent hashmap.
void make_redundant(const bool fence)
convert this to redundant, i.e. have sum coefficients on all levels
Definition: mraimpl.h:1485
scaleinplace(T q)
Definition: mraimpl.h:2912
Void refine_to_common_level(const std::vector< FunctionImpl< T, NDIM > * > &v, const std::vector< tensorT > &c, const keyT key)
Refine multiple functions down to the same finest level.
Definition: mraimpl.h:854
void compress(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Compress a vector of functions.
Definition: vmra.h:130
void mapdim(const implT &f, const std::vector< long > &map, bool fence)
Permute the dimensions of f according to map, result on this.
Definition: mraimpl.h:1138
long rank() const
Definition: gentensor.h:189
void serialize(Archive &ar)
Definition: mraimpl.h:2941
Iterates in lexical order thru all children of a key.
Definition: key.h:61
Void put_in_box(ProcessID from, long nl, long ni) const
Definition: mraimpl.h:911