def visit_point_mesh(self, data_func, data_x, data_y, data_z=None, owner='VISIT'): """Creates a point mesh. The handling for owner other that VISIT_OWNER_VISIT is complete and utterly untested guesswork. data_func is one of VARDATATYPES. NOTE: In Python, floats are doubles. """ h = simV2.VisIt_PointMesh_alloc() if h == simV2.VISIT_INVALID_HANDLE: return h hx = simV2.VisIt_VariableData_alloc() data_func(hx, self.DATAOWNERS[owner], 1, len(data_x), data_x) hy = simV2.VisIt_VariableData_alloc() data_func(hy, self.DATAOWNERS[owner], 1, len(data_y), data_y) if data_z is None: simV2.VisIt_PointMesh_setCoordsXY(h, hx, hy) else: hz = simV2.VisIt_VariableData_alloc() data_func(hz, self.DATAOWNERS[owner], 1, len(data_z), data_z) simV2.VisIt_PointMesh_setCoordsXYZ(h, hx, hy, hz) return h
def passData(data, owner=simV2.VISIT_OWNER_VISIT_EX): """Helper for passing data to VisIt""" valid = lambda x: x != simV2.VISIT_INVALID_HANDLE if not data.size: # not always an error, some processes # wont have data. #if __debug__: pDebug('zero size for %s'%(str(data))) return simV2.VISIT_INVALID_HANDLE vd = simV2.VisIt_VariableData_alloc() if not valid(vd): pError('VisIt_VariableData_alloc failed') return simV2.VISIT_INVALID_HANDLE ierr = simV2.VISIT_ERROR if (data.dtype == np.float64): ierr = simV2.VisIt_VariableData_setDataD(vd, owner, 1, data.size, data) elif (data.dtype == np.float32): ierr = simV2.VisIt_VariableData_setDataF(vd, owner, 1, data.size, data) elif (data.dtype == np.int32): ierr = simV2.VisIt_VariableData_setDataI(vd, owner, 1, data.size, data) elif (data.dtype == np.byte): ierr = simV2.VisIt_VariableData_setDataC(vd, owner, 1, data.size, data) if (ierr == simV2.VISIT_ERROR): pError('VisIt_VariableData_setData failed') return simV2.VISIT_INVALID_HANDLE return vd
def getDomains(name, userData): """ Callback function used to get the list of domains handled by this process """ # VisIt assumes that each process has some data # so you must have at least as many domains as # processes. you just return invalid handle in # getMesh/getVar on those processes that do not valid = lambda x: x != simV2.VISIT_INVALID_HANDLE if __debug__: pDebug('getDomains %s' % (name)) rank = parallel.get_rank() numPE = parallel.number_of_PE() vd = simV2.VisIt_VariableData_alloc() if not valid(vd): pError('VisIt_VariableData_alloc failed') return None simV2.VisIt_VariableData_setDataI(vd, simV2.VISIT_OWNER_COPY, 1, 1, [rank]) doms = simV2.VisIt_DomainList_alloc() if not valid(doms): pError('VisIt_DomainList_alloc failed') return None simV2.VisIt_DomainList_setDomains(doms, numPE, vd) return doms
def visit_curve(self, data_func, data_x, data_y, data_z=None, owner='VISIT'): """Creates a curve.""" h = simV2.VisIt_CurveData_alloc() if h == simV2.VISIT_INVALID_HANDLE: return h hx = simV2.VisIt_VariableData_alloc() data_func(hx,self.DATAOWNERS[owner],1,len(data_x),data_x) hy = simV2.VisIt_VariableData_alloc() data_func(hy,self.DATAOWNERS[owner],1,len(data_y),data_y) if data_z is None: simV2.VisIt_CurveData_setCoordsXY(h,hx,hy) else: hz = simV2.VisIt_VariableData_alloc() data_func(hz,self.DATAOWNERS[owner],1,len(data_z),data_z) simV2.VisIt_CurveData_setCoordsXYZ(h,hx,hy,hz) return h
def visit_variable(self, data_func, data, owner='VISIT', nComp=1): """Creates a variable. nComp determines the "number of components". For a precise definition see the documentation. For Floats and Ints this should typically be 1 (no stride). For character strings (such as labels), this is the length of the label; it is required that each string be the same length. """ h = simV2.VisIt_VariableData_alloc() data_func(h, self.DATAOWNERS[owner], nComp, len(data), data) return h
def getVar(domain, varid, userData): """ Callback function used to send variable data (e.g., vx) to VisIt. """ valid = lambda x: x != simV2.VISIT_INVALID_HANDLE # VisIt assumes that each process has some data # so you must have at least as many domains as # processes. you just return invalid handle in # getMesh/getVar on those processes that do not if __debug__: pDebug('getVar %i %s' % (domain, varid)) tok = varid.split(varsep) meshname = tok[0] varname = tok[1] try: # particle data pMeshNames = getParticleMeshNames() if pMeshNames.count(meshname) > 0: species = getSpecies(meshname) # rank if varname == 'rank': n = species.getx( gather=0).size # FIXME -- must be defined somehwere? if not n: return simV2.VISIT_INVALID_HANDLE rank = [float(parallel.get_rank())] * n # FIXME -- list ? vd = simV2.VisIt_VariableData_alloc() if not valid(vd): pError('VisIt_VariableData_alloc failed') return None simV2.VisIt_VariableData_setDataD(vd, simV2.VISIT_OWNER_COPY, 1, n, rank) del rank return vd getFunc = getattr(species, 'get' + varname) return passParticleData(getFunc(gather=0), getDataOwner()) # grided data elif meshname == 'grid': # ax if varname == 'ax': return passGridData(warp.geta(comp='x', local=1)) # ay if varname == 'ay': return passGridData(warp.geta(comp='y', local=1)) # az if varname == 'az': return passGridData(warp.geta(comp='z', local=1)) # A if varname == 'A': return passGridData(warp.geta(comp='A', local=1)) # b if varname == 'B': return passGridData(warp.getb(comp='B', local=1)) # bx if varname == 'bx': return passGridData(warp.getb(comp='x', local=1)) # by if varname == 'by': return passGridData(warp.getb(comp='y', local=1)) # bz if varname == 'bz': return passGridData(warp.getb(comp='z', local=1)) # j if varname == 'J': return passGridData(warp.getj(comp='J', local=1)) # jx if varname == 'jx': return passGridData(warp.getj(comp='x', local=1)) # jy if varname == 'jy': return passGridData(warp.getj(comp='y', local=1)) # jz if varname == 'jz': return passGridData(warp.getj(comp='z', local=1)) # phi if varname == 'phi': return passGridData(warp.getphi(local=1)) # rho if varname == 'rho': return passGridData(warp.getrho(local=1)) # rank if varname == 'rank': rho = warp.getrho(local=1) # FIXME -- hack to verify rhoCopy = np.reshape(rho, rho.size, order='F').tolist() # FIXME rhoCopy = [float(parallel.get_rank())] * len(rhoCopy) vd = simV2.VisIt_VariableData_alloc() if not valid(vd): pError('VisIt_VariableData_alloc failed') return None simV2.VisIt_VariableData_setDataD(vd, simV2.VISIT_OWNER_COPY, 1, rho.size, rhoCopy) return vd # the simulation crashed when we asked for # that variable except Exception as inst: pError('Warp failed to produce %s\n%s\n' % (varname, str(inst))) return simV2.VISIT_INVALID_HANDLE # invalid pError('Unrecognized variable requested %s' % (varid)) return simV2.VISIT_INVALID_HANDLE
def getMesh(domain, name, userData): """ Callback function used to send mesh data (e.g., particles) to VisIt. """ # VisIt assumes that each process has some data # so you must have at least as many domains as # processes. you just return invalid handle in # getMesh/getVar on those processes that do not valid = lambda x: x != simV2.VISIT_INVALID_HANDLE if __debug__: pDebug('getMesh %i %s' % (domain, name)) # particle mesh (note: visit copies because coords are not interleaved.) pMeshNames = getParticleMeshNames() if pMeshNames.count(name) > 0: species = getSpecies(name) xvd = passParticleData(species.getx(gather=0), getDataOwner()) yvd = passParticleData(species.gety(gather=0), getDataOwner()) zvd = passParticleData(species.getz(gather=0), getDataOwner()) if (not (valid(xvd) and valid(yvd) and valid(zvd))): if __debug__: pDebug('failed to pass particle locations') return None mesh = simV2.VisIt_PointMesh_alloc() if not valid(mesh): pError('VisIt_PointMesh_alloc failed') return None simV2.VisIt_PointMesh_setCoordsXYZ(mesh, xvd, yvd, zvd) return mesh # uniform mesh if name == 'grid': size = getGridSize() coords = getGridCoordinates() xvd = passGridData(coords[0]) yvd = passGridData(coords[1]) zvd = passGridData(coords[2]) if (not (valid(xvd) and valid(yvd) and valid(zvd))): pError('failed to pass mesh coords') return None mesh = simV2.VisIt_RectilinearMesh_alloc() if not valid(mesh): pError('VisIt_RectilinearMesh_alloc failed') return None simV2.VisIt_RectilinearMesh_setCoordsXYZ(mesh, xvd, yvd, zvd) return mesh # CSG mesh if name == 'csg': # FIXME -- parameters must be user setable piperad_outer = 3.445e-2 + 0.3 piperad_inner = piperad_outer * 0.8 pipelength = 2.0 #4. zmin = warp.top.zbeam - pipelength / 2. zmax = warp.top.zbeam + pipelength / 2. ext_min = [-piperad_outer, -piperad_outer, zmin] ext_max = [piperad_outer, piperad_outer, zmax] bound_types = [ simV2.VISIT_CSG_CYLINDER_PNLR, simV2.VISIT_CSG_CYLINDER_PNLR ] bound_coeffs = [ 0., 0., zmin, 0., 0., 1., pipelength, piperad_outer, 0., 0., zmax, 0., 0., 1., pipelength, piperad_inner ] region_operators = [ simV2.VISIT_CSG_INNER, simV2.VISIT_CSG_OUTER, simV2.VISIT_CSG_INTERSECT ] leftids = [0, 1, 0] rightids = [-1, -1, 1] zonelist = [2] mesh = simV2.VisIt_CSGMesh_alloc() if not valid(mesh): pError('VisIt_CSGMesh_alloc failed') return None cbt = simV2.VisIt_VariableData_alloc() if not valid(cbt): pError('VisIt_VariableData_alloc failed') return None simV2.VisIt_VariableData_setDataI(cbt, simV2.VISIT_OWNER_COPY, 1, 2, bound_types) simV2.VisIt_CSGMesh_setBoundaryTypes(mesh, cbt) cbc = simV2.VisIt_VariableData_alloc() if not valid(cbc): pError('VisIt_VariableData_alloc failed') return None simV2.VisIt_VariableData_setDataF(cbc, simV2.VISIT_OWNER_COPY, 1, 16, bound_coeffs) simV2.VisIt_CSGMesh_setBoundaryCoeffs(mesh, cbc) simV2.VisIt_CSGMesh_setExtents(mesh, ext_min, ext_max) cro = simV2.VisIt_VariableData_alloc() if not valid(cro): pError('VisIt_VariableData_alloc failed') return None simV2.VisIt_VariableData_setDataI(cro, simV2.VISIT_OWNER_COPY, 1, 3, region_operators) cli = simV2.VisIt_VariableData_alloc() if not valid(cli): pError('VisIt_VariableData_alloc failed') return None simV2.VisIt_VariableData_setDataI(cli, simV2.VISIT_OWNER_COPY, 1, 3, leftids) cri = simV2.VisIt_VariableData_alloc() if not valid(cri): pError('VisIt_VariableData_alloc failed') return None simV2.VisIt_VariableData_setDataI(cri, simV2.VISIT_OWNER_COPY, 1, 3, rightids) simV2.VisIt_CSGMesh_setRegions(mesh, cro, cli, cri) czl = simV2.VisIt_VariableData_alloc() if not valid(czl): pError('VisIt_VariableData_alloc failed') return None simV2.VisIt_VariableData_setDataI(czl, simV2.VISIT_OWNER_COPY, 1, 1, zonelist) simV2.VisIt_CSGMesh_setZonelist(mesh, czl) return mesh # invalid pError('Unrecognized mesh name %s' % (name)) return None