Beispiel #1
0
def test_helmholtz_single_layer_potential_p1_complex_coeffs(
        default_parameters, helpers, device_interface, precision):
    """Test Helmholtz slp potential with p1 basis and complex coeffs."""
    from bempp.api import function_space
    from bempp.api import GridFunction
    from bempp.api.operators.potential.helmholtz import single_layer

    grid = helpers.load_grid("sphere")
    space = function_space(grid, "P", 1)

    data = helpers.load_npz_data("helmholtz_single_layer_potential_p1")

    points = data["points"]
    coefficients = _np.random.rand(
        space.global_dof_count) + 1j * _np.random.rand(space.global_dof_count)

    fun = GridFunction(space, coefficients=coefficients)
    fun_real = GridFunction(space, coefficients=_np.real(coefficients))
    fun_complex = GridFunction(space, coefficients=_np.imag(coefficients))

    op = single_layer(
        space,
        points,
        WAVENUMBER,
        parameters=default_parameters,
        precision=precision,
        device_interface=device_interface,
    )

    expected = op.evaluate(fun_real) + 1j * op.evaluate(fun_complex)
    actual = op.evaluate(fun)

    _np.testing.assert_allclose(actual,
                                expected,
                                rtol=helpers.default_tolerance(precision))
Beispiel #2
0
def test_helmholtz_single_layer_potential_p1(default_parameters, helpers,
                                             device_interface, precision):
    """Test Helmholtz slp potential with p1 basis."""
    from bempp.api import function_space
    from bempp.api import GridFunction
    from bempp.api.operators.potential.helmholtz import single_layer

    grid = helpers.load_grid("sphere")
    space = function_space(grid, "P", 1)

    data = helpers.load_npz_data("helmholtz_single_layer_potential_p1")

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

    fun = GridFunction(space, coefficients=coefficients)

    actual = single_layer(
        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))
Beispiel #3
0
def plot_me(points):
    from bempp.api.operators.potential import helmholtz as helmholtz_potential
    slp_pot=helmholtz_potential.single_layer(bempp_space,points,k)
    dlp_pot=helmholtz_potential.double_layer(trace_space,points,k)
    output = incident_wave(points.T)
    output += dlp_pot.evaluate(g_soln)[0]
    output -= slp_pot.evaluate(g_n_soln)[0]
    return output
def result (points):
    from bempp.api.operators.potential import helmholtz as helmholtz_potential

    slp_pot=helmholtz_potential.single_layer(piecewise_lin_space, points, k)
    dlp_pot=helmholtz_potential.double_layer(piecewise_lin_space, points, k)

    res =  1j * muD * slp_pot.evaluate(w_fun) - dlp_pot.evaluate(w_fun)
    
    return res
def result (points):
    from bempp.api.operators.potential import helmholtz as helmholtz_potential

    slp_pot=helmholtz_potential.single_layer(piecewise_lin_space, points, k)
    dlp_pot=helmholtz_potential.double_layer(piecewise_lin_space, points, k)

    res =  1j * muD * slp_pot.evaluate(w_fun) - dlp_pot.evaluate(w_fun)
    
    return res[0]
Beispiel #6
0
points = np.vstack(
    (plot_grid[0].ravel(), plot_grid[1].ravel(), np.zeros(plot_grid[0].size)))
u_evaluated = np.zeros(points.shape[1], dtype=np.complex128)
u_evaluated[:] = np.nan

# This will generate a grid of points in the $x$-$y$ plane.
#
# Then we create a single layer potential operator and use it to evaluate the solution at the evaluation points. The variable ``idx`` allows to compute the solution only at points located outside the unit circle of the plane. We use a single layer potential operator to evaluate the solution at the observation points.

# In[10]:

x, y, z = points
idx = np.sqrt(x**2 + y**2) > 1.0

from bempp.api.operators.potential import helmholtz as helmholtz_potential
slp_pot = helmholtz_potential.single_layer(piecewise_const_space,
                                           points[:, idx], k)
res = np.real(np.exp(1j * k * points[0, idx]) - slp_pot.evaluate(neumann_fun))
u_evaluated[idx] = res.flat

# We now plot the slice of the domain solution.

# In[11]:

#get_ipython().run_line_magic('matplotlib', 'inline')

u_evaluated = u_evaluated.reshape((Nx, Ny))

from matplotlib import pyplot as plt
fig = plt.figure(figsize=(10, 8))
plt.imshow(np.real(u_evaluated.T), extent=[-3, 3, -3, 3])
plt.xlabel('x')
Beispiel #7
0

# Then we create a single layer potential operator and use it to evaluate the solution at the evaluation points.

# In[11]:

x, y, z =points
idx = np.sqrt(x**2 + y**2) > 1.0


# The variable idx allows to compute only points located outside the unit circle of the plane. We use a single layer potential operator to evaluate the solution at the observation points.

# In[12]:

from bempp.api.operators.potential import helmholtz as helmholtz_potential
slp_pot=helmholtz_potential.single_layer(piecewise_const_space,points[:,idx],k)
res = np.real(np.exp(1j *k * points[0,idx]) - slp_pot.evaluate(neumann_fun))
u_evaluated[idx] = res.flat


# We can now easily plot a slice of the domain solution.

# In[13]:

u_evaluated=u_evaluated.reshape((Nx, Ny))

print('  -> bempp computations done.')

# get_ipython().magic('matplotlib inline')
# Plot the image
try: