Пример #1
0
def main():
    # Define spherical tiles
    tile_val = magtense.Tiles(1)

    # Define tile as spheroid
    tile_val.set_tile_type(7)
    tile_val.set_size([0.5, 2, 0.5])
    tile_val.set_offset([0.1, 0.3, 0.45])
    tile_val.set_rotation_i([np.pi / 2, -np.pi / 3, np.pi / 4], 0)
    tile_val.set_remanence(1.2 / (4 * np.pi * 1e-7))
    tile_val.set_easy_axis([[0, 1, 0]])
    tile_val.set_rot_axis_i([-2, 1, 2], 0)

    # Config for oblate spheroid
    # tile_val.set_size([2, 2, 0.5])

    # Plot geometry
    # create_plot(tile_val)

    eval_offset = [0.3, 0.45, 0.2]
    model_offset = [1, 0.75, 1]

    # Load reference points from COMSOL calculation
    COMSOL_eval_path = os.path.dirname(os.path.abspath(__file__)) \
        + '/../../documentation/examples_FEM_validation/Validation_spheroid/'

    (eval_points_x, H_norm_x_COMSOL) = load_COMSOL_eval('py_Validation_spheroid_prolate_normH_x.txt', \
        eval_offset, COMSOL_eval_path, model_offset=model_offset, unit='T')
    (eval_points_y, H_norm_y_COMSOL) = load_COMSOL_eval('py_Validation_spheroid_prolate_normH_y.txt', \
        eval_offset, COMSOL_eval_path, model_offset=model_offset, unit='T')
    (eval_points_z, H_norm_z_COMSOL) = load_COMSOL_eval('py_Validation_spheroid_prolate_normH_z.txt', \
        eval_offset, COMSOL_eval_path, model_offset=model_offset, unit='T')

    # x-axis
    (updated_tiles_x, H_x) = magtense.run_simulation(tile_val, eval_points_x)
    H_norm_x_MagTense = get_norm_magnetic_flux(H_x)

    # y-axis
    (updated_tiles_y, H_y) = magtense.run_simulation(tile_val, eval_points_y)
    H_norm_y_MagTense = get_norm_magnetic_flux(H_y)

    # z-axis
    (updated_tiles_z, H_z) = magtense.run_simulation(tile_val, eval_points_z)
    H_norm_z_MagTense = get_norm_magnetic_flux(H_z)

    fig, ax = plt.subplots(1, 3)
    fig.suptitle("SPHEROID - MagTensePython vs. COMSOL")
    add_subplot(ax[0], eval_points_x[:, 0], 'x_axis', H_norm_x_MagTense,
                H_norm_x_COMSOL)
    add_subplot(ax[1], eval_points_y[:, 1], 'y_axis', H_norm_y_MagTense,
                H_norm_y_COMSOL)
    add_subplot(ax[2], eval_points_z[:, 2], 'z_axis', H_norm_z_MagTense,
                H_norm_z_COMSOL)
    plt.show()
Пример #2
0
def valid_circ_inv():
    # Define validation tile
    tile_val = magtense.Tiles(1)
    tile_val.set_center_pos([[0.3, math.pi / 0.55, 0.6]])
    tile_val.set_dev_center([0.15, math.pi / 6, 0.4])
    tile_val.set_offset_i([0.3, 0.5, 0.1], 0)
    tile_val.set_rotation_i([0, 0, 0], 0)
    tile_val.set_tile_type(4)
    tile_val.set_remanence(1.2 / (4 * math.pi * 1e-7))
    tile_val.set_easy_axis([[0.41562694, 0.41562694, 0.80901699]])
    tile_val.set_color([[1, 0, 0]])

    eval_offset = [0.6271937452259475, 0.27251823835641853, 0.7]

    # Load reference points from COMSOL calculation
    COMSOL_eval_path = os.path.dirname(os.path.abspath(__file__)) \
        + '/../../documentation/examples_FEM_validation/Validation_circpiece_inverted/'

    (eval_points_x, H_norm_x_COMSOL) = load_COMSOL_eval(
        'Validation_circpiece_inverted_normH_x.txt', eval_offset,
        COMSOL_eval_path)
    (eval_points_y, H_norm_y_COMSOL) = load_COMSOL_eval(
        'Validation_circpiece_inverted_normH_y.txt', eval_offset,
        COMSOL_eval_path)
    (eval_points_z, H_norm_z_COMSOL) = load_COMSOL_eval(
        'Validation_circpiece_inverted_normH_z.txt', eval_offset,
        COMSOL_eval_path)

    # x-axis
    (updated_tiles_x, H_x) = magtense.run_simulation(tile_val, eval_points_x)
    H_norm_x_MagTense = get_norm_magnetic_flux(H_x)

    # y-axis
    (updated_tiles_y, H_y) = magtense.run_simulation(tile_val, eval_points_y)
    H_norm_y_MagTense = get_norm_magnetic_flux(H_y)

    # z-axis
    (updated_tiles_z, H_z) = magtense.run_simulation(tile_val, eval_points_z)
    H_norm_z_MagTense = get_norm_magnetic_flux(H_z)

    fig, ax = plt.subplots(1, 3)
    fig.suptitle("CIRCPIECE_INV - MagTensePython vs. COMSOL")
    add_subplot(ax[0], eval_points_x[:, 0], 'x_axis', H_norm_x_MagTense,
                H_norm_x_COMSOL)
    add_subplot(ax[1], eval_points_y[:, 1], 'y_axis', H_norm_y_MagTense,
                H_norm_y_COMSOL)
    add_subplot(ax[2], eval_points_z[:, 2], 'z_axis', H_norm_z_MagTense,
                H_norm_z_COMSOL)
    plt.show()
Пример #3
0
def valid_circpiece():
    # Define validation tile
    tile_val = magtense.Tiles(1)
    tile_val.set_center_pos([[0.45, math.pi / 3, 0.35]])
    tile_val.set_dev_center([0.5, math.pi / 7, 0.15])
    tile_val.set_offset_i([0.1, 0.3, 0.2], 0)
    tile_val.set_rotation_i([0, 0, 0], 0)
    tile_val.set_tile_type(3)
    tile_val.set_remanence(1.2 / (4 * math.pi * 1e-7))
    tile_val.set_easy_axis([[-0.3095974, -0.22493568, 0.92387953]])
    tile_val.set_color([[1, 0, 0]])

    eval_offset = [0.406328622087633, 0.8631363102808783, 0.55]

    # Load reference points from COMSOL calculation
    COMSOL_eval_path = os.path.dirname(os.path.abspath(__file__)) \
        + '/../../documentation/examples_FEM_validation/Validation_circpiece/'

    (eval_points_x,
     H_norm_x_COMSOL) = load_COMSOL_eval('Validation_circpiece_normH_x.txt',
                                         eval_offset, COMSOL_eval_path)
    (eval_points_y,
     H_norm_y_COMSOL) = load_COMSOL_eval('Validation_circpiece_normH_y.txt',
                                         eval_offset, COMSOL_eval_path)
    (eval_points_z,
     H_norm_z_COMSOL) = load_COMSOL_eval('Validation_circpiece_normH_z.txt',
                                         eval_offset, COMSOL_eval_path)

    # x-axis
    (updated_tiles_x, H_x) = magtense.run_simulation(tile_val, eval_points_x)
    H_norm_x_MagTense = get_norm_magnetic_flux(H_x)

    # y-axis
    (updated_tiles_y, H_y) = magtense.run_simulation(tile_val, eval_points_y)
    H_norm_y_MagTense = get_norm_magnetic_flux(H_y)

    # z-axis
    (updated_tiles_z, H_z) = magtense.run_simulation(tile_val, eval_points_z)
    H_norm_z_MagTense = get_norm_magnetic_flux(H_z)

    fig, ax = plt.subplots(1, 3)
    fig.suptitle("CIRCPIECE - MagTensePython vs. COMSOL")
    add_subplot(ax[0], eval_points_x[:, 0], 'x_axis', H_norm_x_MagTense,
                H_norm_x_COMSOL)
    add_subplot(ax[1], eval_points_y[:, 1], 'y_axis', H_norm_y_MagTense,
                H_norm_y_COMSOL)
    add_subplot(ax[2], eval_points_z[:, 2], 'z_axis', H_norm_z_MagTense,
                H_norm_z_COMSOL)
    plt.show()
Пример #4
0
def halbach():
    # Defining grid
    places = [10, 10, 1]
    area = [1, 1, 0.01]

    # Defining filled places
    filled_positions = [[i, j, 0] for i in range(10) for j in range(10) \
        if (i==5 and j==5) or (i==4 and j==5) or (i==4 and j==4) or (i==5 and j==4)]

    # Optional parameters for setup: n_magnets, filled_positions, mag_angles, eval_points, eval_mode, B_rem
    (tiles, points, grid) = magtense.setup(places, area, filled_positions=filled_positions)

    # Optimal angle - https://orbit.dtu.dk/ws/files/100219185/Analysis_of_the_magnetic_field_force_and_torque_for_two_dimensional_Halbach_cylinders.pdf
    for i in range(tiles.n):
        # Calculate angle of tile center to x-axis
        d = tiles.get_offset(i) - np.array([0.5, 0.5, 0.05])
        # r_comp = np.sqrt(d[0]**2, d[1]**2)
        angle_comp = np.arctan2(d[1], d[0])
        azimuth_opt = 2 * angle_comp
        tiles.set_mag_angle_i([np.pi / 2, azimuth_opt], i)

    # Standard parameters in settings: max_error=0.00001, max_it=500
    (updated_tiles, H) = magtense.run_simulation(tiles, points, grid=grid, plot=True)

    print("Average magnetic field: " + str(get_average_magnetic_flux(H)))
    print("Peak to peak: " + str(get_p2p(H)))
Пример #5
0
def main():
    # Define validation tile
    tile_val = magtense.Tiles(1)
    vert = np.array([[2.5, 3, 1], [2, 1, 4], [1.5, 4, 3], [4.5, 5, 2]])
    tile_val.set_vertices(vert.transpose())
    tile_val.set_tile_type(5)
    tile_val.set_remanence(1.2 / (4 * np.pi * 1e-7))
    tile_val.set_easy_axis([[0.324264068, 0.734846928, 0.891545179]])
    tile_val.set_color([[1, 0, 0]])

    eval_offset = [3, 3, 2.5]

    # Load reference points from COMSOL calculation
    COMSOL_eval_path = os.path.dirname(os.path.abspath(__file__)) \
        + '/../../documentation/examples_FEM_validation/Validation_tetrahedron/'

    (eval_points_x,
     H_norm_x_COMSOL) = load_COMSOL_eval('Validation_tetrahedron_normH_x.txt',
                                         eval_offset, COMSOL_eval_path)
    (eval_points_y,
     H_norm_y_COMSOL) = load_COMSOL_eval('Validation_tetrahedron_normH_y.txt',
                                         eval_offset, COMSOL_eval_path)
    (eval_points_z,
     H_norm_z_COMSOL) = load_COMSOL_eval('Validation_tetrahedron_normH_z.txt',
                                         eval_offset, COMSOL_eval_path)

    # x-axis
    (updated_tiles_x, H_x) = magtense.run_simulation(tile_val, eval_points_x)
    H_norm_x_MagTense = get_norm_magnetic_flux(H_x)

    # y-axis
    (updated_tiles_y, H_y) = magtense.run_simulation(tile_val, eval_points_y)
    H_norm_y_MagTense = get_norm_magnetic_flux(H_y)

    # z-axis
    (updated_tiles_z, H_z) = magtense.run_simulation(tile_val, eval_points_z)
    H_norm_z_MagTense = get_norm_magnetic_flux(H_z)

    fig, ax = plt.subplots(1, 3)
    fig.suptitle("TETRAHEDRON - MagTensePython vs. COMSOL")
    add_subplot(ax[0], eval_points_x[:, 0], 'x_axis', H_norm_x_MagTense,
                H_norm_x_COMSOL)
    add_subplot(ax[1], eval_points_y[:, 1], 'y_axis', H_norm_y_MagTense,
                H_norm_y_COMSOL)
    add_subplot(ax[2], eval_points_z[:, 2], 'z_axis', H_norm_z_MagTense,
                H_norm_z_COMSOL)
    plt.show()
Пример #6
0
def main():
    # Define spherical tiles
    tile_val = magtense.Tiles(1)

    # Define tile as sphere
    tile_val.set_tile_type(6)
    tile_val.set_size([0.25, 0, 0])
    tile_val.set_offset([0.3, 0.5, 0.1])
    tile_val.set_remanence(1.2 / (4 * np.pi * 1e-7))
    tile_val.set_easy_axis([[1, 0, -1]])

    eval_offset = [0.3, 0.4, 0.15]
    model_offset = [0.25, 0.25, 0.75]

    # Load reference points from COMSOL calculation
    COMSOL_eval_path = os.path.dirname(os.path.abspath(__file__)) \
        + '/../../documentation/examples_FEM_validation/Validation_sphere/'

    (eval_points_x, H_norm_x_COMSOL) = load_COMSOL_eval('py_Validation_sphere_normH_x.txt', \
        eval_offset, COMSOL_eval_path, model_offset=model_offset, unit='T')
    (eval_points_y, H_norm_y_COMSOL) = load_COMSOL_eval('py_Validation_sphere_normH_y.txt', \
        eval_offset, COMSOL_eval_path, model_offset=model_offset, unit='T')
    (eval_points_z, H_norm_z_COMSOL) = load_COMSOL_eval('py_Validation_sphere_normH_z.txt', \
        eval_offset, COMSOL_eval_path, model_offset=model_offset, unit='T')

    # x-axis
    (updated_tiles_x, H_x) = magtense.run_simulation(tile_val, eval_points_x)
    H_norm_x_MagTense = get_norm_magnetic_flux(H_x)

    # y-axis
    (updated_tiles_y, H_y) = magtense.run_simulation(tile_val, eval_points_y)
    H_norm_y_MagTense = get_norm_magnetic_flux(H_y)

    # z-axis
    (updated_tiles_z, H_z) = magtense.run_simulation(tile_val, eval_points_z)
    H_norm_z_MagTense = get_norm_magnetic_flux(H_z)

    fig, ax = plt.subplots(1, 3)
    fig.suptitle("SPHERE - MagTensePython vs. COMSOL")
    add_subplot(ax[0], eval_points_x[:, 0], 'x_axis', H_norm_x_MagTense,
                H_norm_x_COMSOL)
    add_subplot(ax[1], eval_points_y[:, 1], 'y_axis', H_norm_y_MagTense,
                H_norm_y_COMSOL)
    add_subplot(ax[2], eval_points_z[:, 2], 'z_axis', H_norm_z_MagTense,
                H_norm_z_COMSOL)
    plt.show()
Пример #7
0
def basic_geometries():
    # Define all tiles
    all_tiles = magtense.Tiles(6)
    all_tiles.set_remanence(1.2 / (4 * np.pi * 1e-7))
    all_tiles.set_tile_type([2, 1, 3, 4, 5, 7])
    all_tiles.set_mag_angle_rand()

    # 0: Prism
    all_tiles.set_size_i([0.1, 0.3, 0.2], 0)
    all_tiles.set_offset_i([0.1, 0.2, 0.1], 0)
    all_tiles.set_color_i([1, 0, 0], 0)

    # 1: Cylindrical Tiles
    all_tiles.set_center_pos_i([1, 0, 0.3], 1)
    all_tiles.set_dev_center_i([0.15, np.pi / 9, 0.3], 1)
    all_tiles.set_color_i([0, 0, 1], 1)

    # 2: Circpiece
    all_tiles.set_center_pos_i([0.85, np.pi / 5, 1.2], 2)
    all_tiles.set_dev_center_i([0.15, np.pi / 7, 0.25], 2)
    all_tiles.set_color_i([1, 0.5, 0], 2)

    # 3: Inverted Circpiece
    all_tiles.set_center_pos_i([0.2, np.pi / 6, 0.75], 3)
    all_tiles.set_dev_center_i([0.05, np.pi / 4, 0.4], 3)
    all_tiles.set_color_i([0.3, 0.8, 0.2], 3)

    # 4: Tetrahedron
    all_tiles.set_vertices_i(
        np.array([[0.65, 0.9, 0.5], [0.8, 0.9, 0.7], [0.85, 0.55, 0.25],
                  [0.95, 0.85, 0.15]]), 4)
    all_tiles.set_color_i([0, 0, 0], 4)

    # 5: Prolate Spheroid
    all_tiles.set_size_i([0.1, 0.3, 0.1], 5)
    all_tiles.set_offset_i([0.1, 0.6, 0.7], 5)
    all_tiles.set_rot_axis_i([0, 0, 2], 5)
    all_tiles.set_color_i([1, 0, 1], 5)

    area = [0.9, 1, 0.8]
    n_points = [1, 100, 80]
    seg = area / np.asarray(n_points)
    points = [[
        i * seg[0] + seg[0] / 2, j * seg[1] + seg[1] / 2,
        k * seg[2] + seg[2] / 2
    ] for i in range(0, n_points[0]) for j in range(0, n_points[1])
              for k in range(0, n_points[2])]
    points = np.asarray(points, dtype=np.float64, order='F')

    # Simulation
    (updated_tiles, H) = magtense.run_simulation(all_tiles, points, plot=False)

    # Plotting
    create_plot(updated_tiles, H=H, eval_points=points)
Пример #8
0
def valid_prism():
    # Define validation tile
    eval_offset = [0.5, 0.4, 0.1]

    tile_val = magtense.Tiles(1)
    tile_val.set_size([[0.6, 0.1, 0.3]])
    tile_val.set_offset_i(eval_offset,0)
    tile_val.set_rotation_i([math.pi/2, -math.pi/3, math.pi/4],0)
    tile_val.set_tile_type(2)
    tile_val.set_remanence(1.2 / (4*math.pi*1e-7))
    tile_val.set_easy_axis([[0.35355339, 0.61237244, 0.70710678]])
    tile_val.set_color([[1, 0, 0]])

    # Load reference points from COMSOL calculation
    COMSOL_eval_path = os.path.dirname(os.path.abspath(__file__)) + '/../../documentation/examples_FEM_validation/Validation_prism/'

    (eval_points_x, H_norm_x_COMSOL) = load_COMSOL_eval('Validation_prism_normH_x.txt', eval_offset, COMSOL_eval_path)
    (eval_points_y, H_norm_y_COMSOL) = load_COMSOL_eval('Validation_prism_normH_y.txt', eval_offset, COMSOL_eval_path)
    (eval_points_z, H_norm_z_COMSOL) = load_COMSOL_eval('Validation_prism_normH_z.txt', eval_offset, COMSOL_eval_path)
    
    # x-axis
    (updated_tiles_x, H_x) = magtense.run_simulation(tile_val, eval_points_x)
    H_norm_x_MagTense  = get_norm_magnetic_flux(H_x)
    
    # y-axis
    (updated_tiles_y, H_y) = magtense.run_simulation(tile_val, eval_points_y)
    H_norm_y_MagTense  = get_norm_magnetic_flux(H_y)

    # z-axis
    (updated_tiles_z, H_z) = magtense.run_simulation(tile_val, eval_points_z)
    H_norm_z_MagTense  = get_norm_magnetic_flux(H_z)

    fig, ax = plt.subplots(1,3)
    fig.suptitle("PRISM - MagTensePython vs. COMSOL")
    add_subplot(ax[0], eval_points_x[:,0], 'x_axis', H_norm_x_MagTense, H_norm_x_COMSOL)
    add_subplot(ax[1], eval_points_y[:,1], 'y_axis', H_norm_y_MagTense, H_norm_y_COMSOL)
    add_subplot(ax[2], eval_points_z[:,2], 'z_axis', H_norm_z_MagTense, H_norm_z_COMSOL)
    plt.show()
Пример #9
0
def prism_multiple(n_mag=1, soft=None, res=16, x_max=1, y_max=1, z_max=1):
    mu0 = 4 * np.pi * 1e-7
    a = 0.1
    b = 0.3
    c = 0.2
    
    if soft is None: soft = [0 for _ in range(n_mag)]

    prism = magtense.Tiles(n_mag)
    prism.set_tile_type(2)

    for i in range(n_mag):
        # Relative permeability
        if soft == 1:
            prism.set_mu_r_ea_i(4000, i)
            prism.set_mu_r_oa_i(4000, i)
            prism.set_remanence_i(0, i)
            prism.set_mag_type_i(2, i)

            # Default: Easy axis in direction of x-axis
            # [polar angle, azimuthal angle]
            prism.set_mag_angle_i([np.pi/2, 0], i)

        else:
            prism.set_mu_r_ea_i(1.06, i)
            prism.set_mu_r_oa_i(1.17, i)

            # Set remanence in [A/m]
            prism.set_remanence_i(1.2 / mu0, i)

            # Default: Easy axis in direction of x-axis
            # [polar angle, azimuthal angle]
            prism.set_mag_angle_i([np.random.rand() * np.pi, np.random.rand() * 2 * np.pi], i)

        prism.set_size_i([a, b, c], i) 
        prism.set_offset_i([0.1 + i*0.5, 0.2 + i*0.5, 0.1 + i*0.5], i)
        prism.set_mag_angle_rand()
        prism.set_color_i([i / n_mag, 0, 0], i)

    x_eval = np.linspace(0, x_max, res)
    y_eval = np.linspace(0, y_max, res)
    z_eval = np.linspace(0, z_max, res)
    xv, yv, zv = np.meshgrid(x_eval, y_eval, z_eval)
    pts_eval = np.hstack([xv.reshape(-1,1), yv.reshape(-1,1), zv.reshape(-1,1)])

    # Simulation
    (updated_tiles, H) = magtense.run_simulation(prism, pts_eval, plot=False)

    # Plotting
    create_plot(updated_tiles, H=H, eval_points=pts_eval)
Пример #10
0
def prism_grid():
    # Defining grid
    places = [10, 10, 5]
    area = [1, 1, 0.5]

    # Defining filled places
    filled_positions = [[4, 3, 4], [1, 2, 2], [3, 1, 0], [2, 7, 2], [8, 9, 3]]

    # Optional parameters for setup: n_magnets, filled_positions, mag_angles, eval_points, eval_mode, B_rem
    (tiles, points, grid) = magtense.setup(places, area, filled_positions=filled_positions, eval_points=[10, 10, 5])

    # Standard parameters in settings: max_error=0.00001, max_it=500
    (updated_tiles, H) = magtense.run_simulation(tiles, points, grid=grid, plot=True)

    print("Average magnetic field: " + str(get_average_magnetic_flux(H)))
    print("Peak to peak: " + str(get_p2p(H)))
Пример #11
0
def spheroid():
    # Define spherical tiles
    spheroids = magtense.Tiles(3)

    # Defines first tile as sphere
    spheroids.set_tile_type_i(6, 0)
    spheroids.set_size_i([0.3, 0, 0], 0)
    spheroids.set_offset_i([1, 1, 1], 0)
    spheroids.set_remanence_i(1 / (4 * np.pi * 1e-7), 0)
    spheroids.set_easy_axis_i([1, 0, -1], 0)
    spheroids.set_color_i([1, 0, 0], 0)

    # Defines second tile as oblate spheroid
    spheroids.set_tile_type_i(7, 1)
    spheroids.set_size_i([0.1, 0.5, 0.5], 1)
    spheroids.set_offset_i([1, 2.5, 1], 1)
    spheroids.set_remanence_i(1 / (4 * np.pi * 1e-7), 1)
    spheroids.set_easy_axis_i([-1, 1, 0], 1)
    spheroids.set_rot_axis_i([-1, 1, -3], 1)
    spheroids.set_color_i([1, 0, 1], 1)

    # Defines thrid tile as prolate spheroid
    spheroids.set_tile_type_i(7, 2)
    spheroids.set_size_i([0.2, 0.5, 0.2], 2)
    spheroids.set_offset_i([2, 1, 1.5], 2)
    spheroids.set_remanence_i(1 / (4 * np.pi * 1e-7), 2)
    spheroids.set_easy_axis_i([1, 1, 1], 2)
    spheroids.set_rot_axis_i([1, 1, 1], 2)
    spheroids.set_color_i([0, 0, 1], 2)

    # Defining the points, where the field is evaluated (output)
    area = [3, 3, 3]
    n_points = [7, 7, 7]
    seg = area / np.asarray(n_points)
    points = [[
        i * seg[0] + seg[0] / 2, j * seg[1] + seg[1] / 2,
        k * seg[2] + seg[2] / 2
    ] for i in range(0, n_points[0]) for j in range(0, n_points[1])
              for k in range(0, n_points[2])]
    points = np.asarray(points, dtype=np.float64, order='F')

    # Standard parameters in settings: max_error=0.00001, max_it=500
    (updated_tiles, H) = magtense.run_simulation(spheroids, points, plot=True)

    print("Average magnetic field: " + str(get_average_magnetic_flux(H)))
    print("Peak to peak: " + str(get_p2p(H)))