def create_cp_fc_03(L_x = 4, L_y = 4, n_x = 2, n_y = 2, z0_ratio = 0.1,
                     n_steps = 100):
    '''Create scalable rhombus crease pattern with face constraints
       other constraints chosen (more in field in z-direction)
    '''
    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              z0_ratio = z0_ratio,
                              MAX_ITER = 50)

    n_h = cp.N_h
    n_v = cp.N_v
    n_i = cp.N_i

    y_links = []

    n_h_idx = (n_x + 1) / 2
    print "n_h_idx", n_h_idx

    for idx, n in enumerate(n_h[1:, 0]):
        y_links.append([(n_h[0, 0], 1, 1.0), (n, 1, -1.0)])

    for idx, n in enumerate(n_h[1:-1, -1]):
        y_links.append([(n_h[0, -1], 1, 1.0), (n, 1, -1.0)])

    for idx, n in enumerate(n_h[n_h_idx, 1:]):
        y_links.append([(n, 0, 1.0)])


    y_links.append([(n_h[0, -1], 1, 1.0)])

    cp.cnstr_lhs = y_links

    print "n_h[1, 0]", n_h[1, 0]
    print "n_h[-1,-1]", n_h[-1, 0]
    print "n_h[1, -1]", n_h[1, -1]
    print "n_h[-1,-1]", n_h[-1, -1]

    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)

    print "cnstr_lhs", cp.cnstr_lhs
    print "cnstr_rhs", cp.cnstr_rhs

    A = 0.784
    
    face_z_t = CF(Rf = z_ - 4 * A * t_ * x_ * (1 - x_ / L_x))
#    face_x_L2 = CF(Rf = x_ - L_x / 2)
    n_arr = np.hstack([n_h[n_h_idx, :].flatten(),
                    n_h[0, :].flatten(),
                    n_h[-1, :].flatten()])
    cp.cf_lst = [(face_z_t, n_arr)]

    print "edge1", n_h[0, :]
    print "edge2", n_h[-1, :]
    print "center", n_h[1:-1, :]
    return cp
Ejemplo n.º 2
0
def cp01(L_x = 4, L_y = 2, n_x = 2, n_y = 2, n_steps = 80):

    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              z0_ratio = 0.01,
                              show_iter = False,
                              MAX_ITER = 500)

    n_h = cp.N_h
    n_i = cp.N_i
    n_v = cp.N_v

    cp.cnstr_lhs = [[(n_h[0, 0], 2, 1.0)], # 0
                    [(n_h[0, -1], 2, 1.0)], # 1
                    [(n_h[-1, 0], 2, 1.0)], # 2
                    [(n_h[-1, -1], 2, 1.0)], # 3
                    [(n_h[1, 0], 2, 1.0)], # 4
                    [(n_h[0, 0], 1, 1.0), (n_h[1, 0], 1, -1.0)], # 5
                    [(n_h[0, 0], 1, 1.0), (n_h[-1, 0], 1, -1.0)], # 6
                    [(n_h[0, -1], 1, 1.0), (n_h[1, -1], 1, -1.0)], # 7
                    [(n_h[0, -1], 1, 1.0), (n_h[-1, -1], 1, -1.0)], # 8
                    [(n_h[1, 0], 0, 1.0)], # 9
                    [(n_h[0, -1], 1, 1.0)], # 10
                    ]

    # lift node 0 in z-axes
    cp.cnstr_rhs = np.zeros((14,), dtype = float)
    cp.cnstr_rhs[4] = 1.999999999

    return cp
Ejemplo n.º 3
0
def cp04(L_x = 4, L_y = 4, n_x = 2, n_y = 4, n_steps = 100):

    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              MAX_ITER = 500)

    n_h = cp.N_h
    n_i = cp.N_i
    n_v = cp.N_v

    z_nodes = n_h[(0, -1), :].flatten()
    z_cnstr = [[(n, 2, 1.0)] for n in z_nodes]

    y_links = []
    for n_arr in n_h.T:
        for n in n_arr[1:]:
            y_links.append([(n_arr[0], 1, 1.0), (n, 1, -1.0)])

    x_cnstr = [[(n_h[0, 0], 0, 1.0)]]

    y_cnstr = [[(n_h[0, -1], 1, 1.0)],
               [(n_h[0, 0], 1, 1.0)]]

    cp.cnstr_lhs = z_cnstr + y_links + x_cnstr + y_cnstr

    # lift node 0 in z-axes
    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)
    cp.cnstr_rhs[-1] = 3.9

    return cp
def create_cp_fc(L_x = 4, L_y = 4, n_x = 1, n_y = 2,
         n_steps = 100):
    '''Create scalable rhombus crease pattern with face constraints
    '''
    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              MAX_ITER = 500)

    n_h = cp.N_h
    n_i = cp.N_i
    n_v = cp.N_v
    n_h_idx = n_y / 4

    x_links = []
    y_links = []
    z_links = []

#    for n_arr in n_h[:, (-1,)].T:
#        for idx, n in enumerate(n_arr[1:]):
#            y_links.append([(n_arr[0], 1, 1.0), (n, 1, -1.0)])

    for n in n_v[-1, 1:]:
        x_links.append([(n_v[-1, 0], 0, 1.0), (n, 0, -1.0)])

    for n0, n1 in zip(n_v[0, :], n_v[-1, :]):
        z_links.append([(n0, 2, 1.0), (n1, 2, -1.0)])

    #cntrl = [[(n_h[-1, -1], 1, 1.0)]]
    #cntrl = [[(n_h[-1, 1], 0, 1.0)]]

    cp.cnstr_lhs = x_links + y_links + z_links # + cntrl
    #cp.cnstr_lhs = z_cnstr

    # lift node 0 in z-axes
    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)
    #cp.cnstr_rhs[-1] = -L_x * 0.34

    face_z_0 = CF(Rf = z_ - 0)
    face_x_0 = CF(Rf = x_ - 0)
    face_x_L = CF(Rf = x_ - L_x * (1 - 0.2 * t_))
    face_y_0 = CF(Rf = y_ - 0)
    face_y_L = CF(Rf = y_ - L_y * (1 - 0.1 * t_))#* x_ / L_x))

    cp.cf_lst = [(face_x_0, n_h[0, :]), # [n_h[0, 0], n_h[0, -1]]),
                    (face_z_0, n_h[0, :]), # [n_h[0, 0], n_h[0, -1]]),
                    (face_y_0, n_h[:, 0]),
#                    (face_x_L, []),
                    (face_y_L, n_h[:, -1])]
#    cp.cnstr_rhs[-1] = -L_y * 0.9999

    return cp
Ejemplo n.º 5
0
def cp05(L_x = 4, L_y = 4, n_x = 2, n_y = 4,
         n_steps = 100, skew_coeff = 0.0):
    '''Exploit symmetric constraints
    '''
    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              MAX_ITER = 500)

    n_h = cp.N_h
    n_i = cp.N_i
    n_v = cp.N_v

    z_nodes = n_h[(0, -1), :].flatten()
    z_cnstr = [[(n, 2, 1.0)] for n in z_nodes]

    y_links = []
    for n_arr in n_h[:, (0, -1)].T:
        for idx, n in enumerate(n_arr[1:]):
            n_x = len(n_arr)
            coeff = skew_coeff * float(idx + 1) / float(n_x)
            y_links.append([(n_arr[0], 1, 1.0 - coeff), (n, 1, -1.0)])

    for n_arr in n_h[:, 1:-1].T:
        y_links.append([(n_arr[0], 1, 1.0), (n_arr[-1], 1, -1.0)])

    x_links = []
    z_links = []
#    for n0, n1 in zip(n_h[1:-1, 0], n_h[1:-1, -1]):
#        x_links.append([(n0, 0, 1.0), (n1, 0, 1.0)])
#        z_links.append([(n0, 2, 1.0), (n1, 2, -1.0)])
    for n in n_v[0, 1:]:
        z_links.append([(n_v[0, 0], 2, 1.0), (n, 2, -1.0)])

    n_h_idx = n_y / 4
    x_cnstr = [[(n_h[0, n_h_idx], 0, 1.0)]]

    y_cnstr = [[(n_h[0, n_h_idx], 1, 1.0)]]

    cntrl = [[(n_h[-1, n_h_idx], 0, 1.0)]]
    #cntrl = [[(n_h[-1, 0], 1, 1.0)]]

    cp.cnstr_lhs = z_cnstr + x_links + y_links + z_links + x_cnstr + y_cnstr + cntrl

    # lift node 0 in z-axes
    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)
    cp.cnstr_rhs[-1] = -L_x * 0.1

    return cp
Ejemplo n.º 6
0
def create_cp_fc_01(L_x = 4, L_y = 4, n_x = 2, n_y = 2, z0_ratio = 0.1,
                     n_steps = 100):
    '''Create scalable rhombus crease pattern with face constraints
       One basic element with no general formulation
    '''
    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              z0_ratio = z0_ratio,
                              MAX_ITER = 50)

    n_h = cp.N_h
    n_v = cp.N_v
    n_i = cp.N_i


    cp.cnstr_lhs = [[(n_h[0, 0], 1, 1.0), (n_h[1, 0], 1, -1.0)], # 1
                    [(n_h[0, 0], 1, 1.0), (n_h[-1, 0], 1, -1.0)], # 2
                    [(n_h[0, -1], 1, 1.0), (n_h[1, -1], 1, -1.0)], # 3
                    [(n_h[0, -1], 1, 1.0), (n_h[-1, -1], 1, -1.0)], # 4
                    [(n_h[0, -1], 1, 1.0)],
                    [(n_h[1, 0], 0, 1.0)]
                    ]

    print "n_h[1, 0]", n_h[1, 0]
    print "n_h[-1,-1]", n_h[-1, 0]
    print "n_h[1, -1]", n_h[1, -1]
    print "n_h[-1,-1]", n_h[-1, -1]


    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)

    print "cnstr_lhs", cp.cnstr_lhs
    print "cnstr_rhs", cp.cnstr_rhs

    A = 0.2

    face_z_t = CF(Rf = z_ - 4 * A * t_ * x_ * (1 - x_ / L_x))
    face_x_L2 = CF(Rf = x_ - L_x / 2)

    cp.cf_lst = [(face_z_t, n_h[0, :]),
                    (face_z_t, n_h[-1, :]),
                    (face_z_t, [n_h[1, 0]]),
                    ]


    print "edge1", n_h[0, :]
    print "edge2", n_h[-1, :]
    return cp
Ejemplo n.º 7
0
def cp03(L_x = 4, L_y = 4, n_x = 2, n_y = 4, n_steps = 80):

    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              MAX_ITER = 500)

    n_h = cp.N_h
    n_i = cp.N_i
    n_v = cp.N_v

    cp.cnstr_lhs = [[(n_h[0, 0], 2, 1.0)], # 0
                    [(n_h[0, -1], 2, 1.0)], # 1
                    [(n_h[-1, 0], 2, 1.0)], # 2
                    [(n_h[-1, -1], 2, 1.0)], # 3
                    [(n_h[0, 1], 2, 1.0)], # 4
                    [(n_h[-1, 1], 2, 1.0)], # 5
                    [(n_h[0, 0], 1, 1.0)], # 6
                    [(n_h[0, 0], 1, 1.0), (n_h[1, 0], 1, -1.0)], # 7
                    [(n_h[0, 0], 1, 1.0), (n_h[-1, 0], 1, -1.0)], # 8
                    [(n_h[0, -1], 1, 1.0), (n_h[1, -1], 1, -1.0)], # 9
                    [(n_h[0, -1], 1, 1.0), (n_h[-1, -1], 1, -1.0)], # 10
                    [(n_h[1, 1], 0, 1.0)], # 11
                    [(n_h[0, -1], 1, 1.0)], # 12
                    [(n_h[1, 1], 1, 1.0), (n_h[0, 1], 1, -1.0)], # 13
                    [(n_h[1, 1], 1, 1.0), (n_h[-1, 1], 1, -1.0)], # 14
#                    [(n_h[1, 1], 2, 1.0), (n_h[1, 0], 2, -1.0)], # 13
#                    [(n_h[1, 1], 1, 1.0), (n_h[1, -1], 2, -1.0)], # 14
                    ]

    # lift node 0 in z-axes
    cp.cnstr_rhs = np.zeros((15,), dtype = float)
    cp.cnstr_rhs[6] = 3.95

    return cp
Ejemplo n.º 8
0
def rhombus_3x2_crane(n_steps = 10, dx = 1):
    """
        This example shows a 3x2 rhombus creasepattern.

    """
    cpr = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = 3,
                              L_y = 2,
                              n_x = 3,
                              n_y = 4,
                              MAX_ITER = 5000)

    X_rcp = cpr.generate_X0()
    X_rcp = X_rcp.reshape((-1, 3))
    X_rcp[:, 2] += -0.1559

    cp = CreasePattern(n_steps = n_steps, MAX_ITER = 500)

    cp.nodes = cpr.nodes

    cp.crease_lines = cpr.crease_lines

    cp.facets = cpr.facets

    grab_nodes = [[0.5, 0.333, 0],
                  [0.5, 0.667, 0],
                  [0.5, 1.333, 0],
                  [0.5, 1.667, 0],
                  [1.5, 0.333, 0],
                  [1.5, 0.667, 0],
                  [1.5, 1.333, 0],
                  [1.5, 1.667, 0],
                  [2.5, 0.333, 0],
                  [2.5, 0.667, 0],
                  [2.5, 1.333, 0],
                  [2.5, 1.667, 0]]#33

    crane_nodes = [[1.5, 0.5, 1.0], #34
                   [0.5, 0.5, 1],
                   [2.5, 0.5, 1],
                   [0.5, 0.333, 1.0],
                   [0.5, 0.667, 1.0], #38
                   [2.5, 0.333, 1.0],
                   [2.5, 0.667, 1.0],
                   [1.5, 0.333, 1.0],
                   [1.5, 0.667, 1.0],

                   [1.5, 1.5, 1.0], #43
                   [0.5, 1.5, 1],
                   [2.5, 1.5, 1],
                   [0.5, 1.333, 1.0], #46
                   [0.5, 1.667, 1.0],
                   [2.5, 1.333, 1.0],
                   [2.5, 1.667, 1.0],
                   [1.5, 1.333, 1.0],
                   [1.5, 1.667, 1.0], #51
                   ]

    cp.nodes = np.vstack([cp.nodes, grab_nodes])
    cp.nodes = np.vstack([cp.nodes, crane_nodes])


    crane_cl = [#crane 1
                [34, 35], #49
                [34, 36],
                [35, 37],
                [35, 38],
                [36, 39],
                [36, 40],
                [34, 41], #55
                [34, 42],

                [37, 22],
                [38, 23], #60
                [39, 30],
                [40, 31],
                [41, 26],
                [42, 27],
                #crane 2
                [43, 44], #65
                [43, 45],
                [44, 46],
                [44, 47],
                [45, 48],
                [45, 49],
                [43, 50],
                [43, 51],
                [46, 24],
                [47, 25],
                [48, 32],
                [49, 33],
                [50, 28],
                [51, 29],

                ]

    cp.crease_lines = np.vstack([cp.crease_lines, crane_cl])

    cp.grab_pts = [[22, 0],
                   [23, 14],
                   [26, 2],
                   [27, 16],
                   [30, 4],
                   [31, 18],
                   [24, 1],
                   [25, 15],
                   [28, 3],
                   [29, 17],
                   [32, 5],
                   [33, 19]
                   ]
#    cp.line_pts = [[37, 49],
#                   [38, 50],
#                   [48, 63],
#                   [49, 64]
#                   ]
#    

    cnstr_lhs_2 = [[(34, 2, 1.0)],
                    [(34, 0, 1.0)],
#                    [(34, 1, 1.0)],
                    [(34, 2, 1.0), (41, 2, -1.0)],
                    [(34, 2, 1.0), (42, 2, -1.0)],
                    [(34, 2, 1.0), (43, 2, -1.0)],
                    [(34, 0, 1.0), (41, 0, -1.0)],
                    [(34, 0, 1.0), (42, 0, -1.0)],
                    [(35, 2, 1.0), (37, 2, -1.0)],
                    [(35, 2, 1.0), (38, 2, -1.0)],
                    [(35, 0, 1.0), (37, 0, -1.0)],
                    [(35, 0, 1.0), (38, 0, -1.0)],
                    [(36, 2, 1.0), (39, 2, -1.0)],
                    [(36, 2, 1.0), (40, 2, -1.0)],
                    [(36, 0, 1.0), (39, 0, -1.0)],
                    [(36, 0, 1.0), (40, 0, -1.0)],
                    [(35, 2, 1.0)],
                    [(36, 2, 1.0)],
                    [(36, 1, 1.0), (34, 1, -1.0)],
                    [(35, 1, 1.0), (34, 1, -1.0)],

                    [(43, 0, 1.0)],
#                    [(43, 1, 1.0)],
                    [(43, 2, 1.0), (50, 2, -1.0)],
                    [(43, 2, 1.0), (51, 2, -1.0)],
                    [(43, 0, 1.0), (50, 0, -1.0)],
                    [(43, 0, 1.0), (51, 0, -1.0)],
                    [(44, 2, 1.0), (46, 2, -1.0)],
                    [(44, 2, 1.0), (47, 2, -1.0)],
                    [(44, 0, 1.0), (46, 0, -1.0)],
                    [(44, 0, 1.0), (47, 0, -1.0)],
                    [(45, 2, 1.0), (48, 2, -1.0)],
                    [(45, 2, 1.0), (49, 2, -1.0)],
                    [(45, 0, 1.0), (48, 0, -1.0)],
                    [(45, 0, 1.0), (49, 0, -1.0)],
                    [(44, 2, 1.0)],
                    [(45, 2, 1.0)],
                    [(44, 1, 1.0), (43, 1, -1.0)],
                    [(45, 1, 1.0), (43, 1, -1.0)],

                    [(4, 0, 1.0)],
                    [(1, 1, 1.0)],

                    [(22, 1, 1.0), (26, 1, -1.0)],

                    [(3, 2, 1.0), (6, 2, -1.0)],
                    [(23, 1, 1.0), (27, 1, -1.0)],
                    [(27, 1, 1.0), (31, 1, -1.0)],
                    [(22, 0, 1.0), (23, 0, -1.0)],
                    [(34, 1, 1.0), (18, 1, -1.0)],
                    [(34, 1, 1.0), (43, 1, 1.0)]


                    ]

    cnstr_lhs_1 = [[(34, 2, 1.0)],
                    [(34, 0, 1.0)],
                    [(34, 1, 1.0)],
                    [(34, 2, 1.0), (41, 2, -1.0)],
                    [(34, 2, 1.0), (42, 2, -1.0)],
                    [(34, 2, 1.0), (43, 2, -1.0)],
                    [(34, 0, 1.0), (41, 0, -1.0)],
                    [(34, 0, 1.0), (42, 0, -1.0)],
                    [(35, 2, 1.0), (37, 2, -1.0)],
                    [(35, 2, 1.0), (38, 2, -1.0)],
                    [(35, 0, 1.0), (37, 0, -1.0)],
                    [(35, 0, 1.0), (38, 0, -1.0)],
                    [(36, 2, 1.0), (39, 2, -1.0)],
                    [(36, 2, 1.0), (40, 2, -1.0)],
                    [(36, 0, 1.0), (39, 0, -1.0)],
                    [(36, 0, 1.0), (40, 0, -1.0)],
                    [(35, 2, 1.0)],
                    [(36, 2, 1.0)],
                    [(36, 1, 1.0)],
                    [(35, 1, 1.0)],

                    [(43, 0, 1.0)],
                    [(43, 1, 1.0), (45, 1, -1.0)],
                    [(43, 2, 1.0), (50, 2, -1.0)],
                    [(43, 2, 1.0), (51, 2, -1.0)],
                    [(43, 0, 1.0), (50, 0, -1.0)],
                    [(43, 0, 1.0), (51, 0, -1.0)],
                    [(44, 2, 1.0), (46, 2, -1.0)],
                    [(44, 2, 1.0), (47, 2, -1.0)],
                    [(44, 0, 1.0), (46, 0, -1.0)],
                    [(44, 0, 1.0), (47, 0, -1.0)],
                    [(45, 2, 1.0), (48, 2, -1.0)],
                    [(45, 2, 1.0), (49, 2, -1.0)],
                    [(45, 0, 1.0), (48, 0, -1.0)],
                    [(45, 0, 1.0), (49, 0, -1.0)],
                    [(44, 2, 1.0)],
                    [(45, 2, 1.0)],
                    [(44, 1, 1.0), (43, 1, -1.0)],
                    [(43, 1, 1.0), (19, 1, -1.0)],

                    #[(35, 1, 1.0), (12, 1, -1.0)],
                    #[(46, 1, 1.0), (13, 1, -1.0)],
                    #[(35, 1, 1.0), (46, 1, 1.0)],
                    #[(36, 1, 1.0), (47, 1, 1.0)],

                    [(4, 0, 1.0)],
                    [(1, 1, 1.0), (10, 1, -1.0)],
                    #[(10, 1, 1.0)],
                    #[(37, 2, 1.0), (48, 2, -1.0)],
                    #[(26, 1, 1.0), (30, 1, -1.0)],
                    #[(0, 1, 1.0), (3, 1, -1.0)],
                    #[(37, 2, 1.0), (38, 2, -1.0)],
                    #[(29, 1, 1.0), (33, 1, -1.0)],
                    [(22, 1, 1.0), (26, 1, -1.0)],
                    #[(22, 0, 1.0), (24, 0, -1.0)],
                    #[(38, 0, 1.0), (49, 0, -1.0)],
                    #[(48, 2, 1.0), (49, 2, -1.0)],
                    #[(3, 2, 1.0), (6, 2, -1.0)],
                    #[(24, 1, 1.0), (28, 1, -1.0)],
                    #[(27, 1, 1.0), (31, 1, -1.0)],
                    [(3, 2, 1.0), (6, 2, -1.0)],
                    #[(3, 1, 1.0), (6, 1, -1.0)],
                    #[(5, 2, 1.0), (8, 2, -1.0)],
                    #[(30, 0, 1.0), (31, 0, -1.0)]
                    #[(30, 0, 1.0), (31, 0, -1.0)],
                    [(22, 0, 1.0), (23, 0, -1.0)]
#                    [(12, 2, 1.0)],
#                    [(13, 0, 1.0)],
#                    [(14, 2, 1.0)],
#                    [(15, 2, 1.0)]
                    ]

    cnstr_lhs_3 = [[(34, 2, 1.0)],
                    [(34, 0, 1.0)],
                    [(34, 1, 1.0), (43, 1, 1.0)],
                    [(34, 2, 1.0), (41, 2, -1.0)],
                    [(34, 2, 1.0), (42, 2, -1.0)],
                    #[(34, 2, 1.0), (43, 2, -1.0)],
                    [(34, 0, 1.0), (41, 0, -1.0)],
                    [(34, 0, 1.0), (42, 0, -1.0)],
                    [(35, 2, 1.0), (37, 2, -1.0)],
                    [(35, 2, 1.0), (38, 2, -1.0)],
                    [(35, 0, 1.0), (37, 0, -1.0)],
                    [(35, 0, 1.0), (38, 0, -1.0)],
                    [(36, 2, 1.0), (39, 2, -1.0)],
                    [(36, 2, 1.0), (40, 2, -1.0)],
                    [(36, 0, 1.0), (39, 0, -1.0)],
                    [(36, 0, 1.0), (40, 0, -1.0)],
                    [(35, 2, 1.0)],
                    [(36, 2, 1.0)],
                    [(36, 1, 1.0), (34, 1, -1.0)],
                    [(35, 1, 1.0), (34, 1, -1.0)],

                    [(43, 0, 1.0)],
                    [(43, 1, 1.0), (45, 1, -1.0)],
                    [(43, 2, 1.0), (50, 2, -1.0)],
                    [(43, 2, 1.0), (51, 2, -1.0)],
                    [(43, 0, 1.0), (50, 0, -1.0)],
                    [(43, 0, 1.0), (51, 0, -1.0)],
                    [(44, 2, 1.0), (46, 2, -1.0)],
                    [(44, 2, 1.0), (47, 2, -1.0)],
                    [(44, 0, 1.0), (46, 0, -1.0)],
                    [(44, 0, 1.0), (47, 0, -1.0)],
                    [(45, 2, 1.0), (48, 2, -1.0)],
                    [(45, 2, 1.0), (49, 2, -1.0)],
                    [(45, 0, 1.0), (48, 0, -1.0)],
                    [(45, 0, 1.0), (49, 0, -1.0)],
                    [(44, 2, 1.0)],
                    [(45, 2, 1.0)],
                    [(44, 1, 1.0), (43, 1, -1.0)],
                    [(43, 1, 1.0), (19, 1, -1.0)],

                    #[(35, 1, 1.0), (12, 1, -1.0)],
                    #[(46, 1, 1.0), (13, 1, -1.0)],
                    #[(35, 1, 1.0), (46, 1, 1.0)],
                    #[(36, 1, 1.0), (47, 1, 1.0)],

                    [(4, 0, 1.0)],
                    [(1, 1, 1.0)],
                    #[(10, 1, 1.0)],
                    #[(37, 2, 1.0), (48, 2, -1.0)],
                    #[(26, 1, 1.0), (30, 1, -1.0)],
                    #[(0, 1, 1.0), (3, 1, -1.0)],
                    #[(37, 2, 1.0), (38, 2, -1.0)],
                    #[(29, 1, 1.0), (33, 1, -1.0)],
                    [(22, 1, 1.0), (26, 1, -1.0)],
                    [(22, 0, 1.0), (23, 0, -1.0)],
                    #[(38, 0, 1.0), (49, 0, -1.0)],
                    #[(48, 2, 1.0), (49, 2, -1.0)],
                    #[(3, 2, 1.0), (6, 2, -1.0)],
                    #[(24, 1, 1.0), (28, 1, -1.0)],
                    #[(27, 1, 1.0), (31, 1, -1.0)],
                    [(3, 2, 1.0), (6, 2, -1.0)],
                    #[(3, 1, 1.0), (6, 1, -1.0)],
                    #[(5, 2, 1.0), (8, 2, -1.0)],
                    #[(30, 0, 1.0), (31, 0, -1.0)]
                    #[(30, 0, 1.0), (31, 0, -1.0)],
                    [(22, 0, 1.0), (23, 0, -1.0)]
#                    [(12, 2, 1.0)],
#                    [(13, 0, 1.0)],
#                    [(14, 2, 1.0)],
#                    [(15, 2, 1.0)]
                    ]
    cp.cnstr_lhs = cnstr_lhs_1

    cp.cnstr_rhs = np.zeros((cp.n_dofs,))
    cp.cnstr_rhs[0] = dx


    X_ext = np.zeros((cp.n_dofs - len(X_rcp.reshape((-1,))),), dtype = float)
    X0 = np.hstack([X_rcp.reshape((-1,)), X_ext])

    X0[68] = 0.0
    X0[71] = 0.0
    X0[74] = 0.0
    X0[77] = 0.0
    X0[80] = 0.1441
    X0[83] = 0.1441
    X0[86] = 0.1441
    X0[89] = 0.1441
    X0[92] = 0.0
    X0[95] = 0.0
    X0[98] = 0.0
    X0[101] = 0.0

    X0[104] = 0.1441
    X0[125] = 0.1441
    X0[128] = 0.1441
    #X0[131] = 0.45
    X0[152] = 0.1441
    X0[155] = 0.1441

    X0[132] = 0.1441
    X0[135] = -0.1441





    X0 *= 0.1
    #np.set_printoptions(threshold='nan')
    print 'G_du', cp.get_G_du(X0)
    print 'R', cp.get_G(X0)
#    sf = SingularityFinder()
#    sf.singul_test(cp.get_G_du(X0))

    print 'L_vct', cp.grab_pts_L
    print 'n_dofs', cp.n_dofs
    print 'n_c', cp.n_c
    print 'n_g', cp.n_g
    print 'necessary constraints', cp.n_dofs - cp.n_c - cp.n_g * 3 - cp.n_l * 2
    print 'cnstr', len(cp.cnstr_lhs)

    #cp.show_iter = True    
    X = cp.solve(X0)
    return cp
Ejemplo n.º 9
0
def create_cp_fc_bow(L_x = 4, L_y = 4, n_x = 4, n_y = 2, z0_ratio = 0.1,
                     n_steps = 100):
    '''Create scalable rhombus crease pattern with face constraints
       bad working
    '''
    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              z0_ratio = z0_ratio,
                              MAX_ITER = 50)

    n_h = cp.N_h
    n_v = cp.N_v
    n_i = cp.N_i

#    y_links = []

#    n_h0 = n_h[(0, -1), :-1]
#    n_h1 = n_h[(0, -1), 1:]
#    for nv, nh0, nh1 in zip(n_v.T, n_h0.T, n_h1.T):
#        for v, h0, h1 in zip(nv, nh0, nh1):
#            y_links.append([(v, 1, 1.0), (h1, 1, -0.5)])


#    cp.cnstr_lhs = y_links
#    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)

#    print "cnstr_lhs", cp.cnstr_lhs
#    print "cnstr_rhs", cp.cnstr_rhs

#    A = L_x * 0.2
    A = 0.2
#    face_z_t = CF(Rf = z_ - 4 * A * t_ / L_x * x_ * (1 - x_ / L_x))
    face_z_t = CF(Rf = z_ - 4 * A * t_ * x_ * (1 - x_ / L_x))
    face_x_L2 = CF(Rf = x_ - L_x / 2)
#old
#    face_y_L2 = CF(Rf = y_ - L_y / 2)
#new
    face_y_L0 = CF(Rf = y_)
#    face_y_Ly = CF(Rf = y_ - L_y)


#    n_h_idx = n_x / 2

#    z_nodes = n_h[:, :].flatten()

#    cp.cf_lst = [(face_y_L2, [n_i[0, 0]]),
#                    (face_z_t, z_nodes),
###                    (face_x_L2, n_h[2, (0, -1)].flatten()),
##                    (face_x_L2, n_h[n_h_idx, (0, -1)].flatten()),
#                    (face_x_L2, n_h[n_h_idx, :].flatten()),
#                    ]

#new
    n_h_idx = n_x / 2

    z_nodes_field1 = n_h[1:n_h_idx, 0].flatten()
    z_nodes_field2 = n_h[(n_h_idx + 1):-1, 0].flatten()
    z_nodes_field3 = n_h[1:n_h_idx, 1].flatten()
    z_nodes_field4 = n_h[(n_h_idx + 1):-1, 1].flatten()


    cp.cf_lst = [(face_y_L0, [n_h[0, 0]]),
                    (face_y_L0, [n_h[n_h_idx, -1]]),
                    (face_y_L0, [n_h[-1, 0]]),
                    (face_z_t, z_nodes_field1),
                    (face_z_t, z_nodes_field2),
                    (face_z_t, z_nodes_field3),
                    (face_z_t, z_nodes_field4),
                    (face_z_t, n_h[n_h_idx, :]),
                    (face_z_t, n_h[0, :]),
                    (face_z_t, n_h[-1, :]),
#                    (face_z_t, n_h[n_h_idx,1:]),                
#                    (face_x_L2, n_h[2, (0, -1)].flatten()),
#                    (face_x_L2, n_h[n_h_idx, (0, -1)].flatten()),
                    (face_x_L2, n_h[n_h_idx, :].flatten()),
                    ]

    print "field1", z_nodes_field1
    print "field2", z_nodes_field2
    print "edge1", n_h[0, :]
    print "edge2", n_h[-1, :]
    print "center", n_h[n_h_idx, :]
    return cp
Ejemplo n.º 10
0
def create_cp_fc_inclined(L_x = 4, L_y = 4, n_x = 2, n_y = 4,
         n_steps = 100):
    '''Create scalable rhombus crease pattern with face constraints
    '''
    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              MAX_ITER = 50)

    n_h = cp.N_h
    n_v = cp.N_v
    n_i = cp.N_i

    y_links = []

#    n_h0 = n_h[(0, -1), :-1]
#    n_h1 = n_h[(0, -1), 1:]
#    for nv, nh0, nh1 in zip(n_v.T, n_h0.T, n_h1.T):
#        for v, h0, h1 in zip(nv, nh0, nh1):
#            print 'constraining', h0, h1
#            y_links.append([(h0, 1, 1.0), (h1, 1, -1.0)])

    n_h0 = n_h[(0, -1), :-1]
    n_h1 = n_h[(0, -1), 1:]
    for nv in n_v.T:
        print 'adding constraint', nv
        y_links.append([(nv[0], 0, 1.0), (nv[1], 0, 1.0)])

    # here was a conflict @todo - resolve with Jan
    #    for nv, nh0, nh1 in zip(n_v.T, n_h0.T, n_h1.T):
    #        for v, h0, h1 in zip(nv, nh0, nh1):
    #            y_links.append([(v, 1, 1.0), (h1, 1, -0.5)])


    cp.cnstr_lhs = y_links
    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)

    print "cnstr_lhs", cp.cnstr_lhs
    print "cnstr_rhs", cp.cnstr_rhs

#    A = L_x * 0.2
    A = 0.2
#    face_z_t = CF(Rf = z_ - 4 * A * t_ / L_x * x_ * (1 - x_ / L_x))
    face_z_t = CF(Rf = z_ - 4 * A * t_ * x_ * (1 - x_ / L_x))
    face_x_L2 = CF(Rf = x_ - L_x / 2)

    face_y_L2 = CF(Rf = y_ - L_y / 2)
#    face_y_Ly = CF(Rf = y_ - L_y)

#old
    n_h_idx = n_x / 2

    z_nodes = n_h[:, :].flatten()
#    y_nodes = n_i[:, 0] # + list(n_v[:, :].flatten())
    y_nodes = n_i[0, 0] # + list(n_v[:, :].flatten())


    cp.cf_lst = [(face_y_L2, [n_i[0, 0]]),
                    (face_z_t, z_nodes),
##                    (face_x_L2, n_h[2, (0, -1)].flatten()),
#                    (face_x_L2, n_h[n_h_idx, (0, -1)].flatten()),
                    (face_x_L2, n_h[n_h_idx, :].flatten()),
                    ]



    return cp
Ejemplo n.º 11
0
def create_cp_fc_02(L_x = 4, L_y = 4, n_x = 2, n_y = 2, z0_ratio = 0.1,
                     n_steps = 100):
    '''Create scalable rhombus crease pattern with face constraints
       One basic element with general formulation (extension in y-direction variabel)
       (extension in x-direction has to be adepted manually)
    '''
    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              z0_ratio = z0_ratio,
                              MAX_ITER = 50)

    n_h = cp.N_h
    n_v = cp.N_v
    n_i = cp.N_i


    n_h_idx = n_x / 2
    n_h_idx = n_x / 2


    y_links = []
    for n_arr in n_h[0:3, :].T:
        for idx, n in enumerate(n_arr[1:]):
            n_x = len(n_arr)
            y_links.append([(n_arr[0], 1, 1.0), (n, 1, -1.0)])

    '''
    Extension in x-direction
    '''
    #y_links.append([(n_h[0,0], 1, 1.0), (n_h[-1,0], 1, -1.0)])
    #y_links.append([(n_h[0,0], 1, 1.0), (n_h[-2,0], 1, -1.0)])

    y_links.append([(n_h[0, -1], 1, 1.0)])
    y_links.append([(n_h[1, 0], 0, 1.0)])


    cp.cnstr_lhs = y_links

    print "n_h[1, 0]", n_h[1, 0]
    print "n_h[-1,-1]", n_h[-1, 0]
    print "n_h[1, -1]", n_h[1, -1]
    print "n_h[-1,-1]", n_h[-1, -1]

    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)

    print "cnstr_lhs", cp.cnstr_lhs
    print "cnstr_rhs", cp.cnstr_rhs

    A = 0.2

    face_z_t = CF(Rf = z_ - 4 * A * t_ * x_ * (1 - x_ / L_x))


    cp.cf_lst = [(face_z_t, n_h[1:-1, 0]),
                    (face_z_t, n_h[0, :]),
                    (face_z_t, n_h[-1, :])
                    ]



    print "edge1", n_h[0, :]
    print "edge2", n_h[-1, :]
    print "center", n_h[1:-1, 0]
    return cp
Ejemplo n.º 12
0
def rhombus_3x2_grab_points_for_crane(n_steps = 10, dx = 1.5):
    """
        This example shows a 3x2 rhombus creasepattern.

    """
    cpr = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = 3,
                              L_y = 2,
                              n_x = 3,
                              n_y = 4,
                              MAX_ITER = 500)

    X_rcp = cpr.generate_X0()
    X_rcp = X_rcp.reshape((-1, 3))
    X_rcp[:, 2] += 0.15
    print 'X_rcp', X_rcp

    cp = CreasePattern(n_steps = n_steps, MAX_ITER = 500)

    cp.nodes = cpr.nodes

    cp.crease_lines = cpr.crease_lines

    cp.facets = cpr.facets

    grab_nodes = [[0.5, 0.333, 0], #22
                  [0.5, 0.667, 0],
                  [0.5, 1.333, 0],
                  [0.5, 1.667, 0],
                  [1.5, 0.333, 0],
                  [1.5, 0.667, 0],
                  [1.5, 1.333, 0],
                  [1.5, 1.667, 0],
                  [2.5, 0.333, 0],
                  [2.5, 0.666, 0],
                  [2.5, 1.333, 0],
                  [2.5, 1.667, 0]]

    cp.nodes = np.vstack([cp.nodes, grab_nodes])

    cp.grab_pts = [
                   [22, 0],
                   [23, 14],
                   [26, 2],
                   [27, 16],
                   [30, 4],
                   [31, 18],
                   [24, 1],
                   [25, 15],
                   [28, 3],
                   [29, 17],
                   [32, 5],
                   [33, 19]
                   ]

    cp.cnstr_lhs = [[(12, 2, 1.0)],
                    [(13, 2, 1.0)],
                    [(14, 2, 1.0)],
                    [(15, 2, 1.0)],
                    [(1, 1, 1.0)],
                    [(18, 0, 1.0)],

                    [(26, 2, 1.0)],
                    [(22, 1, 1.0), (26, 1, -1.0)],
                    [(26, 1, 1.0), (30, 1, -1.0)],
                    [(23, 1, 1.0), (27, 1, -1.0)],
                    [(5, 2, 1.0), (8, 2, -1.0)],
                    [(24, 1, 1.0), (28, 1, -1.0)],
                    [(28, 1, 1.0), (32, 1, -1.0)],
                    [(25, 1, 1.0), (29, 1, -1.0)],
                    [(3, 2, 1.0), (6, 2, -1.0)],
                    [(22, 2, 1.0), (30, 2, -1.0)],
                    [(29, 1, 1.0), (33, 1, -1.0)]

                    ]

    cp.cnstr_rhs = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, dx, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]


    X_ext = np.zeros((cp.n_g * cp.n_d,), dtype = float)
    X0 = np.hstack([X_rcp.reshape((-1,)), X_ext])

    X0[68] = 0.3059
    X0[71] = 0.3059
    X0[74] = 0.3059
    X0[77] = 0.3059
    X0[80] = 0.4389
    X0[83] = 0.4389
    X0[86] = 0.4389
    X0[89] = 0.4389
    X0[92] = 0.3059
    X0[95] = 0.3059
    X0[98] = 0.3059
    X0[101] = 0.3059

    X0 *= 0.01
    print 'G_du', cp.get_G_du(X0)
    print 'R', cp.get_G(X0)

    print 'n_dofs', cp.n_dofs
    print 'n_c', cp.n_c
    print 'n_g', cp.n_g
    print 'necessary constraints', cp.n_dofs - cp.n_c - cp.n_g * cp.n_d
    print 'cnstr', len(cp.cnstr_lhs)
    #cp.show_iter = True    
    X = cp.solve(X0)
    return cp
Ejemplo n.º 13
0
def rhombus_3x3_crane(n_steps = 10, dx = 0.7):
    """
        This example shows a 3x2 rhombus creasepattern.

    """
    cpr = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = 3,
                              L_y = 3,
                              n_x = 3,
                              n_y = 6,
                              MAX_ITER = 5000)

    X_rcp = cpr.generate_X0()
    X_rcp = X_rcp.reshape((-1, 3))
    X_rcp[:, 2] += -0.1559

    cp = CreasePattern(n_steps = n_steps, MAX_ITER = 500)

    cp.nodes = cpr.nodes

    cp.crease_lines = cpr.crease_lines

    cp.facets = cpr.facets

    grab_nodes = [[0.5, 0.333, 0], #31
                  [0.5, 0.667, 0],
                  [0.5, 1.333, 0],
                  [0.5, 1.667, 0],
                  [0.5, 2.333, 0], #35
                  [0.5, 2.667, 0],
                  [1.5, 0.333, 0],
                  [1.5, 0.667, 0],
                  [1.5, 1.333, 0],
                  [1.5, 1.667, 0],
                  [1.5, 2.333, 0],
                  [1.5, 2.667, 0],
                  [2.5, 0.333, 0],
                  [2.5, 0.667, 0],
                  [2.5, 1.333, 0], #45
                  [2.5, 1.667, 0],
                  [2.5, 2.333, 0],
                  [2.5, 2.667, 0]]#48



    cp.nodes = np.vstack([cp.nodes, grab_nodes])





    cp.grab_pts = [[31, 0],
                   [32, 21],
                   [33, 1],
                   [34, 22],
                   [35, 2],
                   [36, 23],
                   [37, 3],
                   [38, 24],
                   [39, 4],
                   [40, 25],
                   [41, 5],
                   [42, 26],
                   [43, 6],
                   [44, 27],
                   [45, 7],
                   [46, 28],
                   [47, 8],
                   [48, 29]
                   ]




    cnstr_lhs_3 = [[(31, 1, 1.0)],
                   [(31, 1, 1.0), (36, 1, 1.0)],
                   [(16, 2, 1.0)],
                   [(17, 2, 1.0)],
                   [(18, 2, 1.0)],
                   [(19, 2, 1.0)],
                   [(20, 2, 1.0)],
                   [(21, 2, 1.0)],
                   [(17, 1, 1.0)],
                   [(20, 1, 1.0)],
                   [(20, 0, 1.0)],
                   [(37, 1, 1.0), (42, 1, 1.0)],
                   [(31, 2, 1.0), (36, 2, -1.0)],
                   [(37, 2, 1.0), (42, 2, -1.0)],
                   [(43, 1, 1.0), (48, 1, 1.0)],
                   [(43, 2, 1.0), (48, 2, 1.0)],
                   [(33, 1, 1.0), (34, 1, 1.0)],
                   [(39, 1, 1.0), (40, 1, 1.0)],
                   [(45, 1, 1.0), (46, 1, 1.0)],
                   [(19, 0, 1.0), (21, 0, -1.0)],
                   [(1, 2, 1.0), (2, 0, -1.0)]

                    ]
    cp.cnstr_lhs = cnstr_lhs_3

    cp.cnstr_rhs = np.zeros((cp.n_dofs,))
    cp.cnstr_rhs[0] = dx


    X_ext = np.zeros((cp.n_dofs - len(X_rcp.reshape((-1,))),), dtype = float)
    X0 = np.hstack([X_rcp.reshape((-1,)), X_ext])








    X0 *= 0.1
    #np.set_printoptions(threshold='nan')
    print 'dR', cp.get_dR(X0)
    print 'R', cp.get_R(X0)

    cp.set_next_node(X0)

    print 'L_vct', cp.grab_pts_L
    print 'n_dofs', cp.n_dofs
    print 'n_c', cp.n_c
    print 'n_g', cp.n_g
    print 'necessary constraints', cp.n_dofs - cp.n_c - cp.n_g * 3 - cp.n_l * 2
    print 'cnstr', len(cp.cnstr_lhs)

    cp.show_iter = True
    X = cp.solve(X0)
    return cp
# own Modules
from oricrete.folding import \
    YoshimuraCreasePattern, CreasePatternView, x_

from oricrete.folding.cnstr_target_face import \
    CnstrTargetFace, r_, s_, t_


if __name__ == '__main__':

    L_x = 2.42
    L_y = 3.01
    cp = YoshimuraCreasePattern(n_steps=8,
                                L_x=L_x,
                                L_y=L_y,
                                n_x=3,
                                n_y=20,
                                show_iter=False,
                                z0_ratio=0.1,
                                MAX_ITER=100)
    n_h = cp.N_h
    n_v = cp.N_v
    n_i = cp.N_i

    A = 0.1

    B = 0.05

    s_term = 4 * B * t_ * s_ * (1 - s_ / L_y)  # * r_ / L_x

    face_z_t = CnstrTargetFace(
        F=[r_, s_, 4 * A * t_ * r_ * (1 - r_ / L_x) - s_term])
Ejemplo n.º 15
0
def rhombus_3x3_crane(n_steps = 10, dx = 0.7):
    """
        This example shows a 3x2 rhombus creasepattern.

    """
    cpr = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = 3,
                              L_y = 3,
                              n_x = 3,
                              n_y = 6,
                              MAX_ITER = 5000)

    X_rcp = cpr.generate_X0()
    X_rcp = X_rcp.reshape((-1, 3))
    X_rcp[:, 2] += -0.1559

    cp = CreasePattern(n_steps = n_steps, MAX_ITER = 500)

    cp.nodes = cpr.nodes

    cp.crease_lines = cpr.crease_lines

    cp.facets = cpr.facets

    grab_nodes = [[0.5, 0.333, 0], #31
                  [0.5, 0.667, 0],
                  [0.5, 1.333, 0],
                  [0.5, 1.667, 0],
                  [0.5, 2.333, 0], #35
                  [0.5, 2.667, 0],
                  [1.5, 0.333, 0],
                  [1.5, 0.667, 0],
                  [1.5, 1.333, 0],
                  [1.5, 1.667, 0],
                  [1.5, 2.333, 0],
                  [1.5, 2.667, 0],
                  [2.5, 0.333, 0],
                  [2.5, 0.667, 0],
                  [2.5, 1.333, 0], #45
                  [2.5, 1.667, 0],
                  [2.5, 2.333, 0],
                  [2.5, 2.667, 0]]#48

    crane_nodes = [[1.5, 0.5, 1.0], #49
                   [0.5, 0.5, 1],
                   [2.5, 0.5, 1],
                   [0.5, 0.333, 1.0],
                   [0.5, 0.667, 1.0],
                   [2.5, 0.333, 1.0],
                   [2.5, 0.667, 1.0], #55
                   [1.5, 0.333, 1.0],
                   [1.5, 0.667, 1.0],

                   [1.5, 1.5, 1.0],
                   [0.5, 1.5, 1],
                   [2.5, 1.5, 1], #60
                   [0.5, 1.333, 1.0],
                   [0.5, 1.667, 1.0],
                   [2.5, 1.333, 1.0],
                   [2.5, 1.667, 1.0],
                   [1.5, 1.333, 1.0], #65
                   [1.5, 1.667, 1.0],

                   [1.5, 2.5, 1.0],
                   [0.5, 2.5, 1],
                   [2.5, 2.5, 1],
                   [0.5, 2.333, 1.0], #70
                   [0.5, 2.667, 1.0],
                   [2.5, 2.333, 1.0],
                   [2.5, 2.667, 1.0],
                   [1.5, 2.333, 1.0],
                   [1.5, 2.667, 1.0], #75
                   ]

    cp.nodes = np.vstack([cp.nodes, grab_nodes])
    cp.nodes = np.vstack([cp.nodes, crane_nodes])


    crane_cl = [#crane 1
                [49, 50], #72
                [49, 51],
                [50, 52],
                [50, 53],
                [51, 54],
                [51, 55],
                [49, 56],
                [49, 57],

                [52, 31],
                [53, 32],
                [54, 43],
                [55, 44],
                [56, 37],
                [57, 38],
                #crane 2
                [58, 59],
                [58, 60],
                [59, 61],
                [59, 62],
                [60, 63],
                [60, 64],
                [58, 65],
                [58, 66],

                [61, 33],
                [62, 34],
                [63, 45],
                [64, 46],
                [65, 39],
                [66, 40],

                #crane 3
                [67, 68],
                [67, 69],
                [68, 70],
                [68, 71],
                [69, 72],
                [69, 73],
                [67, 74],
                [67, 75],

                [70, 35],
                [71, 36],
                [72, 47],
                [73, 48],
                [74, 41],
                [75, 42],

                ]

    cp.crease_lines = np.vstack([cp.crease_lines, crane_cl])

    cp.grab_pts = [[31, 0],
                   [32, 21],
                   [33, 1],
                   [34, 22],
                   [35, 2],
                   [36, 23],
                   [37, 3],
                   [38, 24],
                   [39, 4],
                   [40, 25],
                   [41, 5],
                   [42, 26],
                   [43, 6],
                   [44, 27],
                   [45, 7],
                   [46, 28],
                   [47, 8],
                   [48, 29]
                   ]




    cnstr_lhs_3 = [[(49, 2, 1.0)],
                    [(49, 0, 1.0)],
                    [(49, 1, 1.0), (67, 1, 1.0)],
                    [(49, 2, 1.0), (58, 2, -1.0)],
                    [(49, 2, 1.0), (67, 2, -1.0)],
                    [(49, 2, 1.0), (56, 2, -1.0)],
                    [(49, 2, 1.0), (57, 2, -1.0)],
                    [(49, 0, 1.0), (56, 0, -1.0)],
                    [(49, 0, 1.0), (57, 0, -1.0)],
                    [(50, 2, 1.0), (52, 2, -1.0)],
                    [(50, 2, 1.0), (53, 2, -1.0)],
                    [(50, 0, 1.0), (52, 0, -1.0)],
                    [(50, 0, 1.0), (53, 0, -1.0)],
                    [(51, 2, 1.0), (54, 2, -1.0)],
                    [(51, 2, 1.0), (55, 2, -1.0)],
                    [(51, 0, 1.0), (54, 0, -1.0)],
                    [(51, 0, 1.0), (55, 0, -1.0)],
                    [(50, 2, 1.0)],
                    [(51, 2, 1.0)],
                    [(50, 1, 1.0), (49, 1, -1.0)],
                    [(51, 1, 1.0), (49, 1, -1.0)],

                    [(58, 0, 1.0)],
                    [(58, 2, 1.0), (65, 2, -1.0)],
                    [(58, 2, 1.0), (66, 2, -1.0)],
                    [(58, 0, 1.0), (65, 0, -1.0)],
                    [(58, 0, 1.0), (66, 0, -1.0)],
                    [(59, 2, 1.0), (61, 2, -1.0)],
                    [(59, 2, 1.0), (62, 2, -1.0)],
                    [(59, 0, 1.0), (61, 0, -1.0)],
                    [(59, 0, 1.0), (62, 0, -1.0)],
                    [(60, 2, 1.0), (63, 2, -1.0)],
                    [(60, 2, 1.0), (64, 2, -1.0)],
                    [(60, 0, 1.0), (63, 0, -1.0)],
                    [(60, 0, 1.0), (64, 0, -1.0)],
                    [(59, 2, 1.0)],
                    [(60, 2, 1.0)],
                    [(59, 1, 1.0)],
                    [(60, 1, 1.0)],
                    [(58, 1, 1.0)],

                    [(67, 0, 1.0)],
                    [(67, 2, 1.0), (74, 2, -1.0)],
                    [(67, 2, 1.0), (75, 2, -1.0)],
                    [(67, 0, 1.0), (74, 0, -1.0)],
                    [(67, 0, 1.0), (75, 0, -1.0)],
                    [(68, 2, 1.0), (70, 2, -1.0)],
                    [(68, 2, 1.0), (71, 2, -1.0)],
                    [(68, 0, 1.0), (70, 0, -1.0)],
                    [(68, 0, 1.0), (71, 0, -1.0)],
                    [(69, 2, 1.0), (72, 2, -1.0)],
                    [(69, 2, 1.0), (73, 2, -1.0)],
                    [(69, 0, 1.0), (72, 0, -1.0)],
                    [(69, 0, 1.0), (73, 0, -1.0)],
                    [(68, 2, 1.0)],
                    [(69, 2, 1.0)],
                    [(67, 1, 1.0), (27, 1, -1.0)],
                    [(68, 1, 1.0), (67, 1, -1.0)],
                    [(69, 1, 1.0), (67, 1, -1.0)],

                    #[(35, 1, 1.0), (12, 1, -1.0)],
                    #[(46, 1, 1.0), (13, 1, -1.0)],
                    #[(35, 1, 1.0), (46, 1, 1.0)],
                    #[(36, 1, 1.0), (47, 1, 1.0)],

                    [(25, 0, 1.0)],
                    [(17, 1, 1.0)],
                    #[(10, 1, 1.0)],
                    #[(37, 2, 1.0), (48, 2, -1.0)],
                    #[(26, 1, 1.0), (30, 1, -1.0)],
                    #[(0, 1, 1.0), (3, 1, -1.0)],
                    #[(37, 2, 1.0), (38, 2, -1.0)],
                    #[(29, 1, 1.0), (33, 1, -1.0)],
                    #[(31, 1, 1.0), (37, 1, -1.0)],
                    #[(7, 2, 1.0), (11, 2, -1.0)],
                    #[(22, 0, 1.0), (24, 0, -1.0)],
                    #[(38, 0, 1.0), (49, 0, -1.0)],
                    #[(48, 2, 1.0), (49, 2, -1.0)],
                    #[(3, 2, 1.0), (6, 2, -1.0)],
                    #[(24, 1, 1.0), (28, 1, -1.0)],
                    #[(27, 1, 1.0), (31, 1, -1.0)],
                    [(4, 2, 1.0), (8, 2, -1.0)],
                    #[(3, 1, 1.0), (6, 1, -1.0)],
                    #[(5, 2, 1.0), (8, 2, -1.0)],
                    #[(30, 0, 1.0), (31, 0, -1.0)]
                    #[(30, 0, 1.0), (31, 0, -1.0)],
                    #[(31, 0, 1.0), (32, 0, -1.0)]
#                    [(12, 2, 1.0)],
#                    [(13, 0, 1.0)],
#                    [(14, 2, 1.0)],
#                    [(15, 2, 1.0)]
                    ]
    cp.cnstr_lhs = cnstr_lhs_3

    cp.cnstr_rhs = np.zeros((cp.n_dofs,))
    cp.cnstr_rhs[0] = dx


    X_ext = np.zeros((cp.n_dofs - len(X_rcp.reshape((-1,))),), dtype = float)
    X0 = np.hstack([X_rcp.reshape((-1,)), X_ext])


    X0[113] = 0.1441
    X0[116] = 0.1441
    X0[119] = 0.1441
    X0[122] = 0.1441
    X0[125] = 0.1441
    X0[128] = 0.1441

    X0[149] = 0.1441
    X0[176] = 0.1441
    X0[203] = 0.1441
    #X0[131] = 0.45
    #X0[152] = 0.1441
    #X0[155] = 0.1441

   # X0[132] = 0.1441
    #X0[135] = -0.1441


    cp.create_rcp_tex(name = 'rcp_x3_y3.tex')

    X0 *= 0.1
    #np.set_printoptions(threshold='nan')
    print 'G_du', cp.get_G_du(X0)
    print 'R', cp.get_G(X0)

    print 'n_dofs', cp.n_dofs
    print 'n_c', cp.n_c
    print 'n_g', cp.n_g
    print 'necessary constraints', cp.n_dofs - cp.n_c - cp.n_g * 3 - cp.n_l * 2
    print 'cnstr', len(cp.cnstr_lhs)

    #cp.show_iter = True    
    X = cp.solve(X0)
    return cp
def create_cp_fc_inclined(L_x = 4, L_y = 4, n_x = 1, n_y = 2,
         n_steps = 100):
    '''Create scalable rhombus crease pattern with face constraints
    '''
    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              MAX_ITER = 2000)

    n_h = cp.N_h
    n_i = cp.N_i
    n_v = cp.N_v
    n_h_idx = n_y / 4

    x_links = []
    y_links = []
    z_links = []

#    for n_arr in n_h[:, (-1,)].T:
#        for idx, n in enumerate(n_arr[1:]):
#            y_links.append([(n_arr[0], 1, 1.0), (n, 1, -1.0)])

#    for n in n_v[-1, 1:]:
#        x_links.append([(n_v[-1, 0], 0, 1.0), (n, 0, -1.0)])

#    for n0, n1 in zip(n_v[0, :], n_v[-1, :]):
#        z_links.append([(n0, 2, 1.0), (n1, 2, -1.0)])
#        y_links.append([(n0, 1, 1.0), (n1, 1, -1.0)])

    #cntrl = [[(n_h[-1, -1], 1, 1.0)]]
    #cntrl = [[(n_h[-1, 1], 0, 1.0)]]

    cp.cnstr_lhs = x_links + y_links + z_links # + cntrl
    #cp.cnstr_lhs = z_cnstr

    # lift node 0 in z-axes
    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)
    #cp.cnstr_rhs[-1] = -L_x * 0.34

#    face_z_0 = CF(Rf = z_ - (1 - x_ / L_x) * 0.2 * t_)
    face_z_0 = CF(Rf = z_ - 0)
    face_x_0 = CF(Rf = x_ - 0)
#    face_x_L = CF(Rf = x_ - L_x * (1 - 0.2 * t_))
#    face_y_0 = CF(Rf = y_ - 0)
#    face_y_L = CF(Rf = y_ - L_y * (1 - 0.1 * t_))
#parallel movement bothsided
    face_y_0 = CF(Rf = y_ - L_y * (0.05 * t_))# * x_ / L_x)
    face_y_L = CF(Rf = y_ - L_y * (1 - 0.05 * t_))# * x_ / L_x)

#parallel movement: one side inclined
#    face_y_0 = CF(Rf = y_ - L_y / 2.0 * (0.1 * t_) * x_ / L_x)
#    face_y_L = CF(Rf = y_ - L_y * (1 - 0.05 * t_))# * x_ / L_x)

#one side inclined, other side fixed
#    face_y_0 = CF(Rf = y_ - 0)
#    face_y_L = CF(Rf = y_ - L_y  + L_y * 0.1 * t_* x_ / L_x)

##symmetric inclined along x
#    face_y_0 = CF(Rf = y_ - L_y / 2.0 * 0.1 * t_ * x_ / L_x)
#    face_y_L = CF(Rf = y_ - L_y + L_y / 2.0 * 0.1 * t_ * x_ / L_x)
#
##symmetric inclined along both x and y
#    face_y_0 = CF(Rf = y_ - L_y / 2.0 * 0.05 * t_ * y_ / L_y)
#    face_y_L = CF(Rf = y_ - L_y + L_y / 2.0 * 0.05 * t_ * y_ / L_y)

#    cp.cf_lst = [(face_x_0, n_h[0, :]),
#                    (face_z_0, n_h[0, :]),
#                    (face_y_0, n_h[:, 0]),
#                    (face_y_L, n_h[:, -1])]

    z_nodes = n_h[:, :].flatten()
    print z_nodes
    cp.cf_lst = [(face_x_0, [n_h[0, 0]]),
                    (face_z_0, z_nodes),
                    (face_y_0, n_h[:, 0]),
                    (face_y_L, n_h[:, -1])]

    return cp
def create_cp_dc(L_x = 4, L_y = 4, n_x = 1, n_y = 2,
         n_steps = 100):
    '''Create scalable rhombus crease pattern with dof_constraints
    '''
    cp = YoshimuraCreasePattern(n_steps = n_steps,
                              L_x = L_x,
                              L_y = L_y,
                              n_x = n_x,
                              n_y = n_y,
                              show_iter = False,
                              MAX_ITER = 500)

    n_h = cp.N_h
    n_i = cp.N_i
    n_v = cp.N_v
    n_h_idx = n_y / 4

    x_links = []
    y_links = []
    z_links = []

    z_nodes = n_h[(0, 0, -1, -1), (0, -1, -1, 0)].flatten()
    print 'z_nodes', z_nodes

    #z_cnstr = [[(n, 2, 1.0)] for n in z_nodes]
    x_cnstr = [[(n_h[0, 0], 0, 1.0)]]
    y_cnstr = [[(n_h[0, 0], 1, 1.0)]]
    z_cnstr = [[(n_h[0, 0], 2, 1.0)]]

    for n_arr in n_h[:, (0, -1)].T:
        for idx, n in enumerate(n_arr[1:]):
            n_x = len(n_arr)
            y_links.append([(n_arr[0], 1, 1.0), (n, 1, -1.0)])

    for n in n_h[0, 1:]:
        z_links.append([(n_h[0, 0], 2, 1.0), (n, 2, -1.0)])
        x_links.append([(n_h[0, 0], 0, 1.0), (n, 0, -1.0)])
    #x_links.append([(n_h[0, -1], 0, 1.0), (n_h[0, -1], 1, -0.5)])

    for n in n_v[-1, 1:]:
        x_links.append([(n_v[-1, 0], 0, 1.0), (n, 0, -1.0)])

    for n0, n1 in zip(n_v[0, :], n_v[-1, :]):
        z_links.append([(n0, 2, 1.0), (n1, 2, -1.0)])

    #cntrl = [[(n_h[-1, -1], 1, 1.0)]]
    cntrl = [[(n_h[-1, 1], 0, 1.0)]]

    print 'x_cnstr', len(x_cnstr)
    print 'y_cnstr', len(y_cnstr)
    print 'z_cnstr', len(z_cnstr)
    print 'x_links', len(x_links)
    print 'y_links', len(y_links)
    print 'z_links', len(z_links)

    cp.cnstr_lhs = z_cnstr + x_links + y_links + z_links + x_cnstr + y_cnstr + cntrl
    #cp.cnstr_lhs = z_cnstr

    # lift node 0 in z-axes
    cp.cnstr_rhs = np.zeros((len(cp.cnstr_lhs),), dtype = float)
    cp.cnstr_rhs[-1] = -L_x * 0.34

#    cp.cnstr_rhs[-1] = -L_y * 0.9999

    return cp
        fn_x = sm.lambdify([x_], fn.subs(abc_subs))

#        y2 = ((x - Lx / 2) / Lx / 2) * fn_x(y)
#        x2 = ((x - Lx / 2) / Lx / 2) * fn_x(x)

        return np.c_[x, y, z]

if __name__ == '__main__':

    L_x = 1.4
    L_y = 0.8
    cp = YoshimuraCreasePattern(n_steps=5,
                              L_x=L_x,
                              L_y=L_y,
                              n_x=4,
                              n_y=4,
                              #geo_transform = GT(L_x = L_x, L_y = L_y),
                              show_iter=False,
                              z0_ratio=0.1,
                              MAX_ITER=100)
    n_h = cp.N_h
    n_v = cp.N_v
    n_i = cp.N_i

    face_z_t = CnstrTargetFace(F=[r_, s_, 1.7 * t_ * (r_ * (1 - r_ / L_x))]) #- s_ / 8 * (1 - s_ / L_y))])
    n_arr = np.hstack([n_h[::, (0, 2)].flatten(),
                       n_h[(0, 1, 3, 4), 1].flatten(),
     #                  n_v[:, :].flatten(),
                       n_i[1:-1, :].flatten()
                       ])
    cp.tf_lst = [(face_z_t, n_arr)]
# own Modules
from oricrete.folding import YoshimuraCreasePattern, CreasePattern, CreasePatternView

from oricrete.folding.cnstr_target_face import CnstrTargetFace, r_, s_, t_

from oricrete.folding.equality_constraint import EqConsDevelopability

if __name__ == "__main__":

    n_x = 3
    n_y = 8
    L_x = 49.7
    L_y = 31.0
    cp = YoshimuraCreasePattern(
        n_steps=1, L_x=L_x, L_y=L_y, n_x=n_x, n_y=n_y, show_iter=False, z0_ratio=0.1, MAX_ITER=100
    )
    n_h = cp.N_h
    n_v = cp.N_v
    n_i = cp.N_i

    A = 0.4

    B = 1.0

    s_term = A * t_ * s_ * (1 - s_ / L_y)  # * r_ / L_x

    face_z_t = CnstrTargetFace(F=[r_, s_, t_ * (B * r_ * (1 - r_ / L_x) - s_term)])
    n_arr = np.hstack(
        [
            n_h[:, :].flatten(),