Пример #1
0
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
Пример #2
0
    def GetRenderScripts(self):
        """
        This function returns a dictionary of rendering scripts
        whose key is a descriptive string. This dictionary will
        be used when our Render function returns a list of scripts
        to run to access the script source code. The source is
        given to VisIt CLI for execution.

        This implementation expects that the user will have called
        AddRenderScripts for each script, initializing the key and
        script scource file name. The first time we are called we
        load the scripts replacing source file with the source
        itself.
        """
        # return the disctionary
        if self._HaveRenderScripts:
            return self._RenderScripts

        # transform the dictionary values from source file names
        # into source code.
        if self._RenderScripts is None:
            pError('RenderScripts uninitialized')
            return {}

        for key,fileName in self._RenderScripts.iteritems():
            if not self._ScriptDir is None:
                fileName = os.path.join(self._ScriptDir,fileName)
            f = open(fileName)
            code = f.read()
            f.close()
            self._RenderScripts[key] = code

        self._HaveRenderScripts = True

        return self._RenderScripts
Пример #3
0
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
Пример #4
0
    def GetRenderScripts(self):
        """
        This function returns a dictionary of rendering scripts
        whose key is a descriptive string. This dictionary will
        be used when our Render function returns a list of scripts
        to run to access the script source code. The source is
        given to VisIt CLI for execution.

        This implementation expects that the user will have called
        AddRenderScripts for each script, initializing the key and
        script scource file name. The first time we are called we
        load the scripts replacing source file with the source
        itself.
        """
        # return the disctionary
        if self._HaveRenderScripts:
            return self._RenderScripts

        # transform the dictionary values from source file names
        # into source code.
        if self._RenderScripts is None:
            pError('RenderScripts uninitialized')
            return {}

        for key, fileName in self._RenderScripts.iteritems():
            if not self._ScriptDir is None:
                fileName = os.path.join(self._ScriptDir, fileName)
            f = open(fileName)
            code = f.read()
            f.close()
            self._RenderScripts[key] = code

        self._HaveRenderScripts = True

        return self._RenderScripts
Пример #5
0
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
Пример #6
0
    def Initialize(self):
        """
        Configure the object. If the sim2 file is
        located before timeout occurs True is returned.
        """
        if __debug__: pDebug('WarpVisItCLI::Initialize')
        # we may need to wait while the engine launches
        # in a separate process
        simFileFound = False
        n = self.__Timeout / 10
        i = 0
        while i < n:
            if os.path.isfile(self.__SimFile):
                simFileFound = True
                sys.stderr.write('CLI found sim file (%s)' % (self.__SimFile))
                break
            else:
                sys.stderr.write('.')
                time.sleep(10)
            i += 1
        sys.stderr.write('\n')

        if not simFileFound:
            pError('CLI failed to find sim file (%s)' % (self.__SimFile))
            return False

        return True
Пример #7
0
    def Initialize(self):
        """
        Configure the object. If the sim2 file is
        located before timeout occurs True is returned.
        """
        if __debug__: pDebug('WarpVisItCLI::Initialize')
        # we may need to wait while the engine launches
        # in a separate process
        simFileFound=False
        n = self.__Timeout/10
        i = 0
        while i<n:
            if os.path.isfile(self.__SimFile):
                simFileFound=True
                sys.stderr.write('CLI found sim file (%s)'%(self.__SimFile))
                break
            else:
                sys.stderr.write('.')
                time.sleep(10)
            i += 1
        sys.stderr.write('\n')

        if not simFileFound:
            pError('CLI failed to find sim file (%s)'%(self.__SimFile))
            return False

        return True
Пример #8
0
    def Initalize(self, engineOpts=''):
        """
        Perform the initial setup of VisIt to include the libsim module
        with the simulation.
        """
        if __debug__: pDebug('WarpVisItEngine::Initialize')

        # initialize libsim
        simV2.VisItSetBroadcastIntFunction(broadcastInt)
        simV2.VisItSetBroadcastStringFunction(broadcastString)
        simV2.VisItSetParallelRank(self._CommRank)
        simV2.VisItSetParallel(self._CommSize > 1)
        simV2.VisItSetDirectory(self._Env.GetRoot())
        simV2.VisItSetupEnvironment()

        if self._TraceFile:
            simV2.VisItOpenTraceFile('%d.trace' % (self._CommRank))

        if self._EngineOpts:
            if __debug__: pDebug('Using options %s' % (self._EngineOpts))
            simV2.VisItSetOptions(self._EngineOpts)

        if self._CommRank == 0:
            if not simV2.VisItInitializeSocketAndDumpSimFile(
                    'WarpVisIt', None, os.getcwd(), None, None, self._SimFile):
                pError('VisIt initialization failed')
                return False

        self._Behavior.Initialize()

        return True
Пример #9
0
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
Пример #10
0
    def Initalize(self, engineOpts=''):
        """
        Perform the initial setup of VisIt to include the libsim module
        with the simulation.
        """
        if __debug__: pDebug('WarpVisItEngine::Initialize')


        # initialize libsim
        simV2.VisItSetBroadcastIntFunction(broadcastInt)
        simV2.VisItSetBroadcastStringFunction(broadcastString)
        simV2.VisItSetParallelRank(self._CommRank)
        simV2.VisItSetParallel(self._CommSize > 1)
        simV2.VisItSetDirectory(self._Env.GetRoot())
        simV2.VisItSetupEnvironment()

        if self._TraceFile:
            simV2.VisItOpenTraceFile('%d.trace'%(self._CommRank))

        if self._EngineOpts:
            if __debug__: pDebug('Using options %s'%(self._EngineOpts))
            simV2.VisItSetOptions(self._EngineOpts);

        if self._CommRank == 0:
            if not simV2.VisItInitializeSocketAndDumpSimFile(
                  'WarpVisIt', None, os.getcwd(), None, None, self._SimFile):
                pError('VisIt initialization failed')
                return False

        self._Behavior.Initialize()

        return True
Пример #11
0
def getSpecies(meshName):
    """Given a mesh name locate the spceies object for it"""
    meshNames = getParticleMeshNames()
    if meshNames.count(meshName) > 0:
        return warp.listofallspecies[meshNames.index(meshName)]
    else:
        pError('Could not find species for mesh %s' % (meshName))
    return None
Пример #12
0
def getSpecies(meshName):
    """Given a mesh name locate the spceies object for it"""
    meshNames = getParticleMeshNames()
    if meshNames.count(meshName) > 0:
        return warp.listofallspecies[meshNames.index(meshName)]
    else:
        pError('Could not find species for mesh %s'%(meshName))
    return None
Пример #13
0
    def CreateSimulation(self):
        """
        Create a WarpVisItSimulation instance using the user
        supplied factory function.
        """
        if not os.path.isfile(self.__FactoryScript):
            pError('Failed to locate factory script (%s)' %
                   self.__FactoryScript)
            raise RuntimeError('Invalid script file')

        # load the script containing the factory function
        factory = imp.load_source('warpScript', self.__FactoryScript)
        # use the factory to create an interface we can use to
        # which ever simulation the user is running
        simulation = factory.NewWarpVisItSimulation(self.__Args)
        return simulation
Пример #14
0
    def Process(self, qcmd):
        """
        process batch control commands.

        adv : take a step and intiate the next step
        end : shut everything down
        """
        if qcmd == 'adv':
            self.__Engine.StepSimulation()
            self.__Engine.ProbeMemory()
            self.Update()

        elif (qcmd == 'end'):
            self.__Engine.RequestShutdown()

        else:
            pError('Unrecognized command %s'%(qcmd))
        return
Пример #15
0
    def Process(self, qcmd):
        """
        process batch control commands.

        adv : take a step and intiate the next step
        end : shut everything down
        """
        if qcmd == 'adv':
            self.__Engine.StepSimulation()
            self.__Engine.ProbeMemory()
            self.Update()

        elif (qcmd == 'end'):
            self.__Engine.RequestShutdown()

        else:
            pError('Unrecognized command %s' % (qcmd))
        return
Пример #16
0
    def Process(self, qcmd):
        """
        process monitor control commands.
        """
        if qcmd == 'pause':
            pStatus('WarpVisItEngine pause')
            self.__Engine._VisItBlockingComm = True
            self.__Engine._VisItControlStepping = True
            self.__Engine._UpdateVisItGUI = True
            self.Update()

        elif qcmd == 'step':
            pStatus('WarpVisItEngine step')
            self.__Engine._VisItBlockingComm = True
            self.__Engine._VisItControlStepping = True
            self.__Engine._UpdateVisItGUI = True
            self.__Engine.StepSimulation()
            self.Update()

        elif qcmd == 'run':
            pStatus('WarpVisItEngine run')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = True

        elif qcmd == 'continue':
            pStatus('WarpVisItEngine continue')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = False

        elif qcmd == 'end' or qcmd == 'disconnect':
            pStatus('WarpVisItEngine disconnect')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = False
            self.__Engine.Disconnect()

        else:
            pError('Unrecognized command %s'%(qcmd))
        return
Пример #17
0
    def Process(self, qcmd):
        """
        process monitor control commands.
        """
        if qcmd == 'pause':
            pStatus('WarpVisItEngine pause')
            self.__Engine._VisItBlockingComm = True
            self.__Engine._VisItControlStepping = True
            self.__Engine._UpdateVisItGUI = True
            self.Update()

        elif qcmd == 'step':
            pStatus('WarpVisItEngine step')
            self.__Engine._VisItBlockingComm = True
            self.__Engine._VisItControlStepping = True
            self.__Engine._UpdateVisItGUI = True
            self.__Engine.StepSimulation()
            self.Update()

        elif qcmd == 'run':
            pStatus('WarpVisItEngine run')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = True

        elif qcmd == 'continue':
            pStatus('WarpVisItEngine continue')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = False

        elif qcmd == 'end' or qcmd == 'disconnect':
            pStatus('WarpVisItEngine disconnect')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = False
            self.__Engine.Disconnect()

        else:
            pError('Unrecognized command %s' % (qcmd))
        return
Пример #18
0
    def CommunicateLibsim(self):
        """ProcessCommand internal VisIt commands."""
        masterRank = lambda r: r == 0
        COMMAND_PROCESS = 0
        COMMAND_SUCCESS = 1
        COMMAND_FAILURE = 2

        if __debug__: pDebug('WarpVisItEngine::ProcessCommands')

        if masterRank(self._CommRank):
            if simV2.VisItProcessEngineCommand():
                if __debug__: pDebug('master success')
                broadcastSlaveCommand(COMMAND_SUCCESS)
                return True

            else:
                if __debug__: pDebug('master discconnect')
                broadcastSlaveCommand(COMMAND_FAILURE)
                return False

        else:
            while True:
                command = broadcastSlaveCommand()
                if __debug__: pDebug('slave command %i' % (command))

                if command == COMMAND_PROCESS:
                    if __debug__: pDebug('slave process command')
                    simV2.VisItProcessEngineCommand()

                elif command == COMMAND_SUCCESS:
                    if __debug__: pDebug('slave success')
                    return True

                elif command == COMMAND_FAILURE:
                    if __debug__: pDebug('slave disconnect')
                    return False

                else:
                    pError('Bad command %i' % (command))

        return False
Пример #19
0
    def CommunicateLibsim(self):
        """ProcessCommand internal VisIt commands."""
        masterRank = lambda r: r==0
        COMMAND_PROCESS = 0
        COMMAND_SUCCESS = 1
        COMMAND_FAILURE = 2

        if __debug__: pDebug('WarpVisItEngine::ProcessCommands')

        if masterRank(self._CommRank):
            if simV2.VisItProcessEngineCommand():
                if __debug__: pDebug('master success')
                broadcastSlaveCommand(COMMAND_SUCCESS)
                return True

            else:
                if __debug__: pDebug('master discconnect')
                broadcastSlaveCommand(COMMAND_FAILURE)
                return False

        else:
            while True:
                command = broadcastSlaveCommand()
                if __debug__: pDebug('slave command %i'%(command))

                if command == COMMAND_PROCESS:
                    if __debug__: pDebug('slave process command')
                    simV2.VisItProcessEngineCommand()

                elif command == COMMAND_SUCCESS:
                    if __debug__: pDebug('slave success')
                    return True

                elif command == COMMAND_FAILURE:
                    if __debug__: pDebug('slave disconnect')
                    return False

                else:
                    pError('Bad command %i'%(command))

        return False
Пример #20
0
    def Process(self, qcmd):
        """
        process interact control commands.
        """
        if (qcmd == 'end'):
            self.__Engine.RequestShutdown()

        elif qcmd == 'pause':
            pStatus('WarpVisItEngine pause')
            self.__Engine._VisItBlockingComm = True
            self.__Engine._VisItControlStepping = True
            self.__Engine._UpdateVisItGUI = True
            self.Update()

        elif qcmd == 'step':
            pStatus('WarpVisItEngine step')
            self.__Engine._VisItBlockingComm = True
            self.__Engine._VisItControlStepping = True
            self.__Engine._UpdateVisItGUI = True
            self.__Engine.StepSimulation()
            self.Update()

        elif qcmd == 'run':
            pStatus('WarpVisItEngine run')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = True

        elif qcmd == 'continue':
            pStatus('WarpVisItEngine continue')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = False

        else:
            pError('Unrecognized command %s' % (qcmd))

        return
Пример #21
0
    def Process(self, qcmd):
        """
        process interact control commands.
        """
        if (qcmd == 'end'):
            self.__Engine.RequestShutdown()

        elif qcmd == 'pause':
            pStatus('WarpVisItEngine pause')
            self.__Engine._VisItBlockingComm = True
            self.__Engine._VisItControlStepping = True
            self.__Engine._UpdateVisItGUI = True
            self.Update()

        elif qcmd == 'step':
            pStatus('WarpVisItEngine step')
            self.__Engine._VisItBlockingComm = True
            self.__Engine._VisItControlStepping = True
            self.__Engine._UpdateVisItGUI = True
            self.__Engine.StepSimulation()
            self.Update()

        elif qcmd == 'run':
            pStatus('WarpVisItEngine run')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = True

        elif qcmd == 'continue':
            pStatus('WarpVisItEngine continue')
            self.__Engine._VisItBlockingComm = False
            self.__Engine._VisItControlStepping = False
            self.__Engine._UpdateVisItGUI = False

        else:
            pError('Unrecognized command %s'%(qcmd))

        return
Пример #22
0
    def EventLoop(self, args=['-nowin']):
        """
        Open the VisIt viewer, connect to the simulation and then execute
        the visualization defined by the visFunction. Any given arguments
        are passed on to the viewer in the form of command line arguments.
        """
        from WarpVisItUtil import pDebug,pError
        from visit import visit
        import sys
        import os
        if __debug__: pDebug('WarpVisItCLI::EventLoop')

        # this process becomes the CLI. here is where we start the viewer
        # process.
        if self.__ViewerOpts:
            args += self.__ViewerOpts.split()

        for arg in args:
            visit.AddArgument(arg)

        visit.Launch()
        ok = visit.OpenDatabase(self.__SimFile)

        # rm the sim file. if left hanging around
        # it could cause the next run to fail and
        # we don't need it after we've opened it
        if ok:
            os.unlink(self.__SimFile)

        while ok:
            time.sleep(500)
            pass
            # keep this process alive.

        # CLI is finished
        pError('CLI failed to launch')
        return False
Пример #23
0
    def EventLoop(self, args=['-nowin']):
        """
        Open the VisIt viewer, connect to the simulation and then execute
        the visualization defined by the visFunction. Any given arguments
        are passed on to the viewer in the form of command line arguments.
        """
        from WarpVisItUtil import pDebug, pError
        from visit import visit
        import sys
        import os
        if __debug__: pDebug('WarpVisItCLI::EventLoop')

        # this process becomes the CLI. here is where we start the viewer
        # process.
        if self.__ViewerOpts:
            args += self.__ViewerOpts.split()

        for arg in args:
            visit.AddArgument(arg)

        visit.Launch()
        ok = visit.OpenDatabase(self.__SimFile)

        # rm the sim file. if left hanging around
        # it could cause the next run to fail and
        # we don't need it after we've opened it
        if ok:
            os.unlink(self.__SimFile)

        while ok:
            time.sleep(500)
            pass
            # keep this process alive.

        # CLI is finished
        pError('CLI failed to launch')
        return False
Пример #24
0
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
Пример #25
0
    def EventLoop(self):
        """
        Run the VisIt controlled event loop. Return False on error
        """
        doError = lambda e: e < 0
        doUpdate = lambda e: e == 0
        doConnect = lambda e: e == 1
        doInternal = lambda e: e == 2
        masterRank = lambda r: r == 0
        onErrorContinue = lambda: self._Behavior == 'Monitor'

        if __debug__: pDebug('WarpVisItEngine::EventLoop')

        while 1:
            # test or wait for incomming communication.
            if masterRank(self._CommRank):
                event = simV2.VisItDetectInput(self._VisItBlockingComm, -1)
                parallel.broadcast(event)
            else:
                event = parallel.broadcast(0)

            # process incomming communication
            if __debug__: pDebug('event=%d' % (event))

            # internal comm error
            if doError(event):
                # the VisIt viewer disconnected.
                pError('An communication error was detected')
                self._Behavior.Initialize()
                if onErrorContinue():
                    continue
                else:
                    return False

            # simulate
            elif doUpdate(event):
                # this is where we can safely do things.
                # it occurs only when VisIt is not in the
                # middle of processing its own commands.
                if __debug__: pDebug('update')
                self._Behavior.Update()
                # TODO -- is it useful to force gc??
                #gc.collect()

            # internal connection
            elif doConnect(event):
                if simV2.VisItAttemptToCompleteConnection() == 1:
                    pStatus('WarpVisItEngine connected')
                    self.ConnectLibsim()
                    self._Behavior.Connect()
                    self._Behavior.Update()
                else:
                    pError('Connection failed')
                    self._Behavior.Initialize()
                    if onErrorContinue():
                        continue
                    else:
                        return False

            # internal comm
            elif doInternal(event):
                if __debug__: pDebug('internal')
                if not self.CommunicateLibsim():
                    pError('Error while processing internal commands')
                    self._Behavior.Initialize()
                    if onErrorContinue():
                        continue
                    else:
                        return False

            # bad value
            else:
                pError('unknown command %d' % (event))

            # check for asynchronous shutdown request
            if self._ShutdownRequested:
                pStatus('WarpVisItEngine exiting the event loop')
                simV2.VisItDisconnect()
                self._Connected = False
                return True

            continue

        return False
Пример #26
0
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
Пример #27
0
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
Пример #28
0
def getMetaData(userData):
    """
    Callback function used to provide visit with metadata
    """
    valid = lambda x: x != simV2.VISIT_INVALID_HANDLE
    if __debug__: pDebug('getMetaData')

    # 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
    nDomains = parallel.number_of_PE()

    simmd = simV2.VisIt_SimulationMetaData_alloc()
    if not valid(simmd):
        pError('VisIt_SimulationMetaData_alloc failed')
        return None

    # time
    simV2.VisIt_SimulationMetaData_setCycleTime(simmd, warp.top.it,
                                                warp.top.time)

    # particles
    pMeshNames = getParticleMeshNames()
    if len(pMeshNames) < 1:
        pError('No particle mesh names were found')
    for pMeshName in pMeshNames:
        # see: warp/scripts/species.py
        # a mesh for each species
        meshmd = simV2.VisIt_MeshMetaData_alloc()
        simV2.VisIt_MeshMetaData_setName(meshmd, pMeshName)
        simV2.VisIt_MeshMetaData_setMeshType(meshmd,
                                             simV2.VISIT_MESHTYPE_POINT)
        simV2.VisIt_MeshMetaData_setTopologicalDimension(meshmd, 0)
        simV2.VisIt_MeshMetaData_setSpatialDimension(meshmd, 3)
        simV2.VisIt_MeshMetaData_setNumDomains(meshmd, nDomains)
        simV2.VisIt_MeshMetaData_setDomainTitle(meshmd, 'Domains')
        simV2.VisIt_MeshMetaData_setDomainPieceName(meshmd, 'domain')
        simV2.VisIt_MeshMetaData_setNumGroups(meshmd, 0)
        simV2.VisIt_MeshMetaData_setXUnits(meshmd, 'm')
        simV2.VisIt_MeshMetaData_setYUnits(meshmd, 'm')
        simV2.VisIt_MeshMetaData_setZUnits(meshmd, 'm')
        simV2.VisIt_MeshMetaData_setXLabel(meshmd, 'x')
        simV2.VisIt_MeshMetaData_setYLabel(meshmd, 'y')
        simV2.VisIt_MeshMetaData_setZLabel(meshmd, 'z')
        simV2.VisIt_SimulationMetaData_addMesh(simmd, meshmd)
        # per species data
        pVarNames = [
            'pid', 'n', 'x', 'y', 'z', 'w', 'r', 'theta', 'vtheta', 'etheta',
            'btheta', 'vx', 'vy', 'vz', 'vr', 'ux', 'uy', 'uz', 'ex', 'ey',
            'ez', 'er', 'bx', 'by', 'bz', 'br', 'xp', 'yp', 'zp', 'rp', 'tp',
            'gaminv', 'weights', 'ke', 'rank'
        ]
        pVarNames.sort()
        for var in pVarNames:
            vmd = simV2.VisIt_VariableMetaData_alloc()
            if not valid(vmd):
                pError('VisIt_VariableMetaData_alloc failed')
                return None
            varname = '%s%s%s' % (pMeshName, varsep, var)
            simV2.VisIt_VariableMetaData_setName(vmd, varname)
            simV2.VisIt_VariableMetaData_setMeshName(vmd, pMeshName)
            simV2.VisIt_VariableMetaData_setType(vmd,
                                                 simV2.VISIT_VARTYPE_SCALAR)
            simV2.VisIt_VariableMetaData_setCentering(
                vmd, simV2.VISIT_VARCENTERING_NODE)
            simV2.VisIt_SimulationMetaData_addVariable(simmd, vmd)
        # expressions
        expname = lambda x: x[0]
        expstr = lambda x: x[1]
        exptype = lambda x: x[2]
        for exp in [
            ('{0}/v', '{{<{0}/vx>, <{0}/vy>, <{0}/vz>}}',
             simV2.VISIT_VARTYPE_VECTOR),
            ('{0}/V',
             'sqrt(<{0}/vx>*<{0}/vx>+<{0}/vy>*<{0}/vy>+<{0}/vz>*<{0}/vz>)',
             simV2.VISIT_VARTYPE_SCALAR),
            ('{0}/B',
             'sqrt(<{0}/bx>*<{0}/bx>+<{0}/by>*<{0}/by>+<{0}/bz>*<{0}/bz>)',
             simV2.VISIT_VARTYPE_SCALAR),
            ('{0}/E',
             'sqrt(<{0}/ex>*<{0}/ex>+<{0}/ey>*<{0}/ey>+<{0}/ez>*<{0}/ez>)',
             simV2.VISIT_VARTYPE_SCALAR)
        ]:
            expmd = simV2.VisIt_ExpressionMetaData_alloc()
            if not valid(expmd):
                pError('VisIt_ExpressionMetaData_alloc failed')
                return None
            simV2.VisIt_ExpressionMetaData_setName(
                expmd,
                expname(exp).format(pMeshName))
            simV2.VisIt_ExpressionMetaData_setDefinition(
                expmd,
                expstr(exp).format(pMeshName))
            simV2.VisIt_ExpressionMetaData_setType(expmd, exptype(exp))
            simV2.VisIt_SimulationMetaData_addExpression(simmd, expmd)

    # field mesh
    meshmd = simV2.VisIt_MeshMetaData_alloc()
    if not valid(meshmd):
        pError('VisIt_MeshMetaData_alloc failed')
        return None
    simV2.VisIt_MeshMetaData_setName(meshmd, 'grid')
    simV2.VisIt_MeshMetaData_setMeshType(meshmd,
                                         simV2.VISIT_MESHTYPE_RECTILINEAR)
    simV2.VisIt_MeshMetaData_setTopologicalDimension(meshmd, 3)
    simV2.VisIt_MeshMetaData_setSpatialDimension(meshmd, 3)
    simV2.VisIt_MeshMetaData_setNumDomains(meshmd, nDomains)
    simV2.VisIt_MeshMetaData_setDomainTitle(meshmd, 'Domains')
    simV2.VisIt_MeshMetaData_setDomainPieceName(meshmd, 'domain')
    simV2.VisIt_MeshMetaData_setNumGroups(meshmd, 0)
    simV2.VisIt_MeshMetaData_setXUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setYUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setZUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setXLabel(meshmd, 'x')
    simV2.VisIt_MeshMetaData_setYLabel(meshmd, 'y')
    simV2.VisIt_MeshMetaData_setZLabel(meshmd, 'z')
    simV2.VisIt_SimulationMetaData_addMesh(simmd, meshmd)

    # CSG mesh
    meshmd = simV2.VisIt_MeshMetaData_alloc()
    if not valid(meshmd):
        pError('VisIt_MeshMetaData_alloc failed')
        return None
    simV2.VisIt_MeshMetaData_setName(meshmd, 'csg')
    simV2.VisIt_MeshMetaData_setMeshType(meshmd, simV2.VISIT_MESHTYPE_CSG)
    simV2.VisIt_MeshMetaData_setTopologicalDimension(meshmd, 3)
    simV2.VisIt_MeshMetaData_setSpatialDimension(meshmd, 3)
    simV2.VisIt_MeshMetaData_setNumDomains(meshmd, nDomains)
    simV2.VisIt_MeshMetaData_setDomainTitle(meshmd, 'Domains')
    simV2.VisIt_MeshMetaData_setDomainPieceName(meshmd, 'domain')
    simV2.VisIt_MeshMetaData_setNumGroups(meshmd, 0)
    simV2.VisIt_MeshMetaData_setXUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setYUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setZUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setXLabel(meshmd, 'x')
    simV2.VisIt_MeshMetaData_setYLabel(meshmd, 'y')
    simV2.VisIt_MeshMetaData_setZLabel(meshmd, 'z')
    simV2.VisIt_SimulationMetaData_addMesh(simmd, meshmd)

    # field data arrays
    for var in [
            'ax', 'ay', 'az', 'A', 'bx', 'by', 'bz', 'B', 'J', 'jx', 'jy',
            'jz', 'phi', 'rho', 'rank'
    ]:
        vmd = simV2.VisIt_VariableMetaData_alloc()
        if not valid(vmd):
            pError('VisIt_VariableMetaData_alloc failed')
            return None
        varname = 'grid%s%s' % (varsep, var)
        simV2.VisIt_VariableMetaData_setName(vmd, varname)
        simV2.VisIt_VariableMetaData_setMeshName(vmd, 'grid')
        simV2.VisIt_VariableMetaData_setType(vmd, simV2.VISIT_VARTYPE_SCALAR)
        simV2.VisIt_VariableMetaData_setCentering(
            vmd, simV2.VISIT_VARCENTERING_NODE)
        simV2.VisIt_SimulationMetaData_addVariable(simmd, vmd)

    # commands
    for cmd in ['step', 'run', 'continue', 'pause', 'end', 'disconnect']:
        cmdmd = simV2.VisIt_CommandMetaData_alloc()
        if not valid(cmdmd):
            pError('VisIt_CommandMetaData_alloc failed')
            return None
        simV2.VisIt_CommandMetaData_setName(cmdmd, cmd)
        simV2.VisIt_SimulationMetaData_addGenericCommand(simmd, cmdmd)

    return simmd
Пример #29
0
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
Пример #30
0
def getMetaData(userData):
    """
    Callback function used to provide visit with metadata
    """
    valid = lambda x : x != simV2.VISIT_INVALID_HANDLE
    if __debug__: pDebug('getMetaData')

    # 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
    nDomains = parallel.number_of_PE()

    simmd = simV2.VisIt_SimulationMetaData_alloc()
    if not valid(simmd):
        pError('VisIt_SimulationMetaData_alloc failed')
        return None

    # time
    simV2.VisIt_SimulationMetaData_setCycleTime(simmd,
          warp.top.it,
          warp.top.time)

    # particles
    pMeshNames = getParticleMeshNames()
    if len(pMeshNames) < 1:
        pError('No particle mesh names were found')
    for pMeshName in pMeshNames:
        # see: warp/scripts/species.py
        # a mesh for each species
        meshmd = simV2.VisIt_MeshMetaData_alloc()
        simV2.VisIt_MeshMetaData_setName(meshmd, pMeshName)
        simV2.VisIt_MeshMetaData_setMeshType(meshmd, simV2.VISIT_MESHTYPE_POINT)
        simV2.VisIt_MeshMetaData_setTopologicalDimension(meshmd, 0)
        simV2.VisIt_MeshMetaData_setSpatialDimension(meshmd, 3)
        simV2.VisIt_MeshMetaData_setNumDomains(meshmd, nDomains)
        simV2.VisIt_MeshMetaData_setDomainTitle(meshmd, 'Domains')
        simV2.VisIt_MeshMetaData_setDomainPieceName(meshmd, 'domain')
        simV2.VisIt_MeshMetaData_setNumGroups(meshmd, 0)
        simV2.VisIt_MeshMetaData_setXUnits(meshmd, 'm')
        simV2.VisIt_MeshMetaData_setYUnits(meshmd, 'm')
        simV2.VisIt_MeshMetaData_setZUnits(meshmd, 'm')
        simV2.VisIt_MeshMetaData_setXLabel(meshmd, 'x')
        simV2.VisIt_MeshMetaData_setYLabel(meshmd, 'y')
        simV2.VisIt_MeshMetaData_setZLabel(meshmd, 'z')
        simV2.VisIt_SimulationMetaData_addMesh(simmd, meshmd)
        # per species data
        pVarNames = ['pid','n','x','y','z','w','r',
            'theta','vtheta','etheta','btheta',
            'vx','vy','vz','vr','ux','uy','uz',
            'ex','ey','ez','er','bx','by','bz','br',
            'xp','yp','zp','rp','tp','gaminv','weights',
            'ke','rank']
        pVarNames.sort()
        for var in pVarNames:
            vmd = simV2.VisIt_VariableMetaData_alloc()
            if not valid(vmd):
                pError('VisIt_VariableMetaData_alloc failed')
                return None
            varname = '%s%s%s'%(pMeshName,varsep,var)
            simV2.VisIt_VariableMetaData_setName(vmd, varname)
            simV2.VisIt_VariableMetaData_setMeshName(vmd, pMeshName)
            simV2.VisIt_VariableMetaData_setType(vmd, simV2.VISIT_VARTYPE_SCALAR)
            simV2.VisIt_VariableMetaData_setCentering(vmd, simV2.VISIT_VARCENTERING_NODE)
            simV2.VisIt_SimulationMetaData_addVariable(simmd, vmd)
        # expressions
        expname = lambda x : x[0]
        expstr = lambda x : x[1]
        exptype = lambda x : x[2]
        for exp in [('{0}/v','{{<{0}/vx>, <{0}/vy>, <{0}/vz>}}',simV2.VISIT_VARTYPE_VECTOR),
              ('{0}/V','sqrt(<{0}/vx>*<{0}/vx>+<{0}/vy>*<{0}/vy>+<{0}/vz>*<{0}/vz>)',simV2.VISIT_VARTYPE_SCALAR),
              ('{0}/B','sqrt(<{0}/bx>*<{0}/bx>+<{0}/by>*<{0}/by>+<{0}/bz>*<{0}/bz>)',simV2.VISIT_VARTYPE_SCALAR),
              ('{0}/E','sqrt(<{0}/ex>*<{0}/ex>+<{0}/ey>*<{0}/ey>+<{0}/ez>*<{0}/ez>)',simV2.VISIT_VARTYPE_SCALAR) ]:
            expmd = simV2.VisIt_ExpressionMetaData_alloc()
            if not valid(expmd):
                pError('VisIt_ExpressionMetaData_alloc failed')
                return None
            simV2.VisIt_ExpressionMetaData_setName(expmd, expname(exp).format(pMeshName))
            simV2.VisIt_ExpressionMetaData_setDefinition(expmd, expstr(exp).format(pMeshName))
            simV2.VisIt_ExpressionMetaData_setType(expmd, exptype(exp))
            simV2.VisIt_SimulationMetaData_addExpression(simmd, expmd)

    # field mesh
    meshmd = simV2.VisIt_MeshMetaData_alloc()
    if not valid(meshmd):
        pError('VisIt_MeshMetaData_alloc failed')
        return None
    simV2.VisIt_MeshMetaData_setName(meshmd, 'grid')
    simV2.VisIt_MeshMetaData_setMeshType(meshmd, simV2.VISIT_MESHTYPE_RECTILINEAR)
    simV2.VisIt_MeshMetaData_setTopologicalDimension(meshmd, 3)
    simV2.VisIt_MeshMetaData_setSpatialDimension(meshmd, 3)
    simV2.VisIt_MeshMetaData_setNumDomains(meshmd, nDomains)
    simV2.VisIt_MeshMetaData_setDomainTitle(meshmd, 'Domains')
    simV2.VisIt_MeshMetaData_setDomainPieceName(meshmd, 'domain')
    simV2.VisIt_MeshMetaData_setNumGroups(meshmd, 0)
    simV2.VisIt_MeshMetaData_setXUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setYUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setZUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setXLabel(meshmd, 'x')
    simV2.VisIt_MeshMetaData_setYLabel(meshmd, 'y')
    simV2.VisIt_MeshMetaData_setZLabel(meshmd, 'z')
    simV2.VisIt_SimulationMetaData_addMesh(simmd, meshmd)

    # CSG mesh
    meshmd = simV2.VisIt_MeshMetaData_alloc()
    if not valid(meshmd):
        pError('VisIt_MeshMetaData_alloc failed')
        return None
    simV2.VisIt_MeshMetaData_setName(meshmd, 'csg')
    simV2.VisIt_MeshMetaData_setMeshType(meshmd, simV2.VISIT_MESHTYPE_CSG)
    simV2.VisIt_MeshMetaData_setTopologicalDimension(meshmd, 3)
    simV2.VisIt_MeshMetaData_setSpatialDimension(meshmd, 3)
    simV2.VisIt_MeshMetaData_setNumDomains(meshmd, nDomains)
    simV2.VisIt_MeshMetaData_setDomainTitle(meshmd, 'Domains')
    simV2.VisIt_MeshMetaData_setDomainPieceName(meshmd, 'domain')
    simV2.VisIt_MeshMetaData_setNumGroups(meshmd, 0)
    simV2.VisIt_MeshMetaData_setXUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setYUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setZUnits(meshmd, 'm')
    simV2.VisIt_MeshMetaData_setXLabel(meshmd, 'x')
    simV2.VisIt_MeshMetaData_setYLabel(meshmd, 'y')
    simV2.VisIt_MeshMetaData_setZLabel(meshmd, 'z')
    simV2.VisIt_SimulationMetaData_addMesh(simmd, meshmd)

    # field data arrays
    for var in ['ax','ay','az','A',
        'bx','by','bz','B','J','jx','jy',
        'jz','phi','rho','rank']:
        vmd = simV2.VisIt_VariableMetaData_alloc()
        if not valid(vmd):
            pError('VisIt_VariableMetaData_alloc failed')
            return None
        varname = 'grid%s%s'%(varsep,var)
        simV2.VisIt_VariableMetaData_setName(vmd, varname)
        simV2.VisIt_VariableMetaData_setMeshName(vmd, 'grid')
        simV2.VisIt_VariableMetaData_setType(vmd, simV2.VISIT_VARTYPE_SCALAR)
        simV2.VisIt_VariableMetaData_setCentering(vmd, simV2.VISIT_VARCENTERING_NODE)
        simV2.VisIt_SimulationMetaData_addVariable(simmd, vmd)

    # commands
    for cmd in ['step','run','continue','pause','end','disconnect']:
        cmdmd = simV2.VisIt_CommandMetaData_alloc()
        if not valid(cmdmd):
            pError('VisIt_CommandMetaData_alloc failed')
            return None
        simV2.VisIt_CommandMetaData_setName(cmdmd, cmd)
        simV2.VisIt_SimulationMetaData_addGenericCommand(simmd, cmdmd)

    return simmd
Пример #31
0
    def EventLoop(self):
        """
        Run the VisIt controlled event loop. Return False on error
        """
        doError = lambda e: e<0
        doUpdate = lambda e: e==0
        doConnect = lambda e: e==1
        doInternal = lambda e: e==2
        masterRank = lambda r: r==0
        onErrorContinue = lambda : self._Behavior=='Monitor'

        if __debug__: pDebug('WarpVisItEngine::EventLoop')

        while 1:
            # test or wait for incomming communication.
            if masterRank(self._CommRank):
                event = simV2.VisItDetectInput(self._VisItBlockingComm, -1)
                parallel.broadcast(event)
            else:
                event = parallel.broadcast(0)

            # process incomming communication
            if __debug__: pDebug('event=%d'%(event))

            # internal comm error
            if doError(event):
                # the VisIt viewer disconnected.
                pError('An communication error was detected')
                self._Behavior.Initialize()
                if onErrorContinue():
                    continue
                else:
                    return False

            # simulate
            elif doUpdate(event):
                # this is where we can safely do things.
                # it occurs only when VisIt is not in the
                # middle of processing its own commands.
                if __debug__: pDebug('update')
                self._Behavior.Update()
                # TODO -- is it useful to force gc??
                #gc.collect()

            # internal connection
            elif doConnect(event):
                if simV2.VisItAttemptToCompleteConnection() == 1:
                    pStatus('WarpVisItEngine connected')
                    self.ConnectLibsim()
                    self._Behavior.Connect()
                    self._Behavior.Update()
                else:
                    pError('Connection failed')
                    self._Behavior.Initialize()
                    if onErrorContinue():
                        continue
                    else:
                        return False

            # internal comm
            elif doInternal(event):
                if __debug__: pDebug('internal')
                if not self.CommunicateLibsim():
                    pError('Error while processing internal commands')
                    self._Behavior.Initialize()
                    if onErrorContinue():
                        continue
                    else:
                        return False

            # bad value
            else:
                pError('unknown command %d'%(event))

            # check for asynchronous shutdown request
            if self._ShutdownRequested:
                pStatus('WarpVisItEngine exiting the event loop')
                simV2.VisItDisconnect()
                self._Connected = False
                return True

            continue

        return False