def __call__(self, skeleton, context, divisions, markedEdges, criterion): subproblemobj = ooflib.engine.subproblemcontext.subproblems[ self.subproblem].getObject() femesh=subproblemobj.mesh self.estimator.preprocess(subproblemobj) prog = progress.findProgress("Refine") elements = skeleton.activeElements() n = len(elements) for i, element in enumerate(elements): # If the refinement is done more than once from the skeleton # page (after a mesh has been created), # some of the new skeleton elements may not have # corresponding mesh elements, i.e. element.meshindex is # undefined. The second refinement could be done after # a new mesh is created from the first refinement. fe_element = femesh.getElement(element.meshindex) if not subproblemobj.contains(fe_element): continue if not fe_element.material(): continue if (self.estimator(fe_element, subproblemobj) and criterion(skeleton, element)): self.markElement(element, divisions, markedEdges) if prog.stopped() : return prog.setFraction(1.0*(i+1)/n) prog.setMessage("checked %d/%d elements" % (i+1, n))
def __call__(self, skeleton, context, divisions, markedEdges, criterion): prog = progress.findProgress("Refine") elements = skeleton.activeElements() n = len(elements) for i, element in enumerate(elements): if criterion(skeleton, element): self.markElement(element, divisions, markedEdges) if prog.stopped(): return prog.setFraction(1.0 * (i + 1) / n) prog.setMessage("checked %d/%d elements" % (i + 1, n))
def __call__(self, skeleton, context, divisions, markedEdges, criterion): prog = progress.findProgress("Refine") segments = context.segmentgroups.get_group(self.group) n = len(segments) for i, segment in enumerate(segments): if segment.active(skeleton): self.markSegment(segment, divisions, markedEdges) if prog.stopped(): return prog.setFraction(1.0 * (i + 1) / n) prog.setMessage("checked %d/%d segments" % (i + 1, n))
def __call__(self, skel, context, targets, criterion, fixer): prog = progress.findProgress("Rationalize") # Copy the element list from skeleton.element before # rationalizing. This is necessary because rationalizing # modifies the Skeleton's element list. elements = targets(skel, context, copy=1) random.shuffle(elements) executed_action = self.getRegistration().gerund processed = set() count = 0 done = 0 # No. of rationalized elements nel = len(elements) # No. of elements to be considered while elements: element = elements.pop() count += 1 # No. of elements that have been considered if element not in processed and element.active(skel): # fixer is either self.findAndFix or self.fixAll. They # return a list of ProvisionalChanges objects, from # which we pick the best one. changes = fixer(skel, element) bestchange = criterion(changes, skel) if bestchange is not None: done += bestchange.nRemoved() # Accepting the change converts provisional # elements to actual elements. bestchange.accept(skel) for elephant in bestchange.removed: processed.add(elephant) for oldel, newel in bestchange.substitutions: # If an unprocessed element has been replaced, # its replacement still has to be processed. # The element being replaced should *not* be # processed, in any case, since it's no longer # in the skeleton. # If the criterion is "Unconditional" or # "Limited Unconditional", it doesn't add subs to # the list. if oldel not in processed: processed.add(oldel) nel += 1 elements.append(newel) for newel in bestchange.inserted: elements.append(newel) nel += 1 if prog.stopped(): break else: prog.setFraction(float(count) / nel) prog.setMessage(executed_action + " %d/%d" % (count, nel)) skel.cleanUp() reporter.report("%d elements rationalized : %s." % (done, self.getRegistration().name()))
def __call__(self, skeleton, context, divisions, markedEdges, criterion): microstructure = skeleton.MS prog = progress.findProgress("Refine") segments = self.choose_from.getSegments(context) n = len(segments) for i, segment in enumerate(segments): if segment.homogeneity(microstructure) < self.threshold: self.markSegment(segment, divisions, markedEdges) if prog.stopped(): return prog.setFraction(1.0 * (i + 1) / n) prog.setMessage("checked %d/%d segments" % (i + 1, n))
def __call__(self, skeleton, context, divisions, markedEdges, criterion): prog = progress.findProgress("Refine") elements = skeleton.activeElements() n = len(elements) for i, element in enumerate(elements): if criterion(skeleton, element) and (element.nnodes() == 4 or not self.only_quads): for segment in element.getAspectRatioSegments(self.threshold, skeleton): if segment.active(skeleton): self.markSegment(segment, divisions, markedEdges) if prog.stopped(): return prog.setFraction(1.0 * (i + 1) / n) prog.setMessage("checked %d/%d elements" % (i + 1, n))
def __call__(self, skeleton, context, divisions, markedEdges, criterion): prog = progress.findProgress("Refine") elements = context.elementgroups.get_group(self.group) n = len(elements) ## for i in range(n): ## element = elements[i] for i, element in enumerate(elements): if element.active(skeleton) and criterion(skeleton, element): self.markElement(element, divisions, markedEdges) if prog.stopped(): return prog.setFraction(1.0 * (i + 1) / n) prog.setMessage("checked %d/%d grouped elements" % (i + 1, n))
def __call__(self, skel, context, targets, criterion, fixer): prog = progress.findProgress("Rationalize") # Copy the element list from skeleton.element before # rationalizing. This is necessary because rationalizing # modifies the Skeleton's element list. elements = targets(skel, context, copy=1) random.shuffle(elements) executed_action = self.getRegistration().gerund processed = {} count = 0 done = 0 # No. of rationalized elements nel = len(elements) # No. of elements in the list for element in elements: count += 1 # The i-th element being processed ... for progress bar if element not in processed and element.active(skel): # fixer is either self.findAndFix or self.fixAll. They # return a list of ProvisionalChanges objects, from # which we pick the best one. changes = fixer(skel, element) bestchange = criterion(changes, skel) if bestchange is not None: done += bestchange.nRemoved() # Accepting the change converts provisional # elements to actual elements. bestchange.accept(skel) for elephant in bestchange.removed: processed[elephant] = 1 for oldel, newel in bestchange.substitutions: # If an unprocessed element has been replaced, # its replacement still has to be processed. # The element being replaced should *not* be # processed, in any case, since it's no longer # in the skeleton. # If the criterion is "Unconditional" or # "Limited Unconditional", it doesn't add subs to # the list. if oldel not in processed: processed[oldel] = 1 if criterion.addSubstitute(elements, newel): nel += 1 if prog.stopped(): break else: prog.setFraction(1.0*count/nel) prog.setMessage(executed_action + " %d/%d" % (count, nel)) skel.cleanUp() reporter.report("%d elements rationalized : %s." % (done, self.getRegistration().name()))
def __call__(self, skeleton, context, divisions, markedEdges, criterion): prog = progress.findProgress("Refine") elements = skeleton.activeElements() n = len(elements) for i, element in enumerate(elements): if (criterion(skeleton, element) and (element.nnodes() == 4 or not self.only_quads)): for segment in element.getAspectRatioSegments( self.threshold, skeleton): if segment.active(skeleton): self.markSegment(segment, divisions, markedEdges) if prog.stopped(): return prog.setFraction(1.0 * (i + 1) / n) prog.setMessage("checked %d/%d elements" % (i + 1, n))