def x_get_fold_deform_task(self): ft = self.factory_task it = self.init_displ_task fixed_z = fix(self.fixed_z, (2)) fixed_y = fix(self.fixed_y, (1)) fixed_x = fix(self.fixed_x, (0)) link_z = link(self.link_z[0], [2], 1, self.link_z[1], [2], -1) dof_constraints = fixed_x + fixed_z + fixed_y + \ link_z gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) def FN(psi): return lambda t: psi * t psi_constr = [([(i, 1.0)], FN(self.psi_max)) for i in self.psi_lines] gu_constant_length = GuConstantLength() gu_psi_constraints = \ GuPsiConstraints(forming_task=ft, psi_constraints=psi_constr) sim_config = SimulationConfig(goal_function_type='gravity potential energy', gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-4, MAX_ITER=self.MAXITER, debug_level=0) fu_tot_poteng = FuPotEngTotal(kappa=np.array([self.kappa]), F_ext_list=[], rho=self.rho, exclude_lines=self.psi_lines) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=ft, config=sim_config, n_steps=self.n_steps) fu_tot_poteng.forming_task = st gu_psi_constraints.forming_task = st cp = st.formed_object cp.u = it.u_1 #cp.u[:, 2] = np.random return st
def _get_fold_angle_cntl(self): # Link the crease factory it with the constraint client gu_constant_length = GuConstantLength() psi_max = np.pi * 0.3 gu_psi_constraints = \ GuPsiConstraints(forming_task=self.factory_task, psi_constraints=[([(1, 1.0)], lambda t: -psi_max * t), ]) dof_constraints = fix([2], [0, 1, 2]) + fix([0], [1, 2]) \ + fix([3], [2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(goal_function_type='none', gu={ 'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=100) sim_task = SimulationTask(previous_task=self.factory_task, config=sim_config, n_steps=5) return sim_task
def _get_fold_task(self): self.init_displ_task.x_1 fixed_z = fix(self.fixed_z, (2)) fixed_y = fix(self.fixed_y, (1)) fixed_x = fix(self.fixed_x, (0)) link_z = link(self.link_z[0], [2], 1, self.link_z[1], [2], -1) dof_constraints = fixed_x + fixed_z + fixed_y + \ link_z gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) FN = lambda psi: lambda t: psi * t psi_constr = [([(i, 1.0)], FN(self.psi_max)) for i in self.psi_lines] gu_constant_length = GuConstantLength() gu_psi_constraints = \ GuPsiConstraints(forming_task=self.init_displ_task, psi_constraints=psi_constr) sim_config = SimulationConfig( goal_function_type='gravity potential energy', gu={ 'cl': gu_constant_length, 'dofs': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=500, debug_level=0) return SimulationTask(previous_task=self.init_displ_task, config=sim_config, n_steps=self.n_steps)
def get_merge_nodes_task(self, prev_ft, merge_nodes=[[]], link_nodes=[], fix_node=[], stiff_lines=[], init_nodes=(), init_val=0.0): cp = self.factory_task.formed_object psi_constr = [ ([(i, 1.0)], lambda t: self.fix_psi * t) # fold_step(t, i)) for i in stiff_lines ] gu_psi_constraints = \ GuPsiConstraints(forming_task=prev_ft, psi_constraints=psi_constr) F_u_fix = cp.F_N[1] dof_constraints = fix([F_u_fix[0]], [0, 1, 2]) + \ fix([F_u_fix[1]], [1, 2]) + \ fix([F_u_fix[2]], [2]) if len(link_nodes) > 0: ln = np.array(link_nodes, dtype=np.int_) link_nodes1, link_nodes2 = ln.T ldofs = link(link_nodes1, [0, 1, 2], 1.0, link_nodes2, [0, 1, 2], -1.0) dof_constraints += ldofs gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig( goal_function_type='total potential energy', gu={ 'cl': gu_constant_length, 'gu': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=500) fu_node_dist = \ FuNodeDist(forming_task=prev_ft, L=merge_nodes, ) sim_config._fu = fu_node_dist st = SimulationTask(previous_task=prev_ft, config=sim_config, n_steps=1) fu_node_dist.forming_task = st cp = st.formed_object return st
def _get_fold_task(self): psi_max = self.fix_psi cp = self.factory_task.formed_object inner_lines = cp.iL psi_constr = [([(i, 1.0)], lambda t: psi_max * t) for i in inner_lines] gu_psi_constraints = \ GuPsiConstraints(forming_task=self.factory_task, psi_constraints=psi_constr) F_u_fix = cp.F_N[1] dof_constraints = fix([F_u_fix[0]], [0, 1, 2]) + \ fix([F_u_fix[1]], [1, 2]) + \ fix([F_u_fix[2]], [2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='none', gu={ 'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=500, debug_level=0) return SimulationTask(previous_task=self.factory_task, config=sim_config, n_steps=self.n_steps)
def get_single_step_fold_task(self, seq_fold_task): ft = self.factory_task seq_cp = seq_fold_task.formed_object iL = seq_cp.iL iL_psi = seq_cp.iL_psi def fold_step(t, start_t=0.0, end_t=1.0): if t < start_t: return 0.0 elif t > end_t: return 1.0 else: return (t - start_t) / (end_t - start_t) def FN(psi, start_t, end_t): return lambda t: psi * \ fold_step(t, start_t, end_t) print('iL', iL) trange = np.zeros((len(iL), 2), dtype=np.float_) trange[:, 0] = 0.0 trange[:, 1] = 0.4 trange[2, :] = [0.3, 0.6] trange[7, :] = [0.5, 0.8] trange[10, :] = [0.5, 0.8] trange[11, :] = [0.6, 0.8] trange[15, :] = [0.6, 0.8] trange[16, :] = [0.8, 1.0] trange[18, :] = [0.6, 0.8] trange[14, :] = [0.8, 1.0] psi_constraints = [([(i, 1.0)], FN(i_psi, i_start, i_end)) for i, i_psi, i_start, i_end in zip( iL, iL_psi, trange[:, 0], trange[:, 1])] gu_psi_constraints = \ GuPsiConstraints(forming_task=ft, psi_constraints=psi_constraints) F_u_fix = cp.F_N[1] dof_constraints = fix([F_u_fix[0]], [0, 1, 2]) + \ fix([F_u_fix[1]], [1, 2]) + \ fix([F_u_fix[2]], [2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='none', gu={ 'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=500, debug_level=0) return SimulationTask(previous_task=ft, config=sim_config, n_steps=50)
def _get_fold_seq_task(self): psi_max = -self.phi_max dt = 1.0 / 7.0 def fold_step(t, fold_index): n_steps = 7.0 dt = 1.0 / n_steps start_t = fold_index * dt end_t = (fold_index + 1) * dt if t < start_t: return 0.0 elif t > end_t: return 1.0 else: return (t - start_t) / (end_t - start_t) gu_psi_constraints = \ GuPsiConstraints(forming_task=self.factory_task, psi_constraints=[([(0, 1.0)], lambda t: psi_max * fold_step(t, 0)), ([(1, 1.0)], lambda t: psi_max * fold_step(t, 1)), ([(6, 1.0)], lambda t: psi_max * fold_step(t, 2)), ([(7, 1.0)], lambda t: psi_max * fold_step(t, 3)), ([(3, 1.0)], lambda t: psi_max * fold_step(t, 4)), ([(12, 1.0)], lambda t: psi_max * fold_step(t, 5)), ([(13, 1.0)], lambda t: psi_max * fold_step(t, 6)), ] ) dof_constraints = fix([0], [0, 1, 2]) + fix([1], [1, 2]) \ + fix([3], [2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='none', gu={ 'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=500, debug_level=0) return SimulationTask(previous_task=self.factory_task, config=sim_config, n_steps=self.n_steps)
def _get_fold_task(self): psi_max = np.pi - 138.19 / 180.0 * np.pi print(psi_max) inner_lines = [ 1, 7, 10, 11, 12, 13, 14, 16, 17, 18, 19, 22, 24, 25, 26, 32, 34, 35, 37 ] def fold_step(t, fold_index): n_steps = len(inner_lines) dt = 1.0 / float(n_steps) start_t = fold_index * dt end_t = (fold_index + 1) * dt print('t', t, start_t, end_t) if t < start_t: return 0.0 elif t > end_t: return 1.0 else: return (t - start_t) / (end_t - start_t) np.random.shuffle(inner_lines) psi_constr = [ ([(i, 1.0)], lambda t: psi_max * t) # fold_step(t, i)) for i in inner_lines ] gu_psi_constraints = \ GuPsiConstraints(forming_task=self.factory_task, psi_constraints=psi_constr) dof_constraints = fix([6], [0, 1, 2]) + \ fix([7], [1, 2]) + \ fix([13], [2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='none', gu={ 'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=500, debug_level=0) return SimulationTask(previous_task=self.factory_task, config=sim_config, n_steps=self.n_steps)
def _get_fold_task(self): psi_max = np.pi - 138.19 / 180.0 * np.pi inner_lines = self.factory_task.formed_object.iL def fold_step(t, fold_index): n_steps = len(inner_lines) print('n_steps', n_steps, fold_index) dt = 1.0 / float(n_steps) start_t = fold_index * dt end_t = (fold_index + 1) * dt print('t', t, start_t, end_t) if t < start_t: return 0.0 elif t > end_t: return 1.0 else: return (t - start_t) / (end_t - start_t) FN = lambda i: lambda t: psi_max * fold_step(t, i) psi_constr = [([(L_idx, 1.0)], FN(i)) for i, L_idx in enumerate(inner_lines)] gu_psi_constraints = \ GuPsiConstraints(forming_task=self.factory_task, psi_constraints=psi_constr) dof_constraints = fix([6], [0, 1, 2]) + \ fix([7], [1, 2]) + \ fix([13], [2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='none', gu={'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints}, acc=1e-5, MAX_ITER=500, debug_level=0) return SimulationTask(previous_task=self.factory_task, config=sim_config, n_steps=self.n_steps)
def _get_fold_angle_cntl(self): fixed_nodes_x = fix( [2], (0)) fixed_nodes_y = fix( [2, 3], (1)) fixed_nodes_z = fix( [2, 3, 6], (2)) dof_constraints = fixed_nodes_x + fixed_nodes_z + fixed_nodes_y def FN(psi): return lambda t: psi * t psi_constr = [([(i, 1.0)], FN(self.psi_max)) for i in self.psi_lines] gu_psi_constraints = \ GuPsiConstraints(forming_task=self.factory_task, psi_constraints=psi_constr) gu_dof_constraints = GuDofConstraints( dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='none', gu={'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=500, debug_level=0) st = SimulationTask(previous_task=self.factory_task, config=sim_config, n_steps=self.n_fold_steps) cp = st.formed_object cp.u[(0, 12), 2] -= 0.4 cp.u[(7, 1, 4), 2] += 0.4 cp.u[(8, 9), 2] -= 0.4 return st
def _get_fold_task(self): L_rigid = self.factory_task.L_rigid N_up = self.factory_task.N_up N_down = self.factory_task.N_down print('N_up', N_up) print('N_down', N_down) N_x_sym = self.factory_task.N_x_sym[2] print('N_x_sym', N_x_sym) # N_x_sym = [] # self.factory_task.N_x_sym[[0, -1]] print('n_dofs', self.factory_task.formed_object.n_dofs) self.init_displ_task.x_1 fixed_z = fix(self.fixed_z, (2)) fixed_x = fix(self.fixed_x, (1)) fixed_y = fix(self.fixed_y, (1)) fixed_y_plus = fix(self.fixed_y_plus, (1), lambda t: t * self.u_max) fixed_y_minus = fix(self.fixed_y_minus, (1), lambda t: -t * self.u_max) link_x1 = link([2], 0, 1, [6], 0, 1) link_x2 = link([10], 0, 1, [14], 0, 1) dof_constraints = fixed_y_minus + \ fixed_y_plus + fixed_x + fixed_z + fixed_y + link_x1 + link_x2 gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) def FN(psi): return lambda t: psi * t psi_constr = [([(i, 1.0)], FN(0)) for i in L_rigid] gu_constant_length = GuConstantLength() gu_psi_constraints = \ GuPsiConstraints(forming_task=self.init_displ_task, psi_constraints=psi_constr) sim_config = SimulationConfig(goal_function_type='none', gu={ 'cl': gu_constant_length, 'dofs': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-4, MAX_ITER=self.MAXITER, debug_level=0) st = SimulationTask(previous_task=self.init_displ_task, config=sim_config, n_steps=self.n_steps, record_iter=False) gu_dof_constraints.forming_task = st st.sim_step.print_gu_lst() print('dofs', st.formed_object.n_dofs) cp = st.formed_object cp.u[N_up, 2] += 0.1 cp.u[N_down, 2] -= 0.1 cp.u[(1, 3, 13, 15), 2] += 0.2 cp.u[(5, 7, 9, 11), 2] -= 0.2 cp.u[(0, 16), 2] += 0.5 cp.u[(0), 1] += 0.5 cp.u[(16), 1] -= 0.5 cp.u[(4), 1] += 0.3 cp.u[(12), 1] -= 0.3 cp.u[(4, 12), 2] -= 0.2 return st
def _get_fold_angle_cntl(self): self.init_displ_task.x_1 corner2_i_x = np.array([0, 0, -1, -1], dtype=np.int_) corner2_i_y = np.array([0, -1, 0, -1], dtype=np.int_) corner2_h_x = np.array([0, 0, -1, -1], dtype=np.int_) corner2_h_y = np.array([0, -1, 0, -1], dtype=np.int_) tb2_i_x = np.array([1, 1, 1], dtype=np.int_) tb2_i_y = np.array([0, -1, -1], dtype=np.int_) tb2_h_x = np.array([1, 1, 2], dtype=np.int_) tb2_h_y = np.array([0, -1, -1], dtype=np.int_) up2_i_x = np.array([0, 0, -1, -1], dtype=np.int_) up2_i_y = np.array([0, 1, 0, 1], dtype=np.int_) up2_h_x = np.array([0, 0, -1, -1], dtype=np.int_) up2_h_y = np.array([1, 1, 1, 1], dtype=np.int_) right2_i_x = np.array([2, 2, 3], dtype=np.int_) right2_i_y = np.array([0, 0, 0], dtype=np.int_) right2_h_x = np.array([3, 3, 3], dtype=np.int_) right2_h_y = np.array([0, 1, 0], dtype=np.int_) base_i_x = corner2_i_x base_i_y = corner2_i_y base_h_x = corner2_h_x base_h_y = corner2_h_y for c_x in range(0, self.n_cell_x): print('c_x', c_x) base_i_x = np.hstack([base_i_x, 3 * c_x + tb2_i_x]) base_i_y = np.hstack([base_i_y, tb2_i_y]) base_h_x = np.hstack([base_h_x, 3 * c_x + tb2_h_x]) base_h_y = np.hstack([base_h_y, tb2_h_y]) for c_x in range(0, self.n_cell_x - 1): print('c_x', c_x) base_i_x = np.hstack([base_i_x, 3 * c_x + right2_i_x]) base_i_y = np.hstack([base_i_y, right2_i_y]) base_h_x = np.hstack([base_h_x, 3 * c_x + right2_h_x]) base_h_y = np.hstack([base_h_y, right2_h_y]) for c_y in range(0, self.n_cell_y - 1): print('c_y', c_y) base_i_x = np.hstack([base_i_x, up2_i_x]) base_i_y = np.hstack([base_i_y, c_y + up2_i_y]) base_h_x = np.hstack([base_h_x, up2_h_x]) base_h_y = np.hstack([base_h_y, c_y + up2_h_y]) f = self.factory_task cp = f.formed_object m_nodes = f.N_i[base_i_x, base_i_y] n_nodes = f.N_h[base_h_x, base_h_y] psi_lines = cp.NN_L[[m_nodes], n_nodes].flatten() print('psi_lines', psi_lines) N_h = f.N_h N_i = f.N_i N_v = f.N_v fixed_nodes_x = fix(N_h[0, 0], (0)) fixed_nodes_y = fix(N_h[(0, -1), 0], (1)) fixed_nodes_z = fix([N_h[0, 0], N_h[-1, 0], N_h[0, -1]], (2)) dof_constraints = fixed_nodes_x + fixed_nodes_z + fixed_nodes_y gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) def FN(psi): return lambda t: psi * t psi_constr = [([(i, 1.0)], FN(self.psi_max)) for i in psi_lines] gu_psi_constraints = \ GuPsiConstraints(forming_task=self.init_displ_task, psi_constraints=psi_constr) gu_constant_length = GuConstantLength() 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=500, debug_level=0) st = SimulationTask(previous_task=self.init_displ_task, config=sim_config, n_steps=self.n_fold_steps) cp = st.formed_object N_down = np.hstack([N_h[::3, :].flatten(), N_i[1::3, :].flatten()]) print('N_down', N_down) N_up = np.hstack([ N_i[::3, :].flatten(), N_i[2::3, :].flatten(), N_v[:, :].flatten() ]) print('N_up', N_up) cp.u[N_down, 2] -= .1 cp.u[N_up, 2] += .1 return st
def _get_load_self_weight(self): self.fold_kinem_cntl.x_1 f = self.factory_task exclude_lines = np.arange(9, 17) cp = f.formed_object N_h = f.N_h N_i = f.N_i N_v = f.N_v fixed_nodes = np.hstack([N_h[[-1, -1], [0, -1]]]) fixed_nodes = [25, 27] fixed_nodes_xyz = fix( list(N_h[[0, 0, -1, -1], [0, -1, 0, -1]].flatten()), (2) #fixed_nodes, (0, 2) ) slided_nodes = np.hstack([N_h[[0, -1], [0, 0]]]) # , [22, 25]]) #slide_y = fix(slided_nodes, [1], lambda t: 1.8 * self.L_y * t) slide_x = fix([22, 24], [2], lambda t: 0.95 * (self.L_x) * t) slide_z = fix(N_h[[1, -2], [1, 1]], [2], lambda t: -0.3 * t) dof_constraints = fixed_nodes_xyz + slide_z gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() fix_psi_constr = [([(i, 1.0)], 0.0) for i in exclude_lines] gu_psi_constraints = \ GuPsiConstraints(forming_task=self.fold_kinem_cntl, psi_constraints=fix_psi_constr) sim_config = SimulationConfig( goal_function_type='total potential energy', gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-7, MAX_ITER=1000, debug_level=0 ) loaded_n = N_h[:, 1].flatten() def FN(F): return lambda t: t * F P = 0.0 * 30.5 F_ext_list = [] # (loaded_n, 2, FN(-P))] thickness = 0.01 E_mod = 21.0e+4 I = 1.0 * thickness**3 / 12.0 kappa = E_mod * I print('kappa', kappa) sig_tu = 3000.0 m_u = sig_tu * 1.0 * thickness**2 / 6.0 print('m_u', m_u) fu_tot_poteng = FuPotEngTotal( exclude_lines=exclude_lines, kappa=np.array([kappa]), thickness=thickness, rho=23.6, m_u=m_u, F_ext_list=F_ext_list ) sim_config._fu = fu_tot_poteng st = SimulationTask( previous_task=self.fold_kinem_cntl, config=sim_config, n_steps=self.n_load_steps ) fu_tot_poteng.forming_task = st cp = st.formed_object cp.x_0 = self.fold_kinem_cntl.x_1 cp.u[:, :] = 0.0 return st
def _get_fold_kinem_cntl(self): self.init_displ_task.x_1 base_i_x = np.array([0, 0, -1, -1], dtype=np.int_) base_i_y = np.array([0, -1, 0, -1], dtype=np.int_) base_h_x = np.array([0, 0, -1, -1], dtype=np.int_) base_h_y = np.array([0, -1, 0, -1], dtype=np.int_) f = self.factory_task cp = f.formed_object m_n = f.N_h[(0, 0, -1, -1), (0, -1, 0, -1)] n_n = f.N_v[(0, 0, -1, -1), (0, -1, 0, -1)] print(m_n.flatten()) print(n_n.flatten()) fix_psi_lines = cp.NN_L[m_n, n_n].flatten() print('psi_lines', fix_psi_lines) cm_nodes = [f.N_i[0, 0], f.N_i[-1, 1]] cn_nodes = [f.N_h[1, 1], f.N_h[2, 1]] cpsi_lines = cp.NN_L[cm_nodes, cn_nodes] print('cpsi_lines', cpsi_lines) N_h = f.N_h N_i = f.N_i N_v = f.N_v fixed_nodes_x = fix( N_i[1, (0, 1)], (0)) fixed_nodes_y = fix( [N_h[1, 1].flatten()], (1)) fixed_nodes_z = fix( list(N_v[[0, 0, -1], [0, -1, 0]].flatten()), (2) ) link_nodes_yz = link( list(N_v[[0, 0], [0, -1]].flatten()) + list(N_h[[0, 0], [0, -1]].flatten()), (1, 2), 1.0, list(N_i[[0, 0], [0, -1]].flatten()) + list(N_h[[-1, -1], [0, -1]].flatten()), (1, 2), -1.0, ) link_nodes_z = link( N_h[1, 1], 2, 1.0, N_h[2, 1], 2, -1.0, ) dof_constraints = fixed_nodes_x + fixed_nodes_z + fixed_nodes_y + \ link_nodes_yz + link_nodes_z gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) def FN(psi): return lambda t: psi * t cpsi_constr = [([(cpsi_line, 1.0)], FN(0.502 * np.pi)) for cpsi_line in cpsi_lines] fix_psi_constr = [([(i, 1.0)], 0.0) for i in fix_psi_lines] print('fix_psi_lines', fix_psi_lines) gu_psi_constraints = \ GuPsiConstraints(forming_task=self.init_displ_task, psi_constraints=fix_psi_constr + cpsi_constr) gu_constant_length = GuConstantLength() 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=500, debug_level=0) st = SimulationTask(previous_task=self.init_displ_task, config=sim_config, n_steps=self.n_fold_steps) cp = st.formed_object N_down = np.hstack([N_h[::3, :].flatten(), N_i[1::3, :].flatten(), [23, 26] ]) print('N_down', N_down) N_up = np.hstack([N_i[::3, :].flatten(), N_i[2::3, :].flatten(), N_v[:, :].flatten()]) print('N_up', N_up) cp.u[N_down, 2] -= self.d_down cp.u[N_up, 2] += self.d_up cp.u[:, 2] += self.d_down return st
def _get_fold_angle_cntl(self): self.init_displ_task.x_1 corner2_i_x = np.array([0, 0, -1, -1], dtype=np.int_) corner2_i_y = np.array([0, -1, 0, -1], dtype=np.int_) corner2_h_x = np.array([0, 0, -1, -1], dtype=np.int_) corner2_h_y = np.array([0, -1, 0, -1], dtype=np.int_) tb2_i_x = np.array([1, 1, 1], dtype=np.int_) tb2_i_y = np.array([0, -1, -1], dtype=np.int_) tb2_h_x = np.array([1, 1, 2], dtype=np.int_) tb2_h_y = np.array([0, -1, -1], dtype=np.int_) up2_i_x = np.array([0, 0, -1, -1], dtype=np.int_) up2_i_y = np.array([0, 1, 0, 1], dtype=np.int_) up2_h_x = np.array([0, 0, -1, -1], dtype=np.int_) up2_h_y = np.array([1, 1, 1, 1], dtype=np.int_) right2_i_x = np.array([2, 2, 3], dtype=np.int_) right2_i_y = np.array([0, 0, 0], dtype=np.int_) right2_h_x = np.array([3, 3, 3], dtype=np.int_) right2_h_y = np.array([0, 1, 0], dtype=np.int_) base_i_x = corner2_i_x base_i_y = corner2_i_y base_h_x = corner2_h_x base_h_y = corner2_h_y for c_x in range(0, self.n_cell_x): base_i_x = np.hstack([base_i_x, 3 * c_x + tb2_i_x]) base_i_y = np.hstack([base_i_y, tb2_i_y]) base_h_x = np.hstack([base_h_x, 3 * c_x + tb2_h_x]) base_h_y = np.hstack([base_h_y, tb2_h_y]) for c_x in range(0, self.n_cell_x - 1): base_i_x = np.hstack([base_i_x, 3 * c_x + right2_i_x]) base_i_y = np.hstack([base_i_y, right2_i_y]) base_h_x = np.hstack([base_h_x, 3 * c_x + right2_h_x]) base_h_y = np.hstack([base_h_y, right2_h_y]) for c_y in range(0, self.n_cell_y - 1): print('c_y', c_y) base_i_x = np.hstack([base_i_x, up2_i_x]) base_i_y = np.hstack([base_i_y, c_y + up2_i_y]) base_h_x = np.hstack([base_h_x, up2_h_x]) base_h_y = np.hstack([base_h_y, c_y + up2_h_y]) f = self.factory_task cp = f.formed_object m_nodes = f.N_i[base_i_x, base_i_y] n_nodes = f.N_h[base_h_x, base_h_y] psi_lines = cp.NN_L[[m_nodes], n_nodes].flatten() print('psi_lines', psi_lines) cm_node = f.N_i[0, 0] cn_node = f.N_h[1, 1] cpsi_line = cp.NN_L[cm_node, cn_node] print('cpsi_lines', cpsi_line) N_h = f.N_h N_i = f.N_i N_v = f.N_v y_mid = N_i.shape[1] / 2 fixed_nodes_x = fix( N_h[0, 0], (0)) fixed_nodes_y = fix( N_h[(0, -1), 0], (1)) fixed_nodes_z = fix( [N_h[0, 0], N_h[-1, 0], N_h[0, -1]], (2)) u_max = (1.999 * self.c * self.t_max) link_mid = link( N_i[0, 0], (0), 1.0, N_i[2, 0], (0), -1.0, lambda t: t * u_max ) print('--------------------------') print(N_i[0, 0].flatten()) print(N_i[2, 0].flatten()) print('--------------------------') dof_constraints = fixed_nodes_x + fixed_nodes_z + fixed_nodes_y # + \ # link_mid gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) def FN(psi): return lambda t: psi * t cpsi_constr = [([(cpsi_line, 1.0)], FN(0.99 * np.pi))] lpsi_constr = [([(psi_lines[0], 1.0), (i, -1.0)], 0.0) for i in psi_lines[1:]] gu_psi_constraints = \ GuPsiConstraints(forming_task=self.init_displ_task, psi_constraints=lpsi_constr + cpsi_constr) gu_constant_length = GuConstantLength() 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=500, debug_level=0) st = SimulationTask(node='Fold angle control', previous_task=self.init_displ_task, config=sim_config, n_steps=self.n_fold_steps) cp = st.formed_object N_down = np.hstack([N_h[::3, :].flatten(), N_i[1::3, :].flatten() ]) print('N_down', N_down) N_up = np.hstack([N_i[::3, :].flatten(), N_i[2::3, :].flatten(), N_v[:, :].flatten()]) print('N_up', N_up) cp.u[N_down, 2] -= self.d_down cp.u[N_up, 2] += self.d_up cp.u[:, 2] += self.d_down return st
return cp_factory if __name__ == '__main__': cp_factory_task = create_cp_factory() cp = cp_factory_task.formed_object # Link the crease factory it with the constraint client gu_constant_length = GuConstantLength() psi_max = np.pi * 0.3 gu_psi_constraints = \ GuPsiConstraints(forming_task=cp_factory_task, psi_constraints=[([(1, 1.0)], lambda t: psi_max * t), ([(3, 1.0)], psi_max), ([(5, 1.0)], lambda t: psi_max * t), ]) dof_constraints = fix([0], [0, 1, 2]) + fix([1], [1, 2]) \ + fix([2], [2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(goal_function_type='none', gu={ 'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints }, acc=1e-5, MAX_ITER=100)
def _get_fold_kinem_cntl(self): self.init_displ_task.x_1 corner2_i_x = np.array([0, 0, -1, -1], dtype=np.int_) corner2_i_y = np.array([0, -1, 0, -1], dtype=np.int_) corner2_h_x = np.array([0, 0, -1, -1], dtype=np.int_) corner2_h_y = np.array([0, -1, 0, -1], dtype=np.int_) tb2_i_x = np.array([1, 1, 1], dtype=np.int_) tb2_i_y = np.array([0, -1, -1], dtype=np.int_) tb2_h_x = np.array([1, 1, 2], dtype=np.int_) tb2_h_y = np.array([0, -1, -1], dtype=np.int_) up2_i_x = np.array([0, 0, -1, -1], dtype=np.int_) up2_i_y = np.array([0, 1, 0, 1], dtype=np.int_) up2_h_x = np.array([0, 0, -1, -1], dtype=np.int_) up2_h_y = np.array([1, 1, 1, 1], dtype=np.int_) right2_i_x = np.array([2, 2, 3], dtype=np.int_) right2_i_y = np.array([0, 0, 0], dtype=np.int_) right2_h_x = np.array([3, 3, 3], dtype=np.int_) right2_h_y = np.array([0, 1, 0], dtype=np.int_) base_i_x = corner2_i_x base_i_y = corner2_i_y base_h_x = corner2_h_x base_h_y = corner2_h_y for c_x in range(0, self.n_cell_x): base_i_x = np.hstack([base_i_x, 3 * c_x + tb2_i_x]) base_i_y = np.hstack([base_i_y, tb2_i_y]) base_h_x = np.hstack([base_h_x, 3 * c_x + tb2_h_x]) base_h_y = np.hstack([base_h_y, tb2_h_y]) for c_x in range(0, self.n_cell_x - 1): base_i_x = np.hstack([base_i_x, 3 * c_x + right2_i_x]) base_i_y = np.hstack([base_i_y, right2_i_y]) base_h_x = np.hstack([base_h_x, 3 * c_x + right2_h_x]) base_h_y = np.hstack([base_h_y, right2_h_y]) for c_y in range(0, self.n_cell_y - 1): print('c_y', c_y) base_i_x = np.hstack([base_i_x, up2_i_x]) base_i_y = np.hstack([base_i_y, c_y + up2_i_y]) base_h_x = np.hstack([base_h_x, up2_h_x]) base_h_y = np.hstack([base_h_y, c_y + up2_h_y]) f = self.factory_task cp = f.formed_object m_nodes = f.N_i[base_i_x, base_i_y] n_nodes = f.N_h[base_h_x, base_h_y] psi_lines = cp.NN_L[m_nodes, n_nodes].flatten() print('psi_lines', psi_lines) cm_nodes = [f.N_i[0, 0], f.N_i[-1, 1]] cn_nodes = [f.N_h[1, 1], f.N_h[2, 1]] cpsi_lines = cp.NN_L[cm_nodes, cn_nodes] print('cpsi_lines', cpsi_lines) N_h = f.N_h N_i = f.N_i N_v = f.N_v fixed_nodes_x = fix( N_i[1, (0, 1)], (0)) fixed_nodes_y = fix( [N_h[1, 1].flatten()], (1)) fixed_nodes_z = fix( list(N_v[[0, 0, -1], [0, -1, 0]].flatten()), (2) ) link_nodes_yz = link( list(N_v[[0, 0], [0, -1]].flatten()) + list(N_h[[0, 0], [0, -1]].flatten()), (1, 2), 1.0, list(N_i[[0, 0], [0, -1]].flatten()) + list(N_h[[-1, -1], [0, -1]].flatten()), (1, 2), -1.0, ) link_nodes_z = link( N_h[1, 1], 2, 1.0, N_h[2, 1], 2, -1.0, ) dof_constraints = fixed_nodes_x + fixed_nodes_z + fixed_nodes_y + \ link_nodes_yz + link_nodes_z gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) def FN(psi): return lambda t: psi * t cpsi_constr = [([(cpsi_line, 1.0)], FN(0.99 * np.pi)) for cpsi_line in cpsi_lines] gu_psi_constraints = \ GuPsiConstraints(forming_task=self.init_displ_task, psi_constraints=cpsi_constr) gu_constant_length = GuConstantLength() 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=500, debug_level=0) st = SimulationTask(previous_task=self.init_displ_task, config=sim_config, n_steps=self.n_fold_steps) cp = st.formed_object N_down = np.hstack([N_h[::3, :].flatten(), N_i[1::3, :].flatten() ]) print('N_down', N_down) N_up = np.hstack([N_i[::3, :].flatten(), N_i[2::3, :].flatten(), N_v[:, :].flatten()]) print('N_up', N_up) cp.u[N_down, 2] -= self.d_down cp.u[N_up, 2] += self.d_up cp.u[:, 2] += self.d_down return st
return cp_factory if __name__ == '__main__': cp_factory_task = create_cp_factory() cp = cp_factory_task.formed_object # Link the crease factory with the constraint client gu_constant_length = GuConstantLength() psi_max = np.pi * .49 gu_psi_constraints = \ GuPsiConstraints(forming_task=cp_factory_task, psi_constraints=[([(2, 1.0)], 0.0), ([(7, 1.0)], 0.0), ([(4, 1.0)], 0.0), ([(6, 1.0)], 0.0), ([(3, 1.0)], lambda t: -psi_max * t), #([(5, 1.0)], lambda t: psi_max * t), ]) dof_constraints = fix([0], [1]) + fix([1], [0, 1, 2]) \ + fix([2, 4], [2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(goal_function_type='none', gu={'cl': gu_constant_length, 'u': gu_dof_constraints, 'psi': gu_psi_constraints}, acc=1e-8, MAX_ITER=100) sim_task = SimulationTask(previous_task=cp_factory_task, config=sim_config,