-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
112 lines (84 loc) · 2.6 KB
/
Copy pathutils.py
File metadata and controls
112 lines (84 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
Utility functions for Wing Analyzer application
"""
import os
import pandas as pd
import numpy as np
def normalize(series, invert=False):
"""
Normalize a pandas Series to [0, 1] range
Args:
series: pandas Series to normalize
invert: If True, inverts the series before normalization
Returns:
Normalized pandas Series
"""
s = series.copy()
if invert:
s = -s
return (s - s.min()) / (s.max() - s.min())
def ensure_file_removed(filepath):
"""
Remove a file if it exists
Args:
filepath: Path to the file to remove
"""
if os.path.exists(filepath):
os.remove(filepath)
def save_dataframe_csv(df, filepath, remove_existing=True):
"""
Save a DataFrame to CSV with optional file removal
Args:
df: pandas DataFrame to save
filepath: Path to save the CSV
remove_existing: If True, removes existing file first
"""
if remove_existing:
ensure_file_removed(filepath)
df.to_csv(filepath, index=False)
print(f"Saved data to {filepath}")
def get_airfoil_files(folder_path):
"""
Get all .dat airfoil files from a folder
Args:
folder_path: Path to folder containing airfoil files
Returns:
List of airfoil file paths
"""
if not os.path.exists(folder_path):
raise FileNotFoundError(f"Airfoils folder not found: {folder_path}")
files = [f for f in os.listdir(folder_path) if f.endswith(".dat")]
if not files:
raise ValueError(f"No .dat files found in {folder_path}")
return files
def calculate_reynolds_number(velocity, chord, kinematic_viscosity=1.81e-5):
"""
Calculate Reynolds number
Args:
velocity: Flow velocity (m/s)
chord: Chord length (m)
kinematic_viscosity: Kinematic viscosity (m^2/s)
Returns:
Reynolds number
"""
return velocity * chord / kinematic_viscosity
def calculate_lift_force(cl, velocity, chord, wingspan, air_density=1.225):
"""
Calculate lift force in Newtons
Args:
cl: Lift coefficient
velocity: Flow velocity (m/s)
chord: Chord length (m)
wingspan: Wing span (m)
air_density: Air density (kg/m^3)
Returns:
Lift force in Newtons
"""
wing_area = chord * wingspan
return cl * 0.5 * air_density * velocity**2 * wing_area
def newtons_to_kgs(force_newtons):
"""Convert Newtons to kilograms"""
return force_newtons / 9.81
def kgs_to_newtons(mass_kgs):
"""Convert kilograms to Newtons"""
return mass_kgs * 9.81