def write_grid_and_print_info(self, iteration): print('{}th iteration of {} smoothing'.format(iteration, self.__name__)) writer.write_tecplot( self.grid, '{}_smoothing_{}.dat'.format(self.__name__, self.name_of_iteration(iteration)))
def create_cylinder(m, n, filename='cylinder', plot_pyplot=False, create_dat=True): if m < 4: raise ValueError('4 is min dimension') u = linspace(-1, 1, m + 1, endpoint=True) v = linspace(-1, 1, n, endpoint=True) u, v = meshgrid(u, v) delaunuy = Triangulation(u.flatten(), v.flatten()) COORDS = zeros((m * n + n, 3)) #rad = 2 * np.pi / m #angles = [i * rad for i in range(m)] angles = np.logspace(-1, np.log2(2 * np.pi), num=m, base=2.0) coss = [cos(r) for r in angles] sins = [sin(r) for r in angles] coss.append(coss[0]) sins.append(sins[0]) z = np.linspace(0, 1, num=n, endpoint=True) for j in range(n): for i in range(m + 1): COORDS[i + j * (m + 1), 0] = coss[i % n] COORDS[i + j * (m + 1), 1] = sins[i % n] COORDS[i + j * (m + 1), 2] = z[j] x = COORDS[:, 0] y = COORDS[:, 1] z = COORDS[:, 2] assert len(x) == m * n + n mgrid = Grid() mgrid.set_nodes_and_faces(x, y, z, delaunuy.triangles) set_faces(mgrid, mgrid.Nodes, mgrid.Faces) mgrid.init_adjacent_faces_list_for_border_nodes() if plot_pyplot: fig = plt.figure() ax = fig.gca(projection='3d') ax.plot_trisurf(x, y, z, triangles=delaunuy.triangles) plt.show() if create_dat: if not filename.endswith('.dat'): filename += '.dat' writer.write_tecplot(mgrid, filename) assert len(mgrid.Edges) < 3 * len(mgrid.Nodes) - 3, 'Wrong number of edges' assert len(mgrid.Faces) < 2 * len(mgrid.Nodes) - 2, 'Wrong number of faces' return mgrid
def create_half_cylinder(m=3, n=5, filename='half_cylinder', create_dat=True, plot_pyplot=False): """Returns Grid object representing half cylinder. Args: m: Number of points along x axis. n: Number of point along y axis. filename: Name of the TECPLOT (.dat) file to write in. Only works if create_dat = True (default). create_dat: Crate TECPLOT (.dat) file. Default True. plot_pyplot: Plot pyplot view of the grid. Returns: Grid object """ u = linspace(0, pi, num=m, endpoint=True) v = linspace(0, 3, num=n, endpoint=True) u, zs = meshgrid(u, v) delaunuy = Triangulation(u.flatten(), zs.flatten()) xs = sin(u) ys = cos(u) x = ys.flatten() y = zs.flatten() z = xs.flatten() mgrid = Grid() mgrid.set_nodes_and_faces(x, y, z, delaunuy.triangles) set_faces(mgrid, mgrid.Nodes, mgrid.Faces) mgrid.init_adjacent_faces_list_for_border_nodes() if plot_pyplot: fig = plt.figure() ax = fig.gca(projection='3d') ax.plot_trisurf(x, y, z, triangles=delaunuy.triangles) plt.show() if create_dat: if not filename.endswith('.dat'): filename += '.dat' writer.write_tecplot(mgrid, filename) assert len(mgrid.Edges) < 3 * len(mgrid.Nodes) - 3, 'Wrong number of edges' assert len(mgrid.Faces) < 2 * len(mgrid.Nodes) - 2, 'Wrong number of faces' return mgrid
def create_circle(n, m, filename='plane', create_dat=True, plot_pyplot=False, nodes_distribution='uniform'): """Returns Grid object representing plain. #todo When n=4, m=4, something ruins Args: m: Number of points along x axis. n: Number of point along y axis. filename: Name of the TECPLOT (.dat) file to write in. Only works if create_dat = True (default). create_dat: Crate TECPLOT (.dat) file. Default True. plot_pyplot: Plot pyplot view of the grid. nodes_distribution: distribution of points along x axis uniform: logarithmic: Returns: Grid object """ u = linspace(-1, 1, m, endpoint=True) v = linspace(-1, 1, n, endpoint=True) u, v = meshgrid(u, v) coss = [] sins = [] for _u, _v in zip(u.flatten(), v.flatten()): hip = sqrt(_u**2 + _v**2) if hip == 0: coss.append(0) sins.append(0) continue coss.append(_u / hip) sins.append(_v / hip) delaunuy = Triangulation(coss, sins) z = zeros(u.shape) x = coss y = sins z = z.flatten() mgrid = Grid() mgrid.set_nodes_and_faces(x, y, z, delaunuy.triangles) set_faces(mgrid, mgrid.Nodes, mgrid.Faces) mgrid.init_adjacent_faces_list_for_border_nodes() if plot_pyplot: fig = plt.figure() ax = fig.gca(projection='3d') ax.plot_trisurf(x, y, z, triangles=delaunuy.triangles) plt.show() if create_dat: if not filename.endswith('.dat'): filename += '.dat' writer.write_tecplot(mgrid, filename) assert len(mgrid.Edges) < 3 * len(mgrid.Nodes) - 3, 'Wrong number of edges' assert len(mgrid.Faces) < 2 * len(mgrid.Nodes) - 2, 'Wrong number of faces' return mgrid
def create_plane(n, m, filename='plane', create_dat=True, plot_pyplot=False, nodes_distribution='uniform'): """Returns Grid object representing plain. Args: m: Number of points along x axis. n: Number of point along y axis. filename: Name of the TECPLOT (.dat) file to write in. Only works if create_dat = True (default). create_dat: Crate TECPLOT (.dat) file. Default True. plot_pyplot: Plot pyplot view of the grid. nodes_distribution: distribution of points along x axis uniform: logarithmic: Returns: Grid object """ if nodes_distribution == 'uniform': u = linspace(0, 1, n, endpoint=True) else: u = logspace(-2, 0, n, base=2.0, endpoint=True) v = linspace(0, 1, m, endpoint=True) u, v = meshgrid(u, v) delaunuy = Triangulation(u.flatten(), v.flatten()) z = zeros(u.shape) x = u.flatten() y = v.flatten() z = z.flatten() mgrid = Grid() mgrid.set_nodes_and_faces(x, y, z, delaunuy.triangles) set_faces(mgrid, mgrid.Nodes, mgrid.Faces) mgrid.init_adjacent_faces_list_for_border_nodes() if plot_pyplot: fig = plt.figure() ax = fig.gca(projection='3d') ax.plot_trisurf(x, y, z, triangles=delaunuy.triangles) plt.show() if create_dat: if not filename.endswith('.dat'): filename += '.dat' writer.write_tecplot(mgrid, filename) assert len(mgrid.Edges) < 3 * len(mgrid.Nodes) - 3, 'Wrong number of edges' assert len(mgrid.Faces) < 2 * len(mgrid.Nodes) - 2, 'Wrong number of faces' return mgrid
if result_grid: if not result_grid[-4:] == '.dat': print('File {} should be .dat file'.format(result_grid)) exit(1) start = time() grid1 = grid.Grid() grid2 = grid.Grid() reader.read_tecplot(grid1, old_grid) if args.verbosity > 0: print('Old grid read') reader.read_tecplot(grid2, new_grid) if args.verbosity > 0: print('New grid read') choose_method(args.method)(grid1, grid2) if args.verbosity > 0: print('Interpolation made') if args.result_grid: writer.write_tecplot(grid2, result_grid) else: writer.write_tecplot(grid2, new_grid[:-4] + '_interpolated.dat') if args.verbosity > 0: print('Result grid was written') print('Total time:', time() - start)