mirror of
https://github.com/vale981/master-thesis
synced 2025-03-08 19:31:40 -05:00
176 lines
3.9 KiB
Org Mode
176 lines
3.9 KiB
Org Mode
#+PROPERTY: header-args :session eta_deriv :kernel python :pandoc t :async yes :tangle no
|
||
|
||
* Setup
|
||
** Jupyter
|
||
#+begin_src jupyter-python
|
||
%load_ext autoreload
|
||
%autoreload 2
|
||
%load_ext jupyter_spaces
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
|
||
** Matplotlib
|
||
#+begin_src jupyter-python
|
||
import matplotlib
|
||
import matplotlib.pyplot as plt
|
||
|
||
#matplotlib.use("TkCairo", force=True)
|
||
%gui tk
|
||
%matplotlib inline
|
||
plt.style.use('ggplot')
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
|
||
** Richard (old) HOPS
|
||
#+begin_src jupyter-python
|
||
import hierarchyLib
|
||
import hierarchyData
|
||
import numpy as np
|
||
|
||
from stocproc.stocproc import StocProc_FFT, StocProc_KLE
|
||
import bcf
|
||
from dataclasses import dataclass
|
||
import scipy
|
||
import scipy.misc
|
||
import scipy.signal
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
|
||
* Model Setup
|
||
Basic parameters.
|
||
#+begin_src jupyter-python
|
||
ω_c = 0 # center of spect. dens
|
||
σ = 1 # breadth BCF
|
||
t_max = 1
|
||
seed = 100
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
|
||
** BCF
|
||
#+begin_src jupyter-python
|
||
@dataclass
|
||
class GaussBCF:
|
||
σ: float
|
||
ω_c: float
|
||
|
||
def I(self, ω):
|
||
return (
|
||
np.exp(-(((ω - self.ω_c) / self.σ) ** 2) / 2)
|
||
,* 1
|
||
/ (np.sqrt(2 * np.pi) * self.σ)
|
||
)
|
||
|
||
def __call__(self, τ):
|
||
return (
|
||
np.exp(-(((τ - self.ω_c) / self.σ) ** 2) / 2)
|
||
,* 1
|
||
/ (np.sqrt(2 * np.pi) * self.σ)
|
||
)
|
||
|
||
def __bfkey__(self):
|
||
return self.σ, self.ω_c
|
||
|
||
|
||
@dataclass
|
||
class GaussBCFD:
|
||
α: GaussBCF
|
||
|
||
def __call__(self, τ):
|
||
# minus is important
|
||
return self.α(τ)/self.α.σ**4 * (self.α.σ**2 - τ**2 + 2*τ*self.α.ω_c-self.α.ω_c**2)
|
||
|
||
def __bfkey__(self):
|
||
return self.α.__bfkey__()
|
||
|
||
|
||
α = GaussBCF(σ, ω_c)
|
||
α_td = GaussBCFD(α)
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
|
||
*** Plot
|
||
#+begin_src jupyter-python
|
||
%%space plot
|
||
t = np.linspace(-t_max, t_max, 1000)
|
||
ω = np.linspace(ω_c - 10, ω_c + 10, 1000)
|
||
fig, axs = plt.subplots(2)
|
||
axs[0].plot(t, np.real(α(t)))
|
||
axs[0].plot(t, np.real(α_td(t)))
|
||
#axs[1].plot(ω, α_td.I(ω))
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
:RESULTS:
|
||
| <matplotlib.lines.Line2D | at | 0x7f6440edd8e0> |
|
||
| <matplotlib.lines.Line2D | at | 0x7f6440eddca0> |
|
||
[[file:./.ob-jupyter/9aa5b8d02f8eefddb2d3408172d2dd9d039cd715.png]]
|
||
:END:
|
||
|
||
** Make stoch-procs
|
||
Normal.
|
||
#+begin_src jupyter-python
|
||
η = StocProc_KLE(
|
||
α,
|
||
t_max,
|
||
seed=seed,
|
||
tol=1e-3
|
||
)
|
||
|
||
η_d = StocProc_KLE(
|
||
α_td,
|
||
t_max,
|
||
seed=seed,
|
||
tol=1e-3
|
||
)
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
: stocproc.method_kle - INFO - check 33 grid points
|
||
: stocproc.method_kle - INFO - calc_ac 3.504%, fredholm 6.936%, integr_intp 1.506%, spline 6.846%, calc_diff 51.646%, rest 29.561%
|
||
: stocproc.method_kle - INFO - auto ng SUCCESSFUL max diff 1.439e-04 < tol 1.000e-03 ng 33 num evec 3
|
||
: stocproc.method_kle - INFO - check 33 grid points
|
||
: stocproc.method_kle - INFO - calc_ac 9.515%, fredholm 4.745%, integr_intp 1.916%, spline 6.469%, calc_diff 49.757%, rest 27.598%
|
||
: stocproc.method_kle - INFO - auto ng SUCCESSFUL max diff 7.083e-04 < tol 1.000e-03 ng 33 num evec 3
|
||
: alpha_k is real
|
||
: alpha_k is real
|
||
#+RESULTS:
|
||
|
||
#+begin_src jupyter-python
|
||
η.new_process(seed=seed)
|
||
η_d.new_process(seed=seed)
|
||
#plt.plot(η.t, np.real(η()), label="orig")
|
||
plt.plot(η.t, np.real(η_d()))
|
||
plt.plot(η.t, scipy.misc.derivative(η, η.t, dx=1e-6).real, label="deriv")
|
||
plt.legend()
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
:RESULTS:
|
||
: stocproc.stocproc - INFO - use fixed seed (100) for new process
|
||
: stocproc.stocproc - INFO - use fixed seed (100) for new process
|
||
: <matplotlib.legend.Legend at 0x7f6440e64640>
|
||
[[file:./.ob-jupyter/5d3b2c2f7a314432526a414fe86aa167976b1e7c.png]]
|
||
:END:
|
||
|
||
|
||
# Time Derivative.
|
||
# #+begin_src jupyter-python
|
||
# Eta = StocProc_FFT(
|
||
# α_td.I,
|
||
# t_max,
|
||
# α_td,
|
||
# negative_frequencies=True,
|
||
# seed=seed,
|
||
# intgr_tol=1e-1,
|
||
# intpl_tol=1e-1,
|
||
# scale=1,
|
||
# )
|
||
# #+end_src
|
||
|
||
# #+RESULTS:
|
||
# : 1b9c7948-872d-4205-9cac-6aa91fa67982
|