File size: 4,010 Bytes
c42edd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
"""Test the NeuralFoil API via HTTP requests"""

import requests
import json

# API endpoint
API_URL = "http://127.0.0.1:7861/api/predict"

print("Testing NeuralFoil API")
print("=" * 60)
print("Make sure the app is running: python app.py")
print("=" * 60)

# Test 1: Simple airfoil
print("\nTest 1: Simple airfoil with 9 points")
print("-" * 60)

coordinates = [
    [1.0, 0.0],
    [0.75, 0.03],
    [0.5, 0.05],
    [0.25, 0.04],
    [0.0, 0.0],
    [0.25, -0.02],
    [0.5, -0.03],
    [0.75, -0.02],
    [1.0, 0.0]
]

payload = {
    "data": [
        coordinates,  # airfoil coordinates
        5.0,          # angle of attack (degrees)
        1000000,      # Reynolds number
        "small"       # model size
    ]
}

try:
    response = requests.post(API_URL, json=payload)
    response.raise_for_status()
    result = response.json()
    
    if "data" in result and len(result["data"]) > 0:
        data = result["data"][0]
        
        print("βœ“ API call successful!")
        print(f"\nAerodynamic coefficients:")
        print(f"  CL = {data.get('CL', 'N/A')}")
        print(f"  CD = {data.get('CD', 'N/A')}")
        print(f"  CM = {data.get('CM', 'N/A')}")
        print(f"  Confidence = {data.get('analysis_confidence', 'N/A')}")
        
        if 'pressure_coefficients' in data:
            pc = data['pressure_coefficients']
            print(f"\nPressure coefficients:")
            print(f"  Upper surface: {len(pc.get('upper_surface_cp', []))} interpolated points")
            print(f"  Lower surface: {len(pc.get('lower_surface_cp', []))} interpolated points")
            print(f"  Upper (32 BL): {len(pc.get('upper_surface_cp_32', []))} points")
            print(f"  Lower (32 BL): {len(pc.get('lower_surface_cp_32', []))} points")
    else:
        print("βœ— Unexpected response format")
        print(json.dumps(result, indent=2)[:200])
        
except requests.exceptions.ConnectionError:
    print("βœ— Error: Cannot connect to API")
    print(f"   Make sure the app is running on {API_URL}")
    print("   Run: python app.py")
except Exception as e:
    print(f"βœ— Error: {e}")

# Test 2: RAE 2822 from file
print("\n\nTest 2: RAE 2822 airfoil from file")
print("-" * 60)

try:
    with open("examples/rae2822.dat", "r") as f:
        lines = f.readlines()[1:]  # Skip header
    
    coordinates = []
    for line in lines:
        parts = line.strip().split()
        if len(parts) >= 2:
            coordinates.append([float(parts[0]), float(parts[1])])
    
    print(f"Loaded {len(coordinates)} coordinate points")
    
    payload = {
        "data": [
            coordinates,
            2.0,      # alpha (deg)
            6e6,      # reynolds
            "large"   # model_size
        ]
    }
    
    response = requests.post(API_URL, json=payload)
    response.raise_for_status()
    result = response.json()
    
    if "data" in result and len(result["data"]) > 0:
        data = result["data"][0]
        
        print("βœ“ API call successful!")
        print(f"\nAerodynamic coefficients:")
        print(f"  CL = {data.get('CL', 'N/A')}")
        print(f"  CD = {data.get('CD', 'N/A')}")
        print(f"  CM = {data.get('CM', 'N/A')}")
        
        cl = data.get('CL', 0)
        cd = data.get('CD', 1)
        ld = cl / cd if cd and cd > 0 else 0
        print(f"  L/D = {ld:.1f}")
        
        if 'pressure_coefficients' in data:
            pc = data['pressure_coefficients']
            print(f"\nPressure coefficients:")
            print(f"  Upper surface: {len(pc.get('upper_surface_cp', []))} interpolated points")
            print(f"  Lower surface: {len(pc.get('lower_surface_cp', []))} interpolated points")
    
except FileNotFoundError:
    print("βœ— Error: examples/rae2822.dat not found")
except requests.exceptions.ConnectionError:
    print("βœ— Error: Cannot connect to API")
except Exception as e:
    print(f"βœ— Error: {e}")

print("\n" + "=" * 60)
print("Testing complete!")
print("=" * 60)