def update(self, frame_num): pyglasstools.get_sysdata().update(frame_num) self.cpphessian.setSystemData( pyglasstools.get_sysdata().cppparticledata) # if self.frame_num != frame_num: self.cpphessian.destroyObjects() self.cpphessian.assembleObjects() self.frame_num = frame_num
def __init__(self, filename, names, solver): #Save filename self.filename = filename #Next, parse the list of names based on what type of obsercables they are self.__obs_names = names #[s for s in names if "" in s or "eigenvalue" in s]; #Initialize a thermoproperty class if solver is None: if rank == 0: print("[ERROR] User must specify solver object!") comm.abort(1) elif names is None: if rank == 0: print("[ERROR] User must specify list of observables to save!") comm.abort(1) elif filename is None: if rank == 0: print("[ERROR] User must specify a filename for the logfile!") comm.abort(1) self.solver = solver #Once initialization is done, the logger adds itself to the global list of available loggers loggers_list.append(self) #write the initial files #Initialize file to save: self.file = _pyglasstools.MPILogFile(comm, self.filename) #Then, add observables self.global_obs = initialize_global( self.__obs_names, pyglasstools.get_sysdata().pysimbox.dim) self.solver.add_observables(self.global_obs) Dim = pyglasstools.get_sysdata().pysimbox.dim #Create column headers if rank == 0 and ( not os.path.exists(pyglasstools.get_sysdata().checkpointfile) or (os.path.exists(pyglasstools.get_sysdata().checkpointfile) and os.path.getsize(pyglasstools.get_sysdata().checkpointfile) == 0)): self.file.write_shared("{} ".format("Frame")) if not (not self.__obs_names): for name in self.__obs_names: if "forcedipole_center" in name or "forcedipole_pi" in name or "forcedipole_pj" in name: for i in range(Dim): self.file.write_shared("{}_{} ".format(name, i)) else: self.file.write_shared("{} ".format(name)) self.file.write_shared("\n")
def __init__(self, keyword, names, solver): #Save filename self.keyword = keyword #Next, parse the list of names based on what type of obsercables they are self.__obs_names = names #Initialize a thermoproperty class if solver is None: if rank == 0: print("[ERROR] User must specify solver object!") comm.abort(1) elif names is None: if rank == 0: print("[ERROR] User must specify list of observables to save!") comm.abort(1) self.solver = solver #Once initialization is done, the logger adds itself to the global list of available loggers loggers_list.append(self) #write the initial files #Then, add observables self.field_obs = initialize_field( self.__obs_names, pyglasstools.get_sysdata().pysimbox.dim) self.solver.add_observables(self.field_obs) self.file = _pyglasstools.MPILogFile(comm, "{}".format(keyword) + ".xyz")
def __init__(self): #Initialize system data and pair potential of the system self.manager = _pyglasstools.Manager() self.thermocalculator = _thermo.ThermoCalculator( pyglasstools.get_sysdata().cppparticledata, pyglasstools.get_potential().cpppairpotential) solvers_list.append(self)
def save(self, frame_num): if rank == 0: self.file.write_shared("{} ".format(frame_num)) for name in self.__obs_names: Dim = pyglasstools.get_sysdata().pysimbox.dim if "potentialenergy" in name: self.global_obs['potentialenergy'].save(self.file, 0) self.file.write_shared(" ") if "virialstress" in name: i = int(name[-2]) j = int(name[-1]) self.global_obs['virialstress'].save( self.file, i + Dim * j) self.file.write_shared(" ") elif "kineticstress" in name: i = int(name[-2]) j = int(name[-1]) self.global_obs['kineticstress'].save( self.file, i + Dim * j) self.file.write_shared(" ") elif "borntensor" in name: i = int(name[-4]) j = int(name[-3]) k = int(name[-2]) l = int(name[-1]) #self.global_obs['borntensor'].save(self.file,i+Dim*(j+Dim*(k+Dim*l))) self.global_obs['borntensor'].save( self.file, l + Dim * (k + Dim * (j + Dim * i))) self.file.write_shared(" ") self.file.write_shared("\n")
def save(self, frame_num): if self.solver.pyhessian.check_diagonals(): if rank == 0: self.file.write_shared("{:d} \n".format( len(pyglasstools.get_sysdata().traj[frame_num].particles. position))) self.file.write_shared("#Frame {:d} \n".format(frame_num)) comm.barrier() self.save_perrank(frame_num)
def __init__(self, cgfunc, dx): self.cgfunc = cgfunc self.manager = _pyglasstools.Manager() self.coordmode = "cartesian" #Maybe move it to C++ side . . . . globalsize = 0 if rank == 0: nmax = int(pyglasstools.get_sysdata().pysimbox.boxsize[0] / dx) points = np.linspace( -pyglasstools.get_sysdata().pysimbox.boxsize[0] / 2.0, +pyglasstools.get_sysdata().pysimbox.boxsize[0] / 2.0, nmax) gridpoints = [] for i in range(len(points)): for j in range(len(points)): gridpoints.append( np.asarray([points[i], points[j], 0], dtype=np.float64)) globalsize = len(gridpoints) self.gridpoints = np.array_split( np.asarray(gridpoints, dtype=np.float64), size) del points, nmax else: self.gridpoints = np.array_split([np.zeros(size)], size) #Scatter and reshape self.gridpoints = comm.scatter_v(self.gridpoints, 0) self.gridpoints = np.reshape(self.gridpoints, (len(self.gridpoints), 3)) #Broadcast the true size self.gridsize = comm.bcast(globalsize, 0) self.calculator = _irvingkirkwood.IrvingKirkwood( pyglasstools.get_sysdata().cppparticledata, pyglasstools.get_potential().cpppairpotential, cgfunc._getCGFunc(), comm) solvers_list.append(self)
def save_perrank(self, frame_num): Dim = pyglasstools.get_sysdata().pysimbox.dim ave, res = divmod( len(pyglasstools.get_sysdata().traj[frame_num].particles.position), size) counts = [ave + 1 if p < res else ave for p in range(size)] # determine the starting and ending indices of each sub-task starts = [sum(counts[:p]) for p in range(size)] ends = [sum(counts[:p + 1]) for p in range(size)] # converts data into a list of arrays #Do scatter for each held eigenvectors for name in self.__obs_names: if "eigenvector" in name: self.field_obs[name].scatterVector(starts[rank], counts[rank]) for i in range(starts[rank], ends[rank]): outline = "{} ".format(1) outline += "{} ".format( pyglasstools.get_sysdata().traj[frame_num].particles.position[ i, 0]) outline += "{} ".format( pyglasstools.get_sysdata().traj[frame_num].particles.position[ i, 1]) if Dim == 3: outline += "{} ".format(pyglasstools.get_sysdata( ).traj[frame_num].particles.position[i, 2]) for name in self.__obs_names: flattenindex = 0 if "forcedipole" in name: outline += self.field_obs["forcedipole"].gettostring(i) if "eigenvector" in name: outline += self.field_obs[name].gettostring(i - starts[rank]) outline += "\n" self.file.write_shared(outline)
def get_vectorfield(self, name, frame_num): vector = [] ave, res = divmod( len(pyglasstools.get_sysdata().traj[frame_num].particles.position), size) counts = [ave + 1 if p < res else ave for p in range(size)] starts = sum(counts[:rank]) ends = sum(counts[:rank + 1]) for i in range(starts, ends): vector.append( np.reshape(self.field_obs[name].getVectorValue(i), (3, ))) #Next, we gather all of these vectors newvector = comm.all_gather_v(vector) vector = [item for sublist in newvector for item in sublist] #vector = np.reshape(newvector,(len(pyglasstools.get_sysdata().traj[frame_num].particles.position),3)); del newvector return vector #Reshape
def save_perrank_polar(self, frame_num): Dim = pyglasstools.get_sysdata().pysimbox.dim for index, gridpos in enumerate(self.solver.gridpoints): outline = "{} ".format(1) outline += "{} ".format(int(self.solver.gridid[index])) outline += "{} ".format(self.solver.globalr[index]) outline += "{} ".format(self.solver.globaltheta[index]) for name in self.__obs_names: flattenindex = 0 if "stress" in name: i = int(name[-2]) j = int(name[-1]) flattenindex = i + Dim * j outline += self.field_obs[name[:-3]].gettostring( i + Dim * j, index) outline += "\n" self.file.write_shared(outline)
def save(self, frame_num): if rank == 0 and self.solver.pyhessian.check_diagonals(): self.file.write_shared("{} ".format(frame_num)) for name in self.__obs_names: Dim = pyglasstools.get_sysdata().pysimbox.dim if "forcedipole" in name: for i in range(Dim): self.global_obs[name].save(self.file, i) self.file.write_shared(" ") if "eigenvalue" in name or "nconv" in name or "eigenrelerr" in name: self.global_obs[name].save(self.file) if "nonaffinetensor" in name: i = int(name[-4]) j = int(name[-3]) k = int(name[-2]) l = int(name[-1]) self.global_obs['nonaffinetensor'].save( self.file, l + Dim * (k + Dim * (j + Dim * i))) self.file.write_shared(" ") self.file.write_shared("\n")
def __init__(self, package): #Initialize system data and pair potential of the system self.package = package self.cppmanager = _elasticity.PETScManager() dimensions = pyglasstools.get_sysdata().pysimbox.dim if (package == "petsc"): if dimensions == 2: self.cpphessian = _elasticity.PETScHessian2D( pyglasstools.get_sysdata().cppparticledata, pyglasstools.get_potential().cpppairpotential, self.cppmanager, comm) else: self.cpphessian = _elasticity.PETScHessian3D( pyglasstools.get_sysdata().cppparticledata, pyglasstools.get_potential().cpppairpotential, self.cppmanager, comm) elif (package == "slepc"): if dimensions == 2: self.cpphessian = _elasticity.SLEPcHessian2D( pyglasstools.get_sysdata().cppparticledata, pyglasstools.get_potential().cpppairpotential, self.cppmanager, comm) else: self.cpphessian = _elasticity.SLEPcHessian3D( pyglasstools.get_sysdata().cppparticledata, pyglasstools.get_potential().cpppairpotential, self.cppmanager, comm) elif (package == "spectra"): if dimensions == 2: self.cpphessian = _elasticity.SpectraHessian2D( pyglasstools.get_sysdata().cppparticledata, pyglasstools.get_potential().cpppairpotential, self.cppmanager, comm) else: self.cpphessian = _elasticity.SpectraHessian3D( pyglasstools.get_sysdata().cppparticledata, pyglasstools.get_potential().cpppairpotential, self.cppmanager, comm) self.frame_num = pyglasstools.get_sysdata().frame_num
def update(self, frame_num): pyglasstools.update_sysdata(frame_num) self.calculator.setSystemData( pyglasstools.get_sysdata().cppparticledata)
def __init__(self, cgfunc, center=np.array([0, 0, 0]), spacingtype="normal", rmax=10, rmin=0, dr=0.1, dlnr=0.05): self.cgfunc = cgfunc self.manager = _pyglasstools.Manager() self.coordmode = "polar" #TO DO: Move all of this hassle to C++ side . . . . globalsize = 0 self.center = center if rank == 0: gridpoints = [] if spacingtype == "normal": r = np.linspace(0, rmax, int(rmax / dr))[1:] elif spacingtype == "log": r = np.exp( np.linspace(np.log(rmin), np.log(rmax), int((np.log(rmax) - np.log(rmin)) / dlnr))) gridid = [] #id based on radius globalr = [] globaltheta = [] gridpoints = [] #Append the origin gridid.append(0) globalr.append(0) globaltheta.append(0) gridpoints.append(self.center) for i in range(len(r)): dtheta = dr / r[i] theta = np.linspace(0, 2 * np.pi, int(2 * np.pi / dtheta)) x = r[i] * np.cos(theta) y = r[i] * np.sin(theta) for j in range(len(theta)): gridid.append(i + 1) globalr.append(r[i]) globaltheta.append(theta[j]) gridpoints.append( np.asarray([x[j], y[j], 0], dtype=np.float64) + self.center) globalsize = len(gridpoints) #print(np.shape(gridpoints),np.shape(center)) self.gridid = np.array_split(np.asarray(gridid, dtype=np.float64), size) self.globalr = np.array_split( np.asarray(globalr, dtype=np.float64), size) self.globaltheta = np.array_split( np.asarray(globaltheta, dtype=np.float64), size) self.gridpoints = np.array_split( np.asarray(gridpoints, dtype=np.float64), size) del r, theta, dtheta, x, y, gridpoints, gridid, globalr, globaltheta else: self.gridid = np.array_split(np.zeros(size), size) self.globalr = np.array_split(np.zeros(size), size) self.globaltheta = np.array_split(np.zeros(size), size) self.gridpoints = np.array_split([np.zeros(size)], size) #Scatter and reshape self.gridid = comm.scatter_v(self.gridid, 0) self.gridid = np.reshape(self.gridid, (len(self.gridid), )) #Scatter and reshape self.globalr = comm.scatter_v(self.globalr, 0) self.globalr = np.reshape(self.globalr, (len(self.globalr), )) #Scatter and reshape self.globaltheta = comm.scatter_v(self.globaltheta, 0) self.globaltheta = np.reshape(self.globaltheta, (len(self.globaltheta), )) #Scatter and reshape self.gridpoints = comm.scatter_v(self.gridpoints, 0) self.gridpoints = np.reshape(self.gridpoints, (len(self.gridpoints), 3)) #Broadcast the true size self.gridsize = comm.bcast(globalsize, 0) #del globalsize self.calculator = _irvingkirkwood.IrvingKirkwood( pyglasstools.get_sysdata().cppparticledata, pyglasstools.get_potential().cpppairpotential, cgfunc._getCGFunc(), comm) solvers_list.append(self)