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()
def continue_last_sim(): folders = listdir("./results") max_num1 = 0 for i in folders: num = [int(s) for s in i.split() if s.isdigit()][0] if num > max_num1: max_num1 = num sim_folder = "./results/simulation " + str(max_num1) + "/csv/" files = listdir(sim_folder) max_num2 = 0 for i in files: num = int(i.split("_")[1].replace(".csv", "")) if num > max_num2: max_num2 = num return [ csv_to_dict(sim_folder + "iter_" + str(max_num2 - 1) + ".csv"), max_num2 - 1, "./results/simulation " + str(max_num1), VtkGroup("./results/simulation " + str(max_num1) + "/moving_particles") ]
def get_paths(main_folder): '''Make directories and return the paths for the vtk, group and csv folders''' Path(main_folder).mkdir(parents=True, exist_ok=True) path = main_folder folders = listdir(path) num = 1 if not folders: foldername = 'simulation 1/' else: for string in folders: if [int(s) for s in string.split() if s.isdigit()][0] > num: num = [int(s) for s in string.split() if s.isdigit()][0] foldername = 'simulation ' + str(num + 1) + '/' Path(path + foldername + '/csv').mkdir(parents=True, exist_ok=True) Path(path + foldername + '/vtk').mkdir(parents=True, exist_ok=True) group = VtkGroup(path + foldername + 'moving_particles') return [path + foldername + '/vtk', group, path + foldername + '/csv']
displacement_x.shape = -1, node_number displacement_y.shape = -1, node_number displacement_x = displacement_x[time_select][::skip_step] displacement_y = displacement_y[time_select][::skip_step] print(time.shape) # Coordinates radius_axis = numpy.arange(0, radius_length + 0.1 * radius_delta, radius_delta) angle_axis = numpy.arange(0, angle_length + 0.1 * angle_delta, angle_delta) x = numpy.zeros((radius_number + 1, angle_number + 1, node_number)) 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
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