-
Notifications
You must be signed in to change notification settings - Fork 0
/
mnGen.py
executable file
·425 lines (353 loc) · 13.9 KB
/
mnGen.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#! /Users/tsuno/.pyenv/shims/python3
# -*- coding: utf-8 -*-
import math
import openpyxl
from openpyxl.utils import get_column_letter # 列幅の指定 2020/05/27
import pandas as pd
import numpy as np
import col
import os
import shutil
import report
########################################################################
# Main program
########################################################################
class MnGen():
########################################################################
# init data
def __init__(self,input_path):
print("--------------------")
print("Start Main")
print("--------------------")
if os.path.exists('./db'):
shutil.rmtree('./db')
os.mkdir('./db')
print('remove ./db ^v^!')
else:
os.mkdir('./db')
print('none *db')
####################
# path info.
self.inp_path = input_path
self.home_dir = os.path.dirname(self.inp_path)
########################################################################
# read cntl data
def read_cntl(self):
df_cntl = pd.read_excel(self.inp_path, sheet_name="CNTL",\
engine='openpyxl')
print("--------------------")
print("CNTL")
print("--------------------")
print(df_cntl)
# grobal var as following
self.out_path = self.home_dir + "/" + df_cntl.iloc[0,0]
self.view_path = self.home_dir + "/" + df_cntl.iloc[1,0]
self.report_path = self.home_dir + "/" + df_cntl.iloc[2,0]
self.report_title = str(df_cntl.iloc[2,1])
#
self.ndiv = int(df_cntl.iloc[0,1])
self.mdmax = df_cntl.iloc[0,2]
self.ndmin = df_cntl.iloc[0,3]
self.ndmax = df_cntl.iloc[0,4]
####################
# clear outputdata
if os.path.exists(self.out_path):
os.remove(self.out_path)
#print('remove',self.out_path,'^v^!')
print('exists,',self.out_path,'^v^!')
else:
print('none',self.out_path)
wb = openpyxl.Workbook()
wb.save(self.out_path)
########################################################################
# read_column data
def read_column(self):
# read data
####################
df_col = pd.read_excel(self.inp_path, sheet_name="COLUMN",\
engine='openpyxl' )
# skip if comment symbol "*" is in st.
df_col = df_col[ df_col['st'] != "*"]
print("--------------------")
print("COLUMN DATA")
print("--------------------")
print(df_col.head())
# data making
self.st = df_col.iloc[:,0].astype(int).values
self.symb = df_col.iloc[:,1].values
self.fc = df_col.iloc[:,2].values
self.fy = df_col.iloc[:,3].values
# additional for short term
self.lfc = df_col.iloc[:,4].values
self.sfc = df_col.iloc[:,5].values
self.lfy = df_col.iloc[:,6].values
self.sfy = df_col.iloc[:,7].values
self.alpha= df_col.iloc[:,8].values
# modified
#self.b = df_col.iloc[:,4].values
#self.d = df_col.iloc[:,5].values
#self.dia = df_col.iloc[:,6].astype(int).values
#
self.b = df_col.iloc[:,9].values
self.d = df_col.iloc[:,10].values
self.dia = df_col.iloc[:,11].astype(int).values
#
tmpnx = df_col[['nx1','nx2','nx3','nx4','nx5']]
tmpny = df_col[['ny1','ny2','ny3','ny4','ny5']]
tmpdtx = df_col[['dtx1','dtx2','dtx3','dtx4','dtx5']]
tmpdty = df_col[['dty1','dty2','dty3','dty4','dty5']]
#
#print(df_col[['nx1','nx2','nx3','nx4','nx5']])
#print( nx[ nx != '*' ])
#print(df_col.head())
#print(df_col)
#print(tmpnx.head())
#
self.nx = []
self.ny = []
self.dtx = []
self.dty = []
for i in range(0,len(tmpnx)):
self.nx.append( tmpnx.iloc[i,:].dropna().astype(int).values )
self.ny.append( tmpny.iloc[i,:].dropna().astype(int).values)
self.dtx.append( tmpdtx.iloc[i,:].dropna().values)
self.dty.append( tmpdty.iloc[i,:].dropna().values)
self.name = []
for i in range(0,len(self.fc)):
self.name.append( str(self.st[i]) + str(self.symb[i]) )
########################################################################
# make datasets for deep learning
def solve_deep(self):
print("---------------------------------")
print(" make datasets for deep learning ")
print("---------------------------------")
# load exel file
####################
wb = openpyxl.load_workbook(self.out_path)
# make mn data
####################
self.obj = [] # column object
# parameter for the deep learning
fc_d = []
fy_d = []
b_d = []
d_d = []
szx_d = []
szy_d = []
ag_d = []
nu_d = []
mu_d = []
for i in range(0,len(self.fc)):
self.obj.append(\
col.col(\
self.fc[i],self.fy[i],self.b[i],self.d[i],\
self.nx[i],self.ny[i],\
self.dtx[i],self.dty[i],self.dia[i],\
self.lfc[i],self.sfc[i],self.lfy[i],self.sfy[i],self.alpha[i]\
)\
)
#self.obj[i].mn_result_xlsx(self.ndiv,self.out_path,self.name[i],wb)
six,siy,szx,szy,ag =\
self.obj[i].feature()
nu, mu = self.obj[i].mnuGen("X",self.ndiv)
nu = nu*10**3/(self.b[i] * self.d[i])
mu = mu*10**6/(self.b[i]**2 * self.d[i] )
#print(six,siy,szx,szy,ag)
#for i in range(0,len(nu)):
# print(nu[i],mu[i])
for j in range(0,len(nu)):
fc_d.append( self.fc[i] )
fy_d.append( self.fy[i] )
b_d.append( self.b[i] )
d_d.append( self.d[i] )
szx_d.append( szx*6/(self.b[i]**2*self.d[i]) )
szy_d.append( szy*6/(self.b[i]*self.d[i]**2) )
ag_d.append( ag/(self.b[i]*self.d[i]) )
#nu_d.append(nu * 10**3 /(self.b[i] * self.d[i]))
#mu_d.append(mu * 10**6 /(self.b[i]**2 * self.d[i]))
nu_d = np.hstack( (np.array(nu_d), nu ))
mu_d = np.hstack( (np.array(mu_d), mu ))
#print(nu_d)
df_deep = pd.DataFrame({'fc':fc_d,
'fy':fy_d,
'b':b_d,
'd':d_d,
'szx':szx_d,
'szy':szy_d,
'ag':ag_d,
'nu':nu_d,
'mu':mu_d})
print(df_deep)
df_deep.to_csv('dl.dat')
#print('mux=',self.obj[i].mnuaci_twoM("X",0.0))
#print('muy=',self.obj[i].mnuaci_twoM("Y",0.0))
#print("mn generate ---- No.",i,self.name[i])
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(6,6),tight_layout=True)
ax = fig.add_subplot()
ax.scatter(df_deep['mu'],df_deep['nu'],s=5)
plt.show()
wb.save(self.out_path)
########################################################################
# solve
def solve(self):
print("--------------------")
print(" generate MN-data")
print("--------------------")
# load exel file
####################
wb = openpyxl.load_workbook(self.out_path)
# make mn data
####################
self.obj = [] # column object
for i in range(0,len(self.fc)):
self.obj.append(\
col.col(\
self.fc[i],self.fy[i],self.b[i],self.d[i],\
self.nx[i],self.ny[i],\
self.dtx[i],self.dty[i],self.dia[i],\
self.lfc[i],self.sfc[i],self.lfy[i],self.sfy[i],self.alpha[i]\
)\
)
self.obj[i].mn_result_xlsx(self.ndiv,self.out_path,self.name[i],wb)
#print('mux=',self.obj[i].mnuaci_twoM("X",0.0))
#print('muy=',self.obj[i].mnuaci_twoM("Y",0.0))
print("mn generate ---- No.",i,self.name[i])
wb.save(self.out_path)
# make mn fig
####################
for i in range(0,len(self.fc)):
print("draw section ------",self.name[i])
self.obj[i].make_model_fig(self.name[i])
########################################################################
# make report
def make_report(self):
# cntl: control file
# no use!!!!!!
# make report
cntl = "./"
num = len(self.fc)
pathname = self.report_path
title = "mn"
obj = report.Report(cntl,self.name)
obj.create_pdf(num,pathname,title)
########################################################################
# read calc
def read_calc(self):
########################################################################
# read_load
df_cal = pd.read_excel(self.inp_path, sheet_name="CALC",\
engine='openpyxl')
print(df_cal.head())
"""
calc_st = df_cal.iloc[:,0].values
calc_sym = df_cal.iloc[:,1].values
"""
# change column
calc_ind = df_cal.iloc[:,0].values
calc_st = df_cal.iloc[:,1].values
calc_sym = df_cal.iloc[:,2].values
"""
calc_xnum = df_cal.iloc[:,2].values
nend = 4+3*int(calc_xnum[0])
print( df_cal.iloc[:,4:nend] )
print( 'N=',df_cal['N_x1'].values )
print( 'M=',df_cal['M_x1'].values )
"""
print("--------------------")
print("CALC")
print("--------------------")
#print(calc_sym)
name_cal = [] # symbol name control
name_ind = [] # index name control
location = df_cal['loc']
"""
print('****** This is the test******')
print(location)
"""
for i in range(0,len(calc_sym)):
if calc_st[i] != "*":
name_cal.append( str(calc_st[i])+str(calc_sym[i]) )
name_ind.append( str(calc_ind[i])+name_cal[i] )
else:
name_cal.append( "*" )
name_ind.append( "*" )
#print( name_cal ,"!!!!!!")
#print(name_ind)
"""
for i in range(0,len(name_cal)):
if name_cal[i] != "*":
ind = self.name.index(name_cal[i])
# mn curve fig
#self.obj[ind].mn_result_xlsx(self.ndiv,self.out_path,self.name[ind])
# mn curve fig
self.obj[ind].make_fig(self.out_path,self.name[ind])
"""
# test
coldata = []
for i in range(0,len(name_cal)):
#print("mn drawing generate ---- No.",i,name_cal[i])
print("mn drawing generate ---- No.",i,name_ind[i],name_cal[i]) # modified index
if name_cal[i] != "*":
obj = col.Aft_mn(self.out_path,name_ind[i],name_cal[i],"XY",\
self.mdmax,self.ndmin,self.ndmax)
# get stress by excel
## x-dir.
xnum = int(df_cal.loc[i,'xnum'])
xtitle = []
nux = []
mux = []
if xnum != 0:
xtitle.append( str(df_cal.loc[i,'load_x1']) )
nux.append( float( df_cal.loc[i,'N_x1'] ) )
mux.append( float( df_cal.loc[i,'M_x1'] ) )
if xnum == 2:
xtitle.append( str(df_cal.loc[i,'load_x2']) )
nux.append( float( df_cal.loc[i,'N_x2'] ) )
mux.append( float( df_cal.loc[i,'M_x2'] ) )
print( 'xnum, Nux, Mux=', xnum, nux, mux )
## y-dir.
ynum = int(df_cal.loc[i,'ynum'])
ytitle = []
nuy = []
muy = []
if ynum != 0:
ytitle.append( str(df_cal.loc[i,'load_y1']) )
nuy.append( float( df_cal.loc[i,'N_y1'] ) )
muy.append( float( df_cal.loc[i,'M_y1'] ) )
if xnum == 2:
ytitle.append( str(df_cal.loc[i,'load_y2']) )
nuy.append( float( df_cal.loc[i,'N_y2'] ) )
muy.append( float( df_cal.loc[i,'M_y2'] ) )
print( 'ynum, Nuy, Muy=', ynum, nuy, muy )
# make mn figure by aftFib
obj.make_fig(xnum,xtitle,nux,\
mux,ynum,ytitle,nuy,muy)
coldata.append(obj.spec())
else:
coldata.append("*")
num = len(name_cal)
cntl = "./"
pathname = self.report_path
title = self.report_title
rep = report.Report(cntl,name_ind,name_cal,coldata,calc_st,location)
rep.create_pdf(num,pathname,title)
########################################################################
# end of class
if __name__ == '__main__':
#input_path = "./input_mngen/data.xlsx"
#input_path = "./input_mngen/data_new.xlsx"
#input_path = "./input_mngen/before.xlsx"
#input_path = "./input_mngen/after.xlsx"
#input_path = "./test/data.xlsx"
input_path = "./input_mngen/ve.xlsx"
obj = MnGen(input_path)
obj.read_cntl()
# they are sets
obj.read_column()
#
obj.solve()
obj.read_calc()
#or for deep learning
#obj.solve_deep()
######obj.make_report() # no use