def generate_temporal_vtk(output_path): for dtype in ("mesh", "particles"): group = VtkGroup("{}/pseudo_temporal_{}".format(output_path, dtype)) dfiles = sorted(glob.glob("{}/{}*".format(output_path, dtype))) for t, df in enumerate(dfiles): group.addFile(filepath = df, sim_time = t) group.save()
def generate_temporal_vtk(output_path): for dtype in ("mesh", "particles"): group = VtkGroup("{}/pseudo_temporal_{}".format(output_path, dtype)) dfiles = sorted(glob.glob("{}/{}*".format(output_path, dtype))) for t, df in enumerate(dfiles): group.addFile(filepath=df, sim_time=t) group.save()
y = numpy.zeros((radius_number + 1, angle_number + 1, node_number)) z = numpy.zeros((radius_number + 1, angle_number + 1, node_number)) # Group vtk_group = VtkGroup("cylinder/RiserGroup") # cnt=0 for time_index in range(time.size): for k in range(node_number): # Nodal displacement x_deviation = displacement_x[time_index][k] y_deviation = displacement_y[time_index][k] z_deviation = k/float(node_number) * length # # Trans for j in range(angle_number + 1): for i in range(radius_number + 1): rad = numpy.radians(angle_axis[j]) x[i, j, k] = radius_axis[i] * numpy.cos(rad) + x_deviation y[i, j, k] = radius_axis[i] * numpy.sin(rad) + y_deviation z[i, j, k] = z_deviation # Variables # # Output str1 = str(time_index) filename = 'cylinder/' + 'cylinder' + str1.zfill(4) filename_extension = filename + '.vts' gridToVTK(filename, x, y, z) vtk_group.addFile(filepath=filename_extension, sim_time=time[time_index]) vtk_group.save()
def main(): output_path = "D:\PyStokes\low_contrast" #output_path = "/home/luke/Working Grounds/PyStokes/low_contrast" output_time_interval = 0.1 output_timestep_interval = 1000 logging = False domain = {"xmin": 0., "xmax": 2., "nx": 41, "ymin": 0., "ymax": 2., "ny": 41} domain = create_domain(domain) domain["gravity"] = [0., -1.] dt = 0.0001 nt = 50000 max_time = 20 nit = 50 c = 0.01 rho = 1. u = create_variable_mesh(domain) v = create_variable_mesh(domain) p = create_variable_mesh(domain) particles = generate_particles(domain) timestep = 0 current_time = 0 dt_since_output = 0 mesh_group = VtkGroup("{}/temporal_mesh".format(output_path)) particles_group = VtkGroup("{}/temporal_particles".format(output_path)) while timestep < nt and current_time < max_time: print current_time, nu = interp_particles_to_mesh(particles, domain) u, v, p = solve_flow(u, v, dt, p, rho, nu, nit, domain) p -= np.min(p) # set min pressure to be 0 dt = calc_dt(c, u, v, domain) current_time += dt dt_since_output += dt # Interpolate velocities back to particles particles = interp_mesh_to_particles(particles, u, v, domain) # Advect particles particles = advect_particles_rk2(dt, particles, u, v, domain) if timestep % output_timestep_interval == 0 or dt_since_output > output_time_interval: point_data = {"visc" : nu[:,:,np.newaxis], "u" : u[:,:,np.newaxis], "v" : v[:,:,np.newaxis]} write_mesh(output_path, timestep, domain, point_data, mesh_group, current_time) write_particles(output_path, timestep, particles, particles_group, current_time) dt_since_output = 0 timestep += 1 mesh_group.save() particles_group.save() return 0
def main(): output_path = "D:\PyStokes\low_contrast" #output_path = "/home/luke/Working Grounds/PyStokes/low_contrast" output_time_interval = 0.1 output_timestep_interval = 1000 logging = False domain = { "xmin": 0., "xmax": 2., "nx": 41, "ymin": 0., "ymax": 2., "ny": 41 } domain = create_domain(domain) domain["gravity"] = [0., -1.] dt = 0.0001 nt = 50000 max_time = 20 nit = 50 c = 0.01 rho = 1. u = create_variable_mesh(domain) v = create_variable_mesh(domain) p = create_variable_mesh(domain) particles = generate_particles(domain) timestep = 0 current_time = 0 dt_since_output = 0 mesh_group = VtkGroup("{}/temporal_mesh".format(output_path)) particles_group = VtkGroup("{}/temporal_particles".format(output_path)) while timestep < nt and current_time < max_time: print current_time, nu = interp_particles_to_mesh(particles, domain) u, v, p = solve_flow(u, v, dt, p, rho, nu, nit, domain) p -= np.min(p) # set min pressure to be 0 dt = calc_dt(c, u, v, domain) current_time += dt dt_since_output += dt # Interpolate velocities back to particles particles = interp_mesh_to_particles(particles, u, v, domain) # Advect particles particles = advect_particles_rk2(dt, particles, u, v, domain) if timestep % output_timestep_interval == 0 or dt_since_output > output_time_interval: point_data = { "visc": nu[:, :, np.newaxis], "u": u[:, :, np.newaxis], "v": v[:, :, np.newaxis] } write_mesh(output_path, timestep, domain, point_data, mesh_group, current_time) write_particles(output_path, timestep, particles, particles_group, current_time) dt_since_output = 0 timestep += 1 mesh_group.save() particles_group.save() return 0