Exemplo n.º 1
0
def test_compute_modes():

    obj = _fake_mesh_conductor("unit_disc")

    DC_n = thermal_noise.compute_current_modes(
        obj, T=300, resistivity=1e-8, thickness=1e-3, mode="DC"
    )

    AC_n = thermal_noise.compute_current_modes(
        obj, freqs=np.array((0,)), T=300, resistivity=1e-8, thickness=1e-3, mode="AC"
    )

    points = np.array([[0.1, 0, 0.2], [-0.1, 0.1, -0.2]])

    obj.set_basis("vertex")

    DC_Bn_covar = thermal_noise.noise_covar(obj.B_coupling(points), DC_n)
    AC_Bn_covar = thermal_noise.noise_covar(obj.B_coupling(points), AC_n)

    assert_allclose(DC_Bn_covar, AC_Bn_covar[:, :, :, 0])

    DC_Bn_covar_dir = thermal_noise.noise_covar_dir(obj.B_coupling(points), DC_n)
    AC_Bn_covar_dir = thermal_noise.noise_covar_dir(obj.B_coupling(points), AC_n)

    assert_allclose(DC_Bn_covar_dir, AC_Bn_covar_dir[:, :, :, 0])

    DC_Bn_var = thermal_noise.noise_var(obj.B_coupling(points), DC_n)
    AC_Bn_var = thermal_noise.noise_var(obj.B_coupling(points), AC_n)

    assert_allclose(DC_Bn_var, AC_Bn_var[:, :, 0])

    thermal_noise.visualize_current_modes(obj.mesh, DC_n, scale=0.5, Nmodes=3)
Exemplo n.º 2
0
def test_vs_analytic():

    obj = _fake_mesh_conductor("unit_disc")
    mesh = obj.mesh

    mesh.vertices, mesh.faces = trimesh.remesh.subdivide(mesh.vertices, mesh.faces)

    # Fix the simulation parameters
    d = 100e-6  # thickness
    sigma = 3.7e7  # conductivity
    res = 1 / sigma  # resistivity
    T = 300  # temperature
    kB = 1.38064852e-23  # Boltz
    mu0 = 4 * np.pi * 1e-7  # permeability of freespace

    # Compute the AC-current modes and visualize them
    vl, u = thermal_noise.compute_current_modes(
        obj=mesh, T=T, resistivity=res, thickness=d, mode="AC", return_eigenvals=True
    )

    # Define field points on z axis
    Np = 10
    z = np.linspace(0.2, 1, Np)
    fp = np.array((np.zeros(z.shape), np.zeros(z.shape), z)).T

    B_coupling = magnetic_field_coupling(
        mesh, fp, analytic=True
    )  # field coupling matrix

    # Compute noise variance
    B = np.sqrt(thermal_noise.noise_var(B_coupling, vl))

    # Next, we compute the DC noise without reference to the inductance
    vl_dc, u_dc = thermal_noise.compute_current_modes(
        obj=mesh, T=T, resistivity=res, thickness=d, mode="DC", return_eigenvals=True
    )

    # Compute noise variance
    B_dc = np.sqrt(thermal_noise.noise_var(B_coupling, vl_dc))

    # Calculate Bz noise using analytical formula and plot the results
    r = 1
    Ban = (
        mu0
        * np.sqrt(sigma * d * kB * T / (8 * np.pi * z ** 2))
        * (1 / (1 + z ** 2 / r ** 2))
    )

    assert_allclose(B_dc[:, 2], B[:, 2, 0])

    assert_allclose(Ban, B[:, 2, 0], rtol=5e-2)
Exemplo n.º 3
0
    vl = compute_current_modes(
        obj=mesh,
        T=T,
        resistivity=1 / sigma,
        thickness=d,
        mode="AC",
        return_eigenvals=False,
    )

    #    scene = mlab.figure(None, bgcolor=(1, 1, 1), fgcolor=(0.5, 0.5, 0.5),
    #               size=(800, 800))
    #    visualize_current_modes(mesh,vl[:,:,0], 8, 1)

    vl[:, 0] = np.zeros(vl[:, 0].shape)  # fix DC-component

    Btemp = noise_var(B_coupling, vl)

    B[i] = Btemp[:, :, 0]

scene = mlab.figure(None, bgcolor=(1, 1, 1), fgcolor=(0.5, 0.5, 0.5), size=(800, 800))
s = mlab.triangular_mesh(*mesh.vertices.T, mesh.faces)
scene.scene.z_minus_view()
surface = scene.children[0].children[0].children[0].children[0]
surface.actor.property.representation = "wireframe"
surface.actor.mapper.scalar_visibility = False
scene.scene.camera.position = [0.0, 0.0, -5.530686305704514]
scene.scene.camera.focal_point = [0.0, 0.0, 0.0]
scene.scene.camera.view_angle = 30.0
scene.scene.camera.view_up = [0.0, 1.0, 0.0]
scene.scene.camera.clipping_range = [3.485379442647469, 8.118646600290083]
scene.scene.camera.compute_view_plane_normal()
Exemplo n.º 4
0
        None, bgcolor=(1, 1, 1), fgcolor=(0.5, 0.5, 0.5), size=(800, 800)
    )
    s = mlab.triangular_mesh(*mesh.vertices.T, mesh.faces)
    scene.scene.z_minus_view()
    surface = scene.children[0].children[0].children[0].children[0]
    surface.actor.property.representation = "wireframe"
    surface.actor.mapper.scalar_visibility = False
    scene.scene.camera.position = [0.0, 0.0, -4.515786458791532]
    scene.scene.camera.focal_point = [0.0, 0.0, 0.0]
    scene.scene.camera.view_angle = 30.0
    scene.scene.camera.view_up = [0.0, 1.0, 0.0]
    scene.scene.camera.clipping_range = [4.229838328573525, 4.886628590046963]
    scene.scene.camera.compute_view_plane_normal()
    scene.scene.render()

    Bvar = noise_var(B_coupling, vl)
    Bn[i] = np.sqrt(Bvar[:, 2, 0])

    if i == 0:
        u0 = u
    if i == 1:
        u1 = u
    if i == 2:
        u2 = u

    print(i)

figw = 3.75

plt.figure(figsize=(figw, 5))
plt.loglog(1 / u0 * 1e3, linewidth=2, label="N = %i" % Nfaces[0])
Exemplo n.º 5
0
s = mlab.triangular_mesh(*mesh.vertices.T, mesh.faces)
scene.scene.z_minus_view()
surface = scene.children[0].children[0].children[0].children[0]
surface.actor.property.representation = "wireframe"
surface.actor.mapper.scalar_visibility = False
scene.scene.isometric_view()
scene.scene.render()


Np = 30

x = np.linspace(-0.95, 0.95, Np)
fp = np.array((x, np.zeros(x.shape), np.zeros(x.shape))).T

B_coupling = magnetic_field_coupling(mesh, fp, analytic=True)
B = noise_var(B_coupling, vl)

a = 0.5
L = 2
rat = L / (2 * a)
Gfact = (
    1
    / (8 * np.pi)
    * (
        (3 * rat ** 5 + 5 * rat ** 3 + 2) / (rat ** 2 * (1 + rat ** 2) ** 2)
        + 3 * np.arctan(rat)
    )
)
Ban = np.sqrt(Gfact) * mu0 * np.sqrt(kB * T * sigma * d) / a

plt.figure(figsize=(5, 5))
Exemplo n.º 6
0
Ngrid = 21
xx = np.linspace(np.min(mesh.vertices[:, 0]), np.max(mesh.vertices[:, 0]), Ngrid)
yy = np.linspace(np.min(mesh.vertices[:, 1]), np.max(mesh.vertices[:, 1]), Ngrid)
zz = np.max(mesh.vertices[:, 2]) + np.array([0.1, 0.2, 0.3, 0.4, 0.5])
X, Y, Z = np.meshgrid(xx, yy, zz, indexing="ij")

x = X.ravel()
y = Y.ravel()
z = Z.ravel()

fp = np.vstack((x, y, z)).T


B_coupling = magnetic_field_coupling(mesh, fp, analytic=True)

Bvar = noise_var(B_coupling, vl) * 1e30

#%%

cmap = "inferno"


vmin = 1e-2
vmax = 30


levels = np.linspace(vmin, vmax, 5)

Bzcov = np.sqrt(Bvar[:, 0, 0])
Bgrid = Bzcov.reshape((Ngrid, Ngrid, 5))
Exemplo n.º 7
0
    T=T,
    resistivity=1 / sigma,
    thickness=d,
    mode="AC",
    freqs=freqs,
    return_eigenvals=False,
)

#%%
Np = 25
z = np.linspace(0.05, 1, Np)
fp = np.array((np.zeros(z.shape), np.zeros(z.shape), z)).T

B_coupling = magnetic_field_coupling(mesh, fp, analytic=True)

Bf = np.sqrt(noise_var(B_coupling, vl))

plt.figure(figsize=(5, 5))
plt.loglog(freqs, Bf[:, 2, :].T * 1e15, linewidth=2)
plt.grid()
plt.ylim(0.1, 100)
plt.gca().spines["right"].set_visible(False)
plt.gca().spines["top"].set_visible(False)
plt.legend(frameon=False)
plt.xlabel("Frequency (Hz)")
plt.ylabel(r"$B_z$ noise (fT/rHz)")
plt.tight_layout()

f_interp = np.linspace(0, 120, 500)

cutf = np.zeros(Np)
scene = mlab.figure(None,
                    bgcolor=(1, 1, 1),
                    fgcolor=(0.5, 0.5, 0.5),
                    size=(800, 800))
visualize_current_modes(mesh, vl[:, :, 0], 42, 5, contours=True)

# Define field points on z axis
Np = 30
z = np.linspace(0.1, 1, Np)
fp = np.array((np.zeros(z.shape), np.zeros(z.shape), z)).T

B_coupling = magnetic_field_coupling(mesh, fp,
                                     analytic=True)  # field coupling matrix

# Compute noise variance
B = np.sqrt(noise_var(B_coupling, vl))

# Calculate Bz noise using analytical formula and plot the results
r = 1
Ban = (mu0 * np.sqrt(sigma * d * kB * T / (8 * np.pi * z**2)) *
       (1 / (1 + z**2 / r**2)))

plt.figure()
plt.subplot(2, 1, 1)
plt.semilogy(z, Ban, label="Analytic")
plt.semilogy(z, B[:, 2, 0], "x", label="Numerical")
plt.legend(frameon=False)
plt.xlabel("Distance d/R")
plt.ylabel("DC noise Bz (T/rHz)")

plt.subplot(2, 1, 2)