Commit 83fdc12b authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

biot savart sheet test

parent bd718105
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@ def current_sheet_finite(r, s1, s2, s3):
    # Transformation of the field back into the original coordinate system
    return bx*ex + by*ey

def current_sheet_infinite(r):
def current_sheet_infinite(_r):
    """
    Compute the magnetic field of an infinite current sheet with
    a current density of 1 A/m.
+5 −3
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ class FlippersTestCase(unittest.TestCase):



def curve_test():
def curve_test(plot):
    "test with plots"

    points = 163
@@ -86,7 +86,7 @@ def curve_test():
    B_ext = [ 0.0*GAUSS, 0.0, 0.0*GAUSS]

    for lamax in (5.0, 8.0, 11.0, 14.0):
        fig, ax1 = plt.subplots(1,1,figsize=(8,6))
        fig, ax1 = plot.subplots(1,1,figsize=(8,6))
        fig.suptitle(rf'$\lambda_{{max}}$={lamax:g}$\AA$')
        print(f"lambda_max = {lamax:g}A")

@@ -111,6 +111,8 @@ def curve_test():
        ax1.set_ylabel(r'I (A)')
        ax1.grid()



if __name__ == "__main__":
    unittest.main(exit=False, verbosity=2)

@@ -118,6 +120,6 @@ if __name__ == "__main__":
    # graphical tests
    import matplotlib.pyplot as plt

    curve_test()
    curve_test(plt)

    plt.show()
+56 −4
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ four_pi = 4*pi
R   = 1.0      # coil radius in m
L   = 1.0      # coil separation in m

#pylint: disable=too-many-public-methods

class BiotSavartTestCase(unittest.TestCase):
    "Biot-Savart Test Cases"
@@ -183,7 +184,7 @@ class BiotSavartTestCase(unittest.TestCase):
        r   =  array((0.1,0.2,0.3))
        bexp = array((-0.40581227, 0.02079833, 0))
        bact = bs.current_sheet(r, xs1, xs2, xs3)
        self.assertTrue(np.allclose(bexp, bact))
        self.assertTrue(np.allclose(bexp, bact), f"{bexp} != {bact}")

        xs1  = array((-100, 0,-100))
        xs2  = array((-100, 0,+100))
@@ -191,11 +192,11 @@ class BiotSavartTestCase(unittest.TestCase):
        r    = array((0.0,2e-6,0.0))
        bexp = array((-0.5, 0, 0))
        bact = bs.current_sheet(r, xs1, xs2, xs3)
        self.assertTrue(np.allclose(bexp, bact))
        self.assertTrue(np.allclose(bexp, bact), f"{bexp} != {bact}")
        r    = array((0.0,-2e-6,0.0))
        bexp = array((0.5, 0, 0))
        bact = bs.current_sheet(r, xs1, xs2, xs3)
        self.assertTrue(np.allclose(bexp, bact))
        self.assertTrue(np.allclose(bexp, bact), f"{bexp} != {bact}")

        xs1  = array((-2, 0,-1))
        xs2  = array((-2, 0,+1))
@@ -203,7 +204,7 @@ class BiotSavartTestCase(unittest.TestCase):
        r    = array((0.4,0.6,0.5))
        bexp = array((-0.23694913, 0.08906743, 0))
        bact = bs.current_sheet(r, xs1, xs2, xs3)
        self.assertTrue(np.allclose(bexp, bact))
        self.assertTrue(np.allclose(bexp, bact), f"{bexp} != {bact}")

    def test_current_sheet_rotated(self):
        "test rotated sheet"
@@ -231,5 +232,56 @@ class BiotSavartTestCase(unittest.TestCase):
        bact = bs.current_sheet(r, xs1, xs2, xs3)
        self.assertTrue(np.allclose(bexp, bact))




def current_sheet_test(axs):
    "the main"
    def run_one_test(dy, yrange=0.025):
        "test3"
        yrange = np.linspace(-yrange, yrange, 221)

        s1 = array((-0.18/2, dy/2, -0.10/2))
        s2 = array((-0.18/2, dy/2, +0.10/2))
        s3 = array((+0.18/2, dy/2, -0.10/2))
        res1 = []
        for y in yrange:
            r = array(( 0, y, 0))
            b = bs.current_sheet(r, s1, s2, s3)
            res1.append((y,b[0]))
        res1 = array(res1)

        s1 = array((-0.18/2,-dy/2, -0.10/2))
        s2 = array((-0.18/2,-dy/2, +0.10/2))
        s3 = array((+0.18/2,-dy/2, -0.10/2))
        res2 = []
        for y in yrange:
            r = array(( 0, y, 0))
            b = bs.current_sheet(r, s1, s2, s3)
            res2.append((y,-b[0]))
        res2 = array(res2)
        res = np.zeros_like(res1)
        res[:,0] = (res1[:,0]+res2[:,0])/2
        res[:,1] =  res1[:,1]+res2[:,1]
        return res

    for dy in (0.005, 0.010, 0.015, 0.020, 0.025):
        res = run_one_test(dy)
        y = res[:,0]
        b = res[:,1]
        print(f"{dy:.3f} => {np.average(b[b>0]):g}")
        axs.plot(y, b, '.-', ms=2, lw=1, label=f"dy={dy}")
    axs.legend()
    axs.grid(True, which='both')

if __name__ == "__main__":
    unittest.main(exit=False, verbosity=2)

    # ==================================================================
    # graphical tests
    import matplotlib.pyplot as plt

    _fig, axis = plt.subplots(1,1)
    current_sheet_test(axis)

    plt.show()
+2 −2

File changed.

Contains only whitespace changes.

+1 −1

File changed.

Contains only whitespace changes.