Skip to content
Snippets Groups Projects
Commit 49088332 authored by patavirt's avatar patavirt
Browse files

tests: more tests for GF

parent b3f2b33a
No related branches found
No related tags found
No related merge requests found
......@@ -10,13 +10,10 @@ import usadelndsoc.solver
usadelndsoc.logger.setLevel(logging.DEBUG)
def basic_setup(terminals=False, nx=15, ny=5):
Delta = np.zeros((4, 4))
Delta[:2, 2:] = np.eye(2)
Delta[2:, :2] = np.eye(2)
def basic_setup(terminals=False, nx=15, ny=5, h=0):
s = usadelndsoc.solver.Solver(nx=nx, ny=ny)
s.Omega[...] = 1j * Delta
s.Delta[...] = np.eye(2)
s.Omega[...] += np.diag([1, -1, -1, 1]) * h
s.alpha = 0.0
s.Lx = 10
s.Ly = 10
......@@ -40,10 +37,11 @@ def test_solve_dos():
assert_allclose(g, g_an, rtol=1e-4)
@pytest.mark.parametrize("omega", [0.5 + 0.8j, -0.5 + 0.8j])
def test_result_S_J0(omega):
s = basic_setup()
s.Delta[...] = np.eye(2)
@pytest.mark.parametrize(
"omega,h", [(w, h) for w in (0.5 + 0.8j, -0.5 + 0.8j) for h in (0, -0.5, 0.5)]
)
def test_result_S_J0(omega, h):
s = basic_setup(h=h)
res = s.solve_many(omega=omega)
S = res.S
......@@ -55,17 +53,20 @@ def test_result_S_J0(omega):
assert_allclose(S[:, :, 2:, 2:], vol * res.Gc)
# Check vs. analytic
Gan = omega / np.sqrt(omega**2 + 1) * np.eye(2)
Fan = 1 / np.sqrt(omega**2 + 1) * np.eye(2)
Fcan = 1 / np.sqrt(omega**2 + 1) * np.eye(2)
Gcan = -omega / np.sqrt(omega**2 + 1) * np.eye(2)
print(omega, h)
wp = omega - 1j * h
wm = omega + 1j * h
Gan = np.diag([wp / np.sqrt(wp**2 + 1), wm / np.sqrt(wm**2 + 1)])
Fan = np.diag([1 / np.sqrt(wp**2 + 1), 1 / np.sqrt(wm**2 + 1)])
Fcan = np.diag([1 / np.sqrt(wp**2 + 1), 1 / np.sqrt(wm**2 + 1)])
Gcan = -np.diag([wp / np.sqrt(wp**2 + 1), wm / np.sqrt(wm**2 + 1)])
shp = res.G.shape
assert_allclose(res.G, np.broadcast_to(Gan, shp))
assert_allclose(res.F, np.broadcast_to(Fan, shp))
assert_allclose(res.Fc, np.broadcast_to(Fcan, shp))
assert_allclose(res.Gc, np.broadcast_to(Gcan, shp))
assert_allclose(res.G, np.broadcast_to(Gan, shp), rtol=1e-5)
assert_allclose(res.F, np.broadcast_to(Fan, shp), rtol=1e-5)
assert_allclose(res.Fc, np.broadcast_to(Fcan, shp), rtol=1e-5)
assert_allclose(res.Gc, np.broadcast_to(Gcan, shp), rtol=1e-5)
# There are no gradients, hence no currents either
J = res.J
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment