예제 #1
0
def spinning_period_sim():
    samples = 200
    fine_res = 150
    fineT = 2.5 / 12.
    maxT = 18. / 12.
    data_out = open('./%d.txt' % time.time(), 'w')
    start = time.time()
    energies = []
    for frac in range(1, samples):
        if frac <= fine_res:
            T_0 = (fineT / fine_res) * frac
        else:
            T_0 = fineT + (frac - fine_res) * (maxT - fineT) / (samples -
                                                                fine_res)
        energies.append(T_0)
        # T_0 = .5
        print(T_0)
        Pd = (T_0 / 10.)**.5
        init = numpy.array([0.0, 0.0, 0.0, 0.0, Pd, 0., 0.0])
        sim_path = utils.RK4_adapt(reduced_double_dipole,
                                   init,
                                   .05,
                                   max_steps=10**6,
                                   precision=10**-10)
        S_0 = sim_path[-1]
        S_0[0] = 0.0
        # S_0 = init
        # print(S_0)
        return_times = utils.return_times_finder(reduced_double_dipole,
                                                 S_0,
                                                 max_steps=10**6,
                                                 precision=10**-10,
                                                 max_time=75)
        # print(return_times)
        # print([val[0]/return_times[0][0] for val in return_times])
        period = utils.fit_slope_and_chisqr(return_times)
        print(period)
        S_0 = list(S_0)
        S_0.append(period[0])
        S_0.append(period[1])
        data_out.write(('%f ' * 8) % tuple(S_0[1:]))
        data_out.write('\n')
        print(' ')
    data_out.close()
    # periods = utils.read_column(S_0, -2)
    # matplotlib.plot(energies, periods)
    # pyplot.show()
    print('took %d seconds' %
          (time.time() - start))  # print(len(sim_path), T_0)
예제 #2
0
def random_point_period():
    state0p, state0m = utils.reduced_state_gen()
    state0p = [
        0.0, 0.0, 0.5166312725363087, 0.33848195776981216, 0.0,
        0.10794186242929231, 0.10008255831561577
    ]
    states = [state0p, state0m]
    for state0_ind in range(1):
        start = numpy.array(states[state0_ind])
        print(start[-2:])
        return_times = utils.return_times_finder(reduced_double_dipole,
                                                 start,
                                                 max_steps=10**6,
                                                 precision=10**-7,
                                                 max_time=2 * 2.8)
        print(return_times)
        print([val / return_times[0] for val in return_times])
예제 #3
0
 def test_return_times_finder(self):
     x0 = random.random()
     p0 = (1. - x0**2)**.5
     stateI = numpy.array([0., x0, p0])
     return_times = utils.return_times_finder(base_SHO,
                                              stateI,
                                              precision=10**-10,
                                              max_time=100.0,
                                              max_steps=10**6)
     print(return_times)
     print([val[0] / (2 * numpy.pi) for val in return_times])
     print(len(return_times))
     for i in range(len(return_times)):
         self.assertAlmostEqual((i + 1) * 2 * numpy.pi,
                                return_times[i][0],
                                delta=return_times[i][1])
     self.assertTrue(len(return_times) > 10.0 / 2.1 * numpy.pi)
예제 #4
0
def orbital_period_sim():
    samples = 100
    # coarse_res = 50
    # coarseT = 0./12.
    maxT = 1. / 3.
    data_out = open('./%d.txt' % time.time(), 'w')
    start = time.time()
    for frac in range(1, samples):
        # if frac <=coarse_res:
        #     T_0 = (coarseT/coarse_res)*frac
        # else:
        #     T_0 = coarseT + (frac-coarse_res)*(maxT-coarseT)/(samples-coarse_res)
        T_0 = (maxT / samples) * frac
        # T_0 = .5
        print(T_0)
        P_tht = (2. * T_0 / 7.)**.5
        init = numpy.array([0.0, 0.0, 0.0, 0.0, 0.0, -P_tht / 2., P_tht])
        sim_path = utils.RK4_adapt(reduced_double_dipole,
                                   init,
                                   .01,
                                   max_steps=10**6,
                                   precision=10**-10)
        S_0 = sim_path[-1]
        S_0[0] = 0.0
        # S_0 = init
        # print(S_0)
        return_times = utils.return_times_finder(reduced_double_dipole,
                                                 S_0,
                                                 max_steps=10**6,
                                                 precision=10**-9,
                                                 max_time=75)
        # print(return_times)
        # print([val[0]/return_times[0][0] for val in return_times])
        period = utils.fit_slope_and_chisqr(return_times)
        print(period)
        S_0 = list(S_0)
        S_0.append(period[0])
        S_0.append(period[1])
        data_out.write(('%f ' * 8) % tuple(S_0[1:]))
        data_out.write('\n')
        print(' ')
    data_out.close()
    print('took %d seconds' %
          (time.time() - start))  # print(len(sim_path), T_0)
예제 #5
0
def spinning_period_sim():
    samples = 150
    maxT = 2. / 12.
    data_out = open('./%d.txt' % time.time(), 'w')
    start = time.time()
    for frac in range(1, samples):
        T_0 = (maxT / samples) * frac
        # T_0 = .5
        print(T_0)
        Pd = (T_0 / 10.)**.5
        init = numpy.array([0.0, 0.0, 0.0, 0.0, Pd, 0., 0.0])
        sim_path = utils.RK4_adapt(reduced_double_dipole,
                                   init,
                                   .05,
                                   max_steps=10**6,
                                   precision=10**-10)
        S_0 = sim_path[-1]
        S_0[0] = 0.0
        # S_0 = init
        # print(S_0)
        return_times = utils.return_times_finder(reduced_double_dipole,
                                                 S_0,
                                                 max_steps=10**6,
                                                 precision=10**-10,
                                                 max_time=75)
        # print(return_times)
        # print([val[0]/return_times[0][0] for val in return_times])
        period = utils.fit_slope_and_chisqr(return_times)
        print(period)
        S_0 = list(S_0)
        S_0.append(period[0])
        S_0.append(period[1])
        data_out.write(('%f ' * 8) % tuple(S_0[1:]))
        data_out.write('\n')
        print(' ')
    data_out.close()
    print('took %d seconds' %
          (time.time() - start))  # print(len(sim_path), T_0)