Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scipy as sp
- import scipy.integrate
- import numpy as np
- import matplotlib.pyplot as plt
- import functools
- import math
- def sphere_volume(r):
- return 4*math.pi*r**3/3
- def full_pressure(v, t, p0, v0, t0):
- return p0*v0*t/(t0*v)
- def pressure_fn(p0, v0, t0, t):
- return functools.partial(full_pressure, t=t, p0=p0, v0=v0, t0=t0)
- class Bubble(object):
- def __init__(self, s=0.0728, p0=101325., t0=20, r0=5, dr0=0.0, pi=lambda t:101325., ro=998.2071, nu=1.004, t=np.linspace(0,1,100)):
- """
- Creates a mathy object with method <method_name> to compute
- the Rayleigh-Plesset equation.
- The default instance (without arguments) is suitable for an air
- bubble in water at STP.
- """
- self.r0 = r0
- self.dr0 = dr0
- self.pb = pressure_fn(t0, p0, sphere_volume(r0), t0)
- self.pi = pi
- self.s = s
- self.ro = ro
- self.nu = nu
- self.t = t
- self.calculate()
- def calculate(self):
- self.R = sp.integrate.odeint(self.dR, [self.r0, self.dr0], self.t)
- def dR(self, r, t):
- """derivative function for R"""
- #r[0] = R, r[1] = dR/dt, return [dR/dt=r[1], d2r/dt2=...]
- dR = r[1]
- #the math is messy and looks wrong so i'm splitting it up
- #EDIT: I think it was right. I was just assuming if pinf=pb dr=0
- term = [(self.pb(r[0])-self.pi(t))/(self.ro*r[0]),
- 3*r[1]**2/(r[0]*2),
- 4*self.nu*r[1]/r[0],
- 2*self.s/(self.ro*r[0])]
- ddR = term[0]+term[1]+term[2]+term[3]
- return np.array([dR, ddR])
- def plot(self):
- plt.subplot(2,1,1)
- plt.plot(self.t, self.R[:,0])
- plt.title('R(t)')
- plt.subplot(2,1,2)
- plt.plot(self.t, self.R[:,1])
- plt.title('''dR(t)/dt''')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment