Exemple #1
0
    def plot_qs(self):
        length = 0.2 * M
        aper = 30 * MM
        g = 10.0
        L = 0
        lc = LocalCoordinateSystem()
        qs = QS(lc, length, g, L, aper)

        Plot3.plot_qs(qs)
Exemple #2
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))
Exemple #3
0
    def test_quad_1(self):
        """
        测试 qs 四极场
        Returns
        -------

        """
        length = 0.2 * M
        aper = 30 * MM
        g = -45.7
        L = 0
        lc = LocalCoordinateSystem(P3(), -P3.x_direct(), P3.y_direct())
        qs = QS(lc, length, g, L, aper)

        m = qs.magnetic_field_at(P3(10 * MM, 0.1, 0))
        self.assertTrue(m == P3(0.0, 0.0, 0.457))

        m = qs.magnetic_field_at(P3(15 * MM, 0.1, 0))
        self.assertTrue(m == P3(0.0, 0.0, 0.6855))

        m = qs.magnetic_field_at(P3(15 * MM, 0.1, 5 * MM))
        self.assertTrue(m == P3(0.2285, 1.399158968025851e-17, 0.6855))
Exemple #4
0
    def test_quad_0(self):
        """
        测试 qs 四极场
        Returns
        -------

        """
        length = 0.2 * M
        aper = 30 * MM
        g = 10.0
        L = 0
        lc = LocalCoordinateSystem(P3(), -P3.x_direct(), P3.y_direct())
        qs = QS(lc, length, g, L, aper)

        m = qs.magnetic_field_at(P3(10 * MM, 0.1, 0.0))
        self.assertTrue(m == P3(0.0, 0.0, -0.1))

        m = qs.magnetic_field_at(P3(15 * MM, 0.1, 0.0))
        self.assertTrue(m == P3(0.0, 0.0, -0.15))

        m = qs.magnetic_field_at(P3(15 * MM, 0.1, 5 * MM))
        self.assertTrue(m == P3(-0.05, -3.061616997868383e-18, -0.15))
        float *p0 = winding + tid * DIM;
        float *p1 = winding + (tid + 1) * DIM;
        float db[3];

        dB(p0, p1, p, db);

        atomicAdd(&ret[X], db[X]);
        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)
from cctpy import M, MM, LocalCoordinateSystem, QS, Plot3, P3

length = 0.2 * M
aper = 30 * MM
g = 10.0
L = 0
lc = LocalCoordinateSystem(P3(), -P3.x_direct(), P3.y_direct())
qs = QS(lc, length, g, L, aper)

Plot3.plot_qs(qs)
Plot3.show()

m = qs.magnetic_field_at_cpu(P3(10 * MM, 0.1, 0.0))
print(m)