Esempio n. 1
0
def TaskOfKRandomBodies(K, type):
    list_of_mass_all = np.zeros(K)
    list_of_radius_and_velocity_all = np.zeros((K, 6))
    step = random.randrange(10**3, 10**10)
    #max_velocity = 0 #максимальная скорость
    for i in range(0, K):
        list_of_mass_all[i] = random.randrange(pow(10, 24), pow(10, 30))
        temp = random.randrange(200, 500)
        # if(temp > max_velocity):
        #    max_velocity = temp
        list_of_radius_velocity = [0, i * step, 0, temp, 0, 0]
        list_of_radius_and_velocity_all[i, :] = list_of_radius_velocity

    N = len(list_of_radius_and_velocity_all)
    init = list_of_radius_and_velocity_all.reshape((6 * N))

    # asize = step*K
    T = 500 * step * 10  #Расчетное время
    M = 100

    t = time.time()
    if (type == "verlet"):
        result = VerletMethod(list_of_radius_and_velocity_all,
                              list_of_mass_all, N, M, T)
        return result, time.time() - t
    if (type == "scipy"):
        time_span = np.linspace(0, T, M)
        result = odeint(g, init, time_span, args=(list_of_mass_all, N))
        result2 = result.reshape((M, N, 6))
        return result2, time.time() - t
    if (type == "verlet-threading"):
        result = VerletMethodThreading(list_of_radius_and_velocity_all,
                                       list_of_mass_all, M, T)
        return result, time.time() - t
    if (type == "verlet-cython without typed memoryview"):
        result = cythverlet.cverletnotypedmemoryview(
            np.asarray(list_of_radius_and_velocity_all),
            np.asarray(list_of_mass_all), M, T)
        return np.asarray(result), time.time() - t
    if (type == "verlet-cython with typed memoryview"):
        result = cythverlet.cverlettypedmemoryview(
            np.asarray(list_of_radius_and_velocity_all),
            np.asarray(list_of_mass_all), M, T)
        return np.asarray(result), time.time() - t
    if (type == "verlet-openmp without typed memoryview"):
        result = cythverlet.cverlet_openmp(
            np.asarray(list_of_radius_and_velocity_all),
            np.asarray(list_of_mass_all), M, T)
        return np.asarray(result), time.time() - t
    if (type == "verlet-openmp with typed memoryview"):
        result = cythverlet.cverlettypedmemoryview_openmp(
            np.asarray(list_of_radius_and_velocity_all),
            np.asarray(list_of_mass_all), M, T)
        return np.asarray(result), time.time() - t
Esempio n. 2
0
def TaskOfNbodiesVerle(type):

    #list_of_mass_all = [MassMoon, MassEarth, MassSun]
    list_of_mass_all = [MassMoon/MassSun, MassEarth/MassSun, 1, MassMerc/MassSun]
    list_of_radius_and_velocity_all = np.zeros((4, 6))

    #T_norm = 12*2592000

    #first body moon
    list_of_radius_velocity = [0, 1.496*10**11/r_norm + 384467000/r_norm, 0, 1022/r_norm +29.783*10 **3/r_norm, 0, 0]
    list_of_radius_and_velocity_all[0,:] = list_of_radius_velocity

    #second body earth
    list_of_radius_velocity = [0, 1.496*10**11/r_norm, 0, 29.783*10 **3/r_norm, 0, 0]
    list_of_radius_and_velocity_all[1, :] = list_of_radius_velocity

    # third sun
    list_of_radius_velocity = [0, 0, 0, 0, 0, 0]
    list_of_radius_and_velocity_all[2, :] = list_of_radius_velocity

    # fourth mercury
    list_of_radius_velocity = [0, 57910000*1000/r_norm, 0, 47.36*1000/r_norm, 0, 0]
    list_of_radius_and_velocity_all[3, :] = list_of_radius_velocity

    N = len(list_of_radius_and_velocity_all)
    init =list_of_radius_and_velocity_all.reshape((6 * N))

    if(type == "verlet"):
        result = VerletMethod(list_of_radius_and_velocity_all, list_of_mass_all, N, M, T)
        return  result
    if (type =="scipy"):
        time_span = np.linspace(0,T,M)
        result = odeint(g,init,time_span,args=(list_of_mass_all,N))
        result2 = result.reshape((M, N, 6))
        return result2
    if (type == "verlet-threading"):
        result = VerletMethodThreading(list_of_radius_and_velocity_all, list_of_mass_all, M, T)
        return result
    if (type == "verlet-cython without typed memoryview"):
        result = cythverlet.cverletnotypedmemoryview(np.asarray(list_of_radius_and_velocity_all), np.asarray(list_of_mass_all), M, T)
        return np.asarray(result)
    if (type == "verlet-cython with typed memoryview"):
        result = cythverlet.cverlettypedmemoryview(np.asarray(list_of_radius_and_velocity_all), np.asarray(list_of_mass_all), M, T)
        return np.asarray(result)
    if (type == "verlet-openmp without typed memoryview"):
        result = cythverlet.cverlet_openmp(np.asarray(list_of_radius_and_velocity_all),
                                                   np.asarray(list_of_mass_all), M, T)
        return np.asarray(result)
    if (type == "verlet-openmp with typed memoryview"):
        result = cythverlet.cverlettypedmemoryview_openmp(np.asarray(list_of_radius_and_velocity_all),
                                                    np.asarray(list_of_mass_all), M, T)
        return np.asarray(result)