Ejemplo n.º 1
0
def constrained_cells_center(self):
    """ calculate cell centers giving preference to constrained
    nodes 
    """
    for c in np.arange(self.Ncells()):
        nodes=self.cell_to_nodes(c)
        constrained=(self.nodes['constrained'][nodes]==C_FIXED)
        points=self.nodes['x'][nodes]
        # for starters, only invoke the special logic when there
        # at least three constrained nodes
        ncon=np.sum(constrained)
        if ncon==0: # regular
            self.cells['_center'][c] = utils.poly_circumcenter(points)
        elif ncon==1:
            ci=np.nonzero(constrained)[0][0]
            nn=len(constrained)
            constrained[(ci+1)%nn]=True
            constrained[(ci-1)%nn]=True
            self.cells['_center'][c] = utils.poly_circumcenter(points[constrained])
        else:
            print ".",
            self.cells['_center'][c] = utils.poly_circumcenter(points[constrained])
    print
    return self.cells['_center']