In [2]:
%run matt_startup
%run -i matt_utils
button_qtconsole()
#import other needed modules in all used engines
#with dview.sync_imports():
# import os
In [33]:
filename = 'FIWT_Exp014_20150601105647.dat.npz'
def loadData():
# Read and parse raw data
global exp_data
exp_data = np.load(filename)
# Select colums
global T_rig, phi_rig
T_rig = exp_data['data44'][:,0]
phi_rig = exp_data['data44'][:,2]
loadData()
In [34]:
text_loadData()
Click 'Check data' button to show the raw data.
Click on curves to select time point and push into queue; click 'T/s' text to pop up last point in the queue; and click 'Output' text to print time sequence table.
In [35]:
def checkInputOutputData():
#check inputs/outputs
fig, ax = plt.subplots(2,1,True)
ax[1].plot(T_rig,phi_rig, 'b', picker=2)
ax[1].set_ylabel('$\phi \/ / \/ ^o/s$')
ax[1].set_xlabel('$T \/ / \/ s$', picker=True)
ax[0].set_title('Output', picker=True)
fig.canvas.mpl_connect('pick_event', onPickTime)
fig.show()
display(fig)
button_CheckData()
For each section,
In [36]:
# Pick up focused time ranges
time_marks = [[341.47, 350, "free drop 1"],
[369.83, 377, "free drop 2"],
[392.38, 400, "free drop 3"],
[413.57, 421, "free drop 4"],
[439.80, 450, "free drop 5"],
[463.46, 474, "free drop 6"],
[488.48, 498, "free drop 7"],
[509.40, 520, "free drop 8"],
[531.80, 543, "free drop 9"],
[557.84, 569, "free drop 10"],
[587.60, 599, "free drop 11"],
[615.00, 627, "free drop 12"]
]
# Decide DT,U,Z and their processing method
DT=0.01
process_set = {
'U':[],
'Z':[(T_rig, phi_rig,3),],
'cutoff_freq': 10 #Hz
}
U_names = []
Y_names = Z_names = ['$\phi_{a,rig} \, / \, ^o$',
'$\dot{\phi}_{a,rig} \, / \, ^o/s$',]
display_data_prepare()
In [37]:
resample(True);
In [38]:
%%px --local
#update common const parameters in all engines
#problem size
Nx = 2
Nu = 0
Ny = 2
Npar = 7
#reference
S_c = 0.1254 #S_c(m2)
b_c = 0.7 #b_c(m)
g = 9.81 #g(m/s2)
#other parameters
v_th = 0.5/57.3 #v_th(rad/s)
v_th2 = 0.5/57.3 #v_th(rad/s)
def x0(Z,T,U,params):
return Z[0,:]/57.3
def xdot(X,t,U,params):
F_c = params[0]
f = params[1]
Ixx = params[2]
m_T = params[3]
l_z_T = params[4]
kBrk = params[5]
phi0 = params[6]
phi = X[0]
phi_dot = X[1]
moments = -(m_T*l_z_T)*g*math.sin(phi-phi0)
abs_phi_dot = abs(phi_dot)
F = f*phi_dot
if abs_phi_dot > v_th+v_th2:
F += math.copysign(F_c, phi_dot)
elif abs_phi_dot > v_th:
F += math.copysign(F_c*(kBrk-(kBrk-1)*(abs_phi_dot-v_th)/v_th2), phi_dot)
else:
F += phi_dot/v_th*(F_c*kBrk)
moments -= F
phi_dot2 = moments/Ixx
return [phi_dot, phi_dot2]
def obs(X,T,U,params):
return X*57.3
In [39]:
display(HTML('<b>Constant Parameters</b>'))
table = ListTable()
table.append(['Name','Value','unit'])
table.append(['$S_c$',S_c,'$m^2$'])
table.append(['$b_c$',b_c,'$m$'])
table.append(['$g$',g,'$m/s^2$'])
display(table)
In [40]:
#initial guess
param0 = [
0.05, #F_c(N*m)
0.03, #f(N*m/(rad/s))
0.1678, #Ixx(kg*m2)
7.5588, #m_T(kg)
0.0526, #l_z_T(m)
1.01, #kBrk
0, #phi0(rad)
]
param_name = ['$F_c$','$f$', '$I_{xx,rig}$', '$m_T$',r'$l_{zT}$','$k_{Brk}$','$phi_0$']
param_unit = ['$Nm$',r'$\frac{Nm}{rad/s}$', '$kg\,m^2$', 'kg', 'm','1', 'rad']
NparID = 4
opt_idx = [0,1,2,6]
opt_param0 = [param0[i] for i in opt_idx]
par_del = [0.3*1e-3, 0.3*1e-3, 0.2*1e-3, 0.0174]
bounds = [(1e-6,0.15),(1e-6,0.1), (1e-6,0.5), (-0.1,0.1)]
display_default_params()
#select sections for training
section_idx = range(8)
display_data_for_train()
#push parameters to engines
push_opt_param()
In [41]:
# select 2 section from training data
idx = random.sample(section_idx, 2)
interact_guess();
In [42]:
display_preopt_params()
if True:
InfoMat = None
method = 'trust-ncg'
def hessian(opt_params, index):
global InfoMat
return InfoMat
dview['enable_infomat']=True
options={'gtol':1}
opt_bounds = None
else:
method = 'L-BFGS-B'
hessian = None
dview['enable_infomat']=False
options={'ftol':1e-4,'maxfun':200}
opt_bounds = bounds
cnt = 0
tmp_rslt = None
T0 = time.time()
print('#cnt, Time, |R|')
%time res = sp.optimize.minimize(fun=costfunc, x0=opt_param0, \
args=(opt_idx,), method=method, jac=True, hess=hessian, \
bounds=opt_bounds, options=options)
In [43]:
display_opt_params()
# show result
idx = range(len(time_marks))
display_data_for_test();
update_guess();
In [20]:
toggle_inputs()
button_qtconsole()
In [ ]: