Exemplo n.º 1
0
def test_one_well_numerov(method, width, depth, separation, width_bg):
    r = numerov(widths=[width], depths=[depth], separations=separation, width_bg=width_bg, dx=0.01, method=method)
    E = r['E']

    s = one_well_energies(depth=depth, width=width)

    assert np.allclose(E, s, atol=1e-1)
Exemplo n.º 2
0
def test_one_well_numerov(method):
    """Test the one well analytic solution code against the original one well matlab code from Lena"""
    r = numerov(widths=[3.0], depths=[10.0])

    mat = loadmat('tests/numerov/get_p_1W.mat', squeeze_me=True, method=method)
    E = mat['E']

    assert np.allclose(r['E'], E)
Exemplo n.º 3
0
def test_get_p_2W(method):
    """
    Test the output for the matrix numerov method against the MATLAB implementation. This is Lena's 2-well code.
    """
    mat = loadmat('tests/numerov/get_p_2W.mat', squeeze_me=True)

    # Get the parameters we are going to test
    d1 = mat['d1']
    d2 = mat['d2']
    w1 = mat['w1']
    w2 = mat['w2']
    w_sep = mat['w_sep']

    r = numerov(widths=[w1, w2], depths=[d1, d2], separations=[w_sep], method=method)

    assert np.allclose(mat['v'], r['v'])
    assert np.allclose(mat['E'], r['E'])
    #assert np.allclose(mat['psi'], r['psi'])
    assert np.allclose(mat['dens'], r['dens'])
    assert np.allclose(mat['p_1'], r['p_wells'][0, :])
    assert np.allclose(mat['p_2'], r['p_wells'][1, :])
    assert np.allclose(mat['p_int'], r['p_int'][0, :])
    assert np.allclose(mat['p_bg'], r['p_bg'])
Exemplo n.º 4
0
def test_N_wells_numerov(widths, depths, separations, width_bg):
    r = numerov(widths=widths, depths=depths, separations=separations, width_bg=width_bg)
Exemplo n.º 5
0
import pandas as pd
import seaborn as sns

from tise_solver.numerov import numerov

if __name__ == "__main__":
    results = []
    for method in ['sparse', 'dense']:
        for dx in [
                0.02, 0.01, 0.009, 0.008, 0.007, 0.006, 0.005, 0.004, 0.003
        ]:

            # Run it to get the total number of steps for this dx
            n_steps = numerov(widths=[3.0],
                              depths=[10.0],
                              separations=[],
                              dx=dx,
                              method=method)['n_steps']

            # Run to time it
            e = timeit.timeit(
                stmt=
                f"numerov(widths=[3.0], depths=[10.0], separations=[], dx={dx}, method='{method}')",
                setup="from tise_solver.numerov import numerov",
                number=1)
            print(f'method={method}, dx={dx}, n_steps={n_steps}, time={e}')
            results.append((method, dx, n_steps, e))

    results = pd.DataFrame(
        results, columns=['method', 'dx', 'n_steps', 'execution_time'])
Exemplo n.º 6
0
#%%
import time

p = params[f'periodic n_wells=1']

marsiglio_E = []
marsiglio_times = []
numerov_E = []
numerov_times = []
n_steps_vals = []

dxs = [0.5, 0.2, 0.1, 0.02, 0.01, 0.009, 0.008, 0.007, 0.006, 0.005]

for dx in dxs:
    t0 = time.time()
    nr = numerov(**p, dx=dx, method='dense')
    numerov_times.append(time.time() - t0)
    numerov_E.append(nr['E'])
    n_steps = nr['n_steps']
    n_steps_vals.append(n_steps)
    t0 = time.time()
    mr = marsiglio(**p, nt=n_steps)
    marsiglio_times.append(time.time() - t0)
    marsiglio_E.append(mr['E'])
    print(
        f"dx = {dx}, numerov_time = {numerov_times[-1]}, marsiglio_time = {marsiglio_times[-1]}"
    )

#%%

E1_marsiglio = np.array([E[0] for E in marsiglio_E])