Пример #1
0
    def plot(self, nbin_sin2psi=2, iopt=0, ylim=None, mxnphi=None, hkl='211'):
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        import matplotlib.cm as cm
        if hasattr(self, 'vf'): nh = 2
        else: nh = 1

        if mxnphi == None: mxnphi = self.nphi
        figs = wide_fig(nw=mxnphi, nh=nh, w0=0, w1=0, left=0.2, right=0.15)

        # mx = max(self.flow.epsilon_vm)
        # mn = min(self.flow.epsilon_vm)
        mx = 1.
        mn = 0.

        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx=mx, mn=mn)
        colors = []
        self.flow.nstp = len(self.flow.epsilon_vm)
        for i in xrange(mxnphi):
            for j in xrange(self.flow.nstp):
                eps = self.flow.epsilon_vm[j]
                cl = c.to_rgba(eps)
                if i == 0: colors.append(cl)

                y = self.ig[j, i, :]
                figs.axes[i].plot(np.sign(self.psi) *
                                  sin(self.psi * np.pi / 180.)**2,
                                  y,
                                  '-x',
                                  color=cl)

                if j == 0:
                    figs.axes[i].set_title(r'$\phi: %3.1f^\circ{}$' %
                                           self.phi[i])

        deco = axes_label.__deco__
        rm_inner = mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u

        deco(figs.axes[0], iopt=2, ipsi_opt=1)
        for i in xrange(len(figs.axes)):
            figs.axes[i].set_xlim(-0.5, 0.5)
        mpl_lib.tune_xy_lim(figs.axes)
        rm_inner(figs.axes)
        ticks_bin_u(figs.axes, n=4)

        # color bar
        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88, b.y0, 0.03, b.y1 - b.y0])
        mpl_lib.add_cb(ax=axcb,
                       filled=False,
                       norm=norm,
                       levels=self.flow.epsilon_vm,
                       colors=colors,
                       ylab='Equivalent strain')
Пример #2
0
    def plot_all(self):
        """
        Plot dhkl against psi
        """
        from MP.lib import mpl_lib
        wide_fig = mpl_lib.wide_fig
        tune_xy_lim = mpl_lib.tune_xy_lim
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        deco = axes_label.__deco__
        rm_inner =mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u

        figs = wide_fig(nw=self.nphi,nh=2,w0=0,w1=0,
                        left=0.2,right=0.15,
                        useOffset=False)

        mx = max(self.flow.epsilon_vm)
        mn = min(self.flow.epsilon_vm)
        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx = mx, mn=mn)

        for i in xrange(self.flow.nstp):
            eps = self.flow.epsilon_vm[i]
            cl = c.to_rgba(eps)
            for j in xrange(self.nphi):
                X = self.psi
                Y = []
                for ipsi in xrange(self.npsi):
                    y = self.P_scan[i].protophi[j].\
                        ppscans[ipsi].dspc
                    Y.append(y)
                figs.axes[j].plot(X,Y,'-x',color=cl)
                _Y_=np.array(Y).copy()
                _Y_ = (_Y_+_Y_[::-1])/2.
                # _Y_ = _Y_[:len(_Y_)/2+1]
                figs.axes[j+self.nphi].plot(X,_Y_,'-x',color=cl)
                if i==0:
                    figs.axes[j].set_title(
                        r'$\phi: %3.1f^\circ{}$'%self.phi[j])
                    figs.axes[j+self.nphi].set_title(
                        r'$\phi: %3.1f^\circ{}$'%self.phi[j])

        ticks_bin_u(figs.axes,n=4)
        deco(figs.axes[0+self.nphi],iopt=4)
        tune_xy_lim(figs.axes)
        rm_inner(figs.axes)

        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88,b.y0,0.03,b.y1-b.y0])

        mpl_lib.add_cb(axcb,cmap=cmap,filled=True,
                       ylab='Equivalent Strain',
                       norm=norm,format='%5.3f')
Пример #3
0
    def plot(self, nbin_sin2psi=2, iopt=0,ylim=None,
             mxnphi=None,hkl='211'):
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        import matplotlib.cm as cm
        if hasattr(self,'vf'): nh = 2
        else: nh = 1

        if mxnphi==None: mxnphi = self.nphi
        figs = wide_fig(nw=mxnphi,nh=nh,w0=0,w1=0,
                        left=0.2,right=0.15)

        # mx = max(self.flow.epsilon_vm)
        # mn = min(self.flow.epsilon_vm)
        mx = 1.
        mn = 0.

        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx=mx,mn=mn)
        colors=[]
        self.flow.nstp = len(self.flow.epsilon_vm)
        for i in xrange(mxnphi):
            for j in xrange(self.flow.nstp):
                eps = self.flow.epsilon_vm[j]
                cl = c.to_rgba(eps)
                if i==0: colors.append(cl)

                y = self.ig[j,i,:]
                figs.axes[i].plot(
                    np.sign(self.psi)*sin(self.psi*np.pi/180.)**2,
                    y,'-x',color=cl)

                if j==0:
                    figs.axes[i].set_title(
                        r'$\phi: %3.1f^\circ{}$'%self.phi[i])

        deco = axes_label.__deco__
        rm_inner =mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u

        deco(figs.axes[0],iopt=2,ipsi_opt=1)
        for i in xrange(len(figs.axes)):
            figs.axes[i].set_xlim(-0.5,0.5)
        mpl_lib.tune_xy_lim(figs.axes)
        rm_inner(figs.axes)
        ticks_bin_u(figs.axes,n=4)

        # color bar
        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88,b.y0,0.03,b.y1-b.y0])
        mpl_lib.add_cb(ax=axcb,filled=False,norm=norm,
                       levels=self.flow.epsilon_vm,
                       colors=colors,ylab='Equivalent strain')
Пример #4
0
    def plot(self,nbin_sin2psi=2,iopt=0,ylim=None,
             mxnphi=None,hkl='211'):
        """
        Arguments
        =========
        nbin_sin2psi = 2
        iopt         = iopt
        ylim         = None
        mxnphi       = None
        hkl          = '211'
        """
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        import matplotlib.cm as cm
        import matplotlib.pyplot as plt
        if hasattr(self, 'vf'):
            nh = 3
        else: nh = 2

        if type(mxnphi)==type(None): mxnphi = self.nphi
        figs = wide_fig(nw=mxnphi,nh=nh,w0=0,w1=0,
                        left=0.2,right=0.15)
        mx = max(self.flow.epsilon_vm)
        mn = min(self.flow.epsilon_vm)
        #mx = 1.
        #mn = 0.

        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx=mx,mn=mn)
        colors=[]
        self.flow.nstp = len(self.flow.epsilon_vm)
        for i in xrange(mxnphi):
            for j in xrange(self.flow.nstp):
                eps = self.flow.epsilon_vm[j]
                cl = c.to_rgba(eps)
                if i==0: colors.append(cl)

                y = self.sf[j,i,:,0].copy() * 1e12
                l, = figs.axes[i].plot(
                    np.sign(self.psi)*sin(self.psi*np.pi/180.)**2,
                    y,'-x',color=cl)
                y = self.sf[j,i,:,1].copy() * 1e12
                figs.axes[i+mxnphi].plot(
                    np.sign(self.psi)*sin(self.psi*np.pi/180.)**2,
                    y,'-+',color=cl)

                if j==0:
                    figs.axes[i].set_title(
                        r'$\phi: %3.1f^\circ{}$'%self.phi[i])

        if nh==3:
            for i in xrange(mxnphi):
                for j in xrange(self.flow.nstp):
                    eps = self.flow.epsilon_vm[j]
                    cl = c.to_rgba(eps)
                    y = self.vf[j,i,:]
                    figs.axes[i+mxnphi*2].plot(
                        np.sign(self.psi)*sin(self.psi*np.pi/180.)**2,
                        y,'-',color=cl)

        deco = axes_label.__deco__
        rm_inner =mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u
        rm_inner(figs.axes[:mxnphi*2])
        if nh==3: rm_inner(figs.axes[mxnphi*2:mxnphi*3])
        deco(figs.axes[0],iopt=1,ipsi_opt=1,hkl=hkl)
        if nh==3: deco(figs.axes[mxnphi*2],iopt=7,ipsi_opt=1,hkl=hkl)
        mpl_lib.tune_xy_lim(figs.axes[:mxnphi*2])
        if ylim!=None:
            for i in xrange(len(figs.axes[:mxnphi*2])):
                figs.axes[i].set_ylim(ylim)
        if nh==3: mpl_lib.tune_xy_lim(figs.axes[mxnphi*2:mxnphi*3])
        ticks_bin_u(figs.axes[:mxnphi*2],n=4)
        if nh==3: ticks_bin_u(figs.axes[mxnphi*2:mxnphi*3],n=4)

        # color bar
        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88,b.y0,0.03,b.y1-b.y0])
        mpl_lib.add_cb(ax=axcb,filled=False,norm=norm,
                       levels=self.flow.epsilon_vm,
                       format='%5.3f',
                       colors=colors,ylab='Equivalent strain')

        if nh==1 or nh==2: return

        """   SF(phi,psi) vs plastic strain   """
        ## binning sin2psi
        nbin = nbin_sin2psi
        indx = self.__binning__(nbin=nbin,mx=0.5)

        for i in xrange(len(indx)):
            print '%i bin'%(i+1)
            for j in xrange(len(indx[i])):
                print '%4i'%indx[i][j],
                print '%4.2f'%(self.sin2psi[indx[i][j]]),
            print

        if mxnphi!=None: mxnphi=self.nphi
        figs_p = wide_fig(nw=mxnphi,nh=nbin,
                          w0=0,w1=0,left=0.2,right=0.15)

        eps = self.flow.epsilon_vm
        for i in xrange(mxnphi):
            for j in xrange(nbin):
                ax = figs_p.axes[i+mxnphi*j]
                if j==nbin-1: ax.set_title(
                        r'$\phi: %3.1f^\circ{}$'%self.phi[i])
                idx = indx[j]
                for k in xrange(len(idx)):
                    y = self.sf[:,i,[idx[k]],0][::]
                    ax.plot(eps,y,'x')

        for i in xrange(nbin):
            axes=[]
            for j in xrange(mxnphi*2):
                axes.append(figs_p.axes[j+mxnphi*i])
            #mpl_lib.tune_xy_lim(axes)
            if i==0 and j==0:  rm_inner(axes[1:])
            else: rm_inner(axes)

        deco(figs_p.axes[0],iopt=6,hkl=hkl)

        mpl_lib.tune_xy_lim(figs_p.axes)
        #print 'no'
        ticks_bin_u(figs_p.axes,n=3)

        if ylim!=None:
            for i in xrange(len(figs_p.axes)):
                figs_p.axes[i].set_ylim(ylim)

        if iopt==1:
            for i in xrange(len(figs.axes)):
                figs.axes[i].set_xlim(0.0,0.5)
            for i in xrange(3):
                figs.axes[i].set_ylim(-2,2)
                figs.axes[3+i].set_ylim(0.,0.1)
        plt.draw();plt.show()
Пример #5
0
def main(
    path="../dat/BB/",
    fref="Bsteel_fref_DIC.txt",
    fn_sf="YJ_BB_10times.sff",
    fexp=None,
    iso_SF=False,
    ishow=False,
    ind_plot=False,
    psi_offset=0.0,
    psi_sym=False,
    fc=None,
    fn_str=None,
    ifix_d0=False,
    d0_ref=1.17025,
    iwgt=False,
):
    """
    Arguments
    =========
    path
    fref
    fn_sf
    fexp
    iso_SF
    ishow
    ind_plot
    psi_offset
    psi_sym
    fc
    fn_str
    ifix_d0
    d0_ref=1.17025
    iwgt=False
    """
    from MP.mat import mech
    from MP.lib import axes_label
    from MP.lib import mpl_lib
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    from matplotlib.backends.backend_pdf import PdfPages

    eqv = axes_label.__eqv__
    tune_xy_lim = mpl_lib.tune_xy_lim
    deco = axes_label.__deco__
    rm_inner = mpl_lib.rm_inner
    rm_lab = mpl_lib.rm_lab
    ticks_bin_u = mpl_lib.ticks_bins_ax_u
    plt.ioff()

    if type(fexp) == type(None):
        fexp = ("/Users/yj/repo/evpsc-dev/" "exp_dat/Bsteel/bulge/EXP_BULGE_JINKIM.txt",)

    RS_graphs = PdfPages("RS_Graphs.pdf")
    mystress = StressAnalysis(path=path, fref=fref, fn_sf=fn_sf, isym=psi_sym, fc_sf=fc, fn_str=fn_str)

    if psi_offset != 0:
        mystress.put_psi_offset(psi_offset)
    if psi_sym:
        print "psi symmetry has been applied."
        mystress.apply_sym()

    mystress.nstp
    mystress.EXP.plot_all()
    RS_graphs.savefig(plt.gcf())

    # isotropic stress factor?
    if iso_SF:
        mystress.SF.get_iso_sf(E=204e9, nu=0.3)

    # calc stress
    eps_vm = mystress.EXP.flow.epsilon_vm
    dknot = []
    s11 = []
    s22 = []
    # s12 = []
    Eis = []
    eps = []
    igs = []

    d_ehkl = np.zeros((mystress.EXP.nphi))
    for istp in xrange(mystress.nstp):
        stress, d0 = mystress.find_sigma(ivo=[0, 1], istp=istp, iplot=False, iwgt=iwgt, ifix_d0=ifix_d0, d0=d0_ref)

        dknot.append(d0)
        s11.append(stress[0])
        s22.append(stress[1])

        Eis.append(mystress.Ei)  # fitted Ei
        ehkl = mystress.EXP.ehkl[istp]  # experimental eps_hkl
        ig = mystress.IG.ig[istp]  # experimental eps_ig
        eps.append(ehkl.copy())
        igs.append(ig.copy())

        if istp == 0:
            for iphi in xrange(mystress.EXP.nphi):
                d_ehkl[iphi] = np.array(ehkl[iphi][::]).std()

    print "-----------------------------------"
    print "Standard deviation in d_ehkl at istp=0\n"
    print "phi:",
    for iphi in xrange(mystress.EXP.nphi):
        print "%7.0f " % mystress.EXP.phis[iphi],
    print "avg"
    print "std:",
    for iphi in xrange(mystress.EXP.nphi):
        print "%7.1e " % d_ehkl[iphi],
    print "%7.1e " % d_ehkl.mean()

    # macro flow object
    mystress.flow = mech.FlowCurve()
    mystress.flow.get_stress(s11, 0, 0)
    mystress.flow.get_stress(s22, 1, 1)
    mystress.flow.set_zero_sigma_ij(i=2, j=2)
    # mystress.flow.get_stress(s12,0,1)
    # mystress.flow.get_stress(s12,1,0)

    mystress.flow.set_zero_sigma_ij(i=0, j=1)
    mystress.flow.set_zero_sigma_ij(i=1, j=0)
    mystress.flow.set_zero_sigma_ij(i=2, j=1)
    mystress.flow.set_zero_sigma_ij(i=1, j=2)
    mystress.flow.set_zero_sigma_ij(i=0, j=2)
    mystress.flow.set_zero_sigma_ij(i=2, j=0)
    mystress.flow.get_vm_stress()

    # ------------------------------------------------------------#
    # plots that illustrate the fitted curves...
    Eis = np.array(Eis)
    eps = np.array(eps)
    igs = np.array(igs)
    figs = wide_fig(nw=mystress.EXP.nphi, w0=0, w1=0, left=0.2, right=0.15)

    from MP.lib import mpl_lib

    # mx = eps_vm[mystress.EXP.flow.nstp-1],
    # mn = eps_vm[0])
    mx = 1.0
    mn = 0.0
    norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
    cmap, c = mpl_lib.norm_cmap(mx=mx, mn=mn)  # c.to_rbga()

    for iphi in xrange(mystress.EXP.nphi):
        x = mystress.EXP.psi
        ax = figs.axes[iphi]
        ax.set_title(r"$\phi: %3.1f^\circ{}$" % mystress.EXP.phi[iphi])
        for istp in xrange(mystress.EXP.flow.nstp):
            y_fit = Eis[istp, iphi]
            y1 = eps[istp, iphi]  # e^{hkl}
            y0 = igs[istp, iphi]  # e^{ig}
            y_exp = y1 - y0
            ax.plot(x, y_fit, "--", color=c.to_rgba(eps_vm[istp]))
            ax.plot(x, y_exp, "x", color=c.to_rgba(eps_vm[istp]))

    deco(ax=figs.axes[0], iopt=5)
    rm_inner(figs.axes)
    ticks_bin_u(figs.axes)
    tune_xy_lim(figs.axes)

    b = figs.axes[-1].get_position()
    axcb = figs.add_axes([0.88, b.y0, 0.03, b.y1 - b.y0])
    mpl_lib.add_cb(axcb, cmap=cmap, filled=True, ylab="Equivalent Strain", norm=norm)

    RS_graphs.savefig(plt.gcf())

    # ------------------------------------------------------------#
    # Save fitted curves into individual plots to pdf files
    if ind_plot:
        from matplotlib.backends.backend_pdf import PdfPages

        pdf_pages = PdfPages("Fit_results.pdf")
        x = mystress.EXP.psi
        for istp in xrange(mystress.EXP.flow.nstp):
            figx = wide_fig(nw=mystress.EXP.nphi + 1, w0=0, w1=0, left=0.2, right=0.15)
            for iphi in xrange(mystress.EXP.nphi):
                x = mystress.EXP.psi
                ax = figx.axes[iphi]
                ax.set_title(r"$\phi: %3.1f^\circ{}$" % mystress.EXP.phi[iphi])

                y_fit = Eis[istp, iphi]
                y1 = eps[istp, iphi]  # e^{hkl}
                y0 = igs[istp, iphi]  # e^{ig}
                y_exp = y1 - y0
                ax.plot(x, y_fit, "r-", label="Fitting")
                ax.plot(x, y_exp, "bx", label=r"$\varepsilon^{hkl}" "-\varepsilon^{IG}$")

            ax = figx.axes[-1]
            eqv(ax, ft=8, zero_xy=False)
            ax = ax.twinx()
            eqv(ax, ft=8, zero_xy=False)
            ax.plot(eps_vm, mystress.flow.sigma_vm, "b-")
            ax.plot(eps_vm[istp], mystress.flow.sigma_vm[istp], "ro")

            # for i in xrange(len(figx.axes)-2):
            #     figx.axes[i].set_ylim(-0.0010,0.0006)

            fancy_legend(figx.axes[0])
            rm_inner(figx.axes[:4])
            ticks_bin_u(figx.axes[:4])

            # tune_xy_lim(figx.axes)
            ax.set_xlim(0.0, 1)
            rm_lab(ax=figx.axes[-2], axis="y")
            deco(figx.axes[0], iopt=5)

            pdf_pages.savefig(figx)
            plt.close(figx)
        pdf_pages.close()
        plt.ion()
    # ------------------------------------------------------------#
    ## flow stress curve plotting

    figs = wide_fig(nw=2, w1=0.2)
    figs.axes[0].plot(eps_vm, mystress.flow.sigma_vm, "x")
    figs.axes[0].plot(
        mystress.SF_orig.flow.epsilon_vm, np.zeros((mystress.SF_orig.flow.nstp)), "o", ms=8, mfc="None", mec="r"
    )

    figs.axes[1].plot(eps_vm, dknot, "o")
    eqv(figs.axes[0], ft=8, zero_xy=True)
    eqv(figs.axes[1], ft=8, zero_xy=False)
    figs.axes[1].set_ylabel(r"$\mathrm{d}_o$", dict(fontsize=12))
    RS_graphs.savefig(plt.gcf())

    # ------------------------------------------------------------#
    ## flow stress in plane stress space
    figs = wide_fig(nw=2)
    figs.axes[0].plot(mystress.flow.sigma[0, 0], mystress.flow.sigma[1, 1], "-x")
    figs.axes[1].plot(mystress.EXP.flow.epsilon[0, 0], mystress.EXP.flow.epsilon[1, 1], "-x")
    axes_label.__plane__(ax=figs.axes[0], ft=10, iopt=0)
    axes_label.__plane__(ax=figs.axes[1], ft=10, iopt=1)
    RS_graphs.savefig(plt.gcf())
    RS_graphs.close()
    if not (ishow):
        plt.close("all")
    plt.ion()
    return mystress
Пример #6
0
    def plot(self, nbin_sin2psi=2, iopt=0, ylim=None, mxnphi=None, hkl='211'):
        """
        Arguments
        =========
        nbin_sin2psi = 2
        iopt         = iopt
        ylim         = None
        mxnphi       = None
        hkl          = '211'
        """
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        import matplotlib.cm as cm
        import matplotlib.pyplot as plt
        if hasattr(self, 'vf'):
            nh = 3
        else:
            nh = 2

        if type(mxnphi) == type(None): mxnphi = self.nphi
        figs = wide_fig(nw=mxnphi, nh=nh, w0=0, w1=0, left=0.2, right=0.15)
        mx = max(self.flow.epsilon_vm)
        mn = min(self.flow.epsilon_vm)
        #mx = 1.
        #mn = 0.

        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx=mx, mn=mn)
        colors = []
        self.flow.nstp = len(self.flow.epsilon_vm)
        for i in xrange(mxnphi):
            for j in xrange(self.flow.nstp):
                eps = self.flow.epsilon_vm[j]
                cl = c.to_rgba(eps)
                if i == 0: colors.append(cl)

                y = self.sf[j, i, :, 0].copy() * 1e12
                l, = figs.axes[i].plot(np.sign(self.psi) *
                                       sin(self.psi * np.pi / 180.)**2,
                                       y,
                                       '-x',
                                       color=cl)
                y = self.sf[j, i, :, 1].copy() * 1e12
                figs.axes[i + mxnphi].plot(np.sign(self.psi) *
                                           sin(self.psi * np.pi / 180.)**2,
                                           y,
                                           '-+',
                                           color=cl)

                if j == 0:
                    figs.axes[i].set_title(r'$\phi: %3.1f^\circ{}$' %
                                           self.phi[i])

        if nh == 3:
            for i in xrange(mxnphi):
                for j in xrange(self.flow.nstp):
                    eps = self.flow.epsilon_vm[j]
                    cl = c.to_rgba(eps)
                    y = self.vf[j, i, :]
                    figs.axes[i + mxnphi * 2].plot(
                        np.sign(self.psi) * sin(self.psi * np.pi / 180.)**2,
                        y,
                        '-',
                        color=cl)

        deco = axes_label.__deco__
        rm_inner = mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u
        rm_inner(figs.axes[:mxnphi * 2])
        if nh == 3: rm_inner(figs.axes[mxnphi * 2:mxnphi * 3])
        deco(figs.axes[0], iopt=1, ipsi_opt=1, hkl=hkl)
        if nh == 3: deco(figs.axes[mxnphi * 2], iopt=7, ipsi_opt=1, hkl=hkl)
        mpl_lib.tune_xy_lim(figs.axes[:mxnphi * 2])
        if ylim != None:
            for i in xrange(len(figs.axes[:mxnphi * 2])):
                figs.axes[i].set_ylim(ylim)
        if nh == 3: mpl_lib.tune_xy_lim(figs.axes[mxnphi * 2:mxnphi * 3])
        ticks_bin_u(figs.axes[:mxnphi * 2], n=4)
        if nh == 3: ticks_bin_u(figs.axes[mxnphi * 2:mxnphi * 3], n=4)

        # color bar
        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88, b.y0, 0.03, b.y1 - b.y0])
        mpl_lib.add_cb(ax=axcb,
                       filled=False,
                       norm=norm,
                       levels=self.flow.epsilon_vm,
                       format='%5.3f',
                       colors=colors,
                       ylab='Equivalent strain')

        if nh == 1 or nh == 2: return
        """   SF(phi,psi) vs plastic strain   """
        ## binning sin2psi
        nbin = nbin_sin2psi
        indx = self.__binning__(nbin=nbin, mx=0.5)

        for i in xrange(len(indx)):
            print '%i bin' % (i + 1)
            for j in xrange(len(indx[i])):
                print '%4i' % indx[i][j],
                print '%4.2f' % (self.sin2psi[indx[i][j]]),
            print

        if mxnphi != None: mxnphi = self.nphi
        figs_p = wide_fig(nw=mxnphi, nh=nbin, w0=0, w1=0, left=0.2, right=0.15)

        eps = self.flow.epsilon_vm
        for i in xrange(mxnphi):
            for j in xrange(nbin):
                ax = figs_p.axes[i + mxnphi * j]
                if j == nbin - 1:
                    ax.set_title(r'$\phi: %3.1f^\circ{}$' % self.phi[i])
                idx = indx[j]
                for k in xrange(len(idx)):
                    y = self.sf[:, i, [idx[k]], 0][::]
                    ax.plot(eps, y, 'x')

        for i in xrange(nbin):
            axes = []
            for j in xrange(mxnphi * 2):
                axes.append(figs_p.axes[j + mxnphi * i])
            #mpl_lib.tune_xy_lim(axes)
            if i == 0 and j == 0: rm_inner(axes[1:])
            else: rm_inner(axes)

        deco(figs_p.axes[0], iopt=6, hkl=hkl)

        mpl_lib.tune_xy_lim(figs_p.axes)
        #print 'no'
        ticks_bin_u(figs_p.axes, n=3)

        if ylim != None:
            for i in xrange(len(figs_p.axes)):
                figs_p.axes[i].set_ylim(ylim)

        if iopt == 1:
            for i in xrange(len(figs.axes)):
                figs.axes[i].set_xlim(0.0, 0.5)
            for i in xrange(3):
                figs.axes[i].set_ylim(-2, 2)
                figs.axes[3 + i].set_ylim(0., 0.1)
        plt.draw()
        plt.show()
Пример #7
0
def main(path='../dat/BB/',
         fref='Bsteel_fref_DIC.txt',
         fn_sf='YJ_BB_10times.sff',
         fexp=None,
         iso_SF=False,
         ishow=False,
         ind_plot=False,
         psi_offset=0.0,
         psi_sym=False,
         fc=None,
         fn_str=None,
         ifix_d0=False,
         d0_ref=1.17025,
         iwgt=False):
    """
    Arguments
    =========
    path
    fref
    fn_sf
    fexp
    iso_SF
    ishow
    ind_plot
    psi_offset
    psi_sym
    fc
    fn_str
    ifix_d0
    d0_ref=1.17025
    iwgt=False
    """
    from MP.mat import mech
    from MP.lib import axes_label
    from MP.lib import mpl_lib
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    from matplotlib.backends.backend_pdf import PdfPages
    eqv = axes_label.__eqv__
    tune_xy_lim = mpl_lib.tune_xy_lim
    deco = axes_label.__deco__
    rm_inner = mpl_lib.rm_inner
    rm_lab = mpl_lib.rm_lab
    ticks_bin_u = mpl_lib.ticks_bins_ax_u
    plt.ioff()

    if type(fexp) == type(None):
        fexp='/Users/yj/repo/evpsc-dev/'\
            'exp_dat/Bsteel/bulge/EXP_BULGE_JINKIM.txt',

    RS_graphs = PdfPages('RS_Graphs.pdf')
    mystress = StressAnalysis(path=path,
                              fref=fref,
                              fn_sf=fn_sf,
                              isym=psi_sym,
                              fc_sf=fc,
                              fn_str=fn_str)

    if psi_offset != 0: mystress.put_psi_offset(psi_offset)
    if psi_sym:
        print 'psi symmetry has been applied.'
        mystress.apply_sym()

    mystress.nstp
    mystress.EXP.plot_all()
    RS_graphs.savefig(plt.gcf())

    # isotropic stress factor?
    if iso_SF: mystress.SF.get_iso_sf(E=204e9, nu=0.3)

    # calc stress
    eps_vm = mystress.EXP.flow.epsilon_vm
    dknot = []
    s11 = []
    s22 = []
    # s12 = []
    Eis = []
    eps = []
    igs = []

    d_ehkl = np.zeros((mystress.EXP.nphi))
    for istp in xrange(mystress.nstp):
        stress, d0 = mystress.find_sigma(ivo=[0, 1],
                                         istp=istp,
                                         iplot=False,
                                         iwgt=iwgt,
                                         ifix_d0=ifix_d0,
                                         d0=d0_ref)

        dknot.append(d0)
        s11.append(stress[0])
        s22.append(stress[1])

        Eis.append(mystress.Ei)  # fitted Ei
        ehkl = mystress.EXP.ehkl[istp]  # experimental eps_hkl
        ig = mystress.IG.ig[istp]  # experimental eps_ig
        eps.append(ehkl.copy())
        igs.append(ig.copy())

        if istp == 0:
            for iphi in xrange(mystress.EXP.nphi):
                d_ehkl[iphi] = np.array(ehkl[iphi][::]).std()

    print '-----------------------------------'
    print 'Standard deviation in d_ehkl at istp=0\n'
    print 'phi:',
    for iphi in xrange(mystress.EXP.nphi):
        print '%7.0f ' % mystress.EXP.phis[iphi],
    print 'avg'
    print 'std:',
    for iphi in xrange(mystress.EXP.nphi):
        print '%7.1e ' % d_ehkl[iphi],
    print '%7.1e ' % d_ehkl.mean()

    # macro flow object
    mystress.flow = mech.FlowCurve()
    mystress.flow.get_stress(s11, 0, 0)
    mystress.flow.get_stress(s22, 1, 1)
    mystress.flow.set_zero_sigma_ij(i=2, j=2)
    # mystress.flow.get_stress(s12,0,1)
    # mystress.flow.get_stress(s12,1,0)

    mystress.flow.set_zero_sigma_ij(i=0, j=1)
    mystress.flow.set_zero_sigma_ij(i=1, j=0)
    mystress.flow.set_zero_sigma_ij(i=2, j=1)
    mystress.flow.set_zero_sigma_ij(i=1, j=2)
    mystress.flow.set_zero_sigma_ij(i=0, j=2)
    mystress.flow.set_zero_sigma_ij(i=2, j=0)
    mystress.flow.get_vm_stress()

    #------------------------------------------------------------#
    # plots that illustrate the fitted curves...
    Eis = np.array(Eis)
    eps = np.array(eps)
    igs = np.array(igs)
    figs = wide_fig(nw=mystress.EXP.nphi, w0=0, w1=0, left=0.2, right=0.15)

    from MP.lib import mpl_lib
    # mx = eps_vm[mystress.EXP.flow.nstp-1],
    # mn = eps_vm[0])
    mx = 1.0
    mn = 0.0
    norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
    cmap, c = mpl_lib.norm_cmap(mx=mx, mn=mn)  # c.to_rbga()

    for iphi in xrange(mystress.EXP.nphi):
        x = mystress.EXP.psi
        ax = figs.axes[iphi]
        ax.set_title(r'$\phi: %3.1f^\circ{}$' % mystress.EXP.phi[iphi])
        for istp in xrange(mystress.EXP.flow.nstp):
            y_fit = Eis[istp, iphi]
            y1 = eps[istp, iphi]  # e^{hkl}
            y0 = igs[istp, iphi]  # e^{ig}
            y_exp = y1 - y0
            ax.plot(x, y_fit, '--', color=c.to_rgba(eps_vm[istp]))
            ax.plot(x, y_exp, 'x', color=c.to_rgba(eps_vm[istp]))

    deco(ax=figs.axes[0], iopt=5)
    rm_inner(figs.axes)
    ticks_bin_u(figs.axes)
    tune_xy_lim(figs.axes)

    b = figs.axes[-1].get_position()
    axcb = figs.add_axes([0.88, b.y0, 0.03, b.y1 - b.y0])
    mpl_lib.add_cb(axcb,
                   cmap=cmap,
                   filled=True,
                   ylab='Equivalent Strain',
                   norm=norm)

    RS_graphs.savefig(plt.gcf())

    #------------------------------------------------------------#
    # Save fitted curves into individual plots to pdf files
    if ind_plot:
        from matplotlib.backends.backend_pdf import PdfPages
        pdf_pages = PdfPages('Fit_results.pdf')
        x = mystress.EXP.psi
        for istp in xrange(mystress.EXP.flow.nstp):
            figx = wide_fig(nw=mystress.EXP.nphi + 1,
                            w0=0,
                            w1=0,
                            left=0.2,
                            right=0.15)
            for iphi in xrange(mystress.EXP.nphi):
                x = mystress.EXP.psi
                ax = figx.axes[iphi]
                ax.set_title(
                    r'$\phi: %3.1f^\circ{}$'%\
                    mystress.EXP.phi[iphi])

                y_fit = Eis[istp, iphi]
                y1 = eps[istp, iphi]  # e^{hkl}
                y0 = igs[istp, iphi]  # e^{ig}
                y_exp = y1 - y0
                ax.plot(x, y_fit, 'r-', label='Fitting')
                ax.plot(x,y_exp,'bx',
                        label=r'$\varepsilon^{hkl}'\
                        '-\varepsilon^{IG}$')

            ax = figx.axes[-1]
            eqv(ax, ft=8, zero_xy=False)
            ax = ax.twinx()
            eqv(ax, ft=8, zero_xy=False)
            ax.plot(eps_vm, mystress.flow.sigma_vm, 'b-')
            ax.plot(eps_vm[istp], mystress.flow.sigma_vm[istp], 'ro')

            # for i in xrange(len(figx.axes)-2):
            #     figx.axes[i].set_ylim(-0.0010,0.0006)

            fancy_legend(figx.axes[0])
            rm_inner(figx.axes[:4])
            ticks_bin_u(figx.axes[:4])

            #tune_xy_lim(figx.axes)
            ax.set_xlim(0., 1)
            rm_lab(ax=figx.axes[-2], axis='y')
            deco(figx.axes[0], iopt=5)

            pdf_pages.savefig(figx)
            plt.close(figx)
        pdf_pages.close()
        plt.ion()
#------------------------------------------------------------#
## flow stress curve plotting

    figs = wide_fig(nw=2, w1=0.2)
    figs.axes[0].plot(eps_vm, mystress.flow.sigma_vm, 'x')
    figs.axes[0].plot(mystress.SF_orig.flow.epsilon_vm,
                      np.zeros((mystress.SF_orig.flow.nstp)),
                      'o',
                      ms=8,
                      mfc='None',
                      mec='r')

    figs.axes[1].plot(eps_vm, dknot, 'o')
    eqv(figs.axes[0], ft=8, zero_xy=True)
    eqv(figs.axes[1], ft=8, zero_xy=False)
    figs.axes[1].set_ylabel(r'$\mathrm{d}_o$', dict(fontsize=12))
    RS_graphs.savefig(plt.gcf())

    #------------------------------------------------------------#
    ## flow stress in plane stress space
    figs = wide_fig(nw=2)
    figs.axes[0].plot(mystress.flow.sigma[0, 0], mystress.flow.sigma[1, 1],
                      '-x')
    figs.axes[1].plot(mystress.EXP.flow.epsilon[0, 0],
                      mystress.EXP.flow.epsilon[1, 1], '-x')
    axes_label.__plane__(ax=figs.axes[0], ft=10, iopt=0)
    axes_label.__plane__(ax=figs.axes[1], ft=10, iopt=1)
    RS_graphs.savefig(plt.gcf())
    RS_graphs.close()
    if not (ishow): plt.close('all')
    plt.ion()
    return mystress
Пример #8
0
def main(path='/Users/yj/repo/rs_pack/dat/11Jul12',
         fref='Bsteel_BB_00.txt',fn_sf='YJ_BB_10times.sff',
         fexp=None,iso_SF=False,ishow=False,ind_plot=False,
         psi_offset=0.0,psi_sym=False,fc=None,fn_str=None,
         iwgt=False):
    """
    Arguments
    =========
    path
    fref
    fn_sf
    fexp
    iso_SF
    ishow
    ind_plot
    psi_offset
    psi_sym
    fc
    fn_str
    """
    from MP.mat import mech
    from MP.lib import axes_label
    from MP.lib import mpl_lib
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    from matplotlib.backends.backend_pdf import PdfPages
    eqv = axes_label.__eqv__
    tune_xy_lim = mpl_lib.tune_xy_lim
    deco = axes_label.__deco__
    rm_inner =mpl_lib.rm_inner
    rm_lab = mpl_lib.rm_lab
    ticks_bin_u = mpl_lib.ticks_bins_ax_u
    plt.ioff()

    if type(fexp)==type(None):
        fexp='/Users/yj/repo/evpsc-dev/'\
            'exp_dat/Bsteel/bulge/EXP_BULGE_JINKIM.txt',

    RS_graphs = PdfPages('RS_Graphs.pdf')
    mystress = StressAnalysis(path=path,fref=fref,
                              fn_sf=fn_sf,isym=psi_sym,
                              fc_sf=None,fn_str=fn_str)

    if psi_offset!=0: mystress.put_psi_offset(psi_offset)
    if psi_sym:
        print 'psi symmetry has been applied.'
        mystress.apply_sym()

    mystress.nstp
    mystress.EXP.plot_all()
    RS_graphs.savefig(plt.gcf())

    # isotropic stress factor?
    if iso_SF: mystress.SF.get_iso_sf(E=204e9,nu=0.3)

    # calc stress
    eps_vm = mystress.EXP.flow.epsilon_vm
    dknot = []
    s11 = []; s22 = []
    Eis = []; eps = []; igs = []

    d_ehkl = np.zeros((mystress.EXP.nphi))
    for istp in range(mystress.nstp):
        stress, d0 = mystress.find_sigma(
            ivo=[0,1],istp=istp,iplot=False,iwgt=iwgt)

        dknot.append(d0)
        s11.append(stress[0])
        s22.append(stress[1])

        Eis.append(mystress.Ei) # fitted Ei
        ehkl = mystress.EXP.ehkl[istp] # experimental eps_hkl
        ig   = mystress.IG.ig[istp]    # experimental eps_ig
        eps.append(ehkl.copy())
        igs.append(ig.copy())

        if istp==0:
            for iphi in range(mystress.EXP.nphi):
                d_ehkl[iphi] = np.array(ehkl[iphi][::]).std()

    print '-----------------------------------'
    print 'Stard deviation in d_ehkl at istp=0\n'
    print 'phi:',
    for iphi in range(mystress.EXP.nphi):
        print '%7.0f '%mystress.EXP.phis[iphi],
    print 'avg'
    print 'std:',
    for iphi in range(mystress.EXP.nphi):
        print '%7.1e '%d_ehkl[iphi],
    print '%7.1e '%d_ehkl.mean()

    # macro flow object
    mystress.flow = mech.FlowCurve()
    mystress.flow.get_stress(s11,0,0)
    mystress.flow.get_stress(s22,1,1)
    mystress.flow.set_zero_sigma_ij(i=2,j=2)
    mystress.flow.set_zero_shear_stress()
    mystress.flow.get_vm_stress()

#------------------------------------------------------------#
    # plots that illustrate the fitted curves...
    Eis = np.array(Eis)
    eps = np.array(eps)
    igs = np.array(igs)
    figs = wide_fig(nw=mystress.EXP.nphi,w0=0,w1=0,left=0.2,
                    right=0.15)

    from MP.lib import mpl_lib
    # mx = eps_vm[mystress.EXP.flow.nstp-1],
    # mn = eps_vm[0])
    mx = 1.0; mn = 0.0
    norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
    cmap, c = mpl_lib.norm_cmap(
        mx=mx,mn=mn) # c.to_rbga()

    for iphi in range(mystress.EXP.nphi):
        x = mystress.EXP.psi
        ax = figs.axes[iphi]
        ax.set_title(
            r'$\phi: %3.1f^\circ{}$'%mystress.EXP.phi[iphi])
        for istp in range(mystress.EXP.flow.nstp):
            y_fit = Eis[istp,iphi]
            y1=eps[istp,iphi] # e^{hkl}
            y0=igs[istp,iphi] # e^{ig}
            y_exp = y1-y0
            ax.plot(x,y_fit,'--',color=c.to_rgba(eps_vm[istp]))
            ax.plot(x,y_exp,'x',color=c.to_rgba(eps_vm[istp]))

    deco(ax=figs.axes[0],iopt=5)
    rm_inner(figs.axes)
    ticks_bin_u(figs.axes)
    tune_xy_lim(figs.axes)

    b = figs.axes[-1].get_position()
    axcb = figs.add_axes([0.88,b.y0,0.03,b.y1-b.y0])
    mpl_lib.add_cb(axcb,cmap=cmap,filled=True,
                   ylab='Equivalent Strain',norm=norm)

    RS_graphs.savefig(plt.gcf())

#------------------------------------------------------------#
    # Save fitted curves into individual plots to pdf files
    if ind_plot:
        from matplotlib.backends.backend_pdf import PdfPages
        pdf_pages = PdfPages('Fit_results.pdf')
        x = mystress.EXP.psi
        for istp in range(mystress.EXP.flow.nstp):
            figx = wide_fig(nw=mystress.EXP.nphi+1,
                            w0=0,w1=0,left=0.2,
                            right=0.15)
            for iphi in range(mystress.EXP.nphi):
                x = mystress.EXP.psi
                ax = figx.axes[iphi]
                ax.set_title(
                    r'$\phi: %3.1f^\circ{}$'%\
                    mystress.EXP.phi[iphi])

                y_fit = Eis[istp,iphi]
                y1=eps[istp,iphi] # e^{hkl}
                y0=igs[istp,iphi] # e^{ig}
                y_exp = y1-y0
                ax.plot(x,y_fit,'r-',label='Fitting')
                ax.plot(x,y_exp,'bx',
                        label=r'$\varepsilon^{hkl}'\
                        '-\varepsilon^{IG}$')

            ax = figx.axes[-1]
            eqv(ax,ft=8,zero_xy=False)
            ax = ax.twinx()
            eqv(ax,ft=8,zero_xy=False)
            ax.plot(eps_vm,mystress.flow.sigma_vm,'b-')
            ax.plot(eps_vm[istp],
                    mystress.flow.sigma_vm[istp],'ro')

            for i in range(len(figx.axes)-2):
                figx.axes[i].set_ylim(-0.0010,0.0006)

            fancy_legend(figx.axes[0])
            rm_inner(figx.axes[:4])
            ticks_bin_u(figx.axes[:4])

            #tune_xy_lim(figx.axes)
            ax.set_xlim(0.,1)
            rm_lab(ax=figx.axes[-2],axis='y')
            deco(figx.axes[0],iopt=5)

            pdf_pages.savefig(figx)
            plt.close(figx)
        pdf_pages.close()
        plt.ion()
#------------------------------------------------------------#
    ## flow stress curve plotting

    figs = wide_fig(nw=2,w1=0.2)
    figs.axes[0].plot(eps_vm, mystress.flow.sigma_vm,'x')
    figs.axes[0].plot(mystress.SF_orig.flow.epsilon_vm,
                      np.zeros((mystress.SF_orig.flow.nstp)),
                      'o',ms=8,mfc='None',mec='r')


    figs.axes[1].plot(eps_vm, dknot,'o')
    eqv(figs.axes[0],ft=8,zero_xy=True)
    eqv(figs.axes[1],ft=8,zero_xy=False)
    figs.axes[1].set_ylabel(r'$\mathrm{d}_o$',dict(fontsize=12))
    RS_graphs.savefig(plt.gcf())

#------------------------------------------------------------#
    ## flow stress in plane stress space
    figs = wide_fig(nw=2)
    figs.axes[0].plot(
        mystress.flow.sigma[0,0],
        mystress.flow.sigma[1,1],'-x')
    figs.axes[1].plot(
        mystress.EXP.flow.epsilon[0,0],
        mystress.EXP.flow.epsilon[1,1],'-x')
    axes_label.__plane__(ax=figs.axes[0],ft=10,iopt=0)
    axes_label.__plane__(ax=figs.axes[1],ft=10,iopt=1)
    RS_graphs.savefig(plt.gcf())
    RS_graphs.close()
    if not(ishow): plt.close('all')
    plt.ion()
    return mystress
Пример #9
0
    def plot_all(self):
        """
        Plot dhkl against psi
        """
        from MP.lib import mpl_lib
        wide_fig = mpl_lib.wide_fig
        tune_xy_lim = mpl_lib.tune_xy_lim
        from MP.lib import axes_label
        from MP.lib import mpl_lib
        import matplotlib as mpl
        deco = axes_label.__deco__
        rm_inner = mpl_lib.rm_inner
        ticks_bin_u = mpl_lib.ticks_bins_ax_u

        figs = wide_fig(nw=self.nphi,
                        nh=2,
                        w0=0,
                        w1=0,
                        left=0.2,
                        right=0.15,
                        useOffset=False)

        mx = max(self.flow.epsilon_vm)
        mn = min(self.flow.epsilon_vm)
        norm = mpl.colors.Normalize(vmin=mn, vmax=mx)
        cmap, c = mpl_lib.norm_cmap(mx=mx, mn=mn)

        for i in xrange(self.flow.nstp):
            eps = self.flow.epsilon_vm[i]
            cl = c.to_rgba(eps)
            for j in xrange(self.nphi):
                X = self.psi
                Y = []
                for ipsi in xrange(self.npsi):
                    y = self.P_scan[i].protophi[j].\
                        ppscans[ipsi].dspc
                    Y.append(y)
                figs.axes[j].plot(X, Y, '-x', color=cl)
                _Y_ = np.array(Y).copy()
                _Y_ = (_Y_ + _Y_[::-1]) / 2.
                # _Y_ = _Y_[:len(_Y_)/2+1]
                figs.axes[j + self.nphi].plot(X, _Y_, '-x', color=cl)
                if i == 0:
                    figs.axes[j].set_title(r'$\phi: %3.1f^\circ{}$' %
                                           self.phi[j])
                    figs.axes[j + self.nphi].set_title(
                        r'$\phi: %3.1f^\circ{}$' % self.phi[j])

        ticks_bin_u(figs.axes, n=4)
        deco(figs.axes[0 + self.nphi], iopt=4)
        tune_xy_lim(figs.axes)
        rm_inner(figs.axes)

        b = figs.axes[-1].get_position()
        axcb = figs.add_axes([0.88, b.y0, 0.03, b.y1 - b.y0])

        mpl_lib.add_cb(axcb,
                       cmap=cmap,
                       filled=True,
                       ylab='Equivalent Strain',
                       norm=norm,
                       format='%5.3f')