Exemplo n.º 1
0
def calculateEsurf(surf_array, field_array, param, kernel):

    REAL = param.REAL

    par_reac = parameters()
    par_reac = param
    par_reac.threshold = 0.05
    par_reac.P = 7
    par_reac.theta = 0.0
    par_reac.Nm= (par_reac.P+1)*(par_reac.P+2)*(par_reac.P+3)/6

    ind_reac = index_constant()
    computeIndices(par_reac.P, ind_reac)
    precomputeTerms(par_reac.P, ind_reac)

    par_reac.Nk = 13         # Number of Gauss points per side for semi-analytical integrals

    cal2J = 4.184
    C0 = param.qe**2*param.Na*1e-3*1e10/(cal2J*param.E_0)
    E_surf = []

    ff = -1
    for f in param.E_field:
        parent_surf = surf_array[field_array[f].parent[0]]
         
        if parent_surf.surf_type == 'dirichlet_surface':
            ff += 1
            print 'Calculating surface energy around region %i, stored in E_surf[%i]'%(f,ff)
            Esurf_aux = -sum(-parent_surf.Eout*parent_surf.dphi*parent_surf.phi*parent_surf.Area) 
            E_surf.append(0.5*C0*Esurf_aux)
        
        elif parent_surf.surf_type == 'neumann_surface':
            ff += 1
            print 'Calculating surface energy around region %i, stored in E_surf[%i]'%(f,ff)
            Esurf_aux = sum(-parent_surf.Eout*parent_surf.dphi*parent_surf.phi*parent_surf.Area) 
            E_surf.append(0.5*C0*Esurf_aux)

    return E_surf
Exemplo n.º 2
0
from FMMutils       import *
from cuda_kernels   import kernels

# import modules for testing
#from mpl_toolkits.mplot3d import Axes3D
#import matplotlib.pyplot as plt

### Time stamp
timestamp = time.localtime()
print 'Run started on:'
print '\tDate: %i/%i/%i'%(timestamp.tm_year,timestamp.tm_mon,timestamp.tm_mday)
print '\tTime: %i:%i:%i'%(timestamp.tm_hour,timestamp.tm_min,timestamp.tm_sec)

TIC = time.time()
### Read parameters
param = parameters()
precision = readParameters(param,sys.argv[1])
configFile = sys.argv[2]

param.Nm            = (param.P+1)*(param.P+2)*(param.P+3)/6     # Number of terms in Taylor expansion
param.BlocksPerTwig = int(numpy.ceil(param.NCRIT/float(param.BSZ)))   # CUDA blocks that fit per twig

### Generate array of fields
field_array = initializeField(configFile, param)

### Generate array of surfaces and read in elements
surf_array = initializeSurf(field_array, configFile, param)

### Fill surface class
time_sort = 0.
for i in range(len(surf_array)):
Exemplo n.º 3
0
def calculateEsolv(surf_array, field_array, param, kernel):

    REAL = param.REAL

    par_reac = parameters()
    par_reac = param
    par_reac.threshold = 0.05
    par_reac.P = 7
    par_reac.theta = 0.0
    par_reac.Nm= (par_reac.P+1)*(par_reac.P+2)*(par_reac.P+3)/6

    ind_reac = index_constant()
    computeIndices(par_reac.P, ind_reac)
    precomputeTerms(par_reac.P, ind_reac)

    par_reac.Nk = 13         # Number of Gauss points per side for semi-analytical integrals

    cal2J = 4.184
    C0 = param.qe**2*param.Na*1e-3*1e10/(cal2J*param.E_0)
    E_solv = []

    ff = -1
    for f in param.E_field:
        parent_type = surf_array[field_array[f].parent[0]].surf_type
        if parent_type != 'dirichlet_surface' and parent_type != 'neumann_surface':

            E_solv_aux = 0
            ff += 1
            print 'Calculating solvation energy for region %i, stored in E_solv[%i]'%(f,ff)
            
            AI_int = 0
            Naux = 0
            phi_reac = zeros(len(field_array[f].q))

#           First look at CHILD surfaces
#           Need to account for normals pointing outwards
#           and E_hat coefficient (as region is outside and 
#           dphi_dn is defined inside)
            for i in field_array[f].child:
                s = surf_array[i]
                s.xk,s.wk = GQ_1D(par_reac.Nk)
                s.xk = REAL(s.xk)
                s.wk = REAL(s.wk)
                for C in range(len(s.tree)):
                    s.tree[C].M  = zeros(par_reac.Nm)
                    s.tree[C].Md = zeros(par_reac.Nm)

                Naux += len(s.triangle)

#               Coefficient to account for dphi_dn defined in
#               interior but calculation done in exterior
                C1 = s.E_hat

                if param.GPU==0:
                    phi_aux, AI = get_phir(s.phi, C1*s.dphi, s, field_array[f].xq, s.tree, par_reac, ind_reac)
                elif param.GPU==1:
                    phi_aux, AI = get_phir_gpu(s.phi, C1*s.dphi, s, field_array[f], par_reac, kernel)
                
                AI_int += AI
                phi_reac -= phi_aux # Minus sign to account for normal pointing out

#           Now look at PARENT surface
            if len(field_array[f].parent)>0:
                i = field_array[f].parent[0]
                s = surf_array[i]
                s.xk,s.wk = GQ_1D(par_reac.Nk)
                s.xk = REAL(s.xk)
                s.wk = REAL(s.wk)
                for C in range(len(s.tree)):
                    s.tree[C].M  = zeros(par_reac.Nm)
                    s.tree[C].Md = zeros(par_reac.Nm)

                Naux += len(s.triangle)

                if param.GPU==0:
                    phi_aux, AI = get_phir(s.phi, s.dphi, s, field_array[f].xq, s.tree, par_reac, ind_reac)
                elif param.GPU==1:
                    phi_aux, AI = get_phir_gpu(s.phi, s.dphi, s, field_array[f], par_reac, kernel)
                
                AI_int += AI
                phi_reac += phi_aux 

            
            E_solv_aux += 0.5*C0*sum(field_array[f].q*phi_reac)
            E_solv.append(E_solv_aux)

            print '%i of %i analytical integrals for phi_reac calculation in region %i'%(AI_int/len(field_array[f].xq),Naux, f)

    return E_solv