From 947daeb85321ed804bc3142623844b2617cb1b3e Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 30 Apr 2025 11:23:38 -0300 Subject: Support long double in the integrator --- log-fourier.cpp | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'log-fourier.cpp') diff --git a/log-fourier.cpp b/log-fourier.cpp index 47d5c5c..9ae70be 100644 --- a/log-fourier.cpp +++ b/log-fourier.cpp @@ -2,25 +2,26 @@ #include "p-spin.hpp" #include #include +#include LogarithmicFourierTransform::LogarithmicFourierTransform(unsigned N, Real k, Real Δτ, unsigned pad) : N(N), pad(pad), k(k), Δτ(Δτ) { τₛ = -0.5 * N; ωₛ = -0.5 * N; sₛ = -0.5 * pad * N; - a = reinterpret_cast(fftw_alloc_complex(pad*N)); - â = reinterpret_cast(fftw_alloc_complex(pad*N)); - fftw_import_wisdom_from_filename("fftw.wisdom"); - a_to_â = fftw_plan_dft_1d(pad*N, reinterpret_cast(a), reinterpret_cast(â), FFTW_BACKWARD, 0); - â_to_a = fftw_plan_dft_1d(pad*N, reinterpret_cast(â), reinterpret_cast(a), FFTW_BACKWARD, 0); - fftw_export_wisdom_to_filename("fftw.wisdom"); + a = reinterpret_cast(FFTW_ALLOC_COMPLEX(pad*N)); + â = reinterpret_cast(FFTW_ALLOC_COMPLEX(pad*N)); + FFTW_IMPORT_WISDOM("fftw.wisdom"); + a_to_â = FFTW_PLAN_DFT_1D(pad*N, reinterpret_cast(a), reinterpret_cast(â), FFTW_BACKWARD, 0); + â_to_a = FFTW_PLAN_DFT_1D(pad*N, reinterpret_cast(â), reinterpret_cast(a), FFTW_BACKWARD, 0); + FFTW_EXPORT_WISDOM("fftw.wisdom"); } LogarithmicFourierTransform::~LogarithmicFourierTransform() { - fftw_destroy_plan(a_to_â); - fftw_destroy_plan(â_to_a); - fftw_free(a); - fftw_free(â); - fftw_cleanup(); + FFTW_DESTROY_PLAN(a_to_â); + FFTW_DESTROY_PLAN(â_to_a); + FFTW_FREE(a); + FFTW_FREE(â); + FFTW_CLEANUP(); } Real LogarithmicFourierTransform::τ(unsigned n) const { @@ -47,9 +48,9 @@ Complex Γ(Complex z) { gsl_sf_result logΓ; gsl_sf_result argΓ; - gsl_sf_lngamma_complex_e(z.real(), z.imag(), &logΓ, &argΓ); + gsl_sf_lngamma_complex_e((double)z.real(), (double)z.imag(), &logΓ, &argΓ); - return exp(logΓ.val + 1i * argΓ.val); + return exp((Real)logΓ.val + II * (Real)argΓ.val); } std::vector LogarithmicFourierTransform::fourier(const std::vector& c, bool symmetric) { @@ -67,13 +68,13 @@ std::vector LogarithmicFourierTransform::fourier(const std::vector LogarithmicFourierTransform::inverse(const std::vector& C, const std::vector& R, const std::vector& Ct, const std::vector& Rt, unsigned p, unsigned s, Real λ, Real τ₀, Real β, unsigned log2n, Real Δτ, Real k) { - unsigned N = pow(2, log2n); + unsigned N = std::pow(2, log2n); 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(); @@ -141,7 +142,7 @@ bool logFourierLoad(std::vector& C, std::vector& R, std::vector& C, con auto [RddfCt, dfCt] = RddfCtdfCt(fft, C, R, p, s, λ); Real Γ₀ = 1.0; - return ((2 * Γ₀ * std::conj(Rt[0]) + pow(β, 2) * (RddfCt[0] * Ct[0] + dfCt[0] * std::conj(Rt[0]))) / Ct[0]).real(); + return ((2 * Γ₀ * std::conj(Rt[0]) + std::pow(β, 2) * (RddfCt[0] * Ct[0] + dfCt[0] * std::conj(Rt[0]))) / Ct[0]).real(); } Real energy(const LogarithmicFourierTransform& fft, std::vector& C, const std::vector& R, unsigned p, unsigned s, Real λ, Real β) { @@ -188,7 +189,7 @@ Real energy(const LogarithmicFourierTransform& fft, std::vector& C, const 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₂ₙ₊₁ + + std::pow(h₂ₙ + h₂ₙ₊₁, 2) / (h₂ₙ * h₂ₙ₊₁) * f₂ₙ₊₁ + (2 - h₂ₙ / h₂ₙ₊₁) * f₂ₙ₊₂ ); } -- cgit v1.2.3-70-g09d2