Ejemplo n.º 1
0
def make_grid_1():
    """
    Returns a CavityGrid object of a solid with one cavity at the
    center.
    """
    inner_walls = []
    inner_walls.append(
        shapes.cube(length=2.5, h=ELEMENT_SIZE,
                    origin=(-1.25, -1 / 2, -1.25)), )
    outer_wall = shapes.cube(length=3,
                             h=ELEMENT_SIZE,
                             origin=(-1.5, -1.5, -1.5))
    return bempp_cavity.create_grid(outer_wall, *inner_walls)
Ejemplo n.º 2
0
def make_grid_9():
    """
    Returns a CavityGrid object of a solid with nine cavities within
    arranged in a 3x3 grid.
    """
    cavity_length = 0.65
    inner_walls = [
        # 1
        shapes.cube(length=cavity_length,
                    h=ELEMENT_SIZE,
                    origin=(-1.25, -1 / 2, -1.25)),
        # 2
        shapes.cube(length=cavity_length,
                    h=ELEMENT_SIZE,
                    origin=(-cavity_length / 2, -1 / 2, -1.25)),
        # 3
        shapes.cube(length=cavity_length,
                    h=ELEMENT_SIZE,
                    origin=(0.6, -1 / 2, -1.25)),
        # 4
        shapes.cube(length=cavity_length,
                    h=ELEMENT_SIZE,
                    origin=(-1.25, -1 / 2, -cavity_length / 2)),
        # 5
        shapes.cube(length=cavity_length,
                    h=ELEMENT_SIZE,
                    origin=(-cavity_length / 2, -1 / 2, -cavity_length / 2)),
        # 6
        shapes.cube(length=cavity_length,
                    h=ELEMENT_SIZE,
                    origin=(0.6, -1 / 2, -cavity_length / 2)),
        # 7
        shapes.cube(length=cavity_length,
                    h=ELEMENT_SIZE,
                    origin=(-1.25, -1 / 2, 0.575)),
        # 8
        shapes.cube(length=cavity_length,
                    h=ELEMENT_SIZE,
                    origin=(-cavity_length / 2, -1 / 2, 0.575)),
        # 9
        shapes.cube(length=cavity_length,
                    h=ELEMENT_SIZE,
                    origin=(0.6, -1 / 2, 0.575)),
    ]
    outer_wall = shapes.cube(length=3,
                             h=ELEMENT_SIZE,
                             origin=(-1.5, -1.5, -1.5))
    return bempp_cavity.create_grid(outer_wall, *inner_walls)
Ejemplo n.º 3
0
def make_grid_4():
    """
    Returns a CavityGrid object of a solid with four cavities within it
    arranged in a square.
    """
    inner_walls = [
        shapes.cube(length=1.125,
                    h=ELEMENT_SIZE,
                    origin=(-1.25, -1 / 2, -1.25)),
        shapes.cube(length=1.125,
                    h=ELEMENT_SIZE,
                    origin=(0.125, -1 / 2, -1.25)),
        shapes.cube(length=1.125,
                    h=ELEMENT_SIZE,
                    origin=(-1.25, -1 / 2, 0.125)),
        shapes.cube(length=1.125,
                    h=ELEMENT_SIZE,
                    origin=(0.125, -1 / 2, 0.125)),
    ]
    outer_wall = shapes.cube(length=3,
                             h=ELEMENT_SIZE,
                             origin=(-1.5, -1.5, -1.5))
    return bempp_cavity.create_grid(outer_wall, *inner_walls)
Ejemplo n.º 4
0
def test_laplace_p1_segments_complex_coeffs(default_parameters, helpers,
                                            device_interface, precision):
    """Test P1 potential evaluation on segments with complex coeffs."""

    from bempp.api.shapes import cube
    from bempp.api import function_space
    from bempp.api import GridFunction
    from bempp.api.operators.potential.laplace import single_layer

    grid = cube()
    seg1 = function_space(grid,
                          "P",
                          1,
                          segments=[1, 2, 3],
                          include_boundary_dofs=False)
    seg2 = function_space(
        grid,
        "P",
        1,
        segments=[4, 5, 6],
        include_boundary_dofs=True,
        truncate_at_segment_edge=False,
    )
    seg_all = function_space(grid, "DP", 1)

    random = _np.random.RandomState(0)

    coeffs1 = random.rand(
        seg1.global_dof_count) + 1j * random.rand(seg1.global_dof_count)
    coeffs2 = random.rand(
        seg2.global_dof_count) + 1j * random.rand(seg2.global_dof_count)
    coeffs_all = seg1.map_to_full_grid.dot(
        coeffs1) + seg2.map_to_full_grid.dot(coeffs2)

    points = 1.6 * _np.ones((3, 1)) + 0.5 * _np.random.rand(3, 20)

    fun1 = GridFunction(seg1, coefficients=coeffs1)
    fun2 = GridFunction(seg2, coefficients=coeffs2)
    fun_all = GridFunction(seg_all, coefficients=coeffs_all)

    seg1_res = single_layer(
        seg1,
        points,
        parameters=default_parameters,
        precision=precision,
        device_interface=device_interface,
    ).evaluate(fun1)

    seg2_res = single_layer(
        seg2,
        points,
        parameters=default_parameters,
        precision=precision,
        device_interface=device_interface,
    ).evaluate(fun2)

    seg_all_res = single_layer(
        seg_all,
        points,
        parameters=default_parameters,
        precision=precision,
        device_interface=device_interface,
    ).evaluate(fun_all)

    actual = seg1_res + seg2_res
    expected = seg_all_res

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