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)"
53 bool isnan(
const std::complex<T>&
v) {
69 template <
typename T, std::
size_t NDIM>
71 if (!
two_scale_hg(
k, &hg))
throw "failed to get twoscale coefficients";
89 template <
typename T, std::
size_t NDIM>
99 for (
int mu=0;
mu<npt; ++
mu) {
102 for (
int j=0; j<
k; ++j) {
103 quad_phi(
mu,j) = phi[j];
104 quad_phiw(
mu,j) = quad_w(
mu)*phi[j];
110 template <
typename T, std::
size_t NDIM>
118 template <
typename T, std::
size_t NDIM>
122 for (
const auto& [key,
node] : coeffs) {
124 if (key.level() > 0) {
127 if (pit == coeffs.end()) {
128 print(world.rank(),
"FunctionImpl: verify: MISSING PARENT",key,parent);
133 const nodeT&
pnode = pit->second;
134 if (!
pnode.has_children()) {
135 print(world.rank(),
"FunctionImpl: verify: PARENT THINKS IT HAS NO CHILDREN",key,parent);
143 typename dcT::const_iterator
cit = coeffs.find(
kit.key()).get();
144 if (
cit == coeffs.end()) {
145 if (
node.has_children()) {
146 print(world.rank(),
"FunctionImpl: verify: MISSING CHILD",key,
kit.key());
153 if (!
node.has_children()) {
154 print(world.rank(),
"FunctionImpl: verify: UNEXPECTED CHILD",key,
kit.key());
168 template<
typename T, std::
size_t NDIM>
176 return c.dim(0)==2*
k;
193 for (
const auto& [key,
node] : coeffs) {
194 const auto&
c=
node.coeff();
196 const bool is_leaf=
not node.has_children();
200 print(
"incorrect size of coefficients for key",key,
"state",state,
c.dim(0));;
206 template <
typename T, std::
size_t NDIM>
208 return coeffs.get_pmap();
222 template <
typename T, std::
size_t NDIM>
224 const double beta,
const implT&
g,
const bool fence) {
229 ProcessID owner = coeffs.owner(cdata.key0);
230 if (world.rank() == owner) {
245 if (fence) world.gop.fence();
249 template <
typename T, std::
size_t NDIM>
255 template <
typename T, std::
size_t NDIM>
261 template <
typename T, std::
size_t NDIM>
267 template <
typename T, std::
size_t NDIM>
272 template <
typename T, std::
size_t NDIM>
277 template <
typename T, std::
size_t NDIM>
282 template <
typename T, std::
size_t NDIM>
287 template <
typename T, std::
size_t NDIM>
292 template <
typename T, std::
size_t NDIM>
299 template <
typename T, std::
size_t NDIM>
305 template <
typename T, std::
size_t NDIM>
311 template <
typename T, std::
size_t NDIM>
318 template <
typename T, std::
size_t NDIM>
321 template <
typename T, std::
size_t NDIM>
324 template <
typename T, std::
size_t NDIM>
327 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>
353 timer_accumulate.accumulate(
time);
356 template <
typename T, std::
size_t NDIM>
358 if (world.rank()==0) {
359 timer_accumulate.print(
"accumulate");
360 timer_target_driven.print(
"target_driven");
361 timer_lr_result.print(
"result2low_rank");
365 template <
typename T, std::
size_t NDIM>
367 if (world.rank()==0) {
368 timer_accumulate.reset();
369 timer_target_driven.reset();
370 timer_lr_result.reset();
377 template <
typename T, std::
size_t NDIM>
382 if (world.rank() == coeffs.owner(cdata.key0)) {
383 if (is_compressed()) {
384 truncate_spawn(cdata.key0,tol);
386 truncate_reconstructed_spawn(cdata.key0,tol);
393 template <
typename T, std::
size_t NDIM>
402 template <
typename T, std::
size_t NDIM>
422 template <
typename T, std::
size_t NDIM>
435 const keyT& key = it->first;
444 double scale=std::pow(0.5,
double(n));
465 const double maxrank=40;
471 const int npt = cdata.npt + 1;
498 template <
typename T, std::
size_t NDIM>
500 const int xaxis,
const int yaxis,
const coordT el2) {
512 fprintf(
pFile,
"\\begin{pspicture}(%4.2f,%4.2f)(%4.2f,%4.2f)\n",
522 for (
long i=0; i<
localinfo.dim(0); ++i) {
528 "(%12.8f,%12.8f)(%12.8f,%12.8f)\n",
541 template <
typename T, std::
size_t NDIM>
545 std::vector<keyT>
local_keys=local_leaf_keys();
557 template <
typename T, std::
size_t NDIM>
561 std::vector<keyT>
keys(coeffs.size());
568 const keyT& key = it->first;
583 template <
typename T, std::
size_t NDIM>
590 const size_t npt = qx.
dim(0);
605 typename std::vector<keyT>::const_iterator
key_it=
keys.begin();
616 const double h = std::pow(0.5,
double(n));
623 for (
size_t i=0; i<npt; ++i) {
624 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
625 for (
size_t j=0; j<npt; ++j) {
626 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
627 for (
size_t k=0;
k<npt; ++
k) {
628 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
648 template <
typename T, std::
size_t NDIM>
683 const static double fac=1.0/std::pow(2,
NDIM*0.5);
695 template <
typename T, std::
size_t NDIM>
697 std::vector<Slice> s(
NDIM);
699 for (std::size_t i=0; i<
NDIM; ++i)
700 s[i] = cdata.s[l[i]&1];
706 template <
typename T, std::
size_t NDIM>
708 const keyT& child,
const keyT& parent,
const coeffT& coeff)
const {
718 if (coeff.
dim(0)==2*
f->get_k()) result=coeff;
719 else if (coeff.
dim(0)==
f->get_k()) {
720 result(
f->cdata.s0)+=coeff;
738 template <
typename T, std::
size_t NDIM>
743 for (
typename dcT::iterator it= coeffs.begin(); it!=end; ++it) {
749 this->undo_redundant(
true);
754 template <
typename T, std::
size_t NDIM>
768 template <
typename T, std::
size_t NDIM>
770 const std::vector<tensorT>&
c,
772 if (key == cdata.key0 && coeffs.owner(key)!=world.rank())
return;
775 std::unique_ptr<typename dcT::accessor[]>
acc(
new typename dcT::accessor[
v.size()]);
776 for (
unsigned int i=0; i<
c.size(); i++) {
779 bool exists = !
v[i]->coeffs.insert(
acc[i],key);
791 for (
unsigned int i=0; i<
v.size(); i++) {
792 done &=
acc[i]->second.has_coeff();
797 std::vector<tensorT>
d(
v.size());
798 for (
unsigned int i=0; i<
v.size(); i++) {
802 s(cdata.s0) =
acc[i]->second.coeff().full_tensor();
803 acc[i]->second.clear_coeff();
805 acc[i]->second.set_has_children(
true);
812 std::vector<Slice> cp = child_patch(child);
813 std::vector<tensorT>
childc(
v.size());
814 for (
unsigned int i=0; i<
v.size(); i++) {
817 woT::task(coeffs.owner(child), &implT::refine_to_common_level,
v,
childc, child);
823 template <
typename T, std::
size_t NDIM>
825 if (world.size()> 1000)
832 template <
typename T, std::
size_t NDIM>
834 if (world.size() >= 1000)
836 for (
int i=0; i<world.size(); ++i)
837 box_leaf[i] = box_interior[i] == 0;
848 this->send(0, &implT::put_in_box, world.rank(),
nleaf,
ninterior);
850 if (world.rank() == 0) {
851 for (
int i=0; i<world.size(); ++i) {
852 printf(
"load: %5d %8ld %8ld\n", i, box_leaf[i], box_interior[i]);
858 template <
typename T, std::
size_t NDIM>
864 template <
typename T, std::
size_t NDIM>
868 double test = 2*
lo*hi + hi*hi;
875 template <
typename T, std::
size_t NDIM>
878 coeffs.insert(
acc,key);
891 if (
node.has_children()) {
902 if (
d.size() > 0)
ss =
copy(
d(child_patch(child)));
904 woT::task(coeffs.owner(child), &implT::sum_down_spawn, child,
ss);
909 if (
c.size() <= 0)
c =
coeffT(cdata.vk,targs);
921 template <
typename T, std::
size_t NDIM>
923 if (get_tensor_type()!=
TT_FULL && world.rank()==0)
924 print(
"WARNING: sum_down is numerically unstable for tensor type",get_tensor_type());
926 if (world.rank() == coeffs.owner(cdata.key0)) sum_down_spawn(cdata.key0,
coeffT());
927 if (fence) world.gop.fence();
931 template <
typename T, std::
size_t NDIM>
935 const std::pair<keyT,coeffT>& left,
936 const std::pair<keyT,coeffT>& center,
937 const std::pair<keyT,coeffT>& right) {
938 D->forward_do_diff1(
f,
this,key,left,center,right);
942 template <
typename T, std::
size_t NDIM>
946 const std::pair<keyT,coeffT>& left,
947 const std::pair<keyT,coeffT>& center,
948 const std::pair<keyT,coeffT>& right) {
949 D->do_diff1(
f,
this,key,left,center,right);
954 template <
typename T, std::
size_t NDIM>
956 typedef std::pair<keyT,coeffT> argT;
957 for (
const auto& [key,
node]:
f->coeffs) {
958 if (
node.has_coeff()) {
960 argT center(key,
node.coeff());
968 if (fence) world.gop.fence();
973 template <
typename T, std::
size_t NDIM>
986 template <
typename T, std::
size_t NDIM>
994 std::vector<long>
vkhalf=std::vector<long>(
NDIM/2,cdata.vk[0]);
1021 template <
typename T, std::
size_t NDIM>
1045 if (
veri.has_data()) {
1065 template <
typename T, std::
size_t NDIM>
1069 const_cast<implT*
>(&
f)->flo_unary_op_node_inplace(
do_mapdim(map,*
this),fence);
1074 template <
typename T, std::
size_t NDIM>
1077 const_cast<implT*
>(&
f)->flo_unary_op_node_inplace(
do_mirror(mirrormap,*
this),fence);
1084 template <
typename T, std::
size_t NDIM>
1086 const std::vector<long>&
mirror,
bool fence) {
1096 template <
typename T, std::
size_t NDIM>
1100 this->scale_inplace(0.5,
true);
1107 template <
typename T, std::
size_t NDIM>
1115 template <
typename T, std::
size_t NDIM>
1123 template <
typename T, std::
size_t NDIM>
1126 for (
auto it=coeffs.begin(); it!=coeffs.end(); ++it) {
1127 const keyT& key=it->first;
1139 template <
typename T, std::
size_t NDIM>
1142 flo_unary_op_node_inplace(
1160 template <
typename T, std::
size_t NDIM>
1168 template <
typename T, std::
size_t NDIM>
1189 template <
typename T, std::
size_t NDIM>
1197 template <
typename T, std::
size_t NDIM>
1209 template <
typename T, std::
size_t NDIM>
1215 const tensorT h[2] = {cdata.h0T, cdata.h1T};
1239 template <
typename T, std::
size_t NDIM>
1244 const tensorT h[2] = {cdata.h0, cdata.h1};
1257 template <
typename T, std::
size_t NDIM>
1263 const keyT& key = it->first;
1265 if (
node.has_coeff()) {
1267 c(s) +=
node.coeff()(s);
1268 coeffs.replace(key,
nodeT(
c,
false));
1271 coeffs.replace(key,nodeT(coeffT(),
true));
1278 template <
typename T, std::
size_t NDIM>
1280 return coeffs.probe(key) && coeffs.find(key).get()->second.has_children();
1283 template <
typename T, std::
size_t NDIM>
1285 return coeffs.probe(key) && (
not coeffs.find(key).get()->second.has_children());
1289 template <
typename T, std::
size_t NDIM>
1291 for (
unsigned int i=0; i<
v.size(); ++i) {
1300 template <
typename T, std::
size_t NDIM>
1303 for (
typename dcT::iterator it=coeffs.begin(); it!=end; ++it) {
1304 it->second.set_norm_tree(0.0);
1305 it->second.set_snorm(0.0);
1306 it->second.set_dnorm(0.0);
1311 template <
typename T, std::
size_t NDIM>
1314 for (
typename dcT::iterator it=coeffs.begin(); it!=end; ++it) {
1315 const keyT& key = it->first;
1317 const auto found = coeffs.find(
acc,key);
1320 if (
node.has_coeff() &&
1321 node.get_norm_tree() != -1.0 &&
1322 node.coeff().normf() >= truncate_tol(
thresh,key)) {
1327 int ndir =
static_cast<int>(std::pow(
static_cast<double>(3),
static_cast<int>(
NDIM)));
1333 for (std::size_t
d=0;
d<
NDIM; ++
d) {
1343 if (
neigh.is_valid()) {
1350 woT::task(world.rank(), &implT::broaden_op, key,
v);
1362 template <
typename T, std::
size_t NDIM>
1365 if (world.rank() == coeffs.owner(cdata.key0))
1366 woT::task(world.rank(), &implT::trickle_down_op, cdata.key0,
coeffT());
1367 if (fence) world.gop.fence();
1373 template <
typename T, std::
size_t NDIM>
1384 if (it == coeffs.end()) {
1386 it = coeffs.find(key).get();
1388 nodeT&
node = it->second;
1396 if (
node.has_children()) {
1398 if (key.
level() > 0)
d += s;
1401 const keyT& child =
kit.key();
1405 woT::task(coeffs.owner(child), &implT::trickle_down_op, child,
ss);
1415 template <
typename T, std::
size_t NDIM>
1430 remove_internal_coefficients(fence);
1434 remove_internal_coefficients(fence);
1451 remove_leaf_coefficients(fence);
1469 print(
"could not respect no-fence parameter in change_tree_state");
1476 template <
typename T, std::
size_t NDIM>
1479 if (is_reconstructed())
return;
1481 if (is_redundant()
or is_nonstandard_with_leaves()) {
1483 this->remove_internal_coefficients(fence);
1487 if (world.rank() == coeffs.owner(cdata.key0))
1488 woT::task(world.rank(), &implT::reconstruct_op, cdata.key0,
coeffT(),
true);
1489 }
else if (is_nonstandard()) {
1492 if (world.rank() == coeffs.owner(cdata.key0))
1493 woT::task(world.rank(), &implT::reconstruct_op, cdata.key0,
coeffT(),
false);
1497 if (fence) world.gop.fence();
1508 template <
typename T, std::
size_t NDIM>
1517 if (world.rank() == coeffs.owner(cdata.key0)) {
1525 template <
typename T, std::
size_t NDIM>
1530 template <
typename T, std::
size_t NDIM>
1536 template <
typename T, std::
size_t NDIM>
1540 if (is_redundant())
return;
1541 MADNESS_CHECK_THROW(is_reconstructed(),
"impl::make_redundant() wants a reconstructed tree");
1546 template <
typename T, std::
size_t NDIM>
1555 template <
typename T, std::
size_t NDIM>
1557 if (world.rank() == coeffs.owner(cdata.key0))
1558 norm_tree_spawn(cdata.key0);
1563 template <
typename T, std::
size_t NDIM>
1569 double value =
v[i].get();
1573 coeffs.task(key, &nodeT::set_norm_tree,
sum);
1578 template <
typename T, std::
size_t NDIM>
1580 nodeT&
node = coeffs.find(key).get()->second;
1581 if (
node.has_children()) {
1585 v[i] = woT::task(coeffs.owner(
kit.key()), &implT::norm_tree_spawn,
kit.key());
1587 return woT::task(world.rank(),&implT::norm_tree_op, key,
v);
1591 const double norm=
node.coeff().normf();
1601 template <
typename T, std::
size_t NDIM>
1604 nodeT&
node = coeffs.find(key).get()->second;
1625 template <
typename T, std::
size_t NDIM>
1632 for (
size_t i=0; i<
v.size(); ++i)
if (
v[i].get().has_no_data())
return coeffT();
1639 const auto found = coeffs.find(
acc, key);
1645 d(child_patch(
kit.key())) +=
v[i].get().full_tensor();
1651 const double error=
d.normf();
1653 nodeT&
node = coeffs.find(key).get()->second;
1655 if (
error < truncate_tol(tol,key)) {
1658 coeffs.erase(
kit.key());
1662 acc->second.set_coeff(
ss);
1676 template <
typename T, std::
size_t NDIM>
1689 d(child_patch(
kit.key())) +=
v[i].get().first.full_tensor();
1695 timer_filter.accumulate(
cpu1-
cpu0);
1699 const auto found = coeffs.find(
acc, key);
1709 double snorm=
ss.normf();
1714 double dnorm=
dd.normf();
1717 acc->second.set_snorm(snorm);
1718 acc->second.set_dnorm(dnorm);
1721 acc->second.set_coeff(
dd);
1723 timer_compress_svd.accumulate(
cpu1-
cpu0);
1726 return std::make_pair(
ss,snorm);
1735 template <
typename T, std::
size_t NDIM>
1736 std::pair<typename FunctionImpl<T,NDIM>::coeffT,
double>
1743 d(child_patch(
kit.key())) +=
v[i].get().first.full_tensor();
1756 double dnorm=
d.normf();
1757 double snorm=s.normf();
1760 const auto found = coeffs.find(
acc, key);
1763 acc->second.set_coeff(s);
1764 acc->second.set_dnorm(dnorm);
1765 acc->second.set_snorm(snorm);
1773 template <
typename T, std::
size_t NDIM>
1776 if (is_compressed())
return;
1778 flo_unary_op_node_inplace(
do_standard(
this),fence);
1786 template <
typename T, std::
size_t NDIM>
1794 flo_unary_op_node_inplace(do_consolidate_buffer(
tight_args),
true);
1802 flo_unary_op_node_inplace(do_reduce_rank(targs),
true);
1808 flo_unary_op_node_inplace(do_change_tensor_type(targs,*
this),
true);
1814 flo_unary_op_node_inplace(do_truncate_NS_leafs(
this),
true);
1829 template <
typename T, std::
size_t NDIM>
1838 template <
typename T, std::
size_t NDIM>
1850 template <
typename T, std::
size_t NDIM>
1855 std::size_t
N = (std::size_t) it->first.level();
1864 template <
typename T, std::
size_t NDIM>
1866 std::size_t
maxdepth = max_local_depth();
1872 template <
typename T, std::
size_t NDIM>
1881 template <
typename T, std::
size_t NDIM>
1890 template <
typename T, std::
size_t NDIM>
1892 std::size_t
sum = 0;
1893 sum = coeffs.size();
1899 template <
typename T, std::
size_t NDIM>
1901 std::size_t
sum = 0;
1902 for (
const auto& [key,
node] : coeffs) {
1909 template <
typename T, std::
size_t NDIM>
1911 std::size_t
sum = size_local();
1917 template <
typename T, std::
size_t NDIM>
1919 std::size_t
sum = coeffs.size() * (
sizeof(
keyT) +
sizeof(
nodeT));
1923 if (
node.has_coeff())
sum+=
node.coeff().real_size();
1930 template <
typename T, std::
size_t NDIM>
1933 for (
auto& [key,
node] : coeffs) {
1940 template <
typename T, std::
size_t NDIM>
1942 std::size_t
sum = nCoeff_local();
1949 template <
typename T, std::
size_t NDIM>
1951 const size_t tsize=this->tree_size();
1953 const size_t ncoeff=this->nCoeff();
1955 const double d=
sizeof(
T);
1956 const double fac=1024*1024*1024;
1960 double local = norm2sq_local();
1961 this->world.gop.sum(local);
1962 this->world.gop.fence();
1966 if (this->world.rank()==0) {
1968 constexpr std::size_t
bufsize=128;
1970 snprintf(buf,
bufsize,
"%40s at time %.1fs: norm/tree/#coeff/size: %7.5f %zu, %6.3f m, %6.3f GByte",
1972 print(std::string(buf));
1977 template <
typename T, std::
size_t NDIM>
1979 if (this->targs.tt==
TT_FULL)
return;
1982 if (is_compressed())
k0=2*
k;
1987 if (world.rank()==0)
print(
"n.size(),k0,dim",n.
size(),
k0,dim);
1991 if (
node.has_coeff()) {
1994 }
else if (
node.coeff().rank()==-1) {
1996 }
else if (
node.coeff().rank()<0) {
1997 print(
"small rank",
node.coeff().rank());
1999 n[
node.coeff().rank()]++;
2006 if (world.rank()==0) {
2007 print(
"configurations number of nodes");
2009 for (
unsigned int i=0; i<n.
size(); i++) {
2010 print(
" ",i,
" ",n[i]);
2017 for (
unsigned int i=0; i<std::min(3l,n.
size()); i++)
nlog[0]+=n[i];
2018 for (
unsigned int i=3; i<std::min(10l,n.
size()); i++)
nlog[1]+=n[i];
2019 for (
unsigned int i=10; i<std::min(30l,n.
size()); i++)
nlog[2]+=n[i];
2020 for (
unsigned int i=30; i<std::min(100l,n.
size()); i++)
nlog[3]+=n[i];
2021 for (
unsigned int i=100; i<std::min(300l,n.
size()); i++)
nlog[4]+=n[i];
2022 for (
unsigned int i=300; i<std::min(1000l,n.
size()); i++)
nlog[5]+=n[i];
2024 std::vector<std::string>
slog={
"3",
"10",
"30",
"100",
"300",
"1000"};
2025 for (
unsigned int i=0; i<
nlog.size(); i++) {
2033 template <
typename T, std::
size_t NDIM>
2036 const int k = cdata.k;
2053 if constexpr (
NDIM <= 2) {
2058 if constexpr (
NDIM == 1) {
2059 const T* cp =
c.ptr();
2060 for (
int p=0;
p<
k; ++
p)
sum += cp[
p]*px[0][
p];
2063 for (
int p=0;
p<
k; ++
p) {
2064 const double a = px[0][
p];
2065 const T*
cq = &
c(
p,0);
2067 for (
int q=0;
q<
k; ++
q)
s2 +=
cq[
q]*px[1][
q];
2074 thread_local int phi_k = -1;
2079 for (std::size_t i=0; i<
NDIM; ++i)
2084 auto [
ws,
res] = madness::detail::eval_scratch<evalR>(
c.size());
2100 template <
typename T, std::
size_t NDIM>
2112 if (it == coeffs.end()) {
2114 it = coeffs.find(key).get();
2121 if (
node.has_children() && !
node.has_coeff()) {
2125 if (
node.has_children() ||
node.has_coeff()) {
2127 if (!
d.has_data())
d =
coeffT(cdata.v2k,targs);
2129 if (
d.dim(0)==2*get_k()) {
2132 node.set_has_children(
true);
2134 const keyT& child =
kit.key();
2138 woT::task(coeffs.owner(child), &implT::reconstruct_op, child,
ss,
accumulate_NS);
2143 node.coeff().reduce_rank(targs.thresh);
2148 if (s.has_no_data())
ss=
coeffT(cdata.vk,targs);
2154 template <
typename T, std::
size_t NDIM>
2157 std::vector<long> npt(
NDIM,qx.
dim(0));
2163 template <
typename T, std::
size_t NDIM>
2166 std::vector<long> npt(
NDIM,qx.
dim(0));
2172 template <
typename T, std::
size_t NDIM>
2181 const double h = std::pow(0.5,
double(n));
2183 const int npt = qx.
dim(0);
2190 for (std::size_t i = 0; i <
NDIM; i++) {
2191 c1[i] = cell(i,0) +
h*cell_width[i]*(l[i] + qx((
long)0));
2192 c2[i] = cell(i,0) +
h*cell_width[i]*(l[i] + qx(npt-1));
2194 if (
f.screened(c1, c2)) {
2204 double*
x1 =
new double[npt];
2206 for (
int i=0; i<npt; ++i, ++
idx) {
2207 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2214 else if (
NDIM == 2) {
2215 double*
x1 =
new double[npt*npt];
2216 double*
x2 =
new double[npt*npt];
2218 for (
int i=0; i<npt; ++i) {
2219 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2220 for (
int j=0; j<npt; ++j, ++
idx) {
2221 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2231 else if (
NDIM == 3) {
2232 double*
x1 =
new double[npt*npt*npt];
2233 double*
x2 =
new double[npt*npt*npt];
2234 double*
x3 =
new double[npt*npt*npt];
2236 for (
int i=0; i<npt; ++i) {
2237 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2238 for (
int j=0; j<npt; ++j) {
2239 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2240 for (
int k=0;
k<npt; ++
k, ++
idx) {
2241 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2255 double*
x1 =
new double[npt*npt*npt*npt];
2256 double*
x2 =
new double[npt*npt*npt*npt];
2257 double*
x3 =
new double[npt*npt*npt*npt];
2258 double*
x4 =
new double[npt*npt*npt*npt];
2260 for (
int i=0; i<npt; ++i) {
2261 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2262 for (
int j=0; j<npt; ++j) {
2263 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2264 for (
int k=0;
k<npt; ++
k) {
2265 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2266 for (
int m=0;
m<npt; ++
m, ++
idx) {
2267 c[3] = cell(3,0) +
h*cell_width[3]*(l[3] + qx(
m));
2283 else if (
NDIM == 5) {
2284 double*
x1 =
new double[npt*npt*npt*npt*npt];
2285 double*
x2 =
new double[npt*npt*npt*npt*npt];
2286 double*
x3 =
new double[npt*npt*npt*npt*npt];
2287 double*
x4 =
new double[npt*npt*npt*npt*npt];
2288 double*
x5 =
new double[npt*npt*npt*npt*npt];
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 for (
int n=0; n<npt; ++n, ++
idx) {
2299 c[4] = cell(4,0) +
h*cell_width[4]*(l[4] + qx(n));
2318 else if (
NDIM == 6) {
2319 double*
x1 =
new double[npt*npt*npt*npt*npt*npt];
2320 double*
x2 =
new double[npt*npt*npt*npt*npt*npt];
2321 double*
x3 =
new double[npt*npt*npt*npt*npt*npt];
2322 double*
x4 =
new double[npt*npt*npt*npt*npt*npt];
2323 double*
x5 =
new double[npt*npt*npt*npt*npt*npt];
2324 double*
x6 =
new double[npt*npt*npt*npt*npt*npt];
2326 for (
int i=0; i<npt; ++i) {
2327 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2328 for (
int j=0; j<npt; ++j) {
2329 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2330 for (
int k=0;
k<npt; ++
k) {
2331 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2332 for (
int m=0;
m<npt; ++
m) {
2333 c[3] = cell(3,0) +
h*cell_width[3]*(l[3] + qx(
m));
2334 for (
int n=0; n<npt; ++n) {
2335 c[4] = cell(4,0) +
h*cell_width[4]*(l[4] + qx(n));
2336 for (
int p=0;
p<npt; ++
p, ++
idx) {
2337 c[5] = cell(5,0) +
h*cell_width[5]*(l[5] + qx(
p));
2369 for (
int i=0; i<npt; ++i) {
2370 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2375 else if (
NDIM == 2) {
2376 for (
int i=0; i<npt; ++i) {
2377 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2378 for (
int j=0; j<npt; ++j) {
2379 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2385 else if (
NDIM == 3) {
2386 for (
int i=0; i<npt; ++i) {
2387 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2388 for (
int j=0; j<npt; ++j) {
2389 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2390 for (
int k=0;
k<npt; ++
k) {
2391 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2398 else if (
NDIM == 4) {
2399 for (
int i=0; i<npt; ++i) {
2400 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2401 for (
int j=0; j<npt; ++j) {
2402 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2403 for (
int k=0;
k<npt; ++
k) {
2404 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2405 for (
int m=0;
m<npt; ++
m) {
2406 c[3] = cell(3,0) +
h*cell_width[3]*(l[3] + qx(
m));
2414 else if (
NDIM == 5) {
2415 for (
int i=0; i<npt; ++i) {
2416 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2417 for (
int j=0; j<npt; ++j) {
2418 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2419 for (
int k=0;
k<npt; ++
k) {
2420 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2421 for (
int m=0;
m<npt; ++
m) {
2422 c[3] = cell(3,0) +
h*cell_width[3]*(l[3] + qx(
m));
2423 for (
int n=0; n<npt; ++n) {
2424 c[4] = cell(4,0) +
h*cell_width[4]*(l[4] + qx(n));
2433 else if (
NDIM == 6) {
2434 for (
int i=0; i<npt; ++i) {
2435 c[0] = cell(0,0) +
h*cell_width[0]*(l[0] + qx(i));
2436 for (
int j=0; j<npt; ++j) {
2437 c[1] = cell(1,0) +
h*cell_width[1]*(l[1] + qx(j));
2438 for (
int k=0;
k<npt; ++
k) {
2439 c[2] = cell(2,0) +
h*cell_width[2]*(l[2] + qx(
k));
2440 for (
int m=0;
m<npt; ++
m) {
2441 c[3] = cell(3,0) +
h*cell_width[3]*(l[3] + qx(
m));
2442 for (
int n=0; n<npt; ++n) {
2443 c[4] = cell(4,0) +
h*cell_width[4]*(l[4] + qx(n));
2444 for (
int p=0;
p<npt; ++
p) {
2445 c[5] = cell(5,0) +
h*cell_width[5]*(l[5] + qx(
p));
2461 template <
typename T, std::
size_t NDIM>
2467 template <
typename T, std::
size_t NDIM>
2479 template <
typename T, std::
size_t NDIM>
2488 if (key.
level() < special_level && specialpts.size() > 0) {
2490 const auto bperiodic = bc.is_periodic();
2491 for (
unsigned int i = 0; i < specialpts.size(); ++i) {
2513 const keyT& child = it.key();
2514 r(child_patch(child)) =
project(child);
2518 if (truncate_on_project)
s0 =
copy(
d(cdata.s0));
2528 const keyT& child = it.key();
2531 p = world.random_proc();
2534 p = coeffs.owner(child);
2541 if (truncate_on_project) {
2543 coeffs.replace(key,
nodeT(s,
false));
2548 const keyT& child = it.key();
2550 coeffs.replace(child,
nodeT(s,
false));
2560 template <
typename T, std::
size_t NDIM>
2562 std::vector<long>
v0(
NDIM,0
L);
2563 std::vector<long>
v1(
NDIM,1L);
2566 if (is_compressed()) {
2567 if (world.rank() == coeffs.owner(cdata.key0)) {
2581 for (
typename dcT::iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
2582 Level n = it->first.level();
2584 if (
node.has_coeff()) {
2591 node.coeff()(s) += tt;
2598 if (fence) world.gop.fence();
2601 template <
typename T, std::
size_t NDIM>
2604 if (is_compressed()) initial_level = std::max(initial_level,1);
2605 if (coeffs.is_local(key)) {
2606 if (is_compressed()) {
2607 if (key.
level() == initial_level) {
2611 coeffs.replace(key,
nodeT(
coeffT(cdata.v2k,targs),
true));
2615 if (key.
level()<initial_level) {
2619 coeffs.replace(key,
nodeT(
coeffT(cdata.vk,targs),
false));
2623 if (key.
level() < initial_level) {
2625 insert_zero_down_to_initial_level(
kit.key());
2632 template <
typename T, std::
size_t NDIM>
2636 if (it == coeffs.end()) {
2640 coeffs.replace(key,
nodeT());
2641 it = coeffs.find(key).get();
2644 if (
node.has_children()) {
2650 return woT::task(world.rank(),&implT::truncate_op, key, tol,
v);
2657 if (
node.has_coeff() && key.
level()>1) {
2658 double dnorm =
node.coeff().normf();
2659 if (dnorm < truncate_tol(tol,key)) {
2668 template <
typename T, std::
size_t NDIM>
2672 for (
int i=0; i<(1<<
NDIM); ++i)
if (
v[i].get())
return true;
2673 nodeT&
node = coeffs.find(key).get()->second;
2680 if (key.
level() > 1) {
2681 double dnorm =
node.coeff().normf();
2682 if (dnorm < truncate_tol(tol,key)) {
2684 if (
node.has_children()) {
2685 node.set_has_children(
false);
2687 coeffs.erase(
kit.key());
2692 return node.has_coeff();
2696 template <
typename T, std::
size_t NDIM>
2698 if (world.rank() == 0) do_print_tree(cdata.key0, os,
maxlevel);
2700 if (world.rank() == 0) os.flush();
2705 template <
typename T, std::
size_t NDIM>
2708 if (it == coeffs.end()) {
2710 for (
int i=0; i<key.
level(); ++i) os <<
" ";
2711 os << key <<
" missing --> " << coeffs.owner(key) <<
"\n";
2715 for (
int i=0; i<key.
level(); ++i) os <<
" ";
2716 os << key <<
" " <<
node <<
" --> " << coeffs.owner(key) <<
"\n";
2725 template <
typename T, std::
size_t NDIM>
2727 std::multimap<Level, std::tuple<tranT, std::string>>
data;
2728 if (world.rank() == 0) do_print_tree_json(cdata.key0,
data,
maxlevel);
2730 if (world.rank() == 0) {
2732 if (
data.count(level) == 0)
2737 os <<
"\"" << level <<
"\":{";
2738 os <<
"\"level\": " << level <<
",";
2739 os <<
"\"nodes\":{";
2740 auto range =
data.equal_range(level);
2741 for (
auto it = range.first; it != range.second; ++it) {
2742 os <<
"\"" << std::get<0>(it->second) <<
"\":"
2743 << std::get<1>(it->second);
2744 if (std::next(it) != range.second)
2756 template <
typename T, std::
size_t NDIM>
2759 if (it == coeffs.end()) {
2764 std::ostringstream
oss;
2767 oss <<
",\"owner\": " << coeffs.owner(key) <<
"}";
2778 template <
typename T, std::
size_t NDIM>
2781 if (world.rank() == 0) do_print_tree_graphviz(cdata.key0, os,
maxlevel);
2783 if (world.rank() == 0) os.flush();
2787 template <
typename T, std::
size_t NDIM>
2794 result += (1 << j*
NDIM);
2802 if (it != coeffs.end()) {
2806 os << uniqhash::value(key) <<
" -> " << uniqhash::value(
kit.key()) <<
"\n";
2813 template <
typename T, std::
size_t NDIM>
2820 if (functor->provides_coeff())
return functor->coeff(key).full_tensor_copy();
2834 template <
typename T, std::
size_t NDIM>
2836 if (coeffs.probe(key)) {
2837 return Future<double>(coeffs.find(key).get()->second.get_norm_tree());
2841 return woT::task(coeffs.owner(parent), &implT::get_norm_tree_recursive, parent,
TaskAttributes::hipri());
2845 template <
typename T, std::
size_t NDIM>
2849 if (coeffs.probe(key)) {
2850 const nodeT&
node = coeffs.find(key).get()->second;
2852 if (
node.has_coeff()) {
2854 result.
set(std::pair<keyT,coeffT>(key,
node.coeff()));
2858 result.
set(std::pair<keyT,coeffT>(key,
coeffT()));
2865 if (coeffs.is_local(parent))
2873 template <
typename T, std::
size_t NDIM>
2877 if (coeffs.probe(key)) {
2878 const nodeT&
node = coeffs.find(key).get()->second;
2880 if (
node.has_coeff()) {
2881 result.
set(std::pair<keyT,coeffT>(key,
node.coeff()));
2895 template <
typename T, std::
size_t NDIM>
2918 if (
node.has_coeff()) {
2923 for (std::size_t i=0; i<
NDIM; ++i) {
2924 double xi = x[i]*2.0;
2926 if (
li == 2)
li = 1;
2938 template <
typename T, std::
size_t NDIM>
2946 if (coeffs.owner(key) ==
me) {
2949 if (it != coeffs.end()) {
2951 if (
node.has_coeff()) {
2952 return std::pair<bool,T>(
true,eval_cube(key.
level(), x,
node.coeff().full_tensor()));
2956 for (std::size_t i=0; i<
NDIM; ++i) {
2957 double xi = x[i]*2.0;
2959 if (
li == 2)
li = 1;
2965 return std::pair<bool,T>(
false,0.0);
2968 template <
typename T, std::
size_t NDIM>
2972 std::pair<bool,T>* results) {
2992 for (std::size_t
ip=0;
ip<npt; ++
ip) {
2993 results[
ip] = std::pair<bool,T>(
false,
T(0));
2998 for (std::size_t i=0; i<
NDIM; ++i) l[i] = 0;
3001 for (std::size_t i=0; i<
NDIM; ++i) {
3002 double xi = x[i]*2.0;
3004 if (
li == 2)
li = 1;
3011 for (std::size_t i=0; i<
NDIM; ++i)
same =
same && (l[i] ==
lc[i]);
3013 results[
ip] = std::pair<bool,T>(
true, eval_cube(nl, x,
cached_c));
3024 if (coeffs.owner(key) ==
me) {
3027 if (it != coeffs.end()) {
3029 if (
node.has_coeff()) {
3033 results[
ip] = std::pair<bool,T>(
true,
3039 for (std::size_t i=0; i<
NDIM; ++i) {
3040 double xi = x[i]*2.0;
3042 if (
li == 2)
li = 1;
3051 template <
typename T, std::
size_t NDIM>
3052 std::vector<std::pair<bool,T>>
3054 std::vector<std::pair<bool,T>> results(
xin.size(), std::pair<bool,T>(
false,
T(0)));
3055 eval_local_only(
xin.data(),
xin.size(),
maxlevel, results.data());
3059 template <
typename T, std::
size_t NDIM>
3082 if (
node.has_coeff()) {
3087 for (std::size_t i=0; i<
NDIM; ++i) {
3088 double xi = x[i]*2.0;
3090 if (
li == 2)
li = 1;
3101 template <
typename T, std::
size_t NDIM>
3124 if (
node.has_coeff()) {
3129 for (std::size_t i=0; i<
NDIM; ++i) {
3130 double xi = x[i]*2.0;
3132 if (
li == 2)
li = 1;
3144 template <
typename T, std::
size_t NDIM>
3155 template <
typename T, std::
size_t NDIM>
3165 template <
typename T, std::
size_t NDIM>
3171 if (t.
rank()==0)
return;
3173 for (
long i=0; i<t.
rank(); ++i) {
3176 tnorm(
c, &lo1, &hi1);
3184 template <
typename A,
typename B>
3191 template <
typename T, std::
size_t NDIM>
3201 node.coeff().scale(
q);
3208 template <
typename T, std::
size_t NDIM>
3216 template <
typename T, std::
size_t NDIM>
3222 template <
typename T, std::
size_t NDIM>
3230template <
typename T, std::
size_t NDIM>
3236 template <
typename T, std::
size_t NDIM>
3242 template <
typename T, std::
size_t NDIM>
3247 template <
typename T, std::
size_t NDIM>
3252 template <
typename T, std::
size_t NDIM>
3257 for (
int mu=0;
mu<cdata.npt; ++
mu) {
3261 for (
int i=0; i<
k; ++i) phi(i,
mu) =
p[i];
3266 template <
typename T, std::
size_t NDIM>
3278 result =
transform(result,cdata.quad_phiw);
3284 template <
typename T, std::
size_t NDIM>
3287 std::vector<long>
v0(
NDIM,0);
3289 if (is_compressed()) {
3290 if (world.rank() == coeffs.owner(cdata.key0)) {
3292 if (it != coeffs.end()) {
3300 const keyT& key = it->first;
3321 }
else if (l >=
two2n) {
3325 }
while (l >=
two2n);
3334 return l >= 0 && l <
two2n;
3340 template <
typename T, std::
size_t NDIM>
3349 return keyT::invalid();
3355 template <
typename T, std::
size_t NDIM>
3363 return keyT::invalid();
3369 template <
typename T, std::
size_t NDIM>
3373 typedef std::pair< Key<NDIM>,
coeffT > argT;
3383 template <
typename T, std::
size_t NDIM>
3386 if (!coeffs.probe(key))
print(
"missing node",key);
3390 nodeT&
node = coeffs.find(key).get()->second;
3393 if (
node.has_children()) {
3399 v[i] = woT::task(coeffs.owner(
kit.key()), &implT::compress_spawn,
kit.key(),
3402 if (
redundant1)
return woT::task(world.rank(),&implT::make_redundant_op, key,
v);
3403 return woT::task(world.rank(),&implT::compress_op, key,
v,
nonstandard1);
3414 double snorm=
node.coeff().normf();
3415 node.set_dnorm(0.0);
3416 node.set_snorm(snorm);
3417 node.set_norm_tree(snorm);
3421 coeffT result(
node.coeff());
3422 coeffT
sdcoeff(cdata.v2k,
this->get_tensor_type());
3425 double snorm=
node.coeff().normf();
3427 node.set_snorm(snorm);
3428 node.set_norm_tree(snorm);
3437 node.set_norm_tree(snorm);
3438 node.set_snorm(snorm);
3439 node.set_dnorm(0.0);
3446 template <
typename T, std::
size_t NDIM>
3455 for (std::size_t i=0; i<
NDIM; ++i) {
3466 const Vector<Translation,NDIM>& l = key.
translation();
3467 const double twon =
pow(2.0,
double(n));
3468 const tensorT& coeff = coeffs.find(key).get()->second.coeff().full_tensor();
3474 double fac =
pow(0.5,
double(key.
level()));
3476 for (std::size_t
d=0;
d<
NDIM; ++
d) {
3487 else if (npt[
d] == 1) {
3511 for (IndexIterator it(
boxnpt); it; ++it) {
3512 for (std::size_t
d=0;
d<
NDIM; ++
d) {
3514 x[
d] = twon*
xd - l[
d];
3528 T tmp = eval_cube(n, x, coeff);
3538 template <
typename T, std::
size_t NDIM>
3541 const std::vector<long>& npt,
3549 const keyT& key = it->first;
3551 if (
node.has_coeff()) {
3552 woT::task(world.rank(), &implT::plot_cube_kernel,
3559 world.taskq.fence();
3560 world.gop.sum(r.
ptr(), r.
size());
3571 fprintf(
f,
"%.6e %.6e\n", t.real(), t.imag());
3574 template <
typename T, std::
size_t NDIM>
3578 const std::vector<long>& npt,
3582 const char*
element[6] = {
"lines",
"quads",
"cubes",
"cubes4D",
"cubes5D",
"cubes6D"};
3587 if (world.
rank() == 0) {
3591 fprintf(
f,
"object 1 class gridpositions counts ");
3599 for (std::size_t
d=0;
d<
NDIM; ++
d) {
3603 if (npt[
d]>1)
h = (cell(
d,1)-cell(
d,0))/(npt[
d]-1);
3610 fprintf(
f,
"object 2 class gridconnections counts ");
3614 fprintf(
f,
"attribute \"ref\" string \"positions\"\n");
3623 fprintf(
f,
"object 3 class array type double %s rank 0 items %d %s data follows\n",
3630 if (world.
rank() == 0) {
3634 fwrite((
void *) r.
ptr(),
sizeof(
T), r.
size(),
f);
3646 fprintf(
f,
"component \"positions\" value 1\n");
3647 fprintf(
f,
"component \"connections\" value 2\n");
3648 fprintf(
f,
"component \"data\" value 3\n");
3655 template <std::
size_t NDIM>
3661 max_refine_level = 30;
3666 truncate_on_project =
true;
3667 apply_randomize =
false;
3668 project_randomize =
false;
3671 cell = make_default_cell();
3672 recompute_cell_info();
3673 set_default_pmap(world);
3676 template <std::
size_t NDIM>
3679 return std::make_shared<LevelPmap< Key<NDIM> >>(world);
3683 template <std::
size_t NDIM>
3685 pmap = make_default_pmap(world);
3686 pmap_nproc = world.
nproc();
3690 template <std::
size_t NDIM>
3692 std::cout <<
"Function Defaults:" << std::endl;
3693 std::cout <<
" Dimension " <<
": " <<
NDIM << std::endl;
3694 std::cout <<
" k" <<
": " <<
k << std::endl;
3695 std::cout <<
" thresh" <<
": " <<
thresh << std::endl;
3696 std::cout <<
" initial_level" <<
": " << initial_level << std::endl;
3697 std::cout <<
" special_level" <<
": " << special_level << std::endl;
3698 std::cout <<
" max_refine_level" <<
": " << max_refine_level << std::endl;
3699 std::cout <<
" truncate_mode" <<
": " <<
truncate_mode << std::endl;
3700 std::cout <<
" refine" <<
": " <<
refine << std::endl;
3701 std::cout <<
" autorefine" <<
": " << autorefine << std::endl;
3702 std::cout <<
" debug" <<
": " <<
debug << std::endl;
3703 std::cout <<
" truncate_on_project" <<
": " << truncate_on_project << std::endl;
3704 std::cout <<
" apply_randomize" <<
": " << apply_randomize << std::endl;
3705 std::cout <<
" project_randomize" <<
": " << project_randomize << std::endl;
3706 std::cout <<
" bc" <<
": " << get_bc() << std::endl;
3707 std::cout <<
" tt" <<
": " << tt << std::endl;
3708 std::cout <<
" cell" <<
": " << cell << std::endl;
3711 template <
typename T, std::
size_t NDIM>
3712 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
Definition test_tree.cc:78
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:791
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
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:91
void _init_twoscale()
Private. Initialize the twoscale coefficients.
Definition mraimpl.h:70
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:100
static Tensor< double > make_default_cell_width()
Definition funcdefaults.h:136
static std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > make_default_pmap(World &world)
Makes a default process map for the given world.
Definition mraimpl.h:3677
static bool truncate_on_project
If true initial projection inserts at n-1 not n.
Definition funcdefaults.h:114
static bool apply_randomize
If true use randomization for load balancing in apply integral operator.
Definition funcdefaults.h:115
static double cell_volume
Volume of simulation cell.
Definition funcdefaults.h:121
static int k
Wavelet order.
Definition funcdefaults.h:105
static double get_cell_volume()
Returns the volume of the user cell.
Definition funcdefaults.h:396
static int truncate_mode
Truncation method.
Definition funcdefaults.h:110
static void set_default_pmap(World &world)
Definition mraimpl.h:3684
static int pmap_nproc
Number of processes assumed by pmap, -1 indicates uninitialized pmap.
Definition funcdefaults.h:125
static Tensor< double > cell_width
Width of simulation cell in each dimension.
Definition funcdefaults.h:119
static double thresh
Truncation threshold.
Definition funcdefaults.h:106
static bool debug
Controls output of debug info.
Definition funcdefaults.h:113
static int special_level
Minimum level for fine scale projection of special boxes.
Definition funcdefaults.h:108
static double cell_min_width
Size of smallest dimension.
Definition funcdefaults.h:122
static std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > pmap
Default mapping of keys to processes.
Definition funcdefaults.h:124
static const Tensor< double > & get_cell_width()
Returns the width of each user cell dimension.
Definition funcdefaults.h:381
static const BoundaryConditions< NDIM > & get_bc()
Returns the default boundary conditions.
Definition funcdefaults.h:311
static Tensor< double > cell
cell[NDIM][2] Simulation cell, cell(0,0)=xlo, cell(0,1)=xhi, ...
Definition funcdefaults.h:118
static int initial_level
Initial level for fine scale projection.
Definition funcdefaults.h:107
static bool autorefine
Whether to autorefine in multiplication, etc.
Definition funcdefaults.h:112
static Tensor< double > make_default_cell()
Definition funcdefaults.h:127
static std::optional< BoundaryConditions< NDIM > > bc
Default boundary conditions, not initialized by default and must be set explicitly before use.
Definition funcdefaults.h:117
static void print()
Definition mraimpl.h:3691
static Tensor< double > rcell_width
Reciprocal of width.
Definition funcdefaults.h:120
static double get_cell_min_width()
Returns the minimum width of any user cell dimension.
Definition funcdefaults.h:391
static bool project_randomize
If true use randomization for load balancing in project/refine.
Definition funcdefaults.h:116
static const Tensor< double > & get_cell()
Gets the user cell for the simulation.
Definition funcdefaults.h:348
static void set_defaults(World &world)
Definition mraimpl.h:3656
static int max_refine_level
Level at which to stop refinement.
Definition funcdefaults.h:109
static TensorType tt
structure of the tensor in FunctionNode
Definition funcdefaults.h:123
static bool refine
Whether to refine new functions.
Definition funcdefaults.h:111
Abstract base class interface required for functors used as input to Functions.
Definition function_interface.h:68
Definition funcimpl.h:5558
FunctionImpl holds all Function state to facilitate shallow copy semantics.
Definition funcimpl.h:945
bool is_nonstandard() const
Definition mraimpl.h:273
T eval_cube(Level n, coordT &x, const tensorT &c) const
Definition mraimpl.h:2034
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:2788
void change_tensor_type1(const TensorArgs &targs, bool fence)
change the tensor type of the coefficients in the FunctionNode
Definition mraimpl.h:1108
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:3060
void scale_inplace(const T q, bool fence)
In-place scale by a constant.
Definition mraimpl.h:3231
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:223
bool is_redundant() const
Returns true if the function is redundant.
Definition mraimpl.h:262
std::size_t nCoeff_local() const
Returns the number of coefficients in the function for this MPI rank.
Definition mraimpl.h:1931
void print_size(const std::string name) const
print tree size and size
Definition mraimpl.h:1950
void print_info() const
Prints summary of data distribution.
Definition mraimpl.h:833
void abs_inplace(bool fence)
Definition mraimpl.h:3243
void print_timer() const
Definition mraimpl.h:357
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:3102
void do_print_grid(const std::string filename, const std::vector< keyT > &keys) const
print the grid in xyz format
Definition mraimpl.h:584
std::size_t nCoeff() const
Returns the number of coefficients in the function ... collective global sum.
Definition mraimpl.h:1941
keyT neighbor_in_volume(const keyT &key, const keyT &disp) const
Returns key of general neighbor that resides in-volume.
Definition mraimpl.h:3356
void compress(const TreeState newstate, bool fence)
compress the wave function
Definition mraimpl.h:1509
std::pair< coeffT, double > compress_op(const keyT &key, const std::vector< Future< std::pair< coeffT, double > > > &v, bool nonstandard)
calculate the wavelet coefficients using the sum coefficients of all child nodes
Definition mraimpl.h:1677
Future< bool > truncate_spawn(const keyT &key, double tol)
Returns true if after truncation this node has coefficients.
Definition mraimpl.h:2633
Future< double > norm_tree_spawn(const keyT &key)
Definition mraimpl.h:1579
std::vector< keyT > local_leaf_keys() const
return the keys of the local leaf boxes
Definition mraimpl.h:558
void do_print_tree(const keyT &key, std::ostream &os, Level maxlevel) const
Functor for the do_print_tree method.
Definition mraimpl.h:2706
void unset_functor()
Definition mraimpl.h:312
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:499
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:974
void set_functor(const std::shared_ptr< FunctionFunctorInterface< T, NDIM > > functor1)
Definition mraimpl.h:293
bool verify_tree_state_local() const
check that the tree state and the coeffs are consistent
Definition mraimpl.h:169
const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > & get_pmap() const
Definition mraimpl.h:207
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:2846
double get_thresh() const
Definition mraimpl.h:328
void trickle_down(bool fence)
sum all the contributions from all scales after applying an operator in mod-NS form
Definition mraimpl.h:1363
std::pair< coeffT, double > make_redundant_op(const keyT &key, const std::vector< Future< std::pair< coeffT, double > > > &v)
similar to compress_op, but insert only the sum coefficients in the tree
Definition mraimpl.h:1737
void set_autorefine(bool value)
Definition mraimpl.h:337
tensorT filter(const tensorT &s) const
Transform sum coefficients at level n to sums+differences at level n-1.
Definition mraimpl.h:1161
void chop_at_level(const int n, const bool fence=true)
remove all nodes with level higher than n
Definition mraimpl.h:1124
void print_tree_json(std::ostream &os=std::cout, Level maxlevel=10000) const
Definition mraimpl.h:2726
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:707
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:1066
bool is_compressed() const
Returns true if the function is compressed.
Definition mraimpl.h:250
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:1075
void print_stats() const
print the number of configurations per node
Definition mraimpl.h:1978
void broaden(const array_of_bools< NDIM > &is_periodic, bool fence)
Definition mraimpl.h:1312
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:1626
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:2468
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:932
std::vector< Slice > child_patch(const keyT &child) const
Returns patch referring to coeffs of child in parent box.
Definition mraimpl.h:696
void print_tree_graphviz(std::ostream &os=std::cout, Level maxlevel=10000) const
Definition mraimpl.h:2779
std::size_t min_nodes() const
Returns the min number of nodes on a processor.
Definition mraimpl.h:1882
void make_redundant(const bool fence)
convert this to redundant, i.e. have sum coefficients on all levels
Definition mraimpl.h:1537
std::size_t max_nodes() const
Returns the max number of nodes on a processor.
Definition mraimpl.h:1873
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:1240
void flo_unary_op_node_inplace(const opT &op, bool fence)
Definition funcimpl.h:2231
std::size_t size_local() const
Returns the number of coefficients in the function for each rank.
Definition mraimpl.h:1900
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:3447
T trace_local() const
Returns int(f(x),x) in local volume.
Definition mraimpl.h:3285
void print_grid(const std::string filename) const
Definition mraimpl.h:542
Future< std::pair< coeffT, double > > compress_spawn(const keyT &key, bool nonstandard, bool keepleaves, bool redundant1)
Invoked on node where key is local.
Definition mraimpl.h:3384
bool get_autorefine() const
Definition mraimpl.h:334
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:3253
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:3371
TensorType get_tensor_type() const
Definition mraimpl.h:319
void remove_leaf_coefficients(const bool fence)
Definition mraimpl.h:1531
void insert_zero_down_to_initial_level(const keyT &key)
Initialize nodes to zero function at initial_level of refinement.
Definition mraimpl.h:2602
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:943
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:2757
void finalize_sum()
after summing up we need to do some cleanup;
Definition mraimpl.h:1830
bool exists_and_is_leaf(const keyT &key) const
Definition mraimpl.h:1284
void verify_tree() const
Verify tree is properly constructed ... global synchronization involved.
Definition mraimpl.h:111
void set_tensor_args(const TensorArgs &t)
Definition mraimpl.h:325
std::size_t real_size() const
Returns the number of coefficients in the function ... collective global sum.
Definition mraimpl.h:1918
bool exists_and_has_children(const keyT &key) const
Definition mraimpl.h:1279
void sum_down_spawn(const keyT &key, const coeffT &s)
is this the same as trickle_down() ?
Definition mraimpl.h:876
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:3341
void norm_tree(bool fence)
compute for each FunctionNode the norm of the function inside that node
Definition mraimpl.h:1556
bool has_leaves() const
Definition mraimpl.h:288
bool verify_parents_and_children() const
check that parents and children are consistent
Definition mraimpl.h:119
void reconstruct_op(const keyT &key, const coeffT &s, const bool accumulate_NS=true)
Definition mraimpl.h:2101
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:3268
void undo_redundant(const bool fence)
convert this from redundant to standard reconstructed form
Definition mraimpl.h:1547
const keyT & key0() const
Returns cdata.key0.
Definition mraimpl.h:394
double finalize_apply()
after apply we need to do some cleanup;
Definition mraimpl.h:1787
const dcT & get_coeffs() const
Definition mraimpl.h:343
double norm2sq_local() const
Returns the square of the local norm ... no comms.
Definition mraimpl.h:1839
const FunctionCommonData< T, NDIM > & get_cdata() const
Definition mraimpl.h:349
void sum_down(bool fence)
After 1d push operator must sum coeffs down the tree to restore correct scaling function coefficients...
Definition mraimpl.h:922
bool noautorefine(const keyT &key, const tensorT &t) const
Always returns false (for when autorefine is not wanted)
Definition mraimpl.h:859
double truncate_tol(double tol, const keyT &key) const
Returns the truncation threshold according to truncate_method.
Definition mraimpl.h:649
bool autorefine_square_test(const keyT &key, const nodeT &t) const
Returns true if this block of coeffs needs autorefining.
Definition mraimpl.h:865
void erase(const Level &max_level)
truncate tree at a certain level
Definition mraimpl.h:739
void reconstruct(bool fence)
reconstruct this tree – respects fence
Definition mraimpl.h:1477
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:3677
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:1022
static void tnorm(const tensorT &t, double *lo, double *hi)
Computes norm of low/high-order polyn. coeffs for autorefinement test.
Definition mraimpl.h:3145
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:2940
std::size_t max_depth() const
Returns the maximum depth of the tree ... collective ... global sum/broadcast.
Definition mraimpl.h:1865
std::size_t size() const
Returns the number of coefficients in the function ... collective global sum.
Definition mraimpl.h:1910
void reduce_rank(const double thresh, bool fence)
reduce the rank of the coefficients tensors
Definition mraimpl.h:1116
std::shared_ptr< FunctionFunctorInterface< T, NDIM > > get_functor()
Definition mraimpl.h:300
tensorT unfilter(const tensorT &s) const
Transform sums+differences at level n to sum coefficients at level n+1.
Definition mraimpl.h:1190
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:3539
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:1416
Future< coeffT > truncate_reconstructed_spawn(const keyT &key, const double tol)
truncate using a tree in reconstructed form
Definition mraimpl.h:1602
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:1085
void truncate(double tol, bool fence)
Truncate according to the threshold with optional global fence.
Definition mraimpl.h:378
bool is_reconstructed() const
Returns true if the function is compressed.
Definition mraimpl.h:256
double norm_tree_op(const keyT &key, const std::vector< Future< double > > &v)
Definition mraimpl.h:1564
void reset_timer()
Definition mraimpl.h:366
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:769
int get_k() const
Definition mraimpl.h:340
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:2896
bool truncate_op(const keyT &key, double tol, const std::vector< Future< bool > > &v)
Definition mraimpl.h:2669
void zero_norm_tree()
Definition mraimpl.h:1301
std::size_t max_local_depth() const
Returns the maximum local depth of the tree ... no communications.
Definition mraimpl.h:1851
tensorT project(const keyT &key) const
Definition mraimpl.h:2814
double check_symmetry_local() const
Returns some asymmetry measure ... no comms.
Definition mraimpl.h:755
Future< double > get_norm_tree_recursive(const keyT &key) const
Definition mraimpl.h:2835
bool is_redundant_after_merge() const
Returns true if the function is redundant_after_merge.
Definition mraimpl.h:268
bool is_on_demand() const
Definition mraimpl.h:283
void accumulate_timer(const double time) const
Definition mraimpl.h:352
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:1374
void set_thresh(double value)
Definition mraimpl.h:331
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:423
void sock_it_to_me_too(const keyT &key, const RemoteReference< FutureImpl< std::pair< keyT, coeffT > > > &ref) const
Definition mraimpl.h:2874
void broaden_op(const keyT &key, const std::vector< Future< bool > > &v)
Definition mraimpl.h:1290
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:403
void print_tree(std::ostream &os=std::cout, Level maxlevel=10000) const
Definition mraimpl.h:2697
void project_refine_op(const keyT &key, bool do_refine, const std::vector< Vector< double, NDIM > > &specialpts)
Definition mraimpl.h:2480
std::size_t tree_size() const
Returns the size of the tree structure of the function ... collective global sum.
Definition mraimpl.h:1891
void add_scalar_inplace(T t, bool fence)
Adds a constant to the function. Local operation, optional fence.
Definition mraimpl.h:2561
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:1210
void abs_square_inplace(bool fence)
Definition mraimpl.h:3248
void put_in_box(ProcessID from, long nl, long ni) const
Definition mraimpl.h:824
TensorArgs get_tensor_args() const
Definition mraimpl.h:322
void average(const implT &rhs)
take the average of two functions, similar to: this=0.5*(this+rhs)
Definition mraimpl.h:1097
void diff(const DerivativeBase< T, NDIM > *D, const implT *f, bool fence)
Definition mraimpl.h:955
void square_inplace(bool fence)
Pointwise squaring of function with optional global fence.
Definition mraimpl.h:3237
void remove_internal_coefficients(const bool fence)
Definition mraimpl.h:1526
void compute_snorm_and_dnorm(bool fence=true)
compute norm of s and d coefficients for all nodes
Definition mraimpl.h:1140
void standard(bool fence)
Changes non-standard compressed form to standard compressed form.
Definition mraimpl.h:1774
bool is_nonstandard_with_leaves() const
Definition mraimpl.h:278
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition funcimpl.h:127
void set_has_children(bool flag)
Sets has_children attribute to value of flag.
Definition funcimpl.h:254
void set_is_leaf(bool flag)
Sets has_children attribute to value of !flag.
Definition funcimpl.h:280
void set_coeff(const coeffT &coeffs)
Takes a shallow copy of the coeff — same as this->coeff()=coeff.
Definition funcimpl.h:285
coeffT & coeff()
Returns a non-const reference to the tensor containing the coeffs.
Definition funcimpl.h:227
void set_norm_tree(double norm_tree)
Sets the value of norm_tree.
Definition funcimpl.h:306
A multiresolution adaptive numerical function.
Definition mra.h:139
Implements the functionality of futures.
Definition future.h:75
A future is a possibly yet unevaluated value.
Definition future.h:370
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
Definition lowranktensor.h:59
GenTensor convert(const TensorArgs &targs) const
Definition gentensor.h:198
long dim(const int i) const
return the number of entries in dimension i
Definition lowranktensor.h:391
GenTensor< T > & emul(const GenTensor< T > &other)
Inplace multiply by corresponding elements of argument Tensor.
Definition lowranktensor.h:637
const Tensor< T > & full_tensor() const
Definition gentensor.h:200
TensorType tensor_type() const
Definition gentensor.h:221
GenTensor & gaxpy(const T alpha, const GenTensor &other, const T beta)
Definition lowranktensor.h:586
IsSupported< TensorTypeData< Q >, GenTensor< T > & >::type scale(Q fac)
Inplace multiplication by scalar of supported type (legacy name)
Definition lowranktensor.h:426
Definition worldhashmap.h:330
Iterates in lexical order thru all children of a key.
Definition key.h:548
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:70
Level level() const
Definition key.h:169
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:325
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:400
bool is_invalid() const
Checks if a key is invalid.
Definition key.h:119
Key parent(int generation=1) const
Returns the key of the parent.
Definition key.h:290
const Vector< Translation, NDIM > & translation() const
Definition key.h:174
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:395
double weights(const unsigned int &i) const
return the weight
Definition srconf.h:671
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:545
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:456
static TaskAttributes generator()
Definition thread.h:448
Traits class to specify support of numeric types.
Definition type_data.h:56
A tensor is a multidimensional array.
Definition tensor.h:318
T sum() const
Returns the sum of all elements of the tensor.
Definition tensor.h:1663
Tensor< T > reshape(int ndimnew, const long *d)
Returns new view/tensor reshaping size/number of dimensions to conforming tensor.
Definition tensor.h:1385
T * ptr()
Returns a pointer to the internal data.
Definition tensor.h:1841
IsSupported< TensorTypeData< Q >, Tensor< T > & >::type scale(Q x)
Inplace multiplication by scalar of supported type (legacy name)
Definition tensor.h:687
Tensor< T > & emul(const Tensor< T > &t)
Inplace multiply by corresponding elements of argument Tensor.
Definition tensor.h:1800
Iterator for distributed container wraps the local iterator.
Definition worlddc.h:386
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:176
A parallel world class.
Definition world.h:132
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:320
WorldGopInterface & gop
Global operations.
Definition world.h:207
ProcessID nproc() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition world.h:325
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
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
const std::size_t bufsize
Definition derivatives.cc:16
static double lo
Definition dirac-hatom.cc:23
static bool debug
Definition dirac-hatom.cc:16
Provides FunctionCommonData, FunctionImpl and FunctionFactory.
static double function(const coord_3d &r)
Normalized gaussian.
Definition functionio.cc:100
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:28
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:2460
const double beta
Definition gygi_soltion.cc:62
static const double v
Definition hatom_sf_dirac.cc:20
Tensor< double > op(const Tensor< double > &x)
Definition kain.cc:508
static double pow(const double *a, const double *b)
Definition lda.h:74
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
Vector< double, 3 > coordT
Definition mcpfit.cc:48
static const bool VERIFY_TREE
Definition mra.h:57
Definition potentialmanager.cc:41
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
bool two_scale_hg(int k, Tensor< double > *hg)
Definition twoscale.cc:151
@ BC_FREE
Definition bc.h:53
void make_redundant(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
change tree_state of a vector of functions to redundant
Definition vmra.h:186
static const char * filename
Definition legendre.cc:96
static const std::vector< Slice > ___
Entire dimension.
Definition slice.h:128
static bool enforce_in_volume(Level n, const Translation &l)
Definition mraimpl.h:3332
double abs(double x)
Definition complexfun.h:48
static double cpu_time()
Returns the cpu time in seconds relative to an arbitrary origin.
Definition timers.h:127
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
response_space scale(response_space a, double b)
void legendre_scaling_functions(double x, long k, double *p)
Evaluate the first k Legendre scaling functions.
Definition legendre.cc:85
void norm_tree(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Makes the norm tree for all functions in a vector.
Definition vmra.h:1206
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform(World &world, const std::vector< Function< T, NDIM > > &v, const Tensor< R > &c, bool fence=true)
Transforms a vector of functions according to new[i] = sum[j] old[j]*c[j,i].
Definition vmra.h:731
static Key< NDIM > simpt2key(const Vector< T, NDIM > &pt, Level n)
Definition funcdefaults.h:464
TreeState
Definition funcdefaults.h:59
@ nonstandard_after_apply
s and d coeffs, state after operator application
Definition funcdefaults.h:64
@ on_demand
no coeffs anywhere, but a functor providing if necessary
Definition funcdefaults.h:67
@ redundant_after_merge
s coeffs everywhere, must be summed up to yield the result
Definition funcdefaults.h:66
@ reconstructed
s coeffs at the leaves only
Definition funcdefaults.h:60
@ nonstandard
s and d coeffs in internal nodes
Definition funcdefaults.h:62
@ unknown
Definition funcdefaults.h:68
@ compressed
d coeffs in internal nodes, s and d coeffs at the root
Definition funcdefaults.h:61
@ redundant
s coeffs everywhere
Definition funcdefaults.h:65
@ nonstandard_with_leaves
like nonstandard, with s coeffs at the leaves
Definition funcdefaults.h:63
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:455
void standard(World &world, std::vector< Function< T, NDIM > > &v, bool fence=true)
Generates standard form of a vector of functions.
Definition vmra.h:243
Tensor< double > tensorT
Definition distpm.cc:21
void compress(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Compress a vector of functions.
Definition vmra.h:149
const std::vector< Function< T, NDIM > > & reconstruct(const std::vector< Function< T, NDIM > > &v)
reconstruct a vector of functions
Definition vmra.h:162
response_space transpose(response_space &f)
Definition basic_operators.cc:10
int64_t Translation
Definition key.h:58
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:2525
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:3575
Function< T, NDIM > mirror(const Function< T, NDIM > &f, const std::vector< long > &mirrormap, bool fence=true)
Generate a new function by mirroring within the dimensions .. optional fence.
Definition mra.h:2459
static void verify_tree(World &world, const std::vector< Function< T, NDIM > > &v)
Definition SCF.cc:74
static const Slice _(0,-1, 1)
void change_tensor_type(GenTensor< T > &t, const TensorArgs &targs)
change representation to targ.tt
Definition gentensor.h:284
int Level
Definition key.h:59
std::enable_if< std::is_base_of< ProjectorBase, projT >::value, OuterProjector< projT, projQ > >::type outer(const projT &p0, const projQ &p1)
Definition projector.h:457
TreeState get_tree_state(const Function< T, NDIM > &f)
get tree state of a function
Definition mra.h:2917
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:115
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:226
Tensor< T > fcube(const Key< NDIM > &, T(*f)(const Vector< double, NDIM > &), const Tensor< double > &)
Definition mraimpl.h:2155
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:3566
void refine(World &world, const std::vector< Function< T, NDIM > > &vf, bool fence=true)
refine the functions according to the autorefine criteria
Definition vmra.h:196
NDIM & f
Definition mra.h:2604
void error(const char *msg)
Definition world.cc:142
const Function< T, NDIM > & change_tree_state(const Function< T, NDIM > &f, const TreeState finalstate, bool fence=true)
change tree state of a function
Definition mra.h:2930
NDIM const Function< R, NDIM > & g
Definition mra.h:2604
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition timers.cc:48
static bool print_timings
Definition SCF.cc:106
constexpr Vector< T, sizeof...(Ts)+1 > vec(T t, Ts... ts)
Factory function for creating a madness::Vector.
Definition vector.h:750
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:2560
static std::vector< double > ttt
Definition SCF.cc:107
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:2587
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
std::string name(const FuncType &type, const int ex=-1)
Definition ccpairfunction.h:28
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:2172
static const int MAXK
The maximum wavelet order presently supported.
Definition funcdefaults.h:54
static bool enforce_bc(bool is_periodic, Level n, Translation &l)
Definition mraimpl.h:3312
bool isnan(const std::complex< T > &v)
Definition mraimpl.h:53
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 double thresh
Definition rk.cc:45
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
Definition test_ccpairfunction.cc:22
add two functions f and g: result=alpha * f + beta * g
Definition funcimpl.h:3616
"put" this on g
Definition funcimpl.h:2656
change representation of nodes' coeffs to low rank, optional fence
Definition funcimpl.h:2689
check symmetry wrt particle exchange
Definition funcimpl.h:2362
compute the norm of the wavelet coefficients
Definition funcimpl.h:4513
Definition funcimpl.h:2716
Definition funcimpl.h:1476
mirror dimensions of this, write result on f
Definition funcimpl.h:2590
map this on f
Definition funcimpl.h:2510
mirror dimensions of this, write result on f
Definition funcimpl.h:2540
Definition funcimpl.h:5612
reduce the rank of the nodes, optional fence
Definition funcimpl.h:2336
Changes non-standard compressed form to standard compressed form.
Definition funcimpl.h:4734
remove all coefficients of internal nodes
Definition funcimpl.h:2282
remove all coefficients of leaf nodes
Definition funcimpl.h:2299
Definition funcimpl.h:4585
shallow-copy, pared-down version of FunctionNode, for special purpose only
Definition funcimpl.h:749
TensorArgs holds the arguments for creating a LowRankTensor.
Definition gentensor.h:134
double thresh
Definition gentensor.h:135
Definition mraimpl.h:3217
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition mraimpl.h:3218
void serialize(Archive &ar)
Definition mraimpl.h:3219
Definition mraimpl.h:3223
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition mraimpl.h:3224
void serialize(Archive &ar)
Definition mraimpl.h:3225
Definition mraimpl.h:3185
void operator()(const A &a, const B &b) const
Definition mraimpl.h:3186
void serialize(Archive &ar)
Definition mraimpl.h:3188
Definition mraimpl.h:3192
void operator()(const Key< NDIM > &key, FunctionNode< T, NDIM > &node) const
Definition mraimpl.h:3200
void serialize(Archive &ar)
Definition mraimpl.h:3203
T q
Definition mraimpl.h:3193
scaleinplace()
Definition mraimpl.h:3194
scaleinplace(T q)
Definition mraimpl.h:3196
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition mraimpl.h:3197
Definition mraimpl.h:3209
void serialize(Archive &ar)
Definition mraimpl.h:3213
void operator()(const Key< NDIM > &key, Tensor< T > &t) const
Definition mraimpl.h:3210
insert/replaces the coefficients into the function
Definition funcimpl.h:692
Definition lowrankfunction.h:336
int np
Definition tdse1d.cc:165
static const double s0
Definition tdse4.cc:83
AtomicInt sum
Definition test_atomicint.cc:46
int me
Definition test_binsorter.cc:10
double norm(const T i1)
Definition test_cloud.cc:85
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
static const int truncate_mode
Definition testcosine.cc:14
double cell_volume()
Definition testgconv.cc:86
constexpr std::size_t NDIM
Definition testgconv.cc:54
double h(const coord_1d &r)
Definition testgconv.cc:175
double g1(const coord_t &r)
Definition testgconv.cc:122
std::size_t axis
Definition testpdiff.cc:59
double k0
Definition testperiodic.cc:66
#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
void test()
Definition y.cc:696