Example #1
0
def update_density(x, rho, particles, bins, bins_index):
    ''' function for density summation '''
    ng_l = particles[0].ng[0]
    ng_r = particles[0].ng[1]

    ng_particles = len(particles)
    n_particles = ng_particles - (ng_l + ng_r)

    one = np.ones(ng_particles)
    m_j = particles[0].m
    r_j = np.copy(x)
    h_ij = one * particles[0].h
    rho_a = np.zeros(n_particles)
    W_ij = np.zeros(ng_particles)

    for i in range(ng_l, n_particles + ng_l):
        r_i = x[i]
        r_ij = x[i] - r_j

        bin_min = bins[bins_index[i] - 1][0]
        bin_max = bins[bins_index[i] + 1][-1]

        W_ij[bin_min:bin_max] = interp.cubic_spline(r_ij[bin_min:bin_max],
                                                    h_ij[bin_min:bin_max])
        rho_a[i - ng_l] = np.sum(m_j * W_ij)
    return rho_a
def update_density(x, rho, particles, bins, bins_index):
	''' function for density summation '''
	ng_l = particles[0].ng[0]
	ng_r = particles[0].ng[1]
	
	ng_particles = len(particles)
	n_particles = ng_particles - (ng_l + ng_r)
	
	one = np.ones(ng_particles)
	m_j = particles[0].m
	r_j = np.copy(x)
	h_ij = one*particles[0].h
	rho_a = np.zeros(n_particles)
	W_ij = np.zeros(ng_particles)

	for i in range(ng_l, n_particles + ng_l):
			r_i = x[i]
			r_ij = x[i] - r_j

			bin_min = bins[bins_index[i]-1][0]
			bin_max = bins[bins_index[i]+1][-1]

			W_ij[bin_min:bin_max] = interp.cubic_spline(r_ij[bin_min:bin_max], h_ij[bin_min:bin_max])
			rho_a[i - ng_l] = np.sum(m_j*W_ij)
	return rho_a
Example #3
0
def update_density(x, rho, particles):
    ''' function for density summation '''
    ng_l = particles[0].ng[0]
    ng_r = particles[0].ng[1]

    ng_particles = len(particles)
    n_particles = ng_particles - (ng_l + ng_r)

    one = np.ones(ng_particles)
    m_j = particles[0].m
    r_j = np.copy(x)
    h_ij = one * particles[0].h
    rho_a = np.zeros(n_particles)
    for i in range(ng_l, n_particles + ng_l):
        r_i = x[i]
        r_ij = x[i] - r_j
        W_ij = interp.cubic_spline(r_ij, h_ij)
        rho_a[i - ng_l] = np.sum(m_j * W_ij)
    return rho_a
def update_density(x, rho, particles):
	''' function for density summation '''
	ng_l = particles[0].ng[0]
	ng_r = particles[0].ng[1]
	
	ng_particles = len(particles)
	n_particles = ng_particles - (ng_l + ng_r)
	
	one = np.ones(ng_particles)
	m_j = particles[0].m
	r_j = np.copy(x)
	h_ij = one*particles[0].h
	rho_a = np.zeros(n_particles)
	for i in range(ng_l, n_particles + ng_l):
			r_i = x[i]
			r_ij = x[i] - r_j
			W_ij = interp.cubic_spline(r_ij, h_ij)
			rho_a[i - ng_l] = np.sum(m_j*W_ij)
	return rho_a
Example #5
0
def euler_rhs(x, rho, v, p, particles, bins, bins_index):
    ''' computes the acceleration terms in the Euler Gas Dynamics
		equations
	'''

    ng_l = particles[0].ng[0]
    ng_r = particles[0].ng[1]

    ng_particles = len(particles)
    n_particles = ng_particles - (ng_l + ng_r)

    rho_a = np.zeros(n_particles)
    v_a = np.zeros(n_particles)
    ener_a = np.zeros(n_particles)
    x_sph = np.zeros(n_particles)

    one = np.ones(ng_particles)

    m_i = particles[0].m
    m_j = m_i

    r_j = np.copy(x)
    h_ij = particles[0].h * one

    v_j = np.copy(v)
    c_j = sound_speed(rho, p)

    rho_j = np.copy(rho)
    p_j = np.copy(p)

    W_ij = np.zeros(ng_particles)
    W_ij_prime = np.zeros(ng_particles)

    for i in range(ng_l, ng_l + n_particles):
        r_i = x[i]
        r_ij = r_i - r_j

        bin_min = bins[bins_index[i] - 1][0]
        bin_max = bins[bins_index[i] + 1][-1]

        W_ij[bin_min:bin_max] = interp.cubic_spline(r_ij[bin_min:bin_max],
                                                    h_ij[bin_min:bin_max])
        W_ij_prime[bin_min:bin_max] = interp.cubic_spline_kernel_derivative(
            r_ij[bin_min:bin_max], h_ij[bin_min:bin_max])

        v_i = v[i] * one
        v_ij = v_i - v_j

        c_i = c_j[i] * one
        c_ij = (c_i + c_j) / 2

        rho_i = rho[i] * one
        rho_ij = (rho_i + rho_j) / 2

        pi_ij = get_viscosity(rho_ij, c_ij, r_ij, v_ij, h_ij)

        p_i = p[i] * one

        multiplier = (p_i / (rho_i * rho_i) + p_j / (rho_j * rho_j) + pi_ij)
        multiplier_1 = (p_i / (rho_i * rho_i) + p_j / (rho_j * rho_j))

        rho_a[i - ng_l] = np.sum(m_j * W_ij)

        # multiple v_a formulations
        v_a[i - ng_l] = -np.sum(m_j * multiplier * W_ij_prime)
        # v_a[i - ng_l] =  -np.sum(m_j * multiplier_1 * W_ij_prime) - 0.5*np.sum(m_j * pi_ij * W_ij_prime)

        # multiple ener_a formulations
        ener_a[i - ng_l] = 0.5 * np.sum(m_j * multiplier * v_ij * W_ij_prime)
        # ener_a[i - ng_l] = np.sum(m_j* (p_i/(rho_i*rho_i)) * v_ij * W_ij_prime) + 0.5*np.sum(m_j * pi_ij * v_ij * W_ij_prime)
        # ener_a[i - ng_l] = np.sum(m_j* multiplier_1* v_ij * W_ij_prime) + 0.5*np.sum(m_j* pi_ij * v_ij * W_ij_prime)

        # multiple x_sph formulations
        x_sph[i - ng_l] = 0.5 * np.sum(m_j * (-v_ij) * W_ij / rho_ij)
        # x_sph[i - ng_l] = np.sum(m_j * v_j * W_ij / rho_j)

    return x_sph, rho_a, v_a, ener_a
def euler_rhs(x, rho, v, p, particles, bins, bins_index):
	''' computes the acceleration terms in the Euler Gas Dynamics
		equations
	'''

		
	ng_l = particles[0].ng[0]
	ng_r = particles[0].ng[1]

	ng_particles = len(particles)
	n_particles = ng_particles - (ng_l+ng_r)
	
	
	rho_a = np.zeros(n_particles)
	v_a  = np.zeros(n_particles)
	ener_a = np.zeros(n_particles)
	x_sph = np.zeros(n_particles)

	one = np.ones(ng_particles)

	m_i = particles[0].m
	m_j = m_i
	
	r_j = np.copy(x)
	h_ij = particles[0].h*one
	
	v_j = np.copy(v)
	c_j = sound_speed(rho, p)
	
	rho_j = np.copy(rho)
	p_j = np.copy(p)

	W_ij = np.zeros(ng_particles)
	W_ij_prime = np.zeros(ng_particles)
	
	for i in range(ng_l, ng_l + n_particles):
		r_i  = x[i]
		r_ij = r_i - r_j


		bin_min = bins[bins_index[i]-1][0]
		bin_max = bins[bins_index[i]+1][-1]

		W_ij[bin_min:bin_max] = interp.cubic_spline(r_ij[bin_min:bin_max], h_ij[bin_min:bin_max])
		W_ij_prime[bin_min:bin_max] = interp.cubic_spline_kernel_derivative(r_ij[bin_min:bin_max], h_ij[bin_min:bin_max])

		v_i = v[i]*one
		v_ij = v_i - v_j

		c_i = c_j[i]*one
		c_ij = (c_i+c_j)/2
		
		rho_i = rho[i]*one
		rho_ij = (rho_i+rho_j)/2
		
		pi_ij = get_viscosity(rho_ij, c_ij, r_ij, v_ij, h_ij)

		p_i = p[i]*one
		
		multiplier = (p_i/(rho_i*rho_i) + p_j/(rho_j*rho_j) + pi_ij)
		multiplier_1 = (p_i/(rho_i*rho_i) + p_j/(rho_j*rho_j))

		rho_a[i - ng_l] = np.sum(m_j * W_ij)
		
		# multiple v_a formulations
		v_a[i - ng_l] =  -np.sum(m_j * multiplier * W_ij_prime)
		# v_a[i - ng_l] =  -np.sum(m_j * multiplier_1 * W_ij_prime) - 0.5*np.sum(m_j * pi_ij * W_ij_prime)
		
		# multiple ener_a formulations
		ener_a[i - ng_l] = 0.5 * np.sum(m_j * multiplier * v_ij * W_ij_prime)
		# ener_a[i - ng_l] = np.sum(m_j* (p_i/(rho_i*rho_i)) * v_ij * W_ij_prime) + 0.5*np.sum(m_j * pi_ij * v_ij * W_ij_prime)
		# ener_a[i - ng_l] = np.sum(m_j* multiplier_1* v_ij * W_ij_prime) + 0.5*np.sum(m_j* pi_ij * v_ij * W_ij_prime)
		
		# multiple x_sph formulations
		x_sph[i - ng_l] = 0.5 * np.sum(m_j * (-v_ij) * W_ij /rho_ij)
		# x_sph[i - ng_l] = np.sum(m_j * v_j * W_ij / rho_j)
	
	return x_sph, rho_a, v_a, ener_a