From afe8428d4a295e38062b4b86a4883edacb611bed Mon Sep 17 00:00:00 2001 From: Jared Callaham Date: Thu, 12 Sep 2024 04:46:10 -0400 Subject: [PATCH] Fix indexing error in BDF with k=1 (#189) --- hydrogym/firedrake/solvers/bdf_ext.py | 2 +- test/test_cyl.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/hydrogym/firedrake/solvers/bdf_ext.py b/hydrogym/firedrake/solvers/bdf_ext.py index 756243d..ec2dbc3 100644 --- a/hydrogym/firedrake/solvers/bdf_ext.py +++ b/hydrogym/firedrake/solvers/bdf_ext.py @@ -156,7 +156,7 @@ def step(self, iter, control=None): self.flow.set_control(bc_scale) # Solve the linear problem - if iter > self.k - 1: + if (self.k == 1) or (iter > self.k - 1): self.petsc_solver.solve() else: self.startup_solvers[iter - 1].solve() diff --git a/test/test_cyl.py b/test/test_cyl.py index bc6f76c..e41fca4 100644 --- a/test/test_cyl.py +++ b/test/test_cyl.py @@ -1,3 +1,4 @@ +import pytest import firedrake as fd import numpy as np @@ -41,10 +42,11 @@ def test_steady_rotation(tol=1e-3): assert abs(CD - 1.49) < tol # Re = 100 -def test_integrate(): +@pytest.mark.parametrize("k", [1, 3]) +def test_integrate(k): flow = hgym.Cylinder(mesh="medium") dt = 1e-2 - hgym.integrate(flow, t_span=(0, 10 * dt), dt=dt) + hgym.integrate(flow, t_span=(0, 10 * dt), dt=dt, order=k) # Simple opposition control on lift