示例#1
0
def plot_U1D_Cartesian(ax, ftype, R, S, T):
	"""
	Plot Cartesian potential in 1D. Must be passed axes and parameters.
	"""
	me = me0+"plot_U1D_Cartesian: "

	xmax = +R+1.0
	xmin = -S-1.0 if ftype is "dlin" else -xmax

	x = np.linspace(xmin,xmax,1000)

	if ftype is "dlin":		fx = force_Cdlin([x,0],R,S)[0]
	elif ftype is "nlin":	fx = force_nlin([x,0],R,S)[0]
	elif ftype is "dcon":	fx = force_dcon([x,0],R,S)[0]
	else: raise IOError, me+"Option not available yet."

	U = -sp.integrate.cumtrapz(fx,x,initial=0.0); U-=U.min()

	ax.plot(x, U, "k-")
	
	if ftype is "dlin" or ftype is "dcon":
		ay = 0.15*U.max()
		ax.annotate("",[S,ay],[R,ay],
			arrowprops=dict(arrowstyle='<|-|>',facecolor='black'))
		ax.text(0.5*(R+S),ay+0.05*U.max(),r"$L$",fontsize=fs["fsa"],horizontalalignment="center", color="k")
            
	ax.set_xlim((x[0],x[-1]))
	ax.set_xlabel(r"$x$")
	ax.set_ylabel(r"$U$")
	ax.xaxis.set_major_locator(NullLocator())
	ax.yaxis.set_major_locator(NullLocator())
	ax.grid()
	
	return
示例#2
0
def plot_U1D_Cartesian(ax, ftype, R, S, T):
    """
	Plot Cartesian potential in 1D. Must be passed axes and parameters.
	"""
    me = me0 + "plot_U1D_Cartesian: "

    xmax = +R + 1.0
    xmin = -S - 1.0 if ftype is "dlin" else -xmax

    x = np.linspace(xmin, xmax, 1000)

    if ftype is "dlin": fx = force_Cdlin([x, 0], R, S)[0]
    elif ftype is "nlin": fx = force_nlin([x, 0], R, S)[0]
    elif ftype is "dcon": fx = force_dcon([x, 0], R, S)[0]
    else: raise IOError, me + "Option not available yet."

    U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
    U -= U.min()

    ax.plot(x, U, "k-")

    if ftype is "dlin" or ftype is "dcon":
        ay = 0.15 * U.max()
        ax.annotate("", [S, ay], [R, ay],
                    arrowprops=dict(arrowstyle='<|-|>', facecolor='black'))
        ax.text(0.5 * (R + S),
                ay + 0.05 * U.max(),
                r"$L$",
                fontsize=fs["fsa"],
                horizontalalignment="center",
                color="k")

    ax.set_xlim((x[0], x[-1]))
    ax.set_xlabel(r"$x$")
    ax.set_ylabel(r"$U$")
    ax.xaxis.set_major_locator(NullLocator())
    ax.yaxis.set_major_locator(NullLocator())
    ax.grid()

    return
示例#3
0
def calc_mass_ratio(histdir, srchstr, noread, vb):
	"""
	Read in directory of files with inner and outer regions.
	Compute mass in each region, take ratio.
	Compare with integrated and calculated white noise result. 
	"""
	me = me0+".calc_mass_ratio: "
	t0 = time.time()
	
	##-------------------------------------------------------------------------
	
	## Dir pars
	assert "_CAR_" in histdir, me+"Functional only for Cartesian geometry."
	assert "_DL_" not in histdir, me+"Must have interior region."
	
	## File discovery
	filelist = np.sort(glob.glob(histdir+"/BHIS_CAR_*"+srchstr+"*.npy"))
	numfiles = len(filelist)
	assert numfiles>1, me+"Check input directory."
	if vb: print me+"found",numfiles,"files"
		
	##-------------------------------------------------------------------------
	
	A, ML, MR = np.zeros([3,numfiles])
	
	## Retrieve data
	for i, histfile in enumerate(filelist):
		
		## Assume R, S, T are same for all files
		A[i] = filename_par(histfile, "_a")
		R = filename_par(histfile, "_R")
		S = filename_par(histfile, "_S")
		try: 
			T = filename_par(histfile, "_T")
		except ValueError:
			T = -S
			
		## Space
		bins = np.load(os.path.dirname(histfile)+"/BHISBIN"+os.path.basename(histfile)[4:-4]+".npz")
		xbins = bins["xbins"]
		x = 0.5*(xbins[1:]+xbins[:-1])
		
		##-------------------------------------------------------------------------
		
		## Histogram
		H = np.load(histfile)
		## Spatial density
		Qx = H.sum(axis=2).sum(axis=1) / (H.sum()*(x[1]-x[0]))

		## Mass on either side of cusp: data. Left, right.
		if   "_CL_" in histfile:	cuspind = np.abs(0.5*(T+S)-x).argmin()	## Half-domain
		elif "_ML_" in histfile:	cuspind = np.abs(0.5*(T+S)-x).argmin()
		elif "_NL_" in histfile:	cuspind = np.abs(S-x).argmin()
		
		ML[i] = np.trapz(Qx[:cuspind],x[:cuspind])
		MR[i] = np.trapz(Qx[cuspind:],x[cuspind:])
		
	## SORT BY ALPHA
	srtidx = A.argsort()
	A = A[srtidx]
	ML = ML[srtidx]; MR = MR[srtidx]
	
	##-------------------------------------------------------------------------
	## WN result from density solution
	
	if   "_DL_" in histfile:	fx = force_dlin([x,0],R,S)[0]
	elif "_CL_" in histfile:	fx = force_clin([x,0],R,S,T)[0]
	elif "_ML_" in histfile:	fx = force_mlin([x,0],R,S,T)[0]
	elif "_NL_" in histfile:	fx = force_nlin([x,0],R,S)[0]
	else: raise IOError, me+"Force not recognised."
		
	U = -sp.integrate.cumtrapz(fx, x, initial=0.0); U -= U.min()
	Qx_WN = np.exp(-U) / np.trapz(np.exp(-U), x)
	
	MLwn = np.trapz(Qx_WN[:cuspind],x[:cuspind])
	MRwn = np.trapz(Qx_WN[cuspind:],x[cuspind:])
	
	##-------------------------------------------------------------------------
	## Add a=0 point
	if 0.0 not in A:
		A = np.hstack([0.0,A])
		ML = np.hstack([MLwn,ML])
		MR = np.hstack([MRwn,MR])
	
	##-------------------------------------------------------------------------
	
	### This might not be the cleanest thing to save...
	
	## SAVING
	if not noread:
		massfile = histdir+"/MASS_"+srchstr+".npz"
		np.savez(massfile, A=A, ML=ML, MR=MR, MLwn=MLwn, MRwn=MRwn, x=x, Qx_WN=Qx_WN, R=R, S=S, T=T, cuspind=cuspind)
		if vb:
			print me+"Calculations saved to",massfile
			print me+"Calculation time %.1f seconds."%(time.time()-t0)

	return {"A":A, "ML":ML, "MR":MR, "MLwn":MLwn, "MRwn":MRwn, "x":x, "Qx_WN":Qx_WN, "R":R, "S":S, "T":T, "cuspind":cuspind}
示例#4
0
def plot_mass_ratio(histdir, srchstr, nosave, noread, vb):
	"""
	Plot the mass for all files in directory matching string.
	"""
	me = me0+".plot_mass_ratio: "
	t0 = time.time()
	
	##-------------------------------------------------------------------------
	## Read in existing data or calculate afresh
		
	try:
		assert noread == False
		massdata = np.load(histdir+"/MASS_"+srchstr+".npz")
		print me+"Mass data file found:",histdir+"/MASS_"+srchstr+".npz"
	except (IOError, AssertionError):
		print me+"No mass data found. Calculating from histfiles."
		massdata = calc_mass_ratio(histdir, srchstr, noread, vb)
		
	A = massdata["A"]
	ML = massdata["ML"]
	MR = massdata["MR"]
	MLwn = massdata["MLwn"]
	MRwn = massdata["MRwn"]
	x = massdata["x"]
	Qx_WN = massdata["Qx_WN"]
	R, S, T = massdata["R"], massdata["S"], massdata["T"]
	cuspind = massdata["cuspind"]
	del massdata
	
	##-------------------------------------------------------------------------
	
	## PLOTTING
	
	fig, ax = plt.subplots(1,1)

	## Mass normalised by WN result

	lL = ax.plot(A, ML/MLwn, "o-", label=r"Left")
	lR = ax.plot(A, MR/MRwn, "o-", label=r"Right")

	ax.set_xlabel(r"$\alpha$", fontsize=fs["fsa"])
	ax.set_ylabel(r"$M/M^{\rm passive}$", fontsize=fs["fsa"])
	ax.grid()
	
	##----------------------------------------------------------------------------
	## Casimir insets
	if "_CL_" in histdir:
		## Plot potential as inset
		left, bottom, width, height = [0.2, 0.6, 0.3, 0.25]
		axin = fig.add_axes([left, bottom, width, height])
	
		x = np.linspace(-x[-1],x[-1],2*x.size)
		fx = force_clin([x,0],R,S,T)[0]
		U = -sp.integrate.cumtrapz(fx, x, initial=0.0); U -= U.min()
		axin.plot(x, U, "k-")
		cuspind += x.size/2	## Because x.size has doubles
		axin.axvspan(x[0],-x[cuspind], color=lR[0].get_color(),alpha=0.2)
		axin.axvspan(-x[cuspind],x[cuspind], color=lL[0].get_color(),alpha=0.2)
		axin.axvspan(x[cuspind],x[-1], color=lR[0].get_color(),alpha=0.2)
		axin.set_xlim(-R-2, R+2)
		axin.set_ylim(top=2*U[cuspind])
		axin.xaxis.set_ticklabels([])
		axin.yaxis.set_ticklabels([])
		axin.set_xlabel(r"$x$", fontsize = fs["fsa"]-5)
		axin.set_ylabel(r"$U$", fontsize = fs["fsa"]-5)
	
		## Plot q(eta) as inset
		left, bottom, width, height = [0.55, 0.27, 0.33, 0.28]
		axin = fig.add_axes([left, bottom, width, height])
		## Grab a file. Hacky. Assumes only one match.
		histfile = glob.glob(histdir+"/BHIS_CAR_CL_a5.0_*"+srchstr+"*.npy")[0]
		plot_peta_CL(histfile, fig, axin, True)
		axin.xaxis.set_major_locator(NullLocator())
		axin.yaxis.set_major_locator(NullLocator())
		
	##----------------------------------------------------------------------------
	## Single wall insets
	elif "_ML_" in histdir:
		## Plot potential as inset
		fx = force_mlin([x,0],R,S,T)[0]
		U = -sp.integrate.cumtrapz(fx, x, initial=0.0); U -= U.min()
		left, bottom, width, height = [0.18, 0.68, 0.33, 0.20]
		axin = fig.add_axes([left, bottom, width, height])
		axin.plot(x, U, "k-")
		axin.axvspan(x[0],x[cuspind], color=lL[0].get_color(),alpha=0.2)
		axin.axvspan(x[cuspind],x[-1], color=lR[0].get_color(),alpha=0.2)
		axin.set_xlim(-R-1.5, R+1.5)
		axin.set_ylim(top=2*U[cuspind])
		axin.xaxis.set_major_locator(NullLocator())
		axin.yaxis.set_major_locator(NullLocator())
		axin.set_xlabel(r"$x$", fontsize = fs["fsa"]-5)
		axin.set_ylabel(r"$U$", fontsize = fs["fsa"]-5)
	
		## Plot q(eta) as inset
		left, bottom, width, height = [0.55, 0.35, 0.33, 0.23]
		axin = fig.add_axes([left, bottom, width, height])
		## Grab a file. Hacky. Assumes only one match.
		histfile = glob.glob(histdir+"/BHIS_CAR_ML_a10.0_*"+srchstr+"*.npy")[0]
		plot_peta_CL(histfile, fig, axin, True)
		axin.xaxis.set_major_locator(NullLocator())
		axin.yaxis.set_major_locator(NullLocator())
	
	##----------------------------------------------------------------------------
	## Double well insets
	elif "_NL_" in histdir:
		## Plot potential as inset
		fx = force_nlin([x,0],R,S)[0]
		U = -sp.integrate.cumtrapz(fx, x, initial=0.0); U -= U.min()
		left, bottom, width, height = [0.61, 0.30, 0.28, 0.20]
		axin = fig.add_axes([left, bottom, width, height])
		axin.plot(x, U, "k-")
		axin.axvspan(x[0],x[cuspind], color=lL[0].get_color(),alpha=0.2)
		axin.axvspan(x[cuspind],x[-1], color=lR[0].get_color(),alpha=0.2)
		axin.set_xlim(x[0],x[-1])
		axin.set_ylim(top=2*U[cuspind])
		axin.xaxis.set_major_locator(NullLocator())
		axin.yaxis.set_major_locator(NullLocator())
		axin.set_xlabel(r"$x$", fontsize = fs["fsa"]-5)
		axin.set_ylabel(r"$U$", fontsize = fs["fsa"]-5)
		
	##----------------------------------------------------------------------------
	##----------------------------------------------------------------------------
	
	if not nosave:
		if   "_ML_" in histfile:	geo = "ML"
		elif "_NL_" in histfile:	geo = "NL"
		elif "_CL_" in histfile:	geo = "CL"
		
		plotfile = histdir+"/MLR_CAR_"+geo+"_R%.1f_S%.1f_T%.1f."%(R,S,T)+fs["saveext"] if T>=0.0\
					else histdir+"/MLR_CAR_"+geo+"_R%.1f_S%.1f."%(R,S)+fs["saveext"]
		fig.savefig(plotfile)
		if vb:	print me+"Figure saved to",plotfile
		
	if vb: print me+"Execution time %.1f seconds."%(time.time()-t0)
	
	return
示例#5
0
def calc_mass_ratio(histdir, srchstr, noread, vb):
    """
	Read in directory of files with inner and outer regions.
	Compute mass in each region, take ratio.
	Compare with integrated and calculated white noise result. 
	"""
    me = me0 + ".calc_mass_ratio: "
    t0 = time.time()

    ##-------------------------------------------------------------------------

    ## Dir pars
    assert "_CAR_" in histdir, me + "Functional only for Cartesian geometry."
    assert "_DL_" not in histdir, me + "Must have interior region."

    ## File discovery
    filelist = np.sort(glob.glob(histdir + "/BHIS_CAR_*" + srchstr + "*.npy"))
    numfiles = len(filelist)
    assert numfiles > 1, me + "Check input directory."
    if vb: print me + "found", numfiles, "files"

    ##-------------------------------------------------------------------------

    A, ML, MR = np.zeros([3, numfiles])

    ## Retrieve data
    for i, histfile in enumerate(filelist):

        ## Assume R, S, T are same for all files
        A[i] = filename_par(histfile, "_a")
        R = filename_par(histfile, "_R")
        S = filename_par(histfile, "_S")
        try:
            T = filename_par(histfile, "_T")
        except ValueError:
            T = -S

        ## Space
        bins = np.load(
            os.path.dirname(histfile) + "/BHISBIN" +
            os.path.basename(histfile)[4:-4] + ".npz")
        xbins = bins["xbins"]
        x = 0.5 * (xbins[1:] + xbins[:-1])

        ##-------------------------------------------------------------------------

        ## Histogram
        H = np.load(histfile)
        ## Spatial density
        Qx = H.sum(axis=2).sum(axis=1) / (H.sum() * (x[1] - x[0]))

        ## Mass on either side of cusp: data. Left, right.
        if "_CL_" in histfile:
            cuspind = np.abs(0.5 * (T + S) - x).argmin()  ## Half-domain
        elif "_ML_" in histfile:
            cuspind = np.abs(0.5 * (T + S) - x).argmin()
        elif "_NL_" in histfile:
            cuspind = np.abs(S - x).argmin()

        ML[i] = np.trapz(Qx[:cuspind], x[:cuspind])
        MR[i] = np.trapz(Qx[cuspind:], x[cuspind:])

    ## SORT BY ALPHA
    srtidx = A.argsort()
    A = A[srtidx]
    ML = ML[srtidx]
    MR = MR[srtidx]

    ##-------------------------------------------------------------------------
    ## WN result from density solution

    if "_DL_" in histfile: fx = force_dlin([x, 0], R, S)[0]
    elif "_CL_" in histfile: fx = force_clin([x, 0], R, S, T)[0]
    elif "_ML_" in histfile: fx = force_mlin([x, 0], R, S, T)[0]
    elif "_NL_" in histfile: fx = force_nlin([x, 0], R, S)[0]
    else: raise IOError, me + "Force not recognised."

    U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
    U -= U.min()
    Qx_WN = np.exp(-U) / np.trapz(np.exp(-U), x)

    MLwn = np.trapz(Qx_WN[:cuspind], x[:cuspind])
    MRwn = np.trapz(Qx_WN[cuspind:], x[cuspind:])

    ##-------------------------------------------------------------------------
    ## Add a=0 point
    if 0.0 not in A:
        A = np.hstack([0.0, A])
        ML = np.hstack([MLwn, ML])
        MR = np.hstack([MRwn, MR])

    ##-------------------------------------------------------------------------

    ### This might not be the cleanest thing to save...

    ## SAVING
    if not noread:
        massfile = histdir + "/MASS_" + srchstr + ".npz"
        np.savez(massfile,
                 A=A,
                 ML=ML,
                 MR=MR,
                 MLwn=MLwn,
                 MRwn=MRwn,
                 x=x,
                 Qx_WN=Qx_WN,
                 R=R,
                 S=S,
                 T=T,
                 cuspind=cuspind)
        if vb:
            print me + "Calculations saved to", massfile
            print me + "Calculation time %.1f seconds." % (time.time() - t0)

    return {
        "A": A,
        "ML": ML,
        "MR": MR,
        "MLwn": MLwn,
        "MRwn": MRwn,
        "x": x,
        "Qx_WN": Qx_WN,
        "R": R,
        "S": S,
        "T": T,
        "cuspind": cuspind
    }
示例#6
0
def plot_mass_ratio(histdir, srchstr, nosave, noread, vb):
    """
	Plot the mass for all files in directory matching string.
	"""
    me = me0 + ".plot_mass_ratio: "
    t0 = time.time()

    ##-------------------------------------------------------------------------
    ## Read in existing data or calculate afresh

    try:
        assert noread == False
        massdata = np.load(histdir + "/MASS_" + srchstr + ".npz")
        print me + "Mass data file found:", histdir + "/MASS_" + srchstr + ".npz"
    except (IOError, AssertionError):
        print me + "No mass data found. Calculating from histfiles."
        massdata = calc_mass_ratio(histdir, srchstr, noread, vb)

    A = massdata["A"]
    ML = massdata["ML"]
    MR = massdata["MR"]
    MLwn = massdata["MLwn"]
    MRwn = massdata["MRwn"]
    x = massdata["x"]
    Qx_WN = massdata["Qx_WN"]
    R, S, T = massdata["R"], massdata["S"], massdata["T"]
    cuspind = massdata["cuspind"]
    del massdata

    ##-------------------------------------------------------------------------

    ## PLOTTING

    fig, ax = plt.subplots(1, 1)

    ## Mass normalised by WN result

    lL = ax.plot(A, ML / MLwn, "o-", label=r"Left")
    lR = ax.plot(A, MR / MRwn, "o-", label=r"Right")

    ax.set_xlabel(r"$\alpha$", fontsize=fs["fsa"])
    ax.set_ylabel(r"$M/M^{\rm passive}$", fontsize=fs["fsa"])
    ax.grid()

    ##----------------------------------------------------------------------------
    ## Casimir insets
    if "_CL_" in histdir:
        ## Plot potential as inset
        left, bottom, width, height = [0.2, 0.6, 0.3, 0.25]
        axin = fig.add_axes([left, bottom, width, height])

        x = np.linspace(-x[-1], x[-1], 2 * x.size)
        fx = force_clin([x, 0], R, S, T)[0]
        U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
        U -= U.min()
        axin.plot(x, U, "k-")
        cuspind += x.size / 2  ## Because x.size has doubles
        axin.axvspan(x[0], -x[cuspind], color=lR[0].get_color(), alpha=0.2)
        axin.axvspan(-x[cuspind],
                     x[cuspind],
                     color=lL[0].get_color(),
                     alpha=0.2)
        axin.axvspan(x[cuspind], x[-1], color=lR[0].get_color(), alpha=0.2)
        axin.set_xlim(-R - 2, R + 2)
        axin.set_ylim(top=2 * U[cuspind])
        axin.xaxis.set_ticklabels([])
        axin.yaxis.set_ticklabels([])
        axin.set_xlabel(r"$x$", fontsize=fs["fsa"] - 5)
        axin.set_ylabel(r"$U$", fontsize=fs["fsa"] - 5)

        ## Plot q(eta) as inset
        left, bottom, width, height = [0.55, 0.27, 0.33, 0.28]
        axin = fig.add_axes([left, bottom, width, height])
        ## Grab a file. Hacky. Assumes only one match.
        histfile = glob.glob(histdir + "/BHIS_CAR_CL_a5.0_*" + srchstr +
                             "*.npy")[0]
        plot_peta_CL(histfile, fig, axin, True)
        axin.xaxis.set_major_locator(NullLocator())
        axin.yaxis.set_major_locator(NullLocator())

    ##----------------------------------------------------------------------------
    ## Single wall insets
    elif "_ML_" in histdir:
        ## Plot potential as inset
        fx = force_mlin([x, 0], R, S, T)[0]
        U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
        U -= U.min()
        left, bottom, width, height = [0.18, 0.68, 0.33, 0.20]
        axin = fig.add_axes([left, bottom, width, height])
        axin.plot(x, U, "k-")
        axin.axvspan(x[0], x[cuspind], color=lL[0].get_color(), alpha=0.2)
        axin.axvspan(x[cuspind], x[-1], color=lR[0].get_color(), alpha=0.2)
        axin.set_xlim(-R - 1.5, R + 1.5)
        axin.set_ylim(top=2 * U[cuspind])
        axin.xaxis.set_major_locator(NullLocator())
        axin.yaxis.set_major_locator(NullLocator())
        axin.set_xlabel(r"$x$", fontsize=fs["fsa"] - 5)
        axin.set_ylabel(r"$U$", fontsize=fs["fsa"] - 5)

        ## Plot q(eta) as inset
        left, bottom, width, height = [0.55, 0.35, 0.33, 0.23]
        axin = fig.add_axes([left, bottom, width, height])
        ## Grab a file. Hacky. Assumes only one match.
        histfile = glob.glob(histdir + "/BHIS_CAR_ML_a10.0_*" + srchstr +
                             "*.npy")[0]
        plot_peta_CL(histfile, fig, axin, True)
        axin.xaxis.set_major_locator(NullLocator())
        axin.yaxis.set_major_locator(NullLocator())

    ##----------------------------------------------------------------------------
    ## Double well insets
    elif "_NL_" in histdir:
        ## Plot potential as inset
        fx = force_nlin([x, 0], R, S)[0]
        U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
        U -= U.min()
        left, bottom, width, height = [0.61, 0.30, 0.28, 0.20]
        axin = fig.add_axes([left, bottom, width, height])
        axin.plot(x, U, "k-")
        axin.axvspan(x[0], x[cuspind], color=lL[0].get_color(), alpha=0.2)
        axin.axvspan(x[cuspind], x[-1], color=lR[0].get_color(), alpha=0.2)
        axin.set_xlim(x[0], x[-1])
        axin.set_ylim(top=2 * U[cuspind])
        axin.xaxis.set_major_locator(NullLocator())
        axin.yaxis.set_major_locator(NullLocator())
        axin.set_xlabel(r"$x$", fontsize=fs["fsa"] - 5)
        axin.set_ylabel(r"$U$", fontsize=fs["fsa"] - 5)

    ##----------------------------------------------------------------------------
    ##----------------------------------------------------------------------------

    if not nosave:
        if "_ML_" in histfile: geo = "ML"
        elif "_NL_" in histfile: geo = "NL"
        elif "_CL_" in histfile: geo = "CL"

        plotfile = histdir+"/MLR_CAR_"+geo+"_R%.1f_S%.1f_T%.1f."%(R,S,T)+fs["saveext"] if T>=0.0\
           else histdir+"/MLR_CAR_"+geo+"_R%.1f_S%.1f."%(R,S)+fs["saveext"]
        fig.savefig(plotfile)
        if vb: print me + "Figure saved to", plotfile

    if vb: print me + "Execution time %.1f seconds." % (time.time() - t0)

    return
示例#7
0
def plot_pdf1d(histfile, nosave, vb):
    """
	Calculate Q(r) and q(eta) from file and plot.
	"""
    me = me0 + ".plot_pdf1d: "
    t0 = time.time()

    ##-------------------------------------------------------------------------

    ## Filename pars

    assert "_CAR_" in histfile, me + "Functional only for Cartesian geometry."
    Casimir = "_CL_" in histfile or "_ML_" in histfile or "_NL_" in histfile

    a = filename_par(histfile, "_a")
    R = filename_par(histfile, "_R")
    S = filename_par(histfile, "_S")
    try:
        T = filename_par(histfile, "_T")
    except ValueError:
        T = -S

    doQfit = (R == S and "_DL_" in histfile)
    plotq = int(False)

    ##-------------------------------------------------------------------------

    ## Space
    bins = np.load(
        os.path.dirname(histfile) + "/BHISBIN" +
        os.path.basename(histfile)[4:-4] + ".npz")
    xbins = bins["xbins"]
    exbins = bins["exbins"]
    eybins = bins["eybins"]
    x = 0.5 * (xbins[1:] + xbins[:-1])
    etax = 0.5 * (exbins[1:] + exbins[:-1])
    etay = 0.5 * (eybins[1:] + eybins[:-1])

    ## Wall indices
    Rind, Sind = np.abs(x - R).argmin(), np.abs(x - S).argmin()

    ##-------------------------------------------------------------------------

    ## Histogram
    H = np.load(histfile)
    rho = H / (H.sum() * (x[1] - x[0]) * (etax[1] - etax[0]) *
               (etay[1] - etay[0]))

    ## Spatial density
    Qx = rho.sum(axis=2).sum(axis=1) * (etax[1] - etax[0]) * (etay[1] -
                                                              etay[0])
    ## Force density
    qx = rho.sum(axis=2).sum(axis=0) * (x[1] - x[0]) * (etay[1] - etay[0])
    qy = rho.sum(axis=1).sum(axis=0) * (x[1] - x[0]) * (etax[1] - etax[0])

    ##-------------------------------------------------------------------------
    ## Fit
    gauss = lambda x, m, s2: 1 / np.sqrt(2 * np.pi * s2) * np.exp(-0.5 * (
        x - m)**2 / s2)

    if doQfit:
        fitQx = sp.optimize.curve_fit(gauss, x, Qx, p0=[R,
                                                        1 / np.sqrt(1 + a)])[0]

    ##-------------------------------------------------------------------------

    ## PLOTTING

    fig, axs = plt.subplots(1 + plotq, 1, figsize=fs["figsize"])
    fig.canvas.set_window_title("1D PDFs")

    ## Set number of ticks
    for ax in np.ravel([axs]):
        ax.xaxis.set_major_locator(MaxNLocator(5))
        ax.yaxis.set_major_locator(MaxNLocator(4))

    ##-------------------------------------------------------------------------

    ## Spatial density plot
    ax = axs[0] if plotq else axs

    ## Data
    ax.plot(x, Qx, label=r"OUP")
    ax.fill_between(x, 0.0, Qx, color="b", alpha=0.1)

    ## Gaussian for spatial density
    if doQfit:
        ax.plot(x,
                gauss(x, fitQx[0], 1 / (1 + a)),
                "c-",
                label=r"$G\left(\mu, \frac{1}{\alpha+1}\right)$")

    ## Potential and WN
    if "_DC_" in histfile: fx = force_dcon([x, 0], R, S)[0]
    elif "_DL_" in histfile: fx = force_dlin([x, 0], R, S)[0]
    elif "_CL_" in histfile: fx = force_clin([x, 0], R, S, T)[0]
    elif "_ML_" in histfile: fx = force_mlin([x, 0], R, S, T)[0]
    elif "_NL_" in histfile: fx = force_nlin([x, 0], R, S)[0]
    else: raise IOError, me + "Force not recognised."
    U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
    U -= U.min()

    ## Plot passive density
    Qx_WN = np.exp(-U) / np.trapz(np.exp(-U), x)
    ax.plot(x, Qx_WN, "r-", label="Passive")
    ax.fill_between(x, 0.0, Qx_WN, color="r", alpha=0.1)

    ## Plot potential
    ax.plot(x, U / U.max() * ax.get_ylim()[1], "k--", label=r"$U(x)$")

    ## Indicate bulk
    ax.axvline(S, c="k", lw=1)
    ax.axvline(R, c="k", lw=1)
    if T >= 0.0:
        ax.axvspan(S, R, color="y", alpha=0.1)
        ax.axvline(T, c="k", lw=1)
        ax.axvspan(-R, T, color="y", alpha=0.1)
        ax.axvline(-R, c="k", lw=1)
    elif T < 0.0:
        ax.axvline(-R, c="k", lw=1)

    ax.set_xlim(left=x[0], right=x[-1])
    ax.set_xlabel(r"$x$", fontsize=fs["fsa"])
    ax.set_ylabel(r"$n(x)$", fontsize=fs["fsa"])
    ax.grid()
    ax.legend(loc="upper right", fontsize=fs["fsl"]).get_frame().set_alpha(0.5)

    ##-------------------------------------------------------------------------

    if plotq:
        ## Force density plot
        ax = axs[1]

        ## Data
        ax.plot(etax, qx, label=r"Simulation $x$")
        ax.plot(etay, qy, label=r"Simulation $y$")

        ## Gaussian
        ax.plot(etax,
                gauss(etax, 0.0, 1 / a),
                "c-",
                label=r"$G\left(0, \frac{1}{\alpha}\right)$")

        ax.set_xlabel(r"$\eta$", fontsize=fs["fsa"])
        ax.set_ylabel(r"$q(\eta)$", fontsize=fs["fsa"])
        ax.grid()
        ax.legend(loc="upper right",
                  fontsize=fs["fsl"]).get_frame().set_alpha(0.5)

        ##-------------------------------------------------------------------------

        fig.tight_layout()
        fig.subplots_adjust(top=0.95)
        title = r"PDFs in $r$ and $\eta$. $\alpha=%.1f, R=%.1f, S=%.1f$"%(a,R,S)  if T<0.0\
          else r"PDFs in $r$ and $\eta$. $\alpha=%.1f, R=%.1f, S=%.1f, T=%.1f$"%(a,R,S,T)

    else:
        title = r"Spatial PDF. $\alpha=%.1f, R=%.1g, S=%.1g$"%(a,R,S)  if T<0.0\
          else r"Spatial PDF. $\alpha=%.1f, R=%.1f, S=%.1f, T=%.f$"%(a,R,S,T)

#	fig.suptitle(title, fontsize=fs["fst"])

    if not nosave:
        plotfile = os.path.dirname(histfile) + "/PDFxy1d" + os.path.basename(
            histfile)[4:-4]
        plotfile += "." + fs["saveext"]
        fig.savefig(plotfile, format=fs["saveext"])
        if vb: print me + "Figure saved to", plotfile

    if vb: print me + "Execution time %.1f seconds." % (time.time() - t0)

    return
示例#8
0
def plot_file(histfile, nosave, vb):
	"""
	"""
	me = me0+".plot_file: "
	
	##-------------------------------------------------------------------------
	
	## Dir pars
	assert "_CAR_" in histfile, me+"Functional only for Cartesian geometry."
	Casimir = "_CL_" in histfile or "_ML_" in histfile

	## Get pars from filename
	a = filename_par(histfile, "_a")
	R = filename_par(histfile, "_R")
	S = filename_par(histfile, "_S")
	T = filename_par(histfile, "_T") if Casimir else -S
	
	## Calculate quantities
	x, Q, BC = bulk_const(histfile)[:3]
	ex2 = BC/(Q+(Q==0.0))
	
	##-------------------------------------------------------------------------
		
	## Potential
	if   "_DL_" in histfile:	fx = force_dlin([x,0],R,S)[0]
	elif "_CL_" in histfile:	fx = force_clin([x,0],R,S,T)[0]
	elif "_ML_" in histfile:	fx = force_mlin([x,0],R,S,T)[0]
	elif "_NL_" in histfile:	fx = force_nlin([x,0],R,S)[0]
	U = -sp.integrate.cumtrapz(fx, x, initial=0.0); U -= U.min()
	
	##-------------------------------------------------------------------------
	
	## Smooth
	sp.ndimage.gaussian_filter1d(Q,1.0,order=0,output=Q)
	sp.ndimage.gaussian_filter1d(BC,1.0,order=0,output=BC)
	sp.ndimage.gaussian_filter1d(ex2,1.0,order=0,output=ex2)
	
	##-------------------------------------------------------------------------
	
	## PLOT
	fig, ax = plt.subplots(1,1, figsize=fs["figsize"])
	
	## Data
	ax.plot(x, Q/Q.max(),   label=r"$n(x)$",lw=2)
	ax.plot(x, ex2/ex2.max(), label=r"$\langle\eta_x^2\rangle(x)$",lw=2)
	ax.plot(x, BC/BC.max(), label=r"$\langle\eta_x^2\rangle \cdot n$",lw=2)
	
	ax.plot(x, U/U.max()*ax.get_ylim()[1], "k--", label=r"$U(x)$")	
		
	## Indicate bulk region
	if "_DL_" in histfile:
		ax.axvspan(S,R, color="yellow",alpha=0.2)
		ax.axvline(S, c="k",lw=2);	ax.axvline(R, c="k",lw=2)
	elif "_ML_" in histfile:
		ax.axvspan(S,R, color="yellow",alpha=0.2)
		ax.axvspan(-R,T, color="yellow",alpha=0.2)
		ax.axvline(S, c="k",lw=2);	ax.axvline(R, c="k",lw=2)
		ax.axvline(T, c="k",lw=2);	ax.axvline(-R, c="k",lw=2)
	elif "_CL_" in histfile:
		ax.axvspan(S,R, color="yellow",alpha=0.2)
		ax.axvspan(0,T, color="yellow",alpha=0.2)
		ax.axvline(S, c="k",lw=2);	ax.axvline(R, c="k",lw=2)
		ax.axvline(T, c="k",lw=2);	ax.axvline(-R, c="k",lw=2)
		
	##-------------------------------------------------------------------------
	
	## ATTRIBUTES
	
	ax.set_xlim(left=x[0],right=x[-1])
	ax.xaxis.set_major_locator(NullLocator())
	ax.yaxis.set_major_locator(NullLocator())

	ax.set_xlabel("$x$",fontsize=fs["fsa"])
	ax.set_ylabel("Rescaled variable",fontsize=fs["fsa"])
	ax.grid()
	legloc = [0.35,0.25] if "_ML_" in histfile else [0.32,0.67]
	ax.legend(loc=legloc,fontsize=fs["fsl"]).get_frame().set_alpha(0.8)
	title = r"Bulk Constant. $\alpha=%.1f, R=%.1f, S=%.1f, T=%.1f$."%(a,R,S,T) if T>=0.0\
			else r"Bulk Constant. $\alpha=%.1f, R=%.1f, S=%.1f$."%(a,R,S)
#	fig.suptitle(title,fontsize=fs["fst"])
	
	## SAVE
#	ax.set_ylim(top=BC.max())
	plotfile = os.path.dirname(histfile)+"/QEe2"+os.path.basename(histfile)[4:-4]+"."+fs["saveext"]
	if not nosave:
		fig.savefig(plotfile)
		if vb: print me+"Figure saved to",plotfile
	
	##-------------------------------------------------------------------------
	
	return plotfile
示例#9
0
def calc_pressure_dir(histdir, srchstr, noread, vb):
    """
	Calculate the pressure for all files in directory matching string.
	The 
	"""
    me = me0 + ".calc_pressure_dir: "
    t0 = time.time()

    ##-------------------------------------------------------------------------

    ## Dir pars
    assert "_CAR_" in histdir, me + "Functional only for Cartesian geometry."
    Casimir = "_DL_" not in histdir

    ## File discovery
    filelist = np.sort(glob.glob(histdir + "/BHIS_CAR_*" + srchstr + "*.npy"))
    numfiles = len(filelist)
    assert numfiles > 1, me + "Check input directory."
    if vb: print me + "found", numfiles, "files"

    ##-------------------------------------------------------------------------

    A, R, S, T, PR, PS, PT, PU, PR_WN, PS_WN, PT_WN, PU_WN = np.zeros(
        [12, numfiles])

    ## Retrieve data
    for i, histfile in enumerate(filelist):

        ti = time.time()

        ## Assuming R, S, T are same for all files
        A[i] = filename_par(histfile, "_a")
        R[i] = filename_par(histfile, "_R")
        S[i] = filename_par(histfile, "_S")
        try:
            T[i] = filename_par(histfile, "_T")
        except ValueError:
            T[i] = -S[i]

        ## Space
        bins = np.load(
            os.path.dirname(histfile) + "/BHISBIN" +
            os.path.basename(histfile)[4:-4] + ".npz")
        xbins = bins["xbins"]
        x = 0.5 * (xbins[1:] + xbins[:-1])

        ## Wall indices
        Rind, Sind, Tind = np.abs(x - R[i]).argmin(
        ), np.abs(x - S[i]).argmin() + 1, np.abs(x - T[i]).argmin()
        STind = 0 if T[i] < 0.0 else (Sind + Tind) / 2

        ## Adjust indices for pressure calculation
        if "_DC_" in histfile:
            STind = 0
        elif "_DL_" in histfile:
            STind = 0
        elif "_NL_" in histfile:
            STind = Sind
            Sind = Rind
            Tind = x.size - Rind

        ##-------------------------------------------------------------------------

        ## Histogram
        H = np.load(histfile)
        ## Spatial density
        Qx = H.sum(axis=2).sum(axis=1) / (H.sum() * (x[1] - x[0]))

        ##-------------------------------------------------------------------------

        ## Choose force
        if "_DC_" in histfile: fx = force_dcon([x, 0], R[i], S[i])[0]
        elif "_DL_" in histfile: fx = force_dlin([x, 0], R[i], S[i])[0]
        elif "_CL_" in histfile: fx = force_clin([x, 0], R[i], S[i], T[i])[0]
        elif "_ML_" in histfile: fx = force_mlin([x, 0], R[i], S[i], T[i])[0]
        elif "_NL_" in histfile: fx = force_nlin([x, 0], R[i], S[i])[0]
        else: raise IOError, me + "Force not recognised."

        ## Calculate integral pressure
        PR[i] = -sp.integrate.trapz(fx[Rind:] * Qx[Rind:], x[Rind:])
        PS[i] = +sp.integrate.trapz(fx[STind:Sind] * Qx[STind:Sind],
                                    x[STind:Sind])
        PT[i] = -sp.integrate.trapz(fx[Tind:STind] * Qx[Tind:STind],
                                    x[Tind:STind])
        if "_ML_" in histfile:
            mRind = x.size - Rind  ## Index of wall at x=-R
            PU[i] = +sp.integrate.trapz(fx[:mRind] * Qx[:mRind], x[:mRind])

        if vb:
            print me + "a=%.1f:\tPressure calculation %.2g seconds" % (
                A[i], time.time() - ti)

        ## Potential
        U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
        U -= U.min()
        Qx_WN = np.exp(-U) / np.trapz(np.exp(-U), x)
        ## WN pressure
        PR_WN[i] = -sp.integrate.trapz(fx[Rind:] * Qx_WN[Rind:], x[Rind:])
        PS_WN[i] = +sp.integrate.trapz(fx[STind:Sind] * Qx_WN[STind:Sind],
                                       x[STind:Sind])
        if Casimir:
            PT_WN[i] = -sp.integrate.trapz(fx[Tind:STind] * Qx_WN[Tind:STind],
                                           x[Tind:STind])
        if "_ML_" in histfile:
            PU_WN[i] = +sp.integrate.trapz(fx[:mRind] * Qx_WN[:mRind],
                                           x[:mRind])

    ##-------------------------------------------------------------------------

    ## SORT BY ALPHA
    srtidx = A.argsort()
    A = A[srtidx]
    R, S, T = R[srtidx], S[srtidx], T[srtidx]
    PR, PS, PT, PU = PR[srtidx], PS[srtidx], PT[srtidx], PU[srtidx]
    PR_WN, PS_WN, PT_WN, PU_WN = PR_WN[srtidx], PS_WN[srtidx], PT_WN[
        srtidx], PU_WN[srtidx]

    ## Normalise
    PR /= PR_WN + (PR_WN == 0)
    PS /= PS_WN + (PS_WN == 0)
    if Casimir:
        PT /= PT_WN + (PT_WN == 0)
    if "_ML_" in histdir:
        PU /= PU_WN + (PU_WN == 0)

    ##-------------------------------------------------------------------------

    ## SAVING
    if not noread:
        pressfile = histdir + "/PRESS_" + srchstr + ".npz"
        np.savez(pressfile,
                 A=A,
                 R=R,
                 S=S,
                 T=T,
                 PR=PR,
                 PS=PS,
                 PT=PT,
                 PU=PU,
                 PR_WN=PR_WN,
                 PS_WN=PS_WN,
                 PT_WN=PT_WN,
                 PU_WN=PU_WN)
        if vb:
            print me + "Calculations saved to", pressfile
            print me + "Calculation time %.1f seconds." % (time.time() - t0)

    return {
        "A": A,
        "R": R,
        "S": S,
        "T": T,
        "PR": PR,
        "PS": PS,
        "PT": PT,
        "PU": PU,
        "PR_WN": PR_WN,
        "PS_WN": PS_WN,
        "PT_WN": PT_WN,
        "PU_WN": PU_WN
    }
示例#10
0
def plot_pdf1d(histfile, nosave, vb):
	"""
	Calculate Q(r) and q(eta) from file and plot.
	"""
	me = me0+".plot_pdf1d: "
	t0 = time.time()
	
	##-------------------------------------------------------------------------
	
	## Filename pars
	
	assert "_CAR_" in histfile, me+"Functional only for Cartesian geometry."
	Casimir = "_CL_" in histfile or "_ML_" in histfile or "_NL_" in histfile
	
	a = filename_par(histfile, "_a")
	R = filename_par(histfile, "_R")
	S = filename_par(histfile, "_S")
	try: T = filename_par(histfile, "_T")
	except ValueError: T= -S
	
	doQfit = (R==S and "_DL_" in histfile)
	plotq = int(False)
	
	##-------------------------------------------------------------------------
		
	## Space
	bins = np.load(os.path.dirname(histfile)+"/BHISBIN"+os.path.basename(histfile)[4:-4]+".npz")
	xbins = bins["xbins"]
	exbins = bins["exbins"]
	eybins = bins["eybins"]
	x = 0.5*(xbins[1:]+xbins[:-1])
	etax = 0.5*(exbins[1:]+exbins[:-1])
	etay = 0.5*(eybins[1:]+eybins[:-1])
	
	## Wall indices
	Rind, Sind = np.abs(x-R).argmin(), np.abs(x-S).argmin()
	
	##-------------------------------------------------------------------------
	
	## Histogram
	H = np.load(histfile)
	rho = H / (H.sum() * (x[1]-x[0])*(etax[1]-etax[0])*(etay[1]-etay[0]))
	
	## Spatial density
	Qx = rho.sum(axis=2).sum(axis=1) * (etax[1]-etax[0])*(etay[1]-etay[0])
	## Force density
	qx = rho.sum(axis=2).sum(axis=0) * (x[1]-x[0])*(etay[1]-etay[0])
	qy = rho.sum(axis=1).sum(axis=0) * (x[1]-x[0])*(etax[1]-etax[0])
		
	##-------------------------------------------------------------------------
	## Fit
	gauss = lambda x, m, s2: 1/np.sqrt(2*np.pi*s2)*np.exp(-0.5*(x-m)**2/s2)
	
	if doQfit: fitQx = sp.optimize.curve_fit(gauss, x, Qx, p0=[R,1/np.sqrt(1+a)])[0]
	
	##-------------------------------------------------------------------------
	
	## PLOTTING
				
	fig, axs = plt.subplots(1+plotq,1, figsize=fs["figsize"])
	fig.canvas.set_window_title("1D PDFs")
	
	## Set number of ticks
	for ax in np.ravel([axs]):
		ax.xaxis.set_major_locator(MaxNLocator(5))
		ax.yaxis.set_major_locator(MaxNLocator(4))
	
	##-------------------------------------------------------------------------
	
	## Spatial density plot
	ax = axs[0] if plotq else axs
	
	## Data
	ax.plot(x, Qx, label=r"OUP")
	ax.fill_between(x, 0.0, Qx, color="b", alpha=0.1)
	
	## Gaussian for spatial density
	if doQfit:
		ax.plot(x, gauss(x,fitQx[0],1/(1+a)), "c-", label=r"$G\left(\mu, \frac{1}{\alpha+1}\right)$")
	
	## Potential and WN
	if   "_DC_" in histfile:	fx = force_dcon([x,0],R,S)[0]
	elif "_DL_" in histfile:	fx = force_dlin([x,0],R,S)[0]
	elif "_CL_" in histfile:	fx = force_clin([x,0],R,S,T)[0]
	elif "_ML_" in histfile:	fx = force_mlin([x,0],R,S,T)[0]
	elif "_NL_" in histfile:	fx = force_nlin([x,0],R,S)[0]
	else: raise IOError, me+"Force not recognised."
	U = -sp.integrate.cumtrapz(fx, x, initial=0.0); U -= U.min()
	
	## Plot passive density
	Qx_WN = np.exp(-U)/np.trapz(np.exp(-U),x)
	ax.plot(x, Qx_WN, "r-", label="Passive")
	ax.fill_between(x, 0.0, Qx_WN, color="r", alpha=0.1)
	
	## Plot potential
	ax.plot(x, U/U.max()*ax.get_ylim()[1], "k--",label=r"$U(x)$")
	
	## Indicate bulk
	ax.axvline(S,c="k",lw=1)
	ax.axvline(R,c="k",lw=1)
	if T>=0.0:
		ax.axvspan(S,R,color="y",alpha=0.1)
		ax.axvline(T,c="k",lw=1)
		ax.axvspan(-R,T,color="y",alpha=0.1)
		ax.axvline(-R,c="k",lw=1)
	elif T<0.0:
		ax.axvline(-R,c="k",lw=1)
	
	ax.set_xlim(left=x[0],right=x[-1])
	ax.set_xlabel(r"$x$", fontsize=fs["fsa"])
	ax.set_ylabel(r"$n(x)$", fontsize=fs["fsa"])
	ax.grid()
	ax.legend(loc="upper right", fontsize=fs["fsl"]).get_frame().set_alpha(0.5)
		
	##-------------------------------------------------------------------------
	
	if plotq:
		## Force density plot
		ax = axs[1]
	
		## Data
		ax.plot(etax, qx, label=r"Simulation $x$")
		ax.plot(etay, qy, label=r"Simulation $y$")
	
		## Gaussian
		ax.plot(etax, gauss(etax,0.0,1/a), "c-", label=r"$G\left(0, \frac{1}{\alpha}\right)$")
	
		ax.set_xlabel(r"$\eta$", fontsize=fs["fsa"])
		ax.set_ylabel(r"$q(\eta)$", fontsize=fs["fsa"])
		ax.grid()
		ax.legend(loc="upper right", fontsize=fs["fsl"]).get_frame().set_alpha(0.5)
	
		##-------------------------------------------------------------------------
	
		fig.tight_layout()
		fig.subplots_adjust(top=0.95)
		title = r"PDFs in $r$ and $\eta$. $\alpha=%.1f, R=%.1f, S=%.1f$"%(a,R,S)  if T<0.0\
				else r"PDFs in $r$ and $\eta$. $\alpha=%.1f, R=%.1f, S=%.1f, T=%.1f$"%(a,R,S,T)
				
	else:			
		title = r"Spatial PDF. $\alpha=%.1f, R=%.1g, S=%.1g$"%(a,R,S)  if T<0.0\
				else r"Spatial PDF. $\alpha=%.1f, R=%.1f, S=%.1f, T=%.f$"%(a,R,S,T)
				
				
#	fig.suptitle(title, fontsize=fs["fst"])
	
	if not nosave:
		plotfile = os.path.dirname(histfile)+"/PDFxy1d"+os.path.basename(histfile)[4:-4]
		plotfile += "."+fs["saveext"]
		fig.savefig(plotfile, format=fs["saveext"])
		if vb:	print me+"Figure saved to",plotfile
		
	if vb: print me+"Execution time %.1f seconds."%(time.time()-t0)
	
	return
示例#11
0
def plot_file(histfile, nosave, vb):
    """
	"""
    me = me0 + ".plot_file: "

    ##-------------------------------------------------------------------------

    ## Dir pars
    assert "_CAR_" in histfile, me + "Functional only for Cartesian geometry."
    Casimir = "_CL_" in histfile or "_ML_" in histfile

    ## Get pars from filename
    a = filename_par(histfile, "_a")
    R = filename_par(histfile, "_R")
    S = filename_par(histfile, "_S")
    T = filename_par(histfile, "_T") if Casimir else -S

    ## Calculate quantities
    x, Q, BC = bulk_const(histfile)[:3]
    ex2 = BC / (Q + (Q == 0.0))

    ##-------------------------------------------------------------------------

    ## Potential
    if "_DL_" in histfile: fx = force_dlin([x, 0], R, S)[0]
    elif "_CL_" in histfile: fx = force_clin([x, 0], R, S, T)[0]
    elif "_ML_" in histfile: fx = force_mlin([x, 0], R, S, T)[0]
    elif "_NL_" in histfile: fx = force_nlin([x, 0], R, S)[0]
    U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
    U -= U.min()

    ##-------------------------------------------------------------------------

    ## Smooth
    sp.ndimage.gaussian_filter1d(Q, 1.0, order=0, output=Q)
    sp.ndimage.gaussian_filter1d(BC, 1.0, order=0, output=BC)
    sp.ndimage.gaussian_filter1d(ex2, 1.0, order=0, output=ex2)

    ##-------------------------------------------------------------------------

    ## PLOT
    fig, ax = plt.subplots(1, 1, figsize=fs["figsize"])

    ## Data
    ax.plot(x, Q / Q.max(), label=r"$n(x)$", lw=2)
    ax.plot(x, ex2 / ex2.max(), label=r"$\langle\eta_x^2\rangle(x)$", lw=2)
    ax.plot(x, BC / BC.max(), label=r"$\langle\eta_x^2\rangle \cdot n$", lw=2)

    ax.plot(x, U / U.max() * ax.get_ylim()[1], "k--", label=r"$U(x)$")

    ## Indicate bulk region
    if "_DL_" in histfile:
        ax.axvspan(S, R, color="yellow", alpha=0.2)
        ax.axvline(S, c="k", lw=2)
        ax.axvline(R, c="k", lw=2)
    elif "_ML_" in histfile:
        ax.axvspan(S, R, color="yellow", alpha=0.2)
        ax.axvspan(-R, T, color="yellow", alpha=0.2)
        ax.axvline(S, c="k", lw=2)
        ax.axvline(R, c="k", lw=2)
        ax.axvline(T, c="k", lw=2)
        ax.axvline(-R, c="k", lw=2)
    elif "_CL_" in histfile:
        ax.axvspan(S, R, color="yellow", alpha=0.2)
        ax.axvspan(0, T, color="yellow", alpha=0.2)
        ax.axvline(S, c="k", lw=2)
        ax.axvline(R, c="k", lw=2)
        ax.axvline(T, c="k", lw=2)
        ax.axvline(-R, c="k", lw=2)

    ##-------------------------------------------------------------------------

    ## ATTRIBUTES

    ax.set_xlim(left=x[0], right=x[-1])
    ax.xaxis.set_major_locator(NullLocator())
    ax.yaxis.set_major_locator(NullLocator())

    ax.set_xlabel("$x$", fontsize=fs["fsa"])
    ax.set_ylabel("Rescaled variable", fontsize=fs["fsa"])
    ax.grid()
    legloc = [0.35, 0.25] if "_ML_" in histfile else [0.32, 0.67]
    ax.legend(loc=legloc, fontsize=fs["fsl"]).get_frame().set_alpha(0.8)
    title = r"Bulk Constant. $\alpha=%.1f, R=%.1f, S=%.1f, T=%.1f$."%(a,R,S,T) if T>=0.0\
      else r"Bulk Constant. $\alpha=%.1f, R=%.1f, S=%.1f$."%(a,R,S)
    #	fig.suptitle(title,fontsize=fs["fst"])

    ## SAVE
    #	ax.set_ylim(top=BC.max())
    plotfile = os.path.dirname(histfile) + "/QEe2" + os.path.basename(
        histfile)[4:-4] + "." + fs["saveext"]
    if not nosave:
        fig.savefig(plotfile)
        if vb: print me + "Figure saved to", plotfile

    ##-------------------------------------------------------------------------

    return plotfile
示例#12
0
def plot_dir(histdir, srchstr, logplot, nosave, vb):
    """
	For each file in directory, calculate the pressure in both ways for all walls
	(where applicable) and plot against alpha.
	"""
    me = me0 + ".plot_dir: "

    filelist = np.sort(glob.glob(histdir + "/BHIS_CAR_*" + srchstr + "*.npy"))
    numfiles = filelist.size
    if vb: print me + "Found", numfiles, "files."

    ## Initialise arrays
    A, pR, pS, pT, PR, PS, PT = np.zeros([7, numfiles])

    ## Retrieve data
    for i, histfile in enumerate(filelist):

        Casimir = "_CL_" in histfile or "_ML_" in histfile or "_NL_" in histfile

        ## Get pars from filename
        A[i] = filename_par(histfile, "_a")
        R = filename_par(histfile, "_R")
        S = filename_par(histfile, "_S")
        T = filename_par(histfile, "_T") if Casimir else -S

        ## Calculate BC
        x, Qx, BC = bulk_const(histfile)[:3]

        ## Wall indices
        Rind, Sind, Tind = np.abs(x - R).argmin(), np.abs(
            x - S).argmin(), np.abs(x - T).argmin()
        STind = 0 if "_DL_" in histfile else (Tind + Sind) / 2

        ##---------------------------------------------------------------------
        ## Calculate pressure from BC

        if "_DL_" in histfile:
            BCsr = BC[Sind:Rind + 1].mean()
            pR[i] = A[i] * BCsr
            pS[i] = A[i] * BCsr

        elif "_CL_" in histfile:
            BCsr = BC[Sind:Rind + 1].mean()
            BCts = BC[STind]
            BC0t = BC[0:Tind + 1].mean()
            pR[i] = A[i] * BCsr
            pS[i] = A[i] * (BCsr - BCts)
            pT[i] = A[i] * (BC0t - BCts)

        elif "_ML_" in histfile:
            BCsr = BC[Sind:Rind + 1].mean()
            BCts = BC[STind]
            BCrt = BC[x.size - Rind:Tind + 1].mean()
            pR[i] = A[i] * BCsr
            pS[i] = A[i] * (-BCsr + BCts)
            pT[i] = A[i] * (-BCrt + BCts)

        elif "_NL_" in histfile:
            BCr = BC[Rind]
            BCs = BC[Sind]
            BCmr = BC[x.size - Rind]
            pR[i] = A[i] * BCr
            pS[i] = A[i] * (BCs - BCr)
            pT[i] = A[i] * (BCs - BCmr)

        ##---------------------------------------------------------------------
        ## Calculate pressure from integral

        ## Choose force
        if "_DL_" in histfile: fx = force_dlin([x, 0], R, S)[0]
        elif "_CL_" in histfile: fx = force_clin([x, 0], R, S, T)[0]
        elif "_ML_" in histfile: fx = force_mlin([x, 0], R, S, T)[0]
        elif "_NL_" in histfile: fx = force_nlin([x, 0], R, S)[0]

        ## Calculate integral pressure
        PR[i] = -sp.integrate.trapz(fx[Rind:] * Qx[Rind:], x[Rind:])
        PS[i] = +sp.integrate.trapz(fx[STind:Sind] * Qx[STind:Sind],
                                    x[STind:Sind])
        PT[i] = -sp.integrate.trapz(fx[Tind:STind] * Qx[Tind:STind],
                                    x[Tind:STind])

        ##---------------------------------------------------------------------

    ## SORT BY ALPHA
    srtidx = A.argsort()
    A = A[srtidx]
    pR, pS, pT = pR[srtidx], pS[srtidx], pT[srtidx]
    PR, PS, PT = PR[srtidx], PS[srtidx], PT[srtidx]

    ##-------------------------------------------------------------------------

    ## Calculate white noise PDF and pressure -- assuming alpha is only varying parameter
    U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
    U -= U.min()
    Qx_WN = np.exp(-U) / np.trapz(np.exp(-U), x)

    PR_WN = -sp.integrate.trapz(fx[Rind:] * Qx_WN[Rind:], x[Rind:])
    PS_WN = +sp.integrate.trapz(fx[STind:Sind] * Qx_WN[STind:Sind],
                                x[STind:Sind])
    PT_WN = -sp.integrate.trapz(fx[Tind:STind] * Qx_WN[Tind:STind],
                                x[Tind:STind])

    ## Normalise
    pR /= PR_WN
    pS /= PS_WN
    pT /= PT_WN
    PR /= PR_WN
    PS /= PS_WN
    PT /= PT_WN

    ##-------------------------------------------------------------------------

    ## Add a=0 point
    if 0.0 not in A:
        nlin = np.unique(S).size
        A = np.hstack([[0.0] * nlin, A])
        pR = np.hstack([[1.0] * nlin, pR])
        pS = np.hstack([[1.0] * nlin, pS])
        PR = np.hstack([[1.0] * nlin, PR])
        PS = np.hstack([[1.0] * nlin, PS])

    ##-------------------------------------------------------------------------

    ## PLOT DATA

    fig, ax = plt.subplots(1, 1, figsize=fs["figsize"])
    sty = ["-", "--", ":"]

    A += int(logplot)
    """
	lpR = ax.plot(A, pR, "o"+sty[0], label=r"BC pR")
	lpS = ax.plot(A, pS, "o"+sty[1], c=ax.lines[-1].get_color(), label=r"BC pS")
	if Casimir:	
		lpT = ax.plot(A, pT, "o"+sty[2], c=ax.lines[-1].get_color(), label=r"BC pT")
	
	ax.plot(A, PR, "v"+sty[0], label=r"Int PR")
	ax.plot(A, PS, "v"+sty[1], c=ax.lines[-1].get_color(), label=r"Int PS")
	if Casimir:	
		ax.plot(A, PT, "v"+sty[2], c=ax.lines[-1].get_color(), label=r"Int PT")
	"""
    lpR = ax.plot(A,
                  0.5 * (pR + pS),
                  "o--",
                  label=r"$\alpha\left<\eta^2\right>n(x)|^{\rm bulk}$")
    ax.plot(A, 0.5 * (PR + PS), "v--", label=r"$-\int f(x)n(x) {\rm d}x$")

    ##-------------------------------------------------------------------------

    ## ACCOUTREMENTS

    if logplot:
        ax.set_xscale("log")
        ax.set_yscale("log")
        xlim = (ax.get_xlim()[0], A[-1])
        xlabel = r"$1+\alpha$"
    else:
        xlim = (0.0, A[-1])
        xlabel = r"$\alpha$"

    ax.set_xlim(xlim)
    ax.set_ylim(1e-1, 1e+1)
    ax.set_xlabel(xlabel, fontsize=fs["fsa"])
    ax.set_ylabel(r"$P(\alpha)/P^{\rm passive}$", fontsize=fs["fsa"])
    ax.grid()
    ax.legend(loc="best", fontsize=fs["fsl"]).get_frame().set_alpha(0.5)
    title = "Pressure normalised by WN result. $R=%.1f, S=%.1f, T=%.1f.$"%(R,S,T) if T>=0.0\
      else "Pressure normalised by WN result. $R=%.1f, S=%.1f.$"%(R,S)
    #	fig.suptitle(title,fontsize=fs["fst"])

    ## SAVING
    plotfile = histdir+"/QEe2_Pa_R%.1f_S%.1f_T%.1f"%(R,S,T) if T>=0.0\
       else histdir+"/QEe2_Pa_R%.1f_S%.1f"%(R,S)
    plotfile += "_loglog" * logplot + "." + fs["saveext"]
    if not nosave:
        fig.savefig(plotfile)
        if vb: print me + "Figure saved to", plotfile

    return plotfile
示例#13
0
        ##-------------------------------------------------------------------------

        plt.show()

        exit()

    ##=============================================================================

    ## 1D potential for NLIN with pressure key
    if 0:

        R = 2.0
        S = 1.0

        x = np.linspace(-R - 3, R + 3, 1000)
        fx = force_nlin([x, 0], R, S)[0]
        U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
        U -= U.min()

        fig, ax = plt.subplots(1, 1, figsize=fs["figsize"])

        ax.plot(x, U, "-", lw=2)
        ax.axvline(-R, c="k", ls="-")
        ax.axvline(S, c="k", ls="-")
        ax.axvline(R, c="k", ls="-")
        ax.text(0.5 * (x[0] - R),
                0.4 * U.max(),
                r"$\leftarrow P_U$",
                fontsize=fs["fsl"],
                horizontalalignment="center")
        ax.text(0.5 * (-R + S),
示例#14
0
		##-------------------------------------------------------------------------

		plt.show()
	
		exit()

	##=============================================================================

	## 1D potential for NLIN with pressure key
	if 0:

		R = 2.0
		S = 1.0
		
		x = np.linspace(-R-3,R+3,1000)
		fx = force_nlin([x,0],R,S)[0]
		U = -sp.integrate.cumtrapz(fx,x,initial=0.0); U-=U.min()

		fig, ax = plt.subplots(1,1, figsize=fs["figsize"])
	
		ax.plot(x, U, "-", lw=2)
		ax.axvline(-R, c="k",ls="-")
		ax.axvline(S, c="k",ls="-")
		ax.axvline(R, c="k",ls="-")
		ax.text(0.5*(x[0]-R),0.4*U.max(), r"$\leftarrow P_U$", fontsize=fs["fsl"], horizontalalignment="center")
		ax.text(0.5*(-R+S),0.4*U.max(), r"$P_T \rightarrow$", fontsize=fs["fsl"], horizontalalignment="center")
		ax.text(0.5*(S+R),0.55*U.max(), r"$\leftarrow P_S$", fontsize=fs["fsl"], horizontalalignment="center")
		ax.text(0.5*(R+x[-1]),0.55*U.max(), r"$P_R \rightarrow$", fontsize=fs["fsl"], horizontalalignment="center")

		ax.set_xlim((x[0],x[-1]))
		ax.set_xlabel(r"$x$", fontsize=fs["fsa"])
示例#15
0
def calc_pressure_dir(histdir, srchstr, noread, vb):
	"""
	Calculate the pressure for all files in directory matching string.
	The 
	"""
	me = me0+".calc_pressure_dir: "
	t0 = time.time()
	
	##-------------------------------------------------------------------------
	
	## Dir pars
	assert "_CAR_" in histdir, me+"Functional only for Cartesian geometry."
	Casimir = "_DL_" not in histdir
	
	## File discovery
	filelist = np.sort(glob.glob(histdir+"/BHIS_CAR_*"+srchstr+"*.npy"))
	numfiles = len(filelist)
	assert numfiles>1, me+"Check input directory."
	if vb: print me+"found",numfiles,"files"

	##-------------------------------------------------------------------------
	
	A, R, S, T, PR, PS, PT, PU, PR_WN, PS_WN, PT_WN, PU_WN = np.zeros([12,numfiles])
	
	## Retrieve data
	for i, histfile in enumerate(filelist):
		
		ti = time.time()
		
		## Assuming R, S, T are same for all files
		A[i] = filename_par(histfile, "_a")
		R[i] = filename_par(histfile, "_R")
		S[i] = filename_par(histfile, "_S")
		try: 
			T[i] = filename_par(histfile, "_T")
		except ValueError:
			T[i] = -S[i]
			
		## Space
		bins = np.load(os.path.dirname(histfile)+"/BHISBIN"+os.path.basename(histfile)[4:-4]+".npz")
		xbins = bins["xbins"]
		x = 0.5*(xbins[1:]+xbins[:-1])
		
		## Wall indices
		Rind, Sind, Tind = np.abs(x-R[i]).argmin(), np.abs(x-S[i]).argmin()+1, np.abs(x-T[i]).argmin()
		STind = 0 if T[i]<0.0 else (Sind+Tind)/2
	
		## Adjust indices for pressure calculation
		if "_DC_" in histfile:
			STind = 0
		elif "_DL_" in histfile:
			STind = 0
		elif "_NL_" in histfile:
			STind = Sind
			Sind = Rind
			Tind = x.size-Rind
		
		##-------------------------------------------------------------------------
		
		## Histogram
		H = np.load(histfile)
		## Spatial density
		Qx = H.sum(axis=2).sum(axis=1) / (H.sum()*(x[1]-x[0]))
		
		##-------------------------------------------------------------------------
		
		## Choose force
		if   "_DC_" in histfile:	fx = force_dcon([x,0],R[i],S[i])[0]
		elif "_DL_" in histfile:	fx = force_dlin([x,0],R[i],S[i])[0]
		elif "_CL_" in histfile:	fx = force_clin([x,0],R[i],S[i],T[i])[0]
		elif "_ML_" in histfile:	fx = force_mlin([x,0],R[i],S[i],T[i])[0]
		elif "_NL_" in histfile:	fx = force_nlin([x,0],R[i],S[i])[0]
		else: raise IOError, me+"Force not recognised."
		
		## Calculate integral pressure
		PR[i] = -sp.integrate.trapz(fx[Rind:]*Qx[Rind:], x[Rind:])
		PS[i] = +sp.integrate.trapz(fx[STind:Sind]*Qx[STind:Sind], x[STind:Sind])
		PT[i] = -sp.integrate.trapz(fx[Tind:STind]*Qx[Tind:STind], x[Tind:STind])
		if "_ML_" in histfile:
			mRind = x.size-Rind	## Index of wall at x=-R
			PU[i] = +sp.integrate.trapz(fx[:mRind]*Qx[:mRind], x[:mRind])
		
		if vb: print me+"a=%.1f:\tPressure calculation %.2g seconds"%(A[i],time.time()-ti)
		
		## Potential
		U = -sp.integrate.cumtrapz(fx, x, initial=0.0); U -= U.min()
		Qx_WN = np.exp(-U) / np.trapz(np.exp(-U), x)
		## WN pressure
		PR_WN[i] = -sp.integrate.trapz(fx[Rind:]*Qx_WN[Rind:], x[Rind:])
		PS_WN[i] = +sp.integrate.trapz(fx[STind:Sind]*Qx_WN[STind:Sind], x[STind:Sind])
		if Casimir:
			PT_WN[i] = -sp.integrate.trapz(fx[Tind:STind]*Qx_WN[Tind:STind], x[Tind:STind])
		if "_ML_" in histfile:
			PU_WN[i] = +sp.integrate.trapz(fx[:mRind]*Qx_WN[:mRind], x[:mRind])
		
	##-------------------------------------------------------------------------
			
	## SORT BY ALPHA
	srtidx = A.argsort()
	A = A[srtidx]
	R, S, T = R[srtidx], S[srtidx], T[srtidx]
	PR, PS, PT, PU = PR[srtidx], PS[srtidx], PT[srtidx], PU[srtidx]
	PR_WN, PS_WN, PT_WN, PU_WN = PR_WN[srtidx], PS_WN[srtidx], PT_WN[srtidx], PU_WN[srtidx]
	
	## Normalise
	PR /= PR_WN + (PR_WN==0)
	PS /= PS_WN + (PS_WN==0)
	if Casimir:
		PT /= PT_WN + (PT_WN==0)
	if "_ML_" in histdir:
		PU /= PU_WN + (PU_WN==0)
		
	##-------------------------------------------------------------------------
		
	## SAVING
	if not noread:
		pressfile = histdir+"/PRESS_"+srchstr+".npz"
		np.savez(pressfile, A=A, R=R, S=S, T=T, PR=PR, PS=PS, PT=PT, PU=PU,
								PR_WN=PR_WN, PS_WN=PS_WN, PT_WN=PT_WN, PU_WN=PU_WN)
		if vb:
			print me+"Calculations saved to",pressfile
			print me+"Calculation time %.1f seconds."%(time.time()-t0)

	return {"A":A,"R":R,"S":S,"T":T,"PR":PR,"PS":PS,"PT":PT,"PU":PU,
					"PR_WN":PR_WN,"PS_WN":PS_WN,"PT_WN":PT_WN,"PU_WN":PU_WN}
示例#16
0
def plot_dir(histdir, srchstr, logplot, nosave, vb):
	"""
	For each file in directory, calculate the pressure in both ways for all walls
	(where applicable) and plot against alpha.
	"""
	me = me0+".plot_dir: "
	
	filelist = np.sort(glob.glob(histdir+"/BHIS_CAR_*"+srchstr+"*.npy"))
	numfiles = filelist.size
	if vb: print me+"Found",numfiles,"files."
	
	## Initialise arrays
	A, pR, pS, pT, PR, PS, PT = np.zeros([7,numfiles])	
	
	## Retrieve data
	for i, histfile in enumerate(filelist):
	
		Casimir = "_CL_" in histfile or "_ML_" in histfile or "_NL_" in histfile

		## Get pars from filename
		A[i] = filename_par(histfile, "_a")
		R = filename_par(histfile, "_R")
		S = filename_par(histfile, "_S")
		T = filename_par(histfile, "_T") if Casimir else -S
		
		## Calculate BC
		x, Qx, BC = bulk_const(histfile)[:3]
		
		## Wall indices
		Rind, Sind, Tind = np.abs(x-R).argmin(), np.abs(x-S).argmin(), np.abs(x-T).argmin()
		STind = 0 if "_DL_" in histfile else (Tind+Sind)/2
		
		##---------------------------------------------------------------------
		## Calculate pressure from BC
		
		if "_DL_" in histfile:	
			BCsr = BC[Sind:Rind+1].mean()
			pR[i] = A[i] * BCsr
			pS[i] = A[i] * BCsr
			
		elif "_CL_" in histfile:
			BCsr = BC[Sind:Rind+1].mean()
			BCts = BC[STind]
			BC0t = BC[0:Tind+1].mean()
			pR[i] = A[i] * BCsr
			pS[i] = A[i] * (BCsr - BCts)
			pT[i] = A[i] * (BC0t - BCts)
			
		elif "_ML_" in histfile:
			BCsr = BC[Sind:Rind+1].mean()
			BCts = BC[STind]
			BCrt = BC[x.size-Rind:Tind+1].mean()
			pR[i] = A[i] * BCsr
			pS[i] = A[i] * (-BCsr + BCts)
			pT[i] = A[i] * (-BCrt + BCts)
			
		elif "_NL_" in histfile:
			BCr = BC[Rind]
			BCs = BC[Sind]
			BCmr = BC[x.size-Rind]
			pR[i] = A[i] * BCr
			pS[i] = A[i] * (BCs - BCr)
			pT[i] = A[i] * (BCs - BCmr)
		
		##---------------------------------------------------------------------
		## Calculate pressure from integral
		
		## Choose force
		if   "_DL_" in histfile:	fx = force_dlin([x,0],R,S)[0]
		elif "_CL_" in histfile:	fx = force_clin([x,0],R,S,T)[0]
		elif "_ML_" in histfile:	fx = force_mlin([x,0],R,S,T)[0]
		elif "_NL_" in histfile:	fx = force_nlin([x,0],R,S)[0]
	
		## Calculate integral pressure
		PR[i] = -sp.integrate.trapz(fx[Rind:]*Qx[Rind:], x[Rind:])
		PS[i] = +sp.integrate.trapz(fx[STind:Sind]*Qx[STind:Sind], x[STind:Sind])
		PT[i] = -sp.integrate.trapz(fx[Tind:STind]*Qx[Tind:STind], x[Tind:STind])
		
		##---------------------------------------------------------------------
		
			
	## SORT BY ALPHA
	srtidx = A.argsort()
	A = A[srtidx]
	pR, pS, pT = pR[srtidx], pS[srtidx], pT[srtidx]
	PR, PS, PT = PR[srtidx], PS[srtidx], PT[srtidx]
	
	##-------------------------------------------------------------------------
	
	## Calculate white noise PDF and pressure -- assuming alpha is only varying parameter
	U = -sp.integrate.cumtrapz(fx, x, initial=0.0); U -= U.min()
	Qx_WN = np.exp(-U) / np.trapz(np.exp(-U),x)
	
	PR_WN = -sp.integrate.trapz(fx[Rind:]*Qx_WN[Rind:], x[Rind:])
	PS_WN = +sp.integrate.trapz(fx[STind:Sind]*Qx_WN[STind:Sind], x[STind:Sind])
	PT_WN = -sp.integrate.trapz(fx[Tind:STind]*Qx_WN[Tind:STind], x[Tind:STind])
	
	## Normalise
	pR /= PR_WN; pS /= PS_WN; pT /= PT_WN
	PR /= PR_WN; PS /= PS_WN; PT /= PT_WN
	
	##-------------------------------------------------------------------------
	
	## Add a=0 point
	if 0.0 not in A:
		nlin = np.unique(S).size
		A = np.hstack([[0.0]*nlin,A])
		pR = np.hstack([[1.0]*nlin,pR])
		pS = np.hstack([[1.0]*nlin,pS])
		PR = np.hstack([[1.0]*nlin,PR])
		PS = np.hstack([[1.0]*nlin,PS])
		
	##-------------------------------------------------------------------------
	
	## PLOT DATA
	
	fig, ax = plt.subplots(1,1, figsize=fs["figsize"])
	sty = ["-","--",":"]
	
	A += int(logplot)
	
	"""
	lpR = ax.plot(A, pR, "o"+sty[0], label=r"BC pR")
	lpS = ax.plot(A, pS, "o"+sty[1], c=ax.lines[-1].get_color(), label=r"BC pS")
	if Casimir:	
		lpT = ax.plot(A, pT, "o"+sty[2], c=ax.lines[-1].get_color(), label=r"BC pT")
	
	ax.plot(A, PR, "v"+sty[0], label=r"Int PR")
	ax.plot(A, PS, "v"+sty[1], c=ax.lines[-1].get_color(), label=r"Int PS")
	if Casimir:	
		ax.plot(A, PT, "v"+sty[2], c=ax.lines[-1].get_color(), label=r"Int PT")
	"""
	lpR = ax.plot(A, 0.5*(pR+pS), "o--", label=r"$\alpha\left<\eta^2\right>n(x)|^{\rm bulk}$")
	ax.plot(A, 0.5*(PR+PS), "v--", label=r"$-\int f(x)n(x) {\rm d}x$")
		
	##-------------------------------------------------------------------------
	
	## ACCOUTREMENTS
	
	if logplot:
		ax.set_xscale("log"); ax.set_yscale("log")
		xlim = (ax.get_xlim()[0],A[-1])
		xlabel = r"$1+\alpha$"
	else:
		xlim = (0.0,A[-1])
		xlabel = r"$\alpha$"
		
	ax.set_xlim(xlim)
	ax.set_ylim(1e-1,1e+1)
	ax.set_xlabel(xlabel,fontsize=fs["fsa"])
	ax.set_ylabel(r"$P(\alpha)/P^{\rm passive}$",fontsize=fs["fsa"])
	ax.grid()
	ax.legend(loc="best", fontsize=fs["fsl"]).get_frame().set_alpha(0.5)
	title = "Pressure normalised by WN result. $R=%.1f, S=%.1f, T=%.1f.$"%(R,S,T) if T>=0.0\
			else "Pressure normalised by WN result. $R=%.1f, S=%.1f.$"%(R,S)
#	fig.suptitle(title,fontsize=fs["fst"])
	
	## SAVING
	plotfile = histdir+"/QEe2_Pa_R%.1f_S%.1f_T%.1f"%(R,S,T) if T>=0.0\
				else histdir+"/QEe2_Pa_R%.1f_S%.1f"%(R,S)
	plotfile += "_loglog"*logplot+"."+fs["saveext"]
	if not nosave:
		fig.savefig(plotfile)
		if vb: print me+"Figure saved to",plotfile
		
	return plotfile
示例#17
0
def plot_pressure_file(histfile, nosave, vb):
	"""
	Plot spatial PDF Q(x) and spatially-varying pressure P(x).
	"""
	me = me0+".plot_pressure_file: "
	
	##-------------------------------------------------------------------------
	
	## Dir pars
	assert "_CAR_" in histfile, me+"Functional only for Cartesian geometry."
	Casimir = "_CL_" in histfile or "_ML_" in histfile or "_NL_" in histfile

	##-------------------------------------------------------------------------
	
	## Filename parameters
	a = filename_par(histfile, "_a")
	R = filename_par(histfile, "_R")
	S = filename_par(histfile, "_S")
	try: T = filename_par(histfile, "_T")
	except ValueError: T = -S
			
	## Space
	bins = np.load(os.path.dirname(histfile)+"/BHISBIN"+os.path.basename(histfile)[4:-4]+".npz")
	xbins = bins["xbins"]
	x = 0.5*(xbins[1:]+xbins[:-1])
		
	## Wall indices
	Rind, Sind, Tind = np.abs(x-R).argmin(), np.abs(x-S).argmin(), np.abs(x-T).argmin()
	STind = (Sind+Tind)/2
	
	## Adjust indices for pressure calculation
	if "_DC_" in histfile:
		STind = 0
	elif "_DL_" in histfile:
		STind = 0
	elif "_NL_" in histfile:
		STind = Sind
		Sind = Rind
		Tind = x.size-Rind
		
	##-------------------------------------------------------------------------
	
	## Histogram
	H = np.load(histfile)
	## Spatial density
	Qx = H.sum(axis=2).sum(axis=1) / (H.sum()*(x[1]-x[0]))
	
	##-------------------------------------------------------------------------
	
	## Choose force
	if   "_DC_" in histfile:	fx = force_dcon([x,0],R,S)[0]
	elif "_DL_" in histfile:	fx = force_dlin([x,0],R[i],S[i])[0]
	elif "_CL_" in histfile:	fx = force_clin([x,0],R,S,T)[0]
	elif "_ML_" in histfile:	fx = force_mlin([x,0],R,S,T)[0]
	elif "_NL_" in histfile:	fx = force_nlin([x,0],R,S)[0]
	else: raise IOError, me+"Force not recognised."
		
	## Calculate integral pressure
	PR = -sp.integrate.cumtrapz(fx[Rind:]*Qx[Rind:], x[Rind:], initial=0.0)
	PS = -sp.integrate.cumtrapz(fx[STind:Sind+1]*Qx[STind:Sind+1], x[STind:Sind+1], initial=0.0); PS -= PS[-1]
	if Casimir:
		PT = -sp.integrate.cumtrapz(fx[Tind:STind+1]*Qx[Tind:STind+1], x[Tind:STind+1], initial=0.0)
	
	if x[0]<0:
		R2ind = x.size-Rind
		PR2 = -sp.integrate.cumtrapz(fx[:R2ind]*Qx[:R2ind], x[:R2ind], initial=0.0); PR2 -= PR2[-1]
			
	##-------------------------------------------------------------------------
	
	## Potential and WN
	U = -sp.integrate.cumtrapz(fx, x, initial=0.0); U -= U.min()
	Qx_WN = np.exp(-U) / np.trapz(np.exp(-U), x)
	
	## WN pressure
	PR_WN = -sp.integrate.cumtrapz(fx[Rind:]*Qx_WN[Rind:], x[Rind:], initial=0.0)
	PS_WN = -sp.integrate.cumtrapz(fx[STind:Sind+1]*Qx_WN[STind:Sind+1], x[STind:Sind+1], initial=0.0); PS_WN -= PS_WN[-1]
	if Casimir:
		PT_WN = -sp.integrate.cumtrapz(fx[Tind:STind+1]*Qx_WN[Tind:STind+1], x[Tind:STind+1], initial=0.0)
	
	##-------------------------------------------------------------------------
	
	## PLOTTING
	
	fig, axs = plt.subplots(2,1, sharex=True, figsize=fs["figsize"])
	
	if   "_DL_" in histfile:	legloc = "upper right"
	elif "_CL_" in histfile:	legloc = "upper right"
	elif "_ML_" in histfile:	legloc = "upper left"
	elif "_NL_" in histfile:	legloc = "lower left"
	else:						legloc = "best"
	
	## Plot PDF
	ax = axs[0]
	lQ = ax.plot(x, Qx, lw=2, label=r"CN")
	ax.plot(x, Qx_WN, lQ[0].get_color()+":", lw=2, label="WN")
	## Potential
	ax.plot(x, U/U.max()*ax.get_ylim()[1], "k--", lw=2, label=r"$U(x)$")
	
	ax.set_xlim((x[0],x[-1]))	
	ax.set_ylim(bottom=0.0)	
	ax.set_ylabel(r"$Q(x)$", fontsize=fs["fsa"])
	ax.grid()
	ax.legend(loc=legloc, fontsize=fs["fsl"]).get_frame().set_alpha(0.5)
	
	## Plot pressure
	ax = axs[1]
	lPR = ax.plot(x[Rind:], PR, lw=2, label=r"$P_R$")
	lPS = ax.plot(x[STind:Sind+1], PS, lw=2, label=r"$P_S$")
	if Casimir:
		lPT = ax.plot(x[Tind:STind+1], PT, lw=2, label=r"$P_T$")
	if x[0]<0:
		ax.plot(x[:R2ind], PR2, lPR[0].get_color()+"-", lw=2)
	## WN result
	ax.plot(x[Rind:], PR_WN, lPR[0].get_color()+":", lw=2)
	ax.plot(x[STind:Sind+1], PS_WN, lPS[0].get_color()+":", lw=2)
	if Casimir:
		ax.plot(x[Tind:STind+1], PT_WN, lPT[0].get_color()+":", lw=2)
	if x[0]<0:
		ax.plot(x[:R2ind], PR_WN[::-1], lPR[0].get_color()+":", lw=2)
	## Potential
	ax.plot(x, U/U.max()*ax.get_ylim()[1], "k--", lw=2)#, label=r"$U(x)$")
	
	ax.set_xlim((x[0],x[-1]))	
	ax.set_ylim(bottom=0.0)	
	ax.set_xlabel(r"$x$", fontsize=fs["fsa"])
	ax.set_ylabel(r"$P(x)$", fontsize=fs["fsa"])
	ax.grid()
	if Casimir:
		ax.legend(loc=legloc, fontsize=fs["fsl"]).get_frame().set_alpha(0.5)

	##-------------------------------------------------------------------------
	
	fig.tight_layout()
	fig.subplots_adjust(top=0.90)
	title = r"Spatial PDF and Pressure. $\alpha=%.1f, R=%.1f, S=%.1f, T=%.1f$"%(a,R,S,T) if T>=0.0\
			else r"Spatial PDF and Pressure. $\alpha=%.1f, R=%.1f, S=%.1f$"%(a,R,S)
	fig.suptitle(title, fontsize=fs["fst"])
	
	if not nosave:
		plotfile = os.path.dirname(histfile)+"/PDFP"+os.path.basename(histfile)[4:-4]+".jpg"
		fig.savefig(plotfile)
		if vb:	print me+"Figure saved to",plotfile
		
	return
示例#18
0
def plot_pressure_file(histfile, nosave, vb):
    """
	Plot spatial PDF Q(x) and spatially-varying pressure P(x).
	"""
    me = me0 + ".plot_pressure_file: "

    ##-------------------------------------------------------------------------

    ## Dir pars
    assert "_CAR_" in histfile, me + "Functional only for Cartesian geometry."
    Casimir = "_CL_" in histfile or "_ML_" in histfile or "_NL_" in histfile

    ##-------------------------------------------------------------------------

    ## Filename parameters
    a = filename_par(histfile, "_a")
    R = filename_par(histfile, "_R")
    S = filename_par(histfile, "_S")
    try:
        T = filename_par(histfile, "_T")
    except ValueError:
        T = -S

    ## Space
    bins = np.load(
        os.path.dirname(histfile) + "/BHISBIN" +
        os.path.basename(histfile)[4:-4] + ".npz")
    xbins = bins["xbins"]
    x = 0.5 * (xbins[1:] + xbins[:-1])

    ## Wall indices
    Rind, Sind, Tind = np.abs(x - R).argmin(), np.abs(x - S).argmin(), np.abs(
        x - T).argmin()
    STind = (Sind + Tind) / 2

    ## Adjust indices for pressure calculation
    if "_DC_" in histfile:
        STind = 0
    elif "_DL_" in histfile:
        STind = 0
    elif "_NL_" in histfile:
        STind = Sind
        Sind = Rind
        Tind = x.size - Rind

    ##-------------------------------------------------------------------------

    ## Histogram
    H = np.load(histfile)
    ## Spatial density
    Qx = H.sum(axis=2).sum(axis=1) / (H.sum() * (x[1] - x[0]))

    ##-------------------------------------------------------------------------

    ## Choose force
    if "_DC_" in histfile: fx = force_dcon([x, 0], R, S)[0]
    elif "_DL_" in histfile: fx = force_dlin([x, 0], R[i], S[i])[0]
    elif "_CL_" in histfile: fx = force_clin([x, 0], R, S, T)[0]
    elif "_ML_" in histfile: fx = force_mlin([x, 0], R, S, T)[0]
    elif "_NL_" in histfile: fx = force_nlin([x, 0], R, S)[0]
    else: raise IOError, me + "Force not recognised."

    ## Calculate integral pressure
    PR = -sp.integrate.cumtrapz(fx[Rind:] * Qx[Rind:], x[Rind:], initial=0.0)
    PS = -sp.integrate.cumtrapz(fx[STind:Sind + 1] * Qx[STind:Sind + 1],
                                x[STind:Sind + 1],
                                initial=0.0)
    PS -= PS[-1]
    if Casimir:
        PT = -sp.integrate.cumtrapz(fx[Tind:STind + 1] * Qx[Tind:STind + 1],
                                    x[Tind:STind + 1],
                                    initial=0.0)

    if x[0] < 0:
        R2ind = x.size - Rind
        PR2 = -sp.integrate.cumtrapz(
            fx[:R2ind] * Qx[:R2ind], x[:R2ind], initial=0.0)
        PR2 -= PR2[-1]

    ##-------------------------------------------------------------------------

    ## Potential and WN
    U = -sp.integrate.cumtrapz(fx, x, initial=0.0)
    U -= U.min()
    Qx_WN = np.exp(-U) / np.trapz(np.exp(-U), x)

    ## WN pressure
    PR_WN = -sp.integrate.cumtrapz(
        fx[Rind:] * Qx_WN[Rind:], x[Rind:], initial=0.0)
    PS_WN = -sp.integrate.cumtrapz(fx[STind:Sind + 1] * Qx_WN[STind:Sind + 1],
                                   x[STind:Sind + 1],
                                   initial=0.0)
    PS_WN -= PS_WN[-1]
    if Casimir:
        PT_WN = -sp.integrate.cumtrapz(
            fx[Tind:STind + 1] * Qx_WN[Tind:STind + 1],
            x[Tind:STind + 1],
            initial=0.0)

    ##-------------------------------------------------------------------------

    ## PLOTTING

    fig, axs = plt.subplots(2, 1, sharex=True, figsize=fs["figsize"])

    if "_DL_" in histfile: legloc = "upper right"
    elif "_CL_" in histfile: legloc = "upper right"
    elif "_ML_" in histfile: legloc = "upper left"
    elif "_NL_" in histfile: legloc = "lower left"
    else: legloc = "best"

    ## Plot PDF
    ax = axs[0]
    lQ = ax.plot(x, Qx, lw=2, label=r"CN")
    ax.plot(x, Qx_WN, lQ[0].get_color() + ":", lw=2, label="WN")
    ## Potential
    ax.plot(x, U / U.max() * ax.get_ylim()[1], "k--", lw=2, label=r"$U(x)$")

    ax.set_xlim((x[0], x[-1]))
    ax.set_ylim(bottom=0.0)
    ax.set_ylabel(r"$Q(x)$", fontsize=fs["fsa"])
    ax.grid()
    ax.legend(loc=legloc, fontsize=fs["fsl"]).get_frame().set_alpha(0.5)

    ## Plot pressure
    ax = axs[1]
    lPR = ax.plot(x[Rind:], PR, lw=2, label=r"$P_R$")
    lPS = ax.plot(x[STind:Sind + 1], PS, lw=2, label=r"$P_S$")
    if Casimir:
        lPT = ax.plot(x[Tind:STind + 1], PT, lw=2, label=r"$P_T$")
    if x[0] < 0:
        ax.plot(x[:R2ind], PR2, lPR[0].get_color() + "-", lw=2)
    ## WN result
    ax.plot(x[Rind:], PR_WN, lPR[0].get_color() + ":", lw=2)
    ax.plot(x[STind:Sind + 1], PS_WN, lPS[0].get_color() + ":", lw=2)
    if Casimir:
        ax.plot(x[Tind:STind + 1], PT_WN, lPT[0].get_color() + ":", lw=2)
    if x[0] < 0:
        ax.plot(x[:R2ind], PR_WN[::-1], lPR[0].get_color() + ":", lw=2)
    ## Potential
    ax.plot(x, U / U.max() * ax.get_ylim()[1], "k--",
            lw=2)  #, label=r"$U(x)$")

    ax.set_xlim((x[0], x[-1]))
    ax.set_ylim(bottom=0.0)
    ax.set_xlabel(r"$x$", fontsize=fs["fsa"])
    ax.set_ylabel(r"$P(x)$", fontsize=fs["fsa"])
    ax.grid()
    if Casimir:
        ax.legend(loc=legloc, fontsize=fs["fsl"]).get_frame().set_alpha(0.5)

    ##-------------------------------------------------------------------------

    fig.tight_layout()
    fig.subplots_adjust(top=0.90)
    title = r"Spatial PDF and Pressure. $\alpha=%.1f, R=%.1f, S=%.1f, T=%.1f$"%(a,R,S,T) if T>=0.0\
      else r"Spatial PDF and Pressure. $\alpha=%.1f, R=%.1f, S=%.1f$"%(a,R,S)
    fig.suptitle(title, fontsize=fs["fst"])

    if not nosave:
        plotfile = os.path.dirname(histfile) + "/PDFP" + os.path.basename(
            histfile)[4:-4] + ".jpg"
        fig.savefig(plotfile)
        if vb: print me + "Figure saved to", plotfile

    return