Exemplo n.º 1
0
 def test_p2_change_len(self):
     for i in range(1, 100):
         a = random.random() + i
         b = random.random() + i
         p = P2(a, b)
         self.assertTrue(
             p.change_length(1).normalize() == P2(a, b).normalize())
Exemplo n.º 2
0
 def test_p2_add(self):
     for i in range(100):
         a = random.random() + i
         b = random.random() + i
         c = random.random() + i
         d = random.random() + i
         self.assertEqual(P2(a, b) + P2(c, d), P2(a + c, b + d))
Exemplo n.º 3
0
 def test_p2_sub(self):
     for i in range(100):
         a = random.random() + i
         b = random.random() + i
         c = random.random() + i
         d = random.random() + i
         self.assertEqual(P2(a, b) - P2(c, d), P2(a - c, b - d))
Exemplo n.º 4
0
    def test_tr_01(self):
        t = (Trajectory(StraightLine2(2.0, P2(1, 0), P2(0, 0))).add_arc_line(
            0.95, False, 22.5).add_strait_line(1.5).add_arc_line(
                0.95, False, 22.5).add_strait_line(2.0 + 2.2).add_arc_line(
                    0.95, True, 67.5).add_strait_line(1.5).add_arc_line(
                        0.95, True, 67.5).add_strait_line(2.2))

        self.assertTrue(BaseUtils.equal(t.direct_at_end(), P2(0, -1)))
Exemplo n.º 5
0
 def test_mul2(self):
     for i in range(100):
         a = random.random() + i + 1
         b = random.random() + i + 1
         c = random.random() + i + 1
         d = random.random() + i + 1
         self.assertTrue(
             BaseUtils.equal(P2(a, b) * P2(c, d),
                             a * c + b * d,
                             msg="error"))
Exemplo n.º 6
0
 def test_p2_isub(self):
     for i in range(100):
         a = random.random() + i
         b = random.random() + i
         c = random.random() + i
         d = random.random() + i
         p1 = P2(a, b)
         p2 = P2(c, d)
         p1_copy = p1.copy()
         p1 -= p2
         self.assertEqual(p1, p1_copy - p2)
Exemplo n.º 7
0
    def test_magnet_at(self):
        cct = CCT(
            LocalCoordinateSystem.global_coordinate_system(),
            0.95,
            83 * MM + 15 * MM * 2,
            67.5,
            [30.0, 80.0, 90.0, 90.0],
            128,
            -9664,
            P2(0, 0),
            P2(128 * np.pi * 2, 67.5 / 180.0 * np.pi),
        )

        m = cct.magnetic_field_at(P3.origin())
        self.assertEqual(
            m,
            P3(0.0031436355039083964, -0.00470478301086915,
               0.00888627084434009))
Exemplo n.º 8
0
    def test_angle_to(self):
        for i in range(100):
            a0 = random.random() * np.pi * 1.9 + 1e-6
            b0 = random.random() * np.pi * 1.9 + 1e-6
            a = max(a0, b0)
            b = min(a0, b0)
            p1 = P2(1.0)
            p2 = P2(1.0)

            p1 = p1.rotate(a)
            p2 = p2.rotate(b)

            diff = a - b

            # print(p1.angle_to(p2),diff)

            self.assertTrue(
                BaseUtils.equal(
                    p2.angle_to(p1),
                    diff  #if diff >0 else 2 * np.pi - diff
                ))
Exemplo n.º 9
0
    def test_tr_02(self):
        """
        彩蛋,把绘图代码注释取消即可
        Returns
        -------

        """
        c1 = (Trajectory(StraightLine2(0.01, P2(0, 1), P2(0, 0))).add_arc_line(
            1, True, 135).add_arc_line(
                0.01, True, 90).add_strait_line(0.1).add_arc_line(
                    0.01, True,
                    90).add_arc_line(0.9, False, 360 - 90).add_arc_line(
                        0.01, True, 90).add_strait_line(0.1).add_arc_line(
                            0.01, True, 90).add_arc_line(1, True, 135))

        c2 = c1 + P2(3, 0)

        t = Trajectory(StraightLine2(0.8, P2(1, 0), P2(6, 1))).add_arc_line(
            0.01, True, 90).add_strait_line(0.2).add_arc_line(
                0.01, True, 90).add_strait_line(0.7).add_arc_line(
                    0.01, False, 90).add_strait_line(1.7).add_arc_line(
                        0.01, True, 90).add_strait_line(0.2).add_arc_line(
                            0.01, True, 90).add_strait_line(1.7).add_arc_line(
                                0.01, False,
                                90).add_strait_line(0.7).add_arc_line(
                                    0.01, True,
                                    90).add_strait_line(0.2).add_arc_line(
                                        0.01, True,
                                        90).add_strait_line(0.8) + P2(0.5, 0)

        Plot3.plot_line2(c1, describe='r')
        Plot3.plot_line2(c2, describe='b')
        Plot3.plot_line2(t, describe='g')
        Plot3.set_center()

        Plot3.show()

        self.assertTrue(True)
Exemplo n.º 10
0
 def test_p2_neg(self):
     for i in range(100):
         a = random.random() + i
         b = random.random() + i
         self.assertEqual(P2(-a, -b), -P2(a, b))
Exemplo n.º 11
0
 def test_p2_len(self):
     p = P2(1, 1)
     self.assertTrue(BaseUtils.equal(p.length(), np.sqrt(2)))
Exemplo n.º 12
0
 def test_p2_copy(self):
     for i in range(100):
         p = P2(random.random() + i, random.random() + i)
         self.assertTrue(BaseUtils.equal(p, p.copy()))
         self.assertFalse(p is p.copy())
Exemplo n.º 13
0
 def test_angle_to_x_axis(self):
     for i in range(100):
         phi = random.random() * np.pi * 1.9 + 1e-6
         p = P2(1.0)
         p = p.rotate(phi)
         self.assertTrue(BaseUtils.equal(p.angle_to_x_axis(), phi))
Exemplo n.º 14
0
 def test_mul1(self):
     for i in range(100):
         a = random.random() + i + 1
         b = random.random() + i + 1
         c = random.random() + i + 1
         self.assertTrue(P2(a, b) * c, P2(a * c, b * c))
Exemplo n.º 15
0
 def test_p2_norm(self):
     p = P2(1, 1)
     self.assertTrue(
         BaseUtils.equal(p.normalize(), P2(np.sqrt(2) / 2,
                                           np.sqrt(2) / 2)))
Exemplo n.º 16
0
 def test_to_p3(self):
     for i in range(100):
         a = random.random() + i
         b = random.random() + i
         self.assertTrue(P2(a, b).to_p3() == P3(a, b, 0.0))
Exemplo n.º 17
0
 def test_p2_rotate(self):
     for phi in np.linspace(0.1, 2 * np.pi * 0.99, 100):
         p = P2(1.0)
         p = p.rotate(phi)
         self.assertTrue(BaseUtils.equal(p.angle_to_x_axis(), phi))
Exemplo n.º 18
0
 def test_equal2(self):
     BaseUtils.equal(P2(), P2(1e-10), msg="不相等")
     with self.assertRaises(AssertionError):
         BaseUtils.equal(P2(), P2(1e-5), msg="不相等")
Exemplo n.º 19
0
        atomicAdd(&ret[Y], db[Y]);
        atomicAdd(&ret[Z], db[Z]);
    }
}""")

magnet = mod.get_function("magnet_solo_cct")

cct = CCT(
    LocalCoordinateSystem.global_coordinate_system(),
    0.95,
    83 * MM + 15 * MM * 2,
    67.5,
    [30.0, 80.0, 90.0, 90.0],
    128,
    -9664,
    P2(0, 0),
    P2(128 * np.pi * 2, 67.5 / 180.0 * np.pi),
)

length = int(cct.dispersed_path3.shape[0])
winding = cct.dispersed_path3.flatten().astype(np.float32)

ret = np.empty((3, ), dtype=np.float32)

###################### time ###############
import time

times = 2
#################
s = time.time()
for x in np.linspace(0, 0.01, times):
Exemplo n.º 20
0
try:
    from books.cct.cctpy.cctpy import *
except ModuleNotFoundError:
    pass

import sys
sys.path.append(
    r'C:\Users\madoka_9900\Documents\github\madokast.github.io\books\cct\cctpy'
)

from cctpy import Beamline, P2, MM, BaseUtils
import matplotlib.pyplot as plt

bl: Beamline = (  # QS 磁铁加前后 1m 漂移段
    Beamline.set_start_point(P2.origin()).first_drift(
        direct=P2.x_direct(),
        length=1.0).append_qs(length=0.27,
                              gradient=0,
                              second_gradient=-1000,
                              aperture_radius=60 * MM).append_drift(1.0))

x, y = bl.track_phase_ellipse(x_sigma_mm=3.5,
                              xp_sigma_mrad=7.5,
                              y_sigma_mm=3.5,
                              yp_sigma_mrad=7.5,
                              delta=0.0,
                              kinetic_MeV=250,
                              particle_number=32,
                              footstep=1 * MM,
                              concurrency_level=16)