-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aircraft_Wing_Load_Distribution.py
220 lines (175 loc) · 7.07 KB
/
Aircraft_Wing_Load_Distribution.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Name : Mmasechaba Justicia Francesca Seopa
# Student no : 834758
# Date : 10 May 2015
"""
Background info of the program:
This code is created to open a csv file, then create a matrix of our distances. then it is bound togo to an extent where is uses the guassian elimination method to get
the inverse and thenmultiplying that with the necessary matrix tho get the distributed load. then from there it needs to integrate the funtion to get co-efficients
for the shear an the bending moment, then get the constances, and thenafter this this code is going to allow us to know the bending moment of an aircraft wing then
we create an output csv file. from this we can deduce the mechanical stresses using the correct equation and many more stuffs
"""
#/////////////////////////////////////////////////function for opening and reading an csv file\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
import csv
def openningFile():
user=input('Please enter the the file name only,please do not add the extension: ')
mycsv=open(user+".csv", 'r')
FileReader=csv.reader(mycsv)
Distances = []
Loads = []
b= []
#formation of a matrix
for i in FileReader:
Distances.append(float(i[0]))
b.append(float(i[1]))
Loads.append(b)
b = []
return Distances, Loads,user
#/////////////////////////////////////////////////function for matrix creation\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def matrixCreation(Distances):
degree=int(input("Please enter the degree of polynomial you have at heart: "))
matrix=[]
for points in range(len(Distances)):
Length=[]
for k in range(int(degree)+1):
Length.append(Distances[points]**k)
matrix.append(Length)
t =len(matrix)-1
x= matrix[t][1]
return matrix,x
#/////////////////////////////////////////////////function for matrix transposing\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def interchangingMatrix(matrix):
trans1=[]
me=list(map(list,zip(*matrix)))
trans1.append(me)
trans=trans1[0]
return trans
#/////////////////////////////////////////////////function for matrix multiplication\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def multiplication(trans,matrix):
row=[]
for k in range(len(trans)):
sub= []
for j in range(len(matrix[0])):
temp=0
for i in range(len(trans[0])):
temp+=(trans[k][i]*matrix[i][j])
sub.append(temp)
row.append(sub)
sub = []
return row
#/////////////////////////////////////////////////function for matrix of zeros\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def identityMatrix(row):
Row = len(row)
Column = len(row[0])
eye = []
for i in range(Column):
new=[]
for j in range(Column):
if i==j:
new.append(1)
else:
new.append(0)
eye.append(new)
return eye
#/////////////////////////////////////////////////function for matrix inversion\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def antithesis(eye,row):
me = 0
ice = 0
for n in range(len(row)):
big = row[n][me]
for k in range(me ,len(row[n])):
row[n][k] = row[n][k]/big
while ice <len(row[n]):
eye[n][ice] = eye[n][ice]/big
ice +=1
ice = 0
if me < len(row)-1:
for z in range(me+1,len(row)):
submatrix =row[n][me]*row[z][me]
for t in range(len(row[z])):
row[z][t] = row[z][t] - row[n][t]*submatrix
eye[z][t] = eye[z][t] - eye[n][t]*submatrix
me +=1
mat = len(row)-1
the = mat
while mat > 0:
while the > 0:
music = row[the-1][mat]*row[mat][mat]
row[the-1][mat] = row[the-1][mat] -music
for f in range(len(eye[the-1])):
eye[the-1][f] = eye[the-1][f] - eye[mat][f]*music
the = the-1
mat = mat-1
the = mat
return eye
#///function for creating a list to make it easy to integrate the list many times\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def matrixSorting(tot):
Sorted = []
for w in range(len(tot)):
Sorted.append(tot[w][0])
return Sorted
#/////////////////////////////////////////////////function for integration\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def integral(j,x):
you= []
integral = []
m = 0
for i in range(len(j)):
you.append(j[i]/(i+1))
for k in range(len(you)):
m += you[k]*x**(k+1)
integral.append(-m)
for j in range(len(you)):
integral.append(you[j])
return integral
#/////////////////////////////////////////////////function for co-efficients for matrix\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def coefficient (j):
for g in range(len(j)):
if g == 0:
CoEf = str(j[g])+"x^"+str(g)
else:
CoEf = CoEf +" + "+str(j[g])+"x^"+str(g)
return CoEf
#/////////////////////////////////////////////////function for writing a file to csv\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def grace (j,h,p,name):
info = open(name+"out.csv","w")#lecture slides 18, 30 April by
for l in range(len(j)):
if l ==0:
info.write(str(j[l]))
else:
info.write(","+str(j[l]))
for w in range(len(h)):
if w ==0:
info.write("\n"+str(h[w]))
else:
info.write(","+str(h[w]))
for m in range(len(p)):
if m ==0:
info.write("\n"+str(p[m]))
else:
info.write(","+str(p[m]))
info.close()
#/////////////////////////////////////////////////function for main code\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
def main():
a = openningFile()
m = matrixCreation(a[0])
i = interchangingMatrix(m[0])
row = multiplication(i,m[0])
I = identityMatrix(row)
eye = antithesis(I,row)
x = multiplication(eye,i)
tot = multiplication(x,a[1])
j = matrixSorting(tot)
h = integral (j,m[1])
pie = integral (h,m[1])
kip = coefficient (j)
toe = coefficient (h)
Zip = coefficient (pie)
print("\n\n"+"Load Distribution :")
print("W ="+kip)
print("Shear Force :")
print("V ="+toe)
print("Bending Moment :")
print("M ="+Zip)
print()
grace(j,h,pie,a[2])
if __name__== "__main__":
main()