def find_levels(self, mesh, what): # 2D only assert config.dimension() == 2 nlevels = self.levels clevels = None if type(nlevels) == types.ListType or type(nlevels) == types.TupleType: clevels = nlevels nlevels = len(clevels) # Make a list of mastercoords of all nodes of all elements ## TODO OPT: Rework this to use generators instead of passing ## lists around. It may be faster for large meshes. nodepoints = [] for element in mesh.elements(): master = element.masterelement() el_mpos = [] # master coords of nodes in this element for n in range(master.nnodes()): el_mpos.append(master.get_protonode(n).mastercoord()) nodepoints.append(el_mpos) # Evaluate the function at the nodes values = [ float(x) for x in what.evaluate(mesh, mesh.elements(), nodepoints) ] # Get function values grouped by element evalues = utils.unflatten(nodepoints, values) # TODO OPT: This is a lot of evaluation work -- are # these values cached somewhere, and can they be reused? ## vmax = max(values) ## for (vals, element) in zip(evalues, mesh.elements()): ## if vmax in vals: ## debug.fmsg('max found in element', element, vals) ## break # Determine contour levels, if necessary if clevels is None: # contours not specified by user # Find range of values. This is just approximate, since the # interpolation within an element may give a value outside of # the range spanned by the nodal values. if self.min_contour == automatic.automatic: vmin = float(min(values)) else: vmin = float(self.min_contour) if self.max_contour == automatic.automatic: vmax = float(max(values)) else: vmax = float(self.max_contour) if nlevels == 1: clevels = [0.5 * (vmax + vmin)] else: dz = (vmax - vmin) / (nlevels - 1) clevels = [vmin + i * dz for i in range(nlevels)] return clevels, evalues
def polygons(self, gfxwindow, meshctxt): themesh = meshctxt.getObject() meshctxt.restoreCachedData(self.getTime(meshctxt, gfxwindow)) try: # PARALLEL_RCL: Make changes here to display parallel mesh # There is an issue with clicking on the skeleton or mesh # graphics: only the nodes or elements for the front-end # process get the cursor or mark if parallel_enable.enabled(): # This snippet taken from SkeletonDisplayMethod nodes = themesh.all_meshskeletons["nodes"] elements = themesh.all_meshskeletons["elements"] polys = [] for i in range(mpitools.Size()): for el in elements[i]: polys.append( [primitives.Point(*nodes[i][ni]) for ni in el]) return polys else: if gfxwindow.settings.hideEmptyElements: edges = [ element.perimeter() for element in themesh.element_iterator() if element.material() is not None ] else: edges = [ element.perimeter() for element in themesh.element_iterator() ] flatedges = utils.flatten(edges) # corners tells where on each edge to evaluate self.where corners = [[0.0]] * len(flatedges) # evaluate position output for all edges at once polys = self.where.evaluate(themesh, flatedges, corners) # give the corner list the same structure as the edge list: a # list of lists, where each sublist is the list of corners of # an element. polys = utils.unflatten(edges, polys) if len(polys) == 0: mainthread.runBlock(reporter.warn, ( "No mesh elements drawn! Are there no materials assigned?", )) return polys finally: meshctxt.releaseCachedData()
def polygons(self, gfxwindow, meshctxt): themesh = meshctxt.getObject() meshctxt.restoreCachedData(self.getTime(meshctxt, gfxwindow)) try: # PARALLEL_RCL: Make changes here to display parallel mesh # There is an issue with clicking on the skeleton or mesh # graphics: only the nodes or elements for the front-end # process get the cursor or mark if parallel_enable.enabled(): # This snippet taken from SkeletonDisplayMethod nodes = themesh.all_meshskeletons["nodes"] elements = themesh.all_meshskeletons["elements"] polys = [] for i in range(mpitools.Size()): for el in elements[i]: polys.append([primitives.Point(*nodes[i][ni]) for ni in el]) return polys else: if gfxwindow.settings.hideEmptyElements: edges = [element.perimeter() for element in themesh.element_iterator() if element.material() is not None] else: edges = [element.perimeter() for element in themesh.element_iterator()] flatedges = utils.flatten(edges) # corners tells where on each edge to evaluate self.where corners = [[0.0]]*len(flatedges) # evaluate position output for all edges at once polys = self.where.evaluate(themesh, flatedges, corners) # give the corner list the same structure as the edge list: a # list of lists, where each sublist is the list of corners of # an element. polys = utils.unflatten(edges, polys) if len(polys) == 0: mainthread.runBlock( reporter.warn, ("No mesh elements drawn! Are there no materials assigned?",)) return polys finally: meshctxt.releaseCachedData()
def find_levels(self, mesh, what): nlevels = self.levels clevels = None ## if nlevels is automatic: ## reporter.warn( ## "levels=automatic is not yet implemented for contour plotting.") ## # Not implemented yet. ## # Should print an apology here. ## return [], [] if type(nlevels) == ListType or type(nlevels) == TupleType: clevels = nlevels nlevels = len(clevels) # Make a list of mastercoords of all nodes of all elements ## TODO OPT: Rework this to use generators instead of passing ## lists around. It may be faster for large meshes. nodepoints = [] for element in mesh.element_iterator(): master = element.masterelement() el_mpos = [] # master coords of nodes in this element for n in range(master.nnodes()): el_mpos.append(master.get_protonode(n).mastercoord()) nodepoints.append(el_mpos) # Evaluate the function at the nodes values = [float(x) for x in what.evaluate(mesh, mesh.element_iterator(), nodepoints)] # Get function values grouped by element evalues = utils.unflatten(nodepoints, values) # TODO OPT: This is a lot of evaluation work -- are these # values cached somewhere, and can they be reused? ## vmax = max(values) ## for (vals, element) in zip(evalues, mesh.element_iterator()): ## if vmax in vals: ## debug.fmsg('max found in element', element, vals) ## break # Determine contour levels, if necessary if clevels is None: # contours not specified by user # Find range of values. This is just approximate, since the # interpolation within an element may give a value outside of # the range spanned by the nodal values. if self.min == automatic.automatic: vmin = float(min(values)) else: vmin = float(self.min) if self.max == automatic.automatic: vmax = float(max(values)) else: vmax = float(self.max) if nlevels == 1: clevels = [0.5*(vmax + vmin)] else: dz = (vmax - vmin)/(nlevels - 1) clevels = [vmin + i*dz for i in range(nlevels)] return clevels, evalues