Пример #1
0
def calculate_cavity_fields(solution, points, cavity_indexers, domains):
    """
    Return the value of a cavity's field, calculated from the trace data.
    """
    # cavities
    E_pot_cavities = []
    H_pot_cavities = []
    # print(cavity_indexers)
    for i in range(solution.system.N-1):
        
        cavity_points = points[:, cavity_indexers[i]] # [:, :, 0]
        H_pot_cavities.append(
            maxwell_potential.magnetic_field(
                domains[2*i], cavity_points, solution.system.wave_numbers[i+2]
            )
        )
        E_pot_cavities.append(
            maxwell_potential.electric_field(
                domains[2*i+1], cavity_points, solution.system.wave_numbers[i+2]
            )
        )
    # fields
    ## cavities
    cavity_fields = [
        H_pot_cavities[i] * solution.traces[2*i] \
            + E_pot_cavities[i] * \
                (solution.system.mu_numbers[2+i]/solution.system.wave_numbers[2+i] * \
                    solution.traces[2*i+1])
        for i, _ in enumerate(solution.system.cavity_grid.cavities)
    ]
    return cavity_fields
Пример #2
0
def test_maxwell_magnetic_field_potential_rwg(default_parameters, helpers,
                                              device_interface, precision):
    """Test Maxwell magnetic potential."""
    from bempp.api import function_space
    from bempp.api import GridFunction
    from bempp.api.operators.potential.maxwell import magnetic_field

    grid = helpers.load_grid("sphere")
    space = function_space(grid, "RWG", 0)

    data = helpers.load_npz_data("maxwell_magnetic_field_potential")

    coefficients = data["vec"]
    points = data["points"]
    expected = data["result"]

    fun = GridFunction(space, coefficients=coefficients)

    actual = magnetic_field(
        space,
        points,
        WAVENUMBER,
        parameters=default_parameters,
        precision=precision,
        device_interface=device_interface,
    ).evaluate(fun)

    _np.testing.assert_allclose(actual,
                                expected,
                                rtol=helpers.default_tolerance(precision))
Пример #3
0
def calculate_scattered_field(points, exterior_indexer, domains, solution):
    """
    Return the value of the scattered field, calculated from the trace data.
    """
    exterior_points = points[:, exterior_indexer] # [:, :, 0]
    H_pot_ext = maxwell_potential.magnetic_field(
        domains[-2], exterior_points, solution.system.wave_numbers[0]
    )
    E_pot_ext = maxwell_potential.magnetic_field(
        domains[-1], exterior_points, solution.system.wave_numbers[0]
    )
    scattered_field = - H_pot_ext * solution.traces[-2] \
        - E_pot_ext * (
            solution.system.mu_numbers[0]/solution.system.wave_numbers[0] * solution.traces[-1]
        )
    return scattered_field
Пример #4
0
def calculate_cavity_fields_weak(solution, points, cavity_indexers, domains, traces):
    """
    Return the value of a cavity field, calculated from the trace data.
    """
    E_pot_cavities = []
    H_pot_cavities = []
    # print(cavity_indexers)
    for i in range(solution.system.N-1):
        cavity_points = points[:, cavity_indexers[i]] # [:, :, 0]
        H_pot_cavities.append(
            maxwell_potential.magnetic_field(
                domains[i], cavity_points, solution.system.wave_numbers[i+2]
            )
        )
        E_pot_cavities.append(
            maxwell_potential.electric_field(
                domains[i], cavity_points, solution.system.wave_numbers[i+2]
            )
        )
    ## cavities
    cavity_fields = [
        H_pot_cavities[i] * trace.dirichlet \
            + E_pot_cavities[i] * \
                (solution.system.mu_numbers[2+i]/solution.system.wave_numbers[2+i] * \
                    trace.neumann)
        for i, trace in enumerate(traces)
    ]
    return cavity_fields
Пример #5
0
def calculate_wall_field(solution, points, wall_indexer, domains, wall_dTrace, wall_nTrace):
    """
    Return the value of the field in the wall, calculated from the trace data.
    """

    # wall
    wall_points = points[:, wall_indexer]
    H_pot_wall = maxwell_potential.magnetic_field(
        domains[-2], wall_points, solution.system.wave_numbers[1])
    E_pot_wall = maxwell_potential.electric_field(
        domains[-1], wall_points, solution.system.wave_numbers[1])

    H_pot_cavities = []
    E_pot_cavities = []
    
    # Influence of cavity
    for i in range(solution.system.N-1):
        H_pot_cavities.append(
            maxwell_potential.magnetic_field(
                domains[2*i], wall_points, solution.system.wave_numbers[1])
        )
        E_pot_cavities.append(
            maxwell_potential.electric_field(
                domains[2*i+1], wall_points, solution.system.wave_numbers[1])
        )

    cavity_contribution = sum([
        H_pot_cavities[i] * solution.traces[2*i] \
            + E_pot_cavities[i] * (
                solution.system.mu_numbers[2+i]/solution.system.wave_numbers[2+i] \
                    * solution.traces[2*i+1]
            )
        for i in range(solution.system.N-1)
    ])
    
    wall_field = H_pot_wall * wall_dTrace + E_pot_wall * (solution.system.mu_numbers[1]/solution.system.wave_numbers[1] \
        * wall_nTrace) - cavity_contribution
    return wall_field
Пример #6
0
def calculate_wall_field_weak(solution, points, wall_indexer, domains, trace_wall, trace_cavities):
    """
    Return the value of the field within the wall, calculated from the trace data.
    """
    # wall
    wall_points = points[:, wall_indexer]
    kw = solution.system.wave_numbers[-1]
    mw = solution.system.wave_numbers[-1]
    H_pot_w = maxwell_potential.magnetic_field(domains[-1], wall_points, kw)
    E_pot_w = maxwell_potential.electric_field(domains[-1], wall_points, kw)

    H_pot_c = []
    E_pot_c = []
    kc_list = []
    mu_list = []
    for i in range(solution.system.N-1):
        kc = solution.system.wave_numbers[i+2]
        kc_list.append(kc)
        mu_list.append(solution.system.mu_numbers[i+2])
        H_pot_c.append(
            maxwell_potential.magnetic_field(
                domains[i], wall_points, kc
            )
        )
        E_pot_c.append(
            maxwell_potential.electric_field(
                domains[i], wall_points, kc
            )
        )
    
    wall_field = H_pot_w * trace_wall.dirichlet + E_pot_w * (mw/kw * trace_wall.neumann) \
        + sum([
            H_pot_c[i] * trace_cavities[i].dirichlet \
                + E_pot_c[i] * (mu_list[i]/kc_list[i] * trace_cavities[i].neumann)
        ])
    return wall_field
Пример #7
0
def calculate_scattered_field_weak(solution, points, exterior_indexer, domains, trace_wall):
    """
    Return the value of the scattered field, calculated from the trace data.
    """
    exterior_points = points[:, exterior_indexer]
    H_pot = maxwell_potential.magnetic_field(
        domains[-1], exterior_points, solution.system.wave_numbers[0]
    )
    E_pot = maxwell_potential.electric_field(
        domains[-1], exterior_points, solution.system.wave_numbers[0]
    )
    k = solution.system.wave_numbers[0]
    mu = solution.system.mu_numbers[0]
    scattered_field = - H_pot * trace_wall.dirichlet - E_pot * (mu/k * trace_wall.neumann)
    return scattered_field