summaryrefslogtreecommitdiff
path: root/fourier_integrator.cpp
blob: 015a4b4a7355881053ce31828159689de6a537aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <getopt.h>
#include <vector>
#include <cmath>
#include <iostream>
#include <fftw3.h>
#include <complex>

using Real = double;
using Complex = std::complex<Real>;
using namespace std::complex_literals;

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);
}



int main(int argc, char* argv[]) {
  Real Δω = 1e-3;
  Real Δτ = 1e-3;
  Real τ₀ = 0;
  Real y = 0.5;
  unsigned iterations = 10;

  int opt;

  while ((opt = getopt(argc, argv, "d:T:t:y:I:")) != -1) {
    switch (opt) {
    case 'd':
      Δω = atof(optarg);
      break;
    case 'T':
      Δτ = atof(optarg);
      break;
    case 't':
      τ₀ = atof(optarg);
      break;
    case 'y':
      y = atof(optarg);
      break;
    case 'I':
      iterations = (unsigned)atof(optarg);
      break;
    default:
      exit(1);
    }
  }

  Real z = (-1+sqrt(1+2*τ₀)) / (2 * τ₀);
  Real Γ₀ = 1;

  Real ωₘₐₓ = 1 / Δτ;
  unsigned N = 2 * ωₘₐₓ / Δω + 1;
  unsigned n = ωₘₐₓ / Δω + 1;

  std::vector<Complex> Ĉ(N / 2 + 1);
  std::vector<Real> C(N);

  std::vector<Complex> Ř(N / 2 + 1);
  std::vector<Real> R(N);

  for (unsigned i = 0; i < n; i++) {
    Real τ = i * Δτ * M_PI;
    C[i] = Γ₀ / 2 * (exp(-z * τ) - z * τ₀ * exp(-τ / τ₀)) / (z - pow(z, 3) * pow(τ₀, 2));
    C[N - 1 - i] = Γ₀ / 2 * (exp(-z * τ) - z * τ₀ * exp(-τ / τ₀)) / (z - pow(z, 3) * pow(τ₀, 2));
  }

  /*
  for (unsigned it = 0; it < iterations; it++) {
    for (unsigned i = 0; i < n; i++) {
      Real ω = i * Δω;
      ĉ[i] = Γ₀ / ((pow(z, 2) + pow(ω, 2)) * (1 + pow(τ₀ * ω ,2)));
    }
  }

    ř[i] = (z - 1i * ω) / (pow(z, 2) + pow(ω, 2));
  std::vector<Real> c(n);
  */
  fftw_plan test = fftw_plan_dft_r2c_1d(N, C.data(), reinterpret_cast<fftw_complex*>(Ĉ.data()), 0);

  for (unsigned i = 0; i < n; i++) {
    Real τ = i * Δτ * M_PI;
    C[i] = Γ₀ / 2 * (exp(-z * τ) - z * τ₀ * exp(-τ / τ₀)) / (z - pow(z, 3) * pow(τ₀, 2));
    C[N - 1 - i] = Γ₀ / 2 * (exp(-z * τ) - z * τ₀ * exp(-τ / τ₀)) / (z - pow(z, 3) * pow(τ₀, 2));
  }

  fftw_execute(test);

  for (unsigned i = 0; i < Ĉ.size(); i++) {
    std::cout << i * Δτ * M_PI << " " << Ĉ[i].real() << std::endl;
  }

  /*
  for (unsigned i = 0; i < Ĉ.size(); i++) {
    std::cout << i * Δω << " " << Ĉ[i].real() * Δω / (2 * M_PI) << std::endl;
  }

  */
  return 0;
}