def cp_t3(self):

        # ------------------------------------------------------------------------------
        # test 6 triangles (standard pattern)
        # 7 nodes
        # 12 creaselines
        # 3 * 7 - 12 constrains needed
        # ------------------------------------------------------------------------------

        cp = CreasePattern()

        cp.nodes = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [-1, 1, 0], [-1, 0, 0], [-1, -1, 0], [1, -1, 0]]

        cp.crease_lines = [
            [0, 1],
            [1, 2],
            [2, 0],
            [2, 3],
            [3, 0],
            [3, 4],
            [4, 0],
            [4, 5],
            [5, 0],
            [5, 6],
            [6, 0],
            [6, 1],
        ]

        cp.constraints = [[0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [4, 1], [2, 0], [6, 0], [4, 2]]

        # lift node 0 in z-axes
        cp.constraint_values = [0, 0.5, 0, 0, 0, 0, 0, 0, 0]

        X = np.zeros((cp.n_dofs,), dtype=float)

        print "initial lengths\n", cp.c_lengths
        print "initial vectors\n", cp.c_vectors

        print "initial R\n", cp.get_R(X)
        print "initial dR\n", cp.get_dR(X)

        print "constrained dofs\n", cp.cnstr_dofs
        print "free dofs\n", cp.free_dofs

        # Newton-Raphson iteration
        MAX_ITER = 150
        TOLERANCE = 1e-10
        n_steps = 8
        cv = np.copy(cp.constraint_values)

        for k in range(n_steps):
            print "step", k
            cp.constraint_values = (k + 1.0) / float(n_steps) * cv
            for i in range(MAX_ITER):
                dR = cp.get_dR(X)[:, cp.free_dofs]
                print "dR", dR.shape
                R = cp.get_R(X)
                if np.linalg.norm(R) < TOLERANCE:
                    print "==== converged in ", i, "iterations ===="
                    break
                dX = np.linalg.solve(dR, -R)
                X[cp.free_dofs] += dX
            cp.set_next_node(X)

        print "========== results =============="
        print "solution X\n", X
        print "final positions\n", cp.get_new_nodes(X)
        print "final vectors\n", cp.get_new_vectors(X)
        print "final lengths\n", cp.get_new_lengths(X)

        # initialise View
        from crease_pattern_view import CreasePatternView

        my_model = CreasePatternView(data=cp)
        print my_model.data.iteration_nodes.shape

        my_model.configure_traits()
Exemplo n.º 2
0
#    X[1] = 0.01
#    X[0] = 0.01


    print 'initial lengths\n', cp.c_lengths
    print 'initial vectors\n', cp.c_vectors

    print 'initial R\n', cp.get_R(X)
    print 'initial dR\n', cp.get_dR(X)

    X = cp.solve_ff(X)

    print '========== results =============='
    print 'solution X\n', X
    print 'final positions\n', cp.get_new_nodes(X)
    print 'final vectors\n', cp.get_new_vectors(X)
    print 'final lengths\n', cp.get_new_lengths(X)

    return cp



if __name__ == '__main__':
#    cp = moving_truss_cp_circle(n_steps = 10, dx = -1.99)
#    cp = moving_truss_cp_ff_cnstr(n_steps = 40)
    cp = triangle_cp_cnstr(n_steps = 40)

    # initialise View
    my_model = CreasePatternView(data = cp)
    my_model.configure_traits()
Exemplo n.º 3
0
                          [1, 3]],
                       F=[[0, 1, 3],
                          [1, 2, 3]])

    init = Initialization(cp=cp)
    init.U_0[5] = 0.05

    lift = Lifting(source=init, n_steps=10)
    print 'initial vector', lift.U_0

#    lift.TS = [[r_ , s_, 0.01 + t_ * (0.5)]]
    lift.CS = [[z_ - 4 * 0.4 * t_ * x_ * (1 - x_ / 3)]]
    lift.GP = [[4, 0]]
    lift.LP = [[5, 4],
               [6, 4]]
    lift.cf_lst = [(CF(Rf=lift.CS[0][0]), [1])]

    lift.cnstr_lhs = [[(0, 0, 1.0)],
                      [(0, 1, 1.0)],
                      [(0, 2, 1.0)],
                      [(3, 0, 1.0)],
                      [(3, 2, 1.0)],
                      [(2, 2, 1.0)],
                      [(5, 0, 1.0)],
                      [(6, 0, 1.0)]]
    lift.cnstr_rhs[0] = 0.9
    print lift.U_1
#
    v = CreasePatternView(reshaping_history=init)
    v.configure_traits()
Exemplo n.º 4
0
def rhombcp():

    cp = CreasePattern()

    cp.nodes = [[ 0, 0, 0 ],
                [ 2, 0, 0 ],
                [ 4, 0, 0 ],
                [ 0, 1, 0 ],
                [ 1, 1, 0 ],
                [ 3, 1, 0 ],
                [ 4, 1, 0]]

    cp.crease_lines = [[ 0, 1 ],
                       [ 1, 2 ],
                       [ 0, 3 ],
                       [ 2, 6 ],
                       [ 0, 4 ],
                       [ 1, 4 ],
                       [ 3, 4 ],
                       [ 5, 4 ],
                       [ 1, 5 ],
                       [ 2, 5 ],
                       [ 6, 5 ],
                        ]

    cp.constraints = [[3, 2],
                      [3, 1],
                      [4, 1],
                      [4, 2],
                      [5, 1],
                      [5, 2],
                      [6, 0],
                      [6, 1],
                      [6, 2],
                      [0, 2]]

    # lift node 0 in z-axes
    cp.constraint_values = np.zeros((10,), dtype = float)
    cp.constraint_values[3] = 0.4
    cp.constraint_values[5] = 0.4
    cp.constraint_values[8] = 0.0
    cp.constraint_values[9] = 0.0

    X = np.zeros((cp.n_dofs,), dtype = float)
    X[3] = 0.1
    X[5] = 0.1

    print 'initial lengths\n', cp.c_lengths
    print 'initial vectors\n', cp.c_vectors

    print 'initial R\n', cp.get_R(X)
    print 'initial dR\n', cp.get_dR(X)

    print 'constrained dofs\n', cp.cnstr_dofs
    print 'free dofs\n', cp.free_dofs

    # Newton-Raphson iteration
    MAX_ITER = 150
    TOLERANCE = 1e-10
    n_steps = 3
    cv = np.copy(cp.constraint_values)

    for k in range(n_steps):
        print 'step', k
        #cp.set_next_node(X)
        cp.constraint_values = (k + 1.) / float(n_steps) * cv
        i = 0
        while i in range(MAX_ITER):
            dR = cp.get_dR(X)[:, cp.free_dofs ]
            print 'dR', dR.shape
            R = cp.get_R(X)
            if np.linalg.norm(R) < TOLERANCE:
                print '==== converged in ', i, 'iterations ===='
                cp.set_next_node(X)
                break
            dX = np.linalg.solve(dR, -R)
            X[ cp.free_dofs ] += dX
            i += 1
        else:
            raise ValueError
            break


    print '========== results =============='
    print 'solution X\n', X
    print 'final positions\n', cp.get_new_nodes(X)
    print 'final vectors\n', cp.get_new_vectors(X)
    print 'final lengths\n', cp.get_new_lengths(X)

    # initialise View
    my_model = CreasePatternView(data = cp)

    my_model.configure_traits()
Exemplo n.º 5
0
 def show(self):
     from crease_pattern_view import \
         CreasePatternView
     cpv = CreasePatternView()
     cpv.data = self
     cpv.configure_traits()
                          [3, 0, 0],
                          [3, 1, 0]],
                       L=[[0, 1], [0, 2], [2, 3], [1, 3], [0, 3],
                          [2, 3], [2, 4], [4, 5], [3, 5], [2, 5],
                          [4, 5], [4, 6], [6, 7], [5, 7], [4, 7],
                          ],
                       F=[[0, 1, 2], [1, 2, 3],
                          [2, 3, 4], [3, 4, 5],
                          [4, 5, 6], [5, 6, 7]
                          ]
                       )

    init = Initialization(cp=cp)
    init.t_arr
    init.u_t[-1]

    fold = Folding(source=init, n_steps=1,
                   acc=1e-6, MAX_ITER=500,
                   )

    fold.u_t[-1]

    oc = OptCritPotentialEnergy(reshaping=init)

    u = np.zeros_like(cp.X)
    print 'f', oc.get_f(u)
    print 'f_du', oc.get_f_du(u)

    cpw = CreasePatternView(root=init)
    cpw.configure_traits()