#include #include #include #include #include using Real = double; class Point : public std::array { public: Real τ() const { return front(); } Real C() const { return back(); } }; unsigned p = 3; 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 I = 0; for (unsigned i = 0; i < Cₜ.size() - 1; i++) { unsigned j = Cₜ.size() - 1 - i; Real Δτ = Cₜ[i + 1].τ() - Cₜ[i].τ(); Real C = (Cₜ[j].C() + Cₜ[j - 1].C()) / 2; Real dC = (Cₜ[i + 1].C() - Cₜ[i].C()) / Δτ; I += Δτ * df(C) * dC; } return I; } Real energy(const std::vector& Ct) { Real I = 0; for (unsigned i = 0; i < Ct.size() - 1; i++) { Real Δτ = Ct[i + 1].τ() - Ct[i].τ(); Real C = (Ct[i].C() + Ct[i + 1].C()) / 2; Real dC = (Ct[i + 1].C() - Ct[i].C()) / Δτ; I += Δτ * df(C) * dC; } 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 + 0.0 * pow(y, 2); std::vector Cₜ; Cₜ.reserve(τₘₐₓ / Δτ + 1); Cₜ.push_back({0, 1}); while (Cₜ.back().τ() < τₘₐₓ) { Real dC = -z * Cₜ.back().C() - 2 * pow(y, 2) * integrate(Cₜ); Cₜ.push_back({Cₜ.back().τ() + Δτ, Cₜ.back().C() + Δτ * dC}); std::cout << Cₜ.back().τ() << " " << Cₜ.back().C() << std::endl; } std::cerr << - 2 * y * energy(Cₜ) << std::endl; return 0; }