Skip to content

Commit

Permalink
Add test cases parametrized on which POD optional arguments are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-ballarin committed Aug 29, 2023
1 parent b4e6440 commit 0b0db94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,24 @@ def tensors_list_mat(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsList:
return tensors_list


@pytest.mark.parametrize("normalize", [True, False])
@pytest.mark.parametrize("N", [None, 2])
@pytest.mark.parametrize("tol", [None, 0.0])
@pytest.mark.parametrize("normalize", [None, True, False])
def test_backends_proper_orthogonal_decomposition_functions( # type: ignore[no-any-unimported]
functions_list: rbnicsx.backends.FunctionsList, inner_product: ufl.Form, normalize: bool
functions_list: rbnicsx.backends.FunctionsList, inner_product: ufl.Form,
N: typing.Optional[int], tol: typing.Optional[float], normalize: typing.Optional[bool]
) -> None:
"""Check rbnicsx.backends.proper_orthogonal_decomposition for the case of dolfinx.fem.Function snapshots."""
kwargs = dict()
if N is not None:
kwargs["N"] = N
if tol is not None:
kwargs["tol"] = tol
if normalize is not None:
kwargs["normalize"] = normalize
compute_inner_product = rbnicsx.backends.bilinear_form_action(inner_product)
eigenvalues, modes, eigenvectors = rbnicsx.backends.proper_orthogonal_decomposition(
functions_list[:2], compute_inner_product, N=2, tol=0.0, normalize=normalize)
functions_list[:2], compute_inner_product, **kwargs)
assert len(eigenvalues) == 2
assert np.isclose(eigenvalues[0], 5)
assert np.isclose(eigenvalues[1], 0)
Expand Down
13 changes: 11 additions & 2 deletions tests/unit/online/test_online_proper_orthogonal_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,25 @@ def tensors_list_mat(request: _pytest.fixtures.SubRequest) -> rbnicsx.online.Ten
return request.getfixturevalue(request.param) # type: ignore[no-any-return]


@pytest.mark.parametrize("N", [None, 2])
@pytest.mark.parametrize("tol", [None, 0.0])
@pytest.mark.parametrize("normalize", [True, False])
def test_online_proper_orthogonal_decomposition_functions( # type: ignore[no-any-unimported]
functions_list: rbnicsx.online.FunctionsList, inner_product: typing.Callable[[int], petsc4py.PETSc.Mat],
normalize: bool
N: typing.Optional[int], tol: typing.Optional[float], normalize: typing.Optional[bool]
) -> None:
"""Check rbnicsx.online.proper_orthogonal_decomposition for the case of snapshots stored in a FunctionsList."""
size = functions_list[0].size
inner_product_matrix = inner_product(size)
kwargs = dict()
if N is not None:
kwargs["N"] = N
if tol is not None:
kwargs["tol"] = tol
if normalize is not None:
kwargs["normalize"] = normalize
eigenvalues, modes, eigenvectors = rbnicsx.online.proper_orthogonal_decomposition(
functions_list[:2], inner_product_matrix, N=2, tol=0.0, normalize=normalize)
functions_list[:2], inner_product_matrix, **kwargs)
assert len(eigenvalues) == 2
sum_squares_first_size_numbers = size * (size + 1) * (2 * size + 1) / 6
assert np.isclose(eigenvalues[0], 5 * sum_squares_first_size_numbers)
Expand Down

0 comments on commit 0b0db94

Please sign in to comment.