Example #1
0
def main():
    """
    A sample main program to test our algorithms.

    @return: None
    """
    t0 = time.time()
    # initialize the random generator seed to always use the same set of points
    seed(0)
    # creates some points
    pts = create_points(30)

    show = True  # to display a frame
    save = False  # to save into .png files in "figs" directory
    scatter_plot(pts, [[]],
                 title="convex hull : initial set",
                 show=show,
                 save=save)
    print("Points:", pts)
    # compute the hull
    hull = Graham(pts, show=show, save=save)
    print("Hull:", hull)
    scatter_plot(pts, [hull],
                 title="convex hull : final result",
                 show=True,
                 save=save)
    t1 = time.time()
    print("temps en secondes :")
    print(t1 - t0)
Example #2
0
def main():
    """
    A sample main program to test our algorithms.

    @return: None
    """
    # initialize the random generator seed to always use the same set of points
    seed(0)
    # creates some points
    pts = create_points(6)
    show = True  # to display a frame
    save = False  # to save into .png files in "figs" directory
    scatter_plot(pts, [[]],
                 title="convex hull : initial set",
                 show=show,
                 save=save)
    print("Points:", pts)
    # compute the hull
    #hull = exhaustive(pts, show=show, save=save)
    hull = graham(pts, show=show, save=save)
    #hull = jarvis(pts, show=show, save=save)
    #hull = eddy_floyd(pts)
    print("Hull:", hull)
    scatter_plot(pts, [hull],
                 title="convex hull : final result",
                 show=True,
                 save=save)
Example #3
0
def global_stiffness_matrix(nodes, triangles):
    """
        Funtion for the assembly of the global stiffnes matrix.
        
        Parameters:
        -----------
        nodes:  numpy array of dimension (n_nodes, 3), where n_nodes is the 
                number of nodes forming the mesh, and the three columns 
                represent coordinates (x, y, z).
        triangles:  numpy array of dimension (n_triangles, 4), where n_nodes 
                    is the number of nodes forming the mesh, the first is the 
                    label that refers to the physical entity where each node 
                    belongs. The remaining columns  tell which nodes belong
                    to each of the vertices of the triangle
        remove:   List with the numbers of columns to be removed

        Returns:
        --------
        
        glo_stif:  Matrix like array of size (n_nodes, n_nodes). Represents
                   the global stiffness matrix of the system
    """
    from matrices import local_stiffness_matrix
    from utils import create_points, calculate_area
    
    
    n_nodes = nodes.shape[0]         # Number (n) of nodes
    n_triangles = triangles.shape[0] # Number (n) of triangles
    
    glo_stif = zeros((n_nodes, n_nodes))# Initiate Global (glo) stiffness matrix
    
    for el in range(n_triangles):
         
        pt_a, pt_b, pt_c = create_points(nodes, triangles, el)
        #print pt_a, pt_b, pt_c
        ln_ab = pt_b - pt_a    
        ln_bc = pt_c - pt_b
        ln_ca = pt_a - pt_c    
        lines = [ln_bc, ln_ca, ln_ab]
        
        area = calculate_area(lines)
        
       
        lo_stif = local_stiffness_matrix(lines)
        lo_stif = lo_stif/(4*area)
       
        for i in range(1, lo_stif.shape[0]+1):
            for j in range(1, lo_stif.shape[0]+1):
                
                glo_stif[triangles[el, i]-1, triangles[el, j]-1] = \
                glo_stif[triangles[el, i]-1, triangles[el, j]-1] + \
                lo_stif[i-1,j-1]
                #                        ^ due to python's 0 base numbering
    return glo_stif
Example #4
0
def global_mass_matrix(nodes, triangles, *remove):
    """
        funtion for the ensamble of the global mass matrix
        
        Parameters:
        -----------
        nodes:  numpy array of dimension (n_nodes, 3), where n_nodes is the 
                number of nodes forming the mesh, and the three columns 
                represent coordinates (x, y, z).
        triangles:  numpy array of dimension (n_triangles, 4), where n_nodes 
                    is the number of nodes forming the mesh, the first is the 
                    label that refers to the physical entity where each node 
                    belongs. The remaining columns  tell which nodes belong
                    to each of the vertices of the triangle
        remove:   List with the numbers of columns to be removed
        Returns:
        --------
    """
    from matrices import local_mass_matrix
    from utils import create_points
    from numpy.linalg import det
    from numpy import delete
    
    n_nodes = nodes.shape[0]         # Number (n) of nodes
    n_triangles = triangles.shape[0] # Number (n) of triangles
    
    glo_mass = zeros((n_nodes, n_nodes))# Initiate Global (glo) mass matrix
    tr_mat = zeros((2,2))      # Initiate the transformation (tr) matrix (mat)
    
    for el in range(n_triangles):
         
        pt_a, pt_b, pt_c = create_points(nodes, triangles, el)
        tr_mat[:, 0] = pt_b - pt_a
        tr_mat[:, 1] = pt_c - pt_a
        
        jac = det(tr_mat)  
        
        lo_mass = local_mass_matrix()
        lo_mass = jac * lo_mass    # Escalate acording with the jacobian of the
                                   # transformation 
       
        for i in range(1, lo_mass.shape[0]+1):
            for j in range(1, lo_mass.shape[0]+1):
                
                glo_mass[triangles[el, i]-1, triangles[el, j]-1] = \
                glo_mass[triangles[el, i]-1, triangles[el, j]-1] + \
                lo_mass[i-1,j-1]
                #                        ^ due to python's 0 base numbering
    glo_mass_d = delete(glo_mass, remove, 0)
    glo_mass_d = delete(glo_mass_d, remove, 1)
    
    return glo_mass_d
Example #5
0
def sources_vector(nodes, triangles, remove):
    """
        This function computes the l vector associated to sources in the domain 
        
        Parameters:
        -----------
        nodes:  numpy array of dimension (n_nodes, 3), where n_nodes is the 
                number of nodes forming the mesh, and the three columns 
                represent coordinates (x, y, z).
        
        triangles:  numpy array of dimension (n_triangles, 4), where n_nodes 
                    is the number of nodes forming the mesh, the first is the 
                    label that refers to the physical entity where each node 
                    belongs. The remaining columns  tell which nodes belong
                    to each of the vertices of the triangle
        Returns:
        --------
        l:  right hand side vector of the equation associated to sources.   
    """    
    
    from utils import create_points
    from numpy.linalg import det
    from numpy import array
    
    n_nodes = nodes.shape[0]         # Number (n) of nodes
    n_triangles = triangles.shape[0] # Number (n) of triangles

    glo_l = zeros(n_nodes)   # Initiate global sources vector l 

    tr_mat = zeros((2,2))      # Initiate the transformation (tr) matrix (mat)
    
    for el in range(n_triangles):
        pt_a, pt_b, pt_c = create_points(nodes, triangles, el)
        
        tr_mat[:, 0] = pt_b - pt_a
        tr_mat[:, 1] = pt_c - pt_a
        
        jac = det(tr_mat)  
        
        lo_l = array([1./6, 1./6, 1./6]) # This is the local (lo) l vector fo 
                                         # a standard triangular element of 
                                         # base 1 and height 1
        for i in range(1, 4):
            glo_l[triangles[el, i]-1] = glo_l[triangles[el, i]-1] + \
                                        jac * lo_l[i - 1]            
    
    glo_l = delete(glo_l, remove) # Remove Dirichlet columns
    
    return glo_l    
Example #6
0
def main():
    """
    A sample main program to test our algorithms.

    @return: None
    """
    to=time.time()
    # initialize the random generator seed to always use the same set of points
    seed(0)
    # creates some points
    pts = create_points(1800)
    show = True  # to display a frame
    save = False  # to save into .png files in "figs" directory
    scatter_plot(pts, [[]], title="convex hull : initial set", show=show, save=save)
    print("Points:", pts)
    # compute the hull
    #hull = exhaustive(pts, show=show, save=save)
    print("graham",graham(pts))
    hull=graham(pts)
    print("Hull:", hull)
    scatter_plot(pts, [hull], title="convex hull : final result", show=True, save=save)
    print("Temps d'éxecution: %s secondes" %(time.time()-to))