Repository navigation
Expand file tree
/
Copy pathcdw3D.cpp
More file actions
167 lines (153 loc) · 3.55 KB
/
Copy pathcdw3D.cpp
File metadata and controls
167 lines (153 loc) · 3.55 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
#define PI acos(-1.0)
double epsilon(double kx, double ky, double kz, double t)
{
return -2*t*(cos(kx) + cos(ky) + cos(kz));
}
double square(double a)
{
return a*a;
}
double energy(double epsilon, double Delta)
{
return sqrt(square(epsilon) + square(Delta));
}
struct Parameters
{
double lambda;
double K;
double t;
int Nx, Ny, Nz;
double beta;
Parameters(double lambda, double K, double t, int Nx, int Ny, int Nz, double beta)
{
this->lambda = lambda;
this->K = K;
this->t = t;
this->Nx = Nx;
this->Ny = Ny;
this->Nz = Nz;
this->beta = beta;
}
};
double f(double Delta, const Parameters &p)
{
double s = 0;
double kx, ky, kz;
int nx, ny, nz;
for (nx = -p.Nx/4; nx < p.Nx/4; ++nx)
{
for (ny = -p.Ny/2; ny < p.Ny/2; ++ny)
{
for (nz = -p.Nz/2; nz < p.Nz/2; ++nz)
{
kx = 2*nx*PI/p.Nx;
ky = 2*ny*PI/p.Ny;
kz = 2*nz*PI/p.Nz;
s = s + (2*square(p.lambda)/p.K)*(1/energy(epsilon(kx, ky, kz, p.t), Delta))*tanh(p.beta*energy(epsilon(kx, ky, kz, p.t), Delta));
}
}
}
s = s/(p.Nx/2*p.Ny*p.Nz);
return s-1;
}
double fprime(double Delta, const Parameters &p)
{
double delta = 0.0001;
return (f(Delta + delta, p) - f(Delta, p))/delta;
}
double newton(double (*f)(double, const Parameters &), const Parameters &p)
{
double x0 = 0.3;
double x1 = x0 - f(x0, p)/fprime(x0, p);
int count = 0;
int iterationMax = 6;
while(fabs(x0 - x1) > 0.01)
{
count++;
x0 = x1;
x1 = x0 - f(x0, p)/fprime(x0, p);
if (count > iterationMax) exit(-1);
}
return x1;
}
int main(int argc, char **argv)
{
if (argc != 2)
{
cout << "T = argv[1]. " << endl;
return -1;
}
int Nx, Ny, Nz;
int nx, ny, nz;
double t;
double K;
double lambda;
double T;
double beta;
int N;
T = atof(argv[1]);
beta = 1.0/T;
t = 1;
K = 1;
lambda = 0.65;
Nx = 100;
Ny = 100;
Nz = 100;
double Delta;
Parameters p(lambda, K, t, Nx, Ny, Nz, beta);
/*double delta = 0.05;
int grids = 40;
ofstream ofile;
ofile.open("function.txt");
for (int i = 0; i < grids; ++i)
{
double temp = (i+0.5)*delta;
ofile << temp << " " << f(temp, p) << endl;
}
ofile.close();
ofile.open("derived.txt");
for (int i = 0; i < grids; ++i)
{
double temp = (i+0.5)*delta;
ofile << temp << " " << fprime(temp, p) << endl;
}
ofile.close();*/
Delta = newton(f, p);
cout << T << " " << Delta << endl;
/*double Delta;
double delta;
int count;
int iterationMax = 5000;
delta = 0.001;
count = 0;
Delta = 0;
while(true)
{
count++;
double s = 0;
double kx, ky;
for (nx = -Nx/4; nx < Nx/4; ++nx)
{
for (ny = -Ny/2; ny < Ny/2; ++ny)
{
kx = 2*PI*nx/Nx;
ky = 2*PI*ny/Ny;
s = s + (2*square(lambda)/K)*(1.0/energy(epsilon(kx, ky, t), Delta))*tanh(beta*energy(epsilon(kx, ky, t), Delta));
}
}
s = 2*s/N;
cout << s << endl;
if (count > iterationMax) break;
if (fabs(s - 1) < delta)
{
cout << T << " " << Delta << endl;
break;
}
else Delta = Delta + delta;
}*/
return 0;
}