Example #1
0
def time_evolution(u=None):
    '''
    Solves the wave equation
    
    .. math:: u^{t_n + 1} = b(t_n) \\times A
    
    iterated over time.shape[0] time steps t_n 

    Second order time stepping is used.
    It increases the accuracy of the wave evolution.

    The second order time-stepping would be
    `U^{n + 1/2} = U^n + dt / 2 (A^{-1} B(U^n))`
    `U^{n + 1}   = U^n + dt     (A^{-1} B(U^{n + 1/2}))`
    
    Returns
    -------
    None
    '''

    # Creating a folder to store hdf5 files. If it doesn't exist.
    results_directory = 'results/hdf5_%02d' % (int(params.N_LGL))

    if not os.path.exists(results_directory):
        os.makedirs(results_directory)

    element_LGL = params.element_LGL
    delta_t = params.delta_t
    shape_u_n = utils.shape(u)
    time = params.time
    A_inverse = af.tile(af.inverse(A_matrix()), d0=1, d1=1, d2=shape_u_n[2])

    element_boundaries = af.np_to_af_array(params.np_element_array)

    for t_n in trange(0, time.shape[0]):
        if (t_n % 20) == 0:
            h5file = h5py.File(
                'results/hdf5_%02d/dump_timestep_%06d' %
                (int(params.N_LGL), int(t_n)) + '.hdf5', 'w')
            dset = h5file.create_dataset('u_i', data=u, dtype='d')

            dset[:, :] = u[:, :]

        # Code for solving 1D Maxwell's Equations
        # Storing u at timesteps which are multiples of 100.
        #if (t_n % 5) == 0:
        #h5file = h5py.File('results/hdf5_%02d/dump_timestep_%06d' \
        #%(int(params.N_LGL), int(t_n)) + '.hdf5', 'w')
        #Ez_dset   = h5file.create_dataset('E_z', data = u[:, :, 0],
        #dtype = 'd')
        #By_dset   = h5file.create_dataset('B_y', data = u[:, :, 1],
        #dtype = 'd')

        #Ez_dset[:, :] = u[:, :, 0]
        #By_dset[:, :] = u[:, :, 1]

        u += RK4_timestepping(A_inverse, u, delta_t)
Example #2
0
def simple_lapack(verbose=False):
    display_func = _util.display_func(verbose)
    print_func = _util.print_func(verbose)
    a = af.randu(5, 5)

    l, u, p = af.lu(a)

    display_func(l)
    display_func(u)
    display_func(p)

    p = af.lu_inplace(a, "full")

    display_func(a)
    display_func(p)

    a = af.randu(5, 3)

    q, r, t = af.qr(a)

    display_func(q)
    display_func(r)
    display_func(t)

    af.qr_inplace(a)

    display_func(a)

    a = af.randu(5, 5)
    a = af.matmulTN(a, a.copy()) + 10 * af.identity(5, 5)

    R, info = af.cholesky(a)
    display_func(R)
    print_func(info)

    af.cholesky_inplace(a)
    display_func(a)

    a = af.randu(5, 5)
    ai = af.inverse(a)

    display_func(a)
    display_func(ai)

    x0 = af.randu(5, 3)
    b = af.matmul(a, x0)
    x1 = af.solve(a, b)

    display_func(x0)
    display_func(x1)

    p = af.lu_inplace(a)

    x2 = af.solve_lu(a, p, b)

    display_func(x2)

    print_func(af.rank(a))
    print_func(af.det(a))
    print_func(af.norm(a, af.NORM.EUCLID))
    print_func(af.norm(a, af.NORM.MATRIX_1))
    print_func(af.norm(a, af.NORM.MATRIX_INF))
    print_func(af.norm(a, af.NORM.MATRIX_L_PQ, 1, 1))

    a = af.randu(10, 10)
    display_func(a)
    u, s, vt = af.svd(a)
    display_func(af.matmul(af.matmul(u, af.diag(s, 0, False)), vt))
    u, s, vt = af.svd_inplace(a)
    display_func(af.matmul(af.matmul(u, af.diag(s, 0, False)), vt))
Example #3
0
def simple_lapack(verbose=False):
    display_func = _util.display_func(verbose)
    print_func   = _util.print_func(verbose)
    a = af.randu(5,5)

    l,u,p = af.lu(a)

    display_func(l)
    display_func(u)
    display_func(p)

    p = af.lu_inplace(a, "full")

    display_func(a)
    display_func(p)

    a = af.randu(5,3)

    q,r,t = af.qr(a)

    display_func(q)
    display_func(r)
    display_func(t)

    af.qr_inplace(a)

    display_func(a)

    a = af.randu(5, 5)
    a = af.matmulTN(a, a) + 10 * af.identity(5,5)

    R,info = af.cholesky(a)
    display_func(R)
    print_func(info)

    af.cholesky_inplace(a)
    display_func(a)

    a = af.randu(5,5)
    ai = af.inverse(a)

    display_func(a)
    display_func(ai)

    x0 = af.randu(5, 3)
    b = af.matmul(a, x0)
    x1 = af.solve(a, b)

    display_func(x0)
    display_func(x1)

    p = af.lu_inplace(a)

    x2 = af.solve_lu(a, p, b)

    display_func(x2)

    print_func(af.rank(a))
    print_func(af.det(a))
    print_func(af.norm(a, af.NORM.EUCLID))
    print_func(af.norm(a, af.NORM.MATRIX_1))
    print_func(af.norm(a, af.NORM.MATRIX_INF))
    print_func(af.norm(a, af.NORM.MATRIX_L_PQ, 1, 1))
af.qr_inplace(a)

af.display(a)

a = af.randu(5, 5)
a = af.matmulTN(a, a) + 10 * af.identity(5, 5)

R, info = af.cholesky(a)
af.display(R)
print(info)

af.cholesky_inplace(a)
af.display(a)

a = af.randu(5, 5)
ai = af.inverse(a)

af.display(a)
af.display(ai)

x0 = af.randu(5, 3)
b = af.matmul(a, x0)
x1 = af.solve(a, b)

af.display(x0)
af.display(x1)

p = af.lu_inplace(a)

x2 = af.solve_lu(a, p, b)