32#ifndef MADNESS_MRA_KEY_H__INCLUDED
33#define MADNESS_MRA_KEY_H__INCLUDED
57 template<std::
size_t NDIM>
65 template<std::
size_t NDIM>
121 if (
n != other.
n)
return false;
122 for (
unsigned int i=0; i<
NDIM; i++)
123 if (
l[i] != other.
l[i])
return false;
128 return !(*
this == other);
136 if (
n < other.
n)
return true;
137 if (
n > other.
n)
return false;
139 for (
unsigned int i=0; i<
NDIM; i++) {
140 if (
l[i] < other.
l[i])
return true;
141 if (
l[i] > other.
l[i])
return false;
171 for (std::size_t
d = 0;
d <
NDIM; ++
d) {
191 for (std::size_t i = 0; i <
NDIM; ++i)
192 pl[i] =
l[i] >> generation;
193 return Key(
n - generation, pl);
199 if (this->n < key.
n) {
202 else if (this->n == key.
n) {
203 return (*
this == key);
206 Level dn = this->n - key.
n;
208 return (mama == key);
225 for (std::size_t i=0; i<
NDIM; ++i)
228 if (bperiodic[i] && ll==TWON1) ll=1;
246 const unsigned int& dim1)
const {
250 const double twotoN = std::pow(2.0,
double(
n));
253 for (
unsigned int i=0; i<
NDIM; i++ ) {
259 if ((i==dim0) or (i==dim1))
continue;
261 const int ll=int (x[i]*twotoN);
262 if (not (
l[i]==ll)) contains=
false;
268 template<std::
size_t LDIM, std::
size_t KDIM>
275 for (
int i=0; i<static_cast<int>(LDIM); ++i) {
280 for (
size_t i=LDIM; i<
NDIM; ++i) {
290 template<std::
size_t VDIM>
293 for (
int i = 0; i < VDIM; ++i) t[i] = this->
translation()[v[i]];
298 template<std::
size_t VDIM>
303 auto v_complement = [](
const std::array<int, VDIM>&
v) {
304 std::array<int,
NDIM - VDIM> result;
305 for (std::size_t i = 0; i <
NDIM - VDIM; i++) result[i] = (
v.back() + i + 1) %
NDIM;
312 template<std::
size_t LDIM>
315 for (
int i=0; i<static_cast<int>(
NDIM); ++i) t[i] =this->l[i];
316 for (
int i=0; i<static_cast<int>(LDIM); ++i) t[
NDIM+i]=rhs.
translation()[i];
327 for (
size_t i=0; i<
NDIM; ++i) {
346 template<std::
size_t NDIM>
358 template<
size_t NDIM>
373 template<std::
size_t NDIM>
396 for (i = 0; i <
NDIM; ++i) {
400 for (std::size_t j = 0; j < i; ++j) {
413 operator bool()
const {
417 template<
typename Archive>
431 template<std::
size_t NDIM,
typename opT>
435 it(parent); it; ++it)
440 template<std::
size_t NDIM,
typename objT>
443 (objT::*memfun)(const
Key<
NDIM>&)) {
445 it(parent); it; ++it)
446 (obj ->* memfun)(it.key());
455 template <
class Archive, std::
size_t NDIM>
462 template <std::
size_t NDIM>
470 template <
class Archive, std::
size_t NDIM>
Implements an archive wrapping a binary filestream.
Iterates in lexical order thru all children of a key.
Definition key.h:374
Vector< Translation, NDIM > p
Definition key.h:377
KeyChildIterator(const Key< NDIM > &parent)
Definition key.h:385
bool finished
Definition key.h:378
const Key< NDIM > & key() const
Returns the key of the child.
Definition key.h:425
KeyChildIterator()
Definition key.h:381
Key< NDIM > child
Definition key.h:376
Key< NDIM > parent
Definition key.h:375
void serialize(Archive &ar)
Definition key.h:419
KeyChildIterator & operator++()
Pre-increment of an iterator (i.e., ++it)
Definition key.h:392
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:66
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:313
Level level() const
Definition key.h:159
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:326
Vector< Translation, NDIM > l
Definition key.h:74
Key(int n)
Constructor with given n and l=0.
Definition key.h:90
Key(Level n, const Vector< Translation, NDIM > &l)
Constructor with given n, l.
Definition key.h:84
bool is_parent_of(const Key &key) const
Definition key.h:214
Key()
Default constructor makes an uninitialized key.
Definition key.h:81
bool is_valid() const
Checks if a key is valid.
Definition key.h:114
hashT hash() const
Definition key.h:148
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:245
bool is_invalid() const
Checks if a key is invalid.
Definition key.h:109
bool operator==(const Key &other) const
Equality test.
Definition key.h:119
Level n
Definition key.h:73
static const std::size_t static_size
Definition key.h:69
bool operator!=(const Key &other) const
Definition key.h:127
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:299
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:291
hashT hashval
Definition key.h:75
Key parent(int generation=1) const
Returns the key of the parent.
Definition key.h:187
void rehash()
Recomputes hashval ... presently only done when reading from external storage.
Definition key.h:337
const Vector< Translation, NDIM > & translation() const
Definition key.h:164
bool operator<(const Key &other) const
Comparison operator less than to enable storage in STL map.
Definition key.h:132
static Key< NDIM > invalid()
Returns an invalid key.
Definition key.h:104
uint64_t distsq() const
Definition key.h:169
Key neighbor(const Key< NDIM > &disp) const
given a displacement, generate a neighbor key; ignore boundary conditions and disp's level
Definition key.h:238
bool is_child_of(const Key &key) const
Definition key.h:198
void break_apart(Key< LDIM > &key1, Key< KDIM > &key2) const
break key into two low-dimensional keys
Definition key.h:269
bool is_neighbor_of(const Key &key, const std::vector< bool > &bperiodic) const
Assuming keys are at the same level, returns true if displaced by no more than 1 in any direction.
Definition key.h:222
A simple, fixed dimension vector.
Definition vector.h:64
archive_array< T > wrap(const T *, unsigned int)
Factory function to wrap a dynamically allocated pointer as a typed archive_array.
Definition archive.h:913
static const double v
Definition hatom_sf_dirac.cc:20
Tensor< double > op(const Tensor< double > &x)
Definition kain.cc:508
#define MADNESS_PRAGMA_GCC(x)
Definition madness_config.h:205
#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:397
void hash_combine(hashT &seed, const T &v)
Combine hash values.
Definition worldhash.h:260
int64_t Translation
Definition key.h:54
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:359
int Level
Definition key.h:55
static double pop(std::vector< double > &v)
Definition SCF.cc:113
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:433
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 void load(const Archive &ar, Key< NDIM > &t)
Definition key.h:457
Default load of an object via serialize(ar, t).
Definition archive.h:666
static void store(const Archive &ar, const Key< NDIM > &t)
Definition key.h:472
Default store of an object via serialize(ar, t).
Definition archive.h:611
double dist(const Vector< double, 3 > v1, const Vector< double, 3 > v2)
distance between v1 and v2
Definition test_localizer.cc:38
static const std::size_t NDIM
Definition testpdiff.cc:42
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