HΦ  3.2.0
Multiply.c
Go to the documentation of this file.
1 /* HPhi - Quantum Lattice Model Simulator */
2 /* Copyright (C) 2015 The University of Tokyo */
3 
4 /* This program is free software: you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation, either version 3 of the License, or */
7 /* (at your option) any later version. */
8 
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13 
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 
17 #include "Common.h"
18 #include "diagonalcalc.h"
19 #include "Multiply.h"
20 #include "wrapperMPI.h"
21 #include "mltply.h"
22 
42 int Multiply
43 (
44  struct BindStruct *X
45  )
46 {
47  long int i,i_max;
48  double complex dnorm;
49  double Ns;
50 
51  i_max=X->Check.idim_max;
52  Ns = 1.0*X->Def.NsiteMPI;
53  // mltply is in expec_energy.c v0=H*v1
54  dnorm=0.0;
55 #pragma omp parallel for default(none) reduction(+: dnorm) private(i) shared(v0, v1) firstprivate(i_max, Ns, LargeValue)
56  for(i = 1; i <= i_max; i++){
57  v0[i]=LargeValue*v1[i]-v0[i]/Ns; //v0=(l-H/Ns)*v1
58  dnorm += conj(v0[i])*v0[i];
59  }
60  dnorm=SumMPI_dc(dnorm);
61  dnorm=sqrt(dnorm);
62  global_norm = dnorm;
63 #pragma omp parallel for default(none) private(i) shared(v0) firstprivate(i_max, dnorm)
64  for(i=1;i<=i_max;i++){
65  v0[i] = v0[i]/dnorm;
66  }
67  return 0;
68 }
69 
80 (
81  struct BindStruct *X
82  )
83 {
84 
85  long int i,i_max;
86  int coef;
87  double complex dnorm=0.0;
88  double complex tmp1 = 1.0;
89  double complex 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.c v0=H*v1
95  if(dt <pow(10.0, -14)){
96 #pragma omp parallel for default(none) reduction(+: dnorm) private(i) shared(v0, v1, v2) firstprivate(i_max, dt, tmp2)
97  for(i = 1; i <= i_max; i++){
98  tmp2 = v0[i];
99  v0[i]=v1[i]; //v0=(1-i*dt*H)*v1
100  v1[i]=tmp2;
101  v2[i]= 0.0 + I*0.0;
102  }
103  mltply(X, v2, v1);
104  }
105  else {
106  tmp1 *= -I * dt;
107 #pragma omp parallel for default(none) reduction(+: dnorm) private(i) shared(v0, v1, v2) firstprivate(i_max, dt, tmp1, tmp2)
108  for (i = 1; i <= i_max; i++) {
109  tmp2 = v0[i];
110  v0[i] = v1[i] + tmp1 * tmp2; //v0=(1-i*dt*H)*v1
111  v1[i] = tmp2;
112  v2[i] = 0.0 + I * 0.0;
113  }
114  for (coef = 2; coef <= X->Def.Param.ExpandCoef; coef++) {
115  tmp1 *= -I * dt / (double complex) coef;
116  //v2 = H*v1 = H^coef |psi(t)>
117  mltply(X, v2, v1);
118 
119 #pragma omp parallel for default(none) private(i) shared(v0, v1, v2) firstprivate(i_max, tmp1, myrank)
120  for (i = 1; i <= i_max; i++) {
121  v0[i] += tmp1 * v2[i];
122  v1[i] = v2[i];
123  v2[i] = 0.0 + I * 0.0;
124  }
125  }
126  }
127  dnorm=0.0;
128 #pragma omp parallel for default(none) reduction(+: dnorm) private(i) shared(v0) firstprivate(i_max, dt)
129  for(i = 1; i <= i_max; i++){
130  dnorm += conj(v0[i])*v0[i];
131  }
132  dnorm=SumMPI_dc(dnorm);
133  dnorm=sqrt(dnorm);
134  global_norm = dnorm;
135 #pragma omp parallel for default(none) private(i) shared(v0) firstprivate(i_max, dnorm)
136  for(i=1;i<=i_max;i++){
137  v0[i] = v0[i]/dnorm;
138  }
139  return 0;
140 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
int mltply(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Parent function of multiplying the wavefunction by the Hamiltonian. . First, the calculation of diago...
Definition: mltply.c:56
double complex SumMPI_dc(double complex norm)
MPI wrapper function to obtain sum of Double complex across processes.
Definition: wrapperMPI.c:205
unsigned long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.h:303
double complex * v1
Definition: global.h:35
double complex * v2
Definition: global.h:36
int Multiply(struct BindStruct *X)
Function of calculating the i-th step norm as and update the i+1-th wave vector as for TPQ calculat...
Definition: Multiply.c:43
double global_norm
Definition: global.h:67
Bind.
Definition: struct.h:409
double TimeSlice
Definition: struct.h:33
unsigned int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
Definition: struct.h:57
struct ParamList Param
Definition: struct.h:241
int MultiplyForTEM(struct BindStruct *X)
Function of multiplying Hamiltonian for Time Evolution.
Definition: Multiply.c:80
int ExpandCoef
Definition: struct.h:35
struct EDMainCalStruct X
Definition: struct.h:432
double complex * v0
Definition: global.h:34
struct CheckList Check
Size of the Hilbert space.
Definition: struct.h:411
double LargeValue
Definition: global.h:64