35 #ifndef MADNESS_MRA_KEY_H__INCLUDED
36 #define MADNESS_MRA_KEY_H__INCLUDED
60 template<std::
size_t NDIM>
68 template<std::
size_t NDIM>
79 encode(
int dig)
const {
81 for (std::size_t j = 0; j <
NDIM; ++j) {
83 retval += ((l[j] >> (n - 1 - dig)) % 2) << j;
89 Vector<Translation, NDIM>
90 decode(Level
level, Translation k)
const {
91 Vector<Translation, NDIM>
L(0);
92 int twotoD = power<static_cast<int>(
NDIM)> ();
93 int powr = 1, divisor = 2;
94 for (Level i = 0; i <
level; ++i) {
95 Translation r = k % twotoD;
96 for (
int j = 0; j <
NDIM; ++j) {
97 L[NDIM - j - 1] += (r % divisor) * powr;
123 Key(Level n, Translation p) :
130 Key(
const int n,
const int l0) : n(n) {
131 MADNESS_ASSERT(
NDIM==1);
137 Key(
const int n,
const int l0,
const int l1,
const int l2) : n(n) {
138 MADNESS_ASSERT(
NDIM==3);
140 l[0]=l0; l[1]=l1; l[2]=l2;
165 if (hashval != other.hashval)
169 bool result = l == other.l;
170 if (result && hashval != other.hashval) {
171 print(
"!! keys same but hash is different", hashval,
172 other.hashval, *
this, other);
180 return !(*
this == other);
191 if (this->n > other.n) {
199 for (Level i = 0; i < nmin; ++i) {
200 int tthis = this->encode(i), tother = other.encode(i);
201 if (tthis != tother) {
202 return (tthis < tother);
232 for (std::size_t d = 0; d <
NDIM; ++d) {
252 for (std::size_t i = 0; i <
NDIM; ++i)
253 pl[i] = l[i] >> generation;
254 return Key(n - generation, pl);
260 if (this->n < key.n) {
263 else if (this->n == key.n) {
264 return (*
this == key);
267 Level dn = this->n - key.n;
269 return (mama == key);
284 Translation dist = 0;
286 for (std::size_t i=0; i<
NDIM; ++i)
288 Translation ll = std::abs(l[i] - key.l[i]);
289 if (bperiodic[i] && ll==TWON1) ll=1;
307 const unsigned int& dim1)
const {
311 const double twotoN = std::pow(2.0,
double(n));
312 MADNESS_ASSERT(dim0<
NDIM and dim1<
NDIM);
314 for (
unsigned int i=0; i<
NDIM; i++ ) {
317 MADNESS_ASSERT((x[i]>=0.0) and (x[i]<=1.0));
320 if ((i==dim0) or (i==dim1))
continue;
322 const int ll=int (x[i]*twotoN);
323 if (not (l[i]==ll)) contains=
false;
329 template<std::
size_t LDIM, std::
size_t KDIM>
333 MADNESS_ASSERT((LDIM+KDIM==
NDIM) or (LDIM==
NDIM));
336 for (
int i=0; i<static_cast<int>(LDIM); ++i) {
339 for (
size_t i=LDIM; i<
NDIM; ++i) {
347 template<std::
size_t LDIM>
350 for (
int i=0; i<static_cast<int>(
NDIM); ++i) t[i] =this->l[i];
351 for (
int i=0; i<static_cast<int>(LDIM); ++i) t[
NDIM+i]=rhs.
translation()[i];
362 for (
size_t i=0; i<
NDIM; ++i) {
380 template<std::
size_t NDIM>
382 operator<<(std::ostream& s, const Key<NDIM>& key) {
383 s <<
"(" << key.level() <<
"," << key.translation() <<
")";
392 template<
size_t NDIM>
394 MADNESS_ASSERT(source.
level()==target.
level());
407 template<std::
size_t NDIM>
408 class KeyChildIterator {
411 Vector<Translation, NDIM> p;
416 p(0), finished(true) {
420 parent(parent), child(parent.n + 1, parent.l * 2), p(0),
430 for (i = 0; i <
NDIM; ++i) {
434 for (std::size_t j = 0; j < i; ++j) {
441 finished = (i ==
NDIM);
447 operator bool()
const {
451 template<
typename Archive>
465 template<std::
size_t NDIM,
typename opT>
469 it(parent); it; ++it)
474 template<std::
size_t NDIM,
typename objT>
479 it(parent); it; ++it)
480 (obj ->* memfun)(it.key());
489 template <
class Archive, std::
size_t NDIM>
496 template <std::
size_t NDIM>
504 template <
class Archive, std::
size_t NDIM>
514 #endif // MADNESS_MRA_KEY_H__INCLUDED
void rehash()
Recomputes hashval ... presently only done when reading from external storage.
Definition: key.h:372
Key(const int n, const int l0)
easy constructor
Definition: key.h:130
static void store(const Archive &ar, const Key< NDIM > &t)
Definition: key.h:506
const Vector< Translation, NDIM > & translation() const
Definition: key.h:225
Key()
Default constructor makes an uninitialized key.
Definition: key.h:107
const int NDIM
Definition: tdse1.cc:44
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:348
KeyChildIterator(const Key< NDIM > &parent)
Definition: key.h:419
Key(int n)
Constructor with given n and l=0.
Definition: key.h:117
archive_array< T > wrap(const T *, unsigned int)
Factory function to wrap dynamically allocated pointer as typed archive_array.
Definition: archive.h:820
Defines hash functions for use in distributed containers.
const double L
Definition: 3dharmonic.cc:123
bool operator<(const Key &other) const
Comparison based upon depth first lexical order.
Definition: key.h:185
FLOAT target(const FLOAT &x)
Definition: y.cc:295
void foreach_child(const Key< NDIM > &parent, opT &op)
Applies op(key) to each child key of parent.
Definition: key.h:467
KeyChildIterator & operator++()
Pre-increment of an iterator (i.e., ++it)
Definition: key.h:426
const Key< NDIM > & key() const
Returns the key of the child.
Definition: key.h:459
Key(Level n, const Vector< Translation, NDIM > &l)
Constructor with given n, l.
Definition: key.h:111
KeyChildIterator()
Definition: key.h:415
Default store of a thingy via serialize(ar,t)
Definition: archive.h:708
uint64_t distsq() const
Definition: key.h:230
void break_apart(Key< LDIM > &key1, Key< KDIM > &key2) const
break key into two low-dimensional keys
Definition: key.h:330
bool is_invalid() const
Checks if a key is invalid.
Definition: key.h:152
void serialize(Archive &ar)
Definition: key.h:453
bool operator!=(const Key &other) const
Definition: key.h:179
bool is_valid() const
Checks if a key is valid.
Definition: key.h:158
Implements archive wrapping a binary filestream.
bool is_child_of(const Key &key) const
Definition: key.h:259
Key(const int n, const int l0, const int l1, const int l2)
easy constructor
Definition: key.h:137
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:306
#define max(a, b)
Definition: lda.h:53
Key parent(int generation=1) const
Returns the key of the parent.
Definition: key.h:248
bool is_parent_of(const Key &key) const
Definition: key.h:275
static Key< NDIM > invalid()
Returns an invalid key.
Definition: key.h:146
Level level() const
Definition: key.h:220
Default load of a thingy via serialize(ar,t)
Definition: archive.h:718
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness::Hash.
Definition: array.h:62
void hash_combine(hashT &seed, const T &v)
Combine hash values.
Definition: worldhash.h:259
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:393
std::size_t hashT
The hash value type.
Definition: worldhash.h:148
int Level
Definition: key.h:58
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:361
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:283
hashT hash() const
Definition: key.h:209
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
bool operator==(const Key &other) const
Equality test.
Definition: key.h:164
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
Key(Level n, Translation p)
Constructor from lexical index in depth first order.
Definition: key.h:123
int64_t Translation
Definition: key.h:57
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
Key neighbor(const Key< NDIM > &disp) const
given a displacement, generate a neighbor key; ignore boundary conditions and disp's level ...
Definition: key.h:299
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
static void load(const Archive &ar, Key< NDIM > &t)
Definition: key.h:491
Iterates in lexical order thru all children of a key.
Definition: key.h:61