Compare commits

...

2 Commits

Author SHA1 Message Date
Cal Wing
29c11bab72 Add force to pressure grpahs 2024-08-29 00:47:40 +10:00
Cal Wing
a794c47d1a Fix force generation 2024-08-29 00:16:53 +10:00

142
main.py
View File

@ -25,7 +25,7 @@ for folder in folders:
INCH_TO_M = 0.0254 INCH_TO_M = 0.0254
GRAVITY = 9.81 #m/s^2 GRAVITY = 9.81 #m/s^2
CHORD_LEN = 90 #mm CHORD_LEN = 1000 #90 #mm
PITOT_PLACEMENT = np.array((0,4,8,16,25,34,43,52,61,70,5,9,17,25,34,43,52,61,70)) # mm from base of chord PITOT_PLACEMENT = np.array((0,4,8,16,25,34,43,52,61,70,5,9,17,25,34,43,52,61,70)) # mm from base of chord
PITOT_PLACEMENT_CHORD_NORM = PITOT_PLACEMENT / CHORD_LEN PITOT_PLACEMENT_CHORD_NORM = PITOT_PLACEMENT / CHORD_LEN
@ -59,10 +59,34 @@ def make_pressure_graph(sheet1, aoa, rpm, air_speed, doGraph=True):
#print(pressure) #print(pressure)
#print(pressure.min(), pressure.max()) #print(pressure.min(), pressure.max())
# Do the trapiztoal rule integration
da = []
for i, _ in enumerate(pressure):
if i in [0]: continue # Skip 0
if i in [10]: # Force tapping 11 to use tapping 1 rather then 0
da.append(((PITOT_PLACEMENT_CHORD_NORM[i] - PITOT_PLACEMENT_CHORD_NORM[0])/2) * (pressure.iloc[0] + pressure.iloc[i]))
continue
da.append(((PITOT_PLACEMENT_CHORD_NORM[i] - PITOT_PLACEMENT_CHORD_NORM[i-1])/2) * (pressure.iloc[i-1] + pressure.iloc[i]))
da = np.array(da)
#print("\n\n\n\n")
#print(da)
#print("\n\n\n\n")
upper_force = da[:10].sum()
lower_force = da[10 :].sum()
force = lower_force - upper_force # Upper Sum (1-10) less Lower Sum (11-19)
lift = force * cos(aoa)
drag = force * sin(aoa)
# Extrapolate Aerofoil Tip # Extrapolate Aerofoil Tip
p1 = (PITOT_PLACEMENT[9], pressure.iloc[9]) p1 = (PITOT_PLACEMENT[9], pressure.iloc[9])
p2 = (PITOT_PLACEMENT[18], pressure.iloc[18]) p2 = (PITOT_PLACEMENT[18], pressure.iloc[18])
pN = (0.9*CHORD_LEN, p2[1] + (p1[1]-p2[1])/2) pN = (1.1*max(PITOT_PLACEMENT), p2[1] + (p1[1]-p2[1])/2)
#print(aoa, rpm, p1[1], p2[1], (p1[1]-p2[1])/2, pN[1], pN[1] > p1[1]) #print(aoa, rpm, p1[1], p2[1], (p1[1]-p2[1])/2, pN[1], pN[1] > p1[1])
@ -94,14 +118,14 @@ def make_pressure_graph(sheet1, aoa, rpm, air_speed, doGraph=True):
# Draw Points & text # Draw Points & text
{"x":PITOT_PLACEMENT, "y":pressure, "label":"Pressure Data", "type":"scatter", "args":{"zorder":2}}, {"x":PITOT_PLACEMENT, "y":pressure, "label":"Pressure Data", "type":"scatter", "args":{"zorder":2}},
{"label":[str(i) for i in range(1, len(PITOT_PLACEMENT)+1)], "x":PITOT_PLACEMENT, "y":pressure, "type":"annotate"}, {"label":[str(i) for i in range(1, len(PITOT_PLACEMENT)+1)], "x":PITOT_PLACEMENT, "y":pressure, "type":"annotate"},
{"type":"text", "x": 0.98, "y": 0.02, "text": f"Min: {pressure.min():.3f} Pa\nMax: {pressure.max():.3f} Pa", "align": ('bottom', 'right')} {"type":"text", "x": 0.98, "y": 0.02, "text": f"Min: {pressure.min():.3f} Pa\nMax: {pressure.max():.3f} Pa\nForce: {force:.3f}N\nLift: {lift:.3f}N\nDrag: {drag:.3f}N", "align": ('bottom', 'right')}
] ]
} }
if doGraph: if doGraph:
makeGraph(graph, False, figSavePath=f'./images/pressure/{{0}}.png', closeFig=True) makeGraph(graph, False, figSavePath=f'./images/pressure/{{0}}.png', closeFig=True)
return pressure, graph, (water_density, air_density, atm_presure_inch, pitot_height_inch), (p1, p2, pN) return pressure, graph, (water_density, air_density, atm_presure_inch, pitot_height_inch), (p1, p2, pN), aoa, (force, lift, drag, da, upper_force, lower_force)
def make_cp_graph(pressure, aoa, rpm, air_speed, data, doGraph=True): def make_cp_graph(pressure, aoa, rpm, air_speed, data, doGraph=True):
@ -113,29 +137,23 @@ def make_cp_graph(pressure, aoa, rpm, air_speed, data, doGraph=True):
# Calculate Cp # Calculate Cp
cp = pressure / (0.5 * air_density * (air_speed ** 2)) cp = pressure / (0.5 * air_density * (air_speed ** 2))
# Do the trapiztoal rule integration #print("force, lift, drag, upper_force, lower_force")
da = [] #print(force, lift, drag, upper_force, lower_force)
for i, _ in enumerate(pressure):
if i in [0, 10]: continue # Skip 0 & Tapping 11 (Don't want to calc taping[11] - tapp[10])
da.append(((pressure.iloc[i-1] + pressure.iloc[i])/2) * (PITOT_PLACEMENT_CHORD_NORM[i]-PITOT_PLACEMENT_CHORD_NORM[i-1]))
da = np.array(da)
force = da.sum() #print(f"{aoa}, ")
lift = force * cos(aoa)
drag = force * sin(aoa)
# Extrapolate Aerofoil Tip # Extrapolate Aerofoil Tip
p1 = (PITOT_PLACEMENT_CHORD_NORM[9], cp.iloc[9]) p1 = (PITOT_PLACEMENT_CHORD_NORM[9], cp.iloc[9])
p2 = (PITOT_PLACEMENT_CHORD_NORM[18], cp.iloc[18]) p2 = (PITOT_PLACEMENT_CHORD_NORM[18], cp.iloc[18])
pN = (0.9, p2[1] + (p1[1]-p2[1])/2) pN = (1.1*max(PITOT_PLACEMENT_CHORD_NORM), p2[1] + (p1[1]-p2[1])/2)
#print(aoa, rpm, p1[1], p2[1], (p1[1]-p2[1])/2, pN[1], pN[1] > p1[1]) #print(aoa, rpm, p1[1], p2[1], (p1[1]-p2[1])/2, pN[1], pN[1] > p1[1])
graph = { graph = {
"title": f"$C_p$ vs Pitot Placement along Chord\nfor a Clark Y 14% Aerofoil at:\nα = {int(aoa):d}° at {rpm:d} RPM ({air_speed:.1f}m/s)", "title": f"$C_p$ vs Pitot Placement along Chord\nfor a Clark Y 14% Aerofoil at:\nα = {int(aoa):d}° at {rpm:d} RPM ({air_speed:.1f}m/s)",
"windowTitle": f"Cp along Clark Y 14 Percent Airfoil - Alpha {int(aoa):d} Degrees - {rpm:d}rpm - {air_speed:.1f}m_s", "windowTitle": f"Cp along Clark Y 14 Percent Airfoil - Alpha {int(aoa):d} Degrees - {rpm:d}rpm - {air_speed:.1f}m_s",
"xLabel": "Normalized Pitot Placement", "xLabel": "Pitot Placement [m]",
"yLabel": "$C_p$", "yLabel": "$C_p$",
"grid": True, "grid": True,
"yLim": (cp.min()-0.5, cp.max()+0.5), "yLim": (cp.min()-0.5, cp.max()+0.5),
@ -160,14 +178,14 @@ def make_cp_graph(pressure, aoa, rpm, air_speed, data, doGraph=True):
# Draw Points & text # Draw Points & text
{"x":PITOT_PLACEMENT_CHORD_NORM, "y":cp, "label":"cp Data", "type":"scatter", "args":{"zorder":2}}, {"x":PITOT_PLACEMENT_CHORD_NORM, "y":cp, "label":"cp Data", "type":"scatter", "args":{"zorder":2}},
{"label":[str(i) for i in range(1, len(PITOT_PLACEMENT_CHORD_NORM)+1)], "x":PITOT_PLACEMENT_CHORD_NORM, "y":cp, "type":"annotate"}, {"label":[str(i) for i in range(1, len(PITOT_PLACEMENT_CHORD_NORM)+1)], "x":PITOT_PLACEMENT_CHORD_NORM, "y":cp, "type":"annotate"},
{"type":"text", "x": 0.98, "y": 0.02, "text": f"Min $C_p$: {cp.min():.3f}\nMax $C_p$: {cp.max():.3f}\nForce: {force:.3f}N\nLift: {lift:.3f}N\nDrag: {drag:.3f}N", "align": ('bottom', 'right')} {"type":"text", "x": 0.98, "y": 0.02, "text": f"Min $C_p$: {cp.min():.3f}\nMax $C_p$: {cp.max():.3f}", "align": ('bottom', 'right')}
] ]
} }
if doGraph: if doGraph:
makeGraph(graph, False, figSavePath=f'./images/cp/{{0}}.png', closeFig=True) makeGraph(graph, False, figSavePath=f'./images/cp/{{0}}.png', closeFig=True)
return cp, (force, lift, drag, da), graph, (p1, p2, pN), aoa return cp, graph, (p1, p2, pN), aoa
def make_rpm_graph(): def make_rpm_graph():
@ -200,17 +218,19 @@ def make_rpm_graph():
if __name__ == '__main__': if __name__ == '__main__':
print("Generating RPM Graph") print("Generating RPM Graph")
make_rpm_graph() #make_rpm_graph()
print("Generated") print("Generated")
print("Loading Data & Generating Pressure Graphs") print("Loading Data & Generating Pressure Graphs")
data = {} data = {}
for raw_data in tqdm((data_508rpm, data_1000rpm), position=0): for raw_data in tqdm((data_508rpm, data_1000rpm), position=0):
aoa_data = {} aoa_data = {}
cp_pain_data = []
for aoa in tqdm(raw_data["AoA"], position=1): for aoa in tqdm(raw_data["AoA"], position=1):
sheet = raw_data["data"][f"{aoa} AoA"] sheet = raw_data["data"][f"{aoa} AoA"]
aoa_data[aoa] = make_pressure_graph(sheet, aoa, raw_data["rpm"], raw_data["airSpeed"], True) aoa_data[aoa] = make_pressure_graph(sheet, aoa, raw_data["rpm"], raw_data["airSpeed"], True)
cp_pain_data.append(aoa_data[aoa])
data[raw_data["rpm"]] = aoa_data data[raw_data["rpm"]] = aoa_data
@ -297,6 +317,36 @@ if __name__ == '__main__':
makeGraph(graph, False, figSavePath="./images/pressure/__{0}.png") makeGraph(graph, False, figSavePath="./images/pressure/__{0}.png")
if True:
aoa = [a[-2] for a in cp_pain_data][1::2]
forces = [a[-1] for a in cp_pain_data][1::2]
# Force Graphs
graph = {
"title": f"All Total, Lift & Drag Forces\nfor a Clark Y 14% Aerofoil at:\n{raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m/s)",
"windowTitle": f"All Total, Lift and Drag Forces for a Clark Y 14 Percent Airfoil - {raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m_s",
"xLabel": "Attack Angle [$\\alpha$]",
"yLabel": "Force [N]",
"grid": True,
"ledgLoc": 1,
"plots": [
{"x":aoa, "y":[f[0] for f in forces], "label":"Total Force"},
{"x":aoa, "y":[f[1] for f in forces], "label":"Lift"},
{"x":aoa, "y":[f[2] for f in forces], "label":"Drag"},
]
}
makeGraph(graph, False, figSavePath="./images/{0}.png", closeFig=True)
print("\n\n")
print(raw_data["rpm"])
print("AoA Total Lift Drag ---- Upper Force Lower Force ")
for aoa, force in [(a[-2], a[-1]) for a in cp_pain_data]:
print(f"{aoa:d}\\textdegree & {force[0]:.3f} & {force[1]:.3f} & {force[2]:.3f} -- {force[4]:.3f} {force[5]:.3f} \\\\")
print("-"*50)
print("\n\n")
print("Generating Cp Graphs") print("Generating Cp Graphs")
cp_data = {} cp_data = {}
@ -315,7 +365,7 @@ if __name__ == '__main__':
graph = { graph = {
"title": f"All $C_p$ vs Pitot Placement along Chord\nfor a Clark Y 14% Aerofoil at:\n{raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m/s)", "title": f"All $C_p$ vs Pitot Placement along Chord\nfor a Clark Y 14% Aerofoil at:\n{raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m/s)",
"windowTitle": f"All Cp along Clark Y 14 Percent Airfoil - {raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m_s", "windowTitle": f"All Cp along Clark Y 14 Percent Airfoil - {raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m_s",
"xLabel": "Normalized Pitot Placement", "xLabel": "Pitot Placement [m]",
"yLabel": "$C_p$", "yLabel": "$C_p$",
"grid": True, "grid": True,
"ledgLoc": 1, "ledgLoc": 1,
@ -327,7 +377,7 @@ if __name__ == '__main__':
cp = this_data[0] cp = this_data[0]
# Extrapolate Aerofoil Tip # Extrapolate Aerofoil Tip
p1, p2, pN = this_data[3] p1, p2, pN = this_data[2]
plts = ( plts = (
# Draw Lines # Draw Lines
@ -340,7 +390,7 @@ if __name__ == '__main__':
{"x": [PITOT_PLACEMENT_CHORD_NORM[9], pN[0]], "y": [cp.iloc[18], pN[1]], "colour": c["color"], "args":{"alpha":0.3}}, {"x": [PITOT_PLACEMENT_CHORD_NORM[9], pN[0]], "y": [cp.iloc[18], pN[1]], "colour": c["color"], "args":{"alpha":0.3}},
# Draw Points & text # Draw Points & text
{"x":PITOT_PLACEMENT_CHORD_NORM, "y":cp, "label":f"α = {int(this_data[4]):d}°", "type":"scatter", "args":{"zorder":2}, "colour": c["color"]}, {"x":PITOT_PLACEMENT_CHORD_NORM, "y":cp, "label":f"α = {int(this_data[-1]):d}°", "type":"scatter", "args":{"zorder":2}, "colour": c["color"]},
) )
for plt in plts: for plt in plts:
graph["plots"].append(plt) graph["plots"].append(plt)
@ -363,7 +413,7 @@ if __name__ == '__main__':
cp = this_data[0] cp = this_data[0]
# Extrapolate Aerofoil Tip # Extrapolate Aerofoil Tip
p1, p2, pN = this_data[3] p1, p2, pN = this_data[2]
plts = ( plts = (
# Draw Lines # Draw Lines
@ -376,58 +426,12 @@ if __name__ == '__main__':
{"x": [PITOT_PLACEMENT_CHORD_NORM[9], pN[0]], "y": [cp.iloc[18], pN[1]], "colour": c["color"], "args":{"alpha":0.3}}, {"x": [PITOT_PLACEMENT_CHORD_NORM[9], pN[0]], "y": [cp.iloc[18], pN[1]], "colour": c["color"], "args":{"alpha":0.3}},
# Draw Points & text # Draw Points & text
{"x":PITOT_PLACEMENT_CHORD_NORM, "y":cp, "label":f"α = {int(this_data[4]):d}°", "type":"scatter", "args":{"zorder":2}, "colour": c["color"]}, {"x":PITOT_PLACEMENT_CHORD_NORM, "y":cp, "label":f"α = {int(this_data[-1]):d}°", "type":"scatter", "args":{"zorder":2}, "colour": c["color"]},
) )
for plt in plts: for plt in plts:
graph["plots"].append(plt) graph["plots"].append(plt)
makeGraph(graph, False, figSavePath="./images/cp/__{0}.png", closeFig=True) makeGraph(graph, False, figSavePath="./images/cp/__{0}.png", closeFig=True)
if True:
aoa = [a[4] for a in cp_pain_data]
forces = [a[1] for a in cp_pain_data]
# Force Graphs
graph = {
"title": f"All Total, Lift & Drag Forces\nfor a Clark Y 14% Aerofoil at:\n{raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m/s)",
"windowTitle": f"All Total, Lift and Drag Forces for a Clark Y 14 Percent Airfoil - {raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m_s",
"xLabel": "Attack Angle [$\\alpha$]",
"yLabel": "Force [N]",
"grid": True,
"ledgLoc": 1,
"plots": [
{"x":aoa, "y":[f[0] for f in forces], "label":"Total Force"},
{"x":aoa, "y":[f[1] for f in forces], "label":"Lift"},
{"x":aoa, "y":[f[2] for f in forces], "label":"Drag"},
]
}
makeGraph(graph, False, figSavePath="./images/{0}.png", closeFig=True)
aoa = [a[4] for a in cp_pain_data][1::2]
forces = [a[1] for a in cp_pain_data][1::2]
# Force Graphs
graph = {
"title": f"All Total, Lift & Drag Forces\nfor a Clark Y 14% Aerofoil at:\n{raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m/s)",
"windowTitle": f"All Total, Lift and Drag Forces for a Clark Y 14 Percent Airfoil - {raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m_s",
"xLabel": "Attack Angle [$\\alpha$]",
"yLabel": "Force [N]",
"grid": True,
"ledgLoc": 1,
"plots": [
{"x":aoa, "y":[f[0] for f in forces], "label":"Total Force"},
{"x":aoa, "y":[f[1] for f in forces], "label":"Lift"},
{"x":aoa, "y":[f[2] for f in forces], "label":"Drag"},
]
}
makeGraph(graph, False, figSavePath="./images/{0}.png", closeFig=True)
if True:
print("\n\n")
print(raw_data["rpm"])
for aoa, force in [(a[4], a[1]) for a in cp_pain_data]:
print(f"{aoa:d}\\textdegree & {force[0]:.3f} & {force[1]:.3f} & {force[2]:.3f} \\\\")
print("-"*50)
print("\n\n")
print("Complete") print("Complete")