"""Plot the instantaneous force coefficients.""" from matplotlib import pyplot import pathlib import rodney args = rodney.parse_command_line() maindir = pathlib.Path(__file__).absolute().parents[1] # Load force coefficients for simulation with AR=1.27. label = 'AR = 1.27' simudir = maindir / 'Re200_St0.6_AR1.27_psi90' config = rodney.WingKinematics(Re=200, AR=1.27, nt_period=2000) filepath = simudir / 'output' / 'forces-0.txt' solution = rodney.load_force_coefficients(filepath, config) rodney.print_stats(label, *rodney.get_stats(solution, limits=(4, 5))) plot_kwargs = dict(color='C3', linestyle='-') # Load force coefficients for simulation with AR=1.91. label2 = 'AR = 1.91' simudir2 = maindir / 'Re200_St0.6_AR1.91_psi90' config2 = rodney.WingKinematics(Re=200, AR=1.91, nt_period=2000) filepath = simudir2 / 'output' / 'forces-0.txt' solution2 = rodney.load_force_coefficients(filepath, config2) rodney.print_stats(label2, *rodney.get_stats(solution2, limits=(4, 5))) plot_kwargs2 = dict(color='black', linestyle='--') # Load force coefficients for simulation with AR=2.55. label3 = 'AR = 2.55' simudir3 = maindir / 'Re200_St0.6_AR2.55_psi90'
"""Plot the instantaneous force coefficients.""" from matplotlib import pyplot import pathlib import rodney args = rodney.parse_command_line() maindir = pathlib.Path(__file__).absolute().parents[1] # Load force coefficients for simulation with psi=90. label = r'$\psi = 90^o$' simudir = maindir / 'Re200_St0.6_AR1.27_psi90' config = rodney.WingKinematics(psi=90.0) filepath = simudir / 'output' / 'forces-0.txt' solution = rodney.load_force_coefficients(filepath, config) rodney.print_stats(label, *rodney.get_stats(solution, limits=(4, 5))) plot_kwargs = dict(color='C3', linestyle='-') # Load force coefficients for simulation with psi=100. label2 = r'$\psi = 100^o$' simudir2 = maindir / 'Re200_St0.6_AR1.27_psi100' config2 = rodney.WingKinematics(psi=100.0) filepath = simudir2 / 'output' / 'forces-0.txt' solution2 = rodney.load_force_coefficients(filepath, config2) rodney.print_stats(label2, *rodney.get_stats(solution2, limits=(4, 5))) plot_kwargs2 = dict(color='C2', linestyle='--') # Load force coefficients for simulation with psi=110. label3 = r'$\psi = 110^o$' simudir3 = maindir / 'Re200_St0.6_AR1.27_psi110'
from collections import OrderedDict import numpy import pathlib import yaml import petibmpy import rodney # Set the simulation directory. simudir = pathlib.Path(__file__).absolute().parents[1] datadir = simudir / 'output' # Set the wing kinematics. config = rodney.WingKinematics(nt_period=2000) c = config.c # chord length S = config.S # spanwise length A_phi = config.A_phi # rolling amplitude (radians) n_periods = config.n_periods # number of flapping cycles nt_period = config.nt_period # number of time steps per cycle dt = config.dt # time-step size probes = [] # will store info about the probes # Set probe information for the x- and y- components of the velocity. fields = ['u', 'v'] for field in fields: filepath = datadir / 'grid.h5' grid = petibmpy.read_grid_hdf5(filepath, field) xlocs = [1.0, 2.0, 3.0, 4.0, 5.0]
def resize_for_uniform(L, xc, dx, buf=0.0): """Adjust the limits of the interval to allow uniform discretization.""" xs, xe = xc - L / 2 - buf, xc + L / 2 + buf L = xe - xs n = math.ceil(L / dx) L = n * dx xs, xe = xc - L / 2, xc + L / 2 assert abs((xe - xs) / n - dx) < 1e-12 return xs, xe Box = collections.namedtuple( 'Box', ['xstart', 'xend', 'ystart', 'yend', 'zstart', 'zend']) config = rodney.WingKinematics(psi=70.0, Re=200, St=0.6, nt_period=2000) c, S, A_phi = config.c, config.S, config.A_phi box1 = Box(-15.0, 15.0, -12.5, 12.5, -12.5, 12.5) box2, width2 = Box(-2.0, 6.0, -3.0, 3.0, -1.0, 2.0), 0.05 * c dx = 0.01 * c buf = 0.05 * c xs, xe = resize_for_uniform(c, 0.0, dx, buf=buf) ys, ye = resize_for_uniform(2 * S * numpy.cos(A_phi), 0.0, dx, buf=buf) zs, ze = resize_for_uniform(S, S / 2, dx, buf=buf) box3, width3 = Box(xs, xe, ys, ye, zs, ze), dx show_figure = False config_x = get_gridline_config(box1.xstart, box2.xstart, box3.xstart,
"""Plot the instantaneous force coefficients and compare grid resolutions.""" from matplotlib import pyplot import pathlib import rodney args = rodney.parse_command_line() maindir = pathlib.Path(__file__).absolute().parents[1] data = {} # Process force coefficients for simulation on coarse mesh. label = 'Coarse' simudir = maindir / 'run1' config = rodney.WingKinematics(Re=200.0, St=0.6, psi=90.0, nt_period=2000) filepath = simudir / 'output' / 'forces-0.txt' solution = rodney.load_force_coefficients(filepath, config) rodney.print_stats(label, *rodney.get_stats(solution, limits=(4, 5))) data[label] = dict(config=config, solution=solution, plot_kwargs=dict(linestyle='-', color='C0')) # Process force coefficients for simulation on intermediate mesh. label = 'Nominal' simudir = maindir / 'run3' config = rodney.WingKinematics(Re=200.0, St=0.6, psi=90.0, nt_period=2000) filepath = simudir / 'output' / 'forces-0.txt' solution = rodney.load_force_coefficients(filepath, config) rodney.print_stats(label, *rodney.get_stats(solution, limits=(4, 5))) data[label] = dict(config=config, solution=solution,
simudir = pathlib.Path(__file__).absolute().parents[1] datadir = simudir / 'output' # Compute the cycle-averaged thrust coefficient. filepath = datadir / 'forces-0.txt' t, fx, _, _ = petibmpy.read_forces(filepath) thrust = -fx # switch from drag to thrust time_limits = (4 * T, 5 * T) # interval to consider for average thrust_avg, = petibmpy.get_time_averaged_values(t, thrust, limits=time_limits) # Create the wing kinematics. wing = rodney.WingKinematics(c=1.0, AR=1.27, hook=(0.0, 0.0, 0.0), A_phi=45.0, A_theta=45.0, psi=90.0, theta_bias=0.0, Re=200.0, U_inf=1.0, St=0.6) # Load original boundary coordinates from file. filepath = simudir / 'wing.body' wing.load_body(filepath, skiprows=1) x0, y0, z0 = wing.get_coordinates() # Grab 3 reference points (to later compute unit normal vector). points0 = Point(x0[:3], y0[:3], z0[:3]) dx = 0.01 # grid-spacing size in the vicinity of the body ds = dx**2 # surface area associated with each marker
"""Plot the instantaneous force coefficients.""" from matplotlib import pyplot import numpy import pathlib import rodney args = rodney.parse_command_line() maindir = pathlib.Path(__file__).absolute().parents[1] # Load force coefficients for simulation at Re=100. label = 'Re = 100' simudir = maindir / 'Re100_St0.6_AR1.27_psi90' config = rodney.WingKinematics(Re=100, nt_period=2000) filepath = simudir / 'output' / 'forces-0.txt' solution = rodney.load_force_coefficients(filepath, config) rodney.print_stats(label, *rodney.get_stats(solution, limits=(4, 5))) mask = numpy.where((solution.t >= 4) & (solution.t <= 5))[0] print('max(|C_T|) =', numpy.max(numpy.abs(solution.ct[mask]))) plot_kwargs = dict(color='black', linestyle='--') # Load force coefficients for simulation at Re=200. label2 = 'Re = 200' simudir2 = maindir / 'Re200_St0.6_AR1.27_psi90' config2 = rodney.WingKinematics(Re=200, nt_period=2000) filepath = simudir2 / 'output' / 'forces-0.txt' solution2 = rodney.load_force_coefficients(filepath, config2) rodney.print_stats(label2, *rodney.get_stats(solution2, limits=(4, 5))) mask = numpy.where((solution2.t >= 4) & (solution2.t <= 5))[0]
"""Write the YAML configuration file for the probes.""" import numpy import pathlib import yaml import petibmpy import rodney # Set the simulation directory. simudir = pathlib.Path(__file__).absolute().parents[1] datadir = simudir / 'output' # Set the kinematics of the wing. config = rodney.WingKinematics(AR=1.91, Re=200, St=0.6, nt_period=2000) c, S, A_phi = config.c, config.S, config.A_phi n_periods, nt_period = config.n_periods, config.nt_period dt = config.dt probes = [] # will store info about the probes # Set probe information for the x- and y- components of the velocity. fields = ['u', 'v'] for field in fields: filepath = datadir / 'grid.h5' grid = petibmpy.read_grid_hdf5(filepath, field) xlocs = [1.0, 2.0, 3.0, 4.0, 5.0] for i, xloc in enumerate(xlocs): name = f'probe{i + 1}-{field}'
"""Print parameters related to the kinematics of the wing.""" import numpy import rodney kinematics = rodney.WingKinematics(psi=80.0, Re=200, St=0.6, nt_period=2000) print(kinematics)
args = rodney.parse_command_line() maindir = pathlib.Path(__file__).parents[1] datadir = maindir / 'output' # Load gridline coordinates from file. filepath = datadir / 'grid.h5' x, y, z = petibmpy.read_grid_hdf5(filepath, 'vertex') # Subset gridline coordinates. x, xlim = subset_gridline(x, -5.0, 5.0) y, ylim = subset_gridline(y, -5.0, 5.0) z, zlim = subset_gridline(z, -5.0, 5.0) # Load body coordinates from file. filepath = maindir / 'wing.body' wing = rodney.WingKinematics() wing.load_body(filepath, skiprows=1) # Keep only points on the contour of the wing. x0, _, z0 = wing.get_coordinates(org=True) points = numpy.array([x0, z0]).T hull = ConvexHull(points) x0, z0 = points[hull.vertices, 0], points[hull.vertices, 1] y0 = numpy.zeros_like(x0) wing.set_coordinates(x0, y0, z0, org=True) # Get position at given time. xb, yb, zb = wing.compute_position(0.0) pyplot.rc('font', family='serif', size=12)
"""Print parameters related to the kinematics of the wing.""" import numpy import rodney kinematics = rodney.WingKinematics(nt_period=1000) print(kinematics)
roll=phi, pitch=theta, center=wing.hook) p1, p2, p3 = numpy.array([x, y, z]).T v1 = (p1 - p2) / numpy.linalg.norm(p1 - p2) v2 = (p3 - p1) / numpy.linalg.norm(p3 - p1) v3 = numpy.cross(v1, v2) return v3 / numpy.linalg.norm(v3) # Set simulation directory and data directory. simudir = pathlib.Path(__file__).absolute().parents[1] datadir = simudir / 'output' # Create the wing kinematics. wing = rodney.WingKinematics(Re=200.0, St=0.6, psi=110.0, nt_period=2000) # Compute the cycle-averaged thrust. filepath = datadir / 'forces-0.txt' t, fx, _, _ = petibmpy.read_forces(filepath) thrust = -fx # switch from drag to thrust time_limits = (4 * wing.T, 5 * wing.T) # interval to consider for average thrust_avg, = petibmpy.get_time_averaged_values(t, thrust, limits=time_limits) # Compute the cycle-averaged thrust coefficient. rho, U_inf, A_plan = (getattr(wing, name) for name in ('rho', 'U_inf', 'A_plan')) scale = 1 / (0.5 * rho * U_inf**2 * A_plan) ct, = petibmpy.get_force_coefficients(thrust, coeff=scale) ct_avg, = petibmpy.get_time_averaged_values(t, ct, limits=time_limits)
pitch=theta, center=wing.hook) p1, p2, p3 = numpy.array([x, y, z]).T v1 = (p1 - p2) / numpy.linalg.norm(p1 - p2) v2 = (p3 - p1) / numpy.linalg.norm(p3 - p1) v3 = numpy.cross(v1, v2) return v3 / numpy.linalg.norm(v3) # Set simulation directory and data directory. simudir = pathlib.Path(__file__).absolute().parents[1] datadir = simudir / 'output' # Create the wing kinematics. wing = rodney.WingKinematics(Re=200.0, St=1.0, nt_period=2000) # Compute the cycle-averaged thrust. filepath = datadir / 'forces-0.txt' t, fx, _, _ = petibmpy.read_forces(filepath) thrust = -fx # switch from drag to thrust time_limits = (4 * wing.T, 5 * wing.T) # interval to consider for average thrust_avg, = petibmpy.get_time_averaged_values(t, thrust, limits=time_limits) # Compute the cycle-averaged thrust coefficient. rho, U_inf, A_plan = (getattr(wing, name) for name in ('rho', 'U_inf', 'A_plan')) scale = 1 / (0.5 * rho * U_inf**2 * A_plan) ct, = petibmpy.get_force_coefficients(thrust, coeff=scale) ct_avg, = petibmpy.get_time_averaged_values(t, ct, limits=time_limits)
"""Print parameters related to the kinematics of the wing.""" import numpy import rodney kinematics = rodney.WingKinematics(AR=2.55, Re=200, St=0.6, nt_period=2000) print(kinematics)
"""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)
def resize_for_uniform(L, xc, dx, buf=0.0): """Adjust the limits of the interval to allow uniform discretization.""" xs, xe = xc - L / 2 - buf, xc + L / 2 + buf L = xe - xs n = math.ceil(L / dx) L = n * dx xs, xe = xc - L / 2, xc + L / 2 assert abs((xe - xs) / n - dx) < 1e-12 return xs, xe Box = collections.namedtuple('Box', ['xstart', 'xend', 'ystart', 'yend', 'zstart', 'zend']) config = rodney.WingKinematics(Re=200, St=0.8, nt_period=2000) c, S, A_phi = config.c, config.S, config.A_phi box1 = Box(-15.0, 15.0, -12.5, 12.5, -12.5, 12.5) box2, width2 = Box(-2.0, 6.0, -3.0, 3.0, -1.0, 2.0), 0.05 * c dx = 0.01 * c buf = 0.05 * c xs, xe = resize_for_uniform(c, 0.0, dx, buf=buf) ys, ye = resize_for_uniform(2 * S * numpy.cos(A_phi), 0.0, dx, buf=buf) zs, ze = resize_for_uniform(S, S / 2, dx, buf=buf) box3, width3 = Box(xs, xe, ys, ye, zs, ze), dx show_figure = False config_x = get_gridline_config(box1.xstart, box2.xstart, box3.xstart,
Slice the spanwise vorticity in the x/y plane at the midspan (z=S/2). """ import collections from matplotlib import pyplot, patches import numpy import pathlib import petibmpy import rodney # Parse command line, and set kinematics and directories. args = rodney.parse_command_line() config = rodney.WingKinematics(Re=200, St=0.6, AR=1.27, nt_period=2000) simudir = pathlib.Path(__file__).absolute().parents[1] datadir = simudir / 'output' # Set parameters. t_nodim = 4.25 # non-dimensional time t = t_nodim * config.T # time timestep = int(t / config.dt) # time-step index theta = config.pitching(t) # pitching angle (radians) if args.save_figures: # Create directory for figures if needed. figdir = simudir / 'figures' figdir.mkdir(parents=True, exist_ok=True) # Set default font family and size for Matplotlib figures.
"""Print parameters related to the kinematics of the wing.""" import numpy import rodney kinematics = rodney.WingKinematics(Re=200, St=0.4, nt_period=2000) print(kinematics)