def __init__(self, filename): self.file = None self.filename = filename self.fem = FEM.FEM() self.sections = [] # List of supported datasets and corresponding dataset handler functions self.datasetsIds = [2411, 2412, 2467, 2477] self.datasetsHandlers = [UNV2411Reader, UNV2412Reader, UNV2467Reader, UNV2467Reader]
def __init__(self,filename): self.file=None self.filename=filename self.FEM=FEM() self.startFlag=' -1' self.endFlag=' -1' # list of supported datasets and corresponding dataset handler functions self.datasetsIds=[2411,2412,2467, 2477] self.datasetsHandlers=[self.UNV2411Reader, self.UNV2412Reader, self.UNV2467Reader, self.UNV2467Reader] self.sections=[]
def __init__(self, filename): self.file = None self.filename = filename self.FEM = FEM() self.ElementConfiguration = self.setupElements()
def main(): # 'linear;, 'quadratic' or 'cubic' elementType = 'cubic' # '2pt','3pt', '4pt' quadratureRule = '4pt' # meshType = 'uniform' or 'adaptive' meshType = 'uniform' # FIXME: generalize later numAtoms = 1 if(numAtoms == 1): # define number of elements numberElements = 52 # define domain size in 1D domainStart = -17.5 domainEnd = 17.5 #define parameters for adaptive Mesh innerDomainSize = 8 innerMeshSize = 0.25 #read the external potental from matlab if(meshType == 'uniform'): pot = open('vpotOneAtomUniform52Elem.txt','r') else : pot = open('vpotOneAtomAdaptive52Elem.txt','r') else: # define number of elements numberElements = 84 # define domain size in 1D domainStart = -17.5 domainEnd = 17.5 #define parameters for adaptive Mesh innerDomainSize = 16 innerMeshSize = 0.25 #read the external potental from matlab if(meshType =='uniform'): pot = open('vpot14AtomUniform84Elem.txt','r') else : pot = open('vpot14AtomAdaptive84Elem.txt','r') # create FEM object fem=FEM.FEM(numberElements, quadratureRule, elementType, domainStart, domainEnd, innerDomainSize, innerMeshSize, meshType) # mesh the domain in 1D globalNodalCoordinates = fem.generateNodes() # generate Adaptive Mesh numberNodes = fem.numberNodes #get number quadrature points numberQuadraturePoints = fem.getNumberQuadPointsPerElement() totalnumberQuadraturePoints = numberElements*numberQuadraturePoints v= [] for line in pot: v.append(float(line)) v = np.array(v) data= np.reshape(v,(totalnumberQuadraturePoints,totalnumberQuadraturePoints,totalnumberQuadraturePoints)) # reducedRank rankVeff = 5 reducedRank = (rankVeff, rankVeff, rankVeff) #perform tensor decomposition of effective potential time_tensorStart = time.clock() #convert to a tensor fTensor = tensor.tensor(data) [a,b] = DTA.DTA(fTensor,reducedRank) time_tensorEnd = time.clock() print 'time elapsed for tensor decomposition of Veff (s)',time_tensorEnd-time_tensorStart sigma_core = a.core sigma = sigma_core.tondarray() umat = a.u[0].real vmat = a.u[1].real wmat = a.u[2].real sigma = sigma.real sigma2D = sigma.reshape((rankVeff**2,rankVeff)) # done to reduce cost while contracting functional = FunctionalRayleighQuotientSeparable.FEMFunctional(fem, rankVeff, sigma2D, [umat,vmat,wmat]) # initial guess for psix, psiy, psiz xx = globalNodalCoordinates yy = xx.copy() zz = xx.copy() X, Y, Z = meshgrid2(xx,yy,zz) psixyz = (1/np.sqrt(np.pi))*np.exp(-np.sqrt(X**2 + Y**2 + Z**2)) igTensor = tensor.tensor(psixyz) # generate tensor decomposition of above guess of rank 1 time_tensorStart = time.clock() rankIG = (1,1,1) [Psi,Xi] = DTA.DTA(igTensor,rankIG) time_tensorEnd = time.clock() print 'time elapsed(s) for DTA of initial guess',time_tensorEnd-time_tensorStart guessPsix = Psi.u[0].real guessPsiy = Psi.u[1].real guessPsiz = Psi.u[2].real guessLM = 0.2 guessFields = np.concatenate((guessPsix[1:-1],guessPsiy[1:-1],guessPsiz[1:-1])) #append the initial guess for lagrange multiplier guessFields = np.append(guessFields,guessLM) petsc = True if (petsc == False): t0 = time.clock() print 'Method fsolve' [result,infodict,ier,mesg] = scipy.optimize.fsolve(residual,guessFields,args=(functional),full_output=1,xtol=1.0e-8,maxfev=20000) print 'Number of Function Evaluations: ',infodict['nfev'] print 'Ground State Energy: ',result[-1] print 'numberElements ',numberElements print mesg t1 = time.clock() print 'time elapsed(s) for minimization problem',t1-t0 else: t0 = time.clock() snes = PETSc.SNES().create() pde = SeparableHamiltonian(functional) n = len(guessFields) F = PETSc.Vec().createSeq(n) snes.setFunction(pde.residualPetsc,F) snes.setUseMF() snes.getKSP().setType('gmres') snes.setFromOptions() X = PETSc.Vec().createSeq(n) pde.formInitGuess(snes, X,guessFields) snes.solve(None, X) print X[n-1] t1 = time.clock() print 'time elapsed(s) for minimization problem',t1-t0 result = pde.copySolution(X,guessFields)