Re = v*d/nu
    CD = cd_sphere(Re)
    alpha = 3.0*rho_f/(4.0*rho_s*d)*CD
    zout[:] = [z[1], g - alpha*z[1]**2]
    return zout
        
# main program starts here

T = 10  # end of simulation
N = 20  # no of time steps
time = np.linspace(0, T, N+1)

z0=np.zeros(2)
z0[0] = 2.0

ze = euler(f, z0, time)     # compute response with constant CD using Euler's method
ze2 = euler(f2, z0, time)   # compute response with varying CD using Euler's method

zh = heun(f, z0, time)     # compute response with constant CD using Heun's method
zh2 = heun(f2, z0, time)   # compute response with varying CD using Heun's method

k1 = np.sqrt(g*4*rho_s*d/(3*rho_f*CD))
k2 = np.sqrt(3*rho_f*g*CD/(4*rho_s*d))
v_a = k1*np.tanh(k2*time)   # compute response with constant CD using analytical solution

# plotting

legends=[]
line_type=['-',':','.','-.','--']

plot(time, v_a, line_type[0])
    alpha = 3.0 * rho_f / (4.0 * rho_s * d) * CD
    zout[:] = [z[1], g - alpha * z[1]**2]
    return zout


# main program starts here

T = 10  # end of simulation
N = 20  # no of time steps
time = np.linspace(0, T, N + 1)

z0 = np.zeros(2)
z0[0] = 2.0

# compute response with constant CD using Euler's method
ze = euler(f, z0, time)
# compute response with varying CD using Euler's method
ze2 = euler(f2, z0, time)

# compute response with constant CD using Heun's method
zh = heun(f, z0, time)
# compute response with varying CD using Heun's method
zh2 = heun(f2, z0, time)

zrk4 = rk4(f, z0, time)  # compute response with constant CD using RK4
zrk4_2 = rk4(f2, z0, time)  # compute response with varying CD using RK4

k1 = np.sqrt(g * 4 * rho_s * d / (3 * rho_f * CD))
k2 = np.sqrt(3 * rho_f * g * CD / (4 * rho_s * d))
# compute response with constant CD using analytical solution
v_a = k1 * np.tanh(k2 * time)
예제 #3
0
    return gfunc(t)


#### Main program starts here
t = symbols('t')
u = sin(t)
g = diff(u, t)

ufunc = lambdify(t, u,
                 np)  # create python function of the manufactured solution
gfunc = lambdify(t, g, np)  # create python function of the source term g

N = 100
t0, tend = 0, 2 * pi  # domain
time = np.linspace(t0, tend, N)

u_0 = ufunc(t0)  # initial value

uNum = euler(func, u_0, time)
uM = ufunc(time)

#plotting:
plt.figure()
plt.plot(time, uM, 'k')
plt.plot(time, uNum, 'r--')
plt.legend(['Manufactured', 'Numerical'], frameon=False)
plt.xlabel('t')
plt.ylabel('u')
#plt.savefig('../fig-ch1/MMSExample0.png', transparent=True) # transparent=True
plt.show()
예제 #4
0
#### Main program starts here
t = symbols('t')
u = sin(t)
g = diff(u, t)

ufunc = lambdify(t, u, np) # create python function of the manufactured solution
gfunc = lambdify(t, g, np) # create python function of the source term g

N = 100
t0, tend = 0, 2*pi # domain
time = np.linspace(t0, tend, N)

u_0 = ufunc(t0) # initial value

uNum = euler(func, u_0, time)
uM = ufunc(time)

#plotting:
plt.figure()
plt.plot(time, uM, 'k')
plt.plot(time, uNum, 'r--')
plt.legend(['Manufactured', 'Numerical'], frameon=False)
plt.xlabel('t')
plt.ylabel('u')
#plt.savefig('../fig-ch1/MMSExample0.png', transparent=True) # transparent=True
plt.show()