コード例 #1
0
ファイル: model.py プロジェクト: sheeshee/MSc-Project-Code
def get_simple_block_op(base, target, k, mu, parameters, space_group):
    """
    Return a 2x2 block operator defining the block matrix that would
    act on the given grid.
    
    This is similar to the `multitrace_operator` constructor, but it
    allows us to specify exactly which boundary discretize functions
    to use.
    """
    if space_group == "default":
        domain_space = OP_DOM
        dual_space = OP_DUA
    elif space_group == "preconditioner":
        domain_space = PR_DOM
        dual_space = PR_DUA
    else:
        raise NotImplementedError("Unsupported space group %s" % space_group)
    efie = maxwell.electric_field(base[domain_space],
                                  target[domain_space],
                                  target[dual_space],
                                  k,
                                  parameters=parameters)
    mfie = maxwell.magnetic_field(base[domain_space],
                                  target[domain_space],
                                  target[dual_space],
                                  k,
                                  parameters=parameters)
    A = to_block_op(mfie, efie, k, mu)
    return A
コード例 #2
0
def test_maxwell_electric_field_sphere(default_parameters, helpers,
                                       device_interface, precision):
    """Test Maxwell electric field on sphere."""
    from bempp.api import function_space
    from bempp.api.operators.boundary.maxwell import electric_field

    grid = helpers.load_grid("sphere")

    space1 = function_space(grid, "RWG", 0)
    space2 = function_space(grid, "SNC", 0)

    discrete_op = electric_field(
        space1,
        space1,
        space2,
        2.5,
        assembler="dense",
        device_interface=device_interface,
        precision=precision,
        parameters=default_parameters,
    ).weak_form()

    if precision == "single":
        rtol = 1e-5
        atol = 1e-7
    else:
        rtol = 1e-10
        atol = 1e-14

    expected = helpers.load_npy_data("maxwell_electric_field_boundary")
    _np.testing.assert_allclose(discrete_op.A, expected, rtol=rtol, atol=atol)
コード例 #3
0
def test_maxwell_electric_field_complex_sphere_evaluator(
        default_parameters, helpers, device_interface, precision):
    """Test Maxwell electric field evaluator on sphere with complex wavenumber."""
    from bempp.api import get_precision
    from bempp.api import function_space
    from bempp.api.operators.boundary.maxwell import electric_field

    grid = helpers.load_grid("sphere")

    space1 = function_space(grid, "RWG", 0)
    space2 = function_space(grid, "SNC", 0)

    discrete_op = electric_field(
        space1,
        space1,
        space2,
        2.5 + 1j,
        assembler="dense_evaluator",
        device_interface=device_interface,
        precision=precision,
        parameters=default_parameters,
    ).weak_form()

    mat = electric_field(
        space1,
        space1,
        space2,
        2.5 + 1j,
        assembler="dense",
        device_interface=device_interface,
        precision=precision,
        parameters=default_parameters,
    ).weak_form()

    x = _np.random.RandomState(0).randn(space1.global_dof_count)

    actual = discrete_op @ x
    expected = mat @ x

    if precision == "single":
        tol = 1e-4
    else:
        tol = 1e-12

    _np.testing.assert_allclose(actual, expected, rtol=tol)
コード例 #4
0
ファイル: test_maxwell.py プロジェクト: evantwout/bempp
    def test_compound_electric_field_operator_agrees_with_standard_electric_field_operator(self):
        from bempp.api.operators.boundary.maxwell import electric_field
        import numpy as np

        parameters = bempp.api.common.global_parameters()
        parameters.assembly.boundary_operator_assembly_type = 'dense'

        standard_efie = electric_field(self._space, self._space, self._space,
                                       WAVE_NUMBER,
                                       parameters=parameters).weak_form()
        compound_efie = electric_field(self._space, self._space, self._space,
                                       WAVE_NUMBER,
                                       parameters=parameters, use_slp=True).weak_form()

        mat1 = bempp.api.as_matrix(standard_efie)
        mat2 = bempp.api.as_matrix(compound_efie)

        self.assertAlmostEqual(np.linalg.norm(mat1 - mat2) / np.linalg.norm(mat1), 0)
コード例 #5
0
def test_maxwell_electric_field_rbc_bc_sphere(default_parameters, helpers,
                                              device_interface, precision,
                                              skip):
    """Test Maxwell electric field on sphere with RBC/BC basis."""
    if skip == "circleci":
        pytest.skip()

    import bempp.api
    from bempp.api import function_space
    from bempp.api.operators.boundary.maxwell import electric_field

    grid = helpers.load_grid("sphere")

    space1 = function_space(grid, "BC", 0)
    space2 = function_space(grid, "RBC", 0)

    rand = _np.random.RandomState(0)
    vec = rand.rand(space1.global_dof_count)

    bempp.api.GLOBAL_PARAMETERS.fmm.dense_evaluation = True

    discrete_op = electric_field(
        space1,
        space1,
        space2,
        2.5,
        assembler="fmm",
        device_interface=device_interface,
        precision=precision,
        parameters=default_parameters,
    ).weak_form()

    actual = discrete_op @ vec

    bempp.api.GLOBAL_PARAMETERS.fmm.dense_evaluation = False

    if precision == "single":
        rtol = 5e-5
        atol = 5e-6
    else:
        rtol = 1e-10
        atol = 1e-14

    mat = helpers.load_npy_data("maxwell_electric_field_boundary_rbc_bc")

    expected = mat @ vec

    _np.testing.assert_allclose(actual, expected, rtol=rtol, atol=atol)

    bempp.api.clear_fmm_cache()
コード例 #6
0
def maxwell_electric_field_dense_large_benchmark(benchmark,
                                                 default_parameters):
    """Maxwell electric field benchmark on large grid."""
    from bempp.api.operators.boundary.maxwell import electric_field
    from bempp.api import function_space

    grid = bempp.api.shapes.regular_sphere(5)
    space = function_space(grid, "RWG", 0)

    wavenumber = 2.5

    fun = lambda: electric_field(
        space,
        space,
        space,
        wavenumber,
        assembler="dense",
        parameters=default_parameters,
    ).weak_form()

    benchmark(fun)
コード例 #7
0
def test_maxwell_electric_field_bc_sphere(default_parameters, helpers,
                                          device_interface, precision):
    """Test Maxwell electric field on sphere with BC basis."""
    from bempp.api import get_precision
    from bempp.api import function_space
    from bempp.api.operators.boundary.maxwell import electric_field

    grid = helpers.load_grid("sphere")

    space1 = function_space(grid, "BC", 0)
    space2 = function_space(grid, "SNC", 0)

    rand = _np.random.RandomState(0)
    vec = rand.rand(space1.global_dof_count)

    discrete_op = electric_field(
        space1,
        space1,
        space2,
        2.5,
        assembler="dense_evaluator",
        device_interface=device_interface,
        precision=precision,
        parameters=default_parameters,
    ).weak_form()

    actual = discrete_op @ vec

    if precision == "single":
        rtol = 1e-5
        atol = 1e-6
    else:
        rtol = 1e-10
        atol = 1e-14

    mat = helpers.load_npy_data("maxwell_electric_field_boundary_bc")

    expected = mat @ vec

    _np.testing.assert_allclose(actual, expected, rtol=rtol, atol=atol)