Пример #1
0
from matplotlib import pyplot as plt

# shape = (3,3,3)
shape = (100,100,100)
# b_rand = [np.random.randn(*shape).astype(np.complex128) for k in range(3)]
omega = 0.4
b = [np.zeros(shape).astype(np.complex128) for k in range(3)]
b[1][50,50,50] = 1.
# b[0][30,30,30] = 1.

ops, b = maxwell.get_ops(omega, b)
# a0 = b.dup()
# ops['multA'](b, a0)
# a1 = b.dup()
# ops['multAT'](b, a1)
# for k in range(3):
#     diff = a0.f[k].g.get() - a1.f[k].g.get()
#     print np.linalg.norm(diff.flatten(), ord=2)
# a = a1.f[0].g.get().flatten()
# for t in a:
#     print t
x, err = bicg.solve_asymm(b, max_iters=1000, **ops)
# for k in range(err.size):
#     print k, err[k]
# print err.size, 'iterations ending with', err[-3:]

v = 0.01
plt.imshow(np.real(np.squeeze(x.f[1].g.get()[50,:,:])), \
        cmap=plt.cm.jet, vmin=-v, vmax=v, interpolation='nearest')
plt.show()
Пример #2
0
import numpy as np
from my_math import bicg
from my_phys import simple_wave
import pycuda.autoinit

 
shape = (1, 1, 400)
omega = 0.3;
b = np.zeros(shape).astype(np.complex128)
b[0,0,shape[2]/2] = 1 + 0j;
# b = ga.to_gpu(b)
# b.set(np.arange(shape[2]).astype(np.complex128))
# y = ga.zeros_like(b) 
b, ops = simple_wave.get_ops(shape, omega, b)
# multAT(b, y)
# print y.get()
# multA(b, y)
# print y.get()
x, err = bicg.solve_asymm(b, **ops)
# x, err = bicg.solve_asymm(multA, multAT, b, \
#                 dot=my_dot, axby=my_axby, copy=my_copy)
print err.size, 'iterations ending with', err[-3:]
Пример #3
0
A = np.dot(A2, A1) - omega**2 * np.eye(N)

def mA(x, y):
    y[:] = np.dot(A, x) 
    return

def mAT(x, y):
    y[:] = np.dot(A.T, x)
    return

b = np.zeros(N).astype(np.complex128)
b[N/2] = 1 + 0j

# print mAT(b)

# Find "exact" solution.
x = np.linalg.solve(A, b)
print 'error from "exact" solution', np.linalg.norm(np.dot(A, x) - b)

# Solve using bi-cg.
x = np.zeros_like(b)
x, err  = bicg.solve_asymm(mA, mAT, b)
print len(err), 'iterations'
print 'ending in:'
for err_val in err[-5:]:
    print err_val

print 'error is', np.linalg.norm(np.dot(A, x) - b)
# plt.plot(np.abs(x), 'b.-')
# plt.show()
Пример #4
0
def mA(x, y):
    y[:] = np.dot(A, x)
    return


def mAT(x, y):
    y[:] = np.dot(A.T, x)
    return


b = np.zeros(N).astype(np.complex128)
b[N / 2] = 1 + 0j

# print mAT(b)

# Find "exact" solution.
x = np.linalg.solve(A, b)
print 'error from "exact" solution', np.linalg.norm(np.dot(A, x) - b)

# Solve using bi-cg.
x = np.zeros_like(b)
x, err = bicg.solve_asymm(mA, mAT, b)
print len(err), 'iterations'
print 'ending in:'
for err_val in err[-5:]:
    print err_val

print 'error is', np.linalg.norm(np.dot(A, x) - b)
# plt.plot(np.abs(x), 'b.-')
# plt.show()
Пример #5
0
from matplotlib import pyplot as plt

# shape = (3,3,3)
shape = (100, 100, 100)
# b_rand = [np.random.randn(*shape).astype(np.complex128) for k in range(3)]
omega = 0.4
b = [np.zeros(shape).astype(np.complex128) for k in range(3)]
b[1][50, 50, 50] = 1.
# b[0][30,30,30] = 1.

ops, b = maxwell.get_ops(omega, b)
# a0 = b.dup()
# ops['multA'](b, a0)
# a1 = b.dup()
# ops['multAT'](b, a1)
# for k in range(3):
#     diff = a0.f[k].g.get() - a1.f[k].g.get()
#     print np.linalg.norm(diff.flatten(), ord=2)
# a = a1.f[0].g.get().flatten()
# for t in a:
#     print t
x, err = bicg.solve_asymm(b, max_iters=1000, **ops)
# for k in range(err.size):
#     print k, err[k]
# print err.size, 'iterations ending with', err[-3:]

v = 0.01
plt.imshow(np.real(np.squeeze(x.f[1].g.get()[50,:,:])), \
        cmap=plt.cm.jet, vmin=-v, vmax=v, interpolation='nearest')
plt.show()