def _get_load_task(self): self.fold_task.x_1 dof_constraints = fix( [0, 2, 6], [2]) + fix([0, 2], [1]) + fix([6], [0]) 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, 'dofs': gu_dof_constraints}, use_f_du=True, acc=1e-8, MAX_ITER=1000, debug_level=0) FN = lambda F: lambda t: t * F F_ext_list = [(n, 2, FN(-1)) for n in [1, 3]] print 'F_ext_list', F_ext_list fu_tot_poteng = FuPotEngTotal(kappa=10, fu_factor=1, F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=1) cp = st.formed_object cp.x_0 = self.fold_task.x_1 cp.u[:, :] = 0.0 #cp.u[(4, 5), 2] = -0.001 #cp.u[(1, 3), 2] = -0.001 fu_tot_poteng.forming_task = st return st
def _get_fold_task(self): self.init_displ_task.x_1 cp = self.factory_task n_t_h = cp.N_h[:, -1].flatten() n_b_h = cp.N_h[:, 0].flatten() n_lr_h = cp.N_h[(0, -1), :].flatten() u_max = self.u_x dof_constraints = fix(n_b_h, [1], lambda t: t * u_max) + fix(n_lr_h, [2]) + \ fix(n_t_h, [1], lambda t: t * -u_max) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='gravity potential energy', gu={'cl': gu_constant_length, 'dofs': gu_dof_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_steps) st.formed_object.u[(4, 5), 2] = 0.001 return st
def _get_fold_task(self): x_1 = self.init_displ_task.x_1 cp = self.factory_task n_l_h = cp.N_h[0, :].flatten() n_r_h = cp.N_h[-1, :].flatten() n_lr_h = cp.N_h[(0, -1), :].flatten() n_fixed_y = cp.N_h[(0, -1), 1].flatten() u_max = self.u_x dof_constraints = fix(n_l_h, [0], lambda t: t * u_max) + fix(n_lr_h, [2]) + \ fix(n_fixed_y, [1]) + fix(n_r_h, [0], lambda t: t * -u_max) + \ link(cp.N_v[0, :].flatten(), 0, 1.0, cp.N_v[1, :].flatten(), 0, 1.0) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig( goal_function_type='gravity potential energy', gu={ 'cl': gu_constant_length, 'dofs': gu_dof_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_turn_task2(self): self.fold_task.x_1 u_z = 0.1 fixed_nodes_xzy = fix([7, 19], (0, 1, 2)) lift_nodes_z = fix([3, 15], (2), lambda t: t * u_z) dof_constraints = fixed_nodes_xzy + lift_nodes_z 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, 'dofs': gu_dof_constraints }, acc=1e-5, MAX_ITER=1000, debug_level=0) load_nodes = [] FN = lambda F: lambda t: t * F F_ext_list = [(n, 2, FN(-10)) for n in load_nodes] fu_tot_poteng = FuPotEngTotal(kappa=np.array([1000]), F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=1) fu_tot_poteng.forming_task = st cp = st.formed_object cp.u[(3, 15), 2] = u_z return st
def _get_turn_task(self): self.fold_task.x_1 fixed_nodes_z = fix([0, 1, 2, 20, 21, 22], (0, 2)) fixed_nodes_y = fix([1, 21], (1)) front_nodes = fix([8, 14], (0, 1, 2)) dof_constraints = fixed_nodes_z + fixed_nodes_y + \ front_nodes gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig( goal_function_type='gravity potential energy', gu={ 'cl': gu_constant_length, 'dofs': gu_dof_constraints }, acc=1e-5, MAX_ITER=500, debug_level=0) st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=2) cp = st.formed_object cp.x_0 = self.fold_task.x_1 cp.x_0[:, 2] *= -1 cp.u[:, :] = 0.0 if self.stiffening_boundary: cp.u[tuple(np.arange(47, 47 + 32)), 2] = -0.2 return st
def _get_load_task(self): self.fold_task.x_1 dof_constraints = fix( [0, 2, 6], [2]) + fix([0, 2], [1]) + fix([6], [0]) 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, 'dofs': gu_dof_constraints}, use_f_du=True, acc=1e-8, MAX_ITER=1000, debug_level=0) FN = lambda F: lambda t: t * F F_ext_list = [(n, 2, FN(-1)) for n in [1, 3]] print('F_ext_list', F_ext_list) fu_tot_poteng = FuPotEngTotal(kappa=10, fu_factor=1, F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=1) cp = st.formed_object cp.x_0 = self.fold_task.x_1 cp.u[:, :] = 0.0 #cp.u[(4, 5), 2] = -0.001 #cp.u[(1, 3), 2] = -0.001 fu_tot_poteng.forming_task = st 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) 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=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_load_task(self): self.fold_task.x_1 cp = self.factory_task n_l_h = cp.N_h[0, (0, -1)].flatten() n_r_h = cp.N_h[-1, (0, -1)].flatten() dof_constraints = fix(n_l_h, [0, 1, 2]) + fix(n_r_h, [0, 1, 2]) 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, 'dofs': gu_dof_constraints}, use_f_du=True, acc=1e-4, MAX_ITER=1000, debug_level=0) F_ext_list = [(n, 2, 100.0) for n in cp.N_h[1, :]] fu_tot_poteng = FuPotEngTotal(kappa=np.array([10]), F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=1) cp = st.formed_object cp.x_0 = self.fold_task.x_1 cp.u[:, :] = 0.0 fu_tot_poteng.forming_task = st return st
def _get_fold_task(self): self.init_displ_task.x_1 # cp = self.init_displ_task.formed_object # print 'nodes', x_1[(0, 1, 2, 20, 21, 22), 2] # cp.u[(26, 25, 24, 23), 2] = -0.01 # cp.x[(0, 1, 2, 20, 21, 22), 2] = 0.0 u_max = self.u_x fixed_nodes_z = fix( [0, 1, 2, 20, 21, 22], (2)) # fixed_nodes_x = fix( # [8, 9, 10, 11, 12, 13, 14], (0)) fixed_nodes_y = fix( [1, 21], (1)) # 5, 11, 17, control_left = fix( [0, 1, 2], (0), lambda t: t * u_max) control_right = fix( [20, 21, 22], (0), lambda t: -t * u_max) dof_constraints = fixed_nodes_z + fixed_nodes_y + \ control_left + control_right gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='gravity potential energy', gu={'cl': gu_constant_length, 'dofs': gu_dof_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_load_task(self): self.fold_task.x_1 cp = self.factory_task n_l_h = cp.N_h[0, (0, -1)].flatten() n_r_h = cp.N_h[-1, (0, -1)].flatten() dof_constraints = fix(n_l_h, [0, 1, 2]) + fix(n_r_h, [0, 1, 2]) 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, 'dofs': gu_dof_constraints }, use_f_du=True, acc=1e-4, MAX_ITER=1000, debug_level=0) F_ext_list = [(n, 2, 100.0) for n in cp.N_h[1, :]] fu_tot_poteng = FuPotEngTotal(kappa=np.array([10]), F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=1) cp = st.formed_object cp.x_0 = self.fold_task.x_1 cp.u[:, :] = 0.0 fu_tot_poteng.forming_task = st return st
def _get_turn_task(self): self.fold_task.x_1 fixed_nodes_z = fix( [0, 1, 2, 20, 21, 22], (0, 2)) fixed_nodes_y = fix( [1, 21], (1)) front_nodes = fix( [8, 14], (0, 1, 2)) dof_constraints = fixed_nodes_z + fixed_nodes_y + \ front_nodes gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='gravity potential energy', gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints}, acc=1e-5, MAX_ITER=500, debug_level=0) st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=1) cp = st.formed_object cp.x_0 = self.fold_task.x_1 cp.x_0[:, 2] *= -1 cp.u[:, :] = 0.0 cp.u[tuple(np.arange(47, 47 + 32)), 2] = -0.2 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_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_load_task(self): self.turn_task.x_1 fixed_nodes_yz = fix([0, 2, 20, 22], (1, 2)) # + \ fixed_nodes_x = fix([0, 2, 20, 22], (0)) # + \ # fix([1, 21], [0, 2]) link_bnd = link([48, 49, 50, 56, 57, 58, 64, 65, 66, 72, 73, 74], [0, 1, 2], 1.0, [51, 52, 53, 59, 60, 61, 67, 68, 69, 75, 76, 77], [0, 1, 2], -1.0) dof_constraints = fixed_nodes_x + fixed_nodes_yz + link_bnd 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, 'dofs': gu_dof_constraints}, acc=1e-5, MAX_ITER=1000, debug_level=0) load_nodes = [10, 11, 12] FN = lambda F: lambda t: t * F F_ext_list = [(n, 2, FN(-10)) for n in load_nodes] fu_tot_poteng = FuPotEngTotal(kappa=np.array([10]), F_ext_list=F_ext_list) # (2 * n, 2, -1)]) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.turn_task, config=sim_config, n_steps=1) fu_tot_poteng.forming_task = st cp = st.formed_object cp.x_0 = self.turn_task.x_1 cp.u[:, :] = 0.0 return st
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_load_task(self): self.fold_task.x_1 cp = self.factory_task n_l_h = cp.N_h[0, (0, -1)].flatten() n_r_h = cp.N_h[-1, (0, -1)].flatten() dof_constraints = fix( [0, 2, 4], [0, 1, 2]) + fix([20, 22, 24], [0, 1, 2]) 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, 'dofs': gu_dof_constraints}, acc=1e-6, MAX_ITER=1000, debug_level=0) FN = lambda F: lambda t: t * F F_max = 20 F_ext_list = [(cp.N_h[2, :], 2, FN(F_max))] fu_tot_poteng = FuPotEngTotal(kappa=np.array([10]), F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=10) cp = st.formed_object cp.x_0 = self.fold_task.x_1 cp.u[:, :] = 0.0 cp.u[[10, 11, 12, 13, 14], 2] = 0.001 fu_tot_poteng.forming_task = st return st
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_turn_task2(self): self.fold_task.x_1 u_z = 0.1 fixed_nodes_xzy = fix([7, 19], (0, 1, 2)) lift_nodes_z = fix([3, 15], (2), lambda t: t * u_z) dof_constraints = fixed_nodes_xzy + lift_nodes_z 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, 'dofs': gu_dof_constraints}, acc=1e-5, MAX_ITER=1000, debug_level=0) load_nodes = [] FN = lambda F: lambda t: t * F F_ext_list = [(n, 2, FN(-10)) for n in load_nodes] fu_tot_poteng = FuPotEngTotal(kappa=np.array([1000]), F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=1) fu_tot_poteng.forming_task = st cp = st.formed_object cp.u[(3, 15), 2] = u_z return st
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_deform_task(self): ft = self.factory_task 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) 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-5, 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=self.init_displ_task, config=sim_config, n_steps=self.n_steps) # # 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 return st
def _get_load_task(self): self.turn_task.x_1 fixed_nodes_yz = fix([0, 2, 20, 22], (1, 2)) # + \ fixed_nodes_x = fix([0, 2, 20, 22], (0)) # + \ # fix([1, 21], [0, 2]) link_bnd = [] if self.stiffening_boundary: link_bnd = link([48, 49, 50, 56, 57, 58, 64, 65, 66, 72, 73, 74], [0, 1, 2], 1.0, [51, 52, 53, 59, 60, 61, 67, 68, 69, 75, 76, 77], [0, 1, 2], -1.0) dof_constraints = fixed_nodes_x + fixed_nodes_yz + link_bnd 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, 'dofs': gu_dof_constraints }, acc=1e-5, MAX_ITER=1000, debug_level=0) def FN(F): return lambda t: t * F H = 0 P = 3.5 * self.load_factor F_ext_list = [(33, 2, FN(-P)), (34, 2, FN(-P)), (11, 2, FN(-P)), (39, 2, FN(-P)), (40, 2, FN(-P)), (4, 0, FN(0.1609 * H)), (4, 2, FN(-0.2385 * H)), (10, 2, FN(-0.3975 * H)), (16, 0, FN(-0.1609 * H)), (16, 2, FN(-0.2385 * H)), (6, 0, FN(0.1609 * H)), (6, 2, FN(-0.2385 * H)), (12, 2, FN(-0.3975 * H)), (18, 0, FN(-0.1609 * H)), (18, 2, FN(-0.2385 * H))] fu_tot_poteng = FuPotEngTotal(kappa=np.array([5.28]), F_ext_list=F_ext_list) # load_nodes = [10, 11, 12] # FN = lambda F: lambda t: t * F # F_ext_list = [(n, 2, FN(-10)) for n in load_nodes] # fu_tot_poteng = FuPotEngTotal(kappa=np.array([10]), # F_ext_list=F_ext_list) # (2 * n, 2, -1)]) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.turn_task, config=sim_config, n_steps=self.n_load_steps) fu_tot_poteng.forming_task = st cp = st.formed_object cp.x_0 = self.turn_task.x_1 cp.u[:, :] = 0.0 return st
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_load_task(self): self.turn_task.x_1 fixed_nodes_yz = fix([0, 2, 20, 22], (1, 2)) # + \ fixed_nodes_x = fix([0, 2, 20, 22], (0)) # + \ fixed_nodes_middle = fix([1, 21], [0, 1, 2]) # 'Gesamter Randbereich' # link_bnd = link([48, 49, 50, 56, 57, 58, 64, 65, 66, 72, 73, 74, 71, 55], # [0, 1, 2], 1.0, # [51, 52, 53, 59, 60, 61, 67, # 68, 69, 75, 76, 77, 63, 47], # [0, 1, 2], -1.0) # 'Ohne mittlere Randknoten' # link_bnd = link([48, 49, 50, 56, 57, 58, 64, 65, 66, 72, 73, 74], # [0, 1, 2], 1.0, # [51, 52, 53, 59, 60, 61, 67, # 68, 69, 75, 76, 77], # [0, 1, 2], -1.0) # 'Ohne aeussere Randknoten' # link_bnd = link([48, 49, 56, 57, 64, 65, 72, 73, 71, 55], # [0, 1, 2], 1.0, # [51, 52, 59, 60, 67, # 68, 75, 76, 63, 47], # [0, 1, 2], -1.0) # + link_bnd + # fixed_nodes_middle dof_constraints = fixed_nodes_x + fixed_nodes_yz 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, 'dofs': gu_dof_constraints}, acc=1e-8, MAX_ITER=1000, debug_level=0) FN = lambda F: lambda t: t * F H = 0 P = 3.5 F_ext_list = [(33, 2, FN(-P)), (34, 2, FN(-P)), (11, 2, FN(-P)), (39, 2, FN(-P)), (40, 2, FN(-P)), (4, 0, FN(0.1609 * H)), (4, 2, FN(-0.2385 * H)), (10, 2, FN(-0.3975 * H)), (16, 0, FN(-0.1609 * H)), (16, 2, FN(-0.2385 * H)), (6, 0, FN(0.1609 * H)), (6, 2, FN(-0.2385 * H)), (12, 2, FN(-0.3975 * H)), (18, 0, FN(-0.1609 * H)), (18, 2, FN(-0.2385 * H))] fu_tot_poteng = FuPotEngTotal(kappa=np.array([5.28]), F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.turn_task, config=sim_config, n_steps=1) fu_tot_poteng.forming_task = st cp = st.formed_object cp.x_0 = self.turn_task.x_1 cp.u[:, :] = 0.0 return st
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) FN = lambda psi, start_t, end_t: 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_deform_task(self): ft = self.factory_task 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) 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-5, 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=self.init_displ_task, config=sim_config, n_steps=self.n_steps) # # 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 return st
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): self.init_displ_task.x_1 u_max = self.u_max fixed_nodes_x = fix([12, 14], (0)) fixed_nodes_z = fix([1, 7, 10, 16, 19, 25], (2)) fixed_nodes_y = fix([1, 25], (1)) link_mid = link((6, 7, 8, 15, 16, 17, 24, 25, 26), (0), 1.0, (0, 1, 2, 9, 10, 11, 18, 19, 20), (0), -1.0, lambda t: -t * u_max) sym_y = link([0, 6, 9, 15, 18, 24], [2], 1.0, [2, 8, 11, 17, 20, 26], [2], -1.0) dof_constraints = fixed_nodes_x + fixed_nodes_z + fixed_nodes_y + \ link_mid + sym_y gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig( goal_function_type='gravity potential energy', gu={ 'cl': gu_constant_length, 'dofs': gu_dof_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 cp.u[( 4, 13, 22, 3, 12, 21, 5, 14, 23, 28, 30, 36, 42, 27, 29, 35, 41, ), 2] -= 0.2 return st
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_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_load_task(self): self.turn_task.x_1 fixed_nodes_yz = fix([0, 2, 20, 22], (1, 2)) # + \ fixed_nodes_x = fix([0, 2, 20, 22], (0)) # + \ # fix([1, 21], [0, 2]) link_bnd = [] if self.stiffening_boundary: link_bnd = link([48, 49, 50, 56, 57, 58, 64, 65, 66, 72, 73, 74], [0, 1, 2], 1.0, [51, 52, 53, 59, 60, 61, 67, 68, 69, 75, 76, 77], [0, 1, 2], -1.0) dof_constraints = fixed_nodes_x + fixed_nodes_yz + link_bnd 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, 'dofs': gu_dof_constraints}, acc=1e-5, MAX_ITER=1000, debug_level=0) FN = lambda F: lambda t: t * F H = 0 P = 3.5 * self.load_factor F_ext_list = [(33, 2, FN(-P)), (34, 2, FN(-P)), (11, 2, FN(-P)), (39, 2, FN(-P)), (40, 2, FN(-P)), (4, 0, FN(0.1609 * H)), (4, 2, FN(-0.2385 * H)), (10, 2, FN(-0.3975 * H)), (16, 0, FN(-0.1609 * H)), (16, 2, FN(-0.2385 * H)), (6, 0, FN(0.1609 * H)), (6, 2, FN(-0.2385 * H)), (12, 2, FN(-0.3975 * H)), (18, 0, FN(-0.1609 * H)), (18, 2, FN(-0.2385 * H))] fu_tot_poteng = FuPotEngTotal(kappa=np.array([5.28]), F_ext_list=F_ext_list) # load_nodes = [10, 11, 12] # FN = lambda F: lambda t: t * F # F_ext_list = [(n, 2, FN(-10)) for n in load_nodes] # fu_tot_poteng = FuPotEngTotal(kappa=np.array([10]), # F_ext_list=F_ext_list) # (2 * n, 2, -1)]) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.turn_task, config=sim_config, n_steps=self.n_load_steps) fu_tot_poteng.forming_task = st cp = st.formed_object cp.x_0 = self.turn_task.x_1 cp.u[:, :] = 0.0 return st
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 * 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_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_task(self): self.init_displ_task.x_1 # cp = self.init_displ_task.formed_object # print 'nodes', x_1[(0, 1, 2, 20, 21, 22), 2] # cp.u[(26, 25, 24, 23), 2] = -0.01 # cp.x[(0, 1, 2, 20, 21, 22), 2] = 0.0 u_max = self.u_x fixed_nodes_z = fix([0, 1, 2, 20, 21, 22], (2)) # fixed_nodes_x = fix( # [8, 9, 10, 11, 12, 13, 14], (0)) fixed_nodes_y = fix([1, 21], (1)) # 5, 11, 17, control_left = fix([0, 1, 2], (0), lambda t: t * u_max) control_right = fix([20, 21, 22], (0), lambda t: -t * u_max) front_node = fix([8], (1), lambda t: t * 0.03) back_node = fix([14], (1), lambda t: -t * 0.03) dof_constraints = fixed_nodes_z + fixed_nodes_y + \ control_left + control_right + front_node + back_node gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig( goal_function_type='gravity potential energy', gu={ 'cl': gu_constant_length, 'dofs': gu_dof_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_fold_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_load_task(self): self.fold_task.x_1 cp = self.factory_task n_l_h = cp.N_h[0, (0, -1)].flatten() n_r_h = cp.N_h[-1, (0, -1)].flatten() n_fixed_y = cp.N_h[(0, -1), 1].flatten() n_scheitel = cp.N_h[2, :] n_aussen = cp.N_v dof_constraints = fix( n_l_h, [0, 2]) + fix(n_r_h, [0, 2]) + fix(n_fixed_y, [0, 1]) 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, 'dofs': gu_dof_constraints}, acc=1e-10, MAX_ITER=1000, debug_level=0) FN = lambda F: lambda t: t * F F_max = 2 F_min = 1 F_ext_list = [(7, 2, FN(F_max)), (6, 2, FN(F_min)), (8, 2, FN(F_min))] fu_tot_poteng = FuPotEngTotal(kappa=np.array([4.97]), F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.fold_task, config=sim_config, n_steps=10) cp = st.formed_object cp.L = np.vstack([cp.L, np.array([[6, 7], [7, 8]], dtype='int_')]) cp.x_0 = self.fold_task.x_1 cp.u[:, :] = 0.0 cp.u[[6, 7, 8], 2] = 0.0001 fu_tot_poteng.forming_task = st return st
def _get_fold_task(self): pt = self.init_displ_task cp = self.init_displ_task.formed_object cp.u[(26, 25, 24, 23), 2] = 0.5 H = pt.x_1[42, 2] Z0_r = pt.x_1[7, 2] fixed_nodes_z = fix( [31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42], (2), lambda t: H) fixed_nodes_xr = fix( [3, 4, 5, 6, 7], (2), lambda t: Z0_r - t * 0.32) fixed_nodes_xl = fix( [15, 16, 17, 18, 19], (2), lambda t: Z0_r - t * 0.32) fixed_nodes_y = fix( [42, 36], (1)) fixed_nodes_x = fix( [36], (0)) front_facet = link([13], 2, 1.0, [14], 2, -1.0) back_facet = link([8], 2, 1.0, [9], 2, -1.0) dof_constraints = fixed_nodes_z + fixed_nodes_xl + fixed_nodes_xr +\ front_facet + back_facet +\ fixed_nodes_y + fixed_nodes_x gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='gravity potential energy', gu={'cl': gu_constant_length, 'dofs': gu_dof_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_fold_task(self): pt = self.init_displ_task cp = self.init_displ_task.formed_object cp.u[(26, 25, 24, 23), 2] = 0.5 H = pt.x_1[42, 2] Z0_r = pt.x_1[7, 2] fixed_nodes_z = fix([31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42], (2), lambda t: H) fixed_nodes_xr = fix([3, 4, 5, 6, 7], (2), lambda t: Z0_r - t * 0.32) fixed_nodes_xl = fix([15, 16, 17, 18, 19], (2), lambda t: Z0_r - t * 0.32) fixed_nodes_y = fix([42, 36], (1)) fixed_nodes_x = fix([36], (0)) front_facet = link([13], 2, 1.0, [14], 2, -1.0) back_facet = link([8], 2, 1.0, [9], 2, -1.0) dof_constraints = fixed_nodes_z + fixed_nodes_xl + fixed_nodes_xr +\ front_facet + back_facet +\ fixed_nodes_y + fixed_nodes_x gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig( goal_function_type='gravity potential energy', gu={ 'cl': gu_constant_length, 'dofs': gu_dof_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_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): x_1 = self.init_displ_task.x_1 cp = self.factory_task n_l_h = cp.N_h[0, :].flatten() n_r_h = cp.N_h[-1, :].flatten() n_lr_h = cp.N_h[(0, -1), :].flatten() n_fixed_y = cp.N_h[(0, -1), 1].flatten() u_max = self.u_x dof_constraints = fix([0, 2, 4], [0], lambda t: t * u_max) + fix([0, 2, 4, 20, 22, 24], [2]) + \ fix([2, 22], [1]) + fix([20, 22, 24], [0], lambda t: t * -u_max) + \ link(cp.N_v[0, :].flatten(), 0, 1.0, cp.N_v[1, :].flatten(), 0, 1.0) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='gravity potential energy', gu={'cl': gu_constant_length, 'dofs': gu_dof_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_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 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] -= self.d_down cp.u[N_up, 2] += self.d_up return st
cp_factory = CustomCPFactory(formed_object=cp) return cp_factory if __name__ == '__main__': n = 10 cp_factory_task = create_cp_factory(n=n, b=2.0) cp = cp_factory_task.formed_object #cp.x_0[4, 2] = 0.3 # 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([n + 1], [2]) # + fix([n * 2], [1]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(goal_function_type='total potential energy', debug_level=0, use_f_du=True, gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints}, acc=1e-7, MAX_ITER=1000) F_nodes = np.linspace(0, -10, n) FN = lambda F: lambda t: t * F F_ext_list = [(i + 1, 2, FN(F_n)) for i, F_n in enumerate(F_nodes)] fu_tot_poteng = FuPotEngTotal(kappa=np.array([5000.0]), fu_factor=1,
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_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_self_weight_cntl(self): self.init_displ_task.x_1 f = self.factory_task cp = f.formed_object 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, -1], [0, -1, 0, -1]].flatten()) + list(N_i[[0, 0, -1, -1], [0, -1, 0, -1]].flatten()), (2) ) cntl_z = fix(N_h[(1, 2), 1], 2, lambda t: 0.1 * t) link_nodes_y = link( list(N_v[[0, -1], [0, -1]].flatten()), 1, 1.0, list(N_i[[0, -1], [0, -1]].flatten()), 1, -1.0, ) link_nodes_z = link( list(N_h[[1, 1, 1], [0, 1, -1]].flatten()), 2, 1.0, list(N_h[[2, 2, 2], [0, 1, -1]].flatten()), 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_z + \ link_nodes_y # link_nodes_yz + link_nodes_z 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, 'dofs': gu_dof_constraints, }, acc=1e-5, MAX_ITER=1000, debug_level=0) def FN(F): return lambda t: t * F H = 0 P = 0.1 F_ext_list = [(N_i[1, 1], 2, FN(-P)), (N_i[1, -1], 2, FN(-P)), (N_h[(0, -1), 0], 2, FN(-P)), (N_h[(0, -1), -1], 2, FN(-P)) ] fu_tot_poteng = FuPotEngTotal(kappa=0.0, thickness=0.01, rho=23.6, F_ext_list=F_ext_list) sim_config._fu = fu_tot_poteng st = SimulationTask(previous_task=self.init_displ_task, config=sim_config, n_steps=self.n_fold_steps) fu_tot_poteng.forming_task = st 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
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
def _get_fold_task(self): self.init_displ_task.x_1 u_max = self.u_max fa = self.factory_task N_h = fa.N_h N_i = fa.N_i N_v = fa.N_v n_x, n_y = N_h.shape mid_n_x = n_x / 2 i_fixed_x = N_h[mid_n_x, (0, -1)] fixed_nodes_x = fix( i_fixed_x, (0)) n_x, n_y = N_i.shape mid_n_y = n_y / 2 i_fixed_z = np.hstack([N_i[:-1:3, mid_n_y], N_i[1::3, mid_n_y]]) i_fixed_z = np.hstack([N_i[:-1:6, mid_n_y], N_i[1::6, mid_n_y]]) fixed_nodes_z = fix( i_fixed_z, (2)) i_fixed_y = N_i[(1, -2), mid_n_y] fixed_nodes_y = fix( i_fixed_y, (1)) i_link_xh_r = N_h[2::3, :] i_link_xh_l = N_h[0:-2:3, :] i_link_xi_r = N_i[3::3, :] i_link_xi_l = N_i[1:-2:3, :] link_mid = link( np.hstack([i_link_xh_r.flatten(), i_link_xi_r.flatten()]), (0), 1.0, np.hstack([i_link_xh_l.flatten(), i_link_xi_l.flatten()]), (0), -1.0, lambda t: -t * u_max ) sym_y = link( N_h[(0, -1), 0], [2], 1.0, N_h[(0, -1), -1], [2], -1.0 ) dof_constraints = fixed_nodes_x + fixed_nodes_z + fixed_nodes_y + \ link_mid + sym_y gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) gu_constant_length = GuConstantLength() sim_config = SimulationConfig(goal_function_type='gravity potential energy', gu={'cl': gu_constant_length, 'dofs': gu_dof_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 d_u = 0.02 i_down_h = N_h[1::3, :] i_down_i = N_i[2::3, :] i_left = N_v[0, :] i_right = N_v[-1, :] cp.u[np.hstack([i_down_h.flatten(), i_down_i.flatten()]), 2] -= d_u cp.u[i_left, 0] -= d_u cp.u[i_right, 0] += d_u # cp.u[( # 36, 48, 57, 39, # 37, 49, 58, 40, # 38, 50, 59, 41, # 4, 16, 28, # 5, 17, 29, # 6, 18, 30, # 7, 19, 31, # ), 2] -= 0.2 return st
cp.u[3, 2] = 0.0 cp.u[3, 0] = 0.0 print 'F_normals', cp.norm_F_normals print 'iL_psi', cp.iL_psi print 'iL_psi_du', cp.iL_psi_du psi_max = 3.999 * np.pi / 4.0 psi_constr = [([(i, 1.0)], lambda t: psi_max * t) for i in cp.iL] gu_psi_constraints = \ GuPsiConstraints(forming_task=cpf, 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) st = SimulationTask(previous_task=cpf, config=sim_config, n_steps=10) st.u_1
] ) cp_factory = CustomCPFactory(formed_object=cp) 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() dof_constraints = fix([1], [0, 1, 2]) + fix([0], [2]) + fix([2], [0, 2]) gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(goal_function_type='total potential energy', debug_level=0, use_f_du=True, gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints}, acc=1e-7, MAX_ITER=1000) FN = lambda F: lambda t: t * F P = 1 F_ext_list = [(3, 2, FN(-P))] fu_tot_poteng = FuPotEngTotal(kappa=np.array([100]), fu_factor=1,
) cp_factory = CustomCPFactory(formed_object=cp) # end 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() u_max = 0.8 displ_cntl = fix([3], 2, lambda t: u_max * t) dof_constraints = fix([0], [0, 1, 2]) + fix([1], [1, 2]) \ + fix([2], [2]) + displ_cntl gu_dof_constraints = GuDofConstraints(dof_constraints=dof_constraints) sim_config = SimulationConfig(goal_function_type='none', gu={'cl': gu_constant_length, 'dofs': gu_dof_constraints}, acc=1e-5, MAX_ITER=10) sim_task = SimulationTask(previous_task=cp_factory_task, config=sim_config, n_steps=5) sim_task.u_1 cp = sim_task.formed_object
plt.show() # 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), ]) 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, n_steps=25) cp.u[(0, 3), 2] = -0.1 cp.u[(1), 2] = 0.1 sim_task.u_1 cp = sim_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, n_steps=25) cp.u[(0, 3), 2] = -0.1 cp.u[(1), 2] = 0.1 sim_task.u_1 cp = sim_task.formed_object
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
return cp_factory 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() F_u_fix = cp.F_N[0] 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() fu_node_dist = \ FuNodeDist(forming_task=cpf, L=[[4, 5]]) sim_config = SimulationConfig(goal_function_type='total potential energy', gu={ 'cl': gu_constant_length, 'gu': gu_dof_constraints }, acc=1e-5, MAX_ITER=100)