Skip to content

Commit

Permalink
Update tests to account for multiplication by CellVolume
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Oct 23, 2023
1 parent 1b825f0 commit f55dce1
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions test/test_error_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ def test_form_type_error(self):
def test_exterior_facet_integral(self):
F = self.one * ds(1) - self.one * ds(2)
indicator = form2indicator(F)
self.assertAlmostEqual(indicator.dat.data[0], -2)
self.assertAlmostEqual(indicator.dat.data[1], 2)
self.assertAlmostEqual(indicator.dat.data[0], -1)
self.assertAlmostEqual(indicator.dat.data[1], 1)

def test_interior_facet_integral(self):
F = avg(self.one) * dS
indicator = form2indicator(F)
self.assertAlmostEqual(indicator.dat.data[0], 2 * sqrt(2))
self.assertAlmostEqual(indicator.dat.data[1], 2 * sqrt(2))
self.assertAlmostEqual(indicator.dat.data[0], sqrt(2))
self.assertAlmostEqual(indicator.dat.data[1], sqrt(2))

def test_cell_integral(self):
x, y = SpatialCoordinate(self.mesh)
F = conditional(x + y < 1, 1, 0) * dx
indicator = form2indicator(F)
self.assertAlmostEqual(indicator.dat.data[0], 0)
self.assertAlmostEqual(indicator.dat.data[1], 1)
self.assertAlmostEqual(indicator.dat.data[1], 0.5)


class TestIndicators2Estimator(ErrorEstimationTestCase):
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_unit_time_instant(self):
time_instant = TimeInstant("field", time=1.0)
indicator = form2indicator(self.one * dx)
estimator = indicators2estimator({"field": [[indicator]]}, time_instant)
self.assertAlmostEqual(estimator, 2.0) # 1 * (1 + 1)
self.assertAlmostEqual(estimator, 1) # 1 * (0.5 + 0.5)

@parameterized.expand([[False], [True]])
def test_unit_time_instant_abs(self, absolute_value):
Expand All @@ -139,36 +139,36 @@ def test_unit_time_instant_abs(self, absolute_value):
{"field": [[indicator]]}, time_instant, absolute_value=absolute_value
)
self.assertAlmostEqual(
estimator, 2.0 if absolute_value else -2.0
) # (-)1 * (1 + 1)
estimator, 1 if absolute_value else -1
) # (-)1 * (0.5 + 0.5)

def test_half_time_instant(self):
time_instant = TimeInstant("field", time=0.5)
indicator = form2indicator(self.one * dx)
estimator = indicators2estimator({"field": [[indicator]]}, time_instant)
self.assertAlmostEqual(estimator, 1.0) # 0.5 * (1 + 1)
self.assertAlmostEqual(estimator, 0.5) # 0.5 * (0.5 + 0.5)

def test_time_partition_same_timestep(self):
time_partition = TimePartition(1.0, 2, [0.5, 0.5], ["field"])
indicator = form2indicator(self.one * dx)
estimator = indicators2estimator({"field": [2 * [indicator]]}, time_partition)
self.assertAlmostEqual(estimator, 2.0) # 0.5 * (1 + 1) + 0.5 * (1 + 1)
self.assertAlmostEqual(estimator, 1) # 2 * 0.5 * (0.5 + 0.5)

def test_time_partition_different_timesteps(self):
time_partition = TimePartition(1.0, 2, [0.5, 0.25], ["field"])
indicator = form2indicator(self.one * dx)
estimator = indicators2estimator(
{"field": [[indicator], 2 * [indicator]]}, time_partition
)
self.assertAlmostEqual(estimator, 2.0) # 0.5 * (1 + 1) + 0.25 * 2 * (1 + 1)
self.assertAlmostEqual(estimator, 1) # 0.5 * (0.5 + 0.5) + 0.25 * 2 * (0.5 + 0.5)

def test_time_instant_multiple_fields(self):
time_instant = TimeInstant(["field1", "field2"], time=1.0)
indicator = form2indicator(self.one * dx)
estimator = indicators2estimator(
{"field1": [[indicator]], "field2": [[indicator]]}, time_instant
)
self.assertAlmostEqual(estimator, 4.0) # 2 * (1 * (1 + 1))
self.assertAlmostEqual(estimator, 2) # 2 * (1 * (0.5 + 0.5))


class TestGetDWRIndicator(ErrorEstimationTestCase):
Expand Down Expand Up @@ -247,32 +247,32 @@ def test_convert_neither(self):
adjoint_error = {"field": self.two}
test_space = {"field": self.one.function_space()}
indicator = get_dwr_indicator(self.F, adjoint_error, test_space=test_space)
self.assertAlmostEqual(indicator.dat.data[0], 2)
self.assertAlmostEqual(indicator.dat.data[1], 2)
self.assertAlmostEqual(indicator.dat.data[0], 1)
self.assertAlmostEqual(indicator.dat.data[1], 1)

def test_convert_both(self):
test_space = self.one.function_space()
indicator = get_dwr_indicator(self.F, self.two, test_space=test_space)
self.assertAlmostEqual(indicator.dat.data[0], 2)
self.assertAlmostEqual(indicator.dat.data[1], 2)
self.assertAlmostEqual(indicator.dat.data[0], 1)
self.assertAlmostEqual(indicator.dat.data[1], 1)

def test_convert_test_space(self):
adjoint_error = {"field": self.two}
test_space = self.one.function_space()
indicator = get_dwr_indicator(self.F, adjoint_error, test_space=test_space)
self.assertAlmostEqual(indicator.dat.data[0], 2)
self.assertAlmostEqual(indicator.dat.data[1], 2)
self.assertAlmostEqual(indicator.dat.data[0], 1)
self.assertAlmostEqual(indicator.dat.data[1], 1)

def test_convert_adjoint_error(self):
test_space = {"Dos": self.one.function_space()}
indicator = get_dwr_indicator(self.F, self.two, test_space=test_space)
self.assertAlmostEqual(indicator.dat.data[0], 2)
self.assertAlmostEqual(indicator.dat.data[1], 2)
self.assertAlmostEqual(indicator.dat.data[0], 1)
self.assertAlmostEqual(indicator.dat.data[1], 1)

def test_convert_adjoint_error_no_test_space(self):
indicator = get_dwr_indicator(self.F, self.two)
self.assertAlmostEqual(indicator.dat.data[0], 2)
self.assertAlmostEqual(indicator.dat.data[1], 2)
self.assertAlmostEqual(indicator.dat.data[0], 1)
self.assertAlmostEqual(indicator.dat.data[1], 1)

def test_convert_adjoint_error_mismatch(self):
test_space = {"field": self.one.function_space()}
Expand Down

0 comments on commit f55dce1

Please sign in to comment.