def ex_consistency( ifig=50,nxphi=3, exp_ref=[],exp_lab=[],mod_ext=None, mod_ref='STR_STR.OUT',sin2psimx=None, iscatter=False,sigma=5e-5,psimx=None,psi_nbin=1, ig_sub=True,istep=None,hkl=None,iplot=True, iwind=False,wdeg=2,ipsi_opt=1,fn_sff=None, pmargin=None,path='', sf_ext=None,ig_ext=None,iwgt=False): """ Consistency check between 'weighted average' stress and the stress obtained following the stress analysis method (SF, IG strain) ifig = 50 nxphi : display only first nxphi of results along phi axis exp_ref : experimental reference mode_ref : model's weighted average flow curves are given sin2psimx : limiting the maximum sin2psi values, with which stress-fitting is carried out iscatter (False) : introducing a random scattering of 'ehkl' psimx : limiting the maximum psi value psi_nbin : If other than 1, limit the number of data ig_sub : flag whether or not subtract the IG strain istep : If other than None, analysis is carried out for a specific istep hkl : hkl of plane, for the sake of labels. iplot (True) : flag whether or not MPL plot is performed ipsi_opt 0: sin2psi 1: sing(psi) * sin2psi 2: psi pmargin : portional margin of volume that should exceed to contribute to the ehkl/SF/IG in model_rs path : place holder for strain path sf_ext : Overwrite stress factor ig_ext : Overwrite IG strain iwgt : Whether or not accounting for 'weight' """ from rs import ResidualStress,u_epshkl,filter_psi,\ filter_psi2,psi_reso, psi_reso2, psi_reso3 from MP.mat import mech # mech is a module FlowCurve = mech.FlowCurve if iplot: from matplotlib import pyplot as plt from matplotlib.backends.backend_pdf import PdfPages from MP.lib import mpl_lib,axes_label wide_fig = mpl_lib.wide_fig fancy_legend = mpl_lib.fancy_legend ## Collection of figures at various plastic strains fe = PdfPages('all_ehkl_fits_%s_%s.pdf'%(hkl,path)) fs = PdfPages('all_stress_factors_%s_%s.pdf'%(hkl,path)) f_er = PdfPages('all_Ei-ehkl-e0_%s_%s.pdf'%(hkl,path)) # fig1 is 'flow_**.pdf' fig1 = wide_fig(ifig,nw=2,nh=1,left=0.2,uw=3.5, w0=0,w1=0.3,right=0,iarange=True) ## ax1: Equivalent Stress/Strain ## ax2: Stress path in the plane stress space (RD/TD) ax1 = fig1.axes[0]; ax2 = fig1.axes[1] ax2.set_axis_bgcolor('0.95') ## i_ip = 1: model case model_rs = ResidualStress( mod_ext=mod_ext, fnmod_ig='igstrain_fbulk_ph1.out', fnmod_sf='igstrain_fbulk_ph1.out', i_ip=1) ## masking array element based on diffraction volume model_rs.dat_model.mask_vol() if pmargin!=None: model_rs.dat_model.mask_vol_margin(pmargin) if mod_ext==None: mod_ref='STR_STR.OUT' else: mod_ref='%s.%s'%( mod_ref.split('.')[0],mod_ext) flow_weight = FlowCurve(name='Model weighted') flow_weight.get_model(fn=mod_ref) flow_weight.get_eqv() ## calc Von Mises stress/strain if len(flow_weight.epsilon_vm)<5: lc='bx' else: lc='bx-' if iplot: ax1.plot(flow_weight.epsilon_vm,flow_weight.sigma_vm, lc,label='Weighted avg',alpha=1.0) axes_label.__eqv__(ax1,ft=10) ## plot all stress factors at individual deformation levels stress = [] print '%8s%8s%8s%8s%8s%8s'%( 'S11','S22','S33','S23','S13','S12') for istp in range(model_rs.dat_model.nstp): """ Dimensions of data arrays for: ============================== sf (nstp, k, nphi, npsi) ig (nstp, nphi, npsi) ehkl (nstp, nphi, npsi) strain (nstp, 6) vf (nstp, nphi, npsi) """ model_rs.sf = model_rs.dat_model.sf[istp] model_rs.eps0 = model_rs.dat_model.ig[istp] model_rs.ehkl = model_rs.dat_model.ehkl[istp] ## whether or not intergranular strain is subtracted. if ig_sub: model_rs.tdat = model_rs.ehkl - model_rs.eps0 else: model_rs.tdat = model_rs.ehkl tdat_ref = model_rs.tdat[::] ## Inducing 'scatters' if iscatter: tdat_scatter = [] for iphi in range(len(tdat_ref)): dum = u_epshkl(tdat_ref[iphi],sigma=sigma) tdat_scatter.append(dum) tdat_scatter = np.array(tdat_scatter) model_rs.tdat = tdat_scatter model_rs.phis = model_rs.dat_model.phi model_rs.psis = model_rs.dat_model.psi model_rs.nphi = len(model_rs.phis) model_rs.npsi = len(model_rs.psis) wgt = model_rs.dat_model.vf[istp][::] if sin2psimx!=None or psimx!=None: filter_psi(model_rs,sin2psimx=sin2psimx,psimx=psimx) wgt = filter_psi2( wgt,sin2psi=np.sin(model_rs.psis)**2, bounds =[0., sin2psimx]) if sf_ext!=None: model_rs.sf = sf_ext[istp] elif ig_ext!=None: model_rs.ig = ig_ext[istp] if psi_nbin!=1: wgt = psi_reso3(wgt,psi=model_rs.psis,ntot=psi_nbin) psi_reso2(model_rs,ntot=psi_nbin) #-----------------------------------# ## find the sigma ... s11 = model_rs.dat_model.flow.sigma[0,0][istp] s22 = model_rs.dat_model.flow.sigma[1,1][istp] if iwgt: pass else: wgt = None # overwrite wgt dsa_sigma = model_rs.find_sigma( ivo=[0,1], init_guess=[0,0,0,0,0,0], #init_guess=[s11,s22,0,0,0,0], weight = wgt # None ) for i in range(6): print '%+7.1f'%(dsa_sigma[i]), print '' stress.append(dsa_sigma) #-----------------------------------# if istp==0: ileg=True else: ileg=False if (istep!=None and istp==istep) or\ (istep==None and istp==model_rs.dat_model.nstp-1)\ and iplot: fig2,fig3,fig4=__model_fit_plot__( model_rs,ifig=ifig+istp*2+10, istp=istp, nxphi=nxphi, stress_wgt=None, ivo=None,hkl=hkl,ileg=ileg,iwind=iwind, wdeg=wdeg) elif iplot: plt.ioff() f1,f2,f3=__model_fit_plot__( model_rs,ifig=ifig+istp*2+10,istp=istp, nxphi=nxphi,stress_wgt=[s11,s22,0,0,0,0], ivo=[0,1],hkl=hkl,ileg=ileg,iwind=False, ipsi_opt=ipsi_opt) fs.savefig(f2);fe.savefig(f1);f_er.savefig(f3) plt.close(f1);plt.close(f2);plt.close(f3) plt.ion() if iplot: fe.close(); fs.close(); f_er.close() stress = np.array(stress).T # diffraction stress flow_dsa = FlowCurve(name='Diffraction Stress') flow_dsa.get_6stress(stress) flow_dsa.get_33strain(model_rs.dat_model.flow.epsilon) flow_dsa.get_eqv() if iplot: ax1.plot(flow_dsa.epsilon_vm,flow_dsa.sigma_vm,'k+', label='Stress Analysis') for i in range(len(exp_ref)): f = exp_ref[i]; lab = exp_lab[i] edat = np.loadtxt(f).T ax1.plot(edat[0],edat[1],'-',lw=2,label=lab) ## ax1.set_ylim(0.,800) fancy_legend(ax1,size=10) sigma_wgt = flow_weight.sigma if iplot: ax2.plot(sigma_wgt[0,0],sigma_wgt[1,1],'bx') ax2.plot(flow_dsa.sigma[0,0],flow_dsa.sigma[1,1],'k+') ## connector npoints = len(sigma_wgt[0,0]) wgtx = sigma_wgt[0,0]; wgty = sigma_wgt[1,1] dsax = flow_dsa.sigma[0,0]; dsay = flow_dsa.sigma[1,1] for i in range(npoints): ax2.plot([wgtx[i],dsax[i]],[wgty[i],dsay[i]],'k-',alpha=0.2) ax2.set_ylim(-100,700); ax2.set_xlim(-100,700) ax2.set_aspect('equal') ax2.set_xlabel(r'$\bar{\Sigma}_{11}$',dict(fontsize=15)) ax2.set_ylabel(r'$\bar{\Sigma}_{22}$',dict(fontsize=15)) ax2.locator_params(nbins=3) ax2.set_xticks(np.linspace(300,700,3),dict(fontsize=4)) ax2.set_yticks(np.linspace(300,700,3),dict(fontsize=4)) ax2.grid('on'); plt.show() ## save figures fig1.savefig('flow_%s_%s.pdf'%(hkl,path)) ## fig2.savefig('ehkl_%s_fit_%s.pdf'%(hkl,path)) ## fig3.savefig('sf_%s_%s.pdf'%(hkl,path)) ## fig4.savefig('ehkl_fit_err_%s_%s.pdf'%(hkl,path)) # close figures plt.close(fig1); plt.close(fig2); plt.close(fig3); plt.close(fig4) return model_rs, flow_weight, flow_dsa