Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs committed Nov 8, 2024
1 parent 8ea0e23 commit 83d3544
Show file tree
Hide file tree
Showing 37 changed files with 625 additions and 625 deletions.
22 changes: 11 additions & 11 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import numpy as np
import pytest

import bempp.api
import bempp.core
import bempp_cl.api
import bempp_cl.core


def pytest_addoption(parser):
Expand Down Expand Up @@ -66,9 +66,9 @@ def set_default_device_interface(request):
if value == "auto":
return
elif value == "numba":
bempp.api.DEFAULT_DEVICE_INTERFACE = "numba"
bempp_cl.api.DEFAULT_DEVICE_INTERFACE = "numba"
elif value == "opencl":
bempp.api.DEFAULT_DEVICE_INTERFACE = "opencl"
bempp_cl.api.DEFAULT_DEVICE_INTERFACE = "opencl"
else:
raise ValueError("device must be one of: 'numba', 'opencl'")

Expand All @@ -79,7 +79,7 @@ def set_device_options(request):
vec_mode = request.config.getoption("--vec")
if vec_mode not in ["auto", "novec", "vec4", "vec8", "vec16"]:
raise ValueError("vec must be one of: 'auto', 'novec', 'vec4', 'vec8', 'vec16'")
bempp.api.VECTORIZATION_MODE = vec_mode
bempp_cl.api.VECTORIZATION_MODE = vec_mode


@pytest.fixture()
Expand All @@ -94,7 +94,7 @@ def precision(request):
@pytest.fixture
def two_element_grid():
"""Simple grid consisting of two elements."""
from bempp.api.grid import Grid
from bempp_cl.api.grid import Grid

vertices = np.array([[0, 1, 1, 0], [0, 0, 1, 1], [0, 0, 0, 0]])

Expand All @@ -106,7 +106,7 @@ def two_element_grid():
@pytest.fixture
def default_parameters():
"""Return a default parameters object."""
from bempp.api.utils.parameters import DefaultParameters
from bempp_cl.api.utils.parameters import DefaultParameters

parameters = DefaultParameters()
parameters.quadrature.regular = 4
Expand All @@ -118,13 +118,13 @@ def default_parameters():
@pytest.fixture
def small_piecewise_const_space(small_sphere):
"""A simple piecewise constant space on a small sphere."""
return bempp.api.function_space(small_sphere, "DP", 0)
return bempp_cl.api.function_space(small_sphere, "DP", 0)


@pytest.fixture
def laplace_slp_small_sphere(small_piecewise_const_space, default_parameters):
"""The Laplace single layer operator on a small sphere."""
from bempp.api.operators.boundary.laplace import single_layer
from bempp_cl.api.operators.boundary.laplace import single_layer

return single_layer(
small_piecewise_const_space,
Expand Down Expand Up @@ -158,11 +158,11 @@ def load_npz_data(name):
def load_grid(name):
"""Load grid stored as msh file (give name without ending)"""
grid_name = os.path.join(Helpers.test_path(), "data/" + name + ".msh")
return bempp.api.import_grid(grid_name)
return bempp_cl.api.import_grid(grid_name)

@staticmethod
def test_path():
"""Return path of the bempp module."""
"""Return path of the bempp_cl module."""
return os.path.abspath(os.path.dirname(__file__))

@staticmethod
Expand Down
74 changes: 37 additions & 37 deletions test/data/generate_fmm_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Script to be run with legacy Bempp to generate the comparison data.

import bempp.api
import bempp_cl.api
import numpy as np

import os.path
Expand Down Expand Up @@ -53,52 +53,52 @@ def save_matvec_result(operator, space1, space2, space3, vec, filename, *args):
def save_potential_eval_result(operator, space, vec, points, filename, *args):
if REGENERATE or not os.path.exists(filename + ".npy"):
print("Generating " + filename)
grid_fun = bempp.api.GridFunction(space, coefficients=vec)
grid_fun = bempp_cl.api.GridFunction(space, coefficients=vec)
result = operator(space, points, *args, assembler="dense").evaluate(grid_fun)
np.save(filename, result)
else:
print("Skipping " + filename + " (already generated)")


grid = bempp.api.shapes.ellipsoid(1, 0.5, 0.3, h=0.1)
bempp.api.export("fmm_grid.msh", grid=grid)
space = bempp.api.function_space(grid, "P", 1)
grid = bempp_cl.api.shapes.ellipsoid(1, 0.5, 0.3, h=0.1)
bempp_cl.api.export("fmm_grid.msh", grid=grid)
space = bempp_cl.api.function_space(grid, "P", 1)

vec = generate_vector(space.global_dof_count, "fmm_p1_vec")
points = generate_points(30, "fmm_potential_points.npy")

# Generate P1 boundary operator results
for filename, operator in [
("fmm_laplace_single", bempp.api.operators.boundary.laplace.single_layer),
("fmm_laplace_double", bempp.api.operators.boundary.laplace.double_layer),
("fmm_laplace_adjoint", bempp.api.operators.boundary.laplace.adjoint_double_layer),
("fmm_laplace_hyper", bempp.api.operators.boundary.laplace.hypersingular),
("fmm_laplace_single", bempp_cl.api.operators.boundary.laplace.single_layer),
("fmm_laplace_double", bempp_cl.api.operators.boundary.laplace.double_layer),
("fmm_laplace_adjoint", bempp_cl.api.operators.boundary.laplace.adjoint_double_layer),
("fmm_laplace_hyper", bempp_cl.api.operators.boundary.laplace.hypersingular),
]:
save_matvec_result(operator, space, space, space, vec, filename)

for filename, operator in [
("fmm_helmholtz_single", bempp.api.operators.boundary.helmholtz.single_layer),
("fmm_helmholtz_double", bempp.api.operators.boundary.helmholtz.double_layer),
("fmm_helmholtz_single", bempp_cl.api.operators.boundary.helmholtz.single_layer),
("fmm_helmholtz_double", bempp_cl.api.operators.boundary.helmholtz.double_layer),
(
"fmm_helmholtz_adjoint",
bempp.api.operators.boundary.helmholtz.adjoint_double_layer,
bempp_cl.api.operators.boundary.helmholtz.adjoint_double_layer,
),
("fmm_helmholtz_hyper", bempp.api.operators.boundary.helmholtz.hypersingular),
("fmm_helmholtz_hyper", bempp_cl.api.operators.boundary.helmholtz.hypersingular),
(
"fmm_modified_helmholtz_single",
bempp.api.operators.boundary.modified_helmholtz.single_layer,
bempp_cl.api.operators.boundary.modified_helmholtz.single_layer,
),
(
"fmm_modified_helmholtz_double",
bempp.api.operators.boundary.modified_helmholtz.double_layer,
bempp_cl.api.operators.boundary.modified_helmholtz.double_layer,
),
(
"fmm_modified_helmholtz_adjoint",
bempp.api.operators.boundary.modified_helmholtz.adjoint_double_layer,
bempp_cl.api.operators.boundary.modified_helmholtz.adjoint_double_layer,
),
(
"fmm_modified_helmholtz_hyper",
bempp.api.operators.boundary.modified_helmholtz.hypersingular,
bempp_cl.api.operators.boundary.modified_helmholtz.hypersingular,
),
]:
save_matvec_result(operator, space, space, space, vec, filename, 1.5)
Expand All @@ -107,75 +107,75 @@ def save_potential_eval_result(operator, space, vec, points, filename, *args):
for filename, operator in [
(
"fmm_laplace_potential_single",
bempp.api.operators.potential.laplace.single_layer,
bempp_cl.api.operators.potential.laplace.single_layer,
),
(
"fmm_laplace_potential_double",
bempp.api.operators.potential.laplace.double_layer,
bempp_cl.api.operators.potential.laplace.double_layer,
),
]:
save_potential_eval_result(operator, space, vec, points, filename)

for filename, operator in [
(
"fmm_helmholtz_potential_single",
bempp.api.operators.potential.helmholtz.single_layer,
bempp_cl.api.operators.potential.helmholtz.single_layer,
),
(
"fmm_helmholtz_potential_double",
bempp.api.operators.potential.helmholtz.double_layer,
bempp_cl.api.operators.potential.helmholtz.double_layer,
),
(
"fmm_modified_potential_helmholtz_single",
bempp.api.operators.potential.modified_helmholtz.single_layer,
bempp_cl.api.operators.potential.modified_helmholtz.single_layer,
),
(
"fmm_modified_potential_helmholtz_double",
bempp.api.operators.potential.modified_helmholtz.double_layer,
bempp_cl.api.operators.potential.modified_helmholtz.double_layer,
),
]:
save_potential_eval_result(operator, space, vec, points, filename, 1.5)


rwg = bempp.api.function_space(grid, "RWG", 0)
snc = bempp.api.function_space(grid, "SNC", 0)
rwg = bempp_cl.api.function_space(grid, "RWG", 0)
snc = bempp_cl.api.function_space(grid, "SNC", 0)

vec2 = generate_vector(rwg.global_dof_count, "fmm_rwg_vec")

# Generate Maxwell boundary operator results
for filename, operator in [
("fmm_maxwell_electric", bempp.api.operators.boundary.maxwell.electric_field),
("fmm_maxwell_magnetic", bempp.api.operators.boundary.maxwell.magnetic_field),
("fmm_maxwell_electric", bempp_cl.api.operators.boundary.maxwell.electric_field),
("fmm_maxwell_magnetic", bempp_cl.api.operators.boundary.maxwell.magnetic_field),
]:
save_matvec_result(operator, rwg, rwg, snc, vec2, filename, 1.5)

# Generate Maxwell potential operator results
for filename, operator in [
(
"fmm_maxwell_potential_electric",
bempp.api.operators.potential.maxwell.electric_field,
bempp_cl.api.operators.potential.maxwell.electric_field,
),
(
"fmm_maxwell_potential_magnetic",
bempp.api.operators.potential.maxwell.magnetic_field,
bempp_cl.api.operators.potential.maxwell.magnetic_field,
),
]:
save_potential_eval_result(operator, rwg, vec2, points, filename, 1.5)


# Generate two grid data
grid1 = bempp.api.shapes.ellipsoid(0.5, 0.5, 0.3, h=0.1)
grid2 = bempp.api.shapes.sphere(r=1.5, h=0.1)
bempp.api.export("fmm_grid1.msh", grid=grid1)
bempp.api.export("fmm_grid2.msh", grid=grid2)
grid1 = bempp_cl.api.shapes.ellipsoid(0.5, 0.5, 0.3, h=0.1)
grid2 = bempp_cl.api.shapes.sphere(r=1.5, h=0.1)
bempp_cl.api.export("fmm_grid1.msh", grid=grid1)
bempp_cl.api.export("fmm_grid2.msh", grid=grid2)

p1_space1 = bempp.api.function_space(grid1, "P", 1)
p1_space2 = bempp.api.function_space(grid2, "P", 1)
p1_space1 = bempp_cl.api.function_space(grid1, "P", 1)
p1_space2 = bempp_cl.api.function_space(grid2, "P", 1)

vec = generate_vector(p1_space1.global_dof_count, "fmm_two_mesh_vec")

for filename, operator in [
("fmm_two_mesh_laplace_single", bempp.api.operators.boundary.laplace.single_layer),
("fmm_two_mesh_laplace_hyper", bempp.api.operators.boundary.laplace.hypersingular),
("fmm_two_mesh_laplace_single", bempp_cl.api.operators.boundary.laplace.single_layer),
("fmm_two_mesh_laplace_hyper", bempp_cl.api.operators.boundary.laplace.hypersingular),
]:
save_matvec_result(operator, p1_space1, p1_space2, p1_space2, vec, filename)
Loading

0 comments on commit 83d3544

Please sign in to comment.