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
|
#include <getopt.h>
#include <vector>
#include <cmath>
#include <iostream>
using Real = double;
unsigned p = 2;
Real f(Real q) {
return 0.5 * pow(q, p);
}
Real df(Real q) {
return 0.5 * p * pow(q, p - 1);
}
Real ddf(Real q) {
return 0.5 * p * (p - 1) * pow(q, p - 2);
}
Real integrate(const std::vector<Real>& C, Real Δτ, Real τ₀) {
Real I = 0;
#pragma omp parallel for reduction(+:I)
for (unsigned σ = 0; σ < C.size() - 1; σ++) {
unsigned τ_σ = C.size() - 1 - σ;
Real Cτ_σ = (C[τ_σ] + C[τ_σ - 1]) / 2;
Real dCσ = (C[σ + 1] - C[σ]) / Δτ;
Real dddC = 0;
if (σ > 3 && σ < C.size() && C.size() > 3) {
dddC += (C[τ_σ] - 3 * C[τ_σ+1] + 3 * C[τ_σ+2] - C[τ_σ+3]) / pow(Δτ, 3);
}
I += Δτ * df(Cτ_σ) * (dCσ - pow(τ₀, 2) * dddC);
}
return I;
}
Real energy(const std::vector<Real>& C, Real Δτ, Real τ₀) {
Real I = 0;
for (unsigned σ = 0; σ < C.size() - 1; σ++) {
Real Cσ = (C[σ] + C[σ + 1]) / 2;
Real dC = (C[σ + 1] - C[σ]) / Δτ;
Real dddC = 0;
if (σ > 1 && σ < C.size() - 2 && C.size() > 3) {
dddC = (C[σ+1] - 3 * C[σ] + 3 * C[σ-1] - C[σ-2]) / pow(Δτ, 3);
}
I += Δτ * df(Cσ) * (dC - pow(τ₀, 2) * dddC);
}
return I;
}
int main(int argc, char* argv[]) {
Real Δτ = 1e-3;
Real τₘₐₓ = 1e3;
Real τ₀ = 0;
Real y = 0.5;
int opt;
while ((opt = getopt(argc, argv, "d:T:t:y:")) != -1) {
switch (opt) {
case 'd':
Δτ = atof(optarg);
break;
case 'T':
τₘₐₓ = atof(optarg);
break;
case 't':
τ₀ = atof(optarg);
break;
case 'y':
y = atof(optarg);
break;
default:
exit(1);
}
}
Real z = 0.5;
Real Γ₀ = 0.5 * (2 * τ₀) / (sqrt(1 + 2 * τ₀) - 1);
Real τ = 0;
std::vector<Real> C;
C.reserve(τₘₐₓ / Δτ + 1);
C.push_back(1);
while (std::cout << τ << " " << C.back() << std::endl, τ < τₘₐₓ) {
τ += Δτ;
Real dC = -z * C.back() - 2 / Γ₀ * pow(y, 2) * integrate(C, Δτ, τ₀);
C.push_back(C.back() + Δτ * dC);
}
std::cerr << - 2 * y / Γ₀ * energy(C, Δτ, τ₀) << std::endl;
return 0;
}
|