コード例 #1
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
    def ProcessCommand(self, cmd):
        """
        process simulation control commands.

        endSyn    : internal use only, for synchronziation between sim and vis

        """
        if __debug__: pDebug('WarpVisItEngine::ProcessCommand %s'%(cmd))

        self._CommandQueue.append(cmd)

        # queue commands while in synchronous mode
        if self.GetSynchronous():
            if cmd == 'endSyn':
                self.SetSynchronous(False)
                self._CommandQueue.pop()
            else:
                if __debug__: pDebug('defered %s'%(cmd))
                return

        # now in asynchronous mode
        # process queued commands
        ncmds = len(self._CommandQueue)
        i = 0
        while (i < ncmds):
            qcmd = self._CommandQueue.pop()
            self._Behavior.Process(qcmd)
            i += 1
        return
コード例 #2
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
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
コード例 #3
0
ファイル: WarpVisItCLI.py プロジェクト: burlen/WarpVisIt
    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
コード例 #4
0
ファイル: WarpVisItCLI.py プロジェクト: burlen/WarpVisIt
    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
コード例 #5
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
コード例 #6
0
    def ProcessCommand(self, cmd):
        """
        process simulation control commands.

        endSyn    : internal use only, for synchronziation between sim and vis

        """
        if __debug__: pDebug('WarpVisItEngine::ProcessCommand %s' % (cmd))

        self._CommandQueue.append(cmd)

        # queue commands while in synchronous mode
        if self.GetSynchronous():
            if cmd == 'endSyn':
                self.SetSynchronous(False)
                self._CommandQueue.pop()
            else:
                if __debug__: pDebug('defered %s' % (cmd))
                return

        # now in asynchronous mode
        # process queued commands
        ncmds = len(self._CommandQueue)
        i = 0
        while (i < ncmds):
            qcmd = self._CommandQueue.pop()
            self._Behavior.Process(qcmd)
            i += 1
        return
コード例 #7
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
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
コード例 #8
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
    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
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
    def StepSimulation(self):
        """Drive the simulation through one or more steps"""
        if __debug__: pDebug('WarpVisItEngine::StepSimulation')

        self._Simulation.Advance()
        simV2.VisItTimeStepChanged()
        self._StepCount += 1

        return True
コード例 #10
0
    def StepSimulation(self):
        """Drive the simulation through one or more steps"""
        if __debug__: pDebug('WarpVisItEngine::StepSimulation')

        self._Simulation.Advance()
        simV2.VisItTimeStepChanged()
        self._StepCount += 1

        return True
コード例 #11
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
 def DisconnectLibsim(self):
     """
     Install database callbacks in libsim
     """
     if __debug__: pDebug('WarpVisItEngine::DisconnectLibsim')
     # handled by libsim internally now
     #simV2.VisItSetGetMetaData(None, None)
     #simV2.VisItSetGetMesh(None, None)
     #simV2.VisItSetGetVariable(None, None)
     #simV2.VisItSetGetDomainList(None, None)
     #simV2.VisItSetCommandCallback(None, None)
     #simV2.VisItSetSlaveProcessCallback(None)
     return
コード例 #12
0
 def DisconnectLibsim(self):
     """
     Install database callbacks in libsim
     """
     if __debug__: pDebug('WarpVisItEngine::DisconnectLibsim')
     # handled by libsim internally now
     #simV2.VisItSetGetMetaData(None, None)
     #simV2.VisItSetGetMesh(None, None)
     #simV2.VisItSetGetVariable(None, None)
     #simV2.VisItSetGetDomainList(None, None)
     #simV2.VisItSetCommandCallback(None, None)
     #simV2.VisItSetSlaveProcessCallback(None)
     return
コード例 #13
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
 def ConnectLibsim(self):
     """
     Install database callbacks in libsim
     """
     if __debug__: pDebug('WarpVisItEngine::ConnectLibsim')
     simV2.VisItSetGetMetaData(WarpVisItSimV2Db.getMetaData, self)
     simV2.VisItSetGetMesh(WarpVisItSimV2Db.getMesh, self)
     simV2.VisItSetGetVariable(WarpVisItSimV2Db.getVar, self)
     simV2.VisItSetGetDomainList(WarpVisItSimV2Db.getDomains, self)
     simV2.VisItSetCommandCallback(commandCallback, self)
     simV2.VisItSetSlaveProcessCallback(slaveProcessCallback)
     self._Connected = True
     self._VisItBlockingComm = True # TODO -- isn't this part of behaviors now??
     return
コード例 #14
0
 def ConnectLibsim(self):
     """
     Install database callbacks in libsim
     """
     if __debug__: pDebug('WarpVisItEngine::ConnectLibsim')
     simV2.VisItSetGetMetaData(WarpVisItSimV2Db.getMetaData, self)
     simV2.VisItSetGetMesh(WarpVisItSimV2Db.getMesh, self)
     simV2.VisItSetGetVariable(WarpVisItSimV2Db.getVar, self)
     simV2.VisItSetGetDomainList(WarpVisItSimV2Db.getDomains, self)
     simV2.VisItSetCommandCallback(commandCallback, self)
     simV2.VisItSetSlaveProcessCallback(slaveProcessCallback)
     self._Connected = True
     self._VisItBlockingComm = True  # TODO -- isn't this part of behaviors now??
     return
コード例 #15
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
def getGridSize(cells=False):
    """
    Get this rank's grid size in units of cells
    (or units of points if cells is False).
    """
    decomp = getDecomp()

    i = 0 if cells else 1

    size = [[],[],[]]
    size[0] = decomp.nx[decomp.ixproc]+i
    size[1] = decomp.ny[decomp.iyproc]+i
    size[2] = decomp.nz[decomp.izproc]+i

    if __debug__: pDebug(size)
    return size
コード例 #16
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
def getGridSize(cells=False):
    """
    Get this rank's grid size in units of cells
    (or units of points if cells is False).
    """
    decomp = getDecomp()

    i = 0 if cells else 1

    size = [[], [], []]
    size[0] = decomp.nx[decomp.ixproc] + i
    size[1] = decomp.ny[decomp.iyproc] + i
    size[2] = decomp.nz[decomp.izproc] + i

    if __debug__: pDebug(size)
    return size
コード例 #17
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
    def PushRenderScripts(self):
        """Render simulation data"""
        if __debug__: pDebug('WarpVisItEngine::Render')

        activeScripts = self._Simulation.GetActiveRenderScripts()
        if len(activeScripts):
            scripts = self._Simulation.GetRenderScripts()
            # push rendering scripts for execution
            # while rendering sim must not advance
            # enable synchronous mode for each script
            # and append a command to disable it to
            # the end of each.
            for script in activeScripts:
                if __debug__: pDebug('Rendering %s'%(script))
                self.SetSynchronous(True)
                source = scripts[script]
                source += ("\nfrom visit import visit\n"
                           "visit.SendSimulationCommand('localhost', '%s', 'endSyn')\n")%(
                          self._SimFile)
                simV2.VisItExecuteCommand(source)

        return True
コード例 #18
0
    def PushRenderScripts(self):
        """Render simulation data"""
        if __debug__: pDebug('WarpVisItEngine::Render')

        activeScripts = self._Simulation.GetActiveRenderScripts()
        if len(activeScripts):
            scripts = self._Simulation.GetRenderScripts()
            # push rendering scripts for execution
            # while rendering sim must not advance
            # enable synchronous mode for each script
            # and append a command to disable it to
            # the end of each.
            for script in activeScripts:
                if __debug__: pDebug('Rendering %s' % (script))
                self.SetSynchronous(True)
                source = scripts[script]
                source += (
                    "\nfrom visit import visit\n"
                    "visit.SendSimulationCommand('localhost', '%s', 'endSyn')\n"
                ) % (self._SimFile)
                simV2.VisItExecuteCommand(source)

        return True
コード例 #19
0
ファイル: WarpVisItCLI.py プロジェクト: burlen/WarpVisIt
    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
コード例 #20
0
ファイル: WarpVisItCLI.py プロジェクト: burlen/WarpVisIt
    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
コード例 #21
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
    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
コード例 #22
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
    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
コード例 #23
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
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
コード例 #24
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
def slaveProcessCallback():
    """Callback involved in command communication"""
    if __debug__: pDebug('slaveProcessCallback')
    processCommand = int(0)
    broadcastSlaveCommand(processCommand)
コード例 #25
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
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
コード例 #26
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
def getIteration():
    """Return current simulation iteration"""
    it = warp.top.it
    if __debug__: pDebug('iteration = %i' % (it))
    return it
コード例 #27
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
def broadcastString(val, n=0, sender=0) :
    """String broadcast callback for libsim"""
    result = parallel.broadcast(val, root=sender)
    if __debug__: pDebug('broadcastString %s'%(result))
    return result
コード例 #28
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
def getTime():
    """Return current simulation time"""
    t = warp.top.time
    if __debug__: pDebug('time = %f' % (t))
    return t
コード例 #29
0
def broadcastSlaveCommand(command=0):
    """Helper function for ProcessCommands"""
    result = parallel.broadcast(command, root=0)
    if __debug__: pDebug('broadcastSlaveCommand %i' % (result))
    return result
コード例 #30
0
def broadcastInt(val, sender=0):
    """Integer broadcast callback for libsim"""
    result = parallel.broadcast(val, root=sender)
    if __debug__: pDebug('broadcastInt %i' % (val))
    return result
コード例 #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
コード例 #32
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
コード例 #33
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
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
コード例 #34
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
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
コード例 #35
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
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
コード例 #36
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
def broadcastInt(val, sender=0) :
    """Integer broadcast callback for libsim"""
    result = parallel.broadcast(val, root=sender)
    if __debug__: pDebug('broadcastInt %i'%(val))
    return result
コード例 #37
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
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
コード例 #38
0
ファイル: WarpVisItEngine.py プロジェクト: burlen/WarpVisIt
def broadcastSlaveCommand(command=0):
    """Helper function for ProcessCommands"""
    result = parallel.broadcast(command, root=0)
    if __debug__: pDebug('broadcastSlaveCommand %i'%(result))
    return result
コード例 #39
0
def broadcastString(val, n=0, sender=0):
    """String broadcast callback for libsim"""
    result = parallel.broadcast(val, root=sender)
    if __debug__: pDebug('broadcastString %s' % (result))
    return result
コード例 #40
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
def getTime():
    """Return current simulation time"""
    t = warp.top.time
    if __debug__: pDebug('time = %f'%(t))
    return t
コード例 #41
0
def slaveProcessCallback():
    """Callback involved in command communication"""
    if __debug__: pDebug('slaveProcessCallback')
    processCommand = int(0)
    broadcastSlaveCommand(processCommand)
コード例 #42
0
ファイル: WarpVisItSimV2Db.py プロジェクト: burlen/WarpVisIt
def getIteration():
    """Return current simulation iteration"""
    it = warp.top.it
    if __debug__: pDebug('iteration = %i'%(it))
    return it