HPhi++  3.1.0
Multiply.cpp File Reference

File for giving multiplying functions to the wave vectors for TPQ and TE method. More...

#include "Common.hpp"
#include "diagonalcalc.hpp"
#include "Multiply.hpp"
#include "wrapperMPI.hpp"
#include "mltply.hpp"
#include <iostream>

Go to the source code of this file.

Functions

int Multiply (struct BindStruct *X)
 Function of calculating the i-th step norm as

\[ N^{(i)} = |L v_1^{(i)}-v_0^{(i)}/N_s | \]

and update the i+1-th wave vector as

\[ v_0^{(i+1)} = \frac{L v_1^{(i)}-v_0^{(i)}/N_s}{N^{(i)}} \]

for TPQ calculation. More...

 
int MultiplyForTEM (struct BindStruct *X, std::complex< double > **v2)
 Function of multiplying Hamiltonian for Time Evolution. More...
 

Detailed Description

File for giving multiplying functions to the wave vectors for TPQ and TE method.

Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Kota Ido (The University of Tokyo)

Definition in file Multiply.cpp.

Function Documentation

◆ Multiply()

int Multiply ( struct BindStruct X)

Function of calculating the i-th step norm as

\[ N^{(i)} = |L v_1^{(i)}-v_0^{(i)}/N_s | \]

and update the i+1-th wave vector as

\[ v_0^{(i+1)} = \frac{L v_1^{(i)}-v_0^{(i)}/N_s}{N^{(i)}} \]

for TPQ calculation.

Parameters
X[in] data list for calculation (idim_max and NsiteMPI)
Return values
0normally finished
-1unnormally finished
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)

Definition at line 44 of file Multiply.cpp.

References BindStruct::Check, BindStruct::Def, global_norm, CheckList::idim_max, LargeValue, MultiplyForTEM(), NormMPI_dv(), DefineList::NsiteMPI, NumAve, v0, and v1.

Referenced by CalcByTPQ().

47 {
48  long int i, i_max;
49  double Ns;
50  int rand_i;
51 
52  i_max = X->Check.idim_max;
53  Ns = 1.0*X->Def.NsiteMPI;
54  // mltply is in expec_energy.cpp v0=H*v1
55 #pragma omp parallel for default(none) private(i,rand_i) \
56  shared(v0, v1,NumAve) firstprivate(i_max, Ns, LargeValue)
57  for (i = 1; i <= i_max; i++) {
58  for (rand_i = 0; rand_i < NumAve; rand_i++) {
59  v0[i][rand_i] = LargeValue * v1[i][rand_i] - v0[i][rand_i] / Ns; //v0=(l-H/Ns)*v1
60  }
61  }
62  NormMPI_dv(i_max, NumAve, v0, global_norm);
63 #pragma omp parallel for default(none) private(i,rand_i) \
64 shared(v0,NumAve,global_norm) firstprivate(i_max)
65  for (i = 1; i <= i_max; i++)
66  for (rand_i = 0; rand_i < NumAve; rand_i++)
67  v0[i][rand_i] = v0[i][rand_i] / global_norm[rand_i];
68  return 0;
69 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int NumAve
Definition: global.cpp:43
std::complex< double > ** v0
Definition: global.cpp:20
void NormMPI_dv(long int ndim, int nstate, std::complex< double > **_v1, double *dnorm)
Compute norm of process-distributed vector .
Definition: wrapperMPI.cpp:344
std::complex< double > ** v1
Definition: global.cpp:21
int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
Definition: struct.hpp:57
double * global_norm
Definition: global.cpp:45
double LargeValue
Definition: global.cpp:42
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.hpp:305

◆ MultiplyForTEM()

int MultiplyForTEM ( struct BindStruct X,
std::complex< double > **  v2 
)

Function of multiplying Hamiltonian for Time Evolution.

Make \( |v_0 \rangle = |\psi(t+dt) \rangle \) from \( |v_1 \rangle = | \psi(t) \rangle \) and \( |v_0 \rangle = H |\psi(t) \rangle \).

Parameters
X[in] data list for calculation (idim_max and TimeSlice)
Return values
0normally finished
-1unnormally finished

Definition at line 80 of file Multiply.cpp.

References BindStruct::Check, BindStruct::Def, ParamList::ExpandCoef, global_norm, I(), CheckList::idim_max, mltply(), DefineList::Param, SumMPI_d(), ParamList::TimeSlice, v0, and v1.

Referenced by CalcByTEM(), and Multiply().

84 {
85  long int i, i_max;
86  int coef;
87  double dnorm = 0.0;
88  std::complex<double> tmp1 = 1.0;
89  std::complex<double> tmp2 = 0.0;
90  double dt = X->Def.Param.TimeSlice;
91 
92  //Make |v0> = |psi(t+dt)> from |v1> = |psi(t)> and |v0> = H |psi(t)>
93  i_max = X->Check.idim_max;
94  // mltply is in expec_energy.cpp v0=H*v1
95  if (dt < pow(10.0, -14)) {
96 #pragma omp parallel for default(none) private(i) \
97 shared(I,v0, v1, v2) firstprivate(i_max, dt, tmp2)
98  for (i = 1; i <= i_max; i++) {
99  tmp2 = v0[i][0];
100  v0[i][0] = v1[i][0]; //v0=(1-i*dt*H)*v1
101  v1[i][0] = tmp2;
102  v2[i][0] = 0.0 + I * 0.0;
103  }
104  mltply(X, 1, v2, v1);
105  }
106  else {
107  tmp1 *= -I * dt;
108 #pragma omp parallel for default(none) private(i) \
109 shared(v0, v1, v2,I) firstprivate(i_max, dt, tmp1, tmp2)
110  for (i = 1; i <= i_max; i++) {
111  tmp2 = v0[i][0];
112  v0[i][0] = v1[i][0] + tmp1 * tmp2; //v0=(1-i*dt*H)*v1
113  v1[i][0] = tmp2;
114  v2[i][0] = 0.0 + I * 0.0;
115  }
116  for (coef = 2; coef <= X->Def.Param.ExpandCoef; coef++) {
117  tmp1 *= -I * dt / (std::complex<double>)coef;
118  //v2 = H*v1 = H^coef |psi(t)>
119  mltply(X, 1, v2, v1);
120 
121 #pragma omp parallel for default(none) private(i) shared(I, v0, v1, v2) \
122 firstprivate(i_max, tmp1, myrank)
123  for (i = 1; i <= i_max; i++) {
124  v0[i][0] += tmp1 * v2[i][0];
125  v1[i][0] = v2[i][0];
126  v2[i][0] = 0.0 + I * 0.0;
127  }
128  }
129  }
130  dnorm = 0.0;
131 #pragma omp parallel for default(none) reduction(+: dnorm) private(i) shared(v0) \
132 firstprivate(i_max, dt)
133  for (i = 1; i <= i_max; i++) {
134  dnorm += real(conj(v0[i][0])*v0[i][0]);
135  }
136  dnorm = SumMPI_d(dnorm);
137  dnorm = sqrt(dnorm);
138  global_norm[0] = dnorm;
139 #pragma omp parallel for default(none) private(i) shared(v0) firstprivate(i_max, dnorm)
140  for (i = 1; i <= i_max; i++) {
141  v0[i][0] = v0[i][0] / dnorm;
142  }
143  return 0;
144 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
std::complex< double > ** v0
Definition: global.cpp:20
std::complex< double > I(0.0, 1.0)
int mltply(struct BindStruct *X, int nstate, std::complex< double > **tmp_v0, std::complex< double > **tmp_v1)
Parent function of multiplying the wavefunction by the Hamiltonian. . First, the calculation of diago...
Definition: mltply.cpp:56
std::complex< double > ** v1
Definition: global.cpp:21
double TimeSlice
Definition: struct.hpp:33
double * global_norm
Definition: global.cpp:45
struct ParamList Param
Definition: struct.hpp:243
double SumMPI_d(double norm)
MPI wrapper function to obtain sum of Double across processes.
Definition: wrapperMPI.cpp:222
int ExpandCoef
Definition: struct.hpp:35
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.hpp:305