def objf(xs): """ The objective function generated in mk.yieldFunction.tuneH48.returnObjYS Argument -------- xs -- <f,g,h,n> the four Hill48 parameters in the plane-stress space. """ nth = len(np.array(ref[0])) th=np.linspace(-pi,+pi,nth) x=cos(th); y=sin(th) z=np.zeros(len(th)) s=np.array([x,y,z,z,z,z]).T f,g,h,n = xs X=[]; Y=[] for i in xrange(len(s)): rst=fYLD(s[i],f,g,h,n) ys = rst[0] X.append(ys[0]) Y.append(ys[1]) X=np.array(X) Y=np.array(Y) ## rst to th-r coordinate r,th = xy2rt(X,Y) R,TH = xy2rt(ref[0],ref[1]) diff = ((r-R)**2).sum()/(len(th)-1) return diff
def returnDiff(params): """ Tune using the given in-plane locus Arguments ========= params [0] : rb params [1:4]: y45,y90,yb """ ## Find 4 parameters... paramR = np.ones(4) paramY = np.ones(4) paramR[0:4] = rv[0], rv[1], rv[2], params[0] paramY[1:4] = params[1:4] k = 2 m = 8 ## the exponent is fixed? yldFunc = wrapYLD(r=paramR, y=paramY, m=m, k=k) if type(yldFunc).__name__ == 'int': if yldFunc == -1: return 1 yldLocus = locus(yldFunc, 1000) ## ## convert yldLocus in to (th,r) coordinates r, th = xy2rt(np.array(yldLocus[0]), np.array(yldLocus[1])) th0, r0 = YS ## reference radIntp = rad_xy2(r, th, th0) radIntp = np.array(radIntp) return np.sqrt(((radIntp - r0)**2).sum()) / (len(r) - 1)
def extractParamsFromYS(locus_planestress,psi_uni,rvs_uni,ys_uni): """ Given plane-stress yield locus, extract parameters. """ from vpscyld import lib_dat, calc_normal ## normalize the locus by stress along axis 1 ysx, ysy =lib_dat.nys_th(np.array(locus_planestress[0]),np.array(locus_planestress[1]),t=0) ysr, yst = lib_dat.xy2rt(ysx,ysy) yb = lib_dat.rad_xy(ysr,yst,45*np.pi/180.) ## balanced biaxial yield stress... yb = yb / np.sqrt(2) y0 = lib_dat.rad_xy(ysr,yst,0) ## balanced biaxial yield stress... y90 = lib_dat.rad_xy(ysr,yst,90*np.pi/180.) ## balanced biaxial yield stress... th = calc_normal.main_var(locus_xy=[ysr,yst],psi_ref=[45.]) rb = 1./np.tan(th[0]) y0_uni = ys_uni[0] y90_uni = ys_uni[-1] r0_uni = rvs_uni[0] r90_uni = rvs_uni[-1] r45_uni = np.interp(45*np.pi/180., psi_uni, rvs_uni) y45_uni = np.interp(45*np.pi/180., psi_uni, ys_uni) if abs(y0_uni-y0)>1e-3: print 'y0 diff' print y0_uni,y0 # raise IOError, 'Consider using finer step for yield locus' if abs(y90_uni-y90)>1e-3: print 'y90 diff' print y90_uni, y90 # raise IOError, 'Consider using finer step for yield locus' return y0,y90,yb,rb, y45_uni, r45_uni
def returnDiff(params): """ Tune using the given in-plane locus Arguments ========= params [0] : rb params [1:4]: y45,y90,yb """ ## Find 4 parameters... paramR = np.ones(4) paramY = np.ones(4) paramR[0:4] = rv[0],rv[1],rv[2],params[0] paramY[1:4] = params[1:4] k=2; m=8 ## the exponent is fixed? yldFunc = wrapYLD(r=paramR,y=paramY,m=m,k=k) if type(yldFunc).__name__=='int': if yldFunc==-1: return 1 yldLocus = locus(yldFunc,1000) ## ## convert yldLocus in to (th,r) coordinates r,th=xy2rt(np.array(yldLocus[0]),np.array(yldLocus[1])) th0,r0 = YS## reference radIntp = rad_xy2(r,th,th0) radIntp = np.array(radIntp) return np.sqrt(((radIntp-r0)**2).sum())/ (len(r)-1)
def ex1(): """ Excercise - Tune H48 using three r-values and calculate YS. Using the three given r-values used in H48 find rb, y0, y45, y90, and yb by fitting YS of H48 with that of yld2000-2d """ import tuneH48 import mk.yieldFunction.yf2 as yf2 rv = [2.2, 2.0, 2.9] f, g, h, n = tuneH48.tuneGenR(r=rv) yfunc_H48 = yf2.wrapHill48Gen(f, g, h, n) YS_H48X, YS_H48Y = locus(yfunc_H48, 1000) r, th = xy2rt(np.array(YS_H48X), np.array(YS_H48Y)) ## popt = [rv, y45, y90, yb] popt = case2([r, th], rv=rv) rv.append(popt[0]) ys = np.ones(4) ys[1:] = popt[1:] ## print 'rv:', rv print 'ys:', ys yfunc_yld2000 = wrapYLD(r=rv, y=ys, m=8) import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) YS_YLDX, YS_YLDY = locus(yfunc_yld2000, 1000) ax.plot(YS_H48X, YS_H48Y, '-', label='Hill48') ax.plot(YS_YLDX, YS_YLDY, '-', label='YLD2000') ax.set_xlim(0., ) ax.set_ylim(0., ) ax.set_aspect('equal') ax.legend(loc='best') # print YS_YLDX # print YS_YLDY fig.savefig('Yld2000-Hill48.pdf')
def ex1(): """ Excercise - Tune H48 using three r-values and calculate YS. Using the three given r-values used in H48 find rb, y0, y45, y90, and yb by fitting YS of H48 with that of yld2000-2d """ import tuneH48 import mk.yieldFunction.yf2 as yf2 rv=[2.2,2.0,2.9] f,g,h,n = tuneH48.tuneGenR(r=rv) yfunc_H48 = yf2.wrapHill48Gen(f,g,h,n) YS_H48X, YS_H48Y = locus(yfunc_H48,1000) r, th = xy2rt(np.array(YS_H48X), np.array(YS_H48Y)) ## popt = [rv, y45, y90, yb] popt = case2([r,th], rv=rv) rv.append(popt[0]) ys = np.ones(4) ys[1:] = popt[1:] ## print 'rv:', rv print 'ys:', ys yfunc_yld2000 = wrapYLD(r=rv,y=ys,m=8) import matplotlib.pyplot as plt fig = plt.figure(); ax=fig.add_subplot(111) YS_YLDX, YS_YLDY = locus(yfunc_yld2000,1000) ax.plot(YS_H48X,YS_H48Y,'-',label='Hill48') ax.plot(YS_YLDX,YS_YLDY,'-',label='YLD2000') ax.set_xlim(0.,) ax.set_ylim(0.,) ax.set_aspect('equal') ax.legend(loc='best') # print YS_YLDX # print YS_YLDY fig.savefig('Yld2000-Hill48.pdf')
def extractParamsFromYS(locus_planestress, psi_uni, rvs_uni, ys_uni): """ Given plane-stress yield locus, extract parameters. """ from vpscyld import lib_dat, calc_normal ## normalize the locus by stress along axis 1 ysx, ysy = lib_dat.nys_th(np.array(locus_planestress[0]), np.array(locus_planestress[1]), t=0) ysr, yst = lib_dat.xy2rt(ysx, ysy) yb = lib_dat.rad_xy(ysr, yst, 45 * np.pi / 180.) ## balanced biaxial yield stress... yb = yb / np.sqrt(2) y0 = lib_dat.rad_xy(ysr, yst, 0) ## balanced biaxial yield stress... y90 = lib_dat.rad_xy(ysr, yst, 90 * np.pi / 180.) ## balanced biaxial yield stress... th = calc_normal.main_var(locus_xy=[ysr, yst], psi_ref=[45.]) rb = 1. / np.tan(th[0]) y0_uni = ys_uni[0] y90_uni = ys_uni[-1] r0_uni = rvs_uni[0] r90_uni = rvs_uni[-1] r45_uni = np.interp(45 * np.pi / 180., psi_uni, rvs_uni) y45_uni = np.interp(45 * np.pi / 180., psi_uni, ys_uni) if abs(y0_uni - y0) > 1e-3: print 'y0 diff' print y0_uni, y0 # raise IOError, 'Consider using finer step for yield locus' if abs(y90_uni - y90) > 1e-3: print 'y90 diff' print y90_uni, y90 # raise IOError, 'Consider using finer step for yield locus' return y0, y90, yb, rb, y45_uni, r45_uni