32#ifndef MADNESS_MRA_KEY_H__INCLUDED
33#define MADNESS_MRA_KEY_H__INCLUDED
61 template<std::
size_t NDIM>
69 template<std::
size_t NDIM>
131 if (
n != other.
n)
return false;
132 for (
unsigned int i=0; i<
NDIM; i++)
133 if (
l[i] != other.
l[i])
return false;
138 return !(*
this == other);
146 if (
n < other.
n)
return true;
147 if (
n > other.
n)
return false;
149 for (
unsigned int i=0; i<
NDIM; i++) {
150 if (
l[i] < other.
l[i])
return true;
151 if (
l[i] > other.
l[i])
return false;
186 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
195 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
198 const auto real_width = widths(
d) * least_displacement_distance;
199 dist += real_width * real_width;
209 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
211 if (is_periodic[
d]) {
232 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
234 if (is_periodic[
d]) {
245 const auto least_displacement_distance = std::max(
std::abs(la) - 1,
static_cast<Translation>(0));
246 const auto real_width = widths(
d) * least_displacement_distance;
247 dsq += real_width * real_width;
254 template <std::
size_t NDIM2>
255 std::enable_if_t<NDIM >= NDIM2, uint64_t>
260 for (std::size_t
a = 0;
a < NDIM2; ++
a) {
261 const auto d = axes[
a];
264 if (is_periodic[
d]) {
294 for (std::size_t i = 0; i <
NDIM; ++i)
295 pl[i] =
l[i] >> generation;
296 return Key(
n - generation, pl);
302 if (this->n < key.
n) {
305 else if (this->n == key.
n) {
306 return (*
this == key);
309 Level dn = this->n - key.
n;
311 return (mama == key);
328 for (std::size_t i=0; i<
NDIM; ++i)
331 if (bperiodic[i] && ll==TWON1) ll=1;
358 const unsigned int& dim1)
const {
362 const double twotoN = std::pow(2.0,
double(
n));
365 for (
unsigned int i=0; i<
NDIM; i++ ) {
371 if ((i==dim0) or (i==dim1))
continue;
373 const int ll=int (x[i]*twotoN);
374 if (not (
l[i]==ll)) contains=
false;
380 template<std::
size_t LDIM, std::
size_t KDIM>
387 if constexpr((LDIM+KDIM==
NDIM) or (LDIM==
NDIM)) {
388 for (
size_t i=0; i<LDIM; ++i) {
391 for (
size_t i=LDIM; i<
NDIM; ++i) {
398 MADNESS_EXCEPTION(
"Key::break_apart: LDIM+KDIM must equal NDIM or LDIM==NDIM",1);
403 template<std::
size_t VDIM>
405 static_assert(VDIM <=
NDIM,
"VDIM must be less than or equal to NDIM");
407 for (
size_t i = 0; i < VDIM; ++i) t[i] = this->
translation()[i];
412 template<std::
size_t VDIM>
414 static_assert(VDIM <=
NDIM,
"VDIM must be less than or equal to NDIM");
416 for (
size_t i = 0; i < VDIM; ++i) t[i] = this->
translation()[
NDIM-VDIM+i];
421 template<std::
size_t VDIM>
424 for (
size_t i = 0; i < VDIM; ++i) t[i] = this->
translation()[v[i]];
429 template<std::
size_t VDIM>
434 auto v_complement = [](
const std::array<int, VDIM>&
v) {
435 std::array<int,
NDIM - VDIM> result;
436 for (std::size_t i = 0; i <
NDIM - VDIM; i++) result[i] = (
v.back() + i + 1) %
NDIM;
443 template<std::
size_t LDIM>
446 for (
size_t i=0; i<
NDIM; ++i) t[i] =this->l[i];
458 for (
size_t i=0; i<
NDIM; ++i) {
477 template<std::
size_t NDIM>
489 template<
size_t NDIM>
504 template<std::
size_t NDIM>
527 for (i = 0; i <
NDIM; ++i) {
531 for (std::size_t j = 0; j < i; ++j) {
544 operator bool()
const {
548 template<
typename Archive>
562 template<std::
size_t NDIM,
typename opT>
566 it(parent); it; ++it)
571 template<std::
size_t NDIM,
typename objT>
574 (objT::*memfun)(const
Key<
NDIM>&)) {
576 it(parent); it; ++it)
577 (obj ->* memfun)(it.key());
586 template <
class Archive, std::
size_t NDIM>
593 template <std::
size_t NDIM>
601 template <
class Archive, std::
size_t NDIM>
Provides BoundaryConditions.
Implements an archive wrapping a binary filestream.
Iterates in lexical order thru all children of a key.
Definition key.h:505
Vector< Translation, NDIM > p
Definition key.h:508
KeyChildIterator(const Key< NDIM > &parent)
Definition key.h:516
bool finished
Definition key.h:509
const Key< NDIM > & key() const
Returns the key of the child.
Definition key.h:556
KeyChildIterator()
Definition key.h:512
Key< NDIM > child
Definition key.h:507
Key< NDIM > parent
Definition key.h:506
void serialize(Archive &ar)
Definition key.h:550
KeyChildIterator & operator++()
Pre-increment of an iterator (i.e., ++it)
Definition key.h:523
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:70
Key< VDIM > extract_back() const
extract a new key consisting of last VDIM dimensions of this
Definition key.h:413
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:444
Level level() const
Definition key.h:169
uint64_t distsq_bc(const array_of_bools< NDIM > &is_periodic) const
like distsq() but accounts for periodicity
Definition key.h:205
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:457
Vector< Translation, NDIM > l
Definition key.h:78
double real_distsq(const madness::Tensor< double > &widths) const
Definition key.h:193
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:350
Key(int n)
Constructor with given n and l=0.
Definition key.h:95
Key(Level n, const Vector< Translation, NDIM > &l)
Constructor with given n, l.
Definition key.h:88
bool is_parent_of(const Key &key) const
Definition key.h:317
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
Key()
Default constructor makes an uninitialized key.
Definition key.h:85
bool is_valid() const
Checks if a key is valid.
Definition key.h:124
hashT hash() const
Definition key.h:158
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:357
bool is_invalid() const
Checks if a key is invalid.
Definition key.h:119
bool operator==(const Key &other) const
Equality test.
Definition key.h:129
const Translation & operator[](std::size_t d) const
const accessor to elements of this->translation()
Definition key.h:179
Level n
Definition key.h:77
static const std::size_t static_size
Definition key.h:73
uint64_t distsq_bc(const array_of_bools< NDIM > &is_periodic, const std::array< std::size_t, NDIM2 > &axes) const
Definition key.h:256
bool operator!=(const Key &other) const
Definition key.h:137
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:430
Key< VDIM > extract_front() const
extract a new key consisting of first VDIM dimensions of this
Definition key.h:404
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:228
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:422
hashT hashval
Definition key.h:79
Key parent(int generation=1) const
Returns the key of the parent.
Definition key.h:290
void rehash()
Recomputes hashval ... presently only done when reading from external storage.
Definition key.h:468
const Vector< Translation, NDIM > & translation() const
Definition key.h:174
bool operator<(const Key &other) const
Comparison operator less than to enable storage in STL map.
Definition key.h:142
static Key< NDIM > invalid()
Returns an invalid key.
Definition key.h:110
uint64_t distsq() const
Definition key.h:184
Key neighbor(const Key< NDIM > &disp) const
given a displacement, generate a neighbor key; ignore boundary conditions and disp's level
Definition key.h:341
bool is_child_of(const Key &key) const
Definition key.h:301
void break_apart(Key< LDIM > &key1, Key< KDIM > &key2) const
break key into two low-dimensional keys
Definition key.h:381
A tensor is a multidimensional array.
Definition tensor.h:317
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
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:401
void hash_combine(hashT &seed, const T &v)
Combine hash values.
Definition worldhash.h:260
int64_t Translation
Definition key.h:58
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:490
int Level
Definition key.h:59
std::size_t hashT
The hash value type.
Definition worldhash.h:145
void foreach_child(const Key< NDIM > &parent, opT &op)
Applies op(key) to each child key of parent.
Definition key.h:564
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:218
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:588
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:603
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