coil.s.plot(figure=f, contours=20) shieldcoil.s.plot(figure=f, contours=20) #%% # Compute the field and scalar potential on an XY-plane x = y = np.linspace(-8, 8, 150) X, Y = np.meshgrid(x, y, indexing="ij") points = np.zeros((X.flatten().shape[0], 3)) points[:, 0] = X.flatten() points[:, 1] = Y.flatten() CB1 = coil.B_coupling(points) CB2 = shieldcoil.B_coupling(points) CU1 = coil.U_coupling(points) CU2 = shieldcoil.U_coupling(points) B1 = CB1 @ coil.s B2 = CB2 @ shieldcoil.s U1 = CU1 @ coil.s U2 = CU2 @ shieldcoil.s #%% # Now, plot the field streamlines and scalar potential from bfieldtools.contour import scalar_contour cc1 = scalar_contour(mesh1, mesh1.vertices[:, 2], contours=[-0.001]) cc2 = scalar_contour(mesh2, mesh2.vertices[:, 2], contours=[-0.001])
# A1, Beta1 = compute_sphcoeffs_mesh(mesh1, 5, normalization='energy', R=1) # A2, Beta2 = compute_sphcoeffs_mesh(mesh2, 5, normalization='energy', R=1) # Beta1 = Beta1[:, coil1.inner_vertices] # Beta2 = Beta2[:, coil2.inner_vertices] x = y = np.linspace(-0.8, 0.8, 50) # 150) X, Y = np.meshgrid(x, y, indexing="ij") points = np.zeros((X.flatten().shape[0], 3)) points[:, 0] = X.flatten() points[:, 1] = Y.flatten() CB1 = coil1.B_coupling(points) CB2 = coil2.B_coupling(points) CU1 = coil1.U_coupling(points) CU2 = coil2.U_coupling(points) #%% Precalculations for the solution # alpha[15] = 1 # Minimization of magnetic energy with spherical harmonic constraint C = Beta1 + Beta2 @ P M = M11 + M21.T @ P from scipy.linalg import eigvalsh ssmax = eigvalsh(C.T @ C, M, eigvals=[M.shape[1] - 1, M.shape[1] - 1]) #%% Specify spherical harmonic and calculate corresponding shielded field beta = np.zeros(Beta1.shape[0]) beta[7] = 1 # Gradient
f.scene.isometric_view() f.scene.camera.zoom(0.95) #%% # Now, let's compute the effect of the shield on the field produced by the coil # Points slightly inside the shield d = (np.mean(np.diff(shield.mesh.vertices[shield.mesh.faces[:, 0:2]], axis=1), axis=0) / 10) points = shield.mesh.vertices - d * shield.mesh.vertex_normals # Solve equivalent stream function for the perfect linear mu-metal layer. # This is the equivalent surface current in the shield that would cause its # scalar magnetic potential to be constant shield.s = StreamFunction( np.linalg.solve(shield.U_coupling(points), coil.U_coupling(points) @ coil.s), shield) #%% # Plot the difference in field when taking the shield into account f = mlab.figure(None, bgcolor=(1, 1, 1), fgcolor=(0.5, 0.5, 0.5), size=(800, 800)) mlab.clf() B_target = coil.B_coupling(target_points) @ coil.s B_target_w_shield = (coil.B_coupling(target_points) @ coil.s + shield.B_coupling(target_points) @ shield.s)
#%% interpolate data on planar mesh from bfieldtools.utils import load_example_mesh from bfieldtools.mesh_calculus import gradient plane = load_example_mesh("10x10_plane_hires") scaling_factor = 0.03 plane.apply_scale(scaling_factor) # Rotate to x-plane t = np.eye(4) theta = np.pi / 2 * 1.2 t[1:3, 1:3] = np.array([[np.cos(theta), np.sin(theta)], [-np.sin(theta), np.cos(theta)]]) plane.apply_transform(t) c.U_coupling.reset() U_suh = c.U_coupling(plane.vertices) @ a # Adapt mesh to the function and calculate new points for i in range(2): g = np.linalg.norm(gradient(U_suh, plane), axis=0) face_ind = np.flatnonzero(g > g.max() * 0.05) plane = plane.subdivide(face_ind) U_suh = c.U_coupling(plane.vertices) @ a U_sph = potential(plane.vertices, alpha, np.zeros(alpha.shape), lmax=lmax, normalization="energy", R=R) #%%
] scene.scene.camera.view_angle = 30.0 scene.scene.camera.view_up = [ -0.28276020498745635, 0.33658483701858727, 0.898196701154387, ] scene.scene.camera.clipping_range = [16.139073445910277, 116.31572537292347] scene.scene.camera.compute_view_plane_normal() scene.scene.render() #%% #%% Calculate primary potential matrix # Compute slightly inside d = 1e-3 P_prim = coil.U_coupling(shieldmesh.vertices - d * shieldmesh.vertex_normals) #%% Plot the resulting primary potential mlab.figure() s = mlab.triangular_mesh(*shieldmesh.vertices.T, shieldmesh.faces, scalars=P_prim @ sprim, opacity=1.0) s.enable_contours = True s.contour.filled_contours = True s.contour.number_of_contours = 30 #%% #%% Calculate linear collocation BEM matrix P_shield = shield.U_coupling(shieldmesh.vertices - d * shieldmesh.vertex_normals)