-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlanczosDMRG_helpers.h
70 lines (67 loc) · 1.53 KB
/
lanczosDMRG_helpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @file lanczosDMRG_helpers.h
*
* @brief useful functions for the Lanczos ED
*
* @author Roger Melko
* @author Ivan Gonzalez
* @date $Date$
*
* $Revision$
*/
#ifndef LANCZOS_DMRG_HELPERS_H
#define LANCZOS_DMRG_HELPERS_H
#include <cmath> // for rand()
#include "blitz/array.h"
/**
* @brief A function to do the dot product of two wavefunctions
*
* @param V1 the wavefunction to multiply
* @param V2 the wavefunction to multiply
*/
inline double dotProduct(const blitz::Array<double,1>& V1,
const blitz::Array<double,1>& V2)
{
return sum(V1*V2);
}
/**
* @brief A function to get the norm of a wavefunction
*
* @param V the wavefunction to normalize
*
* Takes a wavefunction and return its norm, i.e. the square
* root of dot product with itself
*/
inline double calculateNorm(const blitz::Array<double,1>& V)
{
double norm = dotProduct(V,V);
return sqrt(norm);
}
/**
* @brief A function to randomize a wavefunction
*
* @param V the wavefunction to randomize
*
* Takes a wavefunction fills all its components with a random real number
*/
inline void randomize(blitz::Array<double,1>& V)
{
for (int i=0; i<V.size(); i++)
{
V(i) = rand()%10*0.1; //random starting vec
if ( (rand()%2) == 0) V(i) *= -1.0000001;
}
}
/**
* @brief A function to normalize a wavefunction
*
* @param V the wavefunction to normalize
*
* Takes a wavefunction and normalizes it
*/
inline void normalize(blitz::Array<double,1>& V)
{
double norm = calculateNorm(V);
V/=norm;
}
#endif // LANCZOS_DMRG_HELPERS_H