예제 #1
0
 def __init__(self, nx=10, ny=10, xmin=0.0, xmax=1.0, ymin=0.0, ymax=1.0):
     self.xmin, self.xmax, self.ymin, self.ymax = xmin, xmax, ymin, ymax
     self.dx = float(xmax - xmin) / (nx - 1)
     self.dy = float(ymax - ymin) / (ny - 1)
     self.u = numpy.zeros((nx, ny), 'd')
     # used to compute the change in solution in some of the methods.
     self.old_u = self.u.copy()
예제 #2
0
 def __init__(self, nx=10, ny=10, xmin=0.0, xmax=1.0, ymin=0.0, ymax=1.0):
     self.xmin, self.xmax, self.ymin, self.ymax = xmin, xmax, ymin, ymax
     self.dx = float(xmax - xmin) / (nx - 1)
     self.dy = float(ymax - ymin) / (ny - 1)
     self.u = numpy.zeros((nx, ny), 'd')
     # used to compute the change in solution in some of the methods.
     self.old_u = self.u.copy()
예제 #3
0
def jacobi(A, B, tol=0.005, forcedIter=0):
    '''itteratively solving for matrix A with solution vector B
       tol = tolerance for dh/h
       init_val = array of initial values to use in the solver
    '''
    h = np.zeros(np.shape(B), float)
    dmax = 1.0
    n = 0
    tmp0 = np.empty(np.shape(A), float)
    tmp1 = np.empty(np.shape(B), float)
    AD = np.diagonal(A)
    #np.timer_reset()
    #np.evalflush()
    t1 = time.time()
    while (forcedIter and forcedIter > n) or \
          (forcedIter == 0 and dmax > tol):
        n += 1
        np.multiply(A, h, tmp0)
        np.add.reduce(tmp0, 1, out=tmp1)
        tmp2 = AD
        np.subtract(B, tmp1, tmp1)
        np.divide(tmp1, tmp2, tmp1)
        hnew = h + tmp1
        np.subtract(hnew, h, tmp2)
        np.divide(tmp2, h, tmp1)
        np.absolute(tmp1, tmp1)
        dmax = np.maximum.reduce(tmp1)
        h = hnew
        print dmax

    #np.evalflush()
    t1 = time.time() - t1

    print 'Iter: ', n, ' size: ', np.shape(B), ' time: ', t1,
    print "(Dist) notes: %s" % sys.argv[4]
    #if A.dist():
    #    print "(Dist) notes: %s"%sys.argv[4]
    #else:
    #    print "(Non-Dist) notes: %s"%sys.argv[4]

    return h
예제 #4
0
def jacobi(A, B, tol=0.005, forcedIter=0):
    """itteratively solving for matrix A with solution vector B
       tol = tolerance for dh/h
       init_val = array of initial values to use in the solver
    """
    h = np.zeros(np.shape(B), float)
    dmax = 1.0
    n = 0
    tmp0 = np.empty(np.shape(A), float)
    tmp1 = np.empty(np.shape(B), float)
    AD = np.diagonal(A)
    # np.timer_reset()
    # np.evalflush()
    t1 = time.time()
    while (forcedIter and forcedIter > n) or (forcedIter == 0 and dmax > tol):
        n += 1
        np.multiply(A, h, tmp0)
        np.add.reduce(tmp0, 1, out=tmp1)
        tmp2 = AD
        np.subtract(B, tmp1, tmp1)
        np.divide(tmp1, tmp2, tmp1)
        hnew = h + tmp1
        np.subtract(hnew, h, tmp2)
        np.divide(tmp2, h, tmp1)
        np.absolute(tmp1, tmp1)
        dmax = np.maximum.reduce(tmp1)
        h = hnew
        print dmax

    # np.evalflush()
    t1 = time.time() - t1

    print "Iter: ", n, " size: ", np.shape(B), " time: ", t1,
    print "(Dist) notes: %s" % sys.argv[4]
    # if A.dist():
    #    print "(Dist) notes: %s"%sys.argv[4]
    # else:
    #    print "(Non-Dist) notes: %s"%sys.argv[4]

    return h
예제 #5
0
#np.ufunc_random(PyT,PyT)
PyT = np.random.random_sample((1,n))
#PzT= np.empty((1,n))
#np.ufunc_random(PzT,PzT)
PzT = np.random.random_sample((1,n))
#Vx = np.empty((n,1))
#np.ufunc_random(Vx,Vx)
Vx  = np.random.random_sample((n,1))
#Vy = np.empty((n,1))
#np.ufunc_random(Vy,Vy)
Vy  = np.random.random_sample((n,1))
#Vz = np.empty((n,1))
#np.ufunc_random(Vz,Vz)
Vz  = np.random.random_sample((n,1))

OnesCol = np.zeros((n,1), dtype=float)+1.0
OnesRow = np.zeros((1,n), dtype=float)+1.0
#Identity= array(diag([1]*n), dtype=double)

#np.timer_reset()
#np.evalflush()
stime = time.time()
for i in xrange(k):
    #distance between all pairs of objects
    Fx = np.dot(OnesCol, PxT) - np.dot(Px, OnesRow)
    Fy = np.dot(OnesCol, PyT) - np.dot(Py, OnesRow)
    Fz = np.dot(OnesCol, PzT) - np.dot(Pz, OnesRow)

    Dsq = Fx * Fx
    Dsq += Fy * Fy
    Dsq += Fz * Fz