#include #include #include #include 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& 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& 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 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; }