From 3907db7c10c6745dda60050d21036a602f2c3570 Mon Sep 17 00:00:00 2001 From: Thomas Albers Raviola Date: Fri, 19 Jul 2024 16:53:53 +0200 Subject: Add documentation to common library --- schroedinger/schroedinger.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/schroedinger/schroedinger.py b/schroedinger/schroedinger.py index 4556d92..3554c6b 100644 --- a/schroedinger/schroedinger.py +++ b/schroedinger/schroedinger.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import TextIO +from typing import TextIO, Type import numpy as np from numpy.polynomial import Polynomial @@ -9,7 +9,14 @@ from scipy.interpolate import CubicSpline from scipy.linalg import eigh_tridiagonal +Interpolator = Type[callable] | Type[Polynomial] | Type[CubicSpline] +# type Interpolator = callable | Polynomial | CubicSpline + + class Config: + '''Wrapper for reading, parsing and storing the contents of a configuration + file + ''' def __init__(self, path): current_line = 0 @@ -50,7 +57,13 @@ class Config: def potential_interp( interpolation: str, points: NDArray[np.float64] -): +) -> Interpolator: + '''Create an interpolator for a set of predefined potential points + + :param interpolation: Kind of interpolation + :param points: Points to interpolate within + :return: Interpolating object + ''' if interpolation == 'linear': def line(x): return np.interp(x, points[:, 0], points[:, 1]) @@ -69,6 +82,11 @@ def potential_interp( def build_potential( config: Config ) -> tuple[NDArray[np.float64], np.float64]: + '''Build a potential based on the options inside a configuration file + + :param config: System parameters + :return: Potential and distance between samples + ''' start, end, steps = config.interval potential = np.zeros((steps, 2)) potential[:, 0] = np.linspace(start, end, steps) @@ -84,8 +102,14 @@ def solve_schroedinger( delta: float, eig_interval: tuple[int, int]=None ) -> tuple[NDArray[np.float64], NDArray[np.float64]]: - ''' - returns eigen values and wave functions specified by eig_interval + '''Solve the one dimensional, time independent Schrödinger's equation for a + particle of given mass inside a discretized potential + + :param mass: Mass of the particle + :param potential: Discretized potential + :param delta: Distance between points in the potential + :param eig_interval: Interval of quantum numbers for which the states are to be calculated + :return: Eigenvalues and normalized wave functions ''' n = potential.shape[0] a = 1 / mass / delta**2 -- cgit v1.2.3