Skip to content

Commit d4b6979

Browse files
committed
fix tests
1 parent 87c4312 commit d4b6979

File tree

2 files changed

+18
-40
lines changed

2 files changed

+18
-40
lines changed

test/unit/test_exports/test_derived_quantities/test_average_surface.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,24 @@ def test_h_average(self):
5959
@pytest.mark.parametrize("radius", [1, 4])
6060
@pytest.mark.parametrize("r0", [3, 5])
6161
@pytest.mark.parametrize("height", [2, 7])
62-
@pytest.mark.parametrize("c_top", [8, 9])
63-
@pytest.mark.parametrize("c_bottom", [10, 11])
64-
def test_compute_cylindrical(r0, radius, height, c_top, c_bottom):
62+
def test_compute_cylindrical(r0, radius, height):
6563
"""
6664
Test that AverageSurfaceCylindrical computes the value correctly on a hollow cylinder
6765
6866
Args:
6967
r0 (float): internal radius
7068
radius (float): cylinder radius
7169
height (float): cylinder height
72-
c_top (float): concentration top
73-
c_bottom (float): concentration bottom
7470
"""
7571
# creating a mesh with FEniCS
7672
r1 = r0 + radius
77-
z0 = 0
78-
z1 = z0 + height
73+
z0, z1 = 0, height
74+
7975
mesh_fenics = f.RectangleMesh(f.Point(r0, z0), f.Point(r1, z1), 10, 10)
8076

8177
top_surface = f.CompiledSubDomain(
8278
f"on_boundary && near(x[1], {z1}, tol)", tol=1e-14
8379
)
84-
8580
surface_markers = f.MeshFunction(
8681
"size_t", mesh_fenics, mesh_fenics.topology().dim() - 1
8782
)
@@ -93,15 +88,16 @@ def test_compute_cylindrical(r0, radius, height, c_top, c_bottom):
9388

9489
my_export = AverageSurfaceCylindrical("solute", top_id)
9590
V = f.FunctionSpace(mesh_fenics, "P", 1)
96-
c_fun = lambda z: c_bottom + (c_top - c_bottom) / (z1 - z0) * z
91+
c_fun = lambda r: 2 * r
92+
9793
expr = f.Expression(
98-
ccode(c_fun(y)),
94+
ccode(c_fun(x)),
9995
degree=1,
10096
)
10197
my_export.function = f.interpolate(expr, V)
10298
my_export.ds = ds
10399

104-
expected_value = c_bottom + (c_top - c_bottom) / (z1 - z0) * height
100+
expected_value = 4 / 3 * (r1**3 - r0**3) / (r1**2 - r0**2)
105101

106102
computed_value = my_export.compute()
107103

@@ -110,18 +106,14 @@ def test_compute_cylindrical(r0, radius, height, c_top, c_bottom):
110106

111107
@pytest.mark.parametrize("radius", [2, 4])
112108
@pytest.mark.parametrize("r0", [3, 5])
113-
@pytest.mark.parametrize("c_left", [8, 9])
114-
@pytest.mark.parametrize("c_right", [10, 11])
115-
def test_compute_spherical(r0, radius, c_left, c_right):
109+
def test_compute_spherical(r0, radius):
116110
"""
117111
Test that AverageSurfaceSpherical computes the average value correctly
118112
on a hollow sphere
119113
120114
Args:
121115
r0 (float): internal radius
122116
radius (float): sphere radius
123-
c_left (float): concentration left
124-
c_right (float): concentration right
125117
"""
126118
# creating a mesh with FEniCS
127119
r1 = r0 + radius
@@ -142,7 +134,7 @@ def test_compute_spherical(r0, radius, c_left, c_right):
142134

143135
my_export = AverageSurfaceSpherical("solute", right_id)
144136
V = f.FunctionSpace(mesh_fenics, "P", 1)
145-
c_fun = lambda r: c_left + (c_right - c_left) / (r1 - r0) * r
137+
c_fun = lambda r: 4 * r
146138
expr = f.Expression(
147139
ccode(c_fun(x)),
148140
degree=1,
@@ -151,7 +143,7 @@ def test_compute_spherical(r0, radius, c_left, c_right):
151143

152144
my_export.ds = ds
153145

154-
expected_value = c_left + ((c_right - c_left) / (r1 - r0)) * r1
146+
expected_value = 4 * r1
155147

156148
computed_value = my_export.compute()
157149

test/unit/test_exports/test_derived_quantities/test_average_volume.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,18 @@ def test_h_average(self):
5454
@pytest.mark.parametrize("radius", [2, 4])
5555
@pytest.mark.parametrize("r0", [3, 5])
5656
@pytest.mark.parametrize("height", [2, 7])
57-
@pytest.mark.parametrize("c_top", [8, 9])
58-
@pytest.mark.parametrize("c_bottom", [10, 11])
59-
def test_compute_cylindrical(r0, radius, height, c_top, c_bottom):
57+
def test_compute_cylindrical(r0, radius, height):
6058
"""
6159
Test that AverageVolumeCylindrical computes the value correctly on a hollow cylinder
6260
6361
Args:
6462
r0 (float): internal radius
6563
radius (float): cylinder radius
6664
height (float): cylinder height
67-
c_top (float): concentration top
68-
c_bottom (float): concentration bottom
6965
"""
7066
# creating a mesh with FEniCS
7167
r1 = r0 + radius
72-
z0 = 0
73-
z1 = z0 + height
68+
z0, z1 = 0, height
7469

7570
mesh_fenics = f.RectangleMesh(f.Point(r0, z0), f.Point(r1, z1), 10, 10)
7671

@@ -80,15 +75,12 @@ def test_compute_cylindrical(r0, radius, height, c_top, c_bottom):
8075

8176
my_export = AverageVolumeCylindrical("solute", 1)
8277
V = f.FunctionSpace(mesh_fenics, "P", 1)
83-
c_fun = lambda z: c_bottom + (c_top - c_bottom) / (height) * z
84-
expr = f.Expression(
85-
ccode(c_fun(y)),
86-
degree=1,
87-
)
78+
c_fun = lambda r: 3 * r
79+
expr = f.Expression(ccode(c_fun(x)), degree=1)
8880
my_export.function = f.interpolate(expr, V)
8981
my_export.dx = dx
9082

91-
expected_value = (c_bottom + c_top) / 2
83+
expected_value = 2 * (r1**3 - r0**3) / (r1**2 - r0**2)
9284

9385
computed_value = my_export.compute()
9486

@@ -97,18 +89,14 @@ def test_compute_cylindrical(r0, radius, height, c_top, c_bottom):
9789

9890
@pytest.mark.parametrize("radius", [2, 4])
9991
@pytest.mark.parametrize("r0", [3, 5])
100-
@pytest.mark.parametrize("c_left", [8, 9])
101-
@pytest.mark.parametrize("c_right", [10, 11])
102-
def test_compute_spherical(r0, radius, c_left, c_right):
92+
def test_compute_spherical(r0, radius):
10393
"""
10494
Test that AverageVolumeSpherical computes the average value correctly
10595
on a hollow sphere
10696
10797
Args:
10898
r0 (float): internal radius
10999
radius (float): sphere radius
110-
c_left (float): concentration left
111-
c_right (float): concentration right
112100
"""
113101
# creating a mesh with FEniCS
114102
r1 = r0 + radius
@@ -121,7 +109,7 @@ def test_compute_spherical(r0, radius, c_left, c_right):
121109

122110
my_export = AverageVolumeSpherical("solute", 1)
123111
V = f.FunctionSpace(mesh_fenics, "P", 1)
124-
c_fun = lambda r: c_left + (c_right - c_left) / (r1 - r0) * r
112+
c_fun = lambda r: 4 * r
125113
expr = f.Expression(
126114
ccode(c_fun(x)),
127115
degree=1,
@@ -130,9 +118,7 @@ def test_compute_spherical(r0, radius, c_left, c_right):
130118

131119
my_export.dx = dx
132120

133-
expected_value = c_left + (3 * (c_right - c_left)) / (4 * (r1**3 - r0**3)) * (
134-
r1 + r0
135-
) * (r1**2 + r0**2)
121+
expected_value = 3 * (r1**4 - r0**4) / (r1**3 - r0**3)
136122

137123
computed_value = my_export.compute()
138124

0 commit comments

Comments
 (0)