def test_rotate2d(self): """Test function `rotate2d`.""" x, y = petibmpy.rotate2d(self.x, self.y) self.assertTrue(numpy.allclose(x, self.x)) self.assertTrue(numpy.allclose(y, self.y)) x, y = petibmpy.rotate2d(self.x, self.y, angle=360.0) self.assertTrue(numpy.allclose(x, self.x)) self.assertTrue(numpy.allclose(y, self.y)) x, y = petibmpy.rotate2d(self.x, self.y, angle=2 * numpy.pi, mode='rad') self.assertTrue(numpy.allclose(x, self.x)) self.assertTrue(numpy.allclose(y, self.y)) with self.assertRaises(ValueError): petibmpy.rotate2d(x, y, mode='typo')
def get_CD_CL(self, filepath, bodypath): """Load the forces from file and return the force coefficients.""" t, fx, fy = petibmpy.read_forces(filepath) # Non-dimensionalize time by the period. t_nodim = self.f * t # Reverse sign of force in x-direction when the body moving # in the positive x-direction. U0, _ = self.translational_velocity(t) fx *= -U0 / numpy.abs(U0) # Normalize the forces by the maximum quasi-steady force on the wing. D, L = [], [] x0 = petibmpy.read_body(bodypath, skiprows=1, usecols=0) y0 = numpy.zeros_like(x0) for ti in t: alpha = self.orientation_angle(ti) x, y = petibmpy.rotate2d(x0, y0, center=(0.0, 0.0), angle=alpha, mode='rad') Di, Li = self.quasi_steady_forces(ti, x, y, 0.0, 0.0, rho=1.0) D.append(numpy.max(Di)) L.append(numpy.max(Li)) D, L = numpy.array(D), numpy.array(L) cd, cl = fx / numpy.max(D), fy / numpy.max(L) return {'CD': (t_nodim, cd), 'CL': (t_nodim, cl)}
def position(self, t, x0, y0): """Return the coordinates of the wing a given time t.""" xd, yd = self.displacement(t) alpha = self.orientation_angle(t) x, y = x0 + xd, y0 + yd x, y = petibmpy.rotate2d(x, y, center=(xd, yd), angle=alpha, mode='rad') return x, y
"""Generate the coordinates of the snake boundary.""" import sys import pathlib import numpy from matplotlib import pyplot import petibmpy # Read the original coordinates of the section. rootdir = pathlib.Path(__file__).absolute().parents[1] datadir = rootdir / 'data' filepath = datadir / 'snake2d.body' with open(filepath, 'r') as infile: x, y = numpy.loadtxt(infile, dtype=numpy.float64, skiprows=1, unpack=True) # Apply rotation and regularize the geometry to desired resolution. x, y = petibmpy.rotate2d(x, y, center=(0.0, 0.0), angle=-35.0) x, y = petibmpy.regularize2d(x, y, ds=0.004) # Write new coordinates in file located in simulation directory. filepath = rootdir / 'snake2d35.body' with open(filepath, 'w') as outfile: outfile.write(f'{x.size}\n') with open(filepath, 'ab') as outfile: numpy.savetxt(outfile, numpy.c_[x, y])