コード例 #1
0
ファイル: test_terminal.py プロジェクト: imranal/inf5620
def test_solver():
    """ 
	In this test we compare the velocities from the simulation for the last 	
	time step with the terminal velocity.
	"""

    # This is incredibly tedious : (every constant....)
    v0 = -10  # start velocity (already falling)
    T = 20  # set a relatively large simulation
    dt = 0.01
    C_D = 0.45  # Sphere
    rho = 1.2  # density of air
    rho_b = 6.8  # density of body -> for V = 4.716m^3; m = 6.8*4.716 = 32.07 kg
    A = 3.40  # Area of the sphere         pi*r^2
    V = 4.716  # Volume of the sphere   (4/3)*pi*r^3
    d = 2.08  # Diameter of the sphere      2*r
    mu = 1.8 * 10**-5  # dynamic viscosity

    g = 9.81  # Gravitational constant

    a_s = 3 * pi * rho * d * mu / (
        rho_b * V)  # Constant to be used for the Stokes model
    a_q = 0.5 * C_D * rho * A / (
        rho_b * V)  # Constant to be used for the quadratic model
    b = g * (-1 + rho / rho_b
             )  # A common constant for both Stokes and quad. model
    rdm = rho * d / mu  # A constant related to the Reynolds number

    t, v = vm.solver(T, dt, a_s, a_q, b, v0, rdm)

    v_terminal = -sqrt(fabs(b) / a_q)
    if v[-1] > 0:  # can be risky to base the terminal velocity on the simulation
        v_terminal = -1 * v_terminal
    nt.assert_almost_equal(v[-1], v_terminal, delta=1E-7)
コード例 #2
0
def main():
    v0 = 0  # start velocity
    T = 23  # here this time is chosen for falling 5000 m when only gravity is applied
    dt = 0.01
    C_D = 1.2  # Coeffi
    rho = 0.79  # density of air (assumed constant)
    rho_b = 1003.0  # kgm^3;
    m = 80  # Mass of the jumper and parachute in kg
    R = 0.5
    A = pi * R**2  # Area of the sphere         pi*r^2
    V = m / rho_b  # Volume of the falling object
    d = 2.08  # Diameter of the sphere      2*r
    mu = 1.8 * 10**-5  # dynamic viscosity

    g = 9.81  # Gravitational constant

    a_s = 3 * pi * rho * d * mu / (
        rho_b * V)  # Constant to be used for the Stokes model
    a_q = 0.5 * C_D * rho * A / (
        rho_b * V)  # Constant to be used for the quadratic model
    b = g * (-1 + rho / rho_b
             )  # A common constant for both Stokes and quad. model
    rdm = rho * d / mu  # A constant related to the Reynolds number

    t, v = vm.solver(T, dt, a_s, a_q, b, v0, rdm)
    plot(t, v, xlabel='t', ylabel='v', title='Parachute Jumper')
    raw_input('Press any key.')
コード例 #3
0
ファイル: test_terminal.py プロジェクト: imranal/INF5620
def test_solver():
	""" 
	In this test we compare the velocities from the simulation for the last 	
	time step with the terminal velocity.
	"""

	# This is incredibly tedious : (every constant....)
	v0 = -10 # start velocity (already falling)
	T = 20 # set a relatively large simulation
	dt = 0.01
	C_D = 0.45  # Sphere
	rho = 1.2   # density of air
	rho_b = 6.8 # density of body -> for V = 4.716m^3; m = 6.8*4.716 = 32.07 kg 
	A = 3.40    # Area of the sphere         pi*r^2
	V = 4.716   # Volume of the sphere   (4/3)*pi*r^3
	d = 2.08    # Diameter of the sphere      2*r
	mu = 1.8*10**-5	# dynamic viscosity
	
	g = 9.81 # Gravitational constant
	
	a_s = 3*pi*rho*d*mu/(rho_b*V) # Constant to be used for the Stokes model
	a_q = 0.5*C_D*rho*A/(rho_b*V) # Constant to be used for the quadratic model
	b = g*(-1 + rho/rho_b) # A common constant for both Stokes and quad. model
	rdm = rho*d/mu         # A constant related to the Reynolds number 
	
	t,v = vm.solver(T,dt,a_s,a_q,b,v0,rdm)

	v_terminal = -sqrt(fabs(b)/a_q)
	if v[-1]>0: # can be risky to base the terminal velocity on the simulation
		v_terminal = -1*v_terminal 
	nt.assert_almost_equal(v[-1],v_terminal,delta=1E-7)
コード例 #4
0
ファイル: parachute_jumper1.py プロジェクト: imranal/INF5620
def main():
	v0 = 0 # start velocity
	T = 23 # here this time is chosen for falling 5000 m when only gravity is applied
	dt = 0.01
	C_D = 1.2  # Coeffi
	rho = 0.79   # density of air (assumed constant)
	rho_b = 1003.0 # kgm^3; 
	m = 80 # Mass of the jumper and parachute in kg
	R = 0.5 	
	A = pi*R**2    # Area of the sphere         pi*r^2
	V = m/rho_b   # Volume of the falling object
	d = 2.08    # Diameter of the sphere      2*r
	mu = 1.8*10**-5	# dynamic viscosity


	g = 9.81 # Gravitational constant
	
	a_s = 3*pi*rho*d*mu/(rho_b*V) # Constant to be used for the Stokes model
	a_q = 0.5*C_D*rho*A/(rho_b*V) # Constant to be used for the quadratic model
	b   = g*(-1 + rho/rho_b)      # A common constant for both Stokes and quad. model
	rdm = rho*d/mu                # A constant related to the Reynolds number 
	
	t,v = vm.solver(T,dt,a_s,a_q,b,v0,rdm)
	plot(t,v,xlabel = 't',ylabel = 'v',title = 'Parachute Jumper')
	raw_input('Press any key.')
コード例 #5
0
def calculate_forces(v0, mu, density_m, CD, diameter_b, \
                         area_b, volume_b, density_b, \
                         dt, T):
    """
    Calculate the gravity force, buoyancy force and
    the drag force of a falling body in a viscous 
    fluid.
    """
    
    #     Gravitational const. m/s^2
    g = 9.81         
    #     Proportionality constant for
    #     Reynolds number
    Re_const = diameter_b*density_m/mu
    
    a_s = 3*math.pi*diameter_b*mu/(density_b*volume_b)
    a_q = 0.5*CD*density_m*area_b/(density_b*volume_b)
    b = g*(density_m/density_b - 1.0)
    
    #     Numerical solution gives velocity as 
    #     a function of time.
    v, t = vm.solver(v0, a_s, a_q, b, Re_const, T, dt) 

    #     Initialize vectors
    Fg = zeros(len(v))
    Fb = zeros(len(v))
    Fd = zeros(len(v))

    #     Loop over time steps
    for n in range(0, len(v)):
        #     Evaluate Reynolds number
        Re = Re_const*v[n]   
        
        #     Gravity force
        Fg[n] = -density_b*volume_b*g
        #     Bouyancy force
        Fb[n] = density_m*g*volume_b
        
        #     Drag force
        if abs(Re) < 1:
            #     If Re < 1, use Stokes' drag force 
            Fd[n] = -3.0*math.pi*diameter_b*mu*v[n]
        else:
            #     If Re >= 1, use the quadratic
            #     drag force
            Fd[n] = -0.5*CD*density_m*area_b*abs(v[n])*v[n]

    
    return Fg, Fb, Fd, t        
コード例 #6
0
def calculate_forces(v0, mu, density_m, CD, diameter_b, \
                         area_b, volume_b, density_b, \
                         dt, T):
    """
    Calculate the gravity force, buoyancy force and
    the drag force of a falling body in a viscous 
    fluid.
    """

    #     Gravitational const. m/s^2
    g = 9.81
    #     Proportionality constant for
    #     Reynolds number
    Re_const = diameter_b * density_m / mu

    a_s = 3 * math.pi * diameter_b * mu / (density_b * volume_b)
    a_q = 0.5 * CD * density_m * area_b / (density_b * volume_b)
    b = g * (density_m / density_b - 1.0)

    #     Numerical solution gives velocity as
    #     a function of time.
    v, t = vm.solver(v0, a_s, a_q, b, Re_const, T, dt)

    #     Initialize vectors
    Fg = zeros(len(v))
    Fb = zeros(len(v))
    Fd = zeros(len(v))

    #     Loop over time steps
    for n in range(0, len(v)):
        #     Evaluate Reynolds number
        Re = Re_const * v[n]

        #     Gravity force
        Fg[n] = -density_b * volume_b * g
        #     Bouyancy force
        Fb[n] = density_m * g * volume_b

        #     Drag force
        if abs(Re) < 1:
            #     If Re < 1, use Stokes' drag force
            Fd[n] = -3.0 * math.pi * diameter_b * mu * v[n]
        else:
            #     If Re >= 1, use the quadratic
            #     drag force
            Fd[n] = -0.5 * CD * density_m * area_b * abs(v[n]) * v[n]

    return Fg, Fb, Fd, t
コード例 #7
0
ファイル: test_vert_motion.py プロジェクト: gba/INF5620
def test_terminal_velocity_q():
    #
    # In the quadratic drag regime the final
    # velociy should be v = -sqrt(abs(a_q)/b).
    # 
    a_s = 1E-6
    a_q = 0.0044
    b = -9.80
    Re_const = 21944.0
    T = 100.0
    dt = 0.1
    v0 = 0.0
    v, t = vm.solver(v0, a_s, a_q, b, Re_const, T, dt)

    vmax = -np.sqrt(abs(b)/a_q)
    print 'vmax = ', vmax
    diff = abs(vmax - v[len(v)-1])
    nt.assert_almost_equal(diff, 0, delta=1E-12)
コード例 #8
0
ファイル: test_vert_motion.py プロジェクト: gba/INF5620
def test_terminal_velocity_q():
    #
    # In the quadratic drag regime the final
    # velociy should be v = -sqrt(abs(a_q)/b).
    #
    a_s = 1E-6
    a_q = 0.0044
    b = -9.80
    Re_const = 21944.0
    T = 100.0
    dt = 0.1
    v0 = 0.0
    v, t = vm.solver(v0, a_s, a_q, b, Re_const, T, dt)

    vmax = -np.sqrt(abs(b) / a_q)
    print 'vmax = ', vmax
    diff = abs(vmax - v[len(v) - 1])
    nt.assert_almost_equal(diff, 0, delta=1E-12)
コード例 #9
0
ファイル: test_vert_motion.py プロジェクト: gba/INF5620
def test_heavy_slow():
    #
    # Assumption: density of body is very large,
    #            density of medium is very small.
    #            This should give linear velocity
    #            according to v(t) = v0 - g*t.
    #
    g = 9.81
    v0 = 0.0
    #     Solve numerically
    v, t = vm.solver(v0, a_s=0.0, a_q=0.0, b=-g, \
                      Re_const=0.0, T=2.0, dt=0.001)
    
    v_a = np.zeros(len(t))
    #     The analytic velocity
    for n in range(0, len(t)):
        v_a[n] = v0 - g*t[n]
        
    diff = np.abs(v-v_a).max()
    nt.assert_almost_equal(diff, 0, delta=1E-12)
コード例 #10
0
ファイル: test_vert_motion.py プロジェクト: gba/INF5620
def test_heavy_slow():
    #
    # Assumption: density of body is very large,
    #            density of medium is very small.
    #            This should give linear velocity
    #            according to v(t) = v0 - g*t.
    #
    g = 9.81
    v0 = 0.0
    #     Solve numerically
    v, t = vm.solver(v0, a_s=0.0, a_q=0.0, b=-g, \
                      Re_const=0.0, T=2.0, dt=0.001)

    v_a = np.zeros(len(t))
    #     The analytic velocity
    for n in range(0, len(t)):
        v_a[n] = v0 - g * t[n]

    diff = np.abs(v - v_a).max()
    nt.assert_almost_equal(diff, 0, delta=1E-12)
コード例 #11
0
def plotter(v0,T,dt,C_D,rho,rho_b,A,V,d,mu):
	
	g = 9.81 # Gravitational constant
	
	a_s = 3*pi*rho*d*mu/(rho_b*V) # Constant to be used for the Stokes model
	a_q = 0.5*C_D*rho*A/(rho_b*V) # Constant to be used for the quadratic model
	b = g*(-1 + rho/rho_b) # A common constant for both Stokes and quad. model
	rdm = rho*d/mu         # A constant related to the Reynolds number 
	
	t,v = vm.solver(T,dt,a_s,a_q,b,v0,rdm)

	F_b   = rho*g*V*ones(len(v))
	F_g   = -g*rho_b*V*ones(len(v))  

	rdm = rho*d/float(mu) 
	Re = rdm*fabs(v0)
	
	F_d_s = -a_s*v
	F_d_q = -a_q*v*fabs(v) 
	
	# The following code attempts to create a force vector based on the appropriate 
    # Reynolds value :
	
	F_d = zeros(len(v))
	R_e = rdm*fabs(v0)
	for n in range(len(v)) :
		if Re < 1 :
			F_d[n] = F_d_s[n] 
		else :
			F_d[n] = F_d_q[n]
		# Update Re :
		R_e = rdm*fabs(v[n])
	plot(t,F_b,
		 t,F_g,
		 xlabel='t',ylabel='F',
		 legend=('Buouncy Force','Gravity Force'),
		 title='Forces acting on a sphere')
	hold('on')
	plot(t,F_d,legend='Stokes and Quad for spesific Re')
	
	raw_input('Press any key.')
コード例 #12
0
ファイル: test_rho0.py プロジェクト: imranal/INF5620
def test_solver():
	""" 
	In this test we neglect air resistance and buoyancy force.
	To accomplish this we can effectively set the density of air 
	to be zero. As a result we can compare the result from the solver
	with the known physical formula v = v0 - g*t.
	"""
	# This is annoying
	v0 = 0 # starts at rest
	rho = 0 # Neglect the buoyancy force as well as air resistance
	T = 8 # Choose a sufficiently large simulation
	dt = 0.1 # Apparently for smaller time steps the error increases slightly 
	g = -9.81 # Constant of gravity
	a_s = 0 # Constant to be used for the Stokes model
	a_q = 0 # Constant to be used for the quadratic model
	b = g  # Common constant for both Stokes and quadratic
	rdm = 0  # Constant used to assess the Reynolds number

	t,v = vm.solver(T,dt,a_s,a_q,b,v0,rdm)
	v_est = v0 + g*T # v = v0 + g*t
	nt.assert_almost_equal(v[-1],v_est,delta=1E-15)
コード例 #13
0
ファイル: test_rho0.py プロジェクト: imranal/inf5620
def test_solver():
    """ 
	In this test we neglect air resistance and buoyancy force.
	To accomplish this we can effectively set the density of air 
	to be zero. As a result we can compare the result from the solver
	with the known physical formula v = v0 - g*t.
	"""
    # This is annoying
    v0 = 0  # starts at rest
    rho = 0  # Neglect the buoyancy force as well as air resistance
    T = 8  # Choose a sufficiently large simulation
    dt = 0.1  # Apparently for smaller time steps the error increases slightly
    g = -9.81  # Constant of gravity
    a_s = 0  # Constant to be used for the Stokes model
    a_q = 0  # Constant to be used for the quadratic model
    b = g  # Common constant for both Stokes and quadratic
    rdm = 0  # Constant used to assess the Reynolds number

    t, v = vm.solver(T, dt, a_s, a_q, b, v0, rdm)
    v_est = v0 + g * T  # v = v0 + g*t
    nt.assert_almost_equal(v[-1], v_est, delta=1E-15)