Attachment ‘BEC.py’

Download

# Author: G.-H. Sam Gweon
# Date: 06-04-2014
#
# This is the code, using which homework solutions for problem 7.1 were
# computed.  This module uses many of my private custom modules (data, gmath,
# reCreateable, util) and so this python module will not be useable right
# away on a random computer.  However, this code should give a good sense of
# how things were calculated.

from data import DataXY
from gmath import brent
from Numeric import exp
from reCreateable import asDefinedReCreateable
from scipy import infty
from scipy.integrate import quad
from scipy.special import gamma
from util import toArray

def _fugacity (nl3inv, N = 1.e5): # <<<
	assert N >= 100
	assert nl3inv >= 0
	gs_val = 1 / (1 + 1. / N)
	if nl3inv == 0:
		return gs_val
	# brent is a zero finding algorithm.
	# TODO: The tolerance (xtol) for brent might need tweaking if higher
	#       precision is required.  This code is OK up to N ~ 1e9.
	return brent (lambda x, nl3inv = nl3inv, N = N:
			1. - g (x, m = 1.5, dxy = False) * nl3inv - x / N / (1. - x),
			0, gs_val)
# >>>
def _g (z, m = 1.5): # <<<
	if z == 0:
		return 0.0
	# TODO: The tolerance (epsabs, epsrel) for quad might need tweaking when
	#       higher precision is required.  This code is OK up to N ~ 1e9.
	return quad (lambda x, z = z, m = m: x ** (m - 1.) / (exp (x) / z - 1.)
			/ gamma (m), 0,  infty) [0]
# >>>

def BECfrac (nl3inv, N = 1.e5, dxy = True): # <<<
	"""
	This returns the condensate fraction n(0)/N.
	"""
	dargs = locals ().copy () if dxy else None
	z = toArray (fugacity (nl3inv, N = N, dxy = False), 'd')
	y = z / (1. - z) / N
	if type (nl3inv) in (int, float):
		return y
	else:
		return asDefinedReCreateable (DataXY (nl3inv, y,
			name = 'BECfrac (N=%g)' % N), None, BECfrac, dargs) if dxy else y
# >>>
def fugacity (nl3inv, N = 1.e5, dxy = True): # <<<
	dargs = locals ().copy () if dxy else None
	func = _fugacity
	if type (nl3inv) in (int, float):
		return func (nl3inv, N = N)
	else:
		y = [func (nl3invval, N = N) for nl3invval in nl3inv]
		return asDefinedReCreateable (DataXY (nl3inv, y, name =
			'fugacity (N=%g)' % N), None, fugacity, dargs) if dxy else y
# >>>
def g (z, m = 1.5, dxy = True): # <<<
	"""
	The "g function" for the Bose gas, which is well-defined for any
	0 <= z < 1 for any value of m, but diverges for z = 1 and m <= 1.
	"""
	dargs = locals ().copy () if dxy else None
	func = _g
	if type (z) in (int, float):
		return func (z, m = m)
	else:
		y = [func (zval, m = m) for zval in z]
		return asDefinedReCreateable (DataXY (z, y,
			name = 'g_{%g} function' % m), None, g, dargs) if dxy else y
# >>>

Attached Files

  • <<la(BEC-hint.py)>> (7:56AM, Jun 08, 2014, 1.9 KB) [get | view]
  • <<la(BEC.py)>> (7:56AM, Jun 08, 2014, 2.5 KB) [get | view]
  • <<la(H01-Thermo.pdf)>> (12:51PM, Apr 03, 2014, 262.0 KB) [get | view]
  • <<la(H02-Probability.pdf)>> (2:31PM, Apr 11, 2014, 157.3 KB) [get | view]
  • <<la(H03-Probability--Irreversibility.pdf)>> (11:40AM, Apr 22, 2014, 208.1 KB) [get | view]
  • <<la(H04-Ensembles-Semi-Classical.pdf)>> (10:38AM, Apr 25, 2014, 329.8 KB) [get | view]
  • <<la(H05-Ensembles-and-Quantum-SM.pdf)>> (7:26AM, May 14, 2014, 215.1 KB) [get | view]
  • <<la(H06-Fermions.pdf)>> (9:56AM, May 15, 2014, 178.6 KB) [get | view]
  • <<la(H07-BEC-and-Phase-Transitions.pdf)>> (9:25PM, Jun 04, 2014, 228.6 KB) [get | view]
  • <<la(H08-MF-LG-MC-RG.pdf)>> (2:01AM, Jun 05, 2014, 222.9 KB) [get | view]
  • <<la(MC.py)>> (10:44AM, Jun 03, 2014, 11.8 KB) [get | view]
To refer to attachments on a page, use the local macros, lia or la.
  • For instance, <<lia(cool_fig.png,scale=0.3)>> or <<la(cool_paper.pdf,Here is a cool paper!))>> will do, assuming that these files do exist.
In these local macros, you should not include attachment: as part of the attachment name.
  • Alternatively, you can use the longer standard syntax, [[attachment:filename]], as shown above in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
Like to rename an existing attachment file? Use the move link above.

You are not allowed to attach a file to this page.