def compute_residual(self, y, PD_deck, t_n): residual = np.zeros((int(PD_deck.Num_Nodes))) #from elastic import elastic_material from viscoelastic import viscoelastic_material # Middle node doesn't move Mid_Node = int(PD_deck.Num_Nodes / 2) y[Mid_Node] = self.x[Mid_Node] #variables = elastic_material( PD_deck, self, y ) variables = viscoelastic_material(PD_deck, self, y, t_n) self.update_force_data(variables, t_n) self.update_ext_state_data(variables, t_n) self.update_ext_state_visco_data(variables, t_n) residual = np.zeros( ( int(PD_deck.Num_Nodes) ) ) # Middle node doesn't move Mid_Node = int(PD_deck.Num_Nodes/2) y[Mid_Node] = self.x[Mid_Node] # Choice of the material class if PD_deck.Material_Flag == "ELASTIC": from elastic import elastic_material variables = elastic_material( PD_deck, self, y ) self.update_force_data(variables, t_n) self.update_ext_state_data(variables, t_n) elif PD_deck.Material_Flag == "VISCOELASTIC": from viscoelastic import viscoelastic_material variables = viscoelastic_material( PD_deck, self, y, t_n) self.update_force_data(variables, t_n) self.update_ext_state_data(variables, t_n) self.update_ext_state_visco_data(variables, t_n) else: logger.error("There is a problem with the Type of Material in your XML deck.") # Computation of the residual for x_i in range(0, Mid_Node): residual[x_i] = variables.Ts[x_i] + self.b[x_i, t_n] for x_i in range(Mid_Node + 1, len(self.x)): residual[x_i] = variables.Ts[x_i] + self.b[x_i, t_n] # print residual return residual
def compute_residual(self, y, PD_deck, t_n): residual = np.zeros((int(PD_deck.Num_Nodes))) from elastic import elastic_material variables = elastic_material(PD_deck, self, y) self.update_force_data(variables, t_n) self.update_ext_state_data(variables, t_n) for x_i in range(PD_deck.Horizon_Factor, len(self.x)): if PD_deck.Loading_Flag == "RAMP": residual[x_i] = variables.Ts[x_i] + self.b[x_i, t_n] else: residual[x_i] = variables.Ts[x_i] # From johntfoster/1DPDpy, the residual should be set to 0 on # Boundary conditions for x_i in range(0, PD_deck.Horizon_Factor): #Clamped node residual[x_i] = 0 #Pulling nodes residual[len(self.x) - 1 - x_i] = 0 return residual
def quasi_static_solver(self, y, PD_deck): for t_n in range(1, PD_deck.Num_TimeStep): if PD_deck.Loading_Flag == "LINEAR_DISPLACEMENT": if t_n == 1: for x_i in range(0, PD_deck.Horizon_Factor): self.y[:, t_n] = self.x y = self.y[:, t_n] # Update the boundary conditions # Clamped Nodes for x_i in range(0, PD_deck.Horizon_Factor): y[x_i] = self.x[x_i] # Nodes being pulled for x_i in range(0, PD_deck.Horizon_Factor): y[len(self.x) - 1 - x_i] = self.x[len(self.x) - 1 - x_i] + self.displ_load[x_i, t_n] # Compute the forces and energy before solving the equilibrium # Else the force is null since equilibrium has been reached from elastic import elastic_material variables = elastic_material(PD_deck, self, y) self.update_energy_data(variables, t_n) print "t_n", t_n print "BEFORE:", y solver = scipy.optimize.root( self.compute_residual, y, args=( PD_deck, t_n), method='krylov', jac=None, tol=1.0e-12, callback=None, options={ 'maxiter': 1000, 'xtol': 1.0e-12, 'xatol': 1.0e-12, 'ftol': 1.0e-12}) print "AFTER:", solver.x # pdb.set_trace() if t_n + 1 > PD_deck.Num_TimeStep - 1: pass else: self.y[:, t_n + 1] = solver.x #y = solver.x + 0.1*random.uniform(-1,1)*PD_deck.Delta_x y = self.random_initial_guess(solver.x, PD_deck) # Notification if the solver failed if solver.success == "False": logger.warning("Convergence could not be reached.") else: logger.info(t_n, solver.success) self.update_displacements(t_n) return solver