Ejemplo n.º 1
0
def create_gu():
    cp = CreasePatternState(X=[[0, 0.5, -0.5],
                               [1, 0, 0],
                               [1, 1, 0],
                               [2, 0.5, -0.5],
                               ],
                            L=[[0, 1], [1, 2], [2, 0], [1, 3],
                               [2, 3]],
                            F=[[0, 1, 2], [1, 3, 2]]
                            )

    cp_factory = CustomCPFactory(formed_object=cp)

    # begin
    from oricreate.gu import GuPsiConstraints
    # Link the crease factory it with the constraint client
    gu_dof_constraints = \
        GuPsiConstraints(forming_task=cp_factory,
                         psi_constraints=[([(0, 1.0)], 0),
                                          ])
    cp = cp_factory.formed_object
    print(cp.iL)
    print(cp.iL_psi)
    print('gu:', gu_dof_constraints.get_G(1.0))
    print('g_du:\n', gu_dof_constraints.get_G_du(1.0))
    # end
    return gu_dof_constraints
Ejemplo n.º 2
0
def create_gu():
    cp = CreasePatternState(X=[[0, 0.5, -0.5],
                               [1, 0, 0],
                               [1, 1, 0],
                               [2, 0.5, -0.5],
                               ],
                            L=[[0, 1], [1, 2], [2, 0], [1, 3],
                               [2, 3]],
                            F=[[0, 1, 2], [1, 3, 2]]
                            )

    cp_factory = CustomCPFactory(formed_object=cp)

    # begin
    from oricreate.gu import GuPsiConstraints
    # Link the crease factory it with the constraint client
    gu_dof_constraints = \
        GuPsiConstraints(forming_task=cp_factory,
                         psi_constraints=[([(0, 1.0)], 0),
                                          ])
    cp = cp_factory.formed_object
    print cp.iL
    print cp.iL_psi
    print 'gu:', gu_dof_constraints.get_G(1.0)
    print 'g_du:\n', gu_dof_constraints.get_G_du(1.0)
    # end
    return gu_dof_constraints
    def _get_load_task(self):
        self.fold_task.x_1
        fat = self.factory_task

        fixed_corner_n = fat.N_grid[(0, 0, -1, -1), (1, -2, 1, -2)].flatten()
        fixed_n = fat.N_grid[(0, 0), (1, -2)].flatten()
        slide_z = fix(fat.N_grid[-1, -2], [2], lambda t: -0.8 * self.L_x * t)
        slide_x = fix(fat.N_grid[-1, -2], [0], lambda t: 0.1 * self.L_y * t)
        loaded_n = fat.N_grid[self.n_x / 2, self.n_y / 2]
        fixed_nodes_xyz = fix(fixed_n, (0, 2)) + slide_z
        #fixed_nodes_xyz = fix(fixed_corner_n, (0, 1, 2))

        dof_constraints = fixed_nodes_xyz
        gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
        gu_constant_length = GuConstantLength()

        diag_psi_mask = np.ones_like(fat.L_d_grid, dtype=np.bool_)
        diag_psi_mask[1:-1, 1:-1] = False
        diag_lines = fat.L_d_grid[diag_psi_mask].flatten()
        diag_psi_constraints = [([(i, 1.0)], 0) for i in diag_lines]
        gu_psi_constraints = \
            GuPsiConstraints(forming_task=fat,
                             psi_constraints=diag_psi_constraints)

        sim_config = SimulationConfig(
            goal_function_type='total potential energy',
            gu={
                'cl': gu_constant_length,
                'dofs': gu_dof_constraints,
                'psi': gu_psi_constraints
            },
            acc=1e-5,
            MAX_ITER=1000,
            debug_level=0)

        def FN(F):
            return lambda t: t * F

        P = 0.0 * 30.5 * self.load_factor
        F_ext_list = [(loaded_n, 2, FN(-P))]

        fu_tot_poteng = FuPotEngTotal(kappa=np.array([1.0]),
                                      F_ext_list=F_ext_list,
                                      thickness=1,
                                      exclude_lines=diag_lines)
        sim_config._fu = fu_tot_poteng
        st = SimulationTask(previous_task=self.fold_task,
                            config=sim_config,
                            n_steps=self.n_load_steps)
        fu_tot_poteng.forming_task = st
        cp = st.formed_object
        cp.x_0 = self.fold_task.x_1
        cp.u[:, :] = 0.0
        return st
    def _get_fold_task(self):
        # Link the crease factory it with the constraint client
        fat = self.factory_task
        gu_constant_length = GuConstantLength()
        nx2 = 1
        ny2 = 2
        dof_constraints = fix(fat.N_grid[nx2 - 1, ny2], [1]) \
            + fix(fat.N_grid[nx2, ny2], [0, 1, 2]) \
            + fix(fat.N_grid[nx2, (ny2 - 1, ny2 + 1)], [2])
        gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
        psi_max = np.pi * 0.4
        diag_psi_mask = np.ones_like(fat.L_d_grid, dtype=np.bool_)
        diag_psi_mask[1:-1, 1:-1] = False
        diag_psi_constraints = [([(i, 1.0)], 0)
                                for i in fat.L_d_grid[diag_psi_mask].flatten()]
        gu_psi_constraints = \
            GuPsiConstraints(forming_task=fat,
                             psi_constraints=diag_psi_constraints +
                             [([(fat.L_h_grid[nx2, ny2], 1.0)],
                               lambda t: psi_max * t),
                              ])

        sim_config = SimulationConfig(goal_function_type='none',
                                      gu={
                                          'cl': gu_constant_length,
                                          'dofs': gu_dof_constraints,
                                          'psi': gu_psi_constraints
                                      },
                                      acc=1e-8,
                                      MAX_ITER=200)
        sim_task = SimulationTask(previous_task=fat,
                                  config=sim_config,
                                  n_steps=20)

        cp = sim_task.formed_object
        cp.u[fat.N_grid[::2, :].flatten(), 2] = -0.1
        cp.u[fat.N_grid[0, ::2].flatten(), 2] = -0.2
        return sim_task
    cp.plot_mpl(ax, facets=True)
    plt.tight_layout()
    plt.show()

    # Link the crease factory it with the constraint client
    gu_constant_length = GuConstantLength()
    dof_constraints = fix(cpf.N_grid[0, 1], [1]) \
        + fix(cpf.N_grid[1, 1], [0, 1, 2]) \
        + fix(cpf.N_grid[1, (0, -1)], [2])
    gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
    psi_max = np.pi / 4.0
    diag_psi_constraints = [([(i, 1.0)], 0) for i in cpf.L_d_grid.flatten()]
    gu_psi_constraints = \
        GuPsiConstraints(forming_task=cpf,
                         psi_constraints=diag_psi_constraints +
                         [([(cpf.L_h_grid[1, 1], 1.0)],
                           lambda t: -psi_max * t),
                          ])

    sim_config = SimulationConfig(goal_function_type='none',
                                  gu={
                                      'cl': gu_constant_length,
                                      'dofs': gu_dof_constraints,
                                      'psi': gu_psi_constraints
                                  },
                                  acc=1e-5,
                                  MAX_ITER=10)
    sim_task = SimulationTask(previous_task=cpf, config=sim_config, n_steps=5)

    cp = sim_task.formed_object
    cp.u[cpf.N_grid[(0, -1), 1], 2] = -1.0
Ejemplo n.º 6
0
    import mayavi.mlab as m
    import pylab as p
    cp_factory_task = create_cp_factory()
    cp = cp_factory_task.formed_object
    ax = p.axes()
    cp.plot_mpl(ax)
    p.show()
    # Link the crease factory it with the constraint client
    gu_constant_length = GuConstantLength()
    dof_constraints = fix([0], [0, 1, 2]) + fix([1], [1, 2]) + fix([4], [2])
    gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
    psi_max = np.pi / 4.0
    gu_psi_constraints = \
        GuPsiConstraints(forming_task=cp_factory_task,
                         psi_constraints=[([(5, 1.0)], lambda t: psi_max * t),
                                          ([(7, 1.0)], 0),
                                          ([(8, 1.0)], 0),
                                          ])

    sim_config = SimulationConfig(gu={
        'cl': gu_constant_length,
        'dofs': gu_dof_constraints,
        'psi': gu_psi_constraints
    },
                                  acc=1e-5,
                                  MAX_ITER=10)
    sim_step = SimulationStep(forming_task=cp_factory_task, config=sim_config)

    sim_step._solve_nr()

    m.figure(bgcolor=(1.0, 1.0, 1.0), fgcolor=(0.6, 0.6, 0.6))
Ejemplo n.º 7
0
    cpf = create_cp_factory()
    cp = cpf.formed_object

    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    cp.plot_mpl(ax, facets=True)
    plt.tight_layout()
    plt.show()

    gu_constant_length = GuConstantLength()
    psi_max = np.pi / 4.0

    diag_psi_constraints = [([(i, 1.0)], 0) for i in cpf.L_d_grid.flatten()]
    gu_psi_constraints = \
        GuPsiConstraints(forming_task=cpf,
                         psi_constraints=diag_psi_constraints
                         )
    fu_psi_target_value = \
        FuTargetPsiValue(forming_task=cpf,
                         psi_value=(cpf.L_h_grid[1, 1], lambda t: -psi_max * t)
                         )
    hu_psi_constraints = \
        HuPsiConstraints(forming_task=cpf,
                         psi_constraints=[(cpf.L_h_grid[0, 1], True),
                                          (cpf.L_v_grid[1, 0], True),
                                          (cpf.L_v_grid[1, 1], True),
                                          ])
    sim_config = SimulationConfig(goal_function_type='total potential energy',
                                  gu={'cl': gu_constant_length,
                                      'psi': gu_psi_constraints},
                                  hu={'mv': hu_psi_constraints},