summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2025-05-08 18:11:35 -0300
committerJaron Kent-Dobias <jaron@kent-dobias.com>2025-05-08 18:11:35 -0300
commit73f4eaba3a08a5e1b85512868c3916c7fd4e4571 (patch)
tree999ceaa31419e37590309e3ccb4a8e9ec0a9c536
parent21a99431f02e799de9a811f9f02ad006fe27df6d (diff)
downloadcode-73f4eaba3a08a5e1b85512868c3916c7fd4e4571.tar.gz
code-73f4eaba3a08a5e1b85512868c3916c7fd4e4571.tar.bz2
code-73f4eaba3a08a5e1b85512868c3916c7fd4e4571.zip
Updated to work with shift
-rw-r--r--log-fourier.cpp16
-rw-r--r--log-fourier.hpp2
-rw-r--r--log-fourier_integrator.cpp22
-rw-r--r--log_get_energy.cpp11
4 files changed, 30 insertions, 21 deletions
diff --git a/log-fourier.cpp b/log-fourier.cpp
index 2e93e87..5b5955a 100644
--- a/log-fourier.cpp
+++ b/log-fourier.cpp
@@ -4,9 +4,9 @@
#include <fstream>
#include <types.hpp>
-LogarithmicFourierTransform::LogarithmicFourierTransform(unsigned N, Real k, Real Δτ, unsigned pad) : N(N), pad(pad), k(k), Δτ(Δτ) {
- τₛ = -0.5 * N;
- ωₛ = -0.5 * N;
+LogarithmicFourierTransform::LogarithmicFourierTransform(unsigned N, Real k, Real Δτ, unsigned pad, Real shift) : N(N), pad(pad), k(k), Δτ(Δτ) {
+ τₛ = -shift * N;
+ ωₛ = -(1-shift) * N;
sₛ = -0.5 * pad * N;
a = reinterpret_cast<Complex*>(FFTW_ALLOC_COMPLEX(pad*N));
â = reinterpret_cast<Complex*>(FFTW_ALLOC_COMPLEX(pad*N));
@@ -70,7 +70,7 @@ std::vector<Complex> LogarithmicFourierTransform::fourier(const std::vector<Real
}
FFTW_EXECUTE(a_to_â);
for (unsigned n = 0; n < pad*N; n++) {
- â[(pad*N / 2 + n) % (pad*N)] *= std::pow(II * σ, II * s(n) - k) * Γ(k - II * s(n));
+ â[(pad*N / 2 + n) % (pad*N)] *= std::exp(II*(0.5 * N + τₛ) * s(n) / Δτ) * std::pow(II * σ, II * s(n) - k) * Γ(k - II * s(n));
}
FFTW_EXECUTE(â_to_a);
for (unsigned n = 0; n < N; n++) {
@@ -98,7 +98,7 @@ std::vector<Real> LogarithmicFourierTransform::inverse(const std::vector<Complex
}
FFTW_EXECUTE(a_to_â);
for (unsigned n = 0; n < pad*N; n++) {
- â[(pad*N / 2 + n) % (pad*N)] *= std::pow(-II * σ, II * s(n) - k) * Γ(k - II * s(n));
+ â[(pad*N / 2 + n) % (pad*N)] *= std::exp(-II*(0.5 * N + τₛ) * s(n) / Δτ) * std::pow(-II * σ, II * s(n) - k) * Γ(k - II * s(n));
}
FFTW_EXECUTE(â_to_a);
for (unsigned n = 0; n < N; n++) {
@@ -113,8 +113,8 @@ std::vector<Real> LogarithmicFourierTransform::inverse(const std::vector<Complex
return c;
}
-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::string logFourierFile(std::string prefix, unsigned p, unsigned s, Real λ, Real τ₀, Real β, unsigned log2n, Real Δτ, Real shift) {
+ 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(shift) + ".dat";
}
void logFourierSave(const std::vector<Real>& C, const std::vector<Real>& R, const std::vector<Complex>& Ct, const std::vector<Complex>& Rt, unsigned p, unsigned s, Real λ, Real τ₀, Real β, unsigned log2n, Real Δτ, Real k) {
@@ -184,7 +184,7 @@ Real estimateZ(LogarithmicFourierTransform& fft, const std::vector<Real>& C, con
}
Real energy(const LogarithmicFourierTransform& fft, std::vector<Real>& C, const std::vector<Real>& R, unsigned p, unsigned s, Real λ, Real β) {
- Real E = 0;
+ Real E = fft.t(0) * (df(λ, p, s, 1) + R[0] * df(λ, p, s, C[0])) / 2;
for (unsigned n = 0; n < C.size()/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);
diff --git a/log-fourier.hpp b/log-fourier.hpp
index f0b53ef..b1e4bd1 100644
--- a/log-fourier.hpp
+++ b/log-fourier.hpp
@@ -21,7 +21,7 @@ private:
Real ωₛ;
Real sₛ;
public:
- LogarithmicFourierTransform(unsigned N, Real k, Real Δτ, unsigned pad = 4);
+ LogarithmicFourierTransform(unsigned N, Real k, Real Δτ, unsigned pad = 4, Real shift = 0.5);
~LogarithmicFourierTransform();
Real τ(unsigned n) const;
Real ω(unsigned n) const;
diff --git a/log-fourier_integrator.cpp b/log-fourier_integrator.cpp
index 55f358a..44ccce1 100644
--- a/log-fourier_integrator.cpp
+++ b/log-fourier_integrator.cpp
@@ -12,22 +12,23 @@ int main(int argc, char* argv[]) {
/* Log-Fourier parameters */
unsigned log2n = 8;
Real Δτ = 0.1;
- Real k = 0.1;
+ Real k = -0.01;
+ Real shift = 0.4;
/* Iteration parameters */
- Real ε = 1e-14;
+ Real ε = 1e-15;
Real γ₀ = 1;
- Real x = 0.5;
+ Real x = 1;
Real β₀ = 0;
- Real βₘₐₓ = 0.7;
+ Real βₘₐₓ = 20;
Real Δβ = 0.01;
bool loadData = false;
- unsigned stepsToRespond = 1000;
- unsigned pad = 4;
+ unsigned stepsToRespond = 1e7;
+ unsigned pad = 2;
int opt;
- while ((opt = getopt(argc, argv, "p:s:2:T:t:b:d:g:k:D:e:0:lS:x:P:")) != -1) {
+ while ((opt = getopt(argc, argv, "p:s:2:T:t:b:d:g:k:D:e:0:lS:x:P:h:")) != -1) {
switch (opt) {
case 'p':
p = atoi(optarg);
@@ -56,6 +57,9 @@ int main(int argc, char* argv[]) {
case 'D':
Δτ = atof(optarg);
break;
+ case 'h':
+ shift = atof(optarg);
+ break;
case 'e':
ε = atof(optarg);
break;
@@ -81,7 +85,7 @@ int main(int argc, char* argv[]) {
unsigned N = pow(2, log2n);
- LogarithmicFourierTransform fft(N, k, Δτ, pad);
+ LogarithmicFourierTransform fft(N, k, Δτ, pad, shift);
Real Γ₀ = 1;
Real μₜ₋₁ = Γ₀;
@@ -186,7 +190,7 @@ int main(int argc, char* argv[]) {
std::cerr << "\x1b[2K" << "\r";
std::cerr << β << " " << μₜ << " " << Ĉₜ[0].real() << " " << E << " " << γ << std::endl;
- logFourierSave(Cₜ, Rₜ, Ĉₜ, Ȓₜ, p, s, λ, τ₀, β, log2n, Δτ, k);
+ logFourierSave(Cₜ, Rₜ, Ĉₜ, Ȓₜ, p, s, λ, τ₀, β, log2n, Δτ, shift);
β += Δβ;
Cₜ₋₁ = Cₜ;
diff --git a/log_get_energy.cpp b/log_get_energy.cpp
index ae17f6f..b01034c 100644
--- a/log_get_energy.cpp
+++ b/log_get_energy.cpp
@@ -15,6 +15,8 @@ int main(int argc, char* argv[]) {
unsigned log2n = 8;
Real Δτ = 0.1;
Real k = 0.1;
+ unsigned pad = 2;
+ Real shift = 0.5;
/* Iteration parameters */
Real β₀ = 0;
@@ -23,7 +25,7 @@ int main(int argc, char* argv[]) {
int opt;
- while ((opt = getopt(argc, argv, "p:s:2:T:t:b:d:k:D:0:")) != -1) {
+ while ((opt = getopt(argc, argv, "p:s:2:T:t:b:d:k:D:0:h:")) != -1) {
switch (opt) {
case 'p':
p = atoi(optarg);
@@ -46,6 +48,9 @@ int main(int argc, char* argv[]) {
case 'k':
k = atof(optarg);
break;
+ case 'h':
+ shift = atof(optarg);
+ break;
case 'D':
Δτ = atof(optarg);
break;
@@ -59,7 +64,7 @@ int main(int argc, char* argv[]) {
unsigned N = pow(2, log2n);
- LogarithmicFourierTransform fft(N, k, Δτ, 4);
+ LogarithmicFourierTransform fft(N, k, Δτ, pad, shift);
std::vector<Real> C(N);
std::vector<Real> R(N);
@@ -71,7 +76,7 @@ int main(int argc, char* argv[]) {
std::cout << std::setprecision(16);
while (β += Δβ, β <= βₘₐₓ) {
- if (logFourierLoad(C, R, Ct, Rt, p, s, λ, τ₀, β, log2n, Δτ, k)) {
+ if (logFourierLoad(C, R, Ct, Rt, p, s, λ, τ₀, β, log2n, Δτ, shift)) {
Real e = energy(fft, C, R, p, s, λ, β);