Skip to content

Commit

Permalink
Test all controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Ig-dolci committed Dec 17, 2024
1 parent 96becfe commit 9f9b8eb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions integration-tests/adjoints/test_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def handle_annotation():
pause_annotation()


def test_diffusion(tmpdir):
@pytest.mark.parametrize("nu_is_control", [True, False])
def test_diffusion(nu_is_control, tmpdir):
n = 30
mesh = PeriodicUnitSquareMesh(n, n)
output = OutputParameters(dirname=str(tmpdir))
Expand Down Expand Up @@ -56,8 +57,6 @@ def test_diffusion(tmpdir):
u = timestepper.fields("f")
J = assemble(inner(u, u)*dx)

# flag to switch between nu and u for control variable
nu_is_control = True
if nu_is_control:
control = Control(nu)
h = Function(R, val=0.0001) # the direction of the perturbation
Expand All @@ -67,8 +66,9 @@ def test_diffusion(tmpdir):

Jhat = ReducedFunctional(J, control) # the functional as a pure function of nu

assert np.allclose(J, Jhat(nu))
if nu_is_control:
assert np.allclose(J, Jhat(nu))
assert taylor_test(Jhat, nu, h) > 1.95
else:
assert np.allclose(J, Jhat(u))
assert taylor_test(Jhat, u, h) > 1.95

0 comments on commit 9f9b8eb

Please sign in to comment.