コード例 #1
0
ファイル: viepy3mp.py プロジェクト: EMJian/VIE
def solver():
    global it
    #******************************************************************************#
    # Computing the total field
    #******************************************************************************#
    # parameters for the GMRES solver
    tol = 1e-6  # relative residual tolerance
    restart = 300  # inner iterations
    maxiter = 300  # max total iterations

    # memory calculation
    MemReq = (restart + 6) * Ein.nbytes + GF.nbytes + EpsArr.nbytes

    proceed = input('You may need extra '+str(round((MemReq/(1024*1024*1024)),2))+\
                    ' GB. Proceed? [y/n]: ')

    if proceed == 'n':
        sys.exit('PROGRAM ABORTED')

    p = Pool(3)  # creating a pool of workers/threads

    # declearing the operator
    def AuClean(U):
        V = matvecpar.Au(U, GF, EpsArr, NX, NY, NZ, p)
        return V

    Aop = ssla.LinearOperator((NX * NY * NZ * 3, NX * NY * NZ * 3),
                              matvec=AuClean,
                              dtype=complex)

    # preparing to read the residual vector
    nb = scila.norm(Bvec)

    print('Computing total field...')
    print('Starting GMRES with: tol =', tol, ' restart =', restart,
          ' maxiter =', maxiter)
    t0 = time.clock()
    it = 1
    (Vsol, info) = ssla.gmres(Aop,
                              Bvec,
                              tol=tol,
                              restart=restart,
                              maxiter=maxiter,
                              callback=resnorm)
    t1 = time.clock()
    V0 = Vsol  # for use as an initial guess
    Etot = sci.reshape(Vsol, (NX, NY, NZ, 3))
    # saving Etot in a *.mat file
    outFile = myDir + '/Output/TotalField'  # file name
    scio.savemat(outFile, {'Etot': Etot})

    deltaT = t1 - t0
    print('Total field computed in', deltaT, 'seconds')
    print('GMRES Info:', info)

    # Plotting residual
    plt.ion()
    fig = plt.figure(3)
    plt.semilogy(relres)
    plt.title('GMRES residual')
    fig.canvas.draw()
    plt.ioff()

    # Slicing E
    figNum = 4
    fieldName = 'E'
    vis.sliceFieldArr(sci.absolute(Etot), NX, NY, NZ, SliceX, SliceY, SliceZ,
                      figNum, fieldName)

    #******************************************************************************#
    # Computing force density
    #******************************************************************************#
    print('Computing force density...')
    t0 = time.clock()

    # To do: Here comes the computation of the force density

    t1 = time.clock()
    deltaT = t1 - t0
    print('Force density computed in', deltaT, 'seconds')

    #plt.show() # show and keep all the figures untill closed
    print('\nPROGRAM END :-)')
    print('***************\n')

    #******************************************************************************#
    return
コード例 #2
0
ファイル: VIEforce.py プロジェクト: the-iterator/VIE
Ein = incident.PointDipole(Freq,EpsRelB,Cell,NX,NY,NZ,Xs,Ys,Zs,PolX,PolY,PolZ)
t1 = time.clock()
# saving Ein in a *.mat file
outFile = myDir+'/Output/IncidentField' # file name
scio.savemat(outFile, {'Ein':Ein})
Bvec = sci.reshape(Ein,(NX*NY*NZ*3,1))
deltaT = t1-t0
sys.stdout.write('Incident field computed in '+str(deltaT)+' seconds\n')

# Slicing Ein
figNum = 1
fieldName = 'E^{in}'
SliceX = round(NX/2.)
SliceY = round(NY/2.)
SliceZ = round(NZ/2.)
vis.sliceFieldArr(sci.real(Ein),NX,NY,NZ,SliceX,SliceY,SliceZ,figNum,fieldName)

#******************************************************************************#
# Computing G tensor
#******************************************************************************#
t0 = time.clock()
GF = green.greentensor(Freq,EpsRelB,Cell,NX,NY,NZ)
t1 = time.clock()
# saving GF in a *.mat file
#outFile = myDir+'/Output/GreenTensor' # file name
#scio.savemat(outFile, {'GF':GF})
deltaT = t1-t0
print 'GF tensor computed in',deltaT, 'seconds'

#******************************************************************************#
# Constructing an object
コード例 #3
0
ファイル: viepy3mp.py プロジェクト: EMJian/VIE
                           PolY, PolZ)
t1 = time.clock()
# saving Ein in a *.mat file
outFile = myDir + '/Output/IncidentField'  # file name
scio.savemat(outFile, {'Ein': Ein})
Bvec = sci.reshape(Ein, (NX * NY * NZ * 3, 1))
deltaT = t1 - t0
sys.stdout.write('Incident field computed in ' + str(deltaT) + ' seconds\n')

# Slicing Ein
figNum = 1
fieldName = 'E^{in}'
SliceX = round(NX / 2.)
SliceY = round(NY / 2.)
SliceZ = round(NZ / 2.)
vis.sliceFieldArr(sci.real(Ein), NX, NY, NZ, SliceX, SliceY, SliceZ, figNum,
                  fieldName)

#******************************************************************************#
# Computing G tensor
#******************************************************************************#
t0 = time.clock()
GF = green.greentensor(Freq, EpsRelB, Cell, NX, NY, NZ)
t1 = time.clock()
# saving GF in a *.mat file
#outFile = myDir+'/Output/GreenTensor' # file name
#scio.savemat(outFile, {'GF':GF})
deltaT = t1 - t0
print('GF tensor computed in', deltaT, 'seconds')

#******************************************************************************#
# Constructing an object
コード例 #4
0
ファイル: viepy3mp.py プロジェクト: the-iterator/VIE
def solver():
    global it
    #******************************************************************************#
    # Computing the total field
    #******************************************************************************#
    # parameters for the GMRES solver
    tol = 1e-6 # relative residual tolerance
    restart = 300 # inner iterations
    maxiter = 300 # max total iterations

    # memory calculation
    MemReq = (restart+6)*Ein.nbytes + GF.nbytes + EpsArr.nbytes

    proceed = input('You may need extra '+str(round((MemReq/(1024*1024*1024)),2))+\
                    ' GB. Proceed? [y/n]: ')

    if proceed == 'n':
        sys.exit('PROGRAM ABORTED')

    p = Pool(3) # creating a pool of workers/threads
    
    # declearing the operator
    def AuClean(U):
        V = matvecpar.Au(U,GF,EpsArr,NX,NY,NZ,p)
        return V

    Aop = ssla.LinearOperator((NX*NY*NZ*3,NX*NY*NZ*3),matvec = AuClean,dtype = complex)

    # preparing to read the residual vector
    nb = scila.norm(Bvec)

    print('Computing total field...')
    print('Starting GMRES with: tol =', tol,' restart =',restart, ' maxiter =', maxiter)
    t0 = time.clock()
    it = 1
    (Vsol,info) = ssla.gmres(Aop,Bvec, tol=tol, restart=restart, maxiter=maxiter, callback=resnorm)
    t1 = time.clock()
    V0 = Vsol # for use as an initial guess
    Etot = sci.reshape(Vsol,(NX,NY,NZ,3))
    # saving Etot in a *.mat file
    outFile = myDir+'/Output/TotalField' # file name
    scio.savemat(outFile, {'Etot':Etot})

    deltaT = t1-t0
    print('GMRES finished in', deltaT, 'seconds')
    print('Info:', info)

    # Plotting residual
    plt.ion()
    fig = plt.figure(3)
    plt.semilogy(relres)
    plt.title('GMRES residual')
    fig.canvas.draw()
    plt.ioff()

    # Slicing E
    figNum = 4
    fieldName = 'E'
    vis.sliceFieldArr(sci.absolute(Etot),NX,NY,NZ,SliceX,SliceY,SliceZ,figNum,fieldName)


    #******************************************************************************#
    # Computing force density
    #******************************************************************************#
    print('Computing force density...')
    t0 = time.clock()

    # To do: Here comes the computation of the force density

    t1 = time.clock()
    deltaT = t1-t0
    print('Force density computed in', deltaT, 'seconds')

    #plt.show() # show and keep all the figures untill closed
    print('\nPROGRAM END :-)')
    print('***************\n')