コード例 #1
0
def test_maxwell_far_field_segments(default_parameters, helpers,
                                    device_interface, precision):
    """Test Maxwell far field on segments."""
    import bempp.api
    from bempp.api import function_space
    from bempp.api.operators.far_field.maxwell import electric_field
    from bempp.api.operators.far_field.maxwell import magnetic_field
    from bempp.api.grid.grid import grid_from_segments

    grid = bempp.api.shapes.multitrace_cube()

    seglists = [[1, 2, 3, 4, 5, 6], [6, 7, 8, 9, 10, 11]]
    swapped_normal_lists = [{}, {6}]

    rand = _np.random.RandomState(0)
    points = rand.randn(3, 10)
    points /= _np.linalg.norm(points, axis=0)

    for op in [electric_field, magnetic_field]:
        for seglist, swapped_normals in zip(seglists, swapped_normal_lists):
            new_grid = grid_from_segments(grid, seglist)

            coeffs = rand.rand(new_grid.number_of_edges)

            space1 = function_space(
                grid,
                "RWG",
                0,
                segments=seglist,
                swapped_normals=swapped_normals,
                include_boundary_dofs=True,
            )
            space2 = function_space(new_grid,
                                    "RWG",
                                    0,
                                    swapped_normals=swapped_normals)

            fun1 = bempp.api.GridFunction(space1, coefficients=coeffs)
            fun2 = bempp.api.GridFunction(space2, coefficients=coeffs)

            actual = (op(
                space1,
                points,
                2.5,
                parameters=default_parameters,
                precision=precision,
                device_interface=device_interface,
            ) * fun1)
            expected = (op(
                space2,
                points,
                2.5,
                parameters=default_parameters,
                precision=precision,
                device_interface=device_interface,
            ) * fun2)

            _np.testing.assert_allclose(
                actual, expected, rtol=helpers.default_tolerance(precision))
コード例 #2
0
def test_helmholtz_far_field_segments_complex_coeffs(default_parameters,
                                                     helpers, device_interface,
                                                     precision):
    """Test Maxwell potentials on segments with complex coeffs."""
    import bempp.api
    from bempp.api import function_space
    from bempp.api.operators.far_field.helmholtz import single_layer
    from bempp.api.operators.far_field.helmholtz import double_layer
    from bempp.api.grid.grid import grid_from_segments

    grid = bempp.api.shapes.multitrace_cube()

    seglists = [[1, 2, 3, 4, 5, 6], [6, 7, 8, 9, 10, 11]]
    swapped_normal_lists = [{}, {6}]

    rand = _np.random.RandomState(0)
    points = rand.randn(3, 10)
    points /= _np.linalg.norm(points, axis=0)

    for op in [single_layer, double_layer]:
        for seglist, swapped_normals in zip(seglists, swapped_normal_lists):
            new_grid = grid_from_segments(grid, seglist)

            coeffs = rand.rand(new_grid.number_of_vertices) + 1j * rand.rand(
                new_grid.number_of_vertices)

            space1 = function_space(
                grid,
                "P",
                1,
                segments=seglist,
                swapped_normals=swapped_normals,
                include_boundary_dofs=True,
            )
            space2 = function_space(new_grid,
                                    "P",
                                    1,
                                    swapped_normals=swapped_normals)

            fun1 = bempp.api.GridFunction(space1, coefficients=coeffs)
            fun2 = bempp.api.GridFunction(space2, coefficients=coeffs)

            actual = (op(
                space1,
                points,
                2.5,
                device_interface=device_interface,
                precision=precision,
            ) * fun1)
            expected = (op(
                space2,
                points,
                2.5,
                device_interface=device_interface,
                precision=precision,
            ) * fun2)

            _np.testing.assert_allclose(
                actual, expected, rtol=helpers.default_tolerance(precision))
コード例 #3
0
def test_helmholtz_potentials_segments(default_parameters, helpers,
                                       device_interface, precision):
    """Test Helmholtz potentials on segments."""
    import bempp.api
    from bempp.api import function_space
    from bempp.api.operators.potential.helmholtz import single_layer
    from bempp.api.operators.potential.helmholtz import double_layer
    from bempp.api.grid.grid import grid_from_segments

    grid = bempp.api.shapes.multitrace_cube()

    seglists = [[1, 2, 3, 4, 5, 6], [6, 7, 8, 9, 10, 11]]
    swapped_normal_lists = [{}, {6}]

    rand = _np.random.RandomState(0)

    for op in [single_layer, double_layer]:
        for seglist, swapped_normals in zip(seglists, swapped_normal_lists):
            new_grid = grid_from_segments(grid, seglist)

            coeffs = rand.rand(new_grid.number_of_vertices)

            space1 = function_space(
                grid,
                "P",
                1,
                segments=seglist,
                swapped_normals=swapped_normals,
                include_boundary_dofs=True,
            )
            space2 = function_space(new_grid,
                                    "P",
                                    1,
                                    swapped_normals=swapped_normals)

            points = _np.array([2.3, 1.3, 1.5]).reshape(3, 1) + rand.rand(3, 5)
            fun1 = bempp.api.GridFunction(space1, coefficients=coeffs)
            fun2 = bempp.api.GridFunction(space2, coefficients=coeffs)

            actual = op(space1, points, 2.5) * fun1
            expected = op(space2, points, 2.5) * fun2

            _np.testing.assert_allclose(
                actual, expected, rtol=helpers.default_tolerance(precision))