In [1]:
%load_ext autoreload
%autoreload 2
from numpy import *
import numpy as np
from bokeh.plotting import *
from pandas import read_excel
from matmodlab2.fitting.hyperopt import *
output_notebook()
In [2]:
# uniaxial data
udf = read_excel('Treloar_hyperelastic_data.xlsx', sheetname='Uniaxial')
ud = udf.as_matrix(columns=('Engineering Strain', 'Engineering Stress (MPa)'))
# Biaxial data
bdf = read_excel('Treloar_hyperelastic_data.xlsx', sheetname='Biaxial')
bd = bdf.as_matrix(columns=('Engineering Strain', 'Engineering Stress (MPa)'))
# Pure shear data
sdf = read_excel('Treloar_hyperelastic_data.xlsx', sheetname='Pure Shear')
sd = sdf.as_matrix(columns=('Engineering Strain', 'Engineering Stress (MPa)'))
In [3]:
uf = hyperopt(UNIAXIAL_DATA, ud[:,0], ud[:,1])
print(uf.summary())
At this point, the optimal parameters have been determined and are accessible with the popt
attribute:
In [4]:
uf.popt
Out[4]:
The optimal parameters are also available as a dictionary via the todict
method:
In [5]:
uf.todict()
Out[5]:
The error in the fit:
In [6]:
uf.error
Out[6]:
Plots are generated with the bp_plot
method
In [7]:
show(uf.bp_plot())
In [8]:
bf = hyperopt(BIAXIAL_DATA, bd[:,0], bd[:,1])
print(bf.summary())
show(bf.bp_plot())
In [9]:
sf = hyperopt(SHEAR_DATA, sd[:,0], sd[:,1])
print(sf.summary())
show(sf.bp_plot())
Examine the error in the shear fit using parameters from the uniaxial fit
In [10]:
y1 = sf.eval(overlay=uf)
y2 = sf.eval()
err = sqrt(mean((y1-y2)**2)) / average(abs(y2))
print(err)
show(sf.bp_plot(overlay=[bf, uf]))
show(uf.bp_plot(overlay=[sf]))
show(bf.bp_plot(overlay=[uf, sf]))
In [11]:
f = hyperopt2(SHEAR_DATA, sd[:,0], sd[:,1],
UNIAXIAL_DATA, ud[:,0], ud[:,1],
BIAXIAL_DATA, bd[:,0], bd[:,1])
In [12]:
print(f.summary())
In [13]:
f.error2
Out[13]:
In [14]:
p = f.bp_plot(strain=linspace(0,6.5), points=False)
p.circle(sd[:,0], sd[:,1], color='black', legend='Shear data')
p.circle(bd[:,0], bd[:,1], color='red', legend='Biaxial data')
p.circle(ud[:,0], ud[:,1], color='green', legend='Uniaxial data')
show(p)
In [ ]: