Ejemplo n.º 1
0
def calc_perf(theta_0=360,
              plot=False,
              verbose=True,
              inertial=False,
              export_csv=True):
    t, torque, drag = foampy.load_all_torque_drag()
    _t, theta, omega = foampy.load_theta_omega(t_interp=t)
    reached_theta_0 = True
    if theta.max() < theta_0:
        theta_0 = 1
        reached_theta_0 = False
    # Compute tip speed ratio
    tsr = omega * R / U_infty
    # Compute mean TSR
    meantsr = np.mean(tsr[theta >= theta_0])
    if inertial:
        inertia = 3  # guess from SolidWorks model
        inertial_torque = inertia * fdiff.second_order_diff(omega, t)
        torque -= inertial_torque
    # Compute power coefficient
    power = torque * omega
    cp = power / (0.5 * rho * area * U_infty**3)
    meancp = np.mean(cp[theta >= theta_0])
    # Compute drag coefficient
    cd = drag / (0.5 * rho * area * U_infty**2)
    meancd = np.mean(cd[theta >= theta_0])
    if export_csv:
        df = pd.DataFrame()
        df["theta_deg"] = theta
        df["tsr"] = tsr
        df["cp"] = cp
        df["cd"] = cd
        df.to_csv("processed/perf.csv", index=False)
    if verbose:
        print("Performance from {:.1f}--{:.1f} degrees:".format(
            theta_0, theta.max()))
        print("Mean TSR = {:.3f}".format(meantsr))
        print("Mean C_P = {:.3f}".format(meancp))
        print("Mean C_D = {:.3f}".format(meancd))
    if plot:
        plt.close('all')
        plt.plot(theta[5:], cp[5:])
        plt.title(r"$\lambda = %1.1f$" % meantsr)
        plt.xlabel(r"$\theta$ (degrees)")
        plt.ylabel(r"$C_P$")
        #plt.ylim((0, 1.0))
        plt.tight_layout()
        plt.show()
    if reached_theta_0:
        return {"C_P": meancp, "C_D": meancd, "TSR": meantsr}
    else:
        return {"C_P": "nan", "C_D": "nan", "TSR": "nan"}
Ejemplo n.º 2
0
def test_gen_dynmeshdict():
    os.chdir("test")
    u = 1
    r = 1
    meantsr = 1
    foampy.gen_dynmeshdict(u, r, meantsr, npoints=10, rpm_fluc=0)
    t, theta, omega = foampy.load_theta_omega()
    assert t.min() == 0
    assert t.max() == 0.5
    assert len(omega) == 10
    assert np.mean(omega*r/u) == meantsr
    os.chdir("../")
    os.system("git checkout test/constant/dynamicMeshDict")
Ejemplo n.º 3
0
def calc_perf(theta_0=360, plot=False, verbose=True, inertial=False):
    t, torque, drag = foampy.load_all_torque_drag()
    _t, theta, omega = foampy.load_theta_omega(t_interp=t)
    reached_theta_0 = True
    if theta.max() < theta_0:
        theta_0 = 1
        reached_theta_0 = False
    # Compute tip speed ratio
    tsr = omega*R/U_infty
    # Compute mean TSR
    meantsr = np.mean(tsr[theta >= theta_0])
    if inertial:
        inertia = 3 # guess from SolidWorks model
        inertial_torque = inertia*fdiff.second_order_diff(omega, t)
        torque -= inertial_torque
    # Compute power coefficient
    power = torque*omega
    cp = power/(0.5*rho*area*U_infty**3)
    meancp = np.mean(cp[theta >= theta_0])
    # Compute drag coefficient
    cd = drag/(0.5*rho*area*U_infty**2)
    meancd = np.mean(cd[theta >= theta_0])
    if verbose:
        print("Performance from {:.1f}--{:.1f} degrees:".format(theta_0, 
                                                                theta.max()))
        print("Mean TSR = {:.3f}".format(meantsr))
        print("Mean C_P = {:.3f}".format(meancp))
        print("Mean C_D = {:.3f}".format(meancd))
    if plot:
        plt.close('all')
        plt.plot(theta[5:], cp[5:])
        plt.title(r"$\lambda = %1.1f$" %meantsr)
        plt.xlabel(r"$\theta$ (degrees)")
        plt.ylabel(r"$C_P$")
        #plt.ylim((0, 1.0))
        plt.tight_layout()
        plt.show()
    if reached_theta_0:
        return {"C_P" : meancp, 
                "C_D" : meancd, 
                "TSR" : meantsr}
    else:
        return {"C_P" : "nan", 
                "C_D" : "nan", 
                "TSR" : "nan"}
def calc_blade_vel():
    """Calculates blade angle of attack and relative velocity time series."""
    # Load sampled data
    data = load_set(name="bladePath", quantity="U")
    times = data["time"]
    # Load turbine azimuthal angle time series
    _t, theta_blade, omega = foampy.load_theta_omega(t_interp=times)
    theta_turbine = theta_blade*1
    theta_blade = theta_blade.round(decimals=0) % 360
    theta_probe = theta_blade + 4
    theta_blade_rad = theta_blade/180*np.pi
    rel_vel = []
    alpha = []
    rel_vel_geom = []
    alpha_geom = []
    # Calculate an array of thetas that correspond to each sampled point
    for i, t in enumerate(times):
        x = data[t]["x"]
        y = data[t]["y"]
        u = data[t]["u"]
        v = data[t]["v"]
        theta = np.round(np.arctan2(-x, y)*180/np.pi, decimals=0)
        theta = [(360 + th) % 360 for th in theta]
        blade_vel_mag = omega[i]*R
        blade_vel_x = blade_vel_mag*np.cos(theta_blade_rad[i])
        blade_vel_y = blade_vel_mag*np.sin(theta_blade_rad[i])
        u_geom = 1.0
        rel_vel_mag_geom = np.sqrt((blade_vel_x + u_geom)**2 + blade_vel_y**2)
        rel_vel_geom.append(rel_vel_mag_geom)
        rel_vel_x_geom = u_geom + blade_vel_x
        rel_vel_y_geom = blade_vel_y
        relvel_dot_bladevel_geom = (blade_vel_x*rel_vel_x_geom + blade_vel_y*rel_vel_y_geom)
        _alpha = np.arccos(relvel_dot_bladevel_geom/(rel_vel_mag_geom*blade_vel_mag))
        alpha_geom.append(_alpha*180/np.pi)
        try:
            ivel = theta.index(theta_probe[i])
            ui = u[ivel]
            vi = v[ivel]
            rel_vel_mag = np.sqrt((blade_vel_x + ui)**2 + (blade_vel_y + vi)**2)
            rel_vel.append(rel_vel_mag)
            rel_vel_x = ui + blade_vel_x
            rel_vel_y = vi + blade_vel_y
            relvel_dot_bladevel = (blade_vel_x*rel_vel_x + blade_vel_y*rel_vel_y)
            _alpha = np.arccos(relvel_dot_bladevel/(rel_vel_mag*blade_vel_mag))
            alpha.append(_alpha*180/np.pi)
        except ValueError:
            rel_vel.append(np.nan)
            alpha.append(np.nan)
    rel_vel = np.array(rel_vel)
    alpha = np.array(alpha)
    alpha[theta_blade > 180] = -alpha[theta_blade > 180]
    rel_vel_geom = np.array(rel_vel_geom)
    alpha_geom = np.array(alpha_geom)
    alpha_geom[theta_blade > 180] = -alpha_geom[theta_blade > 180]
    theta_0 = 720
    alpha = alpha[theta_turbine > theta_0]
    rel_vel = rel_vel[theta_turbine > theta_0]
    alpha_geom = alpha_geom[theta_turbine > theta_0]
    rel_vel_geom = rel_vel_geom[theta_turbine > theta_0]
    theta_turbine = theta_turbine[theta_turbine > theta_0]
    plt.figure(figsize=(8,3))
    plt.subplot(1, 2, 1)
    plt.plot(theta_turbine, alpha, "--ok")
    plt.plot(theta_turbine, alpha_geom)
    plt.xlabel("Azimuthal angle (degrees)")
    plt.ylabel("Angle of attack (degrees)")
    plt.subplot(1, 2, 2)
    plt.plot(theta_turbine, rel_vel, "--ok")
    plt.plot(theta_turbine, rel_vel_geom)
    plt.xlabel("Azimuthal angle (degrees)")
    plt.ylabel("Relative velocity (m/s)")
    plt.tight_layout()
    plt.show()
Ejemplo n.º 5
0
def calc_blade_vel():
    """Calculates blade angle of attack and relative velocity time series."""
    # Load sampled data
    data = load_set(name="bladePath", quantity="U")
    times = data["time"]
    # Load turbine azimuthal angle time series
    _t, theta_blade, omega = foampy.load_theta_omega(t_interp=times)
    theta_turbine = theta_blade * 1
    theta_blade = theta_blade.round(decimals=0) % 360
    theta_probe = theta_blade + 4
    theta_blade_rad = theta_blade / 180 * np.pi
    rel_vel = []
    alpha = []
    rel_vel_geom = []
    alpha_geom = []
    # Calculate an array of thetas that correspond to each sampled point
    for i, t in enumerate(times):
        x = data[t]["x"]
        y = data[t]["y"]
        u = data[t]["u"]
        v = data[t]["v"]
        theta = np.round(np.arctan2(-x, y) * 180 / np.pi, decimals=0)
        theta = [(360 + th) % 360 for th in theta]
        blade_vel_mag = omega[i] * R
        blade_vel_x = blade_vel_mag * np.cos(theta_blade_rad[i])
        blade_vel_y = blade_vel_mag * np.sin(theta_blade_rad[i])
        u_geom = 1.0
        rel_vel_mag_geom = np.sqrt((blade_vel_x + u_geom)**2 + blade_vel_y**2)
        rel_vel_geom.append(rel_vel_mag_geom)
        rel_vel_x_geom = u_geom + blade_vel_x
        rel_vel_y_geom = blade_vel_y
        relvel_dot_bladevel_geom = (blade_vel_x * rel_vel_x_geom +
                                    blade_vel_y * rel_vel_y_geom)
        _alpha = np.arccos(relvel_dot_bladevel_geom /
                           (rel_vel_mag_geom * blade_vel_mag))
        alpha_geom.append(_alpha * 180 / np.pi)
        try:
            ivel = theta.index(theta_probe[i])
            ui = u[ivel]
            vi = v[ivel]
            rel_vel_mag = np.sqrt((blade_vel_x + ui)**2 +
                                  (blade_vel_y + vi)**2)
            rel_vel.append(rel_vel_mag)
            rel_vel_x = ui + blade_vel_x
            rel_vel_y = vi + blade_vel_y
            relvel_dot_bladevel = (blade_vel_x * rel_vel_x +
                                   blade_vel_y * rel_vel_y)
            _alpha = np.arccos(relvel_dot_bladevel /
                               (rel_vel_mag * blade_vel_mag))
            alpha.append(_alpha * 180 / np.pi)
        except ValueError:
            rel_vel.append(np.nan)
            alpha.append(np.nan)
    rel_vel = np.array(rel_vel)
    alpha = np.array(alpha)
    alpha[theta_blade > 180] = -alpha[theta_blade > 180]
    rel_vel_geom = np.array(rel_vel_geom)
    alpha_geom = np.array(alpha_geom)
    alpha_geom[theta_blade > 180] = -alpha_geom[theta_blade > 180]
    theta_0 = 720
    alpha = alpha[theta_turbine > theta_0]
    rel_vel = rel_vel[theta_turbine > theta_0]
    alpha_geom = alpha_geom[theta_turbine > theta_0]
    rel_vel_geom = rel_vel_geom[theta_turbine > theta_0]
    theta_turbine = theta_turbine[theta_turbine > theta_0]
    plt.figure(figsize=(8, 3))
    plt.subplot(1, 2, 1)
    plt.plot(theta_turbine, alpha, "--ok")
    plt.plot(theta_turbine, alpha_geom)
    plt.xlabel("Azimuthal angle (degrees)")
    plt.ylabel("Angle of attack (degrees)")
    plt.subplot(1, 2, 2)
    plt.plot(theta_turbine, rel_vel, "--ok")
    plt.plot(theta_turbine, rel_vel_geom)
    plt.xlabel("Azimuthal angle (degrees)")
    plt.ylabel("Relative velocity (m/s)")
    plt.tight_layout()
    plt.show()