summaryrefslogtreecommitdiff
path: root/log-fourier_integrator.cpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2025-04-20 12:44:38 -0300
committerJaron Kent-Dobias <jaron@kent-dobias.com>2025-04-20 12:44:38 -0300
commit2ede6db86243e59223cd89e6debd7107d02eabd5 (patch)
treeb4371616f8aa124a5f43b6a31e1d199f628fdccf /log-fourier_integrator.cpp
parent70e78cf066aae300fede3745e9d9ea779a6264cc (diff)
downloadcode-2ede6db86243e59223cd89e6debd7107d02eabd5.tar.gz
code-2ede6db86243e59223cd89e6debd7107d02eabd5.tar.bz2
code-2ede6db86243e59223cd89e6debd7107d02eabd5.zip
Standardized saving and loading of files
Diffstat (limited to 'log-fourier_integrator.cpp')
-rw-r--r--log-fourier_integrator.cpp61
1 files changed, 3 insertions, 58 deletions
diff --git a/log-fourier_integrator.cpp b/log-fourier_integrator.cpp
index a032401..cf9819a 100644
--- a/log-fourier_integrator.cpp
+++ b/log-fourier_integrator.cpp
@@ -1,32 +1,6 @@
#include "log-fourier.hpp"
-#include "p-spin.hpp"
#include <getopt.h>
#include <iostream>
-#include <fstream>
-
-std::string logFourierFile(std::string prefix, unsigned p, unsigned s, Real λ, Real τ₀, Real β, unsigned log2n, Real Δτ, Real k) {
- return prefix + "_" + std::to_string(p) + "_" + std::to_string(s) + "_" + std::to_string(λ) + "_" + std::to_string(τ₀) + "_" + std::to_string(β) + "_" + std::to_string(log2n) + "_" + std::to_string(Δτ) + "_" + std::to_string(k) + ".dat";
-}
-
-std::tuple<std::vector<Complex>, std::vector<Complex>> RddfCtdfCt(LogarithmicFourierTransform& fft, const std::vector<Real>& C, const std::vector<Real>& R, unsigned p, unsigned s, Real λ) {
- std::vector<Real> dfC(C.size());
- std::vector<Real> RddfC(C.size());
- for (unsigned n = 0; n < C.size(); n++) {
- RddfC[n] = R[n] * ddf(λ, p, s, C[n]);
- dfC[n] = df(λ, p, s, C[n]);
- }
- std::vector<Complex> RddfCt = fft.fourier(RddfC, false);
- std::vector<Complex> dfCt = fft.fourier(dfC, true);
-
- return {RddfCt, dfCt};
-}
-
-Real estimateZ(LogarithmicFourierTransform& fft, const std::vector<Real>& C, const std::vector<Complex>& Ct, const std::vector<Real>& R, const std::vector<Complex>& Rt, unsigned p, unsigned s, Real λ, Real τ₀, Real β) {
- auto [RddfCt, dfCt] = RddfCtdfCt(fft, C, R, p, s, λ);
- Real Γ₀ = 1 + τ₀ / 2;
-
- return ((2 * Γ₀ * std::conj(Rt[0]) + pow(β, 2) * (RddfCt[0] * Ct[0] + dfCt[0] * std::conj(Rt[0]))) / Ct[0]).real();
-}
int main(int argc, char* argv[]) {
/* Model parameters */
@@ -119,16 +93,7 @@ int main(int argc, char* argv[]) {
Ȓₜ₋₁[n] = 1.0 / (μₜ₋₁ + 1i * fft.ν(n));
}
} else {
- std::ifstream cfile(logFourierFile("C", p, s, λ, τ₀, β₀, log2n, Δτ, k), std::ios::binary);
- cfile.read((char*)(Cₜ₋₁.data()), N * sizeof(Real));
- cfile.close();
- std::ifstream rfile(logFourierFile("R", p, s, λ, τ₀, β₀, log2n, Δτ, k), std::ios::binary);
- rfile.read((char*)(Rₜ₋₁.data()), N * sizeof(Real));
- rfile.close();
-
- Ĉₜ₋₁ = fft.fourier(Cₜ₋₁, true);
- Ȓₜ₋₁ = fft.fourier(Rₜ₋₁, false);
-
+ logFourierLoad(Cₜ₋₁, Rₜ₋₁, Ĉₜ₋₁, Ȓₜ₋₁, p, s, λ, τ₀, β₀, log2n, Δτ, k);
μₜ₋₁ = estimateZ(fft, Cₜ₋₁, Ĉₜ₋₁, Rₜ₋₁, Ȓₜ₋₁, p, s, λ, τ₀, β₀);
}
@@ -181,32 +146,12 @@ int main(int argc, char* argv[]) {
μₜ = μₜ₋₁;
γ /= 2;
} else {
- /* Integrate the energy using Simpson's rule */
- Real E = 0;
- for (unsigned n = 0; n < N/2-1; n++) {
- Real h₂ₙ = fft.t(2*n+1) - fft.t(2*n);
- Real h₂ₙ₊₁ = fft.t(2*n+2) - fft.t(2*n+1);
- Real f₂ₙ = Rₜ[2*n] * df(λ, p, s, Cₜ[2*n]);
- Real f₂ₙ₊₁ = Rₜ[2*n+1] * df(λ, p, s, Cₜ[2*n+1]);
- Real f₂ₙ₊₂ = Rₜ[2*n+2] * df(λ, p, s, Cₜ[2*n+2]);
- E += (h₂ₙ + h₂ₙ₊₁) / 6 * (
- (2 - h₂ₙ₊₁ / h₂ₙ) * f₂ₙ
- + pow(h₂ₙ + h₂ₙ₊₁, 2) / (h₂ₙ * h₂ₙ₊₁) * f₂ₙ₊₁
- + (2 - h₂ₙ / h₂ₙ₊₁) * f₂ₙ₊₂
- );
- }
- E *= β;
+ Real E = energy(fft, Cₜ, Rₜ, p, s, λ, β);
std::cerr << "\x1b[2K" << "\r";
std::cerr << β << " " << μₜ << " " << Ĉₜ[0].real() << " " << E << " " << γ << std::endl;
- std::ofstream outfile(logFourierFile("C", p, s, λ, τ₀, β, log2n, Δτ, k), std::ios::out | std::ios::binary);
- outfile.write((const char*)(Cₜ.data()), N * sizeof(Real));
- outfile.close();
-
- std::ofstream outfileR(logFourierFile("R", p, s, λ, τ₀, β, log2n, Δτ, k), std::ios::out | std::ios::binary);
- outfileR.write((const char*)(Rₜ.data()), N * sizeof(Real));
- outfileR.close();
+ logFourierSave(Cₜ, Rₜ, Ĉₜ, Ȓₜ, p, s, λ, τ₀, β, log2n, Δτ, k);
β += Δβ;
Cₜ₋₁ = Cₜ;