From c4933484df5f1eb3e611ccd031e14f17e674f10f Mon Sep 17 00:00:00 2001 From: Pauli Virtanen <pauli.t.virtanen@jyu.fi> Date: Fri, 12 Jan 2024 13:57:43 +0200 Subject: [PATCH] solver: add some docs, remove Results.g Add some docstrings. Remove results.g, which is unused (and was wrong too). --- usadelndsoc/solver.py | 72 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/usadelndsoc/solver.py b/usadelndsoc/solver.py index 3ca19ed..c8e2783 100644 --- a/usadelndsoc/solver.py +++ b/usadelndsoc/solver.py @@ -495,6 +495,13 @@ class Solver: @functools.wraps(_solve) def solve(self, omega, **kw): + """ + Solve for a given value of omega. + + Returns + ------- + result : Result + """ _log_solve.info(f"omega = {omega}") nx, ny = self.shape Phi00 = np.zeros_like(self._Phi) @@ -549,6 +556,13 @@ class Solver: return M def solve_many(self, omega, **kw): + """ + Solve for many values of omega. + + Returns + ------- + result : Result + """ omega0 = np.asarray(omega) omega = omega0.ravel() @@ -596,6 +610,14 @@ def _bcast_left(x, shape): class Result: + """Resulting Green function and derived quantities. + + Can describe either at a single Matsubara frequency, or multiple. + If multiple, the first array dimension corresponds to the + Matsubara frequencies. + + """ + def __init__(self, parent, omega, Phi, core=None): self._core = core if core is not None else parent._core self.shape = parent.shape @@ -608,10 +630,16 @@ class Result: @property def Delta(self): + """ + Order parameter. Shape (nx, ny, 2, 2). + """ return _DeltaArray(self.Omega) @property def G(self): + """ + Green function Nambu 11-block. Shape ([nw,] nx, ny, 2, 2). + """ g = self.Phi[..., 0, :, :] gt = self.Phi[..., 1, :, :] I = np.eye(2) @@ -621,6 +649,9 @@ class Result: @property def Gc(self): + """ + Green function Nambu 22-block. Shape ([nw,] nx, ny, 2, 2). + """ g = self.Phi[..., 0, :, :] gt = self.Phi[..., 1, :, :] I = np.eye(2) @@ -630,6 +661,9 @@ class Result: @property def F(self): + """ + Green function Nambu 12-block. Shape ([nw,] nx, ny, 2, 2). + """ g = self.Phi[..., 0, :, :] gt = self.Phi[..., 1, :, :] I = np.eye(2) @@ -639,6 +673,9 @@ class Result: @property def Fc(self): + """ + Green function Nambu 21-block. Shape ([nw,] nx, ny, 2, 2). + """ g = self.Phi[..., 0, :, :] gt = self.Phi[..., 1, :, :] I = np.eye(2) @@ -646,16 +683,6 @@ class Result: with np.errstate(invalid="ignore"): return 2 * s * np.linalg.solve(I + gt @ g, gt) - @property - def g(self): - g = self.Phi[..., 0, :, :] - gt = self.Phi[..., 0, :, :] - I = np.eye(2) - s = _bcast_left(np.sign(self.omega), g.shape) - with np.errstate(invalid="ignore"): - G = self.G - return s * np.linalg.solve(I + gt @ g, I - gt @ g) - def _get_J(self, omega, Phi): old_omega = self._core.omega self._core.omega = omega @@ -674,6 +701,9 @@ class Result: @property def S(self): + """ + Matrix density, dS/dOmega. Shape ([nw,] nx, ny, 4, 4) + """ if np.asarray(self.omega).ndim == 0: return self._get_S(self.omega, self.Phi) else: @@ -683,6 +713,16 @@ class Result: @property def J(self): + """ + Matrix current, dS/dA. Shape ([nw,] nx, ny, 4(direction), 4, 4). + + The meaning of the direction index is: + + - RIGHT (0): current exiting cell (x,y) to cell (x+1,y) + - UP (1): current exiting cell (x,y) to cell (x,y+1) + - LEFT (2): current entering cell (x,y) from cell (x-1,y) + - DOWN (3): current entering cell (x,y) from cell (x,y-1) + """ if np.asarray(self.omega).ndim == 0: return self._get_J(self.omega, self.Phi) else: @@ -692,11 +732,23 @@ class Result: @property def J_c(self): + """ + Spectral charge current. Shape ([nw,] nx, ny, 4(direction)). + + Direction index has same meaning as for :ref:`J`. + """ t3 = np.diag([1, 1, -1, -1]) return tr(self.J @ t3) @property def J_s(self): + """ + Spectral spin current. Shape ([nw,] nx, ny, 4(direction), 3(spin-direction)). + + The current direction index has same meaning as for :ref:`J`. + + The spin direction index means (x, y, z). + """ jx = tr(self.J @ np.kron(s0, sx)) jy = tr(self.J @ np.kron(s0, sy)) jz = tr(self.J @ np.kron(s0, sz)) -- GitLab