32#ifndef MADNESS_MRA_MRAIMPL_H__INCLUDED
33#define MADNESS_MRA_MRAIMPL_H__INCLUDED
36#error "mraimpl.h should ONLY be included in one of the mraX.cc files (x=1..6)"
55 bool isnan(
const std::complex<T>&
v) {
71 template <
typename T, std::
size_t NDIM>
73 if (!
two_scale_hg(
k, &
hg))
throw "failed to get twoscale coefficients";
91 template <
typename T, std::
size_t NDIM>
104 for (
int j=0; j<
k; ++j) {
112 template <
typename T, std::
size_t NDIM>
120 template <
typename T, std::
size_t NDIM>
124 for (
const auto& [key, node] :
coeffs) {
126 if (key.level() > 0) {
127 const keyT parent = key.parent();
128 typename dcT::const_iterator pit = coeffs.find(parent).get();
129 if (pit == coeffs.end()) {
130 print(world.rank(),
"FunctionImpl: verify: MISSING PARENT",key,parent);
135 const nodeT& pnode = pit->second;
136 if (!pnode.has_children()) {
137 print(world.rank(),
"FunctionImpl: verify: PARENT THINKS IT HAS NO CHILDREN",key,parent);
144 for (KeyChildIterator<NDIM> kit(key); kit; ++kit) {
145 typename dcT::const_iterator cit = coeffs.find(kit.key()).get();
146 if (cit == coeffs.end()) {
147 if (node.has_children()) {
148 print(world.rank(),
"FunctionImpl: verify: MISSING CHILD",key,kit.key());
155 if (! node.has_children()) {
156 print(world.rank(),
"FunctionImpl: verify: UNEXPECTED CHILD",key,kit.key());
170 template<
typename T, std::
size_t NDIM>
176 auto check_internal_coeff_size = [&state, &
k](
const coeffT&
c) {
178 return c.dim(0)==2*
k;
184 auto check_leaf_coeff_size = [&state, &
k](
const coeffT&
c) {
195 for (
const auto& [key, node] :
coeffs) {
196 const auto&
c=node.coeff();
197 const bool is_internal=node.has_children();
198 const bool is_leaf=not node.has_children();
199 if (is_internal) good=good and check_internal_coeff_size(
c);
200 if (is_leaf) good=good and check_leaf_coeff_size(
c);
202 print(
"incorrect size of coefficients for key",key,
"state",state,
c.dim(0));;
208 template <
typename T, std::
size_t NDIM>
224 template <
typename T, std::
size_t NDIM>
226 const double beta,
const implT&
g,
const bool fence) {
232 if (
world.rank() == owner) {
240 apply_opT apply_op(
this);
243 coeff_op, apply_op,
cdata.key0);
247 if (fence)
world.gop.fence();
251 template <
typename T, std::
size_t NDIM>
257 template <
typename T, std::
size_t NDIM>
263 template <
typename T, std::
size_t NDIM>
269 template <
typename T, std::
size_t NDIM>
274 template <
typename T, std::
size_t NDIM>
279 template <
typename T, std::
size_t NDIM>
284 template <
typename T, std::
size_t NDIM>
289 template <
typename T, std::
size_t NDIM>
294 template <
typename T, std::
size_t NDIM>
299 template <
typename T, std::
size_t NDIM>
304 template <
typename T, std::
size_t NDIM>
311 template <
typename T, std::
size_t NDIM>
317 template <
typename T, std::
size_t NDIM>
323 template <
typename T, std::
size_t NDIM>
330 template <
typename T, std::
size_t NDIM>
333 template <
typename T, std::
size_t NDIM>
336 template <
typename T, std::
size_t NDIM>
339 template <
typename T, std::
size_t NDIM>
342 template <
typename T, std::
size_t NDIM>
345 template <
typename T, std::
size_t NDIM>
348 template <
typename T, std::
size_t NDIM>
351 template <
typename T, std::
size_t NDIM>
354 template <
typename T, std::
size_t NDIM>
357 template <
typename T, std::
size_t NDIM>
360 template <
typename T, std::
size_t NDIM>
363 template <
typename T, std::
size_t NDIM>
368 template <
typename T, std::
size_t NDIM>
370 if (
world.rank()==0) {
377 template <
typename T, std::
size_t NDIM>
379 if (
world.rank()==0) {
389 template <
typename T, std::
size_t NDIM>
405 template <
typename T, std::
size_t NDIM>
414 template <
typename T, std::
size_t NDIM>
421 std::vector<Tensor<double> > localinfo_vec(1,localinfo);
422 std::vector<Tensor<double> > printinfo=
world.gop.concat0(localinfo_vec);
434 template <
typename T, std::
size_t NDIM>
447 const keyT& key = it->first;
448 const nodeT& node = it->second;
456 double scale=std::pow(0.5,
double(n));
457 double xloleft =
scale*l[xaxis];
458 double yloleft =
scale*l[yaxis];
459 double xhiright =
scale*(l[xaxis]+1);
460 double yhiright =
scale*(l[yaxis]+1);
471 if ((user[0]<-5.0) or (user[1]<-5.0) or (user[2]>5.0) or (user[3]>5.0))
continue;
477 const double maxrank=40;
483 const int npt =
cdata.npt + 1;
494 plotinfo(counter,0)=color;
495 plotinfo(counter,1)=user[0];
496 plotinfo(counter,2)=user[1];
497 plotinfo(counter,3)=user[2];
498 plotinfo(counter,4)=user[3];
505 else plotinfo=plotinfo(
Slice(0,counter-1),
Slice(
_));
510 template <
typename T, std::
size_t NDIM>
512 const int xaxis,
const int yaxis,
const coordT el2) {
519 pFile = fopen(
filename.c_str(),
"w");
523 fprintf(pFile,
"\\psset{unit=1cm}\n");
524 fprintf(pFile,
"\\begin{pspicture}(%4.2f,%4.2f)(%4.2f,%4.2f)\n",
527 fprintf(pFile,
"\\pslinewidth=0.1pt\n");
529 for (std::vector<
Tensor<double> >::const_iterator it=plotinfo.begin(); it!=plotinfo.
end(); ++it) {
534 for (
long i=0; i<localinfo.
dim(0); ++i) {
536 fprintf(pFile,
"\\newhsbcolor{mycolor}{%8.4f 1.0 0.7}\n",localinfo(i,0));
537 fprintf(pFile,
"\\psframe["
540 "(%12.8f,%12.8f)(%12.8f,%12.8f)\n",
541 localinfo(i,1),localinfo(i,2),localinfo(i,3),localinfo(i,4));
547 fprintf(pFile,
"\\end{pspicture}\n");
553 template <
typename T, std::
size_t NDIM>
560 std::vector<keyT> all_keys=
world.gop.concat0(local_keys);
569 template <
typename T, std::
size_t NDIM>
573 std::vector<keyT> keys(
coeffs.size());
580 const keyT& key = it->first;
581 const nodeT& node = it->second;
582 if (node.
is_leaf()) keys[i++]=key;
595 template <
typename T, std::
size_t NDIM>
602 const size_t npt = qx.
dim(0);
607 long nboxes=keys.size();
611 pFile = fopen(
filename.c_str(),
"w");
613 fprintf(pFile,
"%ld\n",npoints*nboxes);
614 fprintf(pFile,
"%ld points per box and %ld boxes \n",npoints,nboxes);
617 typename std::vector<keyT>::const_iterator key_it=keys.begin();
618 for (key_it=keys.begin(); key_it!=keys.end(); ++key_it) {
620 const keyT& key=*key_it;
621 fprintf(pFile,
"# key: %8d",key.
level());
628 const double h = std::pow(0.5,
double(n));
635 for (
size_t i=0; i<npt; ++i) {
637 for (
size_t j=0; j<npt; ++j) {
639 for (
size_t k=0;
k<npt; ++
k) {
646 fprintf(pFile,
"%18.12f %18.12f %18.12f\n",
c[0],
c[1],
c[2]);
721 template <
typename T, std::
size_t NDIM>
728 const int MAXLEVEL1 = 20;
729 const int MAXLEVEL2 = 10;
736 return tol*std::min(1.0,
pow(0.5,
double(std::min(key.
level(),MAXLEVEL1)))*
L);
740 return tol*std::min(1.0,
pow(0.25,
double(std::min(key.
level(),MAXLEVEL2)))*
L*
L);
749 const static double fac=1.0/std::pow(2,
NDIM*0.5);
753 return tol*std::min(1.0,
pow(0.5,
double(std::min(key.
level(),MAXLEVEL1)))*
L);
762 int n = std::min(key.
level(), MAXLEVEL2);
763 return tol * std::min(1.0, std::pow(std::pow(0.5, n) *
L,
NDIM * 0.5));
772 int n = std::min(key.
level(), MAXLEVEL1);
773 return tol * std::max(1.0, std::pow(2.0, n) /
L);
787 int n = std::min(key.
level(), MAXLEVEL2);
788 return tol * std::max(1.0, std::pow(std::pow(2.0, n) /
L, 2.0));
796 template <
typename T, std::
size_t NDIM>
798 std::vector<Slice> s(
NDIM);
800 for (std::size_t i=0; i<
NDIM; ++i)
801 s[i] =
cdata.s[l[i]&1];
807 template <
typename T, std::
size_t NDIM>
809 const keyT& child,
const keyT& parent,
const coeffT& coeff)
const {
819 if (coeff.
dim(0)==2*
f->get_k()) result=coeff;
820 else if (coeff.
dim(0)==
f->get_k()) {
821 result(
f->cdata.s0)+=coeff;
830 const coeffT scoeff=
f->parent_to_child(coeff,parent,child);
831 result(
f->cdata.s0)+=scoeff;
839 template <
typename T, std::
size_t NDIM>
846 nodeT& node=it->second;
855 template <
typename T, std::
size_t NDIM>
869 template <
typename T, std::
size_t NDIM>
871 const std::vector<tensorT>&
c,
876 std::unique_ptr<typename dcT::accessor[]> acc(
new typename dcT::accessor[
v.size()]);
877 for (
unsigned int i=0; i<
c.size(); i++) {
880 bool exists = !
v[i]->coeffs.insert(acc[i],key);
892 for (
unsigned int i=0; i<
v.size(); i++) {
893 done &= acc[i]->second.has_coeff();
898 std::vector<tensorT>
d(
v.size());
899 for (
unsigned int i=0; i<
v.size(); i++) {
900 if (acc[i]->second.has_coeff()) {
903 s(
cdata.s0) = acc[i]->second.coeff().full_tensor();
904 acc[i]->second.clear_coeff();
906 acc[i]->second.set_has_children(
true);
912 const keyT& child = kit.key();
914 std::vector<tensorT> childc(
v.size());
915 for (
unsigned int i=0; i<
v.size(); i++) {
924 template <
typename T, std::
size_t NDIM>
926 if (
world.size()> 1000)
933 template <
typename T, std::
size_t NDIM>
935 if (
world.size() >= 1000)
937 for (
int i=0; i<
world.size(); ++i)
940 long nleaf=0, ninterior=0;
943 const nodeT& node = it->second;
951 if (
world.rank() == 0) {
952 for (
int i=0; i<
world.size(); ++i) {
959 template <
typename T, std::
size_t NDIM>
965 template <
typename T, std::
size_t NDIM>
969 double test = 2*
lo*hi + hi*hi;
976 template <
typename T, std::
size_t NDIM>
980 nodeT& node = acc->second;
1002 const keyT& child = kit.key();
1016 template <
typename T, std::
size_t NDIM>
1020 if (fence)
world.gop.fence();
1024 template <
typename T, std::
size_t NDIM>
1028 const std::pair<keyT,coeffT>& left,
1029 const std::pair<keyT,coeffT>& center,
1030 const std::pair<keyT,coeffT>& right) {
1031 D->forward_do_diff1(
f,
this,key,left,center,right);
1035 template <
typename T, std::
size_t NDIM>
1039 const std::pair<keyT,coeffT>& left,
1040 const std::pair<keyT,coeffT>& center,
1041 const std::pair<keyT,coeffT>& right) {
1042 D->do_diff1(
f,
this,key,left,center,right);
1047 template <
typename T, std::
size_t NDIM>
1049 typedef std::pair<keyT,coeffT> argT;
1050 if (
D->parallel_submit_) {
1051 D->submit_diff_tasks(
f,
this);
1052 if (fence)
world.gop.fence();
1055 for (
const auto& [key, node]:
f->coeffs) {
1056 if (node.has_coeff()) {
1058 argT center(key,node.coeff());
1066 if (fence)
world.gop.fence();
1071 template <
typename T, std::
size_t NDIM>
1084 template <
typename T, std::
size_t NDIM>
1092 std::vector<long> vkhalf=std::vector<long>(
NDIM/2,
cdata.vk[0]);
1119 template <
typename T, std::
size_t NDIM>
1126 if (ket_only)
return coeff_ket;
1158 return coeff_result;
1163 template <
typename T, std::
size_t NDIM>
1172 template <
typename T, std::
size_t NDIM>
1182 template <
typename T, std::
size_t NDIM>
1184 const std::vector<long>&
mirror,
bool fence) {
1194 template <
typename T, std::
size_t NDIM>
1205 template <
typename T, std::
size_t NDIM>
1213 template <
typename T, std::
size_t NDIM>
1221 template <
typename T, std::
size_t NDIM>
1223 std::list<keyT> to_be_erased;
1225 const keyT& key=it->first;
1226 nodeT& node=it->second;
1228 if (key.
level()>n) to_be_erased.push_back(key);
1230 for (
auto& key : to_be_erased)
coeffs.erase(key);
1237 template <
typename T, std::
size_t NDIM>
1258 template <
typename T, std::
size_t NDIM>
1266 template <
typename T, std::
size_t NDIM>
1287 template <
typename T, std::
size_t NDIM>
1295 template <
typename T, std::
size_t NDIM>
1307 template <
typename T, std::
size_t NDIM>
1321 for (
size_t ii=0; ii<
NDIM; ++ii) matrices[ii]=
h[kit.key().translation()[ii]%2];
1337 template <
typename T, std::
size_t NDIM>
1355 template <
typename T, std::
size_t NDIM>
1358 std::vector<Slice> s(
NDIM,
Slice(0,kmin-1));
1361 const keyT& key = it->first;
1362 const nodeT& node = it->second;
1376 template <
typename T, std::
size_t NDIM>
1378 return coeffs.probe(key) &&
coeffs.find(key).get()->second.has_children();
1381 template <
typename T, std::
size_t NDIM>
1383 return coeffs.probe(key) && (not
coeffs.find(key).get()->second.has_children());
1387 template <
typename T, std::
size_t NDIM>
1389 for (
unsigned int i=0; i<
v.size(); ++i) {
1399 template <
typename T, std::
size_t NDIM>
1403 it->second.set_norm_tree(0.0);
1405 it->second.set_snorm(0.0);
1406 it->second.set_dnorm(0.0);
1411 template <
typename T, std::
size_t NDIM>
1415 const keyT& key = it->first;
1417 const auto found =
coeffs.find(acc,key);
1419 nodeT& node = acc->second;
1427 int ndir =
static_cast<int>(std::pow(
static_cast<double>(3),
static_cast<int>(
NDIM)));
1433 for (std::size_t
d=0;
d<
NDIM; ++
d) {
1441 keyT neigh = neighbor(key,
keyT(key.
level(),l), is_periodic);
1443 if (neigh.is_valid()) {
1444 v[i++] = this->
task(coeffs.owner(neigh), &implT::exists_and_has_children, neigh);
1450 woT::task(world.rank(), &implT::broaden_op, key,
v);
1462 template <
typename T, std::
size_t NDIM>
1467 if (fence)
world.gop.fence();
1473 template <
typename T, std::
size_t NDIM>
1484 if (it ==
coeffs.end()) {
1486 it =
coeffs.find(key).get();
1488 nodeT& node = it->second;
1498 if (key.
level() > 0)
d += s;
1515 template <
typename T, std::
size_t NDIM>
1519 if (current_state==finalstate)
return;
1544 }
else if (finalstate==compressed) {
1571 static std::atomic<bool> reported(
false);
1572 if (not reported.exchange(
true))
1573 print(
"change_tree_state:", current_state,
"->", finalstate,
1574 "must reconstruct first and therefore fences, despite fence=false");
1583 template <
typename T, std::
size_t NDIM>
1594 if (world.rank() == coeffs.owner(cdata.key0))
1596 }
else if (is_nonstandard()) {
1599 if (world.rank() == coeffs.owner(cdata.key0))
1600 woT::task(world.rank(), &implT::reconstruct_op, cdata.key0,coeffT(),
false);
1604 if (fence) world.gop.fence();
1615 template <
typename T, std::
size_t NDIM>
1632 template <
typename T, std::
size_t NDIM>
1637 template <
typename T, std::
size_t NDIM>
1643 template <
typename T, std::
size_t NDIM>
1653 template <
typename T, std::
size_t NDIM>
1662 template <
typename T, std::
size_t NDIM>
1670 template <
typename T, std::
size_t NDIM>
1676 double value =
v[i].get();
1685 template <
typename T, std::
size_t NDIM>
1694 return woT::task(world.rank(),&implT::norm_tree_op, key,
v);
1708 template <
typename T, std::
size_t NDIM>
1732 template <
typename T, std::
size_t NDIM>
1739 for (
size_t i=0; i<
v.size(); ++i)
if (
v[i].get().has_no_data())
return coeffT();
1746 const auto found =
coeffs.find(acc, key);
1758 const double error=
d.normf();
1769 acc->second.set_coeff(ss);
1782 template <
typename T, std::
size_t NDIM>
1792 double norm_tree2=0.0, dnorm_tree2=0.0;
1795 d(
child_patch(kit.key())) +=
v[i].get().first.full_tensor();
1796 norm_tree2+=
v[i].get().second.first*
v[i].get().second.first;
1797 dnorm_tree2+=
v[i].get().second.second*
v[i].get().second.second;
1806 const auto found =
coeffs.find(acc, key);
1808 MADNESS_CHECK_THROW(!acc->second.has_coeff(),
"compress_op: existing coeffs where there should be none");
1818 double snorm = ss.
normf();
1824 const bool stored_tensor_keeps_s0 = (key.
level() == 0) or nonstandard1;
1826 const double dnorm =
d.normf();
1827 if (stored_tensor_keeps_s0)
d(
cdata.s0) = s0block;
1832 double dnorm_tree=sqrt(dnorm_tree2+dnorm*dnorm);
1834 acc->second.set_snorm(snorm);
1835 acc->second.set_dnorm(dnorm);
1837 acc->second.set_dnorm_tree(dnorm_tree);
1839 acc->second.set_coeff(dd);
1844 return std::make_pair(ss,std::make_pair(
norm_tree,dnorm_tree));
1853 template <
typename T, std::
size_t NDIM>
1859 double norm_tree2=0.0, dnorm_tree2=0.0;
1861 d(
child_patch(kit.key())) +=
v[i].get().first.full_tensor();
1862 norm_tree2+=
v[i].get().second.first*
v[i].get().second.first;
1863 dnorm_tree2+=
v[i].get().second.second*
v[i].get().second.second;
1875 double dnorm=
d.normf();
1876 double snorm=s.normf();
1879 const auto found =
coeffs.find(acc, key);
1883 double dnorm_tree=sqrt(dnorm_tree2+dnorm*dnorm);
1885 acc->second.set_coeff(s);
1886 acc->second.set_dnorm(dnorm);
1887 acc->second.set_snorm(snorm);
1889 acc->second.set_dnorm_tree(dnorm_tree);
1892 return std::make_pair(s,std::make_pair(
norm_tree,dnorm_tree));
1896 template <
typename T, std::
size_t NDIM>
1909 template <
typename T, std::
size_t NDIM>
1919 if (printme) printf(
"time in consolidate_buffer %8.4f\n",end1-begin1);
1927 if (printme) printf(
"time in do_reduce_rank %8.4f\n",end1-begin1);
1933 if (printme) printf(
"time in do_change_tensor_type %8.4f\n",end1-begin1);
1939 if (printme) printf(
"time in do_truncate_NS_leafs %8.4f\n",end1-begin1);
1942 double elapsed=end-begin;
1952 template <
typename T, std::
size_t NDIM>
1961 template <
typename T, std::
size_t NDIM>
1965 "norm2sq_local() needs a tree that holds its coefficients once");
1975 template <
typename T, std::
size_t NDIM>
1977 std::size_t maxdepth = 0;
1980 std::size_t
N = (std::size_t) it->first.level();
1989 template <
typename T, std::
size_t NDIM>
1992 world.gop.max(maxdepth);
1997 template <
typename T, std::
size_t NDIM>
1999 std::size_t maxsize = 0;
2001 world.gop.max(maxsize);
2006 template <
typename T, std::
size_t NDIM>
2008 std::size_t minsize = 0;
2010 world.gop.min(minsize);
2015 template <
typename T, std::
size_t NDIM>
2017 std::size_t
sum = 0;
2024 template <
typename T, std::
size_t NDIM>
2026 std::size_t
sum = 0;
2027 for (
const auto& [key,node] :
coeffs) {
2034 template <
typename T, std::
size_t NDIM>
2042 template <
typename T, std::
size_t NDIM>
2047 const nodeT& node = it->second;
2055 template <
typename T, std::
size_t NDIM>
2058 for (
auto& [key,node] :
coeffs) {
2065 template <
typename T, std::
size_t NDIM>
2074 template <
typename T, std::
size_t NDIM>
2078 const size_t ncoeff=this->
nCoeff();
2080 const double d=
sizeof(T);
2081 const double fac=1024*1024*1024;
2089 if (norm_is_meaningful) {
2091 this->
world.gop.sum(local);
2092 this->
world.gop.fence();
2096 if (this->
world.rank()==0) {
2097 std::ostringstream oss;
2098 oss << std::setw(40) <<
name <<
" at time "
2099 << std::fixed << std::setprecision(1) << wall
2100 <<
"s: norm/tree/#coeff/size: ";
2101 if (norm_is_meaningful)
2102 oss << std::setw(7) << std::setprecision(5) <<
norm;
2104 oss << std::setw(7) <<
"n/a";
2106 <<
", " << std::setw(6) << std::setprecision(3) << double(ncoeff)*1.e-6
2107 <<
" m, " << std::setw(6) << std::setprecision(3) << double(ncoeff)/fac*
d
2114 template <
typename T, std::
size_t NDIM>
2127 const nodeT& node = it->second;
2143 if (
world.rank()==0) {
2144 print(
"configurations number of nodes");
2145 print(
" full rank ",n_full);
2146 for (
unsigned int i=0; i<n.
size(); i++) {
2147 print(
" ",i,
" ",n[i]);
2149 print(
" large rank ",n_large);
2154 for (
unsigned int i=0; i<std::min(3l,n.
size()); i++) nlog[0]+=n[i];
2155 for (
unsigned int i=3; i<std::min(10l,n.
size()); i++) nlog[1]+=n[i];
2156 for (
unsigned int i=10; i<std::min(30l,n.
size()); i++) nlog[2]+=n[i];
2157 for (
unsigned int i=30; i<std::min(100l,n.
size()); i++) nlog[3]+=n[i];
2158 for (
unsigned int i=100; i<std::min(300l,n.
size()); i++) nlog[4]+=n[i];
2159 for (
unsigned int i=300; i<std::min(1000l,n.
size()); i++) nlog[5]+=n[i];
2161 std::vector<std::string> slog={
"3",
"10",
"30",
"100",
"300",
"1000"};
2162 for (
unsigned int i=0; i<nlog.
size(); i++) {
2163 print(
" < ",slog[i],
" ",nlog[i]);
2165 print(
" large rank ",n_large);
2170 template <
typename T, std::
size_t NDIM>
2190 if constexpr (
NDIM <= 2) {
2195 if constexpr (
NDIM == 1) {
2196 const T* cp =
c.ptr();
2197 for (
int p=0;
p<
k; ++
p)
sum += cp[
p]*px[0][
p];
2200 for (
int p=0;
p<
k; ++
p) {
2201 const double a = px[0][
p];
2202 const T* cq = &
c(
p,0);
2204 for (
int q=0;
q<
k; ++
q) s2 += cq[
q]*px[1][
q];
2211 thread_local int phi_k = -1;
2213 for (std::size_t i=0; i<NDIM; ++i) phi[i] = Tensor<double>(
long(
k), 1L);
2216 for (std::size_t i=0; i<
NDIM; ++i)
2227 thread_local double cached_cell_volume = -1.0;
2228 thread_local double cached_inv_sqrt_cell_vol = 0.0;
2232 cached_inv_sqrt_cell_vol = 1.0/std::sqrt(
cell_volume);
2234 return sum * std::exp2(0.5*
NDIM*n) * cached_inv_sqrt_cell_vol;
2237 template <
typename T, std::
size_t NDIM>
2249 if (it ==
coeffs.end()) {
2251 it =
coeffs.find(key).get();
2253 nodeT& node = it->second;
2265 if (accumulate_NS and (key.
level() > 0))
d(
cdata.s0) += s;
2266 if (
d.dim(0)==2*
get_k()) {
2271 const keyT& child = kit.key();
2291 template <
typename T, std::
size_t NDIM>
2294 std::vector<long> npt(
NDIM,qx.
dim(0));
2300 template <
typename T, std::
size_t NDIM>
2303 std::vector<long> npt(
NDIM,qx.
dim(0));
2309 template <
typename T, std::
size_t NDIM>
2318 const double h = std::pow(0.5,
double(n));
2320 const int npt = qx.
dim(0);
2327 for (std::size_t i = 0; i <
NDIM; i++) {
2331 if (
f.screened(c1, c2)) {
2337 bool vectorized =
f.supports_vectorized();
2339 T* fvptr = fval.
ptr();
2341 double* x1 =
new double[npt];
2343 for (
int i=0; i<npt; ++i, ++idx) {
2348 f(xvals, fvptr, npt);
2351 else if (
NDIM == 2) {
2352 double* x1 =
new double[npt*npt];
2353 double* x2 =
new double[npt*npt];
2355 for (
int i=0; i<npt; ++i) {
2357 for (
int j=0; j<npt; ++j, ++idx) {
2364 f(xvals, fvptr, npt*npt);
2368 else if (
NDIM == 3) {
2369 double* x1 =
new double[npt*npt*npt];
2370 double* x2 =
new double[npt*npt*npt];
2371 double* x3 =
new double[npt*npt*npt];
2373 for (
int i=0; i<npt; ++i) {
2375 for (
int j=0; j<npt; ++j) {
2377 for (
int k=0;
k<npt; ++
k, ++idx) {
2386 f(xvals, fvptr, npt*npt*npt);
2391 else if (
NDIM == 4) {
2392 double* x1 =
new double[npt*npt*npt*npt];
2393 double* x2 =
new double[npt*npt*npt*npt];
2394 double* x3 =
new double[npt*npt*npt*npt];
2395 double* x4 =
new double[npt*npt*npt*npt];
2397 for (
int i=0; i<npt; ++i) {
2399 for (
int j=0; j<npt; ++j) {
2401 for (
int k=0;
k<npt; ++
k) {
2403 for (
int m=0;
m<npt; ++
m, ++idx) {
2414 f(xvals, fvptr, npt*npt*npt*npt);
2420 else if (
NDIM == 5) {
2421 double* x1 =
new double[npt*npt*npt*npt*npt];
2422 double* x2 =
new double[npt*npt*npt*npt*npt];
2423 double* x3 =
new double[npt*npt*npt*npt*npt];
2424 double* x4 =
new double[npt*npt*npt*npt*npt];
2425 double* x5 =
new double[npt*npt*npt*npt*npt];
2427 for (
int i=0; i<npt; ++i) {
2429 for (
int j=0; j<npt; ++j) {
2431 for (
int k=0;
k<npt; ++
k) {
2433 for (
int m=0;
m<npt; ++
m) {
2435 for (
int n=0; n<npt; ++n, ++idx) {
2447 Vector<double*,5> xvals {x1, x2, x3, x4, x5};
2448 f(xvals, fvptr, npt*npt*npt*npt*npt);
2455 else if (
NDIM == 6) {
2456 double* x1 =
new double[npt*npt*npt*npt*npt*npt];
2457 double* x2 =
new double[npt*npt*npt*npt*npt*npt];
2458 double* x3 =
new double[npt*npt*npt*npt*npt*npt];
2459 double* x4 =
new double[npt*npt*npt*npt*npt*npt];
2460 double* x5 =
new double[npt*npt*npt*npt*npt*npt];
2461 double* x6 =
new double[npt*npt*npt*npt*npt*npt];
2463 for (
int i=0; i<npt; ++i) {
2464 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2465 for (
int j=0; j<npt; ++j) {
2466 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2467 for (
int k=0;
k<npt; ++
k) {
2468 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2469 for (
int m=0;
m<npt; ++
m) {
2470 c[3] = cell(3,0) +
h*cell_width[3]*(l[3] + qx(
m));
2471 for (
int n=0; n<npt; ++n) {
2472 c[4] = cell(4,0) +
h*cell_width[4]*(l[4] + qx(n));
2473 for (
int p=0;
p<npt; ++
p, ++idx) {
2474 c[5] = cell(5,0) +
h*cell_width[5]*(l[5] + qx(
p));
2487 Vector<double*,6> xvals {x1, x2, x3, x4, x5, x6};
2488 f(xvals, fvptr, npt*npt*npt*npt*npt*npt);
2506 for (
int i=0; i<npt; ++i) {
2507 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2512 else if (
NDIM == 2) {
2513 for (
int i=0; i<npt; ++i) {
2514 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2515 for (
int j=0; j<npt; ++j) {
2516 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2522 else if (
NDIM == 3) {
2523 for (
int i=0; i<npt; ++i) {
2524 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2525 for (
int j=0; j<npt; ++j) {
2526 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2527 for (
int k=0;
k<npt; ++
k) {
2528 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2535 else if (
NDIM == 4) {
2536 for (
int i=0; i<npt; ++i) {
2537 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2538 for (
int j=0; j<npt; ++j) {
2539 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2540 for (
int k=0;
k<npt; ++
k) {
2541 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2542 for (
int m=0;
m<npt; ++
m) {
2543 c[3] = cell(3,0) +
h*cell_width[3]*(l[3] + qx(
m));
2544 fval(i,j,
k,
m) =
f(
c);
2551 else if (
NDIM == 5) {
2552 for (
int i=0; i<npt; ++i) {
2553 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2554 for (
int j=0; j<npt; ++j) {
2555 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2556 for (
int k=0;
k<npt; ++
k) {
2557 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2558 for (
int m=0;
m<npt; ++
m) {
2559 c[3] = cell(3,0) +
h*cell_width[3]*(l[3] + qx(
m));
2560 for (
int n=0; n<npt; ++n) {
2561 c[4] = cell(4,0) +
h*cell_width[4]*(l[4] + qx(n));
2562 fval(i,j,
k,
m,n) =
f(
c);
2570 else if (
NDIM == 6) {
2571 for (
int i=0; i<npt; ++i) {
2572 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2573 for (
int j=0; j<npt; ++j) {
2574 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2575 for (
int k=0;
k<npt; ++
k) {
2576 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2577 for (
int m=0;
m<npt; ++
m) {
2578 c[3] = cell(3,0) +
h*cell_width[3]*(l[3] + qx(
m));
2579 for (
int n=0; n<npt; ++n) {
2580 c[4] = cell(4,0) +
h*cell_width[4]*(l[4] + qx(n));
2581 for (
int p=0;
p<npt; ++
p) {
2582 c[5] = cell(5,0) +
h*cell_width[5]*(l[5] + qx(
p));
2583 fval(i,j,
k,
m,n,
p) =
f(
c);
2598 template <
typename T, std::
size_t NDIM>
2604 template <
typename T, std::
size_t NDIM>
2616 template <
typename T, std::
size_t NDIM>
2624 std::vector<Vector<double,NDIM> > newspecialpts;
2627 const auto bperiodic =
bc.is_periodic();
2628 for (
unsigned int i = 0; i < specialpts.size(); ++i) {
2633 newspecialpts.push_back(specialpts[i]);
2636 newspecialpts.push_back(specialpts[i]);
2650 const keyT& child = it.key();
2665 const keyT& child = it.key();
2685 const keyT& child = it.key();
2697 template <
typename T, std::
size_t NDIM>
2699 std::vector<long> v0(
NDIM,0
L);
2700 std::vector<long> v1(
NDIM,1L);
2707 nodeT& node = it->second;
2719 Level n = it->first.level();
2720 nodeT& node = it->second;
2735 if (fence)
world.gop.fence();
2738 template <
typename T, std::
size_t NDIM>
2742 if (
coeffs.is_local(key)) {
2769 template <
typename T, std::
size_t NDIM>
2773 if (it ==
coeffs.end()) {
2778 it =
coeffs.find(key).get();
2780 nodeT& node = it->second;
2805 template <
typename T, std::
size_t NDIM>
2809 for (
int i=0; i<(1<<
NDIM); ++i)
if (
v[i].get())
return true;
2817 if (key.
level() > 1) {
2833 template <
typename T, std::
size_t NDIM>
2837 if (
world.rank() == 0) os.flush();
2842 template <
typename T, std::
size_t NDIM>
2845 if (it ==
coeffs.end()) {
2847 for (
int i=0; i<key.
level(); ++i) os <<
" ";
2848 os << key <<
" missing --> " <<
coeffs.owner(key) <<
"\n";
2851 const nodeT& node = it->second;
2852 for (
int i=0; i<key.
level(); ++i) os <<
" ";
2853 os << key <<
" " << node <<
" --> " <<
coeffs.owner(key) <<
"\n";
2862 template <
typename T, std::
size_t NDIM>
2864 std::multimap<Level, std::tuple<tranT, std::string>>
data;
2867 if (
world.rank() == 0) {
2868 for (
Level level = 0; level != maxlevel; ++level) {
2869 if (
data.count(level) == 0)
2874 os <<
"\"" << level <<
"\":{";
2875 os <<
"\"level\": " << level <<
",";
2876 os <<
"\"nodes\":{";
2878 for (
auto it =
range.first; it !=
range.second; ++it) {
2879 os <<
"\"" << std::get<0>(it->second) <<
"\":"
2880 << std::get<1>(it->second);
2881 if (std::next(it) !=
range.second)
2893 template <
typename T, std::
size_t NDIM>
2896 if (it ==
coeffs.end()) {
2900 const nodeT& node = it->second;
2901 std::ostringstream oss;
2904 oss <<
",\"owner\": " <<
coeffs.owner(key) <<
"}";
2905 auto node_json_str = oss.str();
2915 template <
typename T, std::
size_t NDIM>
2920 if (
world.rank() == 0) os.flush();
2924 template <
typename T, std::
size_t NDIM>
2930 for (int64_t j = 0; j <= key.
level()-1; ++j) {
2931 result += (1 << j*
NDIM);
2939 if (it !=
coeffs.end()) {
2940 const nodeT& node = it->second;
2943 os << uniqhash::value(key) <<
" -> " << uniqhash::value(kit.key()) <<
"\n";
2950 template <
typename T, std::
size_t NDIM>
2957 if (
functor->provides_coeff())
return functor->coeff(key).full_tensor_copy();
2971 template <
typename T, std::
size_t NDIM>
2982 template <
typename T, std::
size_t NDIM>
2987 while (
coeffs.is_local(curr)) {
2988 if (
coeffs.probe(curr)) {
2989 const nodeT& node =
coeffs.find(curr).get()->second;
2993 result.
set(std::pair<keyT,coeffT>(curr,node.
coeff()));
2997 result.
set(std::pair<keyT,coeffT>(curr,
coeffT()));
3009 template <
typename T, std::
size_t NDIM>
3014 const nodeT& node =
coeffs.find(key).get()->second;
3017 result.
set(std::pair<keyT,coeffT>(key,node.
coeff()));
3031 template <
typename T, std::
size_t NDIM>
3053 nodeT& node = it->second;
3059 for (std::size_t i=0; i<
NDIM; ++i) {
3060 double xi = x[i]*2.0;
3062 if (li == 2) li = 1;
3074 template <
typename T, std::
size_t NDIM>
3081 while (key.
level() <= maxlevel) {
3085 if (it !=
coeffs.end()) {
3086 nodeT& node = it->second;
3092 for (std::size_t i=0; i<
NDIM; ++i) {
3093 double xi = x[i]*2.0;
3095 if (li == 2) li = 1;
3101 return std::pair<bool,T>(
false,0.0);
3104 template <
typename T, std::
size_t NDIM>
3107 std::size_t npt,
Level maxlevel,
3108 std::pair<bool,T>* results) {
3124 bool have_cache =
false;
3128 for (std::size_t ip=0; ip<npt; ++ip) {
3129 results[ip] = std::pair<bool,T>(
false, T(0));
3134 for (std::size_t i=0; i<
NDIM; ++i) l[i] = 0;
3136 for (
Level nn=0; nn<nl; ++nn) {
3137 for (std::size_t i=0; i<
NDIM; ++i) {
3138 double xi = x[i]*2.0;
3140 if (li == 2) li = 1;
3147 for (std::size_t i=0; i<
NDIM; ++i)
same =
same && (l[i] == lc[i]);
3149 results[ip] = std::pair<bool,T>(
true,
eval_cube(nl, x, cached_c));
3159 while (key.
level() <= maxlevel) {
3163 if (it !=
coeffs.end()) {
3164 nodeT& node = it->second;
3169 results[ip] = std::pair<bool,T>(
true,
3175 for (std::size_t i=0; i<
NDIM; ++i) {
3176 double xi = x[i]*2.0;
3178 if (li == 2) li = 1;
3187 template <
typename T, std::
size_t NDIM>
3188 std::vector<std::pair<bool,T>>
3190 std::vector<std::pair<bool,T>> results(xin.size(), std::pair<bool,T>(
false,T(0)));
3195 template <
typename T, std::
size_t NDIM>
3217 nodeT& node = it->second;
3223 for (std::size_t i=0; i<
NDIM; ++i) {
3224 double xi = x[i]*2.0;
3226 if (li == 2) li = 1;
3237 template <
typename T, std::
size_t NDIM>
3259 nodeT& node = it->second;
3265 for (std::size_t i=0; i<
NDIM; ++i) {
3266 double xi = x[i]*2.0;
3268 if (li == 2) li = 1;
3280 template <
typename T, std::
size_t NDIM>
3291 template <
typename T, std::
size_t NDIM>
3297 sfull(
cdata.sh)-=shalf;
3301 template <
typename T, std::
size_t NDIM>
3307 if (t.
rank()==0)
return;
3309 for (
long i=0; i<t.
rank(); ++i) {
3320 template <
typename A,
typename B>
3327 template <
typename T, std::
size_t NDIM>
3345 template <
typename T, std::
size_t NDIM>
3353 template <
typename T, std::
size_t NDIM>
3359 template <
typename T, std::
size_t NDIM>
3367template <
typename T, std::
size_t NDIM>
3373 template <
typename T, std::
size_t NDIM>
3379 template <
typename T, std::
size_t NDIM>
3384 template <
typename T, std::
size_t NDIM>
3389 template <
typename T, std::
size_t NDIM>
3398 for (
int i=0; i<
k; ++i) phi(i,
mu) =
p[i];
3403 template <
typename T, std::
size_t NDIM>
3421 template <
typename T, std::
size_t NDIM>
3425 "trace_local() needs a tree that holds its coefficients once");
3426 std::vector<long> v0(
NDIM,0);
3431 if (it !=
coeffs.end()) {
3432 const nodeT& node = it->second;
3442 const keyT& key = it->first;
3443 const nodeT& node = it->second;
3464 }
else if (l >= two2n) {
3468 }
while (l >= two2n);
3477 return l >= 0 && l < two2n;
3483 template <
typename T, std::
size_t NDIM>
3498 template <
typename T, std::
size_t NDIM>
3512 template <
typename T, std::
size_t NDIM>
3516 typedef std::pair< Key<NDIM>,
coeffT > argT;
3526 template <
typename T, std::
size_t NDIM>
3528 bool nonstandard1,
bool keepleaves,
bool redundant1) {
3529 if (!
coeffs.probe(key))
print(
"missing node",key);
3553 if (key.
level()==0) {
3565 coeffT result(node.
coeff());
3566 coeffT sdcoeff(cdata.v2k,this->get_tensor_type());
3567 sdcoeff(cdata.s0)+=node.
coeff();
3578 Future<coeffT > result(node.
coeff());
3593 node.
set_snorm(keepleaves ? snorm : 0.0);
3601 template <
typename T, std::
size_t NDIM>
3604 const coordT& plotlo,
const coordT& plothi,
const std::vector<long>& npt,
3605 bool eval_refine)
const {
3610 for (std::size_t i=0; i<
NDIM; ++i) {
3612 h[i] = (plothi[i]-plotlo[i])/(npt[i]-1);
3622 const double twon =
pow(2.0,
double(n));
3623 const tensorT& coeff =
coeffs.find(key).get()->second.coeff().full_tensor();
3629 double fac =
pow(0.5,
double(key.
level()));
3631 for (std::size_t
d=0;
d<
NDIM; ++
d) {
3634 boxhi[
d] = boxlo[
d]+fac;
3636 if (boxlo[
d] > plothi[
d] || boxhi[
d] < plotlo[
d]) {
3638 npttotal = boxnpt[
d] = 0;
3642 else if (npt[
d] == 1) {
3644 boxlo[
d] = boxhi[
d] = plotlo[
d];
3649 boxlo[
d] = std::max(boxlo[
d],plotlo[
d]);
3650 boxhi[
d] = std::min(boxhi[
d],plothi[
d]);
3653 double xlo = long((boxlo[
d]-plotlo[
d])/
h[
d])*
h[
d] + plotlo[
d];
3654 if (xlo < boxlo[
d]) xlo +=
h[
d];
3656 double xhi = long((boxhi[
d]-plotlo[
d])/
h[
d])*
h[
d] + plotlo[
d];
3657 if (xhi > boxhi[
d]) xhi -=
h[
d];
3660 boxnpt[
d] = long(round((boxhi[
d] - boxlo[
d])/
h[
d])) + 1;
3662 npttotal *= boxnpt[
d];
3667 for (std::size_t
d=0;
d<
NDIM; ++
d) {
3668 double xd = boxlo[
d] + it[
d]*
h[
d];
3669 x[
d] = twon*xd - l[
d];
3672 ind[
d] = long(round((xd-plotlo[
d])/
h[
d]));
3683 T tmp = eval_cube(n, x, coeff);
3693 template <
typename T, std::
size_t NDIM>
3696 const std::vector<long>& npt,
3697 const bool eval_refine)
const {
3704 const keyT& key = it->first;
3705 const nodeT& node = it->second;
3714 world.taskq.fence();
3722 fprintf(
f,
"%.6e\n",t);
3726 fprintf(
f,
"%.6e %.6e\n", t.real(), t.imag());
3729 template <
typename T, std::
size_t NDIM>
3733 const std::vector<long>& npt,
3743 "plotdx: plot cell must be an (NDIM x 2) [lo,hi] tensor "
3744 "(got an empty or ill-shaped cell)");
3745 const char* element[6] = {
"lines",
"quads",
"cubes",
"cubes4D",
"cubes5D",
"cubes6D"};
3750 if (world.
rank() == 0) {
3754 fprintf(
f,
"object 1 class gridpositions counts ");
3755 for (std::size_t
d=0;
d<
NDIM; ++
d) fprintf(
f,
" %ld",npt[
d]);
3758 fprintf(
f,
"origin ");
3759 for (std::size_t
d=0;
d<
NDIM; ++
d) fprintf(
f,
" %.6e",
cell(
d,0));
3762 for (std::size_t
d=0;
d<
NDIM; ++
d) {
3763 fprintf(
f,
"delta ");
3764 for (std::size_t
c=0;
c<
d; ++
c) fprintf(
f,
" 0");
3767 fprintf(
f,
" %.6e",
h);
3768 for (std::size_t
c=
d+1;
c<
NDIM; ++
c) fprintf(
f,
" 0");
3773 fprintf(
f,
"object 2 class gridconnections counts ");
3774 for (std::size_t
d=0;
d<
NDIM; ++
d) fprintf(
f,
" %ld",npt[
d]);
3776 fprintf(
f,
"attribute \"element type\" string \"%s\"\n", element[
NDIM-1]);
3777 fprintf(
f,
"attribute \"ref\" string \"positions\"\n");
3781 for (std::size_t
d=0;
d<
NDIM; ++
d) npoint *= npt[
d];
3782 const char* iscomplex =
"";
3784 const char* isbinary =
"";
3785 if (binary) isbinary =
"binary";
3786 fprintf(
f,
"object 3 class array type double %s rank 0 items %d %s data follows\n",
3787 iscomplex, npoint, isbinary);
3793 if (world.
rank() == 0) {
3797 fwrite((
void *) r.
ptr(),
sizeof(T), r.
size(),
f);
3808 fprintf(
f,
"object \"%s\" class field\n",
filename);
3809 fprintf(
f,
"component \"positions\" value 1\n");
3810 fprintf(
f,
"component \"connections\" value 2\n");
3811 fprintf(
f,
"component \"data\" value 3\n");
3812 fprintf(
f,
"\nend\n");
3818 template <std::
size_t NDIM>
3839 template <std::
size_t NDIM>
3842 return std::make_shared<LevelPmap< Key<NDIM> >>(world);
3846 template <std::
size_t NDIM>
3853 template <std::
size_t NDIM>
3855 std::cout <<
"Function Defaults:" << std::endl;
3856 std::cout <<
" Dimension " <<
": " <<
NDIM << std::endl;
3857 std::cout <<
" k" <<
": " <<
k << std::endl;
3858 std::cout <<
" thresh" <<
": " <<
thresh << std::endl;
3859 std::cout <<
" initial_level" <<
": " <<
initial_level << std::endl;
3860 std::cout <<
" special_level" <<
": " <<
special_level << std::endl;
3862 std::cout <<
" truncate_mode" <<
": " <<
truncate_mode << std::endl;
3863 std::cout <<
" refine" <<
": " <<
refine << std::endl;
3864 std::cout <<
" autorefine" <<
": " <<
autorefine << std::endl;
3865 std::cout <<
" debug" <<
": " <<
debug << std::endl;
3867 std::cout <<
" apply_randomize" <<
": " <<
apply_randomize << std::endl;
3869 std::cout <<
" bc" <<
": " <<
get_bc() << std::endl;
3870 std::cout <<
" tt" <<
": " <<
tt << std::endl;
3871 std::cout <<
" cell" <<
": " <<
cell << std::endl;
3874 template <
typename T, std::
size_t NDIM>
3875 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};
double w(double t, double eps)
Definition DKops.h:22
double q(double t)
Definition DKops.h:18
std::complex< double > double_complex
Definition cfft.h:14
Definition test_ar.cc:118
Definition test_ar.cc:141
long dim(int i) const
Returns the size of dimension i.
Definition basetensor.h:147
long size() const
Returns the number of elements in the tensor.
Definition basetensor.h:138
This class is used to specify boundary conditions for all operators.
Definition bc.h:72
a class to track where relevant (parent) coeffs are
Definition funcimpl.h:887
Tri-diagonal operator traversing tree primarily for derivative operator.
Definition derivative.h:73
ElementaryInterface (formerly FunctorInterfaceWrapper) interfaces a c-function.
Definition function_interface.h:275
FunctionCommonData holds all Function data common for given k.
Definition function_common_data.h:52
Tensor< double > g1
The separate blocks of twoscale coefficients.
Definition function_common_data.h:105
Tensor< double > quad_phit
transpose of quad_phi
Definition function_common_data.h:102
Tensor< double > quad_phi
quad_phi(i,j) = at x[i] value of phi[j]
Definition function_common_data.h:101
static const FunctionCommonData< T, NDIM > * data[MAXK]
Definition function_common_data.h:54
Tensor< double > h0T
Definition function_common_data.h:106
Tensor< double > quad_phiw
quad_phiw(i,j) = at x[i] value of w[i]*phi[j]
Definition function_common_data.h:103
int npt
no. of quadrature points
Definition function_common_data.h:89
Tensor< double > g0
Definition function_common_data.h:105
Tensor< double > g1T
The separate blocks of twoscale coefficients.
Definition function_common_data.h:106
Tensor< double > hgT
The full twoscale coeff (2k,2k) and transpose.
Definition function_common_data.h:107
Tensor< double > quad_w
quadrature weights
Definition function_common_data.h:100
Tensor< double > h0
Definition function_common_data.h:105
int k
order of the wavelet
Definition function_common_data.h:88
static const FunctionCommonData< T, NDIM > & get(int k)
Definition function_common_data.h:111
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:93
Tensor< double > hg
Definition function_common_data.h:107
Tensor< double > hgsonly
hg[0:k,:]
Definition function_common_data.h:108
Tensor< double > quad_x
quadrature points
Definition function_common_data.h:99
Tensor< double > h1T
Definition function_common_data.h:106
Tensor< double > g0T
Definition function_common_data.h:106
Tensor< double > h1
Definition function_common_data.h:105
void _init_twoscale()
Private. Initialize the twoscale coefficients.
Definition mraimpl.h:72
static Tensor< double > make_default_cell_width()
Definition funcdefaults.h:138
static bool get_project_randomize()
Gets the random load balancing for projection flag.
Definition funcdefaults.h:305
static std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > make_default_pmap(World &world)
Makes a default process map for the given world.
Definition mraimpl.h:3840
static bool truncate_on_project
If true initial projection inserts at n-1 not n.
Definition funcdefaults.h:115
static bool apply_randomize
If true use randomization for load balancing in apply integral operator.
Definition funcdefaults.h:116
static double cell_volume
Volume of simulation cell.
Definition funcdefaults.h:122
static const double & get_thresh()
Returns the default threshold.
Definition funcdefaults.h:183
static int k
Wavelet order.
Definition funcdefaults.h:106
static double get_cell_volume()
Returns the volume of the user cell.
Definition funcdefaults.h:410
static bool get_debug()
Gets the default debug flag, which gates verbose MRA diagnostics.
Definition funcdefaults.h:272
static int truncate_mode
Truncation method.
Definition funcdefaults.h:111
static void set_default_pmap(World &world)
Definition mraimpl.h:3847
static int pmap_nproc
Number of processes assumed by pmap, -1 indicates uninitialized pmap.
Definition funcdefaults.h:127
static double thresh
Truncation threshold.
Definition funcdefaults.h:107
static std::optional< BoundaryConditions< NDIM > > bc
Default boundary conditions, not initialized by default and must be set explicitly before use.
Definition funcdefaults.h:118
static Tensor< double > rcell_width
Reciprocal of width.
Definition funcdefaults.h:121
static bool debug
Controls output of debug info.
Definition funcdefaults.h:114
static int special_level
Minimum level for fine scale projection of special boxes.
Definition funcdefaults.h:109
static double cell_min_width
Size of smallest dimension.
Definition funcdefaults.h:123
static TensorType get_tensor_type()
Returns the default tensor type.
Definition funcdefaults.h:329
static const Tensor< double > & get_cell_width()
Returns the width of each user cell dimension.
Definition funcdefaults.h:390
static double get_cell_geometric_mean_width()
Returns the geometric mean width of the user cell, volume^(1/NDIM).
Definition funcdefaults.h:400
static double cell_geometric_mean_width
volume^(1/NDIM), the mean dimension
Definition funcdefaults.h:124
static std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > pmap
Default mapping of keys to processes.
Definition funcdefaults.h:126
static const BoundaryConditions< NDIM > & get_bc()
Returns the default boundary conditions.
Definition funcdefaults.h:315
static int initial_level
Initial level for fine scale projection.
Definition funcdefaults.h:108
static bool autorefine
Whether to autorefine in multiplication, etc.
Definition funcdefaults.h:113
static Tensor< double > make_default_cell()
Definition funcdefaults.h:129
static void print()
Definition mraimpl.h:3854
static double get_cell_min_width()
Returns the minimum width of any user cell dimension.
Definition funcdefaults.h:405
static void recompute_cell_info()
Definition funcdefaults.h:147
static bool project_randomize
If true use randomization for load balancing in project/refine.
Definition funcdefaults.h:117
static Tensor< double > cell
cell[NDIM][2] Simulation cell, cell(0,0)=xlo, cell(0,1)=xhi, ...
Definition funcdefaults.h:119
static const Tensor< double > & get_cell()
Gets the user cell for the simulation.
Definition funcdefaults.h:352
static void set_defaults(World &world)
Definition mraimpl.h:3819
static int max_refine_level
Level at which to stop refinement.
Definition funcdefaults.h:110
static TensorType tt
structure of the tensor in FunctionNode
Definition funcdefaults.h:125
static Tensor< double > cell_width
Width of simulation cell in each dimension.
Definition funcdefaults.h:120
static bool refine
Whether to refine new functions.
Definition funcdefaults.h:112
Abstract base class interface required for functors used as input to Functions.
Definition function_interface.h:68
Definition funcimpl.h:6300
bool is_nonstandard() const
Definition mraimpl.h:275
T eval_cube(Level n, coordT &x, const tensorT &c) const
Definition mraimpl.h:2171
Timer timer_target_driven
Definition funcimpl.h:1156
void do_print_tree_graphviz(const keyT &key, std::ostream &os, Level maxlevel) const
Functor for the do_print_tree method (using GraphViz).
Definition mraimpl.h:2925
void change_tensor_type1(const TensorArgs &targs, bool fence)
change the tensor type of the coefficients in the FunctionNode
Definition mraimpl.h:1206
int initial_level
Initial level for refinement.
Definition funcimpl.h:1072
int max_refine_level
Do not refine below this level.
Definition funcimpl.h:1076
int special_level
Minimium level for refinement on special points.
Definition funcimpl.h:1073
compressT compress_op(const keyT &key, const std::vector< Future< compressT > > &v, bool nonstandard)
calculate the wavelet coefficients using the sum coefficients of all child nodes
Definition mraimpl.h:1783
WorldContainer< keyT, nodeT > dcT
Type of container holding the coefficients.
Definition funcimpl.h:1055
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:3196
void scale_inplace(const T q, bool fence)
In-place scale by a constant.
Definition mraimpl.h:3368
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:225
World & world
Definition funcimpl.h:1062
bool is_redundant() const
Returns true if the function is redundant.
Definition mraimpl.h:264
FunctionNode< T, NDIM > nodeT
Type of node.
Definition funcimpl.h:1053
std::size_t nCoeff_local() const
Returns the number of coefficients in the function for this MPI rank.
Definition mraimpl.h:2056
void print_size(const std::string name) const
print tree size and size
Definition mraimpl.h:2075
void print_info() const
Prints summary of data distribution.
Definition mraimpl.h:934
void abs_inplace(bool fence)
Definition mraimpl.h:3380
void print_timer() const
Definition mraimpl.h:369
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:3238
const FunctionCommonData< T, NDIM > & cdata
Definition funcimpl.h:1082
void do_print_grid(const std::string filename, const std::vector< keyT > &keys) const
print the grid in xyz format
Definition mraimpl.h:596
bool has_coefficients_on_leaves_only() const
Returns true if only the leaves of this tree carry its coefficients.
Definition mraimpl.h:290
Future< compressT > compress_spawn(const keyT &key, bool nonstandard, bool keepleaves, bool redundant1)
Definition mraimpl.h:3527
std::size_t nCoeff() const
Returns the number of coefficients in the function ... collective global sum.
Definition mraimpl.h:2066
keyT neighbor_in_volume(const keyT &key, const keyT &disp) const
Returns key of general neighbor that resides in-volume.
Definition mraimpl.h:3499
void compress(const TreeState newstate, bool fence)
Definition mraimpl.h:1616
Future< bool > truncate_spawn(const keyT &key, double tol)
Returns true if after truncation this node has coefficients.
Definition mraimpl.h:2770
Future< double > norm_tree_spawn(const keyT &key)
Definition mraimpl.h:1686
std::vector< keyT > local_leaf_keys() const
return the keys of the local leaf boxes
Definition mraimpl.h:570
void do_print_tree(const keyT &key, std::ostream &os, Level maxlevel) const
Functor for the do_print_tree method.
Definition mraimpl.h:2843
void unset_functor()
Definition mraimpl.h:324
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:511
std::pair< Key< NDIM >, ShallowNode< T, NDIM > > find_datum(keyT key) const
return the a std::pair<key, node>, which MUST exist
Definition mraimpl.h:1072
void set_functor(const std::shared_ptr< FunctionFunctorInterface< T, NDIM > > functor1)
Definition mraimpl.h:305
bool verify_tree_state_local() const
check that the tree state and the coeffs are consistent
Definition mraimpl.h:171
const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > & get_pmap() const
Definition mraimpl.h:209
Tensor< Q > fcube_for_mul(const keyT &child, const keyT &parent, const Tensor< Q > &coeff) const
Compute the function values for multiplication.
Definition funcimpl.h:2151
Timer timer_filter
Definition funcimpl.h:1154
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:2983
double get_thresh() const
Definition mraimpl.h:340
void trickle_down(bool fence)
sum all the contributions from all scales after applying an operator in mod-NS form
Definition mraimpl.h:1463
bool autorefine
If true, autorefine where appropriate.
Definition funcimpl.h:1078
void set_autorefine(bool value)
Definition mraimpl.h:349
tensorT filter(const tensorT &s) const
Transform sum coefficients at level n to sums+differences at level n-1.
Definition mraimpl.h:1259
void chop_at_level(const int n, const bool fence=true)
remove all nodes with level higher than n
Definition mraimpl.h:1222
TreeState tree_state
Definition funcimpl.h:1085
void print_tree_json(std::ostream &os=std::cout, Level maxlevel=10000) const
Definition mraimpl.h:2863
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:808
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:1164
bool is_compressed() const
Returns true if the function is compressed.
Definition mraimpl.h:252
Vector< double, NDIM > coordT
Type of vector holding coordinates.
Definition funcimpl.h:1057
Tensor< T > tensorT
Type of tensor for anything but to hold coeffs.
Definition funcimpl.h:1050
void mirror(const implT &f, const std::vector< long > &mirror, bool fence)
mirror the dimensions of f according to map, result on this
Definition mraimpl.h:1173
void print_stats() const
print the number of configurations per node
Definition mraimpl.h:2115
void broaden(const array_of_bools< NDIM > &is_periodic, bool fence)
Definition mraimpl.h:1412
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:1733
void refine_op(const opT &op, const keyT &key)
Definition funcimpl.h:5132
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:2605
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:1025
std::vector< Slice > child_patch(const keyT &child) const
Returns patch referring to coeffs of child in parent box.
Definition mraimpl.h:797
void print_tree_graphviz(std::ostream &os=std::cout, Level maxlevel=10000) const
Definition mraimpl.h:2916
void set_tree_state(const TreeState &state)
Definition funcimpl.h:1539
std::size_t min_nodes() const
Returns the min number of nodes on a processor.
Definition mraimpl.h:2007
std::shared_ptr< FunctionFunctorInterface< T, NDIM > > functor
Definition funcimpl.h:1084
Timer timer_compress_svd
Definition funcimpl.h:1155
void make_redundant(const bool fence)
convert this to redundant, i.e. have sum coefficients on all levels
Definition mraimpl.h:1644
std::size_t max_nodes() const
Returns the max number of nodes on a processor.
Definition mraimpl.h:1998
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:1338
TensorArgs targs
type of tensor to be used in the FunctionNodes
Definition funcimpl.h:1080
void flo_unary_op_node_inplace(const opT &op, bool fence)
Definition funcimpl.h:2416
std::size_t size_local() const
Returns the number of coefficients in the function for each rank.
Definition mraimpl.h:2025
GenTensor< Q > values2coeffs(const keyT &key, const GenTensor< Q > &values) const
Definition funcimpl.h:2130
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:3602
T trace_local() const
Returns int(f(x),x) in local volume.
Definition mraimpl.h:3422
void print_grid(const std::string filename) const
Definition mraimpl.h:554
bool get_autorefine() const
Definition mraimpl.h:346
int k
Wavelet order.
Definition funcimpl.h:1070
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:3390
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:3514
TensorType get_tensor_type() const
Definition mraimpl.h:331
void remove_leaf_coefficients(const bool fence)
Definition mraimpl.h:1638
void insert_zero_down_to_initial_level(const keyT &key)
Initialize nodes to zero function at initial_level of refinement.
Definition mraimpl.h:2739
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:1036
void unary_op_node_inplace(const opT &op, bool fence)
Definition funcimpl.h:2325
void do_print_tree_json(const keyT &key, std::multimap< Level, std::tuple< tranT, std::string > > &data, Level maxlevel) const
Functor for the do_print_tree_json method.
Definition mraimpl.h:2894
void finalize_sum()
after summing up we need to do some cleanup;
Definition mraimpl.h:1953
dcT coeffs
The coefficients.
Definition funcimpl.h:1087
bool exists_and_is_leaf(const keyT &key) const
Definition mraimpl.h:1382
void verify_tree() const
Verify tree is properly constructed ... global synchronization involved.
Definition mraimpl.h:113
void set_tensor_args(const TensorArgs &t)
Definition mraimpl.h:337
Range< typename dcT::const_iterator > rangeT
Definition funcimpl.h:6441
std::size_t real_size() const
Returns the number of coefficients in the function ... collective global sum.
Definition mraimpl.h:2043
bool exists_and_has_children(const keyT &key) const
Definition mraimpl.h:1377
void sum_down_spawn(const keyT &key, const coeffT &s)
is this the same as trickle_down() ?
Definition mraimpl.h:977
long box_interior[1000]
Definition funcimpl.h:3553
keyT neighbor(const keyT &key, const keyT &disp, const array_of_bools< NDIM > &is_periodic) const
Returns key of general neighbor enforcing BC.
Definition mraimpl.h:3484
rangeT range(coeffs.begin(), coeffs.end())
void norm_tree(bool fence)
compute for each FunctionNode the norm of the function inside that node
Definition mraimpl.h:1663
friend class FunctionImpl
Definition funcimpl.h:1060
const Tensor< double > cell
the size of the root cell in each dimension, unchangeable
Definition funcimpl.h:1075
bool has_leaves() const
Definition mraimpl.h:300
bool verify_parents_and_children() const
check that parents and children are consistent
Definition mraimpl.h:121
void reconstruct_op(const keyT &key, const coeffT &s, const bool accumulate_NS=true)
Definition mraimpl.h:2238
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:3405
void undo_redundant(const bool fence)
convert this from redundant to standard reconstructed form
Definition mraimpl.h:1654
GenTensor< T > coeffT
Type of tensor used to hold coeffs.
Definition funcimpl.h:1054
const keyT & key0() const
Returns cdata.key0.
Definition mraimpl.h:406
double finalize_apply()
after apply we need to do some cleanup;
Definition mraimpl.h:1910
bool leaves_only
Definition funcimpl.h:6446
const dcT & get_coeffs() const
Definition mraimpl.h:355
compressT make_redundant_op(const keyT &key, const std::vector< Future< compressT > > &v)
similar to compress_op, but insert only the sum coefficients in the tree
Definition mraimpl.h:1855
double norm2sq_local() const
Returns the square of the local norm ... no comms.
Definition mraimpl.h:1962
const FunctionCommonData< T, NDIM > & get_cdata() const
Definition mraimpl.h:361
void sum_down(bool fence)
After 1d push operator must sum coeffs down the tree to restore correct scaling function coefficients...
Definition mraimpl.h:1017
bool noautorefine(const keyT &key, const tensorT &t) const
Always returns false (for when autorefine is not wanted).
Definition mraimpl.h:960
double truncate_tol(double tol, const keyT &key) const
Returns the truncation threshold according to truncate_method.
Definition mraimpl.h:722
bool autorefine_square_test(const keyT &key, const nodeT &t) const
Returns true if this block of coeffs needs autorefining.
Definition mraimpl.h:966
void erase(const Level &max_level)
truncate tree at a certain level
Definition mraimpl.h:840
std::pair< coeffT, std::pair< double, double > > compressT
s coefficients plus the (snorm_tree, dnorm_tree) pair propagated up by compress
Definition funcimpl.h:5219
void reconstruct(bool fence)
Definition mraimpl.h:1584
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:3897
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:1120
static void tnorm(const tensorT &t, double *lo, double *hi)
Computes norm of low/high-order polyn. coeffs for autorefinement test.
Definition mraimpl.h:3281
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:3076
std::size_t max_depth() const
Returns the maximum depth of the tree ... collective ... global sum/broadcast.
Definition mraimpl.h:1990
std::size_t size() const
Returns the number of coefficients in the function ... collective global sum.
Definition mraimpl.h:2035
void reduce_rank(const double thresh, bool fence)
reduce the rank of the coefficients tensors
Definition mraimpl.h:1214
TreeState get_tree_state() const
Definition funcimpl.h:1543
std::shared_ptr< FunctionFunctorInterface< T, NDIM > > get_functor()
Definition mraimpl.h:312
tensorT unfilter(const tensorT &s) const
Transform sums+differences at level n to sum coefficients at level n+1.
Definition mraimpl.h:1288
Tensor< T > eval_plot_cube(const coordT &plotlo, const coordT &plothi, const std::vector< long > &npt, const bool eval_refine=false) const
Definition mraimpl.h:3694
void change_tree_state(const TreeState finalstate, bool fence=true)
change the tree state of this function, might or might not respect fence!
Definition mraimpl.h:1516
Future< coeffT > truncate_reconstructed_spawn(const keyT &key, const double tol)
truncate using a tree in reconstructed form
Definition mraimpl.h:1709
GenTensor< Q > coeffs2values(const keyT &key, const GenTensor< Q > &coeff) const
Definition funcimpl.h:1997
void map_and_mirror(const implT &f, const std::vector< long > &map, const std::vector< long > &mirror, bool fence)
map and mirror the translation index and the coefficients, result on this
Definition mraimpl.h:1183
Timer timer_lr_result
Definition funcimpl.h:1153
void truncate(double tol, bool fence)
Truncate according to the threshold with optional global fence.
Definition mraimpl.h:390
bool is_reconstructed() const
Returns true if the function is compressed.
Definition mraimpl.h:258
double norm_tree_op(const keyT &key, const std::vector< Future< double > > &v)
Definition mraimpl.h:1671
void reset_timer()
Definition mraimpl.h:378
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:870
int get_k() const
Definition mraimpl.h:352
FunctionImpl< T, NDIM > implT
Type of this class (implementation).
Definition funcimpl.h:1048
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:3032
bool truncate_op(const keyT &key, double tol, const std::vector< Future< bool > > &v)
Definition mraimpl.h:2806
void zero_norm_tree()
Definition mraimpl.h:1400
std::size_t max_local_depth() const
Returns the maximum local depth of the tree ... no communications.
Definition mraimpl.h:1976
tensorT project(const keyT &key) const
Definition mraimpl.h:2951
double thresh
Screening threshold.
Definition funcimpl.h:1071
double check_symmetry_local() const
Returns some asymmetry measure ... no comms.
Definition mraimpl.h:856
Future< double > get_norm_tree_recursive(const keyT &key) const
Definition mraimpl.h:2972
bool is_redundant_after_merge() const
Returns true if the function is redundant_after_merge.
Definition mraimpl.h:270
Key< NDIM > keyT
Type of key.
Definition funcimpl.h:1052
bool truncate_on_project
If true projection inserts at level n-1 not n.
Definition funcimpl.h:1079
bool is_on_demand() const
Definition mraimpl.h:285
void accumulate_timer(const double time) const
Definition mraimpl.h:364
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:1474
void set_thresh(double value)
Definition mraimpl.h:343
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:435
void sock_it_to_me_too(const keyT &key, const RemoteReference< FutureImpl< std::pair< keyT, coeffT > > > &ref) const
Definition mraimpl.h:3010
void broaden_op(const keyT &key, const std::vector< Future< bool > > &v)
Definition mraimpl.h:1388
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:415
void print_tree(std::ostream &os=std::cout, Level maxlevel=10000) const
Definition mraimpl.h:2834
bool has_summable_coefficients() const
Returns true if summing over the local nodes yields the function.
Definition mraimpl.h:295
void project_refine_op(const keyT &key, bool do_refine, const std::vector< Vector< double, NDIM > > &specialpts)
Definition mraimpl.h:2617
std::size_t tree_size() const
Returns the size of the tree structure of the function ... collective global sum.
Definition mraimpl.h:2016
void add_scalar_inplace(T t, bool fence)
Adds a constant to the function. Local operation, optional fence.
Definition mraimpl.h:2698
void forward_traverse(const coeff_opT &coeff_op, const apply_opT &apply_op, const keyT &key) const
traverse a non-existing tree
Definition funcimpl.h:3991
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:1308
void abs_square_inplace(bool fence)
Definition mraimpl.h:3385
void put_in_box(ProcessID from, long nl, long ni) const
Definition mraimpl.h:925
void unary_op_value_inplace(const opT &op, bool fence)
Definition funcimpl.h:3120
Timer timer_accumulate
Definition funcimpl.h:1151
TensorArgs get_tensor_args() const
Definition mraimpl.h:334
void average(const implT &rhs)
take the average of two functions, similar to: this=0.5*(this+rhs)
Definition mraimpl.h:1195
void diff(const DerivativeBase< T, NDIM > *D, const implT *f, bool fence)
Definition mraimpl.h:1048
void square_inplace(bool fence)
Pointwise squaring of function with optional global fence.
Definition mraimpl.h:3374
void remove_internal_coefficients(const bool fence)
Definition mraimpl.h:1633
void compute_snorm_and_dnorm(bool fence=true)
compute norm of s and d coefficients for all nodes
Definition mraimpl.h:1238
long box_leaf[1000]
Definition funcimpl.h:3552
void standard(bool fence)
Definition mraimpl.h:1897
bool is_nonstandard_with_leaves() const
Definition mraimpl.h:280
int truncate_mode
0=default=(|d|<thresh), 1=(|d|<thresh/2^n), 2=(|d|<thresh/4^n);
Definition funcimpl.h:1077
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition funcimpl.h:136
bool has_coeff() const
Returns true if there are coefficients in this node.
Definition funcimpl.h:210
size_t size() const
Returns the number of coefficients in this node.
Definition funcimpl.h:252
void clear_coeff()
Clears the coefficients (has_coeff() will subsequently return false).
Definition funcimpl.h:305
bool is_leaf() const
Returns true if this does not have children.
Definition funcimpl.h:223
void set_has_children(bool flag)
Sets has_children attribute to value of flag.
Definition funcimpl.h:264
void scale_norms(const double a)
Multiply the stored norms by a, for coefficients scaled by some q with |q| = a.
Definition funcimpl.h:360
double get_norm_tree() const
Gets the value of norm_tree.
Definition funcimpl.h:326
void set_snorm(const double sn)
set the precomputed norm of the (virtual) s coefficients
Definition funcimpl.h:341
void set_is_leaf(bool flag)
Sets has_children attribute to value of !flag.
Definition funcimpl.h:290
void print_json(std::ostream &s) const
Definition funcimpl.h:503
void set_dnorm_tree(double dnorm_tree)
Sets the value of dnorm_tree.
Definition funcimpl.h:321
bool has_children() const
Returns true if this node has children.
Definition funcimpl.h:217
void set_coeff(const coeffT &coeffs)
Takes a shallow copy of the coeff — same as this->coeff()=coeff.
Definition funcimpl.h:295
void set_dnorm(const double dn)
set the precomputed norm of the (virtual) d coefficients
Definition funcimpl.h:346
coeffT & coeff()
Returns a non-const reference to the tensor containing the coeffs.
Definition funcimpl.h:237
void set_norm_tree(double norm_tree)
Sets the value of norm_tree.
Definition funcimpl.h:316
A multiresolution adaptive numerical function.
Definition mra.h:141
Implements the functionality of futures.
Definition future.h:75
A future is a possibly yet unevaluated value.
Definition future.h:370
T & get(bool dowork=true) &
Gets the value, waiting if necessary.
Definition future.h:571
remote_refT remote_ref(World &world) const
Returns a structure used to pass references to another process.
Definition future.h:672
void set(const Future< T > &other)
A.set(B), where A and B are futures ensures A has/will have the same value as B.
Definition future.h:505
RemoteReference< FutureImpl< T > > remote_refT
Definition future.h:395
Definition lowranktensor.h:59
GenTensor convert(const TensorArgs &) const
Definition gentensor.h:198
long dim(const int i) const
return the number of entries in dimension i
Definition lowranktensor.h:391
Tensor< T > full_tensor_copy() const
Definition gentensor.h:206
long ndim() const
Definition lowranktensor.h:386
constexpr bool is_full_tensor() const
Definition gentensor.h:224
void reduce_rank(const double &)
Definition gentensor.h:217
bool has_no_data() const
Definition gentensor.h:211
size_t real_size() const
Definition gentensor.h:214
GenTensor< T > & emul(const GenTensor< T > &other)
Inplace multiply by corresponding elements of argument Tensor.
Definition lowranktensor.h:639
float_scalar_type normf() const
Definition lowranktensor.h:406
long rank() const
Definition gentensor.h:212
const Tensor< T > & full_tensor() const
Definition gentensor.h:200
size_t nCoeff() const
Definition gentensor.h:215
TensorType tensor_type() const
Definition gentensor.h:221
bool has_data() const
Definition gentensor.h:210
const long * dims() const
return the number of entries in dimension i
Definition lowranktensor.h:397
IsSupported< TensorTypeData< Q >, GenTensor< T > & >::type scale(Q fac)
Inplace multiplication by scalar of supported type (legacy name).
Definition lowranktensor.h:428
constexpr bool is_svd_tensor() const
Definition gentensor.h:222
Iterates in lexical order thru all children of a key.
Definition key.h:624
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:71
Level level() const
Definition key.h:170
bool is_neighbor_of(const Key &key, const array_of_bools< NDIM > &bperiodic) const
Assuming keys are at the same level, returns true if displaced by no more than 1 in any direction.
Definition key.h:401
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:476
bool is_invalid() const
Checks if a key is invalid.
Definition key.h:120
Key parent(int generation=1) const
Returns the key of the parent.
Definition key.h:366
const Vector< Translation, NDIM > & translation() const
Definition key.h:175
static Key< NDIM > invalid()
Returns an invalid key.
Definition key.h:111
Range, vaguely a la Intel TBB, to encapsulate a random-access, STL-like start and end iterator with c...
Definition range.h:64
Simple structure used to manage references/pointers to remote instances.
Definition worldref.h:394
double weights(const unsigned int &i) const
return the weight
Definition srconf.h:679
const Tensor< T > flat_vector(const unsigned int &idim) const
return shallow copy of a slice of one of the vectors, flattened to (r,kVec)
Definition srconf.h:553
Definition SVDTensor.h:42
long rank() const
Definition SVDTensor.h:77
A slice defines a sub-range or patch of a dimension.
Definition slice.h:103
static TaskAttributes hipri()
Definition thread.h:457
static TaskAttributes generator()
Definition thread.h:449
Traits class to specify support of numeric types.
Definition type_data.h:56
A tensor is a multidimensional array.
Definition tensor.h:313
float_scalar_type normf() const
Returns the Frobenius norm of the tensor.
Definition tensor.h:1731
Tensor< T > & fill(T x)
Inplace fill with a scalar (legacy name).
Definition tensor.h:567
T * ptr()
Returns a pointer to the internal data.
Definition tensor.h:1845
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type scale(Q x)
Inplace multiplication by scalar of supported type (legacy name).
Definition tensor.h:691
Tensor< T > & emul(const Tensor< T > &t)
Inplace multiply by corresponding elements of argument Tensor.
Definition tensor.h:1804
bool has_data() const
Definition tensor.h:1907
const TensorIterator< T > & end() const
End point for forward iteration.
Definition tensor.h:1897
A simple, fixed dimension vector.
Definition vector.h:64
iterator begin()
Returns an iterator to the beginning of the local data (no communication).
Definition worlddc.h:1552
implT::const_iterator const_iterator
Definition worlddc.h:1310
iterator end()
Returns an iterator past the end of the local data (no communication).
Definition worlddc.h:1566
Future< iterator > futureT
Definition worlddc.h:1313
implT::iterator iterator
Definition worlddc.h:1309
implT::accessor accessor
Definition worlddc.h:1311
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:177
ProcessID me
Definition world_object.h:514
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn) const
Definition world_object.h:858
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const TaskAttributes &attr=TaskAttributes()) const
Definition world_object.h:1132
A parallel world class.
Definition world.h:134
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:344
WorldGopInterface & gop
Global operations.
Definition world.h:216
ProcessID nproc() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition world.h:349
Wrapper for an opaque pointer for serialization purposes.
Definition archive.h:851
syntactic sugar for std::array<bool, N>
Definition array_of_bools.h:19
void test(World &world, bool doloadbal=false)
Definition dataloadbal.cc:224
double(* f)(const coord_3d &)
Definition derivatives.cc:54
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
static double lo
Definition dirac-hatom.cc:23
Fcwf copy(Fcwf psi)
Definition fcwf.cc:374
std::vector< Fcwf > transform(World &world, std::vector< Fcwf > &a, Tensor< std::complex< double > > U)
Definition fcwf.cc:515
Provides FunctionCommonData, FunctionImpl and FunctionFactory.
static double function(const coord_3d &r)
Normalized gaussian.
Definition functionio.cc:100
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:2475
Tensor< T > transpose(const Tensor< T > &t)
Returns a new deep copy of the transpose of the input tensor.
Definition tensor.h:2039
const double beta
Definition gygi_soltion.cc:62
static const double v
Definition hatom_sf_dirac.cc:20
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:468
Tensor< double > op(const Tensor< double > &x)
Definition kain.cc:508
static double pow(const double *a, const double *b)
Definition lda.h:74
Macros and tools pertaining to the configuration of MADNESS.
#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_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
Tensor< double > tensorT
Definition mcpfit.cc:52
static double ttt
Definition mcpfit.cc:57
void print(const tensorT &t)
Definition mcpfit.cc:140
static const bool VERIFY_TREE
Definition mra.h:57
Definition potentialmanager.cc:41
std::pair< Tensor< R > &, Tensor< R > & > eval_scratch(long need)
Definition tensor.h:2738
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
@ BC_FREE
Definition bc.h:53
static const char * filename
Definition legendre.cc:96
static const std::vector< Slice > ___
Entire dimension.
Definition slice.h:124
static bool enforce_in_volume(Level n, const Translation &l)
Definition mraimpl.h:3475
int power(int base=2)
Definition power.h:43
Vector< double, 3 > coordT
Definition corepotential.cc:54
GenTensor< TENSOR_RESULT_TYPE(R, Q)> general_transform(const GenTensor< R > &t, const Tensor< Q > c[])
Definition gentensor.h:274
std::optional< BoundaryConditions< NDIM > > FunctionDefaults< NDIM >::bc
Definition mraimpl.h:3890
int FunctionDefaults< NDIM >::k
Definition mraimpl.h:3878
void legendre_scaling_functions(double x, long k, double *p)
Evaluate the first k Legendre scaling functions.
Definition legendre.cc:85
TreeState
Definition funcdefaults.h:60
@ nonstandard_after_apply
s and d coeffs, state after operator application
Definition funcdefaults.h:65
@ on_demand
no coeffs anywhere, but a functor providing if necessary
Definition funcdefaults.h:68
@ redundant_after_merge
s coeffs everywhere, must be summed up to yield the result
Definition funcdefaults.h:67
@ reconstructed
s coeffs at the leaves only
Definition funcdefaults.h:61
@ nonstandard
s and d coeffs in internal nodes
Definition funcdefaults.h:63
@ unknown
Definition funcdefaults.h:69
@ compressed
d coeffs in internal nodes, s and d coeffs at the root, empty leaves may be present
Definition funcdefaults.h:62
@ redundant
s coeffs everywhere
Definition funcdefaults.h:66
@ nonstandard_with_leaves
like nonstandard, with s coeffs at the leaves
Definition funcdefaults.h:64
static void user_to_sim(const Vector< double, NDIM > &xuser, Vector< double, NDIM > &xsim)
Convert user coords (cell[][]) to simulation coords ([0,1]^ndim).
Definition funcdefaults.h:469
Tensor< double > FunctionDefaults< NDIM >::cell
Definition mraimpl.h:3892
void compress(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Compress a vector of functions.
Definition vmra.h:150
int64_t Translation
Definition key.h:59
Tensor< TENSOR_RESULT_TYPE(T, Q)> & general_fast_transform(const Tensor< T > &t, const Tensor< Q > *c, Tensor< TENSOR_RESULT_TYPE(T, Q)> &result, Tensor< TENSOR_RESULT_TYPE(T, Q)> &workspace)
Definition tensor.h:2579
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:3730
static void verify_tree(World &world, const std::vector< Function< T, NDIM > > &v)
Definition SCF.cc:77
Function< T, NDIM > sum(World &world, const std::vector< Function< T, NDIM > > &f, bool fence=true)
Returns new function — q = sum_i f[i].
Definition vmra.h:1774
static const Slice _(0,-1, 1)
ConcurrentHashMap< hashT, std::shared_ptr< GaussianConvolution1D< double > > > GaussianConvolution1DCache< double >::map
Definition convolution1d.h:1073
int Level
Definition key.h:60
std::enable_if< std::is_base_of< ProjectorBase, projT >::value, OuterProjector< projT, projQ > >::type outer(const projT &p0, const projQ &p1)
Definition projector.h:476
static constexpr double NORM_TREE_UNCOMPUTED
Definition funcimpl.h:127
Tensor< double > FunctionDefaults< NDIM >::cell_width
Definition mraimpl.h:3893
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:118
Tensor< T > fcube(const Key< NDIM > &, T(*f)(const Vector< double, NDIM > &), const Tensor< double > &)
Definition mraimpl.h:2292
TensorType
low rank representations of tensors (see gentensor.h)
Definition gentensor.h:120
@ TT_2D
Definition gentensor.h:120
@ TT_FULL
Definition gentensor.h:120
static void dxprintvalue(FILE *f, const double t)
Definition mraimpl.h:3721
NDIM & f
Definition mra.h:2817
void error(const char *msg)
Definition world.cc:147
NDIM const Function< R, NDIM > & g
Definition mra.h:2817
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition timers.cc:48
double FunctionDefaults< NDIM >::cell_volume
Definition mraimpl.h:3895
TensorType FunctionDefaults< NDIM >::tt
Definition mraimpl.h:3891
void change_tensor_type(GenTensor< T > &, const TensorArgs &targs)
change representation to targ.tt
Definition gentensor.h:284
const Future< void > Future< void >::value
Definition future.cc:44
double imag(double x)
Definition complexfun.h:56
static bool print_timings
Definition SCF.cc:109
constexpr Vector< T, sizeof...(Ts)+1 > vec(T t, Ts... ts)
Factory function for creating a madness::Vector.
Definition vector.h:750
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:923
static std::vector< double > ttt
Definition SCF.cc:110
std::vector< Future< T > > future_vector_factory(std::size_t n)
Factory for a vectors of futures.
Definition future.h:889
double real(double x)
Definition complexfun.h:52
const FunctionCommonData< T, NDIM > * FunctionCommonData< T, NDIM >::data[MAXK]
Definition mraimpl.h:3875
@ same
same atoms at the same places
Definition RestartPlan.h:152
std::string name(const FuncType &type, const int ex=-1)
Definition ccpairfunction.h:28
static const int MAXK
The maximum wavelet order presently supported.
Definition funcdefaults.h:55
static bool enforce_bc(bool is_periodic, Level n, Translation &l)
Definition mraimpl.h:3455
bool isnan(const std::complex< T > &v)
Definition mraimpl.h:55
static long abs(long a)
Definition tensor.h:214
const double mu
Definition navstokes_cosines.cc:95
static const double b
Definition nonlinschro.cc:119
static const double d
Definition nonlinschro.cc:121
static const double a
Definition nonlinschro.cc:118
static const double c
Definition relops.cc:10
static const double m
Definition relops.cc:9
static const double L
Definition rk.cc:46
static const long k
Definition rk.cc:44
const double xi
Exponent for delta function approx.
Definition siam_example.cc:60
Definition test_ar.cc:204
add two functions f and g: result=alpha * f + beta * g
Definition funcimpl.h:3836
"put" this on g
Definition funcimpl.h:2843
change representation of nodes' coeffs to low rank, optional fence
Definition funcimpl.h:2876
check symmetry wrt particle exchange
Definition funcimpl.h:2549
compute the norm of the wavelet coefficients
Definition funcimpl.h:5052
Definition funcimpl.h:2903
Definition funcimpl.h:1661
mirror dimensions of this, write result on f
Definition funcimpl.h:2777
map this on f
Definition funcimpl.h:2697
mirror dimensions of this, write result on f
Definition funcimpl.h:2727
Definition funcimpl.h:6354
reduce the rank of the nodes, optional fence
Definition funcimpl.h:2523
Changes non-standard compressed form to standard compressed form.
Definition funcimpl.h:5276
Definition funcimpl.h:5124
shallow-copy, pared-down version of FunctionNode, for special purpose only
Definition funcimpl.h:845
TensorArgs holds the arguments for creating a LowRankTensor.
Definition gentensor.h:134
double thresh
Definition gentensor.h:135
Definition mraimpl.h:3354
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition mraimpl.h:3355
void serialize(Archive &ar)
Definition mraimpl.h:3356
Definition mraimpl.h:3360
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition mraimpl.h:3361
void serialize(Archive &ar)
Definition mraimpl.h:3362
Definition mraimpl.h:3321
void operator()(const A &a, const B &b) const
Definition mraimpl.h:3322
void serialize(Archive &ar)
Definition mraimpl.h:3324
Definition mraimpl.h:3328
void operator()(const Key< NDIM > &key, FunctionNode< T, NDIM > &node) const
Definition mraimpl.h:3336
void serialize(Archive &ar)
Definition mraimpl.h:3340
T q
Definition mraimpl.h:3329
scaleinplace()
Definition mraimpl.h:3330
scaleinplace(T q)
Definition mraimpl.h:3332
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition mraimpl.h:3333
Definition mraimpl.h:3346
void serialize(Archive &ar)
Definition mraimpl.h:3350
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition mraimpl.h:3347
insert/replaces the coefficients into the function
Definition funcimpl.h:788
Definition lowrankfunction.h:387
int np
Definition tdse1d.cc:165
static const double s0
Definition tdse4.cc:83
double norm(const T i1)
Definition test_cloud.cc:85
double cpu_time()
Definition test_list.cc:43
static Function< double, D > project(World &world, const std::shared_ptr< FunctionFunctorInterface< double, D > > &functor)
Definition test_mul_sparse.cc:72
int task(int i)
Definition test_runtime.cpp:4
void e()
Definition test_sig.cc:75
#define N
Definition testconv.cc:37
static const double alpha
Definition testcosine.cc:10
constexpr std::size_t NDIM
Definition testgconv.cc:54
double h(const coord_1d &r)
Definition testgconv.cc:175
std::size_t axis
Definition testpdiff.cc:59
double k0
Definition testperiodic.cc:66
static long abs(long a)
Definition tensor.h:214
#define TENSOR_RESULT_TYPE(L, R)
This macro simplifies access to TensorResultType.
Definition type_data.h:205
Defines and implements WorldObject.
Implements WorldContainer.
Defines and implements a concurrent hashmap.
#define PROFILE_FUNC
Definition worldprofile.h:209
#define PROFILE_MEMBER_FUNC(classname)
Definition worldprofile.h:210
#define PROFILE_BLOCK(name)
Definition worldprofile.h:208
int ProcessID
Used to clearly identify process number/rank.
Definition worldtypes.h:43
Key< D > keyT
Definition writecoeff2.cc:11