-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcpacspy_use.py
186 lines (145 loc) · 5.55 KB
/
cpacspy_use.py
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Script to show how to use the cpacspy package
# Importing cpacspy
from cpacspy.cpacspy import CPACS
# Load a CPACS file
cpacs = CPACS("D150_simple.xml")
# For each object you can print it to what it contains
print(cpacs)
print(cpacs.aircraft)
# Aircraft reference value
print("Ref length:", cpacs.aircraft.ref_length, "m")
print("Ref area:", cpacs.aircraft.ref_area, "m^2")
print(
"Ref point:",
f"({cpacs.aircraft.ref_point_x}, \
{cpacs.aircraft.ref_point_y}, {cpacs.aircraft.ref_point_z}) m",
)
# Wing specific values
# To choose another reference wing (by default the largest wing is the reference one)
# cpacs.aircraft.ref_wing_idx = 3
# or with uid
# cpacs.aircraft.ref_wing_uid = 'Wing3V'
print("Main wing aspect ratio", cpacs.aircraft.wing_ar)
print("Main wing area", cpacs.aircraft.wing_area)
print("Main wing span", cpacs.aircraft.wing_span)
# Get list of all available aeroMaps
print(cpacs.get_aeromap_uid_list())
# Loop in all aeroMaps
for aeromap in cpacs.aeromaps:
print("---")
print(aeromap.uid)
print(aeromap.description)
# Get values from an aeromap
one_aeromap = cpacs.get_aeromap_by_uid("extended_aeromap")
print(one_aeromap.get("angleOfAttack", alt=15500.0, aos=0.0, mach=0.3))
print(one_aeromap.get("cl", alt=15500.0, aos=0.0, mach=0.3))
print(one_aeromap.get("angleOfAttack", alt=15500.0, aos=0.0, mach=[0.3, 0.4, 0.5]))
print(one_aeromap.get("cd", alt=15500.0, aos=0.0, mach=[0.3, 0.4, 0.5]))
# Plot aeromap
# one_aeromap.plot("cd", "cl", alt=15500, aos=0.0, mach=0.5)
# one_aeromap.plot("angleOfAttack", "cd", alt=15500, aos=0.0, mach=0.5)
# Add new values to the aeromap
simple_aeromap = cpacs.get_aeromap_by_uid("aeromap_test2")
simple_aeromap.add_row(
mach=0.555, alt=15000, aos=0.0, aoa=2.4, cd=0.001, cl=1.1, cs=0.22, cmd=0.22
)
# Remove a row from the aeromap (from its parameters values)
simple_aeromap.remove_row(mach=0.555, alt=15000, aos=0.0, aoa=2.4)
simple_aeromap.save()
### Add a new aeromap with values
# Create new aeromap
new_aeromap = cpacs.create_aeromap("my_new_aeromap")
# Add a description
new_aeromap.description = "Test of creation of a new aeromap"
# Fill the aeromap with parameter and coefficients
for i in range(12):
new_aeromap.add_row(
mach=0.555,
alt=15000,
aos=0.0,
aoa=i,
cd=0.001 * i**2,
cl=0.1 * i,
cs=0.0,
cmd=0.0,
cml=1.1,
cms=0.0,
)
# Print the aeromap
print(new_aeromap)
# Save the aeromamp
new_aeromap.save()
# Delete the aeromap
cpacs.delete_aeromap("aeromap_test1")
print(cpacs.get_aeromap_uid_list())
# Duplicate an aeromap
duplicated_aeromap = cpacs.duplicate_aeromap("my_new_aeromap", "my_duplicated_aeromap")
duplicated_aeromap.add_row(
mach=0.666, alt=10000, aos=0.0, aoa=2.4, cd=0.001, cl=1.1, cs=0.22, cmd=0.22
)
# Modfiy aerocoef
print(duplicated_aeromap.get("cd"))
duplicated_aeromap.df["cd"] = duplicated_aeromap.df["cd"].add(1.0)
duplicated_aeromap.save()
print(duplicated_aeromap.get("cd"))
# Export to CSV
duplicated_aeromap.export_csv("aeromap.csv")
# Import from CSV
imported_aeromap = cpacs.create_aeromap_from_csv("aeromap.csv", "imported_aeromap")
imported_aeromap.description = "This aeromap has been imported from a CSV file"
imported_aeromap.save()
# AeroMap with Damping Derivatives coefficients
aeromap_dd = cpacs.duplicate_aeromap("imported_aeromap", "aeromap_dd")
aeromap_dd.description = "Aeromap with damping derivatives coefficients"
# Add damping derivatives coefficients to the aeromap
# Coefficients must be one of the following: 'cd', 'cl', 'cs', 'cmd', 'cml', 'cms'
# Axis must be one of the following: 'dp', 'dq', 'dr'
# The sign of the rate will determine if the coefficient are stored
# in /positiveRate or /negativeRate
aeromap_dd.add_damping_derivatives(
alt=15000, mach=0.555, aos=0.0, aoa=0.0, coef="cd", axis="dp", value=0.001, rate=-1.0
)
# Same in a loop
for i in range(11):
aeromap_dd.add_damping_derivatives(
alt=15000,
mach=0.555,
aos=0.0,
aoa=i + 1,
coef="cd",
axis="dp",
value=0.001 * i + 0.002,
rate=-1.0,
)
aeromap_dd.save()
# Get damping derivatives coefficients
print(aeromap_dd.get_damping_derivatives(alt=15000, mach=0.555, coef="cd", axis="dp", rates="neg"))
print(
aeromap_dd.get_damping_derivatives(
alt=15000, mach=0.555, aoa=[4.0, 6.0, 8.0], coef="cd", axis="dp", rates="neg"
)
)
# Also works with the simple "get" function, but the "coef name" is a bit more complicated
print(aeromap_dd.get("dampingDerivatives_negativeRates_dcddpStar", aoa=[4.0, 6.0, 8.0]))
# Damping derivatives coefficients can also be plotted
# aeromap_dd.plot(
# "angleOfAttack", "dampingDerivatives_negativeRates_dcddpStar", alt=15000, aos=0.0, mach=0.555
# )
## Analyses
# CD0 and oswald factor
aspect_ratio = cpacs.aircraft.wing_ar
cd0, e = one_aeromap.get_cd0_oswald(aspect_ratio, alt=15500.0, aos=0.0, mach=0.5)
# Get Force
one_aeromap.calculate_forces(cpacs.aircraft)
print(one_aeromap.get("cd", alt=15500.0, aos=0.0, mach=[0.3, 0.4, 0.5]))
print(one_aeromap.get("drag", alt=15500.0, aos=0.0, mach=[0.3, 0.4, 0.5]))
# Check Stability
stable, msg = one_aeromap.check_longitudinal_stability(alt=15500.0, aos=0.0, mach=0.5)
print("Longitudinal: ", stable)
stable, msg = one_aeromap.check_directional_stability(alt=15500.0, aoa=0.0, mach=0.4)
print("Directional: ", stable, "->", msg)
stable, msg = one_aeromap.check_lateral_stability(alt=15500.0, aoa=0.0, mach=0.3)
print("Lateral: ", stable, "->", msg)
## Save
# Save all the change in a CPACS file
cpacs.save_cpacs("D150_simple_updated_aeromap_tmp.xml", overwrite=True)