aboutsummaryrefslogtreecommitdiff
path: root/test/test_graphic.py
diff options
context:
space:
mode:
authorTim Suhling <tim@suhling.com>2024-07-19 15:05:01 +0200
committerTim Suhling <tim@suhling.com>2024-07-19 15:05:01 +0200
commit536259f5e608a941b3adb02b83375e804198cafb (patch)
treec7bdbcf80d8f3f61280c1d66a8fefee54e2427c6 /test/test_graphic.py
parent665bff51d17329259a80e0aeae1b2af2f4caaa26 (diff)
parent0ff1bad0697ca7373a9716b80ce4b56d6a20992a (diff)
Merge branch 'solve'
Diffstat (limited to 'test/test_graphic.py')
-rw-r--r--test/test_graphic.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/test_graphic.py b/test/test_graphic.py
new file mode 100644
index 0000000..73d8b82
--- /dev/null
+++ b/test/test_graphic.py
@@ -0,0 +1,48 @@
+from pathlib import Path
+import sys
+sys.path.insert(0, str(Path.cwd().parent/'schroedinger'))
+
+import pytest
+import numpy as np
+
+import matplotlib.pyplot as plt
+
+from schroedinger import (
+ Config, potential_interp, build_potential, solve_schroedinger
+)
+
+potential = {}
+e = {}
+v = {}
+
+FORMS = ['asymmetric', 'double_linear', 'double_cubic']
+
+@pytest.mark.parametrize('form', FORMS)
+def test_potential(form):
+ potential_prec = np.loadtxt(f'test/{form}/potential.dat')
+ assert np.allclose(potential[form], potential_prec, rtol=1e-2, atol=1e-2)
+
+
+@pytest.mark.parametrize('form', FORMS)
+def test_e(form):
+ e_prec = np.loadtxt(f'test/{form}/energies.dat')
+ assert np.allclose(e[form], e_prec, rtol=1e-2, atol=1e-2)
+
+
+@pytest.mark.parametrize('form', FORMS)
+def test_v(form):
+ v_prec = np.loadtxt(f'test/{form}/wavefuncs.dat')[:, 1:]
+ assert np.allclose(v[form], v_prec, rtol=1e-2, atol=1e-2)
+
+
+def setup_module():
+ global conf
+ global potential
+ global e
+ global v
+
+ for form in FORMS:
+ conf = Config(f'test/{form}.inp')
+ potential[form], delta = build_potential(conf)
+ e[form], v[form] = solve_schroedinger(conf.mass, potential[form][:, 1],
+ delta, conf.eig_interval)