|
|
@@ -7,18 +7,26 @@ from hdpg1d.coefficients import coefficients as coeff
|
|
|
from hdpg1d.adaptation import hdpg1d
|
|
|
|
|
|
|
|
|
+testData = [
|
|
|
+ ([1e-4, 0, 1, 2, 2, 1, 1], 1e-2), # diffusion reaction
|
|
|
+ ([0, 1, 0, 2, 2, 1, 1], 0), # convection
|
|
|
+ # ([1, 1, 0, 2, 2, 1, 1], 1) # diffusion convection)
|
|
|
+]
|
|
|
+
|
|
|
+
|
|
|
class TestClass(object):
|
|
|
+ @pytest.fixture(scope="module", params=testData)
|
|
|
+ def coeffGen(self, request):
|
|
|
+ coeffTest = coeff(*request.param[0])
|
|
|
+ expected = request.param[1]
|
|
|
+ yield coeffTest, expected # teardown
|
|
|
+
|
|
|
def test_zeroDivision(self, monkeypatch):
|
|
|
coeffTest = coeff(*([0] * 7))
|
|
|
assert coeffTest.DIFFUSION != 0
|
|
|
|
|
|
- @pytest.mark.parametrize("coeffInput, expected", [
|
|
|
- ([1e-4, 0, 1, 2, 2, 1, 1], 1e-2), # diffusion reaction
|
|
|
- ([0, 1, 0, 2, 2, 1, 1], 0), # convection
|
|
|
- # ([1, 1, 0, 2, 2, 1, 1], 1) # diffusion convection
|
|
|
- ])
|
|
|
- def test_solveAdaptive(self, coeffInput, expected):
|
|
|
- coeffTest = coeff(*coeffInput)
|
|
|
+ def test_solveAdaptive(self, coeffGen):
|
|
|
+ coeffTest, expected = coeffGen
|
|
|
hdpgTest = hdpg1d(coeffTest)
|
|
|
hdpgTest.adaptive()
|
|
|
# get the target function value
|
|
|
@@ -26,16 +34,11 @@ class TestClass(object):
|
|
|
soln = hdpgTest.trueErrorList[1][-1]
|
|
|
assert math.isclose(soln, expected, rel_tol=1e-5, abs_tol=1e-10)
|
|
|
|
|
|
- @pytest.mark.parametrize("coeffInput, expected", [
|
|
|
- ([1e-4, 0, 1, 2, 2, 1, 1], 1e-2), # diffusion reaction
|
|
|
- ([0, 1, 0, 2, 2, 1, 1], 0), # convection
|
|
|
- # ([1, 1, 0, 2, 2, 1, 1], 1) # diffusion convection
|
|
|
- ])
|
|
|
- def test_solvePrimal(self, coeffInput, expected):
|
|
|
- # test the primal solver with a refined mesh and poly order
|
|
|
- coeffInput[3] = 5
|
|
|
- coeffInput[4] = 200
|
|
|
- coeffTest = coeff(*coeffInput)
|
|
|
+ def test_solvePrimal(self, coeffGen):
|
|
|
+ coeffTest, expected = coeffGen
|
|
|
+ # test the primal solver on a refined mesh and higher poly order
|
|
|
+ coeffTest.pOrder = 5
|
|
|
+ coeffTest.numEle = 300
|
|
|
hdpgTest = hdpg1d(coeffTest)
|
|
|
hdpgTest.solvePrimal()
|
|
|
soln = hdpgTest.primalSoln[hdpgTest.numEle *
|