• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python underworld.rank函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中underworld.rank函数的典型用法代码示例。如果您正苦于以下问题:Python rank函数的具体用法?Python rank怎么用?Python rank使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rank函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: show

    def show(self, type="image"):
        """    
        Shows the generated image inline within an ipython notebook
        
        Parameters
        ----------
        type: str
            Type of visualisation to display ('Image' or 'WebGL'). Default is 'Image'.
        
        Returns
        -------
        Ipython HTML object (for type 'Image')
        Ipython IFrame object (for type 'Webgl')
        Note that if IPython is not installed, this method will return nothing.

        """

        try:
            from IPython.display import Image,HTML
            self._generate_DB()
            if uw.rank() == 0:
                if type.lower() == "webgl":
                    return self._generate_HTML()
                else:
                    return self._generate_image()
        except ImportError:
            pass
        except RuntimeError, e:
            print "Error creating image: "
            print e
            pass
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:31,代码来源:_glucifer.py


示例2: max_global_auxiliary

 def max_global_auxiliary(self):
     """
     Returns the results of the auxiliary function evaluated at the
     location corresponding to the primary function maximum. This
     method considers results across all processes (ie, globally).
     
     Notes
     -----
     This method must be called by collectively all processes.
     
     Returns
     -------
     FunctionIO: value at global maximum.
     """
     # first make sure that we have determined the rank with the max
     self.max_global()
     
     import underworld as uw
     # if we are the rank with the max result, extract result
     if uw.rank() == self.max_rank():
         auxout = self.max_local_auxiliary()
     else:
         auxout = None
     
     from mpi4py import MPI
     comm = MPI.COMM_WORLD
     
     # broadcast
     data = comm.bcast(auxout, root=self.max_rank())
     
     return data
开发者ID:dansand,项目名称:underworld2,代码行数:31,代码来源:view.py


示例3: show

    def show(self, type="Image"):
        """    
        Shows the generated image inline within an ipython notebook.
        
        Parameters
        ----------
        type: str
            Type of visualisation to display ('Image' or 'WebGL').
        
        If IPython is installed, displays the result image or WebGL content inline

        If IPython is not installed, this method will call the default image/web 
        output routines to save the result with a default filename in the current directory

        """
        try:
            if type.lower() != "webgl" and lavavu.is_notebook():
                self._generate_DB()
                if uw.rank() > 0:
                    return
                from IPython.display import display,Image,HTML
                #Return inline image result
                filename = self._generate_image()
                display(HTML("<img src='%s'>" % filename))
            else:
                #Fallback to export image or call viewer webgl export
                self.save(filename=self.name, type=type)
        except RuntimeError as e:
            print("Error creating image: ", e)
            pass
        except:
            raise
开发者ID:dansand,项目名称:underworld2,代码行数:32,代码来源:_glucifer.py


示例4: open_viewer

    def open_viewer(self, args=[], background=True):
        """ Open the external viewer.
        """
        fname = self.db.filename
        if not fname:
            fname = os.path.join(tmpdir, "gluciferDB" + self.db._id + ".gldb")
            self.save_database(fname)
        # Already open?
        if self._viewerProc and self._viewerProc.poll() == None:
            return

        global lavavu
        if lavavu and uw.rank() == 0:
            # Open viewer with local web server for interactive/iterative use
            if background:
                self._viewerProc = subprocess.Popen(
                    [self.db._lvbin, "-" + str(self.db.step), "-p9999", "-q90", fname] + args,
                    stdout=PIPE,
                    stdin=PIPE,
                    stderr=STDOUT,
                )
                from IPython.display import HTML

                return HTML(
                    """<a href='#' onclick='window.open("http://" + location.hostname + ":9999");'>Open Viewer Interface</a>"""
                )
            else:
                lv = self.db.lvrun(db=fname, port=9999)
开发者ID:underworldcode,项目名称:underworld2,代码行数:28,代码来源:_glucifer.py


示例5: send_command

 def send_command(self, cmd, retry=True):
     """ 
     Run command on an open viewer instance.
     
     Parameters
     ----------
     cmd: str
         Command to send to open viewer.
     """
     if uw.rank() == 0:
         self.open_viewer()
         url = "http://localhost:9999/command=" + urllib2.quote(cmd)
         try:
             #print url
             response = urllib2.urlopen(url).read()
             #print response
         except:
             print("Send command '" + cmd + "' failed, no response")
             if retry:
                 #Wait a few seconds so server has time to start then try again
                 print("... retrying in 1s ...")
                 time.sleep(1)
                 self.send_command(cmd, False)
             else:
                 print("... failed, skipping ...")
                 pass
开发者ID:dansand,项目名称:underworld2,代码行数:26,代码来源:_glucifer.py


示例6: print_stats

 def print_stats(self):
     purple = "\033[0;35m"
     endcol = "\033[00m"
     boldpurple = "\033[1;35m"
     if 0==uw.rank():
         print boldpurple
         print( " " )
         print( "Pressure iterations: %3d" % (self._cself.stats.pressure_its) )
         print( "Velocity iterations: %3d (presolve)      " % (self._cself.stats.velocity_presolve_its) )
         print( "Velocity iterations: %3d (pressure solve)" % (self._cself.stats.velocity_pressuresolve_its) )
         print( "Velocity iterations: %3d (backsolve)     " % (self._cself.stats.velocity_backsolve_its) )
         print( "Velocity iterations: %3d (total solve)   " % (self._cself.stats.velocity_total_its) )
         print( " " )
         print( "SCR RHS  setup time: %.4e" %(self._cself.stats.velocity_presolve_setup_time) )
         print( "SCR RHS  solve time: %.4e" %(self._cself.stats.velocity_presolve_time) )
         print( "Pressure setup time: %.4e" %(self._cself.stats.velocity_pressuresolve_setup_time) )
         print( "Pressure solve time: %.4e" %(self._cself.stats.pressure_time) )
         print( "Velocity setup time: %.4e (backsolve)" %(self._cself.stats.velocity_backsolve_setup_time) )
         print( "Velocity solve time: %.4e (backsolve)" %(self._cself.stats.velocity_backsolve_time) )
         print( "Total solve time   : %.4e" %(self._cself.stats.total_time) )
         print( " " )
         print( "Velocity solution min/max: %.4e/%.4e" % (self._cself.stats.vmin,self._cself.stats.vmax) )
         print( "Pressure solution min/max: %.4e/%.4e" % (self._cself.stats.pmin,self._cself.stats.pmax) )
         print( " " )
         print endcol
开发者ID:dansand,项目名称:underworld2,代码行数:25,代码来源:_bsscr.py


示例7: save_image

    def save_image(self,filename):
        """  
        Saves the generated image to the provided filename.
        
        Parameters
        ----------
        filename :str
            Filename to save file to.  May include an absolute or relative path.
        """
        if not isinstance(filename, str):
            raise TypeError("Provided parameter 'filename' must be of type 'str'. ")

        self._generate_DB()
        if uw.rank() == 0:
            self._generate_image(asfile=True)
            generatedFilename=self._find_generated_file()
            absfilename = os.path.abspath(filename)
            
            # lets set the final extension to that of the glucifer generated file
            splitabsfilename = os.path.splitext(absfilename)
            splitgenfilename = os.path.splitext(generatedFilename)
            if splitabsfilename[1].lower() in [".png", ".jpg", ".jpeg"]:
                frontpart = splitabsfilename[0]
            else:
                frontpart = absfilename
            finaloutFile = frontpart+splitgenfilename[1]
            os.rename(generatedFilename,finaloutFile)
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:27,代码来源:_glucifer.py


示例8: print_stats

 def print_stats(self):
     if 0==uw.rank():
         print( "Pressure iterations: %d" % (self._cself.stats.pressure_its) )
         print( "Velocity iterations: %d (backsolve)" % (self._cself.stats.velocity_backsolve_its) )
         print( " " )
         print( "Pressure solve time: %.4e" %(self._cself.stats.pressure_time) )
         print( "Velocity solve time: %.4e (backsolve)" %(self._cself.stats.velocity_backsolve_time) )
         print( "Total solve time   : %.4e" %(self._cself.stats.total_time) )
         print( " " )
         print( "Velocity solution min/max: %.4e/%.4e" % (self._cself.stats.vmin,self._cself.stats.vmax) )
         print( "Pressure solution min/max: %.4e/%.4e" % (self._cself.stats.pmin,self._cself.stats.pmax) )
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:11,代码来源:_bsscr.py


示例9: _generate_image

 def _generate_image(self, asfile=False):
     if uw.rank() == 0:
         #Render with viewer
         args = [self._lvbin, self._db.path, "-" + str(self._db.timeStep), "-p0", "-z" + str(self.antialias)]
         if asfile:
             starting_directory = os.getcwd()
             lavavu.initViewer(args + ["-I", ":"] + self._script)
         else:
             imagestr = lavavu.initViewer(args + ["-u", ":"] + self._script)
             from IPython.display import Image,HTML
             return HTML("<img src='%s'>" % imagestr)
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:11,代码来源:_glucifer.py


示例10: viewer

 def viewer(self):
     """ Open the inline viewer.
     """
     fname = self.db.filename
     if not fname:
         fname = os.path.join(tmpdir, "gluciferDB" + self.db._id + ".gldb")
         self.save_database(fname)
     global lavavu
     if lavavu and uw.rank() == 0:
         lavavu.viewer = self.db.lvrun(db=fname)
         lavavu.control.viewer()
         return lavavu.viewer
开发者ID:underworldcode,项目名称:underworld2,代码行数:12,代码来源:_glucifer.py


示例11: _generate_image

 def _generate_image(self, filename="", size=(0, 0)):
     global lavavu
     if not lavavu or uw.rank() > 0:
         return
     try:
         # Render with viewer
         lv = self.db.lvrun(quality=self.quality, script=self._script)
         imagestr = lv.image(filename, size[0], size[1])
         # Return the generated filename
         return imagestr
     except RuntimeError, e:
         print "LavaVu error: " + str(e)
         pass
开发者ID:underworldcode,项目名称:underworld2,代码行数:13,代码来源:_glucifer.py


示例12: set_penalty

 def set_penalty(self, penalty):
     """
     By setting the penalty, the Augmented Lagrangian Method is used as the solve.
     This method is not recommended for normal use as there is additional memory and cpu overhead.
     This method can often help improve convergence issues for subduction-type problems with large viscosity 
     contrasts that are having trouble converging.
     
     A penalty of roughly 0.1 of the maximum viscosity contrast is not a bad place to start as a guess. (check notes/paper)
     """
     if isinstance(self.options.main.penalty, float) and self.options.main.penalty >= 0.0:
         self.options.main.penalty=penalty
     elif 0==uw.rank():
         print( "Invalid penalty number chosen. Penalty must be a positive float." )
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:13,代码来源:_bsscr.py


示例13: _generate_HTML

 def _generate_HTML(self):
     if uw.rank() == 0:
         #Export encoded json string
         jsonstr = lavavu.initViewer([self._lvbin, "-" + str(self._db.timeStep), "-U", "-p0", self._db.path, ":"] + self._script)
         if not os.path.isdir("html"):
             #Create link to web content directory
             os.symlink(self._lvpath + 'html', 'html')
         text_file = open("html/input.json", "w")
         text_file.write(jsonstr);
         text_file.close()
         from IPython.display import IFrame
         return IFrame("html/index.html#input.json", width=1000, height=800)
     return ""
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:13,代码来源:_glucifer.py


示例14: window

    def window(self, *args, **kwargs):
        """ Open an inline viewer.

        This returns a new LavaVu instance to display the figure
        and opens it as an interactive viewing window.
        """
        #Open a new viewer instance and display window
        if uw.rank() == 0:
            v = self.viewer(new=True, *args, **kwargs)
            #Ensure correct figure selected
            v.figure(self.name)
            #Show the inline window,
            v.window()
            return v
开发者ID:dansand,项目名称:underworld2,代码行数:14,代码来源:_glucifer.py


示例15: open_viewer

    def open_viewer(self, args=[]):
        """ Open the viewer.
        """
        if uw.rank() == 0:
            fname = os.path.join(tmpdir,"gluciferDB"+self._id+".gldb")
            self.save_database(fname)
            if self._viewerProc and self._viewerProc.poll() == None:
                return
            #Open viewer with local web server for interactive/iterative use
            args = [self._lvbin, "-" + str(self._db.timeStep), "-L", "-p8080", "-q90", "-Q", fname] + args
            self._viewerProc = subprocess.Popen(args, stdout=PIPE, stdin=PIPE, stderr=STDOUT)

            from IPython.display import HTML
            return HTML('''<a href='#' onclick='window.open("http://" + location.hostname + ":8080");'>Open Viewer Interface</a>''')
开发者ID:AngelValverdePerez,项目名称:underworld2,代码行数:14,代码来源:_glucifer.py


示例16: start

def start():
    """
    Call this function to start recording timing data.
    """
    depth=0
    global timing
    global _maxdepth
    global _currentDepth
    _currentDepth = 0
    if _uw.rank() == 0 and ("UW_ENABLE_TIMING" in _os.environ):
        timing = True
    _maxdepth = depth + 1
    global _starttime
    _starttime = _time.time()
开发者ID:dansand,项目名称:underworld2,代码行数:14,代码来源:timing.py


示例17: _generate_image

 def _generate_image(self, filename="", size=(0,0)):
     if uw.rank() > 0:
         return
     try:
         #Render with viewer
         lv = self.db.lvget(quality=self["quality"], script=self._script)
         imagestr = lv.image(filename, resolution=size)
         #Return the generated filename
         return imagestr
     except RuntimeError as e:
         print("LavaVu error: ", e)
         import traceback
         traceback.print_exc()
         pass
     return ""
开发者ID:dansand,项目名称:underworld2,代码行数:15,代码来源:_glucifer.py


示例18: __init__

    def __init__(self, swarm, particlesPerCell, **kwargs ):
        import underworld as uw
        if uw.rank()==0:
        # TODO: Deprecate
            import warnings
            warnings.warn("Note that the 'GlobalSpaceFillerLayout' will be deprecated in future releases of Underworld. "
                          "The `PerCellSpaceFillerLayout` provides similar functionality.")
        if not isinstance(particlesPerCell, (int,float)):
            raise TypeError("'particlesPerCell' object passed in must be of type 'float' or 'int'.")
        if particlesPerCell<=0:
            raise ValueError("'particlesPerCell' object passed in must take a value greater than zero.")
        self._particlesPerCell = float(particlesPerCell)

        # build parent
        super(GlobalSpaceFillerLayout,self).__init__(swarm=swarm, **kwargs)
开发者ID:dansand,项目名称:underworld2,代码行数:15,代码来源:layouts.py


示例19: save

 def save(self, filename):
     """  
     Saves the database to the provided filename.
         
     Parameters
     ----------
     filename :str
         Filename to save file to.  May include an absolute or relative path.
     """
     if uw.rank() == 0:
         if not isinstance(filename, str):
             raise TypeError("Provided parameter 'filename' must be of type 'str'. ")
         if not filename.lower().endswith(".gldb") and not filename.lower().endswith(".db"):
             filename += ".gldb"
         libUnderworld.gLucifer.lucDatabase_BackupDbFile(self._db, filename)
         return filename
开发者ID:underworldcode,项目名称:underworld2,代码行数:16,代码来源:_glucifer.py


示例20: _read_state

 def _read_state(self):
     # Read state from database
     global lavavu
     if not lavavu or uw.rank() > 0:
         return
     if not self._db.db:
         libUnderworld.gLucifer.lucDatabase_OpenDatabase(self._db)
     try:
         lv = self.lvrun()
         # Get state, includes the list of objects in the loaded database
         statestr = lv.getFigures()
         # Also save the step data
         self.timesteps = json.loads(lv.getTimeSteps())
         return json.loads(statestr)
     except RuntimeError, e:
         print "LavaVu error: " + str(e)
         pass
开发者ID:underworldcode,项目名称:underworld2,代码行数:17,代码来源:_glucifer.py



注:本文中的underworld.rank函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python helpers.FormHelper类代码示例发布时间:2022-05-27
下一篇:
Python unumpy.uarray函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap