def test_read_write_body(self): """Test functions `read_body` and `write_body`.""" filepath = self.datadir / 'body.txt' coords = (self.x, self.y, self.z) for d in [2, 3]: petibmpy.write_body(filepath, *coords[:d]) coords2 = petibmpy.read_body(filepath, skiprows=1) self.assertEqual(len(coords2), d) for i, coord in enumerate(coords2): self.assertTrue(numpy.allclose(coord, coords[i])) filepath.unlink()
"""Create the body and write the coordinates to a file.""" import pathlib import petibmpy import rodney # Set the simulation directory. simudir = pathlib.Path(__file__).absolute().parents[1] # Create the configuration for the wing kinematics. wing = rodney.WingKinematics(Re=200, St=0.6, nt_period=2000) # Discretize the body. wing.create_body(ds=0.01, sort_points=True) x, y, z = wing.get_coordinates() # Save the coordinates into a file. filepath = simudir / 'wing.body' petibmpy.write_body(filepath, x, y, z)
import petibmpy from icosphere import create_icosphere, create_polyhedron def plot_trisurf(vertices, triangles): """Plot the triangular mesh.""" fig = pyplot.figure(figsize=(8.0, 8.0)) ax = fig.gca(projection='3d') ax.plot_trisurf(*vertices.T, triangles=triangles, linewidth=0.5, edgecolor='black') ax.axis('scaled', adjustable='box') fig.tight_layout() simudir = pathlib.Path(__file__).absolute().parent icosphere = create_icosphere(25) # print(icosphere) R = 0.5 icosphere.vertices *= R icosphere.print_info() filepath = simudir / 'sphere.body' petibmpy.write_body(filepath, *icosphere.vertices.T) # plot_trisurf(icosphere.vertices, icosphere.triangles) # pyplot.show()
# Create distance function. a, b = c / 2, S / 2 xc, yc, zc = CoR[0], CoR[1], CoR[2] + b def fd(p): """Distance function.""" return (p[:, 0] - xc)**2 / a**2 + (p[:, 1] - zc)**2 / b**2 - 1 # Discretize the ellipse. ds = 0.01 * c # mesh resolution bbox = (xc - a, zc - b, xc + a, zc + b) # bounding box p, t = distmesh.distmesh2d(fd, distmesh.huniform, ds, bbox, fig=None) # Store the coordinates in arrays. x0, z0 = p[:, 0], p[:, 1] y0 = numpy.zeros_like(x0) sort_points = True if sort_points: idx = numpy.argmin(z0) xp, zp = x0[idx], z0[idx] dist = numpy.sqrt((x0 - xp)**2 + (z0 - zp)**2) indices = numpy.argsort(dist) x0, z0 = x0[indices], z0[indices] # Save the coordinates into a file. filepath = simudir / 'wing.body' petibmpy.write_body(filepath, x0, y0, z0)