def reset_parameters(self): #Resets state variables to initial ones self.parameters = initialise.get_parameters()
def main(params): """This is the main loop which is repeated every timestep. Currently, this follows the Update Strain Last paradigm (does it?!?). :param mode: The name of the input file to use. :type mode: str :returns: int -- The return code. """ P, G, L = initialise.get_parameters(params) plot = Plotting() # if P.O.plot_material_points: plot.draw_material_points(L,P,G,'initial') while P.t <= P.t_f: # Time march G.wipe(P) # Discard previous grid P.update_forces() # update time dependent gravity L.update_forces(P, G) # pass body forces to material points L.get_reference_node(P, G) # Find node down and left L.get_basis_functions(P, G) # Make basis functions if P.O.check_positions: L.recover_position(P, G) # check basis functions L.get_nodal_mass_momentum(P, G) # Initialise from grid state if P.B.cyclic_lr: # G.apply_cyclic_BCs(P) G.make_cyclic(P, G, ['m', 'q']) L.update_stress_strain(P, G) # Update stress and strain L.get_nodal_forces(P, G) # Compute internal and external forces G.BCs(P) # Add external forces from BCs G.update_momentum(P) # Compute rate of momentum and update nodes G.calculate_gammadot(P, G) if P.segregate_grid: G.calculate_grad_gammadot(P, G) G.calculate_phi_increment(P) L.move_grainsize_on_grid(P, G) L.move_material_points( P, G) # Update material points (position and velocity) # Move/Remove any particles that have left the grid if P.B.outlet_left: L.outlet_left(P, G) if P.B.outlet_bottom: L.outlet_bottom(P, G) if P.B.inlet_right: L.inlet_right(P, G) if P.B.cyclic_lr: L.cyclic_lr(P, G) # Output related things if P.O.measure_energy: P.O.energy[P.tstep] = L.measure_elastic_energy(P, G) # measure energy print('{0:.4f}'.format(P.t * 100. / P.t_f) + '% Complete, t = ' + '{0:.4f}'.format(P.t) + ', g = ' + str(P.g), end='\r') if P.t % P.savetime < P.dt: if P.O.plot_gsd_mp: plot.draw_gsd_mp(L, P, G) if P.O.plot_gsd_grid: plot.draw_gsd_grid(L, P, G) # plot.draw_voronoi(P,G) if P.O.plot_continuum: plot.draw_continuum(G, P) if P.O.plot_material_points: plot.draw_material_points(L, P, G) if P.mode == 'anisotropy': plot.draw_gamma_dot(L, P, G) if P.O.measure_energy: P.O.measure_E(P, L) if P.O.save_u: plot.save_u(L, P, G) if P.O.save_s_bar: plot.save_s_bar(L, P, G) if P.mode == 'dp_unit_test' or P.mode == 'dp_rate_unit_test': P.O.store_p_q(P, G, L, P.tstep) if P.mode == 'pouliquen_unit_test': P.O.store_mu(P, G, L, P.tstep) # Increment time P.t += P.dt P.tstep += 1 # for p in range(P.phases): # if (P.S[p].law is 'von_mises' or P.S[p].law is 'dp') and not P.has_yielded: # if P.S[p].law is 'von_mises' and not P.has_yielded: # L.update_timestep(P) # Check for yielding and reduce timestep # Final things to do if P.O.plot_material_points: plot.draw_material_points(L, P, G, 'final') if P.O.measure_stiffness: P.O.measure_E(P, L) if P.O.measure_energy: plot.draw_energy(P) if P.O.plot_gsd_mp: plot.draw_gsd_mp(L, P, G) if P.O.plot_gsd_grid: plot.draw_gsd_grid(L, P, G) if P.O.save_u: plot.save_u(L, P, G) if P.O.save_s_bar: plot.save_s_bar(L, P, G) if P.mode == 'dp_unit_test' or P.mode == 'dp_rate_unit_test': P.O.draw_p_q(P, G, L, plot, P.tstep) if P.mode == 'pouliquen_unit_test': P.O.draw_mu(P, G, L, plot, P.tstep) print('') return 0
flux[boundary] = 0 return flux #, boundary def increment_grainsize(P, G): return KT(P, G, 0) + KT(P, G, 1) # return NT(P,G,0) + NT(P,G,1) if __name__ == "__main__": import initialise from numpy import random, maximum, ones from plotting import Plotting plot = Plotting() P, G, L = initialise.get_parameters(['bi_seg_test', '22', '2']) G.wipe(P) L.get_reference_node(P, G) # Find node down and left L.get_basis_functions(P, G) # Make basis functions L.get_nodal_mass_momentum(P, G) # Initialise from grid state plot.draw_gsd_grid(L, P, G) G.grad_gammadot = -1. * ones([P.G.ny * P.G.nx, 3]) # G.grad_gammadot[:,1] = 0 # P.dt *= 10 # G.phi = zeros_like(G.phi) # G.phi[40:120,0] = 0.5 # G.phi[:,1] = 1- G.phi[:,0] # G.phi[40:100,1] = 0 # P.c *= 100 while P.t <= P.t_f:
def main(params): """This is the main loop which is repeated every timestep. Currently, this follows the Update Strain Last paradigm (does it?!?). :param mode: The name of the input file to use. :type mode: str :returns: int -- The return code. """ P,G,L = initialise.get_parameters(params) plot = Plotting() # if P.O.plot_material_points: plot.draw_material_points(L,P,G,'initial') while P.t <= P.t_f:# Time march G.wipe(P) # Discard previous grid P.update_forces() # update time dependent gravity L.update_forces(P,G) # pass body forces to material points L.get_reference_node(P,G) # Find node down and left L.get_basis_functions(P,G) # Make basis functions if P.O.check_positions: L.recover_position(P,G) # check basis functions L.get_nodal_mass_momentum(P,G) # Initialise from grid state if P.B.cyclic_lr: G.make_cyclic(P,G,['m','q']) L.update_stress_strain(P,G) # Update stress and strain L.get_nodal_forces(P,G) # Compute internal and external forces G.BCs(P) # Add external forces from BCs G.update_momentum(P) # Compute rate of momentum and update nodes G.calculate_gammadot(P,G) if P.segregate_grid: G.update_pk(P,G) # NOTE: THIS IS BRAND NEW AND PROBABLY BROKEN #if P.B.cyclic_lr: G.make_cyclic(P,G,['phi','pk','s_bar']) # if P.B.cyclic_lr: G.make_cyclic(P,G,['pk']) # G.calculate_grad_gammadot(P,G) G.calculate_phi_increment(P) L.move_grainsize_on_grid(P,G) G.make_cyclic(P,G,['eta','dphi']) L.move_material_points(P,G) # Update material points (position and velocity) # Move/Remove any particles that have left the grid if P.B.outlet_left: L.outlet_left(P,G) if P.B.outlet_bottom: L.outlet_bottom(P,G) if P.B.inlet_right: L.inlet_right(P,G) if P.B.inlet_top: L.inlet_top(P,G) if P.B.cyclic_lr: L.cyclic_lr(P,G) # Output related things if P.O.measure_energy: P.O.energy[P.tstep] = L.measure_elastic_energy(P,G) # measure energy print('{0:.4f}'.format(P.t*100./P.t_f) + '% Complete, t = ' + '{0:.4f}'.format(P.t) + ', g = ' + str(P.g), end='\r') if P.t%P.savetime < P.dt: if P.O.plot_gsd_mp: plot.draw_gsd_mp(L,P,G) if P.O.plot_gsd_grid: plot.draw_gsd_grid(L,P,G) # plot.draw_voronoi(P,G) if P.O.plot_continuum: plot.draw_continuum(G,P) if P.O.plot_material_points: plot.draw_material_points(L,P,G) if P.mode == 'anisotropy': plot.draw_gamma_dot(L,P,G) if P.O.measure_energy: P.O.measure_E(L,P,G) # for [field,fieldname] in P.O.save_fields: P.O.save_field(L,P,G,field,fieldname) if P.O.save_u: plot.save_u(L,P,G) if P.O.save_s_bar: plot.save_s_bar(L,P,G) if P.O.save_density: plot.save_density(L,P,G) if P.mode == 'dp_unit_test' or P.mode == 'dp_rate_unit_test': P.O.store_p_q(P,G,L,P.tstep) if P.mode == 'pouliquen_unit_test': P.O.store_mu(P,G,L,P.tstep) # Increment time P.t += P.dt P.tstep += 1 if P.time_stepping == 'dynamic': P.update_timestep(P,G) # for p in range(P.phases): # if (P.S[p].law is 'von_mises' or P.S[p].law is 'dp') and not P.has_yielded: # if P.S[p].law is 'von_mises' and not P.has_yielded: # L.update_timestep(P) # Check for yielding and reduce timestep # Final things to do if P.O.plot_material_points: plot.draw_material_points(L,P,G,'final') if P.O.measure_stiffness: P.O.measure_E(L,P,G) if P.O.measure_energy: plot.draw_energy(P) if P.O.plot_gsd_mp: plot.draw_gsd_mp(L,P,G) if P.O.plot_gsd_grid: plot.draw_gsd_grid(L,P,G) if P.O.save_u: plot.save_u(L,P,G) if P.O.save_s_bar: plot.save_s_bar(L,P,G) if P.O.save_density: plot.save_density(L,P,G) if P.mode == 'dp_unit_test' or P.mode == 'dp_rate_unit_test': P.O.draw_p_q(P,G,L,plot,P.tstep) if P.mode == 'pouliquen_unit_test': P.O.draw_mu(P,G,L,plot,P.tstep) print('') return 0
f_c = 1. - 1./(S_1_bar*S) flux = P.c*f_c*g - P.D*dCdx flux[boundary] = 0 return flux#, boundary def increment_grainsize(P,G): return KT(P,G,0) + KT(P,G,1) # return NT(P,G,0) + NT(P,G,1) if __name__ == "__main__": import initialise from numpy import random, maximum, ones from plotting import Plotting plot = Plotting() P,G,L = initialise.get_parameters(['bi_seg_test','22','2']) G.wipe(P) L.get_reference_node(P,G) # Find node down and left L.get_basis_functions(P,G) # Make basis functions L.get_nodal_mass_momentum(P,G) # Initialise from grid state plot.draw_gsd_grid(L,P,G) G.grad_gammadot = -1.*ones([P.G.ny*P.G.nx,3]) # G.grad_gammadot[:,1] = 0 # P.dt *= 10 # G.phi = zeros_like(G.phi) # G.phi[40:120,0] = 0.5 # G.phi[:,1] = 1- G.phi[:,0] # G.phi[40:100,1] = 0 # P.c *= 100 while P.t <= P.t_f: