Esempio n. 1
0
def get_ops(shape, omega, b, t_pml=10):
    sc0 = dg.Grid(
        stretched_coords.get_coeffs(shape[2], 0.0, t_pml,
                                    omega).astype(np.complex128))
    sc1 = dg.Grid(
        stretched_coords.get_coeffs(shape[2], 0.5, t_pml,
                                    omega).astype(np.complex128))

    if b.dtype.type is np.complex128:
        cuda_type = 'pycuda::complex<double>'
    elif b.dtype.type is np.complex64:
        cuda_type = 'pycuda::complex<float>'
    else:
        print 'error on data type of b'


    mA_func = grid_traverse.TraverseKernel(shape, \
        jinja_env.get_template('simplewave_multA.cu').render(w2=omega**2, zz=shape[2]), \
        (cuda_type, 's0__f'), (cuda_type, 's1__f'), \
        (cuda_type, 'u'), (cuda_type, 'v'))

    def multA(x, y):
        mA_func(sc0, sc1, x, y)
        return

    mAT_func = grid_traverse.TraverseKernel(shape, \
        jinja_env.get_template('simplewave_multAT.cu').render(w2=omega**2, zz=shape[2]), \
        (cuda_type, 's0__f'), (cuda_type, 's1__f'), \
        (cuda_type, 'u'), (cuda_type, 'v'))

    def multAT(x, y):
        mAT_func(sc0, sc1, x, y)
        return

    def dot(x, y):
        return x.dot(y)

    def axby(a, x, b, y):
        y.aby(b, a, x)

    def copy(x):
        return x.dup()

    return dg.Grid(b), \
            {   'multA': multA, \
                'multAT': multAT, \
                'dot': dot, \
                'axby': axby, \
                'copy': copy}
Esempio n. 2
0
def get_ops(omega, b, t_pml=10):
    """ define the operations """

    def copy(x):
        return x.dup()

    def dot(x, y):
        return x.dot(y)

    def axby(a, x, b, y):
        y.aby(b, a, x)

    def norm(x):
        return x.norm()

    shape = b[0].shape
    cuda_type = 'pycuda::complex<double>'
    field_names = ('Ex', 'Ey', 'Ez', 'Ax', 'Ay', 'Az', \
                    'sx0_f', 'sy0_f', 'sz0_f', 'sx1_f', 'sy1_f', 'sz1_f')
    sc_pml_0 = VecField(\
        *[stretched_coords.get_coeffs(len, 0.0, t_pml, omega).astype(np.complex128) \
        for len in shape])
    sc_pml_1 = VecField(\
        *[stretched_coords.get_coeffs(len, 0.5, t_pml, omega).astype(np.complex128) \
        for len in shape])

    mA_func = grid_traverse.TraverseKernel(shape, \
        jinja_env.get_template('maxwell_multA.cu').\
            render(w2=omega**2, dims=shape, type=cuda_type), \
        *[(cuda_type, name) for name in field_names])
    def multA(x, y):
        mA_func(x.f[0], x.f[1], x.f[2], \
                y.f[0], y.f[1], y.f[2], \
                sc_pml_0.f[0], sc_pml_0.f[1], sc_pml_0.f[2], \
                sc_pml_1.f[0], sc_pml_1.f[1], sc_pml_1.f[2])

    mAT_func = grid_traverse.TraverseKernel(shape, \
        jinja_env.get_template('maxwell_multAT.cu').\
            render(w2=omega**2, dims=shape, type=cuda_type), \
        *[(cuda_type, name) for name in field_names])
    def multAT(x, y):
        mAT_func(x.f[0], x.f[1], x.f[2], \
                y.f[0], y.f[1], y.f[2], \
                sc_pml_0.f[0], sc_pml_0.f[1], sc_pml_0.f[2], \
                sc_pml_1.f[0], sc_pml_1.f[1], sc_pml_1.f[2])

    return  {'multA': multA, 'multAT': multAT, 'copy': copy, 'dot': dot, \
            'norm': norm, 'axby': axby}, VecField(*b)
Esempio n. 3
0
def get_ops(shape, omega, b, t_pml=10):
    sc0 = dg.Grid(stretched_coords.get_coeffs(shape[2], 0.0, t_pml, omega).astype(np.complex128))
    sc1 = dg.Grid(stretched_coords.get_coeffs(shape[2], 0.5, t_pml, omega).astype(np.complex128))

    if b.dtype.type is np.complex128:
        cuda_type = 'pycuda::complex<double>'
    elif b.dtype.type is np.complex64:
        cuda_type = 'pycuda::complex<float>'
    else:
        print 'error on data type of b'


    mA_func = grid_traverse.TraverseKernel(shape, \
        jinja_env.get_template('simplewave_multA.cu').render(w2=omega**2, zz=shape[2]), \
        (cuda_type, 's0__f'), (cuda_type, 's1__f'), \
        (cuda_type, 'u'), (cuda_type, 'v'))
    def multA(x, y):
        mA_func(sc0, sc1, x, y)
        return

    mAT_func = grid_traverse.TraverseKernel(shape, \
        jinja_env.get_template('simplewave_multAT.cu').render(w2=omega**2, zz=shape[2]), \
        (cuda_type, 's0__f'), (cuda_type, 's1__f'), \
        (cuda_type, 'u'), (cuda_type, 'v'))
    def multAT(x, y):
        mAT_func(sc0, sc1, x, y)
        return

    def dot(x, y):
        return x.dot(y)
     
    def axby(a, x, b, y):
        y.aby(b, a, x)

    def copy(x):
        return x.dup()
    
    return dg.Grid(b), \
            {   'multA': multA, \
                'multAT': multAT, \
                'dot': dot, \
                'axby': axby, \
                'copy': copy}