示例#1
0
 def test_45_degree_line(self):
     surf = [((1.0, 0.0), (6.0, 5.0))]
     surface = SurfaceGroup()
     surface.add_new_group(surf, (2.0, 0.0))
     particles = dm_p.Particles(100)
     particles.y = np.random.random(100) * 5.0
     particles.x = np.zeros(100, dtype=float)
     particles.v = np.zeros(100, dtype=float)
     particles.u = np.ones(100, dtype=float) * 2.0
     reflector = Specular(surface, particles)
     for index in range(100):
         por = (particles.y[index] + 1.0, particles.y[index])
         reflector.reflect(index, 0, 0, por)
         self.assertAlmostEqual(particles.u[index], 0.0, 6)
         self.assertAlmostEqual(particles.v[index], 2.0, 6)
示例#2
0
 def test_vertical_line(self):
     surf = [((0.0, 0.0), (0.0, 5.0))]
     surface = SurfaceGroup()
     surface.add_new_group(surf, (-0.5, 0.5))
     particles = dm_p.Particles(100)
     particles.y = np.random.random(100) * 5.0
     particles.x = np.ones(100) * 0.5
     particles.v = np.zeros(100, dtype=float)
     particles.u = np.ones(100) * -2.0
     reflector = Specular(surface, particles)
     for index in range(100):
         por = (0.0, particles.y[index])
         reflector.reflect(index, 0, 0, por)
         self.assertTrue(particles.x[index] == 0.0)
         self.assertTrue(particles.v[index] == 0.0)
         self.assertTrue(particles.u[index] == 2.0)
示例#3
0
 def test_horizontal_line_2(self):
     surf = [((0.0, 0.0), (5.0, 0.0))]
     surface = SurfaceGroup()
     surface.add_new_group(surf, (0.0, -0.5))
     particles = dm_p.Particles(100)
     particles.x = np.random.random(100) * 5.0
     particles.x -= 0.5
     particles.y = np.ones(100) * 0.5
     particles.u = np.ones(100) * 2.0
     particles.v = np.ones(100) * -2.0
     reflector = Specular(surface, particles)
     for index in range(100):
         por = (particles.x[index], 0.0)
         reflector.reflect(index, 0, 0, por)
         self.assertTrue(particles.y[index] == 0.0)
         self.assertTrue(particles.u[index] == 2.0)
         self.assertTrue(particles.v[index] == 2.0)
示例#4
0
 def test_box(self):
     surf1 = [((0.0, 0.0), (0.0, 1.0))] 
     surf2 = [((0.0, 1.0), (1.0, 1.0))] 
     surf3 = [((1.0, 1.0), (1.0, 0.0))] 
     surf4 = [((1.0, 0.0), (0.0, 0.0))]
     surface = SurfaceGroup()
     surface.add_new_group(surf1, (-1.0, 0.5))
     surface.add_new_group(surf2, (0.0, 1.5))
     surface.add_new_group(surf3, (1.2, 0.5))
     surface.add_new_group(surf4, (0.0, -0.5))
     particles = dm_p.Particles(100)
     reflector = Specular(surface, particles)
     particles.x[0] = 0.0
     particles.y[0] = 0.26082442984289667
     particles.u[0] = -356.44993069494706
     particles.v[0] = -110.17505903656894
     reflector.__init__(surface, particles)
     por = (0.0, 0.26082442984289667)
     reflector.reflect(0, 0, 0, por)
     self.assertAlmostEqual(particles.u[0], 356.44993069494706, 5)
     self.assertAlmostEqual(particles.v[0], -110.17505903656894, 5)
示例#5
0
def main():

    plate1 = [((0.0, 0.0), (1.0, 0.0))]
    ref_point = (0.5, -0.5)
    surf_temp1 = 300.0

    plate2 = [((0.0, 1.0), (1.0, 1.0))]
    ref_point2 = (0.5, 1.5)
    surf_temp2 = 300.0
    # creating surface
    surf_group = SurfaceGroup()
    surf_group.add_new_group(plate1, ref_point, surf_temp1)
    surf_group.add_new_group(plate2, ref_point2, surf_temp2)

    inlet = [((0.0, 0.0), (0.0, 1.0))]
    outlet = [((1.0, 0.0), (1.0, 1.0))]
    zero_grad = [((0.0, 0.0), (1.0, 0.0)), ((0.0, 1.0), (1.0, 1.0))]
    center = (0.5, 0.5)
    length = 1.0
    width = 1.0
    volume = 1.0
    domain = Domain(volume, inlet, zero_grad, outlet)

    #    ensemble_sample = 10
    time_av_sample = 10000
    dof = 3.0
    mass = 66.3e-27
    viscosity_coeff = 2.117
    viscosity_index = 0.81
    mole_fraction = [0.5, 0.5]
    dia = 4.17e-10
    mach = [3.0, 0.0, 0.0]
    temperature = 300.0
    ref_temperature = 273.0
    number_density = 1.699e20
    gamma = 5.0 / 3.0
    n_particles_in_cell = 8
    ref_point = (0.1, 0.5)
    argon = Molecules(
        dia, viscosity_index, mass, viscosity_coeff, dof, 0, ref_temperature, gamma, volume, number_density
    )
    argon1 = Molecules(
        dia, viscosity_index, mass, viscosity_coeff, dof, 1, ref_temperature, gamma, volume, number_density
    )
    gas = Gas([argon, argon1], mole_fraction, mach, temperature)
    gas.setup()
    #    dl = min(gas.mean_f_path)
    #    dt = min(gas.mean_col_time)
    dt = 1.0e-7
    #    print dt
    #    cell_x, cell_y = np.ceil(length / dl), np.ceil(width / dl)
    cell_x, cell_y = 200, 200
    cells = RectCells(cell_x, cell_y, length, width, center, 2)

    start_time = time()
    solver = DsmcSolver(
        cells,
        gas,
        domain,
        surf_group,
        n_particles_in_cell,
        dt,
        time_av_sample,
        CollisionDetector,
        VhsCollider,
        Diffuse,
        ignore_frac=0.5,
    )
    solver.run()
    end_time = time()

    simulation_time = end_time - start_time
    print "simulation time in mins (upper bound) = ", int(round(simulation_time / 60))
    print "simulation time in sec = ", simulation_time
    number_density_0 = solver.get_2d_num_den(cell_x, cell_y, 0)
    number_density_1 = solver.get_2d_num_den(cell_x, cell_y, 1)
    temperature = solver.get_2d_temperature(cell_x, cell_y)
    speed = solver.get_2d_speed(cell_x, cell_y)
    u = solver.get_2d_u(cell_x, cell_y)
    v = solver.get_2d_v(cell_x, cell_y)
    w = solver.get_2d_w(cell_x, cell_y)
    pressure = (number_density_0 + number_density_1) * 1.3806488e-23 * temperature

    f = open("poise_super_temperature.txt", "w")
    np.savetxt(f, temperature)
    f.close()

    f = open("poise_super_number_density_0.txt", "w")
    np.savetxt(f, number_density_0)
    f.close()

    f = open("poise_super_number_density_1.txt", "w")
    np.savetxt(f, number_density_1)
    f.close()

    f = open("poise_super_speed.txt", "w")
    np.savetxt(f, speed)
    f.close()

    f = open("poise_super_u.txt", "w")
    np.savetxt(f, u)
    f.close()
    f.close()

    f = open("poise_super_v.txt", "w")
    np.savetxt(f, v)
    f.close()

    f = open("poise_super_w.txt", "w")
    np.savetxt(f, w)
    f.close()

    f = open("poise_super_pressure.txt", "w")
    np.savetxt(f, pressure)
    f.close()
示例#6
0
def main():
    
    wedge = [((0.39, 0.0), (1.0, 0.3464))]
    ref_point = (1.0, 0.0)
    surf_temp1 = 1000.0
    
    wedge2 = [((0.39, 1.0), (1.0, 0.6536))]
    ref_point2 = (1.0, 1.0)
    surf_temp2 = 1000.0
    # creating surface
    surf_group = SurfaceGroup()
    surf_group.add_new_group(wedge, ref_point, surf_temp1)
    surf_group.add_new_group(wedge2, ref_point2, surf_temp2)
    
    inlet = [((0.0, 0.0), (0.0, 1.0))]
    outlet = [((1.0, 0.3464), (1.0, 0.6536))]
    zero_grad  = [((0.0, 0.0), (0.39, 0.0)), ((0.39, 0.0), (1.0, 0.3464)),
                  ((0.0, 1.0), (0.39, 1.0)), ((0.39, 1.0), (1.0, 0.6536))]
    center = (0.5, 0.5)
    length = 1.0
    width = 1.0
    volume = 0.36
    domain = Domain(volume, inlet, zero_grad, outlet)
    
    
    sample_size = 10
    dof = 3.0
    mass = 66.3e-27
    viscosity_coeff = 2.117
    viscosity_index = 0.81
    mole_fraction = [0.5, 0.5]
    dia = 4.17e-10
    mach = [5.0, 0.0, 0.0]
    temperature = 300.0
    ref_temperature = 273.0
    number_density = 1.699e19
    gamma = 5.0 / 3.0
    n_particles_in_cell = 10
    ref_point = (0.1, 0.5)
    argon = Molecules(dia, viscosity_index, mass, viscosity_coeff, dof, 0,
                ref_temperature, gamma, volume, number_density)
    argon1 = Molecules(dia, viscosity_index, mass, viscosity_coeff, dof, 1,
                ref_temperature, gamma, volume, number_density)
    gas = Gas([argon, argon1], mole_fraction, mach, temperature)
    gas.setup()
#    dl = min(gas.mean_f_path)
#    dt = min(gas.mean_col_time)
    dt = 1.0e-5
#    print dt
#    cell_x, cell_y = np.ceil(length / dl), np.ceil(width / dl)
    cell_x, cell_y = 10, 10
    cells = RectCells(cell_x, cell_y, length, width, center, 2)
    
    start_time = time()
    solver = DsmcSolver(cells, gas, domain, surf_group, n_particles_in_cell,
                        ref_point, dt, sample_size, CollisionDetector,
                        VhsCollider, Diffuse)
    solver.run()
    end_time = time()
    
    simulation_time = end_time - start_time
    print "simulation time in mins (upper bound) = ", int(simulation_time / 60) + 1
    print "simulation time in sec = ", simulation_time
    number_density = solver.get_2d_num_den(cell_x, cell_y)
    temperature = solver.get_2d_temperature(cell_x, cell_y)
    
    f = open('nozzle_temperature.txt', 'w')
    np.savetxt(f, temperature)
    f.close()
    
    f = open('nozzle_number_density.txt', 'w')
    np.savetxt(f, number_density)
    f.close()
示例#7
0
文件: box.py 项目: mohitRohatgi/dsmc
def main():

    surface = [((0.0, 1.0), (0.0, 0.0)), ((0.0, 0.0), (1.0, 0.0)),
            ((1.0, 0.0), (1.0, 1.0)), ((1.0, 1.0), (0.0, 1.0))]
    
    center = (0.5, 0.5)
    length = 1.0
    width = 1.0
    volume = 1.0
    
    domain = Domain(volume)
    surf_group = SurfaceGroup()
    surf_group.add_new_group(surface, center)
    
    time_av_sample = 10000
    dof = 3.0
    mass = 66.3e-27
    viscosity_coeff = 2.117
    viscosity_index = 0.81
    mole_fraction = [0.5, 0.5]
    dia = 4.17e-10
    mach = [0.0, 0.0, 0.0]
    temperature = 300.0
    ref_temperature = 273.0
    number_density = 5e18
    gamma = 5.0 / 3.0
    n_particles_in_cell = 8
    argon = Molecules(dia, viscosity_index, mass, viscosity_coeff, dof, 0,
                ref_temperature, gamma, volume, number_density)
    argon1 = Molecules(dia, viscosity_index, mass, viscosity_coeff, dof, 1,
                ref_temperature, gamma, volume, number_density)
    gas = Gas([argon, argon1], mole_fraction, mach, temperature)
    gas.setup()
#    dl = min(gas.mean_f_path)
#    dt = min(gas.mean_col_time)
    dt = 1.0e-5
#    print dt
#    cell_x, cell_y = np.ceil(length / dl), np.ceil(width / dl)
    cell_x, cell_y = 200, 200
    cells = RectCells(cell_x, cell_y, length, width, center, 2)
    
    start_time = time()
    solver = DsmcSolver(cells, gas, domain, surf_group, n_particles_in_cell,
                         dt, time_av_sample, CollisionDetector,
                        VhsCollider, Specular, ignore_frac=0.1)
    solver.run()
    end_time = time()
    
    simulation_time = end_time - start_time
    print "simulation time in mins (upper bound) = ", round(simulation_time / 60)
    print "simulation time in sec = ", simulation_time
    number_density_0 = solver.get_2d_num_den(cell_x, cell_y, 0)
    number_density_1 = solver.get_2d_num_den(cell_x, cell_y, 1)
    temperature = solver.get_2d_temperature(cell_x, cell_y)
    mach = solver.get_2d_mach(cell_x, cell_y)
    pressure = (number_density_0 + number_density_1) * 1.3806488e-23 * temperature
    
    f = open('box_temperature.txt', 'w')
    np.savetxt(f, temperature)
    f.close()
    
    f = open('box_number_density_0.txt', 'w')
    np.savetxt(f, number_density_0)
    f.close()
    
    f = open('box_number_density_1.txt', 'w')
    np.savetxt(f, number_density_1)
    f.close()
    
    f = open('box_mach.txt', 'w')
    np.savetxt(f, mach)
    f.close()
    
    f = open('box_pressure.txt', 'w')
    np.savetxt(f, pressure)
    f.close()
示例#8
0
def main():

    surface1 = [((0.0, 1.0), (0.0, 0.0)), ((0.0, 0.0), (1.0, 0.0)), ((1.0, 0.0), (1.0, 1.0))]
    surface1_temp = 300.0
    
    surface2 = [((1.0, 1.0), (0.0, 1.0))]
    surface2_temp = 500.0
    
    center = (0.5, 0.5)
    length = 1.0
    width = 1.0
    volume = 1.0
    
#    ensemble_sample = 10
    sample_size = 10
    dof = 3.0
    mass = 66.3e-27
    viscosity_coeff = 2.117
    viscosity_index = 0.81
    mole_fraction = [0.5, 0.5]
    dia = 4.17e-10
    mach = [0.0, 0.0, 0.0]
    temperature = 500.0
    ref_temperature = 273.0
    number_density = 1.699e19
    gamma = 5.0 / 3.0
    n_particles_in_cell = 10
    ref_point = (0.1, 0.5)
    
    argon = Molecules(dia, viscosity_index, mass, viscosity_coeff, dof, 0,
                ref_temperature, gamma, volume, number_density)
    argon1 = Molecules(dia, viscosity_index, mass, viscosity_coeff, dof, 1,
                ref_temperature, gamma, volume, number_density)
    gas = Gas([argon, argon1], mole_fraction, mach, temperature)
    gas.setup()
    
    domain = Domain(volume)
    surf_group = SurfaceGroup()
    surf_group.add_new_group(surface1, center, surface1_temp)
    surf_group.add_new_group(surface2, center, surface2_temp)
    dt = 1.0e-5
    cell_x, cell_y = 5, 5
    cells = RectCells(cell_x, cell_y, length, width, center, 2)
    
    start_time = time()
    solver = DsmcSolver(cells, gas, domain, surf_group, n_particles_in_cell,
                        ref_point, dt, sample_size, CollisionDetector,
                        VhsCollider, Diffuse)
    solver.run()
    end_time = time()
    
    simulation_time = end_time - start_time
    print "simulation time in mins (upper bound) = ", int(simulation_time / 60) + 1
    print "simulation time in sec = ", simulation_time
    number_density = solver.get_2d_num_den(10, 10)
    print "number_density = ", number_density
    temperature = solver.get_2d_temperature(10, 10)
    print "temperature = ", temperature
    
    f = open('box_temp_grad_temperature.txt', 'w')
    np.savetxt(f, temperature)
    f.close()
    
    f = open('box_temp_grad_number_density.txt', 'w')
    np.savetxt(f, number_density)
    f.close()