32#ifndef MADNESS_MRA_KEY_H__INCLUDED
33#define MADNESS_MRA_KEY_H__INCLUDED
62 template<std::
size_t NDIM>
70 template<std::
size_t NDIM>
132 if (
n != other.
n)
return false;
133 for (
unsigned int i=0; i<
NDIM; i++)
134 if (
l[i] != other.
l[i])
return false;
139 return !(*
this == other);
147 if (
n < other.
n)
return true;
148 if (
n > other.
n)
return false;
150 for (
unsigned int i=0; i<
NDIM; i++) {
151 if (
l[i] < other.
l[i])
return true;
152 if (
l[i] > other.
l[i])
return false;
187 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
196 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
199 const auto real_width = widths(
d) * least_displacement_distance;
200 dist += real_width * real_width;
210 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
212 if (is_periodic[
d]) {
233 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
235 if (is_periodic[
d]) {
246 const auto least_displacement_distance = std::max(
std::abs(la) - 1,
static_cast<Translation>(0));
247 const auto real_width = widths(
d) * least_displacement_distance;
248 dsq += real_width * real_width;
276 return real_width * real_width;
287 const double real_width = widths(
static_cast<long>(
d)) *
static_cast<double>(la);
288 return real_width * real_width;
299 template <
typename F>
301 using T =
decltype(axis_distsq(std::size_t(0),
Translation(0)));
305 bool wrapped =
false;
306 std::optional<T> step;
307 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
309 if (is_periodic[
d]) {
312 if (la > twonm1) {
do la -= twon;
while (la > twonm1); wrapped =
true; }
313 else if (la < -twonm1) {
do la += twon;
while (la < -twonm1); wrapped =
true; }
315 const T s = axis_distsq(
d, la > 0 ? la - twon : la + twon) - axis_distsq(
d, la);
316 if (!step || s < *step) step = s;
319 dsq += axis_distsq(
d, la);
322 MADNESS_CHECK_THROW(step.has_value(),
"Key::distsq_images: no axis is periodic, so there are no images");
330 template <std::
size_t NDIM2>
331 std::enable_if_t<NDIM >= NDIM2, uint64_t>
336 for (std::size_t
a = 0;
a < NDIM2; ++
a) {
337 const auto d = axes[
a];
340 if (is_periodic[
d]) {
370 for (std::size_t i = 0; i <
NDIM; ++i)
371 pl[i] =
l[i] >> generation;
372 return Key(
n - generation, pl);
378 if (this->n < key.
n) {
381 else if (this->n == key.
n) {
382 return (*
this == key);
385 Level dn = this->n - key.
n;
387 return (mama == key);
404 for (std::size_t i=0; i<
NDIM; ++i)
407 if (bperiodic[i] && ll==TWON1) ll=1;
433 template <
typename T>
437 const double twon = std::ldexp(1.0,
n);
438 const double period = twon;
442 const double tol = 8.0 * period * std::numeric_limits<double>::epsilon();
443 for (std::size_t i = 0; i <
NDIM; ++i) {
445 double d = twon *
static_cast<double>(simpt[i]) -
static_cast<double>(
l[i]);
448 d -= period * std::floor((
d + 0.5 * period) / period);
477 const unsigned int& dim1)
const {
481 const double twotoN = std::pow(2.0,
double(
n));
484 for (
unsigned int i=0; i<
NDIM; i++ ) {
490 if ((i==dim0) or (i==dim1))
continue;
492 const int ll=int (x[i]*twotoN);
493 if (not (
l[i]==ll)) contains=
false;
499 template<std::
size_t LDIM, std::
size_t KDIM>
506 if constexpr((LDIM+KDIM==
NDIM) or (LDIM==
NDIM)) {
507 for (
size_t i=0; i<LDIM; ++i) {
510 for (
size_t i=LDIM; i<
NDIM; ++i) {
517 MADNESS_EXCEPTION(
"Key::break_apart: LDIM+KDIM must equal NDIM or LDIM==NDIM",1);
522 template<std::
size_t VDIM>
524 static_assert(VDIM <=
NDIM,
"VDIM must be less than or equal to NDIM");
526 for (
size_t i = 0; i < VDIM; ++i) t[i] = this->
translation()[i];
531 template<std::
size_t VDIM>
533 static_assert(VDIM <=
NDIM,
"VDIM must be less than or equal to NDIM");
535 for (
size_t i = 0; i < VDIM; ++i) t[i] = this->
translation()[
NDIM-VDIM+i];
540 template<std::
size_t VDIM>
543 for (
size_t i = 0; i < VDIM; ++i) t[i] = this->
translation()[v[i]];
548 template<std::
size_t VDIM>
553 auto v_complement = [](
const std::array<int, VDIM>&
v) {
554 std::array<int,
NDIM - VDIM> result;
555 for (std::size_t i = 0; i <
NDIM - VDIM; i++) result[i] = (
v.back() + i + 1) %
NDIM;
562 template<std::
size_t LDIM>
565 if constexpr (
NDIM > 0)
for (
size_t i=0; i<
NDIM; ++i) t[i] =this->l[i];
566 if constexpr (LDIM > 0)
for (
size_t i=0; i<LDIM; ++i) t[
NDIM+i]=rhs.
translation()[i];
577 for (
size_t i=0; i<
NDIM; ++i) {
596 template<std::
size_t NDIM>
608 template<
size_t NDIM>
623 template<std::
size_t NDIM>
646 for (i = 0; i <
NDIM; ++i) {
650 for (std::size_t j = 0; j < i; ++j) {
663 operator bool()
const {
667 template<
typename Archive>
681 template<std::
size_t NDIM,
typename opT>
685 it(parent); it; ++it)
690 template<std::
size_t NDIM,
typename objT>
695 it(parent); it; ++it)
696 (obj ->* memfun)(it.key());
705 template <
class Archive, std::
size_t NDIM>
712 template <std::
size_t NDIM>
720 template <
class Archive, std::
size_t NDIM>
Provides BoundaryConditions.
Implements an archive wrapping a binary filestream.
simple class for testing the solver
Definition derivatives.cc:60
Iterates in lexical order thru all children of a key.
Definition key.h:624
Vector< Translation, NDIM > p
Definition key.h:627
KeyChildIterator(const Key< NDIM > &parent)
Definition key.h:635
bool finished
Definition key.h:628
const Key< NDIM > & key() const
Returns the key of the child.
Definition key.h:675
KeyChildIterator()
Definition key.h:631
Key< NDIM > child
Definition key.h:626
Key< NDIM > parent
Definition key.h:625
void serialize(Archive &ar)
Definition key.h:669
KeyChildIterator & operator++()
Pre-increment of an iterator (i.e., ++it).
Definition key.h:642
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:71
std::enable_if_t< NDIM >=NDIM2, uint64_t > distsq_bc(const array_of_bools< NDIM > &is_periodic, const std::array< std::size_t, NDIM2 > &axes) const
like "periodic" distsq() but only selects the prescribed axes
Definition key.h:332
double real_distsq_images_centers(const array_of_bools< NDIM > &is_periodic, const Tensor< double > &widths) const
like real_distsq_images() but between the centers of the boxes
Definition key.h:285
Key< VDIM > extract_back() const
extract a new key consisting of last VDIM dimensions of this
Definition key.h:532
Key< NDIM+LDIM > merge_with(const Key< LDIM > &rhs) const
merge with other key (ie concatenate), use level of rhs, not of this
Definition key.h:563
Level level() const
Definition key.h:170
uint64_t distsq_images(const array_of_bools< NDIM > &is_periodic) const
like distsq_bc() but to the nearest lattice image other than the home cell
Definition key.h:261
uint64_t distsq_bc(const array_of_bools< NDIM > &is_periodic) const
like distsq() but accounts for periodicity
Definition key.h:206
bool is_farther_out_than(const Key< NDIM > &other) const
return if the other key is pointing in the same direction and is farther out
Definition key.h:576
Vector< Translation, NDIM > l
Definition key.h:79
double real_distsq(const madness::Tensor< double > &widths) const
Definition key.h:194
Key neighbor(const Vector< Translation, NDIM > &disp) const
given a displacement, generate a neighbor key; ignore boundary conditions and disp's level
Definition key.h:469
Key(int n)
Constructor with given n and l=0.
Definition key.h:96
static constexpr uint64_t distsq_images_axis_max()
the largest contribution of one axis to distsq_images(); NDIM <= 6 of them sum below 2^63
Definition key.h:269
Key(Level n, const Vector< Translation, NDIM > &l)
Constructor with given n, l.
Definition key.h:89
bool is_parent_of(const Key &key) const
Definition key.h:393
double real_distsq_images(const array_of_bools< NDIM > &is_periodic, const Tensor< double > &widths) const
like real_distsq_bc() but to the nearest lattice image other than the home cell (see distsq_images())
Definition key.h:272
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
Key()
Default constructor makes an initialized key.
Definition key.h:86
bool is_valid() const
Checks if a key is valid.
Definition key.h:125
hashT hash() const
Definition key.h:159
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
bool operator==(const Key &other) const
Equality test.
Definition key.h:130
auto distsq_images_impl(const array_of_bools< NDIM > &is_periodic, F &&axis_distsq) const
Definition key.h:300
const Translation & operator[](std::size_t d) const
const accessor to elements of this->translation()
Definition key.h:180
Level n
Definition key.h:78
static constexpr uint64_t distsq_images_axis_cap
Definition key.h:293
static const std::size_t static_size
Definition key.h:74
bool operator!=(const Key &other) const
Definition key.h:138
Key< NDIM-VDIM > extract_complement_key(const std::array< int, VDIM > &v) const
extract a new key with the Translations complementary to the ones indicated in the v array
Definition key.h:549
Key< VDIM > extract_front() const
extract a new key consisting of first VDIM dimensions of this
Definition key.h:523
double real_distsq_bc(const array_of_bools< NDIM > &is_periodic, const Tensor< double > &widths) const
like real_distsq() but accounts for periodicity
Definition key.h:229
Key< VDIM > extract_key(const std::array< int, VDIM > &v) const
extract a new key with the Translations indicated in the v array
Definition key.h:541
bool is_neighbor_of(const Vector< T, NDIM > &simpt, const array_of_bools< NDIM > &bperiodic) const
True iff this box is a neighbor of a point in simulation coordinates.
Definition key.h:435
hashT hashval
Definition key.h:80
Key parent(int generation=1) const
Returns the key of the parent.
Definition key.h:366
void rehash()
Recomputes hashval ... presently only done when reading from external storage.
Definition key.h:587
const Vector< Translation, NDIM > & translation() const
Definition key.h:175
bool operator<(const Key &other) const
Comparison operator less than to enable storage in STL map.
Definition key.h:143
static Key< NDIM > invalid()
Returns an invalid key.
Definition key.h:111
uint64_t distsq() const
Definition key.h:185
Key neighbor(const Key< NDIM > &disp) const
given a displacement, generate a neighbor key; ignore boundary conditions and disp's level
Definition key.h:460
bool is_child_of(const Key &key) const
Definition key.h:377
void break_apart(Key< LDIM > &key1, Key< KDIM > &key2) const
break key into two low-dimensional keys
Definition key.h:500
A tensor is a multidimensional array.
Definition tensor.h:313
A simple, fixed dimension vector.
Definition vector.h:64
syntactic sugar for std::array<bool, N>
Definition array_of_bools.h:19
archive_array< T > wrap(const T *, unsigned int)
Factory function to wrap a dynamically allocated pointer as a typed archive_array.
Definition archive.h:914
static const double v
Definition hatom_sf_dirac.cc:20
Tensor< double > op(const Tensor< double > &x)
Definition kain.cc:508
#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
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:452
void hash_combine(hashT &seed, const T &v)
Combine hash values.
Definition worldhash.h:261
int64_t Translation
Definition key.h:59
Key< NDIM > displacement(const Key< NDIM > &source, const Key< NDIM > &target)
given a source and a target, return the displacement in translation
Definition key.h:609
int Level
Definition key.h:60
std::size_t hashT
The hash value type.
Definition worldhash.h:146
void foreach_child(const Key< NDIM > &parent, opT &op)
Applies op(key) to each child key of parent.
Definition key.h:683
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness hash.
Definition array_addons.h:78
static long abs(long a)
Definition tensor.h:214
static const double d
Definition nonlinschro.cc:121
static const double a
Definition nonlinschro.cc:118
static void load(const Archive &ar, Key< NDIM > &t)
Definition key.h:707
Default load of an object via serialize(ar, t).
Definition archive.h:667
static void store(const Archive &ar, const Key< NDIM > &t)
Definition key.h:722
Default store of an object via serialize(ar, t).
Definition archive.h:612
Defines and implements most of Tensor.
double dist(const Vector< double, 3 > v1, const Vector< double, 3 > v2)
distance between v1 and v2
Definition test_localizer.cc:38
constexpr std::size_t NDIM
Definition testgconv.cc:54
double source(const coordT &r)
Definition testperiodic.cc:48
Implement the madness:Vector class, an extension of std::array that supports some mathematical operat...
Defines hash functions for use in distributed containers.
FLOAT target(const FLOAT &x)
Definition y.cc:295