Example #1
0
    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
Example #2
0
 def _get_config(self):
     # Configure simulation
     gu_constant_length = GuConstantLength()
     dof_constraints = fix(
         [0], [0, 1, 2]) + fix([1], [1, 2]) + fix([5], [2]) + \
         fix([3], [0], lambda t: math.cos(math.pi * t) - 1)
     gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
     return SimulationConfig(goal_function_type='none',
                             gu={'cl': gu_constant_length,
                                 'dofs': gu_dof_constraints},
                             acc=1e-5, MAX_ITER=1000)
Example #3
0
 def _get_config(self):
     # Configure simulation
     gu_constant_length = GuConstantLength()
     dof_constraints = fix(
         [0], [0, 1, 2]) + fix([1], [1, 2]) + fix([5], [2]) + \
         fix([3], [0], lambda t: math.cos(math.pi * t) - 1)
     gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
     return SimulationConfig(goal_function_type='none',
                             gu={'cl': gu_constant_length,
                                 'dofs': gu_dof_constraints},
                             acc=1e-5, MAX_ITER=1000)
    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
Example #5
0
    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

if __name__ == '__main__':

    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()

    # 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,
    cpf = create_cp_factory()
    cp = cpf.formed_object

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

    # Link the crease factory it with the constraint client
    gu_constant_length = GuConstantLength()
    nx2 = 1
    ny2 = 2
    dof_constraints = fix(cpf.N_grid[nx2 - 1, ny2], [1]) \
        + fix(cpf.N_grid[nx2, ny2], [0, 1, 2]) \
        + fix(cpf.N_grid[nx2, (ny2 - 1, ny2 + 1)], [2])
    gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
    psi_max = np.pi * 0.498
    diag_psi_mask = np.ones_like(cpf.L_d_grid, dtype=np.bool_)
    diag_psi_mask[1:-1, 1:-1] = False
    diag_psi_constraints = [([(i, 1.0)], 0)
                            for i in cpf.L_d_grid[diag_psi_mask].flatten()]
    print('psi constraints', diag_psi_constraints)
    print('controlled line', cpf.L_h_grid[nx2, ny2])
    gu_psi_constraints = \
        GuPsiConstraints(forming_task=cpf,
                         psi_constraints=diag_psi_constraints +
                         [([(cpf.L_h_grid[nx2, ny2], 1.0)],
                           lambda t: psi_max * t),
Example #9
0
    # end
    return cp_factory


if __name__ == '__main__':

    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)
    # end
    return cp_factory


if __name__ == '__main__':

    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,
    cp_factory = CustomCPFactory(formed_object=cp)
    # end
    return cp_factory


if __name__ == '__main__':

    import mayavi.mlab as m

    cp_factory = create_cp_factory()
    cp = cp_factory.formed_object

    # 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([3], [2]) + \
        fix([5], 2, lambda t: 0.5)
    gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)

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

    sim_step._solve_nr()

    m.figure(bgcolor=(1.0, 1.0, 1.0), fgcolor=(0.6, 0.6, 0.6))
    cp.plot_mlab(m, nodes=True, lines=True)
Example #12
0
def run_sim():

    cp_factory, L_selection = create_cp_factory()
    cp = cp_factory.formed_object

    if False:
        fig, ax = plt.subplots()
        cp.plot_mpl(ax, facets=True)
        plt.tight_layout()
        plt.show()
        return

    # Configure simulation
    gu_constant_length = GuConstantLength()
    dof_constraints = \
        fix([0], [0, 1, 2]) +\
        fix([1], [1, 2]) +\
        fix([5], [2]) +\
        fix([3], [0], lambda t: t * -1.9599)
    gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
    sim_config = SimulationConfig(gu={'cl': gu_constant_length,
                                      'dofs': gu_dof_constraints},
                                  acc=1e-5, MAX_ITER=1000)
    sim_step = SimulationStep(forming_task=cp_factory,
                              config=sim_config)

    if False:
        # Configure rendering visualization operators
        eftlabels_viz3d = FacetsWithTextViz3D(
            label='EFT labels', vis3d=cp)
        efttitle_viz3d = FacetsWithImageViz3D(
            label='EFT title', vis3d=cp,
            F_ref=[0, 2, 4, 6, 8],
            N_ref=[0, 3, 15, 12, 7],
            F_covered=[[0, 9], [2, 11], [4, 13], [6, 15], [8, 17]],
            atimes=[90.0, 180.0, -90, 0, 135],
            im_files=['eft_01.png', 'eft_01.png',
                      'eft_01.png', 'eft_01.png', 'eft_01.png'],
            im_widths=[2, 2, 2, 2, 2],
            im_offsets=[[0, 0, 0.004], [0, 0, 0.004],
                        [0, 0, 0.004], [0, 0, 0.004],
                        [-.295, -.295, 0.004]],
        )
    else:
        fname_eft_front = 'eft_areas_standard_02.png'
        fname_eft_back = 'eft_mission_standard_trans_EF01.png'
        fheight = 0.011
        front_offset = 0.006
        tube_radius = 0.01
        plane_offsets = [0.005, -0.010]
        edge_len = 2.0
        x_offset = 1.0
        c45 = np.cos(np.pi / 4)
        shift_x = x_offset + edge_len / c45 - edge_len
        shift_l = shift_x * c45
        print 'shift_l', shift_l
        F_ref = [0, 2, 4, 6, 8, 16, 1, 12, 14, ]
        N_ref = [0, 3, 15, 12, 7, 4, 1, 11, 13]
        F_covered = [[0, 9], [2, 11], [4, 13], [6, 15],
                     [8, 17], [16, 7], [1, 10], [12, 3], [14, 5]]
        atimes = [90.0, 180.0, -90, 0, 45, 90, 90.0, -90.0, 0.0]
        im_widths = [4, 4, 4, 4, 4, 4, 4, 4, 4]
        imfiles_front = [
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
        ]
        imfiles_back = [
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
        ]
        im_front_offsets = [
            [0, 0, front_offset],
            [0, 0, front_offset],
            [0, 0, front_offset],
            [0, 0, front_offset],
            [-shift_l, -shift_l, front_offset],
            [0, -1, front_offset],
            [-2, 0, front_offset],
            [0, -1, front_offset],
            [0, -1, front_offset]
        ]
        im_back_offsets = [
            [0, 0, -fheight],
            [0, 0, -fheight],
            [0, 0, -fheight],
            [0, 0, -fheight],
            [-shift_l, -shift_l, -fheight],
            [0, -1, -fheight],
            [-2, 0, -fheight],
            [0, -1, -fheight],
            [0, -1, -fheight]
        ]
        efttitle_back_viz3d = FacetsWithImageViz3D(
            label='EFT back', vis3d=cp,
            F_ref=F_ref,  # + F_ref,
            N_ref=N_ref,  # + N_ref,
            F_covered=F_covered,  # + F_covered,
            atimes=atimes,  # + atimes,
            im_files=imfiles_back,  # imfiles_front +
            im_widths=im_widths,  # + im_widths,
            im_offsets=im_back_offsets,  # im_front_offsets +
        )
        efttitle_front_viz3d = FacetsWithImageViz3D(
            label='EFT front', vis3d=cp,
            F_ref=F_ref,
            N_ref=N_ref,
            F_covered=F_covered,
            atimes=atimes,
            im_files=imfiles_front,
            im_widths=im_widths,
            im_offsets=im_front_offsets
        )

    eftlogo_normals = CreasePatternNormalsViz3D(
        label='EFT normals', vis3d=cp)
    eftlogo_bases = CreasePatternBasesViz3D(
        label='EFT bases', vis3d=cp)
    eft_thick_viz3d = CreasePatternThickViz3D(
        label='EFT thick', vis3d=cp,
        plane_offsets=plane_offsets)
    cp.viz3d['cp'].set(tube_radius=tube_radius)

    # Configure scene
    ftv = FTV()
    ftv.add(cp.viz3d['cp'])
    ftv.add(eft_thick_viz3d)
    ftv.add(efttitle_front_viz3d)
    ftv.add(efttitle_back_viz3d)
    # ftv.add(eftlabels_viz3d)
    # ftv.add(eftlogo_normals)
    # ftv.add(eftlogo_bases)

    m = ftv.mlab
    m.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0))
    fig = m.gcf()

    ftv.plot()
#    oricreate_mlab_label(m)

    a, e, d, f = m.view()
    e = 135  # 10
    a = 270  # -45  # 120

    f = sim_step.forming_task.formed_object.center
    m.view(a, e, d, f)

    show = False
    if show:
        m.show()

    n_u = 30

    # Control the folding by a fold angle

    phi_range = np.linspace(0.01, np.pi - 0.01, n_u)

    dramaturgy = False
    animation = True

    def circular_folding(phi_range):
        bot_e = 160
        top_e = 10
        if dramaturgy:
            phi_unfolded = phi_range[0] * np.ones_like(phi_range)
            phi_folded = phi_range[-1] * np.ones_like(phi_range)
            phi_range_u = np.hstack(
                [phi_range, phi_folded, phi_range[::-1], phi_unfolded])
        else:
            phi_range_u = phi_range

        u_range = np.cos(phi_range_u) - 1
        phi_range_e = np.linspace(0.01, np.pi - 0.01, n_u * 4)
        azimuth_step = 360.0 / 4 / n_u
        elevation_range = np.cos(
            2 * phi_range_e)**2 * top_e + np.sin(2 * phi_range_e)**2 * bot_e
        time_range = slice(None)
        return u_range, elevation_range, azimuth_step, time_range

    def eft_folding(phi_range):
        n_u12 = 30
        n_c = 60
        n_u23 = 75
        phi_12_range = damped_range(np.pi * 0.3, 0.012, n_u12)
        phi_c = np.ones((n_c,), dtype='float_') * 0.01
        phi_23_range = damped_range(0.01, np.pi - 0.005, n_u23)
        phi_range_u = np.hstack([phi_12_range, phi_c, phi_23_range])
        u_range = np.cos(phi_range_u) - 1
        conf1 = 230, 50, 52, 1.14
        confc = 230, 50, 20, 1.14
        conf2 = 100, 160, 0, 1.1
        conf3 = 270, 179, 0., 0.5
        azimuth_range = np.hstack([damped_range(conf1[0], confc[0], n_u12),
                                   damped_range(confc[0], conf2[0], n_c),
                                   damped_range(conf2[0], conf3[0], n_u23)])
        elevation_range = np.hstack([damped_range(conf1[1], confc[1], n_u12),
                                     damped_range(confc[1], conf2[1], n_c),
                                     damped_range(conf2[1], conf3[1], n_u23)])
        roll_range = np.hstack([damped_range(conf1[2], confc[2], n_u12),
                                damped_range(confc[2], conf2[2], n_c),
                                damped_range(conf2[2], conf3[2], n_u23)])
        d_range = np.hstack([damped_range(conf1[3], confc[3], n_u12) * d,
                             damped_range(confc[3], conf2[3], n_c) * d,
                             damped_range(conf2[3], conf3[3], n_u23) * d])
        time_range = slice(None)
        #time_range = np.array([-1], dtype=int)
        return u_range, elevation_range, azimuth_range, roll_range, time_range, d_range

    def eft_unfolding(phi_range):
        n_u1 = 30
        n_u2 = 60
        n_u3 = 60

        phi_u1 = np.pi - 0.012
        phi_u2 = np.pi * 0.86
        phi_u3 = 0.012

        phi_1 = damped_range(phi_u1, phi_u2, n_u1)
        phi_2 = np.ones((n_u2,), dtype='float_') * phi_u2
        phi_3 = damped_range(phi_u2, phi_u3, n_u3)

        phi_range_u = np.hstack([phi_1, phi_2, phi_3])
        u_range = np.cos(phi_range_u) - 1

        conf1 = 270, 179, 0., 0.5
        conf2 = 230, 140, 60., 0.6
        conf3 = 150, 70, 70., 0.64
        conf4 = 45, 1, 314., 1.14

        azimuth_range = np.hstack([damped_range(conf1[0], conf2[0], n_u1),
                                   damped_range(conf2[0], conf3[0], n_u2),
                                   damped_range(conf3[0], conf4[0], n_u3)])
        elevation_range = np.hstack([damped_range(conf1[1], conf2[1], n_u1),
                                     damped_range(conf2[1], conf3[1], n_u2),
                                     damped_range(conf3[1], conf4[1], n_u3)])
        roll_range = np.hstack([damped_range(conf1[2], conf2[2], n_u1),
                                damped_range(conf2[2], conf3[2], n_u2),
                                damped_range(conf3[2], conf4[2], n_u3)])
        d_range = np.hstack([damped_range(conf1[3], conf2[3], n_u1) * d,
                             damped_range(conf2[3], conf3[3], n_u2) * d,
                             damped_range(conf3[3], conf4[3], n_u3) * d,
                             ])
        time_range = slice(None)
        #time_range = np.array([0], dtype=int)
        return u_range, elevation_range, azimuth_range, roll_range, time_range, d_range

#     u_range, elevation_range, azimuth_range, roll_range, time_range, d_range = eft_folding(
#         phi_range)

    u_range, elevation_range, azimuth_range, roll_range, time_range, d_range = eft_unfolding(
        phi_range)

    tdir = tempfile.mkdtemp()

    fname_list = []
    for i, (u, e, a, r, d) in enumerate(zip(u_range[time_range],
                                            elevation_range[time_range],
                                            azimuth_range[time_range],
                                            roll_range[time_range],
                                            d_range[time_range])):
        gu_dof_constraints.dof_constraints[-1][-1] = u
        sim_step._solve_nr()
        f = sim_step.forming_task.formed_object.center
        print 'perspective - before', ftv.mlab.view()
        print 'roll', ftv.mlab.roll()
        print 'a,e,d,f', a, e, d, f
        ftv.mlab.view(a, e, d, f)
        ftv.mlab.roll(r)
        print 'perspective', ftv.mlab.view()
        print 'roll', ftv.mlab.roll()
        ftv.update(force=True)
        fname = os.path.join(tdir, 'eftlogo%03d.jpg' % i)
        fname_list.append(fname)
        ftv.mlab.savefig(fname, magnification=2.2)

    if animation:
        animation_file = os.path.join(tdir, 'anim01.gif')
        images = string.join(fname_list, ' ')
        destination = animation_file

        import platform
        if platform.system() == 'Linux':
            os.system(
                'convert -delay 8 -loop 1 ' + images + ' ' + destination)
            # os.system('png2swf -o%s ' % destination + images)
        else:
            raise NotImplementedError(
                'film production available only on linux')
        print 'animation saved in', destination

    ftv.show()
Example #13
0

if __name__ == '__main__':

    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()

    # 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, 2)], [2])
    gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
    psi_max = np.pi * 0.49
    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,
Example #14
0
    cpf = create_cp_factory()
    cp = cpf.formed_object

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

    # Link the crease factory it with the constraint client
    gu_constant_length = GuConstantLength()
    nx2 = 1
    ny2 = 2
    dof_constraints = fix(cpf.N_grid[nx2 - 1, ny2], [1]) \
        + fix(cpf.N_grid[nx2, ny2], [0, 1, 2]) \
        + fix(cpf.N_grid[nx2, (ny2 - 1, ny2 + 1)], [2])
    gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
    psi_max = np.pi * 0.498
    diag_psi_mask = np.ones_like(cpf.L_d_grid, dtype=np.bool_)
    diag_psi_mask[1:-1, 1:-1] = False
    diag_psi_constraints = [([(i, 1.0)], 0)
                            for i in cpf.L_d_grid[diag_psi_mask].flatten()]
    print 'psi constraints', diag_psi_constraints
    print 'controlled line', cpf.L_h_grid[nx2, ny2]
    gu_psi_constraints = \
        GuPsiConstraints(forming_task=cpf,
                         psi_constraints=diag_psi_constraints +
                         [([(cpf.L_h_grid[nx2, ny2], 1.0)],
                           lambda t: psi_max * t),
Example #15
0
    cp.u[5, 2] = 0.01

    cp_factory = CustomCPFactory(formed_object=cp)
    # end
    return cp_factory

if __name__ == '__main__':

    import mayavi.mlab as m

    cp_factory = create_cp_factory()
    cp = cp_factory.formed_object

    # 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([3], [2]) + \
        fix([5], 2, lambda t: 0.5)
    gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)

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

    sim_step._solve_nr()

    m.figure(bgcolor=(1.0, 1.0, 1.0), fgcolor=(0.6, 0.6, 0.6))
    cp.plot_mlab(m, nodes=True, lines=True)

    m.show()
Example #16
0
def run_sim():

    cp_factory, L_selection = create_cp_factory()
    cp = cp_factory.formed_object

    if False:
        fig, ax = plt.subplots()
        cp.plot_mpl(ax, facets=True)
        plt.tight_layout()
        plt.show()
        return

    # Configure simulation
    gu_constant_length = GuConstantLength()
    dof_constraints = \
        fix([0], [0, 1, 2]) +\
        fix([1], [1, 2]) +\
        fix([5], [2]) +\
        fix([3], [0], lambda t: t * -1.9599)
    gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints)
    sim_config = SimulationConfig(gu={'cl': gu_constant_length,
                                      'dofs': gu_dof_constraints},
                                  acc=1e-5, MAX_ITER=1000)
    sim_step = SimulationStep(forming_task=cp_factory,
                              config=sim_config)

    if False:
        # Configure rendering visualization operators
        eftlabels_viz3d = FacetsWithTextViz3D(
            label='EFT labels', vis3d=cp)
        efttitle_viz3d = FacetsWithImageViz3D(
            label='EFT title', vis3d=cp,
            F_ref=[0, 2, 4, 6, 8],
            N_ref=[0, 3, 15, 12, 7],
            F_covered=[[0, 9], [2, 11], [4, 13], [6, 15], [8, 17]],
            atimes=[90.0, 180.0, -90, 0, 135],
            im_files=['eft_01.png', 'eft_01.png',
                      'eft_01.png', 'eft_01.png', 'eft_01.png'],
            im_widths=[2, 2, 2, 2, 2],
            im_offsets=[[0, 0, 0.004], [0, 0, 0.004],
                        [0, 0, 0.004], [0, 0, 0.004],
                        [-.295, -.295, 0.004]],
        )
    else:
        fname_eft_front = 'eft_areas_standard_02.png'
        fname_eft_back = 'eft_mission_standard_trans_EF01.png'
        fheight = 0.011
        front_offset = 0.006
        tube_radius = 0.01
        plane_offsets = [0.005, -0.010]
        edge_len = 2.0
        x_offset = 1.0
        c45 = np.cos(np.pi / 4)
        shift_x = x_offset + edge_len / c45 - edge_len
        shift_l = shift_x * c45
        print('shift_l', shift_l)
        F_ref = [0, 2, 4, 6, 8, 16, 1, 12, 14, ]
        N_ref = [0, 3, 15, 12, 7, 4, 1, 11, 13]
        F_covered = [[0, 9], [2, 11], [4, 13], [6, 15],
                     [8, 17], [16, 7], [1, 10], [12, 3], [14, 5]]
        atimes = [90.0, 180.0, -90, 0, 45, 90, 90.0, -90.0, 0.0]
        im_widths = [4, 4, 4, 4, 4, 4, 4, 4, 4]
        imfiles_front = [
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
            fname_eft_front,
        ]
        imfiles_back = [
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
            fname_eft_back,
        ]
        im_front_offsets = [
            [0, 0, front_offset],
            [0, 0, front_offset],
            [0, 0, front_offset],
            [0, 0, front_offset],
            [-shift_l, -shift_l, front_offset],
            [0, -1, front_offset],
            [-2, 0, front_offset],
            [0, -1, front_offset],
            [0, -1, front_offset]
        ]
        im_back_offsets = [
            [0, 0, -fheight],
            [0, 0, -fheight],
            [0, 0, -fheight],
            [0, 0, -fheight],
            [-shift_l, -shift_l, -fheight],
            [0, -1, -fheight],
            [-2, 0, -fheight],
            [0, -1, -fheight],
            [0, -1, -fheight]
        ]
        efttitle_back_viz3d = FacetsWithImageViz3D(
            label='EFT back', vis3d=cp,
            F_ref=F_ref,  # + F_ref,
            N_ref=N_ref,  # + N_ref,
            F_covered=F_covered,  # + F_covered,
            atimes=atimes,  # + atimes,
            im_files=imfiles_back,  # imfiles_front +
            im_widths=im_widths,  # + im_widths,
            im_offsets=im_back_offsets,  # im_front_offsets +
        )
        efttitle_front_viz3d = FacetsWithImageViz3D(
            label='EFT front', vis3d=cp,
            F_ref=F_ref,
            N_ref=N_ref,
            F_covered=F_covered,
            atimes=atimes,
            im_files=imfiles_front,
            im_widths=im_widths,
            im_offsets=im_front_offsets
        )

    eftlogo_normals = CreasePatternNormalsViz3D(
        label='EFT normals', vis3d=cp)
    eftlogo_bases = CreasePatternBasesViz3D(
        label='EFT bases', vis3d=cp)
    eft_thick_viz3d = CreasePatternThickViz3D(
        label='EFT thick', vis3d=cp,
        plane_offsets=plane_offsets)
    cp.viz3d['cp'].set(tube_radius=tube_radius)

    # Configure scene
    ftv = FTV()
    ftv.add(cp.viz3d['cp'])
    ftv.add(eft_thick_viz3d)
    ftv.add(efttitle_front_viz3d)
    ftv.add(efttitle_back_viz3d)
    # ftv.add(eftlabels_viz3d)
    # ftv.add(eftlogo_normals)
    # ftv.add(eftlogo_bases)

    m = ftv.mlab
    m.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0))
    fig = m.gcf()

    ftv.plot()
#    oricreate_mlab_label(m)

    a, e, d, f = m.view()
    e = 135  # 10
    a = 270  # -45  # 120

    f = sim_step.forming_task.formed_object.center
    m.view(a, e, d, f)

    show = False
    if show:
        m.show()

    n_u = 30

    # Control the folding by a fold angle

    phi_range = np.linspace(0.01, np.pi - 0.01, n_u)

    dramaturgy = False
    animation = True

    def circular_folding(phi_range):
        bot_e = 160
        top_e = 10
        if dramaturgy:
            phi_unfolded = phi_range[0] * np.ones_like(phi_range)
            phi_folded = phi_range[-1] * np.ones_like(phi_range)
            phi_range_u = np.hstack(
                [phi_range, phi_folded, phi_range[::-1], phi_unfolded])
        else:
            phi_range_u = phi_range

        u_range = np.cos(phi_range_u) - 1
        phi_range_e = np.linspace(0.01, np.pi - 0.01, n_u * 4)
        azimuth_step = 360.0 / 4 / n_u
        elevation_range = np.cos(
            2 * phi_range_e)**2 * top_e + np.sin(2 * phi_range_e)**2 * bot_e
        time_range = slice(None)
        return u_range, elevation_range, azimuth_step, time_range

    def eft_folding(phi_range):
        n_u12 = 30
        n_c = 60
        n_u23 = 75
        phi_12_range = damped_range(np.pi * 0.3, 0.012, n_u12)
        phi_c = np.ones((n_c,), dtype='float_') * 0.01
        phi_23_range = damped_range(0.01, np.pi - 0.005, n_u23)
        phi_range_u = np.hstack([phi_12_range, phi_c, phi_23_range])
        u_range = np.cos(phi_range_u) - 1
        conf1 = 230, 50, 52, 1.14
        confc = 230, 50, 20, 1.14
        conf2 = 100, 160, 0, 1.1
        conf3 = 270, 179, 0., 0.5
        azimuth_range = np.hstack([damped_range(conf1[0], confc[0], n_u12),
                                   damped_range(confc[0], conf2[0], n_c),
                                   damped_range(conf2[0], conf3[0], n_u23)])
        elevation_range = np.hstack([damped_range(conf1[1], confc[1], n_u12),
                                     damped_range(confc[1], conf2[1], n_c),
                                     damped_range(conf2[1], conf3[1], n_u23)])
        roll_range = np.hstack([damped_range(conf1[2], confc[2], n_u12),
                                damped_range(confc[2], conf2[2], n_c),
                                damped_range(conf2[2], conf3[2], n_u23)])
        d_range = np.hstack([damped_range(conf1[3], confc[3], n_u12) * d,
                             damped_range(confc[3], conf2[3], n_c) * d,
                             damped_range(conf2[3], conf3[3], n_u23) * d])
        time_range = slice(None)
        #time_range = np.array([-1], dtype=int)
        return u_range, elevation_range, azimuth_range, roll_range, time_range, d_range

    def eft_unfolding(phi_range):
        n_u1 = 30
        n_u2 = 60
        n_u3 = 60

        phi_u1 = np.pi - 0.012
        phi_u2 = np.pi * 0.86
        phi_u3 = 0.012

        phi_1 = damped_range(phi_u1, phi_u2, n_u1)
        phi_2 = np.ones((n_u2,), dtype='float_') * phi_u2
        phi_3 = damped_range(phi_u2, phi_u3, n_u3)

        phi_range_u = np.hstack([phi_1, phi_2, phi_3])
        u_range = np.cos(phi_range_u) - 1

        conf1 = 270, 179, 0., 0.5
        conf2 = 230, 140, 60., 0.6
        conf3 = 150, 70, 70., 0.64
        conf4 = 45, 1, 314., 1.14

        azimuth_range = np.hstack([damped_range(conf1[0], conf2[0], n_u1),
                                   damped_range(conf2[0], conf3[0], n_u2),
                                   damped_range(conf3[0], conf4[0], n_u3)])
        elevation_range = np.hstack([damped_range(conf1[1], conf2[1], n_u1),
                                     damped_range(conf2[1], conf3[1], n_u2),
                                     damped_range(conf3[1], conf4[1], n_u3)])
        roll_range = np.hstack([damped_range(conf1[2], conf2[2], n_u1),
                                damped_range(conf2[2], conf3[2], n_u2),
                                damped_range(conf3[2], conf4[2], n_u3)])
        d_range = np.hstack([damped_range(conf1[3], conf2[3], n_u1) * d,
                             damped_range(conf2[3], conf3[3], n_u2) * d,
                             damped_range(conf3[3], conf4[3], n_u3) * d,
                             ])
        time_range = slice(None)
        #time_range = np.array([0], dtype=int)
        return u_range, elevation_range, azimuth_range, roll_range, time_range, d_range

#     u_range, elevation_range, azimuth_range, roll_range, time_range, d_range = eft_folding(
#         phi_range)

    u_range, elevation_range, azimuth_range, roll_range, time_range, d_range = eft_unfolding(
        phi_range)

    tdir = tempfile.mkdtemp()

    fname_list = []
    for i, (u, e, a, r, d) in enumerate(zip(u_range[time_range],
                                            elevation_range[time_range],
                                            azimuth_range[time_range],
                                            roll_range[time_range],
                                            d_range[time_range])):
        gu_dof_constraints.dof_constraints[-1][-1] = u
        sim_step._solve_nr()
        f = sim_step.forming_task.formed_object.center
        print('perspective - before', ftv.mlab.view())
        print('roll', ftv.mlab.roll())
        print('a,e,d,f', a, e, d, f)
        ftv.mlab.view(a, e, d, f)
        ftv.mlab.roll(r)
        print('perspective', ftv.mlab.view())
        print('roll', ftv.mlab.roll())
        ftv.update(force=True)
        fname = os.path.join(tdir, 'eftlogo%03d.jpg' % i)
        fname_list.append(fname)
        ftv.mlab.savefig(fname, magnification=2.2)

    if animation:
        animation_file = os.path.join(tdir, 'anim01.gif')
        images = string.join(fname_list, ' ')
        destination = animation_file

        import platform
        if platform.system() == 'Linux':
            os.system(
                'convert -delay 8 -loop 1 ' + images + ' ' + destination)
            # os.system('png2swf -o%s ' % destination + images)
        else:
            raise NotImplementedError(
                'film production available only on linux')
        print('animation saved in', destination)

    ftv.show()